diff options
| -rw-r--r-- | api/test-current.txt | 1 | ||||
| -rw-r--r-- | core/jni/android/graphics/Paint.cpp | 22 | ||||
| -rw-r--r-- | graphics/java/android/graphics/Paint.java | 50 |
3 files changed, 66 insertions, 7 deletions
diff --git a/api/test-current.txt b/api/test-current.txt index bbba6500eae0..59347d14c49d 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -511,6 +511,7 @@ package android.graphics { public class Paint { method public void setColor(long); + method public void setShadowLayer(float, float, float, long); } } diff --git a/core/jni/android/graphics/Paint.cpp b/core/jni/android/graphics/Paint.cpp index b4174922aa6c..bc49771c380b 100644 --- a/core/jni/android/graphics/Paint.cpp +++ b/core/jni/android/graphics/Paint.cpp @@ -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 ---------------------- diff --git a/graphics/java/android/graphics/Paint.java b/graphics/java/android/graphics/Paint.java index 154c1b833b7a..cbb780deac8a 100644 --- a/graphics/java/android/graphics/Paint.java +++ b/graphics/java/android/graphics/Paint.java @@ -1397,12 +1397,45 @@ 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) { - mShadowLayerRadius = radius; - mShadowLayerDx = dx; - mShadowLayerDy = dy; - mShadowLayerColor = shadowColor; - nSetShadowLayer(mNativePaint, radius, dx, dy, 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); } /** @@ -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 |