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