| 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 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 public: | 33 public: |
| 34 /** | 34 /** |
| 35 * Create a new SkLazyPixelRef. | 35 * Create a new SkLazyPixelRef. |
| 36 * @param SkData Encoded data representing the pixels. | 36 * @param SkData Encoded data representing the pixels. |
| 37 * @param DecodeProc Called to decode the pixels when needed. Must be non-N
ULL. | 37 * @param DecodeProc Called to decode the pixels when needed. Must be non-N
ULL. |
| 38 * @param SkImageCache Object that handles allocating and freeing | 38 * @param SkImageCache Object that handles allocating and freeing |
| 39 * the pixel memory, as needed. If NULL, use the global | 39 * the pixel memory, as needed. If NULL, use the global |
| 40 * SkScaledImageCache. | 40 * SkScaledImageCache. |
| 41 */ | 41 */ |
| 42 SkLazyPixelRef(SkData*, SkBitmapFactory::DecodeProc, SkImageCache*); | 42 SkLazyPixelRef(const SkImageInfo&, SkData*, SkBitmapFactory::DecodeProc, |
| 43 SkImageCache*); |
| 43 | 44 |
| 44 virtual ~SkLazyPixelRef(); | 45 virtual ~SkLazyPixelRef(); |
| 45 | 46 |
| 46 #ifdef SK_DEBUG | 47 #ifdef SK_DEBUG |
| 47 intptr_t getCacheId() const { return fCacheId; } | 48 intptr_t getCacheId() const { return fCacheId; } |
| 48 #endif | 49 #endif |
| 49 | 50 |
| 50 #if LAZY_CACHE_STATS | 51 #if LAZY_CACHE_STATS |
| 51 static int32_t GetCacheHits() { return gCacheHits; } | 52 static int32_t GetCacheHits() { return gCacheHits; } |
| 52 static int32_t GetCacheMisses() { return gCacheMisses; } | 53 static int32_t GetCacheMisses() { return gCacheMisses; } |
| 53 static void ResetCacheStats() { gCacheHits = gCacheMisses = 0; } | 54 static void ResetCacheStats() { gCacheHits = gCacheMisses = 0; } |
| 54 #endif | 55 #endif |
| 55 | 56 |
| 56 // No need to flatten this object. When flattening an SkBitmap, SkOrderedWri
teBuffer will check | 57 // No need to flatten this object. When flattening an SkBitmap, SkOrderedWri
teBuffer will check |
| 57 // the encoded data and write that instead. | 58 // the encoded data and write that instead. |
| 58 // Future implementations of SkFlattenableWriteBuffer will need to special c
ase for | 59 // Future implementations of SkFlattenableWriteBuffer will need to special c
ase for |
| 59 // onRefEncodedData as well. | 60 // onRefEncodedData as well. |
| 60 SK_DECLARE_UNFLATTENABLE_OBJECT() | 61 SK_DECLARE_UNFLATTENABLE_OBJECT() |
| 61 | 62 |
| 62 protected: | 63 protected: |
| 63 virtual void* onLockPixels(SkColorTable**) SK_OVERRIDE; | 64 virtual bool onNewLockPixels(LockRec*) SK_OVERRIDE; |
| 64 virtual void onUnlockPixels() SK_OVERRIDE; | 65 virtual void onUnlockPixels() SK_OVERRIDE; |
| 65 virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; } | 66 virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; } |
| 66 virtual SkData* onRefEncodedData() SK_OVERRIDE; | 67 virtual SkData* onRefEncodedData() SK_OVERRIDE; |
| 67 virtual bool onImplementsDecodeInto() SK_OVERRIDE; | 68 virtual bool onImplementsDecodeInto() SK_OVERRIDE; |
| 68 virtual bool onDecodeInto(int pow2, SkBitmap*) SK_OVERRIDE; | 69 virtual bool onDecodeInto(int pow2, SkBitmap*) SK_OVERRIDE; |
| 69 | 70 |
| 70 private: | 71 private: |
| 71 bool fErrorInDecoding; | 72 bool fErrorInDecoding; |
| 72 SkData* fData; | 73 SkData* fData; |
| 73 SkBitmapFactory::DecodeProc fDecodeProc; | 74 SkBitmapFactory::DecodeProc fDecodeProc; |
| 74 SkImageCache* fImageCache; | 75 SkImageCache* fImageCache; |
| 75 union { | 76 union { |
| 76 SkImageCache::ID fCacheId; | 77 SkImageCache::ID fCacheId; |
| 77 SkScaledImageCache::ID* fScaledCacheId; | 78 SkScaledImageCache::ID* fScaledCacheId; |
| 78 }; | 79 }; |
| 79 size_t fRowBytes; | 80 size_t fRowBytes; |
| 80 SkImageInfo fLazilyCachedInfo; | 81 SkImageInfo fLazilyCachedInfo; |
| 81 | 82 |
| 82 #if LAZY_CACHE_STATS | 83 #if LAZY_CACHE_STATS |
| 83 static int32_t gCacheHits; | 84 static int32_t gCacheHits; |
| 84 static int32_t gCacheMisses; | 85 static int32_t gCacheMisses; |
| 85 #endif | 86 #endif |
| 86 | 87 |
| 87 // lazily initialized our cached info. Returns NULL on failure. | 88 // lazily initialized our cached info. Returns NULL on failure. |
| 88 const SkImage::Info* getCachedInfo(); | 89 const SkImage::Info* getCachedInfo(); |
| 89 void* lockScaledImageCachePixels(); | 90 bool lockScaledImageCachePixels(LockRec*); |
| 90 void* lockImageCachePixels(); | 91 bool lockImageCachePixels(LockRec*); |
| 91 | 92 |
| 92 | 93 |
| 93 typedef SkPixelRef INHERITED; | 94 typedef SkPixelRef INHERITED; |
| 94 }; | 95 }; |
| 95 | 96 |
| 96 #endif // SkLazyPixelRef_DEFINED | 97 #endif // SkLazyPixelRef_DEFINED |
| OLD | NEW |