Upstream version 10.38.222.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / include / core / SkDeviceProperties.h
1 #ifndef SkDeviceProperties_DEFINED
2 #define SkDeviceProperties_DEFINED
3
4 //TODO: get everyone to stop using SkFontLCDConfig::SetSubpixel* and remove this import.
5 #include "SkFontLCDConfig.h"
6
7 struct SkDeviceProperties {
8     struct Geometry {
9         /** The orientation of the pixel specifies the interpretation of the
10         *  layout. If the orientation is horizontal, the layout is interpreted as
11         *  left to right. It the orientation is vertical, the layout is
12         *  interpreted top to bottom (rotated 90deg cw from horizontal).
13         */
14         enum Orientation {
15             kUnknown_Orientation      = 0x0,
16             kKnown_Orientation        = 0x2,
17
18             kHorizontal_Orientation   = 0x2,  //!< this is the default
19             kVertical_Orientation     = 0x3,
20
21             kOrientationMask          = 0x3,
22         };
23
24         /** The layout of the pixel specifies its subpixel geometry.
25         *
26         *  kUnknown_Layout means that the subpixel elements are not spatially
27         *  separated in any known or usable fashion.
28         */
29         enum Layout {
30             kUnknown_Layout   = 0x0,
31             kKnown_Layout     = 0x8,
32
33             kRGB_Layout       = 0x8,  //!< this is the default
34             kBGR_Layout       = 0xC,
35
36             kLayoutMask       = 0xC,
37         };
38
39         Orientation getOrientation() {
40             return static_cast<Orientation>(fGeometry & kOrientationMask);
41         }
42         Layout getLayout() {
43             return static_cast<Layout>(fGeometry & kLayoutMask);
44         }
45
46         bool isOrientationKnown() {
47             return SkToBool(fGeometry & kKnown_Orientation);
48         }
49         bool isLayoutKnown() {
50             return SkToBool(fGeometry & kKnown_Layout);
51         }
52
53     private:
54         //TODO: get everyone to stop using SkFontLCDConfig::SetSubpixel* and replace these calls with constants.
55         static Orientation fromOldOrientation(SkFontLCDConfig::LCDOrientation orientation) {
56             switch (orientation) {
57             case SkFontLCDConfig::kHorizontal_LCDOrientation: return kHorizontal_Orientation;
58             case SkFontLCDConfig::kVertical_LCDOrientation: return kVertical_Orientation;
59             default: return kUnknown_Orientation;
60             }
61         }
62         static Layout fromOldLayout(SkFontLCDConfig::LCDOrder order) {
63             switch (order) {
64             case SkFontLCDConfig::kRGB_LCDOrder: return kRGB_Layout;
65             case SkFontLCDConfig::kBGR_LCDOrder: return kBGR_Layout;
66             default: return kUnknown_Layout;
67             }
68         }
69     public:
70         static Geometry MakeDefault() {
71             Orientation orientation = fromOldOrientation(SkFontLCDConfig::GetSubpixelOrientation()); //kHorizontal_Orientation
72             Layout layout = fromOldLayout(SkFontLCDConfig::GetSubpixelOrder()); //kRGB_Layout
73             Geometry ret = { SkToU8(orientation | layout) };
74             return ret;
75         }
76
77         static Geometry Make(Orientation orientation, Layout layout) {
78             Geometry ret = { SkToU8(orientation | layout) };
79             return ret;
80         }
81
82         uint8_t fGeometry;
83     };
84
85     static SkDeviceProperties MakeDefault() {
86         SkDeviceProperties ret = { Geometry::MakeDefault(), SK_GAMMA_EXPONENT };
87         return ret;
88     }
89
90     static SkDeviceProperties Make(Geometry geometry, SkScalar gamma) {
91         SkDeviceProperties ret = { geometry, gamma };
92         return ret;
93     }
94
95     /** Each pixel of an image will have some number of channels.
96      *  Can the layout of those channels be exploited? */
97     Geometry fGeometry;
98
99     /** Represents the color space of the image. This is a woefully inadequate beginning. */
100     SkScalar fGamma;
101 };
102
103 #endif