VectorDrawable.h revision 4bbc2931263b232fba61807fca00e127573eff42
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>
234bbc2931263b232fba61807fca00e127573eff42Doris Liu#include <SkMatrix.h>
244bbc2931263b232fba61807fca00e127573eff42Doris Liu#include <SkPaint.h>
254bbc2931263b232fba61807fca00e127573eff42Doris Liu#include <SkPath.h>
264bbc2931263b232fba61807fca00e127573eff42Doris Liu#include <SkPathMeasure.h>
274bbc2931263b232fba61807fca00e127573eff42Doris Liu#include <SkRect.h>
284bbc2931263b232fba61807fca00e127573eff42Doris Liu
294bbc2931263b232fba61807fca00e127573eff42Doris Liu#include <cutils/compiler.h>
304bbc2931263b232fba61807fca00e127573eff42Doris Liu#include <stddef.h>
314bbc2931263b232fba61807fca00e127573eff42Doris Liu#include <vector>
324bbc2931263b232fba61807fca00e127573eff42Doris Liu#include <string>
334bbc2931263b232fba61807fca00e127573eff42Doris Liu
344bbc2931263b232fba61807fca00e127573eff42Doris Liunamespace android {
354bbc2931263b232fba61807fca00e127573eff42Doris Liunamespace uirenderer {
364bbc2931263b232fba61807fca00e127573eff42Doris Liu
374bbc2931263b232fba61807fca00e127573eff42Doris Liunamespace VectorDrawable {
384bbc2931263b232fba61807fca00e127573eff42Doris Liu#define VD_SET_PROP_WITH_FLAG(field, value, flag) (VD_SET_PROP(field, value) ? (flag = true, true): false);
394bbc2931263b232fba61807fca00e127573eff42Doris Liu#define VD_SET_PROP(field, value) (value != field ? (field = value, true) : false)
404bbc2931263b232fba61807fca00e127573eff42Doris Liu
414bbc2931263b232fba61807fca00e127573eff42Doris Liu/* A VectorDrawable is composed of a tree of nodes.
424bbc2931263b232fba61807fca00e127573eff42Doris Liu * Each node can be a group node, or a path.
434bbc2931263b232fba61807fca00e127573eff42Doris Liu * A group node can have groups or paths as children, but a path node has
444bbc2931263b232fba61807fca00e127573eff42Doris Liu * no children.
454bbc2931263b232fba61807fca00e127573eff42Doris Liu * One example can be:
464bbc2931263b232fba61807fca00e127573eff42Doris Liu *                 Root Group
474bbc2931263b232fba61807fca00e127573eff42Doris Liu *                /    |     \
484bbc2931263b232fba61807fca00e127573eff42Doris Liu *           Group    Path    Group
494bbc2931263b232fba61807fca00e127573eff42Doris Liu *          /     \             |
504bbc2931263b232fba61807fca00e127573eff42Doris Liu *         Path   Path         Path
514bbc2931263b232fba61807fca00e127573eff42Doris Liu *
524bbc2931263b232fba61807fca00e127573eff42Doris Liu */
534bbc2931263b232fba61807fca00e127573eff42Doris Liuclass ANDROID_API Node {
544bbc2931263b232fba61807fca00e127573eff42Doris Liupublic:
554bbc2931263b232fba61807fca00e127573eff42Doris Liu    Node(const Node& node) {
564bbc2931263b232fba61807fca00e127573eff42Doris Liu        mName = node.mName;
574bbc2931263b232fba61807fca00e127573eff42Doris Liu    }
584bbc2931263b232fba61807fca00e127573eff42Doris Liu    Node() {}
594bbc2931263b232fba61807fca00e127573eff42Doris Liu    virtual void draw(Canvas* outCanvas, const SkMatrix& currentMatrix,
604bbc2931263b232fba61807fca00e127573eff42Doris Liu            float scaleX, float scaleY) = 0;
614bbc2931263b232fba61807fca00e127573eff42Doris Liu    virtual void dump() = 0;
624bbc2931263b232fba61807fca00e127573eff42Doris Liu    void setName(const char* name) {
634bbc2931263b232fba61807fca00e127573eff42Doris Liu        mName = name;
644bbc2931263b232fba61807fca00e127573eff42Doris Liu    }
654bbc2931263b232fba61807fca00e127573eff42Doris Liu    virtual ~Node(){}
664bbc2931263b232fba61807fca00e127573eff42Doris Liuprotected:
674bbc2931263b232fba61807fca00e127573eff42Doris Liu    std::string mName;
684bbc2931263b232fba61807fca00e127573eff42Doris Liu};
694bbc2931263b232fba61807fca00e127573eff42Doris Liu
704bbc2931263b232fba61807fca00e127573eff42Doris Liuclass ANDROID_API Path : public Node {
714bbc2931263b232fba61807fca00e127573eff42Doris Liupublic:
724bbc2931263b232fba61807fca00e127573eff42Doris Liu    struct ANDROID_API Data {
734bbc2931263b232fba61807fca00e127573eff42Doris Liu        std::vector<char> verbs;
744bbc2931263b232fba61807fca00e127573eff42Doris Liu        std::vector<size_t> verbSizes;
754bbc2931263b232fba61807fca00e127573eff42Doris Liu        std::vector<float> points;
764bbc2931263b232fba61807fca00e127573eff42Doris Liu        bool operator==(const Data& data) const {
774bbc2931263b232fba61807fca00e127573eff42Doris Liu            return verbs == data.verbs && verbSizes == data.verbSizes
784bbc2931263b232fba61807fca00e127573eff42Doris Liu                    && points == data.points;
794bbc2931263b232fba61807fca00e127573eff42Doris Liu        }
804bbc2931263b232fba61807fca00e127573eff42Doris Liu    };
814bbc2931263b232fba61807fca00e127573eff42Doris Liu    Path(const Data& nodes);
824bbc2931263b232fba61807fca00e127573eff42Doris Liu    Path(const Path& path);
834bbc2931263b232fba61807fca00e127573eff42Doris Liu    Path(const char* path, size_t strLength);
844bbc2931263b232fba61807fca00e127573eff42Doris Liu    Path() {}
854bbc2931263b232fba61807fca00e127573eff42Doris Liu    void dump() override;
864bbc2931263b232fba61807fca00e127573eff42Doris Liu    bool canMorph(const Data& path);
874bbc2931263b232fba61807fca00e127573eff42Doris Liu    bool canMorph(const Path& path);
884bbc2931263b232fba61807fca00e127573eff42Doris Liu    void draw(Canvas* outCanvas, const SkMatrix& groupStackedMatrix,
894bbc2931263b232fba61807fca00e127573eff42Doris Liu            float scaleX, float scaleY) override;
904bbc2931263b232fba61807fca00e127573eff42Doris Liu    void setPath(const char* path, size_t strLength);
914bbc2931263b232fba61807fca00e127573eff42Doris Liu    void setPathData(const Data& data);
924bbc2931263b232fba61807fca00e127573eff42Doris Liu    static float getMatrixScale(const SkMatrix& groupStackedMatrix);
934bbc2931263b232fba61807fca00e127573eff42Doris Liu
944bbc2931263b232fba61807fca00e127573eff42Doris Liuprotected:
954bbc2931263b232fba61807fca00e127573eff42Doris Liu    virtual const SkPath& getUpdatedPath();
964bbc2931263b232fba61807fca00e127573eff42Doris Liu    virtual void drawPath(Canvas *outCanvas, const SkPath& renderPath,
974bbc2931263b232fba61807fca00e127573eff42Doris Liu            float strokeScale) = 0;
984bbc2931263b232fba61807fca00e127573eff42Doris Liu    Data mData;
994bbc2931263b232fba61807fca00e127573eff42Doris Liu    SkPath mSkPath;
1004bbc2931263b232fba61807fca00e127573eff42Doris Liu    bool mSkPathDirty = true;
1014bbc2931263b232fba61807fca00e127573eff42Doris Liu};
1024bbc2931263b232fba61807fca00e127573eff42Doris Liu
1034bbc2931263b232fba61807fca00e127573eff42Doris Liuclass ANDROID_API FullPath: public Path {
1044bbc2931263b232fba61807fca00e127573eff42Doris Liupublic:
1054bbc2931263b232fba61807fca00e127573eff42Doris Liu    FullPath(const FullPath& path); // for cloning
1064bbc2931263b232fba61807fca00e127573eff42Doris Liu    FullPath(const char* path, size_t strLength) : Path(path, strLength) {}
1074bbc2931263b232fba61807fca00e127573eff42Doris Liu    FullPath() : Path() {}
1084bbc2931263b232fba61807fca00e127573eff42Doris Liu    FullPath(const Data& nodes) : Path(nodes) {}
1094bbc2931263b232fba61807fca00e127573eff42Doris Liu
1104bbc2931263b232fba61807fca00e127573eff42Doris Liu    void updateProperties(float strokeWidth, SkColor strokeColor,
1114bbc2931263b232fba61807fca00e127573eff42Doris Liu            float strokeAlpha, SkColor fillColor, float fillAlpha,
1124bbc2931263b232fba61807fca00e127573eff42Doris Liu            float trimPathStart, float trimPathEnd, float trimPathOffset,
1134bbc2931263b232fba61807fca00e127573eff42Doris Liu            float strokeMiterLimit, int strokeLineCap, int strokeLineJoin);
1144bbc2931263b232fba61807fca00e127573eff42Doris Liu    float getStrokeWidth() {
1154bbc2931263b232fba61807fca00e127573eff42Doris Liu        return mStrokeWidth;
1164bbc2931263b232fba61807fca00e127573eff42Doris Liu    }
1174bbc2931263b232fba61807fca00e127573eff42Doris Liu    void setStrokeWidth(float strokeWidth) {
1184bbc2931263b232fba61807fca00e127573eff42Doris Liu        mStrokeWidth = strokeWidth;
1194bbc2931263b232fba61807fca00e127573eff42Doris Liu    }
1204bbc2931263b232fba61807fca00e127573eff42Doris Liu    SkColor getStrokeColor() {
1214bbc2931263b232fba61807fca00e127573eff42Doris Liu        return mStrokeColor;
1224bbc2931263b232fba61807fca00e127573eff42Doris Liu    }
1234bbc2931263b232fba61807fca00e127573eff42Doris Liu    void setStrokeColor(SkColor strokeColor) {
1244bbc2931263b232fba61807fca00e127573eff42Doris Liu        mStrokeColor = strokeColor;
1254bbc2931263b232fba61807fca00e127573eff42Doris Liu    }
1264bbc2931263b232fba61807fca00e127573eff42Doris Liu    float getStrokeAlpha() {
1274bbc2931263b232fba61807fca00e127573eff42Doris Liu        return mStrokeAlpha;
1284bbc2931263b232fba61807fca00e127573eff42Doris Liu    }
1294bbc2931263b232fba61807fca00e127573eff42Doris Liu    void setStrokeAlpha(float strokeAlpha) {
1304bbc2931263b232fba61807fca00e127573eff42Doris Liu        mStrokeAlpha = strokeAlpha;
1314bbc2931263b232fba61807fca00e127573eff42Doris Liu    }
1324bbc2931263b232fba61807fca00e127573eff42Doris Liu    SkColor getFillColor() {
1334bbc2931263b232fba61807fca00e127573eff42Doris Liu        return mFillColor;
1344bbc2931263b232fba61807fca00e127573eff42Doris Liu    }
1354bbc2931263b232fba61807fca00e127573eff42Doris Liu    void setFillColor(SkColor fillColor) {
1364bbc2931263b232fba61807fca00e127573eff42Doris Liu        mFillColor = fillColor;
1374bbc2931263b232fba61807fca00e127573eff42Doris Liu    }
1384bbc2931263b232fba61807fca00e127573eff42Doris Liu    float getFillAlpha() {
1394bbc2931263b232fba61807fca00e127573eff42Doris Liu        return mFillAlpha;
1404bbc2931263b232fba61807fca00e127573eff42Doris Liu    }
1414bbc2931263b232fba61807fca00e127573eff42Doris Liu    void setFillAlpha(float fillAlpha) {
1424bbc2931263b232fba61807fca00e127573eff42Doris Liu        mFillAlpha = fillAlpha;
1434bbc2931263b232fba61807fca00e127573eff42Doris Liu    }
1444bbc2931263b232fba61807fca00e127573eff42Doris Liu    float getTrimPathStart() {
1454bbc2931263b232fba61807fca00e127573eff42Doris Liu        return mTrimPathStart;
1464bbc2931263b232fba61807fca00e127573eff42Doris Liu    }
1474bbc2931263b232fba61807fca00e127573eff42Doris Liu    void setTrimPathStart(float trimPathStart) {
1484bbc2931263b232fba61807fca00e127573eff42Doris Liu        VD_SET_PROP_WITH_FLAG(mTrimPathStart, trimPathStart, mTrimDirty);
1494bbc2931263b232fba61807fca00e127573eff42Doris Liu    }
1504bbc2931263b232fba61807fca00e127573eff42Doris Liu    float getTrimPathEnd() {
1514bbc2931263b232fba61807fca00e127573eff42Doris Liu        return mTrimPathEnd;
1524bbc2931263b232fba61807fca00e127573eff42Doris Liu    }
1534bbc2931263b232fba61807fca00e127573eff42Doris Liu    void setTrimPathEnd(float trimPathEnd) {
1544bbc2931263b232fba61807fca00e127573eff42Doris Liu        VD_SET_PROP_WITH_FLAG(mTrimPathEnd, trimPathEnd, mTrimDirty);
1554bbc2931263b232fba61807fca00e127573eff42Doris Liu    }
1564bbc2931263b232fba61807fca00e127573eff42Doris Liu    float getTrimPathOffset() {
1574bbc2931263b232fba61807fca00e127573eff42Doris Liu        return mTrimPathOffset;
1584bbc2931263b232fba61807fca00e127573eff42Doris Liu    }
1594bbc2931263b232fba61807fca00e127573eff42Doris Liu    void setTrimPathOffset(float trimPathOffset) {
1604bbc2931263b232fba61807fca00e127573eff42Doris Liu        VD_SET_PROP_WITH_FLAG(mTrimPathOffset, trimPathOffset, mTrimDirty);
1614bbc2931263b232fba61807fca00e127573eff42Doris Liu    }
1624bbc2931263b232fba61807fca00e127573eff42Doris Liu    bool getProperties(int8_t* outProperties, int length);
1634bbc2931263b232fba61807fca00e127573eff42Doris Liu
1644bbc2931263b232fba61807fca00e127573eff42Doris Liuprotected:
1654bbc2931263b232fba61807fca00e127573eff42Doris Liu    const SkPath& getUpdatedPath() override;
1664bbc2931263b232fba61807fca00e127573eff42Doris Liu    void drawPath(Canvas* outCanvas, const SkPath& renderPath,
1674bbc2931263b232fba61807fca00e127573eff42Doris Liu            float strokeScale) override;
1684bbc2931263b232fba61807fca00e127573eff42Doris Liu
1694bbc2931263b232fba61807fca00e127573eff42Doris Liuprivate:
1704bbc2931263b232fba61807fca00e127573eff42Doris Liu    // Applies trimming to the specified path.
1714bbc2931263b232fba61807fca00e127573eff42Doris Liu    void applyTrim();
1724bbc2931263b232fba61807fca00e127573eff42Doris Liu    float mStrokeWidth = 0;
1734bbc2931263b232fba61807fca00e127573eff42Doris Liu    SkColor mStrokeColor = SK_ColorTRANSPARENT;
1744bbc2931263b232fba61807fca00e127573eff42Doris Liu    float mStrokeAlpha = 1;
1754bbc2931263b232fba61807fca00e127573eff42Doris Liu    SkColor mFillColor = SK_ColorTRANSPARENT;
1764bbc2931263b232fba61807fca00e127573eff42Doris Liu    float mFillAlpha = 1;
1774bbc2931263b232fba61807fca00e127573eff42Doris Liu    float mTrimPathStart = 0;
1784bbc2931263b232fba61807fca00e127573eff42Doris Liu    float mTrimPathEnd = 1;
1794bbc2931263b232fba61807fca00e127573eff42Doris Liu    float mTrimPathOffset = 0;
1804bbc2931263b232fba61807fca00e127573eff42Doris Liu    bool mTrimDirty = true;
1814bbc2931263b232fba61807fca00e127573eff42Doris Liu    SkPaint::Cap mStrokeLineCap = SkPaint::Cap::kButt_Cap;
1824bbc2931263b232fba61807fca00e127573eff42Doris Liu    SkPaint::Join mStrokeLineJoin = SkPaint::Join::kMiter_Join;
1834bbc2931263b232fba61807fca00e127573eff42Doris Liu    float mStrokeMiterLimit = 4;
1844bbc2931263b232fba61807fca00e127573eff42Doris Liu    SkPath mTrimmedSkPath;
1854bbc2931263b232fba61807fca00e127573eff42Doris Liu    SkPaint mPaint;
1864bbc2931263b232fba61807fca00e127573eff42Doris Liu};
1874bbc2931263b232fba61807fca00e127573eff42Doris Liu
1884bbc2931263b232fba61807fca00e127573eff42Doris Liuclass ANDROID_API ClipPath: public Path {
1894bbc2931263b232fba61807fca00e127573eff42Doris Liupublic:
1904bbc2931263b232fba61807fca00e127573eff42Doris Liu    ClipPath(const ClipPath& path) : Path(path) {}
1914bbc2931263b232fba61807fca00e127573eff42Doris Liu    ClipPath(const char* path, size_t strLength) : Path(path, strLength) {}
1924bbc2931263b232fba61807fca00e127573eff42Doris Liu    ClipPath() : Path() {}
1934bbc2931263b232fba61807fca00e127573eff42Doris Liu    ClipPath(const Data& nodes) : Path(nodes) {}
1944bbc2931263b232fba61807fca00e127573eff42Doris Liu
1954bbc2931263b232fba61807fca00e127573eff42Doris Liuprotected:
1964bbc2931263b232fba61807fca00e127573eff42Doris Liu    void drawPath(Canvas* outCanvas, const SkPath& renderPath,
1974bbc2931263b232fba61807fca00e127573eff42Doris Liu            float strokeScale) override;
1984bbc2931263b232fba61807fca00e127573eff42Doris Liu};
1994bbc2931263b232fba61807fca00e127573eff42Doris Liu
2004bbc2931263b232fba61807fca00e127573eff42Doris Liuclass ANDROID_API Group: public Node {
2014bbc2931263b232fba61807fca00e127573eff42Doris Liupublic:
2024bbc2931263b232fba61807fca00e127573eff42Doris Liu    Group(const Group& group);
2034bbc2931263b232fba61807fca00e127573eff42Doris Liu    Group() {}
2044bbc2931263b232fba61807fca00e127573eff42Doris Liu    float getRotation() {
2054bbc2931263b232fba61807fca00e127573eff42Doris Liu        return mRotate;
2064bbc2931263b232fba61807fca00e127573eff42Doris Liu    }
2074bbc2931263b232fba61807fca00e127573eff42Doris Liu    void setRotation(float rotation) {
2084bbc2931263b232fba61807fca00e127573eff42Doris Liu        mRotate = rotation;
2094bbc2931263b232fba61807fca00e127573eff42Doris Liu    }
2104bbc2931263b232fba61807fca00e127573eff42Doris Liu    float getPivotX() {
2114bbc2931263b232fba61807fca00e127573eff42Doris Liu        return mPivotX;
2124bbc2931263b232fba61807fca00e127573eff42Doris Liu    }
2134bbc2931263b232fba61807fca00e127573eff42Doris Liu    void setPivotX(float pivotX) {
2144bbc2931263b232fba61807fca00e127573eff42Doris Liu        mPivotX = pivotX;
2154bbc2931263b232fba61807fca00e127573eff42Doris Liu    }
2164bbc2931263b232fba61807fca00e127573eff42Doris Liu    float getPivotY() {
2174bbc2931263b232fba61807fca00e127573eff42Doris Liu        return mPivotY;
2184bbc2931263b232fba61807fca00e127573eff42Doris Liu    }
2194bbc2931263b232fba61807fca00e127573eff42Doris Liu    void setPivotY(float pivotY) {
2204bbc2931263b232fba61807fca00e127573eff42Doris Liu        mPivotY = pivotY;
2214bbc2931263b232fba61807fca00e127573eff42Doris Liu    }
2224bbc2931263b232fba61807fca00e127573eff42Doris Liu    float getScaleX() {
2234bbc2931263b232fba61807fca00e127573eff42Doris Liu        return mScaleX;
2244bbc2931263b232fba61807fca00e127573eff42Doris Liu    }
2254bbc2931263b232fba61807fca00e127573eff42Doris Liu    void setScaleX(float scaleX) {
2264bbc2931263b232fba61807fca00e127573eff42Doris Liu        mScaleX = scaleX;
2274bbc2931263b232fba61807fca00e127573eff42Doris Liu    }
2284bbc2931263b232fba61807fca00e127573eff42Doris Liu    float getScaleY() {
2294bbc2931263b232fba61807fca00e127573eff42Doris Liu        return mScaleY;
2304bbc2931263b232fba61807fca00e127573eff42Doris Liu    }
2314bbc2931263b232fba61807fca00e127573eff42Doris Liu    void setScaleY(float scaleY) {
2324bbc2931263b232fba61807fca00e127573eff42Doris Liu        mScaleY = scaleY;
2334bbc2931263b232fba61807fca00e127573eff42Doris Liu    }
2344bbc2931263b232fba61807fca00e127573eff42Doris Liu    float getTranslateX() {
2354bbc2931263b232fba61807fca00e127573eff42Doris Liu        return mTranslateX;
2364bbc2931263b232fba61807fca00e127573eff42Doris Liu    }
2374bbc2931263b232fba61807fca00e127573eff42Doris Liu    void setTranslateX(float translateX) {
2384bbc2931263b232fba61807fca00e127573eff42Doris Liu        mTranslateX = translateX;
2394bbc2931263b232fba61807fca00e127573eff42Doris Liu    }
2404bbc2931263b232fba61807fca00e127573eff42Doris Liu    float getTranslateY() {
2414bbc2931263b232fba61807fca00e127573eff42Doris Liu        return mTranslateY;
2424bbc2931263b232fba61807fca00e127573eff42Doris Liu    }
2434bbc2931263b232fba61807fca00e127573eff42Doris Liu    void setTranslateY(float translateY) {
2444bbc2931263b232fba61807fca00e127573eff42Doris Liu        mTranslateY = translateY;
2454bbc2931263b232fba61807fca00e127573eff42Doris Liu    }
2464bbc2931263b232fba61807fca00e127573eff42Doris Liu    virtual void draw(Canvas* outCanvas, const SkMatrix& currentMatrix,
2474bbc2931263b232fba61807fca00e127573eff42Doris Liu            float scaleX, float scaleY) override;
2484bbc2931263b232fba61807fca00e127573eff42Doris Liu    void updateLocalMatrix(float rotate, float pivotX, float pivotY,
2494bbc2931263b232fba61807fca00e127573eff42Doris Liu            float scaleX, float scaleY, float translateX, float translateY);
2504bbc2931263b232fba61807fca00e127573eff42Doris Liu    void getLocalMatrix(SkMatrix* outMatrix);
2514bbc2931263b232fba61807fca00e127573eff42Doris Liu    void addChild(Node* child);
2524bbc2931263b232fba61807fca00e127573eff42Doris Liu    void dump() override;
2534bbc2931263b232fba61807fca00e127573eff42Doris Liu    bool getProperties(float* outProperties, int length);
2544bbc2931263b232fba61807fca00e127573eff42Doris Liu
2554bbc2931263b232fba61807fca00e127573eff42Doris Liuprivate:
2564bbc2931263b232fba61807fca00e127573eff42Doris Liu    enum class Property {
2574bbc2931263b232fba61807fca00e127573eff42Doris Liu        Rotate_Property = 0,
2584bbc2931263b232fba61807fca00e127573eff42Doris Liu        PivotX_Property,
2594bbc2931263b232fba61807fca00e127573eff42Doris Liu        PivotY_Property,
2604bbc2931263b232fba61807fca00e127573eff42Doris Liu        ScaleX_Property,
2614bbc2931263b232fba61807fca00e127573eff42Doris Liu        ScaleY_Property,
2624bbc2931263b232fba61807fca00e127573eff42Doris Liu        TranslateX_Property,
2634bbc2931263b232fba61807fca00e127573eff42Doris Liu        TranslateY_Property,
2644bbc2931263b232fba61807fca00e127573eff42Doris Liu        // Count of the properties, must be at the end.
2654bbc2931263b232fba61807fca00e127573eff42Doris Liu        Count,
2664bbc2931263b232fba61807fca00e127573eff42Doris Liu    };
2674bbc2931263b232fba61807fca00e127573eff42Doris Liu    float mRotate = 0;
2684bbc2931263b232fba61807fca00e127573eff42Doris Liu    float mPivotX = 0;
2694bbc2931263b232fba61807fca00e127573eff42Doris Liu    float mPivotY = 0;
2704bbc2931263b232fba61807fca00e127573eff42Doris Liu    float mScaleX = 1;
2714bbc2931263b232fba61807fca00e127573eff42Doris Liu    float mScaleY = 1;
2724bbc2931263b232fba61807fca00e127573eff42Doris Liu    float mTranslateX = 0;
2734bbc2931263b232fba61807fca00e127573eff42Doris Liu    float mTranslateY = 0;
2744bbc2931263b232fba61807fca00e127573eff42Doris Liu    std::vector<Node*> mChildren;
2754bbc2931263b232fba61807fca00e127573eff42Doris Liu};
2764bbc2931263b232fba61807fca00e127573eff42Doris Liu
2774bbc2931263b232fba61807fca00e127573eff42Doris Liuclass ANDROID_API Tree {
2784bbc2931263b232fba61807fca00e127573eff42Doris Liupublic:
2794bbc2931263b232fba61807fca00e127573eff42Doris Liu    Tree(Group* rootNode) : mRootNode(rootNode) {}
2804bbc2931263b232fba61807fca00e127573eff42Doris Liu    void draw(Canvas* outCanvas, SkColorFilter* colorFilter,
2814bbc2931263b232fba61807fca00e127573eff42Doris Liu            const SkRect& bounds, bool needsMirroring, bool canReuseCache);
2824bbc2931263b232fba61807fca00e127573eff42Doris Liu    void drawCachedBitmapWithRootAlpha(Canvas* outCanvas, SkColorFilter* filter,
2834bbc2931263b232fba61807fca00e127573eff42Doris Liu            const SkRect& originalBounds);
2844bbc2931263b232fba61807fca00e127573eff42Doris Liu
2854bbc2931263b232fba61807fca00e127573eff42Doris Liu    void updateCachedBitmap(int width, int height);
2864bbc2931263b232fba61807fca00e127573eff42Doris Liu    void createCachedBitmapIfNeeded(int width, int height);
2874bbc2931263b232fba61807fca00e127573eff42Doris Liu    bool canReuseBitmap(int width, int height);
2884bbc2931263b232fba61807fca00e127573eff42Doris Liu    void setAllowCaching(bool allowCaching) {
2894bbc2931263b232fba61807fca00e127573eff42Doris Liu        mAllowCaching = allowCaching;
2904bbc2931263b232fba61807fca00e127573eff42Doris Liu    }
2914bbc2931263b232fba61807fca00e127573eff42Doris Liu    bool setRootAlpha(float rootAlpha) {
2924bbc2931263b232fba61807fca00e127573eff42Doris Liu        return VD_SET_PROP(mRootAlpha, rootAlpha);
2934bbc2931263b232fba61807fca00e127573eff42Doris Liu    }
2944bbc2931263b232fba61807fca00e127573eff42Doris Liu
2954bbc2931263b232fba61807fca00e127573eff42Doris Liu    float getRootAlpha() {
2964bbc2931263b232fba61807fca00e127573eff42Doris Liu        return mRootAlpha;
2974bbc2931263b232fba61807fca00e127573eff42Doris Liu    }
2984bbc2931263b232fba61807fca00e127573eff42Doris Liu    void setViewportSize(float viewportWidth, float viewportHeight) {
2994bbc2931263b232fba61807fca00e127573eff42Doris Liu        mViewportWidth = viewportWidth;
3004bbc2931263b232fba61807fca00e127573eff42Doris Liu        mViewportHeight = viewportHeight;
3014bbc2931263b232fba61807fca00e127573eff42Doris Liu    }
3024bbc2931263b232fba61807fca00e127573eff42Doris Liu
3034bbc2931263b232fba61807fca00e127573eff42Doris Liuprivate:
3044bbc2931263b232fba61807fca00e127573eff42Doris Liu    // Cap the bitmap size, such that it won't hurt the performance too much
3054bbc2931263b232fba61807fca00e127573eff42Doris Liu    // and it won't crash due to a very large scale.
3064bbc2931263b232fba61807fca00e127573eff42Doris Liu    // The drawable will look blurry above this size.
3074bbc2931263b232fba61807fca00e127573eff42Doris Liu    const static int MAX_CACHED_BITMAP_SIZE;
3084bbc2931263b232fba61807fca00e127573eff42Doris Liu
3094bbc2931263b232fba61807fca00e127573eff42Doris Liu    bool mCacheDirty = true;
3104bbc2931263b232fba61807fca00e127573eff42Doris Liu    bool mAllowCaching = true;
3114bbc2931263b232fba61807fca00e127573eff42Doris Liu    float mViewportWidth = 0;
3124bbc2931263b232fba61807fca00e127573eff42Doris Liu    float mViewportHeight = 0;
3134bbc2931263b232fba61807fca00e127573eff42Doris Liu    float mRootAlpha = 1.0f;
3144bbc2931263b232fba61807fca00e127573eff42Doris Liu
3154bbc2931263b232fba61807fca00e127573eff42Doris Liu    Group* mRootNode;
3164bbc2931263b232fba61807fca00e127573eff42Doris Liu    SkRect mBounds;
3174bbc2931263b232fba61807fca00e127573eff42Doris Liu    SkMatrix mCanvasMatrix;
3184bbc2931263b232fba61807fca00e127573eff42Doris Liu    SkPaint mPaint;
3194bbc2931263b232fba61807fca00e127573eff42Doris Liu    SkPathMeasure mPathMeasure;
3204bbc2931263b232fba61807fca00e127573eff42Doris Liu    SkBitmap mCachedBitmap;
3214bbc2931263b232fba61807fca00e127573eff42Doris Liu
3224bbc2931263b232fba61807fca00e127573eff42Doris Liu};
3234bbc2931263b232fba61807fca00e127573eff42Doris Liu
3244bbc2931263b232fba61807fca00e127573eff42Doris Liu} // namespace VectorDrawable
3254bbc2931263b232fba61807fca00e127573eff42Doris Liu
3264bbc2931263b232fba61807fca00e127573eff42Doris Liutypedef VectorDrawable::Path::Data PathData;
3274bbc2931263b232fba61807fca00e127573eff42Doris Liu} // namespace uirenderer
3284bbc2931263b232fba61807fca00e127573eff42Doris Liu} // namespace android
3294bbc2931263b232fba61807fca00e127573eff42Doris Liu
3304bbc2931263b232fba61807fca00e127573eff42Doris Liu#endif // ANDROID_HWUI_VPATH_H
331