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 #include "SkThread.h"
11
12 #define DEFAULT_GAMMAEXP 2.2f
13 #define DEFAULT_CONTRASTSCALE 0.5f
14 #define DEFAULT_LCDCONFIG SkDeviceProfile::kNone_LCDConfig
15 #define DEFAULT_FONTHINTLEVEL SkDeviceProfile::kSlight_FontHintLevel
16
pin(float value,float min,float max)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
SkDeviceProfile(float gammaExp,float contrast,LCDConfig config,FontHintLevel level)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
generateTableForLuminanceByte(U8CPU lumByte,uint8_t table[256]) const34 void SkDeviceProfile::generateTableForLuminanceByte(U8CPU lumByte,
35 uint8_t table[256]) const {
36 }
37
38 ///////////////////////////////////////////////////////////////////////////////
39
Create(float gammaExp,float contrast,LCDConfig config,FontHintLevel level)40 SkDeviceProfile* SkDeviceProfile::Create(float gammaExp,
41 float contrast,
42 LCDConfig config,
43 FontHintLevel level) {
44 return SkNEW_ARGS(SkDeviceProfile, (gammaExp, contrast, config, level));
45 }
46
47 SK_DECLARE_STATIC_MUTEX(gMutex);
48 static SkDeviceProfile* gDefaultProfile;
49 static SkDeviceProfile* gGlobalProfile;
50
GetDefault()51 SkDeviceProfile* SkDeviceProfile::GetDefault() {
52 SkAutoMutexAcquire amc(gMutex);
53
54 if (NULL == gDefaultProfile) {
55 gDefaultProfile = SkDeviceProfile::Create(DEFAULT_GAMMAEXP,
56 DEFAULT_CONTRASTSCALE,
57 DEFAULT_LCDCONFIG,
58 DEFAULT_FONTHINTLEVEL);
59 }
60 return gDefaultProfile;
61 }
62
RefGlobal()63 SkDeviceProfile* SkDeviceProfile::RefGlobal() {
64 SkAutoMutexAcquire amc(gMutex);
65
66 if (NULL == gGlobalProfile) {
67 gGlobalProfile = SkDeviceProfile::GetDefault();
68 }
69 gGlobalProfile->ref();
70 return gGlobalProfile;
71 }
72
SetGlobal(SkDeviceProfile * profile)73 void SkDeviceProfile::SetGlobal(SkDeviceProfile* profile) {
74 SkAutoMutexAcquire amc(gMutex);
75
76 SkRefCnt_SafeAssign(gGlobalProfile, profile);
77 }
78