summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
Diffstat (limited to 'libs')
-rw-r--r--libs/hwui/VectorDrawable.cpp44
-rw-r--r--libs/hwui/VectorDrawable.h22
2 files changed, 54 insertions, 12 deletions
diff --git a/libs/hwui/VectorDrawable.cpp b/libs/hwui/VectorDrawable.cpp
index 1d31c9e08a9e..4d4acb94c255 100644
--- a/libs/hwui/VectorDrawable.cpp
+++ b/libs/hwui/VectorDrawable.cpp
@@ -18,6 +18,7 @@
#include "PathParser.h"
#include "SkImageInfo.h"
+#include "SkShader.h"
#include <utils/Log.h>
#include "utils/Macros.h"
#include "utils/VectorDrawableUtils.h"
@@ -49,7 +50,7 @@ void Path::draw(SkCanvas* outCanvas, const SkMatrix& groupStackedMatrix, float s
float minScale = fmin(scaleX, scaleY);
float strokeScale = minScale * matrixScale;
- drawPath(outCanvas, renderPath, strokeScale);
+ drawPath(outCanvas, renderPath, strokeScale, pathMatrix);
}
void Path::setPathData(const Data& data) {
@@ -148,6 +149,9 @@ FullPath::FullPath(const FullPath& path) : Path(path) {
mStrokeMiterLimit = path.mStrokeMiterLimit;
mStrokeLineCap = path.mStrokeLineCap;
mStrokeLineJoin = path.mStrokeLineJoin;
+
+ SkRefCnt_SafeAssign(mStrokeGradient, path.mStrokeGradient);
+ SkRefCnt_SafeAssign(mFillGradient, path.mFillGradient);
}
const SkPath& FullPath::getUpdatedPath() {
@@ -186,22 +190,44 @@ inline SkColor applyAlpha(SkColor color, float alpha) {
return SkColorSetA(color, alphaBytes * alpha);
}
-void FullPath::drawPath(SkCanvas* outCanvas, const SkPath& renderPath, float strokeScale){
- // Draw path's fill, if fill color isn't transparent.
- if (mFillColor != SK_ColorTRANSPARENT) {
+void FullPath::drawPath(SkCanvas* outCanvas, const SkPath& renderPath, float strokeScale,
+ const SkMatrix& matrix){
+ // Draw path's fill, if fill color or gradient is valid
+ bool needsFill = false;
+ if (mFillGradient != nullptr) {
+ mPaint.setColor(applyAlpha(SK_ColorBLACK, mFillAlpha));
+ SkShader* newShader = mFillGradient->newWithLocalMatrix(matrix);
+ mPaint.setShader(newShader);
+ needsFill = true;
+ } else if (mFillColor != SK_ColorTRANSPARENT) {
+ mPaint.setColor(applyAlpha(mFillColor, mFillAlpha));
+ outCanvas->drawPath(renderPath, mPaint);
+ needsFill = true;
+ }
+
+ if (needsFill) {
mPaint.setStyle(SkPaint::Style::kFill_Style);
mPaint.setAntiAlias(true);
- mPaint.setColor(applyAlpha(mFillColor, mFillAlpha));
outCanvas->drawPath(renderPath, mPaint);
}
- // Draw path's stroke, if stroke color isn't transparent
- if (mStrokeColor != SK_ColorTRANSPARENT) {
+
+ // Draw path's stroke, if stroke color or gradient is valid
+ bool needsStroke = false;
+ if (mStrokeGradient != nullptr) {
+ mPaint.setColor(applyAlpha(SK_ColorBLACK, mStrokeAlpha));
+ SkShader* newShader = mStrokeGradient->newWithLocalMatrix(matrix);
+ mPaint.setShader(newShader);
+ needsStroke = true;
+ } else if (mStrokeColor != SK_ColorTRANSPARENT) {
+ mPaint.setColor(applyAlpha(mStrokeColor, mStrokeAlpha));
+ needsStroke = true;
+ }
+ if (needsStroke) {
mPaint.setStyle(SkPaint::Style::kStroke_Style);
mPaint.setAntiAlias(true);
mPaint.setStrokeJoin(mStrokeLineJoin);
mPaint.setStrokeCap(mStrokeLineCap);
mPaint.setStrokeMiter(mStrokeMiterLimit);
- mPaint.setColor(applyAlpha(mStrokeColor, mStrokeAlpha));
mPaint.setStrokeWidth(mStrokeWidth * strokeScale);
outCanvas->drawPath(renderPath, mPaint);
}
@@ -288,7 +314,7 @@ bool FullPath::getProperties(int8_t* outProperties, int length) {
}
void ClipPath::drawPath(SkCanvas* outCanvas, const SkPath& renderPath,
- float strokeScale){
+ float strokeScale, const SkMatrix& matrix){
outCanvas->clipPath(renderPath, SkRegion::kIntersect_Op);
}
diff --git a/libs/hwui/VectorDrawable.h b/libs/hwui/VectorDrawable.h
index 5ae5f6a3bdba..09bdce596a21 100644
--- a/libs/hwui/VectorDrawable.h
+++ b/libs/hwui/VectorDrawable.h
@@ -26,6 +26,7 @@
#include <SkPath.h>
#include <SkPathMeasure.h>
#include <SkRect.h>
+#include <SkShader.h>
#include <cutils/compiler.h>
#include <stddef.h>
@@ -95,7 +96,7 @@ public:
protected:
virtual const SkPath& getUpdatedPath();
virtual void drawPath(SkCanvas *outCanvas, const SkPath& renderPath,
- float strokeScale) = 0;
+ float strokeScale, const SkMatrix& matrix) = 0;
Data mData;
SkPath mSkPath;
bool mSkPathDirty = true;
@@ -108,6 +109,11 @@ public:
FullPath() : Path() {}
FullPath(const Data& nodes) : Path(nodes) {}
+ ~FullPath() {
+ SkSafeUnref(mFillGradient);
+ SkSafeUnref(mStrokeGradient);
+ }
+
void updateProperties(float strokeWidth, SkColor strokeColor,
float strokeAlpha, SkColor fillColor, float fillAlpha,
float trimPathStart, float trimPathEnd, float trimPathOffset,
@@ -162,10 +168,18 @@ public:
}
bool getProperties(int8_t* outProperties, int length);
+ void setFillGradient(SkShader* fillGradient) {
+ SkRefCnt_SafeAssign(mFillGradient, fillGradient);
+ };
+ void setStrokeGradient(SkShader* strokeGradient) {
+ SkRefCnt_SafeAssign(mStrokeGradient, strokeGradient);
+ };
+
+
protected:
const SkPath& getUpdatedPath() override;
void drawPath(SkCanvas* outCanvas, const SkPath& renderPath,
- float strokeScale) override;
+ float strokeScale, const SkMatrix& matrix) override;
private:
// Applies trimming to the specified path.
@@ -174,6 +188,8 @@ private:
SkColor mStrokeColor = SK_ColorTRANSPARENT;
float mStrokeAlpha = 1;
SkColor mFillColor = SK_ColorTRANSPARENT;
+ SkShader* mStrokeGradient = nullptr;
+ SkShader* mFillGradient = nullptr;
float mFillAlpha = 1;
float mTrimPathStart = 0;
float mTrimPathEnd = 1;
@@ -195,7 +211,7 @@ public:
protected:
void drawPath(SkCanvas* outCanvas, const SkPath& renderPath,
- float strokeScale) override;
+ float strokeScale, const SkMatrix& matrix) override;
};
class ANDROID_API Group: public Node {