xref: /aosp_15_r20/external/skia/src/gpu/graphite/geom/AnalyticClip.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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_AnalyticClip_DEFINED
9 #define skgpu_graphite_geom_AnalyticClip_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 CircularRRectClip {
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     Rect     fBounds;           // Bounds of clip
30     float    fRadius = 0;       // Circular radius, if any
31     uint32_t fEdgeFlags = kNone_EdgeFlag;
32     bool     fInverted = false;
33 
isEmptyCircularRRectClip34     bool isEmpty() const { return fBounds.isEmptyNegativeOrNaN(); }
edgeSelectRectCircularRRectClip35     SkRect edgeSelectRect() const {
36         return { fEdgeFlags & kLeft_EdgeFlag   ? 1.f : 0.f,
37                  fEdgeFlags & kTop_EdgeFlag    ? 1.f : 0.f,
38                  fEdgeFlags & kRight_EdgeFlag  ? 1.f : 0.f,
39                  fEdgeFlags & kBottom_EdgeFlag ? 1.f : 0.f };
40     }
41 };
42 
43 } // namespace skgpu::graphite
44 
45 #endif // skgpu_graphite_geom_AnalyticClip_DEFINED
46