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

Commit dab4ad8a authored by Leon Scroggins's avatar Leon Scroggins Committed by Android (Google) Code Review
Browse files

Merge "Add Paint#setShadowLayer(..., @ColorLong)"

parents 1960cd48 8bbcd347
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -511,6 +511,7 @@ package android.graphics {

  public class Paint {
    method public void setColor(long);
    method public void setShadowLayer(float, float, float, long);
  }

}
+22 −0
Original line number Diff line number Diff line
@@ -569,6 +569,26 @@ namespace PaintGlue {
        reinterpret_cast<Paint*>(paintHandle)->setColor4f(color, cs.get());
    }

    static void setShadowLayerLong(JNIEnv* env, jobject clazz, jlong paintHandle, jfloat radius,
                                   jfloat dx, jfloat dy, jobject jColorSpace,
                                   jfloat r, jfloat g, jfloat b, jfloat a) {
        sk_sp<SkColorSpace> cs = GraphicsJNI::getNativeColorSpace(env, jColorSpace);
        if (GraphicsJNI::hasException(env)) {
            return;
        }

        SkColor4f color = SkColor4f{r, g, b, a};

        Paint* paint = reinterpret_cast<Paint*>(paintHandle);
        if (radius <= 0) {
            paint->setLooper(nullptr);
        }
        else {
            SkScalar sigma = android::uirenderer::Blur::convertRadiusToSigma(radius);
            paint->setLooper(SkBlurDrawLooper::Make(color, cs.get(), sigma, dx, dy));
        }
    }

    // ------------------ @FastNative ---------------------------

    static jint setTextLocales(JNIEnv* env, jobject clazz, jlong objHandle, jstring locales) {
@@ -1088,6 +1108,8 @@ static const JNINativeMethod methods[] = {
    {"nGetOffsetForAdvance", "(J[CIIIIZF)I",
            (void*) PaintGlue::getOffsetForAdvance___CIIIIZF_I},
    {"nSetColor","(JLandroid/graphics/ColorSpace;FFFF)V", (void*) PaintGlue::setColorLong},
    {"nSetShadowLayer", "(JFFFLandroid/graphics/ColorSpace;FFFF)V",
            (void*)PaintGlue::setShadowLayerLong},

    // --------------- @FastNative ----------------------

+43 −7
Original line number Diff line number Diff line
@@ -1397,14 +1397,47 @@ public class Paint {
     * The alpha of the shadow will be the paint's alpha if the shadow color is
     * opaque, or the alpha from the shadow color if not.
     */
    public void setShadowLayer(float radius, float dx, float dy, int shadowColor) {
    public void setShadowLayer(float radius, float dx, float dy, @ColorInt int shadowColor) {
        mShadowLayerRadius = radius;
        mShadowLayerDx = dx;
        mShadowLayerDy = dy;
        mShadowLayerColor = shadowColor;
        // FIXME: Share a single native method with the ColorLong version.
        nSetShadowLayer(mNativePaint, radius, dx, dy, shadowColor);
    }

    /**
     * This draws a shadow layer below the main layer, with the specified
     * offset and color, and blur radius. If radius is 0, then the shadow
     * layer is removed.
     * <p>
     * Can be used to create a blurred shadow underneath text. Support for use
     * with other drawing operations is constrained to the software rendering
     * pipeline.
     * <p>
     * The alpha of the shadow will be the paint's alpha if the shadow color is
     * opaque, or the alpha from the shadow color if not.
     *
     * @throws IllegalArgumentException if the color space encoded in the long
     *      is invalid or unknown.
     *
     * @hide pending API approval
     */
    @TestApi
    public void setShadowLayer(float radius, float dx, float dy, @ColorLong long shadowColor) {
        ColorSpace cs = Color.colorSpace(shadowColor);
        float r = Color.red(shadowColor);
        float g = Color.green(shadowColor);
        float b = Color.blue(shadowColor);
        float a = Color.alpha(shadowColor);
        nSetShadowLayer(mNativePaint, radius, dx, dy, cs, r, g, b, a);

        mShadowLayerRadius = radius;
        mShadowLayerDx = dx;
        mShadowLayerDy = dy;
        mShadowLayerColor = Color.toArgb(shadowColor);
    }

    /**
     * Clear the shadow layer.
     */
@@ -2935,6 +2968,9 @@ public class Paint {
            int contextStart, int contextEnd, boolean isRtl, float advance);
    private static native void nSetColor(long paintPtr, ColorSpace cs,
            float r, float g, float b, float a);
    private static native void nSetShadowLayer(long paintPtr,
            float radius, float dx, float dy, ColorSpace cs,
            float r, float g, float b, float a);


    // ---------------- @FastNative ------------------------
@@ -2990,7 +3026,7 @@ public class Paint {
            int mMinikinLocaleListId);
    @CriticalNative
    private static native void nSetShadowLayer(long paintPtr,
            float radius, float dx, float dy, int color);
            float radius, float dx, float dy, @ColorInt int color);
    @CriticalNative
    private static native boolean nHasShadowLayer(long paintPtr);
    @CriticalNative