• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2024 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_geom_NonMSAAClip_DEFINED
9 #define skgpu_graphite_geom_NonMSAAClip_DEFINED
10 
11 #include "src/gpu/graphite/geom/Rect.h"
12 
13 namespace skgpu::graphite {
14 
15 /**
16  * Represents a rect or rrect clip with any non-rect corners having the same circular radii.
17  */
18 struct AnalyticClip {
19     // Indicate which edges are adjacent to circular corners.
20     enum EdgeFlags {
21         kLeft_EdgeFlag   = 0b0001,
22         kTop_EdgeFlag    = 0b0010,
23         kRight_EdgeFlag  = 0b0100,
24         kBottom_EdgeFlag = 0b1000,
25 
26         kNone_EdgeFlag   = 0b0000,
27         kAll_EdgeFlag    = 0b1111,
28     };
29     // These defaults will produce no clip
30     Rect     fBounds = { 0, 0, 0, 0 }; // Bounds of clip
31     float    fRadius = 0;              // Circular radius, if any
32     uint32_t fEdgeFlags = kNone_EdgeFlag;
33     bool     fInverted = true;
34 
isEmptyAnalyticClip35     bool isEmpty() const { return fBounds.isEmptyNegativeOrNaN(); }
edgeSelectRectAnalyticClip36     SkRect edgeSelectRect() const {
37         return { fEdgeFlags & kLeft_EdgeFlag   ? 1.f : 0.f,
38                  fEdgeFlags & kTop_EdgeFlag    ? 1.f : 0.f,
39                  fEdgeFlags & kRight_EdgeFlag  ? 1.f : 0.f,
40                  fEdgeFlags & kBottom_EdgeFlag ? 1.f : 0.f };
41     }
42 };
43 
44 /**
45  * Represents a clip that uses a mask in an atlas
46  */
47 struct AtlasClip {
48     SkIRect             fMaskBounds;
49     SkIPoint            fOutPos;
50     sk_sp<TextureProxy> fAtlasTexture;
51 
isEmptyAtlasClip52     bool isEmpty() const { return !SkToBool(fAtlasTexture.get()); }
53 };
54 
55 /**
56  * Combined non-MSAA clip structure
57  */
58 struct NonMSAAClip {
59     AnalyticClip fAnalyticClip;
60     AtlasClip    fAtlasClip;
61 
isEmptyNonMSAAClip62     bool isEmpty() const { return fAnalyticClip.isEmpty() && fAtlasClip.isEmpty(); }
63 };
64 
65 } // namespace skgpu::graphite
66 
67 #endif // skgpu_graphite_geom_NonMSAAClip_DEFINED
68