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 12SK_DEFINE_INST_COUNT(SkDeviceProfile) 13 14#define DEFAULT_GAMMAEXP 2.2f 15#define DEFAULT_CONTRASTSCALE 0.5f 16#define DEFAULT_LCDCONFIG SkDeviceProfile::kNone_LCDConfig 17#define DEFAULT_FONTHINTLEVEL SkDeviceProfile::kSlight_FontHintLevel 18 19static float pin(float value, float min, float max) { 20 if (value < min) { 21 value = min; 22 } else if (value > max) { 23 value = max; 24 } 25 return value; 26} 27 28SkDeviceProfile::SkDeviceProfile(float gammaExp, float contrast, 29 LCDConfig config, FontHintLevel level) { 30 fGammaExponent = pin(gammaExp, 0, 10); 31 fContrastScale = pin(contrast, 0, 1); 32 fLCDConfig = config; 33 fFontHintLevel = level; 34} 35 36void SkDeviceProfile::generateTableForLuminanceByte(U8CPU lumByte, 37 uint8_t table[256]) const { 38} 39 40/////////////////////////////////////////////////////////////////////////////// 41 42SkDeviceProfile* SkDeviceProfile::Create(float gammaExp, 43 float contrast, 44 LCDConfig config, 45 FontHintLevel level) { 46 return SkNEW_ARGS(SkDeviceProfile, (gammaExp, contrast, config, level)); 47} 48 49SK_DECLARE_STATIC_MUTEX(gMutex); 50static SkDeviceProfile* gDefaultProfile; 51static SkDeviceProfile* gGlobalProfile; 52 53SkDeviceProfile* SkDeviceProfile::GetDefault() { 54 SkAutoMutexAcquire amc(gMutex); 55 56 if (NULL == gDefaultProfile) { 57 gDefaultProfile = SkDeviceProfile::Create(DEFAULT_GAMMAEXP, 58 DEFAULT_CONTRASTSCALE, 59 DEFAULT_LCDCONFIG, 60 DEFAULT_FONTHINTLEVEL); 61 } 62 return gDefaultProfile; 63} 64 65SkDeviceProfile* SkDeviceProfile::RefGlobal() { 66 SkAutoMutexAcquire amc(gMutex); 67 68 if (NULL == gGlobalProfile) { 69 gGlobalProfile = SkDeviceProfile::GetDefault(); 70 } 71 gGlobalProfile->ref(); 72 return gGlobalProfile; 73} 74 75void SkDeviceProfile::SetGlobal(SkDeviceProfile* profile) { 76 SkAutoMutexAcquire amc(gMutex); 77 78 SkRefCnt_SafeAssign(gGlobalProfile, profile); 79} 80