Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 03b3e236 authored by Leon Scroggins III's avatar Leon Scroggins III
Browse files

Restore Paint#nSetColor(@ColorInt)

Bug: 127580253
Test: CtsGraphicsTestCases
Perf: systrace

Restored with a partial revert of "Add Paint#get(ShadowLayer)ColorLong"
(commit 6ee41101).

The original CL combined the @ColorInt and @ColorLong version for
simplicity, but required doing extra work for the @ColorInt version.
Separating them back out speeds it up at the cost of more code.
Using systrace I see the following stats:

Duration:
(w/o this change)       (w/ this change)
avg:    0.020 ms        0.001 ms
max:    9.141 ms        0.072 ms
min:    0.005 ms        0.001 ms
std:    0.074 ms        0.001 ms

This change shows a significant speed improvement. It does not do the
same for setShadowLayer, which is likely used less frequently.

Change-Id: I9021864fcad7d0149b93674f09339f805c272994
parent 309eb41a
Loading
Loading
Loading
Loading
+7 −2
Original line number Original line Diff line number Diff line
@@ -723,13 +723,17 @@ namespace PaintGlue {
        obj->setStyle(style);
        obj->setStyle(style);
    }
    }


    static void setColor(jlong paintHandle, jlong colorSpaceHandle,
    static void setColorLong(jlong paintHandle, jlong colorSpaceHandle,
            jfloat r, jfloat g, jfloat b, jfloat a) {
            jfloat r, jfloat g, jfloat b, jfloat a) {
        sk_sp<SkColorSpace> cs = GraphicsJNI::getNativeColorSpace(colorSpaceHandle);
        sk_sp<SkColorSpace> cs = GraphicsJNI::getNativeColorSpace(colorSpaceHandle);
        SkColor4f color = SkColor4f{r, g, b, a};
        SkColor4f color = SkColor4f{r, g, b, a};
        reinterpret_cast<Paint*>(paintHandle)->setColor4f(color, cs.get());
        reinterpret_cast<Paint*>(paintHandle)->setColor4f(color, cs.get());
    }
    }


    static void setColor(jlong paintHandle, jint color) {
        reinterpret_cast<Paint*>(paintHandle)->setColor(color);
    }

    static void setAlpha(jlong paintHandle, jint a) {
    static void setAlpha(jlong paintHandle, jint a) {
        reinterpret_cast<Paint*>(paintHandle)->setAlpha(a);
        reinterpret_cast<Paint*>(paintHandle)->setAlpha(a);
    }
    }
@@ -1082,7 +1086,8 @@ static const JNINativeMethod methods[] = {
    {"nSetDither","(JZ)V", (void*) PaintGlue::setDither},
    {"nSetDither","(JZ)V", (void*) PaintGlue::setDither},
    {"nGetStyle","(J)I", (void*) PaintGlue::getStyle},
    {"nGetStyle","(J)I", (void*) PaintGlue::getStyle},
    {"nSetStyle","(JI)V", (void*) PaintGlue::setStyle},
    {"nSetStyle","(JI)V", (void*) PaintGlue::setStyle},
    {"nSetColor","(JJFFFF)V", (void*) PaintGlue::setColor},
    {"nSetColor","(JI)V", (void*) PaintGlue::setColor},
    {"nSetColor","(JJFFFF)V", (void*) PaintGlue::setColorLong},
    {"nSetAlpha","(JI)V", (void*) PaintGlue::setAlpha},
    {"nSetAlpha","(JI)V", (void*) PaintGlue::setAlpha},
    {"nGetStrokeWidth","(J)F", (void*) PaintGlue::getStrokeWidth},
    {"nGetStrokeWidth","(J)F", (void*) PaintGlue::getStrokeWidth},
    {"nSetStrokeWidth","(JF)V", (void*) PaintGlue::setStrokeWidth},
    {"nSetStrokeWidth","(JF)V", (void*) PaintGlue::setStrokeWidth},
+4 −1
Original line number Original line Diff line number Diff line
@@ -1048,7 +1048,8 @@ public class Paint {
     * @param color The new color (including alpha) to set in the paint.
     * @param color The new color (including alpha) to set in the paint.
     */
     */
    public void setColor(@ColorInt int color) {
    public void setColor(@ColorInt int color) {
        setColor(Color.pack(color));
        nSetColor(mNativePaint, color);
        mColor = Color.pack(color);
    }
    }


    /**
    /**
@@ -3192,6 +3193,8 @@ public class Paint {
    private static native void nSetColor(long paintPtr, long colorSpaceHandle,
    private static native void nSetColor(long paintPtr, long colorSpaceHandle,
            float r, float g, float b, float a);
            float r, float g, float b, float a);
    @CriticalNative
    @CriticalNative
    private static native void nSetColor(long paintPtr, @ColorInt int color);
    @CriticalNative
    private static native void nSetStrikeThruText(long paintPtr, boolean strikeThruText);
    private static native void nSetStrikeThruText(long paintPtr, boolean strikeThruText);
    @CriticalNative
    @CriticalNative
    private static native boolean nIsElegantTextHeight(long paintPtr);
    private static native boolean nIsElegantTextHeight(long paintPtr);