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