reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2006 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef SkCanvas_DEFINED |
| 9 | #define SkCanvas_DEFINED |
| 10 | |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 11 | #include "SkBlendMode.h" |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 12 | #include "SkClipOp.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 13 | #include "SkDeque.h" |
| 14 | #include "SkPaint.h" |
Mike Reed | 356f7c2 | 2017-01-10 11:58:39 -0500 | [diff] [blame] | 15 | #include "SkRasterHandleAllocator.h" |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 16 | #include "SkSurfaceProps.h" |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 17 | #include "SkLights.h" |
vjiaoblack | e6f5d56 | 2016-08-25 06:30:23 -0700 | [diff] [blame] | 18 | #include "../private/SkShadowParams.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 19 | |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 20 | class GrContext; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 21 | class GrRenderTargetContext; |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 22 | class SkBaseDevice; |
Mike Reed | 267be7f | 2017-02-13 09:32:54 -0500 | [diff] [blame] | 23 | class SkBitmap; |
Mike Reed | 93b1b4f | 2017-04-05 16:21:47 -0400 | [diff] [blame] | 24 | #ifdef SK_SUPPORT_OBSOLETE_REPLAYCLIP |
Mike Reed | 8310f0e | 2017-03-08 21:42:37 +0000 | [diff] [blame] | 25 | class SkCanvasClipVisitor; |
Mike Reed | 93b1b4f | 2017-04-05 16:21:47 -0400 | [diff] [blame] | 26 | #endif |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 27 | class SkClipStack; |
reed | f70b531 | 2016-03-04 16:36:20 -0800 | [diff] [blame] | 28 | class SkData; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 29 | class SkDraw; |
reed | 3cb3840 | 2015-02-06 08:36:15 -0800 | [diff] [blame] | 30 | class SkDrawable; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 31 | class SkDrawFilter; |
Mike Reed | 267be7f | 2017-02-13 09:32:54 -0500 | [diff] [blame] | 32 | class SkImage; |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 33 | class SkImageFilter; |
mike@reedtribe.org | 74bb77e | 2012-09-26 02:24:45 +0000 | [diff] [blame] | 34 | class SkMetaData; |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 35 | class SkPath; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 36 | class SkPicture; |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 37 | class SkPixmap; |
reed | 1e7f5e7 | 2016-04-27 07:49:17 -0700 | [diff] [blame] | 38 | class SkRasterClip; |
Mike Reed | 267be7f | 2017-02-13 09:32:54 -0500 | [diff] [blame] | 39 | class SkRegion; |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 40 | class SkRRect; |
reed | 71c3c76 | 2015-06-24 10:29:17 -0700 | [diff] [blame] | 41 | struct SkRSXform; |
reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 42 | class SkSurface; |
reed@google.com | 97af1a6 | 2012-08-28 12:19:02 +0000 | [diff] [blame] | 43 | class SkSurface_Base; |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 44 | class SkTextBlob; |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 45 | class SkVertices; |
reed | fa35f8e | 2014-09-04 12:14:36 -0700 | [diff] [blame] | 46 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 47 | /** \class SkCanvas |
| 48 | |
| 49 | A Canvas encapsulates all of the state about drawing into a device (bitmap). |
| 50 | This includes a reference to the device itself, and a stack of matrix/clip |
| 51 | values. For any given draw call (e.g. drawRect), the geometry of the object |
| 52 | being drawn is transformed by the concatenation of all the matrices in the |
| 53 | stack. The transformed geometry is clipped by the intersection of all of |
| 54 | the clips in the stack. |
| 55 | |
| 56 | While the Canvas holds the state of the drawing device, the state (style) |
| 57 | of the object being drawn is held by the Paint, which is provided as a |
| 58 | parameter to each of the draw() methods. The Paint holds attributes such as |
| 59 | color, typeface, textSize, strokeWidth, shader (e.g. gradients, patterns), |
| 60 | etc. |
| 61 | */ |
Mike Reed | 02b7349 | 2016-12-07 16:52:58 -0500 | [diff] [blame] | 62 | class SK_API SkCanvas : SkNoncopyable { |
reed | bada188 | 2015-12-21 13:09:44 -0800 | [diff] [blame] | 63 | enum PrivateSaveLayerFlags { |
caryclark | 952538e | 2016-02-26 05:01:42 -0800 | [diff] [blame] | 64 | kDontClipToLayer_PrivateSaveLayerFlag = 1U << 31, |
reed | bada188 | 2015-12-21 13:09:44 -0800 | [diff] [blame] | 65 | }; |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 66 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 67 | public: |
commit-bot@chromium.org | e254310 | 2014-01-31 19:42:58 +0000 | [diff] [blame] | 68 | /** |
commit-bot@chromium.org | 42b0893 | 2014-03-17 02:13:07 +0000 | [diff] [blame] | 69 | * Attempt to allocate raster canvas, matching the ImageInfo, that will draw directly into the |
| 70 | * specified pixels. To access the pixels after drawing to them, the caller should call |
| 71 | * flush() or call peekPixels(...). |
| 72 | * |
| 73 | * On failure, return NULL. This can fail for several reasons: |
| 74 | * 1. invalid ImageInfo (e.g. negative dimensions) |
| 75 | * 2. unsupported ImageInfo for a canvas |
| 76 | * - kUnknown_SkColorType, kIndex_8_SkColorType |
reed | 4497748 | 2015-02-27 10:23:00 -0800 | [diff] [blame] | 77 | * - kUnknown_SkAlphaType |
commit-bot@chromium.org | 42b0893 | 2014-03-17 02:13:07 +0000 | [diff] [blame] | 78 | * - this list is not complete, so others may also be unsupported |
| 79 | * |
| 80 | * Note: it is valid to request a supported ImageInfo, but with zero |
| 81 | * dimensions. |
| 82 | */ |
Mike Reed | 5df4934 | 2016-11-12 08:06:55 -0600 | [diff] [blame] | 83 | static std::unique_ptr<SkCanvas> MakeRasterDirect(const SkImageInfo&, void*, size_t); |
| 84 | |
| 85 | static std::unique_ptr<SkCanvas> MakeRasterDirectN32(int width, int height, SkPMColor* pixels, |
| 86 | size_t rowBytes) { |
| 87 | return MakeRasterDirect(SkImageInfo::MakeN32Premul(width, height), pixels, rowBytes); |
| 88 | } |
| 89 | |
commit-bot@chromium.org | 42b0893 | 2014-03-17 02:13:07 +0000 | [diff] [blame] | 90 | /** |
commit-bot@chromium.org | e254310 | 2014-01-31 19:42:58 +0000 | [diff] [blame] | 91 | * Creates an empty canvas with no backing device/pixels, and zero |
| 92 | * dimensions. |
| 93 | */ |
reed@google.com | cde9211 | 2011-07-06 20:00:52 +0000 | [diff] [blame] | 94 | SkCanvas(); |
vandebo@chromium.org | 8d84fac | 2010-10-13 22:13:05 +0000 | [diff] [blame] | 95 | |
commit-bot@chromium.org | e254310 | 2014-01-31 19:42:58 +0000 | [diff] [blame] | 96 | /** |
| 97 | * Creates a canvas of the specified dimensions, but explicitly not backed |
| 98 | * by any device/pixels. Typically this use used by subclasses who handle |
| 99 | * the draw calls in some other way. |
| 100 | */ |
reed | 96a857e | 2015-01-25 10:33:58 -0800 | [diff] [blame] | 101 | SkCanvas(int width, int height, const SkSurfaceProps* = NULL); |
commit-bot@chromium.org | e254310 | 2014-01-31 19:42:58 +0000 | [diff] [blame] | 102 | |
reed@google.com | 6dc7455 | 2011-07-21 18:00:46 +0000 | [diff] [blame] | 103 | /** Construct a canvas with the specified device to draw into. |
bsalomon@google.com | e97f085 | 2011-06-17 13:10:25 +0000 | [diff] [blame] | 104 | |
vandebo@chromium.org | 8d84fac | 2010-10-13 22:13:05 +0000 | [diff] [blame] | 105 | @param device Specifies a device for the canvas to draw into. |
| 106 | */ |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 107 | explicit SkCanvas(SkBaseDevice* device); |
vandebo@chromium.org | 8d84fac | 2010-10-13 22:13:05 +0000 | [diff] [blame] | 108 | |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 109 | /** Construct a canvas with the specified bitmap to draw into. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 110 | @param bitmap Specifies a bitmap for the canvas to draw into. Its |
| 111 | structure are copied to the canvas. |
| 112 | */ |
| 113 | explicit SkCanvas(const SkBitmap& bitmap); |
fmalita | 3d91aad | 2015-02-02 05:25:04 -0800 | [diff] [blame] | 114 | |
| 115 | /** Construct a canvas with the specified bitmap to draw into. |
| 116 | @param bitmap Specifies a bitmap for the canvas to draw into. Its |
| 117 | structure are copied to the canvas. |
| 118 | @param props New canvas surface properties. |
| 119 | */ |
| 120 | SkCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props); |
| 121 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 122 | virtual ~SkCanvas(); |
| 123 | |
mike@reedtribe.org | 74bb77e | 2012-09-26 02:24:45 +0000 | [diff] [blame] | 124 | SkMetaData& getMetaData(); |
| 125 | |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 126 | /** |
| 127 | * Return ImageInfo for this canvas. If the canvas is not backed by pixels |
| 128 | * (cpu or gpu), then the info's ColorType will be kUnknown_SkColorType. |
| 129 | */ |
| 130 | SkImageInfo imageInfo() const; |
| 131 | |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame] | 132 | /** |
| 133 | * If the canvas is backed by pixels (cpu or gpu), this writes a copy of the SurfaceProps |
| 134 | * for the canvas to the location supplied by the caller, and returns true. Otherwise, |
| 135 | * return false and leave the supplied props unchanged. |
| 136 | */ |
| 137 | bool getProps(SkSurfaceProps*) const; |
| 138 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 139 | /////////////////////////////////////////////////////////////////////////// |
| 140 | |
reed@google.com | 210ce00 | 2011-11-01 14:24:23 +0000 | [diff] [blame] | 141 | /** |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 142 | * Trigger the immediate execution of all pending draw operations. For the GPU |
| 143 | * backend this will resolve all rendering to the GPU surface backing the |
| 144 | * SkSurface that owns this canvas. |
junov@chromium.org | bf6c1e4 | 2012-01-30 14:53:22 +0000 | [diff] [blame] | 145 | */ |
| 146 | void flush(); |
| 147 | |
| 148 | /** |
bsalomon@google.com | 4ebe382 | 2014-02-26 20:22:32 +0000 | [diff] [blame] | 149 | * Gets the size of the base or root layer in global canvas coordinates. The |
| 150 | * origin of the base layer is always (0,0). The current drawable area may be |
| 151 | * smaller (due to clipping or saveLayer). |
reed@google.com | 210ce00 | 2011-11-01 14:24:23 +0000 | [diff] [blame] | 152 | */ |
tomhudson | 68260fa | 2015-03-23 07:22:40 -0700 | [diff] [blame] | 153 | virtual SkISize getBaseLayerSize() const; |
bsalomon@google.com | 4ebe382 | 2014-02-26 20:22:32 +0000 | [diff] [blame] | 154 | |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 155 | /** |
reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 156 | * Create a new surface matching the specified info, one that attempts to |
commit-bot@chromium.org | cae54f1 | 2014-04-11 18:34:35 +0000 | [diff] [blame] | 157 | * be maximally compatible when used with this canvas. If there is no matching Surface type, |
| 158 | * NULL is returned. |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 159 | * |
| 160 | * If surfaceprops is specified, those are passed to the new surface, otherwise the new surface |
| 161 | * inherits the properties of the surface that owns this canvas. If this canvas has no parent |
| 162 | * surface, then the new surface is created with default properties. |
reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 163 | */ |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 164 | sk_sp<SkSurface> makeSurface(const SkImageInfo&, const SkSurfaceProps* = nullptr); |
bsalomon@google.com | e97f085 | 2011-06-17 13:10:25 +0000 | [diff] [blame] | 165 | |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 166 | /** |
| 167 | * Return the GPU context of the device that is associated with the canvas. |
| 168 | * For a canvas with non-GPU device, NULL is returned. |
| 169 | */ |
| 170 | GrContext* getGrContext(); |
| 171 | |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 172 | /////////////////////////////////////////////////////////////////////////// |
| 173 | |
bsalomon@google.com | daba14b | 2011-11-02 20:10:48 +0000 | [diff] [blame] | 174 | /** |
reed@google.com | 9c135db | 2014-03-12 18:28:35 +0000 | [diff] [blame] | 175 | * If the canvas has writable pixels in its top layer (and is not recording to a picture |
| 176 | * or other non-raster target) and has direct access to its pixels (i.e. they are in |
| 177 | * local RAM) return the address of those pixels, and if not null, |
commit-bot@chromium.org | 6b4aaa7 | 2014-04-21 21:09:38 +0000 | [diff] [blame] | 178 | * return the ImageInfo, rowBytes and origin. The returned address is only valid |
reed@google.com | 9c135db | 2014-03-12 18:28:35 +0000 | [diff] [blame] | 179 | * while the canvas object is in scope and unchanged. Any API calls made on |
| 180 | * canvas (or its parent surface if any) will invalidate the |
| 181 | * returned address (and associated information). |
| 182 | * |
commit-bot@chromium.org | 6b4aaa7 | 2014-04-21 21:09:38 +0000 | [diff] [blame] | 183 | * On failure, returns NULL and the info, rowBytes, and origin parameters are ignored. |
reed@google.com | 9c135db | 2014-03-12 18:28:35 +0000 | [diff] [blame] | 184 | */ |
commit-bot@chromium.org | 6b4aaa7 | 2014-04-21 21:09:38 +0000 | [diff] [blame] | 185 | void* accessTopLayerPixels(SkImageInfo* info, size_t* rowBytes, SkIPoint* origin = NULL); |
reed@google.com | 9c135db | 2014-03-12 18:28:35 +0000 | [diff] [blame] | 186 | |
Mike Reed | 356f7c2 | 2017-01-10 11:58:39 -0500 | [diff] [blame] | 187 | SkRasterHandleAllocator::Handle accessTopRasterHandle() const; |
| 188 | |
reed@google.com | 9c135db | 2014-03-12 18:28:35 +0000 | [diff] [blame] | 189 | /** |
| 190 | * If the canvas has readable pixels in its base layer (and is not recording to a picture |
| 191 | * or other non-raster target) and has direct access to its pixels (i.e. they are in |
reed | 6ceeebd | 2016-03-09 14:26:26 -0800 | [diff] [blame] | 192 | * local RAM) return true, and if not null, return in the pixmap parameter information about |
| 193 | * the pixels. The pixmap's pixel address is only valid |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 194 | * while the canvas object is in scope and unchanged. Any API calls made on |
reed | 6ceeebd | 2016-03-09 14:26:26 -0800 | [diff] [blame] | 195 | * canvas (or its parent surface if any) will invalidate the pixel address |
| 196 | * (and associated information). |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 197 | * |
reed | 6ceeebd | 2016-03-09 14:26:26 -0800 | [diff] [blame] | 198 | * On failure, returns false and the pixmap parameter will be ignored. |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 199 | */ |
reed | 6ceeebd | 2016-03-09 14:26:26 -0800 | [diff] [blame] | 200 | bool peekPixels(SkPixmap*); |
| 201 | |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 202 | /** |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 203 | * Copy the pixels from the base-layer into the specified buffer (pixels + rowBytes), |
| 204 | * converting them into the requested format (SkImageInfo). The base-layer pixels are read |
reed | b184f7f | 2014-07-13 04:32:32 -0700 | [diff] [blame] | 205 | * starting at the specified (srcX,srcY) location in the coordinate system of the base-layer. |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 206 | * |
reed | b184f7f | 2014-07-13 04:32:32 -0700 | [diff] [blame] | 207 | * The specified ImageInfo and (srcX,srcY) offset specifies a source rectangle |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 208 | * |
reed | b184f7f | 2014-07-13 04:32:32 -0700 | [diff] [blame] | 209 | * srcR.setXYWH(srcX, srcY, dstInfo.width(), dstInfo.height()); |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 210 | * |
reed | b184f7f | 2014-07-13 04:32:32 -0700 | [diff] [blame] | 211 | * srcR is intersected with the bounds of the base-layer. If this intersection is not empty, |
| 212 | * then we have two sets of pixels (of equal size). Replace the dst pixels with the |
| 213 | * corresponding src pixels, performing any colortype/alphatype transformations needed |
| 214 | * (in the case where the src and dst have different colortypes or alphatypes). |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 215 | * |
| 216 | * This call can fail, returning false, for several reasons: |
reed | b184f7f | 2014-07-13 04:32:32 -0700 | [diff] [blame] | 217 | * - If srcR does not intersect the base-layer bounds. |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 218 | * - If the requested colortype/alphatype cannot be converted from the base-layer's types. |
| 219 | * - If this canvas is not backed by pixels (e.g. picture or PDF) |
| 220 | */ |
reed | b184f7f | 2014-07-13 04:32:32 -0700 | [diff] [blame] | 221 | bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, |
| 222 | int srcX, int srcY); |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 223 | |
| 224 | /** |
| 225 | * Helper for calling readPixels(info, ...). This call will check if bitmap has been allocated. |
| 226 | * If not, it will attempt to call allocPixels(). If this fails, it will return false. If not, |
| 227 | * it calls through to readPixels(info, ...) and returns its result. |
| 228 | */ |
reed | b184f7f | 2014-07-13 04:32:32 -0700 | [diff] [blame] | 229 | bool readPixels(SkBitmap* bitmap, int srcX, int srcY); |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 230 | |
| 231 | /** |
| 232 | * Helper for allocating pixels and then calling readPixels(info, ...). The bitmap is resized |
| 233 | * to the intersection of srcRect and the base-layer bounds. On success, pixels will be |
| 234 | * allocated in bitmap and true returned. On failure, false is returned and bitmap will be |
| 235 | * set to empty. |
reed@google.com | 51df9e3 | 2010-12-23 19:29:18 +0000 | [diff] [blame] | 236 | */ |
| 237 | bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap); |
reed@google.com | 51df9e3 | 2010-12-23 19:29:18 +0000 | [diff] [blame] | 238 | |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 239 | /** |
| 240 | * This method affects the pixels in the base-layer, and operates in pixel coordinates, |
| 241 | * ignoring the matrix and clip. |
| 242 | * |
| 243 | * The specified ImageInfo and (x,y) offset specifies a rectangle: target. |
| 244 | * |
| 245 | * target.setXYWH(x, y, info.width(), info.height()); |
| 246 | * |
| 247 | * Target is intersected with the bounds of the base-layer. If this intersection is not empty, |
| 248 | * then we have two sets of pixels (of equal size), the "src" specified by info+pixels+rowBytes |
| 249 | * and the "dst" by the canvas' backend. Replace the dst pixels with the corresponding src |
| 250 | * pixels, performing any colortype/alphatype transformations needed (in the case where the |
| 251 | * src and dst have different colortypes or alphatypes). |
| 252 | * |
| 253 | * This call can fail, returning false, for several reasons: |
| 254 | * - If the src colortype/alphatype cannot be converted to the canvas' types |
| 255 | * - If this canvas is not backed by pixels (e.g. picture or PDF) |
| 256 | */ |
| 257 | bool writePixels(const SkImageInfo&, const void* pixels, size_t rowBytes, int x, int y); |
| 258 | |
| 259 | /** |
| 260 | * Helper for calling writePixels(info, ...) by passing its pixels and rowbytes. If the bitmap |
| 261 | * is just wrapping a texture, returns false and does nothing. |
| 262 | */ |
| 263 | bool writePixels(const SkBitmap& bitmap, int x, int y); |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 264 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 265 | /////////////////////////////////////////////////////////////////////////// |
vandebo@chromium.org | 8d84fac | 2010-10-13 22:13:05 +0000 | [diff] [blame] | 266 | |
reed@android.com | dc3381f | 2010-02-11 16:05:15 +0000 | [diff] [blame] | 267 | /** This call saves the current matrix, clip, and drawFilter, and pushes a |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 268 | copy onto a private stack. Subsequent calls to translate, scale, |
reed@android.com | dc3381f | 2010-02-11 16:05:15 +0000 | [diff] [blame] | 269 | rotate, skew, concat or clipRect, clipPath, and setDrawFilter all |
| 270 | operate on this copy. |
| 271 | When the balancing call to restore() is made, the previous matrix, clip, |
| 272 | and drawFilter are restored. |
commit-bot@chromium.org | d70fa20 | 2014-04-24 21:51:58 +0000 | [diff] [blame] | 273 | |
| 274 | @return The value to pass to restoreToCount() to balance this save() |
| 275 | */ |
| 276 | int save(); |
| 277 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 278 | /** This behaves the same as save(), but in addition it allocates an |
| 279 | offscreen bitmap. All drawing calls are directed there, and only when |
| 280 | the balancing call to restore() is made is that offscreen transfered to |
reed@android.com | dc3381f | 2010-02-11 16:05:15 +0000 | [diff] [blame] | 281 | the canvas (or the previous layer). |
reed@android.com | ad164b2 | 2010-07-02 17:20:51 +0000 | [diff] [blame] | 282 | @param bounds (may be null) This rect, if non-null, is used as a hint to |
| 283 | limit the size of the offscreen, and thus drawing may be |
| 284 | clipped to it, though that clipping is not guaranteed to |
| 285 | happen. If exact clipping is desired, use clipRect(). |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 286 | @param paint (may be null) This is copied, and is applied to the |
| 287 | offscreen when restore() is called |
commit-bot@chromium.org | d70fa20 | 2014-04-24 21:51:58 +0000 | [diff] [blame] | 288 | @return The value to pass to restoreToCount() to balance this save() |
| 289 | */ |
| 290 | int saveLayer(const SkRect* bounds, const SkPaint* paint); |
reed | 021f631 | 2015-08-09 19:41:13 -0700 | [diff] [blame] | 291 | int saveLayer(const SkRect& bounds, const SkPaint* paint) { |
| 292 | return this->saveLayer(&bounds, paint); |
| 293 | } |
commit-bot@chromium.org | d70fa20 | 2014-04-24 21:51:58 +0000 | [diff] [blame] | 294 | |
reed | 70ee31b | 2015-12-10 13:44:45 -0800 | [diff] [blame] | 295 | /** |
| 296 | * Temporary name. |
| 297 | * Will allow any requests for LCD text to be respected, so the caller must be careful to |
| 298 | * only draw on top of opaque sections of the layer to get good results. |
| 299 | */ |
| 300 | int saveLayerPreserveLCDTextRequests(const SkRect* bounds, const SkPaint* paint); |
| 301 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 302 | /** This behaves the same as save(), but in addition it allocates an |
| 303 | offscreen bitmap. All drawing calls are directed there, and only when |
| 304 | the balancing call to restore() is made is that offscreen transfered to |
reed@android.com | dc3381f | 2010-02-11 16:05:15 +0000 | [diff] [blame] | 305 | the canvas (or the previous layer). |
reed@android.com | 4040861 | 2010-07-02 17:24:23 +0000 | [diff] [blame] | 306 | @param bounds (may be null) This rect, if non-null, is used as a hint to |
| 307 | limit the size of the offscreen, and thus drawing may be |
| 308 | clipped to it, though that clipping is not guaranteed to |
| 309 | happen. If exact clipping is desired, use clipRect(). |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 310 | @param alpha This is applied to the offscreen when restore() is called. |
commit-bot@chromium.org | d70fa20 | 2014-04-24 21:51:58 +0000 | [diff] [blame] | 311 | @return The value to pass to restoreToCount() to balance this save() |
| 312 | */ |
| 313 | int saveLayerAlpha(const SkRect* bounds, U8CPU alpha); |
| 314 | |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 315 | enum { |
| 316 | kIsOpaque_SaveLayerFlag = 1 << 0, |
| 317 | kPreserveLCDText_SaveLayerFlag = 1 << 1, |
reed | bada188 | 2015-12-21 13:09:44 -0800 | [diff] [blame] | 318 | |
Mike Reed | c61abee | 2017-02-28 17:45:27 -0500 | [diff] [blame] | 319 | /** initialize the new layer with the contents of the previous layer */ |
| 320 | kInitWithPrevious_SaveLayerFlag = 1 << 2, |
| 321 | |
reed | bada188 | 2015-12-21 13:09:44 -0800 | [diff] [blame] | 322 | #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |
| 323 | kDontClipToLayer_Legacy_SaveLayerFlag = kDontClipToLayer_PrivateSaveLayerFlag, |
| 324 | #endif |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 325 | }; |
| 326 | typedef uint32_t SaveLayerFlags; |
| 327 | |
| 328 | struct SaveLayerRec { |
reed | bfd5f17 | 2016-01-07 11:28:08 -0800 | [diff] [blame] | 329 | SaveLayerRec() |
| 330 | : fBounds(nullptr), fPaint(nullptr), fBackdrop(nullptr), fSaveLayerFlags(0) |
| 331 | {} |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 332 | SaveLayerRec(const SkRect* bounds, const SkPaint* paint, SaveLayerFlags saveLayerFlags = 0) |
| 333 | : fBounds(bounds) |
| 334 | , fPaint(paint) |
reed | bfd5f17 | 2016-01-07 11:28:08 -0800 | [diff] [blame] | 335 | , fBackdrop(nullptr) |
| 336 | , fSaveLayerFlags(saveLayerFlags) |
| 337 | {} |
| 338 | SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop, |
| 339 | SaveLayerFlags saveLayerFlags) |
| 340 | : fBounds(bounds) |
| 341 | , fPaint(paint) |
| 342 | , fBackdrop(backdrop) |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 343 | , fSaveLayerFlags(saveLayerFlags) |
| 344 | {} |
| 345 | |
reed | bfd5f17 | 2016-01-07 11:28:08 -0800 | [diff] [blame] | 346 | const SkRect* fBounds; // optional |
| 347 | const SkPaint* fPaint; // optional |
| 348 | const SkImageFilter* fBackdrop; // optional |
| 349 | SaveLayerFlags fSaveLayerFlags; |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 350 | }; |
| 351 | |
| 352 | int saveLayer(const SaveLayerRec&); |
| 353 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 354 | /** This call balances a previous call to save(), and is used to remove all |
reed@android.com | dc3381f | 2010-02-11 16:05:15 +0000 | [diff] [blame] | 355 | modifications to the matrix/clip/drawFilter state since the last save |
| 356 | call. |
| 357 | It is an error to call restore() more times than save() was called. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 358 | */ |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 359 | void restore(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 360 | |
| 361 | /** Returns the number of matrix/clip states on the SkCanvas' private stack. |
commit-bot@chromium.org | ea7d08e | 2014-02-13 16:00:51 +0000 | [diff] [blame] | 362 | This will equal # save() calls - # restore() calls + 1. The save count on |
| 363 | a new canvas is 1. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 364 | */ |
junov@chromium.org | a907ac3 | 2012-02-24 21:54:07 +0000 | [diff] [blame] | 365 | int getSaveCount() const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 366 | |
| 367 | /** Efficient way to pop any calls to save() that happened after the save |
commit-bot@chromium.org | ea7d08e | 2014-02-13 16:00:51 +0000 | [diff] [blame] | 368 | count reached saveCount. It is an error for saveCount to be greater than |
| 369 | getSaveCount(). To pop all the way back to the initial matrix/clip context |
| 370 | pass saveCount == 1. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 371 | @param saveCount The number of save() levels to restore from |
| 372 | */ |
| 373 | void restoreToCount(int saveCount); |
| 374 | |
| 375 | /** Preconcat the current matrix with the specified translation |
| 376 | @param dx The distance to translate in X |
| 377 | @param dy The distance to translate in Y |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 378 | */ |
commit-bot@chromium.org | 9236238 | 2014-03-18 12:51:48 +0000 | [diff] [blame] | 379 | void translate(SkScalar dx, SkScalar dy); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 380 | |
| 381 | /** Preconcat the current matrix with the specified scale. |
| 382 | @param sx The amount to scale in X |
| 383 | @param sy The amount to scale in Y |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 384 | */ |
commit-bot@chromium.org | 9236238 | 2014-03-18 12:51:48 +0000 | [diff] [blame] | 385 | void scale(SkScalar sx, SkScalar sy); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 386 | |
bungeman | 7438bfc | 2016-07-12 15:01:19 -0700 | [diff] [blame] | 387 | /** Preconcat the current matrix with the specified rotation about the origin. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 388 | @param degrees The amount to rotate, in degrees |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 389 | */ |
commit-bot@chromium.org | 9236238 | 2014-03-18 12:51:48 +0000 | [diff] [blame] | 390 | void rotate(SkScalar degrees); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 391 | |
bungeman | 7438bfc | 2016-07-12 15:01:19 -0700 | [diff] [blame] | 392 | /** Preconcat the current matrix with the specified rotation about a given point. |
| 393 | @param degrees The amount to rotate, in degrees |
| 394 | @param px The x coordinate of the point to rotate about. |
| 395 | @param py The y coordinate of the point to rotate about. |
| 396 | */ |
| 397 | void rotate(SkScalar degrees, SkScalar px, SkScalar py); |
| 398 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 399 | /** Preconcat the current matrix with the specified skew. |
| 400 | @param sx The amount to skew in X |
| 401 | @param sy The amount to skew in Y |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 402 | */ |
commit-bot@chromium.org | 9236238 | 2014-03-18 12:51:48 +0000 | [diff] [blame] | 403 | void skew(SkScalar sx, SkScalar sy); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 404 | |
| 405 | /** Preconcat the current matrix with the specified matrix. |
| 406 | @param matrix The matrix to preconcatenate with the current matrix |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 407 | */ |
commit-bot@chromium.org | 9236238 | 2014-03-18 12:51:48 +0000 | [diff] [blame] | 408 | void concat(const SkMatrix& matrix); |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 409 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 410 | /** Replace the current matrix with a copy of the specified matrix. |
| 411 | @param matrix The matrix that will be copied into the current matrix. |
| 412 | */ |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 413 | void setMatrix(const SkMatrix& matrix); |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 414 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 415 | /** Helper for setMatrix(identity). Sets the current matrix to identity. |
| 416 | */ |
| 417 | void resetMatrix(); |
| 418 | |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 419 | #ifdef SK_EXPERIMENTAL_SHADOWING |
vjiaoblack | e5de130 | 2016-07-13 14:05:28 -0700 | [diff] [blame] | 420 | /** Add the specified translation to the current draw depth of the canvas. |
| 421 | @param z The distance to translate in Z. |
| 422 | Negative into screen, positive out of screen. |
| 423 | Without translation, the draw depth defaults to 0. |
| 424 | */ |
| 425 | void translateZ(SkScalar z); |
| 426 | |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 427 | /** Set the current set of lights in the canvas. |
| 428 | @param lights The lights that we want the canvas to have. |
| 429 | */ |
| 430 | void setLights(sk_sp<SkLights> lights); |
| 431 | |
| 432 | /** Returns the current set of lights the canvas uses |
| 433 | */ |
| 434 | sk_sp<SkLights> getLights() const; |
| 435 | #endif |
| 436 | |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 437 | /** |
| 438 | * Modify the current clip with the specified rectangle. |
| 439 | * @param rect The rect to combine with the current clip |
| 440 | * @param op The region op to apply to the current clip |
| 441 | * @param doAntiAlias true if the clip should be antialiased |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 442 | */ |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 443 | void clipRect(const SkRect& rect, SkClipOp, bool doAntiAlias); |
| 444 | void clipRect(const SkRect& rect, SkClipOp op) { |
reed | 6699838 | 2016-09-21 11:15:07 -0700 | [diff] [blame] | 445 | this->clipRect(rect, op, false); |
| 446 | } |
| 447 | void clipRect(const SkRect& rect, bool doAntiAlias = false) { |
Mike Reed | 2dc5237 | 2016-12-14 14:00:03 -0500 | [diff] [blame] | 448 | this->clipRect(rect, SkClipOp::kIntersect, doAntiAlias); |
reed | 6699838 | 2016-09-21 11:15:07 -0700 | [diff] [blame] | 449 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 450 | |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 451 | /** |
Stan Iliev | 5f1bb0a | 2016-12-12 17:39:55 -0500 | [diff] [blame] | 452 | * Sets the max clip rectangle, which can be set by clipRect, clipRRect and |
| 453 | * clipPath and intersect the current clip with the specified rect. |
| 454 | * The max clip affects only future ops (it is not retroactive). |
| 455 | * We DON'T record the clip restriction in pictures. |
| 456 | * This is private API to be used only by Android framework. |
| 457 | * @param rect The maximum allowed clip in device coordinates. |
| 458 | * Empty rect means max clip is not enforced. |
| 459 | */ |
| 460 | void androidFramework_setDeviceClipRestriction(const SkIRect& rect); |
| 461 | |
| 462 | /** |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 463 | * Modify the current clip with the specified SkRRect. |
| 464 | * @param rrect The rrect to combine with the current clip |
| 465 | * @param op The region op to apply to the current clip |
| 466 | * @param doAntiAlias true if the clip should be antialiased |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 467 | */ |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 468 | void clipRRect(const SkRRect& rrect, SkClipOp op, bool doAntiAlias); |
| 469 | void clipRRect(const SkRRect& rrect, SkClipOp op) { |
reed | 6699838 | 2016-09-21 11:15:07 -0700 | [diff] [blame] | 470 | this->clipRRect(rrect, op, false); |
| 471 | } |
| 472 | void clipRRect(const SkRRect& rrect, bool doAntiAlias = false) { |
Mike Reed | 2dc5237 | 2016-12-14 14:00:03 -0500 | [diff] [blame] | 473 | this->clipRRect(rrect, SkClipOp::kIntersect, doAntiAlias); |
reed | 6699838 | 2016-09-21 11:15:07 -0700 | [diff] [blame] | 474 | } |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 475 | |
| 476 | /** |
| 477 | * Modify the current clip with the specified path. |
| 478 | * @param path The path to combine with the current clip |
| 479 | * @param op The region op to apply to the current clip |
| 480 | * @param doAntiAlias true if the clip should be antialiased |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 481 | */ |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 482 | void clipPath(const SkPath& path, SkClipOp op, bool doAntiAlias); |
| 483 | void clipPath(const SkPath& path, SkClipOp op) { |
reed | 6699838 | 2016-09-21 11:15:07 -0700 | [diff] [blame] | 484 | this->clipPath(path, op, false); |
| 485 | } |
| 486 | void clipPath(const SkPath& path, bool doAntiAlias = false) { |
Mike Reed | 2dc5237 | 2016-12-14 14:00:03 -0500 | [diff] [blame] | 487 | this->clipPath(path, SkClipOp::kIntersect, doAntiAlias); |
reed | 6699838 | 2016-09-21 11:15:07 -0700 | [diff] [blame] | 488 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 489 | |
caryclark@google.com | 8f0a7b8 | 2012-11-07 14:54:49 +0000 | [diff] [blame] | 490 | /** EXPERIMENTAL -- only used for testing |
caryclark@google.com | 45a75fb | 2013-04-25 13:34:40 +0000 | [diff] [blame] | 491 | Set to simplify clip stack using path ops. |
| 492 | */ |
| 493 | void setAllowSimplifyClip(bool allow) { |
| 494 | fAllowSimplifyClip = allow; |
| 495 | } |
| 496 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 497 | /** Modify the current clip with the specified region. Note that unlike |
| 498 | clipRect() and clipPath() which transform their arguments by the current |
| 499 | matrix, clipRegion() assumes its argument is already in device |
| 500 | coordinates, and so no transformation is performed. |
| 501 | @param deviceRgn The region to apply to the current clip |
mtklein | 6e998e6 | 2016-07-13 09:03:48 -0700 | [diff] [blame] | 502 | @param op The region op to apply to the current clip |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 503 | */ |
Mike Reed | 2dc5237 | 2016-12-14 14:00:03 -0500 | [diff] [blame] | 504 | void clipRegion(const SkRegion& deviceRgn, SkClipOp op = SkClipOp::kIntersect); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 505 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 506 | /** Return true if the specified rectangle, after being transformed by the |
| 507 | current matrix, would lie completely outside of the current clip. Call |
| 508 | this to check if an area you intend to draw into is clipped out (and |
| 509 | therefore you can skip making the draw calls). |
| 510 | @param rect the rect to compare with the current clip |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 511 | @return true if the rect (transformed by the canvas' matrix) does not |
| 512 | intersect with the canvas' clip |
| 513 | */ |
reed@google.com | 3b3e895 | 2012-08-16 20:53:31 +0000 | [diff] [blame] | 514 | bool quickReject(const SkRect& rect) const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 515 | |
| 516 | /** Return true if the specified path, after being transformed by the |
| 517 | current matrix, would lie completely outside of the current clip. Call |
| 518 | this to check if an area you intend to draw into is clipped out (and |
| 519 | therefore you can skip making the draw calls). Note, for speed it may |
| 520 | return false even if the path itself might not intersect the clip |
| 521 | (i.e. the bounds of the path intersects, but the path does not). |
| 522 | @param path The path to compare with the current clip |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 523 | @return true if the path (transformed by the canvas' matrix) does not |
| 524 | intersect with the canvas' clip |
| 525 | */ |
reed@google.com | 3b3e895 | 2012-08-16 20:53:31 +0000 | [diff] [blame] | 526 | bool quickReject(const SkPath& path) const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 527 | |
Mike Reed | 918e144 | 2017-01-23 11:39:45 -0500 | [diff] [blame] | 528 | /** |
| 529 | * Return the bounds of the current clip in local coordinates. If the clip is empty, |
| 530 | * return { 0, 0, 0, 0 }. |
| 531 | */ |
Mike Reed | 42e8c53 | 2017-01-23 14:09:13 -0500 | [diff] [blame] | 532 | SkRect getLocalClipBounds() const { return this->onGetLocalClipBounds(); } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 533 | |
Mike Reed | 918e144 | 2017-01-23 11:39:45 -0500 | [diff] [blame] | 534 | /** |
Mike Reed | 6f4a9b2 | 2017-01-24 09:13:40 -0500 | [diff] [blame] | 535 | * Returns true if the clip bounds are non-empty. |
| 536 | */ |
| 537 | bool getLocalClipBounds(SkRect* bounds) const { |
| 538 | *bounds = this->onGetLocalClipBounds(); |
| 539 | return !bounds->isEmpty(); |
| 540 | } |
| 541 | |
| 542 | /** |
Mike Reed | 918e144 | 2017-01-23 11:39:45 -0500 | [diff] [blame] | 543 | * Return the bounds of the current clip in device coordinates. If the clip is empty, |
| 544 | * return { 0, 0, 0, 0 }. |
| 545 | */ |
Mike Reed | 42e8c53 | 2017-01-23 14:09:13 -0500 | [diff] [blame] | 546 | SkIRect getDeviceClipBounds() const { return this->onGetDeviceClipBounds(); } |
| 547 | |
Mike Reed | 6f4a9b2 | 2017-01-24 09:13:40 -0500 | [diff] [blame] | 548 | /** |
| 549 | * Returns true if the clip bounds are non-empty. |
| 550 | */ |
| 551 | bool getDeviceClipBounds(SkIRect* bounds) const { |
| 552 | *bounds = this->onGetDeviceClipBounds(); |
| 553 | return !bounds->isEmpty(); |
| 554 | } |
| 555 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 556 | /** Fill the entire canvas' bitmap (restricted to the current clip) with the |
reed@android.com | 845fdac | 2009-06-23 03:01:32 +0000 | [diff] [blame] | 557 | specified color and mode. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 558 | @param color the color to draw with |
| 559 | @param mode the mode to apply the color in (defaults to SrcOver) |
| 560 | */ |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 561 | void drawColor(SkColor color, SkBlendMode mode = SkBlendMode::kSrcOver); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 562 | |
reed | f4e0d9e | 2014-12-05 20:49:03 -0800 | [diff] [blame] | 563 | /** |
| 564 | * Helper method for drawing a color in SRC mode, completely replacing all the pixels |
| 565 | * in the current clip with this color. |
| 566 | */ |
| 567 | void clear(SkColor color) { |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 568 | this->drawColor(color, SkBlendMode::kSrc); |
reed | 8eddfb5 | 2014-12-04 07:50:14 -0800 | [diff] [blame] | 569 | } |
reed@google.com | 2a98181 | 2011-04-14 18:59:28 +0000 | [diff] [blame] | 570 | |
| 571 | /** |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 572 | * This makes the contents of the canvas undefined. Subsequent calls that |
| 573 | * require reading the canvas contents will produce undefined results. Examples |
| 574 | * include blending and readPixels. The actual implementation is backend- |
benjaminwagner | a1bb8e0 | 2015-12-11 14:08:58 -0800 | [diff] [blame] | 575 | * dependent and one legal implementation is to do nothing. This method |
| 576 | * ignores the current clip. |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 577 | * |
| 578 | * This function should only be called if the caller intends to subsequently |
| 579 | * draw to the canvas. The canvas may do real work at discard() time in order |
| 580 | * to optimize performance on subsequent draws. Thus, if you call this and then |
| 581 | * never draw to the canvas subsequently you may pay a perfomance penalty. |
| 582 | */ |
| 583 | void discard() { this->onDiscard(); } |
| 584 | |
| 585 | /** |
benjaminwagner | a1bb8e0 | 2015-12-11 14:08:58 -0800 | [diff] [blame] | 586 | * Fill the entire canvas (restricted to the current clip) with the |
reed@google.com | 2a98181 | 2011-04-14 18:59:28 +0000 | [diff] [blame] | 587 | * specified paint. |
| 588 | * @param paint The paint used to fill the canvas |
| 589 | */ |
reed | 0846f1b | 2015-01-09 14:17:40 -0800 | [diff] [blame] | 590 | void drawPaint(const SkPaint& paint); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 591 | |
| 592 | enum PointMode { |
| 593 | /** drawPoints draws each point separately */ |
| 594 | kPoints_PointMode, |
| 595 | /** drawPoints draws each pair of points as a line segment */ |
| 596 | kLines_PointMode, |
| 597 | /** drawPoints draws the array of points as a polygon */ |
| 598 | kPolygon_PointMode |
| 599 | }; |
| 600 | |
| 601 | /** Draw a series of points, interpreted based on the PointMode mode. For |
| 602 | all modes, the count parameter is interpreted as the total number of |
| 603 | points. For kLine mode, count/2 line segments are drawn. |
| 604 | For kPoint mode, each point is drawn centered at its coordinate, and its |
| 605 | size is specified by the paint's stroke-width. It draws as a square, |
| 606 | unless the paint's cap-type is round, in which the points are drawn as |
| 607 | circles. |
| 608 | For kLine mode, each pair of points is drawn as a line segment, |
| 609 | respecting the paint's settings for cap/join/width. |
| 610 | For kPolygon mode, the entire array is drawn as a series of connected |
| 611 | line segments. |
| 612 | Note that, while similar, kLine and kPolygon modes draw slightly |
| 613 | differently than the equivalent path built with a series of moveto, |
| 614 | lineto calls, in that the path will draw all of its contours at once, |
| 615 | with no interactions if contours intersect each other (think XOR |
| 616 | xfermode). drawPoints always draws each element one at a time. |
| 617 | @param mode PointMode specifying how to draw the array of points. |
| 618 | @param count The number of points in the array |
| 619 | @param pts Array of points to draw |
| 620 | @param paint The paint used to draw the points |
| 621 | */ |
reed | 0846f1b | 2015-01-09 14:17:40 -0800 | [diff] [blame] | 622 | void drawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint& paint); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 623 | |
Mike Reed | 3661bc9 | 2017-02-22 13:21:42 -0500 | [diff] [blame] | 624 | /** Helper method for drawing a single point. See drawPoints() for more details. |
| 625 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 626 | void drawPoint(SkScalar x, SkScalar y, const SkPaint& paint); |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 627 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 628 | /** Draw a line segment with the specified start and stop x,y coordinates, |
| 629 | using the specified paint. NOTE: since a line is always "framed", the |
| 630 | paint's Style is ignored. |
| 631 | @param x0 The x-coordinate of the start point of the line |
| 632 | @param y0 The y-coordinate of the start point of the line |
| 633 | @param x1 The x-coordinate of the end point of the line |
| 634 | @param y1 The y-coordinate of the end point of the line |
| 635 | @param paint The paint used to draw the line |
| 636 | */ |
Mike Reed | 3661bc9 | 2017-02-22 13:21:42 -0500 | [diff] [blame] | 637 | void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint& paint); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 638 | |
| 639 | /** Draw the specified rectangle using the specified paint. The rectangle |
| 640 | will be filled or stroked based on the Style in the paint. |
| 641 | @param rect The rect to be drawn |
| 642 | @param paint The paint used to draw the rect |
| 643 | */ |
reed | 0846f1b | 2015-01-09 14:17:40 -0800 | [diff] [blame] | 644 | void drawRect(const SkRect& rect, const SkPaint& paint); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 645 | |
| 646 | /** Draw the specified rectangle using the specified paint. The rectangle |
| 647 | will be filled or framed based on the Style in the paint. |
| 648 | @param rect The rect to be drawn |
| 649 | @param paint The paint used to draw the rect |
| 650 | */ |
reed@google.com | 87001ed | 2014-02-17 16:28:05 +0000 | [diff] [blame] | 651 | void drawIRect(const SkIRect& rect, const SkPaint& paint) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 652 | SkRect r; |
| 653 | r.set(rect); // promotes the ints to scalars |
| 654 | this->drawRect(r, paint); |
| 655 | } |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 656 | |
msarett | 44df651 | 2016-08-25 13:54:30 -0700 | [diff] [blame] | 657 | /** Draw the outline of the specified region using the specified paint. |
| 658 | @param region The region to be drawn |
| 659 | @param paint The paint used to draw the region |
| 660 | */ |
msarett | dca352e | 2016-08-26 06:37:45 -0700 | [diff] [blame] | 661 | void drawRegion(const SkRegion& region, const SkPaint& paint); |
msarett | 44df651 | 2016-08-25 13:54:30 -0700 | [diff] [blame] | 662 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 663 | /** Draw the specified oval using the specified paint. The oval will be |
| 664 | filled or framed based on the Style in the paint. |
| 665 | @param oval The rectangle bounds of the oval to be drawn |
| 666 | @param paint The paint used to draw the oval |
| 667 | */ |
reed | 0846f1b | 2015-01-09 14:17:40 -0800 | [diff] [blame] | 668 | void drawOval(const SkRect& oval, const SkPaint&); |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 669 | |
| 670 | /** |
| 671 | * Draw the specified RRect using the specified paint The rrect will be filled or stroked |
| 672 | * based on the Style in the paint. |
| 673 | * |
| 674 | * @param rrect The round-rect to draw |
| 675 | * @param paint The paint used to draw the round-rect |
| 676 | */ |
reed | 0846f1b | 2015-01-09 14:17:40 -0800 | [diff] [blame] | 677 | void drawRRect(const SkRRect& rrect, const SkPaint& paint); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 678 | |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 679 | /** |
| 680 | * Draw the annulus formed by the outer and inner rrects. The results |
| 681 | * are undefined if the outer does not contain the inner. |
| 682 | */ |
| 683 | void drawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint&); |
| 684 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 685 | /** Draw the specified circle using the specified paint. If radius is <= 0, |
| 686 | then nothing will be drawn. The circle will be filled |
| 687 | or framed based on the Style in the paint. |
| 688 | @param cx The x-coordinate of the center of the cirle to be drawn |
| 689 | @param cy The y-coordinate of the center of the cirle to be drawn |
| 690 | @param radius The radius of the cirle to be drawn |
| 691 | @param paint The paint used to draw the circle |
| 692 | */ |
Mike Reed | 3661bc9 | 2017-02-22 13:21:42 -0500 | [diff] [blame] | 693 | void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint& paint); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 694 | |
| 695 | /** Draw the specified arc, which will be scaled to fit inside the |
bsalomon | 21af9ca | 2016-08-25 12:29:23 -0700 | [diff] [blame] | 696 | specified oval. Sweep angles are not treated as modulo 360 and thus can |
| 697 | exceed a full sweep of the oval. Note that this differs slightly from |
| 698 | SkPath::arcTo, which treats the sweep angle mod 360. If the oval is empty |
| 699 | or the sweep angle is zero nothing is drawn. If useCenter is true the oval |
| 700 | center is inserted into the implied path before the arc and the path is |
| 701 | closed back to the, center forming a wedge. Otherwise, the implied path |
| 702 | contains just the arc and is not closed. |
bsalomon | ac3aa24 | 2016-08-19 11:25:19 -0700 | [diff] [blame] | 703 | @param oval The bounds of oval used to define the shape of the arc. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 704 | @param startAngle Starting angle (in degrees) where the arc begins |
bsalomon | ac3aa24 | 2016-08-19 11:25:19 -0700 | [diff] [blame] | 705 | @param sweepAngle Sweep angle (in degrees) measured clockwise. |
bsalomon | 21af9ca | 2016-08-25 12:29:23 -0700 | [diff] [blame] | 706 | @param useCenter true means include the center of the oval. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 707 | @param paint The paint used to draw the arc |
| 708 | */ |
| 709 | void drawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, |
| 710 | bool useCenter, const SkPaint& paint); |
| 711 | |
| 712 | /** Draw the specified round-rect using the specified paint. The round-rect |
| 713 | will be filled or framed based on the Style in the paint. |
| 714 | @param rect The rectangular bounds of the roundRect to be drawn |
| 715 | @param rx The x-radius of the oval used to round the corners |
| 716 | @param ry The y-radius of the oval used to round the corners |
| 717 | @param paint The paint used to draw the roundRect |
| 718 | */ |
Mike Reed | 3661bc9 | 2017-02-22 13:21:42 -0500 | [diff] [blame] | 719 | void drawRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry, const SkPaint& paint); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 720 | |
| 721 | /** Draw the specified path using the specified paint. The path will be |
| 722 | filled or framed based on the Style in the paint. |
| 723 | @param path The path to be drawn |
| 724 | @param paint The paint used to draw the path |
| 725 | */ |
reed | 0846f1b | 2015-01-09 14:17:40 -0800 | [diff] [blame] | 726 | void drawPath(const SkPath& path, const SkPaint& paint); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 727 | |
piotaixr | d52893c | 2014-09-25 14:39:40 -0700 | [diff] [blame] | 728 | /** Draw the specified image, with its top/left corner at (x,y), using the |
| 729 | specified paint, transformed by the current matrix. |
| 730 | |
| 731 | @param image The image to be drawn |
| 732 | @param left The position of the left side of the image being drawn |
| 733 | @param top The position of the top side of the image being drawn |
| 734 | @param paint The paint used to draw the image, or NULL |
| 735 | */ |
reed | 0846f1b | 2015-01-09 14:17:40 -0800 | [diff] [blame] | 736 | void drawImage(const SkImage* image, SkScalar left, SkScalar top, const SkPaint* paint = NULL); |
reed | f8053da | 2016-03-17 08:14:57 -0700 | [diff] [blame] | 737 | void drawImage(const sk_sp<SkImage>& image, SkScalar left, SkScalar top, |
| 738 | const SkPaint* paint = NULL) { |
| 739 | this->drawImage(image.get(), left, top, paint); |
| 740 | } |
piotaixr | b5fae93 | 2014-09-24 13:03:30 -0700 | [diff] [blame] | 741 | |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 742 | /** |
| 743 | * Controls the behavior at the edge of the src-rect, when specified in drawImageRect, |
| 744 | * trading off speed for exactness. |
| 745 | * |
| 746 | * When filtering is enabled (in the Paint), skia may need to sample in a neighborhood around |
| 747 | * the pixels in the image. If there is a src-rect specified, it is intended to restrict the |
| 748 | * pixels that will be read. However, for performance reasons, some implementations may slow |
| 749 | * down if they cannot read 1-pixel past the src-rect boundary at times. |
| 750 | * |
| 751 | * This enum allows the caller to specify if such a 1-pixel "slop" will be visually acceptable. |
| 752 | * If it is, the caller should pass kFast, and it may result in a faster draw. If the src-rect |
| 753 | * must be strictly respected, the caller should pass kStrict. |
| 754 | */ |
| 755 | enum SrcRectConstraint { |
| 756 | /** |
| 757 | * If kStrict is specified, the implementation must respect the src-rect |
| 758 | * (if specified) strictly, and will never sample outside of those bounds during sampling |
| 759 | * even when filtering. This may be slower than kFast. |
| 760 | */ |
| 761 | kStrict_SrcRectConstraint, |
| 762 | |
| 763 | /** |
| 764 | * If kFast is specified, the implementation may sample outside of the src-rect |
bsalomon | 19e82e3 | 2015-10-23 09:27:42 -0700 | [diff] [blame] | 765 | * (if specified) by half the width of filter. This allows greater flexibility |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 766 | * to the implementation and can make the draw much faster. |
| 767 | */ |
| 768 | kFast_SrcRectConstraint, |
| 769 | }; |
| 770 | |
| 771 | /** Draw the specified image, scaling and translating so that it fills the specified |
| 772 | * dst rect. If the src rect is non-null, only that subset of the image is transformed |
| 773 | * and drawn. |
| 774 | * |
| 775 | * @param image The image to be drawn |
| 776 | * @param src Optional: specify the subset of the image to be drawn |
| 777 | * @param dst The destination rectangle where the scaled/translated |
| 778 | * image will be drawn |
| 779 | * @param paint The paint used to draw the image, or NULL |
| 780 | * @param constraint Control the tradeoff between speed and exactness w.r.t. the src-rect. |
| 781 | */ |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 782 | void drawImageRect(const SkImage* image, const SkRect& src, const SkRect& dst, |
| 783 | const SkPaint* paint, |
| 784 | SrcRectConstraint constraint = kStrict_SrcRectConstraint); |
| 785 | // variant that takes src SkIRect |
| 786 | void drawImageRect(const SkImage* image, const SkIRect& isrc, const SkRect& dst, |
| 787 | const SkPaint* paint, SrcRectConstraint = kStrict_SrcRectConstraint); |
| 788 | // variant that assumes src == image-bounds |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 789 | void drawImageRect(const SkImage* image, const SkRect& dst, const SkPaint* paint, |
| 790 | SrcRectConstraint = kStrict_SrcRectConstraint); |
reed | 84984ef | 2015-07-17 07:09:43 -0700 | [diff] [blame] | 791 | |
reed | f8053da | 2016-03-17 08:14:57 -0700 | [diff] [blame] | 792 | void drawImageRect(const sk_sp<SkImage>& image, const SkRect& src, const SkRect& dst, |
| 793 | const SkPaint* paint, |
| 794 | SrcRectConstraint constraint = kStrict_SrcRectConstraint) { |
| 795 | this->drawImageRect(image.get(), src, dst, paint, constraint); |
| 796 | } |
| 797 | void drawImageRect(const sk_sp<SkImage>& image, const SkIRect& isrc, const SkRect& dst, |
| 798 | const SkPaint* paint, SrcRectConstraint cons = kStrict_SrcRectConstraint) { |
| 799 | this->drawImageRect(image.get(), isrc, dst, paint, cons); |
| 800 | } |
| 801 | void drawImageRect(const sk_sp<SkImage>& image, const SkRect& dst, const SkPaint* paint, |
| 802 | SrcRectConstraint cons = kStrict_SrcRectConstraint) { |
| 803 | this->drawImageRect(image.get(), dst, paint, cons); |
| 804 | } |
| 805 | |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 806 | /** |
| 807 | * Draw the image stretched differentially to fit into dst. |
| 808 | * center is a rect within the image, and logically divides the image |
| 809 | * into 9 sections (3x3). For example, if the middle pixel of a [5x5] |
| 810 | * image is the "center", then the center-rect should be [2, 2, 3, 3]. |
| 811 | * |
| 812 | * If the dst is >= the image size, then... |
| 813 | * - The 4 corners are not stretched at all. |
| 814 | * - The sides are stretched in only one axis. |
| 815 | * - The center is stretched in both axes. |
| 816 | * Else, for each axis where dst < image, |
| 817 | * - The corners shrink proportionally |
| 818 | * - The sides (along the shrink axis) and center are not drawn |
| 819 | */ |
| 820 | void drawImageNine(const SkImage*, const SkIRect& center, const SkRect& dst, |
reed | f8053da | 2016-03-17 08:14:57 -0700 | [diff] [blame] | 821 | const SkPaint* paint = nullptr); |
| 822 | void drawImageNine(const sk_sp<SkImage>& image, const SkIRect& center, const SkRect& dst, |
| 823 | const SkPaint* paint = nullptr) { |
| 824 | this->drawImageNine(image.get(), center, dst, paint); |
| 825 | } |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 826 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 827 | /** Draw the specified bitmap, with its top/left corner at (x,y), using the |
| 828 | specified paint, transformed by the current matrix. Note: if the paint |
| 829 | contains a maskfilter that generates a mask which extends beyond the |
| 830 | bitmap's original width/height, then the bitmap will be drawn as if it |
| 831 | were in a Shader with CLAMP mode. Thus the color outside of the original |
| 832 | width/height will be the edge color replicated. |
commit-bot@chromium.org | 91246b9 | 2013-12-05 15:43:19 +0000 | [diff] [blame] | 833 | |
| 834 | If a shader is present on the paint it will be ignored, except in the |
reed@google.com | f20fc24 | 2014-03-26 13:44:58 +0000 | [diff] [blame] | 835 | case where the bitmap is kAlpha_8_SkColorType. In that case, the color is |
commit-bot@chromium.org | 91246b9 | 2013-12-05 15:43:19 +0000 | [diff] [blame] | 836 | generated by the shader. |
| 837 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 838 | @param bitmap The bitmap to be drawn |
| 839 | @param left The position of the left side of the bitmap being drawn |
| 840 | @param top The position of the top side of the bitmap being drawn |
| 841 | @param paint The paint used to draw the bitmap, or NULL |
| 842 | */ |
reed | 0846f1b | 2015-01-09 14:17:40 -0800 | [diff] [blame] | 843 | void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, |
| 844 | const SkPaint* paint = NULL); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 845 | |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 846 | /** Draw the specified bitmap, scaling and translating so that it fills the specified |
| 847 | * dst rect. If the src rect is non-null, only that subset of the bitmap is transformed |
| 848 | * and drawn. |
| 849 | * |
| 850 | * @param bitmap The bitmap to be drawn |
| 851 | * @param src Optional: specify the subset of the bitmap to be drawn |
| 852 | * @param dst The destination rectangle where the scaled/translated |
| 853 | * bitmap will be drawn |
| 854 | * @param paint The paint used to draw the bitmap, or NULL |
| 855 | * @param constraint Control the tradeoff between speed and exactness w.r.t. the src-rect. |
| 856 | */ |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 857 | void drawBitmapRect(const SkBitmap& bitmap, const SkRect& src, const SkRect& dst, |
reed | 84984ef | 2015-07-17 07:09:43 -0700 | [diff] [blame] | 858 | const SkPaint* paint, SrcRectConstraint = kStrict_SrcRectConstraint); |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 859 | // variant where src is SkIRect |
reed | 84984ef | 2015-07-17 07:09:43 -0700 | [diff] [blame] | 860 | void drawBitmapRect(const SkBitmap& bitmap, const SkIRect& isrc, const SkRect& dst, |
| 861 | const SkPaint* paint, SrcRectConstraint = kStrict_SrcRectConstraint); |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 862 | void drawBitmapRect(const SkBitmap& bitmap, const SkRect& dst, const SkPaint* paint, |
bsalomon | 19e82e3 | 2015-10-23 09:27:42 -0700 | [diff] [blame] | 863 | SrcRectConstraint = kStrict_SrcRectConstraint); |
reed | 84984ef | 2015-07-17 07:09:43 -0700 | [diff] [blame] | 864 | |
reed@google.com | f0b5e11 | 2011-09-07 11:57:34 +0000 | [diff] [blame] | 865 | /** |
msarett | c573a40 | 2016-08-02 08:05:56 -0700 | [diff] [blame] | 866 | * Draw the bitmap stretched or shrunk differentially to fit into dst. |
reed@google.com | f0b5e11 | 2011-09-07 11:57:34 +0000 | [diff] [blame] | 867 | * center is a rect within the bitmap, and logically divides the bitmap |
| 868 | * into 9 sections (3x3). For example, if the middle pixel of a [5x5] |
| 869 | * bitmap is the "center", then the center-rect should be [2, 2, 3, 3]. |
| 870 | * |
| 871 | * If the dst is >= the bitmap size, then... |
robertphillips@google.com | 9bf380c | 2013-07-25 12:10:42 +0000 | [diff] [blame] | 872 | * - The 4 corners are not stretched at all. |
| 873 | * - The sides are stretched in only one axis. |
| 874 | * - The center is stretched in both axes. |
reed@google.com | f0b5e11 | 2011-09-07 11:57:34 +0000 | [diff] [blame] | 875 | * Else, for each axis where dst < bitmap, |
| 876 | * - The corners shrink proportionally |
| 877 | * - The sides (along the shrink axis) and center are not drawn |
| 878 | */ |
reed | 0846f1b | 2015-01-09 14:17:40 -0800 | [diff] [blame] | 879 | void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst, |
| 880 | const SkPaint* paint = NULL); |
reed@google.com | f0b5e11 | 2011-09-07 11:57:34 +0000 | [diff] [blame] | 881 | |
msarett | c573a40 | 2016-08-02 08:05:56 -0700 | [diff] [blame] | 882 | /** |
| 883 | * Specifies coordinates to divide a bitmap into (xCount*yCount) rects. |
msarett | 71df2d7 | 2016-09-30 12:41:42 -0700 | [diff] [blame] | 884 | * |
| 885 | * If the lattice divs or bounds are invalid, the entire lattice |
| 886 | * struct will be ignored on the draw call. |
msarett | c573a40 | 2016-08-02 08:05:56 -0700 | [diff] [blame] | 887 | */ |
| 888 | struct Lattice { |
msarett | 0764efe | 2016-09-02 11:24:30 -0700 | [diff] [blame] | 889 | enum Flags : uint8_t { |
| 890 | // If set, indicates that we should not draw corresponding rect. |
| 891 | kTransparent_Flags = 1 << 0, |
| 892 | }; |
msarett | c573a40 | 2016-08-02 08:05:56 -0700 | [diff] [blame] | 893 | |
msarett | 0764efe | 2016-09-02 11:24:30 -0700 | [diff] [blame] | 894 | // An array of x-coordinates that divide the bitmap vertically. |
msarett | 71df2d7 | 2016-09-30 12:41:42 -0700 | [diff] [blame] | 895 | // These must be unique, increasing, and in the set [fBounds.fLeft, fBounds.fRight). |
msarett | 0764efe | 2016-09-02 11:24:30 -0700 | [diff] [blame] | 896 | // Does not have ownership. |
msarett | 71df2d7 | 2016-09-30 12:41:42 -0700 | [diff] [blame] | 897 | const int* fXDivs; |
msarett | c573a40 | 2016-08-02 08:05:56 -0700 | [diff] [blame] | 898 | |
| 899 | // An array of y-coordinates that divide the bitmap horizontally. |
msarett | 71df2d7 | 2016-09-30 12:41:42 -0700 | [diff] [blame] | 900 | // These must be unique, increasing, and in the set [fBounds.fTop, fBounds.fBottom). |
msarett | c573a40 | 2016-08-02 08:05:56 -0700 | [diff] [blame] | 901 | // Does not have ownership. |
msarett | 71df2d7 | 2016-09-30 12:41:42 -0700 | [diff] [blame] | 902 | const int* fYDivs; |
msarett | 0764efe | 2016-09-02 11:24:30 -0700 | [diff] [blame] | 903 | |
| 904 | // If non-null, the length of this array must be equal to |
| 905 | // (fXCount + 1) * (fYCount + 1). Note that we allow the first rect |
msarett | 71df2d7 | 2016-09-30 12:41:42 -0700 | [diff] [blame] | 906 | // in each direction to be empty (ex: fXDivs[0] = fBounds.fLeft). |
| 907 | // In this case, the caller still must specify a flag (as a placeholder) |
| 908 | // for these empty rects. |
msarett | 0764efe | 2016-09-02 11:24:30 -0700 | [diff] [blame] | 909 | // The flags correspond to the rects in the lattice, first moving |
| 910 | // left to right and then top to bottom. |
msarett | 71df2d7 | 2016-09-30 12:41:42 -0700 | [diff] [blame] | 911 | const Flags* fFlags; |
msarett | 0764efe | 2016-09-02 11:24:30 -0700 | [diff] [blame] | 912 | |
| 913 | // The number of fXDivs. |
msarett | 71df2d7 | 2016-09-30 12:41:42 -0700 | [diff] [blame] | 914 | int fXCount; |
msarett | c573a40 | 2016-08-02 08:05:56 -0700 | [diff] [blame] | 915 | |
| 916 | // The number of fYDivs. |
msarett | 71df2d7 | 2016-09-30 12:41:42 -0700 | [diff] [blame] | 917 | int fYCount; |
| 918 | |
| 919 | // The bound to draw from. Must be contained by the src that is being drawn, |
| 920 | // non-empty, and non-inverted. |
| 921 | // If nullptr, the bounds are the entire src. |
| 922 | const SkIRect* fBounds; |
msarett | c573a40 | 2016-08-02 08:05:56 -0700 | [diff] [blame] | 923 | }; |
| 924 | |
| 925 | /** |
| 926 | * Draw the bitmap stretched or shrunk differentially to fit into dst. |
| 927 | * |
| 928 | * Moving horizontally across the bitmap, alternating rects will be "scalable" |
| 929 | * (in the x-dimension) to fit into dst or must be left "fixed". The first rect |
| 930 | * is treated as "fixed", but it's possible to specify an empty first rect by |
| 931 | * making lattice.fXDivs[0] = 0. |
| 932 | * |
| 933 | * The scale factor for all "scalable" rects will be the same, and may be greater |
| 934 | * than or less than 1 (meaning we can stretch or shrink). If the number of |
| 935 | * "fixed" pixels is greater than the width of the dst, we will collapse all of |
| 936 | * the "scalable" regions and appropriately downscale the "fixed" regions. |
| 937 | * |
| 938 | * The same interpretation also applies to the y-dimension. |
| 939 | */ |
| 940 | void drawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice, const SkRect& dst, |
| 941 | const SkPaint* paint = nullptr); |
| 942 | void drawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst, |
| 943 | const SkPaint* paint = nullptr); |
| 944 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 945 | /** Draw the text, with origin at (x,y), using the specified paint. |
| 946 | The origin is interpreted based on the Align setting in the paint. |
| 947 | @param text The text to be drawn |
| 948 | @param byteLength The number of bytes to read from the text parameter |
| 949 | @param x The x-coordinate of the origin of the text being drawn |
| 950 | @param y The y-coordinate of the origin of the text being drawn |
| 951 | @param paint The paint used for the text (e.g. color, size, style) |
| 952 | */ |
reed | f7430cc | 2014-12-21 11:38:35 -0800 | [diff] [blame] | 953 | void drawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, |
| 954 | const SkPaint& paint); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 955 | |
| 956 | /** Draw the text, with each character/glyph origin specified by the pos[] |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 957 | array. The origin is interpreted by the Align setting in the paint. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 958 | @param text The text to be drawn |
| 959 | @param byteLength The number of bytes to read from the text parameter |
| 960 | @param pos Array of positions, used to position each character |
| 961 | @param paint The paint used for the text (e.g. color, size, style) |
| 962 | */ |
reed | f7430cc | 2014-12-21 11:38:35 -0800 | [diff] [blame] | 963 | void drawPosText(const void* text, size_t byteLength, const SkPoint pos[], |
| 964 | const SkPaint& paint); |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 965 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 966 | /** Draw the text, with each character/glyph origin specified by the x |
| 967 | coordinate taken from the xpos[] array, and the y from the constY param. |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 968 | The origin is interpreted by the Align setting in the paint. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 969 | @param text The text to be drawn |
| 970 | @param byteLength The number of bytes to read from the text parameter |
| 971 | @param xpos Array of x-positions, used to position each character |
| 972 | @param constY The shared Y coordinate for all of the positions |
| 973 | @param paint The paint used for the text (e.g. color, size, style) |
| 974 | */ |
reed | f7430cc | 2014-12-21 11:38:35 -0800 | [diff] [blame] | 975 | void drawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], SkScalar constY, |
| 976 | const SkPaint& paint); |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 977 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 978 | /** Draw the text, with origin at (x,y), using the specified paint, along |
| 979 | the specified path. The paint's Align setting determins where along the |
| 980 | path to start the text. |
| 981 | @param text The text to be drawn |
| 982 | @param byteLength The number of bytes to read from the text parameter |
| 983 | @param path The path the text should follow for its baseline |
| 984 | @param hOffset The distance along the path to add to the text's |
| 985 | starting position |
| 986 | @param vOffset The distance above(-) or below(+) the path to |
| 987 | position the text |
| 988 | @param paint The paint used for the text |
| 989 | */ |
reed | f7430cc | 2014-12-21 11:38:35 -0800 | [diff] [blame] | 990 | void drawTextOnPathHV(const void* text, size_t byteLength, const SkPath& path, SkScalar hOffset, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 991 | SkScalar vOffset, const SkPaint& paint); |
| 992 | |
| 993 | /** Draw the text, with origin at (x,y), using the specified paint, along |
| 994 | the specified path. The paint's Align setting determins where along the |
| 995 | path to start the text. |
| 996 | @param text The text to be drawn |
| 997 | @param byteLength The number of bytes to read from the text parameter |
| 998 | @param path The path the text should follow for its baseline |
| 999 | @param matrix (may be null) Applied to the text before it is |
| 1000 | mapped onto the path |
| 1001 | @param paint The paint used for the text |
| 1002 | */ |
reed | f7430cc | 2014-12-21 11:38:35 -0800 | [diff] [blame] | 1003 | void drawTextOnPath(const void* text, size_t byteLength, const SkPath& path, |
| 1004 | const SkMatrix* matrix, const SkPaint& paint); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1005 | |
reed | 45561a0 | 2016-07-07 12:47:17 -0700 | [diff] [blame] | 1006 | /** |
| 1007 | * Draw the text with each character/glyph individually transformed by its xform. |
| 1008 | * If cullRect is not null, it is a conservative bounds of what will be drawn |
reed | 63f30d9 | 2016-07-07 16:32:51 -0700 | [diff] [blame] | 1009 | * taking into account the xforms and the paint, and will be used to accelerate culling. |
reed | 45561a0 | 2016-07-07 12:47:17 -0700 | [diff] [blame] | 1010 | */ |
| 1011 | void drawTextRSXform(const void* text, size_t byteLength, const SkRSXform[], |
| 1012 | const SkRect* cullRect, const SkPaint& paint); |
| 1013 | |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 1014 | /** Draw the text blob, offset by (x,y), using the specified paint. |
| 1015 | @param blob The text blob to be drawn |
| 1016 | @param x The x-offset of the text being drawn |
| 1017 | @param y The y-offset of the text being drawn |
| 1018 | @param paint The paint used for the text (e.g. color, size, style) |
| 1019 | */ |
| 1020 | void drawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPaint& paint); |
reed | 2ab9057 | 2016-08-10 14:16:41 -0700 | [diff] [blame] | 1021 | void drawTextBlob(const sk_sp<SkTextBlob>& blob, SkScalar x, SkScalar y, const SkPaint& paint) { |
| 1022 | this->drawTextBlob(blob.get(), x, y, paint); |
| 1023 | } |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 1024 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1025 | /** Draw the picture into this canvas. This method effective brackets the |
| 1026 | playback of the picture's draw calls with save/restore, so the state |
djsollen@google.com | a44de96 | 2013-01-02 16:59:19 +0000 | [diff] [blame] | 1027 | of this canvas will be unchanged after this call. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1028 | @param picture The recorded drawing commands to playback into this |
| 1029 | canvas. |
| 1030 | */ |
reed | 1c2c441 | 2015-04-30 13:09:24 -0700 | [diff] [blame] | 1031 | void drawPicture(const SkPicture* picture) { |
| 1032 | this->drawPicture(picture, NULL, NULL); |
| 1033 | } |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 1034 | void drawPicture(const sk_sp<SkPicture>& picture) { |
reed | f8053da | 2016-03-17 08:14:57 -0700 | [diff] [blame] | 1035 | this->drawPicture(picture.get()); |
| 1036 | } |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 1037 | |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 1038 | /** |
| 1039 | * Draw the picture into this canvas. |
| 1040 | * |
| 1041 | * If matrix is non-null, apply that matrix to the CTM when drawing this picture. This is |
| 1042 | * logically equivalent to |
| 1043 | * save/concat/drawPicture/restore |
| 1044 | * |
| 1045 | * If paint is non-null, draw the picture into a temporary buffer, and then apply the paint's |
| 1046 | * alpha/colorfilter/imagefilter/xfermode to that buffer as it is drawn to the canvas. |
| 1047 | * This is logically equivalent to |
| 1048 | * saveLayer(paint)/drawPicture/restore |
| 1049 | */ |
| 1050 | void drawPicture(const SkPicture*, const SkMatrix* matrix, const SkPaint* paint); |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 1051 | void drawPicture(const sk_sp<SkPicture>& picture, const SkMatrix* matrix, const SkPaint* paint) { |
reed | f8053da | 2016-03-17 08:14:57 -0700 | [diff] [blame] | 1052 | this->drawPicture(picture.get(), matrix, paint); |
| 1053 | } |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 1054 | |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 1055 | #ifdef SK_EXPERIMENTAL_SHADOWING |
| 1056 | /** |
vjiaoblack | e6f5d56 | 2016-08-25 06:30:23 -0700 | [diff] [blame] | 1057 | * Draw the picture into this canvas, with shadows! |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 1058 | * |
| 1059 | * We will use the canvas's lights along with the picture information (draw depths of |
| 1060 | * objects, etc) to first create a set of shadowmaps for the light-picture pairs, and |
| 1061 | * then use that set of shadowmaps to render the scene with shadows. |
| 1062 | * |
| 1063 | * If matrix is non-null, apply that matrix to the CTM when drawing this picture. This is |
| 1064 | * logically equivalent to |
| 1065 | * save/concat/drawPicture/restore |
| 1066 | * |
| 1067 | * If paint is non-null, draw the picture into a temporary buffer, and then apply the paint's |
| 1068 | * alpha/colorfilter/imagefilter/xfermode to that buffer as it is drawn to the canvas. |
| 1069 | * This is logically equivalent to |
| 1070 | * saveLayer(paint)/drawPicture/restore |
| 1071 | * |
vjiaoblack | e6f5d56 | 2016-08-25 06:30:23 -0700 | [diff] [blame] | 1072 | * We also support using variance shadow maps for blurred shadows; the user can specify |
| 1073 | * what shadow mapping algorithm to use with params. |
| 1074 | * - Variance Shadow Mapping works by storing both the depth and depth^2 in the shadow map. |
| 1075 | * - Then, the shadow map can be blurred, and when reading from it, the fragment shader |
| 1076 | * can calculate the variance of the depth at a position by doing E(x^2) - E(x)^2. |
| 1077 | * - We can then use the depth variance and depth at a fragment to arrive at an upper bound |
| 1078 | * of the probability that the current surface is shadowed by using Chebyshev's |
| 1079 | * inequality, and then use that to shade the fragment. |
| 1080 | * |
| 1081 | * - There are a few problems with VSM. |
| 1082 | * * Light Bleeding | Areas with high variance, such as near the edges of high up rects, |
| 1083 | * will cause their shadow penumbras to overwrite otherwise solid |
| 1084 | * shadows. |
| 1085 | * * Shape Distortion | We can combat Light Bleeding by biasing the shadow (setting |
| 1086 | * mostly shaded fragments to completely shaded) and increasing |
| 1087 | * the minimum allowed variance. However, this warps and rounds |
| 1088 | * out the shape of the shadow. |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 1089 | */ |
| 1090 | void drawShadowedPicture(const SkPicture*, |
| 1091 | const SkMatrix* matrix, |
vjiaoblack | e6f5d56 | 2016-08-25 06:30:23 -0700 | [diff] [blame] | 1092 | const SkPaint* paint, |
| 1093 | const SkShadowParams& params); |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 1094 | void drawShadowedPicture(const sk_sp<SkPicture>& picture, |
| 1095 | const SkMatrix* matrix, |
vjiaoblack | e6f5d56 | 2016-08-25 06:30:23 -0700 | [diff] [blame] | 1096 | const SkPaint* paint, |
| 1097 | const SkShadowParams& params) { |
| 1098 | this->drawShadowedPicture(picture.get(), matrix, paint, params); |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 1099 | } |
| 1100 | #endif |
| 1101 | |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 1102 | /** Draw vertices from an immutable SkVertices object. |
| 1103 | |
| 1104 | @param vertices The mesh to draw. |
| 1105 | @param mode Used if both texs and colors are present and paint has a |
| 1106 | shader. In this case the colors are combined with the texture |
| 1107 | using mode, before being drawn using the paint. |
| 1108 | @param paint Specifies the shader/texture if present. |
Brian Salomon | 199fb87 | 2017-02-06 09:41:10 -0500 | [diff] [blame] | 1109 | */ |
Mike Reed | e88a1cb | 2017-03-17 09:50:46 -0400 | [diff] [blame] | 1110 | void drawVertices(const SkVertices* vertices, SkBlendMode mode, const SkPaint& paint); |
| 1111 | void drawVertices(const sk_sp<SkVertices>& vertices, SkBlendMode mode, const SkPaint& paint); |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 1112 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 1113 | /** |
| 1114 | Draw a cubic coons patch |
mtklein | 6cfa73a | 2014-08-13 13:33:49 -0700 | [diff] [blame] | 1115 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 1116 | @param cubic specifies the 4 bounding cubic bezier curves of a patch with clockwise order |
| 1117 | starting at the top left corner. |
| 1118 | @param colors specifies the colors for the corners which will be bilerp across the patch, |
| 1119 | their order is clockwise starting at the top left corner. |
mtklein | 6cfa73a | 2014-08-13 13:33:49 -0700 | [diff] [blame] | 1120 | @param texCoords specifies the texture coordinates that will be bilerp across the patch, |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 1121 | their order is the same as the colors. |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 1122 | @param mode specifies how are the colors and the textures combined if both of them are |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 1123 | present. |
dandov | 963137b | 2014-08-07 07:49:53 -0700 | [diff] [blame] | 1124 | @param paint Specifies the shader/texture if present. |
| 1125 | */ |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 1126 | void drawPatch(const SkPoint cubics[12], const SkColor colors[4], |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 1127 | const SkPoint texCoords[4], SkBlendMode mode, const SkPaint& paint); |
| 1128 | void drawPatch(const SkPoint cubics[12], const SkColor colors[4], |
| 1129 | const SkPoint texCoords[4], const SkPaint& paint) { |
| 1130 | this->drawPatch(cubics, colors, texCoords, SkBlendMode::kModulate, paint); |
| 1131 | } |
| 1132 | |
reed | 3cb3840 | 2015-02-06 08:36:15 -0800 | [diff] [blame] | 1133 | /** |
reed | 71c3c76 | 2015-06-24 10:29:17 -0700 | [diff] [blame] | 1134 | * Draw a set of sprites from the atlas. Each is specified by a tex rectangle in the |
| 1135 | * coordinate space of the atlas, and a corresponding xform which transforms the tex rectangle |
| 1136 | * into a quad. |
| 1137 | * |
| 1138 | * xform maps [0, 0, tex.width, tex.height] -> quad |
| 1139 | * |
| 1140 | * The color array is optional. When specified, each color modulates the pixels in its |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 1141 | * corresponding quad (via the specified SkBlendMode). |
reed | 71c3c76 | 2015-06-24 10:29:17 -0700 | [diff] [blame] | 1142 | * |
| 1143 | * The cullRect is optional. When specified, it must be a conservative bounds of all of the |
| 1144 | * resulting transformed quads, allowing the canvas to skip drawing if the cullRect does not |
| 1145 | * intersect the current clip. |
| 1146 | * |
| 1147 | * The paint is optional. If specified, its antialiasing, alpha, color-filter, image-filter |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 1148 | * and blendmode are used to affect each of the quads. |
reed | 71c3c76 | 2015-06-24 10:29:17 -0700 | [diff] [blame] | 1149 | */ |
| 1150 | void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 1151 | const SkColor colors[], int count, SkBlendMode, const SkRect* cullRect, |
reed | 71c3c76 | 2015-06-24 10:29:17 -0700 | [diff] [blame] | 1152 | const SkPaint* paint); |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 1153 | void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[], |
| 1154 | const SkColor colors[], int count, SkBlendMode mode, const SkRect* cullRect, |
| 1155 | const SkPaint* paint) { |
| 1156 | this->drawAtlas(atlas.get(), xform, tex, colors, count, mode, cullRect, paint); |
| 1157 | } |
reed | 71c3c76 | 2015-06-24 10:29:17 -0700 | [diff] [blame] | 1158 | void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], int count, |
| 1159 | const SkRect* cullRect, const SkPaint* paint) { |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 1160 | this->drawAtlas(atlas, xform, tex, nullptr, count, SkBlendMode::kDst, cullRect, paint); |
| 1161 | } |
| 1162 | void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[], |
| 1163 | int count, const SkRect* cullRect, const SkPaint* paint) { |
| 1164 | this->drawAtlas(atlas.get(), xform, tex, nullptr, count, SkBlendMode::kDst, |
| 1165 | cullRect, paint); |
| 1166 | } |
| 1167 | |
reed | 71c3c76 | 2015-06-24 10:29:17 -0700 | [diff] [blame] | 1168 | /** |
reed | 3cb3840 | 2015-02-06 08:36:15 -0800 | [diff] [blame] | 1169 | * Draw the contents of this drawable into the canvas. If the canvas is async |
| 1170 | * (e.g. it is recording into a picture) then the drawable will be referenced instead, |
| 1171 | * to have its draw() method called when the picture is finalized. |
| 1172 | * |
| 1173 | * If the intent is to force the contents of the drawable into this canvas immediately, |
| 1174 | * then drawable->draw(canvas) may be called. |
| 1175 | */ |
reed | a8db728 | 2015-07-07 10:22:31 -0700 | [diff] [blame] | 1176 | void drawDrawable(SkDrawable* drawable, const SkMatrix* = NULL); |
| 1177 | void drawDrawable(SkDrawable*, SkScalar x, SkScalar y); |
reed | 6a070dc | 2014-11-11 19:36:09 -0800 | [diff] [blame] | 1178 | |
reed | f70b531 | 2016-03-04 16:36:20 -0800 | [diff] [blame] | 1179 | /** |
| 1180 | * Send an "annotation" to the canvas. The annotation is a key/value pair, where the key is |
| 1181 | * a null-terminated utf8 string, and the value is a blob of data stored in an SkData |
| 1182 | * (which may be null). The annotation is associated with the specified rectangle. |
| 1183 | * |
| 1184 | * The caller still retains its ownership of the data (if any). |
| 1185 | * |
| 1186 | * Note: on may canvas types, this information is ignored, but some canvases (e.g. recording |
| 1187 | * a picture or drawing to a PDF document) will pass on this information. |
| 1188 | */ |
| 1189 | void drawAnnotation(const SkRect&, const char key[], SkData* value); |
mtklein | 0fba3b9 | 2016-04-01 04:55:51 -0700 | [diff] [blame] | 1190 | void drawAnnotation(const SkRect& rect, const char key[], const sk_sp<SkData>& value) { |
| 1191 | this->drawAnnotation(rect, key, value.get()); |
| 1192 | } |
reed | f70b531 | 2016-03-04 16:36:20 -0800 | [diff] [blame] | 1193 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1194 | ////////////////////////////////////////////////////////////////////////// |
fmalita | 7765000 | 2016-01-21 18:47:11 -0800 | [diff] [blame] | 1195 | #ifdef SK_INTERNAL |
fmalita | 53d9f1c | 2016-01-25 06:23:54 -0800 | [diff] [blame] | 1196 | #ifndef SK_SUPPORT_LEGACY_DRAWFILTER |
| 1197 | #define SK_SUPPORT_LEGACY_DRAWFILTER |
fmalita | 7765000 | 2016-01-21 18:47:11 -0800 | [diff] [blame] | 1198 | #endif |
| 1199 | #endif |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 1200 | |
fmalita | 53d9f1c | 2016-01-25 06:23:54 -0800 | [diff] [blame] | 1201 | #ifdef SK_SUPPORT_LEGACY_DRAWFILTER |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1202 | /** Get the current filter object. The filter's reference count is not |
reed@android.com | dc3381f | 2010-02-11 16:05:15 +0000 | [diff] [blame] | 1203 | affected. The filter is saved/restored, just like the matrix and clip. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1204 | @return the canvas' filter (or NULL). |
| 1205 | */ |
fmalita | 7765000 | 2016-01-21 18:47:11 -0800 | [diff] [blame] | 1206 | SK_ATTR_EXTERNALLY_DEPRECATED("getDrawFilter use is deprecated") |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1207 | SkDrawFilter* getDrawFilter() const; |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 1208 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1209 | /** Set the new filter (or NULL). Pass NULL to clear any existing filter. |
| 1210 | As a convenience, the parameter is returned. If an existing filter |
| 1211 | exists, its refcnt is decrement. If the new filter is not null, its |
reed@android.com | dc3381f | 2010-02-11 16:05:15 +0000 | [diff] [blame] | 1212 | refcnt is incremented. The filter is saved/restored, just like the |
| 1213 | matrix and clip. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1214 | @param filter the new filter (or NULL) |
| 1215 | @return the new filter |
| 1216 | */ |
fmalita | 7765000 | 2016-01-21 18:47:11 -0800 | [diff] [blame] | 1217 | SK_ATTR_EXTERNALLY_DEPRECATED("setDrawFilter use is deprecated") |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1218 | virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter); |
fmalita | 7765000 | 2016-01-21 18:47:11 -0800 | [diff] [blame] | 1219 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1220 | ////////////////////////////////////////////////////////////////////////// |
| 1221 | |
reed@google.com | 754de5f | 2014-02-24 19:38:20 +0000 | [diff] [blame] | 1222 | /** |
| 1223 | * Return true if the current clip is empty (i.e. nothing will draw). |
| 1224 | * Note: this is not always a free call, so it should not be used |
| 1225 | * more often than necessary. However, once the canvas has computed this |
| 1226 | * result, subsequent calls will be cheap (until the clip state changes, |
| 1227 | * which can happen on any clip..() or restore() call. |
| 1228 | */ |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 1229 | virtual bool isClipEmpty() const; |
reed@google.com | 754de5f | 2014-02-24 19:38:20 +0000 | [diff] [blame] | 1230 | |
commit-bot@chromium.org | 5c70cdc | 2014-03-08 03:57:19 +0000 | [diff] [blame] | 1231 | /** |
| 1232 | * Returns true if the current clip is just a (non-empty) rectangle. |
| 1233 | * Returns false if the clip is empty, or if it is complex. |
| 1234 | */ |
| 1235 | virtual bool isClipRect() const; |
| 1236 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1237 | /** Return the current matrix on the canvas. |
| 1238 | This does not account for the translate in any of the devices. |
| 1239 | @return The current matrix on the canvas. |
| 1240 | */ |
junov@chromium.org | a907ac3 | 2012-02-24 21:54:07 +0000 | [diff] [blame] | 1241 | const SkMatrix& getTotalMatrix() const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1242 | |
Mike Reed | 93b1b4f | 2017-04-05 16:21:47 -0400 | [diff] [blame] | 1243 | #ifdef SK_SUPPORT_OBSOLETE_REPLAYCLIP |
Mike Reed | 8310f0e | 2017-03-08 21:42:37 +0000 | [diff] [blame] | 1244 | typedef SkCanvasClipVisitor ClipVisitor; |
| 1245 | /** |
| 1246 | * Replays the clip operations, back to front, that have been applied to |
| 1247 | * the canvas, calling the appropriate method on the visitor for each |
| 1248 | * clip. All clips have already been transformed into device space. |
| 1249 | */ |
| 1250 | void replayClips(ClipVisitor*) const; |
Mike Reed | 93b1b4f | 2017-04-05 16:21:47 -0400 | [diff] [blame] | 1251 | #endif |
Mike Reed | 8310f0e | 2017-03-08 21:42:37 +0000 | [diff] [blame] | 1252 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1253 | /////////////////////////////////////////////////////////////////////////// |
| 1254 | |
robertphillips | 36736a2 | 2016-04-23 08:26:43 -0700 | [diff] [blame] | 1255 | // don't call |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 1256 | GrRenderTargetContext* internal_private_accessTopLayerRenderTargetContext(); |
robertphillips | 36736a2 | 2016-04-23 08:26:43 -0700 | [diff] [blame] | 1257 | |
| 1258 | // don't call |
| 1259 | static void Internal_Private_SetIgnoreSaveLayerBounds(bool); |
| 1260 | static bool Internal_Private_GetIgnoreSaveLayerBounds(); |
| 1261 | static void Internal_Private_SetTreatSpriteAsBitmap(bool); |
| 1262 | static bool Internal_Private_GetTreatSpriteAsBitmap(); |
| 1263 | |
| 1264 | // TEMP helpers until we switch virtual over to const& for src-rect |
| 1265 | void legacy_drawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst, |
| 1266 | const SkPaint* paint, |
| 1267 | SrcRectConstraint constraint = kStrict_SrcRectConstraint); |
| 1268 | void legacy_drawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst, |
| 1269 | const SkPaint* paint, |
| 1270 | SrcRectConstraint constraint = kStrict_SrcRectConstraint); |
| 1271 | |
tomhudson | cb3bd18 | 2016-05-18 07:24:16 -0700 | [diff] [blame] | 1272 | // expose minimum amount of information necessary for transitional refactoring |
| 1273 | /** |
| 1274 | * Returns CTM and clip bounds, translated from canvas coordinates to top layer coordinates. |
| 1275 | */ |
| 1276 | void temporary_internal_describeTopLayer(SkMatrix* matrix, SkIRect* clip_bounds); |
| 1277 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 1278 | /** |
| 1279 | * Returns the global clip as a region. If the clip contains AA, then only the bounds |
| 1280 | * of the clip may be returned. |
| 1281 | */ |
Mike Reed | 3726a4a | 2017-01-19 11:36:41 -0500 | [diff] [blame] | 1282 | void temporary_internal_getRgnClip(SkRegion*); |
| 1283 | |
robertphillips | da2cd8b | 2016-04-21 11:05:32 -0700 | [diff] [blame] | 1284 | protected: |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 1285 | #ifdef SK_EXPERIMENTAL_SHADOWING |
vjiaoblack | e5de130 | 2016-07-13 14:05:28 -0700 | [diff] [blame] | 1286 | /** Returns the current (cumulative) draw depth of the canvas. |
| 1287 | */ |
| 1288 | SkScalar getZ() const; |
| 1289 | |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 1290 | sk_sp<SkLights> fLights; |
| 1291 | #endif |
| 1292 | |
reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 1293 | // default impl defers to getDevice()->newSurface(info) |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 1294 | virtual sk_sp<SkSurface> onNewSurface(const SkImageInfo&, const SkSurfaceProps&); |
reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 1295 | |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 1296 | // default impl defers to its device |
reed | 884e97c | 2015-05-26 11:31:54 -0700 | [diff] [blame] | 1297 | virtual bool onPeekPixels(SkPixmap*); |
| 1298 | virtual bool onAccessTopLayerPixels(SkPixmap*); |
reed | ea5a651 | 2016-07-07 16:44:27 -0700 | [diff] [blame] | 1299 | virtual SkImageInfo onImageInfo() const; |
| 1300 | virtual bool onGetProps(SkSurfaceProps*) const; |
| 1301 | virtual void onFlush(); |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 1302 | |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 1303 | // Subclass save/restore notifiers. |
| 1304 | // Overriders should call the corresponding INHERITED method up the inheritance chain. |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 1305 | // getSaveLayerStrategy()'s return value may suppress full layer allocation. |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 1306 | enum SaveLayerStrategy { |
| 1307 | kFullLayer_SaveLayerStrategy, |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 1308 | kNoLayer_SaveLayerStrategy, |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 1309 | }; |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 1310 | |
fmalita | 6ca763f | 2014-06-17 13:52:18 -0700 | [diff] [blame] | 1311 | virtual void willSave() {} |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 1312 | // Overriders should call the corresponding INHERITED method up the inheritance chain. |
| 1313 | virtual SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) { |
| 1314 | return kFullLayer_SaveLayerStrategy; |
| 1315 | } |
commit-bot@chromium.org | fc6dfba | 2014-05-14 13:13:44 +0000 | [diff] [blame] | 1316 | virtual void willRestore() {} |
mtklein | 6cfa73a | 2014-08-13 13:33:49 -0700 | [diff] [blame] | 1317 | virtual void didRestore() {} |
commit-bot@chromium.org | fc6dfba | 2014-05-14 13:13:44 +0000 | [diff] [blame] | 1318 | virtual void didConcat(const SkMatrix&) {} |
| 1319 | virtual void didSetMatrix(const SkMatrix&) {} |
mtklein | cbdf007 | 2016-08-19 09:05:27 -0700 | [diff] [blame] | 1320 | virtual void didTranslate(SkScalar dx, SkScalar dy) { |
| 1321 | this->didConcat(SkMatrix::MakeTrans(dx, dy)); |
| 1322 | } |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 1323 | |
| 1324 | #ifdef SK_EXPERIMENTAL_SHADOWING |
vjiaoblack | e5de130 | 2016-07-13 14:05:28 -0700 | [diff] [blame] | 1325 | virtual void didTranslateZ(SkScalar) {} |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 1326 | #endif |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 1327 | |
Mike Reed | 42e8c53 | 2017-01-23 14:09:13 -0500 | [diff] [blame] | 1328 | virtual SkRect onGetLocalClipBounds() const; |
| 1329 | virtual SkIRect onGetDeviceClipBounds() const; |
| 1330 | |
| 1331 | |
reed | f70b531 | 2016-03-04 16:36:20 -0800 | [diff] [blame] | 1332 | virtual void onDrawAnnotation(const SkRect&, const char key[], SkData* value); |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 1333 | virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&); |
| 1334 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 1335 | virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, |
| 1336 | SkScalar y, const SkPaint& paint); |
skia.committer@gmail.com | b0430d0 | 2014-04-24 03:05:07 +0000 | [diff] [blame] | 1337 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 1338 | virtual void onDrawPosText(const void* text, size_t byteLength, |
| 1339 | const SkPoint pos[], const SkPaint& paint); |
skia.committer@gmail.com | b0430d0 | 2014-04-24 03:05:07 +0000 | [diff] [blame] | 1340 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 1341 | virtual void onDrawPosTextH(const void* text, size_t byteLength, |
| 1342 | const SkScalar xpos[], SkScalar constY, |
| 1343 | const SkPaint& paint); |
skia.committer@gmail.com | b0430d0 | 2014-04-24 03:05:07 +0000 | [diff] [blame] | 1344 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 1345 | virtual void onDrawTextOnPath(const void* text, size_t byteLength, |
| 1346 | const SkPath& path, const SkMatrix* matrix, |
| 1347 | const SkPaint& paint); |
reed | 45561a0 | 2016-07-07 12:47:17 -0700 | [diff] [blame] | 1348 | virtual void onDrawTextRSXform(const void* text, size_t byteLength, const SkRSXform[], |
| 1349 | const SkRect* cullRect, const SkPaint& paint); |
mtklein | 6cfa73a | 2014-08-13 13:33:49 -0700 | [diff] [blame] | 1350 | |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 1351 | virtual void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, |
| 1352 | const SkPaint& paint); |
| 1353 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 1354 | virtual void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], |
Mike Reed | faba371 | 2016-11-03 14:45:31 -0400 | [diff] [blame] | 1355 | const SkPoint texCoords[4], SkBlendMode, const SkPaint& paint); |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 1356 | |
reed | a8db728 | 2015-07-07 10:22:31 -0700 | [diff] [blame] | 1357 | virtual void onDrawDrawable(SkDrawable*, const SkMatrix*); |
reed | 6a070dc | 2014-11-11 19:36:09 -0800 | [diff] [blame] | 1358 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 1359 | virtual void onDrawPaint(const SkPaint&); |
| 1360 | virtual void onDrawRect(const SkRect&, const SkPaint&); |
msarett | 44df651 | 2016-08-25 13:54:30 -0700 | [diff] [blame] | 1361 | virtual void onDrawRegion(const SkRegion& region, const SkPaint& paint); |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 1362 | virtual void onDrawOval(const SkRect&, const SkPaint&); |
bsalomon | ac3aa24 | 2016-08-19 11:25:19 -0700 | [diff] [blame] | 1363 | virtual void onDrawArc(const SkRect&, SkScalar startAngle, SkScalar sweepAngle, bool useCenter, |
| 1364 | const SkPaint&); |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 1365 | virtual void onDrawRRect(const SkRRect&, const SkPaint&); |
| 1366 | virtual void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&); |
Mike Reed | e88a1cb | 2017-03-17 09:50:46 -0400 | [diff] [blame] | 1367 | virtual void onDrawVerticesObject(const SkVertices*, SkBlendMode, const SkPaint&); |
reed | 71c3c76 | 2015-06-24 10:29:17 -0700 | [diff] [blame] | 1368 | virtual void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[], |
Mike Reed | faba371 | 2016-11-03 14:45:31 -0400 | [diff] [blame] | 1369 | int count, SkBlendMode, const SkRect* cull, const SkPaint*); |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 1370 | virtual void onDrawPath(const SkPath&, const SkPaint&); |
| 1371 | virtual void onDrawImage(const SkImage*, SkScalar dx, SkScalar dy, const SkPaint*); |
reed | 562fe47 | 2015-07-28 07:35:14 -0700 | [diff] [blame] | 1372 | virtual void onDrawImageRect(const SkImage*, const SkRect*, const SkRect&, const SkPaint*, |
| 1373 | SrcRectConstraint); |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 1374 | virtual void onDrawImageNine(const SkImage*, const SkIRect& center, const SkRect& dst, |
| 1375 | const SkPaint*); |
msarett | 1688206 | 2016-08-16 09:31:08 -0700 | [diff] [blame] | 1376 | virtual void onDrawImageLattice(const SkImage*, const Lattice& lattice, const SkRect& dst, |
| 1377 | const SkPaint*); |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 1378 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 1379 | virtual void onDrawBitmap(const SkBitmap&, SkScalar dx, SkScalar dy, const SkPaint*); |
| 1380 | virtual void onDrawBitmapRect(const SkBitmap&, const SkRect*, const SkRect&, const SkPaint*, |
reed | 562fe47 | 2015-07-28 07:35:14 -0700 | [diff] [blame] | 1381 | SrcRectConstraint); |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 1382 | virtual void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst, |
| 1383 | const SkPaint*); |
msarett | 1688206 | 2016-08-16 09:31:08 -0700 | [diff] [blame] | 1384 | virtual void onDrawBitmapLattice(const SkBitmap&, const Lattice& lattice, const SkRect& dst, |
| 1385 | const SkPaint*); |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 1386 | |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 1387 | enum ClipEdgeStyle { |
| 1388 | kHard_ClipEdgeStyle, |
| 1389 | kSoft_ClipEdgeStyle |
| 1390 | }; |
| 1391 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 1392 | virtual void onClipRect(const SkRect& rect, SkClipOp, ClipEdgeStyle); |
| 1393 | virtual void onClipRRect(const SkRRect& rrect, SkClipOp, ClipEdgeStyle); |
| 1394 | virtual void onClipPath(const SkPath& path, SkClipOp, ClipEdgeStyle); |
| 1395 | virtual void onClipRegion(const SkRegion& deviceRgn, SkClipOp); |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 1396 | |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 1397 | virtual void onDiscard(); |
| 1398 | |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 1399 | virtual void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*); |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 1400 | |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 1401 | #ifdef SK_EXPERIMENTAL_SHADOWING |
| 1402 | virtual void onDrawShadowedPicture(const SkPicture*, |
| 1403 | const SkMatrix*, |
vjiaoblack | e6f5d56 | 2016-08-25 06:30:23 -0700 | [diff] [blame] | 1404 | const SkPaint*, |
| 1405 | const SkShadowParams& params); |
vjiaoblack | 95302da | 2016-07-21 10:25:54 -0700 | [diff] [blame] | 1406 | #endif |
Herb Derby | 1356978 | 2016-10-06 14:33:43 -0400 | [diff] [blame] | 1407 | |
junov@chromium.org | a907ac3 | 2012-02-24 21:54:07 +0000 | [diff] [blame] | 1408 | // Clip rectangle bounds. Called internally by saveLayer. |
| 1409 | // returns false if the entire rectangle is entirely clipped out |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 1410 | // If non-NULL, The imageFilter parameter will be used to expand the clip |
| 1411 | // and offscreen bounds for any margin required by the filter DAG. |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 1412 | bool clipRectBounds(const SkRect* bounds, SaveLayerFlags, SkIRect* intersection, |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 1413 | const SkImageFilter* imageFilter = NULL); |
junov@chromium.org | a907ac3 | 2012-02-24 21:54:07 +0000 | [diff] [blame] | 1414 | |
reed | c83a297 | 2015-07-16 07:40:45 -0700 | [diff] [blame] | 1415 | private: |
reed | 3aafe11 | 2016-08-18 12:45:34 -0700 | [diff] [blame] | 1416 | /** After calling saveLayer(), there can be any number of devices that make |
| 1417 | up the top-most drawing area. LayerIter can be used to iterate through |
| 1418 | those devices. Note that the iterator is only valid until the next API |
| 1419 | call made on the canvas. Ownership of all pointers in the iterator stays |
| 1420 | with the canvas, so none of them should be modified or deleted. |
| 1421 | */ |
| 1422 | class LayerIter /*: SkNoncopyable*/ { |
| 1423 | public: |
| 1424 | /** Initialize iterator with canvas, and set values for 1st device */ |
| 1425 | LayerIter(SkCanvas*); |
| 1426 | ~LayerIter(); |
| 1427 | |
| 1428 | /** Return true if the iterator is done */ |
| 1429 | bool done() const { return fDone; } |
| 1430 | /** Cycle to the next device */ |
| 1431 | void next(); |
| 1432 | |
| 1433 | // These reflect the current device in the iterator |
| 1434 | |
| 1435 | SkBaseDevice* device() const; |
| 1436 | const SkMatrix& matrix() const; |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 1437 | void clip(SkRegion*) const; |
reed | 3aafe11 | 2016-08-18 12:45:34 -0700 | [diff] [blame] | 1438 | const SkPaint& paint() const; |
| 1439 | int x() const; |
| 1440 | int y() const; |
| 1441 | |
| 1442 | private: |
| 1443 | // used to embed the SkDrawIter object directly in our instance, w/o |
| 1444 | // having to expose that class def to the public. There is an assert |
| 1445 | // in our constructor to ensure that fStorage is large enough |
| 1446 | // (though needs to be a compile-time-assert!). We use intptr_t to work |
| 1447 | // safely with 32 and 64 bit machines (to ensure the storage is enough) |
| 1448 | intptr_t fStorage[32]; |
| 1449 | class SkDrawIter* fImpl; // this points at fStorage |
| 1450 | SkPaint fDefaultPaint; |
| 1451 | bool fDone; |
| 1452 | }; |
Herb Derby | 1356978 | 2016-10-06 14:33:43 -0400 | [diff] [blame] | 1453 | |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 1454 | static bool BoundsAffectsClip(SaveLayerFlags); |
reed | bada188 | 2015-12-21 13:09:44 -0800 | [diff] [blame] | 1455 | static SaveLayerFlags LegacySaveFlagsToSaveLayerFlags(uint32_t legacySaveFlags); |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 1456 | |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 1457 | static void DrawDeviceWithFilter(SkBaseDevice* src, const SkImageFilter* filter, |
Mike Reed | c42a1cd | 2017-02-14 14:25:14 -0500 | [diff] [blame] | 1458 | SkBaseDevice* dst, const SkIPoint& dstOrigin, |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 1459 | const SkMatrix& ctm); |
reed | a2217ef | 2016-07-20 06:04:34 -0700 | [diff] [blame] | 1460 | |
reed | c83a297 | 2015-07-16 07:40:45 -0700 | [diff] [blame] | 1461 | enum ShaderOverrideOpacity { |
| 1462 | kNone_ShaderOverrideOpacity, //!< there is no overriding shader (bitmap or image) |
| 1463 | kOpaque_ShaderOverrideOpacity, //!< the overriding shader is opaque |
| 1464 | kNotOpaque_ShaderOverrideOpacity, //!< the overriding shader may not be opaque |
| 1465 | }; |
| 1466 | |
reed@google.com | 97af1a6 | 2012-08-28 12:19:02 +0000 | [diff] [blame] | 1467 | // notify our surface (if we have one) that we are about to draw, so it |
| 1468 | // can perform copy-on-write or invalidate any cached images |
reed | c83a297 | 2015-07-16 07:40:45 -0700 | [diff] [blame] | 1469 | void predrawNotify(bool willOverwritesEntireSurface = false); |
| 1470 | void predrawNotify(const SkRect* rect, const SkPaint* paint, ShaderOverrideOpacity); |
| 1471 | void predrawNotify(const SkRect* rect, const SkPaint* paint, bool shaderOverrideIsOpaque) { |
| 1472 | this->predrawNotify(rect, paint, shaderOverrideIsOpaque ? kOpaque_ShaderOverrideOpacity |
| 1473 | : kNotOpaque_ShaderOverrideOpacity); |
| 1474 | } |
reed@google.com | 97af1a6 | 2012-08-28 12:19:02 +0000 | [diff] [blame] | 1475 | |
Florin Malita | 0ed3b64 | 2017-01-13 16:56:38 +0000 | [diff] [blame] | 1476 | SkBaseDevice* getDevice() const; |
| 1477 | SkBaseDevice* getTopDevice() const; |
| 1478 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1479 | class MCRec; |
| 1480 | |
| 1481 | SkDeque fMCStack; |
| 1482 | // points to top of stack |
| 1483 | MCRec* fMCRec; |
| 1484 | // the first N recs that can fit here mean we won't call malloc |
reed | b679ca8 | 2015-04-07 04:40:48 -0700 | [diff] [blame] | 1485 | enum { |
reed | a499f90 | 2015-05-01 09:34:31 -0700 | [diff] [blame] | 1486 | kMCRecSize = 128, // most recent measurement |
reed | 31b80a9 | 2015-11-16 13:22:24 -0800 | [diff] [blame] | 1487 | kMCRecCount = 32, // common depth for save/restores |
Stan Iliev | 5f1bb0a | 2016-12-12 17:39:55 -0500 | [diff] [blame] | 1488 | kDeviceCMSize = 184, // most recent measurement |
reed | b679ca8 | 2015-04-07 04:40:48 -0700 | [diff] [blame] | 1489 | }; |
| 1490 | intptr_t fMCRecStorage[kMCRecSize * kMCRecCount / sizeof(intptr_t)]; |
reed | a499f90 | 2015-05-01 09:34:31 -0700 | [diff] [blame] | 1491 | intptr_t fDeviceCMStorage[kDeviceCMSize / sizeof(intptr_t)]; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1492 | |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 1493 | const SkSurfaceProps fProps; |
| 1494 | |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 1495 | int fSaveCount; // value returned by getSaveCount() |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1496 | |
mike@reedtribe.org | 74bb77e | 2012-09-26 02:24:45 +0000 | [diff] [blame] | 1497 | SkMetaData* fMetaData; |
Mike Reed | 356f7c2 | 2017-01-10 11:58:39 -0500 | [diff] [blame] | 1498 | std::unique_ptr<SkRasterHandleAllocator> fAllocator; |
mike@reedtribe.org | 74bb77e | 2012-09-26 02:24:45 +0000 | [diff] [blame] | 1499 | |
reed@google.com | 97af1a6 | 2012-08-28 12:19:02 +0000 | [diff] [blame] | 1500 | SkSurface_Base* fSurfaceBase; |
| 1501 | SkSurface_Base* getSurfaceBase() const { return fSurfaceBase; } |
| 1502 | void setSurfaceBase(SkSurface_Base* sb) { |
| 1503 | fSurfaceBase = sb; |
| 1504 | } |
| 1505 | friend class SkSurface_Base; |
junov@chromium.org | 45c3db8 | 2013-04-11 17:52:05 +0000 | [diff] [blame] | 1506 | friend class SkSurface_Gpu; |
skia.committer@gmail.com | fc84359 | 2012-10-11 02:01:14 +0000 | [diff] [blame] | 1507 | |
Stan Iliev | 5f1bb0a | 2016-12-12 17:39:55 -0500 | [diff] [blame] | 1508 | SkIRect fClipRestrictionRect = SkIRect::MakeEmpty(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1509 | |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 1510 | void doSave(); |
| 1511 | void checkForDeferredSave(); |
reed | 8c30a81 | 2016-04-20 16:36:51 -0700 | [diff] [blame] | 1512 | void internalSetMatrix(const SkMatrix&); |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 1513 | |
reed@google.com | 9c135db | 2014-03-12 18:28:35 +0000 | [diff] [blame] | 1514 | friend class SkDrawIter; // needs setupDrawForLayerDevice() |
reed@google.com | 8926b16 | 2012-03-23 15:36:36 +0000 | [diff] [blame] | 1515 | friend class AutoDrawLooper; |
commit-bot@chromium.org | 2a67e12 | 2014-05-19 13:53:10 +0000 | [diff] [blame] | 1516 | friend class SkDebugCanvas; // needs experimental fAllowSimplifyClip |
reed | 52d9ac6 | 2014-06-30 09:05:34 -0700 | [diff] [blame] | 1517 | friend class SkSurface_Raster; // needs getDevice() |
Florin Malita | 439ace9 | 2016-12-02 12:05:41 -0500 | [diff] [blame] | 1518 | friend class SkRecorder; // resetForNextPicture |
| 1519 | friend class SkLiteRecorder; // resetForNextPicture |
| 1520 | friend class SkNoDrawCanvas; // InitFlags |
fmalita | 2d97bc1 | 2014-11-20 10:44:58 -0800 | [diff] [blame] | 1521 | friend class SkPictureImageFilter; // SkCanvas(SkBaseDevice*, SkSurfaceProps*, InitFlags) |
reed | c83a297 | 2015-07-16 07:40:45 -0700 | [diff] [blame] | 1522 | friend class SkPictureRecord; // predrawNotify (why does it need it? <reed>) |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 1523 | friend class SkPicturePlayback; // SaveFlagsToSaveLayerFlags |
Herb Derby | 1356978 | 2016-10-06 14:33:43 -0400 | [diff] [blame] | 1524 | friend class SkDeferredCanvas; // For use of resetForNextPicture |
Matt Sarett | 22886c4 | 2016-11-22 11:31:41 -0500 | [diff] [blame] | 1525 | friend class SkOverdrawCanvas; |
Mike Reed | 356f7c2 | 2017-01-10 11:58:39 -0500 | [diff] [blame] | 1526 | friend class SkRasterHandleAllocator; |
piotaixr | b5fae93 | 2014-09-24 13:03:30 -0700 | [diff] [blame] | 1527 | |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 1528 | enum InitFlags { |
| 1529 | kDefault_InitFlags = 0, |
| 1530 | kConservativeRasterClip_InitFlag = 1 << 0, |
| 1531 | }; |
reed | 78e2768 | 2014-11-19 08:04:34 -0800 | [diff] [blame] | 1532 | SkCanvas(const SkIRect& bounds, InitFlags); |
robertphillips | fcf7829 | 2015-06-19 11:49:52 -0700 | [diff] [blame] | 1533 | SkCanvas(SkBaseDevice* device, InitFlags); |
Mike Reed | 356f7c2 | 2017-01-10 11:58:39 -0500 | [diff] [blame] | 1534 | SkCanvas(const SkBitmap&, std::unique_ptr<SkRasterHandleAllocator>, |
| 1535 | SkRasterHandleAllocator::Handle); |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 1536 | |
mtklein | feaadee | 2015-04-08 11:25:48 -0700 | [diff] [blame] | 1537 | void resetForNextPicture(const SkIRect& bounds); |
| 1538 | |
reed | 8f2e791 | 2014-09-04 12:45:18 -0700 | [diff] [blame] | 1539 | // needs gettotalclip() |
tfarina | a5414c4 | 2014-10-10 06:19:09 -0700 | [diff] [blame] | 1540 | friend class SkCanvasStateUtils; |
piotaixr | b5fae93 | 2014-09-24 13:03:30 -0700 | [diff] [blame] | 1541 | |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 1542 | // call this each time we attach ourselves to a device |
| 1543 | // - constructor |
| 1544 | // - internalSaveLayer |
| 1545 | void setupDevice(SkBaseDevice*); |
| 1546 | |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 1547 | SkBaseDevice* init(SkBaseDevice*, InitFlags); |
reed@google.com | f0b5e11 | 2011-09-07 11:57:34 +0000 | [diff] [blame] | 1548 | |
commit-bot@chromium.org | 403f8d7 | 2014-02-17 15:24:26 +0000 | [diff] [blame] | 1549 | /** |
senorblanco | afc7cce | 2016-02-02 18:44:15 -0800 | [diff] [blame] | 1550 | * Gets the bounds of the top level layer in global canvas coordinates. We don't want this |
bsalomon@google.com | 4ebe382 | 2014-02-26 20:22:32 +0000 | [diff] [blame] | 1551 | * to be public because it exposes decisions about layer sizes that are internal to the canvas. |
| 1552 | */ |
senorblanco | afc7cce | 2016-02-02 18:44:15 -0800 | [diff] [blame] | 1553 | SkIRect getTopLayerBounds() const; |
commit-bot@chromium.org | 403f8d7 | 2014-02-17 15:24:26 +0000 | [diff] [blame] | 1554 | |
reed@google.com | 7112173 | 2012-09-18 15:14:33 +0000 | [diff] [blame] | 1555 | void internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, |
commit-bot@chromium.org | eed779d | 2013-08-16 10:24:37 +0000 | [diff] [blame] | 1556 | const SkRect& dst, const SkPaint* paint, |
reed | a5517e2 | 2015-07-14 10:54:12 -0700 | [diff] [blame] | 1557 | SrcRectConstraint); |
bsalomon@google.com | fa6ac93 | 2011-10-05 19:57:55 +0000 | [diff] [blame] | 1558 | void internalDrawPaint(const SkPaint& paint); |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 1559 | void internalSaveLayer(const SaveLayerRec&, SaveLayerStrategy); |
reed | 7503d60 | 2016-07-15 14:23:29 -0700 | [diff] [blame] | 1560 | void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*); |
bsalomon@google.com | fa6ac93 | 2011-10-05 19:57:55 +0000 | [diff] [blame] | 1561 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1562 | // shared by save() and saveLayer() |
reed | 2ff1fce | 2014-12-11 07:07:37 -0800 | [diff] [blame] | 1563 | void internalSave(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1564 | void internalRestore(); |
reed@google.com | 4b22602 | 2011-01-11 18:32:13 +0000 | [diff] [blame] | 1565 | |
reed | c83a297 | 2015-07-16 07:40:45 -0700 | [diff] [blame] | 1566 | /* |
| 1567 | * Returns true if drawing the specified rect (or all if it is null) with the specified |
| 1568 | * paint (or default if null) would overwrite the entire root device of the canvas |
| 1569 | * (i.e. the canvas' surface if it had one). |
| 1570 | */ |
| 1571 | bool wouldOverwriteEntireSurface(const SkRect*, const SkPaint*, ShaderOverrideOpacity) const; |
| 1572 | |
reed | 262a71b | 2015-12-05 13:07:27 -0800 | [diff] [blame] | 1573 | /** |
| 1574 | * Returns true if the paint's imagefilter can be invoked directly, without needed a layer. |
| 1575 | */ |
| 1576 | bool canDrawBitmapAsSprite(SkScalar x, SkScalar y, int w, int h, const SkPaint&); |
reed | c83a297 | 2015-07-16 07:40:45 -0700 | [diff] [blame] | 1577 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 1578 | /** |
| 1579 | * Returns true if the clip (for any active layer) contains antialiasing. |
| 1580 | * If the clip is empty, this will return false. |
Mike Reed | 46784be | 2017-01-15 20:02:32 -0500 | [diff] [blame] | 1581 | */ |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 1582 | bool androidFramework_isClipAA() const; |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 1583 | |
| 1584 | /** |
| 1585 | * Keep track of the device clip bounds and if the matrix is scale-translate. This allows |
| 1586 | * us to do a fast quick reject in the common case. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1587 | */ |
msarett | 9637ea9 | 2016-08-18 14:03:30 -0700 | [diff] [blame] | 1588 | bool fIsScaleTranslate; |
msarett | fbfa258 | 2016-08-12 08:29:08 -0700 | [diff] [blame] | 1589 | SkRect fDeviceClipBounds; |
| 1590 | |
caryclark@google.com | 8f0a7b8 | 2012-11-07 14:54:49 +0000 | [diff] [blame] | 1591 | bool fAllowSoftClip; |
caryclark@google.com | 45a75fb | 2013-04-25 13:34:40 +0000 | [diff] [blame] | 1592 | bool fAllowSimplifyClip; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1593 | |
reed@google.com | 5c3d147 | 2011-02-22 19:12:23 +0000 | [diff] [blame] | 1594 | class AutoValidateClip : ::SkNoncopyable { |
| 1595 | public: |
| 1596 | explicit AutoValidateClip(SkCanvas* canvas) : fCanvas(canvas) { |
| 1597 | fCanvas->validateClip(); |
| 1598 | } |
| 1599 | ~AutoValidateClip() { fCanvas->validateClip(); } |
| 1600 | |
| 1601 | private: |
| 1602 | const SkCanvas* fCanvas; |
| 1603 | }; |
| 1604 | |
| 1605 | #ifdef SK_DEBUG |
| 1606 | void validateClip() const; |
| 1607 | #else |
| 1608 | void validateClip() const {} |
| 1609 | #endif |
robertphillips@google.com | 15e9d3e | 2012-06-21 20:25:03 +0000 | [diff] [blame] | 1610 | |
| 1611 | typedef SkRefCnt INHERITED; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1612 | }; |
| 1613 | |
| 1614 | /** Stack helper class to automatically call restoreToCount() on the canvas |
| 1615 | when this object goes out of scope. Use this to guarantee that the canvas |
| 1616 | is restored to a known state. |
| 1617 | */ |
| 1618 | class SkAutoCanvasRestore : SkNoncopyable { |
| 1619 | public: |
commit-bot@chromium.org | 2887119 | 2013-10-14 15:28:01 +0000 | [diff] [blame] | 1620 | SkAutoCanvasRestore(SkCanvas* canvas, bool doSave) : fCanvas(canvas), fSaveCount(0) { |
| 1621 | if (fCanvas) { |
| 1622 | fSaveCount = canvas->getSaveCount(); |
| 1623 | if (doSave) { |
| 1624 | canvas->save(); |
| 1625 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1626 | } |
| 1627 | } |
| 1628 | ~SkAutoCanvasRestore() { |
reed@google.com | f6c9a5b | 2012-11-20 15:12:21 +0000 | [diff] [blame] | 1629 | if (fCanvas) { |
| 1630 | fCanvas->restoreToCount(fSaveCount); |
| 1631 | } |
| 1632 | } |
| 1633 | |
| 1634 | /** |
| 1635 | * Perform the restore now, instead of waiting for the destructor. Will |
| 1636 | * only do this once. |
| 1637 | */ |
| 1638 | void restore() { |
| 1639 | if (fCanvas) { |
| 1640 | fCanvas->restoreToCount(fSaveCount); |
| 1641 | fCanvas = NULL; |
| 1642 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1643 | } |
| 1644 | |
| 1645 | private: |
| 1646 | SkCanvas* fCanvas; |
| 1647 | int fSaveCount; |
| 1648 | }; |
commit-bot@chromium.org | e61a86c | 2013-11-18 16:03:59 +0000 | [diff] [blame] | 1649 | #define SkAutoCanvasRestore(...) SK_REQUIRE_LOCAL_VAR(SkAutoCanvasRestore) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1650 | |
Mike Reed | 93b1b4f | 2017-04-05 16:21:47 -0400 | [diff] [blame] | 1651 | #ifdef SK_SUPPORT_OBSOLETE_REPLAYCLIP |
Mike Reed | 8310f0e | 2017-03-08 21:42:37 +0000 | [diff] [blame] | 1652 | class SkCanvasClipVisitor { |
| 1653 | public: |
| 1654 | virtual ~SkCanvasClipVisitor(); |
| 1655 | virtual void clipRect(const SkRect&, SkClipOp, bool antialias) = 0; |
| 1656 | virtual void clipRRect(const SkRRect&, SkClipOp, bool antialias) = 0; |
| 1657 | virtual void clipPath(const SkPath&, SkClipOp, bool antialias) = 0; |
| 1658 | }; |
Mike Reed | 93b1b4f | 2017-04-05 16:21:47 -0400 | [diff] [blame] | 1659 | #endif |
Mike Reed | 8310f0e | 2017-03-08 21:42:37 +0000 | [diff] [blame] | 1660 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1661 | #endif |