blob: 8d60151f6f297369ce26824b8f6e6f062f8c9a11 [file] [log] [blame]
robertphillips@google.com15e9d3e2012-06-21 20:25:03 +00001/*
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.com48a4cbc2012-03-01 19:21:11 +00007
8
9#include "SkDeviceProfile.h"
bungeman@google.com415c4802013-07-18 21:05:50 +000010#include "SkThread.h"
reed@google.com48a4cbc2012-03-01 19:21:11 +000011
robertphillips@google.com09042b82012-04-06 20:01:46 +000012#define DEFAULT_GAMMAEXP 2.2f
13#define DEFAULT_CONTRASTSCALE 0.5f
reed@google.com48a4cbc2012-03-01 19:21:11 +000014#define DEFAULT_LCDCONFIG SkDeviceProfile::kNone_LCDConfig
15#define DEFAULT_FONTHINTLEVEL SkDeviceProfile::kSlight_FontHintLevel
16
17static 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
26SkDeviceProfile::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
34void SkDeviceProfile::generateTableForLuminanceByte(U8CPU lumByte,
35 uint8_t table[256]) const {
36}
37
38///////////////////////////////////////////////////////////////////////////////
39
40SkDeviceProfile* SkDeviceProfile::Create(float gammaExp,
41 float contrast,
42 LCDConfig config,
43 FontHintLevel level) {
44 return SkNEW_ARGS(SkDeviceProfile, (gammaExp, contrast, config, level));
45}
46
bungeman@google.com415c4802013-07-18 21:05:50 +000047SK_DECLARE_STATIC_MUTEX(gMutex);
reed@google.com48a4cbc2012-03-01 19:21:11 +000048static SkDeviceProfile* gDefaultProfile;
49static SkDeviceProfile* gGlobalProfile;
50
51SkDeviceProfile* 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
63SkDeviceProfile* SkDeviceProfile::RefGlobal() {
64 SkAutoMutexAcquire amc(gMutex);
65
66 if (NULL == gGlobalProfile) {
67 gGlobalProfile = SkDeviceProfile::GetDefault();
68 }
69 gGlobalProfile->ref();
70 return gGlobalProfile;
71}
rmistry@google.comfbfcd562012-08-23 18:09:54 +000072
reed@google.com48a4cbc2012-03-01 19:21:11 +000073void SkDeviceProfile::SetGlobal(SkDeviceProfile* profile) {
74 SkAutoMutexAcquire amc(gMutex);
75
76 SkRefCnt_SafeAssign(gGlobalProfile, profile);
77}