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