Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7f193c5b authored by Doris Liu's avatar Doris Liu Committed by Android (Google) Code Review
Browse files

Merge "Create SkCanvas on the stack to avoid leaking memeory"

parents 4eb533fe c2de46fa
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ namespace VectorDrawable {

const int Tree::MAX_CACHED_BITMAP_SIZE = 2048;

void Path::draw(Canvas* outCanvas, const SkMatrix& groupStackedMatrix, float scaleX, float scaleY) {
void Path::draw(SkCanvas* outCanvas, const SkMatrix& groupStackedMatrix, float scaleX, float scaleY) {
    float matrixScale = getMatrixScale(groupStackedMatrix);
    if (matrixScale == 0) {
        // When either x or y is scaled to 0, we don't need to draw anything.
@@ -186,7 +186,7 @@ inline SkColor applyAlpha(SkColor color, float alpha) {
    return SkColorSetA(color, alphaBytes * alpha);
}

void FullPath::drawPath(Canvas* outCanvas, const SkPath& renderPath, float strokeScale){
void FullPath::drawPath(SkCanvas* outCanvas, const SkPath& renderPath, float strokeScale){
    // Draw path's fill, if fill color isn't transparent.
    if (mFillColor != SK_ColorTRANSPARENT) {
        mPaint.setStyle(SkPaint::Style::kFill_Style);
@@ -287,9 +287,9 @@ bool FullPath::getProperties(int8_t* outProperties, int length) {
    return true;
}

void ClipPath::drawPath(Canvas* outCanvas, const SkPath& renderPath,
void ClipPath::drawPath(SkCanvas* outCanvas, const SkPath& renderPath,
        float strokeScale){
    outCanvas->clipPath(&renderPath, SkRegion::kIntersect_Op);
    outCanvas->clipPath(renderPath, SkRegion::kIntersect_Op);
}

Group::Group(const Group& group) : Node(group) {
@@ -302,7 +302,7 @@ Group::Group(const Group& group) : Node(group) {
    mTranslateY = group.mTranslateY;
}

void Group::draw(Canvas* outCanvas, const SkMatrix& currentMatrix, float scaleX,
void Group::draw(SkCanvas* outCanvas, const SkMatrix& currentMatrix, float scaleX,
        float scaleY) {
    // TODO: Try apply the matrix to the canvas instead of passing it down the tree

@@ -315,7 +315,7 @@ void Group::draw(Canvas* outCanvas, const SkMatrix& currentMatrix, float scaleX,
    stackedMatrix.postConcat(currentMatrix);

    // Save the current clip information, which is local to this group.
    outCanvas->save(SkCanvas::kMatrixClip_SaveFlag);
    outCanvas->save();
    // Draw the group tree in the same order as the XML file.
    for (Node* child : mChildren) {
        child->draw(outCanvas, stackedMatrix, scaleX, scaleY);
@@ -465,10 +465,10 @@ void Tree::drawCachedBitmapWithRootAlpha(Canvas* outCanvas, SkColorFilter* filte

void Tree::updateCachedBitmap(int width, int height) {
    mCachedBitmap.eraseColor(SK_ColorTRANSPARENT);
    Canvas* outCanvas = Canvas::create_canvas(mCachedBitmap);
    SkCanvas outCanvas(mCachedBitmap);
    float scaleX = width / mViewportWidth;
    float scaleY = height / mViewportHeight;
    mRootNode->draw(outCanvas, SkMatrix::I(), scaleX, scaleY);
    mRootNode->draw(&outCanvas, SkMatrix::I(), scaleX, scaleY);
    mCacheDirty = false;
}

+7 −6
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include "Canvas.h"
#include <SkBitmap.h>
#include <SkColor.h>
#include <SkCanvas.h>
#include <SkMatrix.h>
#include <SkPaint.h>
#include <SkPath.h>
@@ -56,7 +57,7 @@ public:
        mName = node.mName;
    }
    Node() {}
    virtual void draw(Canvas* outCanvas, const SkMatrix& currentMatrix,
    virtual void draw(SkCanvas* outCanvas, const SkMatrix& currentMatrix,
            float scaleX, float scaleY) = 0;
    virtual void dump() = 0;
    void setName(const char* name) {
@@ -85,7 +86,7 @@ public:
    void dump() override;
    bool canMorph(const Data& path);
    bool canMorph(const Path& path);
    void draw(Canvas* outCanvas, const SkMatrix& groupStackedMatrix,
    void draw(SkCanvas* outCanvas, const SkMatrix& groupStackedMatrix,
            float scaleX, float scaleY) override;
    void setPath(const char* path, size_t strLength);
    void setPathData(const Data& data);
@@ -93,7 +94,7 @@ public:

protected:
    virtual const SkPath& getUpdatedPath();
    virtual void drawPath(Canvas *outCanvas, const SkPath& renderPath,
    virtual void drawPath(SkCanvas *outCanvas, const SkPath& renderPath,
            float strokeScale) = 0;
    Data mData;
    SkPath mSkPath;
@@ -163,7 +164,7 @@ public:

protected:
    const SkPath& getUpdatedPath() override;
    void drawPath(Canvas* outCanvas, const SkPath& renderPath,
    void drawPath(SkCanvas* outCanvas, const SkPath& renderPath,
            float strokeScale) override;

private:
@@ -193,7 +194,7 @@ public:
    ClipPath(const Data& nodes) : Path(nodes) {}

protected:
    void drawPath(Canvas* outCanvas, const SkPath& renderPath,
    void drawPath(SkCanvas* outCanvas, const SkPath& renderPath,
            float strokeScale) override;
};

@@ -243,7 +244,7 @@ public:
    void setTranslateY(float translateY) {
        mTranslateY = translateY;
    }
    virtual void draw(Canvas* outCanvas, const SkMatrix& currentMatrix,
    virtual void draw(SkCanvas* outCanvas, const SkMatrix& currentMatrix,
            float scaleX, float scaleY) override;
    void updateLocalMatrix(float rotate, float pivotX, float pivotY,
            float scaleX, float scaleY, float translateX, float translateY);