xref: /aosp_15_r20/external/skia/include/core/SkSurfaceProps.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2014 Google Inc.
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 SkSurfaceProps_DEFINED
9 #define SkSurfaceProps_DEFINED
10 
11 #include "include/core/SkScalar.h"
12 #include "include/core/SkTypes.h"
13 #include "include/private/base/SkTo.h"
14 
15 /**
16  *  Description of how the LCD strips are arranged for each pixel. If this is unknown, or the
17  *  pixels are meant to be "portable" and/or transformed before showing (e.g. rotated, scaled)
18  *  then use kUnknown_SkPixelGeometry.
19  */
20 enum SkPixelGeometry {
21     kUnknown_SkPixelGeometry,
22     kRGB_H_SkPixelGeometry,
23     kBGR_H_SkPixelGeometry,
24     kRGB_V_SkPixelGeometry,
25     kBGR_V_SkPixelGeometry,
26 };
27 
28 // Returns true iff geo is a known geometry and is RGB.
SkPixelGeometryIsRGB(SkPixelGeometry geo)29 static inline bool SkPixelGeometryIsRGB(SkPixelGeometry geo) {
30     return kRGB_H_SkPixelGeometry == geo || kRGB_V_SkPixelGeometry == geo;
31 }
32 
33 // Returns true iff geo is a known geometry and is BGR.
SkPixelGeometryIsBGR(SkPixelGeometry geo)34 static inline bool SkPixelGeometryIsBGR(SkPixelGeometry geo) {
35     return kBGR_H_SkPixelGeometry == geo || kBGR_V_SkPixelGeometry == geo;
36 }
37 
38 // Returns true iff geo is a known geometry and is horizontal.
SkPixelGeometryIsH(SkPixelGeometry geo)39 static inline bool SkPixelGeometryIsH(SkPixelGeometry geo) {
40     return kRGB_H_SkPixelGeometry == geo || kBGR_H_SkPixelGeometry == geo;
41 }
42 
43 // Returns true iff geo is a known geometry and is vertical.
SkPixelGeometryIsV(SkPixelGeometry geo)44 static inline bool SkPixelGeometryIsV(SkPixelGeometry geo) {
45     return kRGB_V_SkPixelGeometry == geo || kBGR_V_SkPixelGeometry == geo;
46 }
47 
48 /**
49  *  Describes properties and constraints of a given SkSurface. The rendering engine can parse these
50  *  during drawing, and can sometimes optimize its performance (e.g. disabling an expensive
51  *  feature).
52  */
53 class SK_API SkSurfaceProps {
54 public:
55     enum Flags {
56         kDefault_Flag = 0,
57         kUseDeviceIndependentFonts_Flag = 1 << 0,
58         // Use internal MSAA to render to non-MSAA GPU surfaces.
59         kDynamicMSAA_Flag = 1 << 1,
60         // If set, all rendering will have dithering enabled
61         // Currently this only impacts GPU backends
62         kAlwaysDither_Flag = 1 << 2,
63     };
64 
65     /** No flags, unknown pixel geometry, platform-default contrast/gamma. */
66     SkSurfaceProps();
67     /** TODO(kschmi): Remove this constructor and replace with the one below. **/
68     SkSurfaceProps(uint32_t flags, SkPixelGeometry);
69     /** Specified pixel geometry, text contrast, and gamma **/
70     SkSurfaceProps(uint32_t flags, SkPixelGeometry, SkScalar textContrast, SkScalar textGamma);
71 
72     SkSurfaceProps(const SkSurfaceProps&) = default;
73     SkSurfaceProps& operator=(const SkSurfaceProps&) = default;
74 
cloneWithPixelGeometry(SkPixelGeometry newPixelGeometry)75     SkSurfaceProps cloneWithPixelGeometry(SkPixelGeometry newPixelGeometry) const {
76         return SkSurfaceProps(fFlags, newPixelGeometry, fTextContrast, fTextGamma);
77     }
78 
79     static constexpr SkScalar kMaxContrastInclusive = 1;
80     static constexpr SkScalar kMinContrastInclusive = 0;
81     static constexpr SkScalar kMaxGammaExclusive = 4;
82     static constexpr SkScalar kMinGammaInclusive = 0;
83 
flags()84     uint32_t flags() const { return fFlags; }
pixelGeometry()85     SkPixelGeometry pixelGeometry() const { return fPixelGeometry; }
textContrast()86     SkScalar textContrast() const { return fTextContrast; }
textGamma()87     SkScalar textGamma() const { return fTextGamma; }
88 
isUseDeviceIndependentFonts()89     bool isUseDeviceIndependentFonts() const {
90         return SkToBool(fFlags & kUseDeviceIndependentFonts_Flag);
91     }
92 
isAlwaysDither()93     bool isAlwaysDither() const {
94         return SkToBool(fFlags & kAlwaysDither_Flag);
95     }
96 
97     bool operator==(const SkSurfaceProps& that) const {
98         return fFlags == that.fFlags && fPixelGeometry == that.fPixelGeometry &&
99         fTextContrast == that.fTextContrast && fTextGamma == that.fTextGamma;
100     }
101 
102     bool operator!=(const SkSurfaceProps& that) const {
103         return !(*this == that);
104     }
105 
106 private:
107     uint32_t        fFlags;
108     SkPixelGeometry fPixelGeometry;
109 
110     // This gamma value is specifically about blending of mask coverage.
111     // The surface also has a color space, but that applies to the colors.
112     SkScalar fTextContrast;
113     SkScalar fTextGamma;
114 };
115 
116 #endif
117