Merge "Optimizing display lists by referencing pointers to resources instead of copying them"

This commit is contained in:
Chet Haase
2010-10-21 13:29:26 -07:00
committed by Android (Google) Code Review
25 changed files with 560 additions and 271 deletions

View File

@@ -23,7 +23,7 @@ package android.animation;
public interface TimeInterpolator {
/**
* Maps a value representing the elapsed fraciton of an animation to a value that represents
* Maps a value representing the elapsed fraction of an animation to a value that represents
* the interpolated fraction. This interpolated value is then multiplied by the change in
* value of an animation to derive the animated value at the current elapsed animation time.
*

View File

@@ -523,7 +523,6 @@ public class ValueAnimator extends Animator {
for (int i = 0; i < numValues; ++i) {
mValues[i].init();
}
mCurrentIteration = 0;
mInitialized = true;
}
}
@@ -933,6 +932,7 @@ public class ValueAnimator extends Animator {
// This sets the initial value of the animation, prior to actually starting it running
setCurrentPlayTime(getCurrentPlayTime());
}
mCurrentIteration = 0;
mPlayingState = STOPPED;
mStartedDelay = false;
sPendingAnimations.add(this);

View File

@@ -38,12 +38,6 @@ abstract class DisplayList {
*/
abstract void end();
/**
* Frees resources taken by this display list. This method must be called
* before releasing all references.
*/
abstract void destroy();
/**
* Indicates whether this display list can be replayed or not.
*

View File

@@ -34,6 +34,11 @@ import android.text.GraphicsOperations;
import android.text.SpannableString;
import android.text.SpannedString;
import android.text.TextUtils;
import android.util.Finalizers;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
/**
* An implementation of Canvas on top of OpenGL ES 2.0.
@@ -84,22 +89,35 @@ class GLES20Canvas extends HardwareCanvas {
if (mRenderer == 0) {
throw new IllegalStateException("Could not create GLES20Canvas renderer");
} else {
new CanvasFinalizer(this);
}
}
private native int nCreateRenderer();
private native int nCreateDisplayListRenderer();
@Override
public synchronized void destroy() {
if (mRenderer != 0) {
private static native void nDestroyRenderer(int renderer);
private static class CanvasFinalizer extends Finalizers.ReclaimableReference<GLES20Canvas> {
private static final Set<CanvasFinalizer> sFinalizers = Collections.synchronizedSet(
new HashSet<CanvasFinalizer>());
private int mRenderer;
CanvasFinalizer(GLES20Canvas canvas) {
super(canvas, Finalizers.getQueue());
mRenderer = canvas.mRenderer;
sFinalizers.add(this);
}
@Override
public void reclaim() {
nDestroyRenderer(mRenderer);
mRenderer = 0;
sFinalizers.remove(this);
}
}
private native void nDestroyRenderer(int renderer);
///////////////////////////////////////////////////////////////////////////
// Canvas management
///////////////////////////////////////////////////////////////////////////
@@ -178,11 +196,11 @@ class GLES20Canvas extends HardwareCanvas {
private native int nCreateDisplayList(int renderer);
void destroyDisplayList(int displayList) {
static void destroyDisplayList(int displayList) {
nDestroyDisplayList(displayList);
}
private native void nDestroyDisplayList(int displayList);
private static native void nDestroyDisplayList(int displayList);
@Override
public void drawDisplayList(DisplayList displayList) {

View File

@@ -16,6 +16,12 @@
package android.view;
import android.util.Finalizers;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
/**
* An implementation of display list for OpenGL ES 2.0.
*/
@@ -33,8 +39,6 @@ class GLES20DisplayList extends DisplayList {
throw new IllegalStateException("Recording has already started");
}
destroyCanvas();
mCanvas = new GLES20Canvas(true, true);
mStarted = true;
mRecorded = false;
@@ -42,16 +46,6 @@ class GLES20DisplayList extends DisplayList {
return mCanvas;
}
private void destroyCanvas() {
if (mCanvas != null) {
mCanvas.destroyDisplayList(mNativeDisplayList);
mCanvas.destroy();
mCanvas = null;
mNativeDisplayList = 0;
}
}
@Override
void end() {
if (mCanvas != null) {
@@ -59,16 +53,31 @@ class GLES20DisplayList extends DisplayList {
mRecorded = true;
mNativeDisplayList = mCanvas.getDisplayList();
new DisplayListFinalizer(this);
}
}
@Override
void destroy() {
destroyCanvas();
}
@Override
boolean isReady() {
return !mStarted && mRecorded;
}
private static class DisplayListFinalizer extends Finalizers.ReclaimableReference<DisplayList> {
private static final Set<DisplayListFinalizer> sFinalizers = Collections.synchronizedSet(
new HashSet<DisplayListFinalizer>());
private int mNativeDisplayList;
DisplayListFinalizer(GLES20DisplayList displayList) {
super(displayList, Finalizers.getQueue());
mNativeDisplayList = displayList.mNativeDisplayList;
sFinalizers.add(this);
}
@Override
public void reclaim() {
GLES20Canvas.destroyDisplayList(mNativeDisplayList);
sFinalizers.remove(this);
}
}
}

View File

@@ -33,14 +33,6 @@ abstract class HardwareCanvas extends Canvas {
throw new UnsupportedOperationException();
}
/**
* This method <strong>must</strong> be called before releasing a
* reference to a hardware canvas. This method is responsible for
* freeing native resources associated with the hardware. Not
* invoking this method properly can result in memory leaks.
*/
public abstract void destroy();
/**
* Invoked before any drawing operation is performed in this canvas.
*/

View File

@@ -414,7 +414,6 @@ public abstract class HardwareRenderer {
@Override
void destroy(boolean full) {
if (full && mCanvas != null) {
mCanvas.destroy();
mCanvas = null;
}

View File

@@ -7417,7 +7417,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
if ((mViewFlags & WILL_NOT_CACHE_DRAWING) == WILL_NOT_CACHE_DRAWING) {
return null;
}
if (mAttachInfo == null || mAttachInfo.mHardwareRenderer == null) {
return null;
}
@@ -7425,10 +7424,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
if ((mViewFlags & DRAWING_CACHE_ENABLED) == DRAWING_CACHE_ENABLED &&
((mPrivateFlags & DRAWING_CACHE_VALID) == 0 || mDisplayList == null)) {
if (mDisplayList != null) {
mDisplayList.destroy();
}
mDisplayList = mAttachInfo.mHardwareRenderer.createDisplayList();
final HardwareCanvas canvas = mDisplayList.start();
@@ -7456,8 +7451,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
canvas.onPostDraw();
mDisplayList.end();
canvas.destroy();
}
}
@@ -7532,7 +7525,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
mUnscaledDrawingCache = null;
}
if (mDisplayList != null) {
mDisplayList.destroy();
mDisplayList = null;
}
}

