blob: f2a271c5ef058dd5087312135bc815a67057b10e [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
8#ifndef SkCanvas_DEFINED
9#define SkCanvas_DEFINED
10
reed374772b2016-10-05 17:33:02 -070011#include "SkBlendMode.h"
reed73603f32016-09-20 08:42:38 -070012#include "SkClipOp.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000013#include "SkDeque.h"
14#include "SkPaint.h"
Mike Reed356f7c22017-01-10 11:58:39 -050015#include "SkRasterHandleAllocator.h"
reed4a8126e2014-09-22 07:29:03 -070016#include "SkSurfaceProps.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000017
bungemand3ebb482015-08-05 13:57:49 -070018class GrContext;
Brian Osman11052242016-10-27 14:47:55 -040019class GrRenderTargetContext;
Stan Iliev73d8fd92017-08-02 15:36:24 -040020class SkAndroidFrameworkUtils;
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000021class SkBaseDevice;
Mike Reed267be7f2017-02-13 09:32:54 -050022class SkBitmap;
bungemand3ebb482015-08-05 13:57:49 -070023class SkClipStack;
reedf70b5312016-03-04 16:36:20 -080024class SkData;
reed@android.com8a1c16f2008-12-17 15:59:43 +000025class SkDraw;
reed3cb38402015-02-06 08:36:15 -080026class SkDrawable;
reed@android.com8a1c16f2008-12-17 15:59:43 +000027class SkDrawFilter;
Mike Reed4204da22017-05-17 08:53:36 -040028struct SkDrawShadowRec;
Mike Reed267be7f2017-02-13 09:32:54 -050029class SkImage;
bungemand3ebb482015-08-05 13:57:49 -070030class SkImageFilter;
mike@reedtribe.org74bb77e2012-09-26 02:24:45 +000031class SkMetaData;
bungemand3ebb482015-08-05 13:57:49 -070032class SkPath;
reed@android.com8a1c16f2008-12-17 15:59:43 +000033class SkPicture;
bungemand3ebb482015-08-05 13:57:49 -070034class SkPixmap;
reed1e7f5e72016-04-27 07:49:17 -070035class SkRasterClip;
Mike Reed267be7f2017-02-13 09:32:54 -050036class SkRegion;
reed@google.com4ed0fb72012-12-12 20:48:18 +000037class SkRRect;
reed71c3c762015-06-24 10:29:17 -070038struct SkRSXform;
reed@google.com76f10a32014-02-05 15:32:21 +000039class SkSurface;
reed@google.com97af1a62012-08-28 12:19:02 +000040class SkSurface_Base;
fmalita00d5c2c2014-08-21 08:53:26 -070041class SkTextBlob;
Brian Salomon199fb872017-02-06 09:41:10 -050042class SkVertices;
reedfa35f8e2014-09-04 12:14:36 -070043
reed@android.com8a1c16f2008-12-17 15:59:43 +000044/** \class SkCanvas
Cary Clarkb7da7232017-09-01 13:49:54 -040045 SkCanvas provides an interface for drawing, and how the drawing is clipped and transformed.
46 SkCanvas contains a stack of SkMatrix and clip values.
reed@android.com8a1c16f2008-12-17 15:59:43 +000047
Cary Clarkb7da7232017-09-01 13:49:54 -040048 SkCanvas and SkPaint together provide the state to draw into SkSurface or SkBaseDevice.
49 Each SkCanvas draw call transforms the geometry of the object by the concatenation of all
50 SkMatrix values in the stack. The transformed geometry is clipped by the intersection
51 of all of clip values in the stack. The SkCanvas draw calls use SkPaint to supply drawing
52 state such as color, SkTypeface, text size, stroke width, SkShader and so on.
reed@android.com8a1c16f2008-12-17 15:59:43 +000053
Cary Clarkb7da7232017-09-01 13:49:54 -040054 To draw to a pixel-based destination, create raster surface or GPU surface.
55 Request SkCanvas from SkSurface to obtain the interface to draw.
56 SkCanvas generated by raster surface draws to memory visible to the CPU.
57 SkCanvas generated by GPU surface uses Vulkan or OpenGL to draw to the GPU.
58
59 To draw to a document, obtain SkCanvas from svg canvas, document pdf, or SkPictureRecorder.
60 SkDocument based SkCanvas and other SkCanvas Subclasses reference SkBaseDevice describing the
61 destination.
62
63 SkCanvas can be constructed to draw to SkBitmap without first creating raster surface.
64 This approach may be deprecated in the future.
reed@android.com8a1c16f2008-12-17 15:59:43 +000065*/
Mike Reed02b73492016-12-07 16:52:58 -050066class SK_API SkCanvas : SkNoncopyable {
reedbada1882015-12-21 13:09:44 -080067 enum PrivateSaveLayerFlags {
caryclark952538e2016-02-26 05:01:42 -080068 kDontClipToLayer_PrivateSaveLayerFlag = 1U << 31,
reedbada1882015-12-21 13:09:44 -080069 };
reed73603f32016-09-20 08:42:38 -070070
reed@android.com8a1c16f2008-12-17 15:59:43 +000071public:
Cary Clarkb7da7232017-09-01 13:49:54 -040072
73 /** Allocates raster SkCanvas that will draw directly into pixels.
74 To access pixels after drawing, call flush() or peekPixels().
75
76 SkCanvas is returned if all parameters are valid.
77 Valid parameters include:
78 info dimensions are zero or positive;
79 info contains SkColorType and SkAlphaType supported by raster surface;
80 pixels is not nullptr;
81 rowBytes is zero or large enough to contain info width pixels of SkColorType.
82
83 Pass zero for rowBytes to compute rowBytes from info width and size of pixel.
84 If rowBytes is greater than zero, it must be equal to or greater than
85 info width times bytes required for SkColorType.
86
87 Pixel buffer size should be info height times computed rowBytes.
88
Cary Clark8a02b0b2017-09-21 12:28:43 -040089 @param info width, height, SkColorType, SkAlphaType, SkColorSpace, of raster surface;
Cary Clarkb7da7232017-09-01 13:49:54 -040090 width, or height, or both, may be zero
91 @param pixels pointer to destination pixels buffer
92 @param rowBytes interval from one SkSurface row to the next, or zero
93 @return SkCanvas if all parameters are valid; otherwise, nullptr
94 */
Cary Clark0418a882017-05-10 09:07:42 -040095 static std::unique_ptr<SkCanvas> MakeRasterDirect(const SkImageInfo& info, void* pixels,
96 size_t rowBytes);
Mike Reed5df49342016-11-12 08:06:55 -060097
Cary Clarkb7da7232017-09-01 13:49:54 -040098 /** Allocates raster SkCanvas specified by inline image specification. Subsequent SkCanvas
99 calls draw into pixels.
100 SkColorType is set to kN32_SkColorType.
101 SkAlphaType is set to kPremul_SkAlphaType.
102 To access pixels after drawing, call flush() or peekPixels().
103
104 SkCanvas is returned if all parameters are valid.
105 Valid parameters include:
106 width and height are zero or positive;
107 pixels is not nullptr;
108 rowBytes is zero or large enough to contain width pixels of kN32_SkColorType.
109
110 Pass zero for rowBytes to compute rowBytes from width and size of pixel.
111 If rowBytes is greater than zero, it must be equal to or greater than
112 width times bytes required for SkColorType.
113
114 Pixel buffer size should be height times rowBytes.
115
116 @param width pixel column count on raster surface created; must be zero or greater
117 @param height pixel row count on raster surface created.; must be zero or greater
118 @param pixels pointer to destination pixels buffer; buffer size should be height
119 times rowBytes
120 @param rowBytes interval from one SkSurface row to the next, or zero
121 @return SkCanvas if all parameters are valid; otherwise, nullptr
122 */
Mike Reed5df49342016-11-12 08:06:55 -0600123 static std::unique_ptr<SkCanvas> MakeRasterDirectN32(int width, int height, SkPMColor* pixels,
124 size_t rowBytes) {
125 return MakeRasterDirect(SkImageInfo::MakeN32Premul(width, height), pixels, rowBytes);
126 }
127
Cary Clark8a02b0b2017-09-21 12:28:43 -0400128 /** Creates an empty SkCanvas with no backing device or pixels, with
Cary Clarkb7da7232017-09-01 13:49:54 -0400129 a width and height of zero.
130
Cary Clark8a02b0b2017-09-21 12:28:43 -0400131 @return empty SkCanvas
Cary Clarkb7da7232017-09-01 13:49:54 -0400132 */
reed@google.comcde92112011-07-06 20:00:52 +0000133 SkCanvas();
vandebo@chromium.org8d84fac2010-10-13 22:13:05 +0000134
Cary Clarkb7da7232017-09-01 13:49:54 -0400135 /** Creates SkCanvas of the specified dimensions without a SkSurface.
136 Used by Subclasses with custom implementations for draw methods.
137
Cary Clark8a02b0b2017-09-21 12:28:43 -0400138 If props equals nullptr, SkSurfaceProps are created with
139 SkSurfaceProps::InitType settings, which choose the pixel striping
140 direction and order. Since a platform may dynamically change its direction when
141 the device is rotated, and since a platform may have multiple monitors with
142 different characteristics, it is best not to rely on this legacy behavior.
Cary Clarkb7da7232017-09-01 13:49:54 -0400143
144 @param width zero or greater
145 @param height zero or greater
146 @param props LCD striping orientation and setting for device independent fonts;
147 may be nullptr
148 @return SkCanvas placeholder with dimensions
149 */
Ben Wagnera93a14a2017-08-28 10:34:05 -0400150 SkCanvas(int width, int height, const SkSurfaceProps* props = nullptr);
commit-bot@chromium.orge2543102014-01-31 19:42:58 +0000151
Cary Clarkb7da7232017-09-01 13:49:54 -0400152 /** Construct a canvas that draws into device.
153 Used by child classes of SkCanvas.
bsalomon@google.come97f0852011-06-17 13:10:25 +0000154
Cary Clarkb7da7232017-09-01 13:49:54 -0400155 @param device specifies a device for the canvas to draw into
156 @return SkCanvas that can be used to draw into device
vandebo@chromium.org8d84fac2010-10-13 22:13:05 +0000157 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000158 explicit SkCanvas(SkBaseDevice* device);
vandebo@chromium.org8d84fac2010-10-13 22:13:05 +0000159
Cary Clarkb7da7232017-09-01 13:49:54 -0400160 /** Construct a canvas that draws into bitmap.
161 Sets SkSurfaceProps::kLegacyFontHost_InitType in constructed SkSurface.
162
163 SkBitmap is copied so that subsequently editing bitmap will not affect
164 constructed SkCanvas.
165
166 May be deprecated in the future.
167
168 @param bitmap width, height, SkColorType, SkAlphaType, and pixel
169 storage of raster surface
170 @return SkCanvas that can be used to draw into bitmap
reed@android.com8a1c16f2008-12-17 15:59:43 +0000171 */
172 explicit SkCanvas(const SkBitmap& bitmap);
fmalita3d91aad2015-02-02 05:25:04 -0800173
Matt Sarett31f99ce2017-04-11 08:46:01 -0400174#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
175 enum class ColorBehavior {
Cary Clarkb7da7232017-09-01 13:49:54 -0400176 kLegacy, //!< Is a placeholder to allow specialized constructor; has no meaning.
Matt Sarett31f99ce2017-04-11 08:46:01 -0400177 };
178
Cary Clarkb7da7232017-09-01 13:49:54 -0400179 /** Android framework only.
180
181 @param bitmap specifies a bitmap for the canvas to draw into
182 @param behavior specializes this constructor; value is unused
183 @return SkCanvas that can be used to draw into bitmap
184 */
Cary Clark304f9d42017-05-13 13:35:35 -0400185 SkCanvas(const SkBitmap& bitmap, ColorBehavior behavior);
Matt Sarett31f99ce2017-04-11 08:46:01 -0400186#endif
187
Cary Clarkb7da7232017-09-01 13:49:54 -0400188 /** Construct a canvas that draws into bitmap.
189 Use props to match the device characteristics, like LCD striping.
190
191 bitmap is copied so that subsequently editing bitmap will not affect
192 constructed SkCanvas.
193
194 @param bitmap width, height, SkColorType, SkAlphaType,
195 and pixel storage of raster surface
196 @param props order and orientation of RGB striping; and whether to use
197 device independent fonts
198 @return SkCanvas that can be used to draw into bitmap
fmalita3d91aad2015-02-02 05:25:04 -0800199 */
200 SkCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props);
201
Cary Clark8a02b0b2017-09-21 12:28:43 -0400202 /** Draw saved layer, if any.
Cary Clarkb7da7232017-09-01 13:49:54 -0400203 Free up resources used by SkCanvas.
204 */
reed@android.com8a1c16f2008-12-17 15:59:43 +0000205 virtual ~SkCanvas();
206
Cary Clarkb7da7232017-09-01 13:49:54 -0400207 /** Returns storage to associate additional data with the canvas.
208 The storage is freed when SkCanvas is deleted.
209
210 @return storage that can be read from and written to
211 */
mike@reedtribe.org74bb77e2012-09-26 02:24:45 +0000212 SkMetaData& getMetaData();
213
Cary Clarkb7da7232017-09-01 13:49:54 -0400214 /** Returns SkImageInfo for SkCanvas. If SkCanvas is not associated with raster surface or
215 GPU surface, returned SkColorType is set to kUnknown_SkColorType.
216
217 @return dimensions and SkColorType of SkCanvas
218 */
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +0000219 SkImageInfo imageInfo() const;
220
Cary Clarkb7da7232017-09-01 13:49:54 -0400221 /** If SkCanvas is associated with raster surface or
222 GPU surface, copies SkSurfaceProps and returns true. Otherwise,
223 return false and leave props unchanged.
224
225 @param props storage for writable SkSurfaceProps
226 @return true if SkSurfaceProps was copied
227 */
Cary Clark0418a882017-05-10 09:07:42 -0400228 bool getProps(SkSurfaceProps* props) const;
brianosman898235c2016-04-06 07:38:23 -0700229
Cary Clarkb7da7232017-09-01 13:49:54 -0400230 /** Triggers the immediate execution of all pending draw operations.
231 If SkCanvas is associated with GPU surface, resolves all pending GPU operations.
232 */
junov@chromium.orgbf6c1e42012-01-30 14:53:22 +0000233 void flush();
234
Cary Clark8a02b0b2017-09-21 12:28:43 -0400235 /** Gets the size of the base or root layer in global canvas coordinates. The
236 origin of the base layer is always (0,0). The area available for drawing may be
Cary Clarkb7da7232017-09-01 13:49:54 -0400237 smaller (due to clipping or saveLayer).
238
Cary Clark8a02b0b2017-09-21 12:28:43 -0400239 @return integral width and height of base layer
Cary Clarkb7da7232017-09-01 13:49:54 -0400240 */
tomhudson68260fa2015-03-23 07:22:40 -0700241 virtual SkISize getBaseLayerSize() const;
bsalomon@google.com4ebe3822014-02-26 20:22:32 +0000242
Cary Clarkb7da7232017-09-01 13:49:54 -0400243 /** Creates SkSurface matching info and props, and associates it with SkCanvas.
244 Returns nullptr if no match found.
245
246 If props is nullptr, matches SkSurfaceProps in SkCanvas. If props is nullptr and SkCanvas
247 does not have SkSurfaceProps, creates SkSurface with default SkSurfaceProps.
248
Cary Clark8a02b0b2017-09-21 12:28:43 -0400249 @param info width, height, SkColorType, SkAlphaType, and SkColorSpace
Cary Clarkb7da7232017-09-01 13:49:54 -0400250 @param props SkSurfaceProps to match; may be nullptr to match SkCanvas
251 @return SkSurface matching info and props, or nullptr if no match is available
252 */
Cary Clark304f9d42017-05-13 13:35:35 -0400253 sk_sp<SkSurface> makeSurface(const SkImageInfo& info, const SkSurfaceProps* props = nullptr);
bsalomon@google.come97f0852011-06-17 13:10:25 +0000254
Cary Clarkb7da7232017-09-01 13:49:54 -0400255 /** Returns GPU context of the GPU surface associated with SkCanvas.
256
257 @return GPU context, if available; nullptr otherwise
258 */
Brian Osmand2da87d2017-05-08 16:02:43 -0400259 virtual GrContext* getGrContext();
commit-bot@chromium.org644629c2013-11-21 06:21:58 +0000260
Cary Clarkb7da7232017-09-01 13:49:54 -0400261 /** Returns the pixel base address, SkImageInfo, rowBytes, and origin if the pixels
262 can be read directly. The returned address is only valid
263 while SkCanvas is in scope and unchanged. Any SkCanvas call or SkSurface call
264 may invalidate the returned address and other returned values.
reed@google.com4b226022011-01-11 18:32:13 +0000265
Cary Clarkb7da7232017-09-01 13:49:54 -0400266 If pixels are inaccessible, info, rowBytes, and origin are unchanged.
267
268 @param info storage for writable pixels' SkImageInfo; may be nullptr
269 @param rowBytes storage for writable pixels' row bytes; may be nullptr
Cary Clark8a02b0b2017-09-21 12:28:43 -0400270 @param origin storage for SkCanvas top layer origin, its top left corner;
Cary Clarkb7da7232017-09-01 13:49:54 -0400271 may be nullptr
272 @return address of pixels, or nullptr if inaccessible
273 */
Ben Wagnera93a14a2017-08-28 10:34:05 -0400274 void* accessTopLayerPixels(SkImageInfo* info, size_t* rowBytes, SkIPoint* origin = nullptr);
reed@google.com9c135db2014-03-12 18:28:35 +0000275
Cary Clarkb7da7232017-09-01 13:49:54 -0400276 /** Returns custom context that tracks the SkMatrix and clip.
277
278 Use SkRasterHandleAllocator to blend Skia drawing with custom drawing, typically performed
279 by the host platform's user interface. The custom context returned is generated by
280 SkRasterHandleAllocator::MakeCanvas, which creates a custom canvas with raster storage for
281 the drawing destination.
282
283 @return context of custom allocation
284 */
Mike Reed356f7c22017-01-10 11:58:39 -0500285 SkRasterHandleAllocator::Handle accessTopRasterHandle() const;
286
Cary Clarkb7da7232017-09-01 13:49:54 -0400287 /** Returns true if SkCanvas has direct access to its pixels.
288
289 Pixels are readable when SkBaseDevice is raster. Pixels are not readable when SkCanvas
290 is returned from GPU surface, returned by SkDocument::beginPage, returned by
291 SkPictureRecorder::beginRecording, or SkCanvas is the base of a utility class
292 like SkDumpCanvas.
293
294 pixmap is valid only while SkCanvas is in scope and unchanged. Any
295 SkCanvas or SkSurface call may invalidate the pixmap values.
296
297 @param pixmap storage for SkCanvas pixel state if SkCanvas pixels are readable;
298 otherwise, ignored
299 @return true if SkCanvas has direct access to pixels
300 */
Cary Clark0418a882017-05-10 09:07:42 -0400301 bool peekPixels(SkPixmap* pixmap);
reed6ceeebd2016-03-09 14:26:26 -0800302
Cary Clarkb7da7232017-09-01 13:49:54 -0400303 /** Copies rectangle of pixels from SkCanvas into dstPixels. SkMatrix and clip are
304 ignored. Source rectangle corners are (srcX, srcY) and
Cary Clark8a02b0b2017-09-21 12:28:43 -0400305 (this->imageInfo.width(), this->imageInfo.height()).
306
307 Destination rectangle corners are (0, 0) and (bitmap.width(), bitmap.height()).
308 Copies each readable pixel intersecting both rectangles, without scaling,
309 converting to dstInfo.colorType() and dstInfo.alphaType() if required.
310
311 Pixels are readable when SkBaseDevice is raster, or backed by a GPU.
312 Pixels are not readable when SkCanvas is returned by SkDocument::beginPage,
313 returned by SkPictureRecorder::beginRecording, or SkCanvas is the base of a utility
314 class like SkDumpCanvas.
315
316 The destination pixel storage must be allocated by the caller.
317
318 Pixel values are converted only if SkColorType and SkAlphaType
319 do not match. Only pixels within both source and destination rectangles
320 are copied. dstPixels contents outside the rectangle intersection are unchanged.
321
322 Pass negative values for srcX or srcY to offset pixels across or down destination.
323
324 Does not copy, and returns false if:
325 - Source and destination rectangles do not intersect.
326 - SkCanvas pixels could not be converted to dstInfo.colorType() or dstInfo.alphaType().
327 - SkCanvas pixels are not readable; for instance, SkCanvas is document-based.
328 - dstRowBytes is too small to contain one row of pixels.
Cary Clarkb7da7232017-09-01 13:49:54 -0400329
330 @param dstInfo width, height, SkColorType, and SkAlphaType of dstPixels
331 @param dstPixels storage for pixels; dstInfo.height() times dstRowBytes, or larger
332 @param dstRowBytes size of one destination row; dstInfo.width() times pixel size, or larger
333 @param srcX offset into readable pixels in x; may be negative
334 @param srcY offset into readable pixels in y; may be negative
335 @return true if pixels were copied
336 */
reedb184f7f2014-07-13 04:32:32 -0700337 bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
338 int srcX, int srcY);
Cary Clarkb7da7232017-09-01 13:49:54 -0400339
340 /** Copies rectangle of pixels from SkCanvas into pixmap. SkMatrix and clip are
341 ignored. Source rectangle corners are (srcX, srcY) and
Cary Clark8a02b0b2017-09-21 12:28:43 -0400342 (this->imageInfo.width(), this->imageInfo.height()).
343
344 Destination rectangle corners are (0, 0) and (bitmap.width(), bitmap.height()).
345 Copies each readable pixel intersecting both rectangles, without scaling,
346 converting to pixmap.colorType() and pixmap.alphaType() if required.
347
348 Pixels are readable when SkBaseDevice is raster, or backed by a GPU.
349 Pixels are not readable when SkCanvas is returned by SkDocument::beginPage,
350 returned by SkPictureRecorder::beginRecording, or SkCanvas is the base of a utility
351 class like SkDumpCanvas.
352
353 Caller must allocate pixel storage in pixmap if needed.
354
355 Pixel values are converted only if SkColorType and SkAlphaType
356 do not match. Only pixels within both source and destination rectangles
357 are copied. pixmap pixels contents outside the rectangle intersection are unchanged.
358
359 Pass negative values for srcX or srcY to offset pixels across or down pixmap.
360
361 Does not copy, and returns false if:
362 - Source and destination rectangles do not intersect.
363 - SkCanvas pixels could not be converted to pixmap.colorType() or pixmap.alphaType().
364 - SkCanvas pixels are not readable; for instance, SkCanvas is document-based.
365 - SkPixmap pixels could not be allocated.
366 - pixmap.rowBytes() is too small to contain one row of pixels.
Cary Clarkb7da7232017-09-01 13:49:54 -0400367
368 @param pixmap storage for pixels copied from SkCanvas
369 @param srcX offset into readable pixels in x; may be negative
370 @param srcY offset into readable pixels in y; may be negative
371 @return true if pixels were copied
372 */
Cary Clark0418a882017-05-10 09:07:42 -0400373 bool readPixels(const SkPixmap& pixmap, int srcX, int srcY);
Cary Clarkb7da7232017-09-01 13:49:54 -0400374
375 /** Copies rectangle of pixels from SkCanvas into bitmap. SkMatrix and clip are
376 ignored. Source rectangle corners are (srcX, srcY) and
Cary Clark8a02b0b2017-09-21 12:28:43 -0400377 (this->imageInfo.width(), this->imageInfo.height()).
378
379 Destination rectangle corners are (0, 0) and (bitmap.width(), bitmap.height()).
380 Copies each readable pixel intersecting both rectangles, without scaling,
381 converting to bitmap.colorType() and bitmap.alphaType() if required.
382
383 Pixels are readable when SkBaseDevice is raster, or backed by a GPU.
384 Pixels are not readable when SkCanvas is returned by SkDocument::beginPage,
385 returned by SkPictureRecorder::beginRecording, or SkCanvas is the base of a utility
386 class like SkDumpCanvas.
387
388 Caller must allocate pixel storage in bitmap if needed.
389
390 SkBitmap values are converted only if SkColorType and SkAlphaType
391 do not match. Only pixels within both source and destination rectangles
392 are copied. SkBitmap pixels outside the rectangle intersection are unchanged.
393
394 Pass negative values for srcX or srcY to offset pixels across or down bitmap.
395
396 Does not copy, and returns false if:
397 - Source and destination rectangles do not intersect.
398 - SkCanvas pixels could not be converted to bitmap.colorType() or bitmap.alphaType().
399 - SkCanvas pixels are not readable; for instance, SkCanvas is document-based.
400 - bitmap pixels could not be allocated.
401 - bitmap.rowBytes() is too small to contain one row of pixels.
Cary Clarkb7da7232017-09-01 13:49:54 -0400402
403 @param bitmap storage for pixels copied from SkCanvas
404 @param srcX offset into readable pixels in x; may be negative
405 @param srcY offset into readable pixels in y; may be negative
406 @return true if pixels were copied
407 */
Cary Clark304f9d42017-05-13 13:35:35 -0400408 bool readPixels(const SkBitmap& bitmap, int srcX, int srcY);
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +0000409
Cary Clarkb7da7232017-09-01 13:49:54 -0400410 /** Copies rectangle from pixels to SkCanvas. SkMatrix and clip are ignored.
411 Source rectangle corners are (0, 0) and (info.width(), info.height()).
412 Destination rectangle corners are (x, y) and
Cary Clark8a02b0b2017-09-21 12:28:43 -0400413 (this->imageInfo.width(), this->imageInfo.height()).
414
415 Copies each readable pixel intersecting both rectangles, without scaling,
416 converting to
417 this->imageInfo.colorType()and
418 this->imageInfo.alphaType()if required.
419
420 Pixels are writable when SkBaseDevice is raster, or backed by a GPU.
421 Pixels are not writable when SkCanvas is returned by SkDocument::beginPage,
422 returned by SkPictureRecorder::beginRecording, or SkCanvas is the base of a utility
423 class like SkDumpCanvas.
424
425 Pixel values are converted only if SkColorType and SkAlphaType
426 do not match. Only pixels within both source and destination rectangles
427 are copied. SkCanvas pixels outside the rectangle intersection are unchanged.
428
429 Pass negative values for x or y to offset pixels to the left or
430 above SkCanvas pixels.
431
432 Does not copy, and returns false if:
433 - Source and destination rectangles do not intersect.
434 - pixels could not be converted to this->imageInfo.colorType() or
435 this->imageInfo.alphaType().
436 - SkCanvas pixels are not writable; for instance, SkCanvas is document-based.
437 - rowBytes is too small to contain one row of pixels.
Cary Clarkb7da7232017-09-01 13:49:54 -0400438
439 @param info width, height, SkColorType, and SkAlphaType of pixels
440 @param pixels pixels to copy, of size info.height() times rowBytes, or larger
Cary Clark8a02b0b2017-09-21 12:28:43 -0400441 @param rowBytes size of one row of pixels; info.width() times pixel size, or larger
Cary Clarkb7da7232017-09-01 13:49:54 -0400442 @param x offset into SkCanvas writable pixels in x; may be negative
443 @param y offset into SkCanvas writable pixels in y; may be negative
444 @return true if pixels were written to SkCanvas
445 */
Cary Clark0418a882017-05-10 09:07:42 -0400446 bool writePixels(const SkImageInfo& info, const void* pixels, size_t rowBytes, int x, int y);
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +0000447
Cary Clarkb7da7232017-09-01 13:49:54 -0400448 /** Copies rectangle from pixels to SkCanvas. SkMatrix and clip are ignored.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400449 Source rectangle corners are (0, 0) and (bitmap.width(), bitmap.height()).
450
451 Destination rectangle corners are (x, y) and
452 (this->imageInfo.width(), this->imageInfo.height()).
453
454 Copies each readable pixel intersecting both rectangles, without scaling,
455 converting to
456 this->imageInfo.colorType()and
457 this->imageInfo.alphaType()if required.
458
459 Pixels are writable when SkBaseDevice is raster, or backed by a GPU.
460 Pixels are not writable when SkCanvas is returned by SkDocument::beginPage,
461 returned by SkPictureRecorder::beginRecording, or SkCanvas is the base of a utility
462 class like SkDumpCanvas.
463
464 Pixel values are converted only if SkColorType and SkAlphaType
465 do not match. Only pixels within both source and destination rectangles
466 are copied. SkCanvas pixels outside the rectangle intersection are unchanged.
467
468 Pass negative values for x or y to offset pixels to the left or
469 above SkCanvas pixels.
470
471 Does not copy, and returns false if:
472 - Source and destination rectangles do not intersect.
473 - bitmap does not have allocated pixels.
474 - bitmap pixels could not be converted to this->imageInfo.colorType() or
475 this->imageInfo.alphaType().
476 - SkCanvas pixels are not writable; for instance, SkCanvas is document based.
477 - bitmap pixels are inaccessible; for instance, bitmap wraps a texture.
Cary Clarkb7da7232017-09-01 13:49:54 -0400478
479 @param bitmap contains pixels copied to SkCanvas
480 @param x offset into SkCanvas writable pixels in x; may be negative
481 @param y offset into SkCanvas writable pixels in y; may be negative
482 @return true if pixels were written to SkCanvas
483 */
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +0000484 bool writePixels(const SkBitmap& bitmap, int x, int y);
reed@google.com4b226022011-01-11 18:32:13 +0000485
Cary Clarkb7da7232017-09-01 13:49:54 -0400486 /** Saves SkMatrix, clip, and SkDrawFilter (Draw_Filter deprecated on most platforms).
487 Calling restore() discards changes to SkMatrix, clip, and SkDrawFilter,
488 restoring the SkMatrix, clip, and SkDrawFilter to their state when save() was called.
vandebo@chromium.org8d84fac2010-10-13 22:13:05 +0000489
Cary Clarkb7da7232017-09-01 13:49:54 -0400490 SkMatrix may be changed by translate(), scale(), rotate(), skew(), concat(), setMatrix(),
491 and resetMatrix(). Clip may be changed by clipRect(), clipRRect(), clipPath(), clipRegion().
commit-bot@chromium.orgd70fa202014-04-24 21:51:58 +0000492
Cary Clarkb7da7232017-09-01 13:49:54 -0400493 Saved SkCanvas state is put on a stack; multiple calls to save() should be balance
494 by an equal number of calls to restore().
495
496 Call restoreToCount() with result to restore this and subsequent saves.
497
498 @return depth of saved stack
commit-bot@chromium.orgd70fa202014-04-24 21:51:58 +0000499 */
500 int save();
501
Cary Clarkb7da7232017-09-01 13:49:54 -0400502 /** Saves SkMatrix, clip, and SkDrawFilter (Draw_Filter deprecated on most platforms),
503 and allocates a SkBitmap for subsequent drawing.
504 Calling restore() discards changes to SkMatrix, clip, and SkDrawFilter,
505 and draws the SkBitmap.
506
507 SkMatrix may be changed by translate(), scale(), rotate(), skew(), concat(),
508 setMatrix(), and resetMatrix(). Clip may be changed by clipRect(), clipRRect(),
509 clipPath(), clipRegion().
510
511 SkRect bounds suggests but does not define the SkBitmap size. To clip drawing to
512 a specific rectangle, use clipRect().
513
514 Optional SkPaint paint applies color alpha, SkColorFilter, SkImageFilter, and
515 SkBlendMode when restore() is called.
516
517 Call restoreToCount() with returned value to restore this and subsequent saves.
518
Cary Clark8a02b0b2017-09-21 12:28:43 -0400519 @param bounds hint to limit the size of the layer; may be nullptr
520 @param paint graphics state for layer; may be nullptr
Cary Clarkb7da7232017-09-01 13:49:54 -0400521 @return depth of saved stack
commit-bot@chromium.orgd70fa202014-04-24 21:51:58 +0000522 */
523 int saveLayer(const SkRect* bounds, const SkPaint* paint);
Cary Clarkb7da7232017-09-01 13:49:54 -0400524
525 /** Saves SkMatrix, clip, and SkDrawFilter (Draw_Filter deprecated on most platforms),
526 and allocates a SkBitmap for subsequent drawing.
527 Calling restore() discards changes to SkMatrix, clip, and SkDrawFilter,
528 and draws the SkBitmap.
529
530 SkMatrix may be changed by translate(), scale(), rotate(), skew(), concat(),
531 setMatrix(), and resetMatrix(). Clip may be changed by clipRect(), clipRRect(),
532 clipPath(), clipRegion().
533
Cary Clark8a02b0b2017-09-21 12:28:43 -0400534 SkRect bounds suggests but does not define the layer size. To clip drawing to
Cary Clarkb7da7232017-09-01 13:49:54 -0400535 a specific rectangle, use clipRect().
536
537 Optional SkPaint paint applies color alpha, SkColorFilter, SkImageFilter, and
538 SkBlendMode when restore() is called.
539
540 Call restoreToCount() with returned value to restore this and subsequent saves.
541
Cary Clark8a02b0b2017-09-21 12:28:43 -0400542 @param bounds hint to limit the size of layer; may be nullptr
543 @param paint graphics state for layer; may be nullptr
Cary Clarkb7da7232017-09-01 13:49:54 -0400544 @return depth of saved stack
545 */
reed021f6312015-08-09 19:41:13 -0700546 int saveLayer(const SkRect& bounds, const SkPaint* paint) {
547 return this->saveLayer(&bounds, paint);
548 }
commit-bot@chromium.orgd70fa202014-04-24 21:51:58 +0000549
Cary Clarkb7da7232017-09-01 13:49:54 -0400550 /** Saves SkMatrix, clip, and SkDrawFilter (Draw_Filter deprecated on most platforms),
551 and allocates a SkBitmap for subsequent drawing.
Cary Clark8a02b0b2017-09-21 12:28:43 -0400552 lcd text is preserved when the layer is drawn to the prior layer.
Cary Clarkb7da7232017-09-01 13:49:54 -0400553
554 Calling restore() discards changes to SkMatrix, clip, and SkDrawFilter,
Cary Clark8a02b0b2017-09-21 12:28:43 -0400555 and draws layer.
Cary Clarkb7da7232017-09-01 13:49:54 -0400556
557 SkMatrix may be changed by translate(), scale(), rotate(), skew(), concat(),
558 setMatrix(), and resetMatrix(). Clip may be changed by clipRect(), clipRRect(),
559 clipPath(), clipRegion().
560
Cary Clark8a02b0b2017-09-21 12:28:43 -0400561 SkRect bounds suggests but does not define the layer size. To clip drawing to
Cary Clarkb7da7232017-09-01 13:49:54 -0400562 a specific rectangle, use clipRect().
563
564 Optional SkPaint paint applies color alpha, SkColorFilter, SkImageFilter, and
565 SkBlendMode when restore() is called.
566
567 Call restoreToCount() with returned value to restore this and subsequent saves.
568
569 Draw text on an opaque background so that lcd text blends correctly with the
Cary Clark8a02b0b2017-09-21 12:28:43 -0400570 prior layer. lcd text drawn on a background with transparency may result in
571 incorrect blending.
Cary Clarkb7da7232017-09-01 13:49:54 -0400572
Cary Clark8a02b0b2017-09-21 12:28:43 -0400573 @param bounds hint to limit the size of layer; may be nullptr
574 @param paint graphics state for layer; may be nullptr
Cary Clarkb7da7232017-09-01 13:49:54 -0400575 @return depth of saved stack
576 */
reed70ee31b2015-12-10 13:44:45 -0800577 int saveLayerPreserveLCDTextRequests(const SkRect* bounds, const SkPaint* paint);
578
Cary Clarkb7da7232017-09-01 13:49:54 -0400579 /** Saves SkMatrix, clip, and SkDrawFilter (Draw_Filter deprecated on most platforms),
580 and allocates SkBitmap for subsequent drawing.
581
582 Calling restore() discards changes to SkMatrix, clip, and SkDrawFilter,
Cary Clark8a02b0b2017-09-21 12:28:43 -0400583 and blends layer with alpha opacity onto prior layer.
Cary Clarkb7da7232017-09-01 13:49:54 -0400584
585 SkMatrix may be changed by translate(), scale(), rotate(), skew(), concat(),
586 setMatrix(), and resetMatrix(). Clip may be changed by clipRect(), clipRRect(),
587 clipPath(), clipRegion().
588
Cary Clark8a02b0b2017-09-21 12:28:43 -0400589 SkRect bounds suggests but does not define layer size. To clip drawing to
Cary Clarkb7da7232017-09-01 13:49:54 -0400590 a specific rectangle, use clipRect().
591
592 alpha of zero is fully transparent, 255 is fully opaque.
593
594 Call restoreToCount() with returned value to restore this and subsequent saves.
595
Cary Clark8a02b0b2017-09-21 12:28:43 -0400596 @param bounds hint to limit the size of layer; may be nullptr
597 @param alpha opacity of layer
Cary Clarkb7da7232017-09-01 13:49:54 -0400598 @return depth of saved stack
commit-bot@chromium.orgd70fa202014-04-24 21:51:58 +0000599 */
600 int saveLayerAlpha(const SkRect* bounds, U8CPU alpha);
601
Cary Clarkb7da7232017-09-01 13:49:54 -0400602 /** \enum
603 SaveLayerFlags provides options that may be used in any combination in SaveLayerRec,
Cary Clark8a02b0b2017-09-21 12:28:43 -0400604 defining how layer allocated by saveLayer() operates.
Cary Clarkb7da7232017-09-01 13:49:54 -0400605 */
reed4960eee2015-12-18 07:09:18 -0800606 enum {
Cary Clark8a02b0b2017-09-21 12:28:43 -0400607 /** Creates layer without transparency. Flag is ignored if layer SkPaint contains
Cary Clarkb7da7232017-09-01 13:49:54 -0400608 SkImageFilter or SkColorFilter.
609 */
610 kIsOpaque_SaveLayerFlag = 1 << 0,
reedbada1882015-12-21 13:09:44 -0800611
Cary Clark8a02b0b2017-09-21 12:28:43 -0400612 /** Creates layer for LCD text. Flag is ignored if layer SkPaint contains
Cary Clarkb7da7232017-09-01 13:49:54 -0400613 SkImageFilter or SkColorFilter.
614 */
615 kPreserveLCDText_SaveLayerFlag = 1 << 1,
616
Cary Clark8a02b0b2017-09-21 12:28:43 -0400617 /** Initializes layer with the contents of the previous layer. */
Cary Clarkb7da7232017-09-01 13:49:54 -0400618 kInitWithPrevious_SaveLayerFlag = 1 << 2,
Mike Reedc61abee2017-02-28 17:45:27 -0500619
reedbada1882015-12-21 13:09:44 -0800620#ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
Cary Clarkb7da7232017-09-01 13:49:54 -0400621 /** to be deprecated: bug.skia.org/2440 */
reedbada1882015-12-21 13:09:44 -0800622 kDontClipToLayer_Legacy_SaveLayerFlag = kDontClipToLayer_PrivateSaveLayerFlag,
623#endif
reed4960eee2015-12-18 07:09:18 -0800624 };
Cary Clarkb7da7232017-09-01 13:49:54 -0400625
reed4960eee2015-12-18 07:09:18 -0800626 typedef uint32_t SaveLayerFlags;
627
Cary Clarkb7da7232017-09-01 13:49:54 -0400628 /** \struct SkCanvas::SaveLayerRec
Cary Clarkb7da7232017-09-01 13:49:54 -0400629 */
reed4960eee2015-12-18 07:09:18 -0800630 struct SaveLayerRec {
Cary Clarkb7da7232017-09-01 13:49:54 -0400631
632 /** Sets fBounds, fPaint, and fBackdrop to nullptr. Clears fSaveLayerFlags.
633
634 @return empty SaveLayerRec
635 */
Florin Malita53f77bd2017-04-28 13:48:37 -0400636 SaveLayerRec() {}
Cary Clarkb7da7232017-09-01 13:49:54 -0400637
638 /** Sets fBounds, fPaint, and fSaveLayerFlags; sets fBackdrop to nullptr.
639
Cary Clark8a02b0b2017-09-21 12:28:43 -0400640 @param bounds layer dimensions; may be nullptr
641 @param paint applied to layer when overlaying prior layer; may be nullptr
642 @param saveLayerFlags SaveLayerRec options to modify layer
Cary Clarkb7da7232017-09-01 13:49:54 -0400643 @return SaveLayerRec with empty backdrop
644 */
reed4960eee2015-12-18 07:09:18 -0800645 SaveLayerRec(const SkRect* bounds, const SkPaint* paint, SaveLayerFlags saveLayerFlags = 0)
646 : fBounds(bounds)
647 , fPaint(paint)
reedbfd5f172016-01-07 11:28:08 -0800648 , fSaveLayerFlags(saveLayerFlags)
649 {}
Cary Clarkb7da7232017-09-01 13:49:54 -0400650
651 /** Sets fBounds, fPaint, fBackdrop, and fSaveLayerFlags.
652
Cary Clark8a02b0b2017-09-21 12:28:43 -0400653 @param bounds layer dimensions; may be nullptr
654 @param paint applied to layer when overlaying prior layer;
Cary Clarkb7da7232017-09-01 13:49:54 -0400655 may be nullptr
Cary Clark8a02b0b2017-09-21 12:28:43 -0400656 @param backdrop prior layer copied with SkImageFilter; may be nullptr
657 @param saveLayerFlags SaveLayerRec options to modify layer
Cary Clarkb7da7232017-09-01 13:49:54 -0400658 @return SaveLayerRec fully specified
659 */
reedbfd5f172016-01-07 11:28:08 -0800660 SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop,
Florin Malita25b37432017-05-01 10:58:40 -0400661 SaveLayerFlags saveLayerFlags)
662 : fBounds(bounds)
663 , fPaint(paint)
664 , fBackdrop(backdrop)
665 , fSaveLayerFlags(saveLayerFlags)
666 {}
Mike Kleinb34ab042017-05-01 21:34:14 +0000667
Cary Clarkb7da7232017-09-01 13:49:54 -0400668 /** EXPERIMENTAL: Not ready for general use.
669 Sets fBounds, fPaint, fBackdrop, fClipMask, fClipMatrix, and fSaveLayerFlags.
670 clipMatrix uses color alpha channel of image, transformed by clipMatrix, to clip
Cary Clark8a02b0b2017-09-21 12:28:43 -0400671 layer when drawn to SkCanvas.
Cary Clarkb7da7232017-09-01 13:49:54 -0400672
673 Implementation is incomplete; has no effect if SkBaseDevice is GPU-backed.
674
Cary Clark8a02b0b2017-09-21 12:28:43 -0400675 @param bounds layer dimensions; may be nullptr
676 @param paint graphics state applied to layer when overlaying prior
677 layer; may be nullptr
678 @param backdrop prior layer copied with SkImageFilter;
Cary Clarkb7da7232017-09-01 13:49:54 -0400679 may be nullptr
Cary Clark8a02b0b2017-09-21 12:28:43 -0400680 @param clipMask clip applied to layer; may be nullptr
Cary Clarkb7da7232017-09-01 13:49:54 -0400681 @param clipMatrix matrix applied to clipMask; may be nullptr to use
682 identity matrix
Cary Clark8a02b0b2017-09-21 12:28:43 -0400683 @param saveLayerFlags SaveLayerRec options to modify layer
Cary Clarkb7da7232017-09-01 13:49:54 -0400684 @return SaveLayerRec fully specified
685 */
Florin Malita25b37432017-05-01 10:58:40 -0400686 SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop,
Mike Kleinb34ab042017-05-01 21:34:14 +0000687 const SkImage* clipMask, const SkMatrix* clipMatrix,
reedbfd5f172016-01-07 11:28:08 -0800688 SaveLayerFlags saveLayerFlags)
689 : fBounds(bounds)
690 , fPaint(paint)
691 , fBackdrop(backdrop)
Vaclav Brozekd0e0a8f2017-06-04 14:12:50 +0200692 , fClipMask(clipMask)
Florin Malita53f77bd2017-04-28 13:48:37 -0400693 , fClipMatrix(clipMatrix)
reed4960eee2015-12-18 07:09:18 -0800694 , fSaveLayerFlags(saveLayerFlags)
695 {}
696
Cary Clark8a02b0b2017-09-21 12:28:43 -0400697 /** fBounds is used as a hint to limit the size of layer; may be nullptr.
698 fBounds suggests but does not define layer size. To clip drawing to
Cary Clarkb7da7232017-09-01 13:49:54 -0400699 a specific rectangle, use clipRect().
700 */
701 const SkRect* fBounds = nullptr;
702
Cary Clark8a02b0b2017-09-21 12:28:43 -0400703 /** fPaint modifies how layer overlays the prior layer; may be nullptr.
Cary Clarkb7da7232017-09-01 13:49:54 -0400704 color alpha, SkBlendMode, SkColorFilter, SkDrawLooper, SkImageFilter, and
Cary Clark8a02b0b2017-09-21 12:28:43 -0400705 SkMaskFilter affect layer draw.
Cary Clarkb7da7232017-09-01 13:49:54 -0400706 */
707 const SkPaint* fPaint = nullptr;
708
Cary Clark8a02b0b2017-09-21 12:28:43 -0400709 /** fBackdrop applies SkImageFilter to the prior layer when copying to the layer;
Cary Clarkb7da7232017-09-01 13:49:54 -0400710 may be nullptr. Use kInitWithPrevious_SaveLayerFlag to copy the
Cary Clark8a02b0b2017-09-21 12:28:43 -0400711 prior layer without an SkImageFilter.
Cary Clarkb7da7232017-09-01 13:49:54 -0400712 */
713 const SkImageFilter* fBackdrop = nullptr;
714
Cary Clark8a02b0b2017-09-21 12:28:43 -0400715 /** restore() clips layer by the color alpha channel of fClipMask when
716 layer is copied to SkBaseDevice. fClipMask may be nullptr. .
Cary Clarkb7da7232017-09-01 13:49:54 -0400717 */
718 const SkImage* fClipMask = nullptr;
719
Cary Clark8a02b0b2017-09-21 12:28:43 -0400720 /** fClipMatrix transforms fClipMask before it clips layer. If
Cary Clarkb7da7232017-09-01 13:49:54 -0400721 fClipMask describes a translucent gradient, it may be scaled and rotated
722 without introducing artifacts. fClipMatrix may be nullptr.
723 */
724 const SkMatrix* fClipMatrix = nullptr;
725
Cary Clark8a02b0b2017-09-21 12:28:43 -0400726 /** fSaveLayerFlags are used to create layer without transparency,
727 create layer for LCD text, and to create layer with the
728 contents of the previous layer.
Cary Clarkb7da7232017-09-01 13:49:54 -0400729 */
730 SaveLayerFlags fSaveLayerFlags = 0;
731
reed4960eee2015-12-18 07:09:18 -0800732 };
733
Cary Clarkb7da7232017-09-01 13:49:54 -0400734 /** Saves SkMatrix, clip, and SkDrawFilter (Draw_Filter deprecated on most platforms),
735 and allocates SkBitmap for subsequent drawing.
736
737 Calling restore() discards changes to SkMatrix, clip, and SkDrawFilter,
Cary Clark8a02b0b2017-09-21 12:28:43 -0400738 and blends SkBitmap with color alpha opacity onto the prior layer.
Cary Clarkb7da7232017-09-01 13:49:54 -0400739
740 SkMatrix may be changed by translate(), scale(), rotate(), skew(), concat(),
741 setMatrix(), and resetMatrix(). Clip may be changed by clipRect(), clipRRect(),
742 clipPath(), clipRegion().
743
Cary Clark8a02b0b2017-09-21 12:28:43 -0400744 SaveLayerRec contains the state used to create the layer.
Cary Clarkb7da7232017-09-01 13:49:54 -0400745
746 Call restoreToCount() with returned value to restore this and subsequent saves.
747
Cary Clark8a02b0b2017-09-21 12:28:43 -0400748 @param layerRec layer state
Cary Clarkb7da7232017-09-01 13:49:54 -0400749 @return depth of save state stack
750 */
Cary Clark0418a882017-05-10 09:07:42 -0400751 int saveLayer(const SaveLayerRec& layerRec);
reed4960eee2015-12-18 07:09:18 -0800752
Cary Clarkb7da7232017-09-01 13:49:54 -0400753 /** Removes changes to SkMatrix, clip, and SkDrawFilter since SkCanvas state was
754 last saved. The state is removed from the stack.
755
756 Does nothing if the stack is empty.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000757 */
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +0000758 void restore();
reed@android.com8a1c16f2008-12-17 15:59:43 +0000759
Cary Clarkb7da7232017-09-01 13:49:54 -0400760 /** Returns the number of saved states, each containing: SkMatrix, clip, and SkDrawFilter.
761 Equals the number of save() calls less the number of restore() calls plus one.
762 The save count of a new canvas is one.
763
764 @return depth of save state stack
reed@android.com8a1c16f2008-12-17 15:59:43 +0000765 */
junov@chromium.orga907ac32012-02-24 21:54:07 +0000766 int getSaveCount() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000767
Cary Clarkb7da7232017-09-01 13:49:54 -0400768 /** Restores state to SkMatrix, clip, and SkDrawFilter values when save(), saveLayer(),
769 saveLayerPreserveLCDTextRequests(), or saveLayerAlpha() returned saveCount.
770
771 Does nothing if saveCount is greater than state stack count.
772 Restores state to initial values if saveCount is less than or equal to one.
773
774 @param saveCount depth of state stack to restore
reed@android.com8a1c16f2008-12-17 15:59:43 +0000775 */
776 void restoreToCount(int saveCount);
777
Cary Clarkb7da7232017-09-01 13:49:54 -0400778 /** Translate SkMatrix by dx along the x-axis and dy along the y-axis.
779
780 Mathematically, replace SkMatrix with a translation matrix
781 premultiplied with SkMatrix.
782
783 This has the effect of moving the drawing by (dx, dy) before transforming
784 the result with SkMatrix.
785
786 @param dx distance to translate in x
787 @param dy distance to translate in y
reed@android.com8a1c16f2008-12-17 15:59:43 +0000788 */
commit-bot@chromium.org92362382014-03-18 12:51:48 +0000789 void translate(SkScalar dx, SkScalar dy);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000790
Cary Clarkb7da7232017-09-01 13:49:54 -0400791 /** Scale SkMatrix by sx on the x-axis and sy on the y-axis.
792
793 Mathematically, replace SkMatrix with a scale matrix
794 premultiplied with SkMatrix.
795
796 This has the effect of scaling the drawing by (sx, sy) before transforming
797 the result with SkMatrix.
798
799 @param sx amount to scale in x
800 @param sy amount to scale in y
reed@android.com8a1c16f2008-12-17 15:59:43 +0000801 */
commit-bot@chromium.org92362382014-03-18 12:51:48 +0000802 void scale(SkScalar sx, SkScalar sy);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000803
Cary Clarkb7da7232017-09-01 13:49:54 -0400804 /** Rotate SkMatrix by degrees. Positive degrees rotates clockwise.
805
806 Mathematically, replace SkMatrix with a rotation matrix
807 premultiplied with SkMatrix.
808
809 This has the effect of rotating the drawing by degrees before transforming
810 the result with SkMatrix.
811
812 @param degrees amount to rotate, in degrees
reed@android.com8a1c16f2008-12-17 15:59:43 +0000813 */
commit-bot@chromium.org92362382014-03-18 12:51:48 +0000814 void rotate(SkScalar degrees);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000815
Cary Clark8a02b0b2017-09-21 12:28:43 -0400816 /** Rotate SkMatrix by degrees about a point at (px, py). Positive degrees rotates
817 clockwise.
Cary Clarkb7da7232017-09-01 13:49:54 -0400818
Cary Clark8a02b0b2017-09-21 12:28:43 -0400819 Mathematically, construct a rotation matrix. Premultiply the rotation matrix by
820 a translation matrix, then replace SkMatrix with the resulting matrix
Cary Clarkb7da7232017-09-01 13:49:54 -0400821 premultiplied with SkMatrix.
822
Cary Clark8a02b0b2017-09-21 12:28:43 -0400823 This has the effect of rotating the drawing about a given point before
824 transforming the result with SkMatrix.
Cary Clarkb7da7232017-09-01 13:49:54 -0400825
826 @param degrees amount to rotate, in degrees
Cary Clark8a02b0b2017-09-21 12:28:43 -0400827 @param px x-coordinate of the point to rotate about
828 @param py y-coordinate of the point to rotate about
bungeman7438bfc2016-07-12 15:01:19 -0700829 */
830 void rotate(SkScalar degrees, SkScalar px, SkScalar py);
831
Cary Clarkb7da7232017-09-01 13:49:54 -0400832 /** Skew SkMatrix by sx on the x-axis and sy on the y-axis. A positive value of sx
833 skews the drawing right as y increases; a positive value of sy skews the drawing
834 down as x increases.
835
836 Mathematically, replace SkMatrix with a skew matrix premultiplied with SkMatrix.
837
838 This has the effect of skewing the drawing by (sx, sy) before transforming
839 the result with SkMatrix.
840
841 @param sx amount to skew in x
842 @param sy amount to skew in y
reed@android.com8a1c16f2008-12-17 15:59:43 +0000843 */
commit-bot@chromium.org92362382014-03-18 12:51:48 +0000844 void skew(SkScalar sx, SkScalar sy);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000845
Cary Clarkb7da7232017-09-01 13:49:54 -0400846 /** Replace SkMatrix with matrix premultiplied with existing SkMatrix.
847
848 This has the effect of transforming the drawn geometry by matrix, before
849 transforming the result with existing SkMatrix.
850
851 @param matrix matrix to premultiply with existing SkMatrix
reed@android.com8a1c16f2008-12-17 15:59:43 +0000852 */
commit-bot@chromium.org92362382014-03-18 12:51:48 +0000853 void concat(const SkMatrix& matrix);
reed@google.com4b226022011-01-11 18:32:13 +0000854
Cary Clarkb7da7232017-09-01 13:49:54 -0400855 /** Replace SkMatrix with matrix.
856 Unlike concat(), any prior matrix state is overwritten.
857
858 @param matrix matrix to copy, replacing existing SkMatrix
reed@android.com8a1c16f2008-12-17 15:59:43 +0000859 */
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000860 void setMatrix(const SkMatrix& matrix);
reed@google.com4b226022011-01-11 18:32:13 +0000861
Cary Clarkb7da7232017-09-01 13:49:54 -0400862 /** Sets SkMatrix to the identity matrix.
863 Any prior matrix state is overwritten.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000864 */
865 void resetMatrix();
866
Cary Clarkb7da7232017-09-01 13:49:54 -0400867 /** Replace clip with the intersection or difference of clip and rect,
868 with an aliased or anti-aliased clip edge. rect is transformed by SkMatrix
869 before it is combined with clip.
870
871 @param rect SkRect to combine with clip
872 @param op SkClipOp to apply to clip
873 @param doAntiAlias true if clip is to be anti-aliased
874 */
Cary Clark0418a882017-05-10 09:07:42 -0400875 void clipRect(const SkRect& rect, SkClipOp op, bool doAntiAlias);
Cary Clarkb7da7232017-09-01 13:49:54 -0400876
877 /** Replace clip with the intersection or difference of clip and rect.
878 Resulting clip is aliased; pixels are fully contained by the clip.
879 rect is transformed by SkMatrix before it is combined with clip.
880
881 @param rect SkRect to combine with clip
882 @param op SkClipOp to apply to clip
883 */
Mike Reedc1f77742016-12-09 09:00:50 -0500884 void clipRect(const SkRect& rect, SkClipOp op) {
reed66998382016-09-21 11:15:07 -0700885 this->clipRect(rect, op, false);
886 }
Cary Clarkb7da7232017-09-01 13:49:54 -0400887
888 /** Replace clip with the intersection of clip and rect.
889 Resulting clip is aliased; pixels are fully contained by the clip.
890 rect is transformed by SkMatrix
891 before it is combined with clip.
892
893 @param rect SkRect to combine with clip
894 @param doAntiAlias true if clip is to be anti-aliased
895 */
reed66998382016-09-21 11:15:07 -0700896 void clipRect(const SkRect& rect, bool doAntiAlias = false) {
Mike Reed2dc52372016-12-14 14:00:03 -0500897 this->clipRect(rect, SkClipOp::kIntersect, doAntiAlias);
reed66998382016-09-21 11:15:07 -0700898 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000899
Cary Clarkb7da7232017-09-01 13:49:54 -0400900 /** Sets the maximum clip rectangle, which can be set by clipRect(), clipRRect() and
901 clipPath() and intersect the current clip with the specified rect.
902 The maximum clip affects only future clipping operations; it is not retroactive.
903 The clip restriction is not recorded in pictures.
904
905 Pass an empty rect to disable maximum clip.
906 This is private API to be used only by Android framework.
907
908 @param rect maximum allowed clip in device coordinates
909 */
Stan Iliev5f1bb0a2016-12-12 17:39:55 -0500910 void androidFramework_setDeviceClipRestriction(const SkIRect& rect);
911
Cary Clarkb7da7232017-09-01 13:49:54 -0400912 /** Replace clip with the intersection or difference of clip and rrect,
913 with an aliased or anti-aliased clip edge.
914 rrect is transformed by SkMatrix
915 before it is combined with clip.
916
917 @param rrect SkRRect to combine with clip
918 @param op SkClipOp to apply to clip
919 @param doAntiAlias true if clip is to be anti-aliased
920 */
Mike Reedc1f77742016-12-09 09:00:50 -0500921 void clipRRect(const SkRRect& rrect, SkClipOp op, bool doAntiAlias);
Cary Clarkb7da7232017-09-01 13:49:54 -0400922
923 /** Replace clip with the intersection or difference of clip and rrect.
924 Resulting clip is aliased; pixels are fully contained by the clip.
925 rrect is transformed by SkMatrix before it is combined with clip.
926
927 @param rrect SkRRect to combine with clip
928 @param op SkClipOp to apply to clip
929 */
Mike Reedc1f77742016-12-09 09:00:50 -0500930 void clipRRect(const SkRRect& rrect, SkClipOp op) {
reed66998382016-09-21 11:15:07 -0700931 this->clipRRect(rrect, op, false);
932 }
Cary Clarkb7da7232017-09-01 13:49:54 -0400933
934 /** Replace clip with the intersection of clip and rrect,
935 with an aliased or anti-aliased clip edge.
936 rrect is transformed by SkMatrix before it is combined with clip.
937
938 @param rrect SkRRect to combine with clip
939 @param doAntiAlias true if clip is to be anti-aliased
940 */
reed66998382016-09-21 11:15:07 -0700941 void clipRRect(const SkRRect& rrect, bool doAntiAlias = false) {
Mike Reed2dc52372016-12-14 14:00:03 -0500942 this->clipRRect(rrect, SkClipOp::kIntersect, doAntiAlias);
reed66998382016-09-21 11:15:07 -0700943 }
reed@google.com4ed0fb72012-12-12 20:48:18 +0000944
Cary Clarkb7da7232017-09-01 13:49:54 -0400945 /** Replace clip with the intersection or difference of clip and path,
946 with an aliased or anti-aliased clip edge. SkPath::FillType determines if path
947 describes the area inside or outside its contours; and if path contour overlaps
948 itself or another path contour, whether the overlaps form part of the area.
949 path is transformed by SkMatrix before it is combined with clip.
950
951 @param path SkPath to combine with clip
952 @param op SkClipOp to apply to clip
953 @param doAntiAlias true if clip is to be anti-aliased
954 */
Mike Reedc1f77742016-12-09 09:00:50 -0500955 void clipPath(const SkPath& path, SkClipOp op, bool doAntiAlias);
Cary Clarkb7da7232017-09-01 13:49:54 -0400956
957 /** Replace clip with the intersection or difference of clip and path.
958 Resulting clip is aliased; pixels are fully contained by the clip.
959 SkPath::FillType determines if path
960 describes the area inside or outside its contours; and if path contour overlaps
961 itself or another path contour, whether the overlaps form part of the area.
962 path is transformed by SkMatrix
963 before it is combined with clip.
964
965 @param path SkPath to combine with clip
966 @param op SkClipOp to apply to clip
967 */
Mike Reedc1f77742016-12-09 09:00:50 -0500968 void clipPath(const SkPath& path, SkClipOp op) {
reed66998382016-09-21 11:15:07 -0700969 this->clipPath(path, op, false);
970 }
Cary Clarkb7da7232017-09-01 13:49:54 -0400971
972 /** Replace clip with the intersection of clip and path.
973 Resulting clip is aliased; pixels are fully contained by the clip.
974 SkPath::FillType determines if path
975 describes the area inside or outside its contours; and if path contour overlaps
976 itself or another path contour, whether the overlaps form part of the area.
977 path is transformed by SkMatrix before it is combined with clip.
978
979 @param path SkPath to combine with clip
980 @param doAntiAlias true if clip is to be anti-aliased
981 */
reed66998382016-09-21 11:15:07 -0700982 void clipPath(const SkPath& path, bool doAntiAlias = false) {
Mike Reed2dc52372016-12-14 14:00:03 -0500983 this->clipPath(path, SkClipOp::kIntersect, doAntiAlias);
reed66998382016-09-21 11:15:07 -0700984 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000985
Cary Clarkb7da7232017-09-01 13:49:54 -0400986 /** EXPERIMENTAL: Only used for testing.
987 Set to simplify clip stack using PathOps.
988 */
caryclark@google.com45a75fb2013-04-25 13:34:40 +0000989 void setAllowSimplifyClip(bool allow) {
990 fAllowSimplifyClip = allow;
991 }
992
Cary Clarkb7da7232017-09-01 13:49:54 -0400993 /** Replace clip with the intersection or difference of clip and SkRegion deviceRgn.
994 Resulting clip is aliased; pixels are fully contained by the clip.
995 deviceRgn is unaffected by SkMatrix.
996
997 @param deviceRgn SkRegion to combine with clip
998 @param op SkClipOp to apply to clip
reed@android.com8a1c16f2008-12-17 15:59:43 +0000999 */
Mike Reed2dc52372016-12-14 14:00:03 -05001000 void clipRegion(const SkRegion& deviceRgn, SkClipOp op = SkClipOp::kIntersect);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001001
Cary Clarkb7da7232017-09-01 13:49:54 -04001002 /** Return true if SkRect rect, transformed by SkMatrix, can be quickly determined to be
1003 outside of clip. May return false even though rect is outside of clip.
1004
1005 Use to check if an area to be drawn is clipped out, to skip subsequent draw calls.
1006
1007 @param rect SkRect to compare with clip
1008 @return true if rect, transformed by SkMatrix, does not intersect clip
reed@android.com8a1c16f2008-12-17 15:59:43 +00001009 */
reed@google.com3b3e8952012-08-16 20:53:31 +00001010 bool quickReject(const SkRect& rect) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001011
Cary Clarkb7da7232017-09-01 13:49:54 -04001012 /** Return true if path, transformed by SkMatrix, can be quickly determined to be
1013 outside of clip. May return false even though path is outside of clip.
1014
1015 Use to check if an area to be drawn is clipped out, to skip subsequent draw calls.
1016
1017 @param path SkPath to compare with clip
1018 @return true if path, transformed by SkMatrix, does not intersect clip
reed@android.com8a1c16f2008-12-17 15:59:43 +00001019 */
reed@google.com3b3e8952012-08-16 20:53:31 +00001020 bool quickReject(const SkPath& path) const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00001021
Cary Clarkb7da7232017-09-01 13:49:54 -04001022 /** Return bounds of clip, transformed by inverse of SkMatrix. If clip is empty,
1023 return SkRect::MakeEmpty, where all SkRect sides equal zero.
1024
1025 SkRect returned is outset by one to account for partial pixel coverage if clip
1026 is anti-aliased.
1027
1028 @return bounds of clip in local coordinates
1029 */
Mike Reed42e8c532017-01-23 14:09:13 -05001030 SkRect getLocalClipBounds() const { return this->onGetLocalClipBounds(); }
reed@android.com8a1c16f2008-12-17 15:59:43 +00001031
Cary Clarkb7da7232017-09-01 13:49:54 -04001032 /** Return bounds of clip, transformed by inverse of SkMatrix. If clip is empty,
1033 return false, and set bounds to SkRect::MakeEmpty, where all SkRect sides equal zero.
1034
1035 bounds is outset by one to account for partial pixel coverage if clip
1036 is anti-aliased.
1037
1038 @param bounds SkRect of clip in local coordinates
1039 @return true if clip bounds is not empty
1040 */
Mike Reed6f4a9b22017-01-24 09:13:40 -05001041 bool getLocalClipBounds(SkRect* bounds) const {
1042 *bounds = this->onGetLocalClipBounds();
1043 return !bounds->isEmpty();
1044 }
1045
Cary Clarkb7da7232017-09-01 13:49:54 -04001046 /** Return SkIRect bounds of clip, unaffected by SkMatrix. If clip is empty,
1047 return SkRect::MakeEmpty, where all SkRect sides equal zero.
1048
1049 Unlike getLocalClipBounds(), returned SkIRect is not outset.
1050
1051 @return bounds of clip in SkBaseDevice coordinates
1052 */
Mike Reed42e8c532017-01-23 14:09:13 -05001053 SkIRect getDeviceClipBounds() const { return this->onGetDeviceClipBounds(); }
1054
Cary Clarkb7da7232017-09-01 13:49:54 -04001055 /** Return SkIRect bounds of clip, unaffected by SkMatrix. If clip is empty,
1056 return false, and set bounds to SkRect::MakeEmpty, where all SkRect sides equal zero.
1057
1058 Unlike getLocalClipBounds(), bounds is not outset.
1059
1060 @param bounds SkRect of clip in device coordinates
1061 @return true if clip bounds is not empty
1062 */
Mike Reed6f4a9b22017-01-24 09:13:40 -05001063 bool getDeviceClipBounds(SkIRect* bounds) const {
1064 *bounds = this->onGetDeviceClipBounds();
1065 return !bounds->isEmpty();
1066 }
1067
Cary Clarkb7da7232017-09-01 13:49:54 -04001068 /** Fill clip with color color.
1069 mode determines how ARGB is combined with destination.
1070
Cary Clark8a02b0b2017-09-21 12:28:43 -04001071 @param color unpremultiplied ARGB
Cary Clarkb7da7232017-09-01 13:49:54 -04001072 @param mode SkBlendMode used to combine source color and destination
reed@android.com8a1c16f2008-12-17 15:59:43 +00001073 */
reed374772b2016-10-05 17:33:02 -07001074 void drawColor(SkColor color, SkBlendMode mode = SkBlendMode::kSrcOver);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001075
Cary Clarkb7da7232017-09-01 13:49:54 -04001076 /** Fill clip with color color using SkBlendMode::kSrc.
1077 This has the effect of replacing all pixels contained by clip with color.
1078
Cary Clark8a02b0b2017-09-21 12:28:43 -04001079 @param color unpremultiplied ARGB
Cary Clarkb7da7232017-09-01 13:49:54 -04001080 */
reedf4e0d9e2014-12-05 20:49:03 -08001081 void clear(SkColor color) {
reed374772b2016-10-05 17:33:02 -07001082 this->drawColor(color, SkBlendMode::kSrc);
reed8eddfb52014-12-04 07:50:14 -08001083 }
reed@google.com2a981812011-04-14 18:59:28 +00001084
Cary Clarkb7da7232017-09-01 13:49:54 -04001085 /** Make SkCanvas contents undefined. Subsequent calls that read SkCanvas pixels,
1086 such as drawing with SkBlendMode, return undefined results. discard() does
1087 not change clip or SkMatrix.
1088
1089 discard() may do nothing, depending on the implementation of SkSurface or SkBaseDevice
1090 that created SkCanvas.
1091
1092 discard() allows optimized performance on subsequent draws by removing
1093 cached data associated with SkSurface or SkBaseDevice.
1094 It is not necessary to call discard() once done with SkCanvas;
1095 any cached data is deleted when owning SkSurface or SkBaseDevice is deleted.
1096 */
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +00001097 void discard() { this->onDiscard(); }
1098
Cary Clarkb7da7232017-09-01 13:49:54 -04001099 /** Fill clip with SkPaint paint. SkPaint components SkRasterizer, SkMaskFilter, SkShader,
1100 SkColorFilter, SkImageFilter, and SkBlendMode affect drawing;
1101 SkPathEffect in paint is ignored.
1102
1103 @param paint graphics state used to fill SkCanvas
1104 */
reed0846f1b2015-01-09 14:17:40 -08001105 void drawPaint(const SkPaint& paint);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001106
Cary Clarkb7da7232017-09-01 13:49:54 -04001107 /** \enum SkCanvas::PointMode
1108 Selects if an array of points are drawn as discrete points, as lines, or as
1109 an open polygon.
1110 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001111 enum PointMode {
Cary Clarkb7da7232017-09-01 13:49:54 -04001112 kPoints_PointMode, //!< Draw each point separately.
1113 kLines_PointMode, //!< Draw each pair of points as a line segment.
1114 kPolygon_PointMode, //!< Draw the array of points as a open polygon.
reed@android.com8a1c16f2008-12-17 15:59:43 +00001115 };
1116
Cary Clarkb7da7232017-09-01 13:49:54 -04001117 /** Draw pts using clip, SkMatrix and SkPaint paint.
1118 count is the number of points; if count is less than one, has no effect.
1119 mode may be one of: kPoints_PointMode, kLines_PointMode, or kPolygon_PointMode.
1120
1121 If mode is kPoints_PointMode, the shape of point drawn depends on paint
1122 SkPaint::Cap. If paint is set to SkPaint::kRound_Cap, each point draws a
1123 circle of diameter SkPaint stroke width. If paint is set to SkPaint::kSquare_Cap
1124 or SkPaint::kButt_Cap, each point draws a square of width and height
1125 SkPaint stroke width.
1126
1127 If mode is kLines_PointMode, each pair of points draws a line segment.
1128 One line is drawn for every two points; each point is used once. If count is odd,
1129 the final point is ignored.
1130
1131 If mode is kPolygon_PointMode, each adjacent pair of points draws a line segment.
1132 count minus one lines are drawn; the first and last point are used once.
1133
1134 Each line segment respects paint SkPaint::Cap and SkPaint stroke width.
1135 SkPaint::Style is ignored, as if were set to SkPaint::kStroke_Style.
1136
1137 Always draws each element one at a time; is not affected by
1138 SkPaint::Join, and unlike drawPath(), does not create a mask from all points
1139 and lines before drawing.
1140
1141 @param mode whether pts draws points or lines
1142 @param count number of points in the array
1143 @param pts array of points to draw
1144 @param paint stroke, blend, color, and so on, used to draw
reed@android.com8a1c16f2008-12-17 15:59:43 +00001145 */
reed0846f1b2015-01-09 14:17:40 -08001146 void drawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint& paint);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001147
Cary Clarkb7da7232017-09-01 13:49:54 -04001148 /** Draw point at (x, y) using clip, SkMatrix and SkPaint paint.
1149
1150 The shape of point drawn depends on paint SkPaint::Cap.
1151 If paint is set to SkPaint::kRound_Cap, draw a circle of diameter
1152 SkPaint stroke width. If paint is set to SkPaint::kSquare_Cap or SkPaint::kButt_Cap,
1153 draw a square of width and height SkPaint stroke width.
1154 SkPaint::Style is ignored, as if were set to SkPaint::kStroke_Style.
1155
1156 @param x left edge of circle or square
1157 @param y top edge of circle or square
1158 @param paint stroke, blend, color, and so on, used to draw
1159 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00001160 void drawPoint(SkScalar x, SkScalar y, const SkPaint& paint);
Cary Clarkb7da7232017-09-01 13:49:54 -04001161
1162 /** Draw point p using clip, SkMatrix and SkPaint paint.
1163
1164 The shape of point drawn depends on paint SkPaint::Cap.
1165 If paint is set to SkPaint::kRound_Cap, draw a circle of diameter
1166 SkPaint stroke width. If paint is set to SkPaint::kSquare_Cap or SkPaint::kButt_Cap,
1167 draw a square of width and height SkPaint stroke width.
1168 SkPaint::Style is ignored, as if were set to SkPaint::kStroke_Style.
1169
1170 @param p top-left edge of circle or square
1171 @param paint stroke, blend, color, and so on, used to draw
1172 */
Hal Canary23e474c2017-05-15 13:35:35 -04001173 void drawPoint(SkPoint p, const SkPaint& paint) {
1174 this->drawPoint(p.x(), p.y(), paint);
1175 }
reed@google.com4b226022011-01-11 18:32:13 +00001176
Cary Clarkb7da7232017-09-01 13:49:54 -04001177 /** Draws line segment from (x0, y0) to (x1, y1) using clip, SkMatrix, and SkPaint paint.
1178 In paint: SkPaint stroke width describes the line thickness;
1179 SkPaint::Cap draws the end rounded or square;
1180 SkPaint::Style is ignored, as if were set to SkPaint::kStroke_Style.
1181
1182 @param x0 start of line segment on x-axis
1183 @param y0 start of line segment on y-axis
1184 @param x1 end of line segment on x-axis
1185 @param y1 end of line segment on y-axis
1186 @param paint stroke, blend, color, and so on, used to draw
reed@android.com8a1c16f2008-12-17 15:59:43 +00001187 */
Mike Reed3661bc92017-02-22 13:21:42 -05001188 void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint& paint);
Cary Clarkb7da7232017-09-01 13:49:54 -04001189
1190 /** Draws line segment from p0 to p1 using clip, SkMatrix, and SkPaint paint.
1191 In paint: SkPaint stroke width describes the line thickness;
1192 SkPaint::Cap draws the end rounded or square;
1193 SkPaint::Style is ignored, as if were set to SkPaint::kStroke_Style.
1194
1195 @param p0 start of line segment
1196 @param p1 end of line segment
1197 @param paint stroke, blend, color, and so on, used to draw
1198 */
Hal Canary23e474c2017-05-15 13:35:35 -04001199 void drawLine(SkPoint p0, SkPoint p1, const SkPaint& paint) {
1200 this->drawLine(p0.x(), p0.y(), p1.x(), p1.y(), paint);
1201 }
reed@android.com8a1c16f2008-12-17 15:59:43 +00001202
Cary Clarkb7da7232017-09-01 13:49:54 -04001203 /** Draw SkRect rect using clip, SkMatrix, and SkPaint paint.
1204 In paint: SkPaint::Style determines if rectangle is stroked or filled;
1205 if stroked, SkPaint stroke width describes the line thickness, and
1206 SkPaint::Join draws the corners rounded or square.
1207
1208 @param rect rectangle to be drawn
1209 @param paint stroke or fill, blend, color, and so on, used to draw
reed@android.com8a1c16f2008-12-17 15:59:43 +00001210 */
reed0846f1b2015-01-09 14:17:40 -08001211 void drawRect(const SkRect& rect, const SkPaint& paint);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001212
Cary Clarkb7da7232017-09-01 13:49:54 -04001213 /** Draw SkIRect rect using clip, SkMatrix, and SkPaint paint.
1214 In paint: SkPaint::Style determines if rectangle is stroked or filled;
1215 if stroked, SkPaint stroke width describes the line thickness, and
1216 SkPaint::Join draws the corners rounded or square.
1217
1218 @param rect rectangle to be drawn
1219 @param paint stroke or fill, blend, color, and so on, used to draw
reed@android.com8a1c16f2008-12-17 15:59:43 +00001220 */
reed@google.com87001ed2014-02-17 16:28:05 +00001221 void drawIRect(const SkIRect& rect, const SkPaint& paint) {
reed@android.com8a1c16f2008-12-17 15:59:43 +00001222 SkRect r;
1223 r.set(rect); // promotes the ints to scalars
1224 this->drawRect(r, paint);
1225 }
reed@google.com4b226022011-01-11 18:32:13 +00001226
Cary Clarkb7da7232017-09-01 13:49:54 -04001227 /** Draw SkRegion region using clip, SkMatrix, and SkPaint paint.
1228 In paint: SkPaint::Style determines if rectangle is stroked or filled;
1229 if stroked, SkPaint stroke width describes the line thickness, and
1230 SkPaint::Join draws the corners rounded or square.
1231
1232 @param region region to be drawn
1233 @param paint SkPaint stroke or fill, blend, color, and so on, used to draw
msarett44df6512016-08-25 13:54:30 -07001234 */
msarettdca352e2016-08-26 06:37:45 -07001235 void drawRegion(const SkRegion& region, const SkPaint& paint);
msarett44df6512016-08-25 13:54:30 -07001236
Cary Clarkb7da7232017-09-01 13:49:54 -04001237 /** Draw oval oval using clip, SkMatrix, and SkPaint.
1238 In paint: SkPaint::Style determines if oval is stroked or filled;
1239 if stroked, SkPaint stroke width describes the line thickness.
1240
1241 @param oval SkRect bounds of oval
1242 @param paint SkPaint stroke or fill, blend, color, and so on, used to draw
reed@android.com8a1c16f2008-12-17 15:59:43 +00001243 */
Cary Clark304f9d42017-05-13 13:35:35 -04001244 void drawOval(const SkRect& oval, const SkPaint& paint);
reed@google.com4ed0fb72012-12-12 20:48:18 +00001245
Cary Clarkb7da7232017-09-01 13:49:54 -04001246 /** Draw SkRRect rrect using clip, SkMatrix, and SkPaint paint.
1247 In paint: SkPaint::Style determines if rrect is stroked or filled;
1248 if stroked, SkPaint stroke width describes the line thickness.
1249
1250 rrect may represent a rectangle, circle, oval, uniformly rounded rectangle, or
1251 may have any combination of positive non-square radii for the four corners.
1252
1253 @param rrect SkRRect with up to eight corner radii to draw
1254 @param paint SkPaint stroke or fill, blend, color, and so on, used to draw
1255 */
reed0846f1b2015-01-09 14:17:40 -08001256 void drawRRect(const SkRRect& rrect, const SkPaint& paint);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001257
Cary Clarkb7da7232017-09-01 13:49:54 -04001258 /** Draw SkRRect outer and inner
1259 using clip, SkMatrix, and SkPaint paint.
1260 outer must contain inner or the drawing is undefined.
1261 In paint: SkPaint::Style determines if SkRRect is stroked or filled;
1262 if stroked, SkPaint stroke width describes the line thickness.
1263 If stroked and SkRRect corner has zero length radii, SkPaint::Join can
1264 draw corners rounded or square.
1265
1266 GPU-backed platforms optimize drawing when both outer and inner are
1267 concave and outer contains inner. These platforms may not be able to draw
1268 SkPath built with identical data as fast.
1269
1270 @param outer SkRRect outer bounds to draw
1271 @param inner SkRRect inner bounds to draw
1272 @param paint SkPaint stroke or fill, blend, color, and so on, used to draw
1273 */
Cary Clark304f9d42017-05-13 13:35:35 -04001274 void drawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint);
commit-bot@chromium.orged9806f2014-02-21 02:32:36 +00001275
Cary Clarkb7da7232017-09-01 13:49:54 -04001276 /** Draw circle at (cx, cy) with radius using clip, SkMatrix, and SkPaint paint.
1277 If radius is zero or less, nothing is drawn.
1278 In paint: SkPaint::Style determines if circle is stroked or filled;
1279 if stroked, SkPaint stroke width describes the line thickness.
1280
Cary Clark8a02b0b2017-09-21 12:28:43 -04001281 @param cx circle center on the x-axis
1282 @param cy circle center on the y-axis
Cary Clarkb7da7232017-09-01 13:49:54 -04001283 @param radius half the diameter of circle
1284 @param paint SkPaint stroke or fill, blend, color, and so on, used to draw
reed@android.com8a1c16f2008-12-17 15:59:43 +00001285 */
Mike Reed3661bc92017-02-22 13:21:42 -05001286 void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint& paint);
Cary Clarkb7da7232017-09-01 13:49:54 -04001287
1288 /** Draw circle at center with radius using clip, SkMatrix, and SkPaint paint.
1289 If radius is zero or less, nothing is drawn.
1290 In paint: SkPaint::Style determines if circle is stroked or filled;
1291 if stroked, SkPaint stroke width describes the line thickness.
1292
Cary Clark8a02b0b2017-09-21 12:28:43 -04001293 @param center circle center
Cary Clarkb7da7232017-09-01 13:49:54 -04001294 @param radius half the diameter of circle
1295 @param paint SkPaint stroke or fill, blend, color, and so on, used to draw
1296 */
Hal Canary23e474c2017-05-15 13:35:35 -04001297 void drawCircle(SkPoint center, SkScalar radius, const SkPaint& paint) {
1298 this->drawCircle(center.x(), center.y(), radius, paint);
1299 }
reed@android.com8a1c16f2008-12-17 15:59:43 +00001300
Cary Clarkb7da7232017-09-01 13:49:54 -04001301 /** Draw arc using clip, SkMatrix, and SkPaint paint.
1302
1303 Arc is part of oval bounded by oval, sweeping from startAngle to startAngle plus
1304 sweepAngle. startAngle and sweepAngle are in degrees.
1305
1306 startAngle of zero places start point at the right middle edge of oval.
1307 A positive sweepAngle places arc end point clockwise from start point;
1308 a negative sweepAngle places arc end point counterclockwise from start point.
1309 sweepAngle may exceed 360 degrees, a full circle.
1310 If useCenter is true, draw a wedge that includes lines from oval
1311 center to arc end points. If useCenter is false, draw arc between end points.
1312
1313 If SkRect oval is empty or sweepAngle is zero, nothing is drawn.
1314
1315 @param oval SkRect bounds of oval containing arc to draw
1316 @param startAngle angle in degrees where arc begins
1317 @param sweepAngle sweep angle in degrees; positive is clockwise
1318 @param useCenter if true, include the center of the oval
1319 @param paint SkPaint stroke or fill, blend, color, and so on, used to draw
reed@android.com8a1c16f2008-12-17 15:59:43 +00001320 */
1321 void drawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle,
1322 bool useCenter, const SkPaint& paint);
1323
Cary Clarkb7da7232017-09-01 13:49:54 -04001324 /** Draw SkRRect bounded by SkRect rect, with corner radii (rx, ry) using clip,
1325 SkMatrix, and SkPaint paint.
1326
1327 In paint: SkPaint::Style determines if SkRRect is stroked or filled;
1328 if stroked, SkPaint stroke width describes the line thickness.
1329 If rx or ry are less than zero, they are treated as if they are zero.
1330 If rx plus ry exceeds rect width or rect height, radii are scaled down to fit.
1331 If rx and ry are zero, SkRRect is drawn as SkRect and if stroked is affected by
1332 SkPaint::Join.
1333
1334 @param rect SkRect bounds of SkRRect to draw
1335 @param rx axis length in x of oval describing rounded corners
1336 @param ry axis length in y of oval describing rounded corners
1337 @param paint stroke, blend, color, and so on, used to draw
reed@android.com8a1c16f2008-12-17 15:59:43 +00001338 */
Mike Reed3661bc92017-02-22 13:21:42 -05001339 void drawRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry, const SkPaint& paint);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001340
Cary Clarkb7da7232017-09-01 13:49:54 -04001341 /** Draw SkPath path using clip, SkMatrix, and SkPaint paint.
1342 SkPath contains an array of path contour, each of which may be open or closed.
1343
1344 In paint: SkPaint::Style determines if SkRRect is stroked or filled:
1345 if filled, SkPath::FillType determines whether path contour describes inside or
1346 outside of fill; if stroked, SkPaint stroke width describes the line thickness,
1347 SkPaint::Cap describes line ends, and SkPaint::Join describes how
1348 corners are drawn.
1349
1350 @param path SkPath to draw
1351 @param paint stroke, blend, color, and so on, used to draw
reed@android.com8a1c16f2008-12-17 15:59:43 +00001352 */
reed0846f1b2015-01-09 14:17:40 -08001353 void drawPath(const SkPath& path, const SkPaint& paint);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001354
Cary Clarkb7da7232017-09-01 13:49:54 -04001355 /** Draw SkImage image, with its top-left corner at (left, top),
1356 using clip, SkMatrix, and optional SkPaint paint.
piotaixrd52893c2014-09-25 14:39:40 -07001357
Cary Clarkb7da7232017-09-01 13:49:54 -04001358 If paint is supplied, apply SkColorFilter, color alpha, SkImageFilter, SkBlendMode,
1359 and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader.
1360 If paint contains SkMaskFilter, generate mask from image bounds. If generated
1361 mask extends beyond image bounds, replicate image edge colors, just as SkShader
1362 made from SkImage::makeShader with SkShader::kClamp_TileMode set replicates the
1363 image's edge color when it samples outside of its bounds.
1364
1365 @param image uncompressed rectangular map of pixels
1366 @param left left side of image
1367 @param top top side of image
1368 @param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
1369 and so on; or nullptr
1370 */
Ben Wagnera93a14a2017-08-28 10:34:05 -04001371 void drawImage(const SkImage* image, SkScalar left, SkScalar top,
1372 const SkPaint* paint = nullptr);
Cary Clarkb7da7232017-09-01 13:49:54 -04001373
1374 /** Draw SkImage image, with its top-left corner at (left, top),
1375 using clip, SkMatrix, and optional SkPaint paint.
1376
1377 If SkPaint paint is supplied, apply SkColorFilter, color alpha, SkImageFilter,
1378 SkBlendMode, and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader.
1379 If paint contains SkMaskFilter, generate mask from image bounds. If generated
1380 mask extends beyond image bounds, replicate image edge colors, just as SkShader
1381 made from SkImage::makeShader with SkShader::kClamp_TileMode set replicates the
1382 image's edge color when it samples outside of its bounds.
1383
1384 @param image uncompressed rectangular map of pixels
1385 @param left left side of image
1386 @param top pop side of image
1387 @param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
1388 and so on; or nullptr
1389 */
reedf8053da2016-03-17 08:14:57 -07001390 void drawImage(const sk_sp<SkImage>& image, SkScalar left, SkScalar top,
Ben Wagnera93a14a2017-08-28 10:34:05 -04001391 const SkPaint* paint = nullptr) {
reedf8053da2016-03-17 08:14:57 -07001392 this->drawImage(image.get(), left, top, paint);
1393 }
piotaixrb5fae932014-09-24 13:03:30 -07001394
Cary Clarkb7da7232017-09-01 13:49:54 -04001395 /** \enum SkCanvas::SrcRectConstraint
1396 SrcRectConstraint controls the behavior at the edge of source SkRect,
1397 provided to drawImageRect(), trading off speed for precision.
1398
1399 SkImageFilter in SkPaint may sample multiple pixels in the image. Source SkRect
1400 restricts the bounds of pixels that may be read. SkImageFilter may slow down if
1401 it cannot read outside the bounds, when sampling near the edge of source SkRect.
1402 SrcRectConstraint specifies whether an SkImageFilter is allowed to read pixels
1403 outside source SkRect.
1404 */
reeda5517e22015-07-14 10:54:12 -07001405 enum SrcRectConstraint {
Cary Clarkb7da7232017-09-01 13:49:54 -04001406 /** sampling only inside of its bounds, possibly with a performance penalty. */
reeda5517e22015-07-14 10:54:12 -07001407 kStrict_SrcRectConstraint,
1408
Cary Clarkb7da7232017-09-01 13:49:54 -04001409 /** by half the width of SkImageFilter, permitting it to run faster but with
1410 error at the image edges.
1411 */
reeda5517e22015-07-14 10:54:12 -07001412 kFast_SrcRectConstraint,
1413 };
1414
Cary Clarkb7da7232017-09-01 13:49:54 -04001415 /** Draw SkRect src of SkImage image, scaled and translated to fill SkRect dst.
1416 Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.
1417
1418 If SkPaint paint is supplied, apply SkColorFilter, color alpha, SkImageFilter,
1419 SkBlendMode, and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader.
1420 If paint contains SkMaskFilter, generate mask from image bounds.
1421
1422 If generated mask extends beyond image bounds, replicate image edge colors, just
1423 as SkShader made from SkImage::makeShader with SkShader::kClamp_TileMode set
1424 replicates the image's edge color when it samples outside of its bounds.
1425
1426 constraint set to kStrict_SrcRectConstraint limits SkPaint SkFilterQuality to
1427 sample within src; set to kFast_SrcRectConstraint allows sampling outside to
1428 improve performance.
1429
1430 @param image SkImage containing pixels, dimensions, and format
1431 @param src source SkRect of image to draw from
1432 @param dst destination SkRect of image to draw to
1433 @param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
1434 and so on; or nullptr
1435 @param constraint filter strictly within src or draw faster
1436 */
reede47829b2015-08-06 10:02:53 -07001437 void drawImageRect(const SkImage* image, const SkRect& src, const SkRect& dst,
1438 const SkPaint* paint,
1439 SrcRectConstraint constraint = kStrict_SrcRectConstraint);
Cary Clarkb7da7232017-09-01 13:49:54 -04001440
1441 /** Draw SkIRect isrc of SkImage image, scaled and translated to fill SkRect dst.
1442 Note that isrc is on integer pixel boundaries; dst may include fractional
1443 boundaries. Additionally transform draw using clip, SkMatrix, and optional SkPaint
1444 paint.
1445
1446 If SkPaint paint is supplied, apply SkColorFilter, color alpha, SkImageFilter,
1447 SkBlendMode, and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader.
1448 If paint contains SkMaskFilter, generate mask from image bounds.
1449
1450 If generated mask extends beyond image bounds, replicate image edge colors, just
1451 as SkShader made from SkImage::makeShader with SkShader::kClamp_TileMode set
1452 replicates the image's edge color when it samples outside of its bounds.
1453
1454 constraint set to kStrict_SrcRectConstraint limits SkPaint SkFilterQuality to
1455 sample within isrc; set to kFast_SrcRectConstraint allows sampling outside to
1456 improve performance.
1457
1458 @param image SkImage containing pixels, dimensions, and format
1459 @param isrc source SkIRect of image to draw from
1460 @param dst destination SkRect of image to draw to
1461 @param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
1462 and so on; or nullptr
1463 @param constraint filter strictly within isrc or draw faster
1464 */
reede47829b2015-08-06 10:02:53 -07001465 void drawImageRect(const SkImage* image, const SkIRect& isrc, const SkRect& dst,
Cary Clark0418a882017-05-10 09:07:42 -04001466 const SkPaint* paint,
1467 SrcRectConstraint constraint = kStrict_SrcRectConstraint);
Cary Clarkb7da7232017-09-01 13:49:54 -04001468
1469 /** Draw SkImage image, scaled and translated to fill SkRect dst, using clip, SkMatrix,
1470 and optional SkPaint paint.
1471
1472 If SkPaint paint is supplied, apply SkColorFilter, color alpha, SkImageFilter,
1473 SkBlendMode, and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader.
1474 If paint contains SkMaskFilter, generate mask from image bounds.
1475
1476 If generated mask extends beyond image bounds, replicate image edge colors, just
1477 as SkShader made from SkImage::makeShader with SkShader::kClamp_TileMode set
1478 replicates the image's edge color when it samples outside of its bounds.
1479
1480 constraint set to kStrict_SrcRectConstraint limits SkPaint SkFilterQuality to
1481 sample within image; set to kFast_SrcRectConstraint allows sampling outside to
1482 improve performance.
1483
1484 @param image SkImage containing pixels, dimensions, and format
1485 @param dst destination SkRect of image to draw to
1486 @param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
1487 and so on; or nullptr
1488 @param constraint filter strictly within image or draw faster
1489 */
reede47829b2015-08-06 10:02:53 -07001490 void drawImageRect(const SkImage* image, const SkRect& dst, const SkPaint* paint,
Cary Clark0418a882017-05-10 09:07:42 -04001491 SrcRectConstraint constraint = kStrict_SrcRectConstraint);
reed84984ef2015-07-17 07:09:43 -07001492
Cary Clarkb7da7232017-09-01 13:49:54 -04001493 /** Draw SkRect src of SkImage image, scaled and translated to fill SkRect dst.
1494 Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.
1495
1496 If SkPaint paint is supplied, apply SkColorFilter, color alpha, SkImageFilter,
1497 SkBlendMode, and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader.
1498 If paint contains SkMaskFilter, generate mask from image bounds.
1499
1500 If generated mask extends beyond image bounds, replicate image edge colors, just
1501 as SkShader made from SkImage::makeShader with SkShader::kClamp_TileMode set
1502 replicates the image's edge color when it samples outside of its bounds.
1503
1504 constraint set to kStrict_SrcRectConstraint limits SkPaint SkFilterQuality to
1505 sample within src; set to kFast_SrcRectConstraint allows sampling outside to
1506 improve performance.
1507
1508 @param image SkImage containing pixels, dimensions, and format
1509 @param src source SkRect of image to draw from
1510 @param dst destination SkRect of image to draw to
1511 @param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
1512 and so on; or nullptr
1513 @param constraint filter strictly within src or draw faster
1514 */
reedf8053da2016-03-17 08:14:57 -07001515 void drawImageRect(const sk_sp<SkImage>& image, const SkRect& src, const SkRect& dst,
1516 const SkPaint* paint,
1517 SrcRectConstraint constraint = kStrict_SrcRectConstraint) {
1518 this->drawImageRect(image.get(), src, dst, paint, constraint);
1519 }
Cary Clarkb7da7232017-09-01 13:49:54 -04001520
1521 /** Draw SkIRect isrc of SkImage image, scaled and translated to fill SkRect dst.
1522 isrc is on integer pixel boundaries; dst may include fractional boundaries.
1523 Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.
1524
1525 If SkPaint paint is supplied, apply SkColorFilter, color alpha, SkImageFilter,
1526 SkBlendMode, and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader.
1527 If paint contains SkMaskFilter, generate mask from image bounds.
1528
1529 If generated mask extends beyond image bounds, replicate image edge colors, just
1530 as SkShader made from SkImage::makeShader with SkShader::kClamp_TileMode set
1531 replicates the image's edge color when it samples outside of its bounds.
1532
1533 constraint set to kStrict_SrcRectConstraint limits SkPaint SkFilterQuality to
1534 sample within image; set to kFast_SrcRectConstraint allows sampling outside to
1535 improve performance.
1536
1537 @param image SkImage containing pixels, dimensions, and format
1538 @param isrc source SkIRect of image to draw from
1539 @param dst destination SkRect of image to draw to
1540 @param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
1541 and so on; or nullptr
1542 @param constraint filter strictly within image or draw faster
1543 */
reedf8053da2016-03-17 08:14:57 -07001544 void drawImageRect(const sk_sp<SkImage>& image, const SkIRect& isrc, const SkRect& dst,
Cary Clark0418a882017-05-10 09:07:42 -04001545 const SkPaint* paint,
1546 SrcRectConstraint constraint = kStrict_SrcRectConstraint) {
1547 this->drawImageRect(image.get(), isrc, dst, paint, constraint);
reedf8053da2016-03-17 08:14:57 -07001548 }
Cary Clarkb7da7232017-09-01 13:49:54 -04001549
1550 /** Draw SkImage image, scaled and translated to fill SkRect dst,
1551 using clip, SkMatrix, and optional SkPaint paint.
1552
1553 If SkPaint paint is supplied, apply SkColorFilter, color alpha, SkImageFilter,
1554 SkBlendMode, and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader.
1555 If paint contains SkMaskFilter, generate mask from image bounds.
1556
1557 If generated mask extends beyond image bounds, replicate image edge colors, just
1558 as SkShader made from SkImage::makeShader with SkShader::kClamp_TileMode set
1559 replicates the image's edge color when it samples outside of its bounds.
1560
1561 constraint set to kStrict_SrcRectConstraint limits SkPaint SkFilterQuality to
1562 sample within image; set to kFast_SrcRectConstraint allows sampling outside to
1563 improve performance.
1564
1565 @param image SkImage containing pixels, dimensions, and format
1566 @param dst destination SkRect of image to draw to
1567 @param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
1568 and so on; or nullptr
1569 @param constraint filter strictly within image or draw faster
1570 */
reedf8053da2016-03-17 08:14:57 -07001571 void drawImageRect(const sk_sp<SkImage>& image, const SkRect& dst, const SkPaint* paint,
Cary Clark0418a882017-05-10 09:07:42 -04001572 SrcRectConstraint constraint = kStrict_SrcRectConstraint) {
1573 this->drawImageRect(image.get(), dst, paint, constraint);
reedf8053da2016-03-17 08:14:57 -07001574 }
1575
Cary Clark8a02b0b2017-09-21 12:28:43 -04001576 /** Draw SkImage image stretched proportionally to fit into SkRect dst.
Cary Clarkb7da7232017-09-01 13:49:54 -04001577 SkIRect center divides the image into nine sections: four sides, four corners, and
1578 the center. Corners are unmodified or scaled down proportionately if their sides
1579 are larger than dst; center and four sides are scaled to fit remaining space, if any.
1580
1581 Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.
1582
1583 If SkPaint paint is supplied, apply SkColorFilter, color alpha, SkImageFilter,
1584 SkBlendMode, and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader.
1585 If paint contains SkMaskFilter, generate mask from image bounds.
1586
1587 If generated mask extends beyond image bounds, replicate image edge colors, just
1588 as SkShader made from SkImage::makeShader with SkShader::kClamp_TileMode set
1589 replicates the image's edge color when it samples outside of its bounds.
1590
1591 @param image SkImage containing pixels, dimensions, and format
1592 @param center SkIRect edge of image corners and sides
1593 @param dst destination SkRect of image to draw to
1594 @param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
1595 and so on; or nullptr
1596 */
Cary Clark0418a882017-05-10 09:07:42 -04001597 void drawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst,
reedf8053da2016-03-17 08:14:57 -07001598 const SkPaint* paint = nullptr);
Cary Clarkb7da7232017-09-01 13:49:54 -04001599
Cary Clark8a02b0b2017-09-21 12:28:43 -04001600 /** Draw SkImage image stretched proportionally to fit into SkRect dst.
Cary Clarkb7da7232017-09-01 13:49:54 -04001601 SkIRect center divides the image into nine sections: four sides, four corners, and
1602 the center. Corners are not scaled, or scaled down proportionately if their sides
1603 are larger than dst; center and four sides are scaled to fit remaining space, if any.
1604
1605 Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.
1606
1607 If SkPaint paint is supplied, apply SkColorFilter, color alpha, SkImageFilter,
1608 SkBlendMode, and SkDrawLooper. If image is kAlpha_8_SkColorType, apply SkShader.
1609 If paint contains SkMaskFilter, generate mask from image bounds.
1610
1611 If generated mask extends beyond image bounds, replicate image edge colors, just
1612 as SkShader made from SkImage::makeShader with SkShader::kClamp_TileMode set
1613 replicates the image's edge color when it samples outside of its bounds.
1614
1615 @param image SkImage containing pixels, dimensions, and format
1616 @param center SkIRect edge of image corners and sides
1617 @param dst destination SkRect of image to draw to
1618 @param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
1619 and so on; or nullptr
1620 */
reedf8053da2016-03-17 08:14:57 -07001621 void drawImageNine(const sk_sp<SkImage>& image, const SkIRect& center, const SkRect& dst,
1622 const SkPaint* paint = nullptr) {
1623 this->drawImageNine(image.get(), center, dst, paint);
1624 }
reed4c21dc52015-06-25 12:32:03 -07001625
Cary Clarkb7da7232017-09-01 13:49:54 -04001626 /** Draw SkBitmap bitmap, with its top-left corner at (left, top),
1627 using clip, SkMatrix, and optional SkPaint paint.
commit-bot@chromium.org91246b92013-12-05 15:43:19 +00001628
Cary Clarkb7da7232017-09-01 13:49:54 -04001629 If SkPaint paint is supplied, apply SkColorFilter, color alpha, SkImageFilter,
1630 SkBlendMode, and SkDrawLooper. If bitmap is kAlpha_8_SkColorType, apply SkShader.
1631 If paint contains SkMaskFilter, generate mask from bitmap bounds.
commit-bot@chromium.org91246b92013-12-05 15:43:19 +00001632
Cary Clarkb7da7232017-09-01 13:49:54 -04001633 If generated mask extends beyond bitmap bounds, replicate bitmap edge colors,
1634 just as SkShader made from SkShader::MakeBitmapShader with
1635 SkShader::kClamp_TileMode set replicates the bitmap's edge color when it samples
1636 outside of its bounds.
1637
1638 @param bitmap SkBitmap containing pixels, dimensions, and format
1639 @param left left side of bitmap
1640 @param top top side of bitmap
1641 @param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
1642 and so on; or nullptr
reed@android.com8a1c16f2008-12-17 15:59:43 +00001643 */
reed0846f1b2015-01-09 14:17:40 -08001644 void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
Ben Wagnera93a14a2017-08-28 10:34:05 -04001645 const SkPaint* paint = nullptr);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001646
Cary Clarkb7da7232017-09-01 13:49:54 -04001647 /** Draw SkRect src of SkBitmap bitmap, scaled and translated to fill SkRect dst.
1648 Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.
1649
1650 If SkPaint paint is supplied, apply SkColorFilter, color alpha, SkImageFilter,
1651 SkBlendMode, and SkDrawLooper. If bitmap is kAlpha_8_SkColorType, apply SkShader.
1652 If paint contains SkMaskFilter, generate mask from bitmap bounds.
1653
1654 If generated mask extends beyond bitmap bounds, replicate bitmap edge colors,
1655 just as SkShader made from SkShader::MakeBitmapShader with
1656 SkShader::kClamp_TileMode set replicates the bitmap's edge color when it samples
1657 outside of its bounds.
1658
1659 constraint set to kStrict_SrcRectConstraint limits SkPaint SkFilterQuality to
1660 sample within src; set to kFast_SrcRectConstraint allows sampling outside to
1661 improve performance.
1662
1663 @param bitmap SkBitmap containing pixels, dimensions, and format
1664 @param src source SkRect of image to draw from
1665 @param dst destination SkRect of image to draw to
1666 @param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
1667 and so on; or nullptr
1668 @param constraint filter strictly within src or draw faster
1669 */
reede47829b2015-08-06 10:02:53 -07001670 void drawBitmapRect(const SkBitmap& bitmap, const SkRect& src, const SkRect& dst,
Cary Clark0418a882017-05-10 09:07:42 -04001671 const SkPaint* paint,
1672 SrcRectConstraint constraint = kStrict_SrcRectConstraint);
Cary Clarkb7da7232017-09-01 13:49:54 -04001673
1674 /** Draw SkIRect isrc of SkBitmap bitmap, scaled and translated to fill SkRect dst.
1675 isrc is on integer pixel boundaries; dst may include fractional boundaries.
1676 Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.
1677
1678 If SkPaint paint is supplied, apply SkColorFilter, color alpha, SkImageFilter,
1679 SkBlendMode, and SkDrawLooper. If bitmap is kAlpha_8_SkColorType, apply SkShader.
1680 If paint contains SkMaskFilter, generate mask from bitmap bounds.
1681
1682 If generated mask extends beyond bitmap bounds, replicate bitmap edge colors,
1683 just as SkShader made from SkShader::MakeBitmapShader with
1684 SkShader::kClamp_TileMode set replicates the bitmap's edge color when it samples
1685 outside of its bounds.
1686
1687 constraint set to kStrict_SrcRectConstraint limits SkPaint SkFilterQuality to
1688 sample within isrc; set to kFast_SrcRectConstraint allows sampling outside to
1689 improve performance.
1690
1691 @param bitmap SkBitmap containing pixels, dimensions, and format
1692 @param isrc source SkIRect of image to draw from
1693 @param dst destination SkRect of image to draw to
1694 @param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
1695 and so on; or nullptr
1696 @param constraint sample strictly within isrc, or draw faster
1697 */
reed84984ef2015-07-17 07:09:43 -07001698 void drawBitmapRect(const SkBitmap& bitmap, const SkIRect& isrc, const SkRect& dst,
Cary Clark0418a882017-05-10 09:07:42 -04001699 const SkPaint* paint,
1700 SrcRectConstraint constraint = kStrict_SrcRectConstraint);
Cary Clarkb7da7232017-09-01 13:49:54 -04001701
1702 /** Draw SkBitmap bitmap, scaled and translated to fill SkRect dst.
1703 bitmap bounds is on integer pixel boundaries; dst may include fractional boundaries.
1704 Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.
1705
1706 If SkPaint paint is supplied, apply SkColorFilter, color alpha, SkImageFilter,
1707 SkBlendMode, and SkDrawLooper. If bitmap is kAlpha_8_SkColorType, apply SkShader.
1708 If paint contains SkMaskFilter, generate mask from bitmap bounds.
1709
1710 If generated mask extends beyond bitmap bounds, replicate bitmap edge colors,
1711 just as SkShader made from SkShader::MakeBitmapShader with
1712 SkShader::kClamp_TileMode set replicates the bitmap's edge color when it samples
1713 outside of its bounds.
1714
1715 constraint set to kStrict_SrcRectConstraint limits SkPaint SkFilterQuality to
1716 sample within bitmap; set to kFast_SrcRectConstraint allows sampling outside to
1717 improve performance.
1718
1719 @param bitmap SkBitmap containing pixels, dimensions, and format
1720 @param dst destination SkRect of image to draw to
1721 @param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
1722 and so on; or nullptr
1723 @param constraint filter strictly within bitmap or draw faster
1724 */
reede47829b2015-08-06 10:02:53 -07001725 void drawBitmapRect(const SkBitmap& bitmap, const SkRect& dst, const SkPaint* paint,
Cary Clark0418a882017-05-10 09:07:42 -04001726 SrcRectConstraint constraint = kStrict_SrcRectConstraint);
reed84984ef2015-07-17 07:09:43 -07001727
Cary Clark8a02b0b2017-09-21 12:28:43 -04001728 /** Draw SkBitmap bitmap stretched proportionally to fit into SkRect dst.
Cary Clarkb7da7232017-09-01 13:49:54 -04001729 SkIRect center divides the bitmap into nine sections: four sides, four corners,
1730 and the center. Corners are not scaled, or scaled down proportionately if their
1731 sides are larger than dst; center and four sides are scaled to fit remaining
1732 space, if any.
1733
1734 Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.
1735
1736 If SkPaint paint is supplied, apply SkColorFilter, color alpha, SkImageFilter,
1737 SkBlendMode, and SkDrawLooper. If bitmap is kAlpha_8_SkColorType, apply SkShader.
1738 If paint contains SkMaskFilter, generate mask from bitmap bounds.
1739
1740 If generated mask extends beyond bitmap bounds, replicate bitmap edge colors,
1741 just as SkShader made from SkShader::MakeBitmapShader with
1742 SkShader::kClamp_TileMode set replicates the bitmap's edge color when it samples
1743 outside of its bounds.
1744
1745 @param bitmap SkBitmap containing pixels, dimensions, and format
1746 @param center SkIRect edge of image corners and sides
1747 @param dst destination SkRect of image to draw to
1748 @param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
1749 and so on; or nullptr
1750 */
reed0846f1b2015-01-09 14:17:40 -08001751 void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst,
Ben Wagnera93a14a2017-08-28 10:34:05 -04001752 const SkPaint* paint = nullptr);
reed@google.comf0b5e112011-09-07 11:57:34 +00001753
Cary Clarkb7da7232017-09-01 13:49:54 -04001754 /** \struct SkCanvas::Lattice
Cary Clark8a02b0b2017-09-21 12:28:43 -04001755 Lattice divides SkBitmap or SkImage into a rectangular grid.
1756 Grid entries on even columns and even rows are fixed; these entries are
1757 always drawn at their original size if the destination is large enough.
1758 If the destination side is too small to hold the fixed entries, all fixed
1759 entries are proportionately scaled down to fit.
1760 The grid entries not on even columns and rows are scaled to fit the
1761 remaining space, if any.
Cary Clarkb7da7232017-09-01 13:49:54 -04001762 */
msarettc573a402016-08-02 08:05:56 -07001763 struct Lattice {
Cary Clarkb7da7232017-09-01 13:49:54 -04001764
1765 /** \enum SkCanvas::Lattice::Flags
1766 Optional setting per rectangular grid entry to make it transparent.
1767 */
msarett0764efe2016-09-02 11:24:30 -07001768 enum Flags : uint8_t {
Cary Clarkb7da7232017-09-01 13:49:54 -04001769 /** Set to skip lattice rectangle by making it transparent. */
msarett0764efe2016-09-02 11:24:30 -07001770 kTransparent_Flags = 1 << 0,
1771 };
msarettc573a402016-08-02 08:05:56 -07001772
Cary Clarkb7da7232017-09-01 13:49:54 -04001773 /** Array of x-coordinates that divide the bitmap vertically.
1774 Array entries must be unique, increasing, greater than or equal to
1775 fBounds left edge, and less than fBounds right edge.
1776 Set the first element to fBounds left to collapse the left column of
1777 fixed grid entries.
1778 */
msarett71df2d72016-09-30 12:41:42 -07001779 const int* fXDivs;
msarettc573a402016-08-02 08:05:56 -07001780
Cary Clarkb7da7232017-09-01 13:49:54 -04001781 /** Array of y-coordinates that divide the bitmap horizontally.
1782 Array entries must be unique, increasing, greater than or equal to
1783 fBounds top edge, and less than fBounds bottom edge.
1784 Set the first element to fBounds top to collapse the top row of fixed
1785 grid entries.
1786 */
msarett71df2d72016-09-30 12:41:42 -07001787 const int* fYDivs;
msarett0764efe2016-09-02 11:24:30 -07001788
Cary Clarkb7da7232017-09-01 13:49:54 -04001789 /** Optional array of flags, one per rectangular grid entry:
1790 array length must be (fXCount + 1) * (fYCount + 1).
Cary Clark8a02b0b2017-09-21 12:28:43 -04001791
Cary Clarkb7da7232017-09-01 13:49:54 -04001792 Array entries correspond to the rectangular grid entries, ascending
1793 left to right and then top to bottom.
1794 */
msarett71df2d72016-09-30 12:41:42 -07001795 const Flags* fFlags;
msarett0764efe2016-09-02 11:24:30 -07001796
Cary Clarkb7da7232017-09-01 13:49:54 -04001797 /** Number of entries in fXDivs array; one less than the number of
1798 horizontal divisions.
1799 */
msarett71df2d72016-09-30 12:41:42 -07001800 int fXCount;
msarettc573a402016-08-02 08:05:56 -07001801
Cary Clarkb7da7232017-09-01 13:49:54 -04001802 /** Number of entries in fYDivs array; one less than the number of vertical
1803 divisions.
1804 */
msarett71df2d72016-09-30 12:41:42 -07001805 int fYCount;
1806
Cary Clarkb7da7232017-09-01 13:49:54 -04001807 /** Optional subset SkIRect source to draw from.
1808 If nullptr, source bounds is dimensions of SkBitmap or SkImage.
1809 */
msarett71df2d72016-09-30 12:41:42 -07001810 const SkIRect* fBounds;
Cary Clarkb7da7232017-09-01 13:49:54 -04001811
msarettc573a402016-08-02 08:05:56 -07001812 };
1813
Cary Clark8a02b0b2017-09-21 12:28:43 -04001814 /** Draw SkBitmap bitmap stretched proportionally to fit into SkRect dst.
Cary Clarkb7da7232017-09-01 13:49:54 -04001815
1816 Lattice lattice divides bitmap into a rectangular grid.
1817 Each intersection of an even-numbered row and column is fixed; like the corners
1818 of drawBitmapNine(), fixed lattice elements never scale larger than their initial
1819 size and shrink proportionately when all fixed elements exceed the bitmap's
1820 dimension. All other grid elements scale to fill the available space, if any.
1821
1822 Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.
1823
1824 If SkPaint paint is supplied, apply SkColorFilter, color alpha, SkImageFilter,
1825 SkBlendMode, and SkDrawLooper. If bitmap is kAlpha_8_SkColorType, apply SkShader.
1826 If paint contains SkMaskFilter, generate mask from bitmap bounds.
1827
1828 If generated mask extends beyond bitmap bounds, replicate bitmap edge colors,
1829 just as SkShader made from SkShader::MakeBitmapShader with
1830 SkShader::kClamp_TileMode set replicates the bitmap's edge color when it samples
1831 outside of its bounds.
1832
1833 @param bitmap SkBitmap containing pixels, dimensions, and format
1834 @param lattice division of bitmap into fixed and variable rectangles
1835 @param dst destination SkRect of image to draw to
1836 @param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
1837 and so on; or nullptr
1838 */
msarettc573a402016-08-02 08:05:56 -07001839 void drawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice, const SkRect& dst,
1840 const SkPaint* paint = nullptr);
Cary Clarkb7da7232017-09-01 13:49:54 -04001841
Cary Clark8a02b0b2017-09-21 12:28:43 -04001842 /** Draw SkImage image stretched proportionally to fit into SkRect dst.
Cary Clarkb7da7232017-09-01 13:49:54 -04001843
1844 Lattice lattice divides image into a rectangular grid.
1845 Each intersection of an even-numbered row and column is fixed; like the corners
1846 of drawBitmapNine(), fixed lattice elements never scale larger than their initial
1847 size and shrink proportionately when all fixed elements exceed the bitmap's
1848 dimension. All other grid elements scale to fill the available space, if any.
1849
1850 Additionally transform draw using clip, SkMatrix, and optional SkPaint paint.
1851
1852 If SkPaint paint is supplied, apply SkColorFilter, color alpha, SkImageFilter,
1853 SkBlendMode, and SkDrawLooper. If bitmap is kAlpha_8_SkColorType, apply SkShader.
1854 If paint contains SkMaskFilter, generate mask from bitmap bounds.
1855
1856 If generated mask extends beyond bitmap bounds, replicate bitmap edge colors,
1857 just as SkShader made from SkShader::MakeBitmapShader with
1858 SkShader::kClamp_TileMode set replicates the bitmap's edge color when it samples
1859 outside of its bounds.
1860
1861 @param image SkImage containing pixels, dimensions, and format
1862 @param lattice division of bitmap into fixed and variable rectangles
1863 @param dst destination SkRect of image to draw to
1864 @param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter,
1865 and so on; or nullptr
1866 */
msarettc573a402016-08-02 08:05:56 -07001867 void drawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst,
1868 const SkPaint* paint = nullptr);
1869
Cary Clarkb7da7232017-09-01 13:49:54 -04001870 /** Draw text, with origin at (x, y), using clip, SkMatrix, and SkPaint paint.
1871
1872 text's meaning depends on SkPaint::TextEncoding; by default, text encoding is
1873 UTF-8.
1874
1875 x and y meaning depends on SkPaint::Align and SkPaint vertical text; by default
1876 text draws left to right, positioning the first glyph's left side bearing at x
1877 and its baseline at y. Text size is affected by SkMatrix and SkPaint text size.
1878
1879 All elements of paint: SkPathEffect, SkRasterizer, SkMaskFilter, SkShader,
1880 SkColorFilter, SkImageFilter, and SkDrawLooper; apply to text. By default, draws
1881 filled 12 point black glyphs.
1882
1883 @param text character code points or glyphs drawn
1884 @param byteLength byte length of text array
1885 @param x start of text on x-axis
1886 @param y start of text on y-axis
1887 @param paint text size, blend, color, and so on, used to draw
reed@android.com8a1c16f2008-12-17 15:59:43 +00001888 */
reedf7430cc2014-12-21 11:38:35 -08001889 void drawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
1890 const SkPaint& paint);
reed@android.com8a1c16f2008-12-17 15:59:43 +00001891
Cary Clarkb7da7232017-09-01 13:49:54 -04001892 /** Draw null terminated string, with origin at (x, y), using clip, SkMatrix, and
1893 SkPaint paint.
1894
1895 string's meaning depends on SkPaint::TextEncoding; by default, string encoding is
1896 UTF-8. Other values of SkPaint::TextEncoding are unlikely to produce the desired
1897 results, since zero bytes may be embedded in the string.
1898
1899 x and y meaning depends on SkPaint::Align and SkPaint vertical text; by default
1900 string draws left to right, positioning the first glyph's left side bearing at x
1901 and its baseline at y. Text size is affected by SkMatrix and SkPaint text size.
1902
1903 All elements of paint: SkPathEffect, SkRasterizer, SkMaskFilter, SkShader,
1904 SkColorFilter, SkImageFilter, and SkDrawLooper; apply to text. By default, draws
1905 filled 12 point black glyphs.
1906
1907 @param string character code points or glyphs drawn,
1908 ending with a char value of zero
1909 @param x start of string on x-axis
1910 @param y start of string on y-axis
1911 @param paint text size, blend, color, and so on, used to draw
Cary Clark2a475ea2017-04-28 15:35:12 -04001912 */
1913 void drawString(const char* string, SkScalar x, SkScalar y, const SkPaint& paint) {
1914 if (!string) {
1915 return;
1916 }
1917 this->drawText(string, strlen(string), x, y, paint);
1918 }
1919
Cary Clarkb7da7232017-09-01 13:49:54 -04001920 /** Draw null terminated string, with origin at (x, y), using clip, SkMatrix, and
1921 SkPaint paint.
1922
1923 string's meaning depends on SkPaint::TextEncoding; by default, string encoding is
1924 UTF-8. Other values of SkPaint::TextEncoding are unlikely to produce the desired
1925 results, since zero bytes may be embedded in the string.
1926
1927 x and y meaning depends on SkPaint::Align and SkPaint vertical text; by default
1928 string draws left to right, positioning the first glyph's left side bearing at x
1929 and its baseline at y. Text size is affected by SkMatrix and SkPaint text size.
1930
1931 All elements of paint: SkPathEffect, SkRasterizer, SkMaskFilter, SkShader,
1932 SkColorFilter, SkImageFilter, and SkDrawLooper; apply to text. By default, draws
1933 filled 12 point black glyphs.
1934
1935 @param string character code points or glyphs drawn,
1936 ending with a char value of zero
1937 @param x start of string on x-axis
1938 @param y start of string on y-axis
1939 @param paint text size, blend, color, and so on, used to draw
Cary Clark2a475ea2017-04-28 15:35:12 -04001940 */
1941 void drawString(const SkString& string, SkScalar x, SkScalar y, const SkPaint& paint);
1942
Cary Clarkb7da7232017-09-01 13:49:54 -04001943 /** Draw each glyph in text with the origin in pos array, using clip, SkMatrix, and
1944 SkPaint paint. The number of entries in pos array must match the number of glyphs
1945 described by byteLength of text.
1946
1947 text's meaning depends on SkPaint::TextEncoding; by default, text encoding is
1948 UTF-8. pos elements' meaning depends on SkPaint::Align and SkPaint vertical text;
1949 by default each glyph's left side bearing is positioned at x and its
1950 baseline is positioned at y. Text size is affected by SkMatrix and
1951 SkPaint text size.
1952
1953 All elements of paint: SkPathEffect, SkRasterizer, SkMaskFilter, SkShader,
1954 SkColorFilter, SkImageFilter, and SkDrawLooper; apply to text. By default, draws
1955 filled 12 point black glyphs.
1956
1957 Layout engines such as Harfbuzz typically position each glyph
1958 rather than using the font's advance widths.
1959
1960 @param text character code points or glyphs drawn
1961 @param byteLength byte length of text array
1962 @param pos array of glyph origins
1963 @param paint text size, blend, color, and so on, used to draw
1964 */
reedf7430cc2014-12-21 11:38:35 -08001965 void drawPosText(const void* text, size_t byteLength, const SkPoint pos[],
1966 const SkPaint& paint);
reed@google.com4b226022011-01-11 18:32:13 +00001967
Cary Clarkb7da7232017-09-01 13:49:54 -04001968 /** Draw each glyph in text with its (x, y) origin composed from xpos array and
1969 constY, using clip, SkMatrix, and SkPaint paint. The number of entries in xpos array
1970 must match the number of glyphs described by byteLength of text.
1971
1972 text's meaning depends on SkPaint::TextEncoding; by default, text encoding is
1973 UTF-8. xpos elements' meaning depends on SkPaint::Align and SkPaint vertical text;
1974 by default each glyph's left side bearing is positioned at an xpos element and
1975 its baseline is positioned at constY. Text size is affected by SkMatrix and
1976 SkPaint text size.
1977
1978 All elements of paint: SkPathEffect, SkRasterizer, SkMaskFilter, SkShader,
1979 SkColorFilter, SkImageFilter, and SkDrawLooper; apply to text. By default, draws
1980 filled 12 point black glyphs.
1981
1982 Layout engines such as Harfbuzz typically position each glyph
1983 rather than using the font's advance widths if all glyphs share the same
1984 baseline.
1985
1986 @param text character code points or glyphs drawn
1987 @param byteLength byte length of text array
1988 @param xpos array of x positions, used to position each glyph
1989 @param constY shared y coordinate for all of x positions
1990 @param paint text size, blend, color, and so on, used to draw
1991 */
reedf7430cc2014-12-21 11:38:35 -08001992 void drawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], SkScalar constY,
1993 const SkPaint& paint);
reed@google.com4b226022011-01-11 18:32:13 +00001994
Cary Clarkb7da7232017-09-01 13:49:54 -04001995 /** Draw text on SkPath path, using clip, SkMatrix, and SkPaint paint.
1996
1997 Origin of text is at distance hOffset along the path, offset by a perpendicular
1998 vector of length vOffset. If the path section corresponding the glyph advance is
1999 curved, the glyph is drawn curved to match; control points in the glyph are
2000 mapped to projected points parallel to the path. If the text's advance is larger
2001 than the path length, the excess text is clipped.
2002
2003 text's meaning depends on SkPaint::TextEncoding; by default, text encoding is
2004 UTF-8. Origin meaning depends on SkPaint::Align and SkPaint vertical text; by
2005 default text positions the first glyph's left side bearing at origin x and its
2006 baseline at origin y. Text size is affected by SkMatrix and SkPaint text size.
2007
2008 All elements of paint: SkPathEffect, SkRasterizer, SkMaskFilter, SkShader,
2009 SkColorFilter, SkImageFilter, and SkDrawLooper; apply to text. By default, draws
2010 filled 12 point black glyphs.
2011
2012 @param text character code points or glyphs drawn
2013 @param byteLength byte length of text array
2014 @param path SkPath providing text baseline
2015 @param hOffset distance along path to offset origin
2016 @param vOffset offset of text above (if negative) or below (if positive) the path
2017 @param paint text size, blend, color, and so on, used to draw
reed@android.com8a1c16f2008-12-17 15:59:43 +00002018 */
reedf7430cc2014-12-21 11:38:35 -08002019 void drawTextOnPathHV(const void* text, size_t byteLength, const SkPath& path, SkScalar hOffset,
reed@android.com8a1c16f2008-12-17 15:59:43 +00002020 SkScalar vOffset, const SkPaint& paint);
2021
Cary Clarkb7da7232017-09-01 13:49:54 -04002022 /** Draw text on SkPath path, using clip, SkMatrix, and SkPaint paint.
2023
2024 Origin of text is at beginning of path offset by matrix, if provided, before it
2025 is mapped to path. If the path section corresponding the glyph advance is
2026 curved, the glyph is drawn curved to match; control points in the glyph are
2027 mapped to projected points parallel to the path. If the text's advance is larger
2028 than the path length, the excess text is clipped.
2029
2030 text's meaning depends on SkPaint::TextEncoding; by default, text encoding is
2031 UTF-8. Origin meaning depends on SkPaint::Align and SkPaint vertical text; by
2032 default text positions the first glyph's left side bearing at origin x and its
2033 baseline at origin y. Text size is affected by SkMatrix and SkPaint text size.
2034
2035 All elements of paint: SkPathEffect, SkRasterizer, SkMaskFilter, SkShader,
2036 SkColorFilter, SkImageFilter, and SkDrawLooper; apply to text. By default, draws
2037 filled 12 point black glyphs.
2038
2039 @param text character code points or glyphs drawn
2040 @param byteLength byte length of text array
2041 @param path SkPath providing text baseline
2042 @param matrix transform of glyphs before mapping to path; may be nullptr
2043 to use identity SkMatrix
2044 @param paint text size, blend, color, and so on, used to draw
2045 */
reedf7430cc2014-12-21 11:38:35 -08002046 void drawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
2047 const SkMatrix* matrix, const SkPaint& paint);
reed@android.com8a1c16f2008-12-17 15:59:43 +00002048
Cary Clarkb7da7232017-09-01 13:49:54 -04002049 /** Draw text, transforming each glyph by the corresponding SkRSXform,
2050 using clip, SkMatrix, and SkPaint paint.
2051
2052 SkRSXform array specifies a separate square scale, rotation, and translation for
2053 each glyph.
2054
2055 Optional SkRect cullRect is a conservative bounds of text, taking into account
2056 SkRSXform and paint. If cullRect is outside of clip, canvas can skip drawing.
2057
2058 All elements of paint: SkPathEffect, SkRasterizer, SkMaskFilter, SkShader,
2059 SkColorFilter, SkImageFilter, and SkDrawLooper; apply to text. By default, draws
2060 filled 12 point black glyphs.
2061
2062 @param text character code points or glyphs drawn
2063 @param byteLength byte length of text array
2064 @param xform SkRSXform rotates, scales, and translates each glyph individually
2065 @param cullRect SkRect bounds of text for efficient clipping; or nullptr
2066 @param paint text size, blend, color, and so on, used to draw
2067 */
Cary Clark0418a882017-05-10 09:07:42 -04002068 void drawTextRSXform(const void* text, size_t byteLength, const SkRSXform xform[],
reed45561a02016-07-07 12:47:17 -07002069 const SkRect* cullRect, const SkPaint& paint);
2070
Cary Clarkb7da7232017-09-01 13:49:54 -04002071 /** Draw SkTextBlob blob at (x, y), using clip, SkMatrix, and SkPaint paint.
2072
2073 blob contains glyphs, their positions, and paint attributes specific to text:
2074 SkTypeface, SkPaint text size, SkPaint text scale x, SkPaint text skew x,
2075 SkPaint::Align, SkPaint::Hinting, anti-alias, SkPaint fake bold,
2076 font embedded bitmaps, full hinting spacing, lcd text, linear text,
2077 subpixel text, and SkPaint vertical text.
2078
2079 Elements of paint: SkPathEffect, SkRasterizer, SkMaskFilter, SkShader, SkColorFilter,
2080 SkImageFilter, and SkDrawLooper; apply to blob.
2081
Cary Clark8a02b0b2017-09-21 12:28:43 -04002082 @param blob glyphs, positions, and their paints' text size, typeface, and so on
Cary Clarkb7da7232017-09-01 13:49:54 -04002083 @param x horizontal offset applied to blob
2084 @param y vertical offset applied to blob
2085 @param paint blend, color, stroking, and so on, used to draw
fmalita00d5c2c2014-08-21 08:53:26 -07002086 */
2087 void drawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPaint& paint);
Cary Clarkb7da7232017-09-01 13:49:54 -04002088
2089 /** Draw SkTextBlob blob at (x, y), using clip, SkMatrix, and SkPaint paint.
2090
2091 blob contains glyphs, their positions, and paint attributes specific to text:
2092 SkTypeface, SkPaint text size, SkPaint text scale x, SkPaint text skew x,
2093 SkPaint::Align, SkPaint::Hinting, anti-alias, SkPaint fake bold,
2094 font embedded bitmaps, full hinting spacing, lcd text, linear text,
2095 subpixel text, and SkPaint vertical text.
2096
2097 Elements of paint: SkPathEffect, SkRasterizer, SkMaskFilter, SkShader, SkColorFilter,
2098 SkImageFilter, and SkDrawLooper; apply to blob.
2099
Cary Clark8a02b0b2017-09-21 12:28:43 -04002100 @param blob glyphs, positions, and their paints' text size, typeface, and so on
Cary Clarkb7da7232017-09-01 13:49:54 -04002101 @param x horizontal offset applied to blob
2102 @param y vertical offset applied to blob
2103 @param paint blend, color, stroking, and so on, used to draw
2104 */
reed2ab90572016-08-10 14:16:41 -07002105 void drawTextBlob(const sk_sp<SkTextBlob>& blob, SkScalar x, SkScalar y, const SkPaint& paint) {
2106 this->drawTextBlob(blob.get(), x, y, paint);
2107 }
fmalita00d5c2c2014-08-21 08:53:26 -07002108
Cary Clarkb7da7232017-09-01 13:49:54 -04002109 /** Draw picture picture, using clip and SkMatrix.
2110 Clip and SkMatrix are unchanged by picture contents, as if
2111 save() was called before and restore() was called after drawPicture().
2112
2113 Picture records a series of draw commands for later playback.
2114
2115 @param picture recorded drawing commands to play
reed@android.com8a1c16f2008-12-17 15:59:43 +00002116 */
reed1c2c4412015-04-30 13:09:24 -07002117 void drawPicture(const SkPicture* picture) {
Ben Wagnera93a14a2017-08-28 10:34:05 -04002118 this->drawPicture(picture, nullptr, nullptr);
reed1c2c4412015-04-30 13:09:24 -07002119 }
Cary Clarkb7da7232017-09-01 13:49:54 -04002120
2121 /** Draw picture picture, using clip and SkMatrix.
2122 Clip and SkMatrix are unchanged by picture contents, as if
2123 save() was called before and restore() was called after drawPicture().
2124
2125 Picture records a series of draw commands for later playback.
2126
2127 @param picture recorded drawing commands to play
2128 */
reedca2622b2016-03-18 07:25:55 -07002129 void drawPicture(const sk_sp<SkPicture>& picture) {
reedf8053da2016-03-17 08:14:57 -07002130 this->drawPicture(picture.get());
2131 }
robertphillips9b14f262014-06-04 05:40:44 -07002132
Cary Clarkb7da7232017-09-01 13:49:54 -04002133 /** Draw picture picture, using clip and SkMatrix; transforming picture with
2134 SkMatrix matrix, if provided; and use SkPaint paint color alpha, SkColorFilter,
2135 SkImageFilter, and SkBlendMode, if provided.
2136
2137 matrix transformation is equivalent to: save(), concat(), drawPicture(), restore().
2138 paint use is equivalent to: saveLayer(), drawPicture(), restore().
2139
2140 @param picture recorded drawing commands to play
2141 @param matrix SkMatrix to rotate, scale, translate, and so on; may be nullptr
2142 @param paint SkPaint to apply transparency, filtering, and so on; may be nullptr
2143 */
Cary Clark0418a882017-05-10 09:07:42 -04002144 void drawPicture(const SkPicture* picture, const SkMatrix* matrix, const SkPaint* paint);
Cary Clarkb7da7232017-09-01 13:49:54 -04002145
2146 /** Draw picture picture, using clip and SkMatrix; transforming picture with
2147 SkMatrix matrix, if provided; and use SkPaint paint color alpha, SkColorFilter,
2148 SkImageFilter, and SkBlendMode, if provided.
2149
2150 matrix transformation is equivalent to: save(), concat(), drawPicture(), restore().
2151 paint use is equivalent to: saveLayer(), drawPicture(), restore().
2152
2153 @param picture recorded drawing commands to play
2154 @param matrix SkMatrix to rotate, scale, translate, and so on; may be nullptr
2155 @param paint SkPaint to apply transparency, filtering, and so on; may be nullptr
2156 */
reedca2622b2016-03-18 07:25:55 -07002157 void drawPicture(const sk_sp<SkPicture>& picture, const SkMatrix* matrix, const SkPaint* paint) {
reedf8053da2016-03-17 08:14:57 -07002158 this->drawPicture(picture.get(), matrix, paint);
2159 }
reedd5fa1a42014-08-09 11:08:05 -07002160
Cary Clarkb7da7232017-09-01 13:49:54 -04002161 /** Draw vertices vertices, a triangle mesh, using clip and SkMatrix.
2162 If vertices texs and vertices colors are defined in vertices, and SkPaint paint
2163 contains SkShader, SkBlendMode mode combines vertices colors with SkShader.
Brian Salomon199fb872017-02-06 09:41:10 -05002164
Cary Clarkb7da7232017-09-01 13:49:54 -04002165 @param vertices triangle mesh to draw
2166 @param mode combines vertices colors with SkShader, if both are present
2167 @param paint specifies the SkShader, used as vertices texture; may be nullptr
2168 */
Mike Reede88a1cb2017-03-17 09:50:46 -04002169 void drawVertices(const SkVertices* vertices, SkBlendMode mode, const SkPaint& paint);
Cary Clarkb7da7232017-09-01 13:49:54 -04002170
2171 /** Draw vertices vertices, a triangle mesh, using clip and SkMatrix.
2172 If vertices texs and vertices colors are defined in vertices, and SkPaint paint
2173 contains SkShader, SkBlendMode mode combines vertices colors with SkShader.
2174
2175 @param vertices triangle mesh to draw
2176 @param mode combines vertices colors with SkShader, if both are present
2177 @param paint specifies the SkShader, used as vertices texture, may be nullptr
2178 */
Mike Reede88a1cb2017-03-17 09:50:46 -04002179 void drawVertices(const sk_sp<SkVertices>& vertices, SkBlendMode mode, const SkPaint& paint);
Mike Reed7d954ad2016-10-28 15:42:34 -04002180
Cary Clarkb7da7232017-09-01 13:49:54 -04002181 /** Draws a Coons patch: the interpolation of four cubics with shared corners,
2182 associating a color, and optionally a texture coordinate, with each corner.
mtklein6cfa73a2014-08-13 13:33:49 -07002183
Cary Clarkb7da7232017-09-01 13:49:54 -04002184 The Coons patch uses clip and SkMatrix, SkPaint paint's SkShader, SkColorFilter,
2185 color alpha, SkImageFilter, and SkBlendMode. If SkShader is provided it is treated
2186 as the Coons patch texture; SkBlendMode mode combines color colors and SkShader if
2187 both are provided.
2188
2189 SkPoint array cubics specifies four cubics starting at the top left corner,
2190 in clockwise order, sharing every fourth point. The last cubic ends at the
2191 first point.
2192
2193 Color array color associates colors with corners in top left, top right,
2194 bottom right, bottom left order.
2195
2196 If paint contains SkShader, SkPoint array texCoords maps SkShader as texture to
2197 corners in top left, top right, bottom right, bottom left order.
2198
2199 @param cubics SkPath cubic array, sharing common points
Cary Clark8a02b0b2017-09-21 12:28:43 -04002200 @param colors color array, one for each corner
Cary Clarkb7da7232017-09-01 13:49:54 -04002201 @param texCoords SkPoint array of texture coordinates, mapping SkShader to corners;
2202 may be nullptr
2203 @param mode SkBlendMode for colors, and for SkShader if paint has one
2204 @param paint SkShader, SkColorFilter, SkBlendMode, used to draw
2205 */
dandovb3c9d1c2014-08-12 08:34:29 -07002206 void drawPatch(const SkPoint cubics[12], const SkColor colors[4],
Mike Reed7d954ad2016-10-28 15:42:34 -04002207 const SkPoint texCoords[4], SkBlendMode mode, const SkPaint& paint);
Cary Clarkb7da7232017-09-01 13:49:54 -04002208
2209 /** Draws cubic Coons patch: the interpolation of four cubics with shared corners,
2210 associating a color, and optionally a texture coordinate, with each corner.
2211
2212 The Coons patch uses clip and SkMatrix, SkPaint paint's SkShader, SkColorFilter,
2213 color alpha, SkImageFilter, and SkBlendMode. If SkShader is provided it is treated
2214 as the Coons patch texture; SkBlendMode mode combines color colors and SkShader if
2215 both are provided.
2216
2217 SkPoint array cubics specifies four cubics starting at the top left corner,
2218 in clockwise order, sharing every fourth point. The last cubic ends at the
2219 first point.
2220
2221 Color array color associates colors with corners in top left, top right,
2222 bottom right, bottom left order.
2223
2224 If paint contains SkShader, SkPoint array texCoords maps SkShader as texture to
2225 corners in top left, top right, bottom right, bottom left order.
2226
2227 @param cubics SkPath cubic array, sharing common points
Cary Clark8a02b0b2017-09-21 12:28:43 -04002228 @param colors color array, one for each corner
Cary Clarkb7da7232017-09-01 13:49:54 -04002229 @param texCoords SkPoint array of texture coordinates, mapping SkShader to corners;
2230 may be nullptr
2231 @param paint SkShader, SkColorFilter, SkBlendMode, used to draw
2232 */
Mike Reed7d954ad2016-10-28 15:42:34 -04002233 void drawPatch(const SkPoint cubics[12], const SkColor colors[4],
2234 const SkPoint texCoords[4], const SkPaint& paint) {
2235 this->drawPatch(cubics, colors, texCoords, SkBlendMode::kModulate, paint);
2236 }
2237
Cary Clarkb7da7232017-09-01 13:49:54 -04002238 /** Draw a set of sprites from atlas, using clip, SkMatrix, and optional SkPaint paint.
2239 paint uses anti-alias, color alpha, SkColorFilter, SkImageFilter, and SkBlendMode
2240 to draw, if present. For each entry in the array, SkRect tex locates sprite in
2241 atlas, and SkRSXform xform transforms it into destination space.
2242
2243 xform, text, and colors if present, must contain count entries.
2244 Optional colors are applied for each sprite using SkBlendMode.
2245 Optional cullRect is a conservative bounds of all transformed sprites.
2246 If cullRect is outside of clip, canvas can skip drawing.
2247
2248 @param atlas SkImage containing sprites
2249 @param xform SkRSXform mappings for sprites in atlas
2250 @param tex SkRect locations of sprites in atlas
Cary Clark8a02b0b2017-09-21 12:28:43 -04002251 @param colors one per sprite, blended with sprite using SkBlendMode; may be nullptr
Cary Clarkb7da7232017-09-01 13:49:54 -04002252 @param count number of sprites to draw
2253 @param mode SkBlendMode combining colors and sprites
Cary Clark8a02b0b2017-09-21 12:28:43 -04002254 @param cullRect bounds of transformed sprites for efficient clipping; may be nullptr
2255 @param paint SkColorFilter, SkImageFilter, SkBlendMode, and so on; may be nullptr
Cary Clarkb7da7232017-09-01 13:49:54 -04002256 */
reed71c3c762015-06-24 10:29:17 -07002257 void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[],
Cary Clark0418a882017-05-10 09:07:42 -04002258 const SkColor colors[], int count, SkBlendMode mode, const SkRect* cullRect,
reed71c3c762015-06-24 10:29:17 -07002259 const SkPaint* paint);
Cary Clarkb7da7232017-09-01 13:49:54 -04002260
2261 /** Draw a set of sprites from atlas, using clip, SkMatrix, and optional SkPaint paint.
2262 paint uses anti-alias, color alpha, SkColorFilter, SkImageFilter, and SkBlendMode
2263 to draw, if present. For each entry in the array, SkRect tex locates sprite in
2264 atlas, and SkRSXform xform transforms it into destination space.
2265
2266 xform, text, and colors if present, must contain count entries.
2267 Optional colors is applied for each sprite using SkBlendMode.
2268 Optional cullRect is a conservative bounds of all transformed sprites.
2269 If cullRect is outside of clip, canvas can skip drawing.
2270
2271 @param atlas SkImage containing sprites
2272 @param xform SkRSXform mappings for sprites in atlas
2273 @param tex SkRect locations of sprites in atlas
Cary Clark8a02b0b2017-09-21 12:28:43 -04002274 @param colors one per sprite, blended with sprite using SkBlendMode; may be nullptr
Cary Clarkb7da7232017-09-01 13:49:54 -04002275 @param count number of sprites to draw
2276 @param mode SkBlendMode combining colors and sprites
Cary Clark8a02b0b2017-09-21 12:28:43 -04002277 @param cullRect bounds of transformed sprites for efficient clipping; may be nullptr
2278 @param paint SkColorFilter, SkImageFilter, SkBlendMode, and so on; may be nullptr
Cary Clarkb7da7232017-09-01 13:49:54 -04002279 */
Mike Reed7d954ad2016-10-28 15:42:34 -04002280 void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[],
2281 const SkColor colors[], int count, SkBlendMode mode, const SkRect* cullRect,
2282 const SkPaint* paint) {
2283 this->drawAtlas(atlas.get(), xform, tex, colors, count, mode, cullRect, paint);
2284 }
Cary Clarkb7da7232017-09-01 13:49:54 -04002285
2286 /** Draw a set of sprites from atlas, using clip, SkMatrix, and optional SkPaint paint.
2287 paint uses anti-alias, color alpha, SkColorFilter, SkImageFilter, and SkBlendMode
2288 to draw, if present. For each entry in the array, SkRect tex locates sprite in
2289 atlas, and SkRSXform xform transforms it into destination space.
2290
2291 xform and text must contain count entries.
2292 Optional cullRect is a conservative bounds of all transformed sprites.
2293 If cullRect is outside of clip, canvas can skip drawing.
2294
2295 @param atlas SkImage containing sprites
2296 @param xform SkRSXform mappings for sprites in atlas
2297 @param tex SkRect locations of sprites in atlas
2298 @param count number of sprites to draw
Cary Clark8a02b0b2017-09-21 12:28:43 -04002299 @param cullRect bounds of transformed sprites for efficient clipping; may be nullptr
2300 @param paint SkColorFilter, SkImageFilter, SkBlendMode, and so on; may be nullptr
Cary Clarkb7da7232017-09-01 13:49:54 -04002301 */
reed71c3c762015-06-24 10:29:17 -07002302 void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], int count,
2303 const SkRect* cullRect, const SkPaint* paint) {
Mike Reed7d954ad2016-10-28 15:42:34 -04002304 this->drawAtlas(atlas, xform, tex, nullptr, count, SkBlendMode::kDst, cullRect, paint);
2305 }
Cary Clarkb7da7232017-09-01 13:49:54 -04002306
2307 /** Draw a set of sprites from atlas, using clip, SkMatrix, and optional SkPaint paint.
2308 paint uses anti-alias, color alpha, SkColorFilter, SkImageFilter, and SkBlendMode
2309 to draw, if present. For each entry in the array, SkRect tex locates sprite in
2310 atlas, and SkRSXform xform transforms it into destination space.
2311
2312 xform and text must contain count entries.
2313 Optional cullRect is a conservative bounds of all transformed sprites.
2314 If cullRect is outside of clip, canvas can skip drawing.
2315
2316 @param atlas SkImage containing sprites
2317 @param xform SkRSXform mappings for sprites in atlas
2318 @param tex SkRect locations of sprites in atlas
2319 @param count number of sprites to draw
Cary Clark8a02b0b2017-09-21 12:28:43 -04002320 @param cullRect bounds of transformed sprites for efficient clipping; may be nullptr
2321 @param paint SkColorFilter, SkImageFilter, SkBlendMode, and so on; may be nullptr
Cary Clarkb7da7232017-09-01 13:49:54 -04002322 */
Mike Reed7d954ad2016-10-28 15:42:34 -04002323 void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[],
2324 int count, const SkRect* cullRect, const SkPaint* paint) {
2325 this->drawAtlas(atlas.get(), xform, tex, nullptr, count, SkBlendMode::kDst,
2326 cullRect, paint);
2327 }
2328
Cary Clarkb7da7232017-09-01 13:49:54 -04002329 /** Draw SkDrawable drawable using clip and SkMatrix, concatenated with
2330 optional matrix.
2331
2332 If SkCanvas has an asynchronous implementation, as is the case
2333 when it is recording into picture, then drawable will be referenced,
2334 so that SkDrawable::draw() can be called when the operation is finalized. To force
2335 immediate drawing, call SkDrawable::draw() instead.
2336
2337 @param drawable custom struct encapsulating drawing commands
2338 @param matrix transformation applied to drawing; may be nullptr
2339 */
Ben Wagnera93a14a2017-08-28 10:34:05 -04002340 void drawDrawable(SkDrawable* drawable, const SkMatrix* matrix = nullptr);
Cary Clarkb7da7232017-09-01 13:49:54 -04002341
2342 /** Draw SkDrawable drawable using clip and SkMatrix, offset by (x, y).
2343
2344 If SkCanvas has an asynchronous implementation, as is the case
2345 when it is recording into picture, then drawable will be referenced,
2346 so that SkDrawable::draw() can be called when the operation is finalized. To force
2347 immediate drawing, call SkDrawable::draw() instead.
2348
2349 @param drawable custom struct encapsulating drawing commands
2350 @param x offset into SkCanvas writable pixels in x
2351 @param y offset into SkCanvas writable pixels in y
2352 */
Cary Clark0418a882017-05-10 09:07:42 -04002353 void drawDrawable(SkDrawable* drawable, SkScalar x, SkScalar y);
reed6a070dc2014-11-11 19:36:09 -08002354
Cary Clarkb7da7232017-09-01 13:49:54 -04002355 /** Associate SkRect on SkCanvas when an annotation; a key-value pair, where the key is
2356 a null-terminated utf8 string, and optional value is stored as data.
2357
2358 Only some canvas implementations, such as recording to picture, or drawing to
2359 document pdf, use annotations.
2360
2361 @param rect SkRect extent of canvas to annotate
2362 @param key string used for lookup
2363 @param value data holding value stored in annotation
2364 */
Cary Clark0418a882017-05-10 09:07:42 -04002365 void drawAnnotation(const SkRect& rect, const char key[], SkData* value);
Cary Clarkb7da7232017-09-01 13:49:54 -04002366
2367 /** Associate SkRect on SkCanvas when an annotation; a key-value pair, where the key is
2368 a null-terminated utf8 string, and optional value is stored as data.
2369
2370 Only some canvas implementations, such as recording to picture, or drawing to
2371 document pdf, use annotations.
2372
2373 @param rect SkRect extent of canvas to annotate
2374 @param key string used for lookup
2375 @param value data holding value stored in annotation
2376 */
mtklein0fba3b92016-04-01 04:55:51 -07002377 void drawAnnotation(const SkRect& rect, const char key[], const sk_sp<SkData>& value) {
2378 this->drawAnnotation(rect, key, value.get());
2379 }
reedf70b5312016-03-04 16:36:20 -08002380
reed@android.com8a1c16f2008-12-17 15:59:43 +00002381 //////////////////////////////////////////////////////////////////////////
reed@google.com4b226022011-01-11 18:32:13 +00002382
fmalita53d9f1c2016-01-25 06:23:54 -08002383#ifdef SK_SUPPORT_LEGACY_DRAWFILTER
Cary Clarkb7da7232017-09-01 13:49:54 -04002384 /** Legacy call to be deprecated.
reed@android.com8a1c16f2008-12-17 15:59:43 +00002385 */
2386 SkDrawFilter* getDrawFilter() const;
reed@google.com4b226022011-01-11 18:32:13 +00002387
Cary Clarkb7da7232017-09-01 13:49:54 -04002388 /** Legacy call to be deprecated.
reed@android.com8a1c16f2008-12-17 15:59:43 +00002389 */
2390 virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter);
fmalita77650002016-01-21 18:47:11 -08002391#endif
reed@android.com8a1c16f2008-12-17 15:59:43 +00002392
Cary Clarkb7da7232017-09-01 13:49:54 -04002393 /** Returns true if clip is empty; that is, nothing will draw.
2394
2395 May do work when called; it should not be called
2396 more often than needed. However, once called, subsequent calls perform no
2397 work until clip changes.
2398
2399 @return true if clip is empty
2400 */
robertphillips@google.com8f90a892014-02-28 18:19:39 +00002401 virtual bool isClipEmpty() const;
reed@google.com754de5f2014-02-24 19:38:20 +00002402
Cary Clarkb7da7232017-09-01 13:49:54 -04002403 /** Returns true if clip is SkRect and not empty.
2404 Returns false if the clip is empty, or if it is not SkRect.
2405
2406 @return true if clip is SkRect and not empty
2407 */
commit-bot@chromium.org5c70cdc2014-03-08 03:57:19 +00002408 virtual bool isClipRect() const;
2409
Cary Clarkb7da7232017-09-01 13:49:54 -04002410 /** Returns SkMatrix.
2411 This does not account for translation by SkBaseDevice or SkSurface.
2412
2413 @return SkMatrix in SkCanvas
reed@android.com8a1c16f2008-12-17 15:59:43 +00002414 */
junov@chromium.orga907ac32012-02-24 21:54:07 +00002415 const SkMatrix& getTotalMatrix() const;
reed@android.com8a1c16f2008-12-17 15:59:43 +00002416
reed@android.com8a1c16f2008-12-17 15:59:43 +00002417 ///////////////////////////////////////////////////////////////////////////
2418
robertphillips36736a22016-04-23 08:26:43 -07002419 // don't call
Brian Osman11052242016-10-27 14:47:55 -04002420 GrRenderTargetContext* internal_private_accessTopLayerRenderTargetContext();
robertphillips36736a22016-04-23 08:26:43 -07002421
2422 // don't call
2423 static void Internal_Private_SetIgnoreSaveLayerBounds(bool);
2424 static bool Internal_Private_GetIgnoreSaveLayerBounds();
2425 static void Internal_Private_SetTreatSpriteAsBitmap(bool);
2426 static bool Internal_Private_GetTreatSpriteAsBitmap();
2427
2428 // TEMP helpers until we switch virtual over to const& for src-rect
2429 void legacy_drawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
2430 const SkPaint* paint,
2431 SrcRectConstraint constraint = kStrict_SrcRectConstraint);
2432 void legacy_drawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst,
2433 const SkPaint* paint,
2434 SrcRectConstraint constraint = kStrict_SrcRectConstraint);
2435
Mike Reeda1361362017-03-07 09:37:29 -05002436 /**
2437 * Returns the global clip as a region. If the clip contains AA, then only the bounds
2438 * of the clip may be returned.
2439 */
Cary Clark0418a882017-05-10 09:07:42 -04002440 void temporary_internal_getRgnClip(SkRegion* region);
Mike Reed3726a4a2017-01-19 11:36:41 -05002441
Mike Reed4204da22017-05-17 08:53:36 -04002442 void private_draw_shadow_rec(const SkPath&, const SkDrawShadowRec&);
2443
robertphillipsda2cd8b2016-04-21 11:05:32 -07002444protected:
reed@google.com76f10a32014-02-05 15:32:21 +00002445 // default impl defers to getDevice()->newSurface(info)
Cary Clark0418a882017-05-10 09:07:42 -04002446 virtual sk_sp<SkSurface> onNewSurface(const SkImageInfo& info, const SkSurfaceProps& props);
reed@google.com76f10a32014-02-05 15:32:21 +00002447
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +00002448 // default impl defers to its device
Cary Clark0418a882017-05-10 09:07:42 -04002449 virtual bool onPeekPixels(SkPixmap* pixmap);
2450 virtual bool onAccessTopLayerPixels(SkPixmap* pixmap);
reedea5a6512016-07-07 16:44:27 -07002451 virtual SkImageInfo onImageInfo() const;
Cary Clark0418a882017-05-10 09:07:42 -04002452 virtual bool onGetProps(SkSurfaceProps* props) const;
reedea5a6512016-07-07 16:44:27 -07002453 virtual void onFlush();
commit-bot@chromium.orgc3bd8af2014-02-13 17:14:46 +00002454
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +00002455 // Subclass save/restore notifiers.
2456 // Overriders should call the corresponding INHERITED method up the inheritance chain.
reed4960eee2015-12-18 07:09:18 -08002457 // getSaveLayerStrategy()'s return value may suppress full layer allocation.
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +00002458 enum SaveLayerStrategy {
2459 kFullLayer_SaveLayerStrategy,
reed4960eee2015-12-18 07:09:18 -08002460 kNoLayer_SaveLayerStrategy,
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +00002461 };
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +00002462
fmalita6ca763f2014-06-17 13:52:18 -07002463 virtual void willSave() {}
reed4960eee2015-12-18 07:09:18 -08002464 // Overriders should call the corresponding INHERITED method up the inheritance chain.
Cary Clark0418a882017-05-10 09:07:42 -04002465 virtual SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec& ) {
reed4960eee2015-12-18 07:09:18 -08002466 return kFullLayer_SaveLayerStrategy;
2467 }
commit-bot@chromium.orgfc6dfba2014-05-14 13:13:44 +00002468 virtual void willRestore() {}
mtklein6cfa73a2014-08-13 13:33:49 -07002469 virtual void didRestore() {}
Cary Clark0418a882017-05-10 09:07:42 -04002470 virtual void didConcat(const SkMatrix& ) {}
2471 virtual void didSetMatrix(const SkMatrix& ) {}
mtkleincbdf0072016-08-19 09:05:27 -07002472 virtual void didTranslate(SkScalar dx, SkScalar dy) {
2473 this->didConcat(SkMatrix::MakeTrans(dx, dy));
2474 }
vjiaoblack95302da2016-07-21 10:25:54 -07002475
Mike Reed42e8c532017-01-23 14:09:13 -05002476 virtual SkRect onGetLocalClipBounds() const;
2477 virtual SkIRect onGetDeviceClipBounds() const;
2478
2479
Cary Clark0418a882017-05-10 09:07:42 -04002480 virtual void onDrawAnnotation(const SkRect& rect, const char key[], SkData* value);
2481 virtual void onDrawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint);
commit-bot@chromium.orged9806f2014-02-21 02:32:36 +00002482
reed@google.come0d9ce82014-04-23 04:00:17 +00002483 virtual void onDrawText(const void* text, size_t byteLength, SkScalar x,
2484 SkScalar y, const SkPaint& paint);
skia.committer@gmail.comb0430d02014-04-24 03:05:07 +00002485
reed@google.come0d9ce82014-04-23 04:00:17 +00002486 virtual void onDrawPosText(const void* text, size_t byteLength,
2487 const SkPoint pos[], const SkPaint& paint);
skia.committer@gmail.comb0430d02014-04-24 03:05:07 +00002488
reed@google.come0d9ce82014-04-23 04:00:17 +00002489 virtual void onDrawPosTextH(const void* text, size_t byteLength,
2490 const SkScalar xpos[], SkScalar constY,
2491 const SkPaint& paint);
skia.committer@gmail.comb0430d02014-04-24 03:05:07 +00002492
reed@google.come0d9ce82014-04-23 04:00:17 +00002493 virtual void onDrawTextOnPath(const void* text, size_t byteLength,
2494 const SkPath& path, const SkMatrix* matrix,
2495 const SkPaint& paint);
Cary Clark0418a882017-05-10 09:07:42 -04002496 virtual void onDrawTextRSXform(const void* text, size_t byteLength, const SkRSXform xform[],
reed45561a02016-07-07 12:47:17 -07002497 const SkRect* cullRect, const SkPaint& paint);
mtklein6cfa73a2014-08-13 13:33:49 -07002498
fmalita00d5c2c2014-08-21 08:53:26 -07002499 virtual void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
2500 const SkPaint& paint);
2501
dandovb3c9d1c2014-08-12 08:34:29 -07002502 virtual void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
Cary Clark0418a882017-05-10 09:07:42 -04002503 const SkPoint texCoords[4], SkBlendMode mode, const SkPaint& paint);
reed@google.come0d9ce82014-04-23 04:00:17 +00002504
Cary Clark0418a882017-05-10 09:07:42 -04002505 virtual void onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix);
reed6a070dc2014-11-11 19:36:09 -08002506
Cary Clark0418a882017-05-10 09:07:42 -04002507 virtual void onDrawPaint(const SkPaint& paint);
2508 virtual void onDrawRect(const SkRect& rect, const SkPaint& paint);
msarett44df6512016-08-25 13:54:30 -07002509 virtual void onDrawRegion(const SkRegion& region, const SkPaint& paint);
Cary Clark0418a882017-05-10 09:07:42 -04002510 virtual void onDrawOval(const SkRect& rect, const SkPaint& paint);
2511 virtual void onDrawArc(const SkRect& rect, SkScalar startAngle, SkScalar sweepAngle,
2512 bool useCenter, const SkPaint& paint);
2513 virtual void onDrawRRect(const SkRRect& rrect, const SkPaint& paint);
2514 virtual void onDrawPoints(PointMode mode, size_t count, const SkPoint pts[],
2515 const SkPaint& paint);
2516 virtual void onDrawVerticesObject(const SkVertices* vertices, SkBlendMode mode,
2517 const SkPaint& paint);
2518 virtual void onDrawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect rect[],
2519 const SkColor colors[], int count, SkBlendMode mode,
2520 const SkRect* cull, const SkPaint* paint);
2521 virtual void onDrawPath(const SkPath& path, const SkPaint& paint);
2522 virtual void onDrawImage(const SkImage* image, SkScalar dx, SkScalar dy, const SkPaint* paint);
2523 virtual void onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
2524 const SkPaint* paint, SrcRectConstraint constraint);
2525 virtual void onDrawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst,
2526 const SkPaint* paint);
2527 virtual void onDrawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst,
2528 const SkPaint* paint);
reed4c21dc52015-06-25 12:32:03 -07002529
Cary Clark0418a882017-05-10 09:07:42 -04002530 virtual void onDrawBitmap(const SkBitmap& bitmap, SkScalar dx, SkScalar dy,
2531 const SkPaint* paint);
2532 virtual void onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst,
2533 const SkPaint* paint, SrcRectConstraint constraint);
2534 virtual void onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst,
2535 const SkPaint* paint);
2536 virtual void onDrawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice,
2537 const SkRect& dst, const SkPaint* paint);
Mike Reed4204da22017-05-17 08:53:36 -04002538 virtual void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&);
reed41af9662015-01-05 07:49:08 -08002539
robertphillips@google.com8f90a892014-02-28 18:19:39 +00002540 enum ClipEdgeStyle {
2541 kHard_ClipEdgeStyle,
2542 kSoft_ClipEdgeStyle
2543 };
2544
Cary Clark0418a882017-05-10 09:07:42 -04002545 virtual void onClipRect(const SkRect& rect, SkClipOp op, ClipEdgeStyle edgeStyle);
2546 virtual void onClipRRect(const SkRRect& rrect, SkClipOp op, ClipEdgeStyle edgeStyle);
2547 virtual void onClipPath(const SkPath& path, SkClipOp op, ClipEdgeStyle edgeStyle);
2548 virtual void onClipRegion(const SkRegion& deviceRgn, SkClipOp op);
robertphillips@google.com8f90a892014-02-28 18:19:39 +00002549
commit-bot@chromium.org28361fa2014-03-28 16:08:05 +00002550 virtual void onDiscard();
2551
Cary Clark0418a882017-05-10 09:07:42 -04002552 virtual void onDrawPicture(const SkPicture* picture, const SkMatrix* matrix,
2553 const SkPaint* paint);
robertphillips9b14f262014-06-04 05:40:44 -07002554
junov@chromium.orga907ac32012-02-24 21:54:07 +00002555 // Clip rectangle bounds. Called internally by saveLayer.
2556 // returns false if the entire rectangle is entirely clipped out
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +00002557 // If non-NULL, The imageFilter parameter will be used to expand the clip
2558 // and offscreen bounds for any margin required by the filter DAG.
Cary Clark0418a882017-05-10 09:07:42 -04002559 bool clipRectBounds(const SkRect* bounds, SaveLayerFlags flags, SkIRect* intersection,
Ben Wagnera93a14a2017-08-28 10:34:05 -04002560 const SkImageFilter* imageFilter = nullptr);
junov@chromium.orga907ac32012-02-24 21:54:07 +00002561
reedc83a2972015-07-16 07:40:45 -07002562private:
reed3aafe112016-08-18 12:45:34 -07002563 /** After calling saveLayer(), there can be any number of devices that make
2564 up the top-most drawing area. LayerIter can be used to iterate through
2565 those devices. Note that the iterator is only valid until the next API
2566 call made on the canvas. Ownership of all pointers in the iterator stays
2567 with the canvas, so none of them should be modified or deleted.
2568 */
2569 class LayerIter /*: SkNoncopyable*/ {
2570 public:
2571 /** Initialize iterator with canvas, and set values for 1st device */
2572 LayerIter(SkCanvas*);
2573 ~LayerIter();
2574
2575 /** Return true if the iterator is done */
2576 bool done() const { return fDone; }
2577 /** Cycle to the next device */
2578 void next();
2579
2580 // These reflect the current device in the iterator
2581
2582 SkBaseDevice* device() const;
2583 const SkMatrix& matrix() const;
Mike Reeda1361362017-03-07 09:37:29 -05002584 void clip(SkRegion*) const;
reed3aafe112016-08-18 12:45:34 -07002585 const SkPaint& paint() const;
2586 int x() const;
2587 int y() const;
2588
2589 private:
2590 // used to embed the SkDrawIter object directly in our instance, w/o
2591 // having to expose that class def to the public. There is an assert
2592 // in our constructor to ensure that fStorage is large enough
2593 // (though needs to be a compile-time-assert!). We use intptr_t to work
2594 // safely with 32 and 64 bit machines (to ensure the storage is enough)
2595 intptr_t fStorage[32];
2596 class SkDrawIter* fImpl; // this points at fStorage
2597 SkPaint fDefaultPaint;
2598 bool fDone;
2599 };
Herb Derby13569782016-10-06 14:33:43 -04002600
reed4960eee2015-12-18 07:09:18 -08002601 static bool BoundsAffectsClip(SaveLayerFlags);
reedbada1882015-12-21 13:09:44 -08002602 static SaveLayerFlags LegacySaveFlagsToSaveLayerFlags(uint32_t legacySaveFlags);
reed4960eee2015-12-18 07:09:18 -08002603
reeda2217ef2016-07-20 06:04:34 -07002604 static void DrawDeviceWithFilter(SkBaseDevice* src, const SkImageFilter* filter,
Mike Reedc42a1cd2017-02-14 14:25:14 -05002605 SkBaseDevice* dst, const SkIPoint& dstOrigin,
Mike Reeda1361362017-03-07 09:37:29 -05002606 const SkMatrix& ctm);
reeda2217ef2016-07-20 06:04:34 -07002607
reedc83a2972015-07-16 07:40:45 -07002608 enum ShaderOverrideOpacity {
2609 kNone_ShaderOverrideOpacity, //!< there is no overriding shader (bitmap or image)
2610 kOpaque_ShaderOverrideOpacity, //!< the overriding shader is opaque
2611 kNotOpaque_ShaderOverrideOpacity, //!< the overriding shader may not be opaque
2612 };
2613
reed@google.com97af1a62012-08-28 12:19:02 +00002614 // notify our surface (if we have one) that we are about to draw, so it
2615 // can perform copy-on-write or invalidate any cached images
reedc83a2972015-07-16 07:40:45 -07002616 void predrawNotify(bool willOverwritesEntireSurface = false);
2617 void predrawNotify(const SkRect* rect, const SkPaint* paint, ShaderOverrideOpacity);
2618 void predrawNotify(const SkRect* rect, const SkPaint* paint, bool shaderOverrideIsOpaque) {
2619 this->predrawNotify(rect, paint, shaderOverrideIsOpaque ? kOpaque_ShaderOverrideOpacity
2620 : kNotOpaque_ShaderOverrideOpacity);
2621 }
reed@google.com97af1a62012-08-28 12:19:02 +00002622
Florin Malita0ed3b642017-01-13 16:56:38 +00002623 SkBaseDevice* getDevice() const;
2624 SkBaseDevice* getTopDevice() const;
2625
reed@android.com8a1c16f2008-12-17 15:59:43 +00002626 class MCRec;
2627
2628 SkDeque fMCStack;
2629 // points to top of stack
2630 MCRec* fMCRec;
2631 // the first N recs that can fit here mean we won't call malloc
reedb679ca82015-04-07 04:40:48 -07002632 enum {
reeda499f902015-05-01 09:34:31 -07002633 kMCRecSize = 128, // most recent measurement
reed31b80a92015-11-16 13:22:24 -08002634 kMCRecCount = 32, // common depth for save/restores
Florin Malita53f77bd2017-04-28 13:48:37 -04002635 kDeviceCMSize = 224, // most recent measurement
reedb679ca82015-04-07 04:40:48 -07002636 };
2637 intptr_t fMCRecStorage[kMCRecSize * kMCRecCount / sizeof(intptr_t)];
reeda499f902015-05-01 09:34:31 -07002638 intptr_t fDeviceCMStorage[kDeviceCMSize / sizeof(intptr_t)];
reed@android.com8a1c16f2008-12-17 15:59:43 +00002639
reed4a8126e2014-09-22 07:29:03 -07002640 const SkSurfaceProps fProps;
2641
reed2ff1fce2014-12-11 07:07:37 -08002642 int fSaveCount; // value returned by getSaveCount()
reed@android.com8a1c16f2008-12-17 15:59:43 +00002643
mike@reedtribe.org74bb77e2012-09-26 02:24:45 +00002644 SkMetaData* fMetaData;
Mike Reed356f7c22017-01-10 11:58:39 -05002645 std::unique_ptr<SkRasterHandleAllocator> fAllocator;
mike@reedtribe.org74bb77e2012-09-26 02:24:45 +00002646
reed@google.com97af1a62012-08-28 12:19:02 +00002647 SkSurface_Base* fSurfaceBase;
2648 SkSurface_Base* getSurfaceBase() const { return fSurfaceBase; }
2649 void setSurfaceBase(SkSurface_Base* sb) {
2650 fSurfaceBase = sb;
2651 }
2652 friend class SkSurface_Base;
junov@chromium.org45c3db82013-04-11 17:52:05 +00002653 friend class SkSurface_Gpu;
skia.committer@gmail.comfc843592012-10-11 02:01:14 +00002654
Stan Iliev5f1bb0a2016-12-12 17:39:55 -05002655 SkIRect fClipRestrictionRect = SkIRect::MakeEmpty();
reed@android.com8a1c16f2008-12-17 15:59:43 +00002656
reed2ff1fce2014-12-11 07:07:37 -08002657 void doSave();
2658 void checkForDeferredSave();
reed8c30a812016-04-20 16:36:51 -07002659 void internalSetMatrix(const SkMatrix&);
reed2ff1fce2014-12-11 07:07:37 -08002660
Stan Iliev73d8fd92017-08-02 15:36:24 -04002661 friend class SkAndroidFrameworkUtils;
reed@google.com9c135db2014-03-12 18:28:35 +00002662 friend class SkDrawIter; // needs setupDrawForLayerDevice()
reed@google.com8926b162012-03-23 15:36:36 +00002663 friend class AutoDrawLooper;
commit-bot@chromium.org2a67e122014-05-19 13:53:10 +00002664 friend class SkDebugCanvas; // needs experimental fAllowSimplifyClip
reed52d9ac62014-06-30 09:05:34 -07002665 friend class SkSurface_Raster; // needs getDevice()
Florin Malita439ace92016-12-02 12:05:41 -05002666 friend class SkNoDrawCanvas; // InitFlags
fmalita2d97bc12014-11-20 10:44:58 -08002667 friend class SkPictureImageFilter; // SkCanvas(SkBaseDevice*, SkSurfaceProps*, InitFlags)
reedc83a2972015-07-16 07:40:45 -07002668 friend class SkPictureRecord; // predrawNotify (why does it need it? <reed>)
reed4960eee2015-12-18 07:09:18 -08002669 friend class SkPicturePlayback; // SaveFlagsToSaveLayerFlags
Matt Sarett22886c42016-11-22 11:31:41 -05002670 friend class SkOverdrawCanvas;
Mike Reed356f7c22017-01-10 11:58:39 -05002671 friend class SkRasterHandleAllocator;
piotaixrb5fae932014-09-24 13:03:30 -07002672
reedd9544982014-09-09 18:46:22 -07002673 enum InitFlags {
2674 kDefault_InitFlags = 0,
2675 kConservativeRasterClip_InitFlag = 1 << 0,
2676 };
reed78e27682014-11-19 08:04:34 -08002677 SkCanvas(const SkIRect& bounds, InitFlags);
robertphillipsfcf78292015-06-19 11:49:52 -07002678 SkCanvas(SkBaseDevice* device, InitFlags);
Mike Reed356f7c22017-01-10 11:58:39 -05002679 SkCanvas(const SkBitmap&, std::unique_ptr<SkRasterHandleAllocator>,
2680 SkRasterHandleAllocator::Handle);
reedd9544982014-09-09 18:46:22 -07002681
mtkleinfeaadee2015-04-08 11:25:48 -07002682 void resetForNextPicture(const SkIRect& bounds);
2683
reed8f2e7912014-09-04 12:45:18 -07002684 // needs gettotalclip()
tfarinaa5414c42014-10-10 06:19:09 -07002685 friend class SkCanvasStateUtils;
piotaixrb5fae932014-09-24 13:03:30 -07002686
reed4a8126e2014-09-22 07:29:03 -07002687 // call this each time we attach ourselves to a device
2688 // - constructor
2689 // - internalSaveLayer
2690 void setupDevice(SkBaseDevice*);
2691
reedd9544982014-09-09 18:46:22 -07002692 SkBaseDevice* init(SkBaseDevice*, InitFlags);
reed@google.comf0b5e112011-09-07 11:57:34 +00002693
commit-bot@chromium.org403f8d72014-02-17 15:24:26 +00002694 /**
senorblancoafc7cce2016-02-02 18:44:15 -08002695 * 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 +00002696 * to be public because it exposes decisions about layer sizes that are internal to the canvas.
2697 */
senorblancoafc7cce2016-02-02 18:44:15 -08002698 SkIRect getTopLayerBounds() const;
commit-bot@chromium.org403f8d72014-02-17 15:24:26 +00002699
reed@google.com71121732012-09-18 15:14:33 +00002700 void internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src,
commit-bot@chromium.orgeed779d2013-08-16 10:24:37 +00002701 const SkRect& dst, const SkPaint* paint,
reeda5517e22015-07-14 10:54:12 -07002702 SrcRectConstraint);
bsalomon@google.comfa6ac932011-10-05 19:57:55 +00002703 void internalDrawPaint(const SkPaint& paint);
reed4960eee2015-12-18 07:09:18 -08002704 void internalSaveLayer(const SaveLayerRec&, SaveLayerStrategy);
Florin Malita53f77bd2017-04-28 13:48:37 -04002705 void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*, SkImage* clipImage,
2706 const SkMatrix& clipMatrix);
bsalomon@google.comfa6ac932011-10-05 19:57:55 +00002707
reed@android.com8a1c16f2008-12-17 15:59:43 +00002708 // shared by save() and saveLayer()
reed2ff1fce2014-12-11 07:07:37 -08002709 void internalSave();
reed@android.com8a1c16f2008-12-17 15:59:43 +00002710 void internalRestore();
reed@google.com4b226022011-01-11 18:32:13 +00002711
reedc83a2972015-07-16 07:40:45 -07002712 /*
2713 * Returns true if drawing the specified rect (or all if it is null) with the specified
2714 * paint (or default if null) would overwrite the entire root device of the canvas
2715 * (i.e. the canvas' surface if it had one).
2716 */
2717 bool wouldOverwriteEntireSurface(const SkRect*, const SkPaint*, ShaderOverrideOpacity) const;
2718
reed262a71b2015-12-05 13:07:27 -08002719 /**
2720 * Returns true if the paint's imagefilter can be invoked directly, without needed a layer.
2721 */
2722 bool canDrawBitmapAsSprite(SkScalar x, SkScalar y, int w, int h, const SkPaint&);
reedc83a2972015-07-16 07:40:45 -07002723
Mike Reeda1361362017-03-07 09:37:29 -05002724 /**
2725 * Returns true if the clip (for any active layer) contains antialiasing.
2726 * If the clip is empty, this will return false.
Mike Reed46784be2017-01-15 20:02:32 -05002727 */
Mike Reeda1361362017-03-07 09:37:29 -05002728 bool androidFramework_isClipAA() const;
msarettfbfa2582016-08-12 08:29:08 -07002729
2730 /**
2731 * Keep track of the device clip bounds and if the matrix is scale-translate. This allows
2732 * us to do a fast quick reject in the common case.
reed@android.com8a1c16f2008-12-17 15:59:43 +00002733 */
msarett9637ea92016-08-18 14:03:30 -07002734 bool fIsScaleTranslate;
msarettfbfa2582016-08-12 08:29:08 -07002735 SkRect fDeviceClipBounds;
2736
caryclark@google.com8f0a7b82012-11-07 14:54:49 +00002737 bool fAllowSoftClip;
caryclark@google.com45a75fb2013-04-25 13:34:40 +00002738 bool fAllowSimplifyClip;
reed@android.com8a1c16f2008-12-17 15:59:43 +00002739
reed@google.com5c3d1472011-02-22 19:12:23 +00002740 class AutoValidateClip : ::SkNoncopyable {
2741 public:
2742 explicit AutoValidateClip(SkCanvas* canvas) : fCanvas(canvas) {
2743 fCanvas->validateClip();
2744 }
2745 ~AutoValidateClip() { fCanvas->validateClip(); }
2746
2747 private:
2748 const SkCanvas* fCanvas;
2749 };
2750
2751#ifdef SK_DEBUG
2752 void validateClip() const;
2753#else
2754 void validateClip() const {}
2755#endif
robertphillips@google.com15e9d3e2012-06-21 20:25:03 +00002756
2757 typedef SkRefCnt INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +00002758};
2759
2760/** Stack helper class to automatically call restoreToCount() on the canvas
2761 when this object goes out of scope. Use this to guarantee that the canvas
2762 is restored to a known state.
2763*/
2764class SkAutoCanvasRestore : SkNoncopyable {
2765public:
commit-bot@chromium.org28871192013-10-14 15:28:01 +00002766 SkAutoCanvasRestore(SkCanvas* canvas, bool doSave) : fCanvas(canvas), fSaveCount(0) {
2767 if (fCanvas) {
2768 fSaveCount = canvas->getSaveCount();
2769 if (doSave) {
2770 canvas->save();
2771 }
reed@android.com8a1c16f2008-12-17 15:59:43 +00002772 }
2773 }
2774 ~SkAutoCanvasRestore() {
reed@google.comf6c9a5b2012-11-20 15:12:21 +00002775 if (fCanvas) {
2776 fCanvas->restoreToCount(fSaveCount);
2777 }
2778 }
2779
2780 /**
2781 * Perform the restore now, instead of waiting for the destructor. Will
2782 * only do this once.
2783 */
2784 void restore() {
2785 if (fCanvas) {
2786 fCanvas->restoreToCount(fSaveCount);
Ben Wagnera93a14a2017-08-28 10:34:05 -04002787 fCanvas = nullptr;
reed@google.comf6c9a5b2012-11-20 15:12:21 +00002788 }
reed@android.com8a1c16f2008-12-17 15:59:43 +00002789 }
2790
2791private:
2792 SkCanvas* fCanvas;
2793 int fSaveCount;
2794};
commit-bot@chromium.orge61a86c2013-11-18 16:03:59 +00002795#define SkAutoCanvasRestore(...) SK_REQUIRE_LOCAL_VAR(SkAutoCanvasRestore)
reed@android.com8a1c16f2008-12-17 15:59:43 +00002796
2797#endif