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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/core/SkPictureShader.h ('k') | src/effects/gradients/SkGradientShader.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkPictureShader.h" 8 #include "SkPictureShader.h"
9 9
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 this->INHERITED::flatten(buffer); 48 this->INHERITED::flatten(buffer);
49 49
50 buffer.write32(fTmx); 50 buffer.write32(fTmx);
51 buffer.write32(fTmy); 51 buffer.write32(fTmy);
52 buffer.writeBool(NULL != fPicture); 52 buffer.writeBool(NULL != fPicture);
53 if (fPicture) { 53 if (fPicture) {
54 fPicture->flatten(buffer); 54 fPicture->flatten(buffer);
55 } 55 }
56 } 56 }
57 57
58 SkShader* SkPictureShader::buildBitmapShader(const SkMatrix& matrix) const { 58 SkShader* SkPictureShader::refBitmapShader(const SkMatrix& matrix) const {
59 if (!fPicture || (0 == fPicture->width() && 0 == fPicture->height())) { 59 if (!fPicture || (0 == fPicture->width() && 0 == fPicture->height())) {
60 return NULL; 60 return NULL;
61 } 61 }
62 62
63 SkMatrix m; 63 SkMatrix m;
64 if (this->hasLocalMatrix()) { 64 if (this->hasLocalMatrix()) {
65 m.setConcat(matrix, this->getLocalMatrix()); 65 m.setConcat(matrix, this->getLocalMatrix());
66 } else { 66 } else {
67 m = matrix; 67 m = matrix;
68 } 68 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 fCachedBitmapShader.get()->ref(); 114 fCachedBitmapShader.get()->ref();
115 return fCachedBitmapShader; 115 return fCachedBitmapShader;
116 } 116 }
117 117
118 SkShader* SkPictureShader::validInternal(const SkBitmap& device, const SkPaint& paint, 118 SkShader* SkPictureShader::validInternal(const SkBitmap& device, const SkPaint& paint,
119 const SkMatrix& matrix, SkMatrix* total Inverse) const { 119 const SkMatrix& matrix, SkMatrix* total Inverse) const {
120 if (!this->INHERITED::validContext(device, paint, matrix, totalInverse)) { 120 if (!this->INHERITED::validContext(device, paint, matrix, totalInverse)) {
121 return NULL; 121 return NULL;
122 } 122 }
123 123
124 SkShader* bitmapShader = this->buildBitmapShader(matrix); 124 SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(matrix));
125 if (!bitmapShader) { 125 if (!bitmapShader || !bitmapShader->validContext(device, paint, matrix)) {
126 return NULL; 126 return NULL;
127 } 127 }
128 128
129 if (!bitmapShader->validContext(device, paint, matrix)) { 129 return bitmapShader.detach();
130 bitmapShader->unref();
131 return NULL;
132 }
133
134 return bitmapShader;
135 } 130 }
136 131
137 bool SkPictureShader::validContext(const SkBitmap& device, const SkPaint& paint, 132 bool SkPictureShader::validContext(const SkBitmap& device, const SkPaint& paint,
138 const SkMatrix& matrix, SkMatrix* totalInvers e) const { 133 const SkMatrix& matrix, SkMatrix* totalInvers e) const {
139 SkAutoTUnref<SkShader> shader(this->validInternal(device, paint, matrix, tot alInverse)); 134 SkAutoTUnref<SkShader> shader(this->validInternal(device, paint, matrix, tot alInverse));
140 return shader != NULL; 135 return shader != NULL;
141 } 136 }
142 137
143 SkShader::Context* SkPictureShader::createContext(const SkBitmap& device, const SkPaint& paint, 138 SkShader::Context* SkPictureShader::createContext(const SkBitmap& device, const SkPaint& paint,
144 const SkMatrix& matrix, void* storage) const { 139 const SkMatrix& matrix, void* storage) const {
145 SkShader* bitmapShader = this->validInternal(device, paint, matrix, NULL); 140 SkAutoTUnref<SkShader> bitmapShader(this->validInternal(device, paint, matri x, NULL));
146 if (!bitmapShader) { 141 if (!bitmapShader) {
147 return NULL; 142 return NULL;
148 } 143 }
149 144
150 return SkNEW_PLACEMENT_ARGS(storage, PictureShaderContext, 145 return SkNEW_PLACEMENT_ARGS(storage, PictureShaderContext,
151 (*this, device, paint, matrix, bitmapShader)); 146 (*this, device, paint, matrix, bitmapShader.deta ch()));
152 } 147 }
153 148
154 size_t SkPictureShader::contextSize() const { 149 size_t SkPictureShader::contextSize() const {
155 return sizeof(PictureShaderContext); 150 return sizeof(PictureShaderContext);
156 } 151 }
157 152
158 SkPictureShader::PictureShaderContext::PictureShaderContext( 153 SkPictureShader::PictureShaderContext::PictureShaderContext(
159 const SkPictureShader& shader, const SkBitmap& device, 154 const SkPictureShader& shader, const SkBitmap& device,
160 const SkPaint& paint, const SkMatrix& matrix, SkShader* bitmapShader) 155 const SkPaint& paint, const SkMatrix& matrix, SkShader* bitmapShader)
161 : INHERITED(shader, device, paint, matrix) 156 : INHERITED(shader, device, paint, matrix)
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 fPicture ? fPicture->height() : 0); 197 fPicture ? fPicture->height() : 0);
203 198
204 str->appendf("(%s, %s)", gTileModeName[fTmx], gTileModeName[fTmy]); 199 str->appendf("(%s, %s)", gTileModeName[fTmx], gTileModeName[fTmy]);
205 200
206 this->INHERITED::toString(str); 201 this->INHERITED::toString(str);
207 } 202 }
208 #endif 203 #endif
209 204
210 #if SK_SUPPORT_GPU 205 #if SK_SUPPORT_GPU
211 GrEffectRef* SkPictureShader::asNewEffect(GrContext* context, const SkPaint& pai nt) const { 206 GrEffectRef* SkPictureShader::asNewEffect(GrContext* context, const SkPaint& pai nt) const {
212 SkAutoTUnref<SkShader> bitmapShader(this->buildBitmapShader(context->getMatr ix())); 207 SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(context->getMatrix ()));
213 if (!bitmapShader) { 208 if (!bitmapShader) {
214 return NULL; 209 return NULL;
215 } 210 }
216 return bitmapShader->asNewEffect(context, paint); 211 return bitmapShader->asNewEffect(context, paint);
217 } 212 }
218 #endif 213 #endif
OLDNEW
« 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