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