• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 Google LLC
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 skgpu_graphite_GraphiteResourceKey_DEFINED
9 #define skgpu_graphite_GraphiteResourceKey_DEFINED
10 
11 #include "src/gpu/ResourceKey.h"
12 #include "src/gpu/graphite/ResourceTypes.h"
13 
14 namespace skgpu::graphite {
15 
16 class GraphiteResourceKey : public skgpu::ResourceKey {
17 public:
18     /** Generate a unique ResourceType. */
19     static ResourceType GenerateResourceType();
20 
21     /** Creates an invalid key. It must be initialized using a Builder object before use. */
GraphiteResourceKey()22     GraphiteResourceKey() : fShareable(Shareable::kNo) {}
23 
GraphiteResourceKey(const GraphiteResourceKey & that)24     GraphiteResourceKey(const GraphiteResourceKey& that) { *this = that; }
25 
26     /** reset() returns the key to the invalid state. */
27     using ResourceKey::reset;
28 
29     using ResourceKey::isValid;
30 
resourceType()31     ResourceType resourceType() const { return this->domain(); }
32 
shareable()33     Shareable shareable() const { return fShareable; }
34 
35     GraphiteResourceKey& operator=(const GraphiteResourceKey& that) {
36         this->ResourceKey::operator=(that);
37         fShareable = that.fShareable;
38         return *this;
39     }
40 
41     bool operator==(const GraphiteResourceKey& that) const {
42         bool result = this->ResourceKey::operator==(that);
43         SkASSERT(result == (fShareable == that.fShareable));
44         return result;
45     }
46     bool operator!=(const GraphiteResourceKey& that) const {
47         return !(*this == that);
48     }
49 
50     class Builder : public ResourceKey::Builder {
51     public:
Builder(GraphiteResourceKey * key,ResourceType type,int data32Count,Shareable shareable)52         Builder(GraphiteResourceKey* key, ResourceType type, int data32Count, Shareable shareable)
53                 : ResourceKey::Builder(key, type, data32Count) {
54             key->fShareable = shareable;
55         }
56     };
57 
58 private:
59     Shareable fShareable;
60 };
61 
62 } // namespace skgpu::graphite
63 
64 #endif // skgpu_graphite_GraphiteResourceKey_DEFINED
65