1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/core/SkDeviceProfile.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,77 @@ 1.4 +/* 1.5 + * Copyright 2012 Google Inc. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license that can be 1.8 + * found in the LICENSE file. 1.9 + */ 1.10 + 1.11 + 1.12 +#include "SkDeviceProfile.h" 1.13 +#include "SkThread.h" 1.14 + 1.15 +#define DEFAULT_GAMMAEXP 2.2f 1.16 +#define DEFAULT_CONTRASTSCALE 0.5f 1.17 +#define DEFAULT_LCDCONFIG SkDeviceProfile::kNone_LCDConfig 1.18 +#define DEFAULT_FONTHINTLEVEL SkDeviceProfile::kSlight_FontHintLevel 1.19 + 1.20 +static float pin(float value, float min, float max) { 1.21 + if (value < min) { 1.22 + value = min; 1.23 + } else if (value > max) { 1.24 + value = max; 1.25 + } 1.26 + return value; 1.27 +} 1.28 + 1.29 +SkDeviceProfile::SkDeviceProfile(float gammaExp, float contrast, 1.30 + LCDConfig config, FontHintLevel level) { 1.31 + fGammaExponent = pin(gammaExp, 0, 10); 1.32 + fContrastScale = pin(contrast, 0, 1); 1.33 + fLCDConfig = config; 1.34 + fFontHintLevel = level; 1.35 +} 1.36 + 1.37 +void SkDeviceProfile::generateTableForLuminanceByte(U8CPU lumByte, 1.38 + uint8_t table[256]) const { 1.39 +} 1.40 + 1.41 +/////////////////////////////////////////////////////////////////////////////// 1.42 + 1.43 +SkDeviceProfile* SkDeviceProfile::Create(float gammaExp, 1.44 + float contrast, 1.45 + LCDConfig config, 1.46 + FontHintLevel level) { 1.47 + return SkNEW_ARGS(SkDeviceProfile, (gammaExp, contrast, config, level)); 1.48 +} 1.49 + 1.50 +SK_DECLARE_STATIC_MUTEX(gMutex); 1.51 +static SkDeviceProfile* gDefaultProfile; 1.52 +static SkDeviceProfile* gGlobalProfile; 1.53 + 1.54 +SkDeviceProfile* SkDeviceProfile::GetDefault() { 1.55 + SkAutoMutexAcquire amc(gMutex); 1.56 + 1.57 + if (NULL == gDefaultProfile) { 1.58 + gDefaultProfile = SkDeviceProfile::Create(DEFAULT_GAMMAEXP, 1.59 + DEFAULT_CONTRASTSCALE, 1.60 + DEFAULT_LCDCONFIG, 1.61 + DEFAULT_FONTHINTLEVEL); 1.62 + } 1.63 + return gDefaultProfile; 1.64 +} 1.65 + 1.66 +SkDeviceProfile* SkDeviceProfile::RefGlobal() { 1.67 + SkAutoMutexAcquire amc(gMutex); 1.68 + 1.69 + if (NULL == gGlobalProfile) { 1.70 + gGlobalProfile = SkDeviceProfile::GetDefault(); 1.71 + } 1.72 + gGlobalProfile->ref(); 1.73 + return gGlobalProfile; 1.74 +} 1.75 + 1.76 +void SkDeviceProfile::SetGlobal(SkDeviceProfile* profile) { 1.77 + SkAutoMutexAcquire amc(gMutex); 1.78 + 1.79 + SkRefCnt_SafeAssign(gGlobalProfile, profile); 1.80 +}