| 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 memory usage information for this GrGpuResource to traceMemoryDump. |
| 258 * Typically, subclasses should not need to override this, and should only |
| 259 * need to override setMemoryBacking. |
| 260 **/ |
| 261 virtual void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const; |
| 262 |
| 255 protected: | 263 protected: |
| 256 // This must be called by every GrGpuObject. It should be called once the ob
ject is fully | 264 // 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). | 265 // initialized (i.e. not in a base class constructor). |
| 258 void registerWithCache(); | 266 void registerWithCache(); |
| 259 | 267 |
| 260 GrGpuResource(GrGpu*, LifeCycle); | 268 GrGpuResource(GrGpu*, LifeCycle); |
| 261 virtual ~GrGpuResource(); | 269 virtual ~GrGpuResource(); |
| 262 | 270 |
| 263 GrGpu* getGpu() const { return fGpu; } | 271 GrGpu* getGpu() const { return fGpu; } |
| 264 | 272 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 281 * The cache will call gpuMemorySize() to update the current size of the res
ource. | 289 * The cache will call gpuMemorySize() to update the current size of the res
ource. |
| 282 */ | 290 */ |
| 283 void didChangeGpuMemorySize() const; | 291 void didChangeGpuMemorySize() const; |
| 284 | 292 |
| 285 /** | 293 /** |
| 286 * Optionally called by the GrGpuResource subclass if the resource can be us
ed as scratch. | 294 * 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. | 295 * By default resources are not usable as scratch. This should only be calle
d once. |
| 288 **/ | 296 **/ |
| 289 void setScratchKey(const GrScratchKey& scratchKey); | 297 void setScratchKey(const GrScratchKey& scratchKey); |
| 290 | 298 |
| 299 /** |
| 300 * Allows subclasses to add additional backing information to the SkTraceMem
oryDump. Called by |
| 301 * onMemoryDump. The default implementation adds no backing information. |
| 302 **/ |
| 303 virtual void setMemoryBacking(SkTraceMemoryDump*, const SkString&) const {} |
| 304 |
| 291 private: | 305 private: |
| 292 /** | 306 /** |
| 293 * Frees the object in the underlying 3D API. Called by CacheAccess. | 307 * Frees the object in the underlying 3D API. Called by CacheAccess. |
| 294 */ | 308 */ |
| 295 void release(); | 309 void release(); |
| 296 | 310 |
| 297 virtual size_t onGpuMemorySize() const = 0; | 311 virtual size_t onGpuMemorySize() const = 0; |
| 298 | 312 |
| 299 // See comments in CacheAccess and ResourcePriv. | 313 // See comments in CacheAccess and ResourcePriv. |
| 300 void setUniqueKey(const GrUniqueKey&); | 314 void setUniqueKey(const GrUniqueKey&); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 330 LifeCycle fLifeCycle; | 344 LifeCycle fLifeCycle; |
| 331 const uint32_t fUniqueID; | 345 const uint32_t fUniqueID; |
| 332 | 346 |
| 333 SkAutoTUnref<const SkData> fData; | 347 SkAutoTUnref<const SkData> fData; |
| 334 | 348 |
| 335 typedef GrIORef<GrGpuResource> INHERITED; | 349 typedef GrIORef<GrGpuResource> INHERITED; |
| 336 friend class GrIORef<GrGpuResource>; // to access notifyAllCntsAreZero and n
otifyRefCntIsZero. | 350 friend class GrIORef<GrGpuResource>; // to access notifyAllCntsAreZero and n
otifyRefCntIsZero. |
| 337 }; | 351 }; |
| 338 | 352 |
| 339 #endif | 353 #endif |
| OLD | NEW |