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

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

Issue 37343002: Allow SkLazyPixelRef to use SkScaledImageCache (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: again Created 7 years, 2 months 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" 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
48 static int32_t GetCacheHits() { return gCacheHits; } 51 static int32_t GetCacheHits() { return gCacheHits; }
49 static int32_t GetCacheMisses() { return gCacheMisses; } 52 static int32_t GetCacheMisses() { return gCacheMisses; }
50 static void ResetCacheStats() { gCacheHits = gCacheMisses = 0; } 53 static void ResetCacheStats() { gCacheHits = gCacheMisses = 0; }
51 #endif 54 #endif
52 55
56 /**
57 * The allocator is used when (fImageCache==NULL) to allocate
58 * concrete PixelRefs as needed. If NULL, use the default allocator.
59 * This is passed directly into SkBitmap::allocPixels().
60 */
61 virtual void setAllocator(SkBitmap::Allocator * allocator = NULL);
reed1 2013/10/24 21:07:04 Why is this API introduced at this time?
hal.canary 2013/10/25 16:37:10 It needs to be done, since "Make current image cac
62
53 // No need to flatten this object. When flattening an SkBitmap, SkOrderedWri teBuffer will check 63 // No need to flatten this object. When flattening an SkBitmap, SkOrderedWri teBuffer will check
54 // the encoded data and write that instead. 64 // the encoded data and write that instead.
55 // Future implementations of SkFlattenableWriteBuffer will need to special c ase for 65 // Future implementations of SkFlattenableWriteBuffer will need to special c ase for
56 // onRefEncodedData as well. 66 // onRefEncodedData as well.
57 SK_DECLARE_UNFLATTENABLE_OBJECT() 67 SK_DECLARE_UNFLATTENABLE_OBJECT()
58 68
59 protected: 69 protected:
60 virtual void* onLockPixels(SkColorTable**) SK_OVERRIDE; 70 virtual void* onLockPixels(SkColorTable**) SK_OVERRIDE;
61 virtual void onUnlockPixels() SK_OVERRIDE; 71 virtual void onUnlockPixels() SK_OVERRIDE;
62 virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; } 72 virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; }
63 virtual SkData* onRefEncodedData() SK_OVERRIDE; 73 virtual SkData* onRefEncodedData() SK_OVERRIDE;
64 virtual bool onImplementsDecodeInto() SK_OVERRIDE; 74 virtual bool onImplementsDecodeInto() SK_OVERRIDE;
65 virtual bool onDecodeInto(int pow2, SkBitmap*) SK_OVERRIDE; 75 virtual bool onDecodeInto(int pow2, SkBitmap*) SK_OVERRIDE;
66 76
67 private: 77 private:
68 bool fErrorInDecoding; 78 bool fErrorInDecoding;
69 SkData* fData; 79 SkData* fData;
70 SkBitmapFactory::DecodeProc fDecodeProc; 80 SkBitmapFactory::DecodeProc fDecodeProc;
71 SkImageCache* fImageCache; 81 SkImageCache* fImageCache;
72 intptr_t fCacheId; 82 union {
83 SkImageCache::ID fCacheId;
84 SkScaledImageCache::ID* fScaledCacheId;
scroggo 2013/10/24 20:41:39 I thought you were going to change the declaration
hal.canary 2013/10/25 16:37:10 I would have, but this way allows me to skip a doz
85 };
73 size_t fRowBytes; 86 size_t fRowBytes;
74 SkImage::Info fLazilyCachedInfo; 87 SkImage::Info fLazilyCachedInfo;
88 SkBitmap::Allocator* fAllocator;
75 89
76 #if LAZY_CACHE_STATS 90 #if LAZY_CACHE_STATS
77 static int32_t gCacheHits; 91 static int32_t gCacheHits;
78 static int32_t gCacheMisses; 92 static int32_t gCacheMisses;
79 #endif 93 #endif
80 94
81 // lazily initialized our cached info. Returns NULL on failure. 95 // lazily initialized our cached info. Returns NULL on failure.
82 const SkImage::Info* getCachedInfo(); 96 const SkImage::Info* getCachedInfo();
97 void* lockScaledImageCachePixels();
98 void* lockImageCachePixels();
99
83 100
84 typedef SkPixelRef INHERITED; 101 typedef SkPixelRef INHERITED;
85 }; 102 };
86 103
87 #endif // SkLazyPixelRef_DEFINED 104 #endif // SkLazyPixelRef_DEFINED
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698