robertphillips@google.com | 15e9d3e | 2012-06-21 20:25:03 +0000 | [diff] [blame] | 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 | */ |
reed@google.com | 48a4cbc | 2012-03-01 19:21:11 +0000 | [diff] [blame] | 7 | |
| 8 | |
| 9 | #include "SkDeviceProfile.h" |
mtklein | 1b24933 | 2015-07-07 12:21:21 -0700 | [diff] [blame] | 10 | #include "SkMutex.h" |
reed@google.com | 48a4cbc | 2012-03-01 19:21:11 +0000 | [diff] [blame] | 11 | |
robertphillips@google.com | 09042b8 | 2012-04-06 20:01:46 +0000 | [diff] [blame] | 12 | #define DEFAULT_GAMMAEXP 2.2f |
| 13 | #define DEFAULT_CONTRASTSCALE 0.5f |
reed@google.com | 48a4cbc | 2012-03-01 19:21:11 +0000 | [diff] [blame] | 14 | #define DEFAULT_LCDCONFIG SkDeviceProfile::kNone_LCDConfig |
| 15 | #define DEFAULT_FONTHINTLEVEL SkDeviceProfile::kSlight_FontHintLevel |
| 16 | |
| 17 | static float pin(float value, float min, float max) { |
| 18 | if (value < min) { |
| 19 | value = min; |
| 20 | } else if (value > max) { |
| 21 | value = max; |
| 22 | } |
| 23 | return value; |
| 24 | } |
| 25 | |
| 26 | SkDeviceProfile::SkDeviceProfile(float gammaExp, float contrast, |
| 27 | LCDConfig config, FontHintLevel level) { |
| 28 | fGammaExponent = pin(gammaExp, 0, 10); |
| 29 | fContrastScale = pin(contrast, 0, 1); |
| 30 | fLCDConfig = config; |
| 31 | fFontHintLevel = level; |
| 32 | } |
| 33 | |
| 34 | void SkDeviceProfile::generateTableForLuminanceByte(U8CPU lumByte, |
| 35 | uint8_t table[256]) const { |
| 36 | } |
| 37 | |
| 38 | /////////////////////////////////////////////////////////////////////////////// |
| 39 | |
| 40 | SkDeviceProfile* SkDeviceProfile::Create(float gammaExp, |
| 41 | float contrast, |
| 42 | LCDConfig config, |
| 43 | FontHintLevel level) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 44 | return new SkDeviceProfile(gammaExp, contrast, config, level); |
reed@google.com | 48a4cbc | 2012-03-01 19:21:11 +0000 | [diff] [blame] | 45 | } |
| 46 | |
reed | 086eea9 | 2016-05-04 17:12:46 -0700 | [diff] [blame] | 47 | SK_DECLARE_STATIC_MUTEX(gMutex); |
reed@google.com | 48a4cbc | 2012-03-01 19:21:11 +0000 | [diff] [blame] | 48 | static SkDeviceProfile* gDefaultProfile; |
| 49 | static SkDeviceProfile* gGlobalProfile; |
| 50 | |
| 51 | SkDeviceProfile* SkDeviceProfile::GetDefault() { |
| 52 | SkAutoMutexAcquire amc(gMutex); |
| 53 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 54 | if (nullptr == gDefaultProfile) { |
reed@google.com | 48a4cbc | 2012-03-01 19:21:11 +0000 | [diff] [blame] | 55 | gDefaultProfile = SkDeviceProfile::Create(DEFAULT_GAMMAEXP, |
| 56 | DEFAULT_CONTRASTSCALE, |
| 57 | DEFAULT_LCDCONFIG, |
| 58 | DEFAULT_FONTHINTLEVEL); |
| 59 | } |
| 60 | return gDefaultProfile; |
| 61 | } |
| 62 | |
| 63 | SkDeviceProfile* SkDeviceProfile::RefGlobal() { |
| 64 | SkAutoMutexAcquire amc(gMutex); |
| 65 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 66 | if (nullptr == gGlobalProfile) { |
reed@google.com | 48a4cbc | 2012-03-01 19:21:11 +0000 | [diff] [blame] | 67 | gGlobalProfile = SkDeviceProfile::GetDefault(); |
| 68 | } |
| 69 | gGlobalProfile->ref(); |
| 70 | return gGlobalProfile; |
| 71 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 72 | |
reed@google.com | 48a4cbc | 2012-03-01 19:21:11 +0000 | [diff] [blame] | 73 | void SkDeviceProfile::SetGlobal(SkDeviceProfile* profile) { |
| 74 | SkAutoMutexAcquire amc(gMutex); |
| 75 | |
| 76 | SkRefCnt_SafeAssign(gGlobalProfile, profile); |
| 77 | } |