1cb93a386Sopenharmony_ci/*
2cb93a386Sopenharmony_ci * Copyright 2020 Google Inc.
3cb93a386Sopenharmony_ci *
4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be
5cb93a386Sopenharmony_ci * found in the LICENSE file.
6cb93a386Sopenharmony_ci */
7cb93a386Sopenharmony_ci
8cb93a386Sopenharmony_ci#ifndef SmallPathShapeData_DEFINED
9cb93a386Sopenharmony_ci#define SmallPathShapeData_DEFINED
10cb93a386Sopenharmony_ci
11cb93a386Sopenharmony_ci#include "src/core/SkOpts.h"
12cb93a386Sopenharmony_ci#include "src/gpu/GrDrawOpAtlas.h"
13cb93a386Sopenharmony_ci
14cb93a386Sopenharmony_ciclass GrStyledShape;
15cb93a386Sopenharmony_ci
16cb93a386Sopenharmony_cinamespace skgpu::v1 {
17cb93a386Sopenharmony_ci
18cb93a386Sopenharmony_ciclass SmallPathShapeDataKey {
19cb93a386Sopenharmony_cipublic:
20cb93a386Sopenharmony_ci    // TODO: add a move variant
21cb93a386Sopenharmony_ci    SmallPathShapeDataKey(const SmallPathShapeDataKey& that) {
22cb93a386Sopenharmony_ci        fKey.reset(that.fKey.count());
23cb93a386Sopenharmony_ci        memcpy(fKey.get(), that.fKey.get(), fKey.count() * sizeof(uint32_t));
24cb93a386Sopenharmony_ci    }
25cb93a386Sopenharmony_ci
26cb93a386Sopenharmony_ci    SmallPathShapeDataKey& operator=(const SmallPathShapeDataKey&) = delete;
27cb93a386Sopenharmony_ci
28cb93a386Sopenharmony_ci    // for SDF paths
29cb93a386Sopenharmony_ci    SmallPathShapeDataKey(const GrStyledShape&, uint32_t dim);
30cb93a386Sopenharmony_ci
31cb93a386Sopenharmony_ci    // for bitmap paths
32cb93a386Sopenharmony_ci    SmallPathShapeDataKey(const GrStyledShape&, const SkMatrix& ctm);
33cb93a386Sopenharmony_ci
34cb93a386Sopenharmony_ci    bool operator==(const SmallPathShapeDataKey & that) const {
35cb93a386Sopenharmony_ci        return fKey.count() == that.fKey.count() &&
36cb93a386Sopenharmony_ci                0 == memcmp(fKey.get(), that.fKey.get(), sizeof(uint32_t) * fKey.count());
37cb93a386Sopenharmony_ci    }
38cb93a386Sopenharmony_ci
39cb93a386Sopenharmony_ci    int count32() const { return fKey.count(); }
40cb93a386Sopenharmony_ci    const uint32_t* data() const { return fKey.get(); }
41cb93a386Sopenharmony_ci
42cb93a386Sopenharmony_ciprivate:
43cb93a386Sopenharmony_ci    // The key is composed of the GrStyledShape's key, and either the dimensions of the DF
44cb93a386Sopenharmony_ci    // generated for the path (32x32 max, 64x64 max, 128x128 max) if an SDF image or
45cb93a386Sopenharmony_ci    // the matrix for the path with only fractional translation.
46cb93a386Sopenharmony_ci    SkAutoSTArray<24, uint32_t> fKey;
47cb93a386Sopenharmony_ci};
48cb93a386Sopenharmony_ci
49cb93a386Sopenharmony_ciclass SmallPathShapeData {
50cb93a386Sopenharmony_cipublic:
51cb93a386Sopenharmony_ci    SmallPathShapeData(const SmallPathShapeDataKey& key) : fKey(key) {}
52cb93a386Sopenharmony_ci
53cb93a386Sopenharmony_ci    const SmallPathShapeDataKey fKey;
54cb93a386Sopenharmony_ci    SkRect                      fBounds;
55cb93a386Sopenharmony_ci    GrDrawOpAtlas::AtlasLocator fAtlasLocator;
56cb93a386Sopenharmony_ci
57cb93a386Sopenharmony_ci    SK_DECLARE_INTERNAL_LLIST_INTERFACE(SmallPathShapeData);
58cb93a386Sopenharmony_ci
59cb93a386Sopenharmony_ci    static inline const SmallPathShapeDataKey& GetKey(const SmallPathShapeData& data) {
60cb93a386Sopenharmony_ci        return data.fKey;
61cb93a386Sopenharmony_ci    }
62cb93a386Sopenharmony_ci
63cb93a386Sopenharmony_ci    static inline uint32_t Hash(const SmallPathShapeDataKey& key) {
64cb93a386Sopenharmony_ci        return SkOpts::hash(key.data(), sizeof(uint32_t) * key.count32());
65cb93a386Sopenharmony_ci    }
66cb93a386Sopenharmony_ci};
67cb93a386Sopenharmony_ci
68cb93a386Sopenharmony_ci} // namespace skgpu::v1
69cb93a386Sopenharmony_ci
70cb93a386Sopenharmony_ci#endif // SmallPathShapeData_DEFINED
71