OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 SkLazyPixelRef_DEFINED | 8 #ifndef SkLazyPixelRef_DEFINED |
9 #define SkLazyPixelRef_DEFINED | 9 #define SkLazyPixelRef_DEFINED |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... | |
26 /** | 26 /** |
27 * PixelRef which defers decoding until SkBitmap::lockPixels() is called. | 27 * PixelRef which defers decoding until SkBitmap::lockPixels() is called. |
28 */ | 28 */ |
29 class SkLazyPixelRef : public SkPixelRef { | 29 class SkLazyPixelRef : public SkPixelRef { |
30 | 30 |
31 public: | 31 public: |
32 /** | 32 /** |
33 * Create a new SkLazyPixelRef. | 33 * Create a new SkLazyPixelRef. |
34 * @param SkData Encoded data representing the pixels. | 34 * @param SkData Encoded data representing the pixels. |
35 * @param DecodeProc Called to decode the pixels when needed. Must be non-N ULL. | 35 * @param DecodeProc Called to decode the pixels when needed. Must be non-N ULL. |
36 * @param SkImageCache Object that handles allocating and freeing the pixel memory, as needed. | 36 * @param SkImageCache Object that handles allocating and freeing |
37 * Must not be NULL. | 37 * the pixel memory, as needed. If NULL, use the global |
38 * SkScaledImageCache. | |
38 */ | 39 */ |
39 SkLazyPixelRef(SkData*, SkBitmapFactory::DecodeProc, SkImageCache*); | 40 SkLazyPixelRef(SkData*, SkBitmapFactory::DecodeProc, SkImageCache*); |
40 | 41 |
41 virtual ~SkLazyPixelRef(); | 42 virtual ~SkLazyPixelRef(); |
42 | 43 |
43 #ifdef SK_DEBUG | 44 #ifdef SK_DEBUG |
44 intptr_t getCacheId() const { return fCacheId; } | 45 intptr_t getCacheId() const { return fCacheId; } |
45 #endif | 46 #endif |
46 | 47 |
47 #if LAZY_CACHE_STATS | 48 #if LAZY_CACHE_STATS |
48 static int32_t GetCacheHits() { return gCacheHits; } | 49 static int32_t GetCacheHits() { return gCacheHits; } |
49 static int32_t GetCacheMisses() { return gCacheMisses; } | 50 static int32_t GetCacheMisses() { return gCacheMisses; } |
50 static void ResetCacheStats() { gCacheHits = gCacheMisses = 0; } | 51 static void ResetCacheStats() { gCacheHits = gCacheMisses = 0; } |
51 #endif | 52 #endif |
52 | 53 |
53 // No need to flatten this object. When flattening an SkBitmap, SkOrderedWri teBuffer will check | 54 // No need to flatten this object. When flattening an SkBitmap, SkOrderedWri teBuffer will check |
54 // the encoded data and write that instead. | 55 // the encoded data and write that instead. |
55 // Future implementations of SkFlattenableWriteBuffer will need to special c ase for | 56 // Future implementations of SkFlattenableWriteBuffer will need to special c ase for |
56 // onRefEncodedData as well. | 57 // onRefEncodedData as well. |
57 SK_DECLARE_UNFLATTENABLE_OBJECT() | 58 SK_DECLARE_UNFLATTENABLE_OBJECT() |
58 | 59 |
59 protected: | 60 protected: |
60 virtual void* onLockPixels(SkColorTable**) SK_OVERRIDE; | 61 virtual void* onLockPixels(SkColorTable**) SK_OVERRIDE; |
61 virtual void onUnlockPixels() SK_OVERRIDE; | 62 virtual void onUnlockPixels() SK_OVERRIDE; |
62 virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; } | 63 virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; } |
63 virtual SkData* onRefEncodedData() SK_OVERRIDE; | 64 virtual SkData* onRefEncodedData() SK_OVERRIDE; |
64 virtual bool onImplementsDecodeInto() SK_OVERRIDE; | 65 virtual bool onImplementsDecodeInto() SK_OVERRIDE; |
65 virtual bool onDecodeInto(int pow2, SkBitmap*) SK_OVERRIDE; | 66 virtual bool onDecodeInto(int pow2, SkBitmap*) SK_OVERRIDE; |
66 | 67 |
68 /** | |
69 * The allocator is used when (fImageCache==NULL) to allocate | |
70 * concrete PixelRefs as needed. If NULL, use the default allocator. | |
71 * This is passed directly into SkBitmap::allocPixels(). | |
72 */ | |
73 virtual void setAllocator(SkBitmap::Allocator * allocator = NULL) { | |
74 fAllocator = allocator; | |
scroggo
2013/10/23 15:27:49
SkBitmap::Allocator inherits from SkRefCnt. Typica
hal.canary
2013/10/23 16:11:52
I'll make that change, unless there is any reason
| |
75 } | |
76 | |
67 private: | 77 private: |
68 bool fErrorInDecoding; | 78 bool fErrorInDecoding; |
69 SkData* fData; | 79 SkData* fData; |
70 SkBitmapFactory::DecodeProc fDecodeProc; | 80 SkBitmapFactory::DecodeProc fDecodeProc; |
71 SkImageCache* fImageCache; | 81 SkImageCache* fImageCache; |
82 // fCacheId is a (SkScaledImageCache::ID*) or a (SkImageCache::ID). | |
72 intptr_t fCacheId; | 83 intptr_t fCacheId; |
73 size_t fRowBytes; | 84 size_t fRowBytes; |
74 SkImage::Info fLazilyCachedInfo; | 85 SkImage::Info fLazilyCachedInfo; |
86 SkBitmap::Allocator* fAllocator; | |
75 | 87 |
76 #if LAZY_CACHE_STATS | 88 #if LAZY_CACHE_STATS |
77 static int32_t gCacheHits; | 89 static int32_t gCacheHits; |
78 static int32_t gCacheMisses; | 90 static int32_t gCacheMisses; |
79 #endif | 91 #endif |
80 | 92 |
81 // lazily initialized our cached info. Returns NULL on failure. | 93 // lazily initialized our cached info. Returns NULL on failure. |
82 const SkImage::Info* getCachedInfo(); | 94 const SkImage::Info* getCachedInfo(); |
83 | 95 |
84 typedef SkPixelRef INHERITED; | 96 typedef SkPixelRef INHERITED; |
85 }; | 97 }; |
86 | 98 |
87 #endif // SkLazyPixelRef_DEFINED | 99 #endif // SkLazyPixelRef_DEFINED |
OLD | NEW |