GrGpuResourcePriv.h 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright 2015 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #ifndef GrGpuResourcePriv_DEFINED
  8. #define GrGpuResourcePriv_DEFINED
  9. #include "include/gpu/GrGpuResource.h"
  10. /**
  11. * This class allows code internal to Skia privileged access to manage the cache keys and budget
  12. * status of a GrGpuResource object.
  13. */
  14. class GrGpuResource::ResourcePriv {
  15. public:
  16. SkDEBUGCODE(bool hasPendingIO_debugOnly() const { return fResource->internalHasPendingIO(); })
  17. /**
  18. * Sets a unique key for the resource. If the resource was previously cached as scratch it will
  19. * be converted to a uniquely-keyed resource. If the key is invalid then this is equivalent to
  20. * removeUniqueKey(). If another resource is using the key then its unique key is removed and
  21. * this resource takes over the key.
  22. */
  23. void setUniqueKey(const GrUniqueKey& key) { fResource->setUniqueKey(key); }
  24. /** Removes the unique key from a resource. If the resource has a scratch key, it may be
  25. preserved for recycling as scratch. */
  26. void removeUniqueKey() { fResource->removeUniqueKey(); }
  27. /**
  28. * If the resource is uncached make it cached. Has no effect on resources that are wrapped or
  29. * already cached.
  30. */
  31. void makeBudgeted() { fResource->makeBudgeted(); }
  32. /**
  33. * If the resource is cached make it uncached. Has no effect on resources that are wrapped or
  34. * already uncached. Furthermore, resources with unique keys cannot be made unbudgeted.
  35. */
  36. void makeUnbudgeted() { fResource->makeUnbudgeted(); }
  37. /**
  38. * Get the resource's budgeted-type which indicates whether it counts against the resource cache
  39. * budget and if not whether it is allowed to be cached.
  40. */
  41. GrBudgetedType budgetedType() const {
  42. SkASSERT(GrBudgetedType::kBudgeted == fResource->fBudgetedType ||
  43. !fResource->getUniqueKey().isValid() || fResource->fRefsWrappedObjects);
  44. return fResource->fBudgetedType;
  45. }
  46. /**
  47. * Is the resource object wrapping an externally allocated GPU resource?
  48. */
  49. bool refsWrappedObjects() const { return fResource->fRefsWrappedObjects; }
  50. /**
  51. * If this resource can be used as a scratch resource this returns a valid scratch key.
  52. * Otherwise it returns a key for which isNullScratch is true. The resource may currently be
  53. * used as a uniquely keyed resource rather than scratch. Check isScratch().
  54. */
  55. const GrScratchKey& getScratchKey() const { return fResource->fScratchKey; }
  56. /**
  57. * If the resource has a scratch key, the key will be removed. Since scratch keys are installed
  58. * at resource creation time, this means the resource will never again be used as scratch.
  59. */
  60. void removeScratchKey() const { fResource->removeScratchKey(); }
  61. bool isPurgeable() const { return fResource->isPurgeable(); }
  62. bool hasRefOrPendingIO() const { return fResource->hasRefOrPendingIO(); }
  63. protected:
  64. ResourcePriv(GrGpuResource* resource) : fResource(resource) { }
  65. ResourcePriv(const ResourcePriv& that) : fResource(that.fResource) {}
  66. ResourcePriv& operator=(const CacheAccess&); // unimpl
  67. // No taking addresses of this type.
  68. const ResourcePriv* operator&() const;
  69. ResourcePriv* operator&();
  70. GrGpuResource* fResource;
  71. friend class GrGpuResource; // to construct/copy this type.
  72. };
  73. inline GrGpuResource::ResourcePriv GrGpuResource::resourcePriv() { return ResourcePriv(this); }
  74. inline const GrGpuResource::ResourcePriv GrGpuResource::resourcePriv() const {
  75. return ResourcePriv(const_cast<GrGpuResource*>(this));
  76. }
  77. #endif