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

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

Issue 510053003: Make textures register with GrResourceCache2 as scratch. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add new h file to git repo Created 6 years, 3 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/gpu/GrBinHashKey.h ('k') | include/gpu/GrResourceKey.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 GrGpuResource_DEFINED 8 #ifndef GrGpuResource_DEFINED
9 #define GrGpuResource_DEFINED 9 #define GrGpuResource_DEFINED
10 10
11 #include "SkInstCnt.h" 11 #include "SkInstCnt.h"
12 #include "SkTInternalLList.h" 12 #include "SkTInternalLList.h"
13 #include "GrResourceKey.h"
13 14
14 class GrResourceCacheEntry; 15 class GrResourceCacheEntry;
15 class GrResourceCache2; 16 class GrResourceCache2;
16 class GrGpu; 17 class GrGpu;
17 class GrContext; 18 class GrContext;
18 19
19 /** 20 /**
20 * Base class for objects that can be kept in the GrResourceCache. 21 * Base class for objects that can be kept in the GrResourceCache.
21 */ 22 */
22 class GrGpuResource : public SkNoncopyable { 23 class GrGpuResource : public SkNoncopyable {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 * approximate since we aren't aware of additional padding or copies made 76 * approximate since we aren't aware of additional padding or copies made
76 * by the driver. 77 * by the driver.
77 * 78 *
78 * @return the amount of GPU memory used in bytes 79 * @return the amount of GPU memory used in bytes
79 */ 80 */
80 virtual size_t gpuMemorySize() const = 0; 81 virtual size_t gpuMemorySize() const = 0;
81 82
82 void setCacheEntry(GrResourceCacheEntry* cacheEntry) { fCacheEntry = cacheEn try; } 83 void setCacheEntry(GrResourceCacheEntry* cacheEntry) { fCacheEntry = cacheEn try; }
83 GrResourceCacheEntry* getCacheEntry() { return fCacheEntry; } 84 GrResourceCacheEntry* getCacheEntry() { return fCacheEntry; }
84 85
86 /**
87 * If this resource can be used as a scratch resource this returns a valid
88 * scratch key. Otherwise it returns a key for which isNullScratch is true.
89 */
90 const GrResourceKey& getScratchKey() const { return fScratchKey; }
91
85 /** 92 /**
86 * Gets an id that is unique for this GrCacheable object. It is static in th at it does 93 * Gets an id that is unique for this GrCacheable object. It is static in th at it does
87 * not change when the content of the GrCacheable object changes. This will never return 94 * not change when the content of the GrCacheable object changes. This will never return
88 * 0. 95 * 0.
89 */ 96 */
90 uint32_t getUniqueID() const { return fUniqueID; } 97 uint32_t getUniqueID() const { return fUniqueID; }
91 98
92 protected: 99 protected:
93
94 // This must be called by every GrGpuObject. It should be called once the ob ject is fully 100 // This must be called by every GrGpuObject. It should be called once the ob ject is fully
95 // initialized (i.e. not in a base class constructor). 101 // initialized (i.e. not in a base class constructor).
96 void registerWithCache(); 102 void registerWithCache();
97 103
98 GrGpuResource(GrGpu*, bool isWrapped); 104 GrGpuResource(GrGpu*, bool isWrapped);
99 virtual ~GrGpuResource(); 105 virtual ~GrGpuResource();
100 106
101 bool isInCache() const { return NULL != fCacheEntry; } 107 bool isInCache() const { return NULL != fCacheEntry; }
102 108
103 GrGpu* getGpu() const { return fGpu; } 109 GrGpu* getGpu() const { return fGpu; }
104 110
105 // Derived classes should always call their parent class' onRelease 111 // Derived classes should always call their parent class' onRelease
106 // and onAbandon methods in their overrides. 112 // and onAbandon methods in their overrides.
107 virtual void onRelease() {}; 113 virtual void onRelease() {};
108 virtual void onAbandon() {}; 114 virtual void onAbandon() {};
109 115
110 bool isWrapped() const { return kWrapped_FlagBit & fFlags; } 116 bool isWrapped() const { return kWrapped_FlagBit & fFlags; }
111 117
112 /** 118 /**
113 * This entry point should be called whenever gpuMemorySize() begins 119 * This entry point should be called whenever gpuMemorySize() begins
114 * reporting a different size. If the object is in the cache, it will call 120 * reporting a different size. If the object is in the cache, it will call
115 * gpuMemorySize() immediately and pass the new size on to the resource 121 * gpuMemorySize() immediately and pass the new size on to the resource
116 * cache. 122 * cache.
117 */ 123 */
118 void didChangeGpuMemorySize() const; 124 void didChangeGpuMemorySize() const;
119 125
126 /**
127 * Optionally called by the GrGpuResource subclass if the resource can be us ed as scratch.
128 * By default resources are not usable as scratch. This should only be calle d once.
129 **/
130 void setScratchKey(const GrResourceKey& scratchKey);
131
120 private: 132 private:
121 #ifdef SK_DEBUG 133 #ifdef SK_DEBUG
122 friend class GrGpu; // for assert in GrGpu to access getGpu 134 friend class GrGpu; // for assert in GrGpu to access getGpu
123 #endif 135 #endif
124 136
125 static uint32_t CreateUniqueID(); 137 static uint32_t CreateUniqueID();
126 138
127 // We're in an internal doubly linked list owned by GrResourceCache2 139 // We're in an internal doubly linked list owned by GrResourceCache2
128 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrGpuResource); 140 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrGpuResource);
129 141
130 // This is not ref'ed but abandon() or release() will be called before the G rGpu object 142 // This is not ref'ed but abandon() or release() will be called before the G rGpu object
131 // is destroyed. Those calls set will this to NULL. 143 // is destroyed. Those calls set will this to NULL.
132 GrGpu* fGpu; 144 GrGpu* fGpu;
133 145
134 enum Flags { 146 enum Flags {
135 /** 147 /**
136 * This object wraps a GPU object given to us by the user. 148 * This object wraps a GPU object given to us by the user.
137 * Lifetime management is left up to the user (i.e., we will not 149 * Lifetime management is left up to the user (i.e., we will not
138 * free it). 150 * free it).
139 */ 151 */
140 kWrapped_FlagBit = 0x1, 152 kWrapped_FlagBit = 0x1,
141 }; 153 };
142 154
143 uint32_t fFlags; 155 uint32_t fFlags;
144 156
145 mutable int32_t fRefCnt; 157 mutable int32_t fRefCnt;
146 GrResourceCacheEntry* fCacheEntry; // NULL if not in cache 158 GrResourceCacheEntry* fCacheEntry; // NULL if not in cache
147 const uint32_t fUniqueID; 159 const uint32_t fUniqueID;
148 160
161 GrResourceKey fScratchKey;
162
149 typedef SkNoncopyable INHERITED; 163 typedef SkNoncopyable INHERITED;
150 }; 164 };
151 165
152 #endif 166 #endif
OLDNEW
« no previous file with comments | « include/gpu/GrBinHashKey.h ('k') | include/gpu/GrResourceKey.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698