diff options
| author | 2015-07-09 15:51:20 -0400 | |
|---|---|---|
| committer | 2015-07-10 19:32:30 +0000 | |
| commit | cc882b6518129a11fa007f8c9343e972f03607b4 (patch) | |
| tree | 6e1ec568b6096f8bd406df5c6317b85b69d399db | |
| parent | 99483dc800910ad321acd1717969c15d872c6531 (diff) | |
Remove unused functions and variables from DisplayListCanvas
This also moves some functions that are only called when creating/completing
a displayList into the appropriate constructors and endRecording calls.
Change-Id: I9f6add156d7f476a52766934af713b0f852c8dea
| -rw-r--r-- | core/java/android/view/DisplayListCanvas.java | 51 | ||||
| -rw-r--r-- | core/java/android/view/RenderNode.java | 46 | ||||
| -rw-r--r-- | core/jni/android_view_DisplayListCanvas.cpp | 43 | ||||
| -rw-r--r-- | graphics/java/android/graphics/Canvas.java | 11 | ||||
| -rw-r--r-- | libs/hwui/DisplayListCanvas.cpp | 42 | ||||
| -rw-r--r-- | libs/hwui/DisplayListCanvas.h | 16 | ||||
| -rw-r--r-- | libs/hwui/tests/main.cpp | 7 |
7 files changed, 45 insertions, 171 deletions
diff --git a/core/java/android/view/DisplayListCanvas.java b/core/java/android/view/DisplayListCanvas.java index 3c21981af192..a68a193d7931 100644 --- a/core/java/android/view/DisplayListCanvas.java +++ b/core/java/android/view/DisplayListCanvas.java @@ -48,13 +48,17 @@ public class DisplayListCanvas extends Canvas { private int mWidth; private int mHeight; - static DisplayListCanvas obtain(@NonNull RenderNode node) { + static DisplayListCanvas obtain(@NonNull RenderNode node, int width, int height) { if (node == null) throw new IllegalArgumentException("node cannot be null"); DisplayListCanvas canvas = sPool.acquire(); if (canvas == null) { - canvas = new DisplayListCanvas(); + canvas = new DisplayListCanvas(width, height); + } else { + nResetDisplayListCanvas(canvas.mNativeCanvasWrapper, width, height); } canvas.mNode = node; + canvas.mWidth = width; + canvas.mHeight = height; return canvas; } @@ -87,12 +91,13 @@ public class DisplayListCanvas extends Canvas { // Constructors /////////////////////////////////////////////////////////////////////////// - private DisplayListCanvas() { - super(nCreateDisplayListCanvas()); + private DisplayListCanvas(int width, int height) { + super(nCreateDisplayListCanvas(width, height)); mDensity = 0; // disable bitmap density scaling } - private static native long nCreateDisplayListCanvas(); + private static native long nCreateDisplayListCanvas(int width, int height); + private static native void nResetDisplayListCanvas(long canvas, int width, int height); /////////////////////////////////////////////////////////////////////////// // Canvas management @@ -154,17 +159,6 @@ public class DisplayListCanvas extends Canvas { /////////////////////////////////////////////////////////////////////////// @Override - public void setViewport(int width, int height) { - mWidth = width; - mHeight = height; - - nSetViewport(mNativeCanvasWrapper, width, height); - } - - private static native void nSetViewport(long renderer, - int width, int height); - - @Override public void setHighContrastText(boolean highContrastText) { nSetHighContrastText(mNativeCanvasWrapper, highContrastText); } @@ -183,31 +177,6 @@ public class DisplayListCanvas extends Canvas { private static native void nInsertReorderBarrier(long renderer, boolean enableReorder); - /** - * Invoked before any drawing operation is performed in this canvas. - * - * @param dirty The dirty rectangle to update, can be null. - */ - public void onPreDraw(Rect dirty) { - if (dirty != null) { - nPrepareDirty(mNativeCanvasWrapper, dirty.left, dirty.top, dirty.right, dirty.bottom); - } else { - nPrepare(mNativeCanvasWrapper); - } - } - - private static native void nPrepare(long renderer); - private static native void nPrepareDirty(long renderer, int left, int top, int right, int bottom); - - /** - * Invoked after all drawing operation have been performed. - */ - public void onPostDraw() { - nFinish(mNativeCanvasWrapper); - } - - private static native void nFinish(long renderer); - /////////////////////////////////////////////////////////////////////////// // Functor /////////////////////////////////////////////////////////////////////////// diff --git a/core/java/android/view/RenderNode.java b/core/java/android/view/RenderNode.java index 236cfefd9718..771856f7d320 100644 --- a/core/java/android/view/RenderNode.java +++ b/core/java/android/view/RenderNode.java @@ -126,45 +126,6 @@ import android.graphics.Rect; * @hide */ public class RenderNode { - /** - * Flag used when calling - * {@link DisplayListCanvas#drawRenderNode - * When this flag is set, draw operations lying outside of the bounds of the - * display list will be culled early. It is recommeneded to always set this - * flag. - */ - public static final int FLAG_CLIP_CHILDREN = 0x1; - - // NOTE: The STATUS_* values *must* match the enum in DrawGlInfo.h - - /** - * Indicates that the display list is done drawing. - * - * @see DisplayListCanvas#drawRenderNode(RenderNode, int) - */ - public static final int STATUS_DONE = 0x0; - - /** - * Indicates that the display list needs another drawing pass. - * - * @see DisplayListCanvas#drawRenderNode(RenderNode, int) - */ - public static final int STATUS_DRAW = 0x1; - - /** - * Indicates that the display list needs to re-execute its GL functors. - * - * @see DisplayListCanvas#drawRenderNode(RenderNode, int) - * @see DisplayListCanvas#callDrawGLFunction2(long) - */ - public static final int STATUS_INVOKE = 0x2; - - /** - * Indicates that the display list performed GL drawing operations. - * - * @see DisplayListCanvas#drawRenderNode(RenderNode, int) - */ - public static final int STATUS_DREW = 0x4; private boolean mValid; // Do not access directly unless you are ThreadedRenderer @@ -225,11 +186,7 @@ public class RenderNode { * @see #isValid() */ public DisplayListCanvas start(int width, int height) { - DisplayListCanvas canvas = DisplayListCanvas.obtain(this); - canvas.setViewport(width, height); - // The dirty rect should always be null for a display list - canvas.onPreDraw(null); - return canvas; + return DisplayListCanvas.obtain(this, width, height); } /** @@ -241,7 +198,6 @@ public class RenderNode { * @see #isValid() */ public void end(DisplayListCanvas canvas) { - canvas.onPostDraw(); long renderNodeData = canvas.finishRecording(); nSetDisplayListData(mNativeRenderNode, renderNodeData); canvas.recycle(); diff --git a/core/jni/android_view_DisplayListCanvas.cpp b/core/jni/android_view_DisplayListCanvas.cpp index bb8ef83c3f8c..71d509c9caae 100644 --- a/core/jni/android_view_DisplayListCanvas.cpp +++ b/core/jni/android_view_DisplayListCanvas.cpp @@ -50,12 +50,6 @@ static struct { // Setup // ---------------------------------------------------------------------------- -static void android_view_DisplayListCanvas_setViewport(JNIEnv* env, jobject clazz, - jlong rendererPtr, jint width, jint height) { - DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr); - renderer->setViewport(width, height); -} - static void android_view_DisplayListCanvas_setHighContrastText(JNIEnv* env, jobject clazz, jlong rendererPtr, jboolean highContrastText) { DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr); @@ -68,24 +62,6 @@ static void android_view_DisplayListCanvas_insertReorderBarrier(JNIEnv* env, job renderer->insertReorderBarrier(reorderEnable); } -static void android_view_DisplayListCanvas_prepare(JNIEnv* env, jobject clazz, - jlong rendererPtr) { - DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr); - renderer->prepare(); -} - -static void android_view_DisplayListCanvas_prepareDirty(JNIEnv* env, jobject clazz, - jlong rendererPtr, jint left, jint top, jint right, jint bottom) { - DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr); - renderer->prepareDirty(left, top, right, bottom); -} - -static void android_view_DisplayListCanvas_finish(JNIEnv* env, jobject clazz, - jlong rendererPtr) { - DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr); - renderer->finish(); -} - // ---------------------------------------------------------------------------- // Functor // ---------------------------------------------------------------------------- @@ -188,10 +164,18 @@ static jlong android_view_DisplayListCanvas_finishRecording(JNIEnv* env, return reinterpret_cast<jlong>(renderer->finishRecording()); } -static jlong android_view_DisplayListCanvas_createDisplayListCanvas(JNIEnv* env, jobject clazz) { - return reinterpret_cast<jlong>(new DisplayListCanvas); +static jlong android_view_DisplayListCanvas_createDisplayListCanvas(JNIEnv* env, jobject clazz, + jint width, jint height) { + return reinterpret_cast<jlong>(new DisplayListCanvas(width, height)); } +static void android_view_DisplayListCanvas_resetDisplayListCanvas(JNIEnv* env, jobject clazz, + jlong rendererPtr, jint width, jint height) { + DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr); + renderer->reset(width, height); +} + + static void android_view_DisplayListCanvas_drawRenderNode(JNIEnv* env, jobject clazz, jlong rendererPtr, jlong renderNodePtr) { DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr); @@ -244,12 +228,8 @@ const char* const kClassPathName = "android/view/DisplayListCanvas"; static JNINativeMethod gMethods[] = { { "nIsAvailable", "()Z", (void*) android_view_DisplayListCanvas_isAvailable }, - { "nSetViewport", "(JII)V", (void*) android_view_DisplayListCanvas_setViewport }, { "nSetHighContrastText","(JZ)V", (void*) android_view_DisplayListCanvas_setHighContrastText }, { "nInsertReorderBarrier","(JZ)V", (void*) android_view_DisplayListCanvas_insertReorderBarrier }, - { "nPrepare", "(J)V", (void*) android_view_DisplayListCanvas_prepare }, - { "nPrepareDirty", "(JIIII)V", (void*) android_view_DisplayListCanvas_prepareDirty }, - { "nFinish", "(J)V", (void*) android_view_DisplayListCanvas_finish }, { "nCallDrawGLFunction", "(JJ)V", (void*) android_view_DisplayListCanvas_callDrawGLFunction }, @@ -262,7 +242,8 @@ static JNINativeMethod gMethods[] = { { "nFinishRecording", "(J)J", (void*) android_view_DisplayListCanvas_finishRecording }, { "nDrawRenderNode", "(JJ)V", (void*) android_view_DisplayListCanvas_drawRenderNode }, - { "nCreateDisplayListCanvas", "()J", (void*) android_view_DisplayListCanvas_createDisplayListCanvas }, + { "nCreateDisplayListCanvas", "(II)J", (void*) android_view_DisplayListCanvas_createDisplayListCanvas }, + { "nResetDisplayListCanvas", "(JII)V", (void*) android_view_DisplayListCanvas_resetDisplayListCanvas }, { "nDrawLayer", "(JJFF)V", (void*) android_view_DisplayListCanvas_drawLayer }, diff --git a/graphics/java/android/graphics/Canvas.java b/graphics/java/android/graphics/Canvas.java index 73866370f300..30627bb93cc3 100644 --- a/graphics/java/android/graphics/Canvas.java +++ b/graphics/java/android/graphics/Canvas.java @@ -214,17 +214,6 @@ public class Canvas { mBitmap = bitmap; } - /** - * Set the viewport dimensions if this canvas is GL based. If it is not, - * this method is ignored and no exception is thrown. - * - * @param width The width of the viewport - * @param height The height of the viewport - * - * @hide - */ - public void setViewport(int width, int height) {} - /** @hide */ public void setHighContrastText(boolean highContrastText) {} diff --git a/libs/hwui/DisplayListCanvas.cpp b/libs/hwui/DisplayListCanvas.cpp index aeb1a3d0ae68..b96e5550beec 100644 --- a/libs/hwui/DisplayListCanvas.cpp +++ b/libs/hwui/DisplayListCanvas.cpp @@ -31,7 +31,7 @@ namespace android { namespace uirenderer { -DisplayListCanvas::DisplayListCanvas() +DisplayListCanvas::DisplayListCanvas(int width, int height) : mState(*this) , mResourceCache(ResourceCache::getInstance()) , mDisplayListData(nullptr) @@ -41,6 +41,7 @@ DisplayListCanvas::DisplayListCanvas() , mDeferredBarrierType(kBarrier_None) , mHighContrastText(false) , mRestoreSaveCount(-1) { + reset(width, height); } DisplayListCanvas::~DisplayListCanvas() { @@ -48,27 +49,12 @@ DisplayListCanvas::~DisplayListCanvas() { "Destroyed a DisplayListCanvas during a record!"); } -/////////////////////////////////////////////////////////////////////////////// -// Operations -/////////////////////////////////////////////////////////////////////////////// - -DisplayListData* DisplayListCanvas::finishRecording() { - mPaintMap.clear(); - mRegionMap.clear(); - mPathMap.clear(); - DisplayListData* data = mDisplayListData; - mDisplayListData = nullptr; - mSkiaCanvasProxy.reset(nullptr); - return data; -} - -void DisplayListCanvas::prepareDirty(float left, float top, - float right, float bottom) { - +void DisplayListCanvas::reset(int width, int height) { LOG_ALWAYS_FATAL_IF(mDisplayListData, "prepareDirty called a second time during a recording!"); mDisplayListData = new DisplayListData(); + mState.setViewport(width, height); mState.initializeSaveStack(0, 0, mState.getWidth(), mState.getHeight(), Vector3()); mDeferredBarrierType = kBarrier_InOrder; @@ -76,16 +62,22 @@ void DisplayListCanvas::prepareDirty(float left, float top, mRestoreSaveCount = -1; } -bool DisplayListCanvas::finish() { + +/////////////////////////////////////////////////////////////////////////////// +// Operations +/////////////////////////////////////////////////////////////////////////////// + +DisplayListData* DisplayListCanvas::finishRecording() { flushRestoreToCount(); flushTranslate(); - return false; -} - -void DisplayListCanvas::interrupt() { -} -void DisplayListCanvas::resume() { + mPaintMap.clear(); + mRegionMap.clear(); + mPathMap.clear(); + DisplayListData* data = mDisplayListData; + mDisplayListData = nullptr; + mSkiaCanvasProxy.reset(nullptr); + return data; } void DisplayListCanvas::callDrawGLFunction(Functor *functor) { diff --git a/libs/hwui/DisplayListCanvas.h b/libs/hwui/DisplayListCanvas.h index 4982cc919b5e..04a65e3951ba 100644 --- a/libs/hwui/DisplayListCanvas.h +++ b/libs/hwui/DisplayListCanvas.h @@ -62,28 +62,18 @@ class StateOp; */ class ANDROID_API DisplayListCanvas: public Canvas, public CanvasStateClient { public: - DisplayListCanvas(); + DisplayListCanvas(int width, int height); virtual ~DisplayListCanvas(); - void insertReorderBarrier(bool enableReorder); + void reset(int width, int height); DisplayListData* finishRecording(); // ---------------------------------------------------------------------------- -// HWUI Frame state operations -// ---------------------------------------------------------------------------- - - void prepareDirty(float left, float top, float right, float bottom); - void prepare() { prepareDirty(0.0f, 0.0f, width(), height()); } - bool finish(); - void interrupt(); - void resume(); - -// ---------------------------------------------------------------------------- // HWUI Canvas state operations // ---------------------------------------------------------------------------- - void setViewport(int width, int height) { mState.setViewport(width, height); } + void insertReorderBarrier(bool enableReorder); const Rect& getRenderTargetClipBounds() const { return mState.getRenderTargetClipBounds(); } diff --git a/libs/hwui/tests/main.cpp b/libs/hwui/tests/main.cpp index 80d7029857c4..64d90374dc55 100644 --- a/libs/hwui/tests/main.cpp +++ b/libs/hwui/tests/main.cpp @@ -42,15 +42,12 @@ public: }; static DisplayListCanvas* startRecording(RenderNode* node) { - DisplayListCanvas* renderer = new DisplayListCanvas(); - renderer->setViewport(node->stagingProperties().getWidth(), - node->stagingProperties().getHeight()); - renderer->prepare(); + DisplayListCanvas* renderer = new DisplayListCanvas( + node->stagingProperties().getWidth(), node->stagingProperties().getHeight()); return renderer; } static void endRecording(DisplayListCanvas* renderer, RenderNode* node) { - renderer->finish(); node->setStagingDisplayList(renderer->finishRecording()); delete renderer; } |