Home | History | Annotate | Download | only in core
      1 /*
      2  * Copyright 2012 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 SkDeviceProfile_DEFINED
      9 #define SkDeviceProfile_DEFINED
     10 
     11 #include "SkRefCnt.h"
     12 
     13 class SkDeviceProfile : public SkRefCnt {
     14 public:
     15 
     16 
     17     enum LCDConfig {
     18         kNone_LCDConfig,   // disables LCD text rendering, uses A8 instead
     19         kRGB_Horizontal_LCDConfig,
     20         kBGR_Horizontal_LCDConfig,
     21         kRGB_Vertical_LCDConfig,
     22         kBGR_Vertical_LCDConfig
     23     };
     24 
     25     enum FontHintLevel {
     26         kNone_FontHintLevel,
     27         kSlight_FontHintLevel,
     28         kNormal_FontHintLevel,
     29         kFull_FontHintLevel,
     30         kAuto_FontHintLevel
     31     };
     32 
     33     /**
     34      *  gammaExp is typically between 1.0 and 2.2. For no gamma adjustment,
     35      *  specify 1.0
     36      *
     37      *  contrastScale will be pinned between 0.0 and 1.0. For no contrast
     38      *  adjustment, specify 0.0
     39      *
     40      *  @param config   Describes the LCD layout for this device. If this is set
     41      *                  to kNone, then all requests for LCD text will be
     42      *                  devolved to A8 antialiasing.
     43      *
     44      *  @param level    The hinting level to be used, IF the paint specifies
     45      *                  "default". Otherwise the paint's hinting level will be
     46      *                  respected.
     47      */
     48     static SkDeviceProfile* Create(float gammaExp,
     49                                    float contrastScale,
     50                                    LCDConfig,
     51                                    FontHintLevel);
     52 
     53     /**
     54      *  Returns the global default profile, that is used if no global profile is
     55      *  specified with SetGlobal(), or if nullptr is specified to SetGlobal().
     56      *  The references count is *not* incremented, and the caller should not
     57      *  call unref().
     58      */
     59     static SkDeviceProfile* GetDefault();
     60 
     61     /**
     62      *  Return the current global profile (or the default if no global had yet
     63      *  been set) and increment its reference count. The call *must* call unref()
     64      *  when it is done using it.
     65      */
     66     static SkDeviceProfile* RefGlobal();
     67 
     68     /**
     69      *  Make the specified profile be the global value for all subsequently
     70      *  instantiated devices. Does not affect any existing devices.
     71      *  Increments the reference count on the profile.
     72      *  Specify nullptr for the "identity" profile (where there is no gamma or
     73      *  contrast correction).
     74      */
     75     static void SetGlobal(SkDeviceProfile*);
     76 
     77     float getFontGammaExponent() const { return fGammaExponent; }
     78     float getFontContrastScale() const { return fContrastScale; }
     79 
     80     /**
     81      *  Given a luminance byte (0 for black, 0xFF for white), generate a table
     82      *  that applies the gamma/contrast settings to linear coverage values.
     83      */
     84     void generateTableForLuminanceByte(U8CPU lumByte, uint8_t table[256]) const;
     85 
     86 private:
     87     SkDeviceProfile(float gammaExp, float contrastScale, LCDConfig,
     88                     FontHintLevel);
     89 
     90     float           fGammaExponent;
     91     float           fContrastScale;
     92     LCDConfig       fLCDConfig;
     93     FontHintLevel   fFontHintLevel;
     94 
     95     typedef SkRefCnt INHERITED;
     96 };
     97 
     98 #endif
     99