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

Side by Side Diff: src/lazy/SkCachingPixelRef.cpp

Issue 539643002: Remove SkBitmapCache::Find/Add(_,width,height,_) in favor of using rect (Closed) Base URL: https://skia.googlesource.com/skia.git@bitmapCache_add_rect
Patch Set: Rebase master Created 6 years, 3 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/SkBitmapCache.cpp ('k') | 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 2013 Google Inc. 2 * Copyright 2013 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 "SkCachingPixelRef.h" 8 #include "SkCachingPixelRef.h"
9 #include "SkBitmapCache.h" 9 #include "SkBitmapCache.h"
10 #include "SkRect.h"
10 11
11 bool SkCachingPixelRef::Install(SkImageGenerator* generator, 12 bool SkCachingPixelRef::Install(SkImageGenerator* generator,
12 SkBitmap* dst) { 13 SkBitmap* dst) {
13 SkImageInfo info; 14 SkImageInfo info;
14 SkASSERT(dst != NULL); 15 SkASSERT(dst != NULL);
15 if ((NULL == generator) 16 if ((NULL == generator)
16 || !(generator->getInfo(&info)) 17 || !(generator->getInfo(&info))
17 || !dst->setInfo(info)) { 18 || !dst->setInfo(info)) {
18 SkDELETE(generator); 19 SkDELETE(generator);
19 return false; 20 return false;
(...skipping 17 matching lines...) Expand all
37 SkDELETE(fImageGenerator); 38 SkDELETE(fImageGenerator);
38 // Assert always unlock before unref. 39 // Assert always unlock before unref.
39 } 40 }
40 41
41 bool SkCachingPixelRef::onNewLockPixels(LockRec* rec) { 42 bool SkCachingPixelRef::onNewLockPixels(LockRec* rec) {
42 if (fErrorInDecoding) { 43 if (fErrorInDecoding) {
43 return false; // don't try again. 44 return false; // don't try again.
44 } 45 }
45 46
46 const SkImageInfo& info = this->info(); 47 const SkImageInfo& info = this->info();
47 if (!SkBitmapCache::Find(this->getGenerationID(), info.width(), info.height( ), &fLockedBitmap)) { 48 if (!SkBitmapCache::Find(this->getGenerationID(),
49 SkIRect::MakeWH(info.width(), info.height()),
50 &fLockedBitmap)) {
48 // Cache has been purged, must re-decode. 51 // Cache has been purged, must re-decode.
49 if (!fLockedBitmap.tryAllocPixels(info, fRowBytes)) { 52 if (!fLockedBitmap.tryAllocPixels(info, fRowBytes)) {
50 fErrorInDecoding = true; 53 fErrorInDecoding = true;
51 return false; 54 return false;
52 } 55 }
53 if (!fImageGenerator->getPixels(info, fLockedBitmap.getPixels(), fRowByt es)) { 56 if (!fImageGenerator->getPixels(info, fLockedBitmap.getPixels(), fRowByt es)) {
54 fErrorInDecoding = true; 57 fErrorInDecoding = true;
55 return false; 58 return false;
56 } 59 }
57 fLockedBitmap.setImmutable(); 60 fLockedBitmap.setImmutable();
58 SkBitmapCache::Add(this->getGenerationID(), info.width(), info.height(), fLockedBitmap); 61 SkBitmapCache::Add(this->getGenerationID(),
62 SkIRect::MakeWH(info.width(), info.height()),
63 fLockedBitmap);
59 } 64 }
60 65
61 // Now bitmap should contain a concrete PixelRef of the decoded image. 66 // Now bitmap should contain a concrete PixelRef of the decoded image.
62 void* pixels = fLockedBitmap.getPixels(); 67 void* pixels = fLockedBitmap.getPixels();
63 SkASSERT(pixels != NULL); 68 SkASSERT(pixels != NULL);
64 rec->fPixels = pixels; 69 rec->fPixels = pixels;
65 rec->fColorTable = NULL; 70 rec->fColorTable = NULL;
66 rec->fRowBytes = fLockedBitmap.rowBytes(); 71 rec->fRowBytes = fLockedBitmap.rowBytes();
67 return true; 72 return true;
68 } 73 }
69 74
70 void SkCachingPixelRef::onUnlockPixels() { 75 void SkCachingPixelRef::onUnlockPixels() {
71 fLockedBitmap.reset(); 76 fLockedBitmap.reset();
72 } 77 }
OLDNEW
« no previous file with comments | « src/core/SkBitmapCache.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698