xref: /aosp_15_r20/external/skia/src/gpu/graphite/UniquePaintParamsID.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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_UniquePaintParamsID_DEFINED
9 #define skgpu_graphite_UniquePaintParamsID_DEFINED
10 
11 #include "include/core/SkTypes.h"
12 
13 namespace skgpu::graphite {
14 
15 // This class boils down to a unique uint that can be used instead of a variable length
16 // key derived from a PaintParams.
17 class UniquePaintParamsID {
18 public:
UniquePaintParamsID(uint32_t id)19     explicit UniquePaintParamsID(uint32_t id) : fID(id) {}
20 
InvalidID()21     static UniquePaintParamsID InvalidID() { return UniquePaintParamsID(); }
22 
UniquePaintParamsID()23     UniquePaintParamsID() : fID(SK_InvalidUniqueID) {}
24 
25     bool operator==(const UniquePaintParamsID &that) const { return fID == that.fID; }
26     bool operator!=(const UniquePaintParamsID &that) const { return !(*this == that); }
27 
isValid()28     bool isValid() const { return fID != SK_InvalidUniqueID; }
asUInt()29     uint32_t asUInt() const { return fID; }
30 
31 private:
32     uint32_t fID;
33 };
34 
35 } // skgpu::graphite
36 
37 #endif // skgpu_graphite_UniquePaintParamsID_DEFINED
38