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 | #include "VectorDrawable.h" |
| 18 | |
| 19 | #include "PathParser.h" |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 20 | #include "SkColorFilter.h" |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 21 | #include "SkImageInfo.h" |
Teng-Hui Zhu | dbee9bb | 2015-12-15 11:01:27 -0800 | [diff] [blame] | 22 | #include "SkShader.h" |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 23 | #include <utils/Log.h> |
| 24 | #include "utils/Macros.h" |
| 25 | #include "utils/VectorDrawableUtils.h" |
| 26 | |
| 27 | #include <math.h> |
| 28 | #include <string.h> |
| 29 | |
| 30 | namespace android { |
| 31 | namespace uirenderer { |
| 32 | namespace VectorDrawable { |
| 33 | |
| 34 | const int Tree::MAX_CACHED_BITMAP_SIZE = 2048; |
| 35 | |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 36 | void Path::draw(SkCanvas* outCanvas, const SkMatrix& groupStackedMatrix, float scaleX, float scaleY, |
| 37 | bool useStagingData) { |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 38 | float matrixScale = getMatrixScale(groupStackedMatrix); |
| 39 | if (matrixScale == 0) { |
| 40 | // When either x or y is scaled to 0, we don't need to draw anything. |
| 41 | return; |
| 42 | } |
| 43 | |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 44 | SkMatrix pathMatrix(groupStackedMatrix); |
| 45 | pathMatrix.postScale(scaleX, scaleY); |
| 46 | |
| 47 | //TODO: try apply the path matrix to the canvas instead of creating a new path. |
| 48 | SkPath renderPath; |
| 49 | renderPath.reset(); |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 50 | |
| 51 | if (useStagingData) { |
| 52 | SkPath tmpPath; |
| 53 | getStagingPath(&tmpPath); |
| 54 | renderPath.addPath(tmpPath, pathMatrix); |
| 55 | } else { |
| 56 | renderPath.addPath(getUpdatedPath(), pathMatrix); |
| 57 | } |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 58 | |
| 59 | float minScale = fmin(scaleX, scaleY); |
| 60 | float strokeScale = minScale * matrixScale; |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 61 | drawPath(outCanvas, renderPath, strokeScale, pathMatrix, useStagingData); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | void Path::dump() { |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 65 | ALOGD("Path: %s has %zu points", mName.c_str(), mProperties.getData().points.size()); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | float Path::getMatrixScale(const SkMatrix& groupStackedMatrix) { |
| 69 | // Given unit vectors A = (0, 1) and B = (1, 0). |
| 70 | // After matrix mapping, we got A' and B'. Let theta = the angel b/t A' and B'. |
| 71 | // Therefore, the final scale we want is min(|A'| * sin(theta), |B'| * sin(theta)), |
| 72 | // which is (|A'| * |B'| * sin(theta)) / max (|A'|, |B'|); |
| 73 | // If max (|A'|, |B'|) = 0, that means either x or y has a scale of 0. |
| 74 | // |
| 75 | // For non-skew case, which is most of the cases, matrix scale is computing exactly the |
| 76 | // scale on x and y axis, and take the minimal of these two. |
| 77 | // For skew case, an unit square will mapped to a parallelogram. And this function will |
| 78 | // return the minimal height of the 2 bases. |
| 79 | SkVector skVectors[2]; |
| 80 | skVectors[0].set(0, 1); |
| 81 | skVectors[1].set(1, 0); |
| 82 | groupStackedMatrix.mapVectors(skVectors, 2); |
| 83 | float scaleX = hypotf(skVectors[0].fX, skVectors[0].fY); |
| 84 | float scaleY = hypotf(skVectors[1].fX, skVectors[1].fY); |
| 85 | float crossProduct = skVectors[0].cross(skVectors[1]); |
| 86 | float maxScale = fmax(scaleX, scaleY); |
| 87 | |
| 88 | float matrixScale = 0; |
| 89 | if (maxScale > 0) { |
| 90 | matrixScale = fabs(crossProduct) / maxScale; |
| 91 | } |
| 92 | return matrixScale; |
| 93 | } |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 94 | |
| 95 | // Called from UI thread during the initial setup/theme change. |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 96 | Path::Path(const char* pathStr, size_t strLength) { |
| 97 | PathParser::ParseResult result; |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 98 | Data data; |
Doris Liu | b35da39 | 2016-04-12 11:06:23 -0700 | [diff] [blame] | 99 | PathParser::getPathDataFromAsciiString(&data, &result, pathStr, strLength); |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 100 | mStagingProperties.setData(data); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | Path::Path(const Path& path) : Node(path) { |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 104 | mStagingProperties.syncProperties(path.mStagingProperties); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | const SkPath& Path::getUpdatedPath() { |
| 108 | if (mSkPathDirty) { |
| 109 | mSkPath.reset(); |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 110 | VectorDrawableUtils::verbsToPath(&mSkPath, mProperties.getData()); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 111 | mSkPathDirty = false; |
| 112 | } |
| 113 | return mSkPath; |
| 114 | } |
| 115 | |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 116 | void Path::getStagingPath(SkPath* outPath) { |
| 117 | outPath->reset(); |
| 118 | VectorDrawableUtils::verbsToPath(outPath, mStagingProperties.getData()); |
| 119 | } |
| 120 | |
| 121 | void Path::syncProperties() { |
| 122 | if (mStagingPropertiesDirty) { |
| 123 | mProperties.syncProperties(mStagingProperties); |
| 124 | } else { |
| 125 | mStagingProperties.syncProperties(mProperties); |
| 126 | } |
| 127 | mStagingPropertiesDirty = false; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | FullPath::FullPath(const FullPath& path) : Path(path) { |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 131 | mStagingProperties.syncProperties(path.mStagingProperties); |
| 132 | } |
| 133 | |
| 134 | static void applyTrim(SkPath* outPath, const SkPath& inPath, float trimPathStart, float trimPathEnd, |
| 135 | float trimPathOffset) { |
| 136 | if (trimPathStart == 0.0f && trimPathEnd == 1.0f) { |
| 137 | *outPath = inPath; |
| 138 | return; |
| 139 | } |
| 140 | outPath->reset(); |
| 141 | if (trimPathStart == trimPathEnd) { |
| 142 | // Trimmed path should be empty. |
| 143 | return; |
| 144 | } |
| 145 | SkPathMeasure measure(inPath, false); |
| 146 | float len = SkScalarToFloat(measure.getLength()); |
| 147 | float start = len * fmod((trimPathStart + trimPathOffset), 1.0f); |
| 148 | float end = len * fmod((trimPathEnd + trimPathOffset), 1.0f); |
| 149 | |
| 150 | if (start > end) { |
| 151 | measure.getSegment(start, len, outPath, true); |
| 152 | if (end > 0) { |
| 153 | measure.getSegment(0, end, outPath, true); |
| 154 | } |
| 155 | } else { |
| 156 | measure.getSegment(start, end, outPath, true); |
| 157 | } |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | const SkPath& FullPath::getUpdatedPath() { |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 161 | if (!mSkPathDirty && !mProperties.mTrimDirty) { |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 162 | return mTrimmedSkPath; |
| 163 | } |
| 164 | Path::getUpdatedPath(); |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 165 | if (mProperties.getTrimPathStart() != 0.0f || mProperties.getTrimPathEnd() != 1.0f) { |
| 166 | mProperties.mTrimDirty = false; |
| 167 | applyTrim(&mTrimmedSkPath, mSkPath, mProperties.getTrimPathStart(), |
| 168 | mProperties.getTrimPathEnd(), mProperties.getTrimPathOffset()); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 169 | return mTrimmedSkPath; |
| 170 | } else { |
| 171 | return mSkPath; |
| 172 | } |
| 173 | } |
| 174 | |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 175 | void FullPath::getStagingPath(SkPath* outPath) { |
| 176 | Path::getStagingPath(outPath); |
| 177 | SkPath inPath = *outPath; |
| 178 | applyTrim(outPath, inPath, mStagingProperties.getTrimPathStart(), |
| 179 | mStagingProperties.getTrimPathEnd(), mStagingProperties.getTrimPathOffset()); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 180 | } |
| 181 | |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 182 | void FullPath::dump() { |
| 183 | Path::dump(); |
| 184 | ALOGD("stroke width, color, alpha: %f, %d, %f, fill color, alpha: %d, %f", |
| 185 | mProperties.getStrokeWidth(), mProperties.getStrokeColor(), mProperties.getStrokeAlpha(), |
| 186 | mProperties.getFillColor(), mProperties.getFillAlpha()); |
| 187 | } |
| 188 | |
| 189 | |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 190 | inline SkColor applyAlpha(SkColor color, float alpha) { |
| 191 | int alphaBytes = SkColorGetA(color); |
| 192 | return SkColorSetA(color, alphaBytes * alpha); |
| 193 | } |
| 194 | |
Teng-Hui Zhu | 46591f4 | 2016-03-15 14:32:16 -0700 | [diff] [blame] | 195 | void FullPath::drawPath(SkCanvas* outCanvas, SkPath& renderPath, float strokeScale, |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 196 | const SkMatrix& matrix, bool useStagingData){ |
| 197 | const FullPathProperties& properties = useStagingData ? mStagingProperties : mProperties; |
| 198 | |
Teng-Hui Zhu | dbee9bb | 2015-12-15 11:01:27 -0800 | [diff] [blame] | 199 | // Draw path's fill, if fill color or gradient is valid |
| 200 | bool needsFill = false; |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 201 | SkPaint paint; |
| 202 | if (properties.getFillGradient() != nullptr) { |
| 203 | paint.setColor(applyAlpha(SK_ColorBLACK, properties.getFillAlpha())); |
Mike Reed | 260ab72 | 2016-10-07 15:59:20 -0400 | [diff] [blame] | 204 | paint.setShader(properties.getFillGradient()->makeWithLocalMatrix(matrix)); |
Teng-Hui Zhu | dbee9bb | 2015-12-15 11:01:27 -0800 | [diff] [blame] | 205 | needsFill = true; |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 206 | } else if (properties.getFillColor() != SK_ColorTRANSPARENT) { |
| 207 | paint.setColor(applyAlpha(properties.getFillColor(), properties.getFillAlpha())); |
Teng-Hui Zhu | dbee9bb | 2015-12-15 11:01:27 -0800 | [diff] [blame] | 208 | needsFill = true; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 209 | } |
Teng-Hui Zhu | dbee9bb | 2015-12-15 11:01:27 -0800 | [diff] [blame] | 210 | |
| 211 | if (needsFill) { |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 212 | paint.setStyle(SkPaint::Style::kFill_Style); |
| 213 | paint.setAntiAlias(true); |
| 214 | SkPath::FillType ft = static_cast<SkPath::FillType>(properties.getFillType()); |
Teng-Hui Zhu | 46591f4 | 2016-03-15 14:32:16 -0700 | [diff] [blame] | 215 | renderPath.setFillType(ft); |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 216 | outCanvas->drawPath(renderPath, paint); |
Teng-Hui Zhu | dbee9bb | 2015-12-15 11:01:27 -0800 | [diff] [blame] | 217 | } |
| 218 | |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 219 | // Draw path's stroke, if stroke color or Gradient is valid |
Teng-Hui Zhu | dbee9bb | 2015-12-15 11:01:27 -0800 | [diff] [blame] | 220 | bool needsStroke = false; |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 221 | if (properties.getStrokeGradient() != nullptr) { |
| 222 | paint.setColor(applyAlpha(SK_ColorBLACK, properties.getStrokeAlpha())); |
Mike Reed | 260ab72 | 2016-10-07 15:59:20 -0400 | [diff] [blame] | 223 | paint.setShader(properties.getStrokeGradient()->makeWithLocalMatrix(matrix)); |
Teng-Hui Zhu | dbee9bb | 2015-12-15 11:01:27 -0800 | [diff] [blame] | 224 | needsStroke = true; |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 225 | } else if (properties.getStrokeColor() != SK_ColorTRANSPARENT) { |
| 226 | paint.setColor(applyAlpha(properties.getStrokeColor(), properties.getStrokeAlpha())); |
Teng-Hui Zhu | dbee9bb | 2015-12-15 11:01:27 -0800 | [diff] [blame] | 227 | needsStroke = true; |
| 228 | } |
| 229 | if (needsStroke) { |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 230 | paint.setStyle(SkPaint::Style::kStroke_Style); |
| 231 | paint.setAntiAlias(true); |
| 232 | paint.setStrokeJoin(SkPaint::Join(properties.getStrokeLineJoin())); |
| 233 | paint.setStrokeCap(SkPaint::Cap(properties.getStrokeLineCap())); |
| 234 | paint.setStrokeMiter(properties.getStrokeMiterLimit()); |
| 235 | paint.setStrokeWidth(properties.getStrokeWidth() * strokeScale); |
| 236 | outCanvas->drawPath(renderPath, paint); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 237 | } |
| 238 | } |
| 239 | |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 240 | void FullPath::syncProperties() { |
| 241 | Path::syncProperties(); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 242 | |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 243 | if (mStagingPropertiesDirty) { |
| 244 | mProperties.syncProperties(mStagingProperties); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 245 | } else { |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 246 | // Update staging property with property values from animation. |
| 247 | mStagingProperties.syncProperties(mProperties); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 248 | } |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 249 | mStagingPropertiesDirty = false; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 250 | } |
| 251 | |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 252 | REQUIRE_COMPATIBLE_LAYOUT(FullPath::FullPathProperties::PrimitiveFields); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 253 | |
| 254 | static_assert(sizeof(float) == sizeof(int32_t), "float is not the same size as int32_t"); |
| 255 | static_assert(sizeof(SkColor) == sizeof(int32_t), "SkColor is not the same size as int32_t"); |
| 256 | |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 257 | bool FullPath::FullPathProperties::copyProperties(int8_t* outProperties, int length) const { |
| 258 | int propertyDataSize = sizeof(FullPathProperties::PrimitiveFields); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 259 | if (length != propertyDataSize) { |
| 260 | LOG_ALWAYS_FATAL("Properties needs exactly %d bytes, a byte array of size %d is provided", |
| 261 | propertyDataSize, length); |
| 262 | return false; |
| 263 | } |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 264 | |
| 265 | PrimitiveFields* out = reinterpret_cast<PrimitiveFields*>(outProperties); |
| 266 | *out = mPrimitiveFields; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 267 | return true; |
| 268 | } |
| 269 | |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 270 | void FullPath::FullPathProperties::setColorPropertyValue(int propertyId, int32_t value) { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 271 | Property currentProperty = static_cast<Property>(propertyId); |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 272 | if (currentProperty == Property::strokeColor) { |
| 273 | setStrokeColor(value); |
| 274 | } else if (currentProperty == Property::fillColor) { |
| 275 | setFillColor(value); |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 276 | } else { |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 277 | LOG_ALWAYS_FATAL("Error setting color property on FullPath: No valid property" |
| 278 | " with id: %d", propertyId); |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 279 | } |
| 280 | } |
| 281 | |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 282 | void FullPath::FullPathProperties::setPropertyValue(int propertyId, float value) { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 283 | Property property = static_cast<Property>(propertyId); |
| 284 | switch (property) { |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 285 | case Property::strokeWidth: |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 286 | setStrokeWidth(value); |
| 287 | break; |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 288 | case Property::strokeAlpha: |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 289 | setStrokeAlpha(value); |
| 290 | break; |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 291 | case Property::fillAlpha: |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 292 | setFillAlpha(value); |
| 293 | break; |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 294 | case Property::trimPathStart: |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 295 | setTrimPathStart(value); |
| 296 | break; |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 297 | case Property::trimPathEnd: |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 298 | setTrimPathEnd(value); |
| 299 | break; |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 300 | case Property::trimPathOffset: |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 301 | setTrimPathOffset(value); |
| 302 | break; |
| 303 | default: |
| 304 | LOG_ALWAYS_FATAL("Invalid property id: %d for animation", propertyId); |
| 305 | break; |
| 306 | } |
| 307 | } |
| 308 | |
Teng-Hui Zhu | 46591f4 | 2016-03-15 14:32:16 -0700 | [diff] [blame] | 309 | void ClipPath::drawPath(SkCanvas* outCanvas, SkPath& renderPath, |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 310 | float strokeScale, const SkMatrix& matrix, bool useStagingData){ |
Doris Liu | c2de46f | 2016-01-21 12:55:54 -0800 | [diff] [blame] | 311 | outCanvas->clipPath(renderPath, SkRegion::kIntersect_Op); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | Group::Group(const Group& group) : Node(group) { |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 315 | mStagingProperties.syncProperties(group.mStagingProperties); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 316 | } |
| 317 | |
Doris Liu | c2de46f | 2016-01-21 12:55:54 -0800 | [diff] [blame] | 318 | void Group::draw(SkCanvas* outCanvas, const SkMatrix& currentMatrix, float scaleX, |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 319 | float scaleY, bool useStagingData) { |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 320 | // TODO: Try apply the matrix to the canvas instead of passing it down the tree |
| 321 | |
| 322 | // Calculate current group's matrix by preConcat the parent's and |
| 323 | // and the current one on the top of the stack. |
| 324 | // Basically the Mfinal = Mviewport * M0 * M1 * M2; |
| 325 | // Mi the local matrix at level i of the group tree. |
| 326 | SkMatrix stackedMatrix; |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 327 | const GroupProperties& prop = useStagingData ? mStagingProperties : mProperties; |
| 328 | getLocalMatrix(&stackedMatrix, prop); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 329 | stackedMatrix.postConcat(currentMatrix); |
| 330 | |
| 331 | // Save the current clip information, which is local to this group. |
Doris Liu | c2de46f | 2016-01-21 12:55:54 -0800 | [diff] [blame] | 332 | outCanvas->save(); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 333 | // Draw the group tree in the same order as the XML file. |
Doris Liu | ef062eb | 2016-02-04 16:16:27 -0800 | [diff] [blame] | 334 | for (auto& child : mChildren) { |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 335 | child->draw(outCanvas, stackedMatrix, scaleX, scaleY, useStagingData); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 336 | } |
| 337 | // Restore the previous clip information. |
| 338 | outCanvas->restore(); |
| 339 | } |
| 340 | |
| 341 | void Group::dump() { |
| 342 | ALOGD("Group %s has %zu children: ", mName.c_str(), mChildren.size()); |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 343 | ALOGD("Group translateX, Y : %f, %f, scaleX, Y: %f, %f", mProperties.getTranslateX(), |
| 344 | mProperties.getTranslateY(), mProperties.getScaleX(), mProperties.getScaleY()); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 345 | for (size_t i = 0; i < mChildren.size(); i++) { |
| 346 | mChildren[i]->dump(); |
| 347 | } |
| 348 | } |
| 349 | |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 350 | void Group::syncProperties() { |
| 351 | // Copy over the dirty staging properties |
| 352 | if (mStagingPropertiesDirty) { |
| 353 | mProperties.syncProperties(mStagingProperties); |
| 354 | } else { |
| 355 | mStagingProperties.syncProperties(mProperties); |
| 356 | } |
| 357 | mStagingPropertiesDirty = false; |
| 358 | for (auto& child : mChildren) { |
| 359 | child->syncProperties(); |
| 360 | } |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 361 | } |
| 362 | |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 363 | void Group::getLocalMatrix(SkMatrix* outMatrix, const GroupProperties& properties) { |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 364 | outMatrix->reset(); |
| 365 | // TODO: use rotate(mRotate, mPivotX, mPivotY) and scale with pivot point, instead of |
| 366 | // translating to pivot for rotating and scaling, then translating back. |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 367 | outMatrix->postTranslate(-properties.getPivotX(), -properties.getPivotY()); |
| 368 | outMatrix->postScale(properties.getScaleX(), properties.getScaleY()); |
| 369 | outMatrix->postRotate(properties.getRotation(), 0, 0); |
| 370 | outMatrix->postTranslate(properties.getTranslateX() + properties.getPivotX(), |
| 371 | properties.getTranslateY() + properties.getPivotY()); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | void Group::addChild(Node* child) { |
Doris Liu | ef062eb | 2016-02-04 16:16:27 -0800 | [diff] [blame] | 375 | mChildren.emplace_back(child); |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 376 | if (mPropertyChangedListener != nullptr) { |
| 377 | child->setPropertyChangedListener(mPropertyChangedListener); |
| 378 | } |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 379 | } |
| 380 | |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 381 | bool Group::GroupProperties::copyProperties(float* outProperties, int length) const { |
| 382 | int propertyCount = static_cast<int>(Property::count); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 383 | if (length != propertyCount) { |
| 384 | LOG_ALWAYS_FATAL("Properties needs exactly %d bytes, a byte array of size %d is provided", |
| 385 | propertyCount, length); |
| 386 | return false; |
| 387 | } |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 388 | |
| 389 | PrimitiveFields* out = reinterpret_cast<PrimitiveFields*>(outProperties); |
| 390 | *out = mPrimitiveFields; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 391 | return true; |
| 392 | } |
| 393 | |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 394 | // TODO: Consider animating the properties as float pointers |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 395 | // Called on render thread |
| 396 | float Group::GroupProperties::getPropertyValue(int propertyId) const { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 397 | Property currentProperty = static_cast<Property>(propertyId); |
| 398 | switch (currentProperty) { |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 399 | case Property::rotate: |
| 400 | return getRotation(); |
| 401 | case Property::pivotX: |
| 402 | return getPivotX(); |
| 403 | case Property::pivotY: |
| 404 | return getPivotY(); |
| 405 | case Property::scaleX: |
| 406 | return getScaleX(); |
| 407 | case Property::scaleY: |
| 408 | return getScaleY(); |
| 409 | case Property::translateX: |
| 410 | return getTranslateX(); |
| 411 | case Property::translateY: |
| 412 | return getTranslateY(); |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 413 | default: |
| 414 | LOG_ALWAYS_FATAL("Invalid property index: %d", propertyId); |
| 415 | return 0; |
| 416 | } |
| 417 | } |
| 418 | |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 419 | // Called on render thread |
| 420 | void Group::GroupProperties::setPropertyValue(int propertyId, float value) { |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 421 | Property currentProperty = static_cast<Property>(propertyId); |
| 422 | switch (currentProperty) { |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 423 | case Property::rotate: |
| 424 | setRotation(value); |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 425 | break; |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 426 | case Property::pivotX: |
| 427 | setPivotX(value); |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 428 | break; |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 429 | case Property::pivotY: |
| 430 | setPivotY(value); |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 431 | break; |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 432 | case Property::scaleX: |
| 433 | setScaleX(value); |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 434 | break; |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 435 | case Property::scaleY: |
| 436 | setScaleY(value); |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 437 | break; |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 438 | case Property::translateX: |
| 439 | setTranslateX(value); |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 440 | break; |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 441 | case Property::translateY: |
| 442 | setTranslateY(value); |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 443 | break; |
| 444 | default: |
| 445 | LOG_ALWAYS_FATAL("Invalid property index: %d", propertyId); |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | bool Group::isValidProperty(int propertyId) { |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 450 | return GroupProperties::isValidProperty(propertyId); |
| 451 | } |
| 452 | |
| 453 | bool Group::GroupProperties::isValidProperty(int propertyId) { |
| 454 | return propertyId >= 0 && propertyId < static_cast<int>(Property::count); |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 455 | } |
| 456 | |
Doris Liu | f8d131c | 2016-04-29 18:41:29 -0700 | [diff] [blame] | 457 | int Tree::draw(Canvas* outCanvas, SkColorFilter* colorFilter, |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 458 | const SkRect& bounds, bool needsMirroring, bool canReuseCache) { |
| 459 | // The imageView can scale the canvas in different ways, in order to |
| 460 | // avoid blurry scaling, we have to draw into a bitmap with exact pixel |
| 461 | // size first. This bitmap size is determined by the bounds and the |
| 462 | // canvas scale. |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 463 | SkMatrix canvasMatrix; |
| 464 | outCanvas->getMatrix(&canvasMatrix); |
Doris Liu | a0e6157 | 2015-12-29 14:57:49 -0800 | [diff] [blame] | 465 | float canvasScaleX = 1.0f; |
| 466 | float canvasScaleY = 1.0f; |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 467 | if (canvasMatrix.getSkewX() == 0 && canvasMatrix.getSkewY() == 0) { |
Doris Liu | a0e6157 | 2015-12-29 14:57:49 -0800 | [diff] [blame] | 468 | // Only use the scale value when there's no skew or rotation in the canvas matrix. |
Doris Liu | e410a35 | 2016-01-13 17:23:33 -0800 | [diff] [blame] | 469 | // TODO: Add a cts test for drawing VD on a canvas with negative scaling factors. |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 470 | canvasScaleX = fabs(canvasMatrix.getScaleX()); |
| 471 | canvasScaleY = fabs(canvasMatrix.getScaleY()); |
Doris Liu | a0e6157 | 2015-12-29 14:57:49 -0800 | [diff] [blame] | 472 | } |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 473 | int scaledWidth = (int) (bounds.width() * canvasScaleX); |
| 474 | int scaledHeight = (int) (bounds.height() * canvasScaleY); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 475 | scaledWidth = std::min(Tree::MAX_CACHED_BITMAP_SIZE, scaledWidth); |
| 476 | scaledHeight = std::min(Tree::MAX_CACHED_BITMAP_SIZE, scaledHeight); |
| 477 | |
| 478 | if (scaledWidth <= 0 || scaledHeight <= 0) { |
Doris Liu | f8d131c | 2016-04-29 18:41:29 -0700 | [diff] [blame] | 479 | return 0; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 480 | } |
| 481 | |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 482 | mStagingProperties.setScaledSize(scaledWidth, scaledHeight); |
Florin Malita | 777bf85 | 2016-02-03 10:48:55 -0500 | [diff] [blame] | 483 | int saveCount = outCanvas->save(SaveFlags::MatrixClip); |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 484 | outCanvas->translate(bounds.fLeft, bounds.fTop); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 485 | |
| 486 | // Handle RTL mirroring. |
| 487 | if (needsMirroring) { |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 488 | outCanvas->translate(bounds.width(), 0); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 489 | outCanvas->scale(-1.0f, 1.0f); |
| 490 | } |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 491 | mStagingProperties.setColorFilter(colorFilter); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 492 | |
| 493 | // At this point, canvas has been translated to the right position. |
| 494 | // And we use this bound for the destination rect for the drawBitmap, so |
| 495 | // we offset to (0, 0); |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 496 | SkRect tmpBounds = bounds; |
| 497 | tmpBounds.offsetTo(0, 0); |
| 498 | mStagingProperties.setBounds(tmpBounds); |
Doris Liu | 766431a | 2016-02-04 22:17:11 +0000 | [diff] [blame] | 499 | outCanvas->drawVectorDrawable(this); |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 500 | outCanvas->restoreToCount(saveCount); |
Doris Liu | f8d131c | 2016-04-29 18:41:29 -0700 | [diff] [blame] | 501 | return scaledWidth * scaledHeight; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 502 | } |
| 503 | |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 504 | void Tree::drawStaging(Canvas* outCanvas) { |
sergeyv | fc999950 | 2016-10-17 13:07:38 -0700 | [diff] [blame] | 505 | bool redrawNeeded = allocateBitmapIfNeeded(mStagingCache, |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 506 | mStagingProperties.getScaledWidth(), mStagingProperties.getScaledHeight()); |
| 507 | // draw bitmap cache |
| 508 | if (redrawNeeded || mStagingCache.dirty) { |
sergeyv | fc999950 | 2016-10-17 13:07:38 -0700 | [diff] [blame] | 509 | updateBitmapCache(*mStagingCache.bitmap, true); |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 510 | mStagingCache.dirty = false; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 511 | } |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 512 | |
| 513 | SkPaint tmpPaint; |
| 514 | SkPaint* paint = updatePaint(&tmpPaint, &mStagingProperties); |
sergeyv | fc999950 | 2016-10-17 13:07:38 -0700 | [diff] [blame] | 515 | outCanvas->drawBitmap(*mStagingCache.bitmap, 0, 0, |
| 516 | mStagingCache.bitmap->width(), mStagingCache.bitmap->height(), |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 517 | mStagingProperties.getBounds().left(), mStagingProperties.getBounds().top(), |
| 518 | mStagingProperties.getBounds().right(), mStagingProperties.getBounds().bottom(), paint); |
| 519 | } |
| 520 | |
| 521 | SkPaint* Tree::getPaint() { |
| 522 | return updatePaint(&mPaint, &mProperties); |
| 523 | } |
| 524 | |
| 525 | // Update the given paint with alpha and color filter. Return nullptr if no color filter is |
| 526 | // specified and root alpha is 1. Otherwise, return updated paint. |
| 527 | SkPaint* Tree::updatePaint(SkPaint* outPaint, TreeProperties* prop) { |
| 528 | if (prop->getRootAlpha() == 1.0f && prop->getColorFilter() == nullptr) { |
| 529 | return nullptr; |
| 530 | } else { |
Mike Reed | 260ab72 | 2016-10-07 15:59:20 -0400 | [diff] [blame] | 531 | outPaint->setColorFilter(sk_ref_sp(prop->getColorFilter())); |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 532 | outPaint->setFilterQuality(kLow_SkFilterQuality); |
| 533 | outPaint->setAlpha(prop->getRootAlpha() * 255); |
| 534 | return outPaint; |
| 535 | } |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 536 | } |
| 537 | |
sergeyv | fc999950 | 2016-10-17 13:07:38 -0700 | [diff] [blame] | 538 | Bitmap& Tree::getBitmapUpdateIfDirty() { |
| 539 | bool redrawNeeded = allocateBitmapIfNeeded(mCache, mProperties.getScaledWidth(), |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 540 | mProperties.getScaledHeight()); |
| 541 | if (redrawNeeded || mCache.dirty) { |
sergeyv | fc999950 | 2016-10-17 13:07:38 -0700 | [diff] [blame] | 542 | updateBitmapCache(*mCache.bitmap, false); |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 543 | mCache.dirty = false; |
| 544 | } |
sergeyv | fc999950 | 2016-10-17 13:07:38 -0700 | [diff] [blame] | 545 | return *mCache.bitmap; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 546 | } |
| 547 | |
sergeyv | fc999950 | 2016-10-17 13:07:38 -0700 | [diff] [blame] | 548 | void Tree::updateBitmapCache(Bitmap& bitmap, bool useStagingData) { |
| 549 | SkBitmap outCache; |
| 550 | bitmap.getSkBitmap(&outCache); |
| 551 | outCache.eraseColor(SK_ColorTRANSPARENT); |
| 552 | SkCanvas outCanvas(outCache); |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 553 | float viewportWidth = useStagingData ? |
| 554 | mStagingProperties.getViewportWidth() : mProperties.getViewportWidth(); |
| 555 | float viewportHeight = useStagingData ? |
| 556 | mStagingProperties.getViewportHeight() : mProperties.getViewportHeight(); |
sergeyv | fc999950 | 2016-10-17 13:07:38 -0700 | [diff] [blame] | 557 | float scaleX = outCache.width() / viewportWidth; |
| 558 | float scaleY = outCache.height() / viewportHeight; |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 559 | mRootNode->draw(&outCanvas, SkMatrix::I(), scaleX, scaleY, useStagingData); |
| 560 | } |
| 561 | |
sergeyv | fc999950 | 2016-10-17 13:07:38 -0700 | [diff] [blame] | 562 | bool Tree::allocateBitmapIfNeeded(Cache& cache, int width, int height) { |
| 563 | if (!canReuseBitmap(cache.bitmap.get(), width, height)) { |
Romain Guy | 253f2c2 | 2016-09-28 17:34:42 -0700 | [diff] [blame] | 564 | #ifndef ANDROID_ENABLE_LINEAR_BLENDING |
| 565 | sk_sp<SkColorSpace> colorSpace = nullptr; |
| 566 | #else |
Mike Reed | ab12c1f | 2016-11-03 12:54:10 -0400 | [diff] [blame] | 567 | sk_sp<SkColorSpace> colorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); |
Romain Guy | 253f2c2 | 2016-09-28 17:34:42 -0700 | [diff] [blame] | 568 | #endif |
| 569 | SkImageInfo info = SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType, colorSpace); |
sergeyv | fc999950 | 2016-10-17 13:07:38 -0700 | [diff] [blame] | 570 | cache.bitmap = Bitmap::allocateHeapBitmap(info); |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 571 | return true; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 572 | } |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 573 | return false; |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 574 | } |
| 575 | |
sergeyv | fc999950 | 2016-10-17 13:07:38 -0700 | [diff] [blame] | 576 | bool Tree::canReuseBitmap(Bitmap* bitmap, int width, int height) { |
Teng-Hui Zhu | 037fc18 | 2016-11-16 10:29:39 -0800 | [diff] [blame] | 577 | return bitmap && width <= bitmap->width() && height <= bitmap->height(); |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | void Tree::onPropertyChanged(TreeProperties* prop) { |
| 581 | if (prop == &mStagingProperties) { |
| 582 | mStagingCache.dirty = true; |
| 583 | } else { |
| 584 | mCache.dirty = true; |
| 585 | } |
Doris Liu | 4bbc293 | 2015-12-01 17:59:40 -0800 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | }; // namespace VectorDrawable |
| 589 | |
| 590 | }; // namespace uirenderer |
| 591 | }; // namespace android |