1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/include/core/SkDeviceProperties.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,112 @@ 1.4 +#ifndef SkDeviceProperties_DEFINED 1.5 +#define SkDeviceProperties_DEFINED 1.6 + 1.7 +#ifndef SK_GAMMA_EXPONENT 1.8 + #define SK_GAMMA_EXPONENT (2.2f) 1.9 +#endif 1.10 + 1.11 +#ifdef SK_GAMMA_SRGB 1.12 + #undef SK_GAMMA_EXPONENT 1.13 + #define SK_GAMMA_EXPONENT (0.0f) 1.14 +#endif 1.15 + 1.16 +//TODO: get everyone to stop using SkFontLCDConfig::SetSubpixel* and remove this import. 1.17 +#include "SkFontLCDConfig.h" 1.18 + 1.19 +struct SkDeviceProperties { 1.20 + struct Geometry { 1.21 + /** The orientation of the pixel specifies the interpretation of the 1.22 + * layout. If the orientation is horizontal, the layout is interpreted as 1.23 + * left to right. It the orientation is vertical, the layout is 1.24 + * interpreted top to bottom (rotated 90deg cw from horizontal). 1.25 + */ 1.26 + enum Orientation { 1.27 + kUnknown_Orientation = 0x0, 1.28 + kKnown_Orientation = 0x2, 1.29 + 1.30 + kHorizontal_Orientation = 0x2, //!< this is the default 1.31 + kVertical_Orientation = 0x3, 1.32 + 1.33 + kOrientationMask = 0x3, 1.34 + }; 1.35 + 1.36 + /** The layout of the pixel specifies its subpixel geometry. 1.37 + * 1.38 + * kUnknown_Layout means that the subpixel elements are not spatially 1.39 + * separated in any known or usable fashion. 1.40 + */ 1.41 + enum Layout { 1.42 + kUnknown_Layout = 0x0, 1.43 + kKnown_Layout = 0x8, 1.44 + 1.45 + kRGB_Layout = 0x8, //!< this is the default 1.46 + kBGR_Layout = 0xC, 1.47 + 1.48 + kLayoutMask = 0xC, 1.49 + }; 1.50 + 1.51 + Orientation getOrientation() { 1.52 + return static_cast<Orientation>(fGeometry & kOrientationMask); 1.53 + } 1.54 + Layout getLayout() { 1.55 + return static_cast<Layout>(fGeometry & kLayoutMask); 1.56 + } 1.57 + 1.58 + bool isOrientationKnown() { 1.59 + return SkToBool(fGeometry & kKnown_Orientation); 1.60 + } 1.61 + bool isLayoutKnown() { 1.62 + return SkToBool(fGeometry & kKnown_Layout); 1.63 + } 1.64 + 1.65 + private: 1.66 + //TODO: get everyone to stop using SkFontLCDConfig::SetSubpixel* and replace these calls with constants. 1.67 + static Orientation fromOldOrientation(SkFontLCDConfig::LCDOrientation orientation) { 1.68 + switch (orientation) { 1.69 + case SkFontLCDConfig::kHorizontal_LCDOrientation: return kHorizontal_Orientation; 1.70 + case SkFontLCDConfig::kVertical_LCDOrientation: return kVertical_Orientation; 1.71 + default: return kUnknown_Orientation; 1.72 + } 1.73 + } 1.74 + static Layout fromOldLayout(SkFontLCDConfig::LCDOrder order) { 1.75 + switch (order) { 1.76 + case SkFontLCDConfig::kRGB_LCDOrder: return kRGB_Layout; 1.77 + case SkFontLCDConfig::kBGR_LCDOrder: return kBGR_Layout; 1.78 + default: return kUnknown_Layout; 1.79 + } 1.80 + } 1.81 + public: 1.82 + static Geometry MakeDefault() { 1.83 + Orientation orientation = fromOldOrientation(SkFontLCDConfig::GetSubpixelOrientation()); //kHorizontal_Orientation 1.84 + Layout layout = fromOldLayout(SkFontLCDConfig::GetSubpixelOrder()); //kRGB_Layout 1.85 + Geometry ret = { SkToU8(orientation | layout) }; 1.86 + return ret; 1.87 + } 1.88 + 1.89 + static Geometry Make(Orientation orientation, Layout layout) { 1.90 + Geometry ret = { SkToU8(orientation | layout) }; 1.91 + return ret; 1.92 + } 1.93 + 1.94 + uint8_t fGeometry; 1.95 + }; 1.96 + 1.97 + static SkDeviceProperties MakeDefault() { 1.98 + SkDeviceProperties ret = { Geometry::MakeDefault(), SK_GAMMA_EXPONENT }; 1.99 + return ret; 1.100 + } 1.101 + 1.102 + static SkDeviceProperties Make(Geometry geometry, SkScalar gamma) { 1.103 + SkDeviceProperties ret = { geometry, gamma }; 1.104 + return ret; 1.105 + } 1.106 + 1.107 + /** Each pixel of an image will have some number of channels. 1.108 + * Can the layout of those channels be exploited? */ 1.109 + Geometry fGeometry; 1.110 + 1.111 + /** Represents the color space of the image. This is a woefully inadequate beginning. */ 1.112 + SkScalar fGamma; 1.113 +}; 1.114 + 1.115 +#endif