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