Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2042)

Unified Diff: android_webview/test/shell/src/org/chromium/android_webview/test/AwTestContainerView.java

Issue 414503004: android: Use hw acceleration in android_webview_shell (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: android_webview/test/shell/src/org/chromium/android_webview/test/AwTestContainerView.java
diff --git a/android_webview/test/shell/src/org/chromium/android_webview/test/AwTestContainerView.java b/android_webview/test/shell/src/org/chromium/android_webview/test/AwTestContainerView.java
index 153a280afe4adb5b86cad42a44a64cd77ea21e42..cd5c2751ee2ebf27606811b08f9a1825629981d9 100644
--- a/android_webview/test/shell/src/org/chromium/android_webview/test/AwTestContainerView.java
+++ b/android_webview/test/shell/src/org/chromium/android_webview/test/AwTestContainerView.java
@@ -4,6 +4,7 @@
package org.chromium.android_webview.test;
+import android.graphics.Color;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Canvas;
@@ -22,19 +23,102 @@ import android.widget.FrameLayout;
import org.chromium.android_webview.AwContents;
import org.chromium.content.browser.ContentViewCore;
+import android.opengl.GLSurfaceView;
+
+import javax.microedition.khronos.opengles.GL10;
+import javax.microedition.khronos.egl.EGLConfig;
+import android.util.Log;
+
+import android.view.SurfaceHolder;
+import android.graphics.PixelFormat;
+import android.view.ViewGroup;
+
/**
* A View used for testing the AwContents internals.
*
* This class takes the place android.webkit.WebView would have in the production configuration.
*/
-public class AwTestContainerView extends FrameLayout {
+public class AwTestContainerView extends ViewGroup /*FrameLayout*/ {
private AwContents mAwContents;
private AwContents.NativeGLDelegate mNativeGLDelegate;
private AwContents.InternalAccessDelegate mInternalAccessDelegate;
+ final GLSurfaceView mSurfaceView;
+ final ViewGroup mRootView;
+ private boolean mReadyToRender = false;
+ private boolean mAttached = false;
+
+ private final Runnable mSurfaceChangedCallback = new Runnable() {
+ public void run() {
+ mReadyToRender = true;
+ if (!mAttached)
+ onAttachedToWindow();
+ }
+ };
+
+ public View getRootView() {
+ return mRootView;
+ }
+
+ private class Renderer implements GLSurfaceView.Renderer {
+ private final AwContents mAwContents;
+ private int mWidth = 0;
+ private int mHeight = 0;
+
+ Renderer(AwContents awContents) {
+ mAwContents = awContents;
+ }
+
+ @Override
+ public void onDrawFrame(GL10 gl) {
+ mAwContents.drawGLForTesting(mWidth, mHeight);
+ }
+
+ @Override
+ public void onSurfaceChanged(GL10 gl, int width, int height) {
+ gl.glViewport(0, 0, width, height);
+ gl.glScissor(0, 0, width, height);
+ mWidth = width;
+ mHeight = height;
+ Log.i("XX", "onSurfaceChanged " + width + "x" + height);
+ }
+
+ @Override
+ public void onSurfaceCreated(GL10 gl, EGLConfig config) {
+ Log.i("XX", "onSurfaceCreated");
+ }
+ }
+
public AwTestContainerView(Context context) {
super(context);
- mNativeGLDelegate = new NativeGLDelegate();
+ mSurfaceView = new GLSurfaceView(context) {
+ @Override
+ public void surfaceChanged(
+ SurfaceHolder holder, int format, int w, int h) {
+ mSurfaceChangedCallback.run();
+ super.surfaceChanged(holder, format, w, h);
+ }
+ };
+ mRootView = new ViewGroup(context) {
+ @Override
+ public void onLayout(boolean changed, int left, int top, int right, int bottom) {
+ for (int i = 0; i < getChildCount(); i++) {
+ final View child = getChildAt(i);
+ final int count = getChildCount();
+ final int leftPos = getPaddingLeft();
+ final int rightPos = right - left - getPaddingRight();
+ final int parentTop = getPaddingTop();
+ final int parentBottom = bottom - top - getPaddingBottom();
+ child.layout(leftPos, parentTop, rightPos, parentBottom);
+ }
+ }
+ };
+ mRootView.addView(this);
+ mRootView.addView(mSurfaceView,
no sievers 2014/07/22 20:53:18 you can also call 'addView' instead of 'mRootView.
+ new FrameLayout.LayoutParams(
+ FrameLayout.LayoutParams.MATCH_PARENT,
+ FrameLayout.LayoutParams.MATCH_PARENT));
+ mNativeGLDelegate = new NativeGLDelegate(mSurfaceView);
mInternalAccessDelegate = new InternalAccessAdapter();
setOverScrollMode(View.OVER_SCROLL_ALWAYS);
setFocusable(true);
@@ -43,6 +127,14 @@ public class AwTestContainerView extends FrameLayout {
public void initialize(AwContents awContents) {
mAwContents = awContents;
+ Log.i("XX", "setRenderer");
+ mSurfaceView.setEGLContextClientVersion(2); // GLES2
+ mSurfaceView.getHolder().setFormat(PixelFormat.OPAQUE);
+ mSurfaceView.setPreserveEGLContextOnPause(true);
+ mSurfaceView.setRenderer(new Renderer(awContents));
+ mSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
+// mSurfaceView.setBackgroundColor(Color.WHITE);
+ mSurfaceView.forceLayout();
}
public ContentViewCore getContentViewCore() {
@@ -66,6 +158,18 @@ public class AwTestContainerView extends FrameLayout {
}
@Override
+ protected void onLayout(boolean changed,int left, int top, int right, int bottom) {
+ final View child = getChildAt(0);
+ if (child != null) {
+ final int width = child.getMeasuredWidth();
+ final int height = child.getMeasuredHeight();
+ Log.i("XX", "onLayoutVG " + width + "x" + height + " " +
+ left + "," + top + "," + right + "," + bottom);
+ child.layout(0, 0, right - left, bottom - top);
+ }
+ }
+
+ @Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mAwContents.onConfigurationChanged(newConfig);
@@ -74,7 +178,11 @@ public class AwTestContainerView extends FrameLayout {
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
- mAwContents.onAttachedToWindow();
+ Log.i("XX", "onAttachedToWindow " + mReadyToRender);
+ if (mReadyToRender == true) {
+ mAwContents.onAttachedToWindow();
+ mAttached = false;
+ }
}
@Override
@@ -107,6 +215,7 @@ public class AwTestContainerView extends FrameLayout {
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
mAwContents.onMeasure(widthMeasureSpec, heightMeasureSpec);
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
@Override
@@ -184,10 +293,18 @@ public class AwTestContainerView extends FrameLayout {
}
private static class NativeGLDelegate implements AwContents.NativeGLDelegate {
+ private final GLSurfaceView mSurfaceView;
+
+ NativeGLDelegate(GLSurfaceView surfaceView) {
+ mSurfaceView = surfaceView;
+ }
+
@Override
public boolean requestDrawGL(Canvas canvas, boolean waitForCompletion,
View containerview) {
- return false;
+ Log.i("XX", "requestRender");
+ mSurfaceView.requestRender();
+ return true;
}
@Override

Powered by Google App Engine
This is Rietveld 408576698