Code cleanup
Change-Id: I64c346004e0adf9a776d0315534d4fe445f0c0ca
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 @@
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 @@
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 @@
int mWidth;
int mHeight;
- final boolean mOpaque;
+ boolean mOpaque;
/**
* Creates a new hardware layer with undefined dimensions.
@@ -92,7 +93,7 @@
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 @@
* @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 @@
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 @@
}
/**
+ * 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 @@
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 @@
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 @@
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 @@
return;
}
- mAttachInfo.mHardwareRenderer.updateTextureLayer(mLayer, getWidth(), getHeight(), mOpaque);
+ mLayer.update(getWidth(), getHeight(), mOpaque);
if (mListener != null) {
mListener.onSurfaceTextureUpdated(mSurface);
@@ -402,7 +402,7 @@
*/
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 @@
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 @@
break;
}
+ //noinspection SimplifiableIfStatement
if (mOnHoverListener != null && (mViewFlags & ENABLED_MASK) == ENABLED
&& mOnHoverListener.onHover(this, event)) {
return true;
@@ -5893,6 +5889,7 @@
*/
private boolean isHoverable() {
final int viewFlags = mViewFlags;
+ //noinspection SimplifiableIfStatement
if ((viewFlags & ENABLED_MASK) == DISABLED) {
return false;
}
@@ -12847,7 +12844,7 @@
* 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 @@
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 @@
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 @@
}
}
if (!mDirty.isEmpty() && !mDirty.contains(dirty)) {
- mSetIgnoreDirtyState = true;
+ mAttachInfo.mSetIgnoreDirtyState = true;
mAttachInfo.mIgnoreDirtyState = true;
}
mDirty.union(dirty);
@@ -1882,10 +1878,10 @@
}
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;
}