gfx/skia/trunk/src/images/SkImageRef_GlobalPool.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     2 /*
     3  * Copyright 2011 Google Inc.
     4  *
     5  * Use of this source code is governed by a BSD-style license that can be
     6  * found in the LICENSE file.
     7  */
     8 #include "SkImageRef_GlobalPool.h"
     9 #include "SkImageRefPool.h"
    10 #include "SkThread.h"
    12 SK_DECLARE_STATIC_MUTEX(gGlobalPoolMutex);
    14 /*
    15  *  This returns the lazily-allocated global pool. It must be called
    16  *  from inside the guard mutex, so we safely only ever allocate 1.
    17  */
    18 static SkImageRefPool* GetGlobalPool() {
    19     static SkImageRefPool* gPool;
    20     if (NULL == gPool) {
    21         gPool = SkNEW(SkImageRefPool);
    22         // call sk_atexit(...) when we have that, to free the global pool
    23     }
    24     return gPool;
    25 }
    27 SkImageRef_GlobalPool::SkImageRef_GlobalPool(const SkImageInfo& info,
    28                                              SkStreamRewindable* stream,
    29                                              int sampleSize)
    30         : SkImageRef(info, stream, sampleSize, &gGlobalPoolMutex) {
    31     SkASSERT(&gGlobalPoolMutex == this->mutex());
    32     SkAutoMutexAcquire ac(gGlobalPoolMutex);
    33     GetGlobalPool()->addToHead(this);
    34 }
    36 SkImageRef_GlobalPool::~SkImageRef_GlobalPool() {
    37     SkASSERT(&gGlobalPoolMutex == this->mutex());
    38     SkAutoMutexAcquire ac(gGlobalPoolMutex);
    39     GetGlobalPool()->detach(this);
    40 }
    42 /*  By design, onUnlockPixels() already is inside the mutex-lock,
    43  *  and it is the (indirect) caller of onDecode(), therefore we can assume
    44  *  that we also are already inside the mutex. Hence, we can reference
    45  *  the global-pool directly.
    46  */
    47 bool SkImageRef_GlobalPool::onDecode(SkImageDecoder* codec, SkStreamRewindable* stream,
    48                                      SkBitmap* bitmap, SkBitmap::Config config,
    49                                      SkImageDecoder::Mode mode) {
    50     if (!this->INHERITED::onDecode(codec, stream, bitmap, config, mode)) {
    51         return false;
    52     }
    53     if (mode == SkImageDecoder::kDecodePixels_Mode) {
    54         // no need to grab the mutex here, it has already been acquired.
    55         GetGlobalPool()->justAddedPixels(this);
    56     }
    57     return true;
    58 }
    60 void SkImageRef_GlobalPool::onUnlockPixels() {
    61     this->INHERITED::onUnlockPixels();
    63     // by design, onUnlockPixels() already is inside the mutex-lock
    64     GetGlobalPool()->canLosePixels(this);
    65 }
    67 SkImageRef_GlobalPool::SkImageRef_GlobalPool(SkReadBuffer& buffer)
    68         : INHERITED(buffer, &gGlobalPoolMutex) {
    69     SkASSERT(&gGlobalPoolMutex == this->mutex());
    70     SkAutoMutexAcquire ac(gGlobalPoolMutex);
    71     GetGlobalPool()->addToHead(this);
    72 }
    74 ///////////////////////////////////////////////////////////////////////////////
    75 // global imagerefpool wrappers
    77 size_t SkImageRef_GlobalPool::GetRAMBudget() {
    78     SkAutoMutexAcquire ac(gGlobalPoolMutex);
    79     return GetGlobalPool()->getRAMBudget();
    80 }
    82 void SkImageRef_GlobalPool::SetRAMBudget(size_t size) {
    83     SkAutoMutexAcquire ac(gGlobalPoolMutex);
    84     GetGlobalPool()->setRAMBudget(size);
    85 }
    87 size_t SkImageRef_GlobalPool::GetRAMUsed() {
    88     SkAutoMutexAcquire ac(gGlobalPoolMutex);
    89     return GetGlobalPool()->getRAMUsed();
    90 }
    92 void SkImageRef_GlobalPool::SetRAMUsed(size_t usage) {
    93     SkAutoMutexAcquire ac(gGlobalPoolMutex);
    94     GetGlobalPool()->setRAMUsed(usage);
    95 }
    97 void SkImageRef_GlobalPool::DumpPool() {
    98     SkAutoMutexAcquire ac(gGlobalPoolMutex);
    99     GetGlobalPool()->dump();
   100 }

mercurial