Sat, 03 Jan 2015 20:18:00 +0100
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 | #ifndef SkSurface_DEFINED |
michael@0 | 9 | #define SkSurface_DEFINED |
michael@0 | 10 | |
michael@0 | 11 | #include "SkRefCnt.h" |
michael@0 | 12 | #include "SkImage.h" |
michael@0 | 13 | |
michael@0 | 14 | class SkCanvas; |
michael@0 | 15 | class SkPaint; |
michael@0 | 16 | class GrContext; |
michael@0 | 17 | class GrRenderTarget; |
michael@0 | 18 | |
michael@0 | 19 | /** |
michael@0 | 20 | * SkSurface represents the backend/results of drawing to a canvas. For raster |
michael@0 | 21 | * drawing, the surface will be pixels, but (for example) when drawing into |
michael@0 | 22 | * a PDF or Picture canvas, the surface stores the recorded commands. |
michael@0 | 23 | * |
michael@0 | 24 | * To draw into a canvas, first create the appropriate type of Surface, and |
michael@0 | 25 | * then request the canvas from the surface. |
michael@0 | 26 | */ |
michael@0 | 27 | class SK_API SkSurface : public SkRefCnt { |
michael@0 | 28 | public: |
michael@0 | 29 | SK_DECLARE_INST_COUNT(SkSurface) |
michael@0 | 30 | |
michael@0 | 31 | /** |
michael@0 | 32 | * Create a new surface, using the specified pixels/rowbytes as its |
michael@0 | 33 | * backend. |
michael@0 | 34 | * |
michael@0 | 35 | * If the requested surface cannot be created, or the request is not a |
michael@0 | 36 | * supported configuration, NULL will be returned. |
michael@0 | 37 | */ |
michael@0 | 38 | static SkSurface* NewRasterDirect(const SkImageInfo&, void* pixels, size_t rowBytes); |
michael@0 | 39 | |
michael@0 | 40 | /** |
michael@0 | 41 | * Return a new surface, with the memory for the pixels automatically |
michael@0 | 42 | * allocated. |
michael@0 | 43 | * |
michael@0 | 44 | * If the requested surface cannot be created, or the request is not a |
michael@0 | 45 | * supported configuration, NULL will be returned. |
michael@0 | 46 | */ |
michael@0 | 47 | static SkSurface* NewRaster(const SkImageInfo&); |
michael@0 | 48 | |
michael@0 | 49 | /** |
michael@0 | 50 | * Helper version of NewRaster. It creates a SkImageInfo with the |
michael@0 | 51 | * specified width and height, and populates the rest of info to match |
michael@0 | 52 | * pixels in SkPMColor format. |
michael@0 | 53 | */ |
michael@0 | 54 | static SkSurface* NewRasterPMColor(int width, int height) { |
michael@0 | 55 | return NewRaster(SkImageInfo::MakeN32Premul(width, height)); |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | /** |
michael@0 | 59 | * Return a new surface whose contents will be recorded into a picture. |
michael@0 | 60 | * When this surface is drawn into another canvas, its contents will be |
michael@0 | 61 | * "replayed" into that canvas. |
michael@0 | 62 | */ |
michael@0 | 63 | static SkSurface* NewPicture(int width, int height); |
michael@0 | 64 | |
michael@0 | 65 | /** |
michael@0 | 66 | * Return a new surface using the specified render target. |
michael@0 | 67 | */ |
michael@0 | 68 | static SkSurface* NewRenderTargetDirect(GrRenderTarget*); |
michael@0 | 69 | |
michael@0 | 70 | /** |
michael@0 | 71 | * Return a new surface whose contents will be drawn to an offscreen |
michael@0 | 72 | * render target, allocated by the surface. |
michael@0 | 73 | */ |
michael@0 | 74 | static SkSurface* NewRenderTarget(GrContext*, const SkImageInfo&, int sampleCount = 0); |
michael@0 | 75 | |
michael@0 | 76 | int width() const { return fWidth; } |
michael@0 | 77 | int height() const { return fHeight; } |
michael@0 | 78 | |
michael@0 | 79 | /** |
michael@0 | 80 | * Returns a unique non-zero, unique value identifying the content of this |
michael@0 | 81 | * surface. Each time the content is changed changed, either by drawing |
michael@0 | 82 | * into this surface, or explicitly calling notifyContentChanged()) this |
michael@0 | 83 | * method will return a new value. |
michael@0 | 84 | * |
michael@0 | 85 | * If this surface is empty (i.e. has a zero-dimention), this will return |
michael@0 | 86 | * 0. |
michael@0 | 87 | */ |
michael@0 | 88 | uint32_t generationID(); |
michael@0 | 89 | |
michael@0 | 90 | /** |
michael@0 | 91 | * Modes that can be passed to notifyContentWillChange |
michael@0 | 92 | */ |
michael@0 | 93 | enum ContentChangeMode { |
michael@0 | 94 | /** |
michael@0 | 95 | * Use this mode if it is known that the upcoming content changes will |
michael@0 | 96 | * clear or overwrite prior contents, thus making them discardable. |
michael@0 | 97 | */ |
michael@0 | 98 | kDiscard_ContentChangeMode, |
michael@0 | 99 | /** |
michael@0 | 100 | * Use this mode if prior surface contents need to be preserved or |
michael@0 | 101 | * if in doubt. |
michael@0 | 102 | */ |
michael@0 | 103 | kRetain_ContentChangeMode, |
michael@0 | 104 | }; |
michael@0 | 105 | |
michael@0 | 106 | /** |
michael@0 | 107 | * Call this if the contents are about to change. This will (lazily) force a new |
michael@0 | 108 | * value to be returned from generationID() when it is called next. |
michael@0 | 109 | */ |
michael@0 | 110 | void notifyContentWillChange(ContentChangeMode mode); |
michael@0 | 111 | |
michael@0 | 112 | /** |
michael@0 | 113 | * Return a canvas that will draw into this surface. This will always |
michael@0 | 114 | * return the same canvas for a given surface, and is manged/owned by the |
michael@0 | 115 | * surface. It should not be used when its parent surface has gone out of |
michael@0 | 116 | * scope. |
michael@0 | 117 | */ |
michael@0 | 118 | SkCanvas* getCanvas(); |
michael@0 | 119 | |
michael@0 | 120 | /** |
michael@0 | 121 | * Return a new surface that is "compatible" with this one, in that it will |
michael@0 | 122 | * efficiently be able to be drawn into this surface. Typical calling |
michael@0 | 123 | * pattern: |
michael@0 | 124 | * |
michael@0 | 125 | * SkSurface* A = SkSurface::New...(); |
michael@0 | 126 | * SkCanvas* canvasA = surfaceA->newCanvas(); |
michael@0 | 127 | * ... |
michael@0 | 128 | * SkSurface* surfaceB = surfaceA->newSurface(...); |
michael@0 | 129 | * SkCanvas* canvasB = surfaceB->newCanvas(); |
michael@0 | 130 | * ... // draw using canvasB |
michael@0 | 131 | * canvasA->drawSurface(surfaceB); // <--- this will always be optimal! |
michael@0 | 132 | */ |
michael@0 | 133 | SkSurface* newSurface(const SkImageInfo&); |
michael@0 | 134 | |
michael@0 | 135 | /** |
michael@0 | 136 | * Returns an image of the current state of the surface pixels up to this |
michael@0 | 137 | * point. Subsequent changes to the surface (by drawing into its canvas) |
michael@0 | 138 | * will not be reflected in this image. |
michael@0 | 139 | */ |
michael@0 | 140 | SkImage* newImageSnapshot(); |
michael@0 | 141 | |
michael@0 | 142 | /** |
michael@0 | 143 | * Thought the caller could get a snapshot image explicitly, and draw that, |
michael@0 | 144 | * it seems that directly drawing a surface into another canvas might be |
michael@0 | 145 | * a common pattern, and that we could possibly be more efficient, since |
michael@0 | 146 | * we'd know that the "snapshot" need only live until we've handed it off |
michael@0 | 147 | * to the canvas. |
michael@0 | 148 | */ |
michael@0 | 149 | void draw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*); |
michael@0 | 150 | |
michael@0 | 151 | /** |
michael@0 | 152 | * If the surface has direct access to its pixels (i.e. they are in local |
michael@0 | 153 | * RAM) return the const-address of those pixels, and if not null, return |
michael@0 | 154 | * the ImageInfo and rowBytes. The returned address is only valid while |
michael@0 | 155 | * the surface object is in scope, and no API call is made on the surface |
michael@0 | 156 | * or its canvas. |
michael@0 | 157 | * |
michael@0 | 158 | * On failure, returns NULL and the info and rowBytes parameters are |
michael@0 | 159 | * ignored. |
michael@0 | 160 | */ |
michael@0 | 161 | const void* peekPixels(SkImageInfo* info, size_t* rowBytes); |
michael@0 | 162 | |
michael@0 | 163 | protected: |
michael@0 | 164 | SkSurface(int width, int height); |
michael@0 | 165 | SkSurface(const SkImageInfo&); |
michael@0 | 166 | |
michael@0 | 167 | // called by subclass if their contents have changed |
michael@0 | 168 | void dirtyGenerationID() { |
michael@0 | 169 | fGenerationID = 0; |
michael@0 | 170 | } |
michael@0 | 171 | |
michael@0 | 172 | private: |
michael@0 | 173 | const int fWidth; |
michael@0 | 174 | const int fHeight; |
michael@0 | 175 | uint32_t fGenerationID; |
michael@0 | 176 | |
michael@0 | 177 | typedef SkRefCnt INHERITED; |
michael@0 | 178 | }; |
michael@0 | 179 | |
michael@0 | 180 | #endif |