OLD | NEW |
---|---|
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 Loading... | |
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.fWidth, info.fHeight, &fLockedBitmap)) { | 48 if (!SkBitmapCache::Find(this->getGenerationID(), SkIRect::MakeWH(info.fWidt h, info.fHeight), &fLockedBitmap)) { |
reed1
2014/09/03 18:48:06
nit: 100col max
Rémi Piotaix
2014/09/03 18:55:27
Done.
| |
48 // Cache has been purged, must re-decode. | 49 // Cache has been purged, must re-decode. |
49 if (!fLockedBitmap.allocPixels(info, fRowBytes)) { | 50 if (!fLockedBitmap.allocPixels(info, fRowBytes)) { |
50 fErrorInDecoding = true; | 51 fErrorInDecoding = true; |
51 return false; | 52 return false; |
52 } | 53 } |
53 if (!fImageGenerator->getPixels(info, fLockedBitmap.getPixels(), fRowByt es)) { | 54 if (!fImageGenerator->getPixels(info, fLockedBitmap.getPixels(), fRowByt es)) { |
54 fErrorInDecoding = true; | 55 fErrorInDecoding = true; |
55 return false; | 56 return false; |
56 } | 57 } |
57 fLockedBitmap.setImmutable(); | 58 fLockedBitmap.setImmutable(); |
58 SkBitmapCache::Add(this->getGenerationID(), info.fWidth, info.fHeight, f LockedBitmap); | 59 SkBitmapCache::Add(this->getGenerationID(), SkIRect::MakeWH(info.fWidth, info.fHeight), fLockedBitmap); |
reed1
2014/09/03 18:48:06
100col
Rémi Piotaix
2014/09/03 18:55:27
Done.
| |
59 } | 60 } |
60 | 61 |
61 // Now bitmap should contain a concrete PixelRef of the decoded image. | 62 // Now bitmap should contain a concrete PixelRef of the decoded image. |
62 void* pixels = fLockedBitmap.getPixels(); | 63 void* pixels = fLockedBitmap.getPixels(); |
63 SkASSERT(pixels != NULL); | 64 SkASSERT(pixels != NULL); |
64 rec->fPixels = pixels; | 65 rec->fPixels = pixels; |
65 rec->fColorTable = NULL; | 66 rec->fColorTable = NULL; |
66 rec->fRowBytes = fLockedBitmap.rowBytes(); | 67 rec->fRowBytes = fLockedBitmap.rowBytes(); |
67 return true; | 68 return true; |
68 } | 69 } |
69 | 70 |
70 void SkCachingPixelRef::onUnlockPixels() { | 71 void SkCachingPixelRef::onUnlockPixels() { |
71 fLockedBitmap.reset(); | 72 fLockedBitmap.reset(); |
72 } | 73 } |
OLD | NEW |