aboutsummaryrefslogtreecommitdiff
path: root/src/deps/skia/include/private/SkUniquePaintParamsID.h
blob: 2cd89fd2f4df5c5bb3d97c639d1dbd6fdac97ed9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
 * Copyright 2022 Google LLC
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef SkUniquePaintParamsID_DEFINED
#define SkUniquePaintParamsID_DEFINED

#include "include/core/SkTypes.h"

// This class boils down to a unique uint that can be used instead of a variable length
// key derived from a PaintParams.
class SkUniquePaintParamsID {
public:
    explicit SkUniquePaintParamsID(uint32_t id) : fID(id) {
        SkASSERT(id != SK_InvalidUniqueID);
    }

    static SkUniquePaintParamsID InvalidID() { return SkUniquePaintParamsID(); }

    SkUniquePaintParamsID() : fID(SK_InvalidUniqueID) {}

    bool operator==(const SkUniquePaintParamsID &that) const { return fID == that.fID; }
    bool operator!=(const SkUniquePaintParamsID &that) const { return !(*this == that); }

    bool isValid() const { return fID != SK_InvalidUniqueID; }
    uint32_t asUInt() const { return fID; }

private:
    uint32_t fID;
};

#endif // SkUniquePaintParamsID_DEFINED