diff options
Diffstat (limited to 'libs/hwui/VectorDrawable.h')
-rw-r--r-- | libs/hwui/VectorDrawable.h | 68 |
1 files changed, 36 insertions, 32 deletions
diff --git a/libs/hwui/VectorDrawable.h b/libs/hwui/VectorDrawable.h index da52a9503377..9c0bb161380c 100644 --- a/libs/hwui/VectorDrawable.h +++ b/libs/hwui/VectorDrawable.h @@ -59,12 +59,6 @@ namespace VectorDrawable { onPropertyChanged(); \ retVal; \ }) -#define UPDATE_SKPROP(field, value) \ - ({ \ - bool retVal = ((field) != (value)); \ - if ((field) != (value)) SkRefCnt_SafeAssign((field), (value)); \ - retVal; \ - }) /* A VectorDrawable is composed of a tree of nodes. * Each node can be a group node, or a path. @@ -126,6 +120,8 @@ public: virtual void syncProperties() = 0; virtual void setAntiAlias(bool aa) = 0; + virtual void forEachFillColor(const std::function<void(SkColor)>& func) const { } + protected: std::string mName; PropertyChangedListener* mPropertyChangedListener = nullptr; @@ -223,29 +219,28 @@ public: int fillType = 0; /* non-zero or kWinding_FillType in Skia */ }; explicit FullPathProperties(Node* mNode) : Properties(mNode), mTrimDirty(false) {} - ~FullPathProperties() { - SkSafeUnref(fillGradient); - SkSafeUnref(strokeGradient); - } + ~FullPathProperties() {} void syncProperties(const FullPathProperties& prop) { mPrimitiveFields = prop.mPrimitiveFields; mTrimDirty = true; - UPDATE_SKPROP(fillGradient, prop.fillGradient); - UPDATE_SKPROP(strokeGradient, prop.strokeGradient); + fillGradient = prop.fillGradient; + strokeGradient = prop.strokeGradient; onPropertyChanged(); } void setFillGradient(SkShader* gradient) { - if (UPDATE_SKPROP(fillGradient, gradient)) { + if (fillGradient.get() != gradient) { + fillGradient = sk_ref_sp(gradient); onPropertyChanged(); } } void setStrokeGradient(SkShader* gradient) { - if (UPDATE_SKPROP(strokeGradient, gradient)) { + if (strokeGradient.get() != gradient) { + strokeGradient = sk_ref_sp(gradient); onPropertyChanged(); } } - SkShader* getFillGradient() const { return fillGradient; } - SkShader* getStrokeGradient() const { return strokeGradient; } + SkShader* getFillGradient() const { return fillGradient.get(); } + SkShader* getStrokeGradient() const { return strokeGradient.get(); } float getStrokeWidth() const { return mPrimitiveFields.strokeWidth; } void setStrokeWidth(float strokeWidth) { VD_SET_PRIMITIVE_FIELD_AND_NOTIFY(strokeWidth, strokeWidth); @@ -325,8 +320,8 @@ public: count, }; PrimitiveFields mPrimitiveFields; - SkShader* fillGradient = nullptr; - SkShader* strokeGradient = nullptr; + sk_sp<SkShader> fillGradient; + sk_sp<SkShader> strokeGradient; }; // Called from UI thread @@ -356,6 +351,9 @@ public: } } virtual void setAntiAlias(bool aa) { mAntiAlias = aa; } + void forEachFillColor(const std::function<void(SkColor)>& func) const override { + func(mStagingProperties.getFillColor()); + } protected: const SkPath& getUpdatedPath(bool useStagingData, SkPath* tempStagingPath) override; @@ -487,6 +485,12 @@ public: } } + void forEachFillColor(const std::function<void(SkColor)>& func) const override { + for (auto& child : mChildren) { + child->forEachFillColor(func); + } + } + private: GroupProperties mProperties = GroupProperties(this); GroupProperties mStagingProperties = GroupProperties(this); @@ -502,8 +506,8 @@ public: // Copy properties from the tree and use the give node as the root node Tree(const Tree* copy, Group* rootNode) : Tree(rootNode) { - mStagingProperties.syncAnimatableProperties(*copy->stagingProperties()); - mStagingProperties.syncNonAnimatableProperties(*copy->stagingProperties()); + mStagingProperties.syncAnimatableProperties(copy->stagingProperties()); + mStagingProperties.syncNonAnimatableProperties(copy->stagingProperties()); } // Draws the VD onto a bitmap cache, then the bitmap cache will be rendered onto the input // canvas. Returns the number of pixels needed for the bitmap cache. @@ -513,7 +517,6 @@ public: Bitmap& getBitmapUpdateIfDirty(); void setAllowCaching(bool allowCaching) { mAllowCaching = allowCaching; } - SkPaint* getPaint(); void syncProperties() { if (mStagingProperties.mNonAnimatablePropertiesDirty) { mCache.dirty |= (mProperties.mNonAnimatableProperties.viewportWidth != @@ -550,8 +553,7 @@ public: SkRect bounds; int scaledWidth = 0; int scaledHeight = 0; - SkColorFilter* colorFilter = nullptr; - ~NonAnimatableProperties() { SkSafeUnref(colorFilter); } + sk_sp<SkColorFilter> colorFilter; } mNonAnimatableProperties; bool mNonAnimatablePropertiesDirty = true; @@ -561,8 +563,7 @@ public: void syncNonAnimatableProperties(const TreeProperties& prop) { // Copy over the data that can only be changed in UI thread if (mNonAnimatableProperties.colorFilter != prop.mNonAnimatableProperties.colorFilter) { - SkRefCnt_SafeAssign(mNonAnimatableProperties.colorFilter, - prop.mNonAnimatableProperties.colorFilter); + mNonAnimatableProperties.colorFilter = prop.mNonAnimatableProperties.colorFilter; } mNonAnimatableProperties = prop.mNonAnimatableProperties; } @@ -599,12 +600,13 @@ public: } } void setColorFilter(SkColorFilter* filter) { - if (UPDATE_SKPROP(mNonAnimatableProperties.colorFilter, filter)) { + if (mNonAnimatableProperties.colorFilter.get() != filter) { + mNonAnimatableProperties.colorFilter = sk_ref_sp(filter); mNonAnimatablePropertiesDirty = true; mTree->onPropertyChanged(this); } } - SkColorFilter* getColorFilter() const { return mNonAnimatableProperties.colorFilter; } + SkColorFilter* getColorFilter() const { return mNonAnimatableProperties.colorFilter.get(); } float getViewportWidth() const { return mNonAnimatableProperties.viewportWidth; } float getViewportHeight() const { return mNonAnimatableProperties.viewportHeight; } @@ -626,7 +628,7 @@ public: }; void onPropertyChanged(TreeProperties* prop); TreeProperties* mutateStagingProperties() { return &mStagingProperties; } - const TreeProperties* stagingProperties() const { return &mStagingProperties; } + const TreeProperties& stagingProperties() const { return mStagingProperties; } // This should only be called from animations on RT TreeProperties* mutateProperties() { return &mProperties; } @@ -644,7 +646,10 @@ public: * Draws VD cache into a canvas. This should always be called from RT and it works with Skia * pipelines only. */ - void draw(SkCanvas* canvas, const SkRect& bounds); + void draw(SkCanvas* canvas, const SkRect& bounds, const SkPaint& paint); + + void getPaintFor(SkPaint* outPaint, const TreeProperties &props) const; + BitmapPalette computePalette(); /** * Draws VD into a GPU backed surface. @@ -688,7 +693,6 @@ private: skiapipeline::AtlasKey mAtlasKey = INVALID_ATLAS_KEY; }; - SkPaint* updatePaint(SkPaint* outPaint, TreeProperties* prop); bool allocateBitmapIfNeeded(Cache& cache, int width, int height); bool canReuseBitmap(Bitmap*, int width, int height); void updateBitmapCache(Bitmap& outCache, bool useStagingData); @@ -704,8 +708,6 @@ private: TreeProperties mProperties = TreeProperties(this); TreeProperties mStagingProperties = TreeProperties(this); - SkPaint mPaint; - Cache mStagingCache; Cache mCache; @@ -718,6 +720,8 @@ private: } // namespace VectorDrawable typedef VectorDrawable::Path::Data PathData; +typedef uirenderer::VectorDrawable::Tree VectorDrawableRoot; + } // namespace uirenderer } // namespace android |