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 SkDeferredCanvas_DEFINED |
michael@0 | 9 | #define SkDeferredCanvas_DEFINED |
michael@0 | 10 | |
michael@0 | 11 | #include "SkCanvas.h" |
michael@0 | 12 | #include "SkPixelRef.h" |
michael@0 | 13 | |
michael@0 | 14 | class SkDeferredDevice; |
michael@0 | 15 | class SkImage; |
michael@0 | 16 | class SkSurface; |
michael@0 | 17 | |
michael@0 | 18 | /** \class SkDeferredCanvas |
michael@0 | 19 | Subclass of SkCanvas that encapsulates an SkPicture or SkGPipe for deferred |
michael@0 | 20 | drawing. The main difference between this class and SkPictureRecord (the |
michael@0 | 21 | canvas provided by SkPicture) is that this is a full drop-in replacement |
michael@0 | 22 | for SkCanvas, while SkPictureRecord only supports draw operations. |
michael@0 | 23 | SkDeferredCanvas will transparently trigger the flushing of deferred |
michael@0 | 24 | draw operations when an attempt is made to access the pixel data. |
michael@0 | 25 | */ |
michael@0 | 26 | class SK_API SkDeferredCanvas : public SkCanvas { |
michael@0 | 27 | public: |
michael@0 | 28 | class SK_API NotificationClient; |
michael@0 | 29 | |
michael@0 | 30 | /** Construct a canvas with the specified surface to draw into. |
michael@0 | 31 | This factory must be used for newImageSnapshot to work. |
michael@0 | 32 | @param surface Specifies a surface for the canvas to draw into. |
michael@0 | 33 | */ |
michael@0 | 34 | static SkDeferredCanvas* Create(SkSurface* surface); |
michael@0 | 35 | |
michael@0 | 36 | // static SkDeferredCanvas* Create(SkBaseDevice* device); |
michael@0 | 37 | |
michael@0 | 38 | virtual ~SkDeferredCanvas(); |
michael@0 | 39 | |
michael@0 | 40 | /** |
michael@0 | 41 | * Specify the surface to be used by this canvas. Calling setSurface will |
michael@0 | 42 | * release the previously set surface or device. Takes a reference on the |
michael@0 | 43 | * surface. |
michael@0 | 44 | * |
michael@0 | 45 | * @param surface The surface that the canvas will raw into |
michael@0 | 46 | * @return The surface argument, for convenience. |
michael@0 | 47 | */ |
michael@0 | 48 | SkSurface* setSurface(SkSurface* surface); |
michael@0 | 49 | |
michael@0 | 50 | /** |
michael@0 | 51 | * Specify a NotificationClient to be used by this canvas. Calling |
michael@0 | 52 | * setNotificationClient will release the previously set |
michael@0 | 53 | * NotificationClient, if any. SkDeferredCanvas does not take ownership |
michael@0 | 54 | * of the notification client. Therefore user code is resposible |
michael@0 | 55 | * for its destruction. The notification client must be unregistered |
michael@0 | 56 | * by calling setNotificationClient(NULL) if it is destroyed before |
michael@0 | 57 | * this canvas. |
michael@0 | 58 | * Note: Must be called after the device is set with setDevice. |
michael@0 | 59 | * |
michael@0 | 60 | * @param notificationClient interface for dispatching notifications |
michael@0 | 61 | * @return The notificationClient argument, for convenience. |
michael@0 | 62 | */ |
michael@0 | 63 | NotificationClient* setNotificationClient(NotificationClient* notificationClient); |
michael@0 | 64 | |
michael@0 | 65 | /** |
michael@0 | 66 | * Enable or disable deferred drawing. When deferral is disabled, |
michael@0 | 67 | * pending draw operations are immediately flushed and from then on, |
michael@0 | 68 | * the SkDeferredCanvas behaves just like a regular SkCanvas. |
michael@0 | 69 | * This method must not be called while the save/restore stack is in use. |
michael@0 | 70 | * @param deferred true/false |
michael@0 | 71 | */ |
michael@0 | 72 | void setDeferredDrawing(bool deferred); |
michael@0 | 73 | |
michael@0 | 74 | /** |
michael@0 | 75 | * Returns true if deferred drawing is currenlty enabled. |
michael@0 | 76 | */ |
michael@0 | 77 | bool isDeferredDrawing() const; |
michael@0 | 78 | |
michael@0 | 79 | /** |
michael@0 | 80 | * Returns true if the canvas contains a fresh frame. A frame is |
michael@0 | 81 | * considered fresh when its content do not depend on the contents |
michael@0 | 82 | * of the previous frame. For example, if a canvas is cleared before |
michael@0 | 83 | * drawing each frame, the frames will all be considered fresh. |
michael@0 | 84 | * A frame is defined as the graphics image produced by as a result |
michael@0 | 85 | * of all the canvas draws operation executed between two successive |
michael@0 | 86 | * calls to isFreshFrame. The result of isFreshFrame is computed |
michael@0 | 87 | * conservatively, so it may report false negatives. |
michael@0 | 88 | */ |
michael@0 | 89 | bool isFreshFrame() const; |
michael@0 | 90 | |
michael@0 | 91 | /** |
michael@0 | 92 | * Returns true if the canvas has recorded draw commands that have |
michael@0 | 93 | * not yet been played back. |
michael@0 | 94 | */ |
michael@0 | 95 | bool hasPendingCommands() const; |
michael@0 | 96 | |
michael@0 | 97 | /** |
michael@0 | 98 | * Flushes pending draw commands, if any, and returns an image of the |
michael@0 | 99 | * current state of the surface pixels up to this point. Subsequent |
michael@0 | 100 | * changes to the surface (by drawing into its canvas) will not be |
michael@0 | 101 | * reflected in this image. Will return NULL if the deferred canvas |
michael@0 | 102 | * was not constructed from an SkSurface. |
michael@0 | 103 | */ |
michael@0 | 104 | SkImage* newImageSnapshot(); |
michael@0 | 105 | |
michael@0 | 106 | /** |
michael@0 | 107 | * Specify the maximum number of bytes to be allocated for the purpose |
michael@0 | 108 | * of recording draw commands to this canvas. The default limit, is |
michael@0 | 109 | * 64MB. |
michael@0 | 110 | * @param maxStorage The maximum number of bytes to be allocated. |
michael@0 | 111 | */ |
michael@0 | 112 | void setMaxRecordingStorage(size_t maxStorage); |
michael@0 | 113 | |
michael@0 | 114 | /** |
michael@0 | 115 | * Returns the number of bytes currently allocated for the purpose of |
michael@0 | 116 | * recording draw commands. |
michael@0 | 117 | */ |
michael@0 | 118 | size_t storageAllocatedForRecording() const; |
michael@0 | 119 | |
michael@0 | 120 | /** |
michael@0 | 121 | * Attempt to reduce the storage allocated for recording by evicting |
michael@0 | 122 | * cache resources. |
michael@0 | 123 | * @param bytesToFree minimum number of bytes that should be attempted to |
michael@0 | 124 | * be freed. |
michael@0 | 125 | * @return number of bytes actually freed. |
michael@0 | 126 | */ |
michael@0 | 127 | size_t freeMemoryIfPossible(size_t bytesToFree); |
michael@0 | 128 | |
michael@0 | 129 | /** |
michael@0 | 130 | * Specifies the maximum size (in bytes) allowed for a given image to be |
michael@0 | 131 | * rendered using the deferred canvas. |
michael@0 | 132 | */ |
michael@0 | 133 | void setBitmapSizeThreshold(size_t sizeThreshold); |
michael@0 | 134 | |
michael@0 | 135 | /** |
michael@0 | 136 | * Executes all pending commands without drawing |
michael@0 | 137 | */ |
michael@0 | 138 | void silentFlush(); |
michael@0 | 139 | |
michael@0 | 140 | // Overrides of the SkCanvas interface |
michael@0 | 141 | virtual bool isDrawingToLayer() const SK_OVERRIDE; |
michael@0 | 142 | virtual void clear(SkColor) SK_OVERRIDE; |
michael@0 | 143 | virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE; |
michael@0 | 144 | virtual void drawPoints(PointMode mode, size_t count, const SkPoint pts[], |
michael@0 | 145 | const SkPaint& paint) SK_OVERRIDE; |
michael@0 | 146 | virtual void drawOval(const SkRect&, const SkPaint& paint) SK_OVERRIDE; |
michael@0 | 147 | virtual void drawRect(const SkRect& rect, const SkPaint& paint) SK_OVERRIDE; |
michael@0 | 148 | virtual void drawRRect(const SkRRect&, const SkPaint& paint) SK_OVERRIDE; |
michael@0 | 149 | virtual void drawPath(const SkPath& path, const SkPaint& paint) |
michael@0 | 150 | SK_OVERRIDE; |
michael@0 | 151 | virtual void drawBitmap(const SkBitmap& bitmap, SkScalar left, |
michael@0 | 152 | SkScalar top, const SkPaint* paint) |
michael@0 | 153 | SK_OVERRIDE; |
michael@0 | 154 | virtual void drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src, |
michael@0 | 155 | const SkRect& dst, const SkPaint* paint, |
michael@0 | 156 | DrawBitmapRectFlags flags) SK_OVERRIDE; |
michael@0 | 157 | |
michael@0 | 158 | virtual void drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m, |
michael@0 | 159 | const SkPaint* paint) SK_OVERRIDE; |
michael@0 | 160 | virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, |
michael@0 | 161 | const SkRect& dst, const SkPaint* paint) |
michael@0 | 162 | SK_OVERRIDE; |
michael@0 | 163 | virtual void drawSprite(const SkBitmap& bitmap, int left, int top, |
michael@0 | 164 | const SkPaint* paint) SK_OVERRIDE; |
michael@0 | 165 | virtual void drawText(const void* text, size_t byteLength, SkScalar x, |
michael@0 | 166 | SkScalar y, const SkPaint& paint) SK_OVERRIDE; |
michael@0 | 167 | virtual void drawPosText(const void* text, size_t byteLength, |
michael@0 | 168 | const SkPoint pos[], const SkPaint& paint) |
michael@0 | 169 | SK_OVERRIDE; |
michael@0 | 170 | virtual void drawPosTextH(const void* text, size_t byteLength, |
michael@0 | 171 | const SkScalar xpos[], SkScalar constY, |
michael@0 | 172 | const SkPaint& paint) SK_OVERRIDE; |
michael@0 | 173 | virtual void drawTextOnPath(const void* text, size_t byteLength, |
michael@0 | 174 | const SkPath& path, const SkMatrix* matrix, |
michael@0 | 175 | const SkPaint& paint) SK_OVERRIDE; |
michael@0 | 176 | virtual void drawPicture(SkPicture& picture) SK_OVERRIDE; |
michael@0 | 177 | virtual void drawVertices(VertexMode vmode, int vertexCount, |
michael@0 | 178 | const SkPoint vertices[], const SkPoint texs[], |
michael@0 | 179 | const SkColor colors[], SkXfermode* xmode, |
michael@0 | 180 | const uint16_t indices[], int indexCount, |
michael@0 | 181 | const SkPaint& paint) SK_OVERRIDE; |
michael@0 | 182 | virtual SkBounder* setBounder(SkBounder* bounder) SK_OVERRIDE; |
michael@0 | 183 | virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter) SK_OVERRIDE; |
michael@0 | 184 | |
michael@0 | 185 | protected: |
michael@0 | 186 | virtual void willSave(SaveFlags) SK_OVERRIDE; |
michael@0 | 187 | virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE; |
michael@0 | 188 | virtual void willRestore() SK_OVERRIDE; |
michael@0 | 189 | |
michael@0 | 190 | virtual void didTranslate(SkScalar, SkScalar) SK_OVERRIDE; |
michael@0 | 191 | virtual void didScale(SkScalar, SkScalar) SK_OVERRIDE; |
michael@0 | 192 | virtual void didRotate(SkScalar) SK_OVERRIDE; |
michael@0 | 193 | virtual void didSkew(SkScalar, SkScalar) SK_OVERRIDE; |
michael@0 | 194 | virtual void didConcat(const SkMatrix&) SK_OVERRIDE; |
michael@0 | 195 | virtual void didSetMatrix(const SkMatrix&) SK_OVERRIDE; |
michael@0 | 196 | |
michael@0 | 197 | virtual void onDrawDRRect(const SkRRect&, const SkRRect&, |
michael@0 | 198 | const SkPaint&) SK_OVERRIDE; |
michael@0 | 199 | |
michael@0 | 200 | virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; |
michael@0 | 201 | virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; |
michael@0 | 202 | virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; |
michael@0 | 203 | virtual void onClipRegion(const SkRegion&, SkRegion::Op) SK_OVERRIDE; |
michael@0 | 204 | |
michael@0 | 205 | public: |
michael@0 | 206 | class NotificationClient { |
michael@0 | 207 | public: |
michael@0 | 208 | virtual ~NotificationClient() {} |
michael@0 | 209 | |
michael@0 | 210 | /** |
michael@0 | 211 | * Called before executing one or several draw commands, which means |
michael@0 | 212 | * once per flush when deferred rendering is enabled. |
michael@0 | 213 | */ |
michael@0 | 214 | virtual void prepareForDraw() {} |
michael@0 | 215 | |
michael@0 | 216 | /** |
michael@0 | 217 | * Called after a recording a draw command if additional memory |
michael@0 | 218 | * had to be allocated for recording. |
michael@0 | 219 | * @param newAllocatedStorage same value as would be returned by |
michael@0 | 220 | * storageAllocatedForRecording(), for convenience. |
michael@0 | 221 | */ |
michael@0 | 222 | virtual void storageAllocatedForRecordingChanged( |
michael@0 | 223 | size_t newAllocatedStorage) {} |
michael@0 | 224 | |
michael@0 | 225 | /** |
michael@0 | 226 | * Called after pending draw commands have been flushed |
michael@0 | 227 | */ |
michael@0 | 228 | virtual void flushedDrawCommands() {} |
michael@0 | 229 | |
michael@0 | 230 | /** |
michael@0 | 231 | * Called after pending draw commands have been skipped, meaning |
michael@0 | 232 | * that they were optimized-out because the canvas is cleared |
michael@0 | 233 | * or completely overwritten by the command currently being recorded. |
michael@0 | 234 | */ |
michael@0 | 235 | virtual void skippedPendingDrawCommands() {} |
michael@0 | 236 | }; |
michael@0 | 237 | |
michael@0 | 238 | protected: |
michael@0 | 239 | virtual SkCanvas* canvasForDrawIter(); |
michael@0 | 240 | SkDeferredDevice* getDeferredDevice() const; |
michael@0 | 241 | |
michael@0 | 242 | private: |
michael@0 | 243 | SkDeferredCanvas(SkDeferredDevice*); |
michael@0 | 244 | |
michael@0 | 245 | void recordedDrawCommand(); |
michael@0 | 246 | SkCanvas* drawingCanvas() const; |
michael@0 | 247 | SkCanvas* immediateCanvas() const; |
michael@0 | 248 | bool isFullFrame(const SkRect*, const SkPaint*) const; |
michael@0 | 249 | void validate() const; |
michael@0 | 250 | void init(); |
michael@0 | 251 | bool fDeferredDrawing; |
michael@0 | 252 | |
michael@0 | 253 | friend class SkDeferredCanvasTester; // for unit testing |
michael@0 | 254 | typedef SkCanvas INHERITED; |
michael@0 | 255 | }; |
michael@0 | 256 | |
michael@0 | 257 | |
michael@0 | 258 | #endif |