diff options
author | Romain Guy <romainguy@google.com> | 2011-06-24 13:20:23 -0700 |
---|---|---|
committer | Romain Guy <romainguy@google.com> | 2011-06-24 13:20:23 -0700 |
commit | 02ccac69fd1c0a03c24c5f3ace0ad4bed337b1fd (patch) | |
tree | 60531b505178d4fb169abc83567d5d8db4f14ed0 | |
parent | b0b1b11b965598cb8fb724e636ebb58a77d437b5 (diff) | |
download | frameworks_base-02ccac69fd1c0a03c24c5f3ace0ad4bed337b1fd.zip frameworks_base-02ccac69fd1c0a03c24c5f3ace0ad4bed337b1fd.tar.gz frameworks_base-02ccac69fd1c0a03c24c5f3ace0ad4bed337b1fd.tar.bz2 |
Code cleanup
Change-Id: I64c346004e0adf9a776d0315534d4fe445f0c0ca
-rw-r--r-- | api/current.txt | 1 | ||||
-rw-r--r-- | core/java/android/view/GLES20Layer.java | 8 | ||||
-rw-r--r-- | core/java/android/view/GLES20TextureLayer.java | 2 | ||||
-rw-r--r-- | core/java/android/view/HardwareLayer.java | 30 | ||||
-rw-r--r-- | core/java/android/view/HardwareRenderer.java | 70 | ||||
-rw-r--r-- | core/java/android/view/TextureView.java | 4 | ||||
-rw-r--r-- | core/java/android/view/View.java | 17 | ||||
-rw-r--r-- | core/java/android/view/ViewAncestor.java | 10 | ||||
-rw-r--r-- | libs/hwui/Caches.cpp | 2 | ||||
-rw-r--r-- | tests/HwAccelerationTest/AndroidManifest.xml | 9 | ||||
-rw-r--r-- | tests/HwAccelerationTest/src/com/android/test/hwui/OpaqueActivity.java | 62 |
11 files changed, 137 insertions, 78 deletions
diff --git a/api/current.txt b/api/current.txt index 19557f5..2ad044e 100644 --- a/api/current.txt +++ b/api/current.txt @@ -22055,6 +22055,7 @@ package android.view { method protected boolean verifyDrawable(android.graphics.drawable.Drawable); method public boolean willNotCacheDrawing(); method public boolean willNotDraw(); + field public static android.util.Property ALPHA; field public static final int DRAWING_CACHE_QUALITY_AUTO = 0; // 0x0 field public static final int DRAWING_CACHE_QUALITY_HIGH = 1048576; // 0x100000 field public static final int DRAWING_CACHE_QUALITY_LOW = 524288; // 0x80000 diff --git a/core/java/android/view/GLES20Layer.java b/core/java/android/view/GLES20Layer.java index 69dfc2b..a491a0b 100644 --- a/core/java/android/view/GLES20Layer.java +++ b/core/java/android/view/GLES20Layer.java @@ -42,9 +42,15 @@ abstract class GLES20Layer extends HardwareLayer { return mLayer; } + @Override boolean copyInto(Bitmap bitmap) { return GLES20Canvas.nCopyLayer(mLayer, bitmap.mNativeBitmap); - } + } + + @Override + void update(int width, int height, boolean isOpaque) { + super.update(width, height, isOpaque); + } @Override void destroy() { diff --git a/core/java/android/view/GLES20TextureLayer.java b/core/java/android/view/GLES20TextureLayer.java index 5ee292e..391d9f4 100644 --- a/core/java/android/view/GLES20TextureLayer.java +++ b/core/java/android/view/GLES20TextureLayer.java @@ -70,7 +70,9 @@ class GLES20TextureLayer extends GLES20Layer { return mSurface; } + @Override void update(int width, int height, boolean isOpaque) { + super.update(width, height, isOpaque); GLES20Canvas.nUpdateTextureLayer(mLayer, width, height, isOpaque, mSurface); } } diff --git a/core/java/android/view/HardwareLayer.java b/core/java/android/view/HardwareLayer.java index 86dec3f..dfb39ae 100644 --- a/core/java/android/view/HardwareLayer.java +++ b/core/java/android/view/HardwareLayer.java @@ -16,6 +16,7 @@ package android.view; +import android.graphics.Bitmap; import android.graphics.Canvas; /** @@ -34,7 +35,7 @@ abstract class HardwareLayer { int mWidth; int mHeight; - final boolean mOpaque; + boolean mOpaque; /** * Creates a new hardware layer with undefined dimensions. @@ -92,7 +93,7 @@ abstract class HardwareLayer { abstract boolean isValid(); /** - * Resizes the layer, if necessary, to be at least as large + * Resize the layer, if necessary, to be at least as large * as the supplied dimensions. * * @param width The new desired minimum width for this layer @@ -124,4 +125,29 @@ abstract class HardwareLayer { * @param currentCanvas */ abstract void end(Canvas currentCanvas); + + /** + * Copies this layer into the specified bitmap. + * + * @param bitmap The bitmap to copy they layer into + * + * @return True if the copy was successful, false otherwise + */ + abstract boolean copyInto(Bitmap bitmap); + + /** + * Update the layer's properties. This method should be used + * when the underlying storage is modified by an external entity. + * To change the underlying storage, use the {@link #resize(int, int)} + * method instead. + * + * @param width The new width of this layer + * @param height The new height of this layer + * @param isOpaque Whether this layer is opaque + */ + void update(int width, int height, boolean isOpaque) { + mWidth = width; + mHeight = height; + mOpaque = isOpaque; + } } diff --git a/core/java/android/view/HardwareRenderer.java b/core/java/android/view/HardwareRenderer.java index c6d011e..bbfb4c1 100644 --- a/core/java/android/view/HardwareRenderer.java +++ b/core/java/android/view/HardwareRenderer.java @@ -17,12 +17,11 @@ package android.view; -import android.graphics.Bitmap; import android.graphics.Paint; import android.graphics.Rect; import android.graphics.SurfaceTexture; -import android.os.*; -import android.util.EventLog; +import android.os.SystemClock; +import android.os.SystemProperties; import android.util.Log; import javax.microedition.khronos.egl.EGL10; @@ -199,26 +198,6 @@ public abstract class HardwareRenderer { abstract SurfaceTexture createSurfaceTexture(HardwareLayer layer); /** - * Updates the specified layer. - * - * @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, boolean isOpaque); - - /** - * Copies the content of the specified layer into the specified bitmap. - * - * @param layer The hardware layer to copy - * @param bitmap The bitmap to copy the layer into - * - * @return True if the copy was successful, false otherwise - */ - abstract boolean copyLayer(HardwareLayer layer, Bitmap bitmap); - - /** * Initializes the hardware renderer for the specified surface and setup the * renderer for drawing, if needed. This is invoked when the ViewAncestor has * potentially lost the hardware renderer. The hardware renderer should be @@ -342,6 +321,13 @@ public abstract class HardwareRenderer { } /** + * Indicates whether this renderer instance can track and update dirty regions. + */ + boolean hasDirtyRegions() { + return mDirtyRegions; + } + + /** * Return a string for the EGL error code, or the hex representation * if the error is unknown. * @@ -634,19 +620,14 @@ public abstract class HardwareRenderer { void draw(View view, View.AttachInfo attachInfo, HardwareDrawCallbacks callbacks, Rect dirty) { if (canDraw()) { - if (!mDirtyRegions) { + if (!hasDirtyRegions()) { dirty = null; } - - attachInfo.mDrawingTime = SystemClock.uptimeMillis(); attachInfo.mIgnoreDirtyState = true; + attachInfo.mDrawingTime = SystemClock.uptimeMillis(); + view.mPrivateFlags |= View.DRAWN; - long startTime; - if (ViewDebug.DEBUG_PROFILE_DRAWING) { - startTime = SystemClock.elapsedRealtime(); - } - final int surfaceState = checkCurrent(); if (surfaceState != SURFACE_STATE_ERROR) { // We had to change the current surface and/or context, redraw everything @@ -700,26 +681,9 @@ public abstract class HardwareRenderer { onPostDraw(); - if (ViewDebug.DEBUG_PROFILE_DRAWING) { - EventLog.writeEvent(60000, SystemClock.elapsedRealtime() - startTime); - } - attachInfo.mIgnoreDirtyState = false; - final long swapBuffersStartTime; - if (ViewDebug.DEBUG_LATENCY) { - swapBuffersStartTime = System.nanoTime(); - } - sEgl.eglSwapBuffers(sEglDisplay, mEglSurface); - - if (ViewDebug.DEBUG_LATENCY) { - long now = System.nanoTime(); - Log.d(LOG_TAG, "Latency: Spent " - + ((now - swapBuffersStartTime) * 0.000001f) - + "ms waiting for eglSwapBuffers()"); - } - checkEglErrors(); } } @@ -820,16 +784,6 @@ public abstract class HardwareRenderer { return ((GLES20TextureLayer) layer).getSurfaceTexture(); } - @Override - void updateTextureLayer(HardwareLayer layer, int width, int height, boolean isOpaque) { - ((GLES20TextureLayer) layer).update(width, height, isOpaque); - } - - @Override - boolean copyLayer(HardwareLayer layer, Bitmap bitmap) { - return ((GLES20Layer) layer).copyInto(bitmap); - } - static HardwareRenderer create(boolean translucent) { if (GLES20Canvas.isAvailable()) { return new Gl20Renderer(translucent); diff --git a/core/java/android/view/TextureView.java b/core/java/android/view/TextureView.java index de398eb..ab4aed3 100644 --- a/core/java/android/view/TextureView.java +++ b/core/java/android/view/TextureView.java @@ -317,7 +317,7 @@ public class TextureView extends View { return; } - mAttachInfo.mHardwareRenderer.updateTextureLayer(mLayer, getWidth(), getHeight(), mOpaque); + mLayer.update(getWidth(), getHeight(), mOpaque); if (mListener != null) { mListener.onSurfaceTextureUpdated(mSurface); @@ -402,7 +402,7 @@ public class TextureView extends View { */ public Bitmap getBitmap(Bitmap bitmap) { if (bitmap != null && isAvailable()) { - mAttachInfo.mHardwareRenderer.copyLayer(mLayer, bitmap); + mLayer.copyInto(bitmap); } return bitmap; } diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 8184643..f91aeb7 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -5121,12 +5121,7 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit mInputEventConsistencyVerifier.onTrackballEvent(event, 0); } - //Log.i("view", "view=" + this + ", " + event.toString()); - if (onTrackballEvent(event)) { - return true; - } - - return false; + return onTrackballEvent(event); } /** @@ -5221,6 +5216,7 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit break; } + //noinspection SimplifiableIfStatement if (mOnHoverListener != null && (mViewFlags & ENABLED_MASK) == ENABLED && mOnHoverListener.onHover(this, event)) { return true; @@ -5893,6 +5889,7 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit */ private boolean isHoverable() { final int viewFlags = mViewFlags; + //noinspection SimplifiableIfStatement if ((viewFlags & ENABLED_MASK) == DISABLED) { return false; } @@ -12847,7 +12844,7 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit * A Property wrapper around the <code>alpha</code> functionality handled by the * {@link View#setAlpha(float)} and {@link View#getAlpha()} methods. */ - static Property<View, Float> ALPHA = new FloatProperty<View>("alpha") { + public static Property<View, Float> ALPHA = new FloatProperty<View>("alpha") { @Override public void setValue(View object, float value) { object.setAlpha(value); @@ -13573,6 +13570,12 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit boolean mIgnoreDirtyState; /** + * This flag tracks when the mIgnoreDirtyState flag is set during draw(), + * to avoid clearing that flag prematurely. + */ + boolean mSetIgnoreDirtyState = false; + + /** * Indicates whether the view's window is currently in touch mode. */ boolean mInTouchMode; diff --git a/core/java/android/view/ViewAncestor.java b/core/java/android/view/ViewAncestor.java index ad660c1..e5d6d9f 100644 --- a/core/java/android/view/ViewAncestor.java +++ b/core/java/android/view/ViewAncestor.java @@ -288,10 +288,6 @@ public final class ViewAncestor extends Handler implements ViewParent, private final int mDensity; - // This flag tracks when the mIgnoreDirtyState flag is set during draw(), to avoid - // clearing that flag prematurely - private boolean mSetIgnoreDirtyState = false; - /** * Consistency verifier for debugging purposes. */ @@ -676,7 +672,7 @@ public final class ViewAncestor extends Handler implements ViewParent, } } if (!mDirty.isEmpty() && !mDirty.contains(dirty)) { - mSetIgnoreDirtyState = true; + mAttachInfo.mSetIgnoreDirtyState = true; mAttachInfo.mIgnoreDirtyState = true; } mDirty.union(dirty); @@ -1882,10 +1878,10 @@ public final class ViewAncestor extends Handler implements ViewParent, } canvas.setScreenDensity(scalingRequired ? DisplayMetrics.DENSITY_DEVICE : 0); - mSetIgnoreDirtyState = false; + mAttachInfo.mSetIgnoreDirtyState = false; mView.draw(canvas); } finally { - if (!mSetIgnoreDirtyState) { + if (!mAttachInfo.mSetIgnoreDirtyState) { // Only clear the flag if it was not set during the mView.draw() call mAttachInfo.mIgnoreDirtyState = false; } diff --git a/libs/hwui/Caches.cpp b/libs/hwui/Caches.cpp index b0d8cf9..563d7e4 100644 --- a/libs/hwui/Caches.cpp +++ b/libs/hwui/Caches.cpp @@ -57,7 +57,7 @@ Caches::Caches(): Singleton<Caches>(), blend(false), lastSrcMode(GL_ZERO), LOGD("Enabling debug mode %d", mDebugLevel); #if RENDER_LAYERS_AS_REGIONS - LOGD("Layers will be composited as regions"); + INIT_LOGD("Layers will be composited as regions"); #endif } diff --git a/tests/HwAccelerationTest/AndroidManifest.xml b/tests/HwAccelerationTest/AndroidManifest.xml index c650021..7aa0617 100644 --- a/tests/HwAccelerationTest/AndroidManifest.xml +++ b/tests/HwAccelerationTest/AndroidManifest.xml @@ -31,6 +31,15 @@ android:hardwareAccelerated="true"> <activity + android:name="OpaqueActivity" + android:label="_Opaque"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + + <activity android:name="GetBitmapActivity" android:label="_GetBitmap"> <intent-filter> diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/OpaqueActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/OpaqueActivity.java new file mode 100644 index 0000000..af45f29 --- /dev/null +++ b/tests/HwAccelerationTest/src/com/android/test/hwui/OpaqueActivity.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.test.hwui; + +import android.app.Activity; +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.PorterDuff; +import android.os.Bundle; +import android.util.Log; +import android.view.Gravity; +import android.view.View; +import android.widget.FrameLayout; + +@SuppressWarnings({"UnusedDeclaration"}) +public class OpaqueActivity extends Activity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + final OpaqueView view = new OpaqueView(this); + setContentView(view, new FrameLayout.LayoutParams(100, 100, Gravity.CENTER)); + } + + public static class OpaqueView extends View { + public OpaqueView(Context c) { + super(c); + setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + invalidate(); + Log.d("OpaqueView", "Invalidate"); + } + }); + } + + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + canvas.drawColor(0xffff0000, PorterDuff.Mode.SRC); + } + + @Override + public boolean isOpaque() { + return true; + } + } +} |