reed@google.com | 48a4cbc | 2012-03-01 19:21:11 +0000 | [diff] [blame^] | 1 | |
| 2 | |
| 3 | #include "SkDeviceProfile.h" |
| 4 | |
| 5 | #define DEFAULT_GAMMAEXP 2.2 |
| 6 | #define DEFAULT_CONTRASTSCALE 0.5 |
| 7 | #define DEFAULT_LCDCONFIG SkDeviceProfile::kNone_LCDConfig |
| 8 | #define DEFAULT_FONTHINTLEVEL SkDeviceProfile::kSlight_FontHintLevel |
| 9 | |
| 10 | static float pin(float value, float min, float max) { |
| 11 | if (value < min) { |
| 12 | value = min; |
| 13 | } else if (value > max) { |
| 14 | value = max; |
| 15 | } |
| 16 | return value; |
| 17 | } |
| 18 | |
| 19 | SkDeviceProfile::SkDeviceProfile(float gammaExp, float contrast, |
| 20 | LCDConfig config, FontHintLevel level) { |
| 21 | fGammaExponent = pin(gammaExp, 0, 10); |
| 22 | fContrastScale = pin(contrast, 0, 1); |
| 23 | fLCDConfig = config; |
| 24 | fFontHintLevel = level; |
| 25 | } |
| 26 | |
| 27 | void SkDeviceProfile::generateTableForLuminanceByte(U8CPU lumByte, |
| 28 | uint8_t table[256]) const { |
| 29 | } |
| 30 | |
| 31 | /////////////////////////////////////////////////////////////////////////////// |
| 32 | |
| 33 | SkDeviceProfile* SkDeviceProfile::Create(float gammaExp, |
| 34 | float contrast, |
| 35 | LCDConfig config, |
| 36 | FontHintLevel level) { |
| 37 | return SkNEW_ARGS(SkDeviceProfile, (gammaExp, contrast, config, level)); |
| 38 | } |
| 39 | |
| 40 | static SkMutex gMutex; |
| 41 | static SkDeviceProfile* gDefaultProfile; |
| 42 | static SkDeviceProfile* gGlobalProfile; |
| 43 | |
| 44 | SkDeviceProfile* SkDeviceProfile::GetDefault() { |
| 45 | SkAutoMutexAcquire amc(gMutex); |
| 46 | |
| 47 | if (NULL == gDefaultProfile) { |
| 48 | gDefaultProfile = SkDeviceProfile::Create(DEFAULT_GAMMAEXP, |
| 49 | DEFAULT_CONTRASTSCALE, |
| 50 | DEFAULT_LCDCONFIG, |
| 51 | DEFAULT_FONTHINTLEVEL); |
| 52 | } |
| 53 | return gDefaultProfile; |
| 54 | } |
| 55 | |
| 56 | SkDeviceProfile* SkDeviceProfile::RefGlobal() { |
| 57 | SkAutoMutexAcquire amc(gMutex); |
| 58 | |
| 59 | if (NULL == gGlobalProfile) { |
| 60 | gGlobalProfile = SkDeviceProfile::GetDefault(); |
| 61 | } |
| 62 | gGlobalProfile->ref(); |
| 63 | return gGlobalProfile; |
| 64 | } |
| 65 | |
| 66 | void SkDeviceProfile::SetGlobal(SkDeviceProfile* profile) { |
| 67 | SkAutoMutexAcquire amc(gMutex); |
| 68 | |
| 69 | SkRefCnt_SafeAssign(gGlobalProfile, profile); |
| 70 | } |
| 71 | |
| 72 | |