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