From 6985a8ba3006320d56fb8c0fee9ee49be28118db Mon Sep 17 00:00:00 2001 From: knox Date: Wed, 6 Nov 2019 10:03:17 +0800 Subject: [PATCH 1/3] fixed video player and webview transform --- cocos2d/videoplayer/video-player-impl.js | 16 +++++----------- cocos2d/webview/webview-impl.js | 22 +++++++++------------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/cocos2d/videoplayer/video-player-impl.js b/cocos2d/videoplayer/video-player-impl.js index b34b85c5fea..215758009fa 100644 --- a/cocos2d/videoplayer/video-player-impl.js +++ b/cocos2d/videoplayer/video-player-impl.js @@ -440,18 +440,17 @@ let VideoPlayerImpl = cc.Class({ }, updateMatrix (node) { - if (!this._video || !this._visible || this._fullScreenEnabled) return; + if (!this._video || !this._visible || this._fullScreenEnabled || !this._forceUpdate) return; node.getWorldMatrix(_mat4_temp); let renderCamera = cc.Camera._findRendererCamera(node); if (renderCamera) { - renderCamera.worldMatrixToScreen(_mat4_temp, _mat4_temp, cc.visibleRect.width, cc.visibleRect.height); + renderCamera.worldMatrixToScreen(_mat4_temp, _mat4_temp, cc.game.canvas.width, cc.game.canvas.height); } let _mat4_tempm = _mat4_temp.m; - if (!this._forceUpdate && - this._m00 === _mat4_tempm[0] && this._m01 === _mat4_tempm[1] && + if (this._m00 === _mat4_tempm[0] && this._m01 === _mat4_tempm[1] && this._m04 === _mat4_tempm[4] && this._m05 === _mat4_tempm[5] && this._m12 === _mat4_tempm[12] && this._m13 === _mat4_tempm[13] && this._w === node._contentSize.width && this._h === node._contentSize.height) { @@ -468,11 +467,9 @@ let VideoPlayerImpl = cc.Class({ this._w = node._contentSize.width; this._h = node._contentSize.height; - let scaleX = cc.view._scaleX, scaleY = cc.view._scaleY; let dpr = cc.view._devicePixelRatio; - - scaleX /= dpr; - scaleY /= dpr; + let scaleX = 1 / dpr; + let scaleY = 1 / dpr; let container = cc.game.container; let a = _mat4_tempm[0] * scaleX, b = _mat4_tempm[1], c = _mat4_tempm[4], d = _mat4_tempm[5] * scaleY; @@ -496,9 +493,6 @@ let VideoPlayerImpl = cc.Class({ let appx = (w * _mat4_tempm[0]) * node._anchorPoint.x; let appy = (h * _mat4_tempm[5]) * node._anchorPoint.y; - let viewport = cc.view._viewportRect; - offsetX += viewport.x / dpr; - offsetY += viewport.y / dpr; let tx = _mat4_tempm[12] * scaleX - appx + offsetX, ty = _mat4_tempm[13] * scaleY - appy + offsetY; diff --git a/cocos2d/webview/webview-impl.js b/cocos2d/webview/webview-impl.js index c0013d48519..ad6721e1efb 100644 --- a/cocos2d/webview/webview-impl.js +++ b/cocos2d/webview/webview-impl.js @@ -341,17 +341,17 @@ let WebViewImpl = cc.Class({ }, updateMatrix (node) { - if (!this._div || !this._visible) return; + if (!this._div || !this._visible || !this._forceUpdate) return; node.getWorldMatrix(_mat4_temp); + let renderCamera = cc.Camera._findRendererCamera(node); if (renderCamera) { - renderCamera.worldMatrixToScreen(_mat4_temp, _mat4_temp, cc.visibleRect.width, cc.visibleRect.height); + renderCamera.worldMatrixToScreen(_mat4_temp, _mat4_temp, cc.game.canvas.width, cc.game.canvas.height); } let _mat4_tempm = _mat4_temp.m; - if (!this._forceUpdate && - this._m00 === _mat4_tempm[0] && this._m01 === _mat4_tempm[1] && + if (this._m00 === _mat4_tempm[0] && this._m01 === _mat4_tempm[1] && this._m04 === _mat4_tempm[4] && this._m05 === _mat4_tempm[5] && this._m12 === _mat4_tempm[12] && this._m13 === _mat4_tempm[13] && this._w === node._contentSize.width && this._h === node._contentSize.height) { @@ -368,11 +368,9 @@ let WebViewImpl = cc.Class({ this._w = node._contentSize.width; this._h = node._contentSize.height; - let scaleX = cc.view._scaleX, scaleY = cc.view._scaleY; let dpr = cc.view._devicePixelRatio; - - scaleX /= dpr; - scaleY /= dpr; + let scaleX = 1 / dpr; + let scaleY = 1 / dpr; let container = cc.game.container; let a = _mat4_tempm[0] * scaleX, b = _mat4_tempm[1], c = _mat4_tempm[4], d = _mat4_tempm[5] * scaleY; @@ -380,14 +378,12 @@ let WebViewImpl = cc.Class({ let offsetX = container && container.style.paddingLeft ? parseInt(container.style.paddingLeft) : 0; let offsetY = container && container.style.paddingBottom ? parseInt(container.style.paddingBottom) : 0; this._updateSize(this._w, this._h); - let w = this._div.clientWidth * scaleX; - let h = this._div.clientHeight * scaleY; + let w = this._w * scaleX; + let h = this._h * scaleY; + let appx = (w * _mat4_tempm[0]) * node._anchorPoint.x; let appy = (h * _mat4_tempm[5]) * node._anchorPoint.y; - let viewport = cc.view._viewportRect; - offsetX += viewport.x / dpr; - offsetY += viewport.y / dpr; let tx = _mat4_tempm[12] * scaleX - appx + offsetX, ty = _mat4_tempm[13] * scaleY - appy + offsetY; From ff68ac12ae2631b93ffcbe6a0e54098e1788e1ab Mon Sep 17 00:00:00 2001 From: knox Date: Wed, 6 Nov 2019 13:43:57 +0800 Subject: [PATCH 2/3] refine code --- cocos2d/videoplayer/CCVideoPlayer.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cocos2d/videoplayer/CCVideoPlayer.js b/cocos2d/videoplayer/CCVideoPlayer.js index 82edfc27c4a..8da338a1df6 100644 --- a/cocos2d/videoplayer/CCVideoPlayer.js +++ b/cocos2d/videoplayer/CCVideoPlayer.js @@ -263,7 +263,9 @@ let VideoPlayer = cc.Class({ }, set (enable) { this._isFullscreen = enable; - this._impl && this._impl.setFullScreenEnabled(enable); + if (!CC_EDITOR) { + this._impl && this._impl.setFullScreenEnabled(enable); + } }, animatable: false, tooltip: CC_DEV && 'i18n:COMPONENT.videoplayer.isFullscreen' From ef36ed8c889fd7665a1db54d03d8abbeba4fd5bc Mon Sep 17 00:00:00 2001 From: knox Date: Wed, 6 Nov 2019 14:05:45 +0800 Subject: [PATCH 3/3] refine code --- cocos2d/videoplayer/video-player-impl.js | 5 +---- cocos2d/webview/webview-impl.js | 4 +--- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/cocos2d/videoplayer/video-player-impl.js b/cocos2d/videoplayer/video-player-impl.js index 215758009fa..5b2bc9cae35 100644 --- a/cocos2d/videoplayer/video-player-impl.js +++ b/cocos2d/videoplayer/video-player-impl.js @@ -58,7 +58,6 @@ let VideoPlayerImpl = cc.Class({ this._ignorePause = false; // update matrix cache - this._forceUpdate = true; this._m00 = 0; this._m01 = 0; this._m04 = 0; @@ -139,13 +138,11 @@ let VideoPlayerImpl = cc.Class({ if (this._visible) { video.style.visibility = 'visible'; - this._forceUpdate = true; } else { video.style.visibility = 'hidden'; video.pause(); this._playing = false; - this._forceUpdate = false; } }, @@ -440,7 +437,7 @@ let VideoPlayerImpl = cc.Class({ }, updateMatrix (node) { - if (!this._video || !this._visible || this._fullScreenEnabled || !this._forceUpdate) return; + if (!this._video || !this._visible || this._fullScreenEnabled) return; node.getWorldMatrix(_mat4_temp); diff --git a/cocos2d/webview/webview-impl.js b/cocos2d/webview/webview-impl.js index ad6721e1efb..e164a851c80 100644 --- a/cocos2d/webview/webview-impl.js +++ b/cocos2d/webview/webview-impl.js @@ -44,7 +44,6 @@ let WebViewImpl = cc.Class({ this._listener = null; // update matrix cache - this._forceUpdate = true; this._m00 = 0; this._m01 = 0; this._m04 = 0; @@ -66,7 +65,6 @@ let WebViewImpl = cc.Class({ else { div.style.visibility = 'hidden'; } - this._forceUpdate = true; }, _updateSize (w, h) { @@ -341,7 +339,7 @@ let WebViewImpl = cc.Class({ }, updateMatrix (node) { - if (!this._div || !this._visible || !this._forceUpdate) return; + if (!this._div || !this._visible) return; node.getWorldMatrix(_mat4_temp);