diff options
author | Romain Guy <romainguy@google.com> | 2011-06-22 20:59:46 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-06-22 20:59:46 -0700 |
commit | c2e0a1f1cdd249694bf707a7bc066e7808c340d0 (patch) | |
tree | 4e6ae9e67ce039cf73d2878318ab982e95a1f6b7 /core | |
parent | b8a8c7a279c50276bddaab1f74bbba735de0b7c8 (diff) | |
parent | a9489274d67b540804aafb587a226f7c2ae4464d (diff) | |
download | frameworks_base-c2e0a1f1cdd249694bf707a7bc066e7808c340d0.zip frameworks_base-c2e0a1f1cdd249694bf707a7bc066e7808c340d0.tar.gz frameworks_base-c2e0a1f1cdd249694bf707a7bc066e7808c340d0.tar.bz2 |
Merge "Add the ability to specify the opacity of a TextureView"
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/view/GLES20Canvas.java | 5 | ||||
-rw-r--r-- | core/java/android/view/GLES20TextureLayer.java | 8 | ||||
-rw-r--r-- | core/java/android/view/HardwareRenderer.java | 15 | ||||
-rw-r--r-- | core/java/android/view/TextureView.java | 62 | ||||
-rw-r--r-- | core/java/android/view/View.java | 2 | ||||
-rw-r--r-- | core/java/android/view/ViewGroup.java | 5 | ||||
-rw-r--r-- | core/jni/android_view_GLES20Canvas.cpp | 12 |
7 files changed, 69 insertions, 40 deletions
diff --git a/core/java/android/view/GLES20Canvas.java b/core/java/android/view/GLES20Canvas.java index 5216c49..04f35dc 100644 --- a/core/java/android/view/GLES20Canvas.java +++ b/core/java/android/view/GLES20Canvas.java @@ -161,10 +161,11 @@ class GLES20Canvas extends HardwareCanvas { // Hardware layers /////////////////////////////////////////////////////////////////////////// - static native int nCreateTextureLayer(int[] layerInfo); + static native int nCreateTextureLayer(boolean opaque, int[] layerInfo); static native int nCreateLayer(int width, int height, boolean isOpaque, int[] layerInfo); static native void nResizeLayer(int layerId, int width, int height, int[] layerInfo); - static native void nUpdateTextureLayer(int layerId, int width, int height, SurfaceTexture surface); + static native void nUpdateTextureLayer(int layerId, int width, int height, boolean opaque, + SurfaceTexture surface); static native void nDestroyLayer(int layerId); static native void nDestroyLayerDeferred(int layerId); static native boolean nCopyLayer(int layerId, int bitmap); diff --git a/core/java/android/view/GLES20TextureLayer.java b/core/java/android/view/GLES20TextureLayer.java index 063eee7..3ac4459 100644 --- a/core/java/android/view/GLES20TextureLayer.java +++ b/core/java/android/view/GLES20TextureLayer.java @@ -28,9 +28,9 @@ class GLES20TextureLayer extends GLES20Layer { private int mTexture; private SurfaceTexture mSurface; - GLES20TextureLayer() { + GLES20TextureLayer(boolean isOpaque) { int[] layerInfo = new int[2]; - mLayer = GLES20Canvas.nCreateTextureLayer(layerInfo); + mLayer = GLES20Canvas.nCreateTextureLayer(isOpaque, layerInfo); if (mLayer != 0) { mTexture = layerInfo[0]; @@ -70,7 +70,7 @@ class GLES20TextureLayer extends GLES20Layer { return mSurface; } - void update(int width, int height) { - GLES20Canvas.nUpdateTextureLayer(mLayer, width, height, mSurface); + void update(int width, int height, boolean isOpaque) { + GLES20Canvas.nUpdateTextureLayer(mLayer, width, height, isOpaque, mSurface); } } diff --git a/core/java/android/view/HardwareRenderer.java b/core/java/android/view/HardwareRenderer.java index 5ceb12a..c6d011e 100644 --- a/core/java/android/view/HardwareRenderer.java +++ b/core/java/android/view/HardwareRenderer.java @@ -170,9 +170,11 @@ public abstract class HardwareRenderer { * Creates a new hardware layer. A hardware layer built by calling this * method will be treated as a texture layer, instead of as a render target. * + * @param isOpaque Whether the layer should be opaque or not + * * @return A hardware layer */ - abstract HardwareLayer createHardwareLayer(); + abstract HardwareLayer createHardwareLayer(boolean isOpaque); /** * Creates a new hardware layer. @@ -202,8 +204,9 @@ public abstract class HardwareRenderer { * @param layer The hardware layer to update * @param width The layer's width * @param height The layer's height + * @param isOpaque Whether the layer is opaque */ - abstract void updateTextureLayer(HardwareLayer layer, int width, int height); + abstract void updateTextureLayer(HardwareLayer layer, int width, int height, boolean isOpaque); /** * Copies the content of the specified layer into the specified bitmap. @@ -803,8 +806,8 @@ public abstract class HardwareRenderer { } @Override - HardwareLayer createHardwareLayer() { - return new GLES20TextureLayer(); + HardwareLayer createHardwareLayer(boolean isOpaque) { + return new GLES20TextureLayer(isOpaque); } @Override @@ -818,8 +821,8 @@ public abstract class HardwareRenderer { } @Override - void updateTextureLayer(HardwareLayer layer, int width, int height) { - ((GLES20TextureLayer) layer).update(width, height); + void updateTextureLayer(HardwareLayer layer, int width, int height, boolean isOpaque) { + ((GLES20TextureLayer) layer).update(width, height, isOpaque); } @Override diff --git a/core/java/android/view/TextureView.java b/core/java/android/view/TextureView.java index 2f598f4..51f6640 100644 --- a/core/java/android/view/TextureView.java +++ b/core/java/android/view/TextureView.java @@ -96,9 +96,14 @@ public class TextureView extends View { private SurfaceTexture mSurface; private SurfaceTextureListener mListener; - private final Object[] mLock = new Object[0]; - private boolean mUpdateLayer; + private boolean mOpaque = true; + private final Runnable mUpdateLayerAction = new Runnable() { + @Override + public void run() { + updateLayer(); + } + }; private SurfaceTexture.OnFrameAvailableListener mUpdateListener; /** @@ -143,6 +148,28 @@ public class TextureView extends View { mLayerPaint = new Paint(); } + /** + * {@inheritDoc} + */ + @Override + public boolean isOpaque() { + return mOpaque; + } + + /** + * Indicates whether the content of this TextureView is opaque. The + * content is assumed to be opaque by default. + * + * @param opaque True if the content of this TextureView is opaque, + * false otherwise + */ + public void setOpaque(boolean opaque) { + if (opaque != mOpaque) { + mOpaque = opaque; + updateLayer(); + } + } + @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); @@ -212,7 +239,6 @@ public class TextureView extends View { */ @Override public final void draw(Canvas canvas) { - super.draw(canvas); } /** @@ -229,8 +255,6 @@ public class TextureView extends View { protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); if (mSurface != null) { - // No need to synchronize here, we set update layer to false only on the UI thread - mUpdateLayer = true; nSetDefaultBufferSize(mSurface, getWidth(), getHeight()); if (mListener != null) { mListener.onSurfaceTextureSizeChanged(mSurface, getWidth(), getHeight()); @@ -245,7 +269,7 @@ public class TextureView extends View { } if (mLayer == null) { - mLayer = mAttachInfo.mHardwareRenderer.createHardwareLayer(); + mLayer = mAttachInfo.mHardwareRenderer.createHardwareLayer(mOpaque); mSurface = mAttachInfo.mHardwareRenderer.createSurfaceTexture(mLayer); nSetDefaultBufferSize(mSurface, getWidth(), getHeight()); @@ -254,10 +278,7 @@ public class TextureView extends View { public void onFrameAvailable(SurfaceTexture surfaceTexture) { // Per SurfaceTexture's documentation, the callback may be invoked // from an arbitrary thread - synchronized (mLock) { - mUpdateLayer = true; - postInvalidate(); - } + post(mUpdateLayerAction); } }; mSurface.setOnFrameAvailableListener(mUpdateListener); @@ -267,13 +288,6 @@ public class TextureView extends View { } } - synchronized (mLock) { - if (mUpdateLayer) { - mAttachInfo.mHardwareRenderer.updateTextureLayer(mLayer, getWidth(), getHeight()); - mUpdateLayer = false; - } - } - return mLayer; } @@ -287,15 +301,23 @@ public class TextureView extends View { // updates listener if (visibility == VISIBLE) { mSurface.setOnFrameAvailableListener(mUpdateListener); - // No need to synchronize here, we set update layer to false only on the UI thread - mUpdateLayer = true; - invalidate(); + updateLayer(); } else { mSurface.setOnFrameAvailableListener(null); } } } + private void updateLayer() { + if (mAttachInfo == null || mAttachInfo.mHardwareRenderer == null) { + return; + } + + mAttachInfo.mHardwareRenderer.updateTextureLayer(mLayer, getWidth(), getHeight(), mOpaque); + + invalidate(); + } + /** * <p>Returns a {@link android.graphics.Bitmap} representation of the content * of the associated surface texture. If the surface texture is not available, diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index f70ca90..8184643 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -9674,10 +9674,10 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit computeScroll(); canvas.translate(-mScrollX, -mScrollY); mPrivateFlags |= DRAWN | DRAWING_CACHE_VALID; + mPrivateFlags &= ~DIRTY_MASK; // Fast path for layouts with no backgrounds if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) { - mPrivateFlags &= ~DIRTY_MASK; dispatchDraw(canvas); } else { draw(canvas); diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java index e928f80..b9474e6 100644 --- a/core/java/android/view/ViewGroup.java +++ b/core/java/android/view/ViewGroup.java @@ -1233,6 +1233,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager /** * {@inheritDoc} */ + @SuppressWarnings({"ConstantConditions"}) @Override protected boolean dispatchHoverEvent(MotionEvent event) { final int action = event.getAction(); @@ -3876,8 +3877,10 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager if (!childMatrix.isIdentity()) { RectF boundingRect = attachInfo.mTmpTransformRect; boundingRect.set(dirty); + //boundingRect.inset(-0.5f, -0.5f); childMatrix.mapRect(boundingRect); - dirty.set((int) boundingRect.left, (int) boundingRect.top, + dirty.set((int) (boundingRect.left - 0.5f), + (int) (boundingRect.top - 0.5f), (int) (boundingRect.right + 0.5f), (int) (boundingRect.bottom + 0.5f)); } diff --git a/core/jni/android_view_GLES20Canvas.cpp b/core/jni/android_view_GLES20Canvas.cpp index 1699299..aff4394 100644 --- a/core/jni/android_view_GLES20Canvas.cpp +++ b/core/jni/android_view_GLES20Canvas.cpp @@ -608,8 +608,8 @@ static OpenGLRenderer* android_view_GLES20Canvas_createLayerRenderer(JNIEnv* env } static Layer* android_view_GLES20Canvas_createTextureLayer(JNIEnv* env, jobject clazz, - jintArray layerInfo) { - Layer* layer = LayerRenderer::createTextureLayer(); + jboolean isOpaque, jintArray layerInfo) { + Layer* layer = LayerRenderer::createTextureLayer(isOpaque); if (layer) { jint* storage = env->GetIntArrayElements(layerInfo, NULL); @@ -645,7 +645,7 @@ static void android_view_GLES20Canvas_resizeLayer(JNIEnv* env, jobject clazz, } static void android_view_GLES20Canvas_updateTextureLayer(JNIEnv* env, jobject clazz, - Layer* layer, jint width, jint height, jobject surface) { + Layer* layer, jint width, jint height, jboolean isOpaque, jobject surface) { float transform[16]; sp<SurfaceTexture> surfaceTexture(SurfaceTexture_getSurfaceTexture(env, surface)); @@ -655,7 +655,7 @@ static void android_view_GLES20Canvas_updateTextureLayer(JNIEnv* env, jobject cl surfaceTexture->getTransformMatrix(transform); GLenum renderTarget = surfaceTexture->getCurrentTextureTarget(); - LayerRenderer::updateTextureLayer(layer, width, height, renderTarget, transform); + LayerRenderer::updateTextureLayer(layer, width, height, isOpaque, renderTarget, transform); } static void android_view_GLES20Canvas_destroyLayer(JNIEnv* env, jobject clazz, Layer* layer) { @@ -797,8 +797,8 @@ static JNINativeMethod gMethods[] = { { "nCreateLayerRenderer", "(I)I", (void*) android_view_GLES20Canvas_createLayerRenderer }, { "nCreateLayer", "(IIZ[I)I", (void*) android_view_GLES20Canvas_createLayer }, { "nResizeLayer", "(III[I)V" , (void*) android_view_GLES20Canvas_resizeLayer }, - { "nCreateTextureLayer", "([I)I", (void*) android_view_GLES20Canvas_createTextureLayer }, - { "nUpdateTextureLayer", "(IIILandroid/graphics/SurfaceTexture;)V", + { "nCreateTextureLayer", "(Z[I)I", (void*) android_view_GLES20Canvas_createTextureLayer }, + { "nUpdateTextureLayer", "(IIIZLandroid/graphics/SurfaceTexture;)V", (void*) android_view_GLES20Canvas_updateTextureLayer }, { "nDestroyLayer", "(I)V", (void*) android_view_GLES20Canvas_destroyLayer }, { "nDestroyLayerDeferred", "(I)V", (void*) android_view_GLES20Canvas_destroyLayerDeferred }, |