blob: 9f342e1fabaef18444fcf828e3db3944baa7c835 [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2006 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00003 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00004 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00006 */
7
Cary Clark91499542018-06-08 11:49:19 -04008/* Generated by tools/bookmaker from include/core/SkCanvas.h and docs/SkCanvas_Reference.bmh
Cary Clark153e76d2018-08-28 11:48:28 -04009 on 2018-08-28 10:32:58. Additional documentation and examples can be found at:
Cary Clark91499542018-06-08 11:49:19 -040010 https://skia.org/user/api/SkCanvas_Reference
11
12 You may edit either file directly. Structural changes to public interfaces require
13 editing both files. After editing docs/SkCanvas_Reference.bmh, run:
14 bookmaker -b docs -i include/core/SkCanvas.h -p
15 to create an updated version of this file.
16 */
17
reed@android.com8a1c16f2008-12-17 15:59:43 +000018#ifndef SkCanvas_DEFINED
19#define SkCanvas_DEFINED
20
Hal Canary22be4c42018-06-12 12:37:31 -040021#include "../private/SkMacros.h"
reed374772b2016-10-05 17:33:02 -070022#include "SkBlendMode.h"
reed73603f32016-09-20 08:42:38 -070023#include "SkClipOp.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000024#include "SkDeque.h"
25#include "SkPaint.h"
Mike Reed356f7c22017-01-10 11:58:39 -050026#include "SkRasterHandleAllocator.h"
reed4a8126e2014-09-22 07:29:03 -070027#include "SkSurfaceProps.h"
Ruiqi Maoc97a3392018-08-15 10:44:19 -040028#include "SkVertices.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000029
bungemand3ebb482015-08-05 13:57:49 -070030class GrContext;
Brian Osman11052242016-10-27 14:47:55 -040031class GrRenderTargetContext;
Stan Iliev73d8fd92017-08-02 15:36:24 -040032class SkAndroidFrameworkUtils;
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000033class SkBaseDevice;
Mike Reed267be7f2017-02-13 09:32:54 -050034class SkBitmap;
reedf70b5312016-03-04 16:36:20 -080035class SkData;
reed@android.com8a1c16f2008-12-17 15:59:43 +000036class SkDraw;
reed3cb38402015-02-06 08:36:15 -080037class SkDrawable;
Mike Reed4204da22017-05-17 08:53:36 -040038struct SkDrawShadowRec;
Mike Reed358fcad2018-11-23 15:27:51 -050039class SkFont;
Herb Derby59d997a2018-06-07 12:44:09 -040040class SkGlyphRunBuilder;
Mike Reed267be7f2017-02-13 09:32:54 -050041class SkImage;
bungemand3ebb482015-08-05 13:57:49 -070042class SkImageFilter;
mike@reedtribe.org74bb77e2012-09-26 02:24:45 +000043class SkMetaData;
bungemand3ebb482015-08-05 13:57:49 -070044class SkPath;
reed@android.com8a1c16f2008-12-17 15:59:43 +000045class SkPicture;
bungemand3ebb482015-08-05 13:57:49 -070046class SkPixmap;
Mike Reed267be7f2017-02-13 09:32:54 -050047class SkRegion;
reed@google.com4ed0fb72012-12-12 20:48:18 +000048class SkRRect;
reed71c3c762015-06-24 10:29:17 -070049struct SkRSXform;
reed@google.com76f10a32014-02-05 15:32:21 +000050class SkSurface;
reed@google.com97af1a62012-08-28 12:19:02 +000051class SkSurface_Base;
fmalita00d5c2c2014-08-21 08:53:26 -070052class SkTextBlob;
reedfa35f8e2014-09-04 12:14:36 -070053
reed@android.com8a1c16f2008-12-17 15:59:43 +000054/** \class SkCanvas
Cary Clarkb7da7232017-09-01 13:49:54 -040055 SkCanvas provides an interface for drawing, and how the drawing is clipped and transformed.
56 SkCanvas contains a stack of SkMatrix and clip values.
reed@android.com8a1c16f2008-12-17 15:59:43 +000057
Cary Clarkb7da7232017-09-01 13:49:54 -040058 SkCanvas and SkPaint together provide the state to draw into SkSurface or SkBaseDevice.
59 Each SkCanvas draw call transforms the geometry of the object by the concatenation of all
60 SkMatrix values in the stack. The transformed geometry is clipped by the intersection
61 of all of clip values in the stack. The SkCanvas draw calls use SkPaint to supply drawing
62 state such as color, SkTypeface, text size, stroke width, SkShader and so on.
reed@android.com8a1c16f2008-12-17 15:59:43 +000063
Cary Clarkb7da7232017-09-01 13:49:54 -040064 To draw to a pixel-based destination, create raster surface or GPU surface.
65 Request SkCanvas from SkSurface to obtain the interface to draw.
66 SkCanvas generated by raster surface draws to memory visible to the CPU.
67 SkCanvas generated by GPU surface uses Vulkan or OpenGL to draw to the GPU.
68
Cary Clark82456492018-10-31 10:54:50 -040069 To draw to a document, obtain SkCanvas from SVG canvas, document PDF, or SkPictureRecorder.
Cary Clark462505f2018-05-30 09:20:29 -040070 SkDocument based SkCanvas and other SkCanvas subclasses reference SkBaseDevice describing the
Cary Clarkb7da7232017-09-01 13:49:54 -040071 destination.
72
73 SkCanvas can be constructed to draw to SkBitmap without first creating raster surface.
74 This approach may be deprecated in the future.
reed@android.com8a1c16f2008-12-17 15:59:43 +000075*/
Hal Canary14f73902018-06-14 14:57:12 -040076class SK_API SkCanvas {
reedbada1882015-12-21 13:09:44 -080077 enum PrivateSaveLayerFlags {
caryclark952538e2016-02-26 05:01:42 -080078 kDontClipToLayer_PrivateSaveLayerFlag = 1U << 31,
reedbada1882015-12-21 13:09:44 -080079 };
reed73603f32016-09-20 08:42:38 -070080
reed@android.com8a1c16f2008-12-17 15:59:43 +000081public:
Cary Clarkb7da7232017-09-01 13:49:54 -040082
83 /** Allocates raster SkCanvas that will draw directly into pixels.
Cary Clarkb7da7232017-09-01 13:49:54 -040084
85 SkCanvas is returned if all parameters are valid.
86 Valid parameters include:
87 info dimensions are zero or positive;
88 info contains SkColorType and SkAlphaType supported by raster surface;
89 pixels is not nullptr;
90 rowBytes is zero or large enough to contain info width pixels of SkColorType.
91
92 Pass zero for rowBytes to compute rowBytes from info width and size of pixel.
93 If rowBytes is greater than zero, it must be equal to or greater than
94 info width times bytes required for SkColorType.
95
96 Pixel buffer size should be info height times computed rowBytes.
Cary Clark2823f9f2018-01-03 10:00:34 -050097 Pixels are not initialized.
98 To access pixels after drawing, call flush() or peekPixels().
Cary Clarkb7da7232017-09-01 13:49:54 -040099
Cary Clark8a02b0b2017-09-21 12:28:43 -0400100 @param info width, height, SkColorType, SkAlphaType, SkColorSpace, of raster surface;
Cary Clarkb7da7232017-09-01 13:49:54 -0400101 width, or height, or both, may be zero
102 @param pixels pointer to destination pixels buffer
103 @param rowBytes interval from one SkSurface row to the next, or zero
Cary Clark2823f9f2018-01-03 10:00:34 -0500104 @param props LCD striping orientation and setting for device independent fonts;
105 may be nullptr
Cary Clarkb7da7232017-09-01 13:49:54 -0400106 @return SkCanvas if all parameters are valid; otherwise, nullptr
107 */
Cary Clark0418a882017-05-10 09:07:42 -0400108 static std::unique_ptr<SkCanvas> MakeRasterDirect(const SkImageInfo& info, void* pixels,
Mike Reed12f77342017-11-08 11:19:52 -0500109 size_t rowBytes,
110 const SkSurfaceProps* props = nullptr);
Mike Reed5df49342016-11-12 08:06:55 -0600111
Cary Clarkb7da7232017-09-01 13:49:54 -0400112 /** Allocates raster SkCanvas specified by inline image specification. Subsequent SkCanvas
113 calls draw into pixels.
114 SkColorType is set to kN32_SkColorType.
115 SkAlphaType is set to kPremul_SkAlphaType.
116 To access pixels after drawing, call flush() or peekPixels().
117
118 SkCanvas is returned if all parameters are valid.
119 Valid parameters include:
120 width and height are zero or positive;
121 pixels is not nullptr;
122 rowBytes is zero or large enough to contain width pixels of kN32_SkColorType.
123
124 Pass zero for rowBytes to compute rowBytes from width and size of pixel.
125 If rowBytes is greater than zero, it must be equal to or greater than
126 width times bytes required for SkColorType.
127
128 Pixel buffer size should be height times rowBytes.
129
130 @param width pixel column count on raster surface created; must be zero or greater
Cary Clarkcc309eb2017-10-30 11:48:35 -0400131 @param height pixel row count on raster surface created; must be zero or greater
Cary Clarkb7da7232017-09-01 13:49:54 -0400132 @param pixels pointer to destination pixels buffer; buffer size should be height
133 times rowBytes
134 @param rowBytes interval from one SkSurface row to the next, or zero
135 @return SkCanvas if all parameters are valid; otherwise, nullptr
136 */
Mike Reed5df49342016-11-12 08:06:55 -0600137 static std::unique_ptr<SkCanvas> MakeRasterDirectN32(int width, int height, SkPMColor* pixels,
138 size_t rowBytes) {
139 return MakeRasterDirect(SkImageInfo::MakeN32Premul(width, height), pixels, rowBytes);
140 }
141
Cary Clark8a02b0b2017-09-21 12:28:43 -0400142 /** Creates an empty SkCanvas with no backing device or pixels, with
Cary Clarkb7da7232017-09-01 13:49:54 -0400143 a width and height of zero.
144
Cary Clark8a02b0b2017-09-21 12:28:43 -0400145 @return empty SkCanvas
Cary Clarkb7da7232017-09-01 13:49:54 -0400146 */
reed@google.comcde92112011-07-06 20:00:52 +0000147 SkCanvas();
vandebo@chromium.org8d84fac2010-10-13 22:13:05 +0000148
Cary Clarkb7da7232017-09-01 13:49:54 -0400149 /** Creates SkCanvas of the specified dimensions without a SkSurface.
Cary Clark462505f2018-05-30 09:20:29 -0400150 Used by subclasses with custom implementations for draw member functions.
Cary Clarkb7da7232017-09-01 13:49:54 -0400151
Cary Clark8a02b0b2017-09-21 12:28:43 -0400152 If props equals nullptr, SkSurfaceProps are created with
153 SkSurfaceProps::InitType settings, which choose the pixel striping
154 direction and order. Since a platform may dynamically change its direction when
155 the device is rotated, and since a platform may have multiple monitors with
156 different characteristics, it is best not to rely on this legacy behavior.
Cary Clarkb7da7232017-09-01 13:49:54 -0400157
158 @param width zero or greater
159 @param height zero or greater
160 @param props LCD striping orientation and setting for device independent fonts;
161 may be nullptr
162 @return SkCanvas placeholder with dimensions
163 */
Ben Wagnera93a14a2017-08-28 10:34:05 -0400164 SkCanvas(int width, int height, const SkSurfaceProps* props = nullptr);
commit-bot@chromium.orge2543102014-01-31 19:42:58 +0000165
Cary Clarkcb6bef02018-11-29 12:05:25 -0500166 /** Private. For internal use only.
vandebo@chromium.org8d84fac2010-10-13 22:13:05 +0000167 */
Herb Derbyefe39bc2018-05-01 17:06:20 -0400168 explicit SkCanvas(sk_sp<SkBaseDevice> device);
vandebo@chromium.org8d84fac2010-10-13 22:13:05 +0000169
Cary Clark7651c162018-07-13 08:21:59 -0400170 /** Constructs a canvas that draws into bitmap.
Cary Clarkb7da7232017-09-01 13:49:54 -0400171 Sets SkSurfaceProps::kLegacyFontHost_InitType in constructed SkSurface.
172
173 SkBitmap is copied so that subsequently editing bitmap will not affect
174 constructed SkCanvas.
175
176 May be deprecated in the future.
177
178 @param bitmap width, height, SkColorType, SkAlphaType, and pixel
179 storage of raster surface
180 @return SkCanvas that can be used to draw into bitmap
reed@android.com8a1c16f2008-12-17 15:59:43 +0000181 */
182 explicit SkCanvas(const SkBitmap& bitmap);
fmalita3d91aad2015-02-02 05:25:04 -0800183
Matt Sarett31f99ce2017-04-11 08:46:01 -0400184#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
Cary Clarkabaffd82018-11-15 08:25:12 -0500185 /** Private.
186 */
Matt Sarett31f99ce2017-04-11 08:46:01 -0400187 enum class ColorBehavior {
Cary Clark462505f2018-05-30 09:20:29 -0400188 kLegacy, //!< placeholder
Matt Sarett31f99ce2017-04-11 08:46:01 -0400189 };
190
Cary Clarkabaffd82018-11-15 08:25:12 -0500191 /** Private. For use by Android framework only.
Cary Clarkb7da7232017-09-01 13:49:54 -0400192
193 @param bitmap specifies a bitmap for the canvas to draw into
194 @param behavior specializes this constructor; value is unused
195 @return SkCanvas that can be used to draw into bitmap
196 */
Cary Clark304f9d42017-05-13 13:35:35 -0400197 SkCanvas(const SkBitmap& bitmap, ColorBehavior behavior);
Matt Sarett31f99ce2017-04-11 08:46:01 -0400198#endif
199
Cary Clark7651c162018-07-13 08:21:59 -0400200 /** Constructs a canvas that draws into bitmap.
Cary Clarkb7da7232017-09-01 13:49:54 -0400201 Use props to match the device characteristics, like LCD striping.
202
203 bitmap is copied so that subsequently editing bitmap will not affect
204 constructed SkCanvas.
205
206 @param bitmap width, height, SkColorType, SkAlphaType,
207 and pixel storage of raster surface
208 @param props order and orientation of RGB striping; and whether to use
209 device independent fonts
210 @return SkCanvas that can be used to draw into bitmap
fmalita3d91aad2015-02-02 05:25:04 -0800211 */
212 SkCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props);
213
Cary Clark462505f2018-05-30 09:20:29 -0400214 /** Draws saved layers, if any.
Cary Clark75959392018-02-27 10:22:04 -0500215 Frees up resources used by SkCanvas.
Cary Clarkb7da7232017-09-01 13:49:54 -0400216 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000217 virtual ~SkCanvas();
218
Cary Clarkb7da7232017-09-01 13:49:54 -0400219 /** Returns storage to associate additional data with the canvas.
220 The storage is freed when SkCanvas is deleted.
221
222 @return storage that can be read from and written to
223 */
mike@reedtribe.org74bb77e2012-09-26 02:24:45 +0000224 SkMetaData& getMetaData();
225
Cary Clarkb7da7232017-09-01 13:49:54 -0400226 /** Returns SkImageInfo for SkCanvas. If SkCanvas is not associated with raster surface or
227 GPU surface, returned SkColorType is set to kUnknown_SkColorType.
228
229 @return dimensions and SkColorType of SkCanvas
230 */
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000231 SkImageInfo imageInfo() const;
232
Cary Clark7651c162018-07-13 08:21:59 -0400233 /** Copies SkSurfaceProps, if SkCanvas is associated with raster surface or
234 GPU surface, and returns true. Otherwise, returns false and leave props unchanged.
Cary Clarkb7da7232017-09-01 13:49:54 -0400235
236 @param props storage for writable SkSurfaceProps
237 @return true if SkSurfaceProps was copied
238 */
Cary Clark0418a882017-05-10 09:07:42 -0400239 bool getProps(SkSurfaceProps* props) const;
brianosman898235c2016-04-06 07:38:23 -0700240
Cary Clarkb7da7232017-09-01 13:49:54 -0400241 /** Triggers the immediate execution of all pending draw operations.
242 If SkCanvas is associated with GPU surface, resolves all pending GPU operations.
Cary Clark2823f9f2018-01-03 10:00:34 -0500243 If SkCanvas is associated with raster surface, has no effect; raster draw
244 operations are never deferred.
Cary Clarkb7da7232017-09-01 13:49:54 -0400245 */
junov@chromium.orgbf6c1e42012-01-30 14:53:22 +0000246 void flush();
247
Cary Clark8a02b0b2017-09-21 12:28:43 -0400248 /** Gets the size of the base or root layer in global canvas coordinates. The
249 origin of the base layer is always (0,0). The area available for drawing may be
Cary Clarkb7da7232017-09-01 13:49:54 -0400250 smaller (due to clipping or saveLayer).
251
Cary Clark8a02b0b2017-09-21 12:28:43 -0400252 @return integral width and height of base layer
Cary Clarkb7da7232017-09-01 13:49:54 -0400253 */
tomhudson68260fa2015-03-23 07:22:40 -0700254 virtual SkISize getBaseLayerSize() const;
bsalomon@google.com4ebe3822014-02-26 20:22:32 +0000255
Cary Clarkb7da7232017-09-01 13:49:54 -0400256 /** Creates SkSurface matching info and props, and associates it with SkCanvas.
257 Returns nullptr if no match found.
258
259 If props is nullptr, matches SkSurfaceProps in SkCanvas. If props is nullptr and SkCanvas
260 does not have SkSurfaceProps, creates SkSurface with default SkSurfaceProps.
261
Cary Clark8a02b0b2017-09-21 12:28:43 -0400262 @param info width, height, SkColorType, SkAlphaType, and SkColorSpace
Cary Clarkb7da7232017-09-01 13:49:54 -0400263 @param props SkSurfaceProps to match; may be nullptr to match SkCanvas
264 @return SkSurface matching info and props, or nullptr if no match is available
265 */
Cary Clark304f9d42017-05-13 13:35:35 -0400266 sk_sp<SkSurface> makeSurface(const SkImageInfo& info, const SkSurfaceProps* props = nullptr);
bsalomon@google.come97f0852011-06-17 13:10:25 +0000267
Cary Clarkb7da7232017-09-01 13:49:54 -0400268 /** Returns GPU context of the GPU surface associated with SkCanvas.
269
270 @return GPU context, if available; nullptr otherwise
271 */
Brian Osmand2da87d2017-05-08 16:02:43 -0400272 virtual GrContext* getGrContext();
commit-bot@chromium.org644629c2013-11-21 06:21:58 +0000273
Cary Clarkb7da7232017-09-01 13:49:54 -0400274 /** Returns the pixel base address, SkImageInfo, rowBytes, and origin if the pixels
275 can be read directly. The returned address is only valid
276 while SkCanvas is in scope and unchanged. Any SkCanvas call or SkSurface call
277 may invalidate the returned address and other returned values.
reed@google.com4b226022011-01-11 18:32:13 +0000278
Cary Clarkb7da7232017-09-01 13:49:54 -0400279 If pixels are inaccessible, info, rowBytes, and origin are unchanged.
280
281 @param info storage for writable pixels' SkImageInfo; may be nullptr
282 @param rowBytes storage for writable pixels' row bytes; may be nullptr
Cary Clarkcc309eb2017-10-30 11:48:35 -0400283 @param origin storage for SkCanvas top layer origin, its top-left corner;
Cary Clarkb7da7232017-09-01 13:49:54 -0400284 may be nullptr
285 @return address of pixels, or nullptr if inaccessible
286 */
Ben Wagnera93a14a2017-08-28 10:34:05 -0400287 void* accessTopLayerPixels(SkImageInfo* info, size_t* rowBytes, SkIPoint* origin = nullptr);
reed@google.com9c135db2014-03-12 18:28:35 +0000288
Cary Clarkb7da7232017-09-01 13:49:54 -0400289 /** Returns custom context that tracks the SkMatrix and clip.
290
291 Use SkRasterHandleAllocator to blend Skia drawing with custom drawing, typically performed
Cary Clarkcc309eb2017-10-30 11:48:35 -0400292 by the host platform user interface. The custom context returned is generated by
Cary Clarkb7da7232017-09-01 13:49:54 -0400293 SkRasterHandleAllocator::MakeCanvas, which creates a custom canvas with raster storage for
294 the drawing destination.
295
296 @return context of custom allocation
297 */
Mike Reed356f7c22017-01-10 11:58:39 -0500298 SkRasterHandleAllocator::Handle accessTopRasterHandle() const;
299
Cary Clarkb7da7232017-09-01 13:49:54 -0400300 /** Returns true if SkCanvas has direct access to its pixels.
301
302 Pixels are readable when SkBaseDevice is raster. Pixels are not readable when SkCanvas
303 is returned from GPU surface, returned by SkDocument::beginPage, returned by
304 SkPictureRecorder::beginRecording, or SkCanvas is the base of a utility class
Brian Osman46fe9c72018-03-09 15:44:34 -0500305 like SkDebugCanvas.
Cary Clarkb7da7232017-09-01 13:49:54 -0400306
307 pixmap is valid only while SkCanvas is in scope and unchanged. Any
308 SkCanvas or SkSurface call may invalidate the pixmap values.
309
Cary Clarkcc309eb2017-10-30 11:48:35 -0400310 @param pixmap storage for pixel state if pixels are readable; otherwise, ignored
Cary Clarkb7da7232017-09-01 13:49:54 -0400311 @return true if SkCanvas has direct access to pixels
312 */
Cary Clark0418a882017-05-10 09:07:42 -0400313 bool peekPixels(SkPixmap* pixmap);
reed6ceeebd2016-03-09 14:26:26 -0800314
Cary Clarkcc309eb2017-10-30 11:48:35 -0400315 /** Copies SkRect of pixels from SkCanvas into dstPixels. SkMatrix and clip are
Cary Clark2823f9f2018-01-03 10:00:34 -0500316 ignored.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400317
Cary Clark2823f9f2018-01-03 10:00:34 -0500318 Source SkRect corners are (srcX, srcY) and (imageInfo().width(), imageInfo().height()).
319 Destination SkRect corners are (0, 0) and (dstInfo.width(), dstInfo.height()).
Cary Clark8a02b0b2017-09-21 12:28:43 -0400320 Copies each readable pixel intersecting both rectangles, without scaling,
321 converting to dstInfo.colorType() and dstInfo.alphaType() if required.
322
323 Pixels are readable when SkBaseDevice is raster, or backed by a GPU.
324 Pixels are not readable when SkCanvas is returned by SkDocument::beginPage,
325 returned by SkPictureRecorder::beginRecording, or SkCanvas is the base of a utility
Brian Osman46fe9c72018-03-09 15:44:34 -0500326 class like SkDebugCanvas.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400327
328 The destination pixel storage must be allocated by the caller.
329
330 Pixel values are converted only if SkColorType and SkAlphaType
331 do not match. Only pixels within both source and destination rectangles
Cary Clarkcc309eb2017-10-30 11:48:35 -0400332 are copied. dstPixels contents outside SkRect intersection are unchanged.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400333
334 Pass negative values for srcX or srcY to offset pixels across or down destination.
335
336 Does not copy, and returns false if:
337 - Source and destination rectangles do not intersect.
338 - SkCanvas pixels could not be converted to dstInfo.colorType() or dstInfo.alphaType().
339 - SkCanvas pixels are not readable; for instance, SkCanvas is document-based.
340 - dstRowBytes is too small to contain one row of pixels.
Cary Clarkb7da7232017-09-01 13:49:54 -0400341
342 @param dstInfo width, height, SkColorType, and SkAlphaType of dstPixels
343 @param dstPixels storage for pixels; dstInfo.height() times dstRowBytes, or larger
344 @param dstRowBytes size of one destination row; dstInfo.width() times pixel size, or larger
Cary Clarkca6a2452018-06-14 13:21:08 -0400345 @param srcX offset into readable pixels on x-axis; may be negative
346 @param srcY offset into readable pixels on y-axis; may be negative
Cary Clarkb7da7232017-09-01 13:49:54 -0400347 @return true if pixels were copied
348 */
reedb184f7f2014-07-13 04:32:32 -0700349 bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
350 int srcX, int srcY);
Cary Clarkb7da7232017-09-01 13:49:54 -0400351
Cary Clarkcc309eb2017-10-30 11:48:35 -0400352 /** Copies SkRect of pixels from SkCanvas into pixmap. SkMatrix and clip are
Cary Clark2823f9f2018-01-03 10:00:34 -0500353 ignored.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400354
Cary Clark2823f9f2018-01-03 10:00:34 -0500355 Source SkRect corners are (srcX, srcY) and (imageInfo().width(), imageInfo().height()).
356 Destination SkRect corners are (0, 0) and (pixmap.width(), pixmap.height()).
Cary Clark8a02b0b2017-09-21 12:28:43 -0400357 Copies each readable pixel intersecting both rectangles, without scaling,
358 converting to pixmap.colorType() and pixmap.alphaType() if required.
359
360 Pixels are readable when SkBaseDevice is raster, or backed by a GPU.
361 Pixels are not readable when SkCanvas is returned by SkDocument::beginPage,
362 returned by SkPictureRecorder::beginRecording, or SkCanvas is the base of a utility
Brian Osman46fe9c72018-03-09 15:44:34 -0500363 class like SkDebugCanvas.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400364
365 Caller must allocate pixel storage in pixmap if needed.
366
367 Pixel values are converted only if SkColorType and SkAlphaType
Cary Clark75959392018-02-27 10:22:04 -0500368 do not match. Only pixels within both source and destination SkRect
Cary Clarkcc309eb2017-10-30 11:48:35 -0400369 are copied. pixmap pixels contents outside SkRect intersection are unchanged.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400370
371 Pass negative values for srcX or srcY to offset pixels across or down pixmap.
372
373 Does not copy, and returns false if:
374 - Source and destination rectangles do not intersect.
375 - SkCanvas pixels could not be converted to pixmap.colorType() or pixmap.alphaType().
376 - SkCanvas pixels are not readable; for instance, SkCanvas is document-based.
377 - SkPixmap pixels could not be allocated.
378 - pixmap.rowBytes() is too small to contain one row of pixels.
Cary Clarkb7da7232017-09-01 13:49:54 -0400379
380 @param pixmap storage for pixels copied from SkCanvas
Cary Clarkca6a2452018-06-14 13:21:08 -0400381 @param srcX offset into readable pixels on x-axis; may be negative
382 @param srcY offset into readable pixels on y-axis; may be negative
Cary Clarkb7da7232017-09-01 13:49:54 -0400383 @return true if pixels were copied
384 */
Cary Clark0418a882017-05-10 09:07:42 -0400385 bool readPixels(const SkPixmap& pixmap, int srcX, int srcY);
Cary Clarkb7da7232017-09-01 13:49:54 -0400386
Cary Clarkcc309eb2017-10-30 11:48:35 -0400387 /** Copies SkRect of pixels from SkCanvas into bitmap. SkMatrix and clip are
Cary Clark2823f9f2018-01-03 10:00:34 -0500388 ignored.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400389
Cary Clark2823f9f2018-01-03 10:00:34 -0500390 Source SkRect corners are (srcX, srcY) and (imageInfo().width(), imageInfo().height()).
Cary Clarkcc309eb2017-10-30 11:48:35 -0400391 Destination SkRect corners are (0, 0) and (bitmap.width(), bitmap.height()).
Cary Clark8a02b0b2017-09-21 12:28:43 -0400392 Copies each readable pixel intersecting both rectangles, without scaling,
393 converting to bitmap.colorType() and bitmap.alphaType() if required.
394
395 Pixels are readable when SkBaseDevice is raster, or backed by a GPU.
396 Pixels are not readable when SkCanvas is returned by SkDocument::beginPage,
397 returned by SkPictureRecorder::beginRecording, or SkCanvas is the base of a utility
Brian Osman46fe9c72018-03-09 15:44:34 -0500398 class like SkDebugCanvas.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400399
400 Caller must allocate pixel storage in bitmap if needed.
401
402 SkBitmap values are converted only if SkColorType and SkAlphaType
403 do not match. Only pixels within both source and destination rectangles
Cary Clarkcc309eb2017-10-30 11:48:35 -0400404 are copied. SkBitmap pixels outside SkRect intersection are unchanged.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400405
406 Pass negative values for srcX or srcY to offset pixels across or down bitmap.
407
408 Does not copy, and returns false if:
409 - Source and destination rectangles do not intersect.
410 - SkCanvas pixels could not be converted to bitmap.colorType() or bitmap.alphaType().
411 - SkCanvas pixels are not readable; for instance, SkCanvas is document-based.
412 - bitmap pixels could not be allocated.
413 - bitmap.rowBytes() is too small to contain one row of pixels.
Cary Clarkb7da7232017-09-01 13:49:54 -0400414
415 @param bitmap storage for pixels copied from SkCanvas
Cary Clarkca6a2452018-06-14 13:21:08 -0400416 @param srcX offset into readable pixels on x-axis; may be negative
417 @param srcY offset into readable pixels on y-axis; may be negative
Cary Clarkb7da7232017-09-01 13:49:54 -0400418 @return true if pixels were copied
419 */
Cary Clark304f9d42017-05-13 13:35:35 -0400420 bool readPixels(const SkBitmap& bitmap, int srcX, int srcY);
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000421
Cary Clarkcc309eb2017-10-30 11:48:35 -0400422 /** Copies SkRect from pixels to SkCanvas. SkMatrix and clip are ignored.
423 Source SkRect corners are (0, 0) and (info.width(), info.height()).
424 Destination SkRect corners are (x, y) and
425 (imageInfo().width(), imageInfo().height()).
Cary Clark8a02b0b2017-09-21 12:28:43 -0400426
427 Copies each readable pixel intersecting both rectangles, without scaling,
Cary Clarkcc309eb2017-10-30 11:48:35 -0400428 converting to imageInfo().colorType() and imageInfo().alphaType() if required.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400429
430 Pixels are writable when SkBaseDevice is raster, or backed by a GPU.
431 Pixels are not writable when SkCanvas is returned by SkDocument::beginPage,
432 returned by SkPictureRecorder::beginRecording, or SkCanvas is the base of a utility
Brian Osman46fe9c72018-03-09 15:44:34 -0500433 class like SkDebugCanvas.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400434
435 Pixel values are converted only if SkColorType and SkAlphaType
436 do not match. Only pixels within both source and destination rectangles
Cary Clarkcc309eb2017-10-30 11:48:35 -0400437 are copied. SkCanvas pixels outside SkRect intersection are unchanged.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400438
439 Pass negative values for x or y to offset pixels to the left or
440 above SkCanvas pixels.
441
442 Does not copy, and returns false if:
443 - Source and destination rectangles do not intersect.
Cary Clark75959392018-02-27 10:22:04 -0500444 - pixels could not be converted to SkCanvas imageInfo().colorType() or
445 imageInfo().alphaType().
Cary Clark8a02b0b2017-09-21 12:28:43 -0400446 - SkCanvas pixels are not writable; for instance, SkCanvas is document-based.
447 - rowBytes is too small to contain one row of pixels.
Cary Clarkb7da7232017-09-01 13:49:54 -0400448
449 @param info width, height, SkColorType, and SkAlphaType of pixels
450 @param pixels pixels to copy, of size info.height() times rowBytes, or larger
Cary Clark8a02b0b2017-09-21 12:28:43 -0400451 @param rowBytes size of one row of pixels; info.width() times pixel size, or larger
Cary Clarkca6a2452018-06-14 13:21:08 -0400452 @param x offset into SkCanvas writable pixels on x-axis; may be negative
453 @param y offset into SkCanvas writable pixels on y-axis; may be negative
Cary Clarkb7da7232017-09-01 13:49:54 -0400454 @return true if pixels were written to SkCanvas
455 */
Cary Clark0418a882017-05-10 09:07:42 -0400456 bool writePixels(const SkImageInfo& info, const void* pixels, size_t rowBytes, int x, int y);
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +0000457
Cary Clarkcc309eb2017-10-30 11:48:35 -0400458 /** Copies SkRect from pixels to SkCanvas. SkMatrix and clip are ignored.
459 Source SkRect corners are (0, 0) and (bitmap.width(), bitmap.height()).
Cary Clark8a02b0b2017-09-21 12:28:43 -0400460
Cary Clarkcc309eb2017-10-30 11:48:35 -0400461 Destination SkRect corners are (x, y) and
462 (imageInfo().width(), imageInfo().height()).
Cary Clark8a02b0b2017-09-21 12:28:43 -0400463
464 Copies each readable pixel intersecting both rectangles, without scaling,
Cary Clarkcc309eb2017-10-30 11:48:35 -0400465 converting to imageInfo().colorType() and imageInfo().alphaType() if required.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400466
467 Pixels are writable when SkBaseDevice is raster, or backed by a GPU.
468 Pixels are not writable when SkCanvas is returned by SkDocument::beginPage,
469 returned by SkPictureRecorder::beginRecording, or SkCanvas is the base of a utility
Brian Osman46fe9c72018-03-09 15:44:34 -0500470 class like SkDebugCanvas.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400471
472 Pixel values are converted only if SkColorType and SkAlphaType
473 do not match. Only pixels within both source and destination rectangles
Cary Clarkcc309eb2017-10-30 11:48:35 -0400474 are copied. SkCanvas pixels outside SkRect intersection are unchanged.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400475
476 Pass negative values for x or y to offset pixels to the left or
477 above SkCanvas pixels.
478
479 Does not copy, and returns false if:
480 - Source and destination rectangles do not intersect.
481 - bitmap does not have allocated pixels.
Cary Clark75959392018-02-27 10:22:04 -0500482 - bitmap pixels could not be converted to SkCanvas imageInfo().colorType() or
483 imageInfo().alphaType().
Cary Clark8a02b0b2017-09-21 12:28:43 -0400484 - SkCanvas pixels are not writable; for instance, SkCanvas is document based.
485 - bitmap pixels are inaccessible; for instance, bitmap wraps a texture.
Cary Clarkb7da7232017-09-01 13:49:54 -0400486
487 @param bitmap contains pixels copied to SkCanvas
Cary Clark82456492018-10-31 10:54:50 -0400488 @param x offset into SkCanvas writable pixels on x-axis; may be negative
489 @param y offset into SkCanvas writable pixels on y-axis; may be negative
Cary Clarkb7da7232017-09-01 13:49:54 -0400490 @return true if pixels were written to SkCanvas
491 */
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +0000492 bool writePixels(const SkBitmap& bitmap, int x, int y);
reed@google.com4b226022011-01-11 18:32:13 +0000493
Ben Wagner2c312c42018-06-27 14:46:46 -0400494 /** Saves SkMatrix and clip.
Cary Clark7651c162018-07-13 08:21:59 -0400495 Calling restore() discards changes to SkMatrix and clip,
496 restoring the SkMatrix and clip to their state when save() was called.
vandebo@chromium.org8d84fac2010-10-13 22:13:05 +0000497
Cary Clarkb7da7232017-09-01 13:49:54 -0400498 SkMatrix may be changed by translate(), scale(), rotate(), skew(), concat(), setMatrix(),
499 and resetMatrix(). Clip may be changed by clipRect(), clipRRect(), clipPath(), clipRegion().
commit-bot@chromium.orgd70fa202014-04-24 21:51:58 +0000500
Cary Clarkb7da7232017-09-01 13:49:54 -0400501 Saved SkCanvas state is put on a stack; multiple calls to save() should be balance
502 by an equal number of calls to restore().
503
504 Call restoreToCount() with result to restore this and subsequent saves.
505
506 @return depth of saved stack
commit-bot@chromium.orgd70fa202014-04-24 21:51:58 +0000507 */
508 int save();
509
Ben Wagner2c312c42018-06-27 14:46:46 -0400510 /** Saves SkMatrix and clip, and allocates a SkBitmap for subsequent drawing.
511 Calling restore() discards changes to SkMatrix and clip, and draws the SkBitmap.
Cary Clarkb7da7232017-09-01 13:49:54 -0400512
513 SkMatrix may be changed by translate(), scale(), rotate(), skew(), concat(),
514 setMatrix(), and resetMatrix(). Clip may be changed by clipRect(), clipRRect(),
515 clipPath(), clipRegion().
516
517 SkRect bounds suggests but does not define the SkBitmap size. To clip drawing to
518 a specific rectangle, use clipRect().
519
Cary Clark462505f2018-05-30 09:20:29 -0400520 Optional SkPaint paint applies alpha, SkColorFilter, SkImageFilter, and
Cary Clarkb7da7232017-09-01 13:49:54 -0400521 SkBlendMode when restore() is called.
522
523 Call restoreToCount() with returned value to restore this and subsequent saves.
524
Cary Clark8a02b0b2017-09-21 12:28:43 -0400525 @param bounds hint to limit the size of the layer; may be nullptr
526 @param paint graphics state for layer; may be nullptr
Cary Clarkb7da7232017-09-01 13:49:54 -0400527 @return depth of saved stack
commit-bot@chromium.orgd70fa202014-04-24 21:51:58 +0000528 */
529 int saveLayer(const SkRect* bounds, const SkPaint* paint);
Cary Clarkb7da7232017-09-01 13:49:54 -0400530
Ben Wagner2c312c42018-06-27 14:46:46 -0400531 /** Saves SkMatrix and clip, and allocates a SkBitmap for subsequent drawing.
532 Calling restore() discards changes to SkMatrix and clip, and draws the SkBitmap.
Cary Clarkb7da7232017-09-01 13:49:54 -0400533
534 SkMatrix may be changed by translate(), scale(), rotate(), skew(), concat(),
535 setMatrix(), and resetMatrix(). Clip may be changed by clipRect(), clipRRect(),
536 clipPath(), clipRegion().
537
Cary Clark8a02b0b2017-09-21 12:28:43 -0400538 SkRect bounds suggests but does not define the layer size. To clip drawing to
Cary Clarkb7da7232017-09-01 13:49:54 -0400539 a specific rectangle, use clipRect().
540
Cary Clark462505f2018-05-30 09:20:29 -0400541 Optional SkPaint paint applies alpha, SkColorFilter, SkImageFilter, and
Cary Clarkb7da7232017-09-01 13:49:54 -0400542 SkBlendMode when restore() is called.
543
544 Call restoreToCount() with returned value to restore this and subsequent saves.
545
Cary Clark8a02b0b2017-09-21 12:28:43 -0400546 @param bounds hint to limit the size of layer; may be nullptr
547 @param paint graphics state for layer; may be nullptr
Cary Clarkb7da7232017-09-01 13:49:54 -0400548 @return depth of saved stack
549 */
reed021f6312015-08-09 19:41:13 -0700550 int saveLayer(const SkRect& bounds, const SkPaint* paint) {
551 return this->saveLayer(&bounds, paint);
552 }
commit-bot@chromium.orgd70fa202014-04-24 21:51:58 +0000553
Ben Wagner2c312c42018-06-27 14:46:46 -0400554 /** Saves SkMatrix and clip, and allocates SkBitmap for subsequent drawing.
Cary Clarkb7da7232017-09-01 13:49:54 -0400555
Cary Clark7651c162018-07-13 08:21:59 -0400556 Calling restore() discards changes to SkMatrix and clip,
557 and blends layer with alpha opacity onto prior layer.
Cary Clarkb7da7232017-09-01 13:49:54 -0400558
559 SkMatrix may be changed by translate(), scale(), rotate(), skew(), concat(),
560 setMatrix(), and resetMatrix(). Clip may be changed by clipRect(), clipRRect(),
561 clipPath(), clipRegion().
562
Cary Clark8a02b0b2017-09-21 12:28:43 -0400563 SkRect bounds suggests but does not define layer size. To clip drawing to
Cary Clarkb7da7232017-09-01 13:49:54 -0400564 a specific rectangle, use clipRect().
565
566 alpha of zero is fully transparent, 255 is fully opaque.
567
568 Call restoreToCount() with returned value to restore this and subsequent saves.
569
Cary Clark8a02b0b2017-09-21 12:28:43 -0400570 @param bounds hint to limit the size of layer; may be nullptr
571 @param alpha opacity of layer
Cary Clarkb7da7232017-09-01 13:49:54 -0400572 @return depth of saved stack
commit-bot@chromium.orgd70fa202014-04-24 21:51:58 +0000573 */
574 int saveLayerAlpha(const SkRect* bounds, U8CPU alpha);
575
Cary Clark462505f2018-05-30 09:20:29 -0400576 /** \enum SkCanvas::SaveLayerFlagsSet
Cary Clarkb7da7232017-09-01 13:49:54 -0400577 SaveLayerFlags provides options that may be used in any combination in SaveLayerRec,
Cary Clark462505f2018-05-30 09:20:29 -0400578 defining how layer allocated by saveLayer() operates. It may be set to zero,
579 kPreserveLCDText_SaveLayerFlag, kInitWithPrevious_SaveLayerFlag, or both flags.
Cary Clarkb7da7232017-09-01 13:49:54 -0400580 */
Cary Clarkd98f78c2018-04-26 08:32:37 -0400581 enum SaveLayerFlagsSet {
Florin Malita07e4adf2019-01-07 16:34:18 -0500582 // kPreserveLCDText_SaveLayerFlag = 1 << 1, (no longer used)
Cary Clark462505f2018-05-30 09:20:29 -0400583 kInitWithPrevious_SaveLayerFlag = 1 << 2, //!< initializes with previous contents
584 kMaskAgainstCoverage_EXPERIMENTAL_DONT_USE_SaveLayerFlag =
585 1 << 3, //!< experimental: do not use
Mike Reed910ca0f2018-04-25 13:04:05 -0400586
reedbada1882015-12-21 13:09:44 -0800587#ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
Cary Clark462505f2018-05-30 09:20:29 -0400588 kDontClipToLayer_Legacy_SaveLayerFlag =
Cary Clarkabaffd82018-11-15 08:25:12 -0500589 kDontClipToLayer_PrivateSaveLayerFlag, //!< deprecated
reedbada1882015-12-21 13:09:44 -0800590#endif
reed4960eee2015-12-18 07:09:18 -0800591 };
Cary Clarkb7da7232017-09-01 13:49:54 -0400592
reed4960eee2015-12-18 07:09:18 -0800593 typedef uint32_t SaveLayerFlags;
594
Cary Clarkb7da7232017-09-01 13:49:54 -0400595 /** \struct SkCanvas::SaveLayerRec
Cary Clarkcc309eb2017-10-30 11:48:35 -0400596 SaveLayerRec contains the state used to create the layer.
Cary Clarkb7da7232017-09-01 13:49:54 -0400597 */
reed4960eee2015-12-18 07:09:18 -0800598 struct SaveLayerRec {
Cary Clarkb7da7232017-09-01 13:49:54 -0400599
600 /** Sets fBounds, fPaint, and fBackdrop to nullptr. Clears fSaveLayerFlags.
601
602 @return empty SaveLayerRec
603 */
Florin Malita53f77bd2017-04-28 13:48:37 -0400604 SaveLayerRec() {}
Cary Clarkb7da7232017-09-01 13:49:54 -0400605
606 /** Sets fBounds, fPaint, and fSaveLayerFlags; sets fBackdrop to nullptr.
607
Cary Clark8a02b0b2017-09-21 12:28:43 -0400608 @param bounds layer dimensions; may be nullptr
609 @param paint applied to layer when overlaying prior layer; may be nullptr
610 @param saveLayerFlags SaveLayerRec options to modify layer
Cary Clark82456492018-10-31 10:54:50 -0400611 @return SaveLayerRec with empty fBackdrop
Cary Clarkb7da7232017-09-01 13:49:54 -0400612 */
reed4960eee2015-12-18 07:09:18 -0800613 SaveLayerRec(const SkRect* bounds, const SkPaint* paint, SaveLayerFlags saveLayerFlags = 0)
614 : fBounds(bounds)
615 , fPaint(paint)
reedbfd5f172016-01-07 11:28:08 -0800616 , fSaveLayerFlags(saveLayerFlags)
617 {}
Cary Clarkb7da7232017-09-01 13:49:54 -0400618
619 /** Sets fBounds, fPaint, fBackdrop, and fSaveLayerFlags.
620
Cary Clark8a02b0b2017-09-21 12:28:43 -0400621 @param bounds layer dimensions; may be nullptr
622 @param paint applied to layer when overlaying prior layer;
Cary Clarkb7da7232017-09-01 13:49:54 -0400623 may be nullptr
Cary Clark8a02b0b2017-09-21 12:28:43 -0400624 @param backdrop prior layer copied with SkImageFilter; may be nullptr
625 @param saveLayerFlags SaveLayerRec options to modify layer
Cary Clarkb7da7232017-09-01 13:49:54 -0400626 @return SaveLayerRec fully specified
627 */
reedbfd5f172016-01-07 11:28:08 -0800628 SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop,
Florin Malita25b37432017-05-01 10:58:40 -0400629 SaveLayerFlags saveLayerFlags)
630 : fBounds(bounds)
631 , fPaint(paint)
632 , fBackdrop(backdrop)
633 , fSaveLayerFlags(saveLayerFlags)
634 {}
Mike Kleinb34ab042017-05-01 21:34:14 +0000635
Cary Clark462505f2018-05-30 09:20:29 -0400636 /** Experimental. Not ready for general use.
Cary Clarkb7da7232017-09-01 13:49:54 -0400637 Sets fBounds, fPaint, fBackdrop, fClipMask, fClipMatrix, and fSaveLayerFlags.
Cary Clark462505f2018-05-30 09:20:29 -0400638 clipMatrix uses alpha channel of image, transformed by clipMatrix, to clip
Cary Clark8a02b0b2017-09-21 12:28:43 -0400639 layer when drawn to SkCanvas.
Cary Clarkb7da7232017-09-01 13:49:54 -0400640
Cary Clark2823f9f2018-01-03 10:00:34 -0500641 Implementation is not complete; has no effect if SkBaseDevice is GPU-backed.
Cary Clarkb7da7232017-09-01 13:49:54 -0400642
Cary Clark8a02b0b2017-09-21 12:28:43 -0400643 @param bounds layer dimensions; may be nullptr
644 @param paint graphics state applied to layer when overlaying prior
645 layer; may be nullptr
646 @param backdrop prior layer copied with SkImageFilter;
Cary Clarkb7da7232017-09-01 13:49:54 -0400647 may be nullptr
Cary Clark8a02b0b2017-09-21 12:28:43 -0400648 @param clipMask clip applied to layer; may be nullptr
Cary Clarkb7da7232017-09-01 13:49:54 -0400649 @param clipMatrix matrix applied to clipMask; may be nullptr to use
650 identity matrix
Cary Clark8a02b0b2017-09-21 12:28:43 -0400651 @param saveLayerFlags SaveLayerRec options to modify layer
Cary Clarkb7da7232017-09-01 13:49:54 -0400652 @return SaveLayerRec fully specified
653 */
Florin Malita25b37432017-05-01 10:58:40 -0400654 SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop,
Mike Kleinb34ab042017-05-01 21:34:14 +0000655 const SkImage* clipMask, const SkMatrix* clipMatrix,
reedbfd5f172016-01-07 11:28:08 -0800656 SaveLayerFlags saveLayerFlags)
657 : fBounds(bounds)
658 , fPaint(paint)
659 , fBackdrop(backdrop)
Vaclav Brozekd0e0a8f2017-06-04 14:12:50 +0200660 , fClipMask(clipMask)
Florin Malita53f77bd2017-04-28 13:48:37 -0400661 , fClipMatrix(clipMatrix)
reed4960eee2015-12-18 07:09:18 -0800662 , fSaveLayerFlags(saveLayerFlags)
663 {}
664
Cary Clark462505f2018-05-30 09:20:29 -0400665 /** hints at layer size limit */
Cary Clarkb7da7232017-09-01 13:49:54 -0400666 const SkRect* fBounds = nullptr;
667
Cary Clark462505f2018-05-30 09:20:29 -0400668 /** modifies overlay */
Cary Clarkb7da7232017-09-01 13:49:54 -0400669 const SkPaint* fPaint = nullptr;
670
Cary Clark462505f2018-05-30 09:20:29 -0400671 /** applies SkImageFilter to prior layer */
Cary Clarkb7da7232017-09-01 13:49:54 -0400672 const SkImageFilter* fBackdrop = nullptr;
673
Cary Clark462505f2018-05-30 09:20:29 -0400674 /** clips layer with mask alpha */
Cary Clarkb7da7232017-09-01 13:49:54 -0400675 const SkImage* fClipMask = nullptr;
676
Cary Clark462505f2018-05-30 09:20:29 -0400677 /** transforms mask alpha used to clip */
Cary Clarkb7da7232017-09-01 13:49:54 -0400678 const SkMatrix* fClipMatrix = nullptr;
679
Cary Clark462505f2018-05-30 09:20:29 -0400680 /** preserves LCD text, creates with prior layer contents */
Cary Clarkb7da7232017-09-01 13:49:54 -0400681 SaveLayerFlags fSaveLayerFlags = 0;
reed4960eee2015-12-18 07:09:18 -0800682 };
683
Ben Wagner2c312c42018-06-27 14:46:46 -0400684 /** Saves SkMatrix and clip, and allocates SkBitmap for subsequent drawing.
Cary Clarkb7da7232017-09-01 13:49:54 -0400685
Ben Wagner2c312c42018-06-27 14:46:46 -0400686 Calling restore() discards changes to SkMatrix and clip,
Cary Clark462505f2018-05-30 09:20:29 -0400687 and blends SkBitmap with alpha opacity onto the prior layer.
Cary Clarkb7da7232017-09-01 13:49:54 -0400688
689 SkMatrix may be changed by translate(), scale(), rotate(), skew(), concat(),
690 setMatrix(), and resetMatrix(). Clip may be changed by clipRect(), clipRRect(),
691 clipPath(), clipRegion().
692
Cary Clark8a02b0b2017-09-21 12:28:43 -0400693 SaveLayerRec contains the state used to create the layer.
Cary Clarkb7da7232017-09-01 13:49:54 -0400694
695 Call restoreToCount() with returned value to restore this and subsequent saves.
696
Cary Clark8a02b0b2017-09-21 12:28:43 -0400697 @param layerRec layer state
Mike Reed148b7fd2018-12-18 17:38:18 -0500698 @return depth of save state stack before this call was made.
Cary Clarkb7da7232017-09-01 13:49:54 -0400699 */
Cary Clark0418a882017-05-10 09:07:42 -0400700 int saveLayer(const SaveLayerRec& layerRec);
reed4960eee2015-12-18 07:09:18 -0800701
Cary Clark7651c162018-07-13 08:21:59 -0400702 /** Removes changes to SkMatrix and clip since SkCanvas state was
703 last saved. The state is removed from the stack.
Cary Clarkb7da7232017-09-01 13:49:54 -0400704
705 Does nothing if the stack is empty.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000706 */
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +0000707 void restore();
reed@android.com8a1c16f2008-12-17 15:59:43 +0000708
Ben Wagner2c312c42018-06-27 14:46:46 -0400709 /** Returns the number of saved states, each containing: SkMatrix and clip.
Cary Clarkb7da7232017-09-01 13:49:54 -0400710 Equals the number of save() calls less the number of restore() calls plus one.
711 The save count of a new canvas is one.
712
713 @return depth of save state stack
reed@android.com8a1c16f2008-12-17 15:59:43 +0000714 */
junov@chromium.orga907ac32012-02-24 21:54:07 +0000715 int getSaveCount() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000716
Ben Wagner2c312c42018-06-27 14:46:46 -0400717 /** Restores state to SkMatrix and clip values when save(), saveLayer(),
Cary Clarkb7da7232017-09-01 13:49:54 -0400718 saveLayerPreserveLCDTextRequests(), or saveLayerAlpha() returned saveCount.
719
720 Does nothing if saveCount is greater than state stack count.
721 Restores state to initial values if saveCount is less than or equal to one.
722
723 @param saveCount depth of state stack to restore
reed@android.com8a1c16f2008-12-17 15:59:43 +0000724 */
725 void restoreToCount(int saveCount);
726
Cary Clark7651c162018-07-13 08:21:59 -0400727 /** Translates SkMatrix by dx along the x-axis and dy along the y-axis.
Cary Clarkb7da7232017-09-01 13:49:54 -0400728
Cary Clark7651c162018-07-13 08:21:59 -0400729 Mathematically, replaces SkMatrix with a translation matrix
Cary Clarkb7da7232017-09-01 13:49:54 -0400730 premultiplied with SkMatrix.
731
732 This has the effect of moving the drawing by (dx, dy) before transforming
733 the result with SkMatrix.
734
Cary Clark82456492018-10-31 10:54:50 -0400735 @param dx distance to translate on x-axis
736 @param dy distance to translate on y-axis
reed@android.com8a1c16f2008-12-17 15:59:43 +0000737 */
commit-bot@chromium.org92362382014-03-18 12:51:48 +0000738 void translate(SkScalar dx, SkScalar dy);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000739
Cary Clark7651c162018-07-13 08:21:59 -0400740 /** Scales SkMatrix by sx on the x-axis and sy on the y-axis.
Cary Clarkb7da7232017-09-01 13:49:54 -0400741
Cary Clark7651c162018-07-13 08:21:59 -0400742 Mathematically, replaces SkMatrix with a scale matrix
Cary Clarkb7da7232017-09-01 13:49:54 -0400743 premultiplied with SkMatrix.
744
745 This has the effect of scaling the drawing by (sx, sy) before transforming
746 the result with SkMatrix.
747
Cary Clark82456492018-10-31 10:54:50 -0400748 @param sx amount to scale on x-axis
749 @param sy amount to scale on y-axis
reed@android.com8a1c16f2008-12-17 15:59:43 +0000750 */
commit-bot@chromium.org92362382014-03-18 12:51:48 +0000751 void scale(SkScalar sx, SkScalar sy);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000752
Cary Clark7651c162018-07-13 08:21:59 -0400753 /** Rotates SkMatrix by degrees. Positive degrees rotates clockwise.
Cary Clarkb7da7232017-09-01 13:49:54 -0400754
Cary Clark7651c162018-07-13 08:21:59 -0400755 Mathematically, replaces SkMatrix with a rotation matrix
Cary Clarkb7da7232017-09-01 13:49:54 -0400756 premultiplied with SkMatrix.
757
758 This has the effect of rotating the drawing by degrees before transforming
759 the result with SkMatrix.
760
761 @param degrees amount to rotate, in degrees
reed@android.com8a1c16f2008-12-17 15:59:43 +0000762 */
commit-bot@chromium.org92362382014-03-18 12:51:48 +0000763 void rotate(SkScalar degrees);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000764
Cary Clark7651c162018-07-13 08:21:59 -0400765 /** Rotates SkMatrix by degrees about a point at (px, py). Positive degrees rotates
Cary Clark8a02b0b2017-09-21 12:28:43 -0400766 clockwise.
Cary Clarkb7da7232017-09-01 13:49:54 -0400767
Cary Clark7651c162018-07-13 08:21:59 -0400768 Mathematically, constructs a rotation matrix; premultiplies the rotation matrix by
769 a translation matrix; then replaces SkMatrix with the resulting matrix
Cary Clarkb7da7232017-09-01 13:49:54 -0400770 premultiplied with SkMatrix.
771
Cary Clark8a02b0b2017-09-21 12:28:43 -0400772 This has the effect of rotating the drawing about a given point before
773 transforming the result with SkMatrix.
Cary Clarkb7da7232017-09-01 13:49:54 -0400774
775 @param degrees amount to rotate, in degrees
Cary Clarkca6a2452018-06-14 13:21:08 -0400776 @param px x-axis value of the point to rotate about
777 @param py y-axis value of the point to rotate about
bungeman7438bfc2016-07-12 15:01:19 -0700778 */
779 void rotate(SkScalar degrees, SkScalar px, SkScalar py);
780
Cary Clark7651c162018-07-13 08:21:59 -0400781 /** Skews SkMatrix by sx on the x-axis and sy on the y-axis. A positive value of sx
Cary Clarkca6a2452018-06-14 13:21:08 -0400782 skews the drawing right as y-axis values increase; a positive value of sy skews
783 the drawing down as x-axis values increase.
Cary Clarkb7da7232017-09-01 13:49:54 -0400784
Cary Clark7651c162018-07-13 08:21:59 -0400785 Mathematically, replaces SkMatrix with a skew matrix premultiplied with SkMatrix.
Cary Clarkb7da7232017-09-01 13:49:54 -0400786
787 This has the effect of skewing the drawing by (sx, sy) before transforming
788 the result with SkMatrix.
789
Cary Clarkca6a2452018-06-14 13:21:08 -0400790 @param sx amount to skew on x-axis
791 @param sy amount to skew on y-axis
reed@android.com8a1c16f2008-12-17 15:59:43 +0000792 */
commit-bot@chromium.org92362382014-03-18 12:51:48 +0000793 void skew(SkScalar sx, SkScalar sy);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000794
Cary Clark7651c162018-07-13 08:21:59 -0400795 /** Replaces SkMatrix with matrix premultiplied with existing SkMatrix.
Cary Clarkb7da7232017-09-01 13:49:54 -0400796
797 This has the effect of transforming the drawn geometry by matrix, before
798 transforming the result with existing SkMatrix.
799
800 @param matrix matrix to premultiply with existing SkMatrix
reed@android.com8a1c16f2008-12-17 15:59:43 +0000801 */
commit-bot@chromium.org92362382014-03-18 12:51:48 +0000802 void concat(const SkMatrix& matrix);
reed@google.com4b226022011-01-11 18:32:13 +0000803
Cary Clark7651c162018-07-13 08:21:59 -0400804 /** Replaces SkMatrix with matrix.
Cary Clarkb7da7232017-09-01 13:49:54 -0400805 Unlike concat(), any prior matrix state is overwritten.
806
807 @param matrix matrix to copy, replacing existing SkMatrix
reed@android.com8a1c16f2008-12-17 15:59:43 +0000808 */
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000809 void setMatrix(const SkMatrix& matrix);
reed@google.com4b226022011-01-11 18:32:13 +0000810
Cary Clarkb7da7232017-09-01 13:49:54 -0400811 /** Sets SkMatrix to the identity matrix.
812 Any prior matrix state is overwritten.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000813 */
814 void resetMatrix();
815
Cary Clark7651c162018-07-13 08:21:59 -0400816 /** Replaces clip with the intersection or difference of clip and rect,
Cary Clarkb7da7232017-09-01 13:49:54 -0400817 with an aliased or anti-aliased clip edge. rect is transformed by SkMatrix
818 before it is combined with clip.
819
820 @param rect SkRect to combine with clip
821 @param op SkClipOp to apply to clip
822 @param doAntiAlias true if clip is to be anti-aliased
823 */
Cary Clark0418a882017-05-10 09:07:42 -0400824 void clipRect(const SkRect& rect, SkClipOp op, bool doAntiAlias);
Cary Clarkb7da7232017-09-01 13:49:54 -0400825
Cary Clark7651c162018-07-13 08:21:59 -0400826 /** Replaces clip with the intersection or difference of clip and rect.
Cary Clarkb7da7232017-09-01 13:49:54 -0400827 Resulting clip is aliased; pixels are fully contained by the clip.
828 rect is transformed by SkMatrix before it is combined with clip.
829
830 @param rect SkRect to combine with clip
831 @param op SkClipOp to apply to clip
832 */
Mike Reedc1f77742016-12-09 09:00:50 -0500833 void clipRect(const SkRect& rect, SkClipOp op) {
reed66998382016-09-21 11:15:07 -0700834 this->clipRect(rect, op, false);
835 }
Cary Clarkb7da7232017-09-01 13:49:54 -0400836
Cary Clark7651c162018-07-13 08:21:59 -0400837 /** Replaces clip with the intersection of clip and rect.
Cary Clarkb7da7232017-09-01 13:49:54 -0400838 Resulting clip is aliased; pixels are fully contained by the clip.
839 rect is transformed by SkMatrix
840 before it is combined with clip.
841
842 @param rect SkRect to combine with clip
843 @param doAntiAlias true if clip is to be anti-aliased
844 */
reed66998382016-09-21 11:15:07 -0700845 void clipRect(const SkRect& rect, bool doAntiAlias = false) {
Mike Reed2dc52372016-12-14 14:00:03 -0500846 this->clipRect(rect, SkClipOp::kIntersect, doAntiAlias);
reed66998382016-09-21 11:15:07 -0700847 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000848
Cary Clarkb7da7232017-09-01 13:49:54 -0400849 /** Sets the maximum clip rectangle, which can be set by clipRect(), clipRRect() and
850 clipPath() and intersect the current clip with the specified rect.
851 The maximum clip affects only future clipping operations; it is not retroactive.
852 The clip restriction is not recorded in pictures.
853
854 Pass an empty rect to disable maximum clip.
Cary Clark462505f2018-05-30 09:20:29 -0400855 This private API is for use by Android framework only.
Cary Clarkb7da7232017-09-01 13:49:54 -0400856
857 @param rect maximum allowed clip in device coordinates
858 */
Stan Iliev5f1bb0a2016-12-12 17:39:55 -0500859 void androidFramework_setDeviceClipRestriction(const SkIRect& rect);
860
Cary Clark7651c162018-07-13 08:21:59 -0400861 /** Replaces clip with the intersection or difference of clip and rrect,
Cary Clarkb7da7232017-09-01 13:49:54 -0400862 with an aliased or anti-aliased clip edge.
863 rrect is transformed by SkMatrix
864 before it is combined with clip.
865
866 @param rrect SkRRect to combine with clip
867 @param op SkClipOp to apply to clip
868 @param doAntiAlias true if clip is to be anti-aliased
869 */
Mike Reedc1f77742016-12-09 09:00:50 -0500870 void clipRRect(const SkRRect& rrect, SkClipOp op, bool doAntiAlias);
Cary Clarkb7da7232017-09-01 13:49:54 -0400871
Cary Clark7651c162018-07-13 08:21:59 -0400872 /** Replaces clip with the intersection or difference of clip and rrect.
Cary Clarkb7da7232017-09-01 13:49:54 -0400873 Resulting clip is aliased; pixels are fully contained by the clip.
874 rrect is transformed by SkMatrix before it is combined with clip.
875
876 @param rrect SkRRect to combine with clip
877 @param op SkClipOp to apply to clip
878 */
Mike Reedc1f77742016-12-09 09:00:50 -0500879 void clipRRect(const SkRRect& rrect, SkClipOp op) {
reed66998382016-09-21 11:15:07 -0700880 this->clipRRect(rrect, op, false);
881 }
Cary Clarkb7da7232017-09-01 13:49:54 -0400882
Cary Clark7651c162018-07-13 08:21:59 -0400883 /** Replaces clip with the intersection of clip and rrect,
Cary Clarkb7da7232017-09-01 13:49:54 -0400884 with an aliased or anti-aliased clip edge.
885 rrect is transformed by SkMatrix before it is combined with clip.
886
887 @param rrect SkRRect to combine with clip
888 @param doAntiAlias true if clip is to be anti-aliased
889 */
reed66998382016-09-21 11:15:07 -0700890 void clipRRect(const SkRRect& rrect, bool doAntiAlias = false) {
Mike Reed2dc52372016-12-14 14:00:03 -0500891 this->clipRRect(rrect, SkClipOp::kIntersect, doAntiAlias);
reed66998382016-09-21 11:15:07 -0700892 }
reed@google.com4ed0fb72012-12-12 20:48:18 +0000893
Cary Clark7651c162018-07-13 08:21:59 -0400894 /** Replaces clip with the intersection or difference of clip and path,
Cary Clarkb7da7232017-09-01 13:49:54 -0400895 with an aliased or anti-aliased clip edge. SkPath::FillType determines if path
896 describes the area inside or outside its contours; and if path contour overlaps
897 itself or another path contour, whether the overlaps form part of the area.
898 path is transformed by SkMatrix before it is combined with clip.
899
900 @param path SkPath to combine with clip
901 @param op SkClipOp to apply to clip
902 @param doAntiAlias true if clip is to be anti-aliased
903 */
Mike Reedc1f77742016-12-09 09:00:50 -0500904 void clipPath(const SkPath& path, SkClipOp op, bool doAntiAlias);
Cary Clarkb7da7232017-09-01 13:49:54 -0400905
Cary Clark7651c162018-07-13 08:21:59 -0400906 /** Replaces clip with the intersection or difference of clip and path.
Cary Clarkb7da7232017-09-01 13:49:54 -0400907 Resulting clip is aliased; pixels are fully contained by the clip.
908 SkPath::FillType determines if path
909 describes the area inside or outside its contours; and if path contour overlaps
910 itself or another path contour, whether the overlaps form part of the area.
911 path is transformed by SkMatrix
912 before it is combined with clip.
913
914 @param path SkPath to combine with clip
915 @param op SkClipOp to apply to clip
916 */
Mike Reedc1f77742016-12-09 09:00:50 -0500917 void clipPath(const SkPath& path, SkClipOp op) {
reed66998382016-09-21 11:15:07 -0700918 this->clipPath(path, op, false);
919 }
Cary Clarkb7da7232017-09-01 13:49:54 -0400920
Cary Clark7651c162018-07-13 08:21:59 -0400921 /** Replaces clip with the intersection of clip and path.
Cary Clarkb7da7232017-09-01 13:49:54 -0400922 Resulting clip is aliased; pixels are fully contained by the clip.
923 SkPath::FillType determines if path
924 describes the area inside or outside its contours; and if path contour overlaps
925 itself or another path contour, whether the overlaps form part of the area.
926 path is transformed by SkMatrix before it is combined with clip.
927
928 @param path SkPath to combine with clip
929 @param doAntiAlias true if clip is to be anti-aliased
930 */
reed66998382016-09-21 11:15:07 -0700931 void clipPath(const SkPath& path, bool doAntiAlias = false) {
Mike Reed2dc52372016-12-14 14:00:03 -0500932 this->clipPath(path, SkClipOp::kIntersect, doAntiAlias);
reed66998382016-09-21 11:15:07 -0700933 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000934
Cary Clark462505f2018-05-30 09:20:29 -0400935 /** Experimental. For testing only.
Cary Clarkb7da7232017-09-01 13:49:54 -0400936 Set to simplify clip stack using PathOps.
937 */
caryclark@google.com45a75fb2013-04-25 13:34:40 +0000938 void setAllowSimplifyClip(bool allow) {
939 fAllowSimplifyClip = allow;
940 }
941
Cary Clark7651c162018-07-13 08:21:59 -0400942 /** Replaces clip with the intersection or difference of clip and SkRegion deviceRgn.
Cary Clarkb7da7232017-09-01 13:49:54 -0400943 Resulting clip is aliased; pixels are fully contained by the clip.
944 deviceRgn is unaffected by SkMatrix.
945
946 @param deviceRgn SkRegion to combine with clip
947 @param op SkClipOp to apply to clip
reed@android.com8a1c16f2008-12-17 15:59:43 +0000948 */
Mike Reed2dc52372016-12-14 14:00:03 -0500949 void clipRegion(const SkRegion& deviceRgn, SkClipOp op = SkClipOp::kIntersect);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000950
Cary Clark7651c162018-07-13 08:21:59 -0400951 /** Returns true if SkRect rect, transformed by SkMatrix, can be quickly determined to be
Cary Clarkb7da7232017-09-01 13:49:54 -0400952 outside of clip. May return false even though rect is outside of clip.
953
954 Use to check if an area to be drawn is clipped out, to skip subsequent draw calls.
955
956 @param rect SkRect to compare with clip
957 @return true if rect, transformed by SkMatrix, does not intersect clip
reed@android.com8a1c16f2008-12-17 15:59:43 +0000958 */
reed@google.com3b3e8952012-08-16 20:53:31 +0000959 bool quickReject(const SkRect& rect) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000960
Cary Clark7651c162018-07-13 08:21:59 -0400961 /** Returns true if path, transformed by SkMatrix, can be quickly determined to be
Cary Clarkb7da7232017-09-01 13:49:54 -0400962 outside of clip. May return false even though path is outside of clip.
963
964 Use to check if an area to be drawn is clipped out, to skip subsequent draw calls.
965
966 @param path SkPath to compare with clip
967 @return true if path, transformed by SkMatrix, does not intersect clip
reed@android.com8a1c16f2008-12-17 15:59:43 +0000968 */
reed@google.com3b3e8952012-08-16 20:53:31 +0000969 bool quickReject(const SkPath& path) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000970
Cary Clark7651c162018-07-13 08:21:59 -0400971 /** Returns bounds of clip, transformed by inverse of SkMatrix. If clip is empty,
Cary Clarkb7da7232017-09-01 13:49:54 -0400972 return SkRect::MakeEmpty, where all SkRect sides equal zero.
973
974 SkRect returned is outset by one to account for partial pixel coverage if clip
975 is anti-aliased.
976
977 @return bounds of clip in local coordinates
978 */
Mike Klein83c8dd92017-11-28 17:08:45 -0500979 SkRect getLocalClipBounds() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000980
Cary Clark7651c162018-07-13 08:21:59 -0400981 /** Returns bounds of clip, transformed by inverse of SkMatrix. If clip is empty,
Cary Clarkb7da7232017-09-01 13:49:54 -0400982 return false, and set bounds to SkRect::MakeEmpty, where all SkRect sides equal zero.
983
984 bounds is outset by one to account for partial pixel coverage if clip
985 is anti-aliased.
986
987 @param bounds SkRect of clip in local coordinates
988 @return true if clip bounds is not empty
989 */
Mike Reed6f4a9b22017-01-24 09:13:40 -0500990 bool getLocalClipBounds(SkRect* bounds) const {
Mike Klein83c8dd92017-11-28 17:08:45 -0500991 *bounds = this->getLocalClipBounds();
Mike Reed6f4a9b22017-01-24 09:13:40 -0500992 return !bounds->isEmpty();
993 }
994
Cary Clark7651c162018-07-13 08:21:59 -0400995 /** Returns SkIRect bounds of clip, unaffected by SkMatrix. If clip is empty,
Cary Clarkb7da7232017-09-01 13:49:54 -0400996 return SkRect::MakeEmpty, where all SkRect sides equal zero.
997
998 Unlike getLocalClipBounds(), returned SkIRect is not outset.
999
1000 @return bounds of clip in SkBaseDevice coordinates
1001 */
Mike Klein83c8dd92017-11-28 17:08:45 -05001002 SkIRect getDeviceClipBounds() const;
Mike Reed42e8c532017-01-23 14:09:13 -05001003
Cary Clark7651c162018-07-13 08:21:59 -04001004 /** Returns SkIRect bounds of clip, unaffected by SkMatrix. If clip is empty,
Cary Clarkb7da7232017-09-01 13:49:54 -04001005 return false, and set bounds to SkRect::MakeEmpty, where all SkRect sides equal zero.
1006
1007 Unlike getLocalClipBounds(), bounds is not outset.
1008
1009 @param bounds SkRect of clip in device coordinates
1010 @return true if clip bounds is not empty
1011 */
Mike Reed6f4a9b22017-01-24 09:13:40 -05001012 bool getDeviceClipBounds(SkIRect* bounds) const {
Mike Klein83c8dd92017-11-28 17:08:45 -05001013 *bounds = this->getDeviceClipBounds();
Mike Reed6f4a9b22017-01-24 09:13:40 -05001014 return !bounds->isEmpty();
1015 }
1016
Cary Clark7651c162018-07-13 08:21:59 -04001017 /** Fills clip with color color.
Cary Clarkb7da7232017-09-01 13:49:54 -04001018 mode determines how ARGB is combined with destination.
1019
Cary Clark8a02b0b2017-09-21 12:28:43 -04001020 @param color unpremultiplied ARGB
Cary Clarkb7da7232017-09-01 13:49:54 -04001021 @param mode SkBlendMode used to combine source color and destination
reed@android.com8a1c16f2008-12-17 15:59:43 +00001022 */
reed374772b2016-10-05 17:33:02 -07001023 void drawColor(SkColor color, SkBlendMode mode = SkBlendMode::kSrcOver);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001024
Cary Clark7651c162018-07-13 08:21:59 -04001025 /** Fills clip with color color using SkBlendMode::kSrc.
Cary Clarkb7da7232017-09-01 13:49:54 -04001026 This has the effect of replacing all pixels contained by clip with color.
1027
Cary Clark8a02b0b2017-09-21 12:28:43 -04001028 @param color unpremultiplied ARGB
Cary Clarkb7da7232017-09-01 13:49:54 -04001029 */
reedf4e0d9e2014-12-05 20:49:03 -08001030 void clear(SkColor color) {
reed374772b2016-10-05 17:33:02 -07001031 this->drawColor(color, SkBlendMode::kSrc);
reed8eddfb52014-12-04 07:50:14 -08001032 }
reed@google.com2a981812011-04-14 18:59:28 +00001033
Cary Clark7651c162018-07-13 08:21:59 -04001034 /** Makes SkCanvas contents undefined. Subsequent calls that read SkCanvas pixels,
Cary Clarkb7da7232017-09-01 13:49:54 -04001035 such as drawing with SkBlendMode, return undefined results. discard() does
1036 not change clip or SkMatrix.
1037
1038 discard() may do nothing, depending on the implementation of SkSurface or SkBaseDevice
1039 that created SkCanvas.
1040
1041 discard() allows optimized performance on subsequent draws by removing
1042 cached data associated with SkSurface or SkBaseDevice.
1043 It is not necessary to call discard() once done with SkCanvas;
1044 any cached data is deleted when owning SkSurface or SkBaseDevice is deleted.
1045 */
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +00001046 void discard() { this->onDiscard(); }
1047
Cary Clark7651c162018-07-13 08:21:59 -04001048 /** Fills clip with SkPaint paint. SkPaint components SkMaskFilter, SkShader,
Cary Clarkb7da7232017-09-01 13:49:54 -04001049 SkColorFilter, SkImageFilter, and SkBlendMode affect drawing;
1050 SkPathEffect in paint is ignored.
1051
1052 @param paint graphics state used to fill SkCanvas
1053 */
reed0846f1b2015-01-09 14:17:40 -08001054 void drawPaint(const SkPaint& paint);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001055
Cary Clarkb7da7232017-09-01 13:49:54 -04001056 /** \enum SkCanvas::PointMode
1057 Selects if an array of points are drawn as discrete points, as lines, or as
1058 an open polygon.
1059 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001060 enum PointMode {
Cary Clark462505f2018-05-30 09:20:29 -04001061 kPoints_PointMode, //!< draw each point separately
1062 kLines_PointMode, //!< draw each pair of points as a line segment
1063 kPolygon_PointMode, //!< draw the array of points as a open polygon
reed@android.com8a1c16f2008-12-17 15:59:43 +00001064 };
1065
Cary Clark7651c162018-07-13 08:21:59 -04001066 /** Draws pts using clip, SkMatrix and SkPaint paint.
Cary Clarkb7da7232017-09-01 13:49:54 -04001067 count is the number of points; if count is less than one, has no effect.
1068 mode may be one of: kPoints_PointMode, kLines_PointMode, or kPolygon_PointMode.
1069
1070 If mode is kPoints_PointMode, the shape of point drawn depends on paint
1071 SkPaint::Cap. If paint is set to SkPaint::kRound_Cap, each point draws a
1072 circle of diameter SkPaint stroke width. If paint is set to SkPaint::kSquare_Cap
1073 or SkPaint::kButt_Cap, each point draws a square of width and height
1074 SkPaint stroke width.
1075
1076 If mode is kLines_PointMode, each pair of points draws a line segment.
1077 One line is drawn for every two points; each point is used once. If count is odd,
1078 the final point is ignored.
1079
1080 If mode is kPolygon_PointMode, each adjacent pair of points draws a line segment.
1081 count minus one lines are drawn; the first and last point are used once.
1082
1083 Each line segment respects paint SkPaint::Cap and SkPaint stroke width.
1084 SkPaint::Style is ignored, as if were set to SkPaint::kStroke_Style.
1085
1086 Always draws each element one at a time; is not affected by
1087 SkPaint::Join, and unlike drawPath(), does not create a mask from all points
1088 and lines before drawing.
1089
1090 @param mode whether pts draws points or lines
1091 @param count number of points in the array
1092 @param pts array of points to draw
1093 @param paint stroke, blend, color, and so on, used to draw
reed@android.com8a1c16f2008-12-17 15:59:43 +00001094 */
reed0846f1b2015-01-09 14:17:40 -08001095 void drawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint& paint);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001096
Cary Clark7651c162018-07-13 08:21:59 -04001097 /** Draws point at (x, y) using clip, SkMatrix and SkPaint paint.
Cary Clarkb7da7232017-09-01 13:49:54 -04001098
1099 The shape of point drawn depends on paint SkPaint::Cap.
1100 If paint is set to SkPaint::kRound_Cap, draw a circle of diameter
1101 SkPaint stroke width. If paint is set to SkPaint::kSquare_Cap or SkPaint::kButt_Cap,
1102 draw a square of width and height SkPaint stroke width.
1103 SkPaint::Style is ignored, as if were set to SkPaint::kStroke_Style.
1104
1105 @param x left edge of circle or square
1106 @param y top edge of circle or square
1107 @param paint stroke, blend, color, and so on, used to draw
1108 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001109 void drawPoint(SkScalar x, SkScalar y, const SkPaint& paint);
Cary Clarkb7da7232017-09-01 13:49:54 -04001110
Cary Clark7651c162018-07-13 08:21:59 -04001111 /** Draws point p using clip, SkMatrix and SkPaint paint.
Cary Clarkb7da7232017-09-01 13:49:54 -04001112
1113 The shape of point drawn depends on paint SkPaint::Cap.
1114 If paint is set to SkPaint::kRound_Cap, draw a circle of diameter
1115 SkPaint stroke width. If paint is set to SkPaint::kSquare_Cap or SkPaint::kButt_Cap,
1116 draw a square of width and height SkPaint stroke width.
1117 SkPaint::Style is ignored, as if were set to SkPaint::kStroke_Style.
1118
1119 @param p top-left edge of circle or square
1120 @param paint stroke, blend, color, and so on, used to draw
1121 */
Hal Canary23e474c2017-05-15 13:35:35 -04001122 void drawPoint(SkPoint p, const SkPaint& paint) {
1123 this->drawPoint(p.x(), p.y(), paint);
1124 }
reed@google.com4b226022011-01-11 18:32:13 +00001125
Cary Clarkb7da7232017-09-01 13:49:54 -04001126 /** Draws line segment from (x0, y0) to (x1, y1) using clip, SkMatrix, and SkPaint paint.
1127 In paint: SkPaint stroke width describes the line thickness;
1128 SkPaint::Cap draws the end rounded or square;
1129 SkPaint::Style is ignored, as if were set to SkPaint::kStroke_Style.
1130
1131 @param x0 start of line segment on x-axis
1132 @param y0 start of line segment on y-axis
1133 @param x1 end of line segment on x-axis
1134 @param y1 end of line segment on y-axis
1135 @param paint stroke, blend, color, and so on, used to draw
reed@android.com8a1c16f2008-12-17 15:59:43 +00001136 */
Mike Reed3661bc92017-02-22 13:21:42 -05001137 void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint& paint);
Cary Clarkb7da7232017-09-01 13:49:54 -04001138
1139 /** Draws line segment from p0 to p1 using clip, SkMatrix, and SkPaint paint.
1140 In paint: SkPaint stroke width describes the line thickness;
1141 SkPaint::Cap draws the end rounded or square;
1142 SkPaint::Style is ignored, as if were set to SkPaint::kStroke_Style.
1143
1144 @param p0 start of line segment
1145 @param p1 end of line segment
1146 @param paint stroke, blend, color, and so on, used to draw
1147 */
Hal Canary23e474c2017-05-15 13:35:35 -04001148 void drawLine(SkPoint p0, SkPoint p1, const SkPaint& paint) {
1149 this->drawLine(p0.x(), p0.y(), p1.x(), p1.y(), paint);
1150 }
reed@android.com8a1c16f2008-12-17 15:59:43 +00001151
Cary Clark7651c162018-07-13 08:21:59 -04001152 /** Draws SkRect rect using clip, SkMatrix, and SkPaint paint.
Cary Clarkb7da7232017-09-01 13:49:54 -04001153 In paint: SkPaint::Style determines if rectangle is stroked or filled;
1154 if stroked, SkPaint stroke width describes the line thickness, and
1155 SkPaint::Join draws the corners rounded or square.
1156
Cary Clarkcc309eb2017-10-30 11:48:35 -04001157 @param rect rectangle to draw
Cary Clarkb7da7232017-09-01 13:49:54 -04001158 @param paint stroke or fill, blend, color, and so on, used to draw
reed@android.com8a1c16f2008-12-17 15:59:43 +00001159 */
reed0846f1b2015-01-09 14:17:40 -08001160 void drawRect(const SkRect& rect, const SkPaint& paint);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001161
Cary Clark7651c162018-07-13 08:21:59 -04001162 /** Draws SkIRect rect using clip, SkMatrix, and SkPaint paint.
Cary Clarkb7da7232017-09-01 13:49:54 -04001163 In paint: SkPaint::Style determines if rectangle is stroked or filled;
1164 if stroked, SkPaint stroke width describes the line thickness, and
1165 SkPaint::Join draws the corners rounded or square.
1166
Cary Clarkcc309eb2017-10-30 11:48:35 -04001167 @param rect rectangle to draw
Cary Clarkb7da7232017-09-01 13:49:54 -04001168 @param paint stroke or fill, blend, color, and so on, used to draw
reed@android.com8a1c16f2008-12-17 15:59:43 +00001169 */
reed@google.com87001ed2014-02-17 16:28:05 +00001170 void drawIRect(const SkIRect& rect, const SkPaint& paint) {
reed@android.com8a1c16f2008-12-17 15:59:43 +00001171 SkRect r;
1172 r.set(rect); // promotes the ints to scalars
1173 this->drawRect(r, paint);
1174 }
reed@google.com4b226022011-01-11 18:32:13 +00001175
Cary Clark7651c162018-07-13 08:21:59 -04001176 /** Draws SkRegion region using clip, SkMatrix, and SkPaint paint.
Cary Clarkb7da7232017-09-01 13:49:54 -04001177 In paint: SkPaint::Style determines if rectangle is stroked or filled;
1178 if stroked, SkPaint stroke width describes the line thickness, and
1179 SkPaint::Join draws the corners rounded or square.
1180
Cary Clarkcc309eb2017-10-30 11:48:35 -04001181 @param region region to draw
Cary Clarkb7da7232017-09-01 13:49:54 -04001182 @param paint SkPaint stroke or fill, blend, color, and so on, used to draw
msarett44df6512016-08-25 13:54:30 -07001183 */
msarettdca352e2016-08-26 06:37:45 -07001184 void drawRegion(const SkRegion& region, const SkPaint& paint);
msarett44df6512016-08-25 13:54:30 -07001185
Cary Clark7651c162018-07-13 08:21:59 -04001186 /** Draws oval oval using clip, SkMatrix, and SkPaint.
Cary Clarkb7da7232017-09-01 13:49:54 -04001187 In paint: SkPaint::Style determines if oval is stroked or filled;
1188 if stroked, SkPaint stroke width describes the line thickness.
1189
1190 @param oval SkRect bounds of oval
1191 @param paint SkPaint stroke or fill, blend, color, and so on, used to draw
reed@android.com8a1c16f2008-12-17 15:59:43 +00001192 */
Cary Clark304f9d42017-05-13 13:35:35 -04001193 void drawOval(const SkRect& oval, const SkPaint& paint);
reed@google.com4ed0fb72012-12-12 20:48:18 +00001194
Cary Clark7651c162018-07-13 08:21:59 -04001195 /** Draws SkRRect rrect using clip, SkMatrix, and SkPaint paint.
Cary Clarkb7da7232017-09-01 13:49:54 -04001196 In paint: SkPaint::Style determines if rrect is stroked or filled;
1197 if stroked, SkPaint stroke width describes the line thickness.
1198
1199 rrect may represent a rectangle, circle, oval, uniformly rounded rectangle, or
1200 may have any combination of positive non-square radii for the four corners.
1201
1202 @param rrect SkRRect with up to eight corner radii to draw
1203 @param paint SkPaint stroke or fill, blend, color, and so on, used to draw
1204 */
reed0846f1b2015-01-09 14:17:40 -08001205 void drawRRect(const SkRRect& rrect, const SkPaint& paint);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001206
Cary Clark7651c162018-07-13 08:21:59 -04001207 /** Draws SkRRect outer and inner
Cary Clarkb7da7232017-09-01 13:49:54 -04001208 using clip, SkMatrix, and SkPaint paint.
1209 outer must contain inner or the drawing is undefined.
1210 In paint: SkPaint::Style determines if SkRRect is stroked or filled;
1211 if stroked, SkPaint stroke width describes the line thickness.
1212 If stroked and SkRRect corner has zero length radii, SkPaint::Join can
1213 draw corners rounded or square.
1214
1215 GPU-backed platforms optimize drawing when both outer and inner are
1216 concave and outer contains inner. These platforms may not be able to draw
1217 SkPath built with identical data as fast.
1218
1219 @param outer SkRRect outer bounds to draw
1220 @param inner SkRRect inner bounds to draw
1221 @param paint SkPaint stroke or fill, blend, color, and so on, used to draw
1222 */
Cary Clark304f9d42017-05-13 13:35:35 -04001223 void drawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint);
commit-bot@chromium.orged9806f2014-02-21 02:32:36 +00001224
Cary Clark7651c162018-07-13 08:21:59 -04001225 /** Draws circle at (cx, cy) with radius using clip, SkMatrix, and SkPaint paint.
Cary Clarkb7da7232017-09-01 13:49:54 -04001226 If radius is zero or less, nothing is drawn.
1227 In paint: SkPaint::Style determines if circle is stroked or filled;
1228 if stroked, SkPaint stroke width describes the line thickness.
1229
Cary Clark8a02b0b2017-09-21 12:28:43 -04001230 @param cx circle center on the x-axis
1231 @param cy circle center on the y-axis
Cary Clarkb7da7232017-09-01 13:49:54 -04001232 @param radius half the diameter of circle
1233 @param paint SkPaint stroke or fill, blend, color, and so on, used to draw
reed@android.com8a1c16f2008-12-17 15:59:43 +00001234 */
Mike Reed3661bc92017-02-22 13:21:42 -05001235 void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint& paint);
Cary Clarkb7da7232017-09-01 13:49:54 -04001236
Cary Clark7651c162018-07-13 08:21:59 -04001237 /** Draws circle at center with radius using clip, SkMatrix, and SkPaint paint.
Cary Clarkb7da7232017-09-01 13:49:54 -04001238 If radius is zero or less, nothing is drawn.
1239 In paint: SkPaint::Style determines if circle is stroked or filled;
1240 if stroked, SkPaint stroke width describes the line thickness.
1241
Cary Clark8a02b0b2017-09-21 12:28:43 -04001242 @param center circle center
Cary Clarkb7da7232017-09-01 13:49:54 -04001243 @param radius half the diameter of circle
1244 @param paint SkPaint stroke or fill, blend, color, and so on, used to draw
1245 */
Hal Canary23e474c2017-05-15 13:35:35 -04001246 void drawCircle(SkPoint center, SkScalar radius, const SkPaint& paint) {
1247 this->drawCircle(center.x(), center.y(), radius, paint);
1248 }
reed@android.com8a1c16f2008-12-17 15:59:43 +00001249
Cary Clark7651c162018-07-13 08:21:59 -04001250 /** Draws arc using clip, SkMatrix, and SkPaint paint.
Cary Clarkb7da7232017-09-01 13:49:54 -04001251
1252 Arc is part of oval bounded by oval, sweeping from startAngle to startAngle plus
1253 sweepAngle. startAngle and sweepAngle are in degrees.
1254
1255 startAngle of zero places start point at the right middle edge of oval.
1256 A positive sweepAngle places arc end point clockwise from start point;
1257 a negative sweepAngle places arc end point counterclockwise from start point.
1258 sweepAngle may exceed 360 degrees, a full circle.
1259 If useCenter is true, draw a wedge that includes lines from oval
1260 center to arc end points. If useCenter is false, draw arc between end points.
1261
1262 If SkRect oval is empty or sweepAngle is zero, nothing is drawn.
1263
1264 @param oval SkRect bounds of oval containing arc to draw
1265 @param startAngle angle in degrees where arc begins
1266 @param sweepAngle sweep angle in degrees; positive is clockwise
1267 @param useCenter if true, include the center of the oval
1268 @param paint SkPaint stroke or fill, blend, color, and so on, used to draw
reed@android.com8a1c16f2008-12-17 15:59:43 +00001269 */
1270 void drawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle,
1271 bool useCenter, const SkPaint& paint);
1272
Cary Clark7651c162018-07-13 08:21:59 -04001273 /** Draws SkRRect bounded by SkRect rect, with corner radii (rx, ry) using clip,
Cary Clarkb7da7232017-09-01 13:49:54 -04001274 SkMatrix, and SkPaint paint.
1275
1276 In paint: SkPaint::Style determines if SkRRect is stroked or filled;
1277 if stroked, SkPaint stroke width describes the line thickness.
1278 If rx or ry are less than zero, they are treated as if they are zero.
1279 If rx plus ry exceeds rect width or rect height, radii are scaled down to fit.
1280 If rx and ry are zero, SkRRect is drawn as SkRect and if stroked is affected by
1281 SkPaint::Join.
1282
1283 @param rect SkRect bounds of SkRRect to draw
Cary Clarkca6a2452018-06-14 13:21:08 -04001284 @param rx axis length on x-axis of oval describing rounded corners
1285 @param ry axis length on y-axis of oval describing rounded corners
Cary Clarkb7da7232017-09-01 13:49:54 -04001286 @param paint stroke, blend, color, and so on, used to draw
reed@android.com8a1c16f2008-12-17 15:59:43 +00001287 */
Mike Reed3661bc92017-02-22 13:21:42 -05001288 void drawRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry, const SkPaint& paint);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001289
Cary Clark7651c162018-07-13 08:21:59 -04001290 /** Draws SkPath path using clip, SkMatrix, and SkPaint paint.
Cary Clarkb7da7232017-09-01 13:49:54 -04001291 SkPath contains an array of path contour, each of which may be open or closed.
1292
1293 In paint: SkPaint::Style determines if SkRRect is stroked or filled:
1294 if filled, SkPath::FillType determines whether path contour describes inside or
1295 outside of fill; if stroked, SkPaint stroke width describes the line thickness,
1296 SkPaint::Cap describes line ends, and SkPaint::Join describes how
1297 corners are drawn.
1298
1299 @param path SkPath to draw
1300 @param paint stroke, blend, color, and so on, used to draw
reed@android.com8a1c16f2008-12-17 15:59:43 +00001301 */
reed0846f1b2015-01-09 14:17:40 -08001302 void drawPath(const SkPath& path, const SkPaint& paint);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001303
Cary Clark7651c162018-07-13 08:21:59 -04001304 /** Draws SkImage image, with its top-left corner at (left, top),
Cary Clarkb7da7232017-09-01 13:49:54 -04001305 using clip, SkMatrix, and optional SkPaint paint.
piotaixrd52893c2014-09-25 14:39:40 -07001306
Cary Clark462505f2018-05-30 09:20:29 -04001307 If paint is supplied, apply SkColorFilter, alpha, SkImageFilter, SkBlendMode,
Cary Clarkb7da7232017-09-01 13:49:54 -04001308 and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader.
1309 If paint contains SkMaskFilter, generate mask from image bounds. If generated
1310 mask extends beyond image bounds, replicate image edge colors, just as SkShader
1311 made from SkImage::makeShader with SkShader::kClamp_TileMode set replicates the
Cary Clarkcc309eb2017-10-30 11:48:35 -04001312 image edge color when it samples outside of its bounds.
Cary Clarkb7da7232017-09-01 13:49:54 -04001313
1314 @param image uncompressed rectangular map of pixels
1315 @param left left side of image
1316 @param top top side of image
1317 @param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
1318 and so on; or nullptr
1319 */
Ben Wagnera93a14a2017-08-28 10:34:05 -04001320 void drawImage(const SkImage* image, SkScalar left, SkScalar top,
1321 const SkPaint* paint = nullptr);
Cary Clarkb7da7232017-09-01 13:49:54 -04001322
Cary Clark7651c162018-07-13 08:21:59 -04001323 /** Draws SkImage image, with its top-left corner at (left, top),
Cary Clarkb7da7232017-09-01 13:49:54 -04001324 using clip, SkMatrix, and optional SkPaint paint.
1325
Cary Clark462505f2018-05-30 09:20:29 -04001326 If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter,
Cary Clarkb7da7232017-09-01 13:49:54 -04001327 SkBlendMode, and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader.
1328 If paint contains SkMaskFilter, generate mask from image bounds. If generated
1329 mask extends beyond image bounds, replicate image edge colors, just as SkShader
1330 made from SkImage::makeShader with SkShader::kClamp_TileMode set replicates the
Cary Clarkcc309eb2017-10-30 11:48:35 -04001331 image edge color when it samples outside of its bounds.
Cary Clarkb7da7232017-09-01 13:49:54 -04001332
1333 @param image uncompressed rectangular map of pixels
1334 @param left left side of image
1335 @param top pop side of image
1336 @param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
1337 and so on; or nullptr
1338 */
reedf8053da2016-03-17 08:14:57 -07001339 void drawImage(const sk_sp<SkImage>& image, SkScalar left, SkScalar top,
Ben Wagnera93a14a2017-08-28 10:34:05 -04001340 const SkPaint* paint = nullptr) {
reedf8053da2016-03-17 08:14:57 -07001341 this->drawImage(image.get(), left, top, paint);
1342 }
piotaixrb5fae932014-09-24 13:03:30 -07001343
Cary Clarkb7da7232017-09-01 13:49:54 -04001344 /** \enum SkCanvas::SrcRectConstraint
1345 SrcRectConstraint controls the behavior at the edge of source SkRect,
1346 provided to drawImageRect(), trading off speed for precision.
1347
Brian Salomonf08002c2018-10-26 16:15:46 -04001348 SkFilterQuality in SkPaint may sample multiple pixels in the image. Source SkRect
1349 restricts the bounds of pixels that may be read. SkFilterQuality may slow down if
Cary Clarkb7da7232017-09-01 13:49:54 -04001350 it cannot read outside the bounds, when sampling near the edge of source SkRect.
1351 SrcRectConstraint specifies whether an SkImageFilter is allowed to read pixels
1352 outside source SkRect.
1353 */
reeda5517e22015-07-14 10:54:12 -07001354 enum SrcRectConstraint {
Cary Clark462505f2018-05-30 09:20:29 -04001355 kStrict_SrcRectConstraint, //!< sample only inside bounds; slower
1356 kFast_SrcRectConstraint, //!< sample outside bounds; faster
reeda5517e22015-07-14 10:54:12 -07001357 };
1358
Cary Clark7651c162018-07-13 08:21:59 -04001359 /** Draws SkRect src of SkImage image, scaled and translated to fill SkRect dst.
Cary Clarkb7da7232017-09-01 13:49:54 -04001360 Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.
1361
Cary Clark462505f2018-05-30 09:20:29 -04001362 If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter,
Cary Clarkb7da7232017-09-01 13:49:54 -04001363 SkBlendMode, and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader.
1364 If paint contains SkMaskFilter, generate mask from image bounds.
1365
1366 If generated mask extends beyond image bounds, replicate image edge colors, just
1367 as SkShader made from SkImage::makeShader with SkShader::kClamp_TileMode set
Cary Clarkcc309eb2017-10-30 11:48:35 -04001368 replicates the image edge color when it samples outside of its bounds.
Cary Clarkb7da7232017-09-01 13:49:54 -04001369
1370 constraint set to kStrict_SrcRectConstraint limits SkPaint SkFilterQuality to
1371 sample within src; set to kFast_SrcRectConstraint allows sampling outside to
1372 improve performance.
1373
1374 @param image SkImage containing pixels, dimensions, and format
1375 @param src source SkRect of image to draw from
1376 @param dst destination SkRect of image to draw to
1377 @param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
1378 and so on; or nullptr
1379 @param constraint filter strictly within src or draw faster
1380 */
reede47829b2015-08-06 10:02:53 -07001381 void drawImageRect(const SkImage* image, const SkRect& src, const SkRect& dst,
1382 const SkPaint* paint,
1383 SrcRectConstraint constraint = kStrict_SrcRectConstraint);
Cary Clarkb7da7232017-09-01 13:49:54 -04001384
Cary Clark7651c162018-07-13 08:21:59 -04001385 /** Draws SkIRect isrc of SkImage image, scaled and translated to fill SkRect dst.
Cary Clarkb7da7232017-09-01 13:49:54 -04001386 Note that isrc is on integer pixel boundaries; dst may include fractional
1387 boundaries. Additionally transform draw using clip, SkMatrix, and optional SkPaint
1388 paint.
1389
Cary Clark462505f2018-05-30 09:20:29 -04001390 If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter,
Cary Clarkb7da7232017-09-01 13:49:54 -04001391 SkBlendMode, and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader.
1392 If paint contains SkMaskFilter, generate mask from image bounds.
1393
1394 If generated mask extends beyond image bounds, replicate image edge colors, just
1395 as SkShader made from SkImage::makeShader with SkShader::kClamp_TileMode set
Cary Clarkcc309eb2017-10-30 11:48:35 -04001396 replicates the image edge color when it samples outside of its bounds.
Cary Clarkb7da7232017-09-01 13:49:54 -04001397
1398 constraint set to kStrict_SrcRectConstraint limits SkPaint SkFilterQuality to
1399 sample within isrc; set to kFast_SrcRectConstraint allows sampling outside to
1400 improve performance.
1401
1402 @param image SkImage containing pixels, dimensions, and format
1403 @param isrc source SkIRect of image to draw from
1404 @param dst destination SkRect of image to draw to
1405 @param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
1406 and so on; or nullptr
1407 @param constraint filter strictly within isrc or draw faster
1408 */
reede47829b2015-08-06 10:02:53 -07001409 void drawImageRect(const SkImage* image, const SkIRect& isrc, const SkRect& dst,
Cary Clark0418a882017-05-10 09:07:42 -04001410 const SkPaint* paint,
1411 SrcRectConstraint constraint = kStrict_SrcRectConstraint);
Cary Clarkb7da7232017-09-01 13:49:54 -04001412
Cary Clark7651c162018-07-13 08:21:59 -04001413 /** Draws SkImage image, scaled and translated to fill SkRect dst, using clip, SkMatrix,
Cary Clarkb7da7232017-09-01 13:49:54 -04001414 and optional SkPaint paint.
1415
Cary Clark462505f2018-05-30 09:20:29 -04001416 If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter,
Cary Clarkb7da7232017-09-01 13:49:54 -04001417 SkBlendMode, and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader.
1418 If paint contains SkMaskFilter, generate mask from image bounds.
1419
1420 If generated mask extends beyond image bounds, replicate image edge colors, just
1421 as SkShader made from SkImage::makeShader with SkShader::kClamp_TileMode set
Cary Clarkcc309eb2017-10-30 11:48:35 -04001422 replicates the image edge color when it samples outside of its bounds.
Cary Clarkb7da7232017-09-01 13:49:54 -04001423
Cary Clarkb7da7232017-09-01 13:49:54 -04001424 @param image SkImage containing pixels, dimensions, and format
1425 @param dst destination SkRect of image to draw to
1426 @param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
1427 and so on; or nullptr
Cary Clarkb7da7232017-09-01 13:49:54 -04001428 */
Brian Salomonf08002c2018-10-26 16:15:46 -04001429 void drawImageRect(const SkImage* image, const SkRect& dst, const SkPaint* paint);
reed84984ef2015-07-17 07:09:43 -07001430
Cary Clark7651c162018-07-13 08:21:59 -04001431 /** Draws SkRect src of SkImage image, scaled and translated to fill SkRect dst.
Cary Clarkb7da7232017-09-01 13:49:54 -04001432 Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.
1433
Cary Clark462505f2018-05-30 09:20:29 -04001434 If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter,
Cary Clarkb7da7232017-09-01 13:49:54 -04001435 SkBlendMode, and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader.
1436 If paint contains SkMaskFilter, generate mask from image bounds.
1437
1438 If generated mask extends beyond image bounds, replicate image edge colors, just
1439 as SkShader made from SkImage::makeShader with SkShader::kClamp_TileMode set
Cary Clarkcc309eb2017-10-30 11:48:35 -04001440 replicates the image edge color when it samples outside of its bounds.
Cary Clarkb7da7232017-09-01 13:49:54 -04001441
Cary Clarkb7da7232017-09-01 13:49:54 -04001442 @param image SkImage containing pixels, dimensions, and format
1443 @param src source SkRect of image to draw from
1444 @param dst destination SkRect of image to draw to
1445 @param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
1446 and so on; or nullptr
1447 @param constraint filter strictly within src or draw faster
1448 */
reedf8053da2016-03-17 08:14:57 -07001449 void drawImageRect(const sk_sp<SkImage>& image, const SkRect& src, const SkRect& dst,
1450 const SkPaint* paint,
1451 SrcRectConstraint constraint = kStrict_SrcRectConstraint) {
1452 this->drawImageRect(image.get(), src, dst, paint, constraint);
1453 }
Cary Clarkb7da7232017-09-01 13:49:54 -04001454
Cary Clark7651c162018-07-13 08:21:59 -04001455 /** Draws SkIRect isrc of SkImage image, scaled and translated to fill SkRect dst.
Cary Clarkb7da7232017-09-01 13:49:54 -04001456 isrc is on integer pixel boundaries; dst may include fractional boundaries.
1457 Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.
1458
Cary Clark462505f2018-05-30 09:20:29 -04001459 If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter,
Cary Clarkb7da7232017-09-01 13:49:54 -04001460 SkBlendMode, and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader.
1461 If paint contains SkMaskFilter, generate mask from image bounds.
1462
1463 If generated mask extends beyond image bounds, replicate image edge colors, just
1464 as SkShader made from SkImage::makeShader with SkShader::kClamp_TileMode set
Cary Clarkcc309eb2017-10-30 11:48:35 -04001465 replicates the image edge color when it samples outside of its bounds.
Cary Clarkb7da7232017-09-01 13:49:54 -04001466
1467 constraint set to kStrict_SrcRectConstraint limits SkPaint SkFilterQuality to
1468 sample within image; set to kFast_SrcRectConstraint allows sampling outside to
1469 improve performance.
1470
1471 @param image SkImage containing pixels, dimensions, and format
1472 @param isrc source SkIRect of image to draw from
1473 @param dst destination SkRect of image to draw to
1474 @param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
1475 and so on; or nullptr
1476 @param constraint filter strictly within image or draw faster
1477 */
reedf8053da2016-03-17 08:14:57 -07001478 void drawImageRect(const sk_sp<SkImage>& image, const SkIRect& isrc, const SkRect& dst,
Ben Wagner63fd7602017-10-09 15:45:33 -04001479 const SkPaint* paint,
Cary Clark0418a882017-05-10 09:07:42 -04001480 SrcRectConstraint constraint = kStrict_SrcRectConstraint) {
1481 this->drawImageRect(image.get(), isrc, dst, paint, constraint);
reedf8053da2016-03-17 08:14:57 -07001482 }
Cary Clarkb7da7232017-09-01 13:49:54 -04001483
Cary Clark7651c162018-07-13 08:21:59 -04001484 /** Draws SkImage image, scaled and translated to fill SkRect dst,
Cary Clarkb7da7232017-09-01 13:49:54 -04001485 using clip, SkMatrix, and optional SkPaint paint.
1486
Cary Clark462505f2018-05-30 09:20:29 -04001487 If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter,
Cary Clarkb7da7232017-09-01 13:49:54 -04001488 SkBlendMode, and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader.
1489 If paint contains SkMaskFilter, generate mask from image bounds.
1490
1491 If generated mask extends beyond image bounds, replicate image edge colors, just
1492 as SkShader made from SkImage::makeShader with SkShader::kClamp_TileMode set
Cary Clarkcc309eb2017-10-30 11:48:35 -04001493 replicates the image edge color when it samples outside of its bounds.
Cary Clarkb7da7232017-09-01 13:49:54 -04001494
1495 constraint set to kStrict_SrcRectConstraint limits SkPaint SkFilterQuality to
1496 sample within image; set to kFast_SrcRectConstraint allows sampling outside to
1497 improve performance.
1498
1499 @param image SkImage containing pixels, dimensions, and format
1500 @param dst destination SkRect of image to draw to
1501 @param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
1502 and so on; or nullptr
Cary Clarkb7da7232017-09-01 13:49:54 -04001503 */
Brian Salomonf08002c2018-10-26 16:15:46 -04001504 void drawImageRect(const sk_sp<SkImage>& image, const SkRect& dst, const SkPaint* paint) {
1505 this->drawImageRect(image.get(), dst, paint);
reedf8053da2016-03-17 08:14:57 -07001506 }
1507
Cary Clark7651c162018-07-13 08:21:59 -04001508 /** Draws SkImage image stretched proportionally to fit into SkRect dst.
Cary Clarkb7da7232017-09-01 13:49:54 -04001509 SkIRect center divides the image into nine sections: four sides, four corners, and
1510 the center. Corners are unmodified or scaled down proportionately if their sides
1511 are larger than dst; center and four sides are scaled to fit remaining space, if any.
1512
1513 Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.
1514
Cary Clark462505f2018-05-30 09:20:29 -04001515 If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter,
Cary Clarkb7da7232017-09-01 13:49:54 -04001516 SkBlendMode, and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader.
Cary Clark462505f2018-05-30 09:20:29 -04001517 If paint contains SkMaskFilter, generate mask from image bounds. If paint
1518 SkFilterQuality set to kNone_SkFilterQuality, disable pixel filtering. For all
1519 other values of paint SkFilterQuality, use kLow_SkFilterQuality to filter pixels.
1520 Any SkMaskFilter on paint is ignored as is paint anti-aliasing state.
Cary Clarkb7da7232017-09-01 13:49:54 -04001521
1522 If generated mask extends beyond image bounds, replicate image edge colors, just
1523 as SkShader made from SkImage::makeShader with SkShader::kClamp_TileMode set
Cary Clarkcc309eb2017-10-30 11:48:35 -04001524 replicates the image edge color when it samples outside of its bounds.
Cary Clarkb7da7232017-09-01 13:49:54 -04001525
1526 @param image SkImage containing pixels, dimensions, and format
1527 @param center SkIRect edge of image corners and sides
1528 @param dst destination SkRect of image to draw to
1529 @param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
1530 and so on; or nullptr
1531 */
Cary Clark0418a882017-05-10 09:07:42 -04001532 void drawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst,
reedf8053da2016-03-17 08:14:57 -07001533 const SkPaint* paint = nullptr);
Cary Clarkb7da7232017-09-01 13:49:54 -04001534
Cary Clark7651c162018-07-13 08:21:59 -04001535 /** Draws SkImage image stretched proportionally to fit into SkRect dst.
Cary Clarkb7da7232017-09-01 13:49:54 -04001536 SkIRect center divides the image into nine sections: four sides, four corners, and
1537 the center. Corners are not scaled, or scaled down proportionately if their sides
1538 are larger than dst; center and four sides are scaled to fit remaining space, if any.
1539
1540 Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.
1541
Cary Clark462505f2018-05-30 09:20:29 -04001542 If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter,
Cary Clarkb7da7232017-09-01 13:49:54 -04001543 SkBlendMode, and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader.
Cary Clark462505f2018-05-30 09:20:29 -04001544 If paint contains SkMaskFilter, generate mask from image bounds. If paint
1545 SkFilterQuality set to kNone_SkFilterQuality, disable pixel filtering. For all
1546 other values of paint SkFilterQuality, use kLow_SkFilterQuality to filter pixels.
1547 Any SkMaskFilter on paint is ignored as is paint anti-aliasing state.
Cary Clarkb7da7232017-09-01 13:49:54 -04001548
1549 If generated mask extends beyond image bounds, replicate image edge colors, just
1550 as SkShader made from SkImage::makeShader with SkShader::kClamp_TileMode set
Cary Clarkcc309eb2017-10-30 11:48:35 -04001551 replicates the image edge color when it samples outside of its bounds.
Cary Clarkb7da7232017-09-01 13:49:54 -04001552
1553 @param image SkImage containing pixels, dimensions, and format
1554 @param center SkIRect edge of image corners and sides
1555 @param dst destination SkRect of image to draw to
1556 @param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
1557 and so on; or nullptr
1558 */
reedf8053da2016-03-17 08:14:57 -07001559 void drawImageNine(const sk_sp<SkImage>& image, const SkIRect& center, const SkRect& dst,
1560 const SkPaint* paint = nullptr) {
1561 this->drawImageNine(image.get(), center, dst, paint);
1562 }
reed4c21dc52015-06-25 12:32:03 -07001563
Cary Clark7651c162018-07-13 08:21:59 -04001564 /** Draws SkBitmap bitmap, with its top-left corner at (left, top),
Cary Clarkb7da7232017-09-01 13:49:54 -04001565 using clip, SkMatrix, and optional SkPaint paint.
commit-bot@chromium.org91246b92013-12-05 15:43:19 +00001566
Cary Clark462505f2018-05-30 09:20:29 -04001567 If SkPaint paint is not nullptr, apply SkColorFilter, alpha, SkImageFilter,
Cary Clarkb7da7232017-09-01 13:49:54 -04001568 SkBlendMode, and SkDrawLooper. If bitmap is kAlpha_8_SkColorType, apply SkShader.
1569 If paint contains SkMaskFilter, generate mask from bitmap bounds.
commit-bot@chromium.org91246b92013-12-05 15:43:19 +00001570
Cary Clarkb7da7232017-09-01 13:49:54 -04001571 If generated mask extends beyond bitmap bounds, replicate bitmap edge colors,
1572 just as SkShader made from SkShader::MakeBitmapShader with
Cary Clarkcc309eb2017-10-30 11:48:35 -04001573 SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples
Cary Clarkb7da7232017-09-01 13:49:54 -04001574 outside of its bounds.
1575
1576 @param bitmap SkBitmap containing pixels, dimensions, and format
1577 @param left left side of bitmap
1578 @param top top side of bitmap
1579 @param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
1580 and so on; or nullptr
reed@android.com8a1c16f2008-12-17 15:59:43 +00001581 */
reed0846f1b2015-01-09 14:17:40 -08001582 void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
Ben Wagnera93a14a2017-08-28 10:34:05 -04001583 const SkPaint* paint = nullptr);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001584
Cary Clark7651c162018-07-13 08:21:59 -04001585 /** Draws SkRect src of SkBitmap bitmap, scaled and translated to fill SkRect dst.
Cary Clarkb7da7232017-09-01 13:49:54 -04001586 Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.
1587
Cary Clark462505f2018-05-30 09:20:29 -04001588 If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter,
Cary Clarkb7da7232017-09-01 13:49:54 -04001589 SkBlendMode, and SkDrawLooper. If bitmap is kAlpha_8_SkColorType, apply SkShader.
1590 If paint contains SkMaskFilter, generate mask from bitmap bounds.
1591
1592 If generated mask extends beyond bitmap bounds, replicate bitmap edge colors,
1593 just as SkShader made from SkShader::MakeBitmapShader with
Cary Clarkcc309eb2017-10-30 11:48:35 -04001594 SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples
Cary Clarkb7da7232017-09-01 13:49:54 -04001595 outside of its bounds.
1596
1597 constraint set to kStrict_SrcRectConstraint limits SkPaint SkFilterQuality to
1598 sample within src; set to kFast_SrcRectConstraint allows sampling outside to
1599 improve performance.
1600
1601 @param bitmap SkBitmap containing pixels, dimensions, and format
1602 @param src source SkRect of image to draw from
1603 @param dst destination SkRect of image to draw to
1604 @param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
1605 and so on; or nullptr
1606 @param constraint filter strictly within src or draw faster
1607 */
reede47829b2015-08-06 10:02:53 -07001608 void drawBitmapRect(const SkBitmap& bitmap, const SkRect& src, const SkRect& dst,
Cary Clark0418a882017-05-10 09:07:42 -04001609 const SkPaint* paint,
1610 SrcRectConstraint constraint = kStrict_SrcRectConstraint);
Cary Clarkb7da7232017-09-01 13:49:54 -04001611
Cary Clark7651c162018-07-13 08:21:59 -04001612 /** Draws SkIRect isrc of SkBitmap bitmap, scaled and translated to fill SkRect dst.
Cary Clarkb7da7232017-09-01 13:49:54 -04001613 isrc is on integer pixel boundaries; dst may include fractional boundaries.
1614 Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.
1615
Cary Clark462505f2018-05-30 09:20:29 -04001616 If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter,
Cary Clarkb7da7232017-09-01 13:49:54 -04001617 SkBlendMode, and SkDrawLooper. If bitmap is kAlpha_8_SkColorType, apply SkShader.
1618 If paint contains SkMaskFilter, generate mask from bitmap bounds.
1619
1620 If generated mask extends beyond bitmap bounds, replicate bitmap edge colors,
1621 just as SkShader made from SkShader::MakeBitmapShader with
Cary Clarkcc309eb2017-10-30 11:48:35 -04001622 SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples
Cary Clarkb7da7232017-09-01 13:49:54 -04001623 outside of its bounds.
1624
1625 constraint set to kStrict_SrcRectConstraint limits SkPaint SkFilterQuality to
1626 sample within isrc; set to kFast_SrcRectConstraint allows sampling outside to
1627 improve performance.
1628
1629 @param bitmap SkBitmap containing pixels, dimensions, and format
1630 @param isrc source SkIRect of image to draw from
1631 @param dst destination SkRect of image to draw to
1632 @param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
1633 and so on; or nullptr
1634 @param constraint sample strictly within isrc, or draw faster
1635 */
reed84984ef2015-07-17 07:09:43 -07001636 void drawBitmapRect(const SkBitmap& bitmap, const SkIRect& isrc, const SkRect& dst,
Ben Wagner63fd7602017-10-09 15:45:33 -04001637 const SkPaint* paint,
Cary Clark0418a882017-05-10 09:07:42 -04001638 SrcRectConstraint constraint = kStrict_SrcRectConstraint);
Cary Clarkb7da7232017-09-01 13:49:54 -04001639
Cary Clark7651c162018-07-13 08:21:59 -04001640 /** Draws SkBitmap bitmap, scaled and translated to fill SkRect dst.
Cary Clarkb7da7232017-09-01 13:49:54 -04001641 bitmap bounds is on integer pixel boundaries; dst may include fractional boundaries.
1642 Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.
1643
Cary Clark462505f2018-05-30 09:20:29 -04001644 If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter,
Cary Clarkb7da7232017-09-01 13:49:54 -04001645 SkBlendMode, and SkDrawLooper. If bitmap is kAlpha_8_SkColorType, apply SkShader.
1646 If paint contains SkMaskFilter, generate mask from bitmap bounds.
1647
1648 If generated mask extends beyond bitmap bounds, replicate bitmap edge colors,
1649 just as SkShader made from SkShader::MakeBitmapShader with
Cary Clarkcc309eb2017-10-30 11:48:35 -04001650 SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples
Cary Clarkb7da7232017-09-01 13:49:54 -04001651 outside of its bounds.
1652
1653 constraint set to kStrict_SrcRectConstraint limits SkPaint SkFilterQuality to
1654 sample within bitmap; set to kFast_SrcRectConstraint allows sampling outside to
1655 improve performance.
1656
1657 @param bitmap SkBitmap containing pixels, dimensions, and format
1658 @param dst destination SkRect of image to draw to
1659 @param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
1660 and so on; or nullptr
1661 @param constraint filter strictly within bitmap or draw faster
1662 */
reede47829b2015-08-06 10:02:53 -07001663 void drawBitmapRect(const SkBitmap& bitmap, const SkRect& dst, const SkPaint* paint,
Cary Clark0418a882017-05-10 09:07:42 -04001664 SrcRectConstraint constraint = kStrict_SrcRectConstraint);
reed84984ef2015-07-17 07:09:43 -07001665
Cary Clark7651c162018-07-13 08:21:59 -04001666 /** Draws SkBitmap bitmap stretched proportionally to fit into SkRect dst.
Cary Clarkb7da7232017-09-01 13:49:54 -04001667 SkIRect center divides the bitmap into nine sections: four sides, four corners,
1668 and the center. Corners are not scaled, or scaled down proportionately if their
1669 sides are larger than dst; center and four sides are scaled to fit remaining
1670 space, if any.
1671
1672 Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.
1673
Cary Clark462505f2018-05-30 09:20:29 -04001674 If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter,
Cary Clarkb7da7232017-09-01 13:49:54 -04001675 SkBlendMode, and SkDrawLooper. If bitmap is kAlpha_8_SkColorType, apply SkShader.
Cary Clark462505f2018-05-30 09:20:29 -04001676 If paint contains SkMaskFilter, generate mask from bitmap bounds. If paint
1677 SkFilterQuality set to kNone_SkFilterQuality, disable pixel filtering. For all
1678 other values of paint SkFilterQuality, use kLow_SkFilterQuality to filter pixels.
1679 Any SkMaskFilter on paint is ignored as is paint anti-aliasing state.
Cary Clarkb7da7232017-09-01 13:49:54 -04001680
1681 If generated mask extends beyond bitmap bounds, replicate bitmap edge colors,
1682 just as SkShader made from SkShader::MakeBitmapShader with
Cary Clarkcc309eb2017-10-30 11:48:35 -04001683 SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples
Cary Clarkb7da7232017-09-01 13:49:54 -04001684 outside of its bounds.
1685
1686 @param bitmap SkBitmap containing pixels, dimensions, and format
1687 @param center SkIRect edge of image corners and sides
1688 @param dst destination SkRect of image to draw to
1689 @param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
1690 and so on; or nullptr
1691 */
reed0846f1b2015-01-09 14:17:40 -08001692 void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst,
Ben Wagnera93a14a2017-08-28 10:34:05 -04001693 const SkPaint* paint = nullptr);
reed@google.comf0b5e112011-09-07 11:57:34 +00001694
Cary Clarkb7da7232017-09-01 13:49:54 -04001695 /** \struct SkCanvas::Lattice
Cary Clark75959392018-02-27 10:22:04 -05001696 SkCanvas::Lattice divides SkBitmap or SkImage into a rectangular grid.
Cary Clark8a02b0b2017-09-21 12:28:43 -04001697 Grid entries on even columns and even rows are fixed; these entries are
1698 always drawn at their original size if the destination is large enough.
1699 If the destination side is too small to hold the fixed entries, all fixed
1700 entries are proportionately scaled down to fit.
1701 The grid entries not on even columns and rows are scaled to fit the
1702 remaining space, if any.
Cary Clarkb7da7232017-09-01 13:49:54 -04001703 */
msarettc573a402016-08-02 08:05:56 -07001704 struct Lattice {
Cary Clarkb7da7232017-09-01 13:49:54 -04001705
Stan Ilievca8c0952017-12-11 13:01:58 -05001706 /** \enum SkCanvas::Lattice::RectType
Cary Clark2823f9f2018-01-03 10:00:34 -05001707 Optional setting per rectangular grid entry to make it transparent,
1708 or to fill the grid entry with a color.
Cary Clarkb7da7232017-09-01 13:49:54 -04001709 */
Stan Ilievca8c0952017-12-11 13:01:58 -05001710 enum RectType : uint8_t {
Cary Clark462505f2018-05-30 09:20:29 -04001711 kDefault = 0, //!< draws SkBitmap into lattice rectangle
1712 kTransparent, //!< skips lattice rectangle by making it transparent
1713 kFixedColor, //!< draws one of fColors into lattice rectangle
msarett0764efe2016-09-02 11:24:30 -07001714 };
msarettc573a402016-08-02 08:05:56 -07001715
Cary Clarkca6a2452018-06-14 13:21:08 -04001716 const int* fXDivs; //!< x-axis values dividing bitmap
1717 const int* fYDivs; //!< y-axis values dividing bitmap
Cary Clark462505f2018-05-30 09:20:29 -04001718 const RectType* fRectTypes; //!< array of fill types
1719 int fXCount; //!< number of x-coordinates
1720 int fYCount; //!< number of y-coordinates
1721 const SkIRect* fBounds; //!< source bounds to draw from
1722 const SkColor* fColors; //!< array of colors
msarettc573a402016-08-02 08:05:56 -07001723 };
1724
Cary Clark7651c162018-07-13 08:21:59 -04001725 /** Draws SkBitmap bitmap stretched proportionally to fit into SkRect dst.
Cary Clarkb7da7232017-09-01 13:49:54 -04001726
Cary Clark75959392018-02-27 10:22:04 -05001727 SkCanvas::Lattice lattice divides bitmap into a rectangular grid.
Cary Clarkb7da7232017-09-01 13:49:54 -04001728 Each intersection of an even-numbered row and column is fixed; like the corners
1729 of drawBitmapNine(), fixed lattice elements never scale larger than their initial
Cary Clarkcc309eb2017-10-30 11:48:35 -04001730 size and shrink proportionately when all fixed elements exceed the bitmap
Cary Clarkb7da7232017-09-01 13:49:54 -04001731 dimension. All other grid elements scale to fill the available space, if any.
1732
1733 Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.
1734
Cary Clark462505f2018-05-30 09:20:29 -04001735 If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter,
Cary Clarkb7da7232017-09-01 13:49:54 -04001736 SkBlendMode, and SkDrawLooper. If bitmap is kAlpha_8_SkColorType, apply SkShader.
Cary Clark462505f2018-05-30 09:20:29 -04001737 If paint contains SkMaskFilter, generate mask from bitmap bounds. If paint
1738 SkFilterQuality set to kNone_SkFilterQuality, disable pixel filtering. For all
1739 other values of paint SkFilterQuality, use kLow_SkFilterQuality to filter pixels.
1740 Any SkMaskFilter on paint is ignored as is paint anti-aliasing state.
Cary Clarkb7da7232017-09-01 13:49:54 -04001741
1742 If generated mask extends beyond bitmap bounds, replicate bitmap edge colors,
1743 just as SkShader made from SkShader::MakeBitmapShader with
Cary Clarkcc309eb2017-10-30 11:48:35 -04001744 SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples
Cary Clarkb7da7232017-09-01 13:49:54 -04001745 outside of its bounds.
1746
1747 @param bitmap SkBitmap containing pixels, dimensions, and format
1748 @param lattice division of bitmap into fixed and variable rectangles
1749 @param dst destination SkRect of image to draw to
1750 @param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
1751 and so on; or nullptr
1752 */
msarettc573a402016-08-02 08:05:56 -07001753 void drawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice, const SkRect& dst,
1754 const SkPaint* paint = nullptr);
Cary Clarkb7da7232017-09-01 13:49:54 -04001755
Cary Clark7651c162018-07-13 08:21:59 -04001756 /** Draws SkImage image stretched proportionally to fit into SkRect dst.
Cary Clarkb7da7232017-09-01 13:49:54 -04001757
Cary Clark75959392018-02-27 10:22:04 -05001758 SkCanvas::Lattice lattice divides image into a rectangular grid.
Cary Clarkb7da7232017-09-01 13:49:54 -04001759 Each intersection of an even-numbered row and column is fixed; like the corners
1760 of drawBitmapNine(), fixed lattice elements never scale larger than their initial
Cary Clarkcc309eb2017-10-30 11:48:35 -04001761 size and shrink proportionately when all fixed elements exceed the bitmap
Cary Clarkb7da7232017-09-01 13:49:54 -04001762 dimension. All other grid elements scale to fill the available space, if any.
1763
1764 Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.
1765
Cary Clark462505f2018-05-30 09:20:29 -04001766 If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter,
1767 SkBlendMode, and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader.
1768 If paint contains SkMaskFilter, generate mask from image bounds. If paint
1769 SkFilterQuality set to kNone_SkFilterQuality, disable pixel filtering. For all
1770 other values of paint SkFilterQuality, use kLow_SkFilterQuality to filter pixels.
1771 Any SkMaskFilter on paint is ignored as is paint anti-aliasing state.
Cary Clarkb7da7232017-09-01 13:49:54 -04001772
1773 If generated mask extends beyond bitmap bounds, replicate bitmap edge colors,
1774 just as SkShader made from SkShader::MakeBitmapShader with
Cary Clarkcc309eb2017-10-30 11:48:35 -04001775 SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples
Cary Clarkb7da7232017-09-01 13:49:54 -04001776 outside of its bounds.
1777
1778 @param image SkImage containing pixels, dimensions, and format
1779 @param lattice division of bitmap into fixed and variable rectangles
1780 @param dst destination SkRect of image to draw to
1781 @param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
1782 and so on; or nullptr
1783 */
msarettc573a402016-08-02 08:05:56 -07001784 void drawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst,
1785 const SkPaint* paint = nullptr);
1786
Brian Salomond7065e72018-10-12 11:42:02 -04001787 /**
Cary Clarkabaffd82018-11-15 08:25:12 -05001788 * Experimental. Controls anti-aliasing of each edge of images in an image-set.
Brian Salomond7065e72018-10-12 11:42:02 -04001789 */
1790 enum QuadAAFlags : unsigned {
1791 kLeft_QuadAAFlag = 0b0001,
1792 kTop_QuadAAFlag = 0b0010,
1793 kRight_QuadAAFlag = 0b0100,
1794 kBottom_QuadAAFlag = 0b1000,
1795
1796 kNone_QuadAAFlags = 0b0000,
1797 kAll_QuadAAFlags = 0b1111,
1798 };
1799
1800 /** This is used by the experimental API below. */
Brian Salomon572fdcf2018-11-28 13:27:06 -05001801 struct ImageSetEntry {
Brian Salomond7065e72018-10-12 11:42:02 -04001802 sk_sp<const SkImage> fImage;
1803 SkRect fSrcRect;
1804 SkRect fDstRect;
Brian Salomon1da5cad2018-11-21 09:21:18 -05001805 float fAlpha;
Brian Salomond7065e72018-10-12 11:42:02 -04001806 unsigned fAAFlags; // QuadAAFlags
1807 };
1808
1809 /**
1810 * This is an experimental API for the SkiaRenderer Chromium project. The signature will
1811 * surely evolve if this is not removed. It currently offers no performance advantage over
1812 * drawing images independently, though may in the future. The antialiasing flags are intended
1813 * to allow control over each edge's AA status, to allow perfect seaming for tile sets. The
1814 * current implementation only antialiases if all edges are flagged, however.
Brian Salomon0087c832018-10-15 14:48:20 -04001815 * Results are undefined if an image's src rect is not within the image's bounds.
Brian Salomond7065e72018-10-12 11:42:02 -04001816 */
Brian Salomon1da5cad2018-11-21 09:21:18 -05001817 void experimental_DrawImageSetV1(const ImageSetEntry imageSet[], int cnt,
Brian Salomond7065e72018-10-12 11:42:02 -04001818 SkFilterQuality quality, SkBlendMode mode);
1819
Mike Reedcb268f62019-01-07 12:51:32 -05001820 /** DEPRECATED. Use drawSimpleText or drawTextBlob.
1821 Draws text, with origin at (x, y), using clip, SkMatrix, and SkPaint paint.
Cary Clarkb7da7232017-09-01 13:49:54 -04001822
Mike Reed97f3cc22018-12-03 09:45:17 -05001823 text meaning depends on SkTextEncoding; by default, text is encoded as
Cary Clarkb7da7232017-09-01 13:49:54 -04001824 UTF-8.
1825
1826 x and y meaning depends on SkPaint::Align and SkPaint vertical text; by default
Cary Clarkcc309eb2017-10-30 11:48:35 -04001827 text draws left to right, positioning the first glyph left side bearing at x
Cary Clarkb7da7232017-09-01 13:49:54 -04001828 and its baseline at y. Text size is affected by SkMatrix and SkPaint text size.
1829
Mike Reed8ad91a92018-01-19 19:09:32 -05001830 All elements of paint: SkPathEffect, SkMaskFilter, SkShader,
Cary Clarkb7da7232017-09-01 13:49:54 -04001831 SkColorFilter, SkImageFilter, and SkDrawLooper; apply to text. By default, draws
1832 filled 12 point black glyphs.
1833
1834 @param text character code points or glyphs drawn
1835 @param byteLength byte length of text array
1836 @param x start of text on x-axis
1837 @param y start of text on y-axis
1838 @param paint text size, blend, color, and so on, used to draw
reed@android.com8a1c16f2008-12-17 15:59:43 +00001839 */
reedf7430cc2014-12-21 11:38:35 -08001840 void drawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
1841 const SkPaint& paint);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001842
Mike Reedcb268f62019-01-07 12:51:32 -05001843 /** Draws text, with origin at (x, y), using clip, SkMatrix, and SkPaint paint.
1844
1845 text meaning depends on SkTextEncoding; by default, text is encoded as
1846 UTF-8.
1847
1848 x and y meaning depends on SkPaint::Align and SkPaint vertical text; by default
1849 text draws left to right, positioning the first glyph left side bearing at x
1850 and its baseline at y. Text size is affected by SkMatrix and SkPaint text size.
1851
1852 All elements of paint: SkPathEffect, SkMaskFilter, SkShader,
1853 SkColorFilter, SkImageFilter, and SkDrawLooper; apply to text. By default, draws
1854 filled 12 point black glyphs.
1855
1856 @param text character code points or glyphs drawn
1857 @param byteLength byte length of text array
1858 @param encoding text encoding used in the text array
1859 @param x start of text on x-axis
1860 @param y start of text on y-axis
1861 @param font typeface, text size and so, used to describe the text
1862 @param paint blend, color, and so on, used to draw
1863 */
Mike Reed358fcad2018-11-23 15:27:51 -05001864 void drawSimpleText(const void* text, size_t byteLength, SkTextEncoding encoding,
1865 SkScalar x, SkScalar y, const SkFont& font, const SkPaint& paint);
1866
Mike Reed4de2f1f2019-01-05 16:35:13 -05001867 // Experimental
1868 void drawString(const char str[], SkScalar x, SkScalar y, const SkFont& font,
1869 const SkPaint& paint) {
1870 this->drawSimpleText(str, strlen(str), kUTF8_SkTextEncoding, x, y, font, paint);
1871 }
1872 // Experimental
1873 void drawString(const SkString& str, SkScalar x, SkScalar y, const SkFont& font,
1874 const SkPaint& paint) {
1875 this->drawSimpleText(str.c_str(), str.size(), kUTF8_SkTextEncoding, x, y, font, paint);
1876 }
Cary Clark2a475ea2017-04-28 15:35:12 -04001877
Cary Clark7651c162018-07-13 08:21:59 -04001878 /** Draws SkTextBlob blob at (x, y), using clip, SkMatrix, and SkPaint paint.
Cary Clarkb7da7232017-09-01 13:49:54 -04001879
1880 blob contains glyphs, their positions, and paint attributes specific to text:
Cary Clarkaf045512018-08-10 13:11:06 -04001881 SkTypeface, SkPaint text size, SkPaint text scale x,
1882 SkPaint text skew x, SkPaint::Align, SkPaint::Hinting, anti-alias, SkPaint fake bold,
Cary Clark75959392018-02-27 10:22:04 -05001883 SkPaint font embedded bitmaps, SkPaint full hinting spacing, LCD text, SkPaint linear text,
Cary Clarkaf045512018-08-10 13:11:06 -04001884 and SkPaint subpixel text.
Cary Clarkb7da7232017-09-01 13:49:54 -04001885
Mike Reed97f3cc22018-12-03 09:45:17 -05001886 SkTextEncoding must be set to kGlyphID_SkTextEncoding.
Cary Clark2823f9f2018-01-03 10:00:34 -05001887
Cary Clarkaf045512018-08-10 13:11:06 -04001888 Elements of paint: anti-alias, SkBlendMode, color including alpha,
1889 SkColorFilter, SkPaint dither, SkDrawLooper, SkMaskFilter, SkPathEffect, SkShader, and
1890 SkPaint::Style; apply to blob. If SkPaint contains SkPaint::kStroke_Style:
1891 SkPaint miter limit, SkPaint::Cap, SkPaint::Join, and SkPaint stroke width;
1892 apply to SkPath created from blob.
Cary Clarkb7da7232017-09-01 13:49:54 -04001893
Cary Clark8a02b0b2017-09-21 12:28:43 -04001894 @param blob glyphs, positions, and their paints' text size, typeface, and so on
Cary Clarkb7da7232017-09-01 13:49:54 -04001895 @param x horizontal offset applied to blob
1896 @param y vertical offset applied to blob
1897 @param paint blend, color, stroking, and so on, used to draw
fmalita00d5c2c2014-08-21 08:53:26 -07001898 */
1899 void drawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPaint& paint);
Cary Clarkb7da7232017-09-01 13:49:54 -04001900
Cary Clark7651c162018-07-13 08:21:59 -04001901 /** Draws SkTextBlob blob at (x, y), using clip, SkMatrix, and SkPaint paint.
Cary Clarkb7da7232017-09-01 13:49:54 -04001902
1903 blob contains glyphs, their positions, and paint attributes specific to text:
Cary Clarkaf045512018-08-10 13:11:06 -04001904 SkTypeface, SkPaint text size, SkPaint text scale x,
1905 SkPaint text skew x, SkPaint::Align, SkPaint::Hinting, anti-alias, SkPaint fake bold,
Cary Clark75959392018-02-27 10:22:04 -05001906 SkPaint font embedded bitmaps, SkPaint full hinting spacing, LCD text, SkPaint linear text,
Cary Clarkaf045512018-08-10 13:11:06 -04001907 and SkPaint subpixel text.
Cary Clarkb7da7232017-09-01 13:49:54 -04001908
Mike Reed97f3cc22018-12-03 09:45:17 -05001909 SkTextEncoding must be set to kGlyphID_SkTextEncoding.
Cary Clark2823f9f2018-01-03 10:00:34 -05001910
Mike Reed8ad91a92018-01-19 19:09:32 -05001911 Elements of paint: SkPathEffect, SkMaskFilter, SkShader, SkColorFilter,
Cary Clarkb7da7232017-09-01 13:49:54 -04001912 SkImageFilter, and SkDrawLooper; apply to blob.
1913
Cary Clark8a02b0b2017-09-21 12:28:43 -04001914 @param blob glyphs, positions, and their paints' text size, typeface, and so on
Cary Clarkb7da7232017-09-01 13:49:54 -04001915 @param x horizontal offset applied to blob
1916 @param y vertical offset applied to blob
1917 @param paint blend, color, stroking, and so on, used to draw
1918 */
reed2ab90572016-08-10 14:16:41 -07001919 void drawTextBlob(const sk_sp<SkTextBlob>& blob, SkScalar x, SkScalar y, const SkPaint& paint) {
1920 this->drawTextBlob(blob.get(), x, y, paint);
1921 }
fmalita00d5c2c2014-08-21 08:53:26 -07001922
Cary Clark7651c162018-07-13 08:21:59 -04001923 /** Draws SkPicture picture, using clip and SkMatrix.
Cary Clarkb7da7232017-09-01 13:49:54 -04001924 Clip and SkMatrix are unchanged by picture contents, as if
1925 save() was called before and restore() was called after drawPicture().
1926
Cary Clark2823f9f2018-01-03 10:00:34 -05001927 SkPicture records a series of draw commands for later playback.
Cary Clarkb7da7232017-09-01 13:49:54 -04001928
1929 @param picture recorded drawing commands to play
reed@android.com8a1c16f2008-12-17 15:59:43 +00001930 */
reed1c2c4412015-04-30 13:09:24 -07001931 void drawPicture(const SkPicture* picture) {
Ben Wagnera93a14a2017-08-28 10:34:05 -04001932 this->drawPicture(picture, nullptr, nullptr);
reed1c2c4412015-04-30 13:09:24 -07001933 }
Cary Clarkb7da7232017-09-01 13:49:54 -04001934
Cary Clark7651c162018-07-13 08:21:59 -04001935 /** Draws SkPicture picture, using clip and SkMatrix.
Cary Clarkb7da7232017-09-01 13:49:54 -04001936 Clip and SkMatrix are unchanged by picture contents, as if
1937 save() was called before and restore() was called after drawPicture().
1938
Cary Clark2823f9f2018-01-03 10:00:34 -05001939 SkPicture records a series of draw commands for later playback.
Cary Clarkb7da7232017-09-01 13:49:54 -04001940
1941 @param picture recorded drawing commands to play
1942 */
reedca2622b2016-03-18 07:25:55 -07001943 void drawPicture(const sk_sp<SkPicture>& picture) {
reedf8053da2016-03-17 08:14:57 -07001944 this->drawPicture(picture.get());
1945 }
robertphillips9b14f262014-06-04 05:40:44 -07001946
Cary Clark7651c162018-07-13 08:21:59 -04001947 /** Draws SkPicture picture, using clip and SkMatrix; transforming picture with
Cary Clark462505f2018-05-30 09:20:29 -04001948 SkMatrix matrix, if provided; and use SkPaint paint alpha, SkColorFilter,
Cary Clarkb7da7232017-09-01 13:49:54 -04001949 SkImageFilter, and SkBlendMode, if provided.
1950
1951 matrix transformation is equivalent to: save(), concat(), drawPicture(), restore().
1952 paint use is equivalent to: saveLayer(), drawPicture(), restore().
1953
1954 @param picture recorded drawing commands to play
1955 @param matrix SkMatrix to rotate, scale, translate, and so on; may be nullptr
1956 @param paint SkPaint to apply transparency, filtering, and so on; may be nullptr
1957 */
Cary Clark0418a882017-05-10 09:07:42 -04001958 void drawPicture(const SkPicture* picture, const SkMatrix* matrix, const SkPaint* paint);
Cary Clarkb7da7232017-09-01 13:49:54 -04001959
Cary Clark7651c162018-07-13 08:21:59 -04001960 /** Draws SkPicture picture, using clip and SkMatrix; transforming picture with
Cary Clark462505f2018-05-30 09:20:29 -04001961 SkMatrix matrix, if provided; and use SkPaint paint alpha, SkColorFilter,
Cary Clarkb7da7232017-09-01 13:49:54 -04001962 SkImageFilter, and SkBlendMode, if provided.
1963
1964 matrix transformation is equivalent to: save(), concat(), drawPicture(), restore().
1965 paint use is equivalent to: saveLayer(), drawPicture(), restore().
1966
1967 @param picture recorded drawing commands to play
1968 @param matrix SkMatrix to rotate, scale, translate, and so on; may be nullptr
1969 @param paint SkPaint to apply transparency, filtering, and so on; may be nullptr
1970 */
Cary Clarkdcec3292018-09-13 11:32:08 -04001971 void drawPicture(const sk_sp<SkPicture>& picture, const SkMatrix* matrix,
1972 const SkPaint* paint) {
reedf8053da2016-03-17 08:14:57 -07001973 this->drawPicture(picture.get(), matrix, paint);
1974 }
reedd5fa1a42014-08-09 11:08:05 -07001975
Cary Clark7651c162018-07-13 08:21:59 -04001976 /** Draws SkVertices vertices, a triangle mesh, using clip and SkMatrix.
Cary Clarkb7da7232017-09-01 13:49:54 -04001977 If vertices texs and vertices colors are defined in vertices, and SkPaint paint
1978 contains SkShader, SkBlendMode mode combines vertices colors with SkShader.
Brian Salomon199fb872017-02-06 09:41:10 -05001979
Cary Clarkb7da7232017-09-01 13:49:54 -04001980 @param vertices triangle mesh to draw
1981 @param mode combines vertices colors with SkShader, if both are present
Cary Clark462505f2018-05-30 09:20:29 -04001982 @param paint specifies the SkShader, used as SkVertices texture; may be nullptr
Cary Clarkb7da7232017-09-01 13:49:54 -04001983 */
Mike Reede88a1cb2017-03-17 09:50:46 -04001984 void drawVertices(const SkVertices* vertices, SkBlendMode mode, const SkPaint& paint);
Cary Clarkb7da7232017-09-01 13:49:54 -04001985
Cary Clark7651c162018-07-13 08:21:59 -04001986 /** Draws SkVertices vertices, a triangle mesh, using clip and SkMatrix.
Cary Clarkb7da7232017-09-01 13:49:54 -04001987 If vertices texs and vertices colors are defined in vertices, and SkPaint paint
1988 contains SkShader, SkBlendMode mode combines vertices colors with SkShader.
1989
1990 @param vertices triangle mesh to draw
1991 @param mode combines vertices colors with SkShader, if both are present
Cary Clark462505f2018-05-30 09:20:29 -04001992 @param paint specifies the SkShader, used as SkVertices texture, may be nullptr
Cary Clarkb7da7232017-09-01 13:49:54 -04001993 */
Mike Reede88a1cb2017-03-17 09:50:46 -04001994 void drawVertices(const sk_sp<SkVertices>& vertices, SkBlendMode mode, const SkPaint& paint);
Mike Reed7d954ad2016-10-28 15:42:34 -04001995
Cary Clark7651c162018-07-13 08:21:59 -04001996 /** Draws SkVertices vertices, a triangle mesh, using clip and SkMatrix. Bone data is used to
Ruiqi Maof5101492018-06-29 14:32:21 -04001997 deform vertices with bone weights.
1998 If vertices texs and vertices colors are defined in vertices, and SkPaint paint
1999 contains SkShader, SkBlendMode mode combines vertices colors with SkShader.
2000 The first element of bones should be an object to world space transformation matrix that
2001 will be applied before performing mesh deformations. If no such transformation is needed,
2002 it should be the identity matrix.
Ruiqi Maoc97a3392018-08-15 10:44:19 -04002003 boneCount must be at most 80, and thus the size of bones should be at most 80.
Ruiqi Maof5101492018-06-29 14:32:21 -04002004
Ruiqi Mao94d57c42018-07-02 15:20:10 -04002005 @param vertices triangle mesh to draw
2006 @param bones bone matrix data
2007 @param boneCount number of bone matrices
2008 @param mode combines vertices colors with SkShader, if both are present
2009 @param paint specifies the SkShader, used as SkVertices texture, may be nullptr
Ruiqi Maof5101492018-06-29 14:32:21 -04002010 */
Ruiqi Maoc97a3392018-08-15 10:44:19 -04002011 void drawVertices(const SkVertices* vertices, const SkVertices::Bone bones[], int boneCount,
Ruiqi Maof5101492018-06-29 14:32:21 -04002012 SkBlendMode mode, const SkPaint& paint);
2013
Cary Clark7651c162018-07-13 08:21:59 -04002014 /** Draws SkVertices vertices, a triangle mesh, using clip and SkMatrix. Bone data is used to
Ruiqi Maof5101492018-06-29 14:32:21 -04002015 deform vertices with bone weights.
2016 If vertices texs and vertices colors are defined in vertices, and SkPaint paint
2017 contains SkShader, SkBlendMode mode combines vertices colors with SkShader.
2018 The first element of bones should be an object to world space transformation matrix that
2019 will be applied before performing mesh deformations. If no such transformation is needed,
2020 it should be the identity matrix.
Ruiqi Maoc97a3392018-08-15 10:44:19 -04002021 boneCount must be at most 80, and thus the size of bones should be at most 80.
Ruiqi Maof5101492018-06-29 14:32:21 -04002022
Ruiqi Mao94d57c42018-07-02 15:20:10 -04002023 @param vertices triangle mesh to draw
2024 @param bones bone matrix data
2025 @param boneCount number of bone matrices
2026 @param mode combines vertices colors with SkShader, if both are present
2027 @param paint specifies the SkShader, used as SkVertices texture, may be nullptr
Ruiqi Maof5101492018-06-29 14:32:21 -04002028 */
Ruiqi Maoc97a3392018-08-15 10:44:19 -04002029 void drawVertices(const sk_sp<SkVertices>& vertices, const SkVertices::Bone bones[],
2030 int boneCount, SkBlendMode mode, const SkPaint& paint);
Ruiqi Maof5101492018-06-29 14:32:21 -04002031
Cary Clarkca6a2452018-06-14 13:21:08 -04002032 /** Draws a Coons patch: the interpolation of four cubics with shared corners,
2033 associating a color, and optionally a texture SkPoint, with each corner.
mtklein6cfa73a2014-08-13 13:33:49 -07002034
Cary Clarkca6a2452018-06-14 13:21:08 -04002035 Coons patch uses clip and SkMatrix, paint SkShader, SkColorFilter,
Cary Clark462505f2018-05-30 09:20:29 -04002036 alpha, SkImageFilter, and SkBlendMode. If SkShader is provided it is treated
Cary Clarkca6a2452018-06-14 13:21:08 -04002037 as Coons patch texture; SkBlendMode mode combines color colors and SkShader if
Cary Clarkb7da7232017-09-01 13:49:54 -04002038 both are provided.
2039
Cary Clark75959392018-02-27 10:22:04 -05002040 SkPoint array cubics specifies four SkPath cubic starting at the top-left corner,
2041 in clockwise order, sharing every fourth point. The last SkPath cubic ends at the
Cary Clarkb7da7232017-09-01 13:49:54 -04002042 first point.
2043
Cary Clarkcc309eb2017-10-30 11:48:35 -04002044 Color array color associates colors with corners in top-left, top-right,
2045 bottom-right, bottom-left order.
Cary Clarkb7da7232017-09-01 13:49:54 -04002046
2047 If paint contains SkShader, SkPoint array texCoords maps SkShader as texture to
Cary Clarkcc309eb2017-10-30 11:48:35 -04002048 corners in top-left, top-right, bottom-right, bottom-left order.
Cary Clarkb7da7232017-09-01 13:49:54 -04002049
2050 @param cubics SkPath cubic array, sharing common points
Cary Clark8a02b0b2017-09-21 12:28:43 -04002051 @param colors color array, one for each corner
Cary Clarkb7da7232017-09-01 13:49:54 -04002052 @param texCoords SkPoint array of texture coordinates, mapping SkShader to corners;
2053 may be nullptr
2054 @param mode SkBlendMode for colors, and for SkShader if paint has one
2055 @param paint SkShader, SkColorFilter, SkBlendMode, used to draw
2056 */
dandovb3c9d1c2014-08-12 08:34:29 -07002057 void drawPatch(const SkPoint cubics[12], const SkColor colors[4],
Mike Reed7d954ad2016-10-28 15:42:34 -04002058 const SkPoint texCoords[4], SkBlendMode mode, const SkPaint& paint);
Cary Clarkb7da7232017-09-01 13:49:54 -04002059
Cary Clarkca6a2452018-06-14 13:21:08 -04002060 /** Draws SkPath cubic Coons patch: the interpolation of four cubics with shared corners,
2061 associating a color, and optionally a texture SkPoint, with each corner.
Cary Clarkb7da7232017-09-01 13:49:54 -04002062
Cary Clarkca6a2452018-06-14 13:21:08 -04002063 Coons patch uses clip and SkMatrix, paint SkShader, SkColorFilter,
Cary Clark462505f2018-05-30 09:20:29 -04002064 alpha, SkImageFilter, and SkBlendMode. If SkShader is provided it is treated
Cary Clarkca6a2452018-06-14 13:21:08 -04002065 as Coons patch texture; SkBlendMode mode combines color colors and SkShader if
Cary Clarkb7da7232017-09-01 13:49:54 -04002066 both are provided.
2067
Cary Clark75959392018-02-27 10:22:04 -05002068 SkPoint array cubics specifies four SkPath cubic starting at the top-left corner,
2069 in clockwise order, sharing every fourth point. The last SkPath cubic ends at the
Cary Clarkb7da7232017-09-01 13:49:54 -04002070 first point.
2071
Cary Clarkcc309eb2017-10-30 11:48:35 -04002072 Color array color associates colors with corners in top-left, top-right,
2073 bottom-right, bottom-left order.
Cary Clarkb7da7232017-09-01 13:49:54 -04002074
2075 If paint contains SkShader, SkPoint array texCoords maps SkShader as texture to
Cary Clarkcc309eb2017-10-30 11:48:35 -04002076 corners in top-left, top-right, bottom-right, bottom-left order.
Cary Clarkb7da7232017-09-01 13:49:54 -04002077
2078 @param cubics SkPath cubic array, sharing common points
Cary Clark8a02b0b2017-09-21 12:28:43 -04002079 @param colors color array, one for each corner
Cary Clarkb7da7232017-09-01 13:49:54 -04002080 @param texCoords SkPoint array of texture coordinates, mapping SkShader to corners;
2081 may be nullptr
2082 @param paint SkShader, SkColorFilter, SkBlendMode, used to draw
2083 */
Mike Reed7d954ad2016-10-28 15:42:34 -04002084 void drawPatch(const SkPoint cubics[12], const SkColor colors[4],
2085 const SkPoint texCoords[4], const SkPaint& paint) {
2086 this->drawPatch(cubics, colors, texCoords, SkBlendMode::kModulate, paint);
2087 }
2088
Cary Clark7651c162018-07-13 08:21:59 -04002089 /** Draws a set of sprites from atlas, using clip, SkMatrix, and optional SkPaint paint.
Cary Clark462505f2018-05-30 09:20:29 -04002090 paint uses anti-alias, alpha, SkColorFilter, SkImageFilter, and SkBlendMode
Cary Clarkb7da7232017-09-01 13:49:54 -04002091 to draw, if present. For each entry in the array, SkRect tex locates sprite in
2092 atlas, and SkRSXform xform transforms it into destination space.
2093
2094 xform, text, and colors if present, must contain count entries.
Ruiqi Mao94d57c42018-07-02 15:20:10 -04002095 Optional colors are applied for each sprite using SkBlendMode mode, treating
2096 sprite as source and colors as destination.
Cary Clarkb7da7232017-09-01 13:49:54 -04002097 Optional cullRect is a conservative bounds of all transformed sprites.
2098 If cullRect is outside of clip, canvas can skip drawing.
2099
2100 @param atlas SkImage containing sprites
2101 @param xform SkRSXform mappings for sprites in atlas
2102 @param tex SkRect locations of sprites in atlas
Cary Clark8a02b0b2017-09-21 12:28:43 -04002103 @param colors one per sprite, blended with sprite using SkBlendMode; may be nullptr
Cary Clarkb7da7232017-09-01 13:49:54 -04002104 @param count number of sprites to draw
2105 @param mode SkBlendMode combining colors and sprites
Cary Clark8a02b0b2017-09-21 12:28:43 -04002106 @param cullRect bounds of transformed sprites for efficient clipping; may be nullptr
2107 @param paint SkColorFilter, SkImageFilter, SkBlendMode, and so on; may be nullptr
Cary Clarkb7da7232017-09-01 13:49:54 -04002108 */
reed71c3c762015-06-24 10:29:17 -07002109 void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[],
Cary Clark0418a882017-05-10 09:07:42 -04002110 const SkColor colors[], int count, SkBlendMode mode, const SkRect* cullRect,
reed71c3c762015-06-24 10:29:17 -07002111 const SkPaint* paint);
Cary Clarkb7da7232017-09-01 13:49:54 -04002112
Cary Clark7651c162018-07-13 08:21:59 -04002113 /** Draws a set of sprites from atlas, using clip, SkMatrix, and optional SkPaint paint.
Cary Clark462505f2018-05-30 09:20:29 -04002114 paint uses anti-alias, alpha, SkColorFilter, SkImageFilter, and SkBlendMode
Cary Clarkb7da7232017-09-01 13:49:54 -04002115 to draw, if present. For each entry in the array, SkRect tex locates sprite in
2116 atlas, and SkRSXform xform transforms it into destination space.
2117
2118 xform, text, and colors if present, must contain count entries.
2119 Optional colors is applied for each sprite using SkBlendMode.
2120 Optional cullRect is a conservative bounds of all transformed sprites.
2121 If cullRect is outside of clip, canvas can skip drawing.
2122
2123 @param atlas SkImage containing sprites
2124 @param xform SkRSXform mappings for sprites in atlas
2125 @param tex SkRect locations of sprites in atlas
Cary Clark8a02b0b2017-09-21 12:28:43 -04002126 @param colors one per sprite, blended with sprite using SkBlendMode; may be nullptr
Cary Clarkb7da7232017-09-01 13:49:54 -04002127 @param count number of sprites to draw
2128 @param mode SkBlendMode combining colors and sprites
Cary Clark8a02b0b2017-09-21 12:28:43 -04002129 @param cullRect bounds of transformed sprites for efficient clipping; may be nullptr
2130 @param paint SkColorFilter, SkImageFilter, SkBlendMode, and so on; may be nullptr
Cary Clarkb7da7232017-09-01 13:49:54 -04002131 */
Mike Reed7d954ad2016-10-28 15:42:34 -04002132 void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[],
2133 const SkColor colors[], int count, SkBlendMode mode, const SkRect* cullRect,
2134 const SkPaint* paint) {
2135 this->drawAtlas(atlas.get(), xform, tex, colors, count, mode, cullRect, paint);
2136 }
Cary Clarkb7da7232017-09-01 13:49:54 -04002137
Cary Clark7651c162018-07-13 08:21:59 -04002138 /** Draws a set of sprites from atlas, using clip, SkMatrix, and optional SkPaint paint.
Cary Clark462505f2018-05-30 09:20:29 -04002139 paint uses anti-alias, alpha, SkColorFilter, SkImageFilter, and SkBlendMode
Cary Clarkb7da7232017-09-01 13:49:54 -04002140 to draw, if present. For each entry in the array, SkRect tex locates sprite in
2141 atlas, and SkRSXform xform transforms it into destination space.
2142
2143 xform and text must contain count entries.
2144 Optional cullRect is a conservative bounds of all transformed sprites.
2145 If cullRect is outside of clip, canvas can skip drawing.
2146
2147 @param atlas SkImage containing sprites
2148 @param xform SkRSXform mappings for sprites in atlas
2149 @param tex SkRect locations of sprites in atlas
2150 @param count number of sprites to draw
Cary Clark8a02b0b2017-09-21 12:28:43 -04002151 @param cullRect bounds of transformed sprites for efficient clipping; may be nullptr
2152 @param paint SkColorFilter, SkImageFilter, SkBlendMode, and so on; may be nullptr
Cary Clarkb7da7232017-09-01 13:49:54 -04002153 */
reed71c3c762015-06-24 10:29:17 -07002154 void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], int count,
2155 const SkRect* cullRect, const SkPaint* paint) {
Mike Reed7d954ad2016-10-28 15:42:34 -04002156 this->drawAtlas(atlas, xform, tex, nullptr, count, SkBlendMode::kDst, cullRect, paint);
2157 }
Cary Clarkb7da7232017-09-01 13:49:54 -04002158
Cary Clark7651c162018-07-13 08:21:59 -04002159 /** Draws a set of sprites from atlas, using clip, SkMatrix, and optional SkPaint paint.
Cary Clark462505f2018-05-30 09:20:29 -04002160 paint uses anti-alias, alpha, SkColorFilter, SkImageFilter, and SkBlendMode
Cary Clarkb7da7232017-09-01 13:49:54 -04002161 to draw, if present. For each entry in the array, SkRect tex locates sprite in
2162 atlas, and SkRSXform xform transforms it into destination space.
2163
2164 xform and text must contain count entries.
2165 Optional cullRect is a conservative bounds of all transformed sprites.
2166 If cullRect is outside of clip, canvas can skip drawing.
2167
2168 @param atlas SkImage containing sprites
2169 @param xform SkRSXform mappings for sprites in atlas
2170 @param tex SkRect locations of sprites in atlas
2171 @param count number of sprites to draw
Cary Clark8a02b0b2017-09-21 12:28:43 -04002172 @param cullRect bounds of transformed sprites for efficient clipping; may be nullptr
2173 @param paint SkColorFilter, SkImageFilter, SkBlendMode, and so on; may be nullptr
Cary Clarkb7da7232017-09-01 13:49:54 -04002174 */
Mike Reed7d954ad2016-10-28 15:42:34 -04002175 void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[],
2176 int count, const SkRect* cullRect, const SkPaint* paint) {
2177 this->drawAtlas(atlas.get(), xform, tex, nullptr, count, SkBlendMode::kDst,
2178 cullRect, paint);
2179 }
2180
Cary Clark7651c162018-07-13 08:21:59 -04002181 /** Draws SkDrawable drawable using clip and SkMatrix, concatenated with
Cary Clarkb7da7232017-09-01 13:49:54 -04002182 optional matrix.
2183
2184 If SkCanvas has an asynchronous implementation, as is the case
Cary Clark2823f9f2018-01-03 10:00:34 -05002185 when it is recording into SkPicture, then drawable will be referenced,
Cary Clarkb7da7232017-09-01 13:49:54 -04002186 so that SkDrawable::draw() can be called when the operation is finalized. To force
2187 immediate drawing, call SkDrawable::draw() instead.
2188
2189 @param drawable custom struct encapsulating drawing commands
2190 @param matrix transformation applied to drawing; may be nullptr
2191 */
Ben Wagnera93a14a2017-08-28 10:34:05 -04002192 void drawDrawable(SkDrawable* drawable, const SkMatrix* matrix = nullptr);
Cary Clarkb7da7232017-09-01 13:49:54 -04002193
Cary Clark7651c162018-07-13 08:21:59 -04002194 /** Draws SkDrawable drawable using clip and SkMatrix, offset by (x, y).
Cary Clarkb7da7232017-09-01 13:49:54 -04002195
2196 If SkCanvas has an asynchronous implementation, as is the case
Cary Clark2823f9f2018-01-03 10:00:34 -05002197 when it is recording into SkPicture, then drawable will be referenced,
Cary Clarkb7da7232017-09-01 13:49:54 -04002198 so that SkDrawable::draw() can be called when the operation is finalized. To force
2199 immediate drawing, call SkDrawable::draw() instead.
2200
2201 @param drawable custom struct encapsulating drawing commands
Cary Clarkca6a2452018-06-14 13:21:08 -04002202 @param x offset into SkCanvas writable pixels on x-axis
2203 @param y offset into SkCanvas writable pixels on y-axis
Cary Clarkb7da7232017-09-01 13:49:54 -04002204 */
Cary Clark0418a882017-05-10 09:07:42 -04002205 void drawDrawable(SkDrawable* drawable, SkScalar x, SkScalar y);
reed6a070dc2014-11-11 19:36:09 -08002206
Cary Clark7651c162018-07-13 08:21:59 -04002207 /** Associates SkRect on SkCanvas with an annotation; a key-value pair, where the key is
Cary Clark82456492018-10-31 10:54:50 -04002208 a null-terminated UTF-8 string, and optional value is stored as SkData.
Cary Clarkb7da7232017-09-01 13:49:54 -04002209
Cary Clark2823f9f2018-01-03 10:00:34 -05002210 Only some canvas implementations, such as recording to SkPicture, or drawing to
Cary Clark82456492018-10-31 10:54:50 -04002211 document PDF, use annotations.
Cary Clarkb7da7232017-09-01 13:49:54 -04002212
2213 @param rect SkRect extent of canvas to annotate
2214 @param key string used for lookup
2215 @param value data holding value stored in annotation
2216 */
Cary Clark0418a882017-05-10 09:07:42 -04002217 void drawAnnotation(const SkRect& rect, const char key[], SkData* value);
Cary Clarkb7da7232017-09-01 13:49:54 -04002218
Cary Clark7651c162018-07-13 08:21:59 -04002219 /** Associates SkRect on SkCanvas when an annotation; a key-value pair, where the key is
Cary Clark82456492018-10-31 10:54:50 -04002220 a null-terminated UTF-8 string, and optional value is stored as SkData.
Cary Clarkb7da7232017-09-01 13:49:54 -04002221
Cary Clark2823f9f2018-01-03 10:00:34 -05002222 Only some canvas implementations, such as recording to SkPicture, or drawing to
Cary Clark82456492018-10-31 10:54:50 -04002223 document PDF, use annotations.
Cary Clarkb7da7232017-09-01 13:49:54 -04002224
2225 @param rect SkRect extent of canvas to annotate
2226 @param key string used for lookup
2227 @param value data holding value stored in annotation
2228 */
mtklein0fba3b92016-04-01 04:55:51 -07002229 void drawAnnotation(const SkRect& rect, const char key[], const sk_sp<SkData>& value) {
2230 this->drawAnnotation(rect, key, value.get());
2231 }
reedf70b5312016-03-04 16:36:20 -08002232
Cary Clarkb7da7232017-09-01 13:49:54 -04002233 /** Returns true if clip is empty; that is, nothing will draw.
2234
2235 May do work when called; it should not be called
2236 more often than needed. However, once called, subsequent calls perform no
2237 work until clip changes.
2238
2239 @return true if clip is empty
2240 */
robertphillips@google.com8f90a892014-02-28 18:19:39 +00002241 virtual bool isClipEmpty() const;
reed@google.com754de5f2014-02-24 19:38:20 +00002242
Cary Clarkb7da7232017-09-01 13:49:54 -04002243 /** Returns true if clip is SkRect and not empty.
2244 Returns false if the clip is empty, or if it is not SkRect.
2245
2246 @return true if clip is SkRect and not empty
2247 */
commit-bot@chromium.org5c70cdc2014-03-08 03:57:19 +00002248 virtual bool isClipRect() const;
2249
Cary Clarkb7da7232017-09-01 13:49:54 -04002250 /** Returns SkMatrix.
2251 This does not account for translation by SkBaseDevice or SkSurface.
2252
2253 @return SkMatrix in SkCanvas
reed@android.com8a1c16f2008-12-17 15:59:43 +00002254 */
junov@chromium.orga907ac32012-02-24 21:54:07 +00002255 const SkMatrix& getTotalMatrix() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00002256
reed@android.com8a1c16f2008-12-17 15:59:43 +00002257 ///////////////////////////////////////////////////////////////////////////
2258
robertphillips36736a22016-04-23 08:26:43 -07002259 // don't call
Brian Osman61b43da2017-11-01 09:26:38 -04002260 virtual GrRenderTargetContext* internal_private_accessTopLayerRenderTargetContext();
Derek Sollenberger8103bb92018-05-31 13:34:48 -04002261 SkIRect internal_private_getTopLayerBounds() const { return getTopLayerBounds(); }
robertphillips36736a22016-04-23 08:26:43 -07002262
robertphillips36736a22016-04-23 08:26:43 -07002263 // TEMP helpers until we switch virtual over to const& for src-rect
2264 void legacy_drawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
2265 const SkPaint* paint,
2266 SrcRectConstraint constraint = kStrict_SrcRectConstraint);
2267 void legacy_drawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst,
2268 const SkPaint* paint,
2269 SrcRectConstraint constraint = kStrict_SrcRectConstraint);
2270
Mike Reeda1361362017-03-07 09:37:29 -05002271 /**
2272 * Returns the global clip as a region. If the clip contains AA, then only the bounds
2273 * of the clip may be returned.
2274 */
Cary Clark0418a882017-05-10 09:07:42 -04002275 void temporary_internal_getRgnClip(SkRegion* region);
Mike Reed3726a4a2017-01-19 11:36:41 -05002276
Mike Reed4204da22017-05-17 08:53:36 -04002277 void private_draw_shadow_rec(const SkPath&, const SkDrawShadowRec&);
2278
Herb Derby76d69b42018-03-15 17:34:40 -04002279
robertphillipsda2cd8b2016-04-21 11:05:32 -07002280protected:
reed@google.com76f10a32014-02-05 15:32:21 +00002281 // default impl defers to getDevice()->newSurface(info)
Cary Clark0418a882017-05-10 09:07:42 -04002282 virtual sk_sp<SkSurface> onNewSurface(const SkImageInfo& info, const SkSurfaceProps& props);
reed@google.com76f10a32014-02-05 15:32:21 +00002283
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +00002284 // default impl defers to its device
Cary Clark0418a882017-05-10 09:07:42 -04002285 virtual bool onPeekPixels(SkPixmap* pixmap);
2286 virtual bool onAccessTopLayerPixels(SkPixmap* pixmap);
reedea5a6512016-07-07 16:44:27 -07002287 virtual SkImageInfo onImageInfo() const;
Cary Clark0418a882017-05-10 09:07:42 -04002288 virtual bool onGetProps(SkSurfaceProps* props) const;
reedea5a6512016-07-07 16:44:27 -07002289 virtual void onFlush();
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +00002290
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +00002291 // Subclass save/restore notifiers.
2292 // Overriders should call the corresponding INHERITED method up the inheritance chain.
reed4960eee2015-12-18 07:09:18 -08002293 // getSaveLayerStrategy()'s return value may suppress full layer allocation.
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +00002294 enum SaveLayerStrategy {
2295 kFullLayer_SaveLayerStrategy,
reed4960eee2015-12-18 07:09:18 -08002296 kNoLayer_SaveLayerStrategy,
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +00002297 };
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +00002298
fmalita6ca763f2014-06-17 13:52:18 -07002299 virtual void willSave() {}
reed4960eee2015-12-18 07:09:18 -08002300 // Overriders should call the corresponding INHERITED method up the inheritance chain.
Cary Clark0418a882017-05-10 09:07:42 -04002301 virtual SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec& ) {
reed4960eee2015-12-18 07:09:18 -08002302 return kFullLayer_SaveLayerStrategy;
2303 }
Mike Reed148b7fd2018-12-18 17:38:18 -05002304 // returns true if we should actually perform the saveBehind, or false if we should just save.
2305 virtual bool onDoSaveBehind(const SkRect*) { return true; }
commit-bot@chromium.orgfc6dfba2014-05-14 13:13:44 +00002306 virtual void willRestore() {}
mtklein6cfa73a2014-08-13 13:33:49 -07002307 virtual void didRestore() {}
Cary Clark0418a882017-05-10 09:07:42 -04002308 virtual void didConcat(const SkMatrix& ) {}
2309 virtual void didSetMatrix(const SkMatrix& ) {}
mtkleincbdf0072016-08-19 09:05:27 -07002310 virtual void didTranslate(SkScalar dx, SkScalar dy) {
2311 this->didConcat(SkMatrix::MakeTrans(dx, dy));
2312 }
vjiaoblack95302da2016-07-21 10:25:54 -07002313
Brian Osman37886ce2018-03-09 13:40:31 -05002314 // NOTE: If you are adding a new onDraw virtual to SkCanvas, PLEASE add an override to
2315 // SkCanvasVirtualEnforcer (in SkCanvasVirtualEnforcer.h). This ensures that subclasses using
2316 // that mechanism will be required to implement the new function.
2317 virtual void onDrawPaint(const SkPaint& paint);
2318 virtual void onDrawRect(const SkRect& rect, const SkPaint& paint);
2319 virtual void onDrawRRect(const SkRRect& rrect, const SkPaint& paint);
Cary Clark0418a882017-05-10 09:07:42 -04002320 virtual void onDrawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint);
Brian Osman37886ce2018-03-09 13:40:31 -05002321 virtual void onDrawOval(const SkRect& rect, const SkPaint& paint);
2322 virtual void onDrawArc(const SkRect& rect, SkScalar startAngle, SkScalar sweepAngle,
2323 bool useCenter, const SkPaint& paint);
2324 virtual void onDrawPath(const SkPath& path, const SkPaint& paint);
2325 virtual void onDrawRegion(const SkRegion& region, const SkPaint& paint);
commit-bot@chromium.orged9806f2014-02-21 02:32:36 +00002326
fmalita00d5c2c2014-08-21 08:53:26 -07002327 virtual void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
2328 const SkPaint& paint);
2329
dandovb3c9d1c2014-08-12 08:34:29 -07002330 virtual void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
Cary Clark0418a882017-05-10 09:07:42 -04002331 const SkPoint texCoords[4], SkBlendMode mode, const SkPaint& paint);
Cary Clark0418a882017-05-10 09:07:42 -04002332 virtual void onDrawPoints(PointMode mode, size_t count, const SkPoint pts[],
2333 const SkPaint& paint);
Ruiqi Maof5101492018-06-29 14:32:21 -04002334
2335 // TODO: Remove old signature
Cary Clark0418a882017-05-10 09:07:42 -04002336 virtual void onDrawVerticesObject(const SkVertices* vertices, SkBlendMode mode,
Ruiqi Maof5101492018-06-29 14:32:21 -04002337 const SkPaint& paint) {
2338 this->onDrawVerticesObject(vertices, nullptr, 0, mode, paint);
2339 }
Ruiqi Maoc97a3392018-08-15 10:44:19 -04002340 virtual void onDrawVerticesObject(const SkVertices* vertices, const SkVertices::Bone bones[],
Ruiqi Maof5101492018-06-29 14:32:21 -04002341 int boneCount, SkBlendMode mode, const SkPaint& paint);
Brian Osman37886ce2018-03-09 13:40:31 -05002342
Cary Clark0418a882017-05-10 09:07:42 -04002343 virtual void onDrawImage(const SkImage* image, SkScalar dx, SkScalar dy, const SkPaint* paint);
2344 virtual void onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
2345 const SkPaint* paint, SrcRectConstraint constraint);
2346 virtual void onDrawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst,
2347 const SkPaint* paint);
2348 virtual void onDrawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst,
2349 const SkPaint* paint);
reed4c21dc52015-06-25 12:32:03 -07002350
Brian Salomond003d222018-11-26 13:25:05 -05002351 virtual void onDrawImageSet(const ImageSetEntry imageSet[], int count, SkFilterQuality,
2352 SkBlendMode);
Brian Salomond7065e72018-10-12 11:42:02 -04002353
Cary Clark0418a882017-05-10 09:07:42 -04002354 virtual void onDrawBitmap(const SkBitmap& bitmap, SkScalar dx, SkScalar dy,
2355 const SkPaint* paint);
2356 virtual void onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst,
2357 const SkPaint* paint, SrcRectConstraint constraint);
2358 virtual void onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst,
2359 const SkPaint* paint);
2360 virtual void onDrawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice,
2361 const SkRect& dst, const SkPaint* paint);
Brian Osman37886ce2018-03-09 13:40:31 -05002362
2363 virtual void onDrawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect rect[],
2364 const SkColor colors[], int count, SkBlendMode mode,
2365 const SkRect* cull, const SkPaint* paint);
2366
2367 virtual void onDrawAnnotation(const SkRect& rect, const char key[], SkData* value);
Mike Reed4204da22017-05-17 08:53:36 -04002368 virtual void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&);
reed41af9662015-01-05 07:49:08 -08002369
Brian Osman37886ce2018-03-09 13:40:31 -05002370 virtual void onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix);
2371 virtual void onDrawPicture(const SkPicture* picture, const SkMatrix* matrix,
2372 const SkPaint* paint);
2373
robertphillips@google.com8f90a892014-02-28 18:19:39 +00002374 enum ClipEdgeStyle {
2375 kHard_ClipEdgeStyle,
2376 kSoft_ClipEdgeStyle
2377 };
2378
Cary Clark0418a882017-05-10 09:07:42 -04002379 virtual void onClipRect(const SkRect& rect, SkClipOp op, ClipEdgeStyle edgeStyle);
2380 virtual void onClipRRect(const SkRRect& rrect, SkClipOp op, ClipEdgeStyle edgeStyle);
2381 virtual void onClipPath(const SkPath& path, SkClipOp op, ClipEdgeStyle edgeStyle);
2382 virtual void onClipRegion(const SkRegion& deviceRgn, SkClipOp op);
robertphillips@google.com8f90a892014-02-28 18:19:39 +00002383
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +00002384 virtual void onDiscard();
2385
junov@chromium.orga907ac32012-02-24 21:54:07 +00002386 // Clip rectangle bounds. Called internally by saveLayer.
2387 // returns false if the entire rectangle is entirely clipped out
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +00002388 // If non-NULL, The imageFilter parameter will be used to expand the clip
2389 // and offscreen bounds for any margin required by the filter DAG.
Cary Clark0418a882017-05-10 09:07:42 -04002390 bool clipRectBounds(const SkRect* bounds, SaveLayerFlags flags, SkIRect* intersection,
Ben Wagnera93a14a2017-08-28 10:34:05 -04002391 const SkImageFilter* imageFilter = nullptr);
junov@chromium.orga907ac32012-02-24 21:54:07 +00002392
Herb Derby76d69b42018-03-15 17:34:40 -04002393 SkBaseDevice* getTopDevice() const;
2394
reedc83a2972015-07-16 07:40:45 -07002395private:
reed3aafe112016-08-18 12:45:34 -07002396 /** After calling saveLayer(), there can be any number of devices that make
2397 up the top-most drawing area. LayerIter can be used to iterate through
2398 those devices. Note that the iterator is only valid until the next API
2399 call made on the canvas. Ownership of all pointers in the iterator stays
2400 with the canvas, so none of them should be modified or deleted.
2401 */
2402 class LayerIter /*: SkNoncopyable*/ {
2403 public:
2404 /** Initialize iterator with canvas, and set values for 1st device */
2405 LayerIter(SkCanvas*);
2406 ~LayerIter();
2407
2408 /** Return true if the iterator is done */
2409 bool done() const { return fDone; }
2410 /** Cycle to the next device */
2411 void next();
2412
2413 // These reflect the current device in the iterator
2414
2415 SkBaseDevice* device() const;
2416 const SkMatrix& matrix() const;
Mike Reedca37f322018-03-08 13:22:16 -05002417 SkIRect clipBounds() const;
reed3aafe112016-08-18 12:45:34 -07002418 const SkPaint& paint() const;
2419 int x() const;
2420 int y() const;
2421
2422 private:
2423 // used to embed the SkDrawIter object directly in our instance, w/o
2424 // having to expose that class def to the public. There is an assert
2425 // in our constructor to ensure that fStorage is large enough
2426 // (though needs to be a compile-time-assert!). We use intptr_t to work
2427 // safely with 32 and 64 bit machines (to ensure the storage is enough)
2428 intptr_t fStorage[32];
2429 class SkDrawIter* fImpl; // this points at fStorage
2430 SkPaint fDefaultPaint;
2431 bool fDone;
2432 };
Herb Derby13569782016-10-06 14:33:43 -04002433
reed4960eee2015-12-18 07:09:18 -08002434 static bool BoundsAffectsClip(SaveLayerFlags);
reed4960eee2015-12-18 07:09:18 -08002435
reeda2217ef2016-07-20 06:04:34 -07002436 static void DrawDeviceWithFilter(SkBaseDevice* src, const SkImageFilter* filter,
Mike Reedc42a1cd2017-02-14 14:25:14 -05002437 SkBaseDevice* dst, const SkIPoint& dstOrigin,
Mike Reeda1361362017-03-07 09:37:29 -05002438 const SkMatrix& ctm);
reeda2217ef2016-07-20 06:04:34 -07002439
reedc83a2972015-07-16 07:40:45 -07002440 enum ShaderOverrideOpacity {
2441 kNone_ShaderOverrideOpacity, //!< there is no overriding shader (bitmap or image)
2442 kOpaque_ShaderOverrideOpacity, //!< the overriding shader is opaque
2443 kNotOpaque_ShaderOverrideOpacity, //!< the overriding shader may not be opaque
2444 };
2445
reed@google.com97af1a62012-08-28 12:19:02 +00002446 // notify our surface (if we have one) that we are about to draw, so it
2447 // can perform copy-on-write or invalidate any cached images
reedc83a2972015-07-16 07:40:45 -07002448 void predrawNotify(bool willOverwritesEntireSurface = false);
2449 void predrawNotify(const SkRect* rect, const SkPaint* paint, ShaderOverrideOpacity);
2450 void predrawNotify(const SkRect* rect, const SkPaint* paint, bool shaderOverrideIsOpaque) {
2451 this->predrawNotify(rect, paint, shaderOverrideIsOpaque ? kOpaque_ShaderOverrideOpacity
2452 : kNotOpaque_ShaderOverrideOpacity);
2453 }
reed@google.com97af1a62012-08-28 12:19:02 +00002454
Florin Malita0ed3b642017-01-13 16:56:38 +00002455 SkBaseDevice* getDevice() const;
Florin Malita0ed3b642017-01-13 16:56:38 +00002456
reed@android.com8a1c16f2008-12-17 15:59:43 +00002457 class MCRec;
2458
2459 SkDeque fMCStack;
2460 // points to top of stack
2461 MCRec* fMCRec;
Cary Clarkd98f78c2018-04-26 08:32:37 -04002462
reed@android.com8a1c16f2008-12-17 15:59:43 +00002463 // the first N recs that can fit here mean we won't call malloc
Cary Clarkd98f78c2018-04-26 08:32:37 -04002464 static constexpr int kMCRecSize = 128; // most recent measurement
2465 static constexpr int kMCRecCount = 32; // common depth for save/restores
2466 static constexpr int kDeviceCMSize = 224; // most recent measurement
2467
reedb679ca82015-04-07 04:40:48 -07002468 intptr_t fMCRecStorage[kMCRecSize * kMCRecCount / sizeof(intptr_t)];
reeda499f902015-05-01 09:34:31 -07002469 intptr_t fDeviceCMStorage[kDeviceCMSize / sizeof(intptr_t)];
reed@android.com8a1c16f2008-12-17 15:59:43 +00002470
reed4a8126e2014-09-22 07:29:03 -07002471 const SkSurfaceProps fProps;
2472
reed2ff1fce2014-12-11 07:07:37 -08002473 int fSaveCount; // value returned by getSaveCount()
reed@android.com8a1c16f2008-12-17 15:59:43 +00002474
mike@reedtribe.org74bb77e2012-09-26 02:24:45 +00002475 SkMetaData* fMetaData;
Mike Reed356f7c22017-01-10 11:58:39 -05002476 std::unique_ptr<SkRasterHandleAllocator> fAllocator;
mike@reedtribe.org74bb77e2012-09-26 02:24:45 +00002477
reed@google.com97af1a62012-08-28 12:19:02 +00002478 SkSurface_Base* fSurfaceBase;
2479 SkSurface_Base* getSurfaceBase() const { return fSurfaceBase; }
2480 void setSurfaceBase(SkSurface_Base* sb) {
2481 fSurfaceBase = sb;
2482 }
2483 friend class SkSurface_Base;
junov@chromium.org45c3db82013-04-11 17:52:05 +00002484 friend class SkSurface_Gpu;
skia.committer@gmail.comfc843592012-10-11 02:01:14 +00002485
Stan Iliev5f1bb0a2016-12-12 17:39:55 -05002486 SkIRect fClipRestrictionRect = SkIRect::MakeEmpty();
reed@android.com8a1c16f2008-12-17 15:59:43 +00002487
reed2ff1fce2014-12-11 07:07:37 -08002488 void doSave();
2489 void checkForDeferredSave();
reed8c30a812016-04-20 16:36:51 -07002490 void internalSetMatrix(const SkMatrix&);
reed2ff1fce2014-12-11 07:07:37 -08002491
Stan Iliev73d8fd92017-08-02 15:36:24 -04002492 friend class SkAndroidFrameworkUtils;
Cary Clark7eddfb82018-03-13 14:41:10 -04002493 friend class SkCanvasPriv; // needs kDontClipToLayer_PrivateSaveLayerFlag
reed@google.com9c135db2014-03-12 18:28:35 +00002494 friend class SkDrawIter; // needs setupDrawForLayerDevice()
reed@google.com8926b162012-03-23 15:36:36 +00002495 friend class AutoDrawLooper;
commit-bot@chromium.org2a67e122014-05-19 13:53:10 +00002496 friend class SkDebugCanvas; // needs experimental fAllowSimplifyClip
reed52d9ac62014-06-30 09:05:34 -07002497 friend class SkSurface_Raster; // needs getDevice()
Hal Canary363a3f82018-10-04 11:04:48 -04002498 friend class SkNoDrawCanvas; // needs resetForNextPicture()
reedc83a2972015-07-16 07:40:45 -07002499 friend class SkPictureRecord; // predrawNotify (why does it need it? <reed>)
Matt Sarett22886c42016-11-22 11:31:41 -05002500 friend class SkOverdrawCanvas;
Mike Reed356f7c22017-01-10 11:58:39 -05002501 friend class SkRasterHandleAllocator;
piotaixrb5fae932014-09-24 13:03:30 -07002502
Brian Osman37886ce2018-03-09 13:40:31 -05002503protected:
2504 // For use by SkNoDrawCanvas (via SkCanvasVirtualEnforcer, which can't be a friend)
Hal Canary363a3f82018-10-04 11:04:48 -04002505 SkCanvas(const SkIRect& bounds);
Brian Osman37886ce2018-03-09 13:40:31 -05002506private:
Mike Reed356f7c22017-01-10 11:58:39 -05002507 SkCanvas(const SkBitmap&, std::unique_ptr<SkRasterHandleAllocator>,
2508 SkRasterHandleAllocator::Handle);
reedd9544982014-09-09 18:46:22 -07002509
Hal Canary51382992018-06-15 20:27:52 -04002510 SkCanvas(SkCanvas&&) = delete;
2511 SkCanvas(const SkCanvas&) = delete;
2512 SkCanvas& operator=(SkCanvas&&) = delete;
2513 SkCanvas& operator=(const SkCanvas&) = delete;
2514
Mike Reed148b7fd2018-12-18 17:38:18 -05002515 /** Experimental
2516 * Saves the specified subset of the current pixels in the current layer,
2517 * and then clears those pixels to transparent black.
2518 * Restores the pixels on restore() by drawing them in SkBlendMode::kDstOver.
2519 *
2520 * @param subset conservative bounds of the area to be saved / restored.
2521 * @return depth of save state stack before this call was made.
2522 */
2523 int only_axis_aligned_saveBehind(const SkRect* subset);
2524
mtkleinfeaadee2015-04-08 11:25:48 -07002525 void resetForNextPicture(const SkIRect& bounds);
2526
reed8f2e7912014-09-04 12:45:18 -07002527 // needs gettotalclip()
tfarinaa5414c42014-10-10 06:19:09 -07002528 friend class SkCanvasStateUtils;
piotaixrb5fae932014-09-24 13:03:30 -07002529
reed4a8126e2014-09-22 07:29:03 -07002530 // call this each time we attach ourselves to a device
2531 // - constructor
2532 // - internalSaveLayer
2533 void setupDevice(SkBaseDevice*);
2534
Hal Canary363a3f82018-10-04 11:04:48 -04002535 void init(sk_sp<SkBaseDevice>);
reed@google.comf0b5e112011-09-07 11:57:34 +00002536
commit-bot@chromium.org403f8d72014-02-17 15:24:26 +00002537 /**
senorblancoafc7cce2016-02-02 18:44:15 -08002538 * Gets the bounds of the top level layer in global canvas coordinates. We don't want this
bsalomon@google.com4ebe3822014-02-26 20:22:32 +00002539 * to be public because it exposes decisions about layer sizes that are internal to the canvas.
2540 */
senorblancoafc7cce2016-02-02 18:44:15 -08002541 SkIRect getTopLayerBounds() const;
commit-bot@chromium.org403f8d72014-02-17 15:24:26 +00002542
reed@google.com71121732012-09-18 15:14:33 +00002543 void internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src,
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +00002544 const SkRect& dst, const SkPaint* paint,
reeda5517e22015-07-14 10:54:12 -07002545 SrcRectConstraint);
bsalomon@google.comfa6ac932011-10-05 19:57:55 +00002546 void internalDrawPaint(const SkPaint& paint);
reed4960eee2015-12-18 07:09:18 -08002547 void internalSaveLayer(const SaveLayerRec&, SaveLayerStrategy);
Mike Reed148b7fd2018-12-18 17:38:18 -05002548 void internalSaveBehind(const SkRect*);
Florin Malita53f77bd2017-04-28 13:48:37 -04002549 void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*, SkImage* clipImage,
2550 const SkMatrix& clipMatrix);
bsalomon@google.comfa6ac932011-10-05 19:57:55 +00002551
reed@android.com8a1c16f2008-12-17 15:59:43 +00002552 // shared by save() and saveLayer()
reed2ff1fce2014-12-11 07:07:37 -08002553 void internalSave();
reed@android.com8a1c16f2008-12-17 15:59:43 +00002554 void internalRestore();
reed@google.com4b226022011-01-11 18:32:13 +00002555
reedc83a2972015-07-16 07:40:45 -07002556 /*
2557 * Returns true if drawing the specified rect (or all if it is null) with the specified
2558 * paint (or default if null) would overwrite the entire root device of the canvas
2559 * (i.e. the canvas' surface if it had one).
2560 */
2561 bool wouldOverwriteEntireSurface(const SkRect*, const SkPaint*, ShaderOverrideOpacity) const;
2562
reed262a71b2015-12-05 13:07:27 -08002563 /**
2564 * Returns true if the paint's imagefilter can be invoked directly, without needed a layer.
2565 */
2566 bool canDrawBitmapAsSprite(SkScalar x, SkScalar y, int w, int h, const SkPaint&);
reedc83a2972015-07-16 07:40:45 -07002567
Mike Reeda1361362017-03-07 09:37:29 -05002568 /**
2569 * Returns true if the clip (for any active layer) contains antialiasing.
2570 * If the clip is empty, this will return false.
Mike Reed46784be2017-01-15 20:02:32 -05002571 */
Mike Reeda1361362017-03-07 09:37:29 -05002572 bool androidFramework_isClipAA() const;
msarettfbfa2582016-08-12 08:29:08 -07002573
2574 /**
2575 * Keep track of the device clip bounds and if the matrix is scale-translate. This allows
2576 * us to do a fast quick reject in the common case.
reed@android.com8a1c16f2008-12-17 15:59:43 +00002577 */
msarett9637ea92016-08-18 14:03:30 -07002578 bool fIsScaleTranslate;
msarettfbfa2582016-08-12 08:29:08 -07002579 SkRect fDeviceClipBounds;
2580
caryclark@google.com8f0a7b82012-11-07 14:54:49 +00002581 bool fAllowSoftClip;
caryclark@google.com45a75fb2013-04-25 13:34:40 +00002582 bool fAllowSimplifyClip;
reed@android.com8a1c16f2008-12-17 15:59:43 +00002583
Hal Canary14f73902018-06-14 14:57:12 -04002584 class AutoValidateClip {
reed@google.com5c3d1472011-02-22 19:12:23 +00002585 public:
2586 explicit AutoValidateClip(SkCanvas* canvas) : fCanvas(canvas) {
2587 fCanvas->validateClip();
2588 }
2589 ~AutoValidateClip() { fCanvas->validateClip(); }
2590
2591 private:
2592 const SkCanvas* fCanvas;
Hal Canary51382992018-06-15 20:27:52 -04002593
2594 AutoValidateClip(AutoValidateClip&&) = delete;
2595 AutoValidateClip(const AutoValidateClip&) = delete;
2596 AutoValidateClip& operator=(AutoValidateClip&&) = delete;
2597 AutoValidateClip& operator=(const AutoValidateClip&) = delete;
reed@google.com5c3d1472011-02-22 19:12:23 +00002598 };
2599
2600#ifdef SK_DEBUG
2601 void validateClip() const;
2602#else
2603 void validateClip() const {}
2604#endif
robertphillips@google.com15e9d3e2012-06-21 20:25:03 +00002605
Herb Derby59d997a2018-06-07 12:44:09 -04002606 std::unique_ptr<SkGlyphRunBuilder> fScratchGlyphRunBuilder;
Herb Derby4ffa0272018-06-04 15:49:15 -04002607
robertphillips@google.com15e9d3e2012-06-21 20:25:03 +00002608 typedef SkRefCnt INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +00002609};
2610
Cary Clarkcc309eb2017-10-30 11:48:35 -04002611/** \class SkAutoCanvasRestore
Cary Clarkecf548b2018-04-03 11:49:10 -04002612 Stack helper class calls SkCanvas::restoreToCount when SkAutoCanvasRestore
Cary Clarkcc309eb2017-10-30 11:48:35 -04002613 goes out of scope. Use this to guarantee that the canvas is restored to a known
2614 state.
reed@android.com8a1c16f2008-12-17 15:59:43 +00002615*/
Hal Canary14f73902018-06-14 14:57:12 -04002616class SkAutoCanvasRestore {
Cary Clarkb7a72a52018-06-15 05:11:24 -04002617public:
Ruiqi Mao94d57c42018-07-02 15:20:10 -04002618
Cary Clark77b3f3a2018-11-07 14:59:03 -05002619 /** Preserves SkCanvas::save() count. Optionally saves SkCanvas clip and SkCanvas matrix.
Cary Clarkcc309eb2017-10-30 11:48:35 -04002620
2621 @param canvas SkCanvas to guard
2622 @param doSave call SkCanvas::save()
2623 @return utility to restore SkCanvas state on destructor
2624 */
commit-bot@chromium.org28871192013-10-14 15:28:01 +00002625 SkAutoCanvasRestore(SkCanvas* canvas, bool doSave) : fCanvas(canvas), fSaveCount(0) {
2626 if (fCanvas) {
2627 fSaveCount = canvas->getSaveCount();
2628 if (doSave) {
2629 canvas->save();
2630 }
reed@android.com8a1c16f2008-12-17 15:59:43 +00002631 }
2632 }
Cary Clarkcc309eb2017-10-30 11:48:35 -04002633
Cary Clark2823f9f2018-01-03 10:00:34 -05002634 /** Restores SkCanvas to saved state. Destructor is called when container goes out of
2635 scope.
Cary Clarkcc309eb2017-10-30 11:48:35 -04002636 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00002637 ~SkAutoCanvasRestore() {
reed@google.comf6c9a5b2012-11-20 15:12:21 +00002638 if (fCanvas) {
2639 fCanvas->restoreToCount(fSaveCount);
2640 }
2641 }
2642
Cary Clarkcc309eb2017-10-30 11:48:35 -04002643 /** Restores SkCanvas to saved state immediately. Subsequent calls and
Cary Clarkcb6bef02018-11-29 12:05:25 -05002644 ~SkAutoCanvasRestore() have no effect.
Cary Clarkcc309eb2017-10-30 11:48:35 -04002645 */
reed@google.comf6c9a5b2012-11-20 15:12:21 +00002646 void restore() {
2647 if (fCanvas) {
2648 fCanvas->restoreToCount(fSaveCount);
Ben Wagnera93a14a2017-08-28 10:34:05 -04002649 fCanvas = nullptr;
reed@google.comf6c9a5b2012-11-20 15:12:21 +00002650 }
reed@android.com8a1c16f2008-12-17 15:59:43 +00002651 }
2652
2653private:
2654 SkCanvas* fCanvas;
2655 int fSaveCount;
Hal Canary51382992018-06-15 20:27:52 -04002656
2657 SkAutoCanvasRestore(SkAutoCanvasRestore&&) = delete;
2658 SkAutoCanvasRestore(const SkAutoCanvasRestore&) = delete;
2659 SkAutoCanvasRestore& operator=(SkAutoCanvasRestore&&) = delete;
2660 SkAutoCanvasRestore& operator=(const SkAutoCanvasRestore&) = delete;
reed@android.com8a1c16f2008-12-17 15:59:43 +00002661};
Cary Clarkcb6bef02018-11-29 12:05:25 -05002662
2663// Private
commit-bot@chromium.orge61a86c2013-11-18 16:03:59 +00002664#define SkAutoCanvasRestore(...) SK_REQUIRE_LOCAL_VAR(SkAutoCanvasRestore)
reed@android.com8a1c16f2008-12-17 15:59:43 +00002665
2666#endif