diff options
| -rw-r--r-- | core/java/android/view/DisplayListCanvas.java | 14 | ||||
| -rw-r--r-- | core/jni/android_graphics_Canvas.cpp | 45 | ||||
| -rw-r--r-- | core/jni/android_view_DisplayListCanvas.cpp | 7 | ||||
| -rw-r--r-- | graphics/java/android/graphics/Canvas.java | 5 | ||||
| -rw-r--r-- | libs/hwui/Canvas.h | 3 | ||||
| -rw-r--r-- | libs/hwui/DisplayListCanvas.cpp | 38 | ||||
| -rw-r--r-- | libs/hwui/DisplayListCanvas.h | 19 | ||||
| -rw-r--r-- | libs/hwui/SkiaCanvas.cpp | 7 |
8 files changed, 64 insertions, 74 deletions
diff --git a/core/java/android/view/DisplayListCanvas.java b/core/java/android/view/DisplayListCanvas.java index ac98fa94975c..05fa45fc3ff2 100644 --- a/core/java/android/view/DisplayListCanvas.java +++ b/core/java/android/view/DisplayListCanvas.java @@ -147,25 +147,11 @@ public class DisplayListCanvas extends Canvas { private static native int nGetMaximumTextureWidth(); private static native int nGetMaximumTextureHeight(); - /** - * Returns the native OpenGLRenderer object. - */ - long getRenderer() { - return mNativeCanvasWrapper; - } - /////////////////////////////////////////////////////////////////////////// // Setup /////////////////////////////////////////////////////////////////////////// @Override - public void setHighContrastText(boolean highContrastText) { - nSetHighContrastText(mNativeCanvasWrapper, highContrastText); - } - - private static native void nSetHighContrastText(long renderer, boolean highContrastText); - - @Override public void insertReorderBarrier() { nInsertReorderBarrier(mNativeCanvasWrapper, true); } diff --git a/core/jni/android_graphics_Canvas.cpp b/core/jni/android_graphics_Canvas.cpp index 1f0145315fc1..43825adc7a80 100644 --- a/core/jni/android_graphics_Canvas.cpp +++ b/core/jni/android_graphics_Canvas.cpp @@ -69,6 +69,11 @@ static jint getHeight(JNIEnv*, jobject, jlong canvasHandle) { return static_cast<jint>(get_canvas(canvasHandle)->height()); } +static void setHighContrastText(JNIEnv*, jobject, jlong canvasHandle, jboolean highContrastText) { + Canvas* canvas = get_canvas(canvasHandle); + canvas->setHighContrastText(highContrastText); +} + static jint getSaveCount(JNIEnv*, jobject, jlong canvasHandle) { return static_cast<jint>(get_canvas(canvasHandle)->getSaveCount()); } @@ -430,6 +435,16 @@ static void drawBitmapMesh(JNIEnv* env, jobject, jlong canvasHandle, jobject jbi vertA.ptr(), colorA.ptr(), paint); } +static void simplifyPaint(int color, SkPaint* paint) { + paint->setColor(color); + paint->setShader(nullptr); + paint->setColorFilter(nullptr); + paint->setLooper(nullptr); + paint->setStrokeWidth(4 + 0.04 * paint->getTextSize()); + paint->setStrokeJoin(SkPaint::kRound_Join); + paint->setLooper(nullptr); +} + class DrawTextFunctor { public: DrawTextFunctor(const Layout& layout, Canvas* canvas, uint16_t* glyphs, float* pos, @@ -454,9 +469,32 @@ public: } size_t glyphCount = end - start; - canvas->drawText(glyphs + start, pos + (2 * start), glyphCount, paint, x, y, - bounds.mLeft, bounds.mTop, bounds.mRight, bounds.mBottom, - totalAdvance); + + if (CC_UNLIKELY(canvas->isHighContrastText())) { + // high contrast draw path + int color = paint.getColor(); + int channelSum = SkColorGetR(color) + SkColorGetG(color) + SkColorGetB(color); + bool darken = channelSum < (128 * 3); + + // outline + SkPaint outlinePaint(paint); + simplifyPaint(darken ? SK_ColorWHITE : SK_ColorBLACK, &outlinePaint); + outlinePaint.setStyle(SkPaint::kStrokeAndFill_Style); + canvas->drawText(glyphs + start, pos + (2 * start), glyphCount, outlinePaint, x, y, + bounds.mLeft, bounds.mTop, bounds.mRight, bounds.mBottom, totalAdvance); + + // inner + SkPaint innerPaint(paint); + simplifyPaint(darken ? SK_ColorBLACK : SK_ColorWHITE, &innerPaint); + innerPaint.setStyle(SkPaint::kFill_Style); + canvas->drawText(glyphs + start, pos + (2 * start), glyphCount, innerPaint, x, y, + bounds.mLeft, bounds.mTop, bounds.mRight, bounds.mBottom, totalAdvance); + } else { + // standard draw path + canvas->drawText(glyphs + start, pos + (2 * start), glyphCount, paint, x, y, + bounds.mLeft, bounds.mTop, bounds.mRight, bounds.mBottom, + totalAdvance); + } } private: const Layout& layout; @@ -679,6 +717,7 @@ static JNINativeMethod gMethods[] = { {"native_isOpaque","(J)Z", (void*) CanvasJNI::isOpaque}, {"native_getWidth","(J)I", (void*) CanvasJNI::getWidth}, {"native_getHeight","(J)I", (void*) CanvasJNI::getHeight}, + {"native_setHighContrastText","(JZ)V", (void*) CanvasJNI::setHighContrastText}, {"native_save","(JI)I", (void*) CanvasJNI::save}, {"native_saveLayer","(JFFFFJI)I", (void*) CanvasJNI::saveLayer}, {"native_saveLayerAlpha","(JFFFFII)I", (void*) CanvasJNI::saveLayerAlpha}, diff --git a/core/jni/android_view_DisplayListCanvas.cpp b/core/jni/android_view_DisplayListCanvas.cpp index 2c0e79046d73..2953db41f1a4 100644 --- a/core/jni/android_view_DisplayListCanvas.cpp +++ b/core/jni/android_view_DisplayListCanvas.cpp @@ -50,12 +50,6 @@ static struct { // Setup // ---------------------------------------------------------------------------- -static void android_view_DisplayListCanvas_setHighContrastText(JNIEnv* env, jobject clazz, - jlong rendererPtr, jboolean highContrastText) { - DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr); - renderer->setHighContrastText(highContrastText); -} - static void android_view_DisplayListCanvas_insertReorderBarrier(JNIEnv* env, jobject clazz, jlong rendererPtr, jboolean reorderEnable) { DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr); @@ -198,7 +192,6 @@ const char* const kClassPathName = "android/view/DisplayListCanvas"; static JNINativeMethod gMethods[] = { { "nIsAvailable", "()Z", (void*) android_view_DisplayListCanvas_isAvailable }, - { "nSetHighContrastText","(JZ)V", (void*) android_view_DisplayListCanvas_setHighContrastText }, { "nInsertReorderBarrier","(JZ)V", (void*) android_view_DisplayListCanvas_insertReorderBarrier }, { "nCallDrawGLFunction", "(JJ)V", (void*) android_view_DisplayListCanvas_callDrawGLFunction }, diff --git a/graphics/java/android/graphics/Canvas.java b/graphics/java/android/graphics/Canvas.java index 73caf683ff3c..7bcc7f903964 100644 --- a/graphics/java/android/graphics/Canvas.java +++ b/graphics/java/android/graphics/Canvas.java @@ -215,7 +215,9 @@ public class Canvas { } /** @hide */ - public void setHighContrastText(boolean highContrastText) {} + public void setHighContrastText(boolean highContrastText) { + native_setHighContrastText(mNativeCanvasWrapper, highContrastText); + } /** @hide */ public void insertReorderBarrier() {} @@ -1974,6 +1976,7 @@ public class Canvas { private static native void native_setBitmap(long canvasHandle, Bitmap bitmap); private static native boolean native_isOpaque(long canvasHandle); + private static native void native_setHighContrastText(long renderer, boolean highContrastText); private static native int native_getWidth(long canvasHandle); private static native int native_getHeight(long canvasHandle); diff --git a/libs/hwui/Canvas.h b/libs/hwui/Canvas.h index 116bc56bfe4d..a0b87f9cadb6 100644 --- a/libs/hwui/Canvas.h +++ b/libs/hwui/Canvas.h @@ -62,6 +62,9 @@ public: virtual int width() = 0; virtual int height() = 0; + virtual void setHighContrastText(bool highContrastText) = 0; + virtual bool isHighContrastText() = 0; + // ---------------------------------------------------------------------------- // Canvas state operations // ---------------------------------------------------------------------------- diff --git a/libs/hwui/DisplayListCanvas.cpp b/libs/hwui/DisplayListCanvas.cpp index af18e03c60a9..cc69d55cbfac 100644 --- a/libs/hwui/DisplayListCanvas.cpp +++ b/libs/hwui/DisplayListCanvas.cpp @@ -437,16 +437,6 @@ void DisplayListCanvas::drawPosText(const uint16_t* text, const float* positions addDrawOp(op); } -static void simplifyPaint(int color, SkPaint* paint) { - paint->setColor(color); - paint->setShader(nullptr); - paint->setColorFilter(nullptr); - paint->setLooper(nullptr); - paint->setStrokeWidth(4 + 0.04 * paint->getTextSize()); - paint->setStrokeJoin(SkPaint::kRound_Join); - paint->setLooper(nullptr); -} - void DisplayListCanvas::drawText(const uint16_t* glyphs, const float* positions, int count, const SkPaint& paint, float x, float y, float boundsLeft, float boundsTop, float boundsRight, float boundsBottom, @@ -459,31 +449,9 @@ void DisplayListCanvas::drawText(const uint16_t* glyphs, const float* positions, positions = refBuffer<float>(positions, count * 2); Rect bounds(boundsLeft, boundsTop, boundsRight, boundsBottom); - if (CC_UNLIKELY(mHighContrastText)) { - // high contrast draw path - int color = paint.getColor(); - int channelSum = SkColorGetR(color) + SkColorGetG(color) + SkColorGetB(color); - bool darken = channelSum < (128 * 3); - - // outline - SkPaint* outlinePaint = copyPaint(&paint); - simplifyPaint(darken ? SK_ColorWHITE : SK_ColorBLACK, outlinePaint); - outlinePaint->setStyle(SkPaint::kStrokeAndFill_Style); - addDrawOp(new (alloc()) DrawTextOp(text, bytesCount, count, - x, y, positions, outlinePaint, totalAdvance, bounds)); // bounds? - - // inner - SkPaint* innerPaint = copyPaint(&paint); - simplifyPaint(darken ? SK_ColorBLACK : SK_ColorWHITE, innerPaint); - innerPaint->setStyle(SkPaint::kFill_Style); - addDrawOp(new (alloc()) DrawTextOp(text, bytesCount, count, - x, y, positions, innerPaint, totalAdvance, bounds)); - } else { - // standard draw path - DrawOp* op = new (alloc()) DrawTextOp(text, bytesCount, count, - x, y, positions, refPaint(&paint), totalAdvance, bounds); - addDrawOp(op); - } + DrawOp* op = new (alloc()) DrawTextOp(text, bytesCount, count, + x, y, positions, refPaint(&paint), totalAdvance, bounds); + addDrawOp(op); } void DisplayListCanvas::drawRegion(const SkRegion& region, const SkPaint& paint) { diff --git a/libs/hwui/DisplayListCanvas.h b/libs/hwui/DisplayListCanvas.h index 6f2e2b50967e..efdf9ed336d9 100644 --- a/libs/hwui/DisplayListCanvas.h +++ b/libs/hwui/DisplayListCanvas.h @@ -101,10 +101,6 @@ public: // TODO: rename for consistency void callDrawGLFunction(Functor* functor); - void setHighContrastText(bool highContrastText) { - mHighContrastText = highContrastText; - } - // ---------------------------------------------------------------------------- // CanvasStateClient interface // ---------------------------------------------------------------------------- @@ -125,6 +121,11 @@ public: virtual int width() override { return mState.getWidth(); } virtual int height() override { return mState.getHeight(); } + virtual void setHighContrastText(bool highContrastText) override { + mHighContrastText = highContrastText; + } + virtual bool isHighContrastText() override { return mHighContrastText; } + // ---------------------------------------------------------------------------- // android/graphics/Canvas state operations // ---------------------------------------------------------------------------- @@ -304,16 +305,6 @@ private: return cachedPaint; } - inline SkPaint* copyPaint(const SkPaint* paint) { - if (!paint) return nullptr; - - SkPaint* returnPaint = new SkPaint(*paint); - std::unique_ptr<const SkPaint> copy(returnPaint); - mDisplayListData->paints.push_back(std::move(copy)); - - return returnPaint; - } - inline const SkRegion* refRegion(const SkRegion* region) { if (!region) { return region; diff --git a/libs/hwui/SkiaCanvas.cpp b/libs/hwui/SkiaCanvas.cpp index 971b53aaf198..77079b7bb788 100644 --- a/libs/hwui/SkiaCanvas.cpp +++ b/libs/hwui/SkiaCanvas.cpp @@ -55,6 +55,11 @@ public: virtual int width() override; virtual int height() override; + virtual void setHighContrastText(bool highContrastText) override { + mHighContrastText = highContrastText; + } + virtual bool isHighContrastText() override { return mHighContrastText; } + virtual int getSaveCount() const override; virtual int save(SkCanvas::SaveFlags flags) override; virtual void restore() override; @@ -135,6 +140,8 @@ private: SkCanvas::SaveFlags saveFlags; }; + bool mHighContrastText = false; + void recordPartialSave(SkCanvas::SaveFlags flags); void saveClipsForFrame(SkTArray<SkClipStack::Element>& clips, int frameSaveCount); void applyClips(const SkTArray<SkClipStack::Element>& clips); |