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

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

Issue 12393046: Add a way to monitor cache hits and misses for deferred decoding. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 9 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
« no previous file with comments | « gyp/tools.gyp ('k') | src/lazy/SkLazyPixelRef.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "SkPixelRef.h" 13 #include "SkPixelRef.h"
14 #include "SkFlattenable.h" 14 #include "SkFlattenable.h"
15 15
16 class SkColorTable; 16 class SkColorTable;
17 class SkData; 17 class SkData;
18 class SkImageCache; 18 class SkImageCache;
19 19
20 #ifdef SK_DEBUG
21 #define LAZY_CACHE_STATS 1
22 #elif !defined(LAZY_CACHE_STATS)
23 #define LAZY_CACHE_STATS 0
24 #endif
25
20 /** 26 /**
21 * PixelRef which defers decoding until SkBitmap::lockPixels() is called. 27 * PixelRef which defers decoding until SkBitmap::lockPixels() is called.
22 */ 28 */
23 class SkLazyPixelRef : public SkPixelRef { 29 class SkLazyPixelRef : public SkPixelRef {
24 30
25 public: 31 public:
26 /** 32 /**
27 * Create a new SkLazyPixelRef. 33 * Create a new SkLazyPixelRef.
28 * @param SkData Encoded data representing the pixels. 34 * @param SkData Encoded data representing the pixels.
29 * @param DecodeProc Called to decode the pixels when needed. Must be non-N ULL. 35 * @param DecodeProc Called to decode the pixels when needed. Must be non-N ULL.
30 * @param SkImageCache Object that handles allocating and freeing the pixel memory, as needed. 36 * @param SkImageCache Object that handles allocating and freeing the pixel memory, as needed.
31 * Must not be NULL. 37 * Must not be NULL.
32 */ 38 */
33 SkLazyPixelRef(SkData*, SkBitmapFactory::DecodeProc, SkImageCache*); 39 SkLazyPixelRef(SkData*, SkBitmapFactory::DecodeProc, SkImageCache*);
34 40
35 virtual ~SkLazyPixelRef(); 41 virtual ~SkLazyPixelRef();
36 42
37 #ifdef SK_DEBUG 43 #ifdef SK_DEBUG
38 intptr_t getCacheId() const { return fCacheId; } 44 intptr_t getCacheId() const { return fCacheId; }
39 #endif 45 #endif
40 46
47 #if LAZY_CACHE_STATS
48 static int32_t GetCacheHits() { return gCacheHits; }
49 static int32_t GetCacheMisses() { return gCacheMisses; }
50 static void ResetCacheStats() { gCacheHits = gCacheMisses = 0; }
51 #endif
52
41 // No need to flatten this object. When flattening an SkBitmap, SkOrderedWri teBuffer will check 53 // No need to flatten this object. When flattening an SkBitmap, SkOrderedWri teBuffer will check
42 // the encoded data and write that instead. 54 // the encoded data and write that instead.
43 // Future implementations of SkFlattenableWriteBuffer will need to special c ase for 55 // Future implementations of SkFlattenableWriteBuffer will need to special c ase for
44 // onRefEncodedData as well. 56 // onRefEncodedData as well.
45 SK_DECLARE_UNFLATTENABLE_OBJECT() 57 SK_DECLARE_UNFLATTENABLE_OBJECT()
46 58
47 protected: 59 protected:
48 virtual void* onLockPixels(SkColorTable**) SK_OVERRIDE; 60 virtual void* onLockPixels(SkColorTable**) SK_OVERRIDE;
49 virtual void onUnlockPixels() SK_OVERRIDE; 61 virtual void onUnlockPixels() SK_OVERRIDE;
50 virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; } 62 virtual bool onLockPixelsAreWritable() const SK_OVERRIDE { return false; }
51 virtual SkData* onRefEncodedData() SK_OVERRIDE; 63 virtual SkData* onRefEncodedData() SK_OVERRIDE;
52 64
53 private: 65 private:
54 bool fErrorInDecoding; 66 bool fErrorInDecoding;
55 SkData* fData; 67 SkData* fData;
56 SkBitmapFactory::DecodeProc fDecodeProc; 68 SkBitmapFactory::DecodeProc fDecodeProc;
57 SkImageCache* fImageCache; 69 SkImageCache* fImageCache;
58 intptr_t fCacheId; 70 intptr_t fCacheId;
59 71
72 #if LAZY_CACHE_STATS
73 static int32_t gCacheHits;
74 static int32_t gCacheMisses;
75 #endif
76
60 typedef SkPixelRef INHERITED; 77 typedef SkPixelRef INHERITED;
61 }; 78 };
62 79
63 #endif // SkLazyPixelRef_DEFINED 80 #endif // SkLazyPixelRef_DEFINED
OLDNEW
« no previous file with comments | « gyp/tools.gyp ('k') | src/lazy/SkLazyPixelRef.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698