View File

@@ -1700,10 +1700,10 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
}
return false;
}
/**
* {@inheritDoc}
*
*
* @hide
*/
@Override
@@ -1715,10 +1715,10 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
children[i].dispatchStartTemporaryDetach();
}
}
/**
* {@inheritDoc}
*
*
* @hide
*/
@Override
@@ -1915,7 +1915,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
if (skipChildren) {
for (int i = 0; i < count; i++) {
getChildAt(i).setVisibility(visibilities[i]);
}
}
}
return b;
@@ -2045,7 +2045,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
*
* @param i The current iteration.
* @return The index of the child to draw this iteration.
*
*
* @see #setChildrenDrawingOrderEnabled(boolean)
* @see #isChildrenDrawingOrderEnabled()
*/
@@ -2186,7 +2186,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
(child.mPrivateFlags & DRAW_ANIMATION) == 0) {
return more;
}
float alpha = child.getAlpha();
// Bail out early if the view does not need to be drawn
if (alpha <= ViewConfiguration.ALPHA_THRESHOLD && (child.mPrivateFlags & ALPHA_SET) == 0 &&
@@ -2360,7 +2360,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
final View[] children = mChildren;
final int count = mChildrenCount;
for (int i = 0; i < count; i++) {
children[i].setSelected(selected);
}
}