Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: src/lazy/SkLazyPixelRef.h

Issue 83663006: Modify SkLazyPixelRef to use SkImageGenerator. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: reupload Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
12 #include "SkImage.h"
13 #include "SkImageCache.h" 11 #include "SkImageCache.h"
12 #include "SkImageGenerator.h"
13 #include "SkImageInfo.h"
14 #include "SkPixelRef.h" 14 #include "SkPixelRef.h"
15 #include "SkFlattenable.h"
16 #include "SkScaledImageCache.h"
17 15
18 class SkColorTable; 16 class SkColorTable;
19 class SkData;
20 class SkImageCache;
21 17
22 #ifdef SK_DEBUG 18 #ifdef SK_DEBUG
23 #define LAZY_CACHE_STATS 1 19 #define LAZY_CACHE_STATS 1
24 #elif !defined(LAZY_CACHE_STATS) 20 #elif !defined(LAZY_CACHE_STATS)
25 #define LAZY_CACHE_STATS 0 21 #define LAZY_CACHE_STATS 0
26 #endif 22 #endif
27 23
28 /** 24 /**
29 * PixelRef which defers decoding until SkBitmap::lockPixels() is called. 25 * PixelRef which defers decoding until SkBitmap::lockPixels() is called.
30 */ 26 */
31 class SkLazyPixelRef : public SkPixelRef { 27 class SkLazyPixelRef : public SkPixelRef {
32
33 public: 28 public:
34 /** 29 /**
35 * Create a new SkLazyPixelRef. 30 * Given a SkImageGenerator object, creates a new SkLazyPixelRef
36 * @param SkData Encoded data representing the pixels. 31 * and installs it into destination SkBitmap.
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 */ 32 */
42 SkLazyPixelRef(SkData*, SkBitmapFactory::DecodeProc, SkImageCache*); 33 static bool Install(SkImageGenerator*, SkImageCache*, SkBitmap* dst);
reed1 2013/11/25 18:06:56 Do we still support SkImageCache?
43
44 virtual ~SkLazyPixelRef();
45 34
46 #ifdef SK_DEBUG 35 #ifdef SK_DEBUG
47 intptr_t getCacheId() const { return fCacheId; } 36 intptr_t getCacheId() const { return fCacheId; }
48 #endif 37 #endif
49 38
50 #if LAZY_CACHE_STATS 39 #if LAZY_CACHE_STATS
51 static int32_t GetCacheHits() { return gCacheHits; } 40 static int32_t GetCacheHits() { return gCacheHits; }
52 static int32_t GetCacheMisses() { return gCacheMisses; } 41 static int32_t GetCacheMisses() { return gCacheMisses; }
53 static void ResetCacheStats() { gCacheHits = gCacheMisses = 0; } 42 static void ResetCacheStats() { gCacheHits = gCacheMisses = 0; }
54 #endif 43 #endif
55 44
56 // No need to flatten this object. When flattening an SkBitmap, SkOrderedWri teBuffer will check 45 // No need to flatten this object. When flattening an SkBitmap,
57 // the encoded data and write that instead. 46 // SkOrderedWriteBuffer will check the encoded data and write that
58 // Future implementations of SkFlattenableWriteBuffer will need to special c ase for 47 // instead.
59 // onRefEncodedData as well. 48 // Future implementations of SkFlattenableWriteBuffer will need to
49 // special case for onRefEncodedData as well.
60 SK_DECLARE_UNFLATTENABLE_OBJECT() 50 SK_DECLARE_UNFLATTENABLE_OBJECT()
61 51
62 protected: 52 protected:
63 virtual void* onLockPixels(SkColorTable**) SK_OVERRIDE; 53 virtual ~SkLazyPixelRef();
54 virtual void* onLockPixels(SkColorTable** colorTable) SK_OVERRIDE;
64 virtual void onUnlockPixels() SK_OVERRIDE; 55 virtual void onUnlockPixels() SK_OVERRIDE;
65 virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; } 56 virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; }
66 virtual SkData* onRefEncodedData() SK_OVERRIDE; 57 virtual SkData* onRefEncodedData() SK_OVERRIDE;
67 virtual bool onImplementsDecodeInto() SK_OVERRIDE; 58 virtual bool onImplementsDecodeInto() SK_OVERRIDE { return true; }
68 virtual bool onDecodeInto(int pow2, SkBitmap*) SK_OVERRIDE; 59 virtual bool onDecodeInto(int pow2, SkBitmap*) SK_OVERRIDE;
69 60
70 private: 61 private:
71 bool fErrorInDecoding; 62 bool fErrorInDecoding;
72 SkData* fData; 63 SkImageGenerator* fImageGenerator;
73 SkBitmapFactory::DecodeProc fDecodeProc; 64 SkImageCache::ID fCacheId;
74 SkImageCache* fImageCache; 65 SkImageInfo fInfo;
75 union { 66 size_t fSize;
76 SkImageCache::ID fCacheId; 67 size_t fRowBytes;
77 SkScaledImageCache::ID* fScaledCacheId; 68 SkImageCache* fImageCache;
78 };
79 size_t fRowBytes;
80 SkImageInfo fLazilyCachedInfo;
81 69
82 #if LAZY_CACHE_STATS 70 #if LAZY_CACHE_STATS
83 static int32_t gCacheHits; 71 static int32_t gCacheHits;
84 static int32_t gCacheMisses; 72 static int32_t gCacheMisses;
85 #endif 73 #endif
86 74
87 // lazily initialized our cached info. Returns NULL on failure. 75 /**
88 const SkImage::Info* getCachedInfo(); 76 * @param SkImageCache Object that handles allocating and freeing
89 void* lockScaledImageCachePixels(); 77 * the pixel memory, as needed.
90 void* lockImageCachePixels(); 78 */
91 79 SkLazyPixelRef(SkImageGenerator*,
80 const SkImageInfo&,
81 size_t size,
82 size_t rowBytes,
83 SkImageCache*);
92 84
93 typedef SkPixelRef INHERITED; 85 typedef SkPixelRef INHERITED;
94 }; 86 };
95 87
96 #endif // SkLazyPixelRef_DEFINED 88 #endif // SkLazyPixelRef_DEFINED
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698