diff options
-rw-r--r-- | core/java/android/view/GLES20Canvas.java | 13 | ||||
-rw-r--r-- | core/jni/android_view_GLES20Canvas.cpp | 17 | ||||
-rw-r--r-- | docs/html/guide/topics/graphics/hardware-accel.jd | 3 | ||||
-rw-r--r-- | graphics/java/android/graphics/PaintFlagsDrawFilter.java | 6 | ||||
-rw-r--r-- | libs/hwui/DisplayListRenderer.cpp | 103 | ||||
-rw-r--r-- | libs/hwui/DisplayListRenderer.h | 9 | ||||
-rw-r--r-- | libs/hwui/OpenGLRenderer.cpp | 26 | ||||
-rw-r--r-- | libs/hwui/OpenGLRenderer.h | 11 | ||||
-rw-r--r-- | tests/HwAccelerationTest/AndroidManifest.xml | 9 | ||||
-rw-r--r-- | tests/HwAccelerationTest/src/com/android/test/hwui/PaintDrawFilterActivity.java | 64 |
10 files changed, 222 insertions, 39 deletions
diff --git a/core/java/android/view/GLES20Canvas.java b/core/java/android/view/GLES20Canvas.java index e06d661..c08a402 100644 --- a/core/java/android/view/GLES20Canvas.java +++ b/core/java/android/view/GLES20Canvas.java @@ -22,6 +22,7 @@ import android.graphics.ColorFilter; import android.graphics.DrawFilter; import android.graphics.Matrix; import android.graphics.Paint; +import android.graphics.PaintFlagsDrawFilter; import android.graphics.Path; import android.graphics.Picture; import android.graphics.PorterDuff; @@ -546,6 +547,7 @@ class GLES20Canvas extends HardwareCanvas { private static native void nSetMatrix(int renderer, int matrix); + @SuppressWarnings("deprecation") @Override public void getMatrix(Matrix matrix) { nGetMatrix(mRenderer, matrix.native_instance); @@ -658,8 +660,17 @@ class GLES20Canvas extends HardwareCanvas { @Override public void setDrawFilter(DrawFilter filter) { mFilter = filter; + if (filter == null) { + nResetPaintFilter(mRenderer); + } else if (filter instanceof PaintFlagsDrawFilter) { + PaintFlagsDrawFilter flagsFilter = (PaintFlagsDrawFilter) filter; + nSetupPaintFilter(mRenderer, flagsFilter.clearBits, flagsFilter.setBits); + } } + private static native void nResetPaintFilter(int renderer); + private static native void nSetupPaintFilter(int renderer, int clearBits, int setBits); + @Override public DrawFilter getDrawFilter() { return mFilter; @@ -968,6 +979,7 @@ class GLES20Canvas extends HardwareCanvas { private static native void nDrawPoints(int renderer, float[] points, int offset, int count, int paint); + @SuppressWarnings("deprecation") @Override public void drawPosText(char[] text, int index, int count, float[] pos, Paint paint) { if (index < 0 || index + count > text.length || count * 2 > pos.length) { @@ -985,6 +997,7 @@ class GLES20Canvas extends HardwareCanvas { private static native void nDrawPosText(int renderer, char[] text, int index, int count, float[] pos, int paint); + @SuppressWarnings("deprecation") @Override public void drawPosText(String text, float[] pos, Paint paint) { if (text.length() * 2 > pos.length) { diff --git a/core/jni/android_view_GLES20Canvas.cpp b/core/jni/android_view_GLES20Canvas.cpp index 064dcac..5811ddd 100644 --- a/core/jni/android_view_GLES20Canvas.cpp +++ b/core/jni/android_view_GLES20Canvas.cpp @@ -483,6 +483,20 @@ static void android_view_GLES20Canvas_setupShadow(JNIEnv* env, jobject clazz, } // ---------------------------------------------------------------------------- +// Draw filters +// ---------------------------------------------------------------------------- + +static void android_view_GLES20Canvas_setupPaintFilter(JNIEnv* env, jobject clazz, + OpenGLRenderer* renderer, jint clearBits, jint setBits) { + renderer->setupPaintFilter(clearBits, setBits); +} + +static void android_view_GLES20Canvas_resetPaintFilter(JNIEnv* env, jobject clazz, + OpenGLRenderer* renderer) { + renderer->resetPaintFilter(); +} + +// ---------------------------------------------------------------------------- // Text // ---------------------------------------------------------------------------- @@ -870,6 +884,9 @@ static JNINativeMethod gMethods[] = { { "nSetupColorFilter", "(II)V", (void*) android_view_GLES20Canvas_setupColorFilter }, { "nSetupShadow", "(IFFFI)V", (void*) android_view_GLES20Canvas_setupShadow }, + { "nSetupPaintFilter", "(III)V", (void*) android_view_GLES20Canvas_setupPaintFilter }, + { "nResetPaintFilter", "(I)V", (void*) android_view_GLES20Canvas_resetPaintFilter }, + { "nDrawText", "(I[CIIFFII)V", (void*) android_view_GLES20Canvas_drawTextArray }, { "nDrawText", "(ILjava/lang/String;IIFFII)V", (void*) android_view_GLES20Canvas_drawText }, diff --git a/docs/html/guide/topics/graphics/hardware-accel.jd b/docs/html/guide/topics/graphics/hardware-accel.jd index 3e24c5c..39ccbf4 100644 --- a/docs/html/guide/topics/graphics/hardware-accel.jd +++ b/docs/html/guide/topics/graphics/hardware-accel.jd @@ -325,9 +325,6 @@ changed.</li> <li>{@link android.graphics.Canvas#drawBitmapMesh drawBitmapMesh()}: colors array is ignored</li> - - <li>{@link android.graphics.Canvas#setDrawFilter setDrawFilter()}: can be set, but is - ignored</li> </ul> </li> diff --git a/graphics/java/android/graphics/PaintFlagsDrawFilter.java b/graphics/java/android/graphics/PaintFlagsDrawFilter.java index 0f0d03d..c833a12 100644 --- a/graphics/java/android/graphics/PaintFlagsDrawFilter.java +++ b/graphics/java/android/graphics/PaintFlagsDrawFilter.java @@ -17,6 +17,10 @@ package android.graphics; public class PaintFlagsDrawFilter extends DrawFilter { + /** @hide **/ + public final int clearBits; + /** @hide **/ + public final int setBits; /** * Subclass of DrawFilter that affects every paint by first clearing @@ -27,6 +31,8 @@ public class PaintFlagsDrawFilter extends DrawFilter { * @param setBits These bits will be set in the paint's flags */ public PaintFlagsDrawFilter(int clearBits, int setBits) { + this.clearBits = clearBits; + this.setBits = setBits; // our native constructor can return 0, if the specified bits // are effectively a no-op mNativeInt = nativeConstructor(clearBits, setBits); diff --git a/libs/hwui/DisplayListRenderer.cpp b/libs/hwui/DisplayListRenderer.cpp index 824ab4f..ee935e4 100644 --- a/libs/hwui/DisplayListRenderer.cpp +++ b/libs/hwui/DisplayListRenderer.cpp @@ -67,6 +67,8 @@ const char* DisplayList::OP_NAMES[] = { "SetupColorFilter", "ResetShadow", "SetupShadow", + "ResetPaintFilter", + "SetupPaintFilter", "DrawGLFunction" }; @@ -249,7 +251,7 @@ void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) { float f2 = getFloat(); float f3 = getFloat(); float f4 = getFloat(); - SkPaint* paint = getPaint(); + SkPaint* paint = getPaint(renderer); int flags = getInt(); ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p, 0x%x", (char*) indent, OP_NAMES[op], f1, f2, f3, f4, paint, flags); @@ -322,7 +324,7 @@ void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) { Layer* layer = (Layer*) getInt(); float x = getFloat(); float y = getFloat(); - SkPaint* paint = getPaint(); + SkPaint* paint = getPaint(renderer); ALOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op], layer, x, y, paint); } @@ -331,7 +333,7 @@ void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) { SkBitmap* bitmap = getBitmap(); float x = getFloat(); float y = getFloat(); - SkPaint* paint = getPaint(); + SkPaint* paint = getPaint(renderer); ALOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op], bitmap, x, y, paint); } @@ -339,7 +341,7 @@ void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) { case DrawBitmapMatrix: { SkBitmap* bitmap = getBitmap(); SkMatrix* matrix = getMatrix(); - SkPaint* paint = getPaint(); + SkPaint* paint = getPaint(renderer); ALOGD("%s%s %p, %p, %p", (char*) indent, OP_NAMES[op], bitmap, matrix, paint); } @@ -354,7 +356,7 @@ void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) { float f6 = getFloat(); float f7 = getFloat(); float f8 = getFloat(); - SkPaint* paint = getPaint(); + SkPaint* paint = getPaint(renderer); ALOGD("%s%s %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op], bitmap, f1, f2, f3, f4, f5, f6, f7, f8, paint); } @@ -368,7 +370,7 @@ void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) { float* vertices = getFloats(verticesCount); bool hasColors = getInt(); int* colors = hasColors ? getInts(colorsCount) : NULL; - SkPaint* paint = getPaint(); + SkPaint* paint = getPaint(renderer); ALOGD("%s%s", (char*) indent, OP_NAMES[op]); } break; @@ -387,7 +389,7 @@ void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) { float top = getFloat(); float right = getFloat(); float bottom = getFloat(); - SkPaint* paint = getPaint(); + SkPaint* paint = getPaint(renderer); ALOGD("%s%s %.2f, %.2f, %.2f, %.2f", (char*) indent, OP_NAMES[op], left, top, right, bottom); } @@ -403,7 +405,7 @@ void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) { float f2 = getFloat(); float f3 = getFloat(); float f4 = getFloat(); - SkPaint* paint = getPaint(); + SkPaint* paint = getPaint(renderer); ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op], f1, f2, f3, f4, paint); } @@ -415,7 +417,7 @@ void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) { float f4 = getFloat(); float f5 = getFloat(); float f6 = getFloat(); - SkPaint* paint = getPaint(); + SkPaint* paint = getPaint(renderer); ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, paint); } @@ -424,7 +426,7 @@ void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) { float f1 = getFloat(); float f2 = getFloat(); float f3 = getFloat(); - SkPaint* paint = getPaint(); + SkPaint* paint = getPaint(renderer); ALOGD("%s%s %.2f, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op], f1, f2, f3, paint); } @@ -434,7 +436,7 @@ void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) { float f2 = getFloat(); float f3 = getFloat(); float f4 = getFloat(); - SkPaint* paint = getPaint(); + SkPaint* paint = getPaint(renderer); ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op], f1, f2, f3, f4, paint); } @@ -447,28 +449,28 @@ void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) { float f5 = getFloat(); float f6 = getFloat(); int i1 = getInt(); - SkPaint* paint = getPaint(); + SkPaint* paint = getPaint(renderer); ALOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p", (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, i1, paint); } break; case DrawPath: { SkPath* path = getPath(); - SkPaint* paint = getPaint(); + SkPaint* paint = getPaint(renderer); ALOGD("%s%s %p, %p", (char*) indent, OP_NAMES[op], path, paint); } break; case DrawLines: { int count = 0; float* points = getFloats(count); - SkPaint* paint = getPaint(); + SkPaint* paint = getPaint(renderer); ALOGD("%s%s", (char*) indent, OP_NAMES[op]); } break; case DrawPoints: { int count = 0; float* points = getFloats(count); - SkPaint* paint = getPaint(); + SkPaint* paint = getPaint(renderer); ALOGD("%s%s", (char*) indent, OP_NAMES[op]); } break; @@ -477,7 +479,7 @@ void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) { int count = getInt(); float x = getFloat(); float y = getFloat(); - SkPaint* paint = getPaint(); + SkPaint* paint = getPaint(renderer); float length = getFloat(); ALOGD("%s%s %s, %d, %d, %.2f, %.2f, %p, %.2f", (char*) indent, OP_NAMES[op], text.text(), text.length(), count, x, y, paint, length); @@ -488,7 +490,7 @@ void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) { int count = getInt(); int positionsCount = 0; float* positions = getFloats(positionsCount); - SkPaint* paint = getPaint(); + SkPaint* paint = getPaint(renderer); ALOGD("%s%s %s, %d, %d, %p", (char*) indent, OP_NAMES[op], text.text(), text.length(), count, paint); } @@ -523,6 +525,16 @@ void DisplayList::output(OpenGLRenderer& renderer, uint32_t level) { radius, dx, dy, color); } break; + case ResetPaintFilter: { + ALOGD("%s%s", (char*) indent, OP_NAMES[op]); + } + break; + case SetupPaintFilter: { + int clearBits = getInt(); + int setBits = getInt(); + ALOGD("%s%s 0x%x, 0x%x", (char*) indent, OP_NAMES[op], clearBits, setBits); + } + break; default: ALOGD("Display List error: op not handled: %s%s", (char*) indent, OP_NAMES[op]); @@ -588,7 +600,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level) float f2 = getFloat(); float f3 = getFloat(); float f4 = getFloat(); - SkPaint* paint = getPaint(); + SkPaint* paint = getPaint(renderer); int flags = getInt(); DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p, 0x%x", (char*) indent, OP_NAMES[op], f1, f2, f3, f4, paint, flags); @@ -671,7 +683,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level) Layer* layer = (Layer*) getInt(); float x = getFloat(); float y = getFloat(); - SkPaint* paint = getPaint(); + SkPaint* paint = getPaint(renderer); DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op], layer, x, y, paint); renderer.drawLayer(layer, x, y, paint); @@ -681,7 +693,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level) SkBitmap* bitmap = getBitmap(); float x = getFloat(); float y = getFloat(); - SkPaint* paint = getPaint(); + SkPaint* paint = getPaint(renderer); DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op], bitmap, x, y, paint); renderer.drawBitmap(bitmap, x, y, paint); @@ -690,7 +702,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level) case DrawBitmapMatrix: { SkBitmap* bitmap = getBitmap(); SkMatrix* matrix = getMatrix(); - SkPaint* paint = getPaint(); + SkPaint* paint = getPaint(renderer); DISPLAY_LIST_LOGD("%s%s %p, %p, %p", (char*) indent, OP_NAMES[op], bitmap, matrix, paint); renderer.drawBitmap(bitmap, matrix, paint); @@ -706,7 +718,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level) float f6 = getFloat(); float f7 = getFloat(); float f8 = getFloat(); - SkPaint* paint = getPaint(); + SkPaint* paint = getPaint(renderer); DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op], bitmap, f1, f2, f3, f4, f5, f6, f7, f8, paint); renderer.drawBitmap(bitmap, f1, f2, f3, f4, f5, f6, f7, f8, paint); @@ -722,7 +734,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level) float* vertices = getFloats(verticesCount); bool hasColors = getInt(); int* colors = hasColors ? getInts(colorsCount) : NULL; - SkPaint* paint = getPaint(); + SkPaint* paint = getPaint(renderer); DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]); renderer.drawBitmapMesh(bitmap, meshWidth, meshHeight, vertices, colors, paint); @@ -746,7 +758,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level) float top = getFloat(); float right = getFloat(); float bottom = getFloat(); - SkPaint* paint = getPaint(); + SkPaint* paint = getPaint(renderer); DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]); renderer.drawPatch(bitmap, xDivs, yDivs, colors, xDivsCount, yDivsCount, @@ -765,7 +777,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level) float f2 = getFloat(); float f3 = getFloat(); float f4 = getFloat(); - SkPaint* paint = getPaint(); + SkPaint* paint = getPaint(renderer); DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op], f1, f2, f3, f4, paint); renderer.drawRect(f1, f2, f3, f4, paint); @@ -778,7 +790,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level) float f4 = getFloat(); float f5 = getFloat(); float f6 = getFloat(); - SkPaint* paint = getPaint(); + SkPaint* paint = getPaint(renderer); DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, paint); renderer.drawRoundRect(f1, f2, f3, f4, f5, f6, paint); @@ -788,7 +800,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level) float f1 = getFloat(); float f2 = getFloat(); float f3 = getFloat(); - SkPaint* paint = getPaint(); + SkPaint* paint = getPaint(renderer); DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op], f1, f2, f3, paint); renderer.drawCircle(f1, f2, f3, paint); @@ -799,7 +811,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level) float f2 = getFloat(); float f3 = getFloat(); float f4 = getFloat(); - SkPaint* paint = getPaint(); + SkPaint* paint = getPaint(renderer); DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op], f1, f2, f3, f4, paint); renderer.drawOval(f1, f2, f3, f4, paint); @@ -813,7 +825,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level) float f5 = getFloat(); float f6 = getFloat(); int i1 = getInt(); - SkPaint* paint = getPaint(); + SkPaint* paint = getPaint(renderer); DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p", (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, i1, paint); renderer.drawArc(f1, f2, f3, f4, f5, f6, i1 == 1, paint); @@ -821,7 +833,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level) break; case DrawPath: { SkPath* path = getPath(); - SkPaint* paint = getPaint(); + SkPaint* paint = getPaint(renderer); DISPLAY_LIST_LOGD("%s%s %p, %p", (char*) indent, OP_NAMES[op], path, paint); renderer.drawPath(path, paint); } @@ -829,7 +841,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level) case DrawLines: { int count = 0; float* points = getFloats(count); - SkPaint* paint = getPaint(); + SkPaint* paint = getPaint(renderer); DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]); renderer.drawLines(points, count, paint); } @@ -837,7 +849,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level) case DrawPoints: { int count = 0; float* points = getFloats(count); - SkPaint* paint = getPaint(); + SkPaint* paint = getPaint(renderer); DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]); renderer.drawPoints(points, count, paint); } @@ -847,7 +859,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level) int count = getInt(); float x = getFloat(); float y = getFloat(); - SkPaint* paint = getPaint(); + SkPaint* paint = getPaint(renderer); float length = getFloat(); DISPLAY_LIST_LOGD("%s%s %s, %d, %d, %.2f, %.2f, %p, %.2f", (char*) indent, OP_NAMES[op], text.text(), text.length(), count, x, y, paint, length); @@ -859,7 +871,7 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level) int count = getInt(); int positionsCount = 0; float* positions = getFloats(positionsCount); - SkPaint* paint = getPaint(); + SkPaint* paint = getPaint(renderer); DISPLAY_LIST_LOGD("%s%s %s, %d, %d, %p", (char*) indent, OP_NAMES[op], text.text(), text.length(), count, paint); renderer.drawPosText(text.text(), text.length(), count, positions, paint); @@ -902,6 +914,19 @@ bool DisplayList::replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level) renderer.setupShadow(radius, dx, dy, color); } break; + case ResetPaintFilter: { + DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]); + renderer.resetPaintFilter(); + } + break; + case SetupPaintFilter: { + int clearBits = getInt(); + int setBits = getInt(); + DISPLAY_LIST_LOGD("%s%s 0x%x, 0x%x", (char*) indent, OP_NAMES[op], + clearBits, setBits); + renderer.setupPaintFilter(clearBits, setBits); + } + break; default: DISPLAY_LIST_LOGD("Display List error: op not handled: %s%s", (char*) indent, OP_NAMES[op]); @@ -1277,5 +1302,15 @@ void DisplayListRenderer::setupShadow(float radius, float dx, float dy, int colo addInt(color); } +void DisplayListRenderer::resetPaintFilter() { + addOp(DisplayList::ResetPaintFilter); +} + +void DisplayListRenderer::setupPaintFilter(int clearBits, int setBits) { + addOp(DisplayList::SetupPaintFilter); + addInt(clearBits); + addInt(setBits); +} + }; // namespace uirenderer }; // namespace android diff --git a/libs/hwui/DisplayListRenderer.h b/libs/hwui/DisplayListRenderer.h index 422184e..6fe4205 100644 --- a/libs/hwui/DisplayListRenderer.h +++ b/libs/hwui/DisplayListRenderer.h @@ -103,6 +103,8 @@ public: SetupColorFilter, ResetShadow, SetupShadow, + ResetPaintFilter, + SetupPaintFilter, DrawGLFunction, }; @@ -177,8 +179,8 @@ private: return (SkPath*) getInt(); } - SkPaint* getPaint() { - return (SkPaint*) getInt(); + SkPaint* getPaint(OpenGLRenderer& renderer) { + return renderer.filterPaint((SkPaint*) getInt()); } DisplayList* getDisplayList() { @@ -304,6 +306,9 @@ public: virtual void resetShadow(); virtual void setupShadow(float radius, float dx, float dy, int color); + virtual void resetPaintFilter(); + virtual void setupPaintFilter(int clearBits, int setBits); + ANDROID_API void reset(); const SkWriter32& writeStream() const { diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp index 786a4f1..cc0e05e 100644 --- a/libs/hwui/OpenGLRenderer.cpp +++ b/libs/hwui/OpenGLRenderer.cpp @@ -111,6 +111,7 @@ OpenGLRenderer::OpenGLRenderer(): mCaches(Caches::getInstance()) { mShader = NULL; mColorFilter = NULL; mHasShadow = false; + mHasDrawFilter = false; memcpy(mMeshVertices, gMeshVertices, sizeof(gMeshVertices)); @@ -2399,6 +2400,31 @@ void OpenGLRenderer::setupShadow(float radius, float dx, float dy, int color) { } /////////////////////////////////////////////////////////////////////////////// +// Draw filters +/////////////////////////////////////////////////////////////////////////////// + +void OpenGLRenderer::resetPaintFilter() { + mHasDrawFilter = false; +} + +void OpenGLRenderer::setupPaintFilter(int clearBits, int setBits) { + mHasDrawFilter = true; + mPaintFilterClearBits = clearBits & SkPaint::kAllFlags; + mPaintFilterSetBits = setBits & SkPaint::kAllFlags; +} + +SkPaint* OpenGLRenderer::filterPaint(SkPaint* paint) { + if (!mHasDrawFilter || !paint) return paint; + + uint32_t flags = paint->getFlags(); + + mFilteredPaint = *paint; + mFilteredPaint.setFlags((flags & ~mPaintFilterClearBits) | mPaintFilterSetBits); + + return &mFilteredPaint; +} + +/////////////////////////////////////////////////////////////////////////////// // Drawing implementation /////////////////////////////////////////////////////////////////////////////// diff --git a/libs/hwui/OpenGLRenderer.h b/libs/hwui/OpenGLRenderer.h index a9cda47..ae355bb 100644 --- a/libs/hwui/OpenGLRenderer.h +++ b/libs/hwui/OpenGLRenderer.h @@ -136,6 +136,11 @@ public: virtual void resetShadow(); virtual void setupShadow(float radius, float dx, float dy, int color); + virtual void resetPaintFilter(); + virtual void setupPaintFilter(int clearBits, int setBits); + + SkPaint* filterPaint(SkPaint* paint); + protected: /** * Compose the layer defined in the current snapshot with the layer @@ -581,6 +586,12 @@ private: float mShadowDy; int mShadowColor; + // Draw filters + bool mHasDrawFilter; + int mPaintFilterClearBits; + int mPaintFilterSetBits; + SkPaint mFilteredPaint; + // Various caches Caches& mCaches; diff --git a/tests/HwAccelerationTest/AndroidManifest.xml b/tests/HwAccelerationTest/AndroidManifest.xml index 112c606..5bbcce3 100644 --- a/tests/HwAccelerationTest/AndroidManifest.xml +++ b/tests/HwAccelerationTest/AndroidManifest.xml @@ -31,6 +31,15 @@ android:hardwareAccelerated="true"> <activity + android:name="PaintDrawFilterActivity" + android:label="_DrawFilter"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + + <activity android:name="DisplayListLayersActivity" android:label="__DisplayListLayers"> <intent-filter> diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/PaintDrawFilterActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/PaintDrawFilterActivity.java new file mode 100644 index 0000000..8523272 --- /dev/null +++ b/tests/HwAccelerationTest/src/com/android/test/hwui/PaintDrawFilterActivity.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.test.hwui; + +import android.app.Activity; +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.PaintFlagsDrawFilter; +import android.os.Bundle; +import android.view.View; + +@SuppressWarnings({"UnusedDeclaration"}) +public class PaintDrawFilterActivity extends Activity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setContentView(new CustomTextView(this)); + } + + static class CustomTextView extends View { + private final Paint mMediumPaint; + private final PaintFlagsDrawFilter mDrawFilter; + + CustomTextView(Context c) { + super(c); + + mMediumPaint = new Paint(); + mMediumPaint.setAntiAlias(true); + mMediumPaint.setColor(0xff000000); + mMediumPaint.setFakeBoldText(true); + mMediumPaint.setTextSize(24.0f); + + mDrawFilter = new PaintFlagsDrawFilter( + Paint.FAKE_BOLD_TEXT_FLAG, Paint.UNDERLINE_TEXT_FLAG); + } + + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + canvas.drawRGB(255, 255, 255); + + canvas.setDrawFilter(null); + canvas.drawText("Hello OpenGL renderer!", 100, 120, mMediumPaint); + canvas.setDrawFilter(mDrawFilter); + canvas.drawText("Hello OpenGL renderer!", 100, 220, mMediumPaint); + } + } +} |