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/SkTypes.h"
12 #include "include/private/base/SkTo.h"
13
14 /**
15 * Description of how the LCD strips are arranged for each pixel. If this is unknown, or the
16 * pixels are meant to be "portable" and/or transformed before showing (e.g. rotated, scaled)
17 * then use kUnknown_SkPixelGeometry.
18 */
19 enum SkPixelGeometry {
20 kUnknown_SkPixelGeometry,
21 kRGB_H_SkPixelGeometry,
22 kBGR_H_SkPixelGeometry,
23 kRGB_V_SkPixelGeometry,
24 kBGR_V_SkPixelGeometry,
25 };
26
27 // Returns true iff geo is a known geometry and is RGB.
SkPixelGeometryIsRGB(SkPixelGeometry geo)28 static inline bool SkPixelGeometryIsRGB(SkPixelGeometry geo) {
29 return kRGB_H_SkPixelGeometry == geo || kRGB_V_SkPixelGeometry == geo;
30 }
31
32 // Returns true iff geo is a known geometry and is BGR.
SkPixelGeometryIsBGR(SkPixelGeometry geo)33 static inline bool SkPixelGeometryIsBGR(SkPixelGeometry geo) {
34 return kBGR_H_SkPixelGeometry == geo || kBGR_V_SkPixelGeometry == geo;
35 }
36
37 // Returns true iff geo is a known geometry and is horizontal.
SkPixelGeometryIsH(SkPixelGeometry geo)38 static inline bool SkPixelGeometryIsH(SkPixelGeometry geo) {
39 return kRGB_H_SkPixelGeometry == geo || kBGR_H_SkPixelGeometry == geo;
40 }
41
42 // Returns true iff geo is a known geometry and is vertical.
SkPixelGeometryIsV(SkPixelGeometry geo)43 static inline bool SkPixelGeometryIsV(SkPixelGeometry geo) {
44 return kRGB_V_SkPixelGeometry == geo || kBGR_V_SkPixelGeometry == geo;
45 }
46
47 /**
48 * Describes properties and constraints of a given SkSurface. The rendering engine can parse these
49 * during drawing, and can sometimes optimize its performance (e.g. disabling an expensive
50 * feature).
51 */
52 class SK_API SkSurfaceProps {
53 public:
54 enum Flags {
55 kUseDeviceIndependentFonts_Flag = 1 << 0,
56 // Use internal MSAA to render to non-MSAA GPU surfaces.
57 kDynamicMSAA_Flag = 1 << 1,
58 // If set, all rendering will have dithering enabled
59 // Currently this only impacts GPU backends
60 kAlwaysDither_Flag = 1 << 2,
61 };
62 /** Deprecated alias used by Chromium. Will be removed. */
63 static const Flags kUseDistanceFieldFonts_Flag = kUseDeviceIndependentFonts_Flag;
64
65 /** No flags, unknown pixel geometry. */
66 SkSurfaceProps();
67 SkSurfaceProps(uint32_t flags, SkPixelGeometry);
68
69 SkSurfaceProps(const SkSurfaceProps&);
70 SkSurfaceProps& operator=(const SkSurfaceProps&);
71
cloneWithPixelGeometry(SkPixelGeometry newPixelGeometry)72 SkSurfaceProps cloneWithPixelGeometry(SkPixelGeometry newPixelGeometry) const {
73 return SkSurfaceProps(fFlags, newPixelGeometry);
74 }
75
flags()76 uint32_t flags() const { return fFlags; }
pixelGeometry()77 SkPixelGeometry pixelGeometry() const { return fPixelGeometry; }
78
isUseDeviceIndependentFonts()79 bool isUseDeviceIndependentFonts() const {
80 return SkToBool(fFlags & kUseDeviceIndependentFonts_Flag);
81 }
82
isAlwaysDither()83 bool isAlwaysDither() const {
84 return SkToBool(fFlags & kAlwaysDither_Flag);
85 }
86
87 bool operator==(const SkSurfaceProps& that) const {
88 return fFlags == that.fFlags && fPixelGeometry == that.fPixelGeometry;
89 }
90
91 bool operator!=(const SkSurfaceProps& that) const {
92 return !(*this == that);
93 }
94
95 private:
96 uint32_t fFlags;
97 SkPixelGeometry fPixelGeometry;
98 };
99
100 #endif
101