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 { | |
scroggo
2013/12/06 14:50:33
This file was deleted by Hal.
| |
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(const SkImageInfo&, SkData*, SkBitmapFactory::DecodeProc, | |
43 SkImageCache*); | |
44 | |
45 virtual ~SkLazyPixelRef(); | |
46 | |
47 #ifdef SK_DEBUG | |
48 intptr_t getCacheId() const { return fCacheId; } | |
49 #endif | |
50 | |
51 #if LAZY_CACHE_STATS | |
52 static int32_t GetCacheHits() { return gCacheHits; } | |
53 static int32_t GetCacheMisses() { return gCacheMisses; } | |
54 static void ResetCacheStats() { gCacheHits = gCacheMisses = 0; } | |
55 #endif | |
56 | |
57 // No need to flatten this object. When flattening an SkBitmap, SkOrderedWri teBuffer will check | |
58 // the encoded data and write that instead. | |
59 // Future implementations of SkFlattenableWriteBuffer will need to special c ase for | |
60 // onRefEncodedData as well. | |
61 SK_DECLARE_UNFLATTENABLE_OBJECT() | |
62 | |
63 protected: | |
64 virtual bool onNewLockPixels(LockRec*) SK_OVERRIDE; | |
65 virtual void onUnlockPixels() SK_OVERRIDE; | |
66 virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; } | |
67 virtual SkData* onRefEncodedData() SK_OVERRIDE; | |
68 virtual bool onImplementsDecodeInto() SK_OVERRIDE; | |
69 virtual bool onDecodeInto(int pow2, SkBitmap*) SK_OVERRIDE; | |
70 | |
71 private: | |
72 bool fErrorInDecoding; | |
73 SkData* fData; | |
74 SkBitmapFactory::DecodeProc fDecodeProc; | |
75 SkImageCache* fImageCache; | |
76 union { | |
77 SkImageCache::ID fCacheId; | |
78 SkScaledImageCache::ID* fScaledCacheId; | |
79 }; | |
80 size_t fRowBytes; | |
81 SkImageInfo fLazilyCachedInfo; | |
82 | |
83 #if LAZY_CACHE_STATS | |
84 static int32_t gCacheHits; | |
85 static int32_t gCacheMisses; | |
86 #endif | |
87 | |
88 // lazily initialized our cached info. Returns NULL on failure. | |
89 const SkImage::Info* getCachedInfo(); | |
90 bool lockScaledImageCachePixels(LockRec*); | |
91 bool lockImageCachePixels(LockRec*); | |
92 | |
93 | |
94 typedef SkPixelRef INHERITED; | |
95 }; | |
96 | |
97 #endif // SkLazyPixelRef_DEFINED | |
OLD | NEW |