Commit c2899c5c authored by Klaus Weidner's avatar Klaus Weidner Committed by Commit Bot

WebXR: Update Surface in SurfaceControl mode if needed

The previous workaround for WebXR DOM Overlay mode from
https://crrev.com/c/2378653 didn't work consistently due to a race
condition.

CompositorView's notifyWillUseSurfaceControl is asynchronous, so it's
possible that initNativeCompositor will be using the OPAQUE surface even
though a later call to canUseSurfaceControl() returns true and
getSurfacePixelFormat() returns TRANSLUCENT. In this case, continue with
the normal requestSurface path.

Bug: 1123951
Change-Id: I612b24bcdeb8b45fb33c6d94481e6b2ab63c74c6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2386331
Commit-Queue: Klaus Weidner <klausw@chromium.org>
Reviewed-by: default avatarPiotr Bialecki <bialpio@chromium.org>
Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804140}
parent 83a6102e
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
package org.chromium.chrome.browser.vr; package org.chromium.chrome.browser.vr;
import android.graphics.PixelFormat;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.view.Surface; import android.view.Surface;
import android.view.View; import android.view.View;
...@@ -79,6 +80,12 @@ public class VrCompositorSurfaceManager implements CompositorSurfaceManager { ...@@ -79,6 +80,12 @@ public class VrCompositorSurfaceManager implements CompositorSurfaceManager {
mSurfaceState = SurfaceState.NOT_REQUESTED; mSurfaceState = SurfaceState.NOT_REQUESTED;
} }
@Override
public int getFormatOfOwnedSurface() {
if (mSurface == null) return PixelFormat.UNKNOWN;
return mFormat;
}
@Override @Override
public void requestSurface(int format) { public void requestSurface(int format) {
if (mSurface == null) { if (mSurface == null) {
......
...@@ -40,6 +40,12 @@ public interface CompositorSurfaceManager { ...@@ -40,6 +40,12 @@ public interface CompositorSurfaceManager {
*/ */
void requestSurface(int format); void requestSurface(int format);
/**
* Returns the PixelFormat of the currently owned surface if any (OPAQUE or TRANSLUCENT),
* or UNKNOWN if there is no owned surface or it isn't initialized yet.
*/
int getFormatOfOwnedSurface();
/** /**
* Called to notify us that the client no longer needs the surface that it doesn't own. This * Called to notify us that the client no longer needs the surface that it doesn't own. This
* tells us that we may destroy it. Note that it's okay if it never had an unowned surface. * tells us that we may destroy it. Note that it's okay if it never had an unowned surface.
......
...@@ -148,6 +148,12 @@ class CompositorSurfaceManagerImpl implements SurfaceHolder.Callback2, Composito ...@@ -148,6 +148,12 @@ class CompositorSurfaceManagerImpl implements SurfaceHolder.Callback2, Composito
mOpaque.surfaceHolder().removeCallback(this); mOpaque.surfaceHolder().removeCallback(this);
} }
@Override
public int getFormatOfOwnedSurface() {
if (mOwnedByClient == null) return PixelFormat.UNKNOWN;
return mOwnedByClient.format;
}
@Override @Override
public void requestSurface(int format) { public void requestSurface(int format) {
Log.e(TAG, "Transitioning to surface with format : " + format); Log.e(TAG, "Transitioning to surface with format : " + format);
......
...@@ -349,9 +349,10 @@ public class CompositorView ...@@ -349,9 +349,10 @@ public class CompositorView
// content. The compositor surface appears on top of that as an overlay.) // content. The compositor surface appears on top of that as an overlay.)
// TODO(https://crbug.com/1122103): revisit once the stale-ChromeChildSurface issue is // TODO(https://crbug.com/1122103): revisit once the stale-ChromeChildSurface issue is
// fixed. // fixed.
if (!canUseSurfaceControl()) { if (!canUseSurfaceControl()
// If SurfaceControl is off, switch the compositor to a translucent surface, same as || mCompositorSurfaceManager.getFormatOfOwnedSurface() != PixelFormat.TRANSLUCENT) {
// overlay video mode. // If SurfaceControl is off, or if we haven't started using it yet, switch the
// compositor to a translucent surface, same as overlay video mode.
setOverlayVideoMode(enabled); setOverlayVideoMode(enabled);
} }
CompositorViewJni.get().setOverlayImmersiveArMode( CompositorViewJni.get().setOverlayImmersiveArMode(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment