Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed video player and webview transform #5684

Merged
merged 3 commits into from Nov 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看了一下代码发现,在隐藏 videoplayer 的时,updateMatrix 是不会执行的,所以没必要设置该属性,进行移除

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里可能还是要用 let scaleX = cc.view._scaleX / dpr
不同 canvas 适配模式,可能 scaleY scaleX 不一定为 1


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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果 canvas 组件是其他适配模式的话,可能还是得考虑 viewport 的偏移量


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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上


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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上


let tx = _mat4_tempm[12] * scaleX - appx + offsetX, ty = _mat4_tempm[13] * scaleY - appy + offsetY;

Expand Down