• 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_GraphiteResourceKey_DEFINED
9 #define skgpu_GraphiteResourceKey_DEFINED
10 
11 #include "experimental/graphite/src/ResourceTypes.h"
12 #include "src/gpu/ResourceKey.h"
13 
14 namespace skgpu {
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         return *this;
38     }
39 
40     bool operator==(const GraphiteResourceKey& that) const {
41         bool result = this->ResourceKey::operator==(that);
42         SkASSERT(result == (fShareable == that.fShareable));
43         return result;
44     }
45     bool operator!=(const GraphiteResourceKey& that) const {
46         return !(*this == that);
47     }
48 
49     class Builder : public ResourceKey::Builder {
50     public:
Builder(GraphiteResourceKey * key,ResourceType type,int data32Count,Shareable shareable)51         Builder(GraphiteResourceKey* key, ResourceType type, int data32Count, Shareable shareable)
52                 : ResourceKey::Builder(key, type, data32Count) {
53             key->fShareable = shareable;
54         }
55     };
56 
57 private:
58     Shareable fShareable;
59 };
60 
61 } // namespace skgpu
62 
63 #endif // skgpu_GraphiteResourceKey_DEFINED
64