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 |
11 #include "SkBitmapFactory.h" | 11 #include "SkBitmapFactory.h" |
12 #include "SkImage.h" | 12 #include "SkImage.h" |
| 13 #include "SkImageCache.h" |
13 #include "SkPixelRef.h" | 14 #include "SkPixelRef.h" |
14 #include "SkFlattenable.h" | 15 #include "SkFlattenable.h" |
| 16 #include "SkScaledImageCache.h" |
15 | 17 |
16 class SkColorTable; | 18 class SkColorTable; |
17 class SkData; | 19 class SkData; |
18 class SkImageCache; | 20 class SkImageCache; |
19 | 21 |
20 #ifdef SK_DEBUG | 22 #ifdef SK_DEBUG |
21 #define LAZY_CACHE_STATS 1 | 23 #define LAZY_CACHE_STATS 1 |
22 #elif !defined(LAZY_CACHE_STATS) | 24 #elif !defined(LAZY_CACHE_STATS) |
23 #define LAZY_CACHE_STATS 0 | 25 #define LAZY_CACHE_STATS 0 |
24 #endif | 26 #endif |
25 | 27 |
26 /** | 28 /** |
27 * PixelRef which defers decoding until SkBitmap::lockPixels() is called. | 29 * PixelRef which defers decoding until SkBitmap::lockPixels() is called. |
28 */ | 30 */ |
29 class SkLazyPixelRef : public SkPixelRef { | 31 class SkLazyPixelRef : public SkPixelRef { |
30 | 32 |
31 public: | 33 public: |
32 /** | 34 /** |
33 * Create a new SkLazyPixelRef. | 35 * Create a new SkLazyPixelRef. |
34 * @param SkData Encoded data representing the pixels. | 36 * @param SkData Encoded data representing the pixels. |
35 * @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. |
36 * @param SkImageCache Object that handles allocating and freeing the pixel
memory, as needed. | 38 * @param SkImageCache Object that handles allocating and freeing |
37 * Must not be NULL. | 39 * the pixel memory, as needed. If NULL, use the global |
| 40 * SkScaledImageCache. |
38 */ | 41 */ |
39 SkLazyPixelRef(SkData*, SkBitmapFactory::DecodeProc, SkImageCache*); | 42 SkLazyPixelRef(SkData*, SkBitmapFactory::DecodeProc, SkImageCache*); |
40 | 43 |
41 virtual ~SkLazyPixelRef(); | 44 virtual ~SkLazyPixelRef(); |
42 | 45 |
43 #ifdef SK_DEBUG | 46 #ifdef SK_DEBUG |
44 intptr_t getCacheId() const { return fCacheId; } | 47 intptr_t getCacheId() const { return fCacheId; } |
45 #endif | 48 #endif |
46 | 49 |
47 #if LAZY_CACHE_STATS | 50 #if LAZY_CACHE_STATS |
(...skipping 14 matching lines...) Expand all Loading... |
62 virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; } | 65 virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; } |
63 virtual SkData* onRefEncodedData() SK_OVERRIDE; | 66 virtual SkData* onRefEncodedData() SK_OVERRIDE; |
64 virtual bool onImplementsDecodeInto() SK_OVERRIDE; | 67 virtual bool onImplementsDecodeInto() SK_OVERRIDE; |
65 virtual bool onDecodeInto(int pow2, SkBitmap*) SK_OVERRIDE; | 68 virtual bool onDecodeInto(int pow2, SkBitmap*) SK_OVERRIDE; |
66 | 69 |
67 private: | 70 private: |
68 bool fErrorInDecoding; | 71 bool fErrorInDecoding; |
69 SkData* fData; | 72 SkData* fData; |
70 SkBitmapFactory::DecodeProc fDecodeProc; | 73 SkBitmapFactory::DecodeProc fDecodeProc; |
71 SkImageCache* fImageCache; | 74 SkImageCache* fImageCache; |
72 intptr_t fCacheId; | 75 union { |
| 76 SkImageCache::ID fCacheId; |
| 77 SkScaledImageCache::ID* fScaledCacheId; |
| 78 }; |
73 size_t fRowBytes; | 79 size_t fRowBytes; |
74 SkImage::Info fLazilyCachedInfo; | 80 SkImage::Info fLazilyCachedInfo; |
75 | 81 |
76 #if LAZY_CACHE_STATS | 82 #if LAZY_CACHE_STATS |
77 static int32_t gCacheHits; | 83 static int32_t gCacheHits; |
78 static int32_t gCacheMisses; | 84 static int32_t gCacheMisses; |
79 #endif | 85 #endif |
80 | 86 |
81 // lazily initialized our cached info. Returns NULL on failure. | 87 // lazily initialized our cached info. Returns NULL on failure. |
82 const SkImage::Info* getCachedInfo(); | 88 const SkImage::Info* getCachedInfo(); |
| 89 void* lockScaledImageCachePixels(); |
| 90 void* lockImageCachePixels(); |
| 91 |
83 | 92 |
84 typedef SkPixelRef INHERITED; | 93 typedef SkPixelRef INHERITED; |
85 }; | 94 }; |
86 | 95 |
87 #endif // SkLazyPixelRef_DEFINED | 96 #endif // SkLazyPixelRef_DEFINED |
OLD | NEW |