Create SkCanvas on the stack to avoid leaking memeory
Bug: 26447978
Change-Id: Ied022c103c3b08e9cfc3cb775a8c95fd5461e81d
diff --git a/libs/hwui/VectorDrawable.cpp b/libs/hwui/VectorDrawable.cpp
index 793df92..3e20608 100644
--- a/libs/hwui/VectorDrawable.cpp
+++ b/libs/hwui/VectorDrawable.cpp
@@ -31,7 +31,7 @@
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 @@
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 @@
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 @@
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 @@
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::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;
}
diff --git a/libs/hwui/VectorDrawable.h b/libs/hwui/VectorDrawable.h
index 6c84b05..5ae5f6a 100644
--- a/libs/hwui/VectorDrawable.h
+++ b/libs/hwui/VectorDrawable.h
@@ -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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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);