michael@0: /* michael@0: * Copyright 2012 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #include "SkDeviceProfile.h" michael@0: #include "SkThread.h" michael@0: michael@0: #define DEFAULT_GAMMAEXP 2.2f michael@0: #define DEFAULT_CONTRASTSCALE 0.5f michael@0: #define DEFAULT_LCDCONFIG SkDeviceProfile::kNone_LCDConfig michael@0: #define DEFAULT_FONTHINTLEVEL SkDeviceProfile::kSlight_FontHintLevel michael@0: michael@0: static float pin(float value, float min, float max) { michael@0: if (value < min) { michael@0: value = min; michael@0: } else if (value > max) { michael@0: value = max; michael@0: } michael@0: return value; michael@0: } michael@0: michael@0: SkDeviceProfile::SkDeviceProfile(float gammaExp, float contrast, michael@0: LCDConfig config, FontHintLevel level) { michael@0: fGammaExponent = pin(gammaExp, 0, 10); michael@0: fContrastScale = pin(contrast, 0, 1); michael@0: fLCDConfig = config; michael@0: fFontHintLevel = level; michael@0: } michael@0: michael@0: void SkDeviceProfile::generateTableForLuminanceByte(U8CPU lumByte, michael@0: uint8_t table[256]) const { michael@0: } michael@0: michael@0: /////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: SkDeviceProfile* SkDeviceProfile::Create(float gammaExp, michael@0: float contrast, michael@0: LCDConfig config, michael@0: FontHintLevel level) { michael@0: return SkNEW_ARGS(SkDeviceProfile, (gammaExp, contrast, config, level)); michael@0: } michael@0: michael@0: SK_DECLARE_STATIC_MUTEX(gMutex); michael@0: static SkDeviceProfile* gDefaultProfile; michael@0: static SkDeviceProfile* gGlobalProfile; michael@0: michael@0: SkDeviceProfile* SkDeviceProfile::GetDefault() { michael@0: SkAutoMutexAcquire amc(gMutex); michael@0: michael@0: if (NULL == gDefaultProfile) { michael@0: gDefaultProfile = SkDeviceProfile::Create(DEFAULT_GAMMAEXP, michael@0: DEFAULT_CONTRASTSCALE, michael@0: DEFAULT_LCDCONFIG, michael@0: DEFAULT_FONTHINTLEVEL); michael@0: } michael@0: return gDefaultProfile; michael@0: } michael@0: michael@0: SkDeviceProfile* SkDeviceProfile::RefGlobal() { michael@0: SkAutoMutexAcquire amc(gMutex); michael@0: michael@0: if (NULL == gGlobalProfile) { michael@0: gGlobalProfile = SkDeviceProfile::GetDefault(); michael@0: } michael@0: gGlobalProfile->ref(); michael@0: return gGlobalProfile; michael@0: } michael@0: michael@0: void SkDeviceProfile::SetGlobal(SkDeviceProfile* profile) { michael@0: SkAutoMutexAcquire amc(gMutex); michael@0: michael@0: SkRefCnt_SafeAssign(gGlobalProfile, profile); michael@0: }