Skip to content

Commit

Permalink
fixed video player and webview transform (#5684)
Browse files Browse the repository at this point in the history
* fixed video player and webview transform

* refine code

* refine code
  • Loading branch information
knoxHuang authored and holycanvas committed Nov 8, 2019
1 parent aad1d74 commit de36207
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 28 deletions.
4 changes: 3 additions & 1 deletion cocos2d/videoplayer/CCVideoPlayer.js
Expand Up @@ -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'
Expand Down
17 changes: 4 additions & 13 deletions cocos2d/videoplayer/video-player-impl.js
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
},

Expand Down Expand Up @@ -446,12 +443,11 @@ let VideoPlayerImpl = cc.Class({

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) {
Expand All @@ -468,11 +464,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;
Expand All @@ -496,9 +490,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;

Expand Down
22 changes: 8 additions & 14 deletions cocos2d/webview/webview-impl.js
Expand Up @@ -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;
Expand All @@ -66,7 +65,6 @@ let WebViewImpl = cc.Class({
else {
div.style.visibility = 'hidden';
}
this._forceUpdate = true;
},

_updateSize (w, h) {
Expand Down Expand Up @@ -344,14 +342,14 @@ let WebViewImpl = cc.Class({
if (!this._div || !this._visible) 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) {
Expand All @@ -368,26 +366,22 @@ 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;

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;

Expand Down

0 comments on commit de36207

Please sign in to comment.