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 2010 The Android Open Source Project |
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 | |
michael@0 | 10 | #ifndef SkDevice_DEFINED |
michael@0 | 11 | #define SkDevice_DEFINED |
michael@0 | 12 | |
michael@0 | 13 | #include "SkRefCnt.h" |
michael@0 | 14 | #include "SkBitmap.h" |
michael@0 | 15 | #include "SkCanvas.h" |
michael@0 | 16 | #include "SkColor.h" |
michael@0 | 17 | #include "SkDeviceProperties.h" |
michael@0 | 18 | #include "SkImageFilter.h" |
michael@0 | 19 | |
michael@0 | 20 | // getDeviceCapabilities() is not called by skia, but this flag keeps it around |
michael@0 | 21 | // for clients that have "override" annotations on their subclass. These overrides |
michael@0 | 22 | // should be deleted. |
michael@0 | 23 | //#define SK_SUPPORT_LEGACY_GETDEVICECAPABILITIES |
michael@0 | 24 | |
michael@0 | 25 | //#define SK_SUPPORT_LEGACY_COMPATIBLEDEVICE_CONFIG |
michael@0 | 26 | |
michael@0 | 27 | class SkClipStack; |
michael@0 | 28 | class SkDraw; |
michael@0 | 29 | struct SkIRect; |
michael@0 | 30 | class SkMatrix; |
michael@0 | 31 | class SkMetaData; |
michael@0 | 32 | class SkRegion; |
michael@0 | 33 | |
michael@0 | 34 | class GrRenderTarget; |
michael@0 | 35 | |
michael@0 | 36 | class SK_API SkBaseDevice : public SkRefCnt { |
michael@0 | 37 | public: |
michael@0 | 38 | SK_DECLARE_INST_COUNT(SkBaseDevice) |
michael@0 | 39 | |
michael@0 | 40 | /** |
michael@0 | 41 | * Construct a new device. |
michael@0 | 42 | */ |
michael@0 | 43 | SkBaseDevice(); |
michael@0 | 44 | |
michael@0 | 45 | /** |
michael@0 | 46 | * Construct a new device. |
michael@0 | 47 | */ |
michael@0 | 48 | SkBaseDevice(const SkDeviceProperties& deviceProperties); |
michael@0 | 49 | |
michael@0 | 50 | virtual ~SkBaseDevice(); |
michael@0 | 51 | |
michael@0 | 52 | #ifdef SK_SUPPORT_LEGACY_COMPATIBLEDEVICE_CONFIG |
michael@0 | 53 | /** |
michael@0 | 54 | * Creates a device that is of the same type as this device (e.g. SW-raster, |
michael@0 | 55 | * GPU, or PDF). The backing store for this device is created automatically |
michael@0 | 56 | * (e.g. offscreen pixels or FBO or whatever is appropriate). |
michael@0 | 57 | * |
michael@0 | 58 | * @param width width of the device to create |
michael@0 | 59 | * @param height height of the device to create |
michael@0 | 60 | * @param isOpaque performance hint, set to true if you know that you will |
michael@0 | 61 | * draw into this device such that all of the pixels will |
michael@0 | 62 | * be opaque. |
michael@0 | 63 | */ |
michael@0 | 64 | SkBaseDevice* createCompatibleDevice(SkBitmap::Config config, |
michael@0 | 65 | int width, int height, |
michael@0 | 66 | bool isOpaque); |
michael@0 | 67 | #endif |
michael@0 | 68 | SkBaseDevice* createCompatibleDevice(const SkImageInfo&); |
michael@0 | 69 | |
michael@0 | 70 | SkMetaData& getMetaData(); |
michael@0 | 71 | |
michael@0 | 72 | #ifdef SK_SUPPORT_LEGACY_GETDEVICECAPABILITIES |
michael@0 | 73 | enum Capabilities { |
michael@0 | 74 | kVector_Capability = 0x1, |
michael@0 | 75 | }; |
michael@0 | 76 | virtual uint32_t getDeviceCapabilities() { return 0; } |
michael@0 | 77 | #endif |
michael@0 | 78 | |
michael@0 | 79 | /** Return the width of the device (in pixels). |
michael@0 | 80 | */ |
michael@0 | 81 | virtual int width() const = 0; |
michael@0 | 82 | /** Return the height of the device (in pixels). |
michael@0 | 83 | */ |
michael@0 | 84 | virtual int height() const = 0; |
michael@0 | 85 | |
michael@0 | 86 | /** Return the image properties of the device. */ |
michael@0 | 87 | virtual const SkDeviceProperties& getDeviceProperties() const { |
michael@0 | 88 | //Currently, all the properties are leaky. |
michael@0 | 89 | return fLeakyProperties; |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | /** |
michael@0 | 93 | * Return ImageInfo for this device. If the canvas is not backed by pixels |
michael@0 | 94 | * (cpu or gpu), then the info's ColorType will be kUnknown_SkColorType. |
michael@0 | 95 | */ |
michael@0 | 96 | virtual SkImageInfo imageInfo() const; |
michael@0 | 97 | |
michael@0 | 98 | /** |
michael@0 | 99 | * Return the bounds of the device in the coordinate space of the root |
michael@0 | 100 | * canvas. The root device will have its top-left at 0,0, but other devices |
michael@0 | 101 | * such as those associated with saveLayer may have a non-zero origin. |
michael@0 | 102 | */ |
michael@0 | 103 | void getGlobalBounds(SkIRect* bounds) const { |
michael@0 | 104 | SkASSERT(bounds); |
michael@0 | 105 | const SkIPoint& origin = this->getOrigin(); |
michael@0 | 106 | bounds->setXYWH(origin.x(), origin.y(), this->width(), this->height()); |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | |
michael@0 | 110 | /** Returns true if the device's bitmap's config treats every pixel as |
michael@0 | 111 | implicitly opaque. |
michael@0 | 112 | */ |
michael@0 | 113 | virtual bool isOpaque() const = 0; |
michael@0 | 114 | |
michael@0 | 115 | /** Return the bitmap config of the device's pixels |
michael@0 | 116 | */ |
michael@0 | 117 | virtual SkBitmap::Config config() const = 0; |
michael@0 | 118 | |
michael@0 | 119 | /** Return the bitmap associated with this device. Call this each time you need |
michael@0 | 120 | to access the bitmap, as it notifies the subclass to perform any flushing |
michael@0 | 121 | etc. before you examine the pixels. |
michael@0 | 122 | @param changePixels set to true if the caller plans to change the pixels |
michael@0 | 123 | @return the device's bitmap |
michael@0 | 124 | */ |
michael@0 | 125 | const SkBitmap& accessBitmap(bool changePixels); |
michael@0 | 126 | |
michael@0 | 127 | #ifdef SK_SUPPORT_LEGACY_WRITEPIXELSCONFIG |
michael@0 | 128 | /** |
michael@0 | 129 | * DEPRECATED: This will be made protected once WebKit stops using it. |
michael@0 | 130 | * Instead use Canvas' writePixels method. |
michael@0 | 131 | * |
michael@0 | 132 | * Similar to draw sprite, this method will copy the pixels in bitmap onto |
michael@0 | 133 | * the device, with the top/left corner specified by (x, y). The pixel |
michael@0 | 134 | * values in the device are completely replaced: there is no blending. |
michael@0 | 135 | * |
michael@0 | 136 | * Currently if bitmap is backed by a texture this is a no-op. This may be |
michael@0 | 137 | * relaxed in the future. |
michael@0 | 138 | * |
michael@0 | 139 | * If the bitmap has config kARGB_8888_Config then the config8888 param |
michael@0 | 140 | * will determines how the pixel valuess are intepreted. If the bitmap is |
michael@0 | 141 | * not kARGB_8888_Config then this parameter is ignored. |
michael@0 | 142 | */ |
michael@0 | 143 | virtual void writePixels(const SkBitmap& bitmap, int x, int y, |
michael@0 | 144 | SkCanvas::Config8888 config8888 = SkCanvas::kNative_Premul_Config8888); |
michael@0 | 145 | #endif |
michael@0 | 146 | |
michael@0 | 147 | bool writePixelsDirect(const SkImageInfo&, const void*, size_t rowBytes, int x, int y); |
michael@0 | 148 | |
michael@0 | 149 | void* accessPixels(SkImageInfo* info, size_t* rowBytes); |
michael@0 | 150 | |
michael@0 | 151 | /** |
michael@0 | 152 | * Return the device's associated gpu render target, or NULL. |
michael@0 | 153 | */ |
michael@0 | 154 | virtual GrRenderTarget* accessRenderTarget() = 0; |
michael@0 | 155 | |
michael@0 | 156 | |
michael@0 | 157 | /** |
michael@0 | 158 | * Return the device's origin: its offset in device coordinates from |
michael@0 | 159 | * the default origin in its canvas' matrix/clip |
michael@0 | 160 | */ |
michael@0 | 161 | const SkIPoint& getOrigin() const { return fOrigin; } |
michael@0 | 162 | |
michael@0 | 163 | /** |
michael@0 | 164 | * onAttachToCanvas is invoked whenever a device is installed in a canvas |
michael@0 | 165 | * (i.e., setDevice, saveLayer (for the new device created by the save), |
michael@0 | 166 | * and SkCanvas' SkBaseDevice & SkBitmap -taking ctors). It allows the |
michael@0 | 167 | * devices to prepare for drawing (e.g., locking their pixels, etc.) |
michael@0 | 168 | */ |
michael@0 | 169 | virtual void onAttachToCanvas(SkCanvas*) { |
michael@0 | 170 | SkASSERT(!fAttachedToCanvas); |
michael@0 | 171 | this->lockPixels(); |
michael@0 | 172 | #ifdef SK_DEBUG |
michael@0 | 173 | fAttachedToCanvas = true; |
michael@0 | 174 | #endif |
michael@0 | 175 | }; |
michael@0 | 176 | |
michael@0 | 177 | /** |
michael@0 | 178 | * onDetachFromCanvas notifies a device that it will no longer be drawn to. |
michael@0 | 179 | * It gives the device a chance to clean up (e.g., unlock its pixels). It |
michael@0 | 180 | * is invoked from setDevice (for the displaced device), restore and |
michael@0 | 181 | * possibly from SkCanvas' dtor. |
michael@0 | 182 | */ |
michael@0 | 183 | virtual void onDetachFromCanvas() { |
michael@0 | 184 | SkASSERT(fAttachedToCanvas); |
michael@0 | 185 | this->unlockPixels(); |
michael@0 | 186 | #ifdef SK_DEBUG |
michael@0 | 187 | fAttachedToCanvas = false; |
michael@0 | 188 | #endif |
michael@0 | 189 | }; |
michael@0 | 190 | |
michael@0 | 191 | protected: |
michael@0 | 192 | enum Usage { |
michael@0 | 193 | kGeneral_Usage, |
michael@0 | 194 | kSaveLayer_Usage // <! internal use only |
michael@0 | 195 | }; |
michael@0 | 196 | |
michael@0 | 197 | struct TextFlags { |
michael@0 | 198 | uint32_t fFlags; // SkPaint::getFlags() |
michael@0 | 199 | SkPaint::Hinting fHinting; |
michael@0 | 200 | }; |
michael@0 | 201 | |
michael@0 | 202 | /** |
michael@0 | 203 | * Device may filter the text flags for drawing text here. If it wants to |
michael@0 | 204 | * make a change to the specified values, it should write them into the |
michael@0 | 205 | * textflags parameter (output) and return true. If the paint is fine as |
michael@0 | 206 | * is, then ignore the textflags parameter and return false. |
michael@0 | 207 | * |
michael@0 | 208 | * The baseclass SkBaseDevice filters based on its depth and blitters. |
michael@0 | 209 | */ |
michael@0 | 210 | virtual bool filterTextFlags(const SkPaint& paint, TextFlags*) = 0; |
michael@0 | 211 | |
michael@0 | 212 | /** |
michael@0 | 213 | * |
michael@0 | 214 | * DEPRECATED: This will be removed in a future change. Device subclasses |
michael@0 | 215 | * should use the matrix and clip from the SkDraw passed to draw functions. |
michael@0 | 216 | * |
michael@0 | 217 | * Called with the correct matrix and clip before this device is drawn |
michael@0 | 218 | * to using those settings. If your subclass overrides this, be sure to |
michael@0 | 219 | * call through to the base class as well. |
michael@0 | 220 | * |
michael@0 | 221 | * The clipstack is another view of the clip. It records the actual |
michael@0 | 222 | * geometry that went into building the region. It is present for devices |
michael@0 | 223 | * that want to parse it, but is not required: the region is a complete |
michael@0 | 224 | * picture of the current clip. (i.e. if you regionize all of the geometry |
michael@0 | 225 | * in the clipstack, you will arrive at an equivalent region to the one |
michael@0 | 226 | * passed in). |
michael@0 | 227 | */ |
michael@0 | 228 | virtual void setMatrixClip(const SkMatrix&, const SkRegion&, |
michael@0 | 229 | const SkClipStack&) {}; |
michael@0 | 230 | |
michael@0 | 231 | /** Clears the entire device to the specified color (including alpha). |
michael@0 | 232 | * Ignores the clip. |
michael@0 | 233 | */ |
michael@0 | 234 | virtual void clear(SkColor color) = 0; |
michael@0 | 235 | |
michael@0 | 236 | SK_ATTR_DEPRECATED("use clear() instead") |
michael@0 | 237 | void eraseColor(SkColor eraseColor) { this->clear(eraseColor); } |
michael@0 | 238 | |
michael@0 | 239 | /** These are called inside the per-device-layer loop for each draw call. |
michael@0 | 240 | When these are called, we have already applied any saveLayer operations, |
michael@0 | 241 | and are handling any looping from the paint, and any effects from the |
michael@0 | 242 | DrawFilter. |
michael@0 | 243 | */ |
michael@0 | 244 | virtual void drawPaint(const SkDraw&, const SkPaint& paint) = 0; |
michael@0 | 245 | virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t count, |
michael@0 | 246 | const SkPoint[], const SkPaint& paint) = 0; |
michael@0 | 247 | virtual void drawRect(const SkDraw&, const SkRect& r, |
michael@0 | 248 | const SkPaint& paint) = 0; |
michael@0 | 249 | virtual void drawOval(const SkDraw&, const SkRect& oval, |
michael@0 | 250 | const SkPaint& paint) = 0; |
michael@0 | 251 | virtual void drawRRect(const SkDraw&, const SkRRect& rr, |
michael@0 | 252 | const SkPaint& paint) = 0; |
michael@0 | 253 | |
michael@0 | 254 | // Default impl calls drawPath() |
michael@0 | 255 | virtual void drawDRRect(const SkDraw&, const SkRRect& outer, |
michael@0 | 256 | const SkRRect& inner, const SkPaint&); |
michael@0 | 257 | |
michael@0 | 258 | /** |
michael@0 | 259 | * If pathIsMutable, then the implementation is allowed to cast path to a |
michael@0 | 260 | * non-const pointer and modify it in place (as an optimization). Canvas |
michael@0 | 261 | * may do this to implement helpers such as drawOval, by placing a temp |
michael@0 | 262 | * path on the stack to hold the representation of the oval. |
michael@0 | 263 | * |
michael@0 | 264 | * If prePathMatrix is not null, it should logically be applied before any |
michael@0 | 265 | * stroking or other effects. If there are no effects on the paint that |
michael@0 | 266 | * affect the geometry/rasterization, then the pre matrix can just be |
michael@0 | 267 | * pre-concated with the current matrix. |
michael@0 | 268 | */ |
michael@0 | 269 | virtual void drawPath(const SkDraw&, const SkPath& path, |
michael@0 | 270 | const SkPaint& paint, |
michael@0 | 271 | const SkMatrix* prePathMatrix = NULL, |
michael@0 | 272 | bool pathIsMutable = false) = 0; |
michael@0 | 273 | virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap, |
michael@0 | 274 | const SkMatrix& matrix, const SkPaint& paint) = 0; |
michael@0 | 275 | virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap, |
michael@0 | 276 | int x, int y, const SkPaint& paint) = 0; |
michael@0 | 277 | |
michael@0 | 278 | /** |
michael@0 | 279 | * The default impl. will create a bitmap-shader from the bitmap, |
michael@0 | 280 | * and call drawRect with it. |
michael@0 | 281 | */ |
michael@0 | 282 | virtual void drawBitmapRect(const SkDraw&, const SkBitmap&, |
michael@0 | 283 | const SkRect* srcOrNull, const SkRect& dst, |
michael@0 | 284 | const SkPaint& paint, |
michael@0 | 285 | SkCanvas::DrawBitmapRectFlags flags) = 0; |
michael@0 | 286 | |
michael@0 | 287 | /** |
michael@0 | 288 | * Does not handle text decoration. |
michael@0 | 289 | * Decorations (underline and stike-thru) will be handled by SkCanvas. |
michael@0 | 290 | */ |
michael@0 | 291 | virtual void drawText(const SkDraw&, const void* text, size_t len, |
michael@0 | 292 | SkScalar x, SkScalar y, const SkPaint& paint) = 0; |
michael@0 | 293 | virtual void drawPosText(const SkDraw&, const void* text, size_t len, |
michael@0 | 294 | const SkScalar pos[], SkScalar constY, |
michael@0 | 295 | int scalarsPerPos, const SkPaint& paint) = 0; |
michael@0 | 296 | virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len, |
michael@0 | 297 | const SkPath& path, const SkMatrix* matrix, |
michael@0 | 298 | const SkPaint& paint) = 0; |
michael@0 | 299 | virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, int vertexCount, |
michael@0 | 300 | const SkPoint verts[], const SkPoint texs[], |
michael@0 | 301 | const SkColor colors[], SkXfermode* xmode, |
michael@0 | 302 | const uint16_t indices[], int indexCount, |
michael@0 | 303 | const SkPaint& paint) = 0; |
michael@0 | 304 | /** The SkDevice passed will be an SkDevice which was returned by a call to |
michael@0 | 305 | onCreateDevice on this device with kSaveLayer_Usage. |
michael@0 | 306 | */ |
michael@0 | 307 | virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y, |
michael@0 | 308 | const SkPaint&) = 0; |
michael@0 | 309 | |
michael@0 | 310 | /** |
michael@0 | 311 | * On success (returns true), copy the device pixels into the bitmap. |
michael@0 | 312 | * On failure, the bitmap parameter is left unchanged and false is |
michael@0 | 313 | * returned. |
michael@0 | 314 | * |
michael@0 | 315 | * The device's pixels are converted to the bitmap's config. The only |
michael@0 | 316 | * supported config is kARGB_8888_Config, though this is likely to be |
michael@0 | 317 | * relaxed in the future. The meaning of config kARGB_8888_Config is |
michael@0 | 318 | * modified by the enum param config8888. The default value interprets |
michael@0 | 319 | * kARGB_8888_Config as SkPMColor |
michael@0 | 320 | * |
michael@0 | 321 | * If the bitmap has pixels already allocated, the device pixels will be |
michael@0 | 322 | * written there. If not, bitmap->allocPixels() will be called |
michael@0 | 323 | * automatically. If the bitmap is backed by a texture readPixels will |
michael@0 | 324 | * fail. |
michael@0 | 325 | * |
michael@0 | 326 | * The actual pixels written is the intersection of the device's bounds, |
michael@0 | 327 | * and the rectangle formed by the bitmap's width,height and the specified |
michael@0 | 328 | * x,y. If bitmap pixels extend outside of that intersection, they will not |
michael@0 | 329 | * be modified. |
michael@0 | 330 | * |
michael@0 | 331 | * Other failure conditions: |
michael@0 | 332 | * * If the device is not a raster device (e.g. PDF) then readPixels will |
michael@0 | 333 | * fail. |
michael@0 | 334 | * * If bitmap is texture-backed then readPixels will fail. (This may be |
michael@0 | 335 | * relaxed in the future.) |
michael@0 | 336 | */ |
michael@0 | 337 | bool readPixels(SkBitmap* bitmap, |
michael@0 | 338 | int x, int y, |
michael@0 | 339 | SkCanvas::Config8888 config8888); |
michael@0 | 340 | |
michael@0 | 341 | /////////////////////////////////////////////////////////////////////////// |
michael@0 | 342 | |
michael@0 | 343 | /** Update as needed the pixel value in the bitmap, so that the caller can |
michael@0 | 344 | access the pixels directly. |
michael@0 | 345 | @return The device contents as a bitmap |
michael@0 | 346 | */ |
michael@0 | 347 | virtual const SkBitmap& onAccessBitmap() = 0; |
michael@0 | 348 | |
michael@0 | 349 | /** Called when this device is installed into a Canvas. Balanced by a call |
michael@0 | 350 | to unlockPixels() when the device is removed from a Canvas. |
michael@0 | 351 | */ |
michael@0 | 352 | virtual void lockPixels() = 0; |
michael@0 | 353 | virtual void unlockPixels() = 0; |
michael@0 | 354 | |
michael@0 | 355 | /** |
michael@0 | 356 | * Returns true if the device allows processing of this imagefilter. If |
michael@0 | 357 | * false is returned, then the filter is ignored. This may happen for |
michael@0 | 358 | * some subclasses that do not support pixel manipulations after drawing |
michael@0 | 359 | * has occurred (e.g. printing). The default implementation returns true. |
michael@0 | 360 | */ |
michael@0 | 361 | virtual bool allowImageFilter(const SkImageFilter*) = 0; |
michael@0 | 362 | |
michael@0 | 363 | /** |
michael@0 | 364 | * Override and return true for filters that the device can handle |
michael@0 | 365 | * intrinsically. Doing so means that SkCanvas will pass-through this |
michael@0 | 366 | * filter to drawSprite and drawDevice (and potentially filterImage). |
michael@0 | 367 | * Returning false means the SkCanvas will have apply the filter itself, |
michael@0 | 368 | * and just pass the resulting image to the device. |
michael@0 | 369 | */ |
michael@0 | 370 | virtual bool canHandleImageFilter(const SkImageFilter*) = 0; |
michael@0 | 371 | |
michael@0 | 372 | /** |
michael@0 | 373 | * Related (but not required) to canHandleImageFilter, this method returns |
michael@0 | 374 | * true if the device could apply the filter to the src bitmap and return |
michael@0 | 375 | * the result (and updates offset as needed). |
michael@0 | 376 | * If the device does not recognize or support this filter, |
michael@0 | 377 | * it just returns false and leaves result and offset unchanged. |
michael@0 | 378 | */ |
michael@0 | 379 | virtual bool filterImage(const SkImageFilter*, const SkBitmap&, |
michael@0 | 380 | const SkImageFilter::Context& ctx, |
michael@0 | 381 | SkBitmap* result, SkIPoint* offset) = 0; |
michael@0 | 382 | |
michael@0 | 383 | // This is equal kBGRA_Premul_Config8888 or kRGBA_Premul_Config8888 if |
michael@0 | 384 | // either is identical to kNative_Premul_Config8888. Otherwise, -1. |
michael@0 | 385 | static const SkCanvas::Config8888 kPMColorAlias; |
michael@0 | 386 | |
michael@0 | 387 | protected: |
michael@0 | 388 | // default impl returns NULL |
michael@0 | 389 | virtual SkSurface* newSurface(const SkImageInfo&); |
michael@0 | 390 | |
michael@0 | 391 | // default impl returns NULL |
michael@0 | 392 | virtual const void* peekPixels(SkImageInfo*, size_t* rowBytes); |
michael@0 | 393 | |
michael@0 | 394 | /** |
michael@0 | 395 | * Implements readPixels API. The caller will ensure that: |
michael@0 | 396 | * 1. bitmap has pixel config kARGB_8888_Config. |
michael@0 | 397 | * 2. bitmap has pixels. |
michael@0 | 398 | * 3. The rectangle (x, y, x + bitmap->width(), y + bitmap->height()) is |
michael@0 | 399 | * contained in the device bounds. |
michael@0 | 400 | */ |
michael@0 | 401 | virtual bool onReadPixels(const SkBitmap& bitmap, |
michael@0 | 402 | int x, int y, |
michael@0 | 403 | SkCanvas::Config8888 config8888); |
michael@0 | 404 | |
michael@0 | 405 | /** |
michael@0 | 406 | * The caller is responsible for "pre-clipping" the src. The impl can assume that the src |
michael@0 | 407 | * image at the specified x,y offset will fit within the device's bounds. |
michael@0 | 408 | * |
michael@0 | 409 | * This is explicitly asserted in writePixelsDirect(), the public way to call this. |
michael@0 | 410 | */ |
michael@0 | 411 | virtual bool onWritePixels(const SkImageInfo&, const void*, size_t, int x, int y); |
michael@0 | 412 | |
michael@0 | 413 | /** |
michael@0 | 414 | * Default impl returns NULL. |
michael@0 | 415 | */ |
michael@0 | 416 | virtual void* onAccessPixels(SkImageInfo* info, size_t* rowBytes); |
michael@0 | 417 | |
michael@0 | 418 | /** |
michael@0 | 419 | * Leaky properties are those which the device should be applying but it isn't. |
michael@0 | 420 | * These properties will be applied by the draw, when and as it can. |
michael@0 | 421 | * If the device does handle a property, that property should be set to the identity value |
michael@0 | 422 | * for that property, effectively making it non-leaky. |
michael@0 | 423 | */ |
michael@0 | 424 | SkDeviceProperties fLeakyProperties; |
michael@0 | 425 | |
michael@0 | 426 | /** |
michael@0 | 427 | * PRIVATE / EXPERIMENTAL -- do not call |
michael@0 | 428 | * Construct an acceleration object and attach it to 'picture' |
michael@0 | 429 | */ |
michael@0 | 430 | virtual void EXPERIMENTAL_optimize(SkPicture* picture); |
michael@0 | 431 | |
michael@0 | 432 | /** |
michael@0 | 433 | * PRIVATE / EXPERIMENTAL -- do not call |
michael@0 | 434 | * This entry point gives the backend an opportunity to take over the rendering |
michael@0 | 435 | * of 'picture'. If optimization data is available (due to an earlier |
michael@0 | 436 | * 'optimize' call) this entry point should make use of it and return true |
michael@0 | 437 | * if all rendering has been done. If false is returned, SkCanvas will |
michael@0 | 438 | * perform its own rendering pass. It is acceptable for the backend |
michael@0 | 439 | * to perform some device-specific warm up tasks and then let SkCanvas |
michael@0 | 440 | * perform the main rendering loop (by return false from here). |
michael@0 | 441 | */ |
michael@0 | 442 | virtual bool EXPERIMENTAL_drawPicture(const SkPicture& picture); |
michael@0 | 443 | |
michael@0 | 444 | private: |
michael@0 | 445 | friend class SkCanvas; |
michael@0 | 446 | friend struct DeviceCM; //for setMatrixClip |
michael@0 | 447 | friend class SkDraw; |
michael@0 | 448 | friend class SkDrawIter; |
michael@0 | 449 | friend class SkDeviceFilteredPaint; |
michael@0 | 450 | friend class SkDeviceImageFilterProxy; |
michael@0 | 451 | friend class SkDeferredDevice; // for newSurface |
michael@0 | 452 | |
michael@0 | 453 | friend class SkSurface_Raster; |
michael@0 | 454 | |
michael@0 | 455 | // used to change the backend's pixels (and possibly config/rowbytes) |
michael@0 | 456 | // but cannot change the width/height, so there should be no change to |
michael@0 | 457 | // any clip information. |
michael@0 | 458 | // TODO: move to SkBitmapDevice |
michael@0 | 459 | virtual void replaceBitmapBackendForRasterSurface(const SkBitmap&) = 0; |
michael@0 | 460 | |
michael@0 | 461 | // just called by SkCanvas when built as a layer |
michael@0 | 462 | void setOrigin(int x, int y) { fOrigin.set(x, y); } |
michael@0 | 463 | // just called by SkCanvas for saveLayer |
michael@0 | 464 | SkBaseDevice* createCompatibleDeviceForSaveLayer(const SkImageInfo&); |
michael@0 | 465 | |
michael@0 | 466 | #ifdef SK_SUPPORT_LEGACY_COMPATIBLEDEVICE_CONFIG |
michael@0 | 467 | /** |
michael@0 | 468 | * Justs exists during the period where clients still "override" this |
michael@0 | 469 | * signature. They are supported by our base-impl calling this old |
michael@0 | 470 | * signature from the new one (using ImageInfo). |
michael@0 | 471 | */ |
michael@0 | 472 | virtual SkBaseDevice* onCreateCompatibleDevice(SkBitmap::Config config, |
michael@0 | 473 | int width, int height, |
michael@0 | 474 | bool isOpaque, Usage) { |
michael@0 | 475 | return NULL; |
michael@0 | 476 | } |
michael@0 | 477 | #endif |
michael@0 | 478 | virtual SkBaseDevice* onCreateDevice(const SkImageInfo&, Usage) { |
michael@0 | 479 | return NULL; |
michael@0 | 480 | } |
michael@0 | 481 | |
michael@0 | 482 | /** Causes any deferred drawing to the device to be completed. |
michael@0 | 483 | */ |
michael@0 | 484 | virtual void flush() = 0; |
michael@0 | 485 | |
michael@0 | 486 | SkIPoint fOrigin; |
michael@0 | 487 | SkMetaData* fMetaData; |
michael@0 | 488 | |
michael@0 | 489 | #ifdef SK_DEBUG |
michael@0 | 490 | bool fAttachedToCanvas; |
michael@0 | 491 | #endif |
michael@0 | 492 | |
michael@0 | 493 | typedef SkRefCnt INHERITED; |
michael@0 | 494 | }; |
michael@0 | 495 | |
michael@0 | 496 | #endif |