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(); |
Doris Liu | c2de46f | 2016-01-21 12:55:54 -0800 | [diff] [blame] | 99 | virtual void drawPath(SkCanvas *outCanvas, const 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; |
| 121 | }; |
| 122 | |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 123 | FullPath(const FullPath& path); // for cloning |
| 124 | FullPath(const char* path, size_t strLength) : Path(path, strLength) {} |
| 125 | FullPath() : Path() {} |
| 126 | FullPath(const Data& nodes) : Path(nodes) {} |
| 127 | |
Teng-Hui Zhu | dbee9bb | 2015-12-15 11:01:27 -0800 | [diff] [blame] | 128 | ~FullPath() { |
| 129 | SkSafeUnref(mFillGradient); |
| 130 | SkSafeUnref(mStrokeGradient); |
| 131 | } |
| 132 | |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 133 | void updateProperties(float strokeWidth, SkColor strokeColor, |
| 134 | float strokeAlpha, SkColor fillColor, float fillAlpha, |
| 135 | float trimPathStart, float trimPathEnd, float trimPathOffset, |
| 136 | float strokeMiterLimit, int strokeLineCap, int strokeLineJoin); |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 137 | // 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] | 138 | float getStrokeWidth() { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 139 | return mProperties.strokeWidth; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 140 | } |
| 141 | void setStrokeWidth(float strokeWidth) { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 142 | mProperties.strokeWidth = strokeWidth; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 143 | } |
| 144 | SkColor getStrokeColor() { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 145 | return mProperties.strokeColor; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 146 | } |
| 147 | void setStrokeColor(SkColor strokeColor) { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 148 | mProperties.strokeColor = strokeColor; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 149 | } |
| 150 | float getStrokeAlpha() { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 151 | return mProperties.strokeAlpha; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 152 | } |
| 153 | void setStrokeAlpha(float strokeAlpha) { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 154 | mProperties.strokeAlpha = strokeAlpha; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 155 | } |
| 156 | SkColor getFillColor() { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 157 | return mProperties.fillColor; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 158 | } |
| 159 | void setFillColor(SkColor fillColor) { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 160 | mProperties.fillColor = fillColor; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 161 | } |
| 162 | float getFillAlpha() { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 163 | return mProperties.fillAlpha; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 164 | } |
| 165 | void setFillAlpha(float fillAlpha) { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 166 | mProperties.fillAlpha = fillAlpha; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 167 | } |
| 168 | float getTrimPathStart() { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 169 | return mProperties.trimPathStart; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 170 | } |
| 171 | void setTrimPathStart(float trimPathStart) { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 172 | VD_SET_PROP_WITH_FLAG(mProperties.trimPathStart, trimPathStart, mTrimDirty); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 173 | } |
| 174 | float getTrimPathEnd() { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 175 | return mProperties.trimPathEnd; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 176 | } |
| 177 | void setTrimPathEnd(float trimPathEnd) { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 178 | VD_SET_PROP_WITH_FLAG(mProperties.trimPathEnd, trimPathEnd, mTrimDirty); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 179 | } |
| 180 | float getTrimPathOffset() { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 181 | return mProperties.trimPathOffset; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 182 | } |
| 183 | void setTrimPathOffset(float trimPathOffset) { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 184 | VD_SET_PROP_WITH_FLAG(mProperties.trimPathOffset, trimPathOffset, mTrimDirty); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 185 | } |
| 186 | bool getProperties(int8_t* outProperties, int length); |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 187 | void setColorPropertyValue(int propertyId, int32_t value); |
| 188 | void setPropertyValue(int propertyId, float value); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 189 | |
Teng-Hui Zhu | dbee9bb | 2015-12-15 11:01:27 -0800 | [diff] [blame] | 190 | void setFillGradient(SkShader* fillGradient) { |
| 191 | SkRefCnt_SafeAssign(mFillGradient, fillGradient); |
| 192 | }; |
| 193 | void setStrokeGradient(SkShader* strokeGradient) { |
| 194 | SkRefCnt_SafeAssign(mStrokeGradient, strokeGradient); |
| 195 | }; |
| 196 | |
| 197 | |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 198 | protected: |
| 199 | const SkPath& getUpdatedPath() override; |
Doris Liu | c2de46f | 2016-01-21 12:55:54 -0800 | [diff] [blame] | 200 | void drawPath(SkCanvas* outCanvas, const SkPath& renderPath, |
Teng-Hui Zhu | dbee9bb | 2015-12-15 11:01:27 -0800 | [diff] [blame] | 201 | float strokeScale, const SkMatrix& matrix) override; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 202 | |
| 203 | private: |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 204 | enum class Property { |
| 205 | StrokeWidth = 0, |
| 206 | StrokeColor, |
| 207 | StrokeAlpha, |
| 208 | FillColor, |
| 209 | FillAlpha, |
| 210 | TrimPathStart, |
| 211 | TrimPathEnd, |
| 212 | TrimPathOffset, |
| 213 | StrokeLineCap, |
| 214 | StrokeLineJoin, |
| 215 | StrokeMiterLimit, |
| 216 | Count, |
| 217 | }; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 218 | // Applies trimming to the specified path. |
| 219 | void applyTrim(); |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 220 | Properties mProperties; |
Doris Liu | 5a11e8d | 2016-02-04 20:04:10 +0000 | [diff] [blame] | 221 | bool mTrimDirty = true; |
Doris Liu | 5a11e8d | 2016-02-04 20:04:10 +0000 | [diff] [blame] | 222 | SkPath mTrimmedSkPath; |
| 223 | SkPaint mPaint; |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 224 | SkShader* mStrokeGradient = nullptr; |
| 225 | SkShader* mFillGradient = nullptr; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 226 | }; |
| 227 | |
| 228 | class ANDROID_API ClipPath: public Path { |
| 229 | public: |
| 230 | ClipPath(const ClipPath& path) : Path(path) {} |
| 231 | ClipPath(const char* path, size_t strLength) : Path(path, strLength) {} |
| 232 | ClipPath() : Path() {} |
| 233 | ClipPath(const Data& nodes) : Path(nodes) {} |
| 234 | |
| 235 | protected: |
Doris Liu | c2de46f | 2016-01-21 12:55:54 -0800 | [diff] [blame] | 236 | void drawPath(SkCanvas* outCanvas, const SkPath& renderPath, |
Teng-Hui Zhu | dbee9bb | 2015-12-15 11:01:27 -0800 | [diff] [blame] | 237 | float strokeScale, const SkMatrix& matrix) override; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 238 | }; |
| 239 | |
| 240 | class ANDROID_API Group: public Node { |
| 241 | public: |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 242 | struct Properties { |
| 243 | float rotate = 0; |
| 244 | float pivotX = 0; |
| 245 | float pivotY = 0; |
| 246 | float scaleX = 1; |
| 247 | float scaleY = 1; |
| 248 | float translateX = 0; |
| 249 | float translateY = 0; |
| 250 | }; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 251 | Group(const Group& group); |
| 252 | Group() {} |
| 253 | float getRotation() { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 254 | return mProperties.rotate; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 255 | } |
| 256 | void setRotation(float rotation) { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 257 | mProperties.rotate = rotation; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 258 | } |
| 259 | float getPivotX() { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 260 | return mProperties.pivotX; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 261 | } |
| 262 | void setPivotX(float pivotX) { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 263 | mProperties.pivotX = pivotX; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 264 | } |
| 265 | float getPivotY() { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 266 | return mProperties.pivotY; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 267 | } |
| 268 | void setPivotY(float pivotY) { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 269 | mProperties.pivotY = pivotY; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 270 | } |
| 271 | float getScaleX() { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 272 | return mProperties.scaleX; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 273 | } |
| 274 | void setScaleX(float scaleX) { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 275 | mProperties.scaleX = scaleX; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 276 | } |
| 277 | float getScaleY() { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 278 | return mProperties.scaleY; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 279 | } |
| 280 | void setScaleY(float scaleY) { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 281 | mProperties.scaleY = scaleY; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 282 | } |
| 283 | float getTranslateX() { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 284 | return mProperties.translateX; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 285 | } |
| 286 | void setTranslateX(float translateX) { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 287 | mProperties.translateX = translateX; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 288 | } |
| 289 | float getTranslateY() { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 290 | return mProperties.translateY; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 291 | } |
| 292 | void setTranslateY(float translateY) { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 293 | mProperties.translateY = translateY; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 294 | } |
Doris Liu | c2de46f | 2016-01-21 12:55:54 -0800 | [diff] [blame] | 295 | virtual void draw(SkCanvas* outCanvas, const SkMatrix& currentMatrix, |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 296 | float scaleX, float scaleY) override; |
| 297 | void updateLocalMatrix(float rotate, float pivotX, float pivotY, |
| 298 | float scaleX, float scaleY, float translateX, float translateY); |
| 299 | void getLocalMatrix(SkMatrix* outMatrix); |
| 300 | void addChild(Node* child); |
| 301 | void dump() override; |
| 302 | bool getProperties(float* outProperties, int length); |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 303 | float getPropertyValue(int propertyId) const; |
| 304 | void setPropertyValue(int propertyId, float value); |
| 305 | static bool isValidProperty(int propertyId); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 306 | |
| 307 | private: |
| 308 | enum class Property { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 309 | Rotate = 0, |
| 310 | PivotX, |
| 311 | PivotY, |
| 312 | ScaleX, |
| 313 | ScaleY, |
| 314 | TranslateX, |
| 315 | TranslateY, |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 316 | // Count of the properties, must be at the end. |
| 317 | Count, |
| 318 | }; |
Doris Liu | ef062eb | 2016-02-04 16:16:27 -0800 | [diff] [blame] | 319 | std::vector< std::unique_ptr<Node> > mChildren; |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 320 | Properties mProperties; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 321 | }; |
| 322 | |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 323 | class ANDROID_API Tree : public VirtualLightRefBase { |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 324 | public: |
| 325 | Tree(Group* rootNode) : mRootNode(rootNode) {} |
| 326 | void draw(Canvas* outCanvas, SkColorFilter* colorFilter, |
| 327 | const SkRect& bounds, bool needsMirroring, bool canReuseCache); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 328 | |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 329 | const SkBitmap& getBitmapUpdateIfDirty(); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 330 | void createCachedBitmapIfNeeded(int width, int height); |
| 331 | bool canReuseBitmap(int width, int height); |
| 332 | void setAllowCaching(bool allowCaching) { |
| 333 | mAllowCaching = allowCaching; |
| 334 | } |
| 335 | bool setRootAlpha(float rootAlpha) { |
| 336 | return VD_SET_PROP(mRootAlpha, rootAlpha); |
| 337 | } |
| 338 | |
| 339 | float getRootAlpha() { |
| 340 | return mRootAlpha; |
| 341 | } |
| 342 | void setViewportSize(float viewportWidth, float viewportHeight) { |
| 343 | mViewportWidth = viewportWidth; |
| 344 | mViewportHeight = viewportHeight; |
| 345 | } |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 346 | SkPaint* getPaint(); |
| 347 | const SkRect& getBounds() const { |
| 348 | return mBounds; |
| 349 | } |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 350 | |
| 351 | private: |
| 352 | // Cap the bitmap size, such that it won't hurt the performance too much |
| 353 | // and it won't crash due to a very large scale. |
| 354 | // The drawable will look blurry above this size. |
| 355 | const static int MAX_CACHED_BITMAP_SIZE; |
| 356 | |
| 357 | bool mCacheDirty = true; |
| 358 | bool mAllowCaching = true; |
| 359 | float mViewportWidth = 0; |
| 360 | float mViewportHeight = 0; |
| 361 | float mRootAlpha = 1.0f; |
| 362 | |
Doris Liu | ef062eb | 2016-02-04 16:16:27 -0800 | [diff] [blame] | 363 | std::unique_ptr<Group> mRootNode; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 364 | SkRect mBounds; |
| 365 | SkMatrix mCanvasMatrix; |
| 366 | SkPaint mPaint; |
| 367 | SkPathMeasure mPathMeasure; |
| 368 | SkBitmap mCachedBitmap; |
| 369 | |
| 370 | }; |
| 371 | |
| 372 | } // namespace VectorDrawable |
| 373 | |
| 374 | typedef VectorDrawable::Path::Data PathData; |
| 375 | } // namespace uirenderer |
| 376 | } // namespace android |
| 377 | |
| 378 | #endif // ANDROID_HWUI_VPATH_H |