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

Side by Side Diff: src/core/SkBitmapProcState.cpp

Issue 20102002: free cache in destructor, in case endContext was not called. change Resize to return bool indicatin… (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « src/core/SkBitmapProcState.h ('k') | src/core/SkBitmapScaler.h » ('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 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "SkBitmapProcState.h" 8 #include "SkBitmapProcState.h"
9 #include "SkColorPriv.h" 9 #include "SkColorPriv.h"
10 #include "SkFilterProc.h" 10 #include "SkFilterProc.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 SkASSERT(NULL == fScaledCacheID); 150 SkASSERT(NULL == fScaledCacheID);
151 fScaledCacheID = SkScaledImageCache::FindAndLock(fOrigBitmap, 151 fScaledCacheID = SkScaledImageCache::FindAndLock(fOrigBitmap,
152 invScaleX, invScaleY, 152 invScaleX, invScaleY,
153 &fScaledBitmap); 153 &fScaledBitmap);
154 if (NULL == fScaledCacheID) { 154 if (NULL == fScaledCacheID) {
155 int dest_width = SkScalarCeilToInt(fOrigBitmap.width() / invScaleX) ; 155 int dest_width = SkScalarCeilToInt(fOrigBitmap.width() / invScaleX) ;
156 int dest_height = SkScalarCeilToInt(fOrigBitmap.height() / invScaleY ); 156 int dest_height = SkScalarCeilToInt(fOrigBitmap.height() / invScaleY );
157 157
158 // All the criteria are met; let's make a new bitmap. 158 // All the criteria are met; let's make a new bitmap.
159 159
160 fScaledBitmap = SkBitmapScaler::Resize(fOrigBitmap, 160 if (!SkBitmapScaler::Resize(&fScaledBitmap,
161 SkBitmapScaler::RESIZE_BEST, 161 fOrigBitmap,
162 dest_width, 162 SkBitmapScaler::RESIZE_BEST,
163 dest_height, 163 dest_width,
164 fConvolutionProcs); 164 dest_height,
165 fConvolutionProcs)) {
166 // we failed to create fScaledBitmap, so just return and let
167 // the scanline proc handle it.
168 return;
169
170 }
165 fScaledCacheID = SkScaledImageCache::AddAndLock(fOrigBitmap, 171 fScaledCacheID = SkScaledImageCache::AddAndLock(fOrigBitmap,
166 invScaleX, 172 invScaleX,
167 invScaleY, 173 invScaleY,
168 fScaledBitmap); 174 fScaledBitmap);
169 } 175 }
170 fScaledBitmap.lockPixels(); 176 fScaledBitmap.lockPixels();
171 177
172 fBitmap = &fScaledBitmap; 178 fBitmap = &fScaledBitmap;
173 179
174 // set the inv matrix type to translate-only; 180 // set the inv matrix type to translate-only;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 SkDELETE(fBitmapFilter); 276 SkDELETE(fBitmapFilter);
271 fBitmapFilter = NULL; 277 fBitmapFilter = NULL;
272 fScaledBitmap.reset(); 278 fScaledBitmap.reset();
273 279
274 if (fScaledCacheID) { 280 if (fScaledCacheID) {
275 SkScaledImageCache::Unlock(fScaledCacheID); 281 SkScaledImageCache::Unlock(fScaledCacheID);
276 fScaledCacheID = NULL; 282 fScaledCacheID = NULL;
277 } 283 }
278 } 284 }
279 285
286 SkBitmapProcState::~SkBitmapProcState() {
287 if (fScaledCacheID) {
288 SkScaledImageCache::Unlock(fScaledCacheID);
289 }
290 SkDELETE(fBitmapFilter);
291 }
292
280 bool SkBitmapProcState::chooseProcs(const SkMatrix& inv, const SkPaint& paint) { 293 bool SkBitmapProcState::chooseProcs(const SkMatrix& inv, const SkPaint& paint) {
281 if (fOrigBitmap.width() == 0 || fOrigBitmap.height() == 0) { 294 if (fOrigBitmap.width() == 0 || fOrigBitmap.height() == 0) {
282 return false; 295 return false;
283 } 296 }
284 297
285 bool trivialMatrix = (inv.getType() & ~SkMatrix::kTranslate_Mask) == 0; 298 bool trivialMatrix = (inv.getType() & ~SkMatrix::kTranslate_Mask) == 0;
286 bool clampClamp = SkShader::kClamp_TileMode == fTileModeX && 299 bool clampClamp = SkShader::kClamp_TileMode == fTileModeX &&
287 SkShader::kClamp_TileMode == fTileModeY; 300 SkShader::kClamp_TileMode == fTileModeY;
288 301
289 fInvMatrix = inv; 302 fInvMatrix = inv;
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 } else { 949 } else {
937 size >>= 2; 950 size >>= 2;
938 } 951 }
939 952
940 if (fFilterLevel != SkPaint::kNone_FilterLevel) { 953 if (fFilterLevel != SkPaint::kNone_FilterLevel) {
941 size >>= 1; 954 size >>= 1;
942 } 955 }
943 956
944 return size; 957 return size;
945 } 958 }
OLDNEW
« no previous file with comments | « src/core/SkBitmapProcState.h ('k') | src/core/SkBitmapScaler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698