diff options
author | Doris Liu <tianliu@google.com> | 2016-10-10 15:50:01 -0700 |
---|---|---|
committer | Doris Liu <tianliu@google.com> | 2016-10-12 01:22:11 +0000 |
commit | fc9cf72339c7ce61adb11ceb3b247f112577fb6b (patch) | |
tree | 3ba78d43724d731fe47fbda1c0b2fbd3db27129e /libs/hwui/VectorDrawable.cpp | |
parent | 6c816c6707a5539a7a951617a8b621887c36eb38 (diff) |
Fix SkShader leak for Gradient VectorDrawable and test
This CL fixes a SkShader leak in VD when applying local matrix
to the shader. Specifically, the usage of newWithLocalMatrix(...)
increments the shader's ref count in every draw() call for
Gradient VectorDrawable, whereas there's no balancing call to
decrement the ref count in draw(). In this CL, we assume
the ownership of the shader returned from newWithLocalMatrix(...)
to ensure the correct ref count management.
Also, add test to verify that shader is no longer being leaked
BUG: 32067647
Test: this CL
Change-Id: Ic15fe46cde06a73d81b44e2d3c56b51907344cc0
Diffstat (limited to 'libs/hwui/VectorDrawable.cpp')
-rw-r--r-- | libs/hwui/VectorDrawable.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/libs/hwui/VectorDrawable.cpp b/libs/hwui/VectorDrawable.cpp index 2b7994139641..aeee66106fb3 100644 --- a/libs/hwui/VectorDrawable.cpp +++ b/libs/hwui/VectorDrawable.cpp @@ -202,7 +202,9 @@ void FullPath::drawPath(SkCanvas* outCanvas, SkPath& renderPath, float strokeSca if (properties.getFillGradient() != nullptr) { paint.setColor(applyAlpha(SK_ColorBLACK, properties.getFillAlpha())); SkShader* newShader = properties.getFillGradient()->newWithLocalMatrix(matrix); - paint.setShader(newShader); + // newWithLocalMatrix(...) creates a new SkShader and returns a bare pointer. We need to + // remove the extra ref so that the ref count is correctly managed. + paint.setShader(newShader)->unref(); needsFill = true; } else if (properties.getFillColor() != SK_ColorTRANSPARENT) { paint.setColor(applyAlpha(properties.getFillColor(), properties.getFillAlpha())); @@ -222,7 +224,9 @@ void FullPath::drawPath(SkCanvas* outCanvas, SkPath& renderPath, float strokeSca if (properties.getStrokeGradient() != nullptr) { paint.setColor(applyAlpha(SK_ColorBLACK, properties.getStrokeAlpha())); SkShader* newShader = properties.getStrokeGradient()->newWithLocalMatrix(matrix); - paint.setShader(newShader); + // newWithLocalMatrix(...) creates a new SkShader and returns a bare pointer. We need to + // remove the extra ref so that the ref count is correctly managed. + paint.setShader(newShader)->unref(); needsStroke = true; } else if (properties.getStrokeColor() != SK_ColorTRANSPARENT) { paint.setColor(applyAlpha(properties.getStrokeColor(), properties.getStrokeAlpha())); |