gfx/skia/trunk/src/lazy/SkDiscardablePixelRef.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 "SkDiscardablePixelRef.h"
michael@0 9 #include "SkDiscardableMemory.h"
michael@0 10 #include "SkImageGenerator.h"
michael@0 11
michael@0 12 SkDiscardablePixelRef::SkDiscardablePixelRef(const SkImageInfo& info,
michael@0 13 SkImageGenerator* generator,
michael@0 14 size_t rowBytes,
michael@0 15 SkDiscardableMemory::Factory* fact)
michael@0 16 : INHERITED(info)
michael@0 17 , fGenerator(generator)
michael@0 18 , fDMFactory(fact)
michael@0 19 , fRowBytes(rowBytes)
michael@0 20 , fDiscardableMemory(NULL)
michael@0 21 {
michael@0 22 SkASSERT(fGenerator != NULL);
michael@0 23 SkASSERT(fRowBytes > 0);
michael@0 24 // The SkImageGenerator contract requires fGenerator to always
michael@0 25 // decode the same image on each call to getPixels().
michael@0 26 this->setImmutable();
michael@0 27 SkSafeRef(fDMFactory);
michael@0 28 }
michael@0 29
michael@0 30 SkDiscardablePixelRef::~SkDiscardablePixelRef() {
michael@0 31 if (this->isLocked()) {
michael@0 32 fDiscardableMemory->unlock();
michael@0 33 }
michael@0 34 SkDELETE(fDiscardableMemory);
michael@0 35 SkSafeUnref(fDMFactory);
michael@0 36 SkDELETE(fGenerator);
michael@0 37 }
michael@0 38
michael@0 39 bool SkDiscardablePixelRef::onNewLockPixels(LockRec* rec) {
michael@0 40 if (fDiscardableMemory != NULL) {
michael@0 41 if (fDiscardableMemory->lock()) {
michael@0 42 rec->fPixels = fDiscardableMemory->data();
michael@0 43 rec->fColorTable = NULL;
michael@0 44 rec->fRowBytes = fRowBytes;
michael@0 45 return true;
michael@0 46 }
michael@0 47 SkDELETE(fDiscardableMemory);
michael@0 48 fDiscardableMemory = NULL;
michael@0 49 }
michael@0 50
michael@0 51 const size_t size = this->info().getSafeSize(fRowBytes);
michael@0 52
michael@0 53 if (fDMFactory != NULL) {
michael@0 54 fDiscardableMemory = fDMFactory->create(size);
michael@0 55 } else {
michael@0 56 fDiscardableMemory = SkDiscardableMemory::Create(size);
michael@0 57 }
michael@0 58 if (NULL == fDiscardableMemory) {
michael@0 59 return false; // Memory allocation failed.
michael@0 60 }
michael@0 61
michael@0 62 void* pixels = fDiscardableMemory->data();
michael@0 63 if (!fGenerator->getPixels(this->info(), pixels, fRowBytes)) {
michael@0 64 fDiscardableMemory->unlock();
michael@0 65 SkDELETE(fDiscardableMemory);
michael@0 66 fDiscardableMemory = NULL;
michael@0 67 return false;
michael@0 68 }
michael@0 69
michael@0 70 rec->fPixels = pixels;
michael@0 71 rec->fColorTable = NULL;
michael@0 72 rec->fRowBytes = fRowBytes;
michael@0 73 return true;
michael@0 74 }
michael@0 75
michael@0 76 void SkDiscardablePixelRef::onUnlockPixels() {
michael@0 77 fDiscardableMemory->unlock();
michael@0 78 }
michael@0 79
michael@0 80 bool SkInstallDiscardablePixelRef(SkImageGenerator* generator,
michael@0 81 SkBitmap* dst,
michael@0 82 SkDiscardableMemory::Factory* factory) {
michael@0 83 SkImageInfo info;
michael@0 84 SkAutoTDelete<SkImageGenerator> autoGenerator(generator);
michael@0 85 if ((NULL == autoGenerator.get())
michael@0 86 || (!autoGenerator->getInfo(&info))
michael@0 87 || (!dst->setConfig(info, 0))) {
michael@0 88 return false;
michael@0 89 }
michael@0 90 SkASSERT(dst->colorType() != kUnknown_SkColorType);
michael@0 91 if (dst->empty()) { // Use a normal pixelref.
michael@0 92 return dst->allocPixels();
michael@0 93 }
michael@0 94 SkAutoTUnref<SkDiscardablePixelRef> ref(
michael@0 95 SkNEW_ARGS(SkDiscardablePixelRef,
michael@0 96 (info, autoGenerator.detach(), dst->rowBytes(), factory)));
michael@0 97 dst->setPixelRef(ref);
michael@0 98 return true;
michael@0 99 }

mercurial