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

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

Issue 123223007: Revert "Revert "Revert "Revert of https://codereview.chromium.org/110593003/""" (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: fix compatibility mode for onLockPixels by pre-nulling colortable Created 6 years, 11 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/lazy/SkCachingPixelRef.h ('k') | src/lazy/SkDiscardablePixelRef.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 * 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 "SkScaledImageCache.h" 9 #include "SkScaledImageCache.h"
10 10
11
12 bool SkCachingPixelRef::Install(SkImageGenerator* generator, 11 bool SkCachingPixelRef::Install(SkImageGenerator* generator,
13 SkBitmap* dst) { 12 SkBitmap* dst) {
14 SkImageInfo info; 13 SkImageInfo info;
15 SkASSERT(dst != NULL); 14 SkASSERT(dst != NULL);
16 if ((NULL == generator) 15 if ((NULL == generator)
17 || !(generator->getInfo(&info)) 16 || !(generator->getInfo(&info))
18 || !dst->setConfig(info, 0)) { 17 || !dst->setConfig(info, 0)) {
19 SkDELETE(generator); 18 SkDELETE(generator);
20 return false; 19 return false;
21 } 20 }
(...skipping 12 matching lines...) Expand all
34 , fScaledCacheId(NULL) 33 , fScaledCacheId(NULL)
35 , fRowBytes(rowBytes) { 34 , fRowBytes(rowBytes) {
36 SkASSERT(fImageGenerator != NULL); 35 SkASSERT(fImageGenerator != NULL);
37 } 36 }
38 SkCachingPixelRef::~SkCachingPixelRef() { 37 SkCachingPixelRef::~SkCachingPixelRef() {
39 SkDELETE(fImageGenerator); 38 SkDELETE(fImageGenerator);
40 SkASSERT(NULL == fScaledCacheId); 39 SkASSERT(NULL == fScaledCacheId);
41 // Assert always unlock before unref. 40 // Assert always unlock before unref.
42 } 41 }
43 42
44 void* SkCachingPixelRef::onLockPixels(SkColorTable**) { 43 bool SkCachingPixelRef::onNewLockPixels(LockRec* rec) {
45 if (fErrorInDecoding) { 44 if (fErrorInDecoding) {
46 return NULL; // don't try again. 45 return false; // don't try again.
47 } 46 }
48 47
49 const SkImageInfo& info = this->info(); 48 const SkImageInfo& info = this->info();
50
51 SkBitmap bitmap; 49 SkBitmap bitmap;
52 SkASSERT(NULL == fScaledCacheId); 50 SkASSERT(NULL == fScaledCacheId);
53 fScaledCacheId = SkScaledImageCache::FindAndLock(this->getGenerationID(), 51 fScaledCacheId = SkScaledImageCache::FindAndLock(this->getGenerationID(),
54 info.fWidth, 52 info.fWidth,
55 info.fHeight, 53 info.fHeight,
56 &bitmap); 54 &bitmap);
57 if (NULL == fScaledCacheId) { 55 if (NULL == fScaledCacheId) {
58 // Cache has been purged, must re-decode. 56 // Cache has been purged, must re-decode.
59 if ((!bitmap.setConfig(info, fRowBytes)) || !bitmap.allocPixels()) { 57 if ((!bitmap.setConfig(info, fRowBytes)) || !bitmap.allocPixels()) {
60 fErrorInDecoding = true; 58 fErrorInDecoding = true;
61 return NULL; 59 return false;
62 } 60 }
63 SkAutoLockPixels autoLockPixels(bitmap); 61 SkAutoLockPixels autoLockPixels(bitmap);
64 if (!fImageGenerator->getPixels(info, bitmap.getPixels(), fRowBytes)) { 62 if (!fImageGenerator->getPixels(info, bitmap.getPixels(), fRowBytes)) {
65 fErrorInDecoding = true; 63 fErrorInDecoding = true;
66 return NULL; 64 return false;
67 } 65 }
68 fScaledCacheId = SkScaledImageCache::AddAndLock(this->getGenerationID(), 66 fScaledCacheId = SkScaledImageCache::AddAndLock(this->getGenerationID(),
69 info.fWidth, 67 info.fWidth,
70 info.fHeight, 68 info.fHeight,
71 bitmap); 69 bitmap);
72 SkASSERT(fScaledCacheId != NULL); 70 SkASSERT(fScaledCacheId != NULL);
73 } 71 }
74 72
75 // Now bitmap should contain a concrete PixelRef of the decoded 73 // Now bitmap should contain a concrete PixelRef of the decoded
76 // image. 74 // image.
77 SkAutoLockPixels autoLockPixels(bitmap); 75 SkAutoLockPixels autoLockPixels(bitmap);
78 void* pixels = bitmap.getPixels(); 76 void* pixels = bitmap.getPixels();
79 SkASSERT(pixels != NULL); 77 SkASSERT(pixels != NULL);
80 78
81 // At this point, the autoLockPixels will unlockPixels() 79 // At this point, the autoLockPixels will unlockPixels()
82 // to remove bitmap's lock on the pixels. We will then 80 // to remove bitmap's lock on the pixels. We will then
83 // destroy bitmap. The *only* guarantee that this pointer 81 // destroy bitmap. The *only* guarantee that this pointer
84 // remains valid is the guarantee made by 82 // remains valid is the guarantee made by
85 // SkScaledImageCache that it will not destroy the *other* 83 // SkScaledImageCache that it will not destroy the *other*
86 // bitmap (SkScaledImageCache::Rec.fBitmap) that holds a 84 // bitmap (SkScaledImageCache::Rec.fBitmap) that holds a
87 // reference to the concrete PixelRef while this record is 85 // reference to the concrete PixelRef while this record is
88 // locked. 86 // locked.
89 return pixels; 87 rec->fPixels = pixels;
88 rec->fColorTable = NULL;
89 rec->fRowBytes = bitmap.rowBytes();
90 return true;
90 } 91 }
91 92
92 void SkCachingPixelRef::onUnlockPixels() { 93 void SkCachingPixelRef::onUnlockPixels() {
93 SkASSERT(fScaledCacheId != NULL); 94 SkASSERT(fScaledCacheId != NULL);
94 SkScaledImageCache::Unlock( static_cast<SkScaledImageCache::ID*>(fScaledCach eId)); 95 SkScaledImageCache::Unlock( static_cast<SkScaledImageCache::ID*>(fScaledCach eId));
95 fScaledCacheId = NULL; 96 fScaledCacheId = NULL;
96 } 97 }
OLDNEW
« no previous file with comments | « src/lazy/SkCachingPixelRef.h ('k') | src/lazy/SkDiscardablePixelRef.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698