Skip to content

Commit 27bf191

Browse files
Romain GuyAndroid (Google) Code Review
authored andcommitted
Merge "Optimize display lists"
2 parents 1aabd12 + 04c9d8c commit 27bf191

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

core/java/android/view/View.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9992,8 +9992,6 @@ public DisplayList getDisplayList() {
99929992
// The dirty rect should always be null for a display list
99939993
canvas.onPreDraw(null);
99949994

9995-
final int restoreCount = canvas.save();
9996-
99979995
computeScroll();
99989996
canvas.translate(-mScrollX, -mScrollY);
99999997
mPrivateFlags |= DRAWN | DRAWING_CACHE_VALID;
@@ -10005,8 +10003,6 @@ public DisplayList getDisplayList() {
1000510003
} else {
1000610004
draw(canvas);
1000710005
}
10008-
10009-
canvas.restoreToCount(restoreCount);
1001010006
} finally {
1001110007
canvas.onPostDraw();
1001210008

libs/hwui/DisplayListRenderer.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ void DisplayList::initFromDisplayListRenderer(const DisplayListRenderer& recorde
194194

195195
void DisplayList::init() {
196196
mSize = 0;
197+
mIsRenderable = true;
197198
}
198199

199200
size_t DisplayList::getSize() {
@@ -892,7 +893,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level)
892893
// Base structure
893894
///////////////////////////////////////////////////////////////////////////////
894895

895-
DisplayListRenderer::DisplayListRenderer(): mWriter(MIN_WRITER_SIZE) {
896+
DisplayListRenderer::DisplayListRenderer(): mWriter(MIN_WRITER_SIZE), mHasDrawOps(false) {
896897
}
897898

898899
DisplayListRenderer::~DisplayListRenderer() {
@@ -926,6 +927,8 @@ void DisplayListRenderer::reset() {
926927
mPathMap.clear();
927928

928929
mMatrices.clear();
930+
931+
mHasDrawOps = false;
929932
}
930933

931934
///////////////////////////////////////////////////////////////////////////////
@@ -938,6 +941,7 @@ DisplayList* DisplayListRenderer::getDisplayList(DisplayList* displayList) {
938941
} else {
939942
displayList->initFromDisplayListRenderer(*this, true);
940943
}
944+
displayList->setRenderable(mHasDrawOps);
941945
return displayList;
942946
}
943947

@@ -982,7 +986,11 @@ int DisplayListRenderer::save(int flags) {
982986
}
983987

984988
void DisplayListRenderer::restore() {
985-
addOp(DisplayList::Restore);
989+
if (mRestoreSaveCount < 0) {
990+
addOp(DisplayList::Restore);
991+
} else {
992+
mRestoreSaveCount--;
993+
}
986994
OpenGLRenderer::restore();
987995
}
988996

libs/hwui/DisplayListRenderer.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class DisplayList {
6363
// IMPORTANT: Update the intialization of OP_NAMES in the .cpp file
6464
// when modifying this file
6565
enum Op {
66+
// Non-drawing operations
6667
Save = 0,
6768
Restore,
6869
RestoreToCount,
@@ -75,6 +76,7 @@ class DisplayList {
7576
SetMatrix,
7677
ConcatMatrix,
7778
ClipRect,
79+
// Drawing operations
7880
DrawDisplayList,
7981
DrawLayer,
8082
DrawBitmap,
@@ -113,6 +115,14 @@ class DisplayList {
113115

114116
static void outputLogBuffer(int fd);
115117

118+
void setRenderable(bool renderable) {
119+
mIsRenderable = renderable;
120+
}
121+
122+
bool isRenderable() const {
123+
return mIsRenderable;
124+
}
125+
116126
private:
117127
void init();
118128

@@ -207,6 +217,8 @@ class DisplayList {
207217
mutable SkFlattenableReadBuffer mReader;
208218

209219
size_t mSize;
220+
221+
bool mIsRenderable;
210222
};
211223

212224
///////////////////////////////////////////////////////////////////////////////
@@ -328,6 +340,7 @@ class DisplayListRenderer: public OpenGLRenderer {
328340
inline void addOp(DisplayList::Op drawOp) {
329341
insertRestoreToCount();
330342
mWriter.writeInt(drawOp);
343+
mHasDrawOps = mHasDrawOps || drawOp >= DisplayList::DrawDisplayList;
331344
}
332345

333346
inline void addInt(int value) {
@@ -479,6 +492,7 @@ class DisplayListRenderer: public OpenGLRenderer {
479492
SkWriter32 mWriter;
480493

481494
int mRestoreSaveCount;
495+
bool mHasDrawOps;
482496

483497
friend class DisplayList;
484498

libs/hwui/OpenGLRenderer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,7 @@ bool OpenGLRenderer::drawDisplayList(DisplayList* displayList, uint32_t width, u
12781278

12791279
// All the usual checks and setup operations (quickReject, setupDraw, etc.)
12801280
// will be performed by the display list itself
1281-
if (displayList) {
1281+
if (displayList && displayList->isRenderable()) {
12821282
return displayList->replay(*this, dirty, level);
12831283
}
12841284

0 commit comments

Comments
 (0)