gfx/skia/trunk/src/image/SkSurface_Picture.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 "SkCanvas.h"
michael@0 10 #include "SkImagePriv.h"
michael@0 11 #include "SkPicture.h"
michael@0 12
michael@0 13 /**
michael@0 14 * What does it mean to ask for more than one canvas from a picture?
michael@0 15 * How do we return an Image and then "continue" recording?
michael@0 16 */
michael@0 17 class SkSurface_Picture : public SkSurface_Base {
michael@0 18 public:
michael@0 19 SkSurface_Picture(int width, int height);
michael@0 20 virtual ~SkSurface_Picture();
michael@0 21
michael@0 22 virtual SkCanvas* onNewCanvas() SK_OVERRIDE;
michael@0 23 virtual SkSurface* onNewSurface(const SkImageInfo&) SK_OVERRIDE;
michael@0 24 virtual SkImage* onNewImageSnapshot() SK_OVERRIDE;
michael@0 25 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y,
michael@0 26 const SkPaint*) SK_OVERRIDE;
michael@0 27 virtual void onCopyOnWrite(ContentChangeMode) SK_OVERRIDE;
michael@0 28
michael@0 29 private:
michael@0 30 SkPicture* fPicture;
michael@0 31
michael@0 32 typedef SkSurface_Base INHERITED;
michael@0 33 };
michael@0 34
michael@0 35 ///////////////////////////////////////////////////////////////////////////////
michael@0 36
michael@0 37 SkSurface_Picture::SkSurface_Picture(int width, int height) : INHERITED(width, height) {
michael@0 38 fPicture = NULL;
michael@0 39 }
michael@0 40
michael@0 41 SkSurface_Picture::~SkSurface_Picture() {
michael@0 42 SkSafeUnref(fPicture);
michael@0 43 }
michael@0 44
michael@0 45 SkCanvas* SkSurface_Picture::onNewCanvas() {
michael@0 46 if (!fPicture) {
michael@0 47 fPicture = SkNEW(SkPicture);
michael@0 48 }
michael@0 49 SkCanvas* canvas = fPicture->beginRecording(this->width(), this->height());
michael@0 50 canvas->ref(); // our caller will call unref()
michael@0 51 return canvas;
michael@0 52 }
michael@0 53
michael@0 54 SkSurface* SkSurface_Picture::onNewSurface(const SkImageInfo& info) {
michael@0 55 return SkSurface::NewPicture(info.fWidth, info.fHeight);
michael@0 56 }
michael@0 57
michael@0 58 SkImage* SkSurface_Picture::onNewImageSnapshot() {
michael@0 59 if (fPicture) {
michael@0 60 return SkNewImageFromPicture(fPicture);
michael@0 61 } else {
michael@0 62 SkImageInfo info;
michael@0 63 info.fWidth = info.fHeight = 0;
michael@0 64 info.fColorType = kPMColor_SkColorType;
michael@0 65 info.fAlphaType = kOpaque_SkAlphaType;
michael@0 66 return SkImage::NewRasterCopy(info, NULL, 0);
michael@0 67 }
michael@0 68 }
michael@0 69
michael@0 70 void SkSurface_Picture::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y,
michael@0 71 const SkPaint* paint) {
michael@0 72 if (!fPicture) {
michael@0 73 return;
michael@0 74 }
michael@0 75 SkImagePrivDrawPicture(canvas, fPicture, x, y, paint);
michael@0 76 }
michael@0 77
michael@0 78 void SkSurface_Picture::onCopyOnWrite(ContentChangeMode /*mode*/) {
michael@0 79 // We always spawn a copy of the recording picture when we
michael@0 80 // are asked for a snapshot, so we never need to do anything here.
michael@0 81 }
michael@0 82
michael@0 83 ///////////////////////////////////////////////////////////////////////////////
michael@0 84
michael@0 85
michael@0 86 SkSurface* SkSurface::NewPicture(int width, int height) {
michael@0 87 if ((width | height) < 0) {
michael@0 88 return NULL;
michael@0 89 }
michael@0 90
michael@0 91 return SkNEW_ARGS(SkSurface_Picture, (width, height));
michael@0 92 }

mercurial