aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkDeviceProfile.cpp
blob: e1c10c87d77366ba578d2d392981bf436abf1302 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
 * Copyright 2012 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */


#include "SkDeviceProfile.h"
#include "SkMutex.h"

#define DEFAULT_GAMMAEXP        2.2f
#define DEFAULT_CONTRASTSCALE   0.5f
#define DEFAULT_LCDCONFIG       SkDeviceProfile::kNone_LCDConfig
#define DEFAULT_FONTHINTLEVEL   SkDeviceProfile::kSlight_FontHintLevel

static float pin(float value, float min, float max) {
    if (value < min) {
        value = min;
    } else if (value > max) {
        value = max;
    }
    return value;
}

SkDeviceProfile::SkDeviceProfile(float gammaExp, float contrast,
                                 LCDConfig config, FontHintLevel level) {
    fGammaExponent = pin(gammaExp, 0, 10);
    fContrastScale = pin(contrast, 0, 1);
    fLCDConfig = config;
    fFontHintLevel = level;
}

void SkDeviceProfile::generateTableForLuminanceByte(U8CPU lumByte,
                                                    uint8_t table[256]) const {
}

///////////////////////////////////////////////////////////////////////////////

SkDeviceProfile* SkDeviceProfile::Create(float gammaExp,
                                         float contrast,
                                         LCDConfig config,
                                         FontHintLevel level) {
    return new SkDeviceProfile(gammaExp, contrast, config, level);
}

SK_DECLARE_STATIC_MUTEX(gMutex);
static SkDeviceProfile* gDefaultProfile;
static SkDeviceProfile* gGlobalProfile;

SkDeviceProfile* SkDeviceProfile::GetDefault() {
    SkAutoMutexAcquire amc(gMutex);

    if (nullptr == gDefaultProfile) {
        gDefaultProfile = SkDeviceProfile::Create(DEFAULT_GAMMAEXP,
                                                  DEFAULT_CONTRASTSCALE,
                                                  DEFAULT_LCDCONFIG,
                                                  DEFAULT_FONTHINTLEVEL);
    }
    return gDefaultProfile;
}

SkDeviceProfile* SkDeviceProfile::RefGlobal() {
    SkAutoMutexAcquire amc(gMutex);

    if (nullptr == gGlobalProfile) {
        gGlobalProfile = SkDeviceProfile::GetDefault();
    }
    gGlobalProfile->ref();
    return gGlobalProfile;
}

void SkDeviceProfile::SetGlobal(SkDeviceProfile* profile) {
    SkAutoMutexAcquire amc(gMutex);

    SkRefCnt_SafeAssign(gGlobalProfile, profile);
}