OLD | NEW |
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 "GrResourceKey.h" | 11 #include "GrResourceKey.h" |
12 #include "GrTypesPriv.h" | 12 #include "GrTypesPriv.h" |
13 #include "SkData.h" | 13 #include "SkData.h" |
14 | 14 |
15 class GrContext; | 15 class GrContext; |
16 class GrGpu; | 16 class GrGpu; |
17 class GrResourceCache; | 17 class GrResourceCache; |
| 18 class SkTraceMemoryDump; |
18 | 19 |
19 /** | 20 /** |
20 * Base class for GrGpuResource. Handles the various types of refs we need. Sepa
rated out as a base | 21 * Base class for GrGpuResource. Handles the various types of refs we need. Sepa
rated out as a base |
21 * class to isolate the ref-cnting behavior and provide friendship without expos
ing all of | 22 * class to isolate the ref-cnting behavior and provide friendship without expos
ing all of |
22 * GrGpuResource. | 23 * GrGpuResource. |
23 * | 24 * |
24 * Gpu resources can have three types of refs: | 25 * Gpu resources can have three types of refs: |
25 * 1) Normal ref (+ by ref(), - by unref()): These are used by code that is is
suing draw calls | 26 * 1) Normal ref (+ by ref(), - by unref()): These are used by code that is is
suing draw calls |
26 * that read and write the resource via GrDrawTarget and by any object that
must own a | 27 * that read and write the resource via GrDrawTarget and by any object that
must own a |
27 * GrGpuResource and is itself owned (directly or indirectly) by Skia-clien
t code. | 28 * GrGpuResource and is itself owned (directly or indirectly) by Skia-clien
t code. |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 friend class GrResourceCache; // to check IO ref counts. | 132 friend class GrResourceCache; // to check IO ref counts. |
132 | 133 |
133 template <typename, GrIOType> friend class GrPendingIOResource; | 134 template <typename, GrIOType> friend class GrPendingIOResource; |
134 }; | 135 }; |
135 | 136 |
136 /** | 137 /** |
137 * Base class for objects that can be kept in the GrResourceCache. | 138 * Base class for objects that can be kept in the GrResourceCache. |
138 */ | 139 */ |
139 class SK_API GrGpuResource : public GrIORef<GrGpuResource> { | 140 class SK_API GrGpuResource : public GrIORef<GrGpuResource> { |
140 public: | 141 public: |
141 | |
142 | |
143 enum LifeCycle { | 142 enum LifeCycle { |
144 /** | 143 /** |
145 * The resource is cached and owned by Skia. Resources with this status
may be kept alive | 144 * The resource is cached and owned by Skia. Resources with this status
may be kept alive |
146 * by the cache as either scratch or unique resources even when there ar
e no refs to them. | 145 * by the cache as either scratch or unique resources even when there ar
e no refs to them. |
147 * The cache may release them whenever there are no refs. | 146 * The cache may release them whenever there are no refs. |
148 */ | 147 */ |
149 kCached_LifeCycle, | 148 kCached_LifeCycle, |
150 | 149 |
151 /** | 150 /** |
152 * The resource is uncached. As soon as there are no more refs to it, it
is released. Under | 151 * The resource is uncached. As soon as there are no more refs to it, it
is released. Under |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 /** | 244 /** |
246 * Removes references to objects in the underlying 3D API without freeing th
em. | 245 * Removes references to objects in the underlying 3D API without freeing th
em. |
247 * Called by CacheAccess. | 246 * Called by CacheAccess. |
248 * In general this method should not be called outside of skia. It was | 247 * In general this method should not be called outside of skia. It was |
249 * made by public for a special case where it needs to be called in Blink | 248 * made by public for a special case where it needs to be called in Blink |
250 * when a texture becomes unsafe to use after having been shared through | 249 * when a texture becomes unsafe to use after having been shared through |
251 * a texture mailbox. | 250 * a texture mailbox. |
252 */ | 251 */ |
253 void abandon(); | 252 void abandon(); |
254 | 253 |
| 254 /** |
| 255 * Dumps memory usage information for this GrGpuResource to traceMemoryDump. |
| 256 **/ |
| 257 void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const; |
| 258 |
255 protected: | 259 protected: |
256 // This must be called by every GrGpuObject. It should be called once the ob
ject is fully | 260 // This must be called by every GrGpuObject. It should be called once the ob
ject is fully |
257 // initialized (i.e. not in a base class constructor). | 261 // initialized (i.e. not in a base class constructor). |
258 void registerWithCache(); | 262 void registerWithCache(); |
259 | 263 |
260 GrGpuResource(GrGpu*, LifeCycle); | 264 GrGpuResource(GrGpu*, LifeCycle); |
261 virtual ~GrGpuResource(); | 265 virtual ~GrGpuResource(); |
262 | 266 |
263 GrGpu* getGpu() const { return fGpu; } | 267 GrGpu* getGpu() const { return fGpu; } |
264 | 268 |
(...skipping 16 matching lines...) Expand all Loading... |
281 * The cache will call gpuMemorySize() to update the current size of the res
ource. | 285 * The cache will call gpuMemorySize() to update the current size of the res
ource. |
282 */ | 286 */ |
283 void didChangeGpuMemorySize() const; | 287 void didChangeGpuMemorySize() const; |
284 | 288 |
285 /** | 289 /** |
286 * Optionally called by the GrGpuResource subclass if the resource can be us
ed as scratch. | 290 * Optionally called by the GrGpuResource subclass if the resource can be us
ed as scratch. |
287 * By default resources are not usable as scratch. This should only be calle
d once. | 291 * By default resources are not usable as scratch. This should only be calle
d once. |
288 **/ | 292 **/ |
289 void setScratchKey(const GrScratchKey& scratchKey); | 293 void setScratchKey(const GrScratchKey& scratchKey); |
290 | 294 |
| 295 /** |
| 296 * Allows subclasses to add additional backing information to the SkTraceMem
oryDump. Called by |
| 297 * onMemoryDump. The default implementation adds no backing information. |
| 298 **/ |
| 299 virtual void setMemoryBacking(SkTraceMemoryDump* traceMemoryDump, |
| 300 const SkString& dumpName) const {} |
| 301 |
291 private: | 302 private: |
292 /** | 303 /** |
293 * Frees the object in the underlying 3D API. Called by CacheAccess. | 304 * Frees the object in the underlying 3D API. Called by CacheAccess. |
294 */ | 305 */ |
295 void release(); | 306 void release(); |
296 | 307 |
297 virtual size_t onGpuMemorySize() const = 0; | 308 virtual size_t onGpuMemorySize() const = 0; |
298 | 309 |
299 // See comments in CacheAccess and ResourcePriv. | 310 // See comments in CacheAccess and ResourcePriv. |
300 void setUniqueKey(const GrUniqueKey&); | 311 void setUniqueKey(const GrUniqueKey&); |
(...skipping 29 matching lines...) Expand all Loading... |
330 LifeCycle fLifeCycle; | 341 LifeCycle fLifeCycle; |
331 const uint32_t fUniqueID; | 342 const uint32_t fUniqueID; |
332 | 343 |
333 SkAutoTUnref<const SkData> fData; | 344 SkAutoTUnref<const SkData> fData; |
334 | 345 |
335 typedef GrIORef<GrGpuResource> INHERITED; | 346 typedef GrIORef<GrGpuResource> INHERITED; |
336 friend class GrIORef<GrGpuResource>; // to access notifyAllCntsAreZero and n
otifyRefCntIsZero. | 347 friend class GrIORef<GrGpuResource>; // to access notifyAllCntsAreZero and n
otifyRefCntIsZero. |
337 }; | 348 }; |
338 | 349 |
339 #endif | 350 #endif |
OLD | NEW |