Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1 | #Topic Canvas |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 2 | #Alias Canvas_Reference ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3 | |
Cary Clark | e4aa371 | 2017-09-15 02:56:12 -0400 | [diff] [blame] | 4 | #Class SkCanvas |
| 5 | |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 6 | #Code |
| 7 | #Populate |
| 8 | ## |
| 9 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 10 | Canvas provides an interface for drawing, and how the drawing is clipped and transformed. |
| 11 | Canvas contains a stack of Matrix and Clip values. |
| 12 | |
| 13 | Canvas and Paint together provide the state to draw into Surface or Device. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 14 | Each Canvas draw call transforms the geometry of the object by the concatenation of all |
| 15 | Matrix values in the stack. The transformed geometry is clipped by the intersection |
| 16 | of all of Clip values in the stack. The Canvas draw calls use Paint to supply drawing |
| 17 | state such as Color, Typeface, text size, stroke width, Shader and so on. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 18 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 19 | To draw to a pixel-based destination, create Raster_Surface or GPU_Surface. |
| 20 | Request Canvas from Surface to obtain the interface to draw. |
| 21 | Canvas generated by Raster_Surface draws to memory visible to the CPU. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 22 | Canvas generated by GPU_Surface uses Vulkan or OpenGL to draw to the GPU. |
| 23 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 24 | To draw to a document, obtain Canvas from SVG_Canvas, Document_PDF, or Picture_Recorder. |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 25 | Document based Canvas and other Canvas subclasses reference Device describing the |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 26 | destination. |
| 27 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 28 | Canvas can be constructed to draw to Bitmap without first creating Raster_Surface. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 29 | This approach may be deprecated in the future. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 30 | |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 31 | Canvas may be created directly when no Surface is required; some Canvas methods |
| 32 | implicitly create Raster_Surface. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 33 | |
| 34 | # ------------------------------------------------------------------------------ |
| 35 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 36 | #Method static std::unique_ptr<SkCanvas> MakeRasterDirect(const SkImageInfo& info, void* pixels, |
| 37 | size_t rowBytes, |
| 38 | const SkSurfaceProps* props = nullptr) |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 39 | #In Constructors |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 40 | #Line # creates from SkImageInfo and Pixel_Storage ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 41 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 42 | |
| 43 | #Example |
| 44 | #Description |
| 45 | Allocates a three by three bitmap, clears it to white, and draws a black pixel |
| 46 | in the center. |
| 47 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 48 | void draw(SkCanvas* ) { |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 49 | SkImageInfo info = SkImageInfo::MakeN32Premul(3, 3); // device aligned, 32 bpp, Premultiplied |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 50 | const size_t minRowBytes = info.minRowBytes(); // bytes used by one bitmap row |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 51 | const size_t size = info.computeMinByteSize(); // bytes used by all rows |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 52 | SkAutoTMalloc<SkPMColor> storage(size); // allocate storage for pixels |
| 53 | SkPMColor* pixels = storage.get(); // get pointer to allocated storage |
| 54 | // create a SkCanvas backed by a raster device, and delete it when the |
| 55 | // function goes out of scope. |
| 56 | std::unique_ptr<SkCanvas> canvas = SkCanvas::MakeRasterDirect(info, pixels, minRowBytes); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 57 | canvas->clear(SK_ColorWHITE); // white is Unpremultiplied, in ARGB order |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 58 | canvas->flush(); // ensure that pixels are cleared |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 59 | SkPMColor pmWhite = pixels[0]; // the Premultiplied format may vary |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 60 | SkPaint paint; // by default, draws black |
| 61 | canvas->drawPoint(1, 1, paint); // draw in the center |
| 62 | canvas->flush(); // ensure that point was drawn |
| 63 | for (int y = 0; y < info.height(); ++y) { |
| 64 | for (int x = 0; x < info.width(); ++x) { |
| 65 | SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x'); |
| 66 | } |
| 67 | SkDebugf("\n"); |
| 68 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 69 | } |
| 70 | #StdOut |
| 71 | --- |
| 72 | -x- |
| 73 | --- |
| 74 | ## |
| 75 | ## |
| 76 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 77 | #SeeAlso MakeRasterDirectN32 SkSurface::MakeRasterDirect |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 78 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 79 | ## |
| 80 | |
| 81 | # ------------------------------------------------------------------------------ |
| 82 | |
| 83 | #Method static std::unique_ptr<SkCanvas> MakeRasterDirectN32(int width, int height, SkPMColor* pixels, |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 84 | size_t rowBytes) |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 85 | #In Constructors |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 86 | #Line # creates from image data and Pixel_Storage ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 87 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 88 | |
| 89 | #Example |
| 90 | #Description |
| 91 | Allocates a three by three bitmap, clears it to white, and draws a black pixel |
| 92 | in the center. |
| 93 | ## |
| 94 | void draw(SkCanvas* ) { |
| 95 | const int width = 3; |
| 96 | const int height = 3; |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 97 | SkPMColor pixels[height][width]; // allocate a 3 by 3 Premultiplied bitmap on the stack |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 98 | // create a SkCanvas backed by a raster device, and delete it when the |
| 99 | // function goes out of scope. |
| 100 | std::unique_ptr<SkCanvas> canvas = SkCanvas::MakeRasterDirectN32( |
| 101 | width, |
| 102 | height, |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 103 | pixels[0], // top-left of the bitmap |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 104 | sizeof(pixels[0])); // byte width of the each row |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 105 | // write a Premultiplied value for white into all pixels in the bitmap |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 106 | canvas->clear(SK_ColorWHITE); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 107 | SkPMColor pmWhite = pixels[0][0]; // the Premultiplied format may vary |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 108 | SkPaint paint; // by default, draws black |
| 109 | canvas->drawPoint(1, 1, paint); // draw in the center |
| 110 | canvas->flush(); // ensure that pixels is ready to be read |
| 111 | for (int y = 0; y < height; ++y) { |
| 112 | for (int x = 0; x < width; ++x) { |
| 113 | SkDebugf("%c", pixels[y][x] == pmWhite ? '-' : 'x'); |
| 114 | } |
| 115 | SkDebugf("\n"); |
| 116 | } |
| 117 | } |
| 118 | #StdOut |
| 119 | --- |
| 120 | -x- |
| 121 | --- |
| 122 | ## |
| 123 | ## |
| 124 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 125 | #SeeAlso MakeRasterDirect SkSurface::MakeRasterDirect SkImageInfo::MakeN32Premul |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 126 | |
| 127 | ## |
| 128 | |
| 129 | # ------------------------------------------------------------------------------ |
| 130 | |
| 131 | #Method SkCanvas() |
| 132 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 133 | #Line # creates with no Surface, no dimensions ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 134 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 135 | |
| 136 | #Example |
| 137 | |
| 138 | #Description |
| 139 | Passes a placeholder to a function that requires one. |
| 140 | ## |
| 141 | |
| 142 | #Function |
Mike Reed | 07055a3 | 2018-10-23 13:57:46 -0400 | [diff] [blame] | 143 | static void check_for_rotated_ctm(const SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 144 | const SkMatrix& matrix = canvas->getTotalMatrix(); |
Mike Reed | 07055a3 | 2018-10-23 13:57:46 -0400 | [diff] [blame] | 145 | SkDebugf("rect stays rect is %s\n", matrix.rectStaysRect() ? "true" : "false"); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 146 | } |
| 147 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 148 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 149 | void draw(SkCanvas* canvas) { |
Mike Reed | 07055a3 | 2018-10-23 13:57:46 -0400 | [diff] [blame] | 150 | check_for_rotated_ctm(canvas); |
| 151 | canvas->rotate(30); |
| 152 | check_for_rotated_ctm(canvas); |
| 153 | |
| 154 | SkCanvas defaultCanvas; |
| 155 | check_for_rotated_ctm(&defaultCanvas); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 156 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 157 | |
| 158 | #StdOut |
Mike Reed | 07055a3 | 2018-10-23 13:57:46 -0400 | [diff] [blame] | 159 | rect stays rect is true |
| 160 | rect stays rect is false |
| 161 | rect stays rect is true |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 162 | ## |
| 163 | ## |
| 164 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 165 | #SeeAlso MakeRasterDirect SkRasterHandleAllocator::MakeCanvas SkSurface::getCanvas SkCreateColorSpaceXformCanvas |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 166 | |
| 167 | ## |
| 168 | |
| 169 | # ------------------------------------------------------------------------------ |
| 170 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 171 | #Method SkCanvas(int width, int height, const SkSurfaceProps* props = nullptr) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 172 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 173 | #Line # creates with no Surface, set dimensions, Surface_Properties ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 174 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 175 | |
| 176 | #Example |
| 177 | SkCanvas canvas(10, 20); // 10 units wide, 20 units high |
| 178 | canvas.clipRect(SkRect::MakeXYWH(30, 40, 5, 10)); // clip is outside canvas' device |
| 179 | SkDebugf("canvas %s empty\n", canvas.getDeviceClipBounds().isEmpty() ? "is" : "is not"); |
| 180 | |
| 181 | #StdOut |
| 182 | canvas is empty |
| 183 | ## |
| 184 | ## |
| 185 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 186 | #SeeAlso MakeRasterDirect SkSurfaceProps SkPixelGeometry SkCreateColorSpaceXformCanvas |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 187 | |
| 188 | ## |
| 189 | |
| 190 | # ------------------------------------------------------------------------------ |
| 191 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 192 | #Method explicit SkCanvas(sk_sp<SkBaseDevice> device) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 193 | #Deprecated soon |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 194 | ## |
| 195 | |
| 196 | # ------------------------------------------------------------------------------ |
| 197 | |
| 198 | #Method explicit SkCanvas(const SkBitmap& bitmap) |
| 199 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 200 | #Line # uses existing Bitmap ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 201 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 202 | |
| 203 | #Example |
| 204 | #Description |
| 205 | The actual output depends on the installed fonts. |
| 206 | ## |
| 207 | SkBitmap bitmap; |
| 208 | // create a bitmap 5 wide and 11 high |
| 209 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(5, 11)); |
| 210 | SkCanvas canvas(bitmap); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 211 | canvas.clear(SK_ColorWHITE); // white is Unpremultiplied, in ARGB order |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 212 | SkPixmap pixmap; // provides guaranteed access to the drawn pixels |
| 213 | if (!canvas.peekPixels(&pixmap)) { |
| 214 | SkDebugf("peekPixels should never fail.\n"); |
| 215 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 216 | const SkPMColor* pixels = pixmap.addr32(); // points to top-left of bitmap |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 217 | SkPMColor pmWhite = pixels[0]; // the Premultiplied format may vary |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 218 | SkPaint paint; // by default, draws black, 12 point text |
| 219 | canvas.drawString("!", 1, 10, paint); // 1 char at baseline (1, 10) |
| 220 | for (int y = 0; y < bitmap.height(); ++y) { |
| 221 | for (int x = 0; x < bitmap.width(); ++x) { |
| 222 | SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x'); |
| 223 | } |
| 224 | SkDebugf("\n"); |
| 225 | } |
| 226 | |
| 227 | #StdOut |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 228 | ----- |
| 229 | ---x- |
| 230 | ---x- |
| 231 | ---x- |
| 232 | ---x- |
| 233 | ---x- |
| 234 | ---x- |
| 235 | ----- |
| 236 | ---x- |
| 237 | ---x- |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 238 | ----- |
| 239 | #StdOut ## |
| 240 | ## |
| 241 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 242 | #SeeAlso MakeRasterDirect SkRasterHandleAllocator::MakeCanvas SkSurface::getCanvas SkCreateColorSpaceXformCanvas |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 243 | |
| 244 | ## |
| 245 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 246 | #EnumClass ColorBehavior |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 247 | #Line # exists for Android framework only ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 248 | #Private |
| 249 | Android framework only. |
| 250 | ## |
| 251 | |
| 252 | #Code |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 253 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 254 | ## |
| 255 | #Const kLegacy 0 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 256 | #Line # placeholder ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 257 | Is a placeholder to allow specialized constructor; has no meaning. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 258 | ## |
| 259 | ## |
| 260 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 261 | #Method SkCanvas(const SkBitmap& bitmap, ColorBehavior behavior) |
| 262 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 263 | #Line # exists for Android framework only ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 264 | #Populate |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 265 | |
| 266 | #NoExample |
| 267 | ## |
| 268 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 269 | |
| 270 | # ------------------------------------------------------------------------------ |
| 271 | |
| 272 | #Method SkCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props) |
| 273 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 274 | #Line # uses existing Bitmap and Surface_Properties ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 275 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 276 | |
| 277 | #Example |
| 278 | #Description |
| 279 | The actual output depends on the installed fonts. |
| 280 | ## |
| 281 | SkBitmap bitmap; |
| 282 | // create a bitmap 5 wide and 11 high |
| 283 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(5, 11)); |
| 284 | SkCanvas canvas(bitmap, SkSurfaceProps(0, kUnknown_SkPixelGeometry)); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 285 | canvas.clear(SK_ColorWHITE); // white is Unpremultiplied, in ARGB order |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 286 | SkPixmap pixmap; // provides guaranteed access to the drawn pixels |
| 287 | if (!canvas.peekPixels(&pixmap)) { |
| 288 | SkDebugf("peekPixels should never fail.\n"); |
| 289 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 290 | const SkPMColor* pixels = pixmap.addr32(); // points to top-left of bitmap |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 291 | SkPMColor pmWhite = pixels[0]; // the Premultiplied format may vary |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 292 | SkPaint paint; // by default, draws black, 12 point text |
| 293 | canvas.drawString("!", 1, 10, paint); // 1 char at baseline (1, 10) |
| 294 | for (int y = 0; y < bitmap.height(); ++y) { |
| 295 | for (int x = 0; x < bitmap.width(); ++x) { |
| 296 | SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x'); |
| 297 | } |
| 298 | SkDebugf("\n"); |
| 299 | } |
| 300 | |
| 301 | #StdOut |
| 302 | ----- |
| 303 | ---x- |
| 304 | ---x- |
| 305 | ---x- |
| 306 | ---x- |
| 307 | ---x- |
| 308 | ---x- |
| 309 | ----- |
| 310 | ---x- |
| 311 | ---x- |
| 312 | ----- |
| 313 | #StdOut ## |
| 314 | ## |
| 315 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 316 | #SeeAlso MakeRasterDirect SkRasterHandleAllocator::MakeCanvas SkSurface::getCanvas SkCreateColorSpaceXformCanvas |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 317 | |
| 318 | ## |
| 319 | |
| 320 | # ------------------------------------------------------------------------------ |
| 321 | |
| 322 | #Method virtual ~SkCanvas() |
| 323 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 324 | #Line # draws saved Layers, frees resources ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 325 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 326 | |
| 327 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 328 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 329 | Canvas Layer draws into bitmap. saveLayerAlpha sets up an additional |
| 330 | drawing surface that blends with the bitmap. When Layer goes out of |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 331 | scope, Layer destructor is called. The saved Layer is restored, drawing |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 332 | transparent letters. |
| 333 | ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 334 | void draw(SkCanvas* canvas) { |
| 335 | SkBitmap bitmap; |
| 336 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(200, 200)); |
| 337 | { |
| 338 | SkCanvas offscreen(bitmap); |
| 339 | SkPaint paint; |
| 340 | paint.setTextSize(100); |
| 341 | offscreen.drawString("ABC", 20, 160, paint); |
| 342 | SkRect layerBounds = SkRect::MakeXYWH(32, 32, 192, 192); |
| 343 | offscreen.saveLayerAlpha(&layerBounds, 128); |
| 344 | offscreen.clear(SK_ColorWHITE); |
| 345 | offscreen.drawString("DEF", 20, 160, paint); |
| 346 | } |
| 347 | canvas->drawBitmap(bitmap, 0, 0, nullptr); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 348 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 349 | ## |
| 350 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 351 | #SeeAlso State_Stack |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 352 | |
| 353 | ## |
| 354 | |
| 355 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 356 | #Subtopic Property |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 357 | #Line # metrics and attributes ## |
| 358 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 359 | |
| 360 | #Method SkMetaData& getMetaData() |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 361 | #In Property |
| 362 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 363 | #Line # associates additional data with the canvas ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 364 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 365 | |
| 366 | #Example |
| 367 | const char* kHelloMetaData = "HelloMetaData"; |
| 368 | SkCanvas canvas; |
| 369 | SkMetaData& metaData = canvas.getMetaData(); |
| 370 | SkDebugf("before: %s\n", metaData.findString(kHelloMetaData)); |
| 371 | metaData.setString(kHelloMetaData, "Hello!"); |
| 372 | SkDebugf("during: %s\n", metaData.findString(kHelloMetaData)); |
| 373 | metaData.removeString(kHelloMetaData); |
| 374 | SkDebugf("after: %s\n", metaData.findString(kHelloMetaData)); |
| 375 | |
| 376 | #StdOut |
| 377 | before: (null) |
| 378 | during: Hello! |
| 379 | after: (null) |
| 380 | #StdOut ## |
| 381 | ## |
| 382 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 383 | #SeeAlso SkMetaData |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 384 | |
| 385 | ## |
| 386 | |
| 387 | # ------------------------------------------------------------------------------ |
| 388 | |
| 389 | #Method SkImageInfo imageInfo() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 390 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 391 | #Line # returns Image_Info for Canvas ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 392 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 393 | |
| 394 | #Example |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 395 | SkCanvas emptyCanvas; |
| 396 | SkImageInfo canvasInfo = emptyCanvas.imageInfo(); |
| 397 | SkImageInfo emptyInfo; |
| 398 | SkDebugf("emptyInfo %c= canvasInfo\n", emptyInfo == canvasInfo ? '=' : '!'); |
| 399 | |
| 400 | #StdOut |
| 401 | emptyInfo == canvasInfo |
| 402 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 403 | ## |
| 404 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 405 | #SeeAlso SkImageInfo MakeRasterDirect makeSurface |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 406 | |
| 407 | ## |
| 408 | |
| 409 | # ------------------------------------------------------------------------------ |
| 410 | |
| 411 | #Method bool getProps(SkSurfaceProps* props) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 412 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 413 | #Line # copies Surface_Properties if available ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 414 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 415 | |
| 416 | #Example |
| 417 | SkBitmap bitmap; |
| 418 | SkCanvas canvas(bitmap, SkSurfaceProps(0, kRGB_V_SkPixelGeometry)); |
| 419 | SkSurfaceProps surfaceProps(0, kUnknown_SkPixelGeometry); |
| 420 | SkDebugf("isRGB:%d\n", SkPixelGeometryIsRGB(surfaceProps.pixelGeometry())); |
| 421 | if (!canvas.getProps(&surfaceProps)) { |
| 422 | SkDebugf("getProps failed unexpectedly.\n"); |
| 423 | } |
| 424 | SkDebugf("isRGB:%d\n", SkPixelGeometryIsRGB(surfaceProps.pixelGeometry())); |
| 425 | |
| 426 | #StdOut |
| 427 | isRGB:0 |
| 428 | isRGB:1 |
| 429 | #StdOut ## |
| 430 | ## |
| 431 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 432 | #SeeAlso SkSurfaceProps makeSurface |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 433 | |
| 434 | ## |
| 435 | |
| 436 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 437 | #Subtopic Utility |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 438 | #Line # rarely called management functions ## |
| 439 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 440 | |
| 441 | #Method void flush() |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 442 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 443 | #Line # triggers execution of all pending draw operations ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 444 | #Populate |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 445 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 446 | #NoExample |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 447 | ## |
| 448 | |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 449 | #SeeAlso peekPixels SkSurface::flush GrContext::flush SkSurface::prepareForExternalIO GrContext::abandonContext |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 450 | |
| 451 | ## |
| 452 | |
| 453 | # ------------------------------------------------------------------------------ |
| 454 | |
| 455 | #Method virtual SkISize getBaseLayerSize() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 456 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 457 | #Line # returns size of base Layer in global coordinates ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 458 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 459 | |
| 460 | #Example |
| 461 | SkBitmap bitmap; |
| 462 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(20, 30)); |
| 463 | SkCanvas canvas(bitmap, SkSurfaceProps(0, kUnknown_SkPixelGeometry)); |
| 464 | canvas.clipRect(SkRect::MakeWH(10, 40)); |
| 465 | SkIRect clipDeviceBounds = canvas.getDeviceClipBounds(); |
| 466 | if (clipDeviceBounds.isEmpty()) { |
| 467 | SkDebugf("Empty clip bounds is unexpected!\n"); |
| 468 | } |
| 469 | SkDebugf("clip=%d,%d\n", clipDeviceBounds.width(), clipDeviceBounds.height()); |
| 470 | SkISize baseLayerSize = canvas.getBaseLayerSize(); |
| 471 | SkDebugf("size=%d,%d\n", baseLayerSize.width(), baseLayerSize.height()); |
| 472 | |
| 473 | #StdOut |
| 474 | clip=10,30 |
| 475 | size=20,30 |
| 476 | ## |
| 477 | ## |
| 478 | |
| 479 | #ToDo is this the same as the width and height of surface? ## |
| 480 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 481 | #SeeAlso getDeviceClipBounds |
| 482 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 483 | ## |
| 484 | |
| 485 | # ------------------------------------------------------------------------------ |
| 486 | |
| 487 | #Method sk_sp<SkSurface> makeSurface(const SkImageInfo& info, const SkSurfaceProps* props = nullptr) |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 488 | #In Constructors |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 489 | #Line # creates Surface matching SkImageInfo and SkSurfaceProps ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 490 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 491 | |
| 492 | #Example |
| 493 | sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(5, 6); |
| 494 | SkCanvas* smallCanvas = surface->getCanvas(); |
| 495 | SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(3, 4); |
| 496 | sk_sp<SkSurface> compatible = smallCanvas->makeSurface(imageInfo); |
| 497 | SkDebugf("compatible %c= nullptr\n", compatible == nullptr ? '=' : '!'); |
| 498 | SkDebugf("size = %d, %d\n", compatible->width(), compatible->height()); |
| 499 | |
| 500 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 501 | compatible != nullptr |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 502 | size = 3, 4 |
| 503 | ## |
| 504 | ## |
| 505 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 506 | #SeeAlso SkSurface SkSurface::makeSurface SkImageInfo SkSurfaceProps |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 507 | |
| 508 | ## |
| 509 | |
| 510 | # ------------------------------------------------------------------------------ |
| 511 | |
| 512 | #Method virtual GrContext* getGrContext() |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 513 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 514 | #Line # returns GPU_Context of the GPU_Surface ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 515 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 516 | |
| 517 | #Example |
| 518 | void draw(SkCanvas* canvas) { |
| 519 | if (canvas->getGrContext()) { |
| 520 | canvas->clear(SK_ColorRED); |
| 521 | } else { |
| 522 | canvas->clear(SK_ColorBLUE); |
| 523 | } |
| 524 | } |
| 525 | ## |
| 526 | |
| 527 | #ToDo fiddle should show both CPU and GPU out ## |
| 528 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 529 | #SeeAlso GrContext |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 530 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 531 | ## |
| 532 | |
| 533 | # ------------------------------------------------------------------------------ |
| 534 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 535 | #Method void* accessTopLayerPixels(SkImageInfo* info, size_t* rowBytes, SkIPoint* origin = nullptr) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 536 | #In Utility |
| 537 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 538 | #Line # returns writable pixel access if available ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 539 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 540 | |
| 541 | #Example |
| 542 | void draw(SkCanvas* canvas) { |
| 543 | if (canvas->accessTopLayerPixels(nullptr, nullptr)) { |
| 544 | canvas->clear(SK_ColorRED); |
| 545 | } else { |
| 546 | canvas->clear(SK_ColorBLUE); |
| 547 | } |
| 548 | } |
| 549 | ## |
| 550 | |
| 551 | #Example |
| 552 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 553 | Draws "ABC" on the device. Then draws "DEF" in Layer, and reads |
| 554 | Layer to add a large dotted "DEF". Finally blends Layer with the |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 555 | device. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 556 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 557 | The Layer and blended result appear on the CPU and GPU but the large dotted |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 558 | "DEF" appear only on the CPU. |
| 559 | ## |
| 560 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 561 | SkPaint paint; |
| 562 | paint.setTextSize(100); |
| 563 | canvas->drawString("ABC", 20, 160, paint); |
| 564 | SkRect layerBounds = SkRect::MakeXYWH(32, 32, 192, 192); |
| 565 | canvas->saveLayerAlpha(&layerBounds, 128); |
| 566 | canvas->clear(SK_ColorWHITE); |
| 567 | canvas->drawString("DEF", 20, 160, paint); |
| 568 | SkImageInfo imageInfo; |
| 569 | size_t rowBytes; |
| 570 | SkIPoint origin; |
| 571 | uint32_t* access = (uint32_t*) canvas->accessTopLayerPixels(&imageInfo, &rowBytes, &origin); |
| 572 | if (access) { |
| 573 | int h = imageInfo.height(); |
| 574 | int v = imageInfo.width(); |
| 575 | int rowWords = rowBytes / sizeof(uint32_t); |
| 576 | for (int y = 0; y < h; ++y) { |
| 577 | int newY = (y - h / 2) * 2 + h / 2; |
| 578 | if (newY < 0 || newY >= h) { |
| 579 | continue; |
| 580 | } |
| 581 | for (int x = 0; x < v; ++x) { |
| 582 | int newX = (x - v / 2) * 2 + v / 2; |
| 583 | if (newX < 0 || newX >= v) { |
| 584 | continue; |
| 585 | } |
| 586 | if (access[y * rowWords + x] == SK_ColorBLACK) { |
| 587 | access[newY * rowWords + newX] = SK_ColorGRAY; |
| 588 | } |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 593 | canvas->restore(); |
| 594 | } |
| 595 | ## |
| 596 | |
| 597 | #ToDo there are no callers of this that I can find. Deprecate? ## |
| 598 | #ToDo fiddle should show both CPU and GPU out ## |
| 599 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 600 | #SeeAlso SkImageInfo SkPixmap |
| 601 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 602 | ## |
| 603 | |
| 604 | # ------------------------------------------------------------------------------ |
| 605 | |
| 606 | #Method SkRasterHandleAllocator::Handle accessTopRasterHandle() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 607 | #In Utility |
| 608 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 609 | #Line # returns context that tracks Clip and Matrix ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 610 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 611 | |
| 612 | #Example |
| 613 | #Description |
| 614 | #ToDo ## |
| 615 | ## |
| 616 | #Function |
| 617 | static void DeleteCallback(void*, void* context) { |
| 618 | delete (char*) context; |
| 619 | } |
| 620 | |
| 621 | class CustomAllocator : public SkRasterHandleAllocator { |
| 622 | public: |
| 623 | bool allocHandle(const SkImageInfo& info, Rec* rec) override { |
| 624 | char* context = new char[4]{'s', 'k', 'i', 'a'}; |
| 625 | rec->fReleaseProc = DeleteCallback; |
| 626 | rec->fReleaseCtx = context; |
| 627 | rec->fHandle = context; |
| 628 | rec->fPixels = context; |
| 629 | rec->fRowBytes = 4; |
| 630 | return true; |
| 631 | } |
| 632 | |
| 633 | void updateHandle(Handle handle, const SkMatrix& ctm, const SkIRect& clip_bounds) override { |
| 634 | // apply canvas matrix and clip to custom environment |
| 635 | } |
| 636 | }; |
| 637 | |
| 638 | ## |
| 639 | void draw(SkCanvas* canvas) { |
| 640 | const SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1); |
| 641 | std::unique_ptr<SkCanvas> c2 = |
| 642 | SkRasterHandleAllocator::MakeCanvas(std::unique_ptr<CustomAllocator>( |
| 643 | new CustomAllocator()), info); |
| 644 | char* context = (char*) c2->accessTopRasterHandle(); |
| 645 | SkDebugf("context = %.4s\n", context); |
| 646 | |
| 647 | } |
| 648 | #StdOut |
| 649 | context = skia |
| 650 | ## |
| 651 | #ToDo skstd::make_unique could not be used because def is private -- note to fix in c++14? ## |
| 652 | ## |
| 653 | |
| 654 | #SeeAlso SkRasterHandleAllocator |
| 655 | |
| 656 | ## |
| 657 | |
| 658 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 659 | #Subtopic Pixels |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 660 | #Line # read and write pixel values ## |
| 661 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 662 | |
| 663 | #Method bool peekPixels(SkPixmap* pixmap) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 664 | #In Pixels |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 665 | #Line # returns if Canvas has direct access to its pixels ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 666 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 667 | |
| 668 | #Example |
| 669 | SkPixmap pixmap; |
| 670 | if (canvas->peekPixels(&pixmap)) { |
| 671 | SkDebugf("width=%d height=%d\n", pixmap.bounds().width(), pixmap.bounds().height()); |
| 672 | } |
| 673 | #StdOut |
| 674 | width=256 height=256 |
| 675 | ## |
| 676 | ## |
| 677 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 678 | #SeeAlso readPixels SkBitmap::peekPixels SkImage::peekPixels SkSurface::peekPixels |
| 679 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 680 | ## |
| 681 | |
| 682 | # ------------------------------------------------------------------------------ |
| 683 | |
| 684 | #Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, |
| 685 | int srcX, int srcY) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 686 | #In Pixels |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 687 | #Line # copies and converts rectangle of pixels from Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 688 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 689 | Copies Rect of pixels from Canvas into dstPixels. Matrix and Clip are |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 690 | ignored. |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 691 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 692 | Source Rect corners are (srcX, srcY) and (imageInfo().width(), imageInfo().height()). |
| 693 | Destination Rect corners are (0, 0) and (dstInfo.width(), dstInfo.height()). |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 694 | Copies each readable pixel intersecting both rectangles, without scaling, |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 695 | converting to dstInfo.colorType() and dstInfo.alphaType() if required. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 696 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 697 | Pixels are readable when Device is raster, or backed by a GPU. |
| 698 | Pixels are not readable when SkCanvas is returned by SkDocument::beginPage, |
| 699 | returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility |
Brian Osman | 46fe9c7 | 2018-03-09 15:44:34 -0500 | [diff] [blame] | 700 | class like SkDebugCanvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 701 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 702 | The destination pixel storage must be allocated by the caller. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 703 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 704 | Pixel values are converted only if Color_Type and Alpha_Type |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 705 | do not match. Only pixels within both source and destination rectangles |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 706 | are copied. dstPixels contents outside Rect intersection are unchanged. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 707 | |
| 708 | Pass negative values for srcX or srcY to offset pixels across or down destination. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 709 | |
| 710 | Does not copy, and returns false if: |
| 711 | |
| 712 | #List |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 713 | # Source and destination rectangles do not intersect. ## |
| 714 | # Canvas pixels could not be converted to dstInfo.colorType() or dstInfo.alphaType(). ## |
| 715 | # Canvas pixels are not readable; for instance, Canvas is document-based. ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 716 | # dstRowBytes is too small to contain one row of pixels. ## |
| 717 | ## |
| 718 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 719 | #Param dstInfo width, height, Color_Type, and Alpha_Type of dstPixels ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 720 | #Param dstPixels storage for pixels; dstInfo.height() times dstRowBytes, or larger ## |
| 721 | #Param dstRowBytes size of one destination row; dstInfo.width() times pixel size, or larger ## |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 722 | #Param srcX offset into readable pixels on x-axis; may be negative ## |
| 723 | #Param srcY offset into readable pixels on y-axis; may be negative ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 724 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 725 | #Return true if pixels were copied ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 726 | |
| 727 | #Example |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 728 | #Width 64 |
| 729 | #Height 64 |
| 730 | #Description |
| 731 | A black circle drawn on a blue background provides an image to copy. |
| 732 | readPixels copies one quarter of the canvas into each of the four corners. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 733 | The copied quarter circles overdraw the original circle. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 734 | ## |
| 735 | canvas->clear(SK_ColorBLUE); |
| 736 | SkPaint paint; |
| 737 | canvas->drawCircle(32, 32, 28, paint); |
| 738 | SkImageInfo info = SkImageInfo::Make(64, 64, kBGRA_8888_SkColorType, kPremul_SkAlphaType); |
| 739 | sk_sp<SkData> data(SkData::MakeUninitialized(info.minRowBytes() * info.height())); |
| 740 | sk_bzero(data->writable_data(), info.minRowBytes() * info.height()); |
| 741 | for (int x : { 32, -32 } ) { |
| 742 | for (int y : { 32, -32 } ) { |
| 743 | canvas->readPixels(info, data->writable_data(), info.minRowBytes(), x, y); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 744 | } |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 745 | } |
| 746 | sk_sp<SkImage> image = SkImage::MakeRasterData(info, data, info.minRowBytes()); |
| 747 | canvas->drawImage(image, 0, 0); |
| 748 | ## |
| 749 | |
| 750 | #Example |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 751 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 752 | Canvas returned by Raster_Surface has Premultiplied pixel values. |
| 753 | clear() takes Unpremultiplied input with Color_Alpha equal 0x80 |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 754 | and RGB equal 0x55, 0xAA, 0xFF. RGB is multiplied by Color_Alpha |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 755 | to generate Premultiplied value 0x802B5580. readPixels converts pixel back |
| 756 | to Unpremultiplied value 0x8056A9FF, introducing error. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 757 | ## |
| 758 | canvas->clear(0x8055aaff); |
| 759 | for (SkAlphaType alphaType : { kPremul_SkAlphaType, kUnpremul_SkAlphaType } ) { |
| 760 | uint32_t pixel = 0; |
| 761 | SkImageInfo info = SkImageInfo::Make(1, 1, kBGRA_8888_SkColorType, alphaType); |
| 762 | if (canvas->readPixels(info, &pixel, 4, 0, 0)) { |
| 763 | SkDebugf("pixel = %08x\n", pixel); |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | #StdOut |
| 768 | pixel = 802b5580 |
| 769 | pixel = 8056a9ff |
| 770 | ## |
| 771 | ## |
| 772 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 773 | #SeeAlso peekPixels writePixels drawBitmap drawImage SkBitmap::readPixels SkPixmap::readPixels SkImage::readPixels SkSurface::readPixels |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 774 | |
| 775 | ## |
| 776 | |
| 777 | # ------------------------------------------------------------------------------ |
| 778 | |
| 779 | #Method bool readPixels(const SkPixmap& pixmap, int srcX, int srcY) |
| 780 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 781 | Copies Rect of pixels from Canvas into pixmap. Matrix and Clip are |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 782 | ignored. |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 783 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 784 | Source Rect corners are (srcX, srcY) and (imageInfo().width(), imageInfo().height()). |
| 785 | Destination Rect corners are (0, 0) and (pixmap.width(), pixmap.height()). |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 786 | Copies each readable pixel intersecting both rectangles, without scaling, |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 787 | converting to pixmap.colorType() and pixmap.alphaType() if required. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 788 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 789 | Pixels are readable when Device is raster, or backed by a GPU. |
| 790 | Pixels are not readable when SkCanvas is returned by SkDocument::beginPage, |
| 791 | returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility |
Brian Osman | 46fe9c7 | 2018-03-09 15:44:34 -0500 | [diff] [blame] | 792 | class like SkDebugCanvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 793 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 794 | Caller must allocate pixel storage in pixmap if needed. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 795 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 796 | Pixel values are converted only if Color_Type and Alpha_Type |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 797 | do not match. Only pixels within both source and destination Rects |
| 798 | are copied. pixmap pixels contents outside Rect intersection are unchanged. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 799 | |
| 800 | Pass negative values for srcX or srcY to offset pixels across or down pixmap. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 801 | |
| 802 | Does not copy, and returns false if: |
| 803 | |
| 804 | #List |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 805 | # Source and destination rectangles do not intersect. ## |
| 806 | # Canvas pixels could not be converted to pixmap.colorType() or pixmap.alphaType(). ## |
| 807 | # Canvas pixels are not readable; for instance, Canvas is document-based. ## |
| 808 | # Pixmap pixels could not be allocated. ## |
| 809 | # pixmap.rowBytes() is too small to contain one row of pixels. ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 810 | ## |
| 811 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 812 | #Param pixmap storage for pixels copied from Canvas ## |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 813 | #Param srcX offset into readable pixels on x-axis; may be negative ## |
| 814 | #Param srcY offset into readable pixels on y-axis; may be negative ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 815 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 816 | #Return true if pixels were copied ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 817 | |
| 818 | #Example |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 819 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 820 | clear() takes Unpremultiplied input with Color_Alpha equal 0x80 |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 821 | and RGB equal 0x55, 0xAA, 0xFF. RGB is multiplied by Color_Alpha |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 822 | to generate Premultiplied value 0x802B5580. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 823 | ## |
| 824 | void draw(SkCanvas* canvas) { |
| 825 | canvas->clear(0x8055aaff); |
| 826 | uint32_t pixels[1] = { 0 }; |
| 827 | SkPixmap pixmap(SkImageInfo::MakeN32Premul(1, 1), pixels, 4); |
| 828 | canvas->readPixels(pixmap, 0, 0); |
| 829 | SkDebugf("pixel = %08x\n", pixels[0]); |
| 830 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 831 | #StdOut |
| 832 | pixel = 802b5580 |
| 833 | ## |
| 834 | ## |
| 835 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 836 | #SeeAlso peekPixels writePixels drawBitmap drawImage SkBitmap::readPixels SkPixmap::readPixels SkImage::readPixels SkSurface::readPixels |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 837 | |
| 838 | ## |
| 839 | |
| 840 | # ------------------------------------------------------------------------------ |
| 841 | |
| 842 | #Method bool readPixels(const SkBitmap& bitmap, int srcX, int srcY) |
| 843 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 844 | Copies Rect of pixels from Canvas into bitmap. Matrix and Clip are |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 845 | ignored. |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 846 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 847 | Source Rect corners are (srcX, srcY) and (imageInfo().width(), imageInfo().height()). |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 848 | Destination Rect corners are (0, 0) and (bitmap.width(), bitmap.height()). |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 849 | Copies each readable pixel intersecting both rectangles, without scaling, |
| 850 | converting to bitmap.colorType() and bitmap.alphaType() if required. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 851 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 852 | Pixels are readable when Device is raster, or backed by a GPU. |
| 853 | Pixels are not readable when SkCanvas is returned by SkDocument::beginPage, |
| 854 | returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility |
Brian Osman | 46fe9c7 | 2018-03-09 15:44:34 -0500 | [diff] [blame] | 855 | class like SkDebugCanvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 856 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 857 | Caller must allocate pixel storage in bitmap if needed. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 858 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 859 | Bitmap values are converted only if Color_Type and Alpha_Type |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 860 | do not match. Only pixels within both source and destination rectangles |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 861 | are copied. Bitmap pixels outside Rect intersection are unchanged. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 862 | |
| 863 | Pass negative values for srcX or srcY to offset pixels across or down bitmap. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 864 | |
| 865 | Does not copy, and returns false if: |
| 866 | |
| 867 | #List |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 868 | # Source and destination rectangles do not intersect. ## |
| 869 | # Canvas pixels could not be converted to bitmap.colorType() or bitmap.alphaType(). ## |
| 870 | # Canvas pixels are not readable; for instance, Canvas is document-based. ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 871 | # bitmap pixels could not be allocated. ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 872 | # bitmap.rowBytes() is too small to contain one row of pixels. ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 873 | ## |
| 874 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 875 | #Param bitmap storage for pixels copied from Canvas ## |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 876 | #Param srcX offset into readable pixels on x-axis; may be negative ## |
| 877 | #Param srcY offset into readable pixels on y-axis; may be negative ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 878 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 879 | #Return true if pixels were copied ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 880 | |
| 881 | #Example |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 882 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 883 | clear() takes Unpremultiplied input with Color_Alpha equal 0x80 |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 884 | and RGB equal 0x55, 0xAA, 0xFF. RGB is multiplied by Color_Alpha |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 885 | to generate Premultiplied value 0x802B5580. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 886 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 887 | void draw(SkCanvas* canvas) { |
| 888 | canvas->clear(0x8055aaff); |
| 889 | SkBitmap bitmap; |
| 890 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(1, 1)); |
| 891 | canvas->readPixels(bitmap, 0, 0); |
| 892 | SkDebugf("pixel = %08x\n", bitmap.getAddr32(0, 0)[0]); |
| 893 | } |
| 894 | #StdOut |
| 895 | pixel = 802b5580 |
| 896 | ## |
| 897 | ## |
| 898 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 899 | #SeeAlso peekPixels writePixels drawBitmap drawImage SkBitmap::readPixels SkPixmap::readPixels SkImage::readPixels SkSurface::readPixels |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 900 | |
| 901 | ## |
| 902 | |
| 903 | # ------------------------------------------------------------------------------ |
| 904 | |
| 905 | #Method bool writePixels(const SkImageInfo& info, const void* pixels, size_t rowBytes, int x, int y) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 906 | #In Pixels |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 907 | #Line # copies and converts rectangle of pixels to Canvas ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 908 | Copies Rect from pixels to Canvas. Matrix and Clip are ignored. |
| 909 | Source Rect corners are (0, 0) and (info.width(), info.height()). |
| 910 | Destination Rect corners are (x, y) and |
| 911 | (imageInfo().width(), imageInfo().height()). |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 912 | |
| 913 | Copies each readable pixel intersecting both rectangles, without scaling, |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 914 | converting to imageInfo().colorType() and imageInfo().alphaType() if required. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 915 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 916 | Pixels are writable when Device is raster, or backed by a GPU. |
| 917 | Pixels are not writable when SkCanvas is returned by SkDocument::beginPage, |
| 918 | returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility |
Brian Osman | 46fe9c7 | 2018-03-09 15:44:34 -0500 | [diff] [blame] | 919 | class like SkDebugCanvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 920 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 921 | Pixel values are converted only if Color_Type and Alpha_Type |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 922 | do not match. Only pixels within both source and destination rectangles |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 923 | are copied. Canvas pixels outside Rect intersection are unchanged. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 924 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 925 | Pass negative values for x or y to offset pixels to the left or |
| 926 | above Canvas pixels. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 927 | |
| 928 | Does not copy, and returns false if: |
| 929 | |
| 930 | #List |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 931 | # Source and destination rectangles do not intersect. ## |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 932 | # pixels could not be converted to Canvas imageInfo().colorType() or |
| 933 | imageInfo().alphaType(). ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 934 | # Canvas pixels are not writable; for instance, Canvas is document-based. ## |
| 935 | # rowBytes is too small to contain one row of pixels. ## |
| 936 | ## |
| 937 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 938 | #Param info width, height, Color_Type, and Alpha_Type of pixels ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 939 | #Param pixels pixels to copy, of size info.height() times rowBytes, or larger ## |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 940 | #Param rowBytes size of one row of pixels; info.width() times pixel size, or larger ## |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 941 | #Param x offset into Canvas writable pixels on x-axis; may be negative ## |
| 942 | #Param y offset into Canvas writable pixels on y-axis; may be negative ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 943 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 944 | #Return true if pixels were written to Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 945 | |
| 946 | #Example |
| 947 | SkImageInfo imageInfo = SkImageInfo::MakeN32(256, 1, kPremul_SkAlphaType); |
| 948 | for (int y = 0; y < 256; ++y) { |
| 949 | uint32_t pixels[256]; |
| 950 | for (int x = 0; x < 256; ++x) { |
| 951 | pixels[x] = SkColorSetARGB(x, x + y, x, x - y); |
| 952 | } |
| 953 | canvas->writePixels(imageInfo, &pixels, sizeof(pixels), 0, y); |
| 954 | } |
| 955 | ## |
| 956 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 957 | #SeeAlso readPixels drawBitmap drawImage SkBitmap::writePixels |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 958 | |
| 959 | ## |
| 960 | |
| 961 | # ------------------------------------------------------------------------------ |
| 962 | |
| 963 | #Method bool writePixels(const SkBitmap& bitmap, int x, int y) |
| 964 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 965 | Copies Rect from pixels to Canvas. Matrix and Clip are ignored. |
| 966 | Source Rect corners are (0, 0) and (bitmap.width(), bitmap.height()). |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 967 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 968 | Destination Rect corners are (x, y) and |
| 969 | (imageInfo().width(), imageInfo().height()). |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 970 | |
| 971 | Copies each readable pixel intersecting both rectangles, without scaling, |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 972 | converting to imageInfo().colorType() and imageInfo().alphaType() if required. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 973 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 974 | Pixels are writable when Device is raster, or backed by a GPU. |
| 975 | Pixels are not writable when SkCanvas is returned by SkDocument::beginPage, |
| 976 | returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility |
Brian Osman | 46fe9c7 | 2018-03-09 15:44:34 -0500 | [diff] [blame] | 977 | class like SkDebugCanvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 978 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 979 | Pixel values are converted only if Color_Type and Alpha_Type |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 980 | do not match. Only pixels within both source and destination rectangles |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 981 | are copied. Canvas pixels outside Rect intersection are unchanged. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 982 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 983 | Pass negative values for x or y to offset pixels to the left or |
| 984 | above Canvas pixels. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 985 | |
| 986 | Does not copy, and returns false if: |
| 987 | |
| 988 | #List |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 989 | # Source and destination rectangles do not intersect. ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 990 | # bitmap does not have allocated pixels. ## |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 991 | # bitmap pixels could not be converted to Canvas imageInfo().colorType() or |
| 992 | imageInfo().alphaType(). ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 993 | # Canvas pixels are not writable; for instance, Canvas is document based. ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 994 | # bitmap pixels are inaccessible; for instance, bitmap wraps a texture. ## |
| 995 | ## |
| 996 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 997 | #Param bitmap contains pixels copied to Canvas ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 998 | #Param x offset into Canvas writable pixels in x; may be negative ## |
| 999 | #Param y offset into Canvas writable pixels in y; may be negative ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1000 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1001 | #Return true if pixels were written to Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1002 | |
| 1003 | #Example |
| 1004 | void draw(SkCanvas* canvas) { |
| 1005 | SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(2, 2); |
| 1006 | SkBitmap bitmap; |
| 1007 | bitmap.setInfo(imageInfo); |
| 1008 | uint32_t pixels[4]; |
| 1009 | bitmap.setPixels(pixels); |
| 1010 | for (int y = 0; y < 256; y += 2) { |
| 1011 | for (int x = 0; x < 256; x += 2) { |
| 1012 | pixels[0] = SkColorSetRGB(x, y, x | y); |
| 1013 | pixels[1] = SkColorSetRGB(x ^ y, y, x); |
| 1014 | pixels[2] = SkColorSetRGB(x, x & y, y); |
| 1015 | pixels[3] = SkColorSetRGB(~x, ~y, x); |
| 1016 | canvas->writePixels(bitmap, x, y); |
| 1017 | } |
| 1018 | } |
| 1019 | } |
| 1020 | ## |
| 1021 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1022 | #SeeAlso readPixels drawBitmap drawImage SkBitmap::writePixels |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1023 | |
| 1024 | ## |
| 1025 | |
| 1026 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1027 | #Subtopic State_Stack |
| 1028 | #Line # stack of state for hierarchical drawing ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1029 | |
| 1030 | Canvas maintains a stack of state that allows hierarchical drawing, commonly used |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1031 | to implement windows and views. The initial state has an identity matrix and and |
| 1032 | an infinite clip. Even with a wide-open clip, drawing is constrained by the |
| 1033 | bounds of the Canvas Surface or Device. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1034 | |
Cary Clark | 939fd6c | 2018-07-12 08:40:13 -0400 | [diff] [blame] | 1035 | Canvas savable state consists of Clip and Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1036 | Clip describes the area that may be drawn to. |
| 1037 | Matrix transforms the geometry. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1038 | |
| 1039 | save(), saveLayer, saveLayerPreserveLCDTextRequests, and saveLayerAlpha |
| 1040 | save state and return the depth of the stack. |
| 1041 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1042 | restore(), restoreToCount, and ~SkCanvas() revert state to its value when saved. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1043 | |
| 1044 | Each state on the stack intersects Clip with the previous Clip, |
| 1045 | and concatenates Matrix with the previous Matrix. |
| 1046 | The intersected Clip makes the drawing area the same or smaller; |
| 1047 | the concatenated Matrix may move the origin and potentially scale or rotate |
| 1048 | the coordinate space. |
| 1049 | |
| 1050 | Canvas does not require balancing the state stack but it is a good idea |
| 1051 | to do so. Calling save() without restore() will eventually cause Skia to fail; |
| 1052 | mismatched save() and restore() create hard to find bugs. |
| 1053 | |
| 1054 | It is not possible to use state to draw outside of the clip defined by the |
| 1055 | previous state. |
| 1056 | |
| 1057 | #Example |
| 1058 | #Description |
| 1059 | Draw to ever smaller clips; then restore drawing to full canvas. |
| 1060 | Note that the second clipRect is not permitted to enlarge Clip. |
| 1061 | ## |
| 1062 | #Height 160 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1063 | void draw(SkCanvas* canvas) { |
| 1064 | SkPaint paint; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1065 | canvas->save(); // records stack depth to restore |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1066 | canvas->clipRect(SkRect::MakeWH(100, 100)); // constrains drawing to clip |
| 1067 | canvas->clear(SK_ColorRED); // draws to limit of clip |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1068 | canvas->save(); // records stack depth to restore |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1069 | canvas->clipRect(SkRect::MakeWH(50, 150)); // Rect below 100 is ignored |
| 1070 | canvas->clear(SK_ColorBLUE); // draws to smaller clip |
| 1071 | canvas->restore(); // enlarges clip |
| 1072 | canvas->drawLine(20, 20, 150, 150, paint); // line below 100 is not drawn |
| 1073 | canvas->restore(); // enlarges clip |
| 1074 | canvas->drawLine(150, 20, 50, 120, paint); // line below 100 is drawn |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1075 | } |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1076 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1077 | |
| 1078 | Each Clip uses the current Matrix for its coordinates. |
| 1079 | |
| 1080 | #Example |
| 1081 | #Description |
| 1082 | While clipRect is given the same rectangle twice, Matrix makes the second |
| 1083 | clipRect draw at half the size of the first. |
| 1084 | ## |
| 1085 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1086 | void draw(SkCanvas* canvas) { |
| 1087 | canvas->clipRect(SkRect::MakeWH(100, 100)); |
| 1088 | canvas->clear(SK_ColorRED); |
| 1089 | canvas->scale(.5, .5); |
| 1090 | canvas->clipRect(SkRect::MakeWH(100, 100)); |
| 1091 | canvas->clear(SK_ColorBLUE); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1092 | } |
| 1093 | ## |
| 1094 | |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1095 | #SeeAlso save saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha restore() restoreToCount |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1096 | |
| 1097 | #Method int save() |
| 1098 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1099 | #In State_Stack |
| 1100 | #Line # saves Clip and Matrix on stack ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1101 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1102 | |
| 1103 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1104 | #Description |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1105 | The black square is translated 50 pixels down and to the right. |
| 1106 | Restoring Canvas state removes translate() from Canvas stack; |
| 1107 | the red square is not translated, and is drawn at the origin. |
| 1108 | ## |
| 1109 | #Height 100 |
| 1110 | void draw(SkCanvas* canvas) { |
| 1111 | SkPaint paint; |
| 1112 | SkRect rect = { 0, 0, 25, 25 }; |
| 1113 | canvas->drawRect(rect, paint); |
| 1114 | canvas->save(); |
| 1115 | canvas->translate(50, 50); |
| 1116 | canvas->drawRect(rect, paint); |
| 1117 | canvas->restore(); |
| 1118 | paint.setColor(SK_ColorRED); |
| 1119 | canvas->drawRect(rect, paint); |
| 1120 | } |
| 1121 | ## |
| 1122 | |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1123 | #SeeAlso saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha restore restoreToCount |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1124 | |
| 1125 | ## |
| 1126 | |
| 1127 | # ------------------------------------------------------------------------------ |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1128 | |
| 1129 | #Method void restore() |
| 1130 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1131 | #In State_Stack |
| 1132 | #Line # restores changes to Clip and Matrix, pops save stack ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1133 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1134 | |
| 1135 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1136 | void draw(SkCanvas* canvas) { |
| 1137 | SkCanvas simple; |
| 1138 | SkDebugf("depth = %d\n", simple.getSaveCount()); |
| 1139 | simple.restore(); |
| 1140 | SkDebugf("depth = %d\n", simple.getSaveCount()); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1141 | } |
| 1142 | ## |
| 1143 | |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1144 | #SeeAlso save saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha restoreToCount |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1145 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1146 | ## |
| 1147 | |
| 1148 | # ------------------------------------------------------------------------------ |
| 1149 | |
| 1150 | #Method int getSaveCount() const |
| 1151 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1152 | #In State_Stack |
| 1153 | #Line # returns depth of stack containing Clip and Matrix ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1154 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1155 | |
| 1156 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1157 | void draw(SkCanvas* canvas) { |
| 1158 | SkCanvas simple; |
| 1159 | SkDebugf("depth = %d\n", simple.getSaveCount()); |
| 1160 | simple.save(); |
| 1161 | SkDebugf("depth = %d\n", simple.getSaveCount()); |
| 1162 | simple.restore(); |
| 1163 | SkDebugf("depth = %d\n", simple.getSaveCount()); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1164 | } |
| 1165 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1166 | depth = 1 |
| 1167 | depth = 2 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1168 | depth = 1 |
| 1169 | ## |
| 1170 | ## |
| 1171 | |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1172 | #SeeAlso save restore restoreToCount |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1173 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1174 | ## |
| 1175 | |
| 1176 | # ------------------------------------------------------------------------------ |
| 1177 | |
| 1178 | #Method void restoreToCount(int saveCount) |
| 1179 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1180 | #In State_Stack |
| 1181 | #Line # restores changes to Clip and Matrix to given depth ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1182 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1183 | |
| 1184 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1185 | void draw(SkCanvas* canvas) { |
| 1186 | SkDebugf("depth = %d\n", canvas->getSaveCount()); |
| 1187 | canvas->save(); |
| 1188 | canvas->save(); |
| 1189 | SkDebugf("depth = %d\n", canvas->getSaveCount()); |
| 1190 | canvas->restoreToCount(0); |
| 1191 | SkDebugf("depth = %d\n", canvas->getSaveCount()); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1192 | } |
| 1193 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1194 | depth = 1 |
| 1195 | depth = 3 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1196 | depth = 1 |
| 1197 | ## |
| 1198 | ## |
| 1199 | |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1200 | #SeeAlso restore getSaveCount save |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1201 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1202 | ## |
| 1203 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1204 | #Subtopic State_Stack ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1205 | |
| 1206 | # ------------------------------------------------------------------------------ |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1207 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1208 | #Subtopic Layer |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1209 | #Substitute layer |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1210 | #Alias Layers |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 1211 | #Substitute layers |
| 1212 | ## |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1213 | #Line # temporary Bitmap to draw into ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1214 | |
| 1215 | Layer allocates a temporary Bitmap to draw into. When the drawing is |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1216 | complete, the Bitmap is drawn into the Canvas. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1217 | |
| 1218 | Layer is saved in a stack along with other saved state. When state with a Layer |
| 1219 | is restored, the Bitmap is drawn into the previous Layer. |
| 1220 | |
| 1221 | Layer may be initialized with the contents of the previous Layer. When Layer is |
| 1222 | restored, its Bitmap can be modified by Paint passed to Layer to apply |
| 1223 | Color_Alpha, Color_Filter, Image_Filter, and Blend_Mode. |
| 1224 | |
| 1225 | #Method int saveLayer(const SkRect* bounds, const SkPaint* paint) |
| 1226 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1227 | #In Layer |
| 1228 | #Line # saves Clip and Matrix on stack; creates Layer ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1229 | #Populate |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1230 | |
| 1231 | #Example |
| 1232 | #Description |
| 1233 | Rectangles are blurred by Image_Filter when restore() draws Layer to main |
| 1234 | Canvas. |
| 1235 | ## |
| 1236 | #Height 128 |
Cary Clark | 81abc43 | 2018-06-25 16:30:08 -0400 | [diff] [blame] | 1237 | #Function |
| 1238 | ###$ |
| 1239 | #include "SkBlurImageFilter.h" |
| 1240 | $$$# |
| 1241 | ## |
| 1242 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1243 | void draw(SkCanvas* canvas) { |
| 1244 | SkPaint paint, blur; |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1245 | blur.setImageFilter(SkBlurImageFilter::Make(3, 3, nullptr)); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1246 | canvas->saveLayer(nullptr, &blur); |
| 1247 | SkRect rect = { 25, 25, 50, 50}; |
| 1248 | canvas->drawRect(rect, paint); |
| 1249 | canvas->translate(50, 50); |
| 1250 | paint.setColor(SK_ColorRED); |
| 1251 | canvas->drawRect(rect, paint); |
| 1252 | canvas->restore(); |
| 1253 | } |
| 1254 | ## |
| 1255 | |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1256 | #SeeAlso save restore saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha SaveLayerRec |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1257 | |
| 1258 | ## |
| 1259 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1260 | #Method int saveLayer(const SkRect& bounds, const SkPaint* paint) |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1261 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1262 | #In Layer |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1263 | #Populate |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1264 | |
| 1265 | #Example |
| 1266 | #Description |
| 1267 | Rectangles are blurred by Image_Filter when restore() draws Layer to main Canvas. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1268 | The red rectangle is clipped; it does not fully fit on Layer. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1269 | Image_Filter blurs past edge of Layer so red rectangle is blurred on all sides. |
| 1270 | ## |
| 1271 | #Height 128 |
Cary Clark | 81abc43 | 2018-06-25 16:30:08 -0400 | [diff] [blame] | 1272 | #Function |
| 1273 | ###$ |
| 1274 | #include "SkBlurImageFilter.h" |
| 1275 | $$$# |
| 1276 | ## |
| 1277 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1278 | void draw(SkCanvas* canvas) { |
| 1279 | SkPaint paint, blur; |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1280 | blur.setImageFilter(SkBlurImageFilter::Make(3, 3, nullptr)); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1281 | canvas->saveLayer(SkRect::MakeWH(90, 90), &blur); |
| 1282 | SkRect rect = { 25, 25, 50, 50}; |
| 1283 | canvas->drawRect(rect, paint); |
| 1284 | canvas->translate(50, 50); |
| 1285 | paint.setColor(SK_ColorRED); |
| 1286 | canvas->drawRect(rect, paint); |
| 1287 | canvas->restore(); |
| 1288 | } |
| 1289 | ## |
| 1290 | |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1291 | #SeeAlso save restore saveLayerPreserveLCDTextRequests saveLayerAlpha SaveLayerRec |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1292 | |
| 1293 | ## |
| 1294 | |
| 1295 | #Method int saveLayerPreserveLCDTextRequests(const SkRect* bounds, const SkPaint* paint) |
| 1296 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1297 | #In Layer |
| 1298 | #Line # saves Clip and Matrix on stack; creates Layer for LCD text ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1299 | #Populate |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1300 | |
| 1301 | #Example |
| 1302 | SkPaint paint; |
| 1303 | paint.setAntiAlias(true); |
| 1304 | paint.setLCDRenderText(true); |
| 1305 | paint.setTextSize(20); |
| 1306 | for (auto preserve : { false, true } ) { |
| 1307 | preserve ? canvas->saveLayerPreserveLCDTextRequests(nullptr, nullptr) |
| 1308 | : canvas->saveLayer(nullptr, nullptr); |
| 1309 | SkPaint p; |
| 1310 | p.setColor(SK_ColorWHITE); |
| 1311 | // Comment out the next line to draw on a non-opaque background. |
| 1312 | canvas->drawRect(SkRect::MakeLTRB(25, 40, 200, 70), p); |
| 1313 | canvas->drawString("Hamburgefons", 30, 60, paint); |
| 1314 | |
| 1315 | p.setColor(0xFFCCCCCC); |
| 1316 | canvas->drawRect(SkRect::MakeLTRB(25, 70, 200, 100), p); |
| 1317 | canvas->drawString("Hamburgefons", 30, 90, paint); |
| 1318 | |
| 1319 | canvas->restore(); |
| 1320 | canvas->translate(0, 80); |
| 1321 | } |
| 1322 | ## |
| 1323 | |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1324 | #SeeAlso save restore saveLayer saveLayerAlpha SaveLayerRec |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1325 | |
| 1326 | ## |
| 1327 | |
| 1328 | #Method int saveLayerAlpha(const SkRect* bounds, U8CPU alpha) |
| 1329 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1330 | #In Layer |
| 1331 | #Line # saves Clip and Matrix on stack; creates Layer; sets opacity ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1332 | #Populate |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1333 | |
| 1334 | #Example |
| 1335 | SkPaint paint; |
| 1336 | paint.setColor(SK_ColorRED); |
| 1337 | canvas->drawCircle(50, 50, 50, paint); |
| 1338 | canvas->saveLayerAlpha(nullptr, 128); |
| 1339 | paint.setColor(SK_ColorBLUE); |
| 1340 | canvas->drawCircle(100, 50, 50, paint); |
| 1341 | paint.setColor(SK_ColorGREEN); |
| 1342 | paint.setAlpha(128); |
| 1343 | canvas->drawCircle(75, 90, 50, paint); |
| 1344 | canvas->restore(); |
| 1345 | ## |
| 1346 | |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1347 | #SeeAlso save restore saveLayer saveLayerPreserveLCDTextRequests SaveLayerRec |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1348 | |
| 1349 | ## |
| 1350 | |
Cary Clark | d98f78c | 2018-04-26 08:32:37 -0400 | [diff] [blame] | 1351 | #Enum SaveLayerFlagsSet |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1352 | #Line # sets SaveLayerRec options ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1353 | #Code |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1354 | #Populate |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1355 | ## |
| 1356 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1357 | |
| 1358 | #Typedef uint32_t SaveLayerFlags |
| 1359 | #Line # options for SaveLayerRec ## |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 1360 | ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1361 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1362 | SaveLayerFlags provides options that may be used in any combination in SaveLayerRec, |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1363 | defining how Layer allocated by saveLayer operates. It may be set to zero, |
| 1364 | kPreserveLCDText_SaveLayerFlag, kInitWithPrevious_SaveLayerFlag, or both flags. |
| 1365 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1366 | #Const kPreserveLCDText_SaveLayerFlag 2 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1367 | #Line # creates Layer for LCD text ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1368 | Creates Layer for LCD text. Flag is ignored if Layer Paint contains |
| 1369 | Image_Filter or Color_Filter. |
| 1370 | ## |
| 1371 | |
| 1372 | #Const kInitWithPrevious_SaveLayerFlag 4 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1373 | #Line # initializes with previous contents ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1374 | Initializes Layer with the contents of the previous Layer. |
| 1375 | ## |
| 1376 | |
Mike Reed | 910ca0f | 2018-04-25 13:04:05 -0400 | [diff] [blame] | 1377 | #Const kMaskAgainstCoverage_EXPERIMENTAL_DONT_USE_SaveLayerFlag 8 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1378 | #Experimental do not use |
Mike Reed | 910ca0f | 2018-04-25 13:04:05 -0400 | [diff] [blame] | 1379 | ## |
| 1380 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1381 | #Const kDontClipToLayer_Legacy_SaveLayerFlag 0x80000000 |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1382 | #Deprecated soon |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1383 | ## |
| 1384 | |
| 1385 | #Example |
| 1386 | #Height 160 |
| 1387 | #Description |
| 1388 | Canvas Layer captures red and blue circles scaled up by four. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1389 | scalePaint blends Layer back with transparency. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1390 | ## |
| 1391 | void draw(SkCanvas* canvas) { |
| 1392 | SkPaint redPaint, bluePaint, scalePaint; |
| 1393 | redPaint.setColor(SK_ColorRED); |
| 1394 | canvas->drawCircle(21, 21, 8, redPaint); |
| 1395 | bluePaint.setColor(SK_ColorBLUE); |
| 1396 | canvas->drawCircle(31, 21, 8, bluePaint); |
| 1397 | SkMatrix matrix; |
| 1398 | matrix.setScale(4, 4); |
| 1399 | scalePaint.setAlpha(0x40); |
| 1400 | scalePaint.setImageFilter( |
| 1401 | SkImageFilter::MakeMatrixFilter(matrix, kNone_SkFilterQuality, nullptr)); |
| 1402 | SkCanvas::SaveLayerRec saveLayerRec(nullptr, &scalePaint, |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1403 | SkCanvas::kInitWithPrevious_SaveLayerFlag); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1404 | canvas->saveLayer(saveLayerRec); |
| 1405 | canvas->restore(); |
| 1406 | } |
| 1407 | ## |
| 1408 | |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1409 | #SeeAlso save restore saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha SaveLayerRec |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1410 | |
| 1411 | #Enum ## |
| 1412 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1413 | #Subtopic SaveLayerRec |
| 1414 | #Line # contains the state used to create the Layer ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1415 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1416 | #Struct SaveLayerRec |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1417 | #Line # contains the state used to create the Layer ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1418 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1419 | #Code |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1420 | #Populate |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1421 | ## |
| 1422 | |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 1423 | SaveLayerRec contains the state used to create the Layer. |
| 1424 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1425 | #Member const SkRect* fBounds |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1426 | #Line # hints at Layer size limit ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1427 | fBounds is used as a hint to limit the size of Layer; may be nullptr. |
| 1428 | fBounds suggests but does not define Layer size. To clip drawing to |
| 1429 | a specific rectangle, use clipRect. |
| 1430 | ## |
| 1431 | |
| 1432 | #Member const SkPaint* fPaint |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1433 | #Line # modifies overlay ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1434 | fPaint modifies how Layer overlays the prior Layer; may be nullptr. |
| 1435 | Color_Alpha, Blend_Mode, Color_Filter, Draw_Looper, Image_Filter, and |
| 1436 | Mask_Filter affect Layer draw. |
| 1437 | ## |
| 1438 | |
| 1439 | #Member const SkImageFilter* fBackdrop |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1440 | #Line # applies Image_Filter to prior Layer ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1441 | fBackdrop applies Image_Filter to the prior Layer when copying to the Layer; |
| 1442 | may be nullptr. Use kInitWithPrevious_SaveLayerFlag to copy the |
| 1443 | prior Layer without an Image_Filter. |
| 1444 | ## |
| 1445 | |
| 1446 | #Member const SkImage* fClipMask |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1447 | #Line # clips Layer with Mask_Alpha ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1448 | restore() clips Layer by the Color_Alpha channel of fClipMask when |
| 1449 | Layer is copied to Device. fClipMask may be nullptr. . |
| 1450 | ## |
| 1451 | |
| 1452 | #Member const SkMatrix* fClipMatrix |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1453 | #Line # transforms Mask_Alpha used to clip ## |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1454 | fClipMatrix transforms fClipMask before it clips Layer. If |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1455 | fClipMask describes a translucent gradient, it may be scaled and rotated |
| 1456 | without introducing artifacts. fClipMatrix may be nullptr. |
| 1457 | ## |
| 1458 | |
| 1459 | #Member SaveLayerFlags fSaveLayerFlags |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1460 | #Line # preserves LCD Text, creates with prior Layer contents ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1461 | fSaveLayerFlags are used to create Layer without transparency, |
| 1462 | create Layer for LCD text, and to create Layer with the |
| 1463 | contents of the previous Layer. |
| 1464 | ## |
| 1465 | |
| 1466 | #Example |
| 1467 | #Height 160 |
| 1468 | #Description |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1469 | Canvas Layer captures a red Anti_Aliased circle and a blue Aliased circle scaled |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1470 | up by four. After drawing another red circle without scaling on top, the Layer is |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1471 | transferred to the main canvas. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1472 | ## |
| 1473 | void draw(SkCanvas* canvas) { |
| 1474 | SkPaint redPaint, bluePaint; |
| 1475 | redPaint.setAntiAlias(true); |
| 1476 | redPaint.setColor(SK_ColorRED); |
| 1477 | canvas->drawCircle(21, 21, 8, redPaint); |
| 1478 | bluePaint.setColor(SK_ColorBLUE); |
| 1479 | canvas->drawCircle(31, 21, 8, bluePaint); |
| 1480 | SkMatrix matrix; |
| 1481 | matrix.setScale(4, 4); |
| 1482 | auto scaler = SkImageFilter::MakeMatrixFilter(matrix, kNone_SkFilterQuality, nullptr); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1483 | SkCanvas::SaveLayerRec saveLayerRec(nullptr, nullptr, scaler.get(), 0); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1484 | canvas->saveLayer(saveLayerRec); |
| 1485 | canvas->drawCircle(125, 85, 8, redPaint); |
| 1486 | canvas->restore(); |
| 1487 | } |
| 1488 | ## |
| 1489 | |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1490 | #Subtopic Constructors |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1491 | ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1492 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1493 | #Method SaveLayerRec() |
| 1494 | #Line # constructs SaveLayerRec ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1495 | #Populate |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1496 | |
| 1497 | #Example |
| 1498 | SkCanvas::SaveLayerRec rec1; |
Mike Klein | e083f7c | 2018-02-07 12:54:27 -0500 | [diff] [blame] | 1499 | rec1.fSaveLayerFlags = SkCanvas::kPreserveLCDText_SaveLayerFlag; |
| 1500 | SkCanvas::SaveLayerRec rec2(nullptr, nullptr, SkCanvas::kPreserveLCDText_SaveLayerFlag); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1501 | SkDebugf("rec1 %c= rec2\n", rec1.fBounds == rec2.fBounds |
| 1502 | && rec1.fPaint == rec2.fPaint |
| 1503 | && rec1.fBackdrop == rec2.fBackdrop |
| 1504 | && rec1.fSaveLayerFlags == rec2.fSaveLayerFlags ? '=' : '!'); |
| 1505 | #StdOut |
| 1506 | rec1 == rec2 |
| 1507 | ## |
| 1508 | ## |
| 1509 | |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1510 | #SeeAlso save restore saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1511 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1512 | ## |
| 1513 | |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 1514 | #Method SaveLayerRec(const SkRect* bounds, const SkPaint* paint, SaveLayerFlags saveLayerFlags = 0) |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1515 | #Populate |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1516 | |
| 1517 | #Example |
| 1518 | SkCanvas::SaveLayerRec rec1; |
| 1519 | SkCanvas::SaveLayerRec rec2(nullptr, nullptr); |
| 1520 | SkDebugf("rec1 %c= rec2\n", rec1.fBounds == rec2.fBounds |
| 1521 | && rec1.fPaint == rec2.fPaint |
| 1522 | && rec1.fBackdrop == rec2.fBackdrop |
| 1523 | && rec1.fSaveLayerFlags == rec2.fSaveLayerFlags ? '=' : '!'); |
| 1524 | #StdOut |
| 1525 | rec1 == rec2 |
| 1526 | ## |
| 1527 | ## |
| 1528 | |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1529 | #SeeAlso save restore saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1530 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1531 | ## |
| 1532 | |
| 1533 | #Method SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop, |
| 1534 | SaveLayerFlags saveLayerFlags) |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1535 | #Populate |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1536 | |
| 1537 | #Example |
| 1538 | SkCanvas::SaveLayerRec rec1; |
| 1539 | SkCanvas::SaveLayerRec rec2(nullptr, nullptr, nullptr, 0); |
| 1540 | SkDebugf("rec1 %c= rec2\n", rec1.fBounds == rec2.fBounds |
| 1541 | && rec1.fPaint == rec2.fPaint |
| 1542 | && rec1.fBackdrop == rec2.fBackdrop |
| 1543 | && rec1.fSaveLayerFlags == rec2.fSaveLayerFlags ? '=' : '!'); |
| 1544 | #StdOut |
| 1545 | rec1 == rec2 |
| 1546 | ## |
| 1547 | ## |
| 1548 | |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1549 | #SeeAlso save restore saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1550 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1551 | ## |
| 1552 | |
| 1553 | #Method SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop, |
| 1554 | const SkImage* clipMask, const SkMatrix* clipMatrix, |
| 1555 | SaveLayerFlags saveLayerFlags) |
| 1556 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1557 | #Experimental not ready |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1558 | |
| 1559 | Sets fBounds, fPaint, fBackdrop, fClipMask, fClipMatrix, and fSaveLayerFlags. |
| 1560 | clipMatrix uses Color_Alpha channel of image, transformed by clipMatrix, to clip |
| 1561 | Layer when drawn to Canvas. |
| 1562 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1563 | Implementation is not complete; has no effect if Device is GPU-backed. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1564 | |
| 1565 | #Param bounds Layer dimensions; may be nullptr ## |
| 1566 | #Param paint graphics state applied to Layer when overlaying prior |
| 1567 | Layer; may be nullptr |
| 1568 | ## |
| 1569 | #Param backdrop prior Layer copied with Image_Filter; |
| 1570 | may be nullptr |
| 1571 | ## |
| 1572 | #Param clipMask clip applied to Layer; may be nullptr ## |
| 1573 | #Param clipMatrix matrix applied to clipMask; may be nullptr to use |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1574 | identity matrix |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1575 | ## |
| 1576 | #Param saveLayerFlags SaveLayerRec options to modify Layer ## |
| 1577 | |
| 1578 | #Return SaveLayerRec fully specified ## |
| 1579 | |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1580 | #SeeAlso save restore saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1581 | |
| 1582 | ## |
| 1583 | |
| 1584 | #Struct ## |
| 1585 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1586 | #Subtopic ## |
| 1587 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1588 | #Method int saveLayer(const SaveLayerRec& layerRec) |
| 1589 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1590 | #In Layer |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1591 | #Populate |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1592 | |
| 1593 | #Example |
| 1594 | #Description |
| 1595 | The example draws an image, and saves it into a Layer with kInitWithPrevious_SaveLayerFlag. |
| 1596 | Next it punches a hole in Layer and restore with SkBlendMode::kPlus. |
| 1597 | Where Layer was cleared, the original image will draw unchanged. |
| 1598 | Outside of the circle the mandrill is brightened. |
| 1599 | ## |
| 1600 | #Image 3 |
Hal Canary | c465d13 | 2017-12-08 10:21:31 -0500 | [diff] [blame] | 1601 | // sk_sp<SkImage> image = GetResourceAsImage("images/mandrill_256.png"); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1602 | canvas->drawImage(image, 0, 0, nullptr); |
| 1603 | SkCanvas::SaveLayerRec rec; |
| 1604 | SkPaint paint; |
| 1605 | paint.setBlendMode(SkBlendMode::kPlus); |
| 1606 | rec.fSaveLayerFlags = SkCanvas::kInitWithPrevious_SaveLayerFlag; |
| 1607 | rec.fPaint = &paint; |
| 1608 | canvas->saveLayer(rec); |
| 1609 | paint.setBlendMode(SkBlendMode::kClear); |
| 1610 | canvas->drawCircle(128, 128, 96, paint); |
| 1611 | canvas->restore(); |
| 1612 | ## |
| 1613 | |
| 1614 | #ToDo above example needs to replace GetResourceAsImage with way to select image in fiddle ## |
| 1615 | |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1616 | #SeeAlso save restore saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1617 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1618 | ## |
| 1619 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1620 | #Subtopic Layer ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1621 | |
| 1622 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1623 | #Subtopic Matrix |
| 1624 | #Line # coordinate transformation ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1625 | |
| 1626 | #Method void translate(SkScalar dx, SkScalar dy) |
| 1627 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1628 | #In Matrix |
| 1629 | #Line # translates Matrix ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1630 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1631 | |
| 1632 | #Example |
| 1633 | #Height 128 |
| 1634 | #Description |
| 1635 | scale() followed by translate() produces different results from translate() followed |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1636 | by scale(). |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1637 | |
| 1638 | The blue stroke follows translate of (50, 50); a black |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1639 | fill follows scale of (2, 1/2.f). After restoring the clip, which resets |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1640 | Matrix, a red frame follows the same scale of (2, 1/2.f); a gray fill |
| 1641 | follows translate of (50, 50). |
| 1642 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1643 | void draw(SkCanvas* canvas) { |
| 1644 | SkPaint filledPaint; |
| 1645 | SkPaint outlinePaint; |
| 1646 | outlinePaint.setStyle(SkPaint::kStroke_Style); |
| 1647 | outlinePaint.setColor(SK_ColorBLUE); |
| 1648 | canvas->save(); |
| 1649 | canvas->translate(50, 50); |
| 1650 | canvas->drawCircle(28, 28, 15, outlinePaint); // blue center: (50+28, 50+28) |
| 1651 | canvas->scale(2, 1/2.f); |
| 1652 | canvas->drawCircle(28, 28, 15, filledPaint); // black center: (50+(28*2), 50+(28/2)) |
| 1653 | canvas->restore(); |
| 1654 | filledPaint.setColor(SK_ColorGRAY); |
| 1655 | outlinePaint.setColor(SK_ColorRED); |
| 1656 | canvas->scale(2, 1/2.f); |
| 1657 | canvas->drawCircle(28, 28, 15, outlinePaint); // red center: (28*2, 28/2) |
| 1658 | canvas->translate(50, 50); |
| 1659 | canvas->drawCircle(28, 28, 15, filledPaint); // gray center: ((50+28)*2, (50+28)/2) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1660 | } |
| 1661 | ## |
| 1662 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1663 | #SeeAlso concat() scale() skew() rotate() setMatrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1664 | |
| 1665 | ## |
| 1666 | |
| 1667 | # ------------------------------------------------------------------------------ |
| 1668 | |
| 1669 | #Method void scale(SkScalar sx, SkScalar sy) |
| 1670 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1671 | #In Matrix |
| 1672 | #Line # scales Matrix ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1673 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1674 | |
| 1675 | #Example |
| 1676 | #Height 160 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1677 | void draw(SkCanvas* canvas) { |
| 1678 | SkPaint paint; |
| 1679 | SkRect rect = { 10, 20, 60, 120 }; |
| 1680 | canvas->translate(20, 20); |
| 1681 | canvas->drawRect(rect, paint); |
| 1682 | canvas->scale(2, .5f); |
| 1683 | paint.setColor(SK_ColorGRAY); |
| 1684 | canvas->drawRect(rect, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1685 | } |
| 1686 | ## |
| 1687 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1688 | #SeeAlso concat() translate() skew() rotate() setMatrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1689 | |
| 1690 | ## |
| 1691 | |
| 1692 | # ------------------------------------------------------------------------------ |
| 1693 | |
| 1694 | #Method void rotate(SkScalar degrees) |
| 1695 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1696 | #In Matrix |
| 1697 | #Line # rotates Matrix ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1698 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1699 | |
| 1700 | #Example |
| 1701 | #Description |
| 1702 | Draw clock hands at time 5:10. The hour hand and minute hand point up and |
| 1703 | are rotated clockwise. |
| 1704 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1705 | void draw(SkCanvas* canvas) { |
| 1706 | SkPaint paint; |
| 1707 | paint.setStyle(SkPaint::kStroke_Style); |
| 1708 | canvas->translate(128, 128); |
| 1709 | canvas->drawCircle(0, 0, 60, paint); |
| 1710 | canvas->save(); |
| 1711 | canvas->rotate(10 * 360 / 60); // 10 minutes of 60 scaled to 360 degrees |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1712 | canvas->drawLine(0, 0, 0, -50, paint); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1713 | canvas->restore(); |
| 1714 | canvas->rotate((5 + 10.f/60) * 360 / 12); // 5 and 10/60 hours of 12 scaled to 360 degrees |
| 1715 | canvas->drawLine(0, 0, 0, -30, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1716 | } |
| 1717 | ## |
| 1718 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1719 | #SeeAlso concat() translate() skew() scale() setMatrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1720 | |
| 1721 | ## |
| 1722 | |
| 1723 | # ------------------------------------------------------------------------------ |
| 1724 | |
| 1725 | #Method void rotate(SkScalar degrees, SkScalar px, SkScalar py) |
| 1726 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1727 | #In Matrix |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1728 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1729 | |
| 1730 | #Example |
| 1731 | #Height 192 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1732 | void draw(SkCanvas* canvas) { |
| 1733 | SkPaint paint; |
| 1734 | paint.setTextSize(96); |
| 1735 | canvas->drawString("A1", 130, 100, paint); |
| 1736 | canvas->rotate(180, 130, 100); |
| 1737 | canvas->drawString("A1", 130, 100, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1738 | } |
| 1739 | ## |
| 1740 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1741 | #SeeAlso concat() translate() skew() scale() setMatrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1742 | |
| 1743 | ## |
| 1744 | |
| 1745 | # ------------------------------------------------------------------------------ |
| 1746 | |
| 1747 | #Method void skew(SkScalar sx, SkScalar sy) |
| 1748 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1749 | #In Matrix |
| 1750 | #Line # skews Matrix ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1751 | #Populate |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1752 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1753 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1754 | #Description |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 1755 | Black text mimics an oblique text style by using a negative skew on x-axis |
| 1756 | that shifts the geometry to the right as the y-axis values decrease. |
| 1757 | Red text uses a positive skew on y-axis to shift the geometry down |
| 1758 | as the x-axis values increase. |
| 1759 | Blue text combines sx and sy skew to rotate and scale. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1760 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1761 | SkPaint paint; |
| 1762 | paint.setTextSize(128); |
| 1763 | canvas->translate(30, 130); |
| 1764 | canvas->save(); |
| 1765 | canvas->skew(-.5, 0); |
| 1766 | canvas->drawString("A1", 0, 0, paint); |
| 1767 | canvas->restore(); |
| 1768 | canvas->save(); |
| 1769 | canvas->skew(0, .5); |
| 1770 | paint.setColor(SK_ColorRED); |
| 1771 | canvas->drawString("A1", 0, 0, paint); |
| 1772 | canvas->restore(); |
| 1773 | canvas->skew(-.5, .5); |
| 1774 | paint.setColor(SK_ColorBLUE); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1775 | canvas->drawString("A1", 0, 0, paint); |
| 1776 | ## |
| 1777 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1778 | #SeeAlso concat() translate() rotate() scale() setMatrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1779 | |
| 1780 | ## |
| 1781 | |
| 1782 | # ------------------------------------------------------------------------------ |
| 1783 | |
| 1784 | #Method void concat(const SkMatrix& matrix) |
| 1785 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1786 | #In Matrix |
| 1787 | #Line # multiplies Matrix by Matrix ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1788 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1789 | |
| 1790 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1791 | void draw(SkCanvas* canvas) { |
| 1792 | SkPaint paint; |
| 1793 | paint.setTextSize(80); |
| 1794 | paint.setTextScaleX(.3); |
| 1795 | SkMatrix matrix; |
| 1796 | SkRect rect[2] = {{ 10, 20, 90, 110 }, { 40, 130, 140, 180 }}; |
| 1797 | matrix.setRectToRect(rect[0], rect[1], SkMatrix::kFill_ScaleToFit); |
| 1798 | canvas->drawRect(rect[0], paint); |
| 1799 | canvas->drawRect(rect[1], paint); |
| 1800 | paint.setColor(SK_ColorWHITE); |
| 1801 | canvas->drawString("Here", rect[0].fLeft + 10, rect[0].fBottom - 10, paint); |
| 1802 | canvas->concat(matrix); |
| 1803 | canvas->drawString("There", rect[0].fLeft + 10, rect[0].fBottom - 10, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1804 | } |
| 1805 | ## |
| 1806 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1807 | #SeeAlso translate() rotate() scale() skew() setMatrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1808 | |
| 1809 | ## |
| 1810 | |
| 1811 | # ------------------------------------------------------------------------------ |
| 1812 | |
| 1813 | #Method void setMatrix(const SkMatrix& matrix) |
| 1814 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1815 | #In Matrix |
| 1816 | #Line # sets Matrix ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1817 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1818 | |
| 1819 | #Example |
| 1820 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1821 | void draw(SkCanvas* canvas) { |
| 1822 | SkPaint paint; |
| 1823 | canvas->scale(4, 6); |
| 1824 | canvas->drawString("truth", 2, 10, paint); |
| 1825 | SkMatrix matrix; |
| 1826 | matrix.setScale(2.8f, 6); |
| 1827 | canvas->setMatrix(matrix); |
| 1828 | canvas->drawString("consequences", 2, 20, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1829 | } |
| 1830 | ## |
| 1831 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1832 | #SeeAlso resetMatrix concat() translate() rotate() scale() skew() |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1833 | |
| 1834 | ## |
| 1835 | |
| 1836 | # ------------------------------------------------------------------------------ |
| 1837 | |
| 1838 | #Method void resetMatrix() |
| 1839 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1840 | #In Matrix |
| 1841 | #Line # resets Matrix to identity ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1842 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1843 | |
| 1844 | #Example |
| 1845 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1846 | void draw(SkCanvas* canvas) { |
| 1847 | SkPaint paint; |
| 1848 | canvas->scale(4, 6); |
| 1849 | canvas->drawString("truth", 2, 10, paint); |
| 1850 | canvas->resetMatrix(); |
| 1851 | canvas->scale(2.8f, 6); |
| 1852 | canvas->drawString("consequences", 2, 20, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1853 | } |
| 1854 | ## |
| 1855 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1856 | #SeeAlso setMatrix concat() translate() rotate() scale() skew() |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1857 | |
| 1858 | ## |
| 1859 | |
| 1860 | # ------------------------------------------------------------------------------ |
| 1861 | |
| 1862 | #Method const SkMatrix& getTotalMatrix() const |
| 1863 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1864 | #In Matrix |
| 1865 | #Line # returns Matrix ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1866 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1867 | |
| 1868 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1869 | SkDebugf("isIdentity %s\n", canvas->getTotalMatrix().isIdentity() ? "true" : "false"); |
| 1870 | #StdOut |
| 1871 | isIdentity true |
| 1872 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1873 | ## |
| 1874 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1875 | #SeeAlso setMatrix resetMatrix concat() |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1876 | |
| 1877 | ## |
| 1878 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1879 | #Subtopic Matrix ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1880 | |
| 1881 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1882 | #Subtopic Clip |
| 1883 | #Line # stack of clipping Paths ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1884 | |
| 1885 | Clip is built from a stack of clipping paths. Each Path in the |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1886 | stack can be constructed from one or more Path_Contour elements. The |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1887 | Path_Contour may be composed of any number of Path_Verb segments. Each |
| 1888 | Path_Contour forms a closed area; Path_Fill_Type defines the area enclosed |
| 1889 | by Path_Contour. |
| 1890 | |
| 1891 | Clip stack of Path elements successfully restrict the Path area. Each |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1892 | Path is transformed by Matrix, then intersected with or subtracted from the |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1893 | prior Clip to form the replacement Clip. Use SkClipOp::kDifference |
| 1894 | to subtract Path from Clip; use SkClipOp::kIntersect to intersect Path |
| 1895 | with Clip. |
| 1896 | |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1897 | A clipping Path may be Anti_Aliased; if Path, after transformation, is |
| 1898 | composed of horizontal and vertical lines, clearing Anti_Alias allows whole pixels |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1899 | to either be inside or outside the clip. The fastest drawing has a Aliased, |
| 1900 | rectangular clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1901 | |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1902 | If clipping Path has Anti_Alias set, clip may partially clip a pixel, requiring |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1903 | that drawing blend partially with the destination along the edge. A rotated |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1904 | rectangular Anti_Aliased clip looks smoother but draws slower. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1905 | |
| 1906 | Clip can combine with Rect and Round_Rect primitives; like |
| 1907 | Path, these are transformed by Matrix before they are combined with Clip. |
| 1908 | |
| 1909 | Clip can combine with Region. Region is assumed to be in Device coordinates |
| 1910 | and is unaffected by Matrix. |
| 1911 | |
| 1912 | #Example |
| 1913 | #Height 90 |
| 1914 | #Description |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1915 | Draw a red circle with an Aliased clip and an Anti_Aliased clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1916 | Use an image filter to zoom into the pixels drawn. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1917 | The edge of the Aliased clip fully draws pixels in the red circle. |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1918 | The edge of the Anti_Aliased clip partially draws pixels in the red circle. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1919 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1920 | SkPaint redPaint, scalePaint; |
| 1921 | redPaint.setAntiAlias(true); |
| 1922 | redPaint.setColor(SK_ColorRED); |
| 1923 | canvas->save(); |
| 1924 | for (bool antialias : { false, true } ) { |
| 1925 | canvas->save(); |
| 1926 | canvas->clipRect(SkRect::MakeWH(19.5f, 11.5f), antialias); |
| 1927 | canvas->drawCircle(17, 11, 8, redPaint); |
| 1928 | canvas->restore(); |
| 1929 | canvas->translate(16, 0); |
| 1930 | } |
| 1931 | canvas->restore(); |
| 1932 | SkMatrix matrix; |
| 1933 | matrix.setScale(6, 6); |
| 1934 | scalePaint.setImageFilter( |
| 1935 | SkImageFilter::MakeMatrixFilter(matrix, kNone_SkFilterQuality, nullptr)); |
| 1936 | SkCanvas::SaveLayerRec saveLayerRec( |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1937 | nullptr, &scalePaint, SkCanvas::kInitWithPrevious_SaveLayerFlag); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1938 | canvas->saveLayer(saveLayerRec); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1939 | canvas->restore(); |
| 1940 | ## |
| 1941 | |
| 1942 | #Method void clipRect(const SkRect& rect, SkClipOp op, bool doAntiAlias) |
| 1943 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1944 | #In Clip |
| 1945 | #Line # combines Clip with Rect ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1946 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1947 | |
| 1948 | #Example |
| 1949 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1950 | void draw(SkCanvas* canvas) { |
| 1951 | canvas->rotate(10); |
| 1952 | SkPaint paint; |
| 1953 | paint.setAntiAlias(true); |
| 1954 | for (auto alias: { false, true } ) { |
| 1955 | canvas->save(); |
| 1956 | canvas->clipRect(SkRect::MakeWH(90, 80), SkClipOp::kIntersect, alias); |
| 1957 | canvas->drawCircle(100, 60, 60, paint); |
| 1958 | canvas->restore(); |
| 1959 | canvas->translate(80, 0); |
| 1960 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1961 | } |
| 1962 | ## |
| 1963 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1964 | #SeeAlso clipRRect clipPath clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1965 | |
| 1966 | ## |
| 1967 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1968 | #Method void clipRect(const SkRect& rect, SkClipOp op) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1969 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1970 | #In Clip |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1971 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1972 | |
| 1973 | #Example |
| 1974 | #Height 192 |
| 1975 | #Width 280 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1976 | void draw(SkCanvas* canvas) { |
| 1977 | SkPaint paint; |
| 1978 | for (SkClipOp op: { SkClipOp::kIntersect, SkClipOp::kDifference } ) { |
| 1979 | canvas->save(); |
| 1980 | canvas->clipRect(SkRect::MakeWH(90, 120), op, false); |
| 1981 | canvas->drawCircle(100, 100, 60, paint); |
| 1982 | canvas->restore(); |
| 1983 | canvas->translate(80, 0); |
| 1984 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1985 | } |
| 1986 | ## |
| 1987 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1988 | #SeeAlso clipRRect clipPath clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1989 | |
| 1990 | ## |
| 1991 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1992 | #Method void clipRect(const SkRect& rect, bool doAntiAlias = false) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1993 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1994 | #In Clip |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1995 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1996 | |
| 1997 | #Example |
| 1998 | #Height 133 |
| 1999 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2000 | A circle drawn in pieces looks uniform when drawn Aliased. |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2001 | The same circle pieces blend with pixels more than once when Anti_Aliased, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2002 | visible as a thin pair of lines through the right circle. |
| 2003 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2004 | void draw(SkCanvas* canvas) { |
| 2005 | canvas->clear(SK_ColorWHITE); |
| 2006 | SkPaint paint; |
| 2007 | paint.setAntiAlias(true); |
| 2008 | paint.setColor(0x8055aaff); |
| 2009 | SkRect clipRect = { 0, 0, 87.4f, 87.4f }; |
| 2010 | for (auto alias: { false, true } ) { |
| 2011 | canvas->save(); |
| 2012 | canvas->clipRect(clipRect, SkClipOp::kIntersect, alias); |
| 2013 | canvas->drawCircle(67, 67, 60, paint); |
| 2014 | canvas->restore(); |
| 2015 | canvas->save(); |
| 2016 | canvas->clipRect(clipRect, SkClipOp::kDifference, alias); |
| 2017 | canvas->drawCircle(67, 67, 60, paint); |
| 2018 | canvas->restore(); |
| 2019 | canvas->translate(120, 0); |
| 2020 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2021 | } |
| 2022 | ## |
| 2023 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2024 | #SeeAlso clipRRect clipPath clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2025 | |
| 2026 | ## |
| 2027 | |
| 2028 | #Method void androidFramework_setDeviceClipRestriction(const SkIRect& rect) |
| 2029 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2030 | #In Clip |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2031 | #Line # exists for use by Android framework ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2032 | Sets the maximum clip rectangle, which can be set by clipRect, clipRRect and |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2033 | clipPath and intersect the current clip with the specified rect. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2034 | The maximum clip affects only future clipping operations; it is not retroactive. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2035 | The clip restriction is not recorded in pictures. |
| 2036 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2037 | Pass an empty rect to disable maximum clip. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2038 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2039 | #Private |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 2040 | This private API is for use by Android framework only. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2041 | ## |
| 2042 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2043 | #Param rect maximum allowed clip in device coordinates |
Cary Clark | 579985c | 2017-07-31 11:48:27 -0400 | [diff] [blame] | 2044 | #Param ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2045 | |
| 2046 | ## |
| 2047 | |
| 2048 | #Method void clipRRect(const SkRRect& rrect, SkClipOp op, bool doAntiAlias) |
| 2049 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2050 | #In Clip |
| 2051 | #Line # combines Clip with Round_Rect ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2052 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2053 | |
| 2054 | #Example |
| 2055 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2056 | void draw(SkCanvas* canvas) { |
| 2057 | canvas->clear(SK_ColorWHITE); |
| 2058 | SkPaint paint; |
| 2059 | paint.setAntiAlias(true); |
| 2060 | paint.setColor(0x8055aaff); |
| 2061 | SkRRect oval; |
| 2062 | oval.setOval({10, 20, 90, 100}); |
| 2063 | canvas->clipRRect(oval, SkClipOp::kIntersect, true); |
| 2064 | canvas->drawCircle(70, 100, 60, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2065 | } |
| 2066 | ## |
| 2067 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2068 | #SeeAlso clipRect clipPath clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2069 | |
| 2070 | ## |
| 2071 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2072 | #Method void clipRRect(const SkRRect& rrect, SkClipOp op) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2073 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2074 | #In Clip |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2075 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2076 | |
| 2077 | #Example |
| 2078 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2079 | void draw(SkCanvas* canvas) { |
| 2080 | SkPaint paint; |
| 2081 | paint.setColor(0x8055aaff); |
| 2082 | auto oval = SkRRect::MakeOval({10, 20, 90, 100}); |
| 2083 | canvas->clipRRect(oval, SkClipOp::kIntersect); |
| 2084 | canvas->drawCircle(70, 100, 60, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2085 | } |
| 2086 | ## |
| 2087 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2088 | #SeeAlso clipRect clipPath clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2089 | |
| 2090 | ## |
| 2091 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2092 | #Method void clipRRect(const SkRRect& rrect, bool doAntiAlias = false) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2093 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2094 | #In Clip |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2095 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2096 | |
| 2097 | #Example |
| 2098 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2099 | void draw(SkCanvas* canvas) { |
| 2100 | SkPaint paint; |
| 2101 | paint.setAntiAlias(true); |
| 2102 | auto oval = SkRRect::MakeRectXY({10, 20, 90, 100}, 9, 13); |
| 2103 | canvas->clipRRect(oval, true); |
| 2104 | canvas->drawCircle(70, 100, 60, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2105 | } |
| 2106 | ## |
| 2107 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2108 | #SeeAlso clipRect clipPath clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2109 | |
| 2110 | ## |
| 2111 | |
| 2112 | #Method void clipPath(const SkPath& path, SkClipOp op, bool doAntiAlias) |
| 2113 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2114 | #In Clip |
| 2115 | #Line # combines Clip with Path ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2116 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2117 | |
| 2118 | #Example |
| 2119 | #Description |
| 2120 | Top figure uses SkPath::kInverseWinding_FillType and SkClipOp::kDifference; |
| 2121 | area outside clip is subtracted from circle. |
| 2122 | |
| 2123 | Bottom figure uses SkPath::kWinding_FillType and SkClipOp::kIntersect; |
| 2124 | area inside clip is intersected with circle. |
| 2125 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2126 | void draw(SkCanvas* canvas) { |
| 2127 | SkPaint paint; |
| 2128 | paint.setAntiAlias(true); |
| 2129 | SkPath path; |
| 2130 | path.addRect({20, 30, 100, 110}); |
| 2131 | path.setFillType(SkPath::kInverseWinding_FillType); |
| 2132 | canvas->save(); |
| 2133 | canvas->clipPath(path, SkClipOp::kDifference, false); |
| 2134 | canvas->drawCircle(70, 100, 60, paint); |
| 2135 | canvas->restore(); |
| 2136 | canvas->translate(100, 100); |
| 2137 | path.setFillType(SkPath::kWinding_FillType); |
| 2138 | canvas->clipPath(path, SkClipOp::kIntersect, false); |
| 2139 | canvas->drawCircle(70, 100, 60, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2140 | } |
| 2141 | ## |
| 2142 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2143 | #SeeAlso clipRect clipRRect clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2144 | |
| 2145 | ## |
| 2146 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2147 | #Method void clipPath(const SkPath& path, SkClipOp op) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2148 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2149 | #In Clip |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2150 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2151 | |
| 2152 | #Example |
| 2153 | #Description |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2154 | Overlapping Rects form a clip. When clip Path_Fill_Type is set to |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2155 | SkPath::kWinding_FillType, the overlap is included. Set to |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2156 | SkPath::kEvenOdd_FillType, the overlap is excluded and forms a hole. |
| 2157 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2158 | void draw(SkCanvas* canvas) { |
| 2159 | SkPaint paint; |
| 2160 | paint.setAntiAlias(true); |
| 2161 | SkPath path; |
| 2162 | path.addRect({20, 15, 100, 95}); |
| 2163 | path.addRect({50, 65, 130, 135}); |
| 2164 | path.setFillType(SkPath::kWinding_FillType); |
| 2165 | canvas->save(); |
| 2166 | canvas->clipPath(path, SkClipOp::kIntersect); |
| 2167 | canvas->drawCircle(70, 85, 60, paint); |
| 2168 | canvas->restore(); |
| 2169 | canvas->translate(100, 100); |
| 2170 | path.setFillType(SkPath::kEvenOdd_FillType); |
| 2171 | canvas->clipPath(path, SkClipOp::kIntersect); |
| 2172 | canvas->drawCircle(70, 85, 60, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2173 | } |
| 2174 | ## |
| 2175 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2176 | #SeeAlso clipRect clipRRect clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2177 | |
| 2178 | ## |
| 2179 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2180 | #Method void clipPath(const SkPath& path, bool doAntiAlias = false) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2181 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2182 | #In Clip |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2183 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2184 | |
| 2185 | #Example |
| 2186 | #Height 212 |
| 2187 | #Description |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2188 | Clip loops over itself covering its center twice. When clip Path_Fill_Type |
| 2189 | is set to SkPath::kWinding_FillType, the overlap is included. Set to |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2190 | SkPath::kEvenOdd_FillType, the overlap is excluded and forms a hole. |
| 2191 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2192 | void draw(SkCanvas* canvas) { |
| 2193 | SkPaint paint; |
| 2194 | paint.setAntiAlias(true); |
| 2195 | SkPath path; |
| 2196 | SkPoint poly[] = {{20, 20}, { 80, 20}, { 80, 80}, {40, 80}, |
| 2197 | {40, 40}, {100, 40}, {100, 100}, {20, 100}}; |
| 2198 | path.addPoly(poly, SK_ARRAY_COUNT(poly), true); |
| 2199 | path.setFillType(SkPath::kWinding_FillType); |
| 2200 | canvas->save(); |
| 2201 | canvas->clipPath(path, SkClipOp::kIntersect); |
| 2202 | canvas->drawCircle(50, 50, 45, paint); |
| 2203 | canvas->restore(); |
| 2204 | canvas->translate(100, 100); |
| 2205 | path.setFillType(SkPath::kEvenOdd_FillType); |
| 2206 | canvas->clipPath(path, SkClipOp::kIntersect); |
| 2207 | canvas->drawCircle(50, 50, 45, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2208 | } |
| 2209 | ## |
| 2210 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2211 | #SeeAlso clipRect clipRRect clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2212 | |
| 2213 | ## |
| 2214 | |
| 2215 | # ------------------------------------------------------------------------------ |
| 2216 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2217 | #Method void setAllowSimplifyClip(bool allow) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2218 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2219 | #In Clip |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2220 | #Experimental testing |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2221 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2222 | Set to simplify clip stack using PathOps. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2223 | |
| 2224 | ## |
| 2225 | |
| 2226 | # ------------------------------------------------------------------------------ |
| 2227 | |
| 2228 | #Method void clipRegion(const SkRegion& deviceRgn, SkClipOp op = SkClipOp::kIntersect) |
| 2229 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2230 | #In Clip |
| 2231 | #Line # combines Clip with Region ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2232 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2233 | |
| 2234 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2235 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2236 | region is unaffected by canvas rotation; iRect is affected by canvas rotation. |
| 2237 | Both clips are Aliased; this is not noticeable on Region clip because it |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2238 | aligns to pixel boundaries. |
| 2239 | ## |
| 2240 | void draw(SkCanvas* canvas) { |
| 2241 | SkPaint paint; |
| 2242 | paint.setAntiAlias(true); |
| 2243 | SkIRect iRect = {30, 40, 120, 130 }; |
| 2244 | SkRegion region(iRect); |
| 2245 | canvas->rotate(10); |
| 2246 | canvas->save(); |
| 2247 | canvas->clipRegion(region, SkClipOp::kIntersect); |
| 2248 | canvas->drawCircle(50, 50, 45, paint); |
| 2249 | canvas->restore(); |
| 2250 | canvas->translate(100, 100); |
| 2251 | canvas->clipRect(SkRect::Make(iRect), SkClipOp::kIntersect); |
| 2252 | canvas->drawCircle(50, 50, 45, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2253 | } |
| 2254 | ## |
| 2255 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2256 | #SeeAlso clipRect clipRRect clipPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2257 | |
| 2258 | ## |
| 2259 | |
| 2260 | #Method bool quickReject(const SkRect& rect) const |
| 2261 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2262 | #In Clip |
| 2263 | #Line # returns if Rect is outside Clip ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2264 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2265 | |
| 2266 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2267 | void draw(SkCanvas* canvas) { |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2268 | SkRect testRect = {30, 30, 120, 129 }; |
| 2269 | SkRect clipRect = {30, 130, 120, 230 }; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2270 | canvas->save(); |
| 2271 | canvas->clipRect(clipRect); |
| 2272 | SkDebugf("quickReject %s\n", canvas->quickReject(testRect) ? "true" : "false"); |
| 2273 | canvas->restore(); |
| 2274 | canvas->rotate(10); |
| 2275 | canvas->clipRect(clipRect); |
| 2276 | SkDebugf("quickReject %s\n", canvas->quickReject(testRect) ? "true" : "false"); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2277 | } |
| 2278 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2279 | quickReject true |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2280 | quickReject false |
| 2281 | ## |
| 2282 | ## |
| 2283 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2284 | #SeeAlso getLocalClipBounds getTotalMatrix SkBitmap::drawsNothing |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2285 | |
| 2286 | ## |
| 2287 | |
| 2288 | #Method bool quickReject(const SkPath& path) const |
| 2289 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2290 | #In Clip |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2291 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2292 | |
| 2293 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2294 | void draw(SkCanvas* canvas) { |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2295 | SkPoint testPoints[] = {{30, 30}, {120, 30}, {120, 129} }; |
| 2296 | SkPoint clipPoints[] = {{30, 130}, {120, 130}, {120, 230} }; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2297 | SkPath testPath, clipPath; |
| 2298 | testPath.addPoly(testPoints, SK_ARRAY_COUNT(testPoints), true); |
| 2299 | clipPath.addPoly(clipPoints, SK_ARRAY_COUNT(clipPoints), true); |
| 2300 | canvas->save(); |
| 2301 | canvas->clipPath(clipPath); |
| 2302 | SkDebugf("quickReject %s\n", canvas->quickReject(testPath) ? "true" : "false"); |
| 2303 | canvas->restore(); |
| 2304 | canvas->rotate(10); |
| 2305 | canvas->clipPath(clipPath); |
| 2306 | SkDebugf("quickReject %s\n", canvas->quickReject(testPath) ? "true" : "false"); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2307 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2308 | quickReject true |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2309 | quickReject false |
| 2310 | ## |
| 2311 | } |
| 2312 | ## |
| 2313 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2314 | #SeeAlso getLocalClipBounds getTotalMatrix SkBitmap::drawsNothing |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2315 | |
| 2316 | ## |
| 2317 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2318 | #Method SkRect getLocalClipBounds() const |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2319 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2320 | #In Clip |
| 2321 | #Line # returns Clip bounds in source coordinates ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2322 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2323 | |
| 2324 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2325 | #Description |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2326 | Initial bounds is device bounds outset by 1 on all sides. |
| 2327 | Clipped bounds is clipPath bounds outset by 1 on all sides. |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 2328 | Scaling the canvas by two on both axes scales the local bounds by 1/2 |
| 2329 | on both axes. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2330 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2331 | SkCanvas local(256, 256); |
| 2332 | canvas = &local; |
| 2333 | SkRect bounds = canvas->getLocalClipBounds(); |
| 2334 | SkDebugf("left:%g top:%g right:%g bottom:%g\n", |
| 2335 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2336 | SkPoint clipPoints[] = {{30, 130}, {120, 130}, {120, 230} }; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2337 | SkPath clipPath; |
| 2338 | clipPath.addPoly(clipPoints, SK_ARRAY_COUNT(clipPoints), true); |
| 2339 | canvas->clipPath(clipPath); |
| 2340 | bounds = canvas->getLocalClipBounds(); |
| 2341 | SkDebugf("left:%g top:%g right:%g bottom:%g\n", |
| 2342 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
| 2343 | canvas->scale(2, 2); |
| 2344 | bounds = canvas->getLocalClipBounds(); |
| 2345 | SkDebugf("left:%g top:%g right:%g bottom:%g\n", |
| 2346 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
| 2347 | #StdOut |
| 2348 | left:-1 top:-1 right:257 bottom:257 |
| 2349 | left:29 top:129 right:121 bottom:231 |
| 2350 | left:14.5 top:64.5 right:60.5 bottom:115.5 |
| 2351 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2352 | ## |
| 2353 | |
| 2354 | # local canvas in example works around bug in fiddle ## |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2355 | #Bug 6524 |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2356 | #SeeAlso getDeviceClipBounds getBaseLayerSize quickReject |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2357 | |
| 2358 | ## |
| 2359 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2360 | #Method bool getLocalClipBounds(SkRect* bounds) const |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2361 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2362 | #In Clip |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2363 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2364 | |
| 2365 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2366 | void draw(SkCanvas* canvas) { |
| 2367 | SkCanvas local(256, 256); |
| 2368 | canvas = &local; |
| 2369 | SkRect bounds; |
| 2370 | SkDebugf("local bounds empty = %s\n", canvas->getLocalClipBounds(&bounds) |
| 2371 | ? "false" : "true"); |
| 2372 | SkPath path; |
| 2373 | canvas->clipPath(path); |
| 2374 | SkDebugf("local bounds empty = %s\n", canvas->getLocalClipBounds(&bounds) |
| 2375 | ? "false" : "true"); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2376 | } |
| 2377 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2378 | local bounds empty = false |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2379 | local bounds empty = true |
| 2380 | ## |
| 2381 | ## |
| 2382 | |
| 2383 | # local canvas in example works around bug in fiddle ## |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2384 | #Bug 6524 |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2385 | #SeeAlso getDeviceClipBounds getBaseLayerSize quickReject |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2386 | |
| 2387 | ## |
| 2388 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2389 | #Method SkIRect getDeviceClipBounds() const |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2390 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2391 | #In Clip |
| 2392 | #Line # returns IRect bounds of Clip ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2393 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2394 | |
| 2395 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2396 | void draw(SkCanvas* canvas) { |
| 2397 | #Description |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2398 | Initial bounds is device bounds, not outset. |
| 2399 | Clipped bounds is clipPath bounds, not outset. |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 2400 | Scaling the canvas by 1/2 on both axes scales the device bounds by 1/2 |
| 2401 | on both axes. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2402 | ## |
| 2403 | SkCanvas device(256, 256); |
| 2404 | canvas = &device; |
| 2405 | SkIRect bounds = canvas->getDeviceClipBounds(); |
| 2406 | SkDebugf("left:%d top:%d right:%d bottom:%d\n", |
| 2407 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2408 | SkPoint clipPoints[] = {{30, 130}, {120, 130}, {120, 230} }; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2409 | SkPath clipPath; |
| 2410 | clipPath.addPoly(clipPoints, SK_ARRAY_COUNT(clipPoints), true); |
| 2411 | canvas->save(); |
| 2412 | canvas->clipPath(clipPath); |
| 2413 | bounds = canvas->getDeviceClipBounds(); |
| 2414 | SkDebugf("left:%d top:%d right:%d bottom:%d\n", |
| 2415 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
| 2416 | canvas->restore(); |
| 2417 | canvas->scale(1.f/2, 1.f/2); |
| 2418 | canvas->clipPath(clipPath); |
| 2419 | bounds = canvas->getDeviceClipBounds(); |
| 2420 | SkDebugf("left:%d top:%d right:%d bottom:%d\n", |
| 2421 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2422 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2423 | left:0 top:0 right:256 bottom:256 |
| 2424 | left:30 top:130 right:120 bottom:230 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2425 | left:15 top:65 right:60 bottom:115 |
| 2426 | ## |
| 2427 | } |
| 2428 | ## |
| 2429 | |
| 2430 | #ToDo some confusion on why with an identity Matrix local and device are different ## |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2431 | #SeeAlso getLocalClipBounds getBaseLayerSize quickReject |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2432 | |
| 2433 | # device canvas in example works around bug in fiddle ## |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2434 | #Bug 6524 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2435 | |
| 2436 | ## |
| 2437 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2438 | #Method bool getDeviceClipBounds(SkIRect* bounds) const |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2439 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2440 | #In Clip |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2441 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2442 | |
| 2443 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2444 | void draw(SkCanvas* canvas) { |
| 2445 | SkIRect bounds; |
| 2446 | SkDebugf("device bounds empty = %s\n", canvas->getDeviceClipBounds(&bounds) |
| 2447 | ? "false" : "true"); |
| 2448 | SkPath path; |
| 2449 | canvas->clipPath(path); |
| 2450 | SkDebugf("device bounds empty = %s\n", canvas->getDeviceClipBounds(&bounds) |
| 2451 | ? "false" : "true"); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2452 | } |
| 2453 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2454 | device bounds empty = false |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2455 | device bounds empty = true |
| 2456 | ## |
| 2457 | ## |
| 2458 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2459 | #SeeAlso getLocalClipBounds getBaseLayerSize quickReject |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2460 | |
| 2461 | ## |
| 2462 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2463 | #Subtopic Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2464 | |
| 2465 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2466 | #Subtopic Draw |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2467 | #Line # draws into Canvas ## |
| 2468 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2469 | |
| 2470 | #Method void drawColor(SkColor color, SkBlendMode mode = SkBlendMode::kSrcOver) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2471 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2472 | #Line # fills Clip with Color and Blend_Mode ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2473 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2474 | |
| 2475 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2476 | canvas->drawColor(SK_ColorRED); |
| 2477 | canvas->clipRect(SkRect::MakeWH(150, 150)); |
| 2478 | canvas->drawColor(SkColorSetARGB(0x80, 0x00, 0xFF, 0x00), SkBlendMode::kPlus); |
| 2479 | canvas->clipRect(SkRect::MakeWH(75, 75)); |
| 2480 | canvas->drawColor(SkColorSetARGB(0x80, 0x00, 0x00, 0xFF), SkBlendMode::kPlus); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2481 | ## |
| 2482 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2483 | #SeeAlso clear SkBitmap::erase drawPaint |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2484 | |
| 2485 | ## |
| 2486 | |
| 2487 | # ------------------------------------------------------------------------------ |
| 2488 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2489 | #Method void clear(SkColor color) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2490 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2491 | #Line # fills Clip with Color ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2492 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2493 | |
| 2494 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2495 | void draw(SkCanvas* canvas) { |
| 2496 | canvas->save(); |
| 2497 | canvas->clipRect(SkRect::MakeWH(256, 128)); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2498 | canvas->clear(SkColorSetARGB(0x80, 0xFF, 0x00, 0x00)); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2499 | canvas->restore(); |
| 2500 | canvas->save(); |
| 2501 | canvas->clipRect(SkRect::MakeWH(150, 192)); |
| 2502 | canvas->clear(SkColorSetARGB(0x80, 0x00, 0xFF, 0x00)); |
| 2503 | canvas->restore(); |
| 2504 | canvas->clipRect(SkRect::MakeWH(75, 256)); |
| 2505 | canvas->clear(SkColorSetARGB(0x80, 0x00, 0x00, 0xFF)); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2506 | } |
| 2507 | ## |
| 2508 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2509 | #SeeAlso drawColor SkBitmap::erase drawPaint |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2510 | |
| 2511 | ## |
| 2512 | |
| 2513 | # ------------------------------------------------------------------------------ |
| 2514 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2515 | #Method void discard() |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2516 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2517 | #Line # makes Canvas contents undefined ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2518 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2519 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2520 | #NoExample |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2521 | ## |
| 2522 | |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2523 | #SeeAlso flush() SkSurface::prepareForExternalIO GrContext::abandonContext |
| 2524 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2525 | ## |
| 2526 | |
| 2527 | # ------------------------------------------------------------------------------ |
| 2528 | |
| 2529 | #Method void drawPaint(const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2530 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2531 | #Line # fills Clip with Paint ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2532 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2533 | |
| 2534 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2535 | void draw(SkCanvas* canvas) { |
| 2536 | SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE }; |
| 2537 | SkScalar pos[] = { 0, SK_Scalar1/2, SK_Scalar1 }; |
| 2538 | SkPaint paint; |
| 2539 | paint.setShader(SkGradientShader::MakeSweep(256, 256, colors, pos, SK_ARRAY_COUNT(colors))); |
| 2540 | canvas->drawPaint(paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2541 | } |
| 2542 | ## |
| 2543 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2544 | #SeeAlso clear drawColor SkBitmap::erase |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2545 | |
| 2546 | ## |
| 2547 | |
| 2548 | # ------------------------------------------------------------------------------ |
| 2549 | |
| 2550 | #Enum PointMode |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2551 | #Line # sets drawPoints options ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2552 | |
| 2553 | #Code |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 2554 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2555 | ## |
| 2556 | |
| 2557 | Selects if an array of points are drawn as discrete points, as lines, or as |
| 2558 | an open polygon. |
| 2559 | |
| 2560 | #Const kPoints_PointMode 0 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2561 | #Line # draw each point separately ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2562 | ## |
| 2563 | |
| 2564 | #Const kLines_PointMode 1 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2565 | #Line # draw each pair of points as a line segment ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2566 | ## |
| 2567 | |
| 2568 | #Const kPolygon_PointMode 2 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2569 | #Line # draw the array of points as a open polygon ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2570 | ## |
| 2571 | |
| 2572 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2573 | #Description |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2574 | The upper left corner shows three squares when drawn as points. |
| 2575 | The upper right corner shows one line; when drawn as lines, two points are required per line. |
| 2576 | The lower right corner shows two lines; when draw as polygon, no miter is drawn at the corner. |
| 2577 | The lower left corner shows two lines with a miter when path contains polygon. |
| 2578 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2579 | void draw(SkCanvas* canvas) { |
| 2580 | SkPaint paint; |
| 2581 | paint.setStyle(SkPaint::kStroke_Style); |
| 2582 | paint.setStrokeWidth(10); |
| 2583 | SkPoint points[] = {{64, 32}, {96, 96}, {32, 96}}; |
| 2584 | canvas->drawPoints(SkCanvas::kPoints_PointMode, 3, points, paint); |
| 2585 | canvas->translate(128, 0); |
| 2586 | canvas->drawPoints(SkCanvas::kLines_PointMode, 3, points, paint); |
| 2587 | canvas->translate(0, 128); |
| 2588 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, 3, points, paint); |
| 2589 | SkPath path; |
| 2590 | path.addPoly(points, 3, false); |
| 2591 | canvas->translate(-128, 0); |
| 2592 | canvas->drawPath(path, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2593 | } |
| 2594 | ## |
| 2595 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2596 | #SeeAlso drawLine drawPoint drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2597 | |
| 2598 | ## |
| 2599 | |
| 2600 | # ------------------------------------------------------------------------------ |
| 2601 | |
| 2602 | #Method void drawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2603 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2604 | #Line # draws array as points, lines, polygon ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2605 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2606 | |
| 2607 | #Example |
| 2608 | #Height 200 |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2609 | #Description |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2610 | #List |
| 2611 | # The first column draws points. ## |
| 2612 | # The second column draws points as lines. ## |
| 2613 | # The third column draws points as a polygon. ## |
| 2614 | # The fourth column draws points as a polygonal path. ## |
| 2615 | # The first row uses a round cap and round join. ## |
| 2616 | # The second row uses a square cap and a miter join. ## |
| 2617 | # The third row uses a butt cap and a bevel join. ## |
| 2618 | ## |
| 2619 | The transparent color makes multiple line draws visible; |
| 2620 | the path is drawn all at once. |
| 2621 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2622 | void draw(SkCanvas* canvas) { |
| 2623 | SkPaint paint; |
| 2624 | paint.setAntiAlias(true); |
| 2625 | paint.setStyle(SkPaint::kStroke_Style); |
| 2626 | paint.setStrokeWidth(10); |
| 2627 | paint.setColor(0x80349a45); |
| 2628 | const SkPoint points[] = {{32, 16}, {48, 48}, {16, 32}}; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2629 | const SkPaint::Join join[] = { SkPaint::kRound_Join, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2630 | SkPaint::kMiter_Join, |
| 2631 | SkPaint::kBevel_Join }; |
| 2632 | int joinIndex = 0; |
| 2633 | SkPath path; |
| 2634 | path.addPoly(points, 3, false); |
| 2635 | for (const auto cap : { SkPaint::kRound_Cap, SkPaint::kSquare_Cap, SkPaint::kButt_Cap } ) { |
| 2636 | paint.setStrokeCap(cap); |
| 2637 | paint.setStrokeJoin(join[joinIndex++]); |
| 2638 | for (const auto mode : { SkCanvas::kPoints_PointMode, |
| 2639 | SkCanvas::kLines_PointMode, |
| 2640 | SkCanvas::kPolygon_PointMode } ) { |
| 2641 | canvas->drawPoints(mode, 3, points, paint); |
| 2642 | canvas->translate(64, 0); |
| 2643 | } |
| 2644 | canvas->drawPath(path, paint); |
| 2645 | canvas->translate(-192, 64); |
| 2646 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2647 | } |
| 2648 | ## |
| 2649 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2650 | #SeeAlso drawLine drawPoint drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2651 | |
| 2652 | ## |
| 2653 | |
| 2654 | # ------------------------------------------------------------------------------ |
| 2655 | |
| 2656 | #Method void drawPoint(SkScalar x, SkScalar y, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2657 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2658 | #Line # draws point at (x, y) position ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2659 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2660 | |
| 2661 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2662 | void draw(SkCanvas* canvas) { |
| 2663 | SkPaint paint; |
| 2664 | paint.setAntiAlias(true); |
| 2665 | paint.setColor(0x80349a45); |
| 2666 | paint.setStyle(SkPaint::kStroke_Style); |
| 2667 | paint.setStrokeWidth(100); |
| 2668 | paint.setStrokeCap(SkPaint::kRound_Cap); |
| 2669 | canvas->scale(1, 1.2f); |
| 2670 | canvas->drawPoint(64, 96, paint); |
| 2671 | canvas->scale(.6f, .8f); |
| 2672 | paint.setColor(SK_ColorWHITE); |
| 2673 | canvas->drawPoint(106, 120, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2674 | } |
| 2675 | ## |
| 2676 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2677 | #SeeAlso drawPoints drawCircle drawRect drawLine drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2678 | |
| 2679 | ## |
| 2680 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2681 | #Method void drawPoint(SkPoint p, const SkPaint& paint) |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2682 | #Populate |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2683 | |
| 2684 | #Example |
| 2685 | void draw(SkCanvas* canvas) { |
| 2686 | SkPaint paint; |
| 2687 | paint.setAntiAlias(true); |
| 2688 | paint.setColor(0x80349a45); |
| 2689 | paint.setStyle(SkPaint::kStroke_Style); |
| 2690 | paint.setStrokeWidth(100); |
| 2691 | paint.setStrokeCap(SkPaint::kSquare_Cap); |
| 2692 | canvas->scale(1, 1.2f); |
| 2693 | canvas->drawPoint({64, 96}, paint); |
| 2694 | canvas->scale(.6f, .8f); |
| 2695 | paint.setColor(SK_ColorWHITE); |
| 2696 | canvas->drawPoint(106, 120, paint); |
| 2697 | } |
| 2698 | ## |
| 2699 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2700 | #SeeAlso drawPoints drawCircle drawRect drawLine drawPath |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2701 | |
| 2702 | ## |
| 2703 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2704 | # ------------------------------------------------------------------------------ |
| 2705 | |
| 2706 | #Method void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2707 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2708 | #Line # draws line segment between two points ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2709 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2710 | |
| 2711 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2712 | SkPaint paint; |
| 2713 | paint.setAntiAlias(true); |
| 2714 | paint.setColor(0xFF9a67be); |
| 2715 | paint.setStrokeWidth(20); |
| 2716 | canvas->skew(1, 0); |
| 2717 | canvas->drawLine(32, 96, 32, 160, paint); |
| 2718 | canvas->skew(-2, 0); |
| 2719 | canvas->drawLine(288, 96, 288, 160, paint); |
| 2720 | ## |
| 2721 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2722 | #SeeAlso drawPoint drawCircle drawRect drawPath |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2723 | |
| 2724 | ## |
| 2725 | |
| 2726 | #Method void drawLine(SkPoint p0, SkPoint p1, const SkPaint& paint) |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2727 | #Populate |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2728 | |
| 2729 | #Example |
| 2730 | SkPaint paint; |
| 2731 | paint.setAntiAlias(true); |
| 2732 | paint.setColor(0xFF9a67be); |
| 2733 | paint.setStrokeWidth(20); |
| 2734 | canvas->skew(1, 0); |
| 2735 | canvas->drawLine({32, 96}, {32, 160}, paint); |
| 2736 | canvas->skew(-2, 0); |
| 2737 | canvas->drawLine({288, 96}, {288, 160}, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2738 | ## |
| 2739 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2740 | #SeeAlso drawPoint drawCircle drawRect drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2741 | |
| 2742 | ## |
| 2743 | |
| 2744 | # ------------------------------------------------------------------------------ |
| 2745 | |
| 2746 | #Method void drawRect(const SkRect& rect, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2747 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2748 | #Line # draws Rect using Clip, Matrix, and Paint ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2749 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2750 | |
| 2751 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2752 | void draw(SkCanvas* canvas) { |
| 2753 | SkPoint rectPts[] = { {64, 48}, {192, 160} }; |
| 2754 | SkPaint paint; |
| 2755 | paint.setAntiAlias(true); |
| 2756 | paint.setStyle(SkPaint::kStroke_Style); |
| 2757 | paint.setStrokeWidth(20); |
| 2758 | paint.setStrokeJoin(SkPaint::kRound_Join); |
| 2759 | SkMatrix rotator; |
| 2760 | rotator.setRotate(30, 128, 128); |
| 2761 | for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorMAGENTA } ) { |
| 2762 | paint.setColor(color); |
| 2763 | SkRect rect; |
| 2764 | rect.set(rectPts[0], rectPts[1]); |
| 2765 | canvas->drawRect(rect, paint); |
| 2766 | rotator.mapPoints(rectPts, 2); |
| 2767 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2768 | } |
| 2769 | ## |
| 2770 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2771 | #SeeAlso drawIRect drawRRect drawRoundRect drawRegion drawPath drawLine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2772 | |
| 2773 | ## |
| 2774 | |
| 2775 | # ------------------------------------------------------------------------------ |
| 2776 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2777 | #Method void drawIRect(const SkIRect& rect, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2778 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2779 | #Line # draws IRect using Clip, Matrix, and Paint ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2780 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2781 | |
| 2782 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2783 | SkIRect rect = { 64, 48, 192, 160 }; |
| 2784 | SkPaint paint; |
| 2785 | paint.setAntiAlias(true); |
| 2786 | paint.setStyle(SkPaint::kStroke_Style); |
| 2787 | paint.setStrokeWidth(20); |
| 2788 | paint.setStrokeJoin(SkPaint::kRound_Join); |
| 2789 | for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorMAGENTA } ) { |
| 2790 | paint.setColor(color); |
| 2791 | canvas->drawIRect(rect, paint); |
| 2792 | canvas->rotate(30, 128, 128); |
| 2793 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2794 | ## |
| 2795 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2796 | #SeeAlso drawRect drawRRect drawRoundRect drawRegion drawPath drawLine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2797 | |
| 2798 | ## |
| 2799 | |
| 2800 | # ------------------------------------------------------------------------------ |
| 2801 | |
| 2802 | #Method void drawRegion(const SkRegion& region, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2803 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2804 | #Line # draws Region using Clip, Matrix, and Paint ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2805 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2806 | |
| 2807 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2808 | void draw(SkCanvas* canvas) { |
| 2809 | SkRegion region; |
| 2810 | region.op( 10, 10, 50, 50, SkRegion::kUnion_Op); |
| 2811 | region.op( 10, 50, 90, 90, SkRegion::kUnion_Op); |
| 2812 | SkPaint paint; |
| 2813 | paint.setAntiAlias(true); |
| 2814 | paint.setStyle(SkPaint::kStroke_Style); |
| 2815 | paint.setStrokeWidth(20); |
| 2816 | paint.setStrokeJoin(SkPaint::kRound_Join); |
| 2817 | canvas->drawRegion(region, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2818 | } |
| 2819 | ## |
| 2820 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2821 | #SeeAlso drawRect drawIRect drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2822 | |
| 2823 | ## |
| 2824 | |
| 2825 | # ------------------------------------------------------------------------------ |
| 2826 | |
| 2827 | #Method void drawOval(const SkRect& oval, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2828 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2829 | #Line # draws Oval using Clip, Matrix, and Paint ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2830 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2831 | |
| 2832 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2833 | void draw(SkCanvas* canvas) { |
| 2834 | canvas->clear(0xFF3f5f9f); |
| 2835 | SkColor kColor1 = SkColorSetARGB(0xff, 0xff, 0x7f, 0); |
| 2836 | SkColor g1Colors[] = { kColor1, SkColorSetA(kColor1, 0x20) }; |
| 2837 | SkPoint g1Points[] = { { 0, 0 }, { 0, 100 } }; |
| 2838 | SkScalar pos[] = { 0.2f, 1.0f }; |
| 2839 | SkRect bounds = SkRect::MakeWH(80, 70); |
| 2840 | SkPaint paint; |
| 2841 | paint.setAntiAlias(true); |
| 2842 | paint.setShader(SkGradientShader::MakeLinear(g1Points, g1Colors, pos, SK_ARRAY_COUNT(g1Colors), |
| 2843 | SkShader::kClamp_TileMode)); |
| 2844 | canvas->drawOval(bounds , paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2845 | } |
| 2846 | ## |
| 2847 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2848 | #SeeAlso drawCircle drawPoint drawPath drawRRect drawRoundRect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2849 | |
| 2850 | ## |
| 2851 | |
| 2852 | # ------------------------------------------------------------------------------ |
| 2853 | |
| 2854 | #Method void drawRRect(const SkRRect& rrect, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2855 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2856 | #Line # draws Round_Rect using Clip, Matrix, and Paint ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2857 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2858 | |
| 2859 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2860 | void draw(SkCanvas* canvas) { |
| 2861 | SkPaint paint; |
| 2862 | paint.setAntiAlias(true); |
| 2863 | SkRect outer = {30, 40, 210, 220}; |
| 2864 | SkRect radii = {30, 50, 70, 90 }; |
| 2865 | SkRRect rRect; |
| 2866 | rRect.setNinePatch(outer, radii.fLeft, radii.fTop, radii.fRight, radii.fBottom); |
| 2867 | canvas->drawRRect(rRect, paint); |
| 2868 | paint.setColor(SK_ColorWHITE); |
| 2869 | canvas->drawLine(outer.fLeft + radii.fLeft, outer.fTop, |
| 2870 | outer.fLeft + radii.fLeft, outer.fBottom, paint); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2871 | canvas->drawLine(outer.fRight - radii.fRight, outer.fTop, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2872 | outer.fRight - radii.fRight, outer.fBottom, paint); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2873 | canvas->drawLine(outer.fLeft, outer.fTop + radii.fTop, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2874 | outer.fRight, outer.fTop + radii.fTop, paint); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2875 | canvas->drawLine(outer.fLeft, outer.fBottom - radii.fBottom, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2876 | outer.fRight, outer.fBottom - radii.fBottom, paint); |
| 2877 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2878 | ## |
| 2879 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2880 | #SeeAlso drawRect drawRoundRect drawDRRect drawCircle drawOval drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2881 | |
| 2882 | ## |
| 2883 | |
| 2884 | # ------------------------------------------------------------------------------ |
| 2885 | |
| 2886 | #Method void drawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2887 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2888 | #Line # draws double Round_Rect stroked or filled ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2889 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2890 | |
| 2891 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2892 | void draw(SkCanvas* canvas) { |
| 2893 | SkRRect outer = SkRRect::MakeRect({20, 40, 210, 200}); |
| 2894 | SkRRect inner = SkRRect::MakeOval({60, 70, 170, 160}); |
| 2895 | SkPaint paint; |
| 2896 | canvas->drawDRRect(outer, inner, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2897 | } |
| 2898 | ## |
| 2899 | |
| 2900 | #Example |
| 2901 | #Description |
| 2902 | Outer Rect has no corner radii, but stroke join is rounded. |
| 2903 | Inner Round_Rect has corner radii; outset stroke increases radii of corners. |
| 2904 | Stroke join does not affect inner Round_Rect since it has no sharp corners. |
| 2905 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2906 | void draw(SkCanvas* canvas) { |
| 2907 | SkRRect outer = SkRRect::MakeRect({20, 40, 210, 200}); |
| 2908 | SkRRect inner = SkRRect::MakeRectXY({60, 70, 170, 160}, 10, 10); |
| 2909 | SkPaint paint; |
| 2910 | paint.setAntiAlias(true); |
| 2911 | paint.setStyle(SkPaint::kStroke_Style); |
| 2912 | paint.setStrokeWidth(20); |
| 2913 | paint.setStrokeJoin(SkPaint::kRound_Join); |
| 2914 | canvas->drawDRRect(outer, inner, paint); |
| 2915 | paint.setStrokeWidth(1); |
| 2916 | paint.setColor(SK_ColorWHITE); |
| 2917 | canvas->drawDRRect(outer, inner, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2918 | } |
| 2919 | ## |
| 2920 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2921 | #SeeAlso drawRect drawRoundRect drawRRect drawCircle drawOval drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2922 | |
| 2923 | ## |
| 2924 | |
| 2925 | # ------------------------------------------------------------------------------ |
| 2926 | |
| 2927 | #Method void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2928 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2929 | #Line # draws Circle using Clip, Matrix, and Paint ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2930 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2931 | |
| 2932 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2933 | void draw(SkCanvas* canvas) { |
| 2934 | SkPaint paint; |
| 2935 | paint.setAntiAlias(true); |
| 2936 | canvas->drawCircle(128, 128, 90, paint); |
| 2937 | paint.setColor(SK_ColorWHITE); |
| 2938 | canvas->drawCircle(86, 86, 20, paint); |
| 2939 | canvas->drawCircle(160, 76, 20, paint); |
| 2940 | canvas->drawCircle(140, 150, 35, paint); |
| 2941 | } |
| 2942 | ## |
| 2943 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2944 | #SeeAlso drawOval drawRRect drawRoundRect drawPath drawArc drawPoint drawLine |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2945 | |
| 2946 | ## |
| 2947 | |
| 2948 | #Method void drawCircle(SkPoint center, SkScalar radius, const SkPaint& paint) |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2949 | #Populate |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2950 | |
| 2951 | #Example |
| 2952 | void draw(SkCanvas* canvas) { |
| 2953 | SkPaint paint; |
| 2954 | paint.setAntiAlias(true); |
| 2955 | canvas->drawCircle(128, 128, 90, paint); |
| 2956 | paint.setColor(SK_ColorWHITE); |
| 2957 | canvas->drawCircle({86, 86}, 20, paint); |
| 2958 | canvas->drawCircle({160, 76}, 20, paint); |
| 2959 | canvas->drawCircle({140, 150}, 35, paint); |
| 2960 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2961 | ## |
| 2962 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2963 | #SeeAlso drawOval drawRRect drawRoundRect drawPath drawArc drawPoint drawLine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2964 | |
| 2965 | ## |
| 2966 | |
| 2967 | # ------------------------------------------------------------------------------ |
| 2968 | |
| 2969 | #Method void drawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, |
| 2970 | bool useCenter, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2971 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2972 | #Line # draws Arc using Clip, Matrix, and Paint ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2973 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2974 | |
| 2975 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2976 | void draw(SkCanvas* canvas) { |
| 2977 | SkPaint paint; |
| 2978 | paint.setAntiAlias(true); |
| 2979 | SkRect oval = { 4, 4, 60, 60}; |
| 2980 | for (auto useCenter : { false, true } ) { |
| 2981 | for (auto style : { SkPaint::kFill_Style, SkPaint::kStroke_Style } ) { |
| 2982 | paint.setStyle(style); |
| 2983 | for (auto degrees : { 45, 90, 180, 360} ) { |
| 2984 | canvas->drawArc(oval, 0, degrees , useCenter, paint); |
| 2985 | canvas->translate(64, 0); |
| 2986 | } |
| 2987 | canvas->translate(-256, 64); |
| 2988 | } |
| 2989 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2990 | } |
| 2991 | ## |
| 2992 | |
| 2993 | #Example |
| 2994 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2995 | void draw(SkCanvas* canvas) { |
| 2996 | SkPaint paint; |
| 2997 | paint.setAntiAlias(true); |
| 2998 | paint.setStyle(SkPaint::kStroke_Style); |
| 2999 | paint.setStrokeWidth(4); |
| 3000 | SkRect oval = { 4, 4, 60, 60}; |
| 3001 | float intervals[] = { 5, 5 }; |
| 3002 | paint.setPathEffect(SkDashPathEffect::Make(intervals, 2, 2.5f)); |
| 3003 | for (auto degrees : { 270, 360, 540, 720 } ) { |
| 3004 | canvas->drawArc(oval, 0, degrees, false, paint); |
| 3005 | canvas->translate(64, 0); |
| 3006 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3007 | } |
| 3008 | ## |
| 3009 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3010 | #SeeAlso SkPath::arcTo drawCircle drawOval drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3011 | |
| 3012 | ## |
| 3013 | |
| 3014 | # ------------------------------------------------------------------------------ |
| 3015 | |
| 3016 | #Method void drawRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3017 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3018 | #Line # draws Round_Rect using Clip, Matrix, and Paint ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 3019 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3020 | |
| 3021 | #Example |
| 3022 | #Description |
| 3023 | Top row has a zero radius a generates a rectangle. |
| 3024 | Second row radii sum to less than sides. |
| 3025 | Third row radii sum equals sides. |
| 3026 | Fourth row radii sum exceeds sides; radii are scaled to fit. |
| 3027 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3028 | void draw(SkCanvas* canvas) { |
| 3029 | SkVector radii[] = { {0, 20}, {10, 10}, {10, 20}, {10, 40} }; |
| 3030 | SkPaint paint; |
| 3031 | paint.setStrokeWidth(15); |
| 3032 | paint.setStrokeJoin(SkPaint::kRound_Join); |
| 3033 | paint.setAntiAlias(true); |
| 3034 | for (auto style : { SkPaint::kStroke_Style, SkPaint::kFill_Style } ) { |
| 3035 | paint.setStyle(style ); |
| 3036 | for (size_t i = 0; i < SK_ARRAY_COUNT(radii); ++i) { |
| 3037 | canvas->drawRoundRect({10, 10, 60, 40}, radii[i].fX, radii[i].fY, paint); |
| 3038 | canvas->translate(0, 60); |
| 3039 | } |
| 3040 | canvas->translate(80, -240); |
| 3041 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3042 | } |
| 3043 | ## |
| 3044 | |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 3045 | #SeeAlso drawRRect drawRect drawDRRect drawPath drawCircle drawOval drawPoint |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3046 | |
| 3047 | ## |
| 3048 | |
| 3049 | # ------------------------------------------------------------------------------ |
| 3050 | |
| 3051 | #Method void drawPath(const SkPath& path, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3052 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3053 | #Line # draws Path using Clip, Matrix, and Paint ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 3054 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3055 | |
| 3056 | #Example |
| 3057 | #Description |
| 3058 | Top rows draw stroked path with combinations of joins and caps. The open contour |
| 3059 | is affected by caps; the closed contour is affected by joins. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3060 | Bottom row draws fill the same for open and closed contour. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3061 | First bottom column shows winding fills overlap. |
| 3062 | Second bottom column shows even odd fills exclude overlap. |
| 3063 | Third bottom column shows inverse winding fills area outside both contours. |
| 3064 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3065 | void draw(SkCanvas* canvas) { |
| 3066 | SkPath path; |
| 3067 | path.moveTo(20, 20); |
| 3068 | path.quadTo(60, 20, 60, 60); |
| 3069 | path.close(); |
| 3070 | path.moveTo(60, 20); |
| 3071 | path.quadTo(60, 60, 20, 60); |
| 3072 | SkPaint paint; |
| 3073 | paint.setStrokeWidth(10); |
| 3074 | paint.setAntiAlias(true); |
| 3075 | paint.setStyle(SkPaint::kStroke_Style); |
| 3076 | for (auto join: { SkPaint::kBevel_Join, SkPaint::kRound_Join, SkPaint::kMiter_Join } ) { |
| 3077 | paint.setStrokeJoin(join); |
| 3078 | for (auto cap: { SkPaint::kButt_Cap, SkPaint::kSquare_Cap, SkPaint::kRound_Cap } ) { |
| 3079 | paint.setStrokeCap(cap); |
| 3080 | canvas->drawPath(path, paint); |
| 3081 | canvas->translate(80, 0); |
| 3082 | } |
| 3083 | canvas->translate(-240, 60); |
| 3084 | } |
| 3085 | paint.setStyle(SkPaint::kFill_Style); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3086 | for (auto fill : { SkPath::kWinding_FillType, |
| 3087 | SkPath::kEvenOdd_FillType, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3088 | SkPath::kInverseWinding_FillType } ) { |
| 3089 | path.setFillType(fill); |
| 3090 | canvas->save(); |
| 3091 | canvas->clipRect({0, 10, 80, 70}); |
| 3092 | canvas->drawPath(path, paint); |
| 3093 | canvas->restore(); |
| 3094 | canvas->translate(80, 0); |
| 3095 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3096 | } |
| 3097 | ## |
| 3098 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3099 | #SeeAlso SkPath drawLine drawArc drawRect drawPoints |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3100 | |
| 3101 | ## |
| 3102 | |
| 3103 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3104 | #Subtopic Draw_Image |
| 3105 | #Line # draws Image to Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3106 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3107 | drawImage, drawImageRect, and drawImageNine can be called with a bare pointer or |
| 3108 | a smart pointer as a convenience. The pairs of calls are otherwise identical. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3109 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3110 | #Method void drawImage(const SkImage* image, SkScalar left, SkScalar top, const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3111 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3112 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3113 | #Line # draws Image at (x, y) position ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 3114 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3115 | |
| 3116 | #Example |
| 3117 | #Height 64 |
| 3118 | #Image 4 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3119 | void draw(SkCanvas* canvas) { |
| 3120 | // sk_sp<SkImage> image; |
| 3121 | SkImage* imagePtr = image.get(); |
| 3122 | canvas->drawImage(imagePtr, 0, 0); |
| 3123 | SkPaint paint; |
| 3124 | canvas->drawImage(imagePtr, 80, 0, &paint); |
| 3125 | paint.setAlpha(0x80); |
| 3126 | canvas->drawImage(imagePtr, 160, 0, &paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3127 | } |
| 3128 | ## |
| 3129 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3130 | #SeeAlso drawBitmap drawImageLattice drawImageNine drawImageRect SkPaint::setImageFilter |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3131 | |
| 3132 | ## |
| 3133 | |
| 3134 | # ------------------------------------------------------------------------------ |
| 3135 | |
| 3136 | #Method void drawImage(const sk_sp<SkImage>& image, SkScalar left, SkScalar top, |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3137 | const SkPaint* paint = nullptr) |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 3138 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3139 | |
| 3140 | #Example |
| 3141 | #Height 64 |
| 3142 | #Image 4 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3143 | void draw(SkCanvas* canvas) { |
| 3144 | // sk_sp<SkImage> image; |
| 3145 | canvas->drawImage(image, 0, 0); |
| 3146 | SkPaint paint; |
| 3147 | canvas->drawImage(image, 80, 0, &paint); |
| 3148 | paint.setAlpha(0x80); |
| 3149 | canvas->drawImage(image, 160, 0, &paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3150 | } |
| 3151 | ## |
| 3152 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3153 | #SeeAlso drawBitmap drawImageLattice drawImageNine drawImageRect SkPaint::setImageFilter |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3154 | |
| 3155 | ## |
| 3156 | |
| 3157 | # ------------------------------------------------------------------------------ |
| 3158 | |
| 3159 | #Enum SrcRectConstraint |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3160 | #Line # sets drawImageRect options ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3161 | |
| 3162 | #Code |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 3163 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3164 | ## |
| 3165 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3166 | SrcRectConstraint controls the behavior at the edge of source Rect, |
| 3167 | provided to drawImageRect, trading off speed for precision. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3168 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3169 | Image_Filter in Paint may sample multiple pixels in the image. Source Rect |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3170 | restricts the bounds of pixels that may be read. Image_Filter may slow down if |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3171 | it cannot read outside the bounds, when sampling near the edge of source Rect. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3172 | SrcRectConstraint specifies whether an Image_Filter is allowed to read pixels |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3173 | outside source Rect. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3174 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3175 | #Const kStrict_SrcRectConstraint 0 |
| 3176 | #Line # sample only inside bounds; slower ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3177 | Requires Image_Filter to respect source Rect, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3178 | sampling only inside of its bounds, possibly with a performance penalty. |
| 3179 | ## |
| 3180 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3181 | #Const kFast_SrcRectConstraint 1 |
| 3182 | #Line # sample outside bounds; faster ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3183 | Permits Image_Filter to sample outside of source Rect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3184 | by half the width of Image_Filter, permitting it to run faster but with |
| 3185 | error at the image edges. |
| 3186 | ## |
| 3187 | |
| 3188 | #Example |
| 3189 | #Height 64 |
| 3190 | #Description |
| 3191 | redBorder contains a black and white checkerboard bordered by red. |
| 3192 | redBorder is drawn scaled by 16 on the left. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3193 | The middle and right bitmaps are filtered checkerboards. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3194 | Drawing the checkerboard with kStrict_SrcRectConstraint shows only a blur of black and white. |
| 3195 | Drawing the checkerboard with kFast_SrcRectConstraint allows red to bleed in the corners. |
| 3196 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3197 | void draw(SkCanvas* canvas) { |
| 3198 | SkBitmap redBorder; |
| 3199 | redBorder.allocPixels(SkImageInfo::MakeN32Premul(4, 4)); |
| 3200 | SkCanvas checkRed(redBorder); |
| 3201 | checkRed.clear(SK_ColorRED); |
| 3202 | uint32_t checkers[][2] = { { SK_ColorBLACK, SK_ColorWHITE }, |
| 3203 | { SK_ColorWHITE, SK_ColorBLACK } }; |
| 3204 | checkRed.writePixels( |
| 3205 | SkImageInfo::MakeN32Premul(2, 2), (void*) checkers, sizeof(checkers[0]), 1, 1); |
| 3206 | canvas->scale(16, 16); |
| 3207 | canvas->drawBitmap(redBorder, 0, 0, nullptr); |
| 3208 | canvas->resetMatrix(); |
| 3209 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(redBorder); |
| 3210 | SkPaint lowPaint; |
| 3211 | lowPaint.setFilterQuality(kLow_SkFilterQuality); |
| 3212 | for (auto constraint : { SkCanvas::kStrict_SrcRectConstraint, |
| 3213 | SkCanvas::kFast_SrcRectConstraint } ) { |
| 3214 | canvas->translate(80, 0); |
| 3215 | canvas->drawImageRect(image.get(), SkRect::MakeLTRB(1, 1, 3, 3), |
| 3216 | SkRect::MakeLTRB(16, 16, 48, 48), &lowPaint, constraint); |
| 3217 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3218 | } |
| 3219 | ## |
| 3220 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3221 | #SeeAlso drawImageRect drawImage SkPaint::setImageFilter |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3222 | |
| 3223 | ## |
| 3224 | |
| 3225 | # ------------------------------------------------------------------------------ |
| 3226 | |
| 3227 | #Method void drawImageRect(const SkImage* image, const SkRect& src, const SkRect& dst, |
| 3228 | const SkPaint* paint, |
| 3229 | SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3230 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3231 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3232 | #Line # draws Image, source Rect to destination Rect ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 3233 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3234 | |
| 3235 | #Example |
| 3236 | #Height 64 |
| 3237 | #Description |
| 3238 | The left bitmap draws with Paint default kNone_SkFilterQuality, and stays within |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3239 | its bounds; there is no bleeding with kFast_SrcRectConstraint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3240 | the middle and right bitmaps draw with kLow_SkFilterQuality; with |
| 3241 | kStrict_SrcRectConstraint, the filter remains within the checkerboard, and |
| 3242 | with kFast_SrcRectConstraint red bleeds on the edges. |
| 3243 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3244 | void draw(SkCanvas* canvas) { |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3245 | uint32_t pixels[][4] = { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3246 | { 0xFFFF0000, 0xFFFF0000, 0xFFFF0000, 0xFFFF0000 }, |
| 3247 | { 0xFFFF0000, 0xFF000000, 0xFFFFFFFF, 0xFFFF0000 }, |
| 3248 | { 0xFFFF0000, 0xFFFFFFFF, 0xFF000000, 0xFFFF0000 }, |
| 3249 | { 0xFFFF0000, 0xFFFF0000, 0xFFFF0000, 0xFFFF0000 } }; |
| 3250 | SkBitmap redBorder; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3251 | redBorder.installPixels(SkImageInfo::MakeN32Premul(4, 4), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3252 | (void*) pixels, sizeof(pixels[0])); |
| 3253 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(redBorder); |
| 3254 | SkPaint lowPaint; |
| 3255 | for (auto constraint : { |
| 3256 | SkCanvas::kFast_SrcRectConstraint, |
| 3257 | SkCanvas::kStrict_SrcRectConstraint, |
| 3258 | SkCanvas::kFast_SrcRectConstraint } ) { |
| 3259 | canvas->drawImageRect(image.get(), SkRect::MakeLTRB(1, 1, 3, 3), |
| 3260 | SkRect::MakeLTRB(16, 16, 48, 48), &lowPaint, constraint); |
| 3261 | lowPaint.setFilterQuality(kLow_SkFilterQuality); |
| 3262 | canvas->translate(80, 0); |
| 3263 | } |
| 3264 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3265 | ## |
| 3266 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3267 | #SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3268 | |
| 3269 | ## |
| 3270 | |
| 3271 | # ------------------------------------------------------------------------------ |
| 3272 | |
| 3273 | #Method void drawImageRect(const SkImage* image, const SkIRect& isrc, const SkRect& dst, |
| 3274 | const SkPaint* paint, SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3275 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3276 | #In Draw |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 3277 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3278 | |
| 3279 | #Example |
| 3280 | #Image 4 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3281 | void draw(SkCanvas* canvas) { |
| 3282 | // sk_sp<SkImage> image; |
| 3283 | for (auto i : { 1, 2, 4, 8 } ) { |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3284 | canvas->drawImageRect(image.get(), SkIRect::MakeLTRB(0, 0, 100, 100), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3285 | SkRect::MakeXYWH(i * 20, i * 20, i * 20, i * 20), nullptr); |
| 3286 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3287 | } |
| 3288 | ## |
| 3289 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3290 | #SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3291 | |
| 3292 | ## |
| 3293 | |
| 3294 | # ------------------------------------------------------------------------------ |
| 3295 | |
Cary Clark | 0ac0edd | 2018-10-29 11:28:43 -0400 | [diff] [blame] | 3296 | #Method void drawImageRect(const SkImage* image, const SkRect& dst, const SkPaint* paint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3297 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3298 | #In Draw |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 3299 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3300 | |
| 3301 | #Example |
| 3302 | #Image 4 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3303 | void draw(SkCanvas* canvas) { |
| 3304 | // sk_sp<SkImage> image; |
| 3305 | for (auto i : { 20, 40, 80, 160 } ) { |
| 3306 | canvas->drawImageRect(image.get(), SkRect::MakeXYWH(i, i, i, i), nullptr); |
| 3307 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3308 | } |
| 3309 | ## |
| 3310 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3311 | #SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3312 | |
| 3313 | ## |
| 3314 | |
| 3315 | # ------------------------------------------------------------------------------ |
| 3316 | |
| 3317 | #Method void drawImageRect(const sk_sp<SkImage>& image, const SkRect& src, const SkRect& dst, |
| 3318 | const SkPaint* paint, |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3319 | SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3320 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3321 | #In Draw |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 3322 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3323 | |
| 3324 | #Example |
| 3325 | #Height 64 |
| 3326 | #Description |
| 3327 | Canvas scales and translates; transformation from src to dst also scales. |
| 3328 | The two matrices are concatenated to create the final transformation. |
| 3329 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3330 | void draw(SkCanvas* canvas) { |
| 3331 | uint32_t pixels[][2] = { { SK_ColorBLACK, SK_ColorWHITE }, |
| 3332 | { SK_ColorWHITE, SK_ColorBLACK } }; |
| 3333 | SkBitmap bitmap; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3334 | bitmap.installPixels(SkImageInfo::MakeN32Premul(2, 2), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3335 | (void*) pixels, sizeof(pixels[0])); |
| 3336 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 3337 | SkPaint paint; |
| 3338 | canvas->scale(4, 4); |
| 3339 | for (auto alpha : { 50, 100, 150, 255 } ) { |
| 3340 | paint.setAlpha(alpha); |
| 3341 | canvas->drawImageRect(image, SkRect::MakeWH(2, 2), SkRect::MakeWH(8, 8), &paint); |
| 3342 | canvas->translate(8, 0); |
| 3343 | } |
| 3344 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3345 | ## |
| 3346 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3347 | #SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3348 | |
| 3349 | ## |
| 3350 | |
| 3351 | # ------------------------------------------------------------------------------ |
| 3352 | |
| 3353 | #Method void drawImageRect(const sk_sp<SkImage>& image, const SkIRect& isrc, const SkRect& dst, |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3354 | const SkPaint* paint, SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3355 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3356 | #In Draw |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 3357 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3358 | |
| 3359 | #Example |
| 3360 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3361 | void draw(SkCanvas* canvas) { |
| 3362 | uint32_t pixels[][2] = { { 0x00000000, 0x55555555}, |
| 3363 | { 0xAAAAAAAA, 0xFFFFFFFF} }; |
| 3364 | SkBitmap bitmap; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3365 | bitmap.installPixels(SkImageInfo::MakeN32Premul(2, 2), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3366 | (void*) pixels, sizeof(pixels[0])); |
| 3367 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 3368 | SkPaint paint; |
| 3369 | canvas->scale(4, 4); |
| 3370 | for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN } ) { |
| 3371 | paint.setColorFilter(SkColorFilter::MakeModeFilter(color, SkBlendMode::kPlus)); |
| 3372 | canvas->drawImageRect(image, SkIRect::MakeWH(2, 2), SkRect::MakeWH(8, 8), &paint); |
| 3373 | canvas->translate(8, 0); |
| 3374 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3375 | } |
| 3376 | ## |
| 3377 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3378 | #SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine |
| 3379 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3380 | ## |
| 3381 | |
| 3382 | # ------------------------------------------------------------------------------ |
| 3383 | |
Cary Clark | 0ac0edd | 2018-10-29 11:28:43 -0400 | [diff] [blame] | 3384 | #Method void drawImageRect(const sk_sp<SkImage>& image, const SkRect& dst, const SkPaint* paint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3385 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3386 | #In Draw |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 3387 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3388 | |
| 3389 | #Example |
| 3390 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3391 | void draw(SkCanvas* canvas) { |
| 3392 | uint32_t pixels[][2] = { { 0x00000000, 0x55550000}, |
| 3393 | { 0xAAAA0000, 0xFFFF0000} }; |
| 3394 | SkBitmap bitmap; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3395 | bitmap.installPixels(SkImageInfo::MakeN32Premul(2, 2), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3396 | (void*) pixels, sizeof(pixels[0])); |
| 3397 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 3398 | SkPaint paint; |
| 3399 | canvas->scale(4, 4); |
| 3400 | for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN } ) { |
| 3401 | paint.setColorFilter(SkColorFilter::MakeModeFilter(color, SkBlendMode::kPlus)); |
| 3402 | canvas->drawImageRect(image, SkRect::MakeWH(8, 8), &paint); |
| 3403 | canvas->translate(8, 0); |
| 3404 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3405 | } |
| 3406 | ## |
| 3407 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3408 | #SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3409 | |
| 3410 | ## |
| 3411 | |
| 3412 | # ------------------------------------------------------------------------------ |
| 3413 | |
| 3414 | #Method void drawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst, |
| 3415 | const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3416 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3417 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3418 | #Line # draws Nine_Patch Image ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3419 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3420 | Draws Image image stretched proportionally to fit into Rect dst. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3421 | IRect center divides the image into nine sections: four sides, four corners, and |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3422 | the center. Corners are unmodified or scaled down proportionately if their sides |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3423 | are larger than dst; center and four sides are scaled to fit remaining space, if any. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3424 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3425 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
| 3426 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3427 | #paint_as_used_by_draw_lattice_or_draw_nine(image)# |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3428 | |
| 3429 | If generated mask extends beyond image bounds, replicate image edge colors, just |
| 3430 | as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3431 | replicates the image edge color when it samples outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3432 | |
| 3433 | #Param image Image containing pixels, dimensions, and format ## |
| 3434 | #Param center IRect edge of image corners and sides ## |
| 3435 | #Param dst destination Rect of image to draw to ## |
| 3436 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 3437 | and so on; or nullptr |
| 3438 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3439 | |
| 3440 | #Example |
| 3441 | #Height 128 |
| 3442 | #Description |
| 3443 | The leftmost image is smaller than center; only corners are drawn, all scaled to fit. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3444 | The second image equals the size of center; only corners are drawn without scaling. |
| 3445 | The remaining images are larger than center. All corners draw without scaling. |
| 3446 | The sides and center are scaled if needed to take up the remaining space. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3447 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3448 | void draw(SkCanvas* canvas) { |
| 3449 | SkIRect center = { 20, 10, 50, 40 }; |
| 3450 | SkBitmap bitmap; |
| 3451 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60)); |
| 3452 | SkCanvas bitCanvas(bitmap); |
| 3453 | SkPaint paint; |
| 3454 | SkColor gray = 0xFF000000; |
| 3455 | int left = 0; |
| 3456 | for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) { |
| 3457 | int top = 0; |
| 3458 | for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) { |
| 3459 | paint.setColor(gray); |
| 3460 | bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint); |
| 3461 | gray += 0x001f1f1f; |
| 3462 | top = bottom; |
| 3463 | } |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3464 | left = right; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3465 | } |
| 3466 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 3467 | SkImage* imagePtr = image.get(); |
| 3468 | for (auto dest: { 20, 30, 40, 60, 90 } ) { |
| 3469 | canvas->drawImageNine(imagePtr, center, SkRect::MakeWH(dest, dest), nullptr); |
| 3470 | canvas->translate(dest + 4, 0); |
| 3471 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3472 | } |
| 3473 | ## |
| 3474 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3475 | #SeeAlso drawImage drawBitmapNine drawImageLattice drawImageRect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3476 | |
| 3477 | ## |
| 3478 | |
| 3479 | # ------------------------------------------------------------------------------ |
| 3480 | |
| 3481 | #Method void drawImageNine(const sk_sp<SkImage>& image, const SkIRect& center, const SkRect& dst, |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3482 | const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3483 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3484 | #In Draw |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3485 | Draws Image image stretched proportionally to fit into Rect dst. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3486 | IRect center divides the image into nine sections: four sides, four corners, and |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3487 | the center. Corners are not scaled, or scaled down proportionately if their sides |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3488 | are larger than dst; center and four sides are scaled to fit remaining space, if any. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3489 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3490 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
| 3491 | |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 3492 | #paint_as_used_by_draw_lattice_or_draw_nine(image)# |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3493 | |
| 3494 | If generated mask extends beyond image bounds, replicate image edge colors, just |
| 3495 | as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3496 | replicates the image edge color when it samples outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3497 | |
| 3498 | #Param image Image containing pixels, dimensions, and format ## |
| 3499 | #Param center IRect edge of image corners and sides ## |
| 3500 | #Param dst destination Rect of image to draw to ## |
| 3501 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 3502 | and so on; or nullptr |
| 3503 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3504 | |
| 3505 | #Example |
| 3506 | #Height 128 |
| 3507 | #Description |
| 3508 | The two leftmost images has four corners and sides to the left and right of center. |
| 3509 | The leftmost image scales the width of corners proportionately to fit. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3510 | The third and fourth image corners are not scaled; the sides and center are scaled to |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3511 | fill the remaining space. |
| 3512 | The rightmost image has four corners scaled vertically to fit, and uses sides above |
| 3513 | and below center to fill the remaining space. |
| 3514 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3515 | void draw(SkCanvas* canvas) { |
| 3516 | SkIRect center = { 20, 10, 50, 40 }; |
| 3517 | SkBitmap bitmap; |
| 3518 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60)); |
| 3519 | SkCanvas bitCanvas(bitmap); |
| 3520 | SkPaint paint; |
| 3521 | SkColor gray = 0xFF000000; |
| 3522 | int left = 0; |
| 3523 | for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) { |
| 3524 | int top = 0; |
| 3525 | for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) { |
| 3526 | paint.setColor(gray); |
| 3527 | bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint); |
| 3528 | gray += 0x001f1f1f; |
| 3529 | top = bottom; |
| 3530 | } |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3531 | left = right; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3532 | } |
| 3533 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 3534 | for (auto dest: { 20, 30, 40, 60, 90 } ) { |
| 3535 | canvas->drawImageNine(image, center, SkRect::MakeWH(dest, 110 - dest), nullptr); |
| 3536 | canvas->translate(dest + 4, 0); |
| 3537 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3538 | } |
| 3539 | ## |
| 3540 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3541 | #SeeAlso drawImage drawBitmapNine drawImageLattice drawImageRect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3542 | |
| 3543 | ## |
| 3544 | |
| 3545 | # ------------------------------------------------------------------------------ |
| 3546 | |
| 3547 | #Method void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3548 | const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3549 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3550 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3551 | #Line # draws Bitmap at (x, y) position ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 3552 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3553 | |
| 3554 | #Example |
| 3555 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3556 | void draw(SkCanvas* canvas) { |
| 3557 | uint8_t pixels[][8] = { { 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00}, |
| 3558 | { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00}, |
| 3559 | { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00}, |
| 3560 | { 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF}, |
| 3561 | { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, |
| 3562 | { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00}, |
| 3563 | { 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00}, |
| 3564 | { 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF} }; |
| 3565 | SkBitmap bitmap; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3566 | bitmap.installPixels(SkImageInfo::MakeA8(8, 8), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3567 | (void*) pixels, sizeof(pixels[0])); |
| 3568 | SkPaint paint; |
| 3569 | canvas->scale(4, 4); |
| 3570 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xFF007F00} ) { |
| 3571 | paint.setColor(color); |
| 3572 | canvas->drawBitmap(bitmap, 0, 0, &paint); |
| 3573 | canvas->translate(12, 0); |
| 3574 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3575 | } |
| 3576 | ## |
| 3577 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3578 | #SeeAlso drawImage drawBitmapLattice drawBitmapNine drawBitmapRect SkBitmap::readPixels SkBitmap::writePixels |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3579 | |
| 3580 | ## |
| 3581 | |
| 3582 | # ------------------------------------------------------------------------------ |
| 3583 | |
| 3584 | #Method void drawBitmapRect(const SkBitmap& bitmap, const SkRect& src, const SkRect& dst, |
| 3585 | const SkPaint* paint, SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3586 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3587 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3588 | #Line # draws Bitmap, source Rect to destination Rect ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 3589 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3590 | |
| 3591 | #Example |
| 3592 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3593 | void draw(SkCanvas* canvas) { |
| 3594 | uint8_t pixels[][8] = { { 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00}, |
| 3595 | { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00}, |
| 3596 | { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00}, |
| 3597 | { 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF}, |
| 3598 | { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, |
| 3599 | { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00}, |
| 3600 | { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00}, |
| 3601 | { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00} }; |
| 3602 | SkBitmap bitmap; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3603 | bitmap.installPixels(SkImageInfo::MakeA8(8, 8), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3604 | (void*) pixels, sizeof(pixels[0])); |
| 3605 | SkPaint paint; |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 3606 | paint.setMaskFilter(SkMaskFilter::MakeBlur(kSolid_SkBlurStyle, 6)); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3607 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xFF007F00} ) { |
| 3608 | paint.setColor(color); |
| 3609 | canvas->drawBitmapRect(bitmap, SkRect::MakeWH(8, 8), SkRect::MakeWH(32, 32), &paint); |
| 3610 | canvas->translate(48, 0); |
| 3611 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3612 | } |
| 3613 | ## |
| 3614 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3615 | #SeeAlso drawImageRect drawBitmap drawBitmapLattice drawBitmapNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3616 | |
| 3617 | ## |
| 3618 | |
| 3619 | # ------------------------------------------------------------------------------ |
| 3620 | |
| 3621 | #Method void drawBitmapRect(const SkBitmap& bitmap, const SkIRect& isrc, const SkRect& dst, |
| 3622 | const SkPaint* paint, SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3623 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3624 | #In Draw |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 3625 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3626 | |
| 3627 | #Example |
| 3628 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3629 | void draw(SkCanvas* canvas) { |
| 3630 | uint8_t pixels[][8] = { { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00}, |
| 3631 | { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00}, |
| 3632 | { 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF}, |
| 3633 | { 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF}, |
| 3634 | { 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF}, |
| 3635 | { 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF}, |
| 3636 | { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00}, |
| 3637 | { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00} }; |
| 3638 | SkBitmap bitmap; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3639 | bitmap.installPixels(SkImageInfo::MakeA8(8, 8), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3640 | (void*) pixels, sizeof(pixels[0])); |
| 3641 | SkPaint paint; |
| 3642 | paint.setFilterQuality(kHigh_SkFilterQuality); |
| 3643 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xFF007F00, 0xFF7f007f} ) { |
| 3644 | paint.setColor(color); |
| 3645 | canvas->drawBitmapRect(bitmap, SkIRect::MakeWH(8, 8), SkRect::MakeWH(32, 32), &paint); |
| 3646 | canvas->translate(48.25f, 0); |
| 3647 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3648 | } |
| 3649 | ## |
| 3650 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3651 | #SeeAlso drawImageRect drawBitmap drawBitmapLattice drawBitmapNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3652 | |
| 3653 | ## |
| 3654 | |
| 3655 | # ------------------------------------------------------------------------------ |
| 3656 | |
| 3657 | #Method void drawBitmapRect(const SkBitmap& bitmap, const SkRect& dst, const SkPaint* paint, |
| 3658 | SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3659 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3660 | #In Draw |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 3661 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3662 | |
| 3663 | #Example |
| 3664 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3665 | void draw(SkCanvas* canvas) { |
| 3666 | uint32_t pixels[][2] = { { 0x00000000, 0x55550000}, |
| 3667 | { 0xAAAA0000, 0xFFFF0000} }; |
| 3668 | SkBitmap bitmap; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3669 | bitmap.installPixels(SkImageInfo::MakeN32Premul(2, 2), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3670 | (void*) pixels, sizeof(pixels[0])); |
| 3671 | SkPaint paint; |
| 3672 | canvas->scale(4, 4); |
| 3673 | for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN } ) { |
| 3674 | paint.setColorFilter(SkColorFilter::MakeModeFilter(color, SkBlendMode::kPlus)); |
| 3675 | canvas->drawBitmapRect(bitmap, SkRect::MakeWH(8, 8), &paint); |
| 3676 | canvas->translate(8, 0); |
| 3677 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3678 | } |
| 3679 | ## |
| 3680 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3681 | #SeeAlso drawImageRect drawBitmap drawBitmapLattice drawBitmapNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3682 | |
| 3683 | ## |
| 3684 | |
| 3685 | # ------------------------------------------------------------------------------ |
| 3686 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3687 | #PhraseDef paint_as_used_by_draw_lattice_or_draw_nine(bitmap_or_image) |
| 3688 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 3689 | Blend_Mode, and Draw_Looper. If #bitmap_or_image# is kAlpha_8_SkColorType, apply Shader. |
| 3690 | If paint contains Mask_Filter, generate mask from #bitmap_or_image# bounds. If paint |
| 3691 | Filter_Quality set to kNone_SkFilterQuality, disable pixel filtering. For all |
| 3692 | other values of paint Filter_Quality, use kLow_SkFilterQuality to filter pixels. |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 3693 | Any SkMaskFilter on paint is ignored as is paint Anti_Aliasing state. |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3694 | ## |
| 3695 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3696 | #Method void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3697 | const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3698 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3699 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3700 | #Line # draws Nine_Patch Bitmap ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3701 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3702 | Draws Bitmap bitmap stretched proportionally to fit into Rect dst. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3703 | IRect center divides the bitmap into nine sections: four sides, four corners, |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3704 | and the center. Corners are not scaled, or scaled down proportionately if their |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3705 | sides are larger than dst; center and four sides are scaled to fit remaining |
| 3706 | space, if any. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3707 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3708 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
| 3709 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3710 | #paint_as_used_by_draw_lattice_or_draw_nine(bitmap)# |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3711 | |
| 3712 | If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, |
| 3713 | just as Shader made from SkShader::MakeBitmapShader with |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3714 | SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3715 | outside of its bounds. |
| 3716 | |
| 3717 | #Param bitmap Bitmap containing pixels, dimensions, and format ## |
| 3718 | #Param center IRect edge of image corners and sides ## |
| 3719 | #Param dst destination Rect of image to draw to ## |
| 3720 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 3721 | and so on; or nullptr |
| 3722 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3723 | |
| 3724 | #Example |
| 3725 | #Height 128 |
| 3726 | #Description |
| 3727 | The two leftmost bitmap draws has four corners and sides to the left and right of center. |
| 3728 | The leftmost bitmap draw scales the width of corners proportionately to fit. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3729 | The third and fourth draw corners are not scaled; the sides and center are scaled to |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3730 | fill the remaining space. |
| 3731 | The rightmost bitmap draw has four corners scaled vertically to fit, and uses sides above |
| 3732 | and below center to fill the remaining space. |
| 3733 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3734 | void draw(SkCanvas* canvas) { |
| 3735 | SkIRect center = { 20, 10, 50, 40 }; |
| 3736 | SkBitmap bitmap; |
| 3737 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60)); |
| 3738 | SkCanvas bitCanvas(bitmap); |
| 3739 | SkPaint paint; |
| 3740 | SkColor gray = 0xFF000000; |
| 3741 | int left = 0; |
| 3742 | for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) { |
| 3743 | int top = 0; |
| 3744 | for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) { |
| 3745 | paint.setColor(gray); |
| 3746 | bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint); |
| 3747 | gray += 0x001f1f1f; |
| 3748 | top = bottom; |
| 3749 | } |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3750 | left = right; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3751 | } |
| 3752 | for (auto dest: { 20, 30, 40, 60, 90 } ) { |
| 3753 | canvas->drawBitmapNine(bitmap, center, SkRect::MakeWH(dest, 110 - dest), nullptr); |
| 3754 | canvas->translate(dest + 4, 0); |
| 3755 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3756 | } |
| 3757 | ## |
| 3758 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3759 | #SeeAlso drawImageNine drawBitmap drawBitmapLattice drawBitmapRect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3760 | |
| 3761 | ## |
| 3762 | |
| 3763 | # ------------------------------------------------------------------------------ |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3764 | #Subtopic Lattice |
| 3765 | #Line # divides Bitmap or Image into a rectangular grid ## |
| 3766 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3767 | #Struct Lattice |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3768 | #Line # divides Bitmap or Image into a rectangular grid ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3769 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3770 | #Code |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 3771 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3772 | ## |
| 3773 | |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 3774 | Lattice divides Bitmap or Image into a rectangular grid. |
| 3775 | Grid entries on even columns and even rows are fixed; these entries are |
| 3776 | always drawn at their original size if the destination is large enough. |
| 3777 | If the destination side is too small to hold the fixed entries, all fixed |
| 3778 | entries are proportionately scaled down to fit. |
| 3779 | The grid entries not on even columns and rows are scaled to fit the |
| 3780 | remaining space, if any. |
| 3781 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 3782 | #Enum RectType |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3783 | #Line # optional setting per rectangular grid entry ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3784 | #Code |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 3785 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3786 | ## |
| 3787 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 3788 | Optional setting per rectangular grid entry to make it transparent, |
| 3789 | or to fill the grid entry with a color. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3790 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 3791 | #Const kDefault 0 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3792 | #Line # draws Bitmap into lattice rectangle ## |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 3793 | ## |
| 3794 | |
| 3795 | #Const kTransparent 1 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3796 | #Line # skips lattice rectangle by making it transparent ## |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 3797 | ## |
| 3798 | |
| 3799 | #Const kFixedColor 2 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3800 | #Line # draws one of fColors into lattice rectangle ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3801 | ## |
| 3802 | ## |
| 3803 | |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 3804 | #Subtopic Members |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3805 | ## |
| 3806 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3807 | #Member const int* fXDivs |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 3808 | #Line # x-axis values dividing bitmap ## |
| 3809 | Array of x-axis values that divide the bitmap vertically. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3810 | Array entries must be unique, increasing, greater than or equal to |
| 3811 | fBounds left edge, and less than fBounds right edge. |
| 3812 | Set the first element to fBounds left to collapse the left column of |
| 3813 | fixed grid entries. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3814 | ## |
| 3815 | |
| 3816 | #Member const int* fYDivs |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 3817 | #Line # y-axis values dividing bitmap ## |
| 3818 | Array of y-axis values that divide the bitmap horizontally. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3819 | Array entries must be unique, increasing, greater than or equal to |
| 3820 | fBounds top edge, and less than fBounds bottom edge. |
| 3821 | Set the first element to fBounds top to collapse the top row of fixed |
| 3822 | grid entries. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3823 | ## |
| 3824 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 3825 | #Member const RectType* fRectTypes |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3826 | #Line # array of fill types ## |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 3827 | Optional array of fill types, one per rectangular grid entry: |
Cary Clark | 2be81cf | 2018-09-13 12:04:30 -0400 | [diff] [blame] | 3828 | array length must be #Formula # (fXCount + 1) * (fYCount + 1) ##. |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 3829 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 3830 | Each RectType is one of: kDefault, kTransparent, kFixedColor. |
| 3831 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3832 | Array entries correspond to the rectangular grid entries, ascending |
| 3833 | left to right and then top to bottom. |
| 3834 | ## |
| 3835 | |
| 3836 | #Member int fXCount |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3837 | #Line # number of x-coordinates ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3838 | Number of entries in fXDivs array; one less than the number of |
| 3839 | horizontal divisions. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3840 | ## |
| 3841 | |
| 3842 | #Member int fYCount |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3843 | #Line # number of y-coordinates ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3844 | Number of entries in fYDivs array; one less than the number of vertical |
| 3845 | divisions. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3846 | ## |
| 3847 | |
| 3848 | #Member const SkIRect* fBounds |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3849 | #Line # source bounds to draw from ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3850 | Optional subset IRect source to draw from. |
| 3851 | If nullptr, source bounds is dimensions of Bitmap or Image. |
| 3852 | ## |
| 3853 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 3854 | #Member const SkColor* fColors |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3855 | #Line # array of colors ## |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 3856 | Optional array of colors, one per rectangular grid entry. |
Cary Clark | 2be81cf | 2018-09-13 12:04:30 -0400 | [diff] [blame] | 3857 | Array length must be #Formula # (fXCount + 1) * (fYCount + 1) ##. |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 3858 | |
| 3859 | Array entries correspond to the rectangular grid entries, ascending |
| 3860 | left to right, then top to bottom. |
| 3861 | ## |
| 3862 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3863 | #Struct Lattice ## |
| 3864 | |
| 3865 | #Method void drawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice, const SkRect& dst, |
| 3866 | const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3867 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3868 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3869 | #Line # draws proportionally stretched Bitmap ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3870 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3871 | Draws Bitmap bitmap stretched proportionally to fit into Rect dst. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3872 | |
| 3873 | Lattice lattice divides bitmap into a rectangular grid. |
| 3874 | Each intersection of an even-numbered row and column is fixed; like the corners |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3875 | of drawBitmapNine, fixed lattice elements never scale larger than their initial |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3876 | size and shrink proportionately when all fixed elements exceed the bitmap |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3877 | dimension. All other grid elements scale to fill the available space, if any. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3878 | |
| 3879 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3880 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3881 | #paint_as_used_by_draw_lattice_or_draw_nine(bitmap)# |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3882 | |
| 3883 | If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, |
| 3884 | just as Shader made from SkShader::MakeBitmapShader with |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3885 | SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3886 | outside of its bounds. |
| 3887 | |
| 3888 | #Param bitmap Bitmap containing pixels, dimensions, and format ## |
| 3889 | #Param lattice division of bitmap into fixed and variable rectangles ## |
| 3890 | #Param dst destination Rect of image to draw to ## |
| 3891 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 3892 | and so on; or nullptr |
| 3893 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3894 | |
| 3895 | #Example |
| 3896 | #Height 128 |
| 3897 | #Description |
| 3898 | The two leftmost bitmap draws has four corners and sides to the left and right of center. |
| 3899 | The leftmost bitmap draw scales the width of corners proportionately to fit. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3900 | The third and fourth draw corners are not scaled; the sides are scaled to |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3901 | fill the remaining space; the center is transparent. |
| 3902 | The rightmost bitmap draw has four corners scaled vertically to fit, and uses sides above |
| 3903 | and below center to fill the remaining space. |
| 3904 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3905 | void draw(SkCanvas* canvas) { |
| 3906 | SkIRect center = { 20, 10, 50, 40 }; |
| 3907 | SkBitmap bitmap; |
| 3908 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60)); |
| 3909 | SkCanvas bitCanvas(bitmap); |
| 3910 | SkPaint paint; |
| 3911 | SkColor gray = 0xFF000000; |
| 3912 | int left = 0; |
| 3913 | for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) { |
| 3914 | int top = 0; |
| 3915 | for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) { |
| 3916 | paint.setColor(gray); |
| 3917 | bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint); |
| 3918 | gray += 0x001f1f1f; |
| 3919 | top = bottom; |
| 3920 | } |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3921 | left = right; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3922 | } |
| 3923 | const int xDivs[] = { center.fLeft, center.fRight }; |
| 3924 | const int yDivs[] = { center.fTop, center.fBottom }; |
Cary Clark | ca3ebcd | 2017-12-12 11:22:38 -0500 | [diff] [blame] | 3925 | SkCanvas::Lattice::RectType fillTypes[3][3]; |
| 3926 | memset(fillTypes, 0, sizeof(fillTypes)); |
| 3927 | fillTypes[1][1] = SkCanvas::Lattice::kTransparent; |
| 3928 | SkColor dummy[9]; // temporary pending bug fix |
| 3929 | SkCanvas::Lattice lattice = { xDivs, yDivs, fillTypes[0], SK_ARRAY_COUNT(xDivs), |
| 3930 | SK_ARRAY_COUNT(yDivs), nullptr, dummy }; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3931 | for (auto dest: { 20, 30, 40, 60, 90 } ) { |
Cary Clark | ca3ebcd | 2017-12-12 11:22:38 -0500 | [diff] [blame] | 3932 | canvas->drawBitmapLattice(bitmap, lattice, SkRect::MakeWH(dest, 110 - dest), nullptr); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3933 | canvas->translate(dest + 4, 0); |
| 3934 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3935 | } |
| 3936 | ## |
| 3937 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3938 | #SeeAlso drawImageLattice drawBitmap drawBitmapNine Lattice |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3939 | |
| 3940 | ## |
| 3941 | |
| 3942 | # ------------------------------------------------------------------------------ |
| 3943 | |
| 3944 | #Method void drawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst, |
| 3945 | const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3946 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3947 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3948 | #Line # draws proportionally stretched Image ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3949 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3950 | Draws Image image stretched proportionally to fit into Rect dst. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3951 | |
| 3952 | Lattice lattice divides image into a rectangular grid. |
| 3953 | Each intersection of an even-numbered row and column is fixed; like the corners |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3954 | of drawBitmapNine, fixed lattice elements never scale larger than their initial |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3955 | size and shrink proportionately when all fixed elements exceed the bitmap |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3956 | dimension. All other grid elements scale to fill the available space, if any. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3957 | |
| 3958 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3959 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3960 | #paint_as_used_by_draw_lattice_or_draw_nine(image)# |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3961 | |
| 3962 | If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, |
| 3963 | just as Shader made from SkShader::MakeBitmapShader with |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3964 | SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3965 | outside of its bounds. |
| 3966 | |
| 3967 | #Param image Image containing pixels, dimensions, and format ## |
| 3968 | #Param lattice division of bitmap into fixed and variable rectangles ## |
| 3969 | #Param dst destination Rect of image to draw to ## |
| 3970 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 3971 | and so on; or nullptr |
| 3972 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3973 | |
| 3974 | #Example |
| 3975 | #Height 128 |
| 3976 | #Description |
| 3977 | The leftmost image is smaller than center; only corners are drawn, all scaled to fit. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3978 | The second image equals the size of center; only corners are drawn without scaling. |
| 3979 | The remaining images are larger than center. All corners draw without scaling. The sides |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3980 | are scaled if needed to take up the remaining space; the center is transparent. |
| 3981 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3982 | void draw(SkCanvas* canvas) { |
| 3983 | SkIRect center = { 20, 10, 50, 40 }; |
| 3984 | SkBitmap bitmap; |
| 3985 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60)); |
| 3986 | SkCanvas bitCanvas(bitmap); |
| 3987 | SkPaint paint; |
| 3988 | SkColor gray = 0xFF000000; |
| 3989 | int left = 0; |
| 3990 | for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) { |
| 3991 | int top = 0; |
| 3992 | for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) { |
| 3993 | paint.setColor(gray); |
| 3994 | bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint); |
| 3995 | gray += 0x001f1f1f; |
| 3996 | top = bottom; |
| 3997 | } |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3998 | left = right; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3999 | } |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4000 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 4001 | SkImage* imagePtr = image.get(); |
| 4002 | for (auto dest: { 20, 30, 40, 60, 90 } ) { |
| 4003 | canvas->drawImageNine(imagePtr, center, SkRect::MakeWH(dest, dest), nullptr); |
| 4004 | canvas->translate(dest + 4, 0); |
| 4005 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4006 | } |
| 4007 | ## |
| 4008 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4009 | #SeeAlso drawBitmapLattice drawImage drawImageNine Lattice |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4010 | |
| 4011 | ## |
| 4012 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4013 | #Subtopic Lattice ## |
| 4014 | |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 4015 | # ------------------------------------------------------------------------------ |
| 4016 | |
| 4017 | #Enum QuadAAFlags |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 4018 | #Line # do not use this ## |
Brian Salomon | 5d87892 | 2018-10-12 16:33:11 -0400 | [diff] [blame] | 4019 | #Code |
| 4020 | #Populate |
| 4021 | ## |
| 4022 | |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 4023 | #Private |
Cary Clark | b0ba2ac | 2018-10-15 11:38:31 -0400 | [diff] [blame] | 4024 | Do not use. |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 4025 | ## |
Brian Salomon | 5d87892 | 2018-10-12 16:33:11 -0400 | [diff] [blame] | 4026 | |
| 4027 | #Const kLeft_QuadAAFlag 1 |
| 4028 | #Line # antialias the left edge ## |
| 4029 | ## |
| 4030 | |
| 4031 | #Const kTop_QuadAAFlag 2 |
| 4032 | #Line # antialias the top edge ## |
| 4033 | ## |
| 4034 | |
| 4035 | #Const kRight_QuadAAFlag 4 |
| 4036 | #Line # antialias the right edge ## |
| 4037 | ## |
| 4038 | |
| 4039 | #Const kBottom_QuadAAFlag 8 |
| 4040 | #Line # antialias the bottom edge ## |
| 4041 | ## |
| 4042 | |
| 4043 | #Const kNone_QuadAAFlags 0 |
| 4044 | #Line # antialias none of the edges ## |
| 4045 | ## |
| 4046 | |
| 4047 | #Const kAll_QuadAAFlags 15 |
| 4048 | #Line # antialias all of the edges ## |
| 4049 | ## |
| 4050 | |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 4051 | #NoExample |
| 4052 | ## |
| 4053 | ## |
| 4054 | |
| 4055 | # ------------------------------------------------------------------------------ |
| 4056 | |
| 4057 | #Struct ImageSetEntry |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 4058 | #Line # do not use this ## |
Cary Clark | b0ba2ac | 2018-10-15 11:38:31 -0400 | [diff] [blame] | 4059 | |
| 4060 | #Code |
| 4061 | #Populate |
| 4062 | ## |
| 4063 | |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 4064 | #Private |
Cary Clark | b0ba2ac | 2018-10-15 11:38:31 -0400 | [diff] [blame] | 4065 | Do not use. |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 4066 | ## |
| 4067 | |
| 4068 | #Member SkImage* fImage |
| 4069 | #Line # image to draw ## |
| 4070 | ## |
| 4071 | |
| 4072 | #Member SkRect fSrcRect |
| 4073 | #Line # image src rectangle ## |
| 4074 | ## |
| 4075 | |
| 4076 | #Member SkRect fDstRect |
| 4077 | #Line # local space rectangle ## |
| 4078 | ## |
| 4079 | |
| 4080 | #Member unsigned fAAFlags |
| 4081 | #Line # antialiasing flags ## |
| 4082 | ## |
| 4083 | |
| 4084 | #NoExample |
| 4085 | ## |
| 4086 | |
| 4087 | ## |
| 4088 | |
| 4089 | # ------------------------------------------------------------------------------ |
| 4090 | |
| 4091 | #Method void experimental_DrawImageSetV0(const ImageSetEntry imageSet[], int cnt, float alpha, |
| 4092 | SkFilterQuality quality, SkBlendMode mode); |
| 4093 | #Private |
Cary Clark | b0ba2ac | 2018-10-15 11:38:31 -0400 | [diff] [blame] | 4094 | Do not use. |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 4095 | ## |
| 4096 | #In Draw_Image |
| 4097 | #In Draw |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 4098 | #Line # draws a set a of images; do not call this ## |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 4099 | |
| 4100 | Draws a set of images. Do not use this method. |
| 4101 | |
| 4102 | #Param imageSet images ## |
| 4103 | #Param cnt number of images ## |
| 4104 | #Param alpha alpha ## |
| 4105 | #Param quality filter quality ## |
| 4106 | #Param mode blend mode ## |
| 4107 | |
| 4108 | #NoExample |
| 4109 | ## |
| 4110 | |
| 4111 | ## |
| 4112 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 4113 | #Subtopic Draw_Image ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4114 | |
| 4115 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4116 | #Subtopic Draw_Text |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4117 | #Line # draws text into Canvas ## |
| 4118 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4119 | |
| 4120 | #Method void drawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, |
| 4121 | const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4122 | #In Draw_Text |
| 4123 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4124 | #Line # draws text at (x, y), using font advance ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4125 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4126 | |
| 4127 | #Example |
| 4128 | #Height 200 |
| 4129 | #Description |
| 4130 | The same text is drawn varying Paint_Text_Size and varying |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4131 | Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4132 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4133 | void draw(SkCanvas* canvas) { |
| 4134 | SkPaint paint; |
| 4135 | paint.setAntiAlias(true); |
| 4136 | float textSizes[] = { 12, 18, 24, 36 }; |
| 4137 | for (auto size: textSizes ) { |
| 4138 | paint.setTextSize(size); |
| 4139 | canvas->drawText("Aa", 2, 10, 20, paint); |
| 4140 | canvas->translate(0, size * 2); |
| 4141 | } |
| 4142 | paint.reset(); |
| 4143 | paint.setAntiAlias(true); |
| 4144 | float yPos = 20; |
| 4145 | for (auto size: textSizes ) { |
| 4146 | float scale = size / 12.f; |
| 4147 | canvas->resetMatrix(); |
| 4148 | canvas->translate(100, 0); |
| 4149 | canvas->scale(scale, scale); |
| 4150 | canvas->drawText("Aa", 2, 10 / scale, yPos / scale, paint); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4151 | yPos += size * 2; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4152 | } |
| 4153 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4154 | ## |
| 4155 | |
Cary Clark | 153e76d | 2018-08-28 11:48:28 -0400 | [diff] [blame] | 4156 | #SeeAlso drawString drawPosText drawPosTextH drawTextBlob drawTextRSXform |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4157 | |
| 4158 | ## |
| 4159 | |
| 4160 | #Method void drawString(const char* string, SkScalar x, SkScalar y, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4161 | #In Draw_Text |
| 4162 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4163 | #Line # draws null terminated string at (x, y) using font advance ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4164 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4165 | |
| 4166 | #Example |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 4167 | #Height 48 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4168 | SkPaint paint; |
| 4169 | canvas->drawString("a small hello", 20, 20, paint); |
| 4170 | ## |
| 4171 | |
Cary Clark | 153e76d | 2018-08-28 11:48:28 -0400 | [diff] [blame] | 4172 | #SeeAlso drawText drawPosText drawPosTextH drawTextBlob drawTextRSXform |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4173 | |
| 4174 | ## |
| 4175 | |
| 4176 | #Method void drawString(const SkString& string, SkScalar x, SkScalar y, const SkPaint& paint) |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4177 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4178 | |
| 4179 | #Example |
| 4180 | SkPaint paint; |
| 4181 | SkString string("a small hello"); |
| 4182 | canvas->drawString(string, 20, 20, paint); |
| 4183 | ## |
| 4184 | |
Cary Clark | 153e76d | 2018-08-28 11:48:28 -0400 | [diff] [blame] | 4185 | #SeeAlso drawText drawPosText drawPosTextH drawTextBlob drawTextRSXform |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4186 | |
| 4187 | ## |
| 4188 | |
| 4189 | # ------------------------------------------------------------------------------ |
| 4190 | |
| 4191 | #Method void drawPosText(const void* text, size_t byteLength, const SkPoint pos[], |
| 4192 | const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4193 | #In Draw_Text |
| 4194 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4195 | #Line # draws text at array of (x, y) positions ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4196 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4197 | |
| 4198 | #Example |
| 4199 | #Height 120 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4200 | void draw(SkCanvas* canvas) { |
| 4201 | const char hello[] = "HeLLo!"; |
| 4202 | const SkPoint pos[] = { {40, 100}, {82, 95}, {115, 110}, {130, 95}, {145, 85}, |
| 4203 | {172, 100} }; |
| 4204 | SkPaint paint; |
| 4205 | paint.setTextSize(60); |
| 4206 | canvas->drawPosText(hello, strlen(hello), pos, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4207 | } |
| 4208 | ## |
| 4209 | |
Cary Clark | 153e76d | 2018-08-28 11:48:28 -0400 | [diff] [blame] | 4210 | #SeeAlso drawText drawPosTextH drawTextBlob drawTextRSXform |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4211 | |
| 4212 | ## |
| 4213 | |
| 4214 | # ------------------------------------------------------------------------------ |
| 4215 | |
| 4216 | #Method void drawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], SkScalar constY, |
| 4217 | const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4218 | #In Draw_Text |
| 4219 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4220 | #Line # draws text at x positions with common baseline ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4221 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4222 | |
| 4223 | #Example |
| 4224 | #Height 40 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4225 | void draw(SkCanvas* canvas) { |
| 4226 | SkScalar xpos[] = { 20, 40, 80, 160 }; |
| 4227 | SkPaint paint; |
| 4228 | canvas->drawPosTextH("XXXX", 4, xpos, 20, paint); |
| 4229 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4230 | ## |
| 4231 | |
Cary Clark | 153e76d | 2018-08-28 11:48:28 -0400 | [diff] [blame] | 4232 | #SeeAlso drawText drawPosText drawTextBlob drawTextRSXform |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4233 | |
| 4234 | ## |
| 4235 | |
| 4236 | # ------------------------------------------------------------------------------ |
| 4237 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4238 | #Method void drawTextRSXform(const void* text, size_t byteLength, const SkRSXform xform[], |
| 4239 | const SkRect* cullRect, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4240 | #In Draw_Text |
| 4241 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4242 | #Line # draws text with array of RSXform ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4243 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4244 | |
| 4245 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4246 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4247 | const int iterations = 26; |
| 4248 | SkRSXform transforms[iterations]; |
| 4249 | char alphabet[iterations]; |
| 4250 | SkScalar angle = 0; |
| 4251 | SkScalar scale = 1; |
| 4252 | for (size_t i = 0; i < SK_ARRAY_COUNT(transforms); ++i) { |
| 4253 | const SkScalar s = SkScalarSin(angle) * scale; |
| 4254 | const SkScalar c = SkScalarCos(angle) * scale; |
| 4255 | transforms[i] = SkRSXform::Make(-c, -s, -s * 16, c * 16); |
| 4256 | angle += .45; |
| 4257 | scale += .2; |
| 4258 | alphabet[i] = 'A' + i; |
| 4259 | } |
| 4260 | SkPaint paint; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4261 | canvas->translate(110, 138); |
| 4262 | canvas->drawTextRSXform(alphabet, sizeof(alphabet), transforms, nullptr, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4263 | } |
| 4264 | ## |
| 4265 | |
Cary Clark | 153e76d | 2018-08-28 11:48:28 -0400 | [diff] [blame] | 4266 | #SeeAlso drawText drawPosText drawTextBlob |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4267 | |
| 4268 | ## |
| 4269 | |
| 4270 | # ------------------------------------------------------------------------------ |
| 4271 | |
| 4272 | #Method void drawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4273 | #In Draw_Text |
| 4274 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4275 | #Line # draws text with arrays of positions and Paint ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4276 | Draws Text_Blob blob at (x, y), using Clip, Matrix, and Paint paint. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4277 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4278 | blob contains Glyphs, their positions, and paint attributes specific to text: |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 4279 | #paint_font_metrics#. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4280 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 4281 | Paint_Text_Encoding must be set to SkPaint::kGlyphID_TextEncoding. |
| 4282 | |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 4283 | Elements of paint: Anti_Alias, Blend_Mode, Color including Color_Alpha, |
| 4284 | Color_Filter, Paint_Dither, Draw_Looper, Mask_Filter, Path_Effect, Shader, and |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 4285 | Paint_Style; apply to blob. If Paint contains SkPaint::kStroke_Style: |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 4286 | Paint_Miter_Limit, Paint_Stroke_Cap, Paint_Stroke_Join, and Paint_Stroke_Width; |
| 4287 | apply to Path created from blob. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4288 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4289 | #Param blob Glyphs, positions, and their paints' text size, typeface, and so on ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4290 | #Param x horizontal offset applied to blob ## |
| 4291 | #Param y vertical offset applied to blob ## |
| 4292 | #Param paint blend, color, stroking, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4293 | |
| 4294 | #Example |
| 4295 | #Height 120 |
Cary Clark | e80cd44 | 2018-07-17 13:19:56 -0400 | [diff] [blame] | 4296 | void draw(SkCanvas* canvas) { |
| 4297 | SkTextBlobBuilder textBlobBuilder; |
| 4298 | const char bunny[] = "/(^x^)\\"; |
| 4299 | const int len = sizeof(bunny) - 1; |
| 4300 | uint16_t glyphs[len]; |
| 4301 | SkPaint paint; |
| 4302 | paint.textToGlyphs(bunny, len, glyphs); |
| 4303 | paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 4304 | int runs[] = { 3, 1, 3 }; |
| 4305 | SkPoint textPos = { 20, 100 }; |
| 4306 | int glyphIndex = 0; |
| 4307 | for (auto runLen : runs) { |
| 4308 | paint.setTextSize(1 == runLen ? 20 : 50); |
| 4309 | const SkTextBlobBuilder::RunBuffer& run = |
| 4310 | textBlobBuilder.allocRun(paint, runLen, textPos.fX, textPos.fY); |
| 4311 | memcpy(run.glyphs, &glyphs[glyphIndex], sizeof(glyphs[0]) * runLen); |
| 4312 | textPos.fX += paint.measureText(&glyphs[glyphIndex], sizeof(glyphs[0]) * runLen, nullptr); |
| 4313 | glyphIndex += runLen; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4314 | } |
Cary Clark | e80cd44 | 2018-07-17 13:19:56 -0400 | [diff] [blame] | 4315 | sk_sp<const SkTextBlob> blob = textBlobBuilder.make(); |
| 4316 | paint.reset(); |
| 4317 | canvas->drawTextBlob(blob.get(), 0, 0, paint); |
| 4318 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4319 | ## |
| 4320 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4321 | #SeeAlso drawText drawPosText drawPosTextH |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4322 | |
| 4323 | ## |
| 4324 | |
| 4325 | # ------------------------------------------------------------------------------ |
| 4326 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4327 | #Method void drawTextBlob(const sk_sp<SkTextBlob>& blob, SkScalar x, SkScalar y, const SkPaint& paint) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4328 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4329 | Draws Text_Blob blob at (x, y), using Clip, Matrix, and Paint paint. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4330 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4331 | blob contains Glyphs, their positions, and paint attributes specific to text: |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 4332 | #paint_font_metrics#. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4333 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 4334 | Paint_Text_Encoding must be set to SkPaint::kGlyphID_TextEncoding. |
| 4335 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4336 | Elements of paint: Path_Effect, Mask_Filter, Shader, Color_Filter, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4337 | Image_Filter, and Draw_Looper; apply to blob. |
| 4338 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4339 | #Param blob Glyphs, positions, and their paints' text size, typeface, and so on ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4340 | #Param x horizontal offset applied to blob ## |
| 4341 | #Param y vertical offset applied to blob ## |
| 4342 | #Param paint blend, color, stroking, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4343 | |
| 4344 | #Example |
| 4345 | #Height 120 |
| 4346 | #Description |
| 4347 | Paint attributes unrelated to text, like color, have no effect on paint in allocated Text_Blob. |
| 4348 | Paint attributes related to text, like text size, have no effect on paint passed to drawTextBlob. |
| 4349 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4350 | void draw(SkCanvas* canvas) { |
| 4351 | SkTextBlobBuilder textBlobBuilder; |
| 4352 | SkPaint paint; |
| 4353 | paint.setTextSize(50); |
| 4354 | paint.setColor(SK_ColorRED); |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4355 | paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4356 | const SkTextBlobBuilder::RunBuffer& run = |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4357 | textBlobBuilder.allocRun(paint, 1, 20, 100); |
| 4358 | run.glyphs[0] = 20; |
| 4359 | sk_sp<const SkTextBlob> blob = textBlobBuilder.make(); |
| 4360 | paint.setTextSize(10); |
| 4361 | paint.setColor(SK_ColorBLUE); |
| 4362 | canvas->drawTextBlob(blob.get(), 0, 0, paint); |
| 4363 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4364 | ## |
| 4365 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4366 | #SeeAlso drawText drawPosText drawPosTextH |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4367 | |
| 4368 | ## |
| 4369 | |
| 4370 | # ------------------------------------------------------------------------------ |
| 4371 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4372 | #Method void drawPicture(const SkPicture* picture) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4373 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4374 | #Line # draws Picture using Clip and Matrix ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4375 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4376 | |
| 4377 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4378 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4379 | SkPictureRecorder recorder; |
| 4380 | SkCanvas* recordingCanvas = recorder.beginRecording(50, 50); |
| 4381 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) { |
| 4382 | SkPaint paint; |
| 4383 | paint.setColor(color); |
| 4384 | recordingCanvas->drawRect({10, 10, 30, 40}, paint); |
| 4385 | recordingCanvas->translate(10, 10); |
| 4386 | recordingCanvas->scale(1.2f, 1.4f); |
| 4387 | } |
| 4388 | sk_sp<SkPicture> playback = recorder.finishRecordingAsPicture(); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4389 | canvas->drawPicture(playback); |
| 4390 | canvas->scale(2, 2); |
| 4391 | canvas->translate(50, 0); |
| 4392 | canvas->drawPicture(playback); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4393 | } |
| 4394 | ## |
| 4395 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4396 | #SeeAlso drawDrawable SkPicture SkPicture::playback |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4397 | |
| 4398 | ## |
| 4399 | |
| 4400 | # ------------------------------------------------------------------------------ |
| 4401 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4402 | #Method void drawPicture(const sk_sp<SkPicture>& picture) |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4403 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4404 | |
| 4405 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4406 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4407 | SkPictureRecorder recorder; |
| 4408 | SkCanvas* recordingCanvas = recorder.beginRecording(50, 50); |
| 4409 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) { |
| 4410 | SkPaint paint; |
| 4411 | paint.setColor(color); |
| 4412 | recordingCanvas->drawRect({10, 10, 30, 40}, paint); |
| 4413 | recordingCanvas->translate(10, 10); |
| 4414 | recordingCanvas->scale(1.2f, 1.4f); |
| 4415 | } |
| 4416 | sk_sp<SkPicture> playback = recorder.finishRecordingAsPicture(); |
| 4417 | canvas->drawPicture(playback); |
| 4418 | canvas->scale(2, 2); |
| 4419 | canvas->translate(50, 0); |
| 4420 | canvas->drawPicture(playback); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4421 | } |
| 4422 | ## |
| 4423 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4424 | #SeeAlso drawDrawable SkPicture SkPicture::playback |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4425 | |
| 4426 | ## |
| 4427 | |
| 4428 | # ------------------------------------------------------------------------------ |
| 4429 | |
| 4430 | #Method void drawPicture(const SkPicture* picture, const SkMatrix* matrix, const SkPaint* paint) |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4431 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4432 | |
| 4433 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4434 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4435 | SkPaint paint; |
| 4436 | SkPictureRecorder recorder; |
| 4437 | SkCanvas* recordingCanvas = recorder.beginRecording(50, 50); |
| 4438 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) { |
| 4439 | paint.setColor(color); |
| 4440 | recordingCanvas->drawRect({10, 10, 30, 40}, paint); |
| 4441 | recordingCanvas->translate(10, 10); |
| 4442 | recordingCanvas->scale(1.2f, 1.4f); |
| 4443 | } |
| 4444 | sk_sp<SkPicture> playback = recorder.finishRecordingAsPicture(); |
| 4445 | const SkPicture* playbackPtr = playback.get(); |
| 4446 | SkMatrix matrix; |
| 4447 | matrix.reset(); |
| 4448 | for (auto alpha : { 70, 140, 210 } ) { |
| 4449 | paint.setAlpha(alpha); |
| 4450 | canvas->drawPicture(playbackPtr, &matrix, &paint); |
| 4451 | matrix.preTranslate(70, 70); |
| 4452 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4453 | } |
| 4454 | ## |
| 4455 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4456 | #SeeAlso drawDrawable SkPicture SkPicture::playback |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4457 | |
| 4458 | ## |
| 4459 | |
| 4460 | # ------------------------------------------------------------------------------ |
| 4461 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4462 | #Method void drawPicture(const sk_sp<SkPicture>& picture, const SkMatrix* matrix, const SkPaint* paint) |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4463 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4464 | |
| 4465 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4466 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4467 | SkPaint paint; |
| 4468 | SkPictureRecorder recorder; |
| 4469 | SkCanvas* recordingCanvas = recorder.beginRecording(50, 50); |
| 4470 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) { |
| 4471 | paint.setColor(color); |
| 4472 | recordingCanvas->drawRect({10, 10, 30, 40}, paint); |
| 4473 | recordingCanvas->translate(10, 10); |
| 4474 | recordingCanvas->scale(1.2f, 1.4f); |
| 4475 | } |
| 4476 | sk_sp<SkPicture> playback = recorder.finishRecordingAsPicture(); |
| 4477 | SkMatrix matrix; |
| 4478 | matrix.reset(); |
| 4479 | for (auto alpha : { 70, 140, 210 } ) { |
| 4480 | paint.setAlpha(alpha); |
| 4481 | canvas->drawPicture(playback, &matrix, &paint); |
| 4482 | matrix.preTranslate(70, 70); |
| 4483 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4484 | } |
| 4485 | ## |
| 4486 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4487 | #SeeAlso drawDrawable SkPicture SkPicture::playback |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4488 | |
| 4489 | ## |
| 4490 | |
| 4491 | # ------------------------------------------------------------------------------ |
| 4492 | |
| 4493 | #Method void drawVertices(const SkVertices* vertices, SkBlendMode mode, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4494 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4495 | #Line # draws Vertices, a triangle mesh ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4496 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4497 | |
| 4498 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4499 | void draw(SkCanvas* canvas) { |
| 4500 | SkPaint paint; |
| 4501 | SkPoint points[] = { { 0, 0 }, { 250, 0 }, { 100, 100 }, { 0, 250 } }; |
| 4502 | SkColor colors[] = { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorCYAN }; |
| 4503 | auto vertices = SkVertices::MakeCopy(SkVertices::kTriangleFan_VertexMode, |
| 4504 | SK_ARRAY_COUNT(points), points, nullptr, colors); |
| 4505 | canvas->drawVertices(vertices.get(), SkBlendMode::kSrc, paint); |
| 4506 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4507 | ## |
| 4508 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4509 | #SeeAlso drawPatch drawPicture |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4510 | |
| 4511 | ## |
| 4512 | |
| 4513 | # ------------------------------------------------------------------------------ |
| 4514 | |
| 4515 | #Method void drawVertices(const sk_sp<SkVertices>& vertices, SkBlendMode mode, const SkPaint& paint) |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4516 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4517 | |
| 4518 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4519 | void draw(SkCanvas* canvas) { |
| 4520 | SkPaint paint; |
| 4521 | SkPoint points[] = { { 0, 0 }, { 250, 0 }, { 100, 100 }, { 0, 250 } }; |
| 4522 | SkPoint texs[] = { { 0, 0 }, { 0, 250 }, { 250, 250 }, { 250, 0 } }; |
| 4523 | SkColor colors[] = { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorCYAN }; |
| 4524 | paint.setShader(SkGradientShader::MakeLinear(points, colors, nullptr, 4, |
| 4525 | SkShader::kClamp_TileMode)); |
| 4526 | auto vertices = SkVertices::MakeCopy(SkVertices::kTriangleFan_VertexMode, |
| 4527 | SK_ARRAY_COUNT(points), points, texs, colors); |
Ruiqi Mao | 94d57c4 | 2018-07-02 15:20:10 -0400 | [diff] [blame] | 4528 | canvas->drawVertices(vertices, SkBlendMode::kDarken, paint); |
| 4529 | } |
| 4530 | ## |
| 4531 | |
| 4532 | #SeeAlso drawPatch drawPicture |
| 4533 | |
| 4534 | ## |
| 4535 | |
| 4536 | # ------------------------------------------------------------------------------ |
| 4537 | |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 4538 | #Method void drawVertices(const SkVertices* vertices, const SkVertices::Bone bones[], |
| 4539 | int boneCount, SkBlendMode mode, const SkPaint& paint) |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4540 | #Populate |
Ruiqi Mao | 94d57c4 | 2018-07-02 15:20:10 -0400 | [diff] [blame] | 4541 | |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 4542 | #NoExample |
Ruiqi Mao | 94d57c4 | 2018-07-02 15:20:10 -0400 | [diff] [blame] | 4543 | void draw(SkCanvas* canvas) { |
| 4544 | SkPaint paint; |
| 4545 | SkPoint points[] = { { 0, 0 }, { 250, 0 }, { 100, 100 }, { 0, 250 } }; |
| 4546 | SkPoint texs[] = { { 0, 0 }, { 0, 250 }, { 250, 250 }, { 250, 0 } }; |
| 4547 | SkColor colors[] = { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorCYAN }; |
| 4548 | SkVertices::BoneIndices boneIndices[] = { { 0, 0, 0, 0 }, |
| 4549 | { 1, 0, 0, 0 }, |
| 4550 | { 2, 0, 0, 0 }, |
| 4551 | { 3, 0, 0, 0 } }; |
| 4552 | SkVertices::BoneWeights boneWeights[] = { { 0.0f, 0.0f, 0.0f, 0.0f }, |
| 4553 | { 1.0f, 0.0f, 0.0f, 0.0f }, |
| 4554 | { 1.0f, 0.0f, 0.0f, 0.0f }, |
| 4555 | { 1.0f, 0.0f, 0.0f, 0.0f } }; |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 4556 | SkVertices::Bone bones[] = { {{ 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f }}, |
| 4557 | {{ 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 20.0f }}, |
| 4558 | {{ 1.0f, 0.0f, 0.0f, 1.0f, 50.0f, 50.0f }}, |
| 4559 | {{ 1.0f, 0.0f, 0.0f, 1.0f, 20.0f, 0.0f }} }; |
Ruiqi Mao | 94d57c4 | 2018-07-02 15:20:10 -0400 | [diff] [blame] | 4560 | paint.setShader(SkGradientShader::MakeLinear(points, colors, nullptr, 4, |
| 4561 | SkShader::kClamp_TileMode)); |
| 4562 | auto vertices = SkVertices::MakeCopy(SkVertices::kTriangleFan_VertexMode, |
| 4563 | SK_ARRAY_COUNT(points), points, texs, colors, boneIndices, boneWeights); |
| 4564 | canvas->drawVertices(vertices.get(), bones, SK_ARRAY_COUNT(bones), SkBlendMode::kDarken, paint); |
| 4565 | } |
| 4566 | ## |
| 4567 | |
| 4568 | #SeeAlso drawPatch drawPicture |
| 4569 | |
| 4570 | ## |
| 4571 | |
| 4572 | # ------------------------------------------------------------------------------ |
| 4573 | |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 4574 | #Method void drawVertices(const sk_sp<SkVertices>& vertices, const SkVertices::Bone bones[], |
| 4575 | int boneCount, SkBlendMode mode, const SkPaint& paint) |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4576 | #Populate |
Ruiqi Mao | 94d57c4 | 2018-07-02 15:20:10 -0400 | [diff] [blame] | 4577 | |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 4578 | #NoExample |
Ruiqi Mao | 94d57c4 | 2018-07-02 15:20:10 -0400 | [diff] [blame] | 4579 | void draw(SkCanvas* canvas) { |
| 4580 | SkPaint paint; |
| 4581 | SkPoint points[] = { { 0, 0 }, { 250, 0 }, { 100, 100 }, { 0, 250 } }; |
| 4582 | SkPoint texs[] = { { 0, 0 }, { 0, 250 }, { 250, 250 }, { 250, 0 } }; |
| 4583 | SkColor colors[] = { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorCYAN }; |
| 4584 | SkVertices::BoneIndices boneIndices[] = { { 0, 0, 0, 0 }, |
| 4585 | { 1, 0, 0, 0 }, |
| 4586 | { 2, 0, 0, 0 }, |
| 4587 | { 3, 0, 0, 0 } }; |
| 4588 | SkVertices::BoneWeights boneWeights[] = { { 0.0f, 0.0f, 0.0f, 0.0f }, |
| 4589 | { 1.0f, 0.0f, 0.0f, 0.0f }, |
| 4590 | { 1.0f, 0.0f, 0.0f, 0.0f }, |
| 4591 | { 1.0f, 0.0f, 0.0f, 0.0f } }; |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 4592 | SkVertices::Bone bones[] = { {{ 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f }}, |
| 4593 | {{ 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 20.0f }}, |
| 4594 | {{ 1.0f, 0.0f, 0.0f, 1.0f, 50.0f, 50.0f }}, |
| 4595 | {{ 1.0f, 0.0f, 0.0f, 1.0f, 20.0f, 0.0f }} }; |
Ruiqi Mao | 94d57c4 | 2018-07-02 15:20:10 -0400 | [diff] [blame] | 4596 | paint.setShader(SkGradientShader::MakeLinear(points, colors, nullptr, 4, |
| 4597 | SkShader::kClamp_TileMode)); |
| 4598 | auto vertices = SkVertices::MakeCopy(SkVertices::kTriangleFan_VertexMode, |
| 4599 | SK_ARRAY_COUNT(points), points, texs, colors, boneIndices, boneWeights); |
| 4600 | canvas->drawVertices(vertices, bones, SK_ARRAY_COUNT(bones), SkBlendMode::kDarken, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4601 | } |
| 4602 | ## |
| 4603 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4604 | #SeeAlso drawPatch drawPicture |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4605 | |
| 4606 | ## |
| 4607 | |
| 4608 | # ------------------------------------------------------------------------------ |
| 4609 | |
| 4610 | #Method void drawPatch(const SkPoint cubics[12], const SkColor colors[4], |
| 4611 | const SkPoint texCoords[4], SkBlendMode mode, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4612 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4613 | #Line # draws Coons_Patch ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4614 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4615 | |
| 4616 | #Example |
| 4617 | #Image 5 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4618 | void draw(SkCanvas* canvas) { |
| 4619 | // SkBitmap source = cmbkygk; |
| 4620 | SkPaint paint; |
| 4621 | paint.setFilterQuality(kLow_SkFilterQuality); |
| 4622 | paint.setAntiAlias(true); |
| 4623 | SkPoint cubics[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, |
| 4624 | /* { 7, 3 }, */ { 6, 4 }, { 7, 5 }, { 5, 7 }, |
| 4625 | /* { 5, 7 }, */ { 4, 6 }, { 3, 7 }, { 1, 5 }, |
| 4626 | /* { 1, 5 }, */ { 2, 4 }, { 1, 3 }, /* { 3, 1 } */ }; |
| 4627 | SkColor colors[] = { 0xbfff0000, 0xbf0000ff, 0xbfff00ff, 0xbf00ffff }; |
| 4628 | SkPoint texCoords[] = { { -30, -30 }, { 162, -30}, { 162, 162}, { -30, 162} }; |
| 4629 | paint.setShader(SkShader::MakeBitmapShader(source, SkShader::kClamp_TileMode, |
| 4630 | SkShader::kClamp_TileMode, nullptr)); |
| 4631 | canvas->scale(15, 15); |
| 4632 | for (auto blend : { SkBlendMode::kSrcOver, SkBlendMode::kModulate, SkBlendMode::kXor } ) { |
| 4633 | canvas->drawPatch(cubics, colors, texCoords, blend, paint); |
| 4634 | canvas->translate(4, 4); |
| 4635 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4636 | } |
| 4637 | ## |
| 4638 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4639 | #ToDo can patch use image filter? ## |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 4640 | #SeeAlso drawVertices drawPicture |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4641 | |
| 4642 | ## |
| 4643 | |
| 4644 | # ------------------------------------------------------------------------------ |
| 4645 | |
| 4646 | #Method void drawPatch(const SkPoint cubics[12], const SkColor colors[4], |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4647 | const SkPoint texCoords[4], const SkPaint& paint) |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4648 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4649 | |
| 4650 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4651 | void draw(SkCanvas* canvas) { |
| 4652 | SkPaint paint; |
| 4653 | paint.setAntiAlias(true); |
| 4654 | SkPoint cubics[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, |
| 4655 | /* { 7, 3 }, */ { 6, 4 }, { 7, 5 }, { 5, 7 }, |
| 4656 | /* { 5, 7 }, */ { 4, 6 }, { 3, 7 }, { 1, 5 }, |
| 4657 | /* { 1, 5 }, */ { 2, 4 }, { 1, 3 }, /* { 3, 1 } */ }; |
| 4658 | SkColor colors[] = { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorCYAN }; |
| 4659 | canvas->scale(30, 30); |
| 4660 | canvas->drawPatch(cubics, colors, nullptr, paint); |
| 4661 | SkPoint text[] = { {3,0.9f}, {4,2.5f}, {5,0.9f}, {7.5f,3.2f}, {5.5f,4.2f}, |
| 4662 | {7.5f,5.2f}, {5,7.5f}, {4,5.9f}, {3,7.5f}, {0.5f,5.2f}, {2.5f,4.2f}, |
| 4663 | {0.5f,3.2f} }; |
| 4664 | paint.setTextSize(18.f / 30); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4665 | for (int i = 0; i< 10; ++i) { |
| 4666 | char digit = '0' + i; |
| 4667 | canvas->drawText(&digit, 1, text[i].fX, text[i].fY, paint); |
| 4668 | } |
| 4669 | canvas->drawString("10", text[10].fX, text[10].fY, paint); |
| 4670 | canvas->drawString("11", text[11].fX, text[11].fY, paint); |
| 4671 | paint.setStyle(SkPaint::kStroke_Style); |
| 4672 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, 12, cubics, paint); |
| 4673 | canvas->drawLine(cubics[11].fX, cubics[11].fY, cubics[0].fX, cubics[0].fY, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4674 | } |
| 4675 | ## |
| 4676 | |
| 4677 | #Example |
| 4678 | #Image 6 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4679 | void draw(SkCanvas* canvas) { |
| 4680 | // SkBitmap source = checkerboard; |
| 4681 | SkPaint paint; |
| 4682 | paint.setFilterQuality(kLow_SkFilterQuality); |
| 4683 | paint.setAntiAlias(true); |
| 4684 | SkPoint cubics[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, |
| 4685 | /* { 7, 3 }, */ { 6, 4 }, { 7, 5 }, { 5, 7 }, |
| 4686 | /* { 5, 7 }, */ { 4, 6 }, { 3, 7 }, { 1, 5 }, |
| 4687 | /* { 1, 5 }, */ { 2, 4 }, { 1, 3 }, /* { 3, 1 } */ }; |
| 4688 | SkPoint texCoords[] = { { 0, 0 }, { 0, 62}, { 62, 62}, { 62, 0 } }; |
| 4689 | paint.setShader(SkShader::MakeBitmapShader(source, SkShader::kClamp_TileMode, |
| 4690 | SkShader::kClamp_TileMode, nullptr)); |
| 4691 | canvas->scale(30, 30); |
| 4692 | canvas->drawPatch(cubics, nullptr, texCoords, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4693 | } |
| 4694 | ## |
| 4695 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4696 | #ToDo can patch use image filter? ## |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 4697 | #SeeAlso drawVertices drawPicture |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4698 | |
| 4699 | ## |
| 4700 | |
| 4701 | # ------------------------------------------------------------------------------ |
| 4702 | |
| 4703 | #Method void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], |
| 4704 | const SkColor colors[], int count, SkBlendMode mode, const SkRect* cullRect, |
| 4705 | const SkPaint* paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4706 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4707 | #Line # draws sprites using Clip, Matrix, and Paint ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4708 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4709 | |
| 4710 | #Example |
| 4711 | #Image 3 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4712 | void draw(SkCanvas* canvas) { |
| 4713 | // SkBitmap source = mandrill; |
| 4714 | SkRSXform xforms[] = { { .5f, 0, 0, 0 }, {0, .5f, 200, 100 } }; |
| 4715 | SkRect tex[] = { { 0, 0, 250, 250 }, { 0, 0, 250, 250 } }; |
| 4716 | SkColor colors[] = { 0x7f55aa00, 0x7f3333bf }; |
| 4717 | const SkImage* imagePtr = image.get(); |
| 4718 | canvas->drawAtlas(imagePtr, xforms, tex, colors, 2, SkBlendMode::kSrcOver, nullptr, nullptr); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4719 | } |
| 4720 | ## |
| 4721 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4722 | #SeeAlso drawBitmap drawImage |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4723 | |
| 4724 | ## |
| 4725 | |
| 4726 | # ------------------------------------------------------------------------------ |
| 4727 | |
| 4728 | #Method void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[], |
| 4729 | const SkColor colors[], int count, SkBlendMode mode, const SkRect* cullRect, |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4730 | const SkPaint* paint) |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4731 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4732 | |
| 4733 | #Example |
| 4734 | #Image 3 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4735 | void draw(SkCanvas* canvas) { |
| 4736 | // SkBitmap source = mandrill; |
| 4737 | SkRSXform xforms[] = { { .5f, 0, 0, 0 }, {0, .5f, 200, 100 } }; |
| 4738 | SkRect tex[] = { { 0, 0, 250, 250 }, { 0, 0, 250, 250 } }; |
| 4739 | SkColor colors[] = { 0x7f55aa00, 0x7f3333bf }; |
| 4740 | SkPaint paint; |
| 4741 | paint.setAlpha(127); |
| 4742 | canvas->drawAtlas(image, xforms, tex, colors, 2, SkBlendMode::kPlus, nullptr, &paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4743 | } |
| 4744 | ## |
| 4745 | |
| 4746 | #ToDo bug in example on cpu side, gpu looks ok ## |
| 4747 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4748 | #SeeAlso drawBitmap drawImage |
| 4749 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4750 | ## |
| 4751 | |
| 4752 | # ------------------------------------------------------------------------------ |
| 4753 | |
| 4754 | #Method void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], int count, |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4755 | const SkRect* cullRect, const SkPaint* paint) |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4756 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4757 | |
| 4758 | #Example |
| 4759 | #Image 3 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4760 | void draw(SkCanvas* canvas) { |
| 4761 | // sk_sp<SkImage> image = mandrill; |
| 4762 | SkRSXform xforms[] = { { .5f, 0, 0, 0 }, {0, .5f, 200, 100 } }; |
| 4763 | SkRect tex[] = { { 0, 0, 250, 250 }, { 0, 0, 250, 250 } }; |
| 4764 | const SkImage* imagePtr = image.get(); |
| 4765 | canvas->drawAtlas(imagePtr, xforms, tex, 2, nullptr, nullptr); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4766 | } |
| 4767 | ## |
| 4768 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4769 | #SeeAlso drawBitmap drawImage |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4770 | |
| 4771 | ## |
| 4772 | |
| 4773 | # ------------------------------------------------------------------------------ |
| 4774 | |
| 4775 | #Method void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[], |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4776 | int count, const SkRect* cullRect, const SkPaint* paint) |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4777 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4778 | |
| 4779 | #Example |
| 4780 | #Image 3 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4781 | void draw(SkCanvas* canvas) { |
| 4782 | // sk_sp<SkImage> image = mandrill; |
| 4783 | SkRSXform xforms[] = { { 1, 0, 0, 0 }, {0, 1, 300, 100 } }; |
| 4784 | SkRect tex[] = { { 0, 0, 200, 200 }, { 200, 0, 400, 200 } }; |
| 4785 | canvas->drawAtlas(image, xforms, tex, 2, nullptr, nullptr); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4786 | } |
| 4787 | ## |
| 4788 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4789 | #SeeAlso drawBitmap drawImage |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4790 | |
| 4791 | ## |
| 4792 | |
| 4793 | # ------------------------------------------------------------------------------ |
| 4794 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4795 | #Method void drawDrawable(SkDrawable* drawable, const SkMatrix* matrix = nullptr) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4796 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4797 | #Line # draws Drawable, encapsulated drawing commands ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4798 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4799 | |
| 4800 | #Example |
| 4801 | #Height 100 |
| 4802 | #Function |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4803 | struct MyDrawable : public SkDrawable { |
| 4804 | SkRect onGetBounds() override { return SkRect::MakeWH(50, 100); } |
| 4805 | |
| 4806 | void onDraw(SkCanvas* canvas) override { |
| 4807 | SkPath path; |
| 4808 | path.conicTo(10, 90, 50, 90, 0.9f); |
| 4809 | SkPaint paint; |
| 4810 | paint.setColor(SK_ColorBLUE); |
| 4811 | canvas->drawRect(path.getBounds(), paint); |
| 4812 | paint.setAntiAlias(true); |
| 4813 | paint.setColor(SK_ColorWHITE); |
| 4814 | canvas->drawPath(path, paint); |
| 4815 | } |
| 4816 | }; |
| 4817 | |
| 4818 | #Function ## |
| 4819 | void draw(SkCanvas* canvas) { |
| 4820 | sk_sp<SkDrawable> drawable(new MyDrawable); |
| 4821 | SkMatrix matrix; |
| 4822 | matrix.setTranslate(10, 10); |
| 4823 | canvas->drawDrawable(drawable.get(), &matrix); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4824 | } |
| 4825 | ## |
| 4826 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4827 | #SeeAlso SkDrawable drawPicture |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4828 | |
| 4829 | ## |
| 4830 | |
| 4831 | # ------------------------------------------------------------------------------ |
| 4832 | |
| 4833 | #Method void drawDrawable(SkDrawable* drawable, SkScalar x, SkScalar y) |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4834 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4835 | |
| 4836 | #Example |
| 4837 | #Height 100 |
| 4838 | #Function |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4839 | struct MyDrawable : public SkDrawable { |
| 4840 | SkRect onGetBounds() override { return SkRect::MakeWH(50, 100); } |
| 4841 | |
| 4842 | void onDraw(SkCanvas* canvas) override { |
| 4843 | SkPath path; |
| 4844 | path.conicTo(10, 90, 50, 90, 0.9f); |
| 4845 | SkPaint paint; |
| 4846 | paint.setColor(SK_ColorBLUE); |
| 4847 | canvas->drawRect(path.getBounds(), paint); |
| 4848 | paint.setAntiAlias(true); |
| 4849 | paint.setColor(SK_ColorWHITE); |
| 4850 | canvas->drawPath(path, paint); |
| 4851 | } |
| 4852 | }; |
| 4853 | |
| 4854 | #Function ## |
| 4855 | void draw(SkCanvas* canvas) { |
| 4856 | sk_sp<SkDrawable> drawable(new MyDrawable); |
| 4857 | canvas->drawDrawable(drawable.get(), 10, 10); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4858 | } |
| 4859 | ## |
| 4860 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4861 | #SeeAlso SkDrawable drawPicture |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4862 | |
| 4863 | ## |
| 4864 | |
| 4865 | # ------------------------------------------------------------------------------ |
| 4866 | |
| 4867 | #Method void drawAnnotation(const SkRect& rect, const char key[], SkData* value) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4868 | #In Draw |
| 4869 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4870 | #Line # associates a Rect with a key-value pair ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4871 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4872 | |
| 4873 | #Example |
| 4874 | #Height 1 |
| 4875 | const char text[] = "Click this link!"; |
| 4876 | SkRect bounds; |
| 4877 | SkPaint paint; |
| 4878 | paint.setTextSize(40); |
| 4879 | (void)paint.measureText(text, strlen(text), &bounds); |
| 4880 | const char url[] = "https://www.google.com/"; |
| 4881 | sk_sp<SkData> urlData(SkData::MakeWithCString(url)); |
| 4882 | canvas->drawAnnotation(bounds, "url_key", urlData.get()); |
| 4883 | ## |
| 4884 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4885 | #SeeAlso SkPicture SkDocument |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4886 | |
| 4887 | ## |
| 4888 | |
| 4889 | # ------------------------------------------------------------------------------ |
| 4890 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4891 | #Method void drawAnnotation(const SkRect& rect, const char key[], const sk_sp<SkData>& value) |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4892 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4893 | |
| 4894 | #Example |
| 4895 | #Height 1 |
| 4896 | const char text[] = "Click this link!"; |
| 4897 | SkRect bounds; |
| 4898 | SkPaint paint; |
| 4899 | paint.setTextSize(40); |
| 4900 | (void)paint.measureText(text, strlen(text), &bounds); |
| 4901 | const char url[] = "https://www.google.com/"; |
| 4902 | sk_sp<SkData> urlData(SkData::MakeWithCString(url)); |
| 4903 | canvas->drawAnnotation(bounds, "url_key", urlData.get()); |
| 4904 | ## |
| 4905 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4906 | #SeeAlso SkPicture SkDocument |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4907 | |
| 4908 | ## |
| 4909 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4910 | # ------------------------------------------------------------------------------ |
| 4911 | |
| 4912 | #Method virtual bool isClipEmpty() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4913 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4914 | #Line # returns if Clip is empty ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4915 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4916 | |
| 4917 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4918 | void draw(SkCanvas* canvas) { |
| 4919 | SkDebugf("clip is%s empty\n", canvas->isClipEmpty() ? "" : " not"); |
| 4920 | SkPath path; |
| 4921 | canvas->clipPath(path); |
| 4922 | SkDebugf("clip is%s empty\n", canvas->isClipEmpty() ? "" : " not"); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4923 | } |
| 4924 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4925 | clip is not empty |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4926 | clip is empty |
| 4927 | ## |
| 4928 | ## |
| 4929 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4930 | #SeeAlso isClipRect getLocalClipBounds getDeviceClipBounds |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4931 | |
| 4932 | ## |
| 4933 | |
| 4934 | # ------------------------------------------------------------------------------ |
| 4935 | |
| 4936 | #Method virtual bool isClipRect() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4937 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4938 | #Line # returns if Clip is Rect and not empty ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4939 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4940 | |
| 4941 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4942 | void draw(SkCanvas* canvas) { |
| 4943 | SkDebugf("clip is%s rect\n", canvas->isClipRect() ? "" : " not"); |
| 4944 | canvas->clipRect({0, 0, 0, 0}); |
| 4945 | SkDebugf("clip is%s rect\n", canvas->isClipRect() ? "" : " not"); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4946 | } |
| 4947 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4948 | clip is rect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4949 | clip is not rect |
| 4950 | ## |
| 4951 | ## |
| 4952 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4953 | #SeeAlso isClipEmpty getLocalClipBounds getDeviceClipBounds |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4954 | |
| 4955 | ## |
| 4956 | |
| 4957 | #Class SkCanvas ## |
Cary Clark | 884dd7d | 2017-10-11 10:37:52 -0400 | [diff] [blame] | 4958 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4959 | #Topic Canvas ## |