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
diff --git a/core/java/android/view/DisplayListCanvas.java b/core/java/android/view/DisplayListCanvas.java
index 3c21981..a68a193 100644
--- a/core/java/android/view/DisplayListCanvas.java
+++ b/core/java/android/view/DisplayListCanvas.java
@@ -48,13 +48,17 @@
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 @@
// 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 @@
///////////////////////////////////////////////////////////////////////////
@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 @@
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 236cfef..771856f 100644
--- a/core/java/android/view/RenderNode.java
+++ b/core/java/android/view/RenderNode.java
@@ -126,45 +126,6 @@
* @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 @@
* @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 @@
* @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 bb8ef83..71d509c 100644
--- a/core/jni/android_view_DisplayListCanvas.cpp
+++ b/core/jni/android_view_DisplayListCanvas.cpp
@@ -50,12 +50,6 @@
// 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 @@
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 @@
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 @@
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 @@
{ "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 7386637..30627bb 100644
--- a/graphics/java/android/graphics/Canvas.java
+++ b/graphics/java/android/graphics/Canvas.java
@@ -214,17 +214,6 @@
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 aeb1a3d..b96e555 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 @@
, mDeferredBarrierType(kBarrier_None)
, mHighContrastText(false)
, mRestoreSaveCount(-1) {
+ reset(width, height);
}
DisplayListCanvas::~DisplayListCanvas() {
@@ -48,27 +49,12 @@
"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 @@
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 4982cc9..04a65e3 100644
--- a/libs/hwui/DisplayListCanvas.h
+++ b/libs/hwui/DisplayListCanvas.h
@@ -62,28 +62,18 @@
*/
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 80d7029..64d9037 100644
--- a/libs/hwui/tests/main.cpp
+++ b/libs/hwui/tests/main.cpp
@@ -42,15 +42,12 @@
};
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;
}