Commit 8aa9b775 authored by boliu's avatar boliu Committed by Commit bot

aw: Add test to ensure hardware mode works

We might accidentally turn off hardware acceleration in instrumentation
tests without knowing since tests are supposed to work in software mode
as well. So add a meta test to check this.

BUG=

Review URL: https://codereview.chromium.org/687803009

Cr-Commit-Position: refs/heads/master@{#302690}
parent ac1db38b
...@@ -500,4 +500,15 @@ public class AwContentsTest extends AwTestBase { ...@@ -500,4 +500,15 @@ public class AwContentsTest extends AwTestBase {
} }
} }
// This is a meta test that we don't accidentally turn of hardware
// acceleration in instrumentation tests without notice. Do not add the
// @DisableHardwareAccelerationForTest annotation for this test.
@Feature({"AndroidWebView"})
@SmallTest
public void testHardwareModeWorks() throws Throwable {
AwTestContainerView testContainer =
createAwTestContainerViewOnMainSync(mContentsClient);
assertTrue(testContainer.isHardwareAccelerated());
assertTrue(testContainer.isBackedByHardwareView());
}
} }
...@@ -39,7 +39,7 @@ public class AwTestContainerView extends FrameLayout { ...@@ -39,7 +39,7 @@ public class AwTestContainerView extends FrameLayout {
private AwContents.NativeGLDelegate mNativeGLDelegate; private AwContents.NativeGLDelegate mNativeGLDelegate;
private AwContents.InternalAccessDelegate mInternalAccessDelegate; private AwContents.InternalAccessDelegate mInternalAccessDelegate;
HardwareView mHardwareView = null; private HardwareView mHardwareView = null;
private boolean mAttachedContents = false; private boolean mAttachedContents = false;
private class HardwareView extends GLSurfaceView { private class HardwareView extends GLSurfaceView {
...@@ -232,7 +232,7 @@ public class AwTestContainerView extends FrameLayout { ...@@ -232,7 +232,7 @@ public class AwTestContainerView extends FrameLayout {
if (allowHardwareAcceleration) { if (allowHardwareAcceleration) {
mHardwareView = createHardwareViewOnlyOnce(context); mHardwareView = createHardwareViewOnlyOnce(context);
} }
if (mHardwareView != null) { if (isBackedByHardwareView()) {
addView(mHardwareView, addView(mHardwareView,
new FrameLayout.LayoutParams( new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT,
...@@ -249,12 +249,16 @@ public class AwTestContainerView extends FrameLayout { ...@@ -249,12 +249,16 @@ public class AwTestContainerView extends FrameLayout {
public void initialize(AwContents awContents) { public void initialize(AwContents awContents) {
mAwContents = awContents; mAwContents = awContents;
if (mHardwareView != null) { if (isBackedByHardwareView()) {
mHardwareView.initialize( mHardwareView.initialize(
mAwContents.getAwDrawGLFunction(), mAwContents.getAwDrawGLViewContext()); mAwContents.getAwDrawGLFunction(), mAwContents.getAwDrawGLViewContext());
} }
} }
public boolean isBackedByHardwareView() {
return mHardwareView != null;
}
public ContentViewCore getContentViewCore() { public ContentViewCore getContentViewCore() {
return mAwContents.getContentViewCore(); return mAwContents.getContentViewCore();
} }
...@@ -380,7 +384,7 @@ public class AwTestContainerView extends FrameLayout { ...@@ -380,7 +384,7 @@ public class AwTestContainerView extends FrameLayout {
@Override @Override
public void onDraw(Canvas canvas) { public void onDraw(Canvas canvas) {
if (mHardwareView != null) { if (isBackedByHardwareView()) {
mHardwareView.updateScroll(getScrollX(), getScrollY()); mHardwareView.updateScroll(getScrollX(), getScrollY());
} }
mAwContents.onDraw(canvas); mAwContents.onDraw(canvas);
...@@ -417,14 +421,14 @@ public class AwTestContainerView extends FrameLayout { ...@@ -417,14 +421,14 @@ public class AwTestContainerView extends FrameLayout {
@Override @Override
public boolean requestDrawGL(Canvas canvas, boolean waitForCompletion, public boolean requestDrawGL(Canvas canvas, boolean waitForCompletion,
View containerview) { View containerview) {
if (mHardwareView == null) return false; if (!isBackedByHardwareView()) return false;
mHardwareView.requestRender(canvas, waitForCompletion); mHardwareView.requestRender(canvas, waitForCompletion);
return true; return true;
} }
@Override @Override
public void detachGLFunctor() { public void detachGLFunctor() {
if (mHardwareView != null) mHardwareView.detachGLFunctor(); if (isBackedByHardwareView()) mHardwareView.detachGLFunctor();
} }
} }
...@@ -466,7 +470,7 @@ public class AwTestContainerView extends FrameLayout { ...@@ -466,7 +470,7 @@ public class AwTestContainerView extends FrameLayout {
public void super_scrollTo(int scrollX, int scrollY) { public void super_scrollTo(int scrollX, int scrollY) {
// We're intentionally not calling super.scrollTo here to make testing easier. // We're intentionally not calling super.scrollTo here to make testing easier.
AwTestContainerView.this.scrollTo(scrollX, scrollY); AwTestContainerView.this.scrollTo(scrollX, scrollY);
if (mHardwareView != null) { if (isBackedByHardwareView()) {
// Undo the scroll that will be applied because of mHardwareView // Undo the scroll that will be applied because of mHardwareView
// being a child of |this|. // being a child of |this|.
mHardwareView.setTranslationX(scrollX); mHardwareView.setTranslationX(scrollX);
......
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