From 0b8606266c1afc69cbeb73acda67c85d87943318 Mon Sep 17 00:00:00 2001 From: Derek Sollenberger Date: Wed, 25 Mar 2015 10:08:30 -0400 Subject: [PATCH] Fix DrawFilter's usage in HWUI. Also add additional compile time checks to ensure that the Java and Skia APIs remain in sync. bug:19890753 Change-Id: I8503cacf2859307e3f480a78603f9f05901b58cc --- core/jni/android/graphics/Paint.cpp | 10 ++++++++++ libs/hwui/DisplayListRenderer.cpp | 2 +- libs/hwui/DisplayListRenderer.h | 3 ++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/core/jni/android/graphics/Paint.cpp b/core/jni/android/graphics/Paint.cpp index f0131b4c74ad6..4b43de3e6d3f4 100644 --- a/core/jni/android/graphics/Paint.cpp +++ b/core/jni/android/graphics/Paint.cpp @@ -101,6 +101,16 @@ public: } static jlong init(JNIEnv* env, jobject clazz) { + SK_COMPILE_ASSERT(1 << 0 == SkPaint::kAntiAlias_Flag, paint_flags_mismatch); + SK_COMPILE_ASSERT(1 << 2 == SkPaint::kDither_Flag, paint_flags_mismatch); + SK_COMPILE_ASSERT(1 << 3 == SkPaint::kUnderlineText_Flag, paint_flags_mismatch); + SK_COMPILE_ASSERT(1 << 4 == SkPaint::kStrikeThruText_Flag, paint_flags_mismatch); + SK_COMPILE_ASSERT(1 << 5 == SkPaint::kFakeBoldText_Flag, paint_flags_mismatch); + SK_COMPILE_ASSERT(1 << 6 == SkPaint::kLinearText_Flag, paint_flags_mismatch); + SK_COMPILE_ASSERT(1 << 7 == SkPaint::kSubpixelText_Flag, paint_flags_mismatch); + SK_COMPILE_ASSERT(1 << 8 == SkPaint::kDevKernText_Flag, paint_flags_mismatch); + SK_COMPILE_ASSERT(1 << 10 == SkPaint::kEmbeddedBitmapText_Flag, paint_flags_mismatch); + Paint* obj = new Paint(); defaultSettingsForAndroid(obj); return reinterpret_cast(obj); diff --git a/libs/hwui/DisplayListRenderer.cpp b/libs/hwui/DisplayListRenderer.cpp index 2a673f4bc6fc7..8757e15006b77 100644 --- a/libs/hwui/DisplayListRenderer.cpp +++ b/libs/hwui/DisplayListRenderer.cpp @@ -484,7 +484,7 @@ void DisplayListRenderer::drawRects(const float* rects, int count, const SkPaint } void DisplayListRenderer::setDrawFilter(SkDrawFilter* filter) { - mDrawFilter.reset(filter); + mDrawFilter.reset(SkSafeRef(filter)); } void DisplayListRenderer::insertReorderBarrier(bool enableReorder) { diff --git a/libs/hwui/DisplayListRenderer.h b/libs/hwui/DisplayListRenderer.h index 48ecd698bd916..53fd1adbeb14d 100644 --- a/libs/hwui/DisplayListRenderer.h +++ b/libs/hwui/DisplayListRenderer.h @@ -296,8 +296,9 @@ private: // so that we don't need to modify the paint every time we access it. SkTLazy filteredPaint; if (mDrawFilter.get()) { - paint = filteredPaint.init(); + filteredPaint.set(*paint); mDrawFilter->filter(filteredPaint.get(), SkDrawFilter::kPaint_Type); + paint = filteredPaint.get(); } // compute the hash key for the paint and check the cache.