| 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 |
|
| 8 |
#ifndef GrGpuResourcePriv_DEFINED |
| 9 |
#define GrGpuResourcePriv_DEFINED |
| 10 |
|
| 11 |
#include "include/private/base/SkAssert.h" |
| 12 |
#include "include/private/gpu/ganesh/GrTypesPriv.h" |
| 13 |
#include "src/gpu/ResourceKey.h" |
| 14 |
#include "src/gpu/ganesh/GrGpuResource.h" |
| 15 |
|
| 16 |
/** |
| 17 |
* This class allows code internal to Skia privileged access to manage the cache keys and budget |
| 18 |
* status of a GrGpuResource object. |
| 19 |
*/ |
| 20 |
class GrGpuResource::ResourcePriv { |
| 21 |
public: |
| 22 |
/** |
| 23 |
* Sets a unique key for the resource. If the resource was previously cached as scratch it will |
| 24 |
* be converted to a uniquely-keyed resource. If the key is invalid then this is equivalent to |
| 25 |
* removeUniqueKey(). If another resource is using the key then its unique key is removed and |
| 26 |
* this resource takes over the key. |
| 27 |
*/ |
| 28 |
void setUniqueKey(const skgpu::UniqueKey& key) { fResource->setUniqueKey(key); } |
| 29 |
|
| 30 |
/** Removes the unique key from a resource. If the resource has a scratch key, it may be |
| 31 |
preserved for recycling as scratch. */ |
| 32 |
void removeUniqueKey() { fResource->removeUniqueKey(); } |
| 33 |
|
| 34 |
/** |
| 35 |
* If the resource is uncached make it cached. Has no effect on resources that are wrapped or |
| 36 |
* already cached. |
| 37 |
*/ |
| 38 |
void makeBudgeted() { fResource->makeBudgeted(); } |
| 39 |
|
| 40 |
/** |
| 41 |
* If the resource is cached make it uncached. Has no effect on resources that are wrapped or |
| 42 |
* already uncached. Furthermore, resources with unique keys cannot be made unbudgeted. |
| 43 |
*/ |
| 44 |
void makeUnbudgeted() { fResource->makeUnbudgeted(); } |
| 45 |
|
| 46 |
/** |
| 47 |
* Get the resource's budgeted-type which indicates whether it counts against the resource cache |
| 48 |
* budget and if not whether it is allowed to be cached. |
| 49 |
*/ |
| 50 |
GrBudgetedType budgetedType() const { |
| 51 |
SkASSERT(GrBudgetedType::kBudgeted == fResource->fBudgetedType || |
| 52 |
!fResource->getUniqueKey().isValid() || fResource->fRefsWrappedObjects); |
| 53 |
return fResource->fBudgetedType; |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Is the resource object wrapping an externally allocated GPU resource? |
| 58 |
*/ |
| 59 |
bool refsWrappedObjects() const { return fResource->fRefsWrappedObjects; } |
| 60 |
|
| 61 |
/** |
| 62 |
* If this resource can be used as a scratch resource this returns a valid scratch key. |
| 63 |
* Otherwise it returns a key for which isNullScratch is true. The resource may currently be |
| 64 |
* used as a uniquely keyed resource rather than scratch. Check isScratch(). |
| 65 |
*/ |
| 66 |
const skgpu::ScratchKey& getScratchKey() const { return fResource->fScratchKey; } |
| 67 |
|
| 68 |
/** |
| 69 |
* If the resource has a scratch key, the key will be removed. Since scratch keys are installed |
| 70 |
* at resource creation time, this means the resource will never again be used as scratch. |
| 71 |
*/ |
| 72 |
void removeScratchKey() const { fResource->removeScratchKey(); } |
| 73 |
|
| 74 |
bool isPurgeable() const { return fResource->isPurgeable(); } |
| 75 |
|
| 76 |
bool hasRefOrCommandBufferUsage() const { |
| 77 |
return fResource->hasRef() || !fResource->hasNoCommandBufferUsages(); |
| 78 |
} |
| 79 |
|
| 80 |
protected: |
| 81 |
ResourcePriv(GrGpuResource* resource) : fResource(resource) { } |
| 82 |
ResourcePriv(const ResourcePriv& that) : fResource(that.fResource) {} |
| 83 |
ResourcePriv& operator=(const CacheAccess&) = delete; |
| 84 |
|
| 85 |
// No taking addresses of this type. |
| 86 |
const ResourcePriv* operator&() const; |
| 87 |
ResourcePriv* operator&(); |
| 88 |
|
| 89 |
GrGpuResource* fResource; |
| 90 |
|
| 91 |
friend class GrGpuResource; // to construct/copy this type. |
| 92 |
}; |
| 93 |
|
| 94 |
inline GrGpuResource::ResourcePriv GrGpuResource::resourcePriv() { return ResourcePriv(this); } |
| 95 |
|
| 96 |
inline const GrGpuResource::ResourcePriv GrGpuResource::resourcePriv() const { // NOLINT(readability-const-return-type) |
| 97 |
return ResourcePriv(const_cast<GrGpuResource*>(this)); |
| 98 |
} |
| 99 |
|
| 100 |
#endif |