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

Side by Side Diff: include/gpu/GrCacheable.h

Issue 392333008: Make GrCacheable implement its own ref counting. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: remove extra blank line Created 6 years, 5 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
« no previous file with comments | « include/core/SkRefCnt.h ('k') | include/gpu/GrContext.h » ('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 2014 Google Inc. 2 * Copyright 2014 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 GrCacheable_DEFINED 8 #ifndef GrCacheable_DEFINED
9 #define GrCacheable_DEFINED 9 #define GrCacheable_DEFINED
10 10
11 #include "SkRefCnt.h" 11 #include "SkRefCnt.h"
12 12
13 class GrResourceCacheEntry; 13 class GrResourceCacheEntry;
14 14
15 /** 15 /**
16 * Base class for objects that can be kept in the GrResourceCache. 16 * Base class for objects that can be kept in the GrResourceCache.
17 */ 17 */
18 class GrCacheable : public SkRefCnt { 18 class GrCacheable : public SkNoncopyable {
19 public: 19 public:
20 SK_DECLARE_INST_COUNT(GrCacheable) 20 SK_DECLARE_INST_COUNT_ROOT(GrCacheable)
21
22 // These method signatures are written to mirror SkRefCnt. However, we don't require
23 // thread safety as GrCacheable objects are not intended to cross thread bou ndaries.
24 // internal_dispose() exists because of GrTexture's reliance on it. It will be removed
25 // soon.
26 void ref() const { ++fRefCnt; }
27 void unref() const { --fRefCnt; if (0 == fRefCnt) { this->internal_dispose() ; } }
28 virtual void internal_dispose() const { SkDELETE(this); }
29 bool unique() const { return 1 == fRefCnt; }
30 #ifdef SK_DEBUG
31 void validate() const {
32 SkASSERT(fRefCnt > 0);
33 }
34 #endif
35
36 virtual ~GrCacheable() { SkASSERT(0 == fRefCnt); }
21 37
22 /** 38 /**
23 * Retrieves the amount of GPU memory used by this resource in bytes. It is 39 * Retrieves the amount of GPU memory used by this resource in bytes. It is
24 * approximate since we aren't aware of additional padding or copies made 40 * approximate since we aren't aware of additional padding or copies made
25 * by the driver. 41 * by the driver.
26 * 42 *
27 * @return the amount of GPU memory used in bytes 43 * @return the amount of GPU memory used in bytes
28 */ 44 */
29 virtual size_t gpuMemorySize() const = 0; 45 virtual size_t gpuMemorySize() const = 0;
30 46
(...skipping 12 matching lines...) Expand all
43 59
44 /** 60 /**
45 * Gets an id that is unique for this GrCacheable object. It is static in th at it does 61 * Gets an id that is unique for this GrCacheable object. It is static in th at it does
46 * not change when the content of the GrCacheable object changes. This will never return 62 * not change when the content of the GrCacheable object changes. This will never return
47 * 0. 63 * 0.
48 */ 64 */
49 uint32_t getGenerationID() const; 65 uint32_t getGenerationID() const;
50 66
51 protected: 67 protected:
52 GrCacheable() 68 GrCacheable()
53 : fCacheEntry(NULL) 69 : fRefCnt(1)
70 , fCacheEntry(NULL)
54 , fGenID(0) {} 71 , fGenID(0) {}
55 72
56 bool isInCache() const { return NULL != fCacheEntry; } 73 bool isInCache() const { return NULL != fCacheEntry; }
57 74
58 /** 75 /**
59 * This entry point should be called whenever gpuMemorySize() begins 76 * This entry point should be called whenever gpuMemorySize() begins
60 * reporting a different size. If the object is in the cache, it will call 77 * reporting a different size. If the object is in the cache, it will call
61 * gpuMemorySize() immediately and pass the new size on to the resource 78 * gpuMemorySize() immediately and pass the new size on to the resource
62 * cache. 79 * cache.
63 */ 80 */
64 void didChangeGpuMemorySize() const; 81 void didChangeGpuMemorySize() const;
65 82
66 private: 83 private:
84 mutable int32_t fRefCnt;
67 GrResourceCacheEntry* fCacheEntry; // NULL if not in cache 85 GrResourceCacheEntry* fCacheEntry; // NULL if not in cache
68 mutable uint32_t fGenID; 86 mutable uint32_t fGenID;
69 87
70 typedef SkRefCnt INHERITED; 88 typedef SkNoncopyable INHERITED;
71 }; 89 };
72 90
73 #endif 91 #endif
OLDNEW
« no previous file with comments | « include/core/SkRefCnt.h ('k') | include/gpu/GrContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698