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 #ifndef SkCachingPixelRef_DEFINED | 8 #ifndef SkCachingPixelRef_DEFINED |
9 #define SkCachingPixelRef_DEFINED | 9 #define SkCachingPixelRef_DEFINED |
10 | 10 |
11 #include "SkImage.h" | 11 #include "SkImageInfo.h" |
12 #include "SkImageGenerator.h" | |
12 #include "SkPixelRef.h" | 13 #include "SkPixelRef.h" |
13 | 14 |
14 class SkColorTable; | 15 class SkColorTable; |
15 | 16 |
16 /** | 17 /** |
17 * PixelRef which defers decoding until SkBitmap::lockPixels() is | 18 * PixelRef which defers decoding until SkBitmap::lockPixels() is |
18 * called. Caches the decoded images in the global | 19 * called. Caches the decoded images in the global |
19 * SkScaledImageCache. When the pixels are unlocked, this cache may | 20 * SkScaledImageCache. When the pixels are unlocked, this cache may |
20 * or be destroyed before the next lock. If so, onLockPixels will | 21 * or be destroyed before the next lock. If so, onLockPixels will |
21 * attempt to re-decode. | 22 * attempt to re-decode. |
22 * | 23 * |
23 * Decoding is handled by the pure-virtual functions onDecodeInfo() | 24 * Decoding is handled by the SkImageGenerator |
24 * and onDecodePixels(). Subclasses of this class need only provide | |
25 * those two functions. | |
26 */ | 25 */ |
27 class SkCachingPixelRef : public SkPixelRef { | 26 class SkCachingPixelRef : public SkPixelRef { |
28 public: | 27 public: |
29 SkCachingPixelRef(); | 28 /** |
30 virtual ~SkCachingPixelRef(); | 29 * This created SkCachingPixelRef will take ownership of the |
scroggo
2013/12/02 18:26:01
Could you say that the SkCachingPixelRef is instal
| |
30 * SkImageGenerator and destroy it. | |
31 */ | |
32 static bool Install(SkAutoTDelete<SkImageGenerator>* gen, SkBitmap* dst); | |
scroggo
2013/12/02 18:26:01
Although I understand the motivation - it simplifi
hal.canary
2013/12/04 23:06:41
I ended up changing my mind on this. Let's keep t
| |
31 | 33 |
32 protected: | 34 protected: |
35 virtual ~SkCachingPixelRef(); | |
33 virtual void* onLockPixels(SkColorTable** colorTable) SK_OVERRIDE; | 36 virtual void* onLockPixels(SkColorTable** colorTable) SK_OVERRIDE; |
34 virtual void onUnlockPixels() SK_OVERRIDE; | 37 virtual void onUnlockPixels() SK_OVERRIDE; |
35 virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; } | 38 virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; } |
36 virtual bool onImplementsDecodeInto() SK_OVERRIDE { return true; } | |
37 virtual bool onDecodeInto(int pow2, SkBitmap*) SK_OVERRIDE; | |
38 | 39 |
39 /** | 40 virtual SkData* onRefEncodedData() SK_OVERRIDE { |
40 * Configure the supplied bitmap for this pixelRef, based on | 41 return fImageGenerator->refEncodedData(); |
41 * information provided by onDecodeInfo(). Does not set the | 42 } |
42 * bitmap's pixelRef. */ | 43 // No need to flatten this object. When flattening an SkBitmap, |
43 bool configure(SkBitmap* bitmap); | 44 // SkOrderedWriteBuffer will check the encoded data and write that |
44 | 45 // instead. |
45 /** | 46 // Future implementations of SkFlattenableWriteBuffer will need to |
46 * Cache info from onDecodeInfo(). Returns false on failure. | 47 // special case for onRefEncodedData as well. |
47 */ | 48 SK_DECLARE_UNFLATTENABLE_OBJECT() |
48 bool getInfo(SkImageInfo* info); | |
49 | |
50 /** | |
51 * Return some information about the pixels, allowing this class | |
52 * to allocate pixels. @return false if anything goes wrong. | |
53 */ | |
54 virtual bool onDecodeInfo(SkImageInfo* info) = 0; | |
55 /** | |
56 * Decode into the given pixels, a block of memory of size | |
57 * (info.fHeight - 1) * rowBytes + (info.fWidth * bytesPerPixel) | |
58 * | |
59 * @param info Should be identical to the info returned by | |
60 * onDecodeInfo so that the implementation can confirm | |
61 * that the caller knows what it is asking for (config, | |
62 * size). Thiscontract also allows the caller to specify | |
63 * different output-configs, which the implementation can | |
64 * decide to support or not. | |
65 * | |
66 * @return false if anything goes wrong. | |
67 */ | |
68 virtual bool onDecodePixels(const SkImageInfo& info, | |
69 void* pixels, | |
70 size_t rowBytes) = 0; | |
71 | 49 |
72 private: | 50 private: |
73 bool fErrorInDecoding; | 51 SkImageGenerator* fImageGenerator; |
74 void* fScaledCacheId; | 52 bool fErrorInDecoding; |
75 SkImageInfo fInfo; | 53 void* fScaledCacheId; |
54 SkImageInfo fInfo; | |
scroggo
2013/12/02 18:26:01
fInfo and fRowBytes can be const.
hal.canary
2013/12/04 23:06:41
Done.
| |
55 size_t fRowBytes; | |
76 | 56 |
57 SkCachingPixelRef(SkImageGenerator* imageGenerator, | |
58 const SkImageInfo& info, | |
59 size_t rowBytes); | |
77 typedef SkPixelRef INHERITED; | 60 typedef SkPixelRef INHERITED; |
78 }; | 61 }; |
79 | 62 |
80 #endif // SkCachingPixelRef_DEFINED | 63 #endif // SkCachingPixelRef_DEFINED |
OLD | NEW |