gfx/skia/trunk/src/lazy/SkCachingPixelRef.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.

michael@0 1 /*
michael@0 2 * Copyright 2013 Google Inc.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license that can be
michael@0 5 * found in the LICENSE file.
michael@0 6 */
michael@0 7
michael@0 8 #include "SkCachingPixelRef.h"
michael@0 9 #include "SkScaledImageCache.h"
michael@0 10
michael@0 11 bool SkCachingPixelRef::Install(SkImageGenerator* generator,
michael@0 12 SkBitmap* dst) {
michael@0 13 SkImageInfo info;
michael@0 14 SkASSERT(dst != NULL);
michael@0 15 if ((NULL == generator)
michael@0 16 || !(generator->getInfo(&info))
michael@0 17 || !dst->setConfig(info, 0)) {
michael@0 18 SkDELETE(generator);
michael@0 19 return false;
michael@0 20 }
michael@0 21 SkAutoTUnref<SkCachingPixelRef> ref(SkNEW_ARGS(SkCachingPixelRef,
michael@0 22 (info, generator, dst->rowBytes())));
michael@0 23 dst->setPixelRef(ref);
michael@0 24 return true;
michael@0 25 }
michael@0 26
michael@0 27 SkCachingPixelRef::SkCachingPixelRef(const SkImageInfo& info,
michael@0 28 SkImageGenerator* generator,
michael@0 29 size_t rowBytes)
michael@0 30 : INHERITED(info)
michael@0 31 , fImageGenerator(generator)
michael@0 32 , fErrorInDecoding(false)
michael@0 33 , fScaledCacheId(NULL)
michael@0 34 , fRowBytes(rowBytes) {
michael@0 35 SkASSERT(fImageGenerator != NULL);
michael@0 36 }
michael@0 37 SkCachingPixelRef::~SkCachingPixelRef() {
michael@0 38 SkDELETE(fImageGenerator);
michael@0 39 SkASSERT(NULL == fScaledCacheId);
michael@0 40 // Assert always unlock before unref.
michael@0 41 }
michael@0 42
michael@0 43 bool SkCachingPixelRef::onNewLockPixels(LockRec* rec) {
michael@0 44 if (fErrorInDecoding) {
michael@0 45 return false; // don't try again.
michael@0 46 }
michael@0 47
michael@0 48 const SkImageInfo& info = this->info();
michael@0 49 SkBitmap bitmap;
michael@0 50 SkASSERT(NULL == fScaledCacheId);
michael@0 51 fScaledCacheId = SkScaledImageCache::FindAndLock(this->getGenerationID(),
michael@0 52 info.fWidth,
michael@0 53 info.fHeight,
michael@0 54 &bitmap);
michael@0 55 if (NULL == fScaledCacheId) {
michael@0 56 // Cache has been purged, must re-decode.
michael@0 57 if ((!bitmap.setConfig(info, fRowBytes)) || !bitmap.allocPixels()) {
michael@0 58 fErrorInDecoding = true;
michael@0 59 return false;
michael@0 60 }
michael@0 61 SkAutoLockPixels autoLockPixels(bitmap);
michael@0 62 if (!fImageGenerator->getPixels(info, bitmap.getPixels(), fRowBytes)) {
michael@0 63 fErrorInDecoding = true;
michael@0 64 return false;
michael@0 65 }
michael@0 66 fScaledCacheId = SkScaledImageCache::AddAndLock(this->getGenerationID(),
michael@0 67 info.fWidth,
michael@0 68 info.fHeight,
michael@0 69 bitmap);
michael@0 70 SkASSERT(fScaledCacheId != NULL);
michael@0 71 }
michael@0 72
michael@0 73 // Now bitmap should contain a concrete PixelRef of the decoded
michael@0 74 // image.
michael@0 75 SkAutoLockPixels autoLockPixels(bitmap);
michael@0 76 void* pixels = bitmap.getPixels();
michael@0 77 SkASSERT(pixels != NULL);
michael@0 78
michael@0 79 // At this point, the autoLockPixels will unlockPixels()
michael@0 80 // to remove bitmap's lock on the pixels. We will then
michael@0 81 // destroy bitmap. The *only* guarantee that this pointer
michael@0 82 // remains valid is the guarantee made by
michael@0 83 // SkScaledImageCache that it will not destroy the *other*
michael@0 84 // bitmap (SkScaledImageCache::Rec.fBitmap) that holds a
michael@0 85 // reference to the concrete PixelRef while this record is
michael@0 86 // locked.
michael@0 87 rec->fPixels = pixels;
michael@0 88 rec->fColorTable = NULL;
michael@0 89 rec->fRowBytes = bitmap.rowBytes();
michael@0 90 return true;
michael@0 91 }
michael@0 92
michael@0 93 void SkCachingPixelRef::onUnlockPixels() {
michael@0 94 SkASSERT(fScaledCacheId != NULL);
michael@0 95 SkScaledImageCache::Unlock( static_cast<SkScaledImageCache::ID*>(fScaledCacheId));
michael@0 96 fScaledCacheId = NULL;
michael@0 97 }

mercurial