Skip to content

Commit 56485fe

Browse files
Romain GuyAndroid (Google) Code Review
authored andcommitted
Merge "Use a status_t return type for GL functors"
2 parents 994c26b + 6554943 commit 56485fe

File tree

11 files changed

+93
-46
lines changed

11 files changed

+93
-46
lines changed

core/java/android/view/DisplayList.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,30 @@ public abstract class DisplayList {
3535
*/
3636
public static final int FLAG_CLIP_CHILDREN = 0x1;
3737

38+
// NOTE: The STATUS_* values *must* match the enum in DrawGlInfo.h
39+
40+
/**
41+
* Indicates that the display list is done drawing.
42+
*
43+
* @see HardwareCanvas#drawDisplayList(DisplayList, int, int, android.graphics.Rect, int)
44+
*/
45+
public static final int STATUS_DONE = 0x0;
46+
47+
/**
48+
* Indicates that the display list needs another drawing pass.
49+
*
50+
* @see HardwareCanvas#drawDisplayList(DisplayList, int, int, android.graphics.Rect, int)
51+
*/
52+
public static final int STATUS_DRAW = 0x2;
53+
54+
/**
55+
* Indicates that the display list needs to re-execute its GL functors.
56+
*
57+
* @see HardwareCanvas#drawDisplayList(DisplayList, int, int, android.graphics.Rect, int)
58+
* @see HardwareCanvas#callDrawGLFunction(int)
59+
*/
60+
public static final int STATUS_INVOKE = 0x2;
61+
3862
/**
3963
* Starts recording the display list. All operations performed on the
4064
* returned canvas are recorded and stored in this display list.

core/java/android/view/GLES20Canvas.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,11 @@ public static int getStencilSize() {
296296
///////////////////////////////////////////////////////////////////////////
297297

298298
@Override
299-
public boolean callDrawGLFunction(int drawGLFunction) {
299+
public int callDrawGLFunction(int drawGLFunction) {
300300
return nCallDrawGLFunction(mRenderer, drawGLFunction);
301301
}
302302

303-
private static native boolean nCallDrawGLFunction(int renderer, int drawGLFunction);
303+
private static native int nCallDrawGLFunction(int renderer, int drawGLFunction);
304304

305305
///////////////////////////////////////////////////////////////////////////
306306
// Memory
@@ -394,13 +394,13 @@ static void setDisplayListName(int displayList, String name) {
394394
private static native void nSetDisplayListName(int displayList, String name);
395395

396396
@Override
397-
public boolean drawDisplayList(DisplayList displayList, int width, int height,
397+
public int drawDisplayList(DisplayList displayList, int width, int height,
398398
Rect dirty, int flags) {
399399
return nDrawDisplayList(mRenderer, ((GLES20DisplayList) displayList).getNativeDisplayList(),
400400
width, height, dirty, flags);
401401
}
402402

403-
private static native boolean nDrawDisplayList(int renderer, int displayList,
403+
private static native int nDrawDisplayList(int renderer, int displayList,
404404
int width, int height, Rect dirty, int flags);
405405

406406
@Override

core/java/android/view/HardwareCanvas.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ public void setBitmap(Bitmap bitmap) {
5959
* if this method returns true, can be null.
6060
* @param flags Optional flags about drawing, see {@link DisplayList} for
6161
* the possible flags.
62-
*
63-
* @return True if the content of the display list requires another
64-
* drawing pass (invalidate()), false otherwise
62+
*
63+
* @return One of {@link DisplayList#STATUS_DONE}, {@link DisplayList#STATUS_DRAW} or
64+
* {@link DisplayList#STATUS_INVOKE}
6565
*/
66-
public abstract boolean drawDisplayList(DisplayList displayList, int width, int height,
66+
public abstract int drawDisplayList(DisplayList displayList, int width, int height,
6767
Rect dirty, int flags);
6868

6969
/**
@@ -90,10 +90,12 @@ public abstract boolean drawDisplayList(DisplayList displayList, int width, int
9090
* This function may return true if an invalidation is needed after the call.
9191
*
9292
* @param drawGLFunction A native function pointer
93-
* @return true if an invalidate is needed after the call, false otherwise
93+
*
94+
* @return One of {@link DisplayList#STATUS_DONE}, {@link DisplayList#STATUS_DRAW} or
95+
* {@link DisplayList#STATUS_INVOKE}
9496
*/
95-
public boolean callDrawGLFunction(int drawGLFunction) {
97+
public int callDrawGLFunction(int drawGLFunction) {
9698
// Noop - this is done in the display list recorder subclass
97-
return false;
99+
return DisplayList.STATUS_DONE;
98100
}
99101
}

core/java/android/view/HardwareRenderer.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,6 @@ boolean draw(View view, View.AttachInfo attachInfo, HardwareDrawCallbacks callba
966966
Log.d("DLProperties", "getDisplayList():\t" +
967967
mProfileData[mProfileCurrentFrame]);
968968
}
969-
970969
}
971970

972971
if (displayList != null) {
@@ -975,7 +974,7 @@ boolean draw(View view, View.AttachInfo attachInfo, HardwareDrawCallbacks callba
975974
drawDisplayListStartTime = System.nanoTime();
976975
}
977976

978-
boolean invalidateNeeded = canvas.drawDisplayList(displayList,
977+
int status = canvas.drawDisplayList(displayList,
979978
view.getWidth(), view.getHeight(), mRedrawClip,
980979
DisplayList.FLAG_CLIP_CHILDREN);
981980

@@ -986,19 +985,18 @@ boolean draw(View view, View.AttachInfo attachInfo, HardwareDrawCallbacks callba
986985

987986
if (ViewDebug.DEBUG_LATENCY) {
988987
Log.d(ViewDebug.DEBUG_LATENCY_TAG, "- drawDisplayList() took " +
989-
total + "ms, invalidateNeeded=" +
990-
invalidateNeeded + ".");
988+
total + "ms, status=" + status);
991989
}
992990
}
993991

994-
if (invalidateNeeded) {
992+
if (status != DisplayList.STATUS_DONE) {
995993
if (mRedrawClip.isEmpty()) {
996994
attachInfo.mViewRootImpl.invalidate();
997995
} else {
998996
attachInfo.mViewRootImpl.invalidateChildInParent(
999997
null, mRedrawClip);
998+
mRedrawClip.setEmpty();
1000999
}
1001-
mRedrawClip.setEmpty();
10021000
}
10031001
} else {
10041002
// Shouldn't reach here

core/jni/android_view_GLES20Canvas.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,16 @@
2121
#include "jni.h"
2222
#include "GraphicsJNI.h"
2323
#include <nativehelper/JNIHelp.h>
24+
2425
#include <android_runtime/AndroidRuntime.h>
2526
#include <android_runtime/android_graphics_SurfaceTexture.h>
26-
#include <cutils/properties.h>
27+
#include <gui/SurfaceTexture.h>
28+
2729
#include <androidfw/ResourceTypes.h>
2830

29-
#include <gui/SurfaceTexture.h>
31+
#include <private/hwui/DrawGlInfo.h>
32+
33+
#include <cutils/properties.h>
3034

3135
#include <SkBitmap.h>
3236
#include <SkCanvas.h>
@@ -196,7 +200,7 @@ static jint android_view_GLES20Canvas_getStencilSize(JNIEnv* env, jobject clazz)
196200
// Functor
197201
// ----------------------------------------------------------------------------
198202

199-
static bool android_view_GLES20Canvas_callDrawGLFunction(JNIEnv* env, jobject clazz,
203+
static jint android_view_GLES20Canvas_callDrawGLFunction(JNIEnv* env, jobject clazz,
200204
OpenGLRenderer* renderer, Functor *functor) {
201205
android::uirenderer::Rect dirty;
202206
return renderer->callDrawGLFunction(functor, dirty);
@@ -682,16 +686,16 @@ static void android_view_GLES20Canvas_destroyDisplayList(JNIEnv* env,
682686
DisplayList::destroyDisplayListDeferred(displayList);
683687
}
684688

685-
static bool android_view_GLES20Canvas_drawDisplayList(JNIEnv* env,
689+
static jint android_view_GLES20Canvas_drawDisplayList(JNIEnv* env,
686690
jobject clazz, OpenGLRenderer* renderer, DisplayList* displayList,
687691
jint width, jint height, jobject dirty, jint flags) {
688692
android::uirenderer::Rect bounds;
689-
bool redraw = renderer->drawDisplayList(displayList, width, height, bounds, flags);
690-
if (redraw && dirty != NULL) {
693+
status_t status = renderer->drawDisplayList(displayList, width, height, bounds, flags);
694+
if (status != DrawGlInfo::kStatusDone && dirty != NULL) {
691695
env->CallVoidMethod(dirty, gRectClassInfo.set,
692696
int(bounds.left), int(bounds.top), int(bounds.right), int(bounds.bottom));
693697
}
694-
return redraw;
698+
return status;
695699
}
696700

697701
static void android_view_GLES20Canvas_outputDisplayList(JNIEnv* env,
@@ -865,7 +869,7 @@ static JNINativeMethod gMethods[] = {
865869

866870
{ "nGetStencilSize", "()I", (void*) android_view_GLES20Canvas_getStencilSize },
867871

868-
{ "nCallDrawGLFunction", "(II)Z",
872+
{ "nCallDrawGLFunction", "(II)I",
869873
(void*) android_view_GLES20Canvas_callDrawGLFunction },
870874

871875
{ "nSave", "(II)I", (void*) android_view_GLES20Canvas_save },
@@ -943,7 +947,7 @@ static JNINativeMethod gMethods[] = {
943947
{ "nGetDisplayListSize", "(I)I", (void*) android_view_GLES20Canvas_getDisplayListSize },
944948
{ "nSetDisplayListName", "(ILjava/lang/String;)V",
945949
(void*) android_view_GLES20Canvas_setDisplayListName },
946-
{ "nDrawDisplayList", "(IIIILandroid/graphics/Rect;I)Z",
950+
{ "nDrawDisplayList", "(IIIILandroid/graphics/Rect;I)I",
947951
(void*) android_view_GLES20Canvas_drawDisplayList },
948952

949953
{ "nCreateDisplayListRenderer", "()I", (void*) android_view_GLES20Canvas_createDisplayListRenderer },

include/private/hwui/DrawGlInfo.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,23 @@ struct DrawGlInfo {
4242
float dirtyTop;
4343
float dirtyRight;
4444
float dirtyBottom;
45+
46+
/**
47+
* Values used by OpenGL functors to tell the framework
48+
* what to do next.
49+
*/
50+
enum Status {
51+
// The functor is done
52+
kStatusDone,
53+
// The functor is requesting a redraw (the clip rect
54+
// used by the redraw is specified by DrawGlInfo.)
55+
// The rest of the UI might redraw too.
56+
kStatusDraw,
57+
// The functor needs to be invoked again but will
58+
// not redraw. Only the functor is invoked again
59+
// (unless another functor requests a redraw.)
60+
kStatusInvoke
61+
};
4562
}; // struct DrawGlInfo
4663

4764
}; // namespace uirenderer

libs/hwui/DisplayListRenderer.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
#include <SkCamera.h>
2020

21+
#include <private/hwui/DrawGlInfo.h>
22+
2123
#include "DisplayListLogBuffer.h"
2224
#include "DisplayListRenderer.h"
2325
#include "Caches.h"
@@ -796,9 +798,9 @@ void DisplayList::transformRect(float left, float top, float right, float bottom
796798
* in the output() function, since that function processes the same list of opcodes for the
797799
* purposes of logging display list info for a given view.
798800
*/
799-
bool DisplayList::replay(OpenGLRenderer& renderer, uint32_t width,
801+
status_t DisplayList::replay(OpenGLRenderer& renderer, uint32_t width,
800802
uint32_t height, Rect& dirty, int32_t flags, uint32_t level) {
801-
bool needsInvalidate = false;
803+
status_t drawGlStatus = 0;
802804
TextContainer text;
803805
mReader.rewind();
804806

@@ -843,7 +845,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, uint32_t width,
843845
Functor *functor = (Functor *) getInt();
844846
DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], functor);
845847
renderer.startMark("GL functor");
846-
needsInvalidate |= renderer.callDrawGLFunction(functor, dirty);
848+
drawGlStatus |= renderer.callDrawGLFunction(functor, dirty);
847849
renderer.endMark();
848850
}
849851
break;
@@ -950,7 +952,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, uint32_t width,
950952
int32_t flags = getInt();
951953
DISPLAY_LIST_LOGD("%s%s %p, %dx%d, 0x%x %d", (char*) indent, OP_NAMES[op],
952954
displayList, width, height, flags, level + 1);
953-
needsInvalidate |= renderer.drawDisplayList(displayList, width,
955+
drawGlStatus |= renderer.drawDisplayList(displayList, width,
954956
height, dirty, flags, level + 1);
955957
}
956958
break;
@@ -1233,8 +1235,8 @@ bool DisplayList::replay(OpenGLRenderer& renderer, uint32_t width,
12331235
renderer.endMark();
12341236

12351237
DISPLAY_LIST_LOGD("%sDone (%p, %s), returning %d", (char*) indent + 2, this, mName.string(),
1236-
needsInvalidate);
1237-
return needsInvalidate;
1238+
drawGlStatus);
1239+
return drawGlStatus;
12381240
}
12391241

12401242
///////////////////////////////////////////////////////////////////////////////
@@ -1321,11 +1323,11 @@ void DisplayListRenderer::interrupt() {
13211323
void DisplayListRenderer::resume() {
13221324
}
13231325

1324-
bool DisplayListRenderer::callDrawGLFunction(Functor *functor, Rect& dirty) {
1326+
status_t DisplayListRenderer::callDrawGLFunction(Functor *functor, Rect& dirty) {
13251327
// Ignore dirty during recording, it matters only when we replay
13261328
addOp(DisplayList::DrawGLFunction);
13271329
addInt((int) functor);
1328-
return false; // No invalidate needed at record-time
1330+
return DrawGlInfo::kStatusDone; // No invalidate needed at record-time
13291331
}
13301332

13311333
int DisplayListRenderer::save(int flags) {
@@ -1415,7 +1417,7 @@ bool DisplayListRenderer::clipRect(float left, float top, float right, float bot
14151417
return OpenGLRenderer::clipRect(left, top, right, bottom, op);
14161418
}
14171419

1418-
bool DisplayListRenderer::drawDisplayList(DisplayList* displayList,
1420+
status_t DisplayListRenderer::drawDisplayList(DisplayList* displayList,
14191421
uint32_t width, uint32_t height, Rect& dirty, int32_t flags, uint32_t level) {
14201422
// dirty is an out parameter and should not be recorded,
14211423
// it matters only when replaying the display list
@@ -1437,7 +1439,7 @@ bool DisplayListRenderer::drawDisplayList(DisplayList* displayList,
14371439
addSize(width, height);
14381440
addInt(flags);
14391441
addSkip(location);
1440-
return false;
1442+
return DrawGlInfo::kStatusDone;
14411443
}
14421444

14431445
void DisplayListRenderer::drawLayer(Layer* layer, float x, float y, SkPaint* paint) {

libs/hwui/DisplayListRenderer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class DisplayList {
137137

138138
void initFromDisplayListRenderer(const DisplayListRenderer& recorder, bool reusing = false);
139139

140-
bool replay(OpenGLRenderer& renderer, uint32_t width, uint32_t height,
140+
status_t replay(OpenGLRenderer& renderer, uint32_t width, uint32_t height,
141141
Rect& dirty, int32_t flags, uint32_t level = 0);
142142

143143
void output(OpenGLRenderer& renderer, uint32_t level = 0);
@@ -525,7 +525,7 @@ class DisplayListRenderer: public OpenGLRenderer {
525525
virtual void prepareDirty(float left, float top, float right, float bottom, bool opaque);
526526
virtual void finish();
527527

528-
virtual bool callDrawGLFunction(Functor *functor, Rect& dirty);
528+
virtual status_t callDrawGLFunction(Functor *functor, Rect& dirty);
529529

530530
virtual void interrupt();
531531
virtual void resume();
@@ -549,7 +549,7 @@ class DisplayListRenderer: public OpenGLRenderer {
549549

550550
virtual bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op);
551551

552-
virtual bool drawDisplayList(DisplayList* displayList, uint32_t width, uint32_t height,
552+
virtual status_t drawDisplayList(DisplayList* displayList, uint32_t width, uint32_t height,
553553
Rect& dirty, int32_t flags, uint32_t level = 0);
554554
virtual void drawLayer(Layer* layer, float x, float y, SkPaint* paint);
555555
virtual void drawBitmap(SkBitmap* bitmap, float left, float top, SkPaint* paint);

libs/hwui/FontRenderer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ void FontRenderer::checkInit() {
779779
// We store a string with letters in a rough frequency of occurrence
780780
mLatinPrecache = String16("eisarntolcdugpmhbyfvkwzxjq ");
781781
mLatinPrecache += String16("EISARNTOLCDUGPMHBYFVKWZXJQ");
782-
mLatinPrecache += String16(",.?!()-+@;:`'");
782+
mLatinPrecache += String16(",.?!()-+@;:'");
783783
mLatinPrecache += String16("0123456789");
784784

785785
mInitialized = true;

libs/hwui/OpenGLRenderer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ void OpenGLRenderer::resume() {
236236
glBlendEquation(GL_FUNC_ADD);
237237
}
238238

239-
bool OpenGLRenderer::callDrawGLFunction(Functor *functor, Rect& dirty) {
239+
status_t OpenGLRenderer::callDrawGLFunction(Functor *functor, Rect& dirty) {
240240
interrupt();
241241
if (mDirtyClip) {
242242
setScissorFromClip();
@@ -269,7 +269,7 @@ bool OpenGLRenderer::callDrawGLFunction(Functor *functor, Rect& dirty) {
269269
}
270270

271271
resume();
272-
return result != 0;
272+
return result;
273273
}
274274

275275
///////////////////////////////////////////////////////////////////////////////
@@ -1321,7 +1321,7 @@ void OpenGLRenderer::finishDrawTexture() {
13211321
// Drawing
13221322
///////////////////////////////////////////////////////////////////////////////
13231323

1324-
bool OpenGLRenderer::drawDisplayList(DisplayList* displayList, uint32_t width, uint32_t height,
1324+
status_t OpenGLRenderer::drawDisplayList(DisplayList* displayList, uint32_t width, uint32_t height,
13251325
Rect& dirty, int32_t flags, uint32_t level) {
13261326
float top = 0;
13271327
float left = 0;
@@ -1345,7 +1345,7 @@ bool OpenGLRenderer::drawDisplayList(DisplayList* displayList, uint32_t width, u
13451345
return displayList->replay(*this, width, height, dirty, flags, level);
13461346
}
13471347

1348-
return false;
1348+
return DrawGlInfo::kStatusDone;
13491349
}
13501350

13511351
void OpenGLRenderer::outputDisplayList(DisplayList* displayList, uint32_t level) {

0 commit comments

Comments
 (0)