| 1 |
/* |
| 2 |
* Copyright 2006 The Android Open Source Project |
| 3 |
* |
| 4 |
* Use of this source code is governed by a BSD-style license that can be |
| 5 |
* found in the LICENSE file. |
| 6 |
*/ |
| 7 |
|
| 8 |
#ifndef SkCanvas_DEFINED |
| 9 |
#define SkCanvas_DEFINED |
| 10 |
|
| 11 |
#include "include/core/SkArc.h" |
| 12 |
#include "include/core/SkBlendMode.h" |
| 13 |
#include "include/core/SkClipOp.h" |
| 14 |
#include "include/core/SkColor.h" |
| 15 |
#include "include/core/SkFontTypes.h" |
| 16 |
#include "include/core/SkImageFilter.h" |
| 17 |
#include "include/core/SkImageInfo.h" |
| 18 |
#include "include/core/SkM44.h" |
| 19 |
#include "include/core/SkMatrix.h" |
| 20 |
#include "include/core/SkPaint.h" |
| 21 |
#include "include/core/SkPoint.h" |
| 22 |
#include "include/core/SkRSXform.h" // IWYU pragma: keep (for unspanned apis) |
| 23 |
#include "include/core/SkRasterHandleAllocator.h" |
| 24 |
#include "include/core/SkRect.h" |
| 25 |
#include "include/core/SkRefCnt.h" |
| 26 |
#include "include/core/SkSamplingOptions.h" |
| 27 |
#include "include/core/SkScalar.h" |
| 28 |
#include "include/core/SkSize.h" |
| 29 |
#include "include/core/SkSpan.h" |
| 30 |
#include "include/core/SkString.h" |
| 31 |
#include "include/core/SkSurfaceProps.h" |
| 32 |
#include "include/core/SkTileMode.h" |
| 33 |
#include "include/core/SkTypes.h" |
| 34 |
#include "include/private/base/SkCPUTypes.h" |
| 35 |
#include "include/private/base/SkDeque.h" |
| 36 |
#include "include/private/base/SkTArray.h" |
| 37 |
|
| 38 |
#include <cstddef> |
| 39 |
#include <cstdint> |
| 40 |
#include <cstring> |
| 41 |
#include <memory> |
| 42 |
#include <optional> |
| 43 |
|
| 44 |
#ifndef SK_SUPPORT_LEGACY_GETTOTALMATRIX |
| 45 |
#define SK_SUPPORT_LEGACY_GETTOTALMATRIX |
| 46 |
#endif |
| 47 |
|
| 48 |
namespace sktext { |
| 49 |
class GlyphRunBuilder; |
| 50 |
class GlyphRunList; |
| 51 |
} |
| 52 |
|
| 53 |
class AutoLayerForImageFilter; |
| 54 |
class GrRecordingContext; |
| 55 |
|
| 56 |
class SkBitmap; |
| 57 |
class SkBlender; |
| 58 |
class SkBlurMaskFilterImpl; |
| 59 |
class SkColorSpace; |
| 60 |
class SkData; |
| 61 |
class SkDevice; |
| 62 |
class SkDrawable; |
| 63 |
class SkFont; |
| 64 |
class SkImage; |
| 65 |
class SkMesh; |
| 66 |
class SkPaintFilterCanvas; |
| 67 |
class SkPath; |
| 68 |
class SkPicture; |
| 69 |
class SkPixmap; |
| 70 |
class SkRRect; |
| 71 |
class SkRegion; |
| 72 |
class SkRecorder; |
| 73 |
class SkShader; |
| 74 |
class SkSpecialImage; |
| 75 |
class SkSurface; |
| 76 |
class SkSurface_Base; |
| 77 |
class SkTextBlob; |
| 78 |
class SkVertices; |
| 79 |
struct SkDrawShadowRec; |
| 80 |
|
| 81 |
template<typename E> |
| 82 |
class SkEnumBitMask; |
| 83 |
|
| 84 |
namespace skgpu::graphite { class Recorder; } |
| 85 |
namespace sktext::gpu { class Slug; } |
| 86 |
namespace SkRecords { class Draw; } |
| 87 |
namespace skiatest { |
| 88 |
template <typename Key> |
| 89 |
class TestCanvas;// IWYU pragma: keep |
| 90 |
} |
| 91 |
|
| 92 |
/** \class SkCanvas |
| 93 |
SkCanvas provides an interface for drawing, and how the drawing is clipped and transformed. |
| 94 |
SkCanvas contains a stack of SkMatrix and clip values. |
| 95 |
|
| 96 |
SkCanvas and SkPaint together provide the state to draw into SkSurface or SkDevice. |
| 97 |
Each SkCanvas draw call transforms the geometry of the object by the concatenation of all |
| 98 |
SkMatrix values in the stack. The transformed geometry is clipped by the intersection |
| 99 |
of all of clip values in the stack. The SkCanvas draw calls use SkPaint to supply drawing |
| 100 |
state such as color, SkTypeface, text size, stroke width, SkShader and so on. |
| 101 |
|
| 102 |
To draw to a pixel-based destination, create raster surface or GPU surface. |
| 103 |
Request SkCanvas from SkSurface to obtain the interface to draw. |
| 104 |
SkCanvas generated by raster surface draws to memory visible to the CPU. |
| 105 |
SkCanvas generated by GPU surface uses Vulkan or OpenGL to draw to the GPU. |
| 106 |
|
| 107 |
To draw to a document, obtain SkCanvas from SVG canvas, document PDF, or SkPictureRecorder. |
| 108 |
SkDocument based SkCanvas and other SkCanvas subclasses reference SkDevice describing the |
| 109 |
destination. |
| 110 |
|
| 111 |
SkCanvas can be constructed to draw to SkBitmap without first creating raster surface. |
| 112 |
This approach may be deprecated in the future. |
| 113 |
*/ |
| 114 |
class SK_API SkCanvas { |
| 115 |
public: |
| 116 |
|
| 117 |
/** Allocates raster SkCanvas that will draw directly into pixels. |
| 118 |
|
| 119 |
SkCanvas is returned if all parameters are valid. |
| 120 |
Valid parameters include: |
| 121 |
info dimensions are zero or positive; |
| 122 |
info contains SkColorType and SkAlphaType supported by raster surface; |
| 123 |
pixels is not nullptr; |
| 124 |
rowBytes is zero or large enough to contain info width pixels of SkColorType. |
| 125 |
|
| 126 |
Pass zero for rowBytes to compute rowBytes from info width and size of pixel. |
| 127 |
If rowBytes is greater than zero, it must be equal to or greater than |
| 128 |
info width times bytes required for SkColorType. |
| 129 |
|
| 130 |
Pixel buffer size should be info height times computed rowBytes. |
| 131 |
Pixels are not initialized. |
| 132 |
To access pixels after drawing, call flush() or peekPixels(). |
| 133 |
|
| 134 |
@param info width, height, SkColorType, SkAlphaType, SkColorSpace, of raster surface; |
| 135 |
width, or height, or both, may be zero |
| 136 |
@param pixels pointer to destination pixels buffer |
| 137 |
@param rowBytes interval from one SkSurface row to the next, or zero |
| 138 |
@param props LCD striping orientation and setting for device independent fonts; |
| 139 |
may be nullptr |
| 140 |
@return SkCanvas if all parameters are valid; otherwise, nullptr |
| 141 |
*/ |
| 142 |
static std::unique_ptr<SkCanvas> MakeRasterDirect(const SkImageInfo& info, void* pixels, |
| 143 |
size_t rowBytes, |
| 144 |
const SkSurfaceProps* props = nullptr); |
| 145 |
|
| 146 |
/** Allocates raster SkCanvas specified by inline image specification. Subsequent SkCanvas |
| 147 |
calls draw into pixels. |
| 148 |
SkColorType is set to kN32_SkColorType. |
| 149 |
SkAlphaType is set to kPremul_SkAlphaType. |
| 150 |
To access pixels after drawing, call flush() or peekPixels(). |
| 151 |
|
| 152 |
SkCanvas is returned if all parameters are valid. |
| 153 |
Valid parameters include: |
| 154 |
width and height are zero or positive; |
| 155 |
pixels is not nullptr; |
| 156 |
rowBytes is zero or large enough to contain width pixels of kN32_SkColorType. |
| 157 |
|
| 158 |
Pass zero for rowBytes to compute rowBytes from width and size of pixel. |
| 159 |
If rowBytes is greater than zero, it must be equal to or greater than |
| 160 |
width times bytes required for SkColorType. |
| 161 |
|
| 162 |
Pixel buffer size should be height times rowBytes. |
| 163 |
|
| 164 |
@param width pixel column count on raster surface created; must be zero or greater |
| 165 |
@param height pixel row count on raster surface created; must be zero or greater |
| 166 |
@param pixels pointer to destination pixels buffer; buffer size should be height |
| 167 |
times rowBytes |
| 168 |
@param rowBytes interval from one SkSurface row to the next, or zero |
| 169 |
@return SkCanvas if all parameters are valid; otherwise, nullptr |
| 170 |
*/ |
| 171 |
static std::unique_ptr<SkCanvas> MakeRasterDirectN32(int width, int height, SkPMColor* pixels, |
| 172 |
size_t rowBytes) { |
| 173 |
return MakeRasterDirect(SkImageInfo::MakeN32Premul(width, height), pixels, rowBytes); |
| 174 |
} |
| 175 |
|
| 176 |
/** Creates an empty SkCanvas with no backing device or pixels, with |
| 177 |
a width and height of zero. |
| 178 |
|
| 179 |
@return empty SkCanvas |
| 180 |
|
| 181 |
example: https://fiddle.skia.org/c/@Canvas_empty_constructor |
| 182 |
*/ |
| 183 |
SkCanvas(); |
| 184 |
|
| 185 |
/** Creates SkCanvas of the specified dimensions without a SkSurface. |
| 186 |
Used by subclasses with custom implementations for draw member functions. |
| 187 |
|
| 188 |
If props equals nullptr, SkSurfaceProps are created with |
| 189 |
SkSurfaceProps::InitType settings, which choose the pixel striping |
| 190 |
direction and order. Since a platform may dynamically change its direction when |
| 191 |
the device is rotated, and since a platform may have multiple monitors with |
| 192 |
different characteristics, it is best not to rely on this legacy behavior. |
| 193 |
|
| 194 |
@param width zero or greater |
| 195 |
@param height zero or greater |
| 196 |
@param props LCD striping orientation and setting for device independent fonts; |
| 197 |
may be nullptr |
| 198 |
@return SkCanvas placeholder with dimensions |
| 199 |
|
| 200 |
example: https://fiddle.skia.org/c/@Canvas_int_int_const_SkSurfaceProps_star |
| 201 |
*/ |
| 202 |
SkCanvas(int width, int height, const SkSurfaceProps* props = nullptr); |
| 203 |
|
| 204 |
/** Private. For internal use only. |
| 205 |
*/ |
| 206 |
explicit SkCanvas(sk_sp<SkDevice> device); |
| 207 |
|
| 208 |
/** Constructs a canvas that draws into bitmap. |
| 209 |
Sets kUnknown_SkPixelGeometry in constructed SkSurface. |
| 210 |
|
| 211 |
SkBitmap is copied so that subsequently editing bitmap will not affect |
| 212 |
constructed SkCanvas. |
| 213 |
|
| 214 |
May be deprecated in the future. |
| 215 |
|
| 216 |
@param bitmap width, height, SkColorType, SkAlphaType, and pixel |
| 217 |
storage of raster surface |
| 218 |
@return SkCanvas that can be used to draw into bitmap |
| 219 |
|
| 220 |
example: https://fiddle.skia.org/c/@Canvas_copy_const_SkBitmap |
| 221 |
*/ |
| 222 |
explicit SkCanvas(const SkBitmap& bitmap); |
| 223 |
|
| 224 |
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 225 |
/** Private. |
| 226 |
*/ |
| 227 |
enum class ColorBehavior { |
| 228 |
kLegacy, //!< placeholder |
| 229 |
}; |
| 230 |
|
| 231 |
/** Private. For use by Android framework only. |
| 232 |
|
| 233 |
@param bitmap specifies a bitmap for the canvas to draw into |
| 234 |
@param behavior specializes this constructor; value is unused |
| 235 |
@return SkCanvas that can be used to draw into bitmap |
| 236 |
*/ |
| 237 |
SkCanvas(const SkBitmap& bitmap, ColorBehavior behavior); |
| 238 |
#endif |
| 239 |
|
| 240 |
/** Constructs a canvas that draws into bitmap. |
| 241 |
Use props to match the device characteristics, like LCD striping. |
| 242 |
|
| 243 |
bitmap is copied so that subsequently editing bitmap will not affect |
| 244 |
constructed SkCanvas. |
| 245 |
|
| 246 |
@param bitmap width, height, SkColorType, SkAlphaType, |
| 247 |
and pixel storage of raster surface |
| 248 |
@param props order and orientation of RGB striping; and whether to use |
| 249 |
device independent fonts |
| 250 |
@return SkCanvas that can be used to draw into bitmap |
| 251 |
|
| 252 |
example: https://fiddle.skia.org/c/@Canvas_const_SkBitmap_const_SkSurfaceProps |
| 253 |
*/ |
| 254 |
SkCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props); |
| 255 |
|
| 256 |
/** Draws saved layers, if any. |
| 257 |
Frees up resources used by SkCanvas. |
| 258 |
|
| 259 |
example: https://fiddle.skia.org/c/@Canvas_destructor |
| 260 |
*/ |
| 261 |
virtual ~SkCanvas(); |
| 262 |
|
| 263 |
/** Returns SkImageInfo for SkCanvas. If SkCanvas is not associated with raster surface or |
| 264 |
GPU surface, returned SkColorType is set to kUnknown_SkColorType. |
| 265 |
|
| 266 |
@return dimensions and SkColorType of SkCanvas |
| 267 |
|
| 268 |
example: https://fiddle.skia.org/c/@Canvas_imageInfo |
| 269 |
*/ |
| 270 |
SkImageInfo imageInfo() const; |
| 271 |
|
| 272 |
/** Copies SkSurfaceProps, if SkCanvas is associated with raster surface or |
| 273 |
GPU surface, and returns true. Otherwise, returns false and leave props unchanged. |
| 274 |
|
| 275 |
@param props storage for writable SkSurfaceProps |
| 276 |
@return true if SkSurfaceProps was copied |
| 277 |
|
| 278 |
DEPRECATED: Replace usage with getBaseProps() or getTopProps() |
| 279 |
|
| 280 |
example: https://fiddle.skia.org/c/@Canvas_getProps |
| 281 |
*/ |
| 282 |
bool getProps(SkSurfaceProps* props) const; |
| 283 |
|
| 284 |
/** Returns the SkSurfaceProps associated with the canvas (i.e., at the base of the layer |
| 285 |
stack). |
| 286 |
|
| 287 |
@return base SkSurfaceProps |
| 288 |
*/ |
| 289 |
SkSurfaceProps getBaseProps() const; |
| 290 |
|
| 291 |
/** Returns the SkSurfaceProps associated with the canvas that are currently active (i.e., at |
| 292 |
the top of the layer stack). This can differ from getBaseProps depending on the flags |
| 293 |
passed to saveLayer (see SaveLayerFlagsSet). |
| 294 |
|
| 295 |
@return SkSurfaceProps active in the current/top layer |
| 296 |
*/ |
| 297 |
SkSurfaceProps getTopProps() const; |
| 298 |
|
| 299 |
/** Gets the size of the base or root layer in global canvas coordinates. The |
| 300 |
origin of the base layer is always (0,0). The area available for drawing may be |
| 301 |
smaller (due to clipping or saveLayer). |
| 302 |
|
| 303 |
@return integral width and height of base layer |
| 304 |
|
| 305 |
example: https://fiddle.skia.org/c/@Canvas_getBaseLayerSize |
| 306 |
*/ |
| 307 |
virtual SkISize getBaseLayerSize() const; |
| 308 |
|
| 309 |
/** Creates SkSurface matching info and props, and associates it with SkCanvas. |
| 310 |
Returns nullptr if no match found. |
| 311 |
|
| 312 |
If props is nullptr, matches SkSurfaceProps in SkCanvas. If props is nullptr and SkCanvas |
| 313 |
does not have SkSurfaceProps, creates SkSurface with default SkSurfaceProps. |
| 314 |
|
| 315 |
@param info width, height, SkColorType, SkAlphaType, and SkColorSpace |
| 316 |
@param props SkSurfaceProps to match; may be nullptr to match SkCanvas |
| 317 |
@return SkSurface matching info and props, or nullptr if no match is available |
| 318 |
|
| 319 |
example: https://fiddle.skia.org/c/@Canvas_makeSurface |
| 320 |
*/ |
| 321 |
sk_sp<SkSurface> makeSurface(const SkImageInfo& info, const SkSurfaceProps* props = nullptr); |
| 322 |
|
| 323 |
/** Returns Ganesh context of the GPU surface associated with SkCanvas. |
| 324 |
|
| 325 |
@return GPU context, if available; nullptr otherwise |
| 326 |
|
| 327 |
example: https://fiddle.skia.org/c/@Canvas_recordingContext |
| 328 |
*/ |
| 329 |
virtual GrRecordingContext* recordingContext() const; |
| 330 |
|
| 331 |
/** Returns Recorder for the GPU surface associated with SkCanvas. |
| 332 |
|
| 333 |
@return Recorder, if available; nullptr otherwise |
| 334 |
*/ |
| 335 |
virtual skgpu::graphite::Recorder* recorder() const; |
| 336 |
|
| 337 |
/** Returns Recorder for the surface associated with SkCanvas. |
| 338 |
|
| 339 |
@return Recorder, should be non-null |
| 340 |
*/ |
| 341 |
virtual SkRecorder* baseRecorder() const; |
| 342 |
|
| 343 |
/** Sometimes a canvas is owned by a surface. If it is, getSurface() will return a bare |
| 344 |
* pointer to that surface, else this will return nullptr. |
| 345 |
*/ |
| 346 |
SkSurface* getSurface() const; |
| 347 |
|
| 348 |
/** Returns the pixel base address, SkImageInfo, rowBytes, and origin if the pixels |
| 349 |
can be read directly. The returned address is only valid |
| 350 |
while SkCanvas is in scope and unchanged. Any SkCanvas call or SkSurface call |
| 351 |
may invalidate the returned address and other returned values. |
| 352 |
|
| 353 |
If pixels are inaccessible, info, rowBytes, and origin are unchanged. |
| 354 |
|
| 355 |
@param info storage for writable pixels' SkImageInfo; may be nullptr |
| 356 |
@param rowBytes storage for writable pixels' row bytes; may be nullptr |
| 357 |
@param origin storage for SkCanvas top layer origin, its top-left corner; |
| 358 |
may be nullptr |
| 359 |
@return address of pixels, or nullptr if inaccessible |
| 360 |
|
| 361 |
example: https://fiddle.skia.org/c/@Canvas_accessTopLayerPixels_a |
| 362 |
example: https://fiddle.skia.org/c/@Canvas_accessTopLayerPixels_b |
| 363 |
*/ |
| 364 |
void* accessTopLayerPixels(SkImageInfo* info, size_t* rowBytes, SkIPoint* origin = nullptr); |
| 365 |
|
| 366 |
/** Returns custom context that tracks the SkMatrix and clip. |
| 367 |
|
| 368 |
Use SkRasterHandleAllocator to blend Skia drawing with custom drawing, typically performed |
| 369 |
by the host platform user interface. The custom context returned is generated by |
| 370 |
SkRasterHandleAllocator::MakeCanvas, which creates a custom canvas with raster storage for |
| 371 |
the drawing destination. |
| 372 |
|
| 373 |
@return context of custom allocation |
| 374 |
|
| 375 |
example: https://fiddle.skia.org/c/@Canvas_accessTopRasterHandle |
| 376 |
*/ |
| 377 |
SkRasterHandleAllocator::Handle accessTopRasterHandle() const; |
| 378 |
|
| 379 |
/** Returns true if SkCanvas has direct access to its pixels. |
| 380 |
|
| 381 |
Pixels are readable when SkDevice is raster. Pixels are not readable when SkCanvas |
| 382 |
is returned from GPU surface, returned by SkDocument::beginPage, returned by |
| 383 |
SkPictureRecorder::beginRecording, or SkCanvas is the base of a utility class |
| 384 |
like DebugCanvas. |
| 385 |
|
| 386 |
pixmap is valid only while SkCanvas is in scope and unchanged. Any |
| 387 |
SkCanvas or SkSurface call may invalidate the pixmap values. |
| 388 |
|
| 389 |
@param pixmap storage for pixel state if pixels are readable; otherwise, ignored |
| 390 |
@return true if SkCanvas has direct access to pixels |
| 391 |
|
| 392 |
example: https://fiddle.skia.org/c/@Canvas_peekPixels |
| 393 |
*/ |
| 394 |
bool peekPixels(SkPixmap* pixmap); |
| 395 |
|
| 396 |
/** Copies SkRect of pixels from SkCanvas into dstPixels. SkMatrix and clip are |
| 397 |
ignored. |
| 398 |
|
| 399 |
Source SkRect corners are (srcX, srcY) and (imageInfo().width(), imageInfo().height()). |
| 400 |
Destination SkRect corners are (0, 0) and (dstInfo.width(), dstInfo.height()). |
| 401 |
Copies each readable pixel intersecting both rectangles, without scaling, |
| 402 |
converting to dstInfo.colorType() and dstInfo.alphaType() if required. |
| 403 |
|
| 404 |
Pixels are readable when SkDevice is raster, or backed by a GPU. |
| 405 |
Pixels are not readable when SkCanvas is returned by SkDocument::beginPage, |
| 406 |
returned by SkPictureRecorder::beginRecording, or SkCanvas is the base of a utility |
| 407 |
class like DebugCanvas. |
| 408 |
|
| 409 |
The destination pixel storage must be allocated by the caller. |
| 410 |
|
| 411 |
Pixel values are converted only if SkColorType and SkAlphaType |
| 412 |
do not match. Only pixels within both source and destination rectangles |
| 413 |
are copied. dstPixels contents outside SkRect intersection are unchanged. |
| 414 |
|
| 415 |
Pass negative values for srcX or srcY to offset pixels across or down destination. |
| 416 |
|
| 417 |
Does not copy, and returns false if: |
| 418 |
- Source and destination rectangles do not intersect. |
| 419 |
- SkCanvas pixels could not be converted to dstInfo.colorType() or dstInfo.alphaType(). |
| 420 |
- SkCanvas pixels are not readable; for instance, SkCanvas is document-based. |
| 421 |
- dstRowBytes is too small to contain one row of pixels. |
| 422 |
|
| 423 |
@param dstInfo width, height, SkColorType, and SkAlphaType of dstPixels |
| 424 |
@param dstPixels storage for pixels; dstInfo.height() times dstRowBytes, or larger |
| 425 |
@param dstRowBytes size of one destination row; dstInfo.width() times pixel size, or larger |
| 426 |
@param srcX offset into readable pixels on x-axis; may be negative |
| 427 |
@param srcY offset into readable pixels on y-axis; may be negative |
| 428 |
@return true if pixels were copied |
| 429 |
*/ |
| 430 |
bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, |
| 431 |
int srcX, int srcY); |
| 432 |
|
| 433 |
/** Copies SkRect of pixels from SkCanvas into pixmap. SkMatrix and clip are |
| 434 |
ignored. |
| 435 |
|
| 436 |
Source SkRect corners are (srcX, srcY) and (imageInfo().width(), imageInfo().height()). |
| 437 |
Destination SkRect corners are (0, 0) and (pixmap.width(), pixmap.height()). |
| 438 |
Copies each readable pixel intersecting both rectangles, without scaling, |
| 439 |
converting to pixmap.colorType() and pixmap.alphaType() if required. |
| 440 |
|
| 441 |
Pixels are readable when SkDevice is raster, or backed by a GPU. |
| 442 |
Pixels are not readable when SkCanvas is returned by SkDocument::beginPage, |
| 443 |
returned by SkPictureRecorder::beginRecording, or SkCanvas is the base of a utility |
| 444 |
class like DebugCanvas. |
| 445 |
|
| 446 |
Caller must allocate pixel storage in pixmap if needed. |
| 447 |
|
| 448 |
Pixel values are converted only if SkColorType and SkAlphaType |
| 449 |
do not match. Only pixels within both source and destination SkRect |
| 450 |
are copied. pixmap pixels contents outside SkRect intersection are unchanged. |
| 451 |
|
| 452 |
Pass negative values for srcX or srcY to offset pixels across or down pixmap. |
| 453 |
|
| 454 |
Does not copy, and returns false if: |
| 455 |
- Source and destination rectangles do not intersect. |
| 456 |
- SkCanvas pixels could not be converted to pixmap.colorType() or pixmap.alphaType(). |
| 457 |
- SkCanvas pixels are not readable; for instance, SkCanvas is document-based. |
| 458 |
- SkPixmap pixels could not be allocated. |
| 459 |
- pixmap.rowBytes() is too small to contain one row of pixels. |
| 460 |
|
| 461 |
@param pixmap storage for pixels copied from SkCanvas |
| 462 |
@param srcX offset into readable pixels on x-axis; may be negative |
| 463 |
@param srcY offset into readable pixels on y-axis; may be negative |
| 464 |
@return true if pixels were copied |
| 465 |
|
| 466 |
example: https://fiddle.skia.org/c/@Canvas_readPixels_2 |
| 467 |
*/ |
| 468 |
bool readPixels(const SkPixmap& pixmap, int srcX, int srcY); |
| 469 |
|
| 470 |
/** Copies SkRect of pixels from SkCanvas into bitmap. SkMatrix and clip are |
| 471 |
ignored. |
| 472 |
|
| 473 |
Source SkRect corners are (srcX, srcY) and (imageInfo().width(), imageInfo().height()). |
| 474 |
Destination SkRect corners are (0, 0) and (bitmap.width(), bitmap.height()). |
| 475 |
Copies each readable pixel intersecting both rectangles, without scaling, |
| 476 |
converting to bitmap.colorType() and bitmap.alphaType() if required. |
| 477 |
|
| 478 |
Pixels are readable when SkDevice is raster, or backed by a GPU. |
| 479 |
Pixels are not readable when SkCanvas is returned by SkDocument::beginPage, |
| 480 |
returned by SkPictureRecorder::beginRecording, or SkCanvas is the base of a utility |
| 481 |
class like DebugCanvas. |
| 482 |
|
| 483 |
Caller must allocate pixel storage in bitmap if needed. |
| 484 |
|
| 485 |
SkBitmap values are converted only if SkColorType and SkAlphaType |
| 486 |
do not match. Only pixels within both source and destination rectangles |
| 487 |
are copied. SkBitmap pixels outside SkRect intersection are unchanged. |
| 488 |
|
| 489 |
Pass negative values for srcX or srcY to offset pixels across or down bitmap. |
| 490 |
|
| 491 |
Does not copy, and returns false if: |
| 492 |
- Source and destination rectangles do not intersect. |
| 493 |
- SkCanvas pixels could not be converted to bitmap.colorType() or bitmap.alphaType(). |
| 494 |
- SkCanvas pixels are not readable; for instance, SkCanvas is document-based. |
| 495 |
- bitmap pixels could not be allocated. |
| 496 |
- bitmap.rowBytes() is too small to contain one row of pixels. |
| 497 |
|
| 498 |
@param bitmap storage for pixels copied from SkCanvas |
| 499 |
@param srcX offset into readable pixels on x-axis; may be negative |
| 500 |
@param srcY offset into readable pixels on y-axis; may be negative |
| 501 |
@return true if pixels were copied |
| 502 |
|
| 503 |
example: https://fiddle.skia.org/c/@Canvas_readPixels_3 |
| 504 |
*/ |
| 505 |
bool readPixels(const SkBitmap& bitmap, int srcX, int srcY); |
| 506 |
|
| 507 |
/** Copies SkRect from pixels to SkCanvas. SkMatrix and clip are ignored. |
| 508 |
Source SkRect corners are (0, 0) and (info.width(), info.height()). |
| 509 |
Destination SkRect corners are (x, y) and |
| 510 |
(imageInfo().width(), imageInfo().height()). |
| 511 |
|
| 512 |
Copies each readable pixel intersecting both rectangles, without scaling, |
| 513 |
converting to imageInfo().colorType() and imageInfo().alphaType() if required. |
| 514 |
|
| 515 |
Pixels are writable when SkDevice is raster, or backed by a GPU. |
| 516 |
Pixels are not writable when SkCanvas is returned by SkDocument::beginPage, |
| 517 |
returned by SkPictureRecorder::beginRecording, or SkCanvas is the base of a utility |
| 518 |
class like DebugCanvas. |
| 519 |
|
| 520 |
Pixel values are converted only if SkColorType and SkAlphaType |
| 521 |
do not match. Only pixels within both source and destination rectangles |
| 522 |
are copied. SkCanvas pixels outside SkRect intersection are unchanged. |
| 523 |
|
| 524 |
Pass negative values for x or y to offset pixels to the left or |
| 525 |
above SkCanvas pixels. |
| 526 |
|
| 527 |
Does not copy, and returns false if: |
| 528 |
- Source and destination rectangles do not intersect. |
| 529 |
- pixels could not be converted to SkCanvas imageInfo().colorType() or |
| 530 |
imageInfo().alphaType(). |
| 531 |
- SkCanvas pixels are not writable; for instance, SkCanvas is document-based. |
| 532 |
- rowBytes is too small to contain one row of pixels. |
| 533 |
|
| 534 |
@param info width, height, SkColorType, and SkAlphaType of pixels |
| 535 |
@param pixels pixels to copy, of size info.height() times rowBytes, or larger |
| 536 |
@param rowBytes size of one row of pixels; info.width() times pixel size, or larger |
| 537 |
@param x offset into SkCanvas writable pixels on x-axis; may be negative |
| 538 |
@param y offset into SkCanvas writable pixels on y-axis; may be negative |
| 539 |
@return true if pixels were written to SkCanvas |
| 540 |
|
| 541 |
example: https://fiddle.skia.org/c/@Canvas_writePixels |
| 542 |
*/ |
| 543 |
bool writePixels(const SkImageInfo& info, const void* pixels, size_t rowBytes, int x, int y); |
| 544 |
|
| 545 |
/** Copies SkRect from pixels to SkCanvas. SkMatrix and clip are ignored. |
| 546 |
Source SkRect corners are (0, 0) and (bitmap.width(), bitmap.height()). |
| 547 |
|
| 548 |
Destination SkRect corners are (x, y) and |
| 549 |
(imageInfo().width(), imageInfo().height()). |
| 550 |
|
| 551 |
Copies each readable pixel intersecting both rectangles, without scaling, |
| 552 |
converting to imageInfo().colorType() and imageInfo().alphaType() if required. |
| 553 |
|
| 554 |
Pixels are writable when SkDevice is raster, or backed by a GPU. |
| 555 |
Pixels are not writable when SkCanvas is returned by SkDocument::beginPage, |
| 556 |
returned by SkPictureRecorder::beginRecording, or SkCanvas is the base of a utility |
| 557 |
class like DebugCanvas. |
| 558 |
|
| 559 |
Pixel values are converted only if SkColorType and SkAlphaType |
| 560 |
do not match. Only pixels within both source and destination rectangles |
| 561 |
are copied. SkCanvas pixels outside SkRect intersection are unchanged. |
| 562 |
|
| 563 |
Pass negative values for x or y to offset pixels to the left or |
| 564 |
above SkCanvas pixels. |
| 565 |
|
| 566 |
Does not copy, and returns false if: |
| 567 |
- Source and destination rectangles do not intersect. |
| 568 |
- bitmap does not have allocated pixels. |
| 569 |
- bitmap pixels could not be converted to SkCanvas imageInfo().colorType() or |
| 570 |
imageInfo().alphaType(). |
| 571 |
- SkCanvas pixels are not writable; for instance, SkCanvas is document based. |
| 572 |
- bitmap pixels are inaccessible; for instance, bitmap wraps a texture. |
| 573 |
|
| 574 |
@param bitmap contains pixels copied to SkCanvas |
| 575 |
@param x offset into SkCanvas writable pixels on x-axis; may be negative |
| 576 |
@param y offset into SkCanvas writable pixels on y-axis; may be negative |
| 577 |
@return true if pixels were written to SkCanvas |
| 578 |
|
| 579 |
example: https://fiddle.skia.org/c/@Canvas_writePixels_2 |
| 580 |
example: https://fiddle.skia.org/c/@State_Stack_a |
| 581 |
example: https://fiddle.skia.org/c/@State_Stack_b |
| 582 |
*/ |
| 583 |
bool writePixels(const SkBitmap& bitmap, int x, int y); |
| 584 |
|
| 585 |
/** Saves SkMatrix and clip. |
| 586 |
Calling restore() discards changes to SkMatrix and clip, |
| 587 |
restoring the SkMatrix and clip to their state when save() was called. |
| 588 |
|
| 589 |
SkMatrix may be changed by translate(), scale(), rotate(), skew(), concat(), setMatrix(), |
| 590 |
and resetMatrix(). Clip may be changed by clipRect(), clipRRect(), clipPath(), clipRegion(). |
| 591 |
|
| 592 |
Saved SkCanvas state is put on a stack; multiple calls to save() should be balance |
| 593 |
by an equal number of calls to restore(). |
| 594 |
|
| 595 |
Call restoreToCount() with result to restore this and subsequent saves. |
| 596 |
|
| 597 |
@return depth of saved stack |
| 598 |
|
| 599 |
example: https://fiddle.skia.org/c/@Canvas_save |
| 600 |
*/ |
| 601 |
int save(); |
| 602 |
|
| 603 |
/** Saves SkMatrix and clip, and allocates a SkSurface for subsequent drawing. |
| 604 |
Calling restore() discards changes to SkMatrix and clip, and draws the SkSurface. |
| 605 |
|
| 606 |
SkMatrix may be changed by translate(), scale(), rotate(), skew(), concat(), |
| 607 |
setMatrix(), and resetMatrix(). Clip may be changed by clipRect(), clipRRect(), |
| 608 |
clipPath(), clipRegion(). |
| 609 |
|
| 610 |
SkRect bounds suggests but does not define the SkSurface size. To clip drawing to |
| 611 |
a specific rectangle, use clipRect(). |
| 612 |
|
| 613 |
Optional SkPaint paint applies alpha, SkColorFilter, SkImageFilter, and |
| 614 |
SkBlendMode when restore() is called. |
| 615 |
|
| 616 |
Call restoreToCount() with returned value to restore this and subsequent saves. |
| 617 |
|
| 618 |
@param bounds hint to limit the size of the layer; may be nullptr |
| 619 |
@param paint graphics state for layer; may be nullptr |
| 620 |
@return depth of saved stack |
| 621 |
|
| 622 |
example: https://fiddle.skia.org/c/@Canvas_saveLayer |
| 623 |
example: https://fiddle.skia.org/c/@Canvas_saveLayer_4 |
| 624 |
*/ |
| 625 |
int saveLayer(const SkRect* bounds, const SkPaint* paint); |
| 626 |
|
| 627 |
/** Saves SkMatrix and clip, and allocates a SkSurface for subsequent drawing. |
| 628 |
Calling restore() discards changes to SkMatrix and clip, and draws the SkSurface. |
| 629 |
|
| 630 |
SkMatrix may be changed by translate(), scale(), rotate(), skew(), concat(), |
| 631 |
setMatrix(), and resetMatrix(). Clip may be changed by clipRect(), clipRRect(), |
| 632 |
clipPath(), clipRegion(). |
| 633 |
|
| 634 |
SkRect bounds suggests but does not define the layer size. To clip drawing to |
| 635 |
a specific rectangle, use clipRect(). |
| 636 |
|
| 637 |
Optional SkPaint paint applies alpha, SkColorFilter, SkImageFilter, and |
| 638 |
SkBlendMode when restore() is called. |
| 639 |
|
| 640 |
Call restoreToCount() with returned value to restore this and subsequent saves. |
| 641 |
|
| 642 |
@param bounds hint to limit the size of layer; may be nullptr |
| 643 |
@param paint graphics state for layer; may be nullptr |
| 644 |
@return depth of saved stack |
| 645 |
*/ |
| 646 |
int saveLayer(const SkRect& bounds, const SkPaint* paint) { |
| 647 |
return this->saveLayer(&bounds, paint); |
| 648 |
} |
| 649 |
|
| 650 |
/** Saves SkMatrix and clip, and allocates SkSurface for subsequent drawing. |
| 651 |
|
| 652 |
Calling restore() discards changes to SkMatrix and clip, |
| 653 |
and blends layer with alpha opacity onto prior layer. |
| 654 |
|
| 655 |
SkMatrix may be changed by translate(), scale(), rotate(), skew(), concat(), |
| 656 |
setMatrix(), and resetMatrix(). Clip may be changed by clipRect(), clipRRect(), |
| 657 |
clipPath(), clipRegion(). |
| 658 |
|
| 659 |
SkRect bounds suggests but does not define layer size. To clip drawing to |
| 660 |
a specific rectangle, use clipRect(). |
| 661 |
|
| 662 |
alpha of zero is fully transparent, 1.0f is fully opaque. |
| 663 |
|
| 664 |
Call restoreToCount() with returned value to restore this and subsequent saves. |
| 665 |
|
| 666 |
@param bounds hint to limit the size of layer; may be nullptr |
| 667 |
@param alpha opacity of layer |
| 668 |
@return depth of saved stack |
| 669 |
|
| 670 |
example: https://fiddle.skia.org/c/@Canvas_saveLayerAlpha |
| 671 |
*/ |
| 672 |
int saveLayerAlphaf(const SkRect* bounds, float alpha); |
| 673 |
// Helper that accepts an int between 0 and 255, and divides it by 255.0 |
| 674 |
int saveLayerAlpha(const SkRect* bounds, U8CPU alpha) { |
| 675 |
return this->saveLayerAlphaf(bounds, alpha * (1.0f / 255)); |
| 676 |
} |
| 677 |
|
| 678 |
/** \enum SkCanvas::SaveLayerFlagsSet |
| 679 |
SaveLayerFlags provides options that may be used in any combination in SaveLayerRec, |
| 680 |
defining how layer allocated by saveLayer() operates. It may be set to zero, |
| 681 |
kPreserveLCDText_SaveLayerFlag, kInitWithPrevious_SaveLayerFlag, or both flags. |
| 682 |
*/ |
| 683 |
enum SaveLayerFlagsSet { |
| 684 |
kPreserveLCDText_SaveLayerFlag = 1 << 1, |
| 685 |
kInitWithPrevious_SaveLayerFlag = 1 << 2, //!< initializes with previous contents |
| 686 |
// instead of matching previous layer's colortype, use F16 |
| 687 |
kF16ColorType = 1 << 4, |
| 688 |
}; |
| 689 |
|
| 690 |
using SaveLayerFlags = uint32_t; |
| 691 |
using FilterSpan = SkSpan<sk_sp<SkImageFilter>>; |
| 692 |
static constexpr int kMaxFiltersPerLayer = 16; |
| 693 |
|
| 694 |
/** \struct SkCanvas::SaveLayerRec |
| 695 |
SaveLayerRec contains the state used to create the layer. |
| 696 |
*/ |
| 697 |
struct SaveLayerRec { |
| 698 |
/** Sets fBounds, fPaint, and fBackdrop to nullptr. Clears fSaveLayerFlags. |
| 699 |
|
| 700 |
@return empty SaveLayerRec |
| 701 |
*/ |
| 702 |
SaveLayerRec() {} |
| 703 |
|
| 704 |
/** Sets fBounds, fPaint, and fSaveLayerFlags; sets fBackdrop to nullptr. |
| 705 |
|
| 706 |
@param bounds layer dimensions; may be nullptr |
| 707 |
@param paint applied to layer when overlaying prior layer; may be nullptr |
| 708 |
@param saveLayerFlags SaveLayerRec options to modify layer |
| 709 |
@return SaveLayerRec with empty fBackdrop |
| 710 |
*/ |
| 711 |
SaveLayerRec(const SkRect* bounds, const SkPaint* paint, SaveLayerFlags saveLayerFlags = 0) |
| 712 |
: SaveLayerRec(bounds, paint, nullptr, nullptr, 1.f, SkTileMode::kClamp, |
| 713 |
saveLayerFlags, /*filters=*/{}) {} |
| 714 |
|
| 715 |
/** Sets fBounds, fPaint, fBackdrop, and fSaveLayerFlags. |
| 716 |
|
| 717 |
@param bounds layer dimensions; may be nullptr |
| 718 |
@param paint applied to layer when overlaying prior layer; |
| 719 |
may be nullptr |
| 720 |
@param backdrop If not null, this causes the current layer to be filtered by |
| 721 |
backdrop, and then drawn into the new layer |
| 722 |
(respecting the current clip). |
| 723 |
If null, the new layer is initialized with transparent-black. |
| 724 |
@param saveLayerFlags SaveLayerRec options to modify layer |
| 725 |
@return SaveLayerRec fully specified |
| 726 |
*/ |
| 727 |
SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop, |
| 728 |
SaveLayerFlags saveLayerFlags) |
| 729 |
: SaveLayerRec(bounds, paint, backdrop, nullptr, 1.f, SkTileMode::kClamp, |
| 730 |
saveLayerFlags, /*filters=*/{}) {} |
| 731 |
|
| 732 |
/** Sets fBounds, fBackdrop, fColorSpace, and fSaveLayerFlags. |
| 733 |
|
| 734 |
@param bounds layer dimensions; may be nullptr |
| 735 |
@param paint applied to layer when overlaying prior layer; |
| 736 |
may be nullptr |
| 737 |
@param backdrop If not null, this causes the current layer to be filtered by |
| 738 |
backdrop, and then drawn into the new layer |
| 739 |
(respecting the current clip). |
| 740 |
If null, the new layer is initialized with transparent-black. |
| 741 |
@param colorSpace If not null, when the layer is restored, a color space |
| 742 |
conversion will be applied from this color space to the |
| 743 |
parent's color space. The restore paint and backdrop filters will |
| 744 |
be applied in this color space. |
| 745 |
If null, the new layer will inherit the color space from its |
| 746 |
parent. |
| 747 |
@param saveLayerFlags SaveLayerRec options to modify layer |
| 748 |
@return SaveLayerRec fully specified |
| 749 |
*/ |
| 750 |
SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop, |
| 751 |
const SkColorSpace* colorSpace, SaveLayerFlags saveLayerFlags) |
| 752 |
: SaveLayerRec(bounds, paint, backdrop, colorSpace, 1.f, SkTileMode::kClamp, |
| 753 |
saveLayerFlags, /*filters=*/{}) {} |
| 754 |
|
| 755 |
|
| 756 |
/** Sets fBounds, fBackdrop, fBackdropTileMode, fColorSpace, and fSaveLayerFlags. |
| 757 |
|
| 758 |
@param bounds layer dimensions; may be nullptr |
| 759 |
@param paint applied to layer when overlaying prior layer; |
| 760 |
may be nullptr |
| 761 |
@param backdrop If not null, this causes the current layer to be filtered by |
| 762 |
backdrop, and then drawn into the new layer |
| 763 |
(respecting the current clip). |
| 764 |
If null, the new layer is initialized with transparent-black. |
| 765 |
@param backdropTileMode If the 'backdrop' is not null, or 'saveLayerFlags' has |
| 766 |
kInitWithPrevious set, this tile mode is used when the new layer |
| 767 |
would read outside the backdrop image's available content. |
| 768 |
@param colorSpace If not null, when the layer is restored, a color space |
| 769 |
conversion will be applied from this color space to the parent's |
| 770 |
color space. The restore paint and backdrop filters will be |
| 771 |
applied in this color space. |
| 772 |
If null, the new layer will inherit the color space from its |
| 773 |
parent. |
| 774 |
@param saveLayerFlags SaveLayerRec options to modify layer |
| 775 |
@return SaveLayerRec fully specified |
| 776 |
*/ |
| 777 |
SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop, |
| 778 |
SkTileMode backdropTileMode, const SkColorSpace* colorSpace, |
| 779 |
SaveLayerFlags saveLayerFlags) |
| 780 |
: SaveLayerRec(bounds, paint, backdrop, colorSpace, 1.f, backdropTileMode, |
| 781 |
saveLayerFlags, /*filters=*/{}) {} |
| 782 |
|
| 783 |
/** hints at layer size limit */ |
| 784 |
const SkRect* fBounds = nullptr; |
| 785 |
|
| 786 |
/** modifies overlay */ |
| 787 |
const SkPaint* fPaint = nullptr; |
| 788 |
|
| 789 |
FilterSpan fFilters = {}; |
| 790 |
|
| 791 |
/** |
| 792 |
* If not null, this triggers the same initialization behavior as setting |
| 793 |
* kInitWithPrevious_SaveLayerFlag on fSaveLayerFlags: the current layer is copied into |
| 794 |
* the new layer, rather than initializing the new layer with transparent-black. |
| 795 |
* This is then filtered by fBackdrop (respecting the current clip). |
| 796 |
*/ |
| 797 |
const SkImageFilter* fBackdrop = nullptr; |
| 798 |
|
| 799 |
/** |
| 800 |
* If the layer is initialized with prior content (and/or with a backdrop filter) and this |
| 801 |
* would require sampling outside of the available backdrop, this is the tilemode applied |
| 802 |
* to the boundary of the prior layer's image. |
| 803 |
*/ |
| 804 |
SkTileMode fBackdropTileMode = SkTileMode::kClamp; |
| 805 |
|
| 806 |
/** |
| 807 |
* If not null, this triggers a color space conversion when the layer is restored. It |
| 808 |
* will be as if the layer's contents are drawn in this color space. Filters from |
| 809 |
* fBackdrop and fPaint will be applied in this color space. |
| 810 |
*/ |
| 811 |
const SkColorSpace* fColorSpace = nullptr; |
| 812 |
|
| 813 |
/** preserves LCD text, creates with prior layer contents */ |
| 814 |
SaveLayerFlags fSaveLayerFlags = 0; |
| 815 |
|
| 816 |
private: |
| 817 |
friend class SkCanvas; |
| 818 |
friend class SkCanvasPriv; |
| 819 |
|
| 820 |
SaveLayerRec(const SkRect* bounds, |
| 821 |
const SkPaint* paint, |
| 822 |
const SkImageFilter* backdrop, |
| 823 |
const SkColorSpace* colorSpace, |
| 824 |
SkScalar backdropScale, |
| 825 |
SkTileMode backdropTileMode, |
| 826 |
SaveLayerFlags saveLayerFlags, |
| 827 |
FilterSpan filters) |
| 828 |
: fBounds(bounds) |
| 829 |
, fPaint(paint) |
| 830 |
, fFilters(filters) |
| 831 |
, fBackdrop(backdrop) |
| 832 |
, fBackdropTileMode(backdropTileMode) |
| 833 |
, fColorSpace(colorSpace) |
| 834 |
, fSaveLayerFlags(saveLayerFlags) |
| 835 |
, fExperimentalBackdropScale(backdropScale) { |
| 836 |
// We only allow the paint's image filter or the side-car list of filters -- not both. |
| 837 |
SkASSERT(fFilters.empty() || !paint || !paint->getImageFilter()); |
| 838 |
// To keep things reasonable (during deserialization), we limit filter list size. |
| 839 |
SkASSERT(fFilters.size() <= kMaxFiltersPerLayer); |
| 840 |
} |
| 841 |
|
| 842 |
// Relative scale factor that the image content used to initialize the layer when the |
| 843 |
// kInitFromPrevious flag or a backdrop filter is used. |
| 844 |
SkScalar fExperimentalBackdropScale = 1.f; |
| 845 |
}; |
| 846 |
|
| 847 |
/** Saves SkMatrix and clip, and allocates SkSurface for subsequent drawing. |
| 848 |
|
| 849 |
Calling restore() discards changes to SkMatrix and clip, |
| 850 |
and blends SkSurface with alpha opacity onto the prior layer. |
| 851 |
|
| 852 |
SkMatrix may be changed by translate(), scale(), rotate(), skew(), concat(), |
| 853 |
setMatrix(), and resetMatrix(). Clip may be changed by clipRect(), clipRRect(), |
| 854 |
clipPath(), clipRegion(). |
| 855 |
|
| 856 |
SaveLayerRec contains the state used to create the layer. |
| 857 |
|
| 858 |
Call restoreToCount() with returned value to restore this and subsequent saves. |
| 859 |
|
| 860 |
@param layerRec layer state |
| 861 |
@return depth of save state stack before this call was made. |
| 862 |
|
| 863 |
example: https://fiddle.skia.org/c/@Canvas_saveLayer_3 |
| 864 |
*/ |
| 865 |
int saveLayer(const SaveLayerRec& layerRec); |
| 866 |
|
| 867 |
/** Removes changes to SkMatrix and clip since SkCanvas state was |
| 868 |
last saved. The state is removed from the stack. |
| 869 |
|
| 870 |
Does nothing if the stack is empty. |
| 871 |
|
| 872 |
example: https://fiddle.skia.org/c/@AutoCanvasRestore_restore |
| 873 |
|
| 874 |
example: https://fiddle.skia.org/c/@Canvas_restore |
| 875 |
*/ |
| 876 |
void restore(); |
| 877 |
|
| 878 |
/** Returns the number of saved states, each containing: SkMatrix and clip. |
| 879 |
Equals the number of save() calls less the number of restore() calls plus one. |
| 880 |
The save count of a new canvas is one. |
| 881 |
|
| 882 |
@return depth of save state stack |
| 883 |
|
| 884 |
example: https://fiddle.skia.org/c/@Canvas_getSaveCount |
| 885 |
*/ |
| 886 |
int getSaveCount() const; |
| 887 |
|
| 888 |
/** Restores state to SkMatrix and clip values when save(), saveLayer(), |
| 889 |
saveLayerPreserveLCDTextRequests(), or saveLayerAlpha() returned saveCount. |
| 890 |
|
| 891 |
Does nothing if saveCount is greater than state stack count. |
| 892 |
Restores state to initial values if saveCount is less than or equal to one. |
| 893 |
|
| 894 |
@param saveCount depth of state stack to restore |
| 895 |
|
| 896 |
example: https://fiddle.skia.org/c/@Canvas_restoreToCount |
| 897 |
*/ |
| 898 |
void restoreToCount(int saveCount); |
| 899 |
|
| 900 |
/** Translates SkMatrix by dx along the x-axis and dy along the y-axis. |
| 901 |
|
| 902 |
Mathematically, replaces SkMatrix with a translation matrix |
| 903 |
premultiplied with SkMatrix. |
| 904 |
|
| 905 |
This has the effect of moving the drawing by (dx, dy) before transforming |
| 906 |
the result with SkMatrix. |
| 907 |
|
| 908 |
@param dx distance to translate on x-axis |
| 909 |
@param dy distance to translate on y-axis |
| 910 |
|
| 911 |
example: https://fiddle.skia.org/c/@Canvas_translate |
| 912 |
*/ |
| 913 |
void translate(SkScalar dx, SkScalar dy); |
| 914 |
|
| 915 |
/** Scales SkMatrix by sx on the x-axis and sy on the y-axis. |
| 916 |
|
| 917 |
Mathematically, replaces SkMatrix with a scale matrix |
| 918 |
premultiplied with SkMatrix. |
| 919 |
|
| 920 |
This has the effect of scaling the drawing by (sx, sy) before transforming |
| 921 |
the result with SkMatrix. |
| 922 |
|
| 923 |
@param sx amount to scale on x-axis |
| 924 |
@param sy amount to scale on y-axis |
| 925 |
|
| 926 |
example: https://fiddle.skia.org/c/@Canvas_scale |
| 927 |
*/ |
| 928 |
void scale(SkScalar sx, SkScalar sy); |
| 929 |
|
| 930 |
/** Rotates SkMatrix by degrees. Positive degrees rotates clockwise. |
| 931 |
|
| 932 |
Mathematically, replaces SkMatrix with a rotation matrix |
| 933 |
premultiplied with SkMatrix. |
| 934 |
|
| 935 |
This has the effect of rotating the drawing by degrees before transforming |
| 936 |
the result with SkMatrix. |
| 937 |
|
| 938 |
@param degrees amount to rotate, in degrees |
| 939 |
|
| 940 |
example: https://fiddle.skia.org/c/@Canvas_rotate |
| 941 |
*/ |
| 942 |
void rotate(SkScalar degrees); |
| 943 |
|
| 944 |
/** Rotates SkMatrix by degrees about a point at (px, py). Positive degrees rotates |
| 945 |
clockwise. |
| 946 |
|
| 947 |
Mathematically, constructs a rotation matrix; premultiplies the rotation matrix by |
| 948 |
a translation matrix; then replaces SkMatrix with the resulting matrix |
| 949 |
premultiplied with SkMatrix. |
| 950 |
|
| 951 |
This has the effect of rotating the drawing about a given point before |
| 952 |
transforming the result with SkMatrix. |
| 953 |
|
| 954 |
@param degrees amount to rotate, in degrees |
| 955 |
@param px x-axis value of the point to rotate about |
| 956 |
@param py y-axis value of the point to rotate about |
| 957 |
|
| 958 |
example: https://fiddle.skia.org/c/@Canvas_rotate_2 |
| 959 |
*/ |
| 960 |
void rotate(SkScalar degrees, SkScalar px, SkScalar py); |
| 961 |
|
| 962 |
/** Skews SkMatrix by sx on the x-axis and sy on the y-axis. A positive value of sx |
| 963 |
skews the drawing right as y-axis values increase; a positive value of sy skews |
| 964 |
the drawing down as x-axis values increase. |
| 965 |
|
| 966 |
Mathematically, replaces SkMatrix with a skew matrix premultiplied with SkMatrix. |
| 967 |
|
| 968 |
This has the effect of skewing the drawing by (sx, sy) before transforming |
| 969 |
the result with SkMatrix. |
| 970 |
|
| 971 |
@param sx amount to skew on x-axis |
| 972 |
@param sy amount to skew on y-axis |
| 973 |
|
| 974 |
example: https://fiddle.skia.org/c/@Canvas_skew |
| 975 |
*/ |
| 976 |
void skew(SkScalar sx, SkScalar sy); |
| 977 |
|
| 978 |
/** Replaces SkMatrix with matrix premultiplied with existing SkMatrix. |
| 979 |
|
| 980 |
This has the effect of transforming the drawn geometry by matrix, before |
| 981 |
transforming the result with existing SkMatrix. |
| 982 |
|
| 983 |
@param matrix matrix to premultiply with existing SkMatrix |
| 984 |
|
| 985 |
example: https://fiddle.skia.org/c/@Canvas_concat |
| 986 |
*/ |
| 987 |
void concat(const SkMatrix& matrix); |
| 988 |
void concat(const SkM44&); |
| 989 |
|
| 990 |
/** Replaces SkMatrix with matrix. |
| 991 |
Unlike concat(), any prior matrix state is overwritten. |
| 992 |
|
| 993 |
@param matrix matrix to copy, replacing existing SkMatrix |
| 994 |
|
| 995 |
example: https://fiddle.skia.org/c/@Canvas_setMatrix |
| 996 |
*/ |
| 997 |
void setMatrix(const SkM44& matrix); |
| 998 |
|
| 999 |
// DEPRECATED -- use SkM44 version |
| 1000 |
void setMatrix(const SkMatrix& matrix); |
| 1001 |
|
| 1002 |
/** Sets SkMatrix to the identity matrix. |
| 1003 |
Any prior matrix state is overwritten. |
| 1004 |
|
| 1005 |
example: https://fiddle.skia.org/c/@Canvas_resetMatrix |
| 1006 |
*/ |
| 1007 |
void resetMatrix(); |
| 1008 |
|
| 1009 |
/** Replaces clip with the intersection or difference of clip and rect, |
| 1010 |
with an aliased or anti-aliased clip edge. rect is transformed by SkMatrix |
| 1011 |
before it is combined with clip. |
| 1012 |
|
| 1013 |
@param rect SkRect to combine with clip |
| 1014 |
@param op SkClipOp to apply to clip |
| 1015 |
@param doAntiAlias true if clip is to be anti-aliased |
| 1016 |
|
| 1017 |
example: https://fiddle.skia.org/c/@Canvas_clipRect |
| 1018 |
*/ |
| 1019 |
void clipRect(const SkRect& rect, SkClipOp op, bool doAntiAlias); |
| 1020 |
|
| 1021 |
/** Replaces clip with the intersection or difference of clip and rect. |
| 1022 |
Resulting clip is aliased; pixels are fully contained by the clip. |
| 1023 |
rect is transformed by SkMatrix before it is combined with clip. |
| 1024 |
|
| 1025 |
@param rect SkRect to combine with clip |
| 1026 |
@param op SkClipOp to apply to clip |
| 1027 |
*/ |
| 1028 |
void clipRect(const SkRect& rect, SkClipOp op) { |
| 1029 |
this->clipRect(rect, op, false); |
| 1030 |
} |
| 1031 |
|
| 1032 |
/** Replaces clip with the intersection of clip and rect. |
| 1033 |
Resulting clip is aliased; pixels are fully contained by the clip. |
| 1034 |
rect is transformed by SkMatrix |
| 1035 |
before it is combined with clip. |
| 1036 |
|
| 1037 |
@param rect SkRect to combine with clip |
| 1038 |
@param doAntiAlias true if clip is to be anti-aliased |
| 1039 |
*/ |
| 1040 |
void clipRect(const SkRect& rect, bool doAntiAlias = false) { |
| 1041 |
this->clipRect(rect, SkClipOp::kIntersect, doAntiAlias); |
| 1042 |
} |
| 1043 |
|
| 1044 |
void clipIRect(const SkIRect& irect, SkClipOp op = SkClipOp::kIntersect) { |
| 1045 |
this->clipRect(SkRect::Make(irect), op, false); |
| 1046 |
} |
| 1047 |
|
| 1048 |
/** Sets the maximum clip rectangle, which can be set by clipRect(), clipRRect() and |
| 1049 |
clipPath() and intersect the current clip with the specified rect. |
| 1050 |
The maximum clip affects only future clipping operations; it is not retroactive. |
| 1051 |
The clip restriction is not recorded in pictures. |
| 1052 |
|
| 1053 |
Pass an empty rect to disable maximum clip. |
| 1054 |
This private API is for use by Android framework only. |
| 1055 |
|
| 1056 |
DEPRECATED: Replace usage with SkAndroidFrameworkUtils::replaceClip() |
| 1057 |
|
| 1058 |
@param rect maximum allowed clip in device coordinates |
| 1059 |
*/ |
| 1060 |
void androidFramework_setDeviceClipRestriction(const SkIRect& rect); |
| 1061 |
|
| 1062 |
/** Replaces clip with the intersection or difference of clip and rrect, |
| 1063 |
with an aliased or anti-aliased clip edge. |
| 1064 |
rrect is transformed by SkMatrix |
| 1065 |
before it is combined with clip. |
| 1066 |
|
| 1067 |
@param rrect SkRRect to combine with clip |
| 1068 |
@param op SkClipOp to apply to clip |
| 1069 |
@param doAntiAlias true if clip is to be anti-aliased |
| 1070 |
|
| 1071 |
example: https://fiddle.skia.org/c/@Canvas_clipRRect |
| 1072 |
*/ |
| 1073 |
void clipRRect(const SkRRect& rrect, SkClipOp op, bool doAntiAlias); |
| 1074 |
|
| 1075 |
/** Replaces clip with the intersection or difference of clip and rrect. |
| 1076 |
Resulting clip is aliased; pixels are fully contained by the clip. |
| 1077 |
rrect is transformed by SkMatrix before it is combined with clip. |
| 1078 |
|
| 1079 |
@param rrect SkRRect to combine with clip |
| 1080 |
@param op SkClipOp to apply to clip |
| 1081 |
*/ |
| 1082 |
void clipRRect(const SkRRect& rrect, SkClipOp op) { |
| 1083 |
this->clipRRect(rrect, op, false); |
| 1084 |
} |
| 1085 |
|
| 1086 |
/** Replaces clip with the intersection of clip and rrect, |
| 1087 |
with an aliased or anti-aliased clip edge. |
| 1088 |
rrect is transformed by SkMatrix before it is combined with clip. |
| 1089 |
|
| 1090 |
@param rrect SkRRect to combine with clip |
| 1091 |
@param doAntiAlias true if clip is to be anti-aliased |
| 1092 |
*/ |
| 1093 |
void clipRRect(const SkRRect& rrect, bool doAntiAlias = false) { |
| 1094 |
this->clipRRect(rrect, SkClipOp::kIntersect, doAntiAlias); |
| 1095 |
} |
| 1096 |
|
| 1097 |
/** Replaces clip with the intersection or difference of clip and path, |
| 1098 |
with an aliased or anti-aliased clip edge. SkPath::FillType determines if path |
| 1099 |
describes the area inside or outside its contours; and if path contour overlaps |
| 1100 |
itself or another path contour, whether the overlaps form part of the area. |
| 1101 |
path is transformed by SkMatrix before it is combined with clip. |
| 1102 |
|
| 1103 |
@param path SkPath to combine with clip |
| 1104 |
@param op SkClipOp to apply to clip |
| 1105 |
@param doAntiAlias true if clip is to be anti-aliased |
| 1106 |
|
| 1107 |
example: https://fiddle.skia.org/c/@Canvas_clipPath |
| 1108 |
*/ |
| 1109 |
void clipPath(const SkPath& path, SkClipOp op, bool doAntiAlias); |
| 1110 |
|
| 1111 |
/** Replaces clip with the intersection or difference of clip and path. |
| 1112 |
Resulting clip is aliased; pixels are fully contained by the clip. |
| 1113 |
SkPath::FillType determines if path |
| 1114 |
describes the area inside or outside its contours; and if path contour overlaps |
| 1115 |
itself or another path contour, whether the overlaps form part of the area. |
| 1116 |
path is transformed by SkMatrix |
| 1117 |
before it is combined with clip. |
| 1118 |
|
| 1119 |
@param path SkPath to combine with clip |
| 1120 |
@param op SkClipOp to apply to clip |
| 1121 |
*/ |
| 1122 |
void clipPath(const SkPath& path, SkClipOp op) { |
| 1123 |
this->clipPath(path, op, false); |
| 1124 |
} |
| 1125 |
|
| 1126 |
/** Replaces clip with the intersection of clip and path. |
| 1127 |
Resulting clip is aliased; pixels are fully contained by the clip. |
| 1128 |
SkPath::FillType determines if path |
| 1129 |
describes the area inside or outside its contours; and if path contour overlaps |
| 1130 |
itself or another path contour, whether the overlaps form part of the area. |
| 1131 |
path is transformed by SkMatrix before it is combined with clip. |
| 1132 |
|
| 1133 |
@param path SkPath to combine with clip |
| 1134 |
@param doAntiAlias true if clip is to be anti-aliased |
| 1135 |
*/ |
| 1136 |
void clipPath(const SkPath& path, bool doAntiAlias = false) { |
| 1137 |
this->clipPath(path, SkClipOp::kIntersect, doAntiAlias); |
| 1138 |
} |
| 1139 |
|
| 1140 |
void clipShader(sk_sp<SkShader>, SkClipOp = SkClipOp::kIntersect); |
| 1141 |
|
| 1142 |
/** Replaces clip with the intersection or difference of clip and SkRegion deviceRgn. |
| 1143 |
Resulting clip is aliased; pixels are fully contained by the clip. |
| 1144 |
deviceRgn is unaffected by SkMatrix. |
| 1145 |
|
| 1146 |
@param deviceRgn SkRegion to combine with clip |
| 1147 |
@param op SkClipOp to apply to clip |
| 1148 |
|
| 1149 |
example: https://fiddle.skia.org/c/@Canvas_clipRegion |
| 1150 |
*/ |
| 1151 |
void clipRegion(const SkRegion& deviceRgn, SkClipOp op = SkClipOp::kIntersect); |
| 1152 |
|
| 1153 |
/** Returns true if SkRect rect, transformed by SkMatrix, can be quickly determined to be |
| 1154 |
outside of clip. May return false even though rect is outside of clip. |
| 1155 |
|
| 1156 |
Use to check if an area to be drawn is clipped out, to skip subsequent draw calls. |
| 1157 |
|
| 1158 |
@param rect SkRect to compare with clip |
| 1159 |
@return true if rect, transformed by SkMatrix, does not intersect clip |
| 1160 |
|
| 1161 |
example: https://fiddle.skia.org/c/@Canvas_quickReject |
| 1162 |
*/ |
| 1163 |
bool quickReject(const SkRect& rect) const; |
| 1164 |
|
| 1165 |
/** Returns true if path, transformed by SkMatrix, can be quickly determined to be |
| 1166 |
outside of clip. May return false even though path is outside of clip. |
| 1167 |
|
| 1168 |
Use to check if an area to be drawn is clipped out, to skip subsequent draw calls. |
| 1169 |
|
| 1170 |
@param path SkPath to compare with clip |
| 1171 |
@return true if path, transformed by SkMatrix, does not intersect clip |
| 1172 |
|
| 1173 |
example: https://fiddle.skia.org/c/@Canvas_quickReject_2 |
| 1174 |
*/ |
| 1175 |
bool quickReject(const SkPath& path) const; |
| 1176 |
|
| 1177 |
/** Returns bounds of clip, transformed by inverse of SkMatrix. If clip is empty, |
| 1178 |
return SkRect::MakeEmpty, where all SkRect sides equal zero. |
| 1179 |
|
| 1180 |
SkRect returned is outset by one to account for partial pixel coverage if clip |
| 1181 |
is anti-aliased. |
| 1182 |
|
| 1183 |
@return bounds of clip in local coordinates |
| 1184 |
|
| 1185 |
example: https://fiddle.skia.org/c/@Canvas_getLocalClipBounds |
| 1186 |
*/ |
| 1187 |
SkRect getLocalClipBounds() const; |
| 1188 |
|
| 1189 |
/** Returns bounds of clip, transformed by inverse of SkMatrix. If clip is empty, |
| 1190 |
return false, and set bounds to SkRect::MakeEmpty, where all SkRect sides equal zero. |
| 1191 |
|
| 1192 |
bounds is outset by one to account for partial pixel coverage if clip |
| 1193 |
is anti-aliased. |
| 1194 |
|
| 1195 |
@param bounds SkRect of clip in local coordinates |
| 1196 |
@return true if clip bounds is not empty |
| 1197 |
*/ |
| 1198 |
bool getLocalClipBounds(SkRect* bounds) const { |
| 1199 |
*bounds = this->getLocalClipBounds(); |
| 1200 |
return !bounds->isEmpty(); |
| 1201 |
} |
| 1202 |
|
| 1203 |
/** Returns SkIRect bounds of clip, unaffected by SkMatrix. If clip is empty, |
| 1204 |
return SkRect::MakeEmpty, where all SkRect sides equal zero. |
| 1205 |
|
| 1206 |
Unlike getLocalClipBounds(), returned SkIRect is not outset. |
| 1207 |
|
| 1208 |
@return bounds of clip in base device coordinates |
| 1209 |
|
| 1210 |
example: https://fiddle.skia.org/c/@Canvas_getDeviceClipBounds |
| 1211 |
*/ |
| 1212 |
SkIRect getDeviceClipBounds() const; |
| 1213 |
|
| 1214 |
/** Returns SkIRect bounds of clip, unaffected by SkMatrix. If clip is empty, |
| 1215 |
return false, and set bounds to SkRect::MakeEmpty, where all SkRect sides equal zero. |
| 1216 |
|
| 1217 |
Unlike getLocalClipBounds(), bounds is not outset. |
| 1218 |
|
| 1219 |
@param bounds SkRect of clip in device coordinates |
| 1220 |
@return true if clip bounds is not empty |
| 1221 |
*/ |
| 1222 |
bool getDeviceClipBounds(SkIRect* bounds) const { |
| 1223 |
*bounds = this->getDeviceClipBounds(); |
| 1224 |
return !bounds->isEmpty(); |
| 1225 |
} |
| 1226 |
|
| 1227 |
/** Fills clip with color color. |
| 1228 |
mode determines how ARGB is combined with destination. |
| 1229 |
|
| 1230 |
@param color unpremultiplied ARGB |
| 1231 |
@param mode SkBlendMode used to combine source color and destination |
| 1232 |
|
| 1233 |
example: https://fiddle.skia.org/c/@Canvas_drawColor |
| 1234 |
*/ |
| 1235 |
void drawColor(SkColor color, SkBlendMode mode = SkBlendMode::kSrcOver) { |
| 1236 |
this->drawColor(SkColor4f::FromColor(color), mode); |
| 1237 |
} |
| 1238 |
|
| 1239 |
/** Fills clip with color color. |
| 1240 |
mode determines how ARGB is combined with destination. |
| 1241 |
|
| 1242 |
@param color SkColor4f representing unpremultiplied color. |
| 1243 |
@param mode SkBlendMode used to combine source color and destination |
| 1244 |
*/ |
| 1245 |
void drawColor(const SkColor4f& color, SkBlendMode mode = SkBlendMode::kSrcOver); |
| 1246 |
|
| 1247 |
/** Fills clip with color color using SkBlendMode::kSrc. |
| 1248 |
This has the effect of replacing all pixels contained by clip with color. |
| 1249 |
|
| 1250 |
@param color unpremultiplied ARGB |
| 1251 |
*/ |
| 1252 |
void clear(SkColor color) { |
| 1253 |
this->clear(SkColor4f::FromColor(color)); |
| 1254 |
} |
| 1255 |
|
| 1256 |
/** Fills clip with color color using SkBlendMode::kSrc. |
| 1257 |
This has the effect of replacing all pixels contained by clip with color. |
| 1258 |
|
| 1259 |
@param color SkColor4f representing unpremultiplied color. |
| 1260 |
*/ |
| 1261 |
void clear(const SkColor4f& color) { |
| 1262 |
this->drawColor(color, SkBlendMode::kSrc); |
| 1263 |
} |
| 1264 |
|
| 1265 |
/** Makes SkCanvas contents undefined. Subsequent calls that read SkCanvas pixels, |
| 1266 |
such as drawing with SkBlendMode, return undefined results. discard() does |
| 1267 |
not change clip or SkMatrix. |
| 1268 |
|
| 1269 |
discard() may do nothing, depending on the implementation of SkSurface or SkDevice |
| 1270 |
that created SkCanvas. |
| 1271 |
|
| 1272 |
discard() allows optimized performance on subsequent draws by removing |
| 1273 |
cached data associated with SkSurface or SkDevice. |
| 1274 |
It is not necessary to call discard() once done with SkCanvas; |
| 1275 |
any cached data is deleted when owning SkSurface or SkDevice is deleted. |
| 1276 |
*/ |
| 1277 |
void discard() { this->onDiscard(); } |
| 1278 |
|
| 1279 |
/** Fills clip with SkPaint paint. SkPaint components, SkShader, |
| 1280 |
SkColorFilter, SkImageFilter, and SkBlendMode affect drawing; |
| 1281 |
SkMaskFilter and SkPathEffect in paint are ignored. |
| 1282 |
|
| 1283 |
@param paint graphics state used to fill SkCanvas |
| 1284 |
|
| 1285 |
example: https://fiddle.skia.org/c/@Canvas_drawPaint |
| 1286 |
*/ |
| 1287 |
void drawPaint(const SkPaint& paint); |
| 1288 |
|
| 1289 |
/** \enum SkCanvas::PointMode |
| 1290 |
Selects if an array of points are drawn as discrete points, as lines, or as |
| 1291 |
an open polygon. |
| 1292 |
*/ |
| 1293 |
enum PointMode { |
| 1294 |
kPoints_PointMode, //!< draw each point separately |
| 1295 |
kLines_PointMode, //!< draw each pair of points as a line segment |
| 1296 |
kPolygon_PointMode, //!< draw the array of points as a open polygon |
| 1297 |
}; |
| 1298 |
|
| 1299 |
/** Draws pts using clip, SkMatrix and SkPaint paint. |
| 1300 |
count is the number of points; if count is less than one, has no effect. |
| 1301 |
mode may be one of: kPoints_PointMode, kLines_PointMode, or kPolygon_PointMode. |
| 1302 |
|
| 1303 |
If mode is kPoints_PointMode, the shape of point drawn depends on paint |
| 1304 |
SkPaint::Cap. If paint is set to SkPaint::kRound_Cap, each point draws a |
| 1305 |
circle of diameter SkPaint stroke width. If paint is set to SkPaint::kSquare_Cap |
| 1306 |
or SkPaint::kButt_Cap, each point draws a square of width and height |
| 1307 |
SkPaint stroke width. |
| 1308 |
|
| 1309 |
If mode is kLines_PointMode, each pair of points draws a line segment. |
| 1310 |
One line is drawn for every two points; each point is used once. If count is odd, |
| 1311 |
the final point is ignored. |
| 1312 |
|
| 1313 |
If mode is kPolygon_PointMode, each adjacent pair of points draws a line segment. |
| 1314 |
count minus one lines are drawn; the first and last point are used once. |
| 1315 |
|
| 1316 |
Each line segment respects paint SkPaint::Cap and SkPaint stroke width. |
| 1317 |
SkPaint::Style is ignored, as if were set to SkPaint::kStroke_Style. |
| 1318 |
|
| 1319 |
Always draws each element one at a time; is not affected by |
| 1320 |
SkPaint::Join, and unlike drawPath(), does not create a mask from all points |
| 1321 |
and lines before drawing. |
| 1322 |
|
| 1323 |
@param mode whether pts draws points or lines |
| 1324 |
@param count number of points in the array |
| 1325 |
@param pts array of points to draw |
| 1326 |
@param paint stroke, blend, color, and so on, used to draw |
| 1327 |
|
| 1328 |
example: https://fiddle.skia.org/c/@Canvas_drawPoints |
| 1329 |
*/ |
| 1330 |
void drawPoints(PointMode mode, SkSpan<const SkPoint>, const SkPaint& paint); |
| 1331 |
#ifdef SK_SUPPORT_UNSPANNED_APIS |
| 1332 |
void drawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint& paint) { |
| 1333 |
this->drawPoints(mode, {pts, count}, paint); |
| 1334 |
} |
| 1335 |
#endif |
| 1336 |
|
| 1337 |
/** Draws point at (x, y) using clip, SkMatrix and SkPaint paint. |
| 1338 |
|
| 1339 |
The shape of point drawn depends on paint SkPaint::Cap. |
| 1340 |
If paint is set to SkPaint::kRound_Cap, draw a circle of diameter |
| 1341 |
SkPaint stroke width. If paint is set to SkPaint::kSquare_Cap or SkPaint::kButt_Cap, |
| 1342 |
draw a square of width and height SkPaint stroke width. |
| 1343 |
SkPaint::Style is ignored, as if were set to SkPaint::kStroke_Style. |
| 1344 |
|
| 1345 |
@param x left edge of circle or square |
| 1346 |
@param y top edge of circle or square |
| 1347 |
@param paint stroke, blend, color, and so on, used to draw |
| 1348 |
|
| 1349 |
example: https://fiddle.skia.org/c/@Canvas_drawPoint |
| 1350 |
*/ |
| 1351 |
void drawPoint(SkScalar x, SkScalar y, const SkPaint& paint); |
| 1352 |
|
| 1353 |
/** Draws point p using clip, SkMatrix and SkPaint paint. |
| 1354 |
|
| 1355 |
The shape of point drawn depends on paint SkPaint::Cap. |
| 1356 |
If paint is set to SkPaint::kRound_Cap, draw a circle of diameter |
| 1357 |
SkPaint stroke width. If paint is set to SkPaint::kSquare_Cap or SkPaint::kButt_Cap, |
| 1358 |
draw a square of width and height SkPaint stroke width. |
| 1359 |
SkPaint::Style is ignored, as if were set to SkPaint::kStroke_Style. |
| 1360 |
|
| 1361 |
@param p top-left edge of circle or square |
| 1362 |
@param paint stroke, blend, color, and so on, used to draw |
| 1363 |
*/ |
| 1364 |
void drawPoint(SkPoint p, const SkPaint& paint) { |
| 1365 |
this->drawPoint(p.x(), p.y(), paint); |
| 1366 |
} |
| 1367 |
|
| 1368 |
/** Draws line segment from (x0, y0) to (x1, y1) using clip, SkMatrix, and SkPaint paint. |
| 1369 |
In paint: SkPaint stroke width describes the line thickness; |
| 1370 |
SkPaint::Cap draws the end rounded or square; |
| 1371 |
SkPaint::Style is ignored, as if were set to SkPaint::kStroke_Style. |
| 1372 |
|
| 1373 |
@param x0 start of line segment on x-axis |
| 1374 |
@param y0 start of line segment on y-axis |
| 1375 |
@param x1 end of line segment on x-axis |
| 1376 |
@param y1 end of line segment on y-axis |
| 1377 |
@param paint stroke, blend, color, and so on, used to draw |
| 1378 |
|
| 1379 |
example: https://fiddle.skia.org/c/@Canvas_drawLine |
| 1380 |
*/ |
| 1381 |
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint& paint); |
| 1382 |
|
| 1383 |
/** Draws line segment from p0 to p1 using clip, SkMatrix, and SkPaint paint. |
| 1384 |
In paint: SkPaint stroke width describes the line thickness; |
| 1385 |
SkPaint::Cap draws the end rounded or square; |
| 1386 |
SkPaint::Style is ignored, as if were set to SkPaint::kStroke_Style. |
| 1387 |
|
| 1388 |
@param p0 start of line segment |
| 1389 |
@param p1 end of line segment |
| 1390 |
@param paint stroke, blend, color, and so on, used to draw |
| 1391 |
*/ |
| 1392 |
void drawLine(SkPoint p0, SkPoint p1, const SkPaint& paint) { |
| 1393 |
this->drawLine(p0.x(), p0.y(), p1.x(), p1.y(), paint); |
| 1394 |
} |
| 1395 |
|
| 1396 |
/** Draws SkRect rect using clip, SkMatrix, and SkPaint paint. |
| 1397 |
In paint: SkPaint::Style determines if rectangle is stroked or filled; |
| 1398 |
if stroked, SkPaint stroke width describes the line thickness, and |
| 1399 |
SkPaint::Join draws the corners rounded or square. |
| 1400 |
|
| 1401 |
@param rect rectangle to draw |
| 1402 |
@param paint stroke or fill, blend, color, and so on, used to draw |
| 1403 |
|
| 1404 |
example: https://fiddle.skia.org/c/@Canvas_drawRect |
| 1405 |
*/ |
| 1406 |
void drawRect(const SkRect& rect, const SkPaint& paint); |
| 1407 |
|
| 1408 |
/** Draws SkIRect rect using clip, SkMatrix, and SkPaint paint. |
| 1409 |
In paint: SkPaint::Style determines if rectangle is stroked or filled; |
| 1410 |
if stroked, SkPaint stroke width describes the line thickness, and |
| 1411 |
SkPaint::Join draws the corners rounded or square. |
| 1412 |
|
| 1413 |
@param rect rectangle to draw |
| 1414 |
@param paint stroke or fill, blend, color, and so on, used to draw |
| 1415 |
*/ |
| 1416 |
void drawIRect(const SkIRect& rect, const SkPaint& paint) { |
| 1417 |
SkRect r; |
| 1418 |
r.set(rect); // promotes the ints to scalars |
| 1419 |
this->drawRect(r, paint); |
| 1420 |
} |
| 1421 |
|
| 1422 |
/** Draws SkRegion region using clip, SkMatrix, and SkPaint paint. |
| 1423 |
In paint: SkPaint::Style determines if rectangle is stroked or filled; |
| 1424 |
if stroked, SkPaint stroke width describes the line thickness, and |
| 1425 |
SkPaint::Join draws the corners rounded or square. |
| 1426 |
|
| 1427 |
@param region region to draw |
| 1428 |
@param paint SkPaint stroke or fill, blend, color, and so on, used to draw |
| 1429 |
|
| 1430 |
example: https://fiddle.skia.org/c/@Canvas_drawRegion |
| 1431 |
*/ |
| 1432 |
void drawRegion(const SkRegion& region, const SkPaint& paint); |
| 1433 |
|
| 1434 |
/** Draws oval oval using clip, SkMatrix, and SkPaint. |
| 1435 |
In paint: SkPaint::Style determines if oval is stroked or filled; |
| 1436 |
if stroked, SkPaint stroke width describes the line thickness. |
| 1437 |
|
| 1438 |
@param oval SkRect bounds of oval |
| 1439 |
@param paint SkPaint stroke or fill, blend, color, and so on, used to draw |
| 1440 |
|
| 1441 |
example: https://fiddle.skia.org/c/@Canvas_drawOval |
| 1442 |
*/ |
| 1443 |
void drawOval(const SkRect& oval, const SkPaint& paint); |
| 1444 |
|
| 1445 |
/** Draws SkRRect rrect using clip, SkMatrix, and SkPaint paint. |
| 1446 |
In paint: SkPaint::Style determines if rrect is stroked or filled; |
| 1447 |
if stroked, SkPaint stroke width describes the line thickness. |
| 1448 |
|
| 1449 |
rrect may represent a rectangle, circle, oval, uniformly rounded rectangle, or |
| 1450 |
may have any combination of positive non-square radii for the four corners. |
| 1451 |
|
| 1452 |
@param rrect SkRRect with up to eight corner radii to draw |
| 1453 |
@param paint SkPaint stroke or fill, blend, color, and so on, used to draw |
| 1454 |
|
| 1455 |
example: https://fiddle.skia.org/c/@Canvas_drawRRect |
| 1456 |
*/ |
| 1457 |
void drawRRect(const SkRRect& rrect, const SkPaint& paint); |
| 1458 |
|
| 1459 |
/** Draws SkRRect outer and inner |
| 1460 |
using clip, SkMatrix, and SkPaint paint. |
| 1461 |
outer must contain inner or the drawing is undefined. |
| 1462 |
In paint: SkPaint::Style determines if SkRRect is stroked or filled; |
| 1463 |
if stroked, SkPaint stroke width describes the line thickness. |
| 1464 |
If stroked and SkRRect corner has zero length radii, SkPaint::Join can |
| 1465 |
draw corners rounded or square. |
| 1466 |
|
| 1467 |
GPU-backed platforms optimize drawing when both outer and inner are |
| 1468 |
concave and outer contains inner. These platforms may not be able to draw |
| 1469 |
SkPath built with identical data as fast. |
| 1470 |
|
| 1471 |
@param outer SkRRect outer bounds to draw |
| 1472 |
@param inner SkRRect inner bounds to draw |
| 1473 |
@param paint SkPaint stroke or fill, blend, color, and so on, used to draw |
| 1474 |
|
| 1475 |
example: https://fiddle.skia.org/c/@Canvas_drawDRRect_a |
| 1476 |
example: https://fiddle.skia.org/c/@Canvas_drawDRRect_b |
| 1477 |
*/ |
| 1478 |
void drawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint); |
| 1479 |
|
| 1480 |
/** Draws circle at (cx, cy) with radius using clip, SkMatrix, and SkPaint paint. |
| 1481 |
If radius is zero or less, nothing is drawn. |
| 1482 |
In paint: SkPaint::Style determines if circle is stroked or filled; |
| 1483 |
if stroked, SkPaint stroke width describes the line thickness. |
| 1484 |
|
| 1485 |
@param cx circle center on the x-axis |
| 1486 |
@param cy circle center on the y-axis |
| 1487 |
@param radius half the diameter of circle |
| 1488 |
@param paint SkPaint stroke or fill, blend, color, and so on, used to draw |
| 1489 |
|
| 1490 |
example: https://fiddle.skia.org/c/@Canvas_drawCircle |
| 1491 |
*/ |
| 1492 |
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint& paint); |
| 1493 |
|
| 1494 |
/** Draws circle at center with radius using clip, SkMatrix, and SkPaint paint. |
| 1495 |
If radius is zero or less, nothing is drawn. |
| 1496 |
In paint: SkPaint::Style determines if circle is stroked or filled; |
| 1497 |
if stroked, SkPaint stroke width describes the line thickness. |
| 1498 |
|
| 1499 |
@param center circle center |
| 1500 |
@param radius half the diameter of circle |
| 1501 |
@param paint SkPaint stroke or fill, blend, color, and so on, used to draw |
| 1502 |
*/ |
| 1503 |
void drawCircle(SkPoint center, SkScalar radius, const SkPaint& paint) { |
| 1504 |
this->drawCircle(center.x(), center.y(), radius, paint); |
| 1505 |
} |
| 1506 |
|
| 1507 |
/** Draws arc using clip, SkMatrix, and SkPaint paint. |
| 1508 |
|
| 1509 |
Arc is part of oval bounded by oval, sweeping from startAngle to startAngle plus |
| 1510 |
sweepAngle. startAngle and sweepAngle are in degrees. |
| 1511 |
|
| 1512 |
startAngle of zero places start point at the right middle edge of oval. |
| 1513 |
A positive sweepAngle places arc end point clockwise from start point; |
| 1514 |
a negative sweepAngle places arc end point counterclockwise from start point. |
| 1515 |
sweepAngle may exceed 360 degrees, a full circle. |
| 1516 |
If useCenter is true, draw a wedge that includes lines from oval |
| 1517 |
center to arc end points. If useCenter is false, draw arc between end points. |
| 1518 |
|
| 1519 |
If SkRect oval is empty or sweepAngle is zero, nothing is drawn. |
| 1520 |
|
| 1521 |
@param oval SkRect bounds of oval containing arc to draw |
| 1522 |
@param startAngle angle in degrees where arc begins |
| 1523 |
@param sweepAngle sweep angle in degrees; positive is clockwise |
| 1524 |
@param useCenter if true, include the center of the oval |
| 1525 |
@param paint SkPaint stroke or fill, blend, color, and so on, used to draw |
| 1526 |
*/ |
| 1527 |
void drawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, |
| 1528 |
bool useCenter, const SkPaint& paint); |
| 1529 |
|
| 1530 |
/** Draws arc using clip, SkMatrix, and SkPaint paint. |
| 1531 |
|
| 1532 |
Arc is part of oval bounded by oval, sweeping from startAngle to startAngle plus |
| 1533 |
sweepAngle. startAngle and sweepAngle are in degrees. |
| 1534 |
|
| 1535 |
startAngle of zero places start point at the right middle edge of oval. |
| 1536 |
A positive sweepAngle places arc end point clockwise from start point; |
| 1537 |
a negative sweepAngle places arc end point counterclockwise from start point. |
| 1538 |
sweepAngle may exceed 360 degrees, a full circle. |
| 1539 |
If useCenter is true, draw a wedge that includes lines from oval |
| 1540 |
center to arc end points. If useCenter is false, draw arc between end points. |
| 1541 |
|
| 1542 |
If SkRect oval is empty or sweepAngle is zero, nothing is drawn. |
| 1543 |
|
| 1544 |
@param arc SkArc specifying oval, startAngle, sweepAngle, and arc-vs-wedge |
| 1545 |
@param paint SkPaint stroke or fill, blend, color, and so on, used to draw |
| 1546 |
*/ |
| 1547 |
void drawArc(const SkArc& arc, const SkPaint& paint) { |
| 1548 |
this->drawArc(arc.fOval, arc.fStartAngle, arc.fSweepAngle, arc.isWedge(), paint); |
| 1549 |
} |
| 1550 |
|
| 1551 |
/** Draws SkRRect bounded by SkRect rect, with corner radii (rx, ry) using clip, |
| 1552 |
SkMatrix, and SkPaint paint. |
| 1553 |
|
| 1554 |
In paint: SkPaint::Style determines if SkRRect is stroked or filled; |
| 1555 |
if stroked, SkPaint stroke width describes the line thickness. |
| 1556 |
If rx or ry are less than zero, they are treated as if they are zero. |
| 1557 |
If rx plus ry exceeds rect width or rect height, radii are scaled down to fit. |
| 1558 |
If rx and ry are zero, SkRRect is drawn as SkRect and if stroked is affected by |
| 1559 |
SkPaint::Join. |
| 1560 |
|
| 1561 |
@param rect SkRect bounds of SkRRect to draw |
| 1562 |
@param rx axis length on x-axis of oval describing rounded corners |
| 1563 |
@param ry axis length on y-axis of oval describing rounded corners |
| 1564 |
@param paint stroke, blend, color, and so on, used to draw |
| 1565 |
|
| 1566 |
example: https://fiddle.skia.org/c/@Canvas_drawRoundRect |
| 1567 |
*/ |
| 1568 |
void drawRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry, const SkPaint& paint); |
| 1569 |
|
| 1570 |
/** Draws SkPath path using clip, SkMatrix, and SkPaint paint. |
| 1571 |
SkPath contains an array of path contour, each of which may be open or closed. |
| 1572 |
|
| 1573 |
In paint: SkPaint::Style determines if SkRRect is stroked or filled: |
| 1574 |
if filled, SkPath::FillType determines whether path contour describes inside or |
| 1575 |
outside of fill; if stroked, SkPaint stroke width describes the line thickness, |
| 1576 |
SkPaint::Cap describes line ends, and SkPaint::Join describes how |
| 1577 |
corners are drawn. |
| 1578 |
|
| 1579 |
@param path SkPath to draw |
| 1580 |
@param paint stroke, blend, color, and so on, used to draw |
| 1581 |
|
| 1582 |
example: https://fiddle.skia.org/c/@Canvas_drawPath |
| 1583 |
*/ |
| 1584 |
void drawPath(const SkPath& path, const SkPaint& paint); |
| 1585 |
|
| 1586 |
void drawImage(const SkImage* image, SkScalar left, SkScalar top) { |
| 1587 |
this->drawImage(image, left, top, SkSamplingOptions(), nullptr); |
| 1588 |
} |
| 1589 |
void drawImage(const sk_sp<SkImage>& image, SkScalar left, SkScalar top) { |
| 1590 |
this->drawImage(image.get(), left, top, SkSamplingOptions(), nullptr); |
| 1591 |
} |
| 1592 |
|
| 1593 |
/** \enum SkCanvas::SrcRectConstraint |
| 1594 |
SrcRectConstraint controls the behavior at the edge of source SkRect, |
| 1595 |
provided to drawImageRect() when there is any filtering. If kStrict is set, |
| 1596 |
then extra code is used to ensure it never samples outside of the src-rect. |
| 1597 |
kStrict_SrcRectConstraint disables the use of mipmaps and anisotropic filtering. |
| 1598 |
*/ |
| 1599 |
enum SrcRectConstraint { |
| 1600 |
kStrict_SrcRectConstraint, //!< sample only inside bounds; slower |
| 1601 |
kFast_SrcRectConstraint, //!< sample outside bounds; faster |
| 1602 |
}; |
| 1603 |
|
| 1604 |
void drawImage(const SkImage*, SkScalar x, SkScalar y, const SkSamplingOptions&, |
| 1605 |
const SkPaint* = nullptr); |
| 1606 |
void drawImage(const sk_sp<SkImage>& image, SkScalar x, SkScalar y, |
| 1607 |
const SkSamplingOptions& sampling, const SkPaint* paint = nullptr) { |
| 1608 |
this->drawImage(image.get(), x, y, sampling, paint); |
| 1609 |
} |
| 1610 |
void drawImageRect(const SkImage*, const SkRect& src, const SkRect& dst, |
| 1611 |
const SkSamplingOptions&, const SkPaint*, SrcRectConstraint); |
| 1612 |
void drawImageRect(const SkImage*, const SkRect& dst, const SkSamplingOptions&, |
| 1613 |
const SkPaint* = nullptr); |
| 1614 |
void drawImageRect(const sk_sp<SkImage>& image, const SkRect& src, const SkRect& dst, |
| 1615 |
const SkSamplingOptions& sampling, const SkPaint* paint, |
| 1616 |
SrcRectConstraint constraint) { |
| 1617 |
this->drawImageRect(image.get(), src, dst, sampling, paint, constraint); |
| 1618 |
} |
| 1619 |
void drawImageRect(const sk_sp<SkImage>& image, const SkRect& dst, |
| 1620 |
const SkSamplingOptions& sampling, const SkPaint* paint = nullptr) { |
| 1621 |
this->drawImageRect(image.get(), dst, sampling, paint); |
| 1622 |
} |
| 1623 |
|
| 1624 |
/** Draws SkImage image stretched proportionally to fit into SkRect dst. |
| 1625 |
SkIRect center divides the image into nine sections: four sides, four corners, and |
| 1626 |
the center. Corners are unmodified or scaled down proportionately if their sides |
| 1627 |
are larger than dst; center and four sides are scaled to fit remaining space, if any. |
| 1628 |
|
| 1629 |
Additionally transform draw using clip, SkMatrix, and optional SkPaint paint. |
| 1630 |
|
| 1631 |
If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter, and |
| 1632 |
SkBlendMode. If image is kAlpha_8_SkColorType, apply SkShader. |
| 1633 |
If paint contains SkMaskFilter, generate mask from image bounds. |
| 1634 |
Any SkMaskFilter on paint is ignored as is paint anti-aliasing state. |
| 1635 |
|
| 1636 |
If generated mask extends beyond image bounds, replicate image edge colors, just |
| 1637 |
as SkShader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
| 1638 |
replicates the image edge color when it samples outside of its bounds. |
| 1639 |
|
| 1640 |
@param image SkImage containing pixels, dimensions, and format |
| 1641 |
@param center SkIRect edge of image corners and sides |
| 1642 |
@param dst destination SkRect of image to draw to |
| 1643 |
@param filter what technique to use when sampling the image |
| 1644 |
@param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter, |
| 1645 |
and so on; or nullptr |
| 1646 |
*/ |
| 1647 |
void drawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst, |
| 1648 |
SkFilterMode filter, const SkPaint* paint = nullptr); |
| 1649 |
|
| 1650 |
/** \struct SkCanvas::Lattice |
| 1651 |
SkCanvas::Lattice divides SkBitmap or SkImage into a rectangular grid. |
| 1652 |
Grid entries on even columns and even rows are fixed; these entries are |
| 1653 |
always drawn at their original size if the destination is large enough. |
| 1654 |
If the destination side is too small to hold the fixed entries, all fixed |
| 1655 |
entries are proportionately scaled down to fit. |
| 1656 |
The grid entries not on even columns and rows are scaled to fit the |
| 1657 |
remaining space, if any. |
| 1658 |
*/ |
| 1659 |
struct Lattice { |
| 1660 |
|
| 1661 |
/** \enum SkCanvas::Lattice::RectType |
| 1662 |
Optional setting per rectangular grid entry to make it transparent, |
| 1663 |
or to fill the grid entry with a color. |
| 1664 |
*/ |
| 1665 |
enum RectType : uint8_t { |
| 1666 |
kDefault = 0, //!< draws SkBitmap into lattice rectangle |
| 1667 |
kTransparent, //!< skips lattice rectangle by making it transparent |
| 1668 |
kFixedColor, //!< draws one of fColors into lattice rectangle |
| 1669 |
}; |
| 1670 |
|
| 1671 |
const int* fXDivs; //!< x-axis values dividing bitmap |
| 1672 |
const int* fYDivs; //!< y-axis values dividing bitmap |
| 1673 |
const RectType* fRectTypes; //!< array of fill types |
| 1674 |
int fXCount; //!< number of x-coordinates |
| 1675 |
int fYCount; //!< number of y-coordinates |
| 1676 |
const SkIRect* fBounds; //!< source bounds to draw from |
| 1677 |
const SkColor* fColors; //!< array of colors |
| 1678 |
}; |
| 1679 |
|
| 1680 |
/** Draws SkImage image stretched proportionally to fit into SkRect dst. |
| 1681 |
|
| 1682 |
SkCanvas::Lattice lattice divides image into a rectangular grid. |
| 1683 |
Each intersection of an even-numbered row and column is fixed; |
| 1684 |
fixed lattice elements never scale larger than their initial |
| 1685 |
size and shrink proportionately when all fixed elements exceed the bitmap |
| 1686 |
dimension. All other grid elements scale to fill the available space, if any. |
| 1687 |
|
| 1688 |
Additionally transform draw using clip, SkMatrix, and optional SkPaint paint. |
| 1689 |
|
| 1690 |
If SkPaint paint is supplied, apply SkColorFilter, alpha, SkImageFilter, and |
| 1691 |
SkBlendMode. If image is kAlpha_8_SkColorType, apply SkShader. |
| 1692 |
If paint contains SkMaskFilter, generate mask from image bounds. |
| 1693 |
Any SkMaskFilter on paint is ignored as is paint anti-aliasing state. |
| 1694 |
|
| 1695 |
If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, |
| 1696 |
just as SkShader made from SkShader::MakeBitmapShader with |
| 1697 |
SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples |
| 1698 |
outside of its bounds. |
| 1699 |
|
| 1700 |
@param image SkImage containing pixels, dimensions, and format |
| 1701 |
@param lattice division of bitmap into fixed and variable rectangles |
| 1702 |
@param dst destination SkRect of image to draw to |
| 1703 |
@param filter what technique to use when sampling the image |
| 1704 |
@param paint SkPaint containing SkBlendMode, SkColorFilter, SkImageFilter, |
| 1705 |
and so on; or nullptr |
| 1706 |
*/ |
| 1707 |
void drawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst, |
| 1708 |
SkFilterMode filter, const SkPaint* paint = nullptr); |
| 1709 |
void drawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst) { |
| 1710 |
this->drawImageLattice(image, lattice, dst, SkFilterMode::kNearest, nullptr); |
| 1711 |
} |
| 1712 |
|
| 1713 |
/** |
| 1714 |
* Experimental. Controls anti-aliasing of each edge of images in an image-set. |
| 1715 |
*/ |
| 1716 |
enum QuadAAFlags : unsigned { |
| 1717 |
kLeft_QuadAAFlag = 0b0001, |
| 1718 |
kTop_QuadAAFlag = 0b0010, |
| 1719 |
kRight_QuadAAFlag = 0b0100, |
| 1720 |
kBottom_QuadAAFlag = 0b1000, |
| 1721 |
|
| 1722 |
kNone_QuadAAFlags = 0b0000, |
| 1723 |
kAll_QuadAAFlags = 0b1111, |
| 1724 |
}; |
| 1725 |
|
| 1726 |
/** This is used by the experimental API below. */ |
| 1727 |
struct SK_API ImageSetEntry { |
| 1728 |
ImageSetEntry(sk_sp<const SkImage> image, const SkRect& srcRect, const SkRect& dstRect, |
| 1729 |
int matrixIndex, float alpha, unsigned aaFlags, bool hasClip); |
| 1730 |
|
| 1731 |
ImageSetEntry(sk_sp<const SkImage> image, const SkRect& srcRect, const SkRect& dstRect, |
| 1732 |
float alpha, unsigned aaFlags); |
| 1733 |
|
| 1734 |
ImageSetEntry(); |
| 1735 |
~ImageSetEntry(); |
| 1736 |
ImageSetEntry(const ImageSetEntry&); |
| 1737 |
ImageSetEntry& operator=(const ImageSetEntry&); |
| 1738 |
|
| 1739 |
sk_sp<const SkImage> fImage; |
| 1740 |
SkRect fSrcRect; |
| 1741 |
SkRect fDstRect; |
| 1742 |
int fMatrixIndex = -1; // Index into the preViewMatrices arg, or < 0 |
| 1743 |
float fAlpha = 1.f; |
| 1744 |
unsigned fAAFlags = kNone_QuadAAFlags; // QuadAAFlags |
| 1745 |
bool fHasClip = false; // True to use next 4 points in dstClip arg as quad |
| 1746 |
}; |
| 1747 |
|
| 1748 |
/** |
| 1749 |
* This is an experimental API for the SkiaRenderer Chromium project, and its API will surely |
| 1750 |
* evolve if it is not removed outright. |
| 1751 |
* |
| 1752 |
* This behaves very similarly to drawRect() combined with a clipPath() formed by clip |
| 1753 |
* quadrilateral. 'rect' and 'clip' are in the same coordinate space. If 'clip' is null, then it |
| 1754 |
* is as if the rectangle was not clipped (or, alternatively, clipped to itself). If not null, |
| 1755 |
* then it must provide 4 points. |
| 1756 |
* |
| 1757 |
* In addition to combining the draw and clipping into one operation, this function adds the |
| 1758 |
* additional capability of controlling each of the rectangle's edges anti-aliasing |
| 1759 |
* independently. The edges of the clip will respect the per-edge AA flags. It is required that |
| 1760 |
* 'clip' be contained inside 'rect'. In terms of mapping to edge labels, the 'clip' points |
| 1761 |
* should be ordered top-left, top-right, bottom-right, bottom-left so that the edge between [0] |
| 1762 |
* and [1] is "top", [1] and [2] is "right", [2] and [3] is "bottom", and [3] and [0] is "left". |
| 1763 |
* This ordering matches SkRect::toQuad(). |
| 1764 |
* |
| 1765 |
* This API only draws solid color, filled rectangles so it does not accept a full SkPaint. |
| 1766 |
*/ |
| 1767 |
void experimental_DrawEdgeAAQuad(const SkRect& rect, const SkPoint clip[4], QuadAAFlags aaFlags, |
| 1768 |
const SkColor4f& color, SkBlendMode mode); |
| 1769 |
void experimental_DrawEdgeAAQuad(const SkRect& rect, const SkPoint clip[4], QuadAAFlags aaFlags, |
| 1770 |
SkColor color, SkBlendMode mode) { |
| 1771 |
this->experimental_DrawEdgeAAQuad(rect, clip, aaFlags, SkColor4f::FromColor(color), mode); |
| 1772 |
} |
| 1773 |
|
| 1774 |
/** |
| 1775 |
* This is an bulk variant of experimental_DrawEdgeAAQuad() that renders 'cnt' textured quads. |
| 1776 |
* For each entry, 'fDstRect' is rendered with its clip (determined by entry's 'fHasClip' and |
| 1777 |
* the current index in 'dstClip'). The entry's fImage is applied to the destination rectangle |
| 1778 |
* by sampling from 'fSrcRect' sub-image. The corners of 'fSrcRect' map to the corners of |
| 1779 |
* 'fDstRect', just like in drawImageRect(), and they will be properly interpolated when |
| 1780 |
* applying a clip. |
| 1781 |
* |
| 1782 |
* Like experimental_DrawEdgeAAQuad(), each entry can specify edge AA flags that apply to both |
| 1783 |
* the destination rect and its clip. |
| 1784 |
* |
| 1785 |
* If provided, the 'dstClips' array must have length equal 4 * the number of entries with |
| 1786 |
* fHasClip true. If 'dstClips' is null, every entry must have 'fHasClip' set to false. The |
| 1787 |
* destination clip coordinates will be read consecutively with the image set entries, advancing |
| 1788 |
* by 4 points every time an entry with fHasClip is passed. |
| 1789 |
* |
| 1790 |
* This entry point supports per-entry manipulations to the canvas's current matrix. If an |
| 1791 |
* entry provides 'fMatrixIndex' >= 0, it will be drawn as if the canvas's CTM was |
| 1792 |
* canvas->getTotalMatrix() * preViewMatrices[fMatrixIndex]. If 'fMatrixIndex' is less than 0, |
| 1793 |
* the pre-view matrix transform is implicitly the identity, so it will be drawn using just the |
| 1794 |
* current canvas matrix. The pre-view matrix modifies the canvas's view matrix, it does not |
| 1795 |
* affect the local coordinates of each entry. |
| 1796 |
* |
| 1797 |
* An optional paint may be provided, which supports the same subset of features usable with |
| 1798 |
* drawImageRect (i.e. assumed to be filled and no path effects). When a paint is provided, the |
| 1799 |
* image set is drawn as if each image used the applied paint independently, so each is affected |
| 1800 |
* by the image, color, and/or mask filter. |
| 1801 |
*/ |
| 1802 |
void experimental_DrawEdgeAAImageSet(const ImageSetEntry imageSet[], int cnt, |
| 1803 |
const SkPoint dstClips[], const SkMatrix preViewMatrices[], |
| 1804 |
const SkSamplingOptions&, const SkPaint* paint = nullptr, |
| 1805 |
SrcRectConstraint constraint = kStrict_SrcRectConstraint); |
| 1806 |
|
| 1807 |
/** Draws text, with origin at (x, y), using clip, SkMatrix, SkFont font, |
| 1808 |
and SkPaint paint. |
| 1809 |
|
| 1810 |
When encoding is SkTextEncoding::kUTF8, SkTextEncoding::kUTF16, or |
| 1811 |
SkTextEncoding::kUTF32, this function uses the default |
| 1812 |
character-to-glyph mapping from the SkTypeface in font. It does not |
| 1813 |
perform typeface fallback for characters not found in the SkTypeface. |
| 1814 |
It does not perform kerning or other complex shaping; glyphs are |
| 1815 |
positioned based on their default advances. |
| 1816 |
|
| 1817 |
Text meaning depends on SkTextEncoding. |
| 1818 |
|
| 1819 |
Text size is affected by SkMatrix and SkFont text size. Default text |
| 1820 |
size is 12 point. |
| 1821 |
|
| 1822 |
All elements of paint: SkPathEffect, SkMaskFilter, SkShader, |
| 1823 |
SkColorFilter, and SkImageFilter; apply to text. By |
| 1824 |
default, draws filled black glyphs. |
| 1825 |
|
| 1826 |
@param text character code points or glyphs drawn |
| 1827 |
@param byteLength byte length of text array |
| 1828 |
@param encoding text encoding used in the text array |
| 1829 |
@param x start of text on x-axis |
| 1830 |
@param y start of text on y-axis |
| 1831 |
@param font typeface, text size and so, used to describe the text |
| 1832 |
@param paint blend, color, and so on, used to draw |
| 1833 |
*/ |
| 1834 |
void drawSimpleText(const void* text, size_t byteLength, SkTextEncoding encoding, |
| 1835 |
SkScalar x, SkScalar y, const SkFont& font, const SkPaint& paint); |
| 1836 |
|
| 1837 |
/** Draws null terminated string, with origin at (x, y), using clip, SkMatrix, |
| 1838 |
SkFont font, and SkPaint paint. |
| 1839 |
|
| 1840 |
This function uses the default character-to-glyph mapping from the |
| 1841 |
SkTypeface in font. It does not perform typeface fallback for |
| 1842 |
characters not found in the SkTypeface. It does not perform kerning; |
| 1843 |
glyphs are positioned based on their default advances. |
| 1844 |
|
| 1845 |
String str is encoded as UTF-8. |
| 1846 |
|
| 1847 |
Text size is affected by SkMatrix and font text size. Default text |
| 1848 |
size is 12 point. |
| 1849 |
|
| 1850 |
All elements of paint: SkPathEffect, SkMaskFilter, SkShader, |
| 1851 |
SkColorFilter, and SkImageFilter; apply to text. By |
| 1852 |
default, draws filled black glyphs. |
| 1853 |
|
| 1854 |
@param str character code points drawn, |
| 1855 |
ending with a char value of zero |
| 1856 |
@param x start of string on x-axis |
| 1857 |
@param y start of string on y-axis |
| 1858 |
@param font typeface, text size and so, used to describe the text |
| 1859 |
@param paint blend, color, and so on, used to draw |
| 1860 |
*/ |
| 1861 |
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont& font, |
| 1862 |
const SkPaint& paint) { |
| 1863 |
this->drawSimpleText(str, strlen(str), SkTextEncoding::kUTF8, x, y, font, paint); |
| 1864 |
} |
| 1865 |
|
| 1866 |
/** Draws SkString, with origin at (x, y), using clip, SkMatrix, SkFont font, |
| 1867 |
and SkPaint paint. |
| 1868 |
|
| 1869 |
This function uses the default character-to-glyph mapping from the |
| 1870 |
SkTypeface in font. It does not perform typeface fallback for |
| 1871 |
characters not found in the SkTypeface. It does not perform kerning; |
| 1872 |
glyphs are positioned based on their default advances. |
| 1873 |
|
| 1874 |
SkString str is encoded as UTF-8. |
| 1875 |
|
| 1876 |
Text size is affected by SkMatrix and SkFont text size. Default text |
| 1877 |
size is 12 point. |
| 1878 |
|
| 1879 |
All elements of paint: SkPathEffect, SkMaskFilter, SkShader, |
| 1880 |
SkColorFilter, and SkImageFilter; apply to text. By |
| 1881 |
default, draws filled black glyphs. |
| 1882 |
|
| 1883 |
@param str character code points drawn, |
| 1884 |
ending with a char value of zero |
| 1885 |
@param x start of string on x-axis |
| 1886 |
@param y start of string on y-axis |
| 1887 |
@param font typeface, text size and so, used to describe the text |
| 1888 |
@param paint blend, color, and so on, used to draw |
| 1889 |
*/ |
| 1890 |
void drawString(const SkString& str, SkScalar x, SkScalar y, const SkFont& font, |
| 1891 |
const SkPaint& paint) { |
| 1892 |
this->drawSimpleText(str.c_str(), str.size(), SkTextEncoding::kUTF8, x, y, font, paint); |
| 1893 |
} |
| 1894 |
|
| 1895 |
/** Draws count glyphs, at positions relative to origin styled with font and paint with |
| 1896 |
supporting utf8 and cluster information. |
| 1897 |
|
| 1898 |
This function draw glyphs at the given positions relative to the given origin. |
| 1899 |
It does not perform typeface fallback for glyphs not found in the SkTypeface in font. |
| 1900 |
|
| 1901 |
The drawing obeys the current transform matrix and clipping. |
| 1902 |
|
| 1903 |
All elements of paint: SkPathEffect, SkMaskFilter, SkShader, |
| 1904 |
SkColorFilter, and SkImageFilter; apply to text. By |
| 1905 |
default, draws filled black glyphs. |
| 1906 |
|
| 1907 |
@param glyphs the span of glyphIDs to draw |
| 1908 |
@param positions where to draw each glyph relative to origin |
| 1909 |
@param clusters cluster information |
| 1910 |
@param utf8text utf8text supporting information for the glyphs |
| 1911 |
@param origin the origin of all the positions |
| 1912 |
@param font typeface, text size and so, used to describe the text |
| 1913 |
@param paint blend, color, and so on, used to draw |
| 1914 |
*/ |
| 1915 |
void drawGlyphs(SkSpan<const SkGlyphID> glyphs, SkSpan<const SkPoint> positions, |
| 1916 |
SkSpan<const uint32_t> clusters, SkSpan<const char> utf8text, |
| 1917 |
SkPoint origin, const SkFont& font, const SkPaint& paint); |
| 1918 |
#ifdef SK_SUPPORT_UNSPANNED_APIS |
| 1919 |
void drawGlyphs(int count, const SkGlyphID glyphs[], const SkPoint positions[], |
| 1920 |
const uint32_t clusters[], int textByteCount, const char utf8text[], |
| 1921 |
SkPoint origin, const SkFont& font, const SkPaint& paint) { |
| 1922 |
this->drawGlyphs({glyphs, count}, |
| 1923 |
{positions, count}, |
| 1924 |
{clusters, count}, |
| 1925 |
{utf8text, textByteCount}, |
| 1926 |
origin, font, paint); |
| 1927 |
} |
| 1928 |
#endif |
| 1929 |
|
| 1930 |
/** Draws count glyphs, at positions relative to origin styled with font and paint. |
| 1931 |
|
| 1932 |
This function draw glyphs at the given positions relative to the given origin. |
| 1933 |
It does not perform typeface fallback for glyphs not found in the SkTypeface in font. |
| 1934 |
|
| 1935 |
The drawing obeys the current transform matrix and clipping. |
| 1936 |
|
| 1937 |
All elements of paint: SkPathEffect, SkMaskFilter, SkShader, |
| 1938 |
SkColorFilter, and SkImageFilter; apply to text. By |
| 1939 |
default, draws filled black glyphs. |
| 1940 |
|
| 1941 |
@param count number of glyphs to draw |
| 1942 |
@param glyphs the array of glyphIDs to draw |
| 1943 |
@param positions where to draw each glyph relative to origin |
| 1944 |
@param origin the origin of all the positions |
| 1945 |
@param font typeface, text size and so, used to describe the text |
| 1946 |
@param paint blend, color, and so on, used to draw |
| 1947 |
*/ |
| 1948 |
void drawGlyphs(SkSpan<const SkGlyphID> glyphs, SkSpan<const SkPoint> positions, |
| 1949 |
SkPoint origin, const SkFont& font, const SkPaint& paint); |
| 1950 |
#ifdef SK_SUPPORT_UNSPANNED_APIS |
| 1951 |
void drawGlyphs(int count, const SkGlyphID glyphs[], const SkPoint positions[], |
| 1952 |
SkPoint origin, const SkFont& font, const SkPaint& paint) { |
| 1953 |
this->drawGlyphs({glyphs, count}, {positions, count}, origin, font, paint); |
| 1954 |
} |
| 1955 |
#endif |
| 1956 |
|
| 1957 |
/** Draws count glyphs, at positions relative to origin styled with font and paint. |
| 1958 |
|
| 1959 |
This function draw glyphs using the given scaling and rotations. They are positioned |
| 1960 |
relative to the given origin. It does not perform typeface fallback for glyphs not found |
| 1961 |
in the SkTypeface in font. |
| 1962 |
|
| 1963 |
The drawing obeys the current transform matrix and clipping. |
| 1964 |
|
| 1965 |
All elements of paint: SkPathEffect, SkMaskFilter, SkShader, |
| 1966 |
SkColorFilter, and SkImageFilter; apply to text. By |
| 1967 |
default, draws filled black glyphs. |
| 1968 |
|
| 1969 |
@param count number of glyphs to draw |
| 1970 |
@param glyphs the array of glyphIDs to draw |
| 1971 |
@param xforms where to draw and orient each glyph |
| 1972 |
@param origin the origin of all the positions |
| 1973 |
@param font typeface, text size and so, used to describe the text |
| 1974 |
@param paint blend, color, and so on, used to draw |
| 1975 |
*/ |
| 1976 |
void drawGlyphsRSXform(SkSpan<const SkGlyphID> glyphs, SkSpan<const SkRSXform> xforms, |
| 1977 |
SkPoint origin, const SkFont& font, const SkPaint& paint); |
| 1978 |
#ifdef SK_SUPPORT_UNSPANNED_APIS |
| 1979 |
void drawGlyphs(int count, const SkGlyphID glyphs[], const SkRSXform xforms[], |
| 1980 |
SkPoint origin, const SkFont& font, const SkPaint& paint) { |
| 1981 |
this->drawGlyphsRSXform({glyphs, count}, {xforms, count}, origin, font, paint); |
| 1982 |
} |
| 1983 |
#endif |
| 1984 |
|
| 1985 |
/** Draws SkTextBlob blob at (x, y), using clip, SkMatrix, and SkPaint paint. |
| 1986 |
|
| 1987 |
blob contains glyphs, their positions, and paint attributes specific to text: |
| 1988 |
SkTypeface, SkPaint text size, SkPaint text scale x, |
| 1989 |
SkPaint text skew x, SkPaint::Align, SkPaint::Hinting, anti-alias, SkPaint fake bold, |
| 1990 |
SkPaint font embedded bitmaps, SkPaint full hinting spacing, LCD text, SkPaint linear text, |
| 1991 |
and SkPaint subpixel text. |
| 1992 |
|
| 1993 |
SkTextEncoding must be set to SkTextEncoding::kGlyphID. |
| 1994 |
|
| 1995 |
Elements of paint: anti-alias, SkBlendMode, color including alpha, |
| 1996 |
SkColorFilter, SkPaint dither, SkMaskFilter, SkPathEffect, SkShader, and |
| 1997 |
SkPaint::Style; apply to blob. If SkPaint contains SkPaint::kStroke_Style: |
| 1998 |
SkPaint miter limit, SkPaint::Cap, SkPaint::Join, and SkPaint stroke width; |
| 1999 |
apply to SkPath created from blob. |
| 2000 |
|
| 2001 |
@param blob glyphs, positions, and their paints' text size, typeface, and so on |
| 2002 |
@param x horizontal offset applied to blob |
| 2003 |
@param y vertical offset applied to blob |
| 2004 |
@param paint blend, color, stroking, and so on, used to draw |
| 2005 |
|
| 2006 |
example: https://fiddle.skia.org/c/@Canvas_drawTextBlob |
| 2007 |
*/ |
| 2008 |
void drawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPaint& paint); |
| 2009 |
|
| 2010 |
/** Draws SkTextBlob blob at (x, y), using clip, SkMatrix, and SkPaint paint. |
| 2011 |
|
| 2012 |
blob contains glyphs, their positions, and paint attributes specific to text: |
| 2013 |
SkTypeface, SkPaint text size, SkPaint text scale x, |
| 2014 |
SkPaint text skew x, SkPaint::Align, SkPaint::Hinting, anti-alias, SkPaint fake bold, |
| 2015 |
SkPaint font embedded bitmaps, SkPaint full hinting spacing, LCD text, SkPaint linear text, |
| 2016 |
and SkPaint subpixel text. |
| 2017 |
|
| 2018 |
SkTextEncoding must be set to SkTextEncoding::kGlyphID. |
| 2019 |
|
| 2020 |
Elements of paint: SkPathEffect, SkMaskFilter, SkShader, SkColorFilter, |
| 2021 |
and SkImageFilter; apply to blob. |
| 2022 |
|
| 2023 |
@param blob glyphs, positions, and their paints' text size, typeface, and so on |
| 2024 |
@param x horizontal offset applied to blob |
| 2025 |
@param y vertical offset applied to blob |
| 2026 |
@param paint blend, color, stroking, and so on, used to draw |
| 2027 |
*/ |
| 2028 |
void drawTextBlob(const sk_sp<SkTextBlob>& blob, SkScalar x, SkScalar y, const SkPaint& paint) { |
| 2029 |
this->drawTextBlob(blob.get(), x, y, paint); |
| 2030 |
} |
| 2031 |
|
| 2032 |
/** Draws SkPicture picture, using clip and SkMatrix. |
| 2033 |
Clip and SkMatrix are unchanged by picture contents, as if |
| 2034 |
save() was called before and restore() was called after drawPicture(). |
| 2035 |
|
| 2036 |
SkPicture records a series of draw commands for later playback. |
| 2037 |
|
| 2038 |
@param picture recorded drawing commands to play |
| 2039 |
*/ |
| 2040 |
void drawPicture(const SkPicture* picture) { |
| 2041 |
this->drawPicture(picture, nullptr, nullptr); |
| 2042 |
} |
| 2043 |
|
| 2044 |
/** Draws SkPicture picture, using clip and SkMatrix. |
| 2045 |
Clip and SkMatrix are unchanged by picture contents, as if |
| 2046 |
save() was called before and restore() was called after drawPicture(). |
| 2047 |
|
| 2048 |
SkPicture records a series of draw commands for later playback. |
| 2049 |
|
| 2050 |
@param picture recorded drawing commands to play |
| 2051 |
*/ |
| 2052 |
void drawPicture(const sk_sp<SkPicture>& picture) { |
| 2053 |
this->drawPicture(picture.get()); |
| 2054 |
} |
| 2055 |
|
| 2056 |
/** Draws SkPicture picture, using clip and SkMatrix; transforming picture with |
| 2057 |
SkMatrix matrix, if provided; and use SkPaint paint alpha, SkColorFilter, |
| 2058 |
SkImageFilter, and SkBlendMode, if provided. |
| 2059 |
|
| 2060 |
If paint is non-null, then the picture is always drawn into a temporary layer before |
| 2061 |
actually landing on the canvas. Note that drawing into a layer can also change its |
| 2062 |
appearance if there are any non-associative blendModes inside any of the pictures elements. |
| 2063 |
|
| 2064 |
@param picture recorded drawing commands to play |
| 2065 |
@param matrix SkMatrix to rotate, scale, translate, and so on; may be nullptr |
| 2066 |
@param paint SkPaint to apply transparency, filtering, and so on; may be nullptr |
| 2067 |
|
| 2068 |
example: https://fiddle.skia.org/c/@Canvas_drawPicture_3 |
| 2069 |
*/ |
| 2070 |
void drawPicture(const SkPicture* picture, const SkMatrix* matrix, const SkPaint* paint); |
| 2071 |
|
| 2072 |
/** Draws SkPicture picture, using clip and SkMatrix; transforming picture with |
| 2073 |
SkMatrix matrix, if provided; and use SkPaint paint alpha, SkColorFilter, |
| 2074 |
SkImageFilter, and SkBlendMode, if provided. |
| 2075 |
|
| 2076 |
If paint is non-null, then the picture is always drawn into a temporary layer before |
| 2077 |
actually landing on the canvas. Note that drawing into a layer can also change its |
| 2078 |
appearance if there are any non-associative blendModes inside any of the pictures elements. |
| 2079 |
|
| 2080 |
@param picture recorded drawing commands to play |
| 2081 |
@param matrix SkMatrix to rotate, scale, translate, and so on; may be nullptr |
| 2082 |
@param paint SkPaint to apply transparency, filtering, and so on; may be nullptr |
| 2083 |
*/ |
| 2084 |
void drawPicture(const sk_sp<SkPicture>& picture, const SkMatrix* matrix, |
| 2085 |
const SkPaint* paint) { |
| 2086 |
this->drawPicture(picture.get(), matrix, paint); |
| 2087 |
} |
| 2088 |
|
| 2089 |
/** Draws SkVertices vertices, a triangle mesh, using clip and SkMatrix. |
| 2090 |
If paint contains an SkShader and vertices does not contain texCoords, the shader |
| 2091 |
is mapped using the vertices' positions. |
| 2092 |
|
| 2093 |
SkBlendMode is ignored if SkVertices does not have colors. Otherwise, it combines |
| 2094 |
- the SkShader if SkPaint contains SkShader |
| 2095 |
- or the opaque SkPaint color if SkPaint does not contain SkShader |
| 2096 |
as the src of the blend and the interpolated vertex colors as the dst. |
| 2097 |
|
| 2098 |
SkMaskFilter, SkPathEffect, and antialiasing on SkPaint are ignored. |
| 2099 |
|
| 2100 |
@param vertices triangle mesh to draw |
| 2101 |
@param mode combines vertices' colors with SkShader if present or SkPaint opaque color |
| 2102 |
if not. Ignored if the vertices do not contain color. |
| 2103 |
@param paint specifies the SkShader, used as SkVertices texture, and SkColorFilter. |
| 2104 |
|
| 2105 |
example: https://fiddle.skia.org/c/@Canvas_drawVertices |
| 2106 |
*/ |
| 2107 |
void drawVertices(const SkVertices* vertices, SkBlendMode mode, const SkPaint& paint); |
| 2108 |
|
| 2109 |
/** Draws SkVertices vertices, a triangle mesh, using clip and SkMatrix. |
| 2110 |
If paint contains an SkShader and vertices does not contain texCoords, the shader |
| 2111 |
is mapped using the vertices' positions. |
| 2112 |
|
| 2113 |
SkBlendMode is ignored if SkVertices does not have colors. Otherwise, it combines |
| 2114 |
- the SkShader if SkPaint contains SkShader |
| 2115 |
- or the opaque SkPaint color if SkPaint does not contain SkShader |
| 2116 |
as the src of the blend and the interpolated vertex colors as the dst. |
| 2117 |
|
| 2118 |
SkMaskFilter, SkPathEffect, and antialiasing on SkPaint are ignored. |
| 2119 |
|
| 2120 |
@param vertices triangle mesh to draw |
| 2121 |
@param mode combines vertices' colors with SkShader if present or SkPaint opaque color |
| 2122 |
if not. Ignored if the vertices do not contain color. |
| 2123 |
@param paint specifies the SkShader, used as SkVertices texture, may be nullptr |
| 2124 |
|
| 2125 |
example: https://fiddle.skia.org/c/@Canvas_drawVertices_2 |
| 2126 |
*/ |
| 2127 |
void drawVertices(const sk_sp<SkVertices>& vertices, SkBlendMode mode, const SkPaint& paint); |
| 2128 |
|
| 2129 |
/** |
| 2130 |
Experimental, under active development, and subject to change without notice. |
| 2131 |
|
| 2132 |
Draws a mesh using a user-defined specification (see SkMeshSpecification). Requires |
| 2133 |
a GPU backend or SkSL to be compiled in. |
| 2134 |
|
| 2135 |
SkBlender is ignored if SkMesh's specification does not output fragment shader color. |
| 2136 |
Otherwise, it combines |
| 2137 |
- the SkShader if SkPaint contains SkShader |
| 2138 |
- or the opaque SkPaint color if SkPaint does not contain SkShader |
| 2139 |
as the src of the blend and the mesh's fragment color as the dst. |
| 2140 |
|
| 2141 |
SkMaskFilter, SkPathEffect, and antialiasing on SkPaint are ignored. |
| 2142 |
|
| 2143 |
@param mesh the mesh vertices and compatible specification. |
| 2144 |
@param blender combines vertices colors with SkShader if present or SkPaint opaque color |
| 2145 |
if not. Ignored if the custom mesh does not output color. Defaults to |
| 2146 |
SkBlendMode::kModulate if nullptr. |
| 2147 |
@param paint specifies the SkShader, used as SkVertices texture, may be nullptr |
| 2148 |
*/ |
| 2149 |
void drawMesh(const SkMesh& mesh, sk_sp<SkBlender> blender, const SkPaint& paint); |
| 2150 |
|
| 2151 |
/** Draws a Coons patch: the interpolation of four cubics with shared corners, |
| 2152 |
associating a color, and optionally a texture SkPoint, with each corner. |
| 2153 |
|
| 2154 |
SkPoint array cubics specifies four SkPath cubic starting at the top-left corner, |
| 2155 |
in clockwise order, sharing every fourth point. The last SkPath cubic ends at the |
| 2156 |
first point. |
| 2157 |
|
| 2158 |
Color array color associates colors with corners in top-left, top-right, |
| 2159 |
bottom-right, bottom-left order. |
| 2160 |
|
| 2161 |
If paint contains SkShader, SkPoint array texCoords maps SkShader as texture to |
| 2162 |
corners in top-left, top-right, bottom-right, bottom-left order. If texCoords is |
| 2163 |
nullptr, SkShader is mapped using positions (derived from cubics). |
| 2164 |
|
| 2165 |
SkBlendMode is ignored if colors is null. Otherwise, it combines |
| 2166 |
- the SkShader if SkPaint contains SkShader |
| 2167 |
- or the opaque SkPaint color if SkPaint does not contain SkShader |
| 2168 |
as the src of the blend and the interpolated patch colors as the dst. |
| 2169 |
|
| 2170 |
SkMaskFilter, SkPathEffect, and antialiasing on SkPaint are ignored. |
| 2171 |
|
| 2172 |
@param cubics SkPath cubic array, sharing common points |
| 2173 |
@param colors color array, one for each corner |
| 2174 |
@param texCoords SkPoint array of texture coordinates, mapping SkShader to corners; |
| 2175 |
may be nullptr |
| 2176 |
@param mode combines patch's colors with SkShader if present or SkPaint opaque color |
| 2177 |
if not. Ignored if colors is null. |
| 2178 |
@param paint SkShader, SkColorFilter, SkBlendMode, used to draw |
| 2179 |
*/ |
| 2180 |
void drawPatch(const SkPoint cubics[12], const SkColor colors[4], |
| 2181 |
const SkPoint texCoords[4], SkBlendMode mode, const SkPaint& paint); |
| 2182 |
|
| 2183 |
/** Draws a set of sprites from atlas, using clip, SkMatrix, and optional SkPaint paint. |
| 2184 |
paint uses anti-alias, alpha, SkColorFilter, SkImageFilter, and SkBlendMode |
| 2185 |
to draw, if present. For each entry in the array, SkRect tex locates sprite in |
| 2186 |
atlas, and SkRSXform xform transforms it into destination space. |
| 2187 |
|
| 2188 |
SkMaskFilter and SkPathEffect on paint are ignored. |
| 2189 |
|
| 2190 |
For non-empty spans, the number of draws will be the min of |
| 2191 |
xform.size(), tex.size(), and (if not empty) colors.size(). |
| 2192 |
|
| 2193 |
Optional colors are applied for each sprite using SkBlendMode mode, treating |
| 2194 |
sprite as source and colors as destination. |
| 2195 |
Optional cullRect is a conservative bounds of all transformed sprites. |
| 2196 |
If cullRect is outside of clip, canvas can skip drawing. |
| 2197 |
|
| 2198 |
If atlas is nullptr, this draws nothing. |
| 2199 |
|
| 2200 |
@param atlas SkImage containing sprites |
| 2201 |
@param xform SkRSXform mappings for sprites in atlas |
| 2202 |
@param tex SkRect locations of sprites in atlas |
| 2203 |
@param colors one per sprite, blended with sprite using SkBlendMode; may be nullptr |
| 2204 |
@param mode SkBlendMode combining colors and sprites |
| 2205 |
@param sampling SkSamplingOptions used when sampling from the atlas image |
| 2206 |
@param cullRect bounds of transformed sprites for efficient clipping; may be nullptr |
| 2207 |
@param paint SkColorFilter, SkImageFilter, SkBlendMode, and so on; may be nullptr |
| 2208 |
*/ |
| 2209 |
void drawAtlas(const SkImage* atlas, SkSpan<const SkRSXform> xform, |
| 2210 |
SkSpan<const SkRect> tex, SkSpan<const SkColor> colors, SkBlendMode mode, |
| 2211 |
const SkSamplingOptions& sampling, const SkRect* cullRect, const SkPaint* paint); |
| 2212 |
#ifdef SK_SUPPORT_UNSPANNED_APIS |
| 2213 |
void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], |
| 2214 |
const SkColor colors[], int count, SkBlendMode mode, |
| 2215 |
const SkSamplingOptions& samp, const SkRect* cullRect, const SkPaint* paint) { |
| 2216 |
this->drawAtlas(atlas, |
| 2217 |
{xform, count}, |
| 2218 |
{tex, tex ? count : 0}, |
| 2219 |
{colors, colors ? count : 0}, |
| 2220 |
mode, samp, cullRect, paint); |
| 2221 |
} |
| 2222 |
#endif |
| 2223 |
|
| 2224 |
/** Draws SkDrawable drawable using clip and SkMatrix, concatenated with |
| 2225 |
optional matrix. |
| 2226 |
|
| 2227 |
If SkCanvas has an asynchronous implementation, as is the case |
| 2228 |
when it is recording into SkPicture, then drawable will be referenced, |
| 2229 |
so that SkDrawable::draw() can be called when the operation is finalized. To force |
| 2230 |
immediate drawing, call SkDrawable::draw() instead. |
| 2231 |
|
| 2232 |
@param drawable custom struct encapsulating drawing commands |
| 2233 |
@param matrix transformation applied to drawing; may be nullptr |
| 2234 |
|
| 2235 |
example: https://fiddle.skia.org/c/@Canvas_drawDrawable |
| 2236 |
*/ |
| 2237 |
void drawDrawable(SkDrawable* drawable, const SkMatrix* matrix = nullptr); |
| 2238 |
|
| 2239 |
/** Draws SkDrawable drawable using clip and SkMatrix, offset by (x, y). |
| 2240 |
|
| 2241 |
If SkCanvas has an asynchronous implementation, as is the case |
| 2242 |
when it is recording into SkPicture, then drawable will be referenced, |
| 2243 |
so that SkDrawable::draw() can be called when the operation is finalized. To force |
| 2244 |
immediate drawing, call SkDrawable::draw() instead. |
| 2245 |
|
| 2246 |
@param drawable custom struct encapsulating drawing commands |
| 2247 |
@param x offset into SkCanvas writable pixels on x-axis |
| 2248 |
@param y offset into SkCanvas writable pixels on y-axis |
| 2249 |
|
| 2250 |
example: https://fiddle.skia.org/c/@Canvas_drawDrawable_2 |
| 2251 |
*/ |
| 2252 |
void drawDrawable(SkDrawable* drawable, SkScalar x, SkScalar y); |
| 2253 |
|
| 2254 |
/** Associates SkRect on SkCanvas with an annotation; a key-value pair, where the key is |
| 2255 |
a null-terminated UTF-8 string, and optional value is stored as SkData. |
| 2256 |
|
| 2257 |
Only some canvas implementations, such as recording to SkPicture, or drawing to |
| 2258 |
document PDF, use annotations. |
| 2259 |
|
| 2260 |
@param rect SkRect extent of canvas to annotate |
| 2261 |
@param key string used for lookup |
| 2262 |
@param value data holding value stored in annotation |
| 2263 |
|
| 2264 |
example: https://fiddle.skia.org/c/@Canvas_drawAnnotation_2 |
| 2265 |
*/ |
| 2266 |
void drawAnnotation(const SkRect& rect, const char key[], SkData* value); |
| 2267 |
|
| 2268 |
/** Associates SkRect on SkCanvas when an annotation; a key-value pair, where the key is |
| 2269 |
a null-terminated UTF-8 string, and optional value is stored as SkData. |
| 2270 |
|
| 2271 |
Only some canvas implementations, such as recording to SkPicture, or drawing to |
| 2272 |
document PDF, use annotations. |
| 2273 |
|
| 2274 |
@param rect SkRect extent of canvas to annotate |
| 2275 |
@param key string used for lookup |
| 2276 |
@param value data holding value stored in annotation |
| 2277 |
*/ |
| 2278 |
void drawAnnotation(const SkRect& rect, const char key[], const sk_sp<SkData>& value) { |
| 2279 |
this->drawAnnotation(rect, key, value.get()); |
| 2280 |
} |
| 2281 |
|
| 2282 |
/** Returns true if clip is empty; that is, nothing will draw. |
| 2283 |
|
| 2284 |
May do work when called; it should not be called |
| 2285 |
more often than needed. However, once called, subsequent calls perform no |
| 2286 |
work until clip changes. |
| 2287 |
|
| 2288 |
@return true if clip is empty |
| 2289 |
|
| 2290 |
example: https://fiddle.skia.org/c/@Canvas_isClipEmpty |
| 2291 |
*/ |
| 2292 |
virtual bool isClipEmpty() const; |
| 2293 |
|
| 2294 |
/** Returns true if clip is SkRect and not empty. |
| 2295 |
Returns false if the clip is empty, or if it is not SkRect. |
| 2296 |
|
| 2297 |
@return true if clip is SkRect and not empty |
| 2298 |
|
| 2299 |
example: https://fiddle.skia.org/c/@Canvas_isClipRect |
| 2300 |
*/ |
| 2301 |
virtual bool isClipRect() const; |
| 2302 |
|
| 2303 |
/** Returns the current transform from local coordinates to the 'device', which for most |
| 2304 |
* purposes means pixels. |
| 2305 |
* |
| 2306 |
* @return transformation from local coordinates to device / pixels. |
| 2307 |
*/ |
| 2308 |
SkM44 getLocalToDevice() const; |
| 2309 |
|
| 2310 |
/** |
| 2311 |
* Throws away the 3rd row and column in the matrix, so be warned. |
| 2312 |
*/ |
| 2313 |
SkMatrix getLocalToDeviceAs3x3() const { |
| 2314 |
return this->getLocalToDevice().asM33(); |
| 2315 |
} |
| 2316 |
|
| 2317 |
#ifdef SK_SUPPORT_LEGACY_GETTOTALMATRIX |
| 2318 |
/** DEPRECATED |
| 2319 |
* Legacy version of getLocalToDevice(), which strips away any Z information, and |
| 2320 |
* just returns a 3x3 version. |
| 2321 |
* |
| 2322 |
* @return 3x3 version of getLocalToDevice() |
| 2323 |
* |
| 2324 |
* example: https://fiddle.skia.org/c/@Canvas_getTotalMatrix |
| 2325 |
* example: https://fiddle.skia.org/c/@Clip |
| 2326 |
*/ |
| 2327 |
SkMatrix getTotalMatrix() const; |
| 2328 |
#endif |
| 2329 |
|
| 2330 |
/////////////////////////////////////////////////////////////////////////// |
| 2331 |
|
| 2332 |
/** |
| 2333 |
* Returns the global clip as a region. If the clip contains AA, then only the bounds |
| 2334 |
* of the clip may be returned. |
| 2335 |
*/ |
| 2336 |
void temporary_internal_getRgnClip(SkRegion* region); |
| 2337 |
|
| 2338 |
void private_draw_shadow_rec(const SkPath&, const SkDrawShadowRec&); |
| 2339 |
|
| 2340 |
|
| 2341 |
protected: |
| 2342 |
// default impl defers to getDevice()->newSurface(info) |
| 2343 |
virtual sk_sp<SkSurface> onNewSurface(const SkImageInfo& info, const SkSurfaceProps& props); |
| 2344 |
|
| 2345 |
// default impl defers to its device |
| 2346 |
virtual bool onPeekPixels(SkPixmap* pixmap); |
| 2347 |
virtual bool onAccessTopLayerPixels(SkPixmap* pixmap); |
| 2348 |
virtual SkImageInfo onImageInfo() const; |
| 2349 |
virtual bool onGetProps(SkSurfaceProps* props, bool top) const; |
| 2350 |
|
| 2351 |
// Subclass save/restore notifiers. |
| 2352 |
// Overriders should call the corresponding INHERITED method up the inheritance chain. |
| 2353 |
// getSaveLayerStrategy()'s return value may suppress full layer allocation. |
| 2354 |
enum SaveLayerStrategy { |
| 2355 |
kFullLayer_SaveLayerStrategy, |
| 2356 |
kNoLayer_SaveLayerStrategy, |
| 2357 |
}; |
| 2358 |
|
| 2359 |
virtual void willSave() {} |
| 2360 |
// Overriders should call the corresponding INHERITED method up the inheritance chain. |
| 2361 |
virtual SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec& ) { |
| 2362 |
return kFullLayer_SaveLayerStrategy; |
| 2363 |
} |
| 2364 |
|
| 2365 |
// returns true if we should actually perform the saveBehind, or false if we should just save. |
| 2366 |
virtual bool onDoSaveBehind(const SkRect*) { return true; } |
| 2367 |
virtual void willRestore() {} |
| 2368 |
virtual void didRestore() {} |
| 2369 |
|
| 2370 |
virtual void didConcat44(const SkM44&) {} |
| 2371 |
virtual void didSetM44(const SkM44&) {} |
| 2372 |
virtual void didTranslate(SkScalar, SkScalar) {} |
| 2373 |
virtual void didScale(SkScalar, SkScalar) {} |
| 2374 |
|
| 2375 |
// NOTE: If you are adding a new onDraw virtual to SkCanvas, PLEASE add an override to |
| 2376 |
// SkCanvasVirtualEnforcer (in SkCanvasVirtualEnforcer.h). This ensures that subclasses using |
| 2377 |
// that mechanism will be required to implement the new function. |
| 2378 |
virtual void onDrawPaint(const SkPaint& paint); |
| 2379 |
virtual void onDrawBehind(const SkPaint& paint); |
| 2380 |
virtual void onDrawRect(const SkRect& rect, const SkPaint& paint); |
| 2381 |
virtual void onDrawRRect(const SkRRect& rrect, const SkPaint& paint); |
| 2382 |
virtual void onDrawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint); |
| 2383 |
virtual void onDrawOval(const SkRect& rect, const SkPaint& paint); |
| 2384 |
virtual void onDrawArc(const SkRect& rect, SkScalar startAngle, SkScalar sweepAngle, |
| 2385 |
bool useCenter, const SkPaint& paint); |
| 2386 |
virtual void onDrawPath(const SkPath& path, const SkPaint& paint); |
| 2387 |
virtual void onDrawRegion(const SkRegion& region, const SkPaint& paint); |
| 2388 |
|
| 2389 |
virtual void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, |
| 2390 |
const SkPaint& paint); |
| 2391 |
|
| 2392 |
virtual void onDrawGlyphRunList(const sktext::GlyphRunList& glyphRunList, const SkPaint& paint); |
| 2393 |
|
| 2394 |
virtual void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], |
| 2395 |
const SkPoint texCoords[4], SkBlendMode mode, const SkPaint& paint); |
| 2396 |
virtual void onDrawPoints(PointMode mode, size_t count, const SkPoint pts[], |
| 2397 |
const SkPaint& paint); |
| 2398 |
|
| 2399 |
virtual void onDrawImage2(const SkImage*, SkScalar dx, SkScalar dy, const SkSamplingOptions&, |
| 2400 |
const SkPaint*); |
| 2401 |
virtual void onDrawImageRect2(const SkImage*, const SkRect& src, const SkRect& dst, |
| 2402 |
const SkSamplingOptions&, const SkPaint*, SrcRectConstraint); |
| 2403 |
virtual void onDrawImageLattice2(const SkImage*, const Lattice&, const SkRect& dst, |
| 2404 |
SkFilterMode, const SkPaint*); |
| 2405 |
virtual void onDrawAtlas2(const SkImage*, const SkRSXform[], const SkRect src[], |
| 2406 |
const SkColor[], int count, SkBlendMode, const SkSamplingOptions&, |
| 2407 |
const SkRect* cull, const SkPaint*); |
| 2408 |
virtual void onDrawEdgeAAImageSet2(const ImageSetEntry imageSet[], int count, |
| 2409 |
const SkPoint dstClips[], const SkMatrix preViewMatrices[], |
| 2410 |
const SkSamplingOptions&, const SkPaint*, |
| 2411 |
SrcRectConstraint); |
| 2412 |
|
| 2413 |
virtual void onDrawVerticesObject(const SkVertices* vertices, SkBlendMode mode, |
| 2414 |
const SkPaint& paint); |
| 2415 |
virtual void onDrawMesh(const SkMesh&, sk_sp<SkBlender>, const SkPaint&); |
| 2416 |
virtual void onDrawAnnotation(const SkRect& rect, const char key[], SkData* value); |
| 2417 |
virtual void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&); |
| 2418 |
|
| 2419 |
virtual void onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix); |
| 2420 |
virtual void onDrawPicture(const SkPicture* picture, const SkMatrix* matrix, |
| 2421 |
const SkPaint* paint); |
| 2422 |
|
| 2423 |
virtual void onDrawEdgeAAQuad(const SkRect& rect, const SkPoint clip[4], QuadAAFlags aaFlags, |
| 2424 |
const SkColor4f& color, SkBlendMode mode); |
| 2425 |
|
| 2426 |
enum ClipEdgeStyle { |
| 2427 |
kHard_ClipEdgeStyle, |
| 2428 |
kSoft_ClipEdgeStyle |
| 2429 |
}; |
| 2430 |
|
| 2431 |
virtual void onClipRect(const SkRect& rect, SkClipOp op, ClipEdgeStyle edgeStyle); |
| 2432 |
virtual void onClipRRect(const SkRRect& rrect, SkClipOp op, ClipEdgeStyle edgeStyle); |
| 2433 |
virtual void onClipPath(const SkPath& path, SkClipOp op, ClipEdgeStyle edgeStyle); |
| 2434 |
virtual void onClipShader(sk_sp<SkShader>, SkClipOp); |
| 2435 |
virtual void onClipRegion(const SkRegion& deviceRgn, SkClipOp op); |
| 2436 |
virtual void onResetClip(); |
| 2437 |
|
| 2438 |
virtual void onDiscard(); |
| 2439 |
|
| 2440 |
/** |
| 2441 |
*/ |
| 2442 |
virtual sk_sp<sktext::gpu::Slug> onConvertGlyphRunListToSlug( |
| 2443 |
const sktext::GlyphRunList& glyphRunList, const SkPaint& paint); |
| 2444 |
|
| 2445 |
/** |
| 2446 |
*/ |
| 2447 |
virtual void onDrawSlug(const sktext::gpu::Slug* slug, const SkPaint& paint); |
| 2448 |
|
| 2449 |
private: |
| 2450 |
enum class PredrawFlags : unsigned { |
| 2451 |
kNone = 0, |
| 2452 |
kOpaqueShaderOverride = 1, // The paint's shader is overridden with an opaque image |
| 2453 |
kNonOpaqueShaderOverride = 2, // The paint's shader is overridden but is not opaque |
| 2454 |
kCheckForOverwrite = 4, // Check if the draw would overwrite the entire surface |
| 2455 |
kSkipMaskFilterAutoLayer = 8, // Do not apply mask filters in the AutoLayer |
| 2456 |
}; |
| 2457 |
// Inlined SK_DECL_BITMASK_OPS_FRIENDS to avoid including SkEnumBitMask.h |
| 2458 |
friend constexpr SkEnumBitMask<PredrawFlags> operator|(PredrawFlags, PredrawFlags); |
| 2459 |
friend constexpr SkEnumBitMask<PredrawFlags> operator&(PredrawFlags, PredrawFlags); |
| 2460 |
friend constexpr SkEnumBitMask<PredrawFlags> operator^(PredrawFlags, PredrawFlags); |
| 2461 |
friend constexpr SkEnumBitMask<PredrawFlags> operator~(PredrawFlags); |
| 2462 |
|
| 2463 |
// notify our surface (if we have one) that we are about to draw, so it |
| 2464 |
// can perform copy-on-write or invalidate any cached images |
| 2465 |
// returns false if the copy failed |
| 2466 |
[[nodiscard]] bool predrawNotify(bool willOverwritesEntireSurface = false); |
| 2467 |
[[nodiscard]] bool predrawNotify(const SkRect*, const SkPaint*, SkEnumBitMask<PredrawFlags>); |
| 2468 |
|
| 2469 |
// call the appropriate predrawNotify and create a layer if needed. |
| 2470 |
std::optional<AutoLayerForImageFilter> aboutToDraw( |
| 2471 |
const SkPaint& paint, |
| 2472 |
const SkRect* rawBounds, |
| 2473 |
SkEnumBitMask<PredrawFlags> flags); |
| 2474 |
std::optional<AutoLayerForImageFilter> aboutToDraw( |
| 2475 |
const SkPaint& paint, |
| 2476 |
const SkRect* rawBounds = nullptr); |
| 2477 |
|
| 2478 |
// The bottom-most device in the stack, only changed by init(). Image properties and the final |
| 2479 |
// canvas pixels are determined by this device. |
| 2480 |
SkDevice* rootDevice() const { |
| 2481 |
SkASSERT(fRootDevice); |
| 2482 |
return fRootDevice.get(); |
| 2483 |
} |
| 2484 |
|
| 2485 |
// The top-most device in the stack, will change within saveLayer()'s. All drawing and clipping |
| 2486 |
// operations should route to this device. |
| 2487 |
SkDevice* topDevice() const; |
| 2488 |
|
| 2489 |
// Canvases maintain a sparse stack of layers, where the top-most layer receives the drawing, |
| 2490 |
// clip, and matrix commands. There is a layer per call to saveLayer() using the |
| 2491 |
// kFullLayer_SaveLayerStrategy. |
| 2492 |
struct Layer { |
| 2493 |
sk_sp<SkDevice> fDevice; |
| 2494 |
skia_private::STArray<1, sk_sp<SkImageFilter>> fImageFilters; |
| 2495 |
SkPaint fPaint; |
| 2496 |
bool fIsCoverage; |
| 2497 |
bool fDiscard; |
| 2498 |
|
| 2499 |
// If true, the layer image is sized to include a 1px buffer that remains transparent |
| 2500 |
// to allow for faster linear filtering under complex transforms. |
| 2501 |
bool fIncludesPadding; |
| 2502 |
|
| 2503 |
Layer(sk_sp<SkDevice> device, |
| 2504 |
FilterSpan imageFilters, |
| 2505 |
const SkPaint& paint, |
| 2506 |
bool isCoverage, |
| 2507 |
bool includesPadding); |
| 2508 |
}; |
| 2509 |
|
| 2510 |
// Encapsulate state needed to restore from saveBehind() |
| 2511 |
struct BackImage { |
| 2512 |
// Out of line to avoid including SkSpecialImage.h |
| 2513 |
BackImage(sk_sp<SkSpecialImage>, SkIPoint); |
| 2514 |
BackImage(const BackImage&); |
| 2515 |
BackImage(BackImage&&); |
| 2516 |
BackImage& operator=(const BackImage&); |
| 2517 |
~BackImage(); |
| 2518 |
|
| 2519 |
sk_sp<SkSpecialImage> fImage; |
| 2520 |
SkIPoint fLoc; |
| 2521 |
}; |
| 2522 |
|
| 2523 |
class MCRec { |
| 2524 |
public: |
| 2525 |
// If not null, this MCRec corresponds with the saveLayer() record that made the layer. |
| 2526 |
// The base "layer" is not stored here, since it is stored inline in SkCanvas and has no |
| 2527 |
// restoration behavior. |
| 2528 |
std::unique_ptr<Layer> fLayer; |
| 2529 |
|
| 2530 |
// This points to the device of the top-most layer (which may be lower in the stack), or |
| 2531 |
// to the canvas's fRootDevice. The MCRec does not own the device. |
| 2532 |
SkDevice* fDevice; |
| 2533 |
|
| 2534 |
std::unique_ptr<BackImage> fBackImage; |
| 2535 |
SkM44 fMatrix; |
| 2536 |
int fDeferredSaveCount = 0; |
| 2537 |
|
| 2538 |
MCRec(SkDevice* device); |
| 2539 |
MCRec(const MCRec* prev); |
| 2540 |
~MCRec(); |
| 2541 |
|
| 2542 |
void newLayer(sk_sp<SkDevice> layerDevice, |
| 2543 |
FilterSpan filters, |
| 2544 |
const SkPaint& restorePaint, |
| 2545 |
bool layerIsCoverage, |
| 2546 |
bool includesPadding); |
| 2547 |
|
| 2548 |
void reset(SkDevice* device); |
| 2549 |
}; |
| 2550 |
|
| 2551 |
#if defined(SK_CANVAS_SAVE_RESTORE_PREALLOC_COUNT) |
| 2552 |
static constexpr int kMCRecCount = SK_CANVAS_SAVE_RESTORE_PREALLOC_COUNT; |
| 2553 |
#else |
| 2554 |
static constexpr int kMCRecCount = 32; // common depth for save/restores |
| 2555 |
#endif |
| 2556 |
|
| 2557 |
// This stack allocation of memory will be used to house the first kMCRecCount |
| 2558 |
// layers without need to call malloc. |
| 2559 |
alignas(MCRec) std::byte fMCRecStorage[sizeof(MCRec) * kMCRecCount]; |
| 2560 |
|
| 2561 |
SkDeque fMCStack; // uses the stack memory |
| 2562 |
MCRec* fMCRec; // points to top of stack for convenience |
| 2563 |
|
| 2564 |
// Installed via init() |
| 2565 |
sk_sp<SkDevice> fRootDevice; |
| 2566 |
const SkSurfaceProps fProps; |
| 2567 |
|
| 2568 |
int fSaveCount; // value returned by getSaveCount() |
| 2569 |
|
| 2570 |
std::unique_ptr<SkRasterHandleAllocator> fAllocator; |
| 2571 |
|
| 2572 |
SkSurface_Base* fSurfaceBase; |
| 2573 |
SkSurface_Base* getSurfaceBase() const { return fSurfaceBase; } |
| 2574 |
void setSurfaceBase(SkSurface_Base* sb) { |
| 2575 |
fSurfaceBase = sb; |
| 2576 |
} |
| 2577 |
friend class SkSurface_Base; |
| 2578 |
friend class SkSurface_Ganesh; |
| 2579 |
|
| 2580 |
SkIRect fClipRestrictionRect = SkIRect::MakeEmpty(); |
| 2581 |
int fClipRestrictionSaveCount = -1; |
| 2582 |
|
| 2583 |
void doSave(); |
| 2584 |
void checkForDeferredSave(); |
| 2585 |
void internalSetMatrix(const SkM44&); |
| 2586 |
|
| 2587 |
virtual void onSurfaceDelete() {} |
| 2588 |
|
| 2589 |
friend class SkAndroidFrameworkUtils; |
| 2590 |
friend class SkCanvasPriv; // needs to expose android functions for testing outside android |
| 2591 |
friend class AutoLayerForImageFilter; |
| 2592 |
friend class SkSurface_Raster; // needs getDevice() |
| 2593 |
friend class SkNoDrawCanvas; // needs resetForNextPicture() |
| 2594 |
friend class SkNWayCanvas; |
| 2595 |
friend class SkPictureRecord; // predrawNotify (why does it need it? <reed>) |
| 2596 |
friend class SkOverdrawCanvas; |
| 2597 |
friend class SkRasterHandleAllocator; |
| 2598 |
friend class SkRecords::Draw; |
| 2599 |
template <typename Key> |
| 2600 |
friend class skiatest::TestCanvas; |
| 2601 |
|
| 2602 |
protected: |
| 2603 |
// For use by SkNoDrawCanvas (via SkCanvasVirtualEnforcer, which can't be a friend) |
| 2604 |
explicit SkCanvas(const SkIRect& bounds); |
| 2605 |
|
| 2606 |
private: |
| 2607 |
SkCanvas(const SkBitmap&, std::unique_ptr<SkRasterHandleAllocator>, |
| 2608 |
SkRasterHandleAllocator::Handle, const SkSurfaceProps* props); |
| 2609 |
|
| 2610 |
SkCanvas(SkCanvas&&) = delete; |
| 2611 |
SkCanvas(const SkCanvas&) = delete; |
| 2612 |
SkCanvas& operator=(SkCanvas&&) = delete; |
| 2613 |
SkCanvas& operator=(const SkCanvas&) = delete; |
| 2614 |
|
| 2615 |
friend class sktext::gpu::Slug; |
| 2616 |
friend class SkPicturePlayback; |
| 2617 |
/** |
| 2618 |
* Convert a SkTextBlob to a sktext::gpu::Slug using the current canvas state. |
| 2619 |
*/ |
| 2620 |
sk_sp<sktext::gpu::Slug> convertBlobToSlug(const SkTextBlob& blob, SkPoint origin, |
| 2621 |
const SkPaint& paint); |
| 2622 |
|
| 2623 |
/** |
| 2624 |
* Draw an sktext::gpu::Slug given the current canvas state. |
| 2625 |
*/ |
| 2626 |
void drawSlug(const sktext::gpu::Slug* slug, const SkPaint& paint); |
| 2627 |
|
| 2628 |
/** Experimental |
| 2629 |
* Saves the specified subset of the current pixels in the current layer, |
| 2630 |
* and then clears those pixels to transparent black. |
| 2631 |
* Restores the pixels on restore() by drawing them in SkBlendMode::kDstOver. |
| 2632 |
* |
| 2633 |
* @param subset conservative bounds of the area to be saved / restored. |
| 2634 |
* @return depth of save state stack before this call was made. |
| 2635 |
*/ |
| 2636 |
int only_axis_aligned_saveBehind(const SkRect* subset); |
| 2637 |
|
| 2638 |
/** |
| 2639 |
* Like drawPaint, but magically clipped to the most recent saveBehind buffer rectangle. |
| 2640 |
* If there is no active saveBehind, then this draws nothing. |
| 2641 |
*/ |
| 2642 |
void drawClippedToSaveBehind(const SkPaint&); |
| 2643 |
|
| 2644 |
void resetForNextPicture(const SkIRect& bounds); |
| 2645 |
|
| 2646 |
// needs gettotalclip() |
| 2647 |
friend class SkCanvasStateUtils; |
| 2648 |
|
| 2649 |
void init(sk_sp<SkDevice>); |
| 2650 |
|
| 2651 |
bool nothingToDraw(const SkPaint& paint) const; |
| 2652 |
|
| 2653 |
// All base onDrawX() functions should call this and skip drawing if it returns true. |
| 2654 |
// If 'matrix' is non-null, it maps the paint's fast bounds before checking for quick rejection |
| 2655 |
bool internalQuickReject(const SkRect& bounds, const SkPaint& paint, |
| 2656 |
const SkMatrix* matrix = nullptr); |
| 2657 |
|
| 2658 |
void internalDrawPaint(const SkPaint& paint); |
| 2659 |
void internalSaveLayer(const SaveLayerRec&, SaveLayerStrategy, bool coverageOnly=false); |
| 2660 |
void internalSaveBehind(const SkRect*); |
| 2661 |
|
| 2662 |
void internalConcat44(const SkM44&); |
| 2663 |
|
| 2664 |
// shared by save() and saveLayer() |
| 2665 |
void internalSave(); |
| 2666 |
void internalRestore(); |
| 2667 |
|
| 2668 |
enum class DeviceCompatibleWithFilter : int { |
| 2669 |
// Check the src device's local-to-device matrix for compatibility with the filter, and if |
| 2670 |
// it is not compatible, introduce an intermediate image and transformation that allows the |
| 2671 |
// filter to be evaluated on the modified src content. |
| 2672 |
kUnknown, |
| 2673 |
// Assume that the src device's local-to-device matrix is compatible with the filter. |
| 2674 |
kYes, |
| 2675 |
// Assume that the src device's local-to-device matrix is compatible with the filter, |
| 2676 |
// *and* the source image has a 1px buffer of padding. |
| 2677 |
kYesWithPadding |
| 2678 |
}; |
| 2679 |
/** |
| 2680 |
* Filters the contents of 'src' and draws the result into 'dst'. The filter is evaluated |
| 2681 |
* relative to the current canvas matrix, and src is drawn to dst using their relative transform |
| 2682 |
* 'paint' is applied after the filter and must not have a mask or image filter of its own. |
| 2683 |
* A null 'filter' behaves as if the identity filter were used. |
| 2684 |
* |
| 2685 |
* 'scaleFactor' is an extra uniform scale transform applied to downscale the 'src' image |
| 2686 |
* before any filtering, or as part of the copy, and is then drawn with 1/scaleFactor to 'dst'. |
| 2687 |
* Must be 1.0 if 'compat' is kYes (i.e. any scale factor has already been baked into the |
| 2688 |
* relative transforms between the devices). |
| 2689 |
* |
| 2690 |
* 'srcTileMode' is the tile mode to apply to the boundary of the 'src' image when insufficient |
| 2691 |
* content is available. It defaults to kDecal for the regular saveLayer() case. |
| 2692 |
*/ |
| 2693 |
void internalDrawDeviceWithFilter(SkDevice* src, SkDevice* dst, |
| 2694 |
FilterSpan filters, const SkPaint& paint, |
| 2695 |
DeviceCompatibleWithFilter compat, |
| 2696 |
const SkColorInfo& filterColorInfo, |
| 2697 |
SkScalar scaleFactor = 1.f, |
| 2698 |
SkTileMode srcTileMode = SkTileMode::kDecal, |
| 2699 |
bool srcIsCoverageLayer = false); |
| 2700 |
|
| 2701 |
/* |
| 2702 |
* Returns true if drawing the specified rect (or all if it is null) with the specified |
| 2703 |
* paint (or default if null) would overwrite the entire root device of the canvas |
| 2704 |
* (i.e. the canvas' surface if it had one). |
| 2705 |
*/ |
| 2706 |
bool wouldOverwriteEntireSurface(const SkRect*, const SkPaint*, |
| 2707 |
SkEnumBitMask<PredrawFlags>) const; |
| 2708 |
|
| 2709 |
/** |
| 2710 |
* Returns true if the clip (for any active layer) contains antialiasing. |
| 2711 |
* If the clip is empty, this will return false. |
| 2712 |
*/ |
| 2713 |
bool androidFramework_isClipAA() const; |
| 2714 |
|
| 2715 |
/** |
| 2716 |
* Reset the clip to be wide-open (modulo any separately specified device clip restriction). |
| 2717 |
* This operate within the save/restore clip stack so it can be undone by restoring to an |
| 2718 |
* earlier save point. |
| 2719 |
*/ |
| 2720 |
void internal_private_resetClip(); |
| 2721 |
|
| 2722 |
virtual SkPaintFilterCanvas* internal_private_asPaintFilterCanvas() const { return nullptr; } |
| 2723 |
|
| 2724 |
// Keep track of the device clip bounds in the canvas' global space to reject draws before |
| 2725 |
// invoking the top-level device. |
| 2726 |
SkRect fQuickRejectBounds; |
| 2727 |
|
| 2728 |
// Compute the clip's bounds based on all clipped SkDevice's reported device bounds transformed |
| 2729 |
// into the canvas' global space. |
| 2730 |
SkRect computeDeviceClipBounds(bool outsetForAA=true) const; |
| 2731 |
|
| 2732 |
// Returns the paint's mask filter if it can be used to draw an rrect with an analytic blur, and |
| 2733 |
// returns null otherwise. |
| 2734 |
const SkBlurMaskFilterImpl* canAttemptBlurredRRectDraw(const SkPaint&) const; |
| 2735 |
|
| 2736 |
// Attempt to draw a rrect with an analytic blur. If the draw succeeds or predrawNotify fails, |
| 2737 |
// nullopt is returned indicating that nothing further should be drawn. |
| 2738 |
std::optional<AutoLayerForImageFilter> attemptBlurredRRectDraw(const SkRRect&, |
| 2739 |
const SkBlurMaskFilterImpl*, |
| 2740 |
const SkPaint&, |
| 2741 |
SkEnumBitMask<PredrawFlags>); |
| 2742 |
|
| 2743 |
class AutoUpdateQRBounds; |
| 2744 |
void validateClip() const; |
| 2745 |
|
| 2746 |
std::unique_ptr<sktext::GlyphRunBuilder> fScratchGlyphRunBuilder; |
| 2747 |
}; |
| 2748 |
|
| 2749 |
/** \class SkAutoCanvasRestore |
| 2750 |
Stack helper class calls SkCanvas::restoreToCount when SkAutoCanvasRestore |
| 2751 |
goes out of scope. Use this to guarantee that the canvas is restored to a known |
| 2752 |
state. |
| 2753 |
*/ |
| 2754 |
class [[nodiscard]] SkAutoCanvasRestore { |
| 2755 |
public: |
| 2756 |
|
| 2757 |
/** Preserves SkCanvas::save() count. Optionally saves SkCanvas clip and SkCanvas matrix. |
| 2758 |
|
| 2759 |
@param canvas SkCanvas to guard |
| 2760 |
@param doSave call SkCanvas::save() |
| 2761 |
@return utility to restore SkCanvas state on destructor |
| 2762 |
*/ |
| 2763 |
SkAutoCanvasRestore(SkCanvas* canvas, bool doSave) : fCanvas(canvas), fSaveCount(0) { |
| 2764 |
if (fCanvas) { |
| 2765 |
fSaveCount = canvas->getSaveCount(); |
| 2766 |
if (doSave) { |
| 2767 |
canvas->save(); |
| 2768 |
} |
| 2769 |
} |
| 2770 |
} |
| 2771 |
|
| 2772 |
/** Restores SkCanvas to saved state. Destructor is called when container goes out of |
| 2773 |
scope. |
| 2774 |
*/ |
| 2775 |
~SkAutoCanvasRestore() { |
| 2776 |
if (fCanvas) { |
| 2777 |
fCanvas->restoreToCount(fSaveCount); |
| 2778 |
} |
| 2779 |
} |
| 2780 |
|
| 2781 |
/** Restores SkCanvas to saved state immediately. Subsequent calls and |
| 2782 |
~SkAutoCanvasRestore() have no effect. |
| 2783 |
*/ |
| 2784 |
void restore() { |
| 2785 |
if (fCanvas) { |
| 2786 |
fCanvas->restoreToCount(fSaveCount); |
| 2787 |
fCanvas = nullptr; |
| 2788 |
} |
| 2789 |
} |
| 2790 |
|
| 2791 |
private: |
| 2792 |
SkCanvas* fCanvas; |
| 2793 |
int fSaveCount; |
| 2794 |
|
| 2795 |
SkAutoCanvasRestore(SkAutoCanvasRestore&&) = delete; |
| 2796 |
SkAutoCanvasRestore(const SkAutoCanvasRestore&) = delete; |
| 2797 |
SkAutoCanvasRestore& operator=(SkAutoCanvasRestore&&) = delete; |
| 2798 |
SkAutoCanvasRestore& operator=(const SkAutoCanvasRestore&) = delete; |
| 2799 |
}; |
| 2800 |
|
| 2801 |
#endif |