Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ANDROID_HWUI_VPATH_H |
| 18 | #define ANDROID_HWUI_VPATH_H |
| 19 | |
| 20 | #include "Canvas.h" |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 21 | |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 22 | #include <SkBitmap.h> |
| 23 | #include <SkColor.h> |
Doris Liu | c2de46f | 2016-01-21 12:55:54 -0800 | [diff] [blame] | 24 | #include <SkCanvas.h> |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 25 | #include <SkMatrix.h> |
| 26 | #include <SkPaint.h> |
| 27 | #include <SkPath.h> |
| 28 | #include <SkPathMeasure.h> |
| 29 | #include <SkRect.h> |
Teng-Hui Zhu | dbee9bb | 2015-12-15 11:01:27 -0800 | [diff] [blame] | 30 | #include <SkShader.h> |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 31 | |
| 32 | #include <cutils/compiler.h> |
| 33 | #include <stddef.h> |
| 34 | #include <vector> |
| 35 | #include <string> |
| 36 | |
| 37 | namespace android { |
| 38 | namespace uirenderer { |
| 39 | |
| 40 | namespace VectorDrawable { |
| 41 | #define VD_SET_PROP_WITH_FLAG(field, value, flag) (VD_SET_PROP(field, value) ? (flag = true, true): false); |
| 42 | #define VD_SET_PROP(field, value) (value != field ? (field = value, true) : false) |
| 43 | |
| 44 | /* A VectorDrawable is composed of a tree of nodes. |
| 45 | * Each node can be a group node, or a path. |
| 46 | * A group node can have groups or paths as children, but a path node has |
| 47 | * no children. |
| 48 | * One example can be: |
| 49 | * Root Group |
| 50 | * / | \ |
| 51 | * Group Path Group |
| 52 | * / \ | |
| 53 | * Path Path Path |
| 54 | * |
| 55 | */ |
| 56 | class ANDROID_API Node { |
| 57 | public: |
| 58 | Node(const Node& node) { |
| 59 | mName = node.mName; |
| 60 | } |
| 61 | Node() {} |
Doris Liu | c2de46f | 2016-01-21 12:55:54 -0800 | [diff] [blame] | 62 | virtual void draw(SkCanvas* outCanvas, const SkMatrix& currentMatrix, |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 63 | float scaleX, float scaleY) = 0; |
| 64 | virtual void dump() = 0; |
| 65 | void setName(const char* name) { |
| 66 | mName = name; |
| 67 | } |
| 68 | virtual ~Node(){} |
| 69 | protected: |
| 70 | std::string mName; |
| 71 | }; |
| 72 | |
| 73 | class ANDROID_API Path : public Node { |
| 74 | public: |
| 75 | struct ANDROID_API Data { |
| 76 | std::vector<char> verbs; |
| 77 | std::vector<size_t> verbSizes; |
| 78 | std::vector<float> points; |
| 79 | bool operator==(const Data& data) const { |
| 80 | return verbs == data.verbs && verbSizes == data.verbSizes |
| 81 | && points == data.points; |
| 82 | } |
| 83 | }; |
| 84 | Path(const Data& nodes); |
| 85 | Path(const Path& path); |
| 86 | Path(const char* path, size_t strLength); |
| 87 | Path() {} |
| 88 | void dump() override; |
| 89 | bool canMorph(const Data& path); |
| 90 | bool canMorph(const Path& path); |
Doris Liu | c2de46f | 2016-01-21 12:55:54 -0800 | [diff] [blame] | 91 | void draw(SkCanvas* outCanvas, const SkMatrix& groupStackedMatrix, |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 92 | float scaleX, float scaleY) override; |
| 93 | void setPath(const char* path, size_t strLength); |
| 94 | void setPathData(const Data& data); |
| 95 | static float getMatrixScale(const SkMatrix& groupStackedMatrix); |
| 96 | |
| 97 | protected: |
| 98 | virtual const SkPath& getUpdatedPath(); |
Teng-Hui Zhu | 46591f4 | 2016-03-15 14:32:16 -0700 | [diff] [blame^] | 99 | virtual void drawPath(SkCanvas *outCanvas, SkPath& renderPath, |
Teng-Hui Zhu | dbee9bb | 2015-12-15 11:01:27 -0800 | [diff] [blame] | 100 | float strokeScale, const SkMatrix& matrix) = 0; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 101 | Data mData; |
| 102 | SkPath mSkPath; |
| 103 | bool mSkPathDirty = true; |
| 104 | }; |
| 105 | |
| 106 | class ANDROID_API FullPath: public Path { |
| 107 | public: |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 108 | |
| 109 | struct Properties { |
| 110 | float strokeWidth = 0; |
| 111 | SkColor strokeColor = SK_ColorTRANSPARENT; |
| 112 | float strokeAlpha = 1; |
| 113 | SkColor fillColor = SK_ColorTRANSPARENT; |
| 114 | float fillAlpha = 1; |
| 115 | float trimPathStart = 0; |
| 116 | float trimPathEnd = 1; |
| 117 | float trimPathOffset = 0; |
| 118 | int32_t strokeLineCap = SkPaint::Cap::kButt_Cap; |
| 119 | int32_t strokeLineJoin = SkPaint::Join::kMiter_Join; |
| 120 | float strokeMiterLimit = 4; |
Teng-Hui Zhu | 46591f4 | 2016-03-15 14:32:16 -0700 | [diff] [blame^] | 121 | int fillType = 0; /* non-zero or kWinding_FillType in Skia */ |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 122 | }; |
| 123 | |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 124 | FullPath(const FullPath& path); // for cloning |
| 125 | FullPath(const char* path, size_t strLength) : Path(path, strLength) {} |
| 126 | FullPath() : Path() {} |
| 127 | FullPath(const Data& nodes) : Path(nodes) {} |
| 128 | |
Teng-Hui Zhu | dbee9bb | 2015-12-15 11:01:27 -0800 | [diff] [blame] | 129 | ~FullPath() { |
| 130 | SkSafeUnref(mFillGradient); |
| 131 | SkSafeUnref(mStrokeGradient); |
| 132 | } |
| 133 | |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 134 | void updateProperties(float strokeWidth, SkColor strokeColor, |
| 135 | float strokeAlpha, SkColor fillColor, float fillAlpha, |
| 136 | float trimPathStart, float trimPathEnd, float trimPathOffset, |
Teng-Hui Zhu | 46591f4 | 2016-03-15 14:32:16 -0700 | [diff] [blame^] | 137 | float strokeMiterLimit, int strokeLineCap, int strokeLineJoin, int fillType); |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 138 | // TODO: Cleanup: Remove the setter and getters below, and their counterparts in java and JNI |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 139 | float getStrokeWidth() { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 140 | return mProperties.strokeWidth; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 141 | } |
| 142 | void setStrokeWidth(float strokeWidth) { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 143 | mProperties.strokeWidth = strokeWidth; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 144 | } |
| 145 | SkColor getStrokeColor() { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 146 | return mProperties.strokeColor; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 147 | } |
| 148 | void setStrokeColor(SkColor strokeColor) { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 149 | mProperties.strokeColor = strokeColor; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 150 | } |
| 151 | float getStrokeAlpha() { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 152 | return mProperties.strokeAlpha; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 153 | } |
| 154 | void setStrokeAlpha(float strokeAlpha) { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 155 | mProperties.strokeAlpha = strokeAlpha; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 156 | } |
| 157 | SkColor getFillColor() { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 158 | return mProperties.fillColor; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 159 | } |
| 160 | void setFillColor(SkColor fillColor) { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 161 | mProperties.fillColor = fillColor; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 162 | } |
| 163 | float getFillAlpha() { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 164 | return mProperties.fillAlpha; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 165 | } |
| 166 | void setFillAlpha(float fillAlpha) { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 167 | mProperties.fillAlpha = fillAlpha; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 168 | } |
| 169 | float getTrimPathStart() { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 170 | return mProperties.trimPathStart; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 171 | } |
| 172 | void setTrimPathStart(float trimPathStart) { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 173 | VD_SET_PROP_WITH_FLAG(mProperties.trimPathStart, trimPathStart, mTrimDirty); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 174 | } |
| 175 | float getTrimPathEnd() { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 176 | return mProperties.trimPathEnd; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 177 | } |
| 178 | void setTrimPathEnd(float trimPathEnd) { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 179 | VD_SET_PROP_WITH_FLAG(mProperties.trimPathEnd, trimPathEnd, mTrimDirty); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 180 | } |
| 181 | float getTrimPathOffset() { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 182 | return mProperties.trimPathOffset; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 183 | } |
| 184 | void setTrimPathOffset(float trimPathOffset) { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 185 | VD_SET_PROP_WITH_FLAG(mProperties.trimPathOffset, trimPathOffset, mTrimDirty); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 186 | } |
| 187 | bool getProperties(int8_t* outProperties, int length); |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 188 | void setColorPropertyValue(int propertyId, int32_t value); |
| 189 | void setPropertyValue(int propertyId, float value); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 190 | |
Teng-Hui Zhu | dbee9bb | 2015-12-15 11:01:27 -0800 | [diff] [blame] | 191 | void setFillGradient(SkShader* fillGradient) { |
| 192 | SkRefCnt_SafeAssign(mFillGradient, fillGradient); |
| 193 | }; |
| 194 | void setStrokeGradient(SkShader* strokeGradient) { |
| 195 | SkRefCnt_SafeAssign(mStrokeGradient, strokeGradient); |
| 196 | }; |
| 197 | |
| 198 | |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 199 | protected: |
| 200 | const SkPath& getUpdatedPath() override; |
Teng-Hui Zhu | 46591f4 | 2016-03-15 14:32:16 -0700 | [diff] [blame^] | 201 | void drawPath(SkCanvas* outCanvas, SkPath& renderPath, |
Teng-Hui Zhu | dbee9bb | 2015-12-15 11:01:27 -0800 | [diff] [blame] | 202 | float strokeScale, const SkMatrix& matrix) override; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 203 | |
| 204 | private: |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 205 | enum class Property { |
| 206 | StrokeWidth = 0, |
| 207 | StrokeColor, |
| 208 | StrokeAlpha, |
| 209 | FillColor, |
| 210 | FillAlpha, |
| 211 | TrimPathStart, |
| 212 | TrimPathEnd, |
| 213 | TrimPathOffset, |
| 214 | StrokeLineCap, |
| 215 | StrokeLineJoin, |
| 216 | StrokeMiterLimit, |
Teng-Hui Zhu | 46591f4 | 2016-03-15 14:32:16 -0700 | [diff] [blame^] | 217 | FillType, |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 218 | Count, |
| 219 | }; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 220 | // Applies trimming to the specified path. |
| 221 | void applyTrim(); |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 222 | Properties mProperties; |
Doris Liu | 5a11e8d | 2016-02-04 20:04:10 +0000 | [diff] [blame] | 223 | bool mTrimDirty = true; |
Doris Liu | 5a11e8d | 2016-02-04 20:04:10 +0000 | [diff] [blame] | 224 | SkPath mTrimmedSkPath; |
| 225 | SkPaint mPaint; |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 226 | SkShader* mStrokeGradient = nullptr; |
| 227 | SkShader* mFillGradient = nullptr; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 228 | }; |
| 229 | |
| 230 | class ANDROID_API ClipPath: public Path { |
| 231 | public: |
| 232 | ClipPath(const ClipPath& path) : Path(path) {} |
| 233 | ClipPath(const char* path, size_t strLength) : Path(path, strLength) {} |
| 234 | ClipPath() : Path() {} |
| 235 | ClipPath(const Data& nodes) : Path(nodes) {} |
| 236 | |
| 237 | protected: |
Teng-Hui Zhu | 46591f4 | 2016-03-15 14:32:16 -0700 | [diff] [blame^] | 238 | void drawPath(SkCanvas* outCanvas, SkPath& renderPath, |
Teng-Hui Zhu | dbee9bb | 2015-12-15 11:01:27 -0800 | [diff] [blame] | 239 | float strokeScale, const SkMatrix& matrix) override; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 240 | }; |
| 241 | |
| 242 | class ANDROID_API Group: public Node { |
| 243 | public: |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 244 | struct Properties { |
| 245 | float rotate = 0; |
| 246 | float pivotX = 0; |
| 247 | float pivotY = 0; |
| 248 | float scaleX = 1; |
| 249 | float scaleY = 1; |
| 250 | float translateX = 0; |
| 251 | float translateY = 0; |
| 252 | }; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 253 | Group(const Group& group); |
| 254 | Group() {} |
| 255 | float getRotation() { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 256 | return mProperties.rotate; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 257 | } |
| 258 | void setRotation(float rotation) { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 259 | mProperties.rotate = rotation; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 260 | } |
| 261 | float getPivotX() { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 262 | return mProperties.pivotX; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 263 | } |
| 264 | void setPivotX(float pivotX) { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 265 | mProperties.pivotX = pivotX; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 266 | } |
| 267 | float getPivotY() { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 268 | return mProperties.pivotY; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 269 | } |
| 270 | void setPivotY(float pivotY) { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 271 | mProperties.pivotY = pivotY; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 272 | } |
| 273 | float getScaleX() { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 274 | return mProperties.scaleX; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 275 | } |
| 276 | void setScaleX(float scaleX) { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 277 | mProperties.scaleX = scaleX; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 278 | } |
| 279 | float getScaleY() { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 280 | return mProperties.scaleY; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 281 | } |
| 282 | void setScaleY(float scaleY) { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 283 | mProperties.scaleY = scaleY; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 284 | } |
| 285 | float getTranslateX() { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 286 | return mProperties.translateX; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 287 | } |
| 288 | void setTranslateX(float translateX) { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 289 | mProperties.translateX = translateX; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 290 | } |
| 291 | float getTranslateY() { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 292 | return mProperties.translateY; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 293 | } |
| 294 | void setTranslateY(float translateY) { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 295 | mProperties.translateY = translateY; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 296 | } |
Doris Liu | c2de46f | 2016-01-21 12:55:54 -0800 | [diff] [blame] | 297 | virtual void draw(SkCanvas* outCanvas, const SkMatrix& currentMatrix, |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 298 | float scaleX, float scaleY) override; |
| 299 | void updateLocalMatrix(float rotate, float pivotX, float pivotY, |
| 300 | float scaleX, float scaleY, float translateX, float translateY); |
| 301 | void getLocalMatrix(SkMatrix* outMatrix); |
| 302 | void addChild(Node* child); |
| 303 | void dump() override; |
| 304 | bool getProperties(float* outProperties, int length); |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 305 | float getPropertyValue(int propertyId) const; |
| 306 | void setPropertyValue(int propertyId, float value); |
| 307 | static bool isValidProperty(int propertyId); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 308 | |
| 309 | private: |
| 310 | enum class Property { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 311 | Rotate = 0, |
| 312 | PivotX, |
| 313 | PivotY, |
| 314 | ScaleX, |
| 315 | ScaleY, |
| 316 | TranslateX, |
| 317 | TranslateY, |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 318 | // Count of the properties, must be at the end. |
| 319 | Count, |
| 320 | }; |
Doris Liu | ef062eb | 2016-02-04 16:16:27 -0800 | [diff] [blame] | 321 | std::vector< std::unique_ptr<Node> > mChildren; |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 322 | Properties mProperties; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 323 | }; |
| 324 | |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 325 | class ANDROID_API Tree : public VirtualLightRefBase { |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 326 | public: |
| 327 | Tree(Group* rootNode) : mRootNode(rootNode) {} |
| 328 | void draw(Canvas* outCanvas, SkColorFilter* colorFilter, |
| 329 | const SkRect& bounds, bool needsMirroring, bool canReuseCache); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 330 | |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 331 | const SkBitmap& getBitmapUpdateIfDirty(); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 332 | void createCachedBitmapIfNeeded(int width, int height); |
| 333 | bool canReuseBitmap(int width, int height); |
| 334 | void setAllowCaching(bool allowCaching) { |
| 335 | mAllowCaching = allowCaching; |
| 336 | } |
| 337 | bool setRootAlpha(float rootAlpha) { |
| 338 | return VD_SET_PROP(mRootAlpha, rootAlpha); |
| 339 | } |
| 340 | |
| 341 | float getRootAlpha() { |
| 342 | return mRootAlpha; |
| 343 | } |
| 344 | void setViewportSize(float viewportWidth, float viewportHeight) { |
| 345 | mViewportWidth = viewportWidth; |
| 346 | mViewportHeight = viewportHeight; |
| 347 | } |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 348 | SkPaint* getPaint(); |
| 349 | const SkRect& getBounds() const { |
| 350 | return mBounds; |
| 351 | } |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 352 | |
| 353 | private: |
| 354 | // Cap the bitmap size, such that it won't hurt the performance too much |
| 355 | // and it won't crash due to a very large scale. |
| 356 | // The drawable will look blurry above this size. |
| 357 | const static int MAX_CACHED_BITMAP_SIZE; |
| 358 | |
| 359 | bool mCacheDirty = true; |
| 360 | bool mAllowCaching = true; |
| 361 | float mViewportWidth = 0; |
| 362 | float mViewportHeight = 0; |
| 363 | float mRootAlpha = 1.0f; |
| 364 | |
Doris Liu | ef062eb | 2016-02-04 16:16:27 -0800 | [diff] [blame] | 365 | std::unique_ptr<Group> mRootNode; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 366 | SkRect mBounds; |
| 367 | SkMatrix mCanvasMatrix; |
| 368 | SkPaint mPaint; |
| 369 | SkPathMeasure mPathMeasure; |
| 370 | SkBitmap mCachedBitmap; |
| 371 | |
| 372 | }; |
| 373 | |
| 374 | } // namespace VectorDrawable |
| 375 | |
| 376 | typedef VectorDrawable::Path::Data PathData; |
| 377 | } // namespace uirenderer |
| 378 | } // namespace android |
| 379 | |
| 380 | #endif // ANDROID_HWUI_VPATH_H |