diff --git a/core/jni/android_graphics_drawable_VectorDrawable.cpp b/core/jni/android_graphics_drawable_VectorDrawable.cpp index e9ea7022901bd..6f4a58aadca32 100644 --- a/core/jni/android_graphics_drawable_VectorDrawable.cpp +++ b/core/jni/android_graphics_drawable_VectorDrawable.cpp @@ -96,6 +96,11 @@ static void setAllowCaching(JNIEnv*, jobject, jlong treePtr, jboolean allowCachi tree->setAllowCaching(allowCaching); } +static void setAntiAlias(JNIEnv*, jobject, jlong treePtr, jboolean aa) { + VectorDrawable::Tree* tree = reinterpret_cast(treePtr); + tree->setAntiAlias(aa); +} + /** * Draw */ @@ -363,6 +368,7 @@ static const JNINativeMethod gMethods[] = { {"nSetRendererViewportSize", "(JFF)V", (void*)setTreeViewportSize}, {"nSetRootAlpha", "(JF)Z", (void*)setRootAlpha}, {"nGetRootAlpha", "(J)F", (void*)getRootAlpha}, + {"nSetAntiAlias", "(JZ)V", (void*)setAntiAlias}, {"nSetAllowCaching", "(JZ)V", (void*)setAllowCaching}, {"nCreateFullPath", "()J", (void*)createEmptyFullPath}, diff --git a/graphics/java/android/graphics/drawable/VectorDrawable.java b/graphics/java/android/graphics/drawable/VectorDrawable.java index 7b2e21a40f8b7..c71585f321550 100644 --- a/graphics/java/android/graphics/drawable/VectorDrawable.java +++ b/graphics/java/android/graphics/drawable/VectorDrawable.java @@ -896,6 +896,13 @@ public class VectorDrawable extends Drawable { return mVectorState.getNativeRenderer(); } + /** + * @hide + */ + public void setAntiAlias(boolean aa) { + nSetAntiAlias(mVectorState.mNativeTree.get(), aa); + } + static class VectorDrawableState extends ConstantState { // Variables below need to be copied (deep copy if applicable) for mutation. int[] mThemeAttrs; @@ -2269,6 +2276,8 @@ public class VectorDrawable extends Drawable { @FastNative private static native float nGetRootAlpha(long rendererPtr); @FastNative + private static native void nSetAntiAlias(long rendererPtr, boolean aa); + @FastNative private static native void nSetAllowCaching(long rendererPtr, boolean allowCaching); @FastNative diff --git a/libs/hwui/VectorDrawable.cpp b/libs/hwui/VectorDrawable.cpp index ce00488c97287..f118e8d0a53ec 100644 --- a/libs/hwui/VectorDrawable.cpp +++ b/libs/hwui/VectorDrawable.cpp @@ -166,7 +166,7 @@ void FullPath::draw(SkCanvas* outCanvas, bool useStagingData) { if (needsFill) { paint.setStyle(SkPaint::Style::kFill_Style); - paint.setAntiAlias(true); + paint.setAntiAlias(mAntiAlias); outCanvas->drawPath(renderPath, paint); } @@ -182,7 +182,7 @@ void FullPath::draw(SkCanvas* outCanvas, bool useStagingData) { } if (needsStroke) { paint.setStyle(SkPaint::Style::kStroke_Style); - paint.setAntiAlias(true); + paint.setAntiAlias(mAntiAlias); paint.setStrokeJoin(SkPaint::Join(properties.getStrokeLineJoin())); paint.setStrokeCap(SkPaint::Cap(properties.getStrokeLineCap())); paint.setStrokeMiter(properties.getStrokeMiterLimit()); diff --git a/libs/hwui/VectorDrawable.h b/libs/hwui/VectorDrawable.h index 7f75609580227..d9cf8ab7eedf7 100644 --- a/libs/hwui/VectorDrawable.h +++ b/libs/hwui/VectorDrawable.h @@ -124,6 +124,7 @@ public: virtual void onPropertyChanged(Properties* properties) = 0; virtual ~Node() {} virtual void syncProperties() = 0; + virtual void setAntiAlias(bool aa) = 0; protected: std::string mName; @@ -354,6 +355,7 @@ public: } } } + virtual void setAntiAlias(bool aa) { mAntiAlias = aa; } protected: const SkPath& getUpdatedPath(bool useStagingData, SkPath* tempStagingPath) override; @@ -365,6 +367,8 @@ private: // Intermediate data for drawing, render thread only SkPath mTrimmedSkPath; + // Default to use AntiAlias + bool mAntiAlias = true; }; class ANDROID_API ClipPath : public Path { @@ -373,6 +377,7 @@ public: ClipPath(const char* path, size_t strLength) : Path(path, strLength) {} ClipPath() : Path() {} void draw(SkCanvas* outCanvas, bool useStagingData) override; + virtual void setAntiAlias(bool aa) {} }; class ANDROID_API Group : public Node { @@ -476,6 +481,12 @@ public: } } + virtual void setAntiAlias(bool aa) { + for (auto& child : mChildren) { + child->setAntiAlias(aa); + } + } + private: GroupProperties mProperties = GroupProperties(this); GroupProperties mStagingProperties = GroupProperties(this); @@ -641,6 +652,8 @@ public: */ void updateCache(sp& atlas, GrContext* context); + void setAntiAlias(bool aa) { mRootNode->setAntiAlias(aa); } + private: class Cache { public: