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