Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Unified Diff: src/core/SkPictureShader.cpp

Issue 240303003: Fix memory leak in SkGradientShader. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: getCache -> refCache; buildBitmapShader -> refBitmapShader Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkPictureShader.h ('k') | src/effects/gradients/SkGradientShader.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkPictureShader.cpp
diff --git a/src/core/SkPictureShader.cpp b/src/core/SkPictureShader.cpp
index 1e9507190c60a4ac4e8b16785c9dc06948f13e55..7110a5ba2f0cbe229e89de3e0f8e4354382dc042 100644
--- a/src/core/SkPictureShader.cpp
+++ b/src/core/SkPictureShader.cpp
@@ -55,7 +55,7 @@ void SkPictureShader::flatten(SkWriteBuffer& buffer) const {
}
}
-SkShader* SkPictureShader::buildBitmapShader(const SkMatrix& matrix) const {
+SkShader* SkPictureShader::refBitmapShader(const SkMatrix& matrix) const {
if (!fPicture || (0 == fPicture->width() && 0 == fPicture->height())) {
return NULL;
}
@@ -121,17 +121,12 @@ SkShader* SkPictureShader::validInternal(const SkBitmap& device, const SkPaint&
return NULL;
}
- SkShader* bitmapShader = this->buildBitmapShader(matrix);
- if (!bitmapShader) {
- return NULL;
- }
-
- if (!bitmapShader->validContext(device, paint, matrix)) {
- bitmapShader->unref();
+ SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(matrix));
+ if (!bitmapShader || !bitmapShader->validContext(device, paint, matrix)) {
return NULL;
}
- return bitmapShader;
+ return bitmapShader.detach();
}
bool SkPictureShader::validContext(const SkBitmap& device, const SkPaint& paint,
@@ -142,13 +137,13 @@ bool SkPictureShader::validContext(const SkBitmap& device, const SkPaint& paint,
SkShader::Context* SkPictureShader::createContext(const SkBitmap& device, const SkPaint& paint,
const SkMatrix& matrix, void* storage) const {
- SkShader* bitmapShader = this->validInternal(device, paint, matrix, NULL);
+ SkAutoTUnref<SkShader> bitmapShader(this->validInternal(device, paint, matrix, NULL));
if (!bitmapShader) {
return NULL;
}
return SkNEW_PLACEMENT_ARGS(storage, PictureShaderContext,
- (*this, device, paint, matrix, bitmapShader));
+ (*this, device, paint, matrix, bitmapShader.detach()));
}
size_t SkPictureShader::contextSize() const {
@@ -209,7 +204,7 @@ void SkPictureShader::toString(SkString* str) const {
#if SK_SUPPORT_GPU
GrEffectRef* SkPictureShader::asNewEffect(GrContext* context, const SkPaint& paint) const {
- SkAutoTUnref<SkShader> bitmapShader(this->buildBitmapShader(context->getMatrix()));
+ SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(context->getMatrix()));
if (!bitmapShader) {
return NULL;
}
« no previous file with comments | « src/core/SkPictureShader.h ('k') | src/effects/gradients/SkGradientShader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698