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

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

Issue 691143008: Avoid the use of mipmaps to prevent memory leak (Closed) Base URL: https://skia.googlesource.com/skia.git@m39
Patch Set: Created 6 years, 1 month 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 | « no previous file | no next file » | 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 2011 Google Inc. 2 * Copyright 2011 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 "SkBitmapCache.h" 8 #include "SkBitmapCache.h"
9 #include "SkBitmapProcState.h" 9 #include "SkBitmapProcState.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 return false; 245 return false;
246 } 246 }
247 247
248 // else set the filter-level to Medium, since we're scaling down and 248 // else set the filter-level to Medium, since we're scaling down and
249 // want to reqeust mipmaps 249 // want to reqeust mipmaps
250 fFilterLevel = SkPaint::kMedium_FilterLevel; 250 fFilterLevel = SkPaint::kMedium_FilterLevel;
251 } 251 }
252 252
253 SkASSERT(SkPaint::kMedium_FilterLevel == fFilterLevel); 253 SkASSERT(SkPaint::kMedium_FilterLevel == fFilterLevel);
254 254
255 /** 255 // HACK: Disable use of mipmaps in M39 since they do not use discardable
256 * Medium quality means use a mipmap for down-scaling, and just bilper 256 // memory in the cache.
257 * for upscaling. Since we're examining the inverse matrix, we look for 257 fFilterLevel = SkPaint::kLow_FilterLevel;
258 * a scale > 1 to indicate down scaling by the CTM.
259 */
260 if (scaleSqd > SK_Scalar1) {
261 fCurrMip.reset(SkMipMapCache::FindAndRef(fOrigBitmap));
262 if (NULL == fCurrMip.get()) {
263 fCurrMip.reset(SkMipMap::Build(fOrigBitmap));
264 if (NULL == fCurrMip.get()) {
265 return false;
266 }
267 SkMipMapCache::Add(fOrigBitmap, fCurrMip);
268 }
269
270 SkScalar levelScale = SkScalarInvert(SkScalarSqrt(scaleSqd));
271 SkMipMap::Level level;
272 if (fCurrMip->extractLevel(levelScale, &level)) {
273 SkScalar invScaleFixup = level.fScale;
274 fInvMatrix.postScale(invScaleFixup, invScaleFixup);
275
276 const SkImageInfo info = fOrigBitmap.info().makeWH(level.fWidth, lev el.fHeight);
277 // todo: if we could wrap the fCurrMip in a pixelref, then we could just install
278 // that here, and not need to explicitly track it ourselves.
279 fScaledBitmap.installPixels(info, level.fPixels, level.fRowBytes);
280 fBitmap = &fScaledBitmap;
281 fFilterLevel = SkPaint::kLow_FilterLevel;
282 return true;
283 }
284 }
285 258
286 return false; 259 return false;
287 } 260 }
288 261
289 static bool get_locked_pixels(const SkBitmap& src, int pow2, SkBitmap* dst) { 262 static bool get_locked_pixels(const SkBitmap& src, int pow2, SkBitmap* dst) {
290 SkPixelRef* pr = src.pixelRef(); 263 SkPixelRef* pr = src.pixelRef();
291 if (pr && pr->decodeInto(pow2, dst)) { 264 if (pr && pr->decodeInto(pow2, dst)) {
292 return true; 265 return true;
293 } 266 }
294 267
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 } else { 979 } else {
1007 size >>= 2; 980 size >>= 2;
1008 } 981 }
1009 982
1010 if (fFilterLevel != SkPaint::kNone_FilterLevel) { 983 if (fFilterLevel != SkPaint::kNone_FilterLevel) {
1011 size >>= 1; 984 size >>= 1;
1012 } 985 }
1013 986
1014 return size; 987 return size;
1015 } 988 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698