gfx/skia/trunk/src/core/SkDeviceProfile.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     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  */
     9 #include "SkDeviceProfile.h"
    10 #include "SkThread.h"
    12 #define DEFAULT_GAMMAEXP        2.2f
    13 #define DEFAULT_CONTRASTSCALE   0.5f
    14 #define DEFAULT_LCDCONFIG       SkDeviceProfile::kNone_LCDConfig
    15 #define DEFAULT_FONTHINTLEVEL   SkDeviceProfile::kSlight_FontHintLevel
    17 static 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 }
    26 SkDeviceProfile::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 }
    34 void SkDeviceProfile::generateTableForLuminanceByte(U8CPU lumByte,
    35                                                     uint8_t table[256]) const {
    36 }
    38 ///////////////////////////////////////////////////////////////////////////////
    40 SkDeviceProfile* SkDeviceProfile::Create(float gammaExp,
    41                                          float contrast,
    42                                          LCDConfig config,
    43                                          FontHintLevel level) {
    44     return SkNEW_ARGS(SkDeviceProfile, (gammaExp, contrast, config, level));
    45 }
    47 SK_DECLARE_STATIC_MUTEX(gMutex);
    48 static SkDeviceProfile* gDefaultProfile;
    49 static SkDeviceProfile* gGlobalProfile;
    51 SkDeviceProfile* SkDeviceProfile::GetDefault() {
    52     SkAutoMutexAcquire amc(gMutex);
    54     if (NULL == gDefaultProfile) {
    55         gDefaultProfile = SkDeviceProfile::Create(DEFAULT_GAMMAEXP,
    56                                                   DEFAULT_CONTRASTSCALE,
    57                                                   DEFAULT_LCDCONFIG,
    58                                                   DEFAULT_FONTHINTLEVEL);
    59     }
    60     return gDefaultProfile;
    61 }
    63 SkDeviceProfile* SkDeviceProfile::RefGlobal() {
    64     SkAutoMutexAcquire amc(gMutex);
    66     if (NULL == gGlobalProfile) {
    67         gGlobalProfile = SkDeviceProfile::GetDefault();
    68     }
    69     gGlobalProfile->ref();
    70     return gGlobalProfile;
    71 }
    73 void SkDeviceProfile::SetGlobal(SkDeviceProfile* profile) {
    74     SkAutoMutexAcquire amc(gMutex);
    76     SkRefCnt_SafeAssign(gGlobalProfile, profile);
    77 }

mercurial