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