Debian Codegraph @

include/core/SkSurfaceProps.h

raw
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.
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.
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.
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.
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 // The surface will preserve transparent draws (instead of skipping them).
64 kPreservesTransparentDraws_Flag = 1 << 3,
65 };
66
67 /** No flags, unknown pixel geometry, platform-default contrast/gamma. */
68 SkSurfaceProps();
69 /** TODO(kschmi): Remove this constructor and replace with the one below. **/
70 SkSurfaceProps(uint32_t flags, SkPixelGeometry);
71 /** Specified pixel geometry, text contrast, and gamma **/
72 SkSurfaceProps(uint32_t flags, SkPixelGeometry, SkScalar textContrast, SkScalar textGamma);
73
74 SkSurfaceProps(const SkSurfaceProps&) = default;
75 SkSurfaceProps& operator=(const SkSurfaceProps&) = default;
76
77 SkSurfaceProps cloneWithPixelGeometry(SkPixelGeometry newPixelGeometry) const {
78 return SkSurfaceProps(fFlags, newPixelGeometry, fTextContrast, fTextGamma);
79 }
80
81 static constexpr SkScalar kMaxContrastInclusive = 1;
82 static constexpr SkScalar kMinContrastInclusive = 0;
83 static constexpr SkScalar kMaxGammaExclusive = 4;
84 static constexpr SkScalar kMinGammaInclusive = 0;
85
86 uint32_t flags() const { return fFlags; }
87 SkPixelGeometry pixelGeometry() const { return fPixelGeometry; }
88 SkScalar textContrast() const { return fTextContrast; }
89 SkScalar textGamma() const { return fTextGamma; }
90
91 bool isUseDeviceIndependentFonts() const {
92 return SkToBool(fFlags & kUseDeviceIndependentFonts_Flag);
93 }
94
95 bool isAlwaysDither() const {
96 return SkToBool(fFlags & kAlwaysDither_Flag);
97 }
98
99 bool preservesTransparentDraws() const {
100 return SkToBool(fFlags & kPreservesTransparentDraws_Flag);
101 }
102
103 bool operator==(const SkSurfaceProps& that) const {
104 return fFlags == that.fFlags && fPixelGeometry == that.fPixelGeometry &&
105 fTextContrast == that.fTextContrast && fTextGamma == that.fTextGamma;
106 }
107
108 bool operator!=(const SkSurfaceProps& that) const {
109 return !(*this == that);
110 }
111
112 private:
113 uint32_t fFlags;
114 SkPixelGeometry fPixelGeometry;
115
116 // This gamma value is specifically about blending of mask coverage.
117 // The surface also has a color space, but that applies to the colors.
118 SkScalar fTextContrast;
119 SkScalar fTextGamma;
120 };
121
122 #endif