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
10static 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
19SkDeviceProfile::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
27void SkDeviceProfile::generateTableForLuminanceByte(U8CPU lumByte,
28                                                    uint8_t table[256]) const {
29}
30
31///////////////////////////////////////////////////////////////////////////////
32
33SkDeviceProfile* SkDeviceProfile::Create(float gammaExp,
34                                         float contrast,
35                                         LCDConfig config,
36                                         FontHintLevel level) {
37    return SkNEW_ARGS(SkDeviceProfile, (gammaExp, contrast, config, level));
38}
39
40static SkMutex gMutex;
41static SkDeviceProfile* gDefaultProfile;
42static SkDeviceProfile* gGlobalProfile;
43
44SkDeviceProfile* 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
56SkDeviceProfile* SkDeviceProfile::RefGlobal() {
57    SkAutoMutexAcquire amc(gMutex);
58
59    if (NULL == gGlobalProfile) {
60        gGlobalProfile = SkDeviceProfile::GetDefault();
61    }
62    gGlobalProfile->ref();
63    return gGlobalProfile;
64}
65
66void SkDeviceProfile::SetGlobal(SkDeviceProfile* profile) {
67    SkAutoMutexAcquire amc(gMutex);
68
69    SkRefCnt_SafeAssign(gGlobalProfile, profile);
70}
71
72
73