gfx/skia/trunk/src/image/SkSurface.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 2012 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 "SkSurface_Base.h"
michael@0 9 #include "SkImagePriv.h"
michael@0 10 #include "SkCanvas.h"
michael@0 11
michael@0 12 ///////////////////////////////////////////////////////////////////////////////
michael@0 13
michael@0 14 SkSurface_Base::SkSurface_Base(int width, int height) : INHERITED(width, height) {
michael@0 15 fCachedCanvas = NULL;
michael@0 16 fCachedImage = NULL;
michael@0 17 }
michael@0 18
michael@0 19 SkSurface_Base::SkSurface_Base(const SkImageInfo& info) : INHERITED(info) {
michael@0 20 fCachedCanvas = NULL;
michael@0 21 fCachedImage = NULL;
michael@0 22 }
michael@0 23
michael@0 24 SkSurface_Base::~SkSurface_Base() {
michael@0 25 // in case the canvas outsurvives us, we null the callback
michael@0 26 if (fCachedCanvas) {
michael@0 27 fCachedCanvas->setSurfaceBase(NULL);
michael@0 28 }
michael@0 29
michael@0 30 SkSafeUnref(fCachedImage);
michael@0 31 SkSafeUnref(fCachedCanvas);
michael@0 32 }
michael@0 33
michael@0 34 void SkSurface_Base::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y,
michael@0 35 const SkPaint* paint) {
michael@0 36 SkImage* image = this->newImageSnapshot();
michael@0 37 if (image) {
michael@0 38 image->draw(canvas, x, y, paint);
michael@0 39 image->unref();
michael@0 40 }
michael@0 41 }
michael@0 42
michael@0 43 void SkSurface_Base::aboutToDraw(ContentChangeMode mode) {
michael@0 44 this->dirtyGenerationID();
michael@0 45
michael@0 46 if (NULL != fCachedCanvas) {
michael@0 47 SkASSERT(fCachedCanvas->getSurfaceBase() == this || \
michael@0 48 NULL == fCachedCanvas->getSurfaceBase());
michael@0 49 fCachedCanvas->setSurfaceBase(NULL);
michael@0 50 }
michael@0 51
michael@0 52 if (NULL != fCachedImage) {
michael@0 53 // the surface may need to fork its backend, if its sharing it with
michael@0 54 // the cached image. Note: we only call if there is an outstanding owner
michael@0 55 // on the image (besides us).
michael@0 56 if (!fCachedImage->unique()) {
michael@0 57 this->onCopyOnWrite(mode);
michael@0 58 }
michael@0 59
michael@0 60 // regardless of copy-on-write, we must drop our cached image now, so
michael@0 61 // that the next request will get our new contents.
michael@0 62 fCachedImage->unref();
michael@0 63 fCachedImage = NULL;
michael@0 64 }
michael@0 65 }
michael@0 66
michael@0 67 uint32_t SkSurface_Base::newGenerationID() {
michael@0 68 this->installIntoCanvasForDirtyNotification();
michael@0 69
michael@0 70 static int32_t gID;
michael@0 71 return sk_atomic_inc(&gID) + 1;
michael@0 72 }
michael@0 73
michael@0 74 static SkSurface_Base* asSB(SkSurface* surface) {
michael@0 75 return static_cast<SkSurface_Base*>(surface);
michael@0 76 }
michael@0 77
michael@0 78 ///////////////////////////////////////////////////////////////////////////////
michael@0 79
michael@0 80 SkSurface::SkSurface(int width, int height) : fWidth(width), fHeight(height) {
michael@0 81 SkASSERT(fWidth >= 0);
michael@0 82 SkASSERT(fHeight >= 0);
michael@0 83 fGenerationID = 0;
michael@0 84 }
michael@0 85
michael@0 86 SkSurface::SkSurface(const SkImageInfo& info)
michael@0 87 : fWidth(info.fWidth)
michael@0 88 , fHeight(info.fHeight)
michael@0 89 {
michael@0 90 SkASSERT(fWidth >= 0);
michael@0 91 SkASSERT(fHeight >= 0);
michael@0 92 fGenerationID = 0;
michael@0 93 }
michael@0 94
michael@0 95 uint32_t SkSurface::generationID() {
michael@0 96 if (0 == fGenerationID) {
michael@0 97 fGenerationID = asSB(this)->newGenerationID();
michael@0 98 }
michael@0 99 return fGenerationID;
michael@0 100 }
michael@0 101
michael@0 102 void SkSurface::notifyContentWillChange(ContentChangeMode mode) {
michael@0 103 asSB(this)->aboutToDraw(mode);
michael@0 104 }
michael@0 105
michael@0 106 SkCanvas* SkSurface::getCanvas() {
michael@0 107 return asSB(this)->getCachedCanvas();
michael@0 108 }
michael@0 109
michael@0 110 SkImage* SkSurface::newImageSnapshot() {
michael@0 111 SkImage* image = asSB(this)->getCachedImage();
michael@0 112 SkSafeRef(image); // the caller will call unref() to balance this
michael@0 113 return image;
michael@0 114 }
michael@0 115
michael@0 116 SkSurface* SkSurface::newSurface(const SkImageInfo& info) {
michael@0 117 return asSB(this)->onNewSurface(info);
michael@0 118 }
michael@0 119
michael@0 120 void SkSurface::draw(SkCanvas* canvas, SkScalar x, SkScalar y,
michael@0 121 const SkPaint* paint) {
michael@0 122 return asSB(this)->onDraw(canvas, x, y, paint);
michael@0 123 }
michael@0 124
michael@0 125 const void* SkSurface::peekPixels(SkImageInfo* info, size_t* rowBytes) {
michael@0 126 return this->getCanvas()->peekPixels(info, rowBytes);
michael@0 127 }

mercurial