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