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 |
142 | 143 |
143 enum LifeCycle { | 144 enum LifeCycle { |
144 /** | 145 /** |
145 * The resource is cached and owned by Skia. Resources with this status
may be kept alive | 146 * 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. | 147 * 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. | 148 * The cache may release them whenever there are no refs. |
148 */ | 149 */ |
149 kCached_LifeCycle, | 150 kCached_LifeCycle, |
150 | 151 |
151 /** | 152 /** |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 /** | 246 /** |
246 * Removes references to objects in the underlying 3D API without freeing th
em. | 247 * Removes references to objects in the underlying 3D API without freeing th
em. |
247 * Called by CacheAccess. | 248 * Called by CacheAccess. |
248 * In general this method should not be called outside of skia. It was | 249 * 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 | 250 * 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 | 251 * when a texture becomes unsafe to use after having been shared through |
251 * a texture mailbox. | 252 * a texture mailbox. |
252 */ | 253 */ |
253 void abandon(); | 254 void abandon(); |
254 | 255 |
| 256 /** |
| 257 * Dumps details about this GrGpuResource to the provided traceMemoryDump. |
| 258 * May be overridden by subclasses to provide more detailed dumps. |
| 259 **/ |
| 260 virtual void onMemoryDump(SkTraceMemoryDump* traceMemoryDump) const; |
| 261 |
255 protected: | 262 protected: |
256 // This must be called by every GrGpuObject. It should be called once the ob
ject is fully | 263 // 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). | 264 // initialized (i.e. not in a base class constructor). |
258 void registerWithCache(); | 265 void registerWithCache(); |
259 | 266 |
260 GrGpuResource(GrGpu*, LifeCycle); | 267 GrGpuResource(GrGpu*, LifeCycle); |
261 virtual ~GrGpuResource(); | 268 virtual ~GrGpuResource(); |
262 | 269 |
263 GrGpu* getGpu() const { return fGpu; } | 270 GrGpu* getGpu() const { return fGpu; } |
264 | 271 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 LifeCycle fLifeCycle; | 337 LifeCycle fLifeCycle; |
331 const uint32_t fUniqueID; | 338 const uint32_t fUniqueID; |
332 | 339 |
333 SkAutoTUnref<const SkData> fData; | 340 SkAutoTUnref<const SkData> fData; |
334 | 341 |
335 typedef GrIORef<GrGpuResource> INHERITED; | 342 typedef GrIORef<GrGpuResource> INHERITED; |
336 friend class GrIORef<GrGpuResource>; // to access notifyAllCntsAreZero and n
otifyRefCntIsZero. | 343 friend class GrIORef<GrGpuResource>; // to access notifyAllCntsAreZero and n
otifyRefCntIsZero. |
337 }; | 344 }; |
338 | 345 |
339 #endif | 346 #endif |
OLD | NEW |