Commit 0a5b400f authored by Michael Thiessen's avatar Michael Thiessen Committed by Commit Bot

VR: Render Android views using hardware canvas on P

It seems that locking the hardware canvas and drawing view into that
has stopped crashing on P, so we should use it as it's *way* faster than
the software canvas.

Revert this CL if Chrome starts crashing when viewing Android UI in VR.

Change-Id: If63ff109548d54c4315945e55520e6278951c17d
Reviewed-on: https://chromium-review.googlesource.com/1000150Reviewed-by: default avatarYash Malik <ymalik@chromium.org>
Commit-Queue: Michael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#549206}
parent 2b263f3a
...@@ -8,12 +8,14 @@ import android.content.Context; ...@@ -8,12 +8,14 @@ import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.os.Build;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.Surface; import android.view.Surface;
import android.view.View; import android.view.View;
import android.view.ViewTreeObserver.OnPreDrawListener; import android.view.ViewTreeObserver.OnPreDrawListener;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import org.chromium.base.BuildInfo;
import org.chromium.base.TraceEvent; import org.chromium.base.TraceEvent;
/** /**
...@@ -53,13 +55,24 @@ public class VrViewContainer extends FrameLayout { ...@@ -53,13 +55,24 @@ public class VrViewContainer extends FrameLayout {
} }
@Override @Override
protected void dispatchDraw(Canvas canvas) { public void draw(Canvas canvas) {
if (mSurface == null) return; if (mSurface == null) return;
try (TraceEvent e = TraceEvent.scoped("VrViewContainer.dispatchDraw")) { try (TraceEvent e = TraceEvent.scoped("VrViewContainer.dispatchDraw")) {
// TODO(mthiesse): Support mSurface.lockHardwareCanvas(); https://crbug.com/692775 // The linter doesn't understand O_MR1+, so we need this line here to prevent the
final Canvas surfaceCanvas = mSurface.lockCanvas(null); // linter from complaining about lockHardwareCanvas. This won't be reached pre-N
// anyways.
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return;
Canvas surfaceCanvas = null;
if (BuildInfo.isAtLeastP()) {
// This seems to have stopped crashing with Android P. It's >10x faster than the
// software canvas rendering for Android UI.
surfaceCanvas = mSurface.lockHardwareCanvas();
} else {
surfaceCanvas = mSurface.lockCanvas(null);
}
surfaceCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); surfaceCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
super.dispatchDraw(surfaceCanvas); super.draw(surfaceCanvas);
mSurface.unlockCanvasAndPost(surfaceCanvas); mSurface.unlockCanvasAndPost(surfaceCanvas);
} }
} }
......
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