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 | /* |
michael@0 | 3 | * Copyright 2013 Google Inc. |
michael@0 | 4 | * |
michael@0 | 5 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 6 | * found in the LICENSE file. |
michael@0 | 7 | */ |
michael@0 | 8 | |
michael@0 | 9 | #ifndef SkBitmapDevice_DEFINED |
michael@0 | 10 | #define SkBitmapDevice_DEFINED |
michael@0 | 11 | |
michael@0 | 12 | #include "SkDevice.h" |
michael@0 | 13 | |
michael@0 | 14 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 15 | class SK_API SkBitmapDevice : public SkBaseDevice { |
michael@0 | 16 | public: |
michael@0 | 17 | SK_DECLARE_INST_COUNT(SkBitmapDevice) |
michael@0 | 18 | |
michael@0 | 19 | /** |
michael@0 | 20 | * Construct a new device with the specified bitmap as its backend. It is |
michael@0 | 21 | * valid for the bitmap to have no pixels associated with it. In that case, |
michael@0 | 22 | * any drawing to this device will have no effect. |
michael@0 | 23 | */ |
michael@0 | 24 | SkBitmapDevice(const SkBitmap& bitmap); |
michael@0 | 25 | |
michael@0 | 26 | /** |
michael@0 | 27 | * Construct a new device with the specified bitmap as its backend. It is |
michael@0 | 28 | * valid for the bitmap to have no pixels associated with it. In that case, |
michael@0 | 29 | * any drawing to this device will have no effect. |
michael@0 | 30 | */ |
michael@0 | 31 | SkBitmapDevice(const SkBitmap& bitmap, const SkDeviceProperties& deviceProperties); |
michael@0 | 32 | |
michael@0 | 33 | #ifdef SK_SUPPORT_LEGACY_COMPATIBLEDEVICE_CONFIG |
michael@0 | 34 | /** |
michael@0 | 35 | * Create a new raster device and have the pixels be automatically |
michael@0 | 36 | * allocated. The rowBytes of the device will be computed automatically |
michael@0 | 37 | * based on the config and the width. |
michael@0 | 38 | * |
michael@0 | 39 | * @param config The desired config for the pixels. If the request cannot |
michael@0 | 40 | * be met, the closest matching support config will be used. |
michael@0 | 41 | * @param width width (in pixels) of the device |
michael@0 | 42 | * @param height height (in pixels) of the device |
michael@0 | 43 | * @param isOpaque Set to true if it is known that all of the pixels will |
michael@0 | 44 | * be drawn to opaquely. Used as an accelerator when drawing |
michael@0 | 45 | * these pixels to another device. |
michael@0 | 46 | */ |
michael@0 | 47 | SkBitmapDevice(SkBitmap::Config config, int width, int height, bool isOpaque = false); |
michael@0 | 48 | |
michael@0 | 49 | /** |
michael@0 | 50 | * Create a new raster device and have the pixels be automatically |
michael@0 | 51 | * allocated. The rowBytes of the device will be computed automatically |
michael@0 | 52 | * based on the config and the width. |
michael@0 | 53 | * |
michael@0 | 54 | * @param config The desired config for the pixels. If the request cannot |
michael@0 | 55 | * be met, the closest matching support config will be used. |
michael@0 | 56 | * @param width width (in pixels) of the device |
michael@0 | 57 | * @param height height (in pixels) of the device |
michael@0 | 58 | * @param isOpaque Set to true if it is known that all of the pixels will |
michael@0 | 59 | * be drawn to opaquely. Used as an accelerator when drawing |
michael@0 | 60 | * these pixels to another device. |
michael@0 | 61 | * @param deviceProperties Properties which affect compositing. |
michael@0 | 62 | */ |
michael@0 | 63 | SkBitmapDevice(SkBitmap::Config config, int width, int height, bool isOpaque, |
michael@0 | 64 | const SkDeviceProperties& deviceProperties); |
michael@0 | 65 | #endif |
michael@0 | 66 | static SkBitmapDevice* Create(const SkImageInfo&, |
michael@0 | 67 | const SkDeviceProperties* = NULL); |
michael@0 | 68 | |
michael@0 | 69 | /** Return the width of the device (in pixels). |
michael@0 | 70 | */ |
michael@0 | 71 | virtual int width() const SK_OVERRIDE { return fBitmap.width(); } |
michael@0 | 72 | /** Return the height of the device (in pixels). |
michael@0 | 73 | */ |
michael@0 | 74 | virtual int height() const SK_OVERRIDE { return fBitmap.height(); } |
michael@0 | 75 | |
michael@0 | 76 | /** Returns true if the device's bitmap's config treats every pixels as |
michael@0 | 77 | implicitly opaque. |
michael@0 | 78 | */ |
michael@0 | 79 | virtual bool isOpaque() const SK_OVERRIDE { return fBitmap.isOpaque(); } |
michael@0 | 80 | |
michael@0 | 81 | /** Return the bitmap config of the device's pixels |
michael@0 | 82 | */ |
michael@0 | 83 | virtual SkBitmap::Config config() const SK_OVERRIDE { return fBitmap.config(); } |
michael@0 | 84 | |
michael@0 | 85 | virtual SkImageInfo imageInfo() const SK_OVERRIDE; |
michael@0 | 86 | |
michael@0 | 87 | #ifdef SK_SUPPORT_LEGACY_WRITEPIXELSCONFIG |
michael@0 | 88 | /** |
michael@0 | 89 | * DEPRECATED: This will be made protected once WebKit stops using it. |
michael@0 | 90 | * Instead use Canvas' writePixels method. |
michael@0 | 91 | * |
michael@0 | 92 | * Similar to draw sprite, this method will copy the pixels in bitmap onto |
michael@0 | 93 | * the device, with the top/left corner specified by (x, y). The pixel |
michael@0 | 94 | * values in the device are completely replaced: there is no blending. |
michael@0 | 95 | * |
michael@0 | 96 | * Currently if bitmap is backed by a texture this is a no-op. This may be |
michael@0 | 97 | * relaxed in the future. |
michael@0 | 98 | * |
michael@0 | 99 | * If the bitmap has config kARGB_8888_Config then the config8888 param |
michael@0 | 100 | * will determines how the pixel valuess are intepreted. If the bitmap is |
michael@0 | 101 | * not kARGB_8888_Config then this parameter is ignored. |
michael@0 | 102 | */ |
michael@0 | 103 | virtual void writePixels(const SkBitmap& bitmap, int x, int y, |
michael@0 | 104 | SkCanvas::Config8888 config8888) SK_OVERRIDE; |
michael@0 | 105 | #endif |
michael@0 | 106 | /** |
michael@0 | 107 | * Return the device's associated gpu render target, or NULL. |
michael@0 | 108 | */ |
michael@0 | 109 | virtual GrRenderTarget* accessRenderTarget() SK_OVERRIDE { return NULL; } |
michael@0 | 110 | |
michael@0 | 111 | protected: |
michael@0 | 112 | /** |
michael@0 | 113 | * Device may filter the text flags for drawing text here. If it wants to |
michael@0 | 114 | * make a change to the specified values, it should write them into the |
michael@0 | 115 | * textflags parameter (output) and return true. If the paint is fine as |
michael@0 | 116 | * is, then ignore the textflags parameter and return false. |
michael@0 | 117 | * |
michael@0 | 118 | * The baseclass SkDevice filters based on its depth and blitters. |
michael@0 | 119 | */ |
michael@0 | 120 | virtual bool filterTextFlags(const SkPaint& paint, TextFlags*) SK_OVERRIDE; |
michael@0 | 121 | |
michael@0 | 122 | /** Clears the entire device to the specified color (including alpha). |
michael@0 | 123 | * Ignores the clip. |
michael@0 | 124 | */ |
michael@0 | 125 | virtual void clear(SkColor color) SK_OVERRIDE; |
michael@0 | 126 | |
michael@0 | 127 | /** These are called inside the per-device-layer loop for each draw call. |
michael@0 | 128 | When these are called, we have already applied any saveLayer operations, |
michael@0 | 129 | and are handling any looping from the paint, and any effects from the |
michael@0 | 130 | DrawFilter. |
michael@0 | 131 | */ |
michael@0 | 132 | virtual void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE; |
michael@0 | 133 | virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t count, |
michael@0 | 134 | const SkPoint[], const SkPaint& paint) SK_OVERRIDE; |
michael@0 | 135 | virtual void drawRect(const SkDraw&, const SkRect& r, |
michael@0 | 136 | const SkPaint& paint) SK_OVERRIDE; |
michael@0 | 137 | virtual void drawOval(const SkDraw&, const SkRect& oval, |
michael@0 | 138 | const SkPaint& paint) SK_OVERRIDE; |
michael@0 | 139 | virtual void drawRRect(const SkDraw&, const SkRRect& rr, |
michael@0 | 140 | const SkPaint& paint) SK_OVERRIDE; |
michael@0 | 141 | |
michael@0 | 142 | /** |
michael@0 | 143 | * If pathIsMutable, then the implementation is allowed to cast path to a |
michael@0 | 144 | * non-const pointer and modify it in place (as an optimization). Canvas |
michael@0 | 145 | * may do this to implement helpers such as drawOval, by placing a temp |
michael@0 | 146 | * path on the stack to hold the representation of the oval. |
michael@0 | 147 | * |
michael@0 | 148 | * If prePathMatrix is not null, it should logically be applied before any |
michael@0 | 149 | * stroking or other effects. If there are no effects on the paint that |
michael@0 | 150 | * affect the geometry/rasterization, then the pre matrix can just be |
michael@0 | 151 | * pre-concated with the current matrix. |
michael@0 | 152 | */ |
michael@0 | 153 | virtual void drawPath(const SkDraw&, const SkPath& path, |
michael@0 | 154 | const SkPaint& paint, |
michael@0 | 155 | const SkMatrix* prePathMatrix = NULL, |
michael@0 | 156 | bool pathIsMutable = false) SK_OVERRIDE; |
michael@0 | 157 | virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap, |
michael@0 | 158 | const SkMatrix& matrix, const SkPaint& paint) SK_OVERRIDE; |
michael@0 | 159 | virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap, |
michael@0 | 160 | int x, int y, const SkPaint& paint) SK_OVERRIDE; |
michael@0 | 161 | |
michael@0 | 162 | /** |
michael@0 | 163 | * The default impl. will create a bitmap-shader from the bitmap, |
michael@0 | 164 | * and call drawRect with it. |
michael@0 | 165 | */ |
michael@0 | 166 | virtual void drawBitmapRect(const SkDraw&, const SkBitmap&, |
michael@0 | 167 | const SkRect* srcOrNull, const SkRect& dst, |
michael@0 | 168 | const SkPaint& paint, |
michael@0 | 169 | SkCanvas::DrawBitmapRectFlags flags) SK_OVERRIDE; |
michael@0 | 170 | |
michael@0 | 171 | /** |
michael@0 | 172 | * Does not handle text decoration. |
michael@0 | 173 | * Decorations (underline and stike-thru) will be handled by SkCanvas. |
michael@0 | 174 | */ |
michael@0 | 175 | virtual void drawText(const SkDraw&, const void* text, size_t len, |
michael@0 | 176 | SkScalar x, SkScalar y, const SkPaint& paint) SK_OVERRIDE; |
michael@0 | 177 | virtual void drawPosText(const SkDraw&, const void* text, size_t len, |
michael@0 | 178 | const SkScalar pos[], SkScalar constY, |
michael@0 | 179 | int scalarsPerPos, const SkPaint& paint) SK_OVERRIDE; |
michael@0 | 180 | virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len, |
michael@0 | 181 | const SkPath& path, const SkMatrix* matrix, |
michael@0 | 182 | const SkPaint& paint) SK_OVERRIDE; |
michael@0 | 183 | virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, int vertexCount, |
michael@0 | 184 | const SkPoint verts[], const SkPoint texs[], |
michael@0 | 185 | const SkColor colors[], SkXfermode* xmode, |
michael@0 | 186 | const uint16_t indices[], int indexCount, |
michael@0 | 187 | const SkPaint& paint) SK_OVERRIDE; |
michael@0 | 188 | /** The SkBaseDevice passed will be an SkBaseDevice which was returned by a call to |
michael@0 | 189 | onCreateDevice on this device with kSaveLayer_Usage. |
michael@0 | 190 | */ |
michael@0 | 191 | virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y, |
michael@0 | 192 | const SkPaint&) SK_OVERRIDE; |
michael@0 | 193 | |
michael@0 | 194 | /////////////////////////////////////////////////////////////////////////// |
michael@0 | 195 | |
michael@0 | 196 | /** Update as needed the pixel value in the bitmap, so that the caller can |
michael@0 | 197 | access the pixels directly. Note: only the pixels field should be |
michael@0 | 198 | altered. The config/width/height/rowbytes must remain unchanged. |
michael@0 | 199 | @return the device contents as a bitmap |
michael@0 | 200 | */ |
michael@0 | 201 | virtual const SkBitmap& onAccessBitmap() SK_OVERRIDE; |
michael@0 | 202 | |
michael@0 | 203 | SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); } |
michael@0 | 204 | // just for subclasses, to assign a custom pixelref |
michael@0 | 205 | SkPixelRef* setPixelRef(SkPixelRef* pr) { |
michael@0 | 206 | fBitmap.setPixelRef(pr); |
michael@0 | 207 | return pr; |
michael@0 | 208 | } |
michael@0 | 209 | |
michael@0 | 210 | /** |
michael@0 | 211 | * Implements readPixels API. The caller will ensure that: |
michael@0 | 212 | * 1. bitmap has pixel config kARGB_8888_Config. |
michael@0 | 213 | * 2. bitmap has pixels. |
michael@0 | 214 | * 3. The rectangle (x, y, x + bitmap->width(), y + bitmap->height()) is |
michael@0 | 215 | * contained in the device bounds. |
michael@0 | 216 | */ |
michael@0 | 217 | virtual bool onReadPixels(const SkBitmap&, int x, int y, SkCanvas::Config8888) SK_OVERRIDE; |
michael@0 | 218 | virtual bool onWritePixels(const SkImageInfo&, const void*, size_t, int, int) SK_OVERRIDE; |
michael@0 | 219 | virtual void* onAccessPixels(SkImageInfo* info, size_t* rowBytes) SK_OVERRIDE; |
michael@0 | 220 | |
michael@0 | 221 | /** Called when this device is installed into a Canvas. Balanced by a call |
michael@0 | 222 | to unlockPixels() when the device is removed from a Canvas. |
michael@0 | 223 | */ |
michael@0 | 224 | virtual void lockPixels() SK_OVERRIDE; |
michael@0 | 225 | virtual void unlockPixels() SK_OVERRIDE; |
michael@0 | 226 | |
michael@0 | 227 | /** |
michael@0 | 228 | * Returns true if the device allows processing of this imagefilter. If |
michael@0 | 229 | * false is returned, then the filter is ignored. This may happen for |
michael@0 | 230 | * some subclasses that do not support pixel manipulations after drawing |
michael@0 | 231 | * has occurred (e.g. printing). The default implementation returns true. |
michael@0 | 232 | */ |
michael@0 | 233 | virtual bool allowImageFilter(const SkImageFilter*) SK_OVERRIDE; |
michael@0 | 234 | |
michael@0 | 235 | /** |
michael@0 | 236 | * Override and return true for filters that the device can handle |
michael@0 | 237 | * intrinsically. Doing so means that SkCanvas will pass-through this |
michael@0 | 238 | * filter to drawSprite and drawDevice (and potentially filterImage). |
michael@0 | 239 | * Returning false means the SkCanvas will have apply the filter itself, |
michael@0 | 240 | * and just pass the resulting image to the device. |
michael@0 | 241 | */ |
michael@0 | 242 | virtual bool canHandleImageFilter(const SkImageFilter*) SK_OVERRIDE; |
michael@0 | 243 | |
michael@0 | 244 | /** |
michael@0 | 245 | * Related (but not required) to canHandleImageFilter, this method returns |
michael@0 | 246 | * true if the device could apply the filter to the src bitmap and return |
michael@0 | 247 | * the result (and updates offset as needed). |
michael@0 | 248 | * If the device does not recognize or support this filter, |
michael@0 | 249 | * it just returns false and leaves result and offset unchanged. |
michael@0 | 250 | */ |
michael@0 | 251 | virtual bool filterImage(const SkImageFilter*, const SkBitmap&, const SkImageFilter::Context&, |
michael@0 | 252 | SkBitmap* result, SkIPoint* offset) SK_OVERRIDE; |
michael@0 | 253 | |
michael@0 | 254 | private: |
michael@0 | 255 | friend class SkCanvas; |
michael@0 | 256 | friend struct DeviceCM; //for setMatrixClip |
michael@0 | 257 | friend class SkDraw; |
michael@0 | 258 | friend class SkDrawIter; |
michael@0 | 259 | friend class SkDeviceFilteredPaint; |
michael@0 | 260 | friend class SkDeviceImageFilterProxy; |
michael@0 | 261 | |
michael@0 | 262 | friend class SkSurface_Raster; |
michael@0 | 263 | |
michael@0 | 264 | // used to change the backend's pixels (and possibly config/rowbytes) |
michael@0 | 265 | // but cannot change the width/height, so there should be no change to |
michael@0 | 266 | // any clip information. |
michael@0 | 267 | virtual void replaceBitmapBackendForRasterSurface(const SkBitmap&) SK_OVERRIDE; |
michael@0 | 268 | |
michael@0 | 269 | #ifdef SK_SUPPORT_LEGACY_COMPATIBLEDEVICE_CONFIG |
michael@0 | 270 | // in support of legacy constructors |
michael@0 | 271 | void init(SkBitmap::Config config, int width, int height, bool isOpaque); |
michael@0 | 272 | #endif |
michael@0 | 273 | |
michael@0 | 274 | virtual SkBaseDevice* onCreateDevice(const SkImageInfo&, Usage) SK_OVERRIDE; |
michael@0 | 275 | |
michael@0 | 276 | /** Causes any deferred drawing to the device to be completed. |
michael@0 | 277 | */ |
michael@0 | 278 | virtual void flush() SK_OVERRIDE {} |
michael@0 | 279 | |
michael@0 | 280 | virtual SkSurface* newSurface(const SkImageInfo&) SK_OVERRIDE; |
michael@0 | 281 | virtual const void* peekPixels(SkImageInfo*, size_t* rowBytes) SK_OVERRIDE; |
michael@0 | 282 | |
michael@0 | 283 | SkBitmap fBitmap; |
michael@0 | 284 | |
michael@0 | 285 | typedef SkBaseDevice INHERITED; |
michael@0 | 286 | }; |
michael@0 | 287 | |
michael@0 | 288 | #endif // SkBitmapDevice_DEFINED |