OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2012 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #ifndef SkLazyPixelRef_DEFINED | |
9 #define SkLazyPixelRef_DEFINED | |
10 | |
11 #include "SkBitmapFactory.h" | |
12 #include "SkImage.h" | |
13 #include "SkImageCache.h" | |
14 #include "SkPixelRef.h" | |
15 #include "SkFlattenable.h" | |
16 #include "SkScaledImageCache.h" | |
17 | |
18 class SkColorTable; | |
19 class SkData; | |
20 class SkImageCache; | |
21 | |
22 #ifdef SK_DEBUG | |
23 #define LAZY_CACHE_STATS 1 | |
24 #elif !defined(LAZY_CACHE_STATS) | |
25 #define LAZY_CACHE_STATS 0 | |
26 #endif | |
27 | |
28 /** | |
29 * PixelRef which defers decoding until SkBitmap::lockPixels() is called. | |
30 */ | |
31 class SkLazyPixelRef : public SkPixelRef { | |
32 | |
33 public: | |
34 /** | |
35 * Create a new SkLazyPixelRef. | |
36 * @param SkData Encoded data representing the pixels. | |
37 * @param DecodeProc Called to decode the pixels when needed. Must be non-N
ULL. | |
38 * @param SkImageCache Object that handles allocating and freeing | |
39 * the pixel memory, as needed. If NULL, use the global | |
40 * SkScaledImageCache. | |
41 */ | |
42 SkLazyPixelRef(SkData*, SkBitmapFactory::DecodeProc, SkImageCache*); | |
43 | |
44 virtual ~SkLazyPixelRef(); | |
45 | |
46 #ifdef SK_DEBUG | |
47 intptr_t getCacheId() const { return fCacheId; } | |
48 #endif | |
49 | |
50 #if LAZY_CACHE_STATS | |
51 static int32_t GetCacheHits() { return gCacheHits; } | |
52 static int32_t GetCacheMisses() { return gCacheMisses; } | |
53 static void ResetCacheStats() { gCacheHits = gCacheMisses = 0; } | |
54 #endif | |
55 | |
56 // No need to flatten this object. When flattening an SkBitmap, SkOrderedWri
teBuffer will check | |
57 // the encoded data and write that instead. | |
58 // Future implementations of SkFlattenableWriteBuffer will need to special c
ase for | |
59 // onRefEncodedData as well. | |
60 SK_DECLARE_UNFLATTENABLE_OBJECT() | |
61 | |
62 protected: | |
63 virtual void* onLockPixels(SkColorTable**) SK_OVERRIDE; | |
64 virtual void onUnlockPixels() SK_OVERRIDE; | |
65 virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; } | |
66 virtual SkData* onRefEncodedData() SK_OVERRIDE; | |
67 virtual bool onImplementsDecodeInto() SK_OVERRIDE; | |
68 virtual bool onDecodeInto(int pow2, SkBitmap*) SK_OVERRIDE; | |
69 | |
70 private: | |
71 bool fErrorInDecoding; | |
72 SkData* fData; | |
73 SkBitmapFactory::DecodeProc fDecodeProc; | |
74 SkImageCache* fImageCache; | |
75 union { | |
76 SkImageCache::ID fCacheId; | |
77 SkScaledImageCache::ID* fScaledCacheId; | |
78 }; | |
79 size_t fRowBytes; | |
80 SkImageInfo fLazilyCachedInfo; | |
81 | |
82 #if LAZY_CACHE_STATS | |
83 static int32_t gCacheHits; | |
84 static int32_t gCacheMisses; | |
85 #endif | |
86 | |
87 // lazily initialized our cached info. Returns NULL on failure. | |
88 const SkImage::Info* getCachedInfo(); | |
89 void* lockScaledImageCachePixels(); | |
90 void* lockImageCachePixels(); | |
91 | |
92 | |
93 typedef SkPixelRef INHERITED; | |
94 }; | |
95 | |
96 #endif // SkLazyPixelRef_DEFINED | |
OLD | NEW |