VectorDrawable.h revision dbee9bb342cdfaa5155b1918f90262c05e2464cb
14bbc2931263b232fba61807fca00e127573eff42Doris Liu/* 24bbc2931263b232fba61807fca00e127573eff42Doris Liu * Copyright (C) 2015 The Android Open Source Project 34bbc2931263b232fba61807fca00e127573eff42Doris Liu * 44bbc2931263b232fba61807fca00e127573eff42Doris Liu * Licensed under the Apache License, Version 2.0 (the "License"); 54bbc2931263b232fba61807fca00e127573eff42Doris Liu * you may not use this file except in compliance with the License. 64bbc2931263b232fba61807fca00e127573eff42Doris Liu * You may obtain a copy of the License at 74bbc2931263b232fba61807fca00e127573eff42Doris Liu * 84bbc2931263b232fba61807fca00e127573eff42Doris Liu * http://www.apache.org/licenses/LICENSE-2.0 94bbc2931263b232fba61807fca00e127573eff42Doris Liu * 104bbc2931263b232fba61807fca00e127573eff42Doris Liu * Unless required by applicable law or agreed to in writing, software 114bbc2931263b232fba61807fca00e127573eff42Doris Liu * distributed under the License is distributed on an "AS IS" BASIS, 124bbc2931263b232fba61807fca00e127573eff42Doris Liu * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 134bbc2931263b232fba61807fca00e127573eff42Doris Liu * See the License for the specific language governing permissions and 144bbc2931263b232fba61807fca00e127573eff42Doris Liu * limitations under the License. 154bbc2931263b232fba61807fca00e127573eff42Doris Liu */ 164bbc2931263b232fba61807fca00e127573eff42Doris Liu 174bbc2931263b232fba61807fca00e127573eff42Doris Liu#ifndef ANDROID_HWUI_VPATH_H 184bbc2931263b232fba61807fca00e127573eff42Doris Liu#define ANDROID_HWUI_VPATH_H 194bbc2931263b232fba61807fca00e127573eff42Doris Liu 204bbc2931263b232fba61807fca00e127573eff42Doris Liu#include "Canvas.h" 214bbc2931263b232fba61807fca00e127573eff42Doris Liu#include <SkBitmap.h> 224bbc2931263b232fba61807fca00e127573eff42Doris Liu#include <SkColor.h> 23c2de46fadd4ca9c6aa2d9dd7a65b161b28fc6f3bDoris Liu#include <SkCanvas.h> 244bbc2931263b232fba61807fca00e127573eff42Doris Liu#include <SkMatrix.h> 254bbc2931263b232fba61807fca00e127573eff42Doris Liu#include <SkPaint.h> 264bbc2931263b232fba61807fca00e127573eff42Doris Liu#include <SkPath.h> 274bbc2931263b232fba61807fca00e127573eff42Doris Liu#include <SkPathMeasure.h> 284bbc2931263b232fba61807fca00e127573eff42Doris Liu#include <SkRect.h> 29dbee9bb342cdfaa5155b1918f90262c05e2464cbTeng-Hui Zhu#include <SkShader.h> 304bbc2931263b232fba61807fca00e127573eff42Doris Liu 314bbc2931263b232fba61807fca00e127573eff42Doris Liu#include <cutils/compiler.h> 324bbc2931263b232fba61807fca00e127573eff42Doris Liu#include <stddef.h> 334bbc2931263b232fba61807fca00e127573eff42Doris Liu#include <vector> 344bbc2931263b232fba61807fca00e127573eff42Doris Liu#include <string> 354bbc2931263b232fba61807fca00e127573eff42Doris Liu 364bbc2931263b232fba61807fca00e127573eff42Doris Liunamespace android { 374bbc2931263b232fba61807fca00e127573eff42Doris Liunamespace uirenderer { 384bbc2931263b232fba61807fca00e127573eff42Doris Liu 394bbc2931263b232fba61807fca00e127573eff42Doris Liunamespace VectorDrawable { 404bbc2931263b232fba61807fca00e127573eff42Doris Liu#define VD_SET_PROP_WITH_FLAG(field, value, flag) (VD_SET_PROP(field, value) ? (flag = true, true): false); 414bbc2931263b232fba61807fca00e127573eff42Doris Liu#define VD_SET_PROP(field, value) (value != field ? (field = value, true) : false) 424bbc2931263b232fba61807fca00e127573eff42Doris Liu 434bbc2931263b232fba61807fca00e127573eff42Doris Liu/* A VectorDrawable is composed of a tree of nodes. 444bbc2931263b232fba61807fca00e127573eff42Doris Liu * Each node can be a group node, or a path. 454bbc2931263b232fba61807fca00e127573eff42Doris Liu * A group node can have groups or paths as children, but a path node has 464bbc2931263b232fba61807fca00e127573eff42Doris Liu * no children. 474bbc2931263b232fba61807fca00e127573eff42Doris Liu * One example can be: 484bbc2931263b232fba61807fca00e127573eff42Doris Liu * Root Group 494bbc2931263b232fba61807fca00e127573eff42Doris Liu * / | \ 504bbc2931263b232fba61807fca00e127573eff42Doris Liu * Group Path Group 514bbc2931263b232fba61807fca00e127573eff42Doris Liu * / \ | 524bbc2931263b232fba61807fca00e127573eff42Doris Liu * Path Path Path 534bbc2931263b232fba61807fca00e127573eff42Doris Liu * 544bbc2931263b232fba61807fca00e127573eff42Doris Liu */ 554bbc2931263b232fba61807fca00e127573eff42Doris Liuclass ANDROID_API Node { 564bbc2931263b232fba61807fca00e127573eff42Doris Liupublic: 574bbc2931263b232fba61807fca00e127573eff42Doris Liu Node(const Node& node) { 584bbc2931263b232fba61807fca00e127573eff42Doris Liu mName = node.mName; 594bbc2931263b232fba61807fca00e127573eff42Doris Liu } 604bbc2931263b232fba61807fca00e127573eff42Doris Liu Node() {} 61c2de46fadd4ca9c6aa2d9dd7a65b161b28fc6f3bDoris Liu virtual void draw(SkCanvas* outCanvas, const SkMatrix& currentMatrix, 624bbc2931263b232fba61807fca00e127573eff42Doris Liu float scaleX, float scaleY) = 0; 634bbc2931263b232fba61807fca00e127573eff42Doris Liu virtual void dump() = 0; 644bbc2931263b232fba61807fca00e127573eff42Doris Liu void setName(const char* name) { 654bbc2931263b232fba61807fca00e127573eff42Doris Liu mName = name; 664bbc2931263b232fba61807fca00e127573eff42Doris Liu } 674bbc2931263b232fba61807fca00e127573eff42Doris Liu virtual ~Node(){} 684bbc2931263b232fba61807fca00e127573eff42Doris Liuprotected: 694bbc2931263b232fba61807fca00e127573eff42Doris Liu std::string mName; 704bbc2931263b232fba61807fca00e127573eff42Doris Liu}; 714bbc2931263b232fba61807fca00e127573eff42Doris Liu 724bbc2931263b232fba61807fca00e127573eff42Doris Liuclass ANDROID_API Path : public Node { 734bbc2931263b232fba61807fca00e127573eff42Doris Liupublic: 744bbc2931263b232fba61807fca00e127573eff42Doris Liu struct ANDROID_API Data { 754bbc2931263b232fba61807fca00e127573eff42Doris Liu std::vector<char> verbs; 764bbc2931263b232fba61807fca00e127573eff42Doris Liu std::vector<size_t> verbSizes; 774bbc2931263b232fba61807fca00e127573eff42Doris Liu std::vector<float> points; 784bbc2931263b232fba61807fca00e127573eff42Doris Liu bool operator==(const Data& data) const { 794bbc2931263b232fba61807fca00e127573eff42Doris Liu return verbs == data.verbs && verbSizes == data.verbSizes 804bbc2931263b232fba61807fca00e127573eff42Doris Liu && points == data.points; 814bbc2931263b232fba61807fca00e127573eff42Doris Liu } 824bbc2931263b232fba61807fca00e127573eff42Doris Liu }; 834bbc2931263b232fba61807fca00e127573eff42Doris Liu Path(const Data& nodes); 844bbc2931263b232fba61807fca00e127573eff42Doris Liu Path(const Path& path); 854bbc2931263b232fba61807fca00e127573eff42Doris Liu Path(const char* path, size_t strLength); 864bbc2931263b232fba61807fca00e127573eff42Doris Liu Path() {} 874bbc2931263b232fba61807fca00e127573eff42Doris Liu void dump() override; 884bbc2931263b232fba61807fca00e127573eff42Doris Liu bool canMorph(const Data& path); 894bbc2931263b232fba61807fca00e127573eff42Doris Liu bool canMorph(const Path& path); 90c2de46fadd4ca9c6aa2d9dd7a65b161b28fc6f3bDoris Liu void draw(SkCanvas* outCanvas, const SkMatrix& groupStackedMatrix, 914bbc2931263b232fba61807fca00e127573eff42Doris Liu float scaleX, float scaleY) override; 924bbc2931263b232fba61807fca00e127573eff42Doris Liu void setPath(const char* path, size_t strLength); 934bbc2931263b232fba61807fca00e127573eff42Doris Liu void setPathData(const Data& data); 944bbc2931263b232fba61807fca00e127573eff42Doris Liu static float getMatrixScale(const SkMatrix& groupStackedMatrix); 954bbc2931263b232fba61807fca00e127573eff42Doris Liu 964bbc2931263b232fba61807fca00e127573eff42Doris Liuprotected: 974bbc2931263b232fba61807fca00e127573eff42Doris Liu virtual const SkPath& getUpdatedPath(); 98c2de46fadd4ca9c6aa2d9dd7a65b161b28fc6f3bDoris Liu virtual void drawPath(SkCanvas *outCanvas, const SkPath& renderPath, 99dbee9bb342cdfaa5155b1918f90262c05e2464cbTeng-Hui Zhu float strokeScale, const SkMatrix& matrix) = 0; 1004bbc2931263b232fba61807fca00e127573eff42Doris Liu Data mData; 1014bbc2931263b232fba61807fca00e127573eff42Doris Liu SkPath mSkPath; 1024bbc2931263b232fba61807fca00e127573eff42Doris Liu bool mSkPathDirty = true; 1034bbc2931263b232fba61807fca00e127573eff42Doris Liu}; 1044bbc2931263b232fba61807fca00e127573eff42Doris Liu 1054bbc2931263b232fba61807fca00e127573eff42Doris Liuclass ANDROID_API FullPath: public Path { 1064bbc2931263b232fba61807fca00e127573eff42Doris Liupublic: 1074bbc2931263b232fba61807fca00e127573eff42Doris Liu FullPath(const FullPath& path); // for cloning 1084bbc2931263b232fba61807fca00e127573eff42Doris Liu FullPath(const char* path, size_t strLength) : Path(path, strLength) {} 1094bbc2931263b232fba61807fca00e127573eff42Doris Liu FullPath() : Path() {} 1104bbc2931263b232fba61807fca00e127573eff42Doris Liu FullPath(const Data& nodes) : Path(nodes) {} 1114bbc2931263b232fba61807fca00e127573eff42Doris Liu 112dbee9bb342cdfaa5155b1918f90262c05e2464cbTeng-Hui Zhu ~FullPath() { 113dbee9bb342cdfaa5155b1918f90262c05e2464cbTeng-Hui Zhu SkSafeUnref(mFillGradient); 114dbee9bb342cdfaa5155b1918f90262c05e2464cbTeng-Hui Zhu SkSafeUnref(mStrokeGradient); 115dbee9bb342cdfaa5155b1918f90262c05e2464cbTeng-Hui Zhu } 116dbee9bb342cdfaa5155b1918f90262c05e2464cbTeng-Hui Zhu 1174bbc2931263b232fba61807fca00e127573eff42Doris Liu void updateProperties(float strokeWidth, SkColor strokeColor, 1184bbc2931263b232fba61807fca00e127573eff42Doris Liu float strokeAlpha, SkColor fillColor, float fillAlpha, 1194bbc2931263b232fba61807fca00e127573eff42Doris Liu float trimPathStart, float trimPathEnd, float trimPathOffset, 1204bbc2931263b232fba61807fca00e127573eff42Doris Liu float strokeMiterLimit, int strokeLineCap, int strokeLineJoin); 1214bbc2931263b232fba61807fca00e127573eff42Doris Liu float getStrokeWidth() { 1224bbc2931263b232fba61807fca00e127573eff42Doris Liu return mStrokeWidth; 1234bbc2931263b232fba61807fca00e127573eff42Doris Liu } 1244bbc2931263b232fba61807fca00e127573eff42Doris Liu void setStrokeWidth(float strokeWidth) { 1254bbc2931263b232fba61807fca00e127573eff42Doris Liu mStrokeWidth = strokeWidth; 1264bbc2931263b232fba61807fca00e127573eff42Doris Liu } 1274bbc2931263b232fba61807fca00e127573eff42Doris Liu SkColor getStrokeColor() { 1284bbc2931263b232fba61807fca00e127573eff42Doris Liu return mStrokeColor; 1294bbc2931263b232fba61807fca00e127573eff42Doris Liu } 1304bbc2931263b232fba61807fca00e127573eff42Doris Liu void setStrokeColor(SkColor strokeColor) { 1314bbc2931263b232fba61807fca00e127573eff42Doris Liu mStrokeColor = strokeColor; 1324bbc2931263b232fba61807fca00e127573eff42Doris Liu } 1334bbc2931263b232fba61807fca00e127573eff42Doris Liu float getStrokeAlpha() { 1344bbc2931263b232fba61807fca00e127573eff42Doris Liu return mStrokeAlpha; 1354bbc2931263b232fba61807fca00e127573eff42Doris Liu } 1364bbc2931263b232fba61807fca00e127573eff42Doris Liu void setStrokeAlpha(float strokeAlpha) { 1374bbc2931263b232fba61807fca00e127573eff42Doris Liu mStrokeAlpha = strokeAlpha; 1384bbc2931263b232fba61807fca00e127573eff42Doris Liu } 1394bbc2931263b232fba61807fca00e127573eff42Doris Liu SkColor getFillColor() { 1404bbc2931263b232fba61807fca00e127573eff42Doris Liu return mFillColor; 1414bbc2931263b232fba61807fca00e127573eff42Doris Liu } 1424bbc2931263b232fba61807fca00e127573eff42Doris Liu void setFillColor(SkColor fillColor) { 1434bbc2931263b232fba61807fca00e127573eff42Doris Liu mFillColor = fillColor; 1444bbc2931263b232fba61807fca00e127573eff42Doris Liu } 1454bbc2931263b232fba61807fca00e127573eff42Doris Liu float getFillAlpha() { 1464bbc2931263b232fba61807fca00e127573eff42Doris Liu return mFillAlpha; 1474bbc2931263b232fba61807fca00e127573eff42Doris Liu } 1484bbc2931263b232fba61807fca00e127573eff42Doris Liu void setFillAlpha(float fillAlpha) { 1494bbc2931263b232fba61807fca00e127573eff42Doris Liu mFillAlpha = fillAlpha; 1504bbc2931263b232fba61807fca00e127573eff42Doris Liu } 1514bbc2931263b232fba61807fca00e127573eff42Doris Liu float getTrimPathStart() { 1524bbc2931263b232fba61807fca00e127573eff42Doris Liu return mTrimPathStart; 1534bbc2931263b232fba61807fca00e127573eff42Doris Liu } 1544bbc2931263b232fba61807fca00e127573eff42Doris Liu void setTrimPathStart(float trimPathStart) { 1554bbc2931263b232fba61807fca00e127573eff42Doris Liu VD_SET_PROP_WITH_FLAG(mTrimPathStart, trimPathStart, mTrimDirty); 1564bbc2931263b232fba61807fca00e127573eff42Doris Liu } 1574bbc2931263b232fba61807fca00e127573eff42Doris Liu float getTrimPathEnd() { 1584bbc2931263b232fba61807fca00e127573eff42Doris Liu return mTrimPathEnd; 1594bbc2931263b232fba61807fca00e127573eff42Doris Liu } 1604bbc2931263b232fba61807fca00e127573eff42Doris Liu void setTrimPathEnd(float trimPathEnd) { 1614bbc2931263b232fba61807fca00e127573eff42Doris Liu VD_SET_PROP_WITH_FLAG(mTrimPathEnd, trimPathEnd, mTrimDirty); 1624bbc2931263b232fba61807fca00e127573eff42Doris Liu } 1634bbc2931263b232fba61807fca00e127573eff42Doris Liu float getTrimPathOffset() { 1644bbc2931263b232fba61807fca00e127573eff42Doris Liu return mTrimPathOffset; 1654bbc2931263b232fba61807fca00e127573eff42Doris Liu } 1664bbc2931263b232fba61807fca00e127573eff42Doris Liu void setTrimPathOffset(float trimPathOffset) { 1674bbc2931263b232fba61807fca00e127573eff42Doris Liu VD_SET_PROP_WITH_FLAG(mTrimPathOffset, trimPathOffset, mTrimDirty); 1684bbc2931263b232fba61807fca00e127573eff42Doris Liu } 1694bbc2931263b232fba61807fca00e127573eff42Doris Liu bool getProperties(int8_t* outProperties, int length); 1704bbc2931263b232fba61807fca00e127573eff42Doris Liu 171dbee9bb342cdfaa5155b1918f90262c05e2464cbTeng-Hui Zhu void setFillGradient(SkShader* fillGradient) { 172dbee9bb342cdfaa5155b1918f90262c05e2464cbTeng-Hui Zhu SkRefCnt_SafeAssign(mFillGradient, fillGradient); 173dbee9bb342cdfaa5155b1918f90262c05e2464cbTeng-Hui Zhu }; 174dbee9bb342cdfaa5155b1918f90262c05e2464cbTeng-Hui Zhu void setStrokeGradient(SkShader* strokeGradient) { 175dbee9bb342cdfaa5155b1918f90262c05e2464cbTeng-Hui Zhu SkRefCnt_SafeAssign(mStrokeGradient, strokeGradient); 176dbee9bb342cdfaa5155b1918f90262c05e2464cbTeng-Hui Zhu }; 177dbee9bb342cdfaa5155b1918f90262c05e2464cbTeng-Hui Zhu 178dbee9bb342cdfaa5155b1918f90262c05e2464cbTeng-Hui Zhu 1794bbc2931263b232fba61807fca00e127573eff42Doris Liuprotected: 1804bbc2931263b232fba61807fca00e127573eff42Doris Liu const SkPath& getUpdatedPath() override; 181c2de46fadd4ca9c6aa2d9dd7a65b161b28fc6f3bDoris Liu void drawPath(SkCanvas* outCanvas, const SkPath& renderPath, 182dbee9bb342cdfaa5155b1918f90262c05e2464cbTeng-Hui Zhu float strokeScale, const SkMatrix& matrix) override; 1834bbc2931263b232fba61807fca00e127573eff42Doris Liu 1844bbc2931263b232fba61807fca00e127573eff42Doris Liuprivate: 1854bbc2931263b232fba61807fca00e127573eff42Doris Liu // Applies trimming to the specified path. 1864bbc2931263b232fba61807fca00e127573eff42Doris Liu void applyTrim(); 1874bbc2931263b232fba61807fca00e127573eff42Doris Liu float mStrokeWidth = 0; 1884bbc2931263b232fba61807fca00e127573eff42Doris Liu SkColor mStrokeColor = SK_ColorTRANSPARENT; 1894bbc2931263b232fba61807fca00e127573eff42Doris Liu float mStrokeAlpha = 1; 1904bbc2931263b232fba61807fca00e127573eff42Doris Liu SkColor mFillColor = SK_ColorTRANSPARENT; 191dbee9bb342cdfaa5155b1918f90262c05e2464cbTeng-Hui Zhu SkShader* mStrokeGradient = nullptr; 192dbee9bb342cdfaa5155b1918f90262c05e2464cbTeng-Hui Zhu SkShader* mFillGradient = nullptr; 1934bbc2931263b232fba61807fca00e127573eff42Doris Liu float mFillAlpha = 1; 1944bbc2931263b232fba61807fca00e127573eff42Doris Liu float mTrimPathStart = 0; 1954bbc2931263b232fba61807fca00e127573eff42Doris Liu float mTrimPathEnd = 1; 1964bbc2931263b232fba61807fca00e127573eff42Doris Liu float mTrimPathOffset = 0; 1974bbc2931263b232fba61807fca00e127573eff42Doris Liu bool mTrimDirty = true; 1984bbc2931263b232fba61807fca00e127573eff42Doris Liu SkPaint::Cap mStrokeLineCap = SkPaint::Cap::kButt_Cap; 1994bbc2931263b232fba61807fca00e127573eff42Doris Liu SkPaint::Join mStrokeLineJoin = SkPaint::Join::kMiter_Join; 2004bbc2931263b232fba61807fca00e127573eff42Doris Liu float mStrokeMiterLimit = 4; 2014bbc2931263b232fba61807fca00e127573eff42Doris Liu SkPath mTrimmedSkPath; 2024bbc2931263b232fba61807fca00e127573eff42Doris Liu SkPaint mPaint; 2034bbc2931263b232fba61807fca00e127573eff42Doris Liu}; 2044bbc2931263b232fba61807fca00e127573eff42Doris Liu 2054bbc2931263b232fba61807fca00e127573eff42Doris Liuclass ANDROID_API ClipPath: public Path { 2064bbc2931263b232fba61807fca00e127573eff42Doris Liupublic: 2074bbc2931263b232fba61807fca00e127573eff42Doris Liu ClipPath(const ClipPath& path) : Path(path) {} 2084bbc2931263b232fba61807fca00e127573eff42Doris Liu ClipPath(const char* path, size_t strLength) : Path(path, strLength) {} 2094bbc2931263b232fba61807fca00e127573eff42Doris Liu ClipPath() : Path() {} 2104bbc2931263b232fba61807fca00e127573eff42Doris Liu ClipPath(const Data& nodes) : Path(nodes) {} 2114bbc2931263b232fba61807fca00e127573eff42Doris Liu 2124bbc2931263b232fba61807fca00e127573eff42Doris Liuprotected: 213c2de46fadd4ca9c6aa2d9dd7a65b161b28fc6f3bDoris Liu void drawPath(SkCanvas* outCanvas, const SkPath& renderPath, 214dbee9bb342cdfaa5155b1918f90262c05e2464cbTeng-Hui Zhu float strokeScale, const SkMatrix& matrix) override; 2154bbc2931263b232fba61807fca00e127573eff42Doris Liu}; 2164bbc2931263b232fba61807fca00e127573eff42Doris Liu 2174bbc2931263b232fba61807fca00e127573eff42Doris Liuclass ANDROID_API Group: public Node { 2184bbc2931263b232fba61807fca00e127573eff42Doris Liupublic: 2194bbc2931263b232fba61807fca00e127573eff42Doris Liu Group(const Group& group); 2204bbc2931263b232fba61807fca00e127573eff42Doris Liu Group() {} 2214bbc2931263b232fba61807fca00e127573eff42Doris Liu float getRotation() { 2224bbc2931263b232fba61807fca00e127573eff42Doris Liu return mRotate; 2234bbc2931263b232fba61807fca00e127573eff42Doris Liu } 2244bbc2931263b232fba61807fca00e127573eff42Doris Liu void setRotation(float rotation) { 2254bbc2931263b232fba61807fca00e127573eff42Doris Liu mRotate = rotation; 2264bbc2931263b232fba61807fca00e127573eff42Doris Liu } 2274bbc2931263b232fba61807fca00e127573eff42Doris Liu float getPivotX() { 2284bbc2931263b232fba61807fca00e127573eff42Doris Liu return mPivotX; 2294bbc2931263b232fba61807fca00e127573eff42Doris Liu } 2304bbc2931263b232fba61807fca00e127573eff42Doris Liu void setPivotX(float pivotX) { 2314bbc2931263b232fba61807fca00e127573eff42Doris Liu mPivotX = pivotX; 2324bbc2931263b232fba61807fca00e127573eff42Doris Liu } 2334bbc2931263b232fba61807fca00e127573eff42Doris Liu float getPivotY() { 2344bbc2931263b232fba61807fca00e127573eff42Doris Liu return mPivotY; 2354bbc2931263b232fba61807fca00e127573eff42Doris Liu } 2364bbc2931263b232fba61807fca00e127573eff42Doris Liu void setPivotY(float pivotY) { 2374bbc2931263b232fba61807fca00e127573eff42Doris Liu mPivotY = pivotY; 2384bbc2931263b232fba61807fca00e127573eff42Doris Liu } 2394bbc2931263b232fba61807fca00e127573eff42Doris Liu float getScaleX() { 2404bbc2931263b232fba61807fca00e127573eff42Doris Liu return mScaleX; 2414bbc2931263b232fba61807fca00e127573eff42Doris Liu } 2424bbc2931263b232fba61807fca00e127573eff42Doris Liu void setScaleX(float scaleX) { 2434bbc2931263b232fba61807fca00e127573eff42Doris Liu mScaleX = scaleX; 2444bbc2931263b232fba61807fca00e127573eff42Doris Liu } 2454bbc2931263b232fba61807fca00e127573eff42Doris Liu float getScaleY() { 2464bbc2931263b232fba61807fca00e127573eff42Doris Liu return mScaleY; 2474bbc2931263b232fba61807fca00e127573eff42Doris Liu } 2484bbc2931263b232fba61807fca00e127573eff42Doris Liu void setScaleY(float scaleY) { 2494bbc2931263b232fba61807fca00e127573eff42Doris Liu mScaleY = scaleY; 2504bbc2931263b232fba61807fca00e127573eff42Doris Liu } 2514bbc2931263b232fba61807fca00e127573eff42Doris Liu float getTranslateX() { 2524bbc2931263b232fba61807fca00e127573eff42Doris Liu return mTranslateX; 2534bbc2931263b232fba61807fca00e127573eff42Doris Liu } 2544bbc2931263b232fba61807fca00e127573eff42Doris Liu void setTranslateX(float translateX) { 2554bbc2931263b232fba61807fca00e127573eff42Doris Liu mTranslateX = translateX; 2564bbc2931263b232fba61807fca00e127573eff42Doris Liu } 2574bbc2931263b232fba61807fca00e127573eff42Doris Liu float getTranslateY() { 2584bbc2931263b232fba61807fca00e127573eff42Doris Liu return mTranslateY; 2594bbc2931263b232fba61807fca00e127573eff42Doris Liu } 2604bbc2931263b232fba61807fca00e127573eff42Doris Liu void setTranslateY(float translateY) { 2614bbc2931263b232fba61807fca00e127573eff42Doris Liu mTranslateY = translateY; 2624bbc2931263b232fba61807fca00e127573eff42Doris Liu } 263c2de46fadd4ca9c6aa2d9dd7a65b161b28fc6f3bDoris Liu virtual void draw(SkCanvas* outCanvas, const SkMatrix& currentMatrix, 2644bbc2931263b232fba61807fca00e127573eff42Doris Liu float scaleX, float scaleY) override; 2654bbc2931263b232fba61807fca00e127573eff42Doris Liu void updateLocalMatrix(float rotate, float pivotX, float pivotY, 2664bbc2931263b232fba61807fca00e127573eff42Doris Liu float scaleX, float scaleY, float translateX, float translateY); 2674bbc2931263b232fba61807fca00e127573eff42Doris Liu void getLocalMatrix(SkMatrix* outMatrix); 2684bbc2931263b232fba61807fca00e127573eff42Doris Liu void addChild(Node* child); 2694bbc2931263b232fba61807fca00e127573eff42Doris Liu void dump() override; 2704bbc2931263b232fba61807fca00e127573eff42Doris Liu bool getProperties(float* outProperties, int length); 2714bbc2931263b232fba61807fca00e127573eff42Doris Liu 2724bbc2931263b232fba61807fca00e127573eff42Doris Liuprivate: 2734bbc2931263b232fba61807fca00e127573eff42Doris Liu enum class Property { 2744bbc2931263b232fba61807fca00e127573eff42Doris Liu Rotate_Property = 0, 2754bbc2931263b232fba61807fca00e127573eff42Doris Liu PivotX_Property, 2764bbc2931263b232fba61807fca00e127573eff42Doris Liu PivotY_Property, 2774bbc2931263b232fba61807fca00e127573eff42Doris Liu ScaleX_Property, 2784bbc2931263b232fba61807fca00e127573eff42Doris Liu ScaleY_Property, 2794bbc2931263b232fba61807fca00e127573eff42Doris Liu TranslateX_Property, 2804bbc2931263b232fba61807fca00e127573eff42Doris Liu TranslateY_Property, 2814bbc2931263b232fba61807fca00e127573eff42Doris Liu // Count of the properties, must be at the end. 2824bbc2931263b232fba61807fca00e127573eff42Doris Liu Count, 2834bbc2931263b232fba61807fca00e127573eff42Doris Liu }; 2844bbc2931263b232fba61807fca00e127573eff42Doris Liu float mRotate = 0; 2854bbc2931263b232fba61807fca00e127573eff42Doris Liu float mPivotX = 0; 2864bbc2931263b232fba61807fca00e127573eff42Doris Liu float mPivotY = 0; 2874bbc2931263b232fba61807fca00e127573eff42Doris Liu float mScaleX = 1; 2884bbc2931263b232fba61807fca00e127573eff42Doris Liu float mScaleY = 1; 2894bbc2931263b232fba61807fca00e127573eff42Doris Liu float mTranslateX = 0; 2904bbc2931263b232fba61807fca00e127573eff42Doris Liu float mTranslateY = 0; 2914bbc2931263b232fba61807fca00e127573eff42Doris Liu std::vector<Node*> mChildren; 2924bbc2931263b232fba61807fca00e127573eff42Doris Liu}; 2934bbc2931263b232fba61807fca00e127573eff42Doris Liu 2944bbc2931263b232fba61807fca00e127573eff42Doris Liuclass ANDROID_API Tree { 2954bbc2931263b232fba61807fca00e127573eff42Doris Liupublic: 2964bbc2931263b232fba61807fca00e127573eff42Doris Liu Tree(Group* rootNode) : mRootNode(rootNode) {} 2974bbc2931263b232fba61807fca00e127573eff42Doris Liu void draw(Canvas* outCanvas, SkColorFilter* colorFilter, 2984bbc2931263b232fba61807fca00e127573eff42Doris Liu const SkRect& bounds, bool needsMirroring, bool canReuseCache); 2994bbc2931263b232fba61807fca00e127573eff42Doris Liu void drawCachedBitmapWithRootAlpha(Canvas* outCanvas, SkColorFilter* filter, 3004bbc2931263b232fba61807fca00e127573eff42Doris Liu const SkRect& originalBounds); 3014bbc2931263b232fba61807fca00e127573eff42Doris Liu 3024bbc2931263b232fba61807fca00e127573eff42Doris Liu void updateCachedBitmap(int width, int height); 3034bbc2931263b232fba61807fca00e127573eff42Doris Liu void createCachedBitmapIfNeeded(int width, int height); 3044bbc2931263b232fba61807fca00e127573eff42Doris Liu bool canReuseBitmap(int width, int height); 3054bbc2931263b232fba61807fca00e127573eff42Doris Liu void setAllowCaching(bool allowCaching) { 3064bbc2931263b232fba61807fca00e127573eff42Doris Liu mAllowCaching = allowCaching; 3074bbc2931263b232fba61807fca00e127573eff42Doris Liu } 3084bbc2931263b232fba61807fca00e127573eff42Doris Liu bool setRootAlpha(float rootAlpha) { 3094bbc2931263b232fba61807fca00e127573eff42Doris Liu return VD_SET_PROP(mRootAlpha, rootAlpha); 3104bbc2931263b232fba61807fca00e127573eff42Doris Liu } 3114bbc2931263b232fba61807fca00e127573eff42Doris Liu 3124bbc2931263b232fba61807fca00e127573eff42Doris Liu float getRootAlpha() { 3134bbc2931263b232fba61807fca00e127573eff42Doris Liu return mRootAlpha; 3144bbc2931263b232fba61807fca00e127573eff42Doris Liu } 3154bbc2931263b232fba61807fca00e127573eff42Doris Liu void setViewportSize(float viewportWidth, float viewportHeight) { 3164bbc2931263b232fba61807fca00e127573eff42Doris Liu mViewportWidth = viewportWidth; 3174bbc2931263b232fba61807fca00e127573eff42Doris Liu mViewportHeight = viewportHeight; 3184bbc2931263b232fba61807fca00e127573eff42Doris Liu } 3194bbc2931263b232fba61807fca00e127573eff42Doris Liu 3204bbc2931263b232fba61807fca00e127573eff42Doris Liuprivate: 3214bbc2931263b232fba61807fca00e127573eff42Doris Liu // Cap the bitmap size, such that it won't hurt the performance too much 3224bbc2931263b232fba61807fca00e127573eff42Doris Liu // and it won't crash due to a very large scale. 3234bbc2931263b232fba61807fca00e127573eff42Doris Liu // The drawable will look blurry above this size. 3244bbc2931263b232fba61807fca00e127573eff42Doris Liu const static int MAX_CACHED_BITMAP_SIZE; 3254bbc2931263b232fba61807fca00e127573eff42Doris Liu 3264bbc2931263b232fba61807fca00e127573eff42Doris Liu bool mCacheDirty = true; 3274bbc2931263b232fba61807fca00e127573eff42Doris Liu bool mAllowCaching = true; 3284bbc2931263b232fba61807fca00e127573eff42Doris Liu float mViewportWidth = 0; 3294bbc2931263b232fba61807fca00e127573eff42Doris Liu float mViewportHeight = 0; 3304bbc2931263b232fba61807fca00e127573eff42Doris Liu float mRootAlpha = 1.0f; 3314bbc2931263b232fba61807fca00e127573eff42Doris Liu 3324bbc2931263b232fba61807fca00e127573eff42Doris Liu Group* mRootNode; 3334bbc2931263b232fba61807fca00e127573eff42Doris Liu SkRect mBounds; 3344bbc2931263b232fba61807fca00e127573eff42Doris Liu SkMatrix mCanvasMatrix; 3354bbc2931263b232fba61807fca00e127573eff42Doris Liu SkPaint mPaint; 3364bbc2931263b232fba61807fca00e127573eff42Doris Liu SkPathMeasure mPathMeasure; 3374bbc2931263b232fba61807fca00e127573eff42Doris Liu SkBitmap mCachedBitmap; 3384bbc2931263b232fba61807fca00e127573eff42Doris Liu 3394bbc2931263b232fba61807fca00e127573eff42Doris Liu}; 3404bbc2931263b232fba61807fca00e127573eff42Doris Liu 3414bbc2931263b232fba61807fca00e127573eff42Doris Liu} // namespace VectorDrawable 3424bbc2931263b232fba61807fca00e127573eff42Doris Liu 3434bbc2931263b232fba61807fca00e127573eff42Doris Liutypedef VectorDrawable::Path::Data PathData; 3444bbc2931263b232fba61807fca00e127573eff42Doris Liu} // namespace uirenderer 3454bbc2931263b232fba61807fca00e127573eff42Doris Liu} // namespace android 3464bbc2931263b232fba61807fca00e127573eff42Doris Liu 3474bbc2931263b232fba61807fca00e127573eff42Doris Liu#endif // ANDROID_HWUI_VPATH_H 348