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 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 192 | #Method explicit SkCanvas(const SkBitmap& bitmap) |
| 193 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 194 | #Line # uses existing Bitmap ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 195 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 196 | |
| 197 | #Example |
| 198 | #Description |
| 199 | The actual output depends on the installed fonts. |
| 200 | ## |
| 201 | SkBitmap bitmap; |
| 202 | // create a bitmap 5 wide and 11 high |
| 203 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(5, 11)); |
| 204 | SkCanvas canvas(bitmap); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 205 | canvas.clear(SK_ColorWHITE); // white is Unpremultiplied, in ARGB order |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 206 | SkPixmap pixmap; // provides guaranteed access to the drawn pixels |
| 207 | if (!canvas.peekPixels(&pixmap)) { |
| 208 | SkDebugf("peekPixels should never fail.\n"); |
| 209 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 210 | const SkPMColor* pixels = pixmap.addr32(); // points to top-left of bitmap |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 211 | SkPMColor pmWhite = pixels[0]; // the Premultiplied format may vary |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 212 | SkPaint paint; // by default, draws black, 12 point text |
Mike Reed | 33535cb | 2019-01-09 11:25:18 -0500 | [diff] [blame] | 213 | canvas.drawString("!", 1, 10, SkFont(), paint); // 1 char at baseline (1, 10) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 214 | for (int y = 0; y < bitmap.height(); ++y) { |
| 215 | for (int x = 0; x < bitmap.width(); ++x) { |
| 216 | SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x'); |
| 217 | } |
| 218 | SkDebugf("\n"); |
| 219 | } |
| 220 | |
| 221 | #StdOut |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 222 | ----- |
| 223 | ---x- |
| 224 | ---x- |
| 225 | ---x- |
| 226 | ---x- |
| 227 | ---x- |
| 228 | ---x- |
| 229 | ----- |
| 230 | ---x- |
| 231 | ---x- |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 232 | ----- |
| 233 | #StdOut ## |
| 234 | ## |
| 235 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 236 | #SeeAlso MakeRasterDirect SkRasterHandleAllocator::MakeCanvas SkSurface::getCanvas SkCreateColorSpaceXformCanvas |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 237 | |
| 238 | ## |
| 239 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 240 | # ------------------------------------------------------------------------------ |
| 241 | |
| 242 | #Method SkCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props) |
| 243 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 244 | #Line # uses existing Bitmap and Surface_Properties ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 245 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 246 | |
| 247 | #Example |
| 248 | #Description |
| 249 | The actual output depends on the installed fonts. |
| 250 | ## |
| 251 | SkBitmap bitmap; |
| 252 | // create a bitmap 5 wide and 11 high |
| 253 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(5, 11)); |
| 254 | SkCanvas canvas(bitmap, SkSurfaceProps(0, kUnknown_SkPixelGeometry)); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 255 | canvas.clear(SK_ColorWHITE); // white is Unpremultiplied, in ARGB order |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 256 | SkPixmap pixmap; // provides guaranteed access to the drawn pixels |
| 257 | if (!canvas.peekPixels(&pixmap)) { |
| 258 | SkDebugf("peekPixels should never fail.\n"); |
| 259 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 260 | const SkPMColor* pixels = pixmap.addr32(); // points to top-left of bitmap |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 261 | SkPMColor pmWhite = pixels[0]; // the Premultiplied format may vary |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 262 | SkPaint paint; // by default, draws black, 12 point text |
Mike Reed | 33535cb | 2019-01-09 11:25:18 -0500 | [diff] [blame] | 263 | canvas.drawString("!", 1, 10, SkFont(), paint); // 1 char at baseline (1, 10) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 264 | for (int y = 0; y < bitmap.height(); ++y) { |
| 265 | for (int x = 0; x < bitmap.width(); ++x) { |
| 266 | SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x'); |
| 267 | } |
| 268 | SkDebugf("\n"); |
| 269 | } |
| 270 | |
| 271 | #StdOut |
| 272 | ----- |
| 273 | ---x- |
| 274 | ---x- |
| 275 | ---x- |
| 276 | ---x- |
| 277 | ---x- |
| 278 | ---x- |
| 279 | ----- |
| 280 | ---x- |
| 281 | ---x- |
| 282 | ----- |
| 283 | #StdOut ## |
| 284 | ## |
| 285 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 286 | #SeeAlso MakeRasterDirect SkRasterHandleAllocator::MakeCanvas SkSurface::getCanvas SkCreateColorSpaceXformCanvas |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 287 | |
| 288 | ## |
| 289 | |
| 290 | # ------------------------------------------------------------------------------ |
| 291 | |
| 292 | #Method virtual ~SkCanvas() |
| 293 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 294 | #Line # draws saved Layers, frees resources ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 295 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 296 | |
| 297 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 298 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 299 | Canvas Layer draws into bitmap. saveLayerAlpha sets up an additional |
| 300 | drawing surface that blends with the bitmap. When Layer goes out of |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 301 | scope, Layer destructor is called. The saved Layer is restored, drawing |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 302 | transparent letters. |
| 303 | ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 304 | void draw(SkCanvas* canvas) { |
| 305 | SkBitmap bitmap; |
| 306 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(200, 200)); |
| 307 | { |
| 308 | SkCanvas offscreen(bitmap); |
| 309 | SkPaint paint; |
Mike Reed | 33535cb | 2019-01-09 11:25:18 -0500 | [diff] [blame] | 310 | SkFont font(nullptr, 100); |
| 311 | offscreen.drawString("ABC", 20, 160, font, paint); |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 312 | SkRect layerBounds = SkRect::MakeXYWH(32, 32, 192, 192); |
| 313 | offscreen.saveLayerAlpha(&layerBounds, 128); |
| 314 | offscreen.clear(SK_ColorWHITE); |
Mike Reed | 33535cb | 2019-01-09 11:25:18 -0500 | [diff] [blame] | 315 | offscreen.drawString("DEF", 20, 160, font, paint); |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 316 | } |
| 317 | canvas->drawBitmap(bitmap, 0, 0, nullptr); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 318 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 319 | ## |
| 320 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 321 | #SeeAlso State_Stack |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 322 | |
| 323 | ## |
| 324 | |
| 325 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 326 | #Subtopic Property |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 327 | #Line # metrics and attributes ## |
| 328 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 329 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 330 | #Method SkImageInfo imageInfo() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 331 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 332 | #Line # returns Image_Info for Canvas ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 333 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 334 | |
| 335 | #Example |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 336 | SkCanvas emptyCanvas; |
| 337 | SkImageInfo canvasInfo = emptyCanvas.imageInfo(); |
| 338 | SkImageInfo emptyInfo; |
| 339 | SkDebugf("emptyInfo %c= canvasInfo\n", emptyInfo == canvasInfo ? '=' : '!'); |
| 340 | |
| 341 | #StdOut |
| 342 | emptyInfo == canvasInfo |
| 343 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 344 | ## |
| 345 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 346 | #SeeAlso SkImageInfo MakeRasterDirect makeSurface |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 347 | |
| 348 | ## |
| 349 | |
| 350 | # ------------------------------------------------------------------------------ |
| 351 | |
| 352 | #Method bool getProps(SkSurfaceProps* props) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 353 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 354 | #Line # copies Surface_Properties if available ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 355 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 356 | |
| 357 | #Example |
| 358 | SkBitmap bitmap; |
| 359 | SkCanvas canvas(bitmap, SkSurfaceProps(0, kRGB_V_SkPixelGeometry)); |
| 360 | SkSurfaceProps surfaceProps(0, kUnknown_SkPixelGeometry); |
| 361 | SkDebugf("isRGB:%d\n", SkPixelGeometryIsRGB(surfaceProps.pixelGeometry())); |
| 362 | if (!canvas.getProps(&surfaceProps)) { |
| 363 | SkDebugf("getProps failed unexpectedly.\n"); |
| 364 | } |
| 365 | SkDebugf("isRGB:%d\n", SkPixelGeometryIsRGB(surfaceProps.pixelGeometry())); |
| 366 | |
| 367 | #StdOut |
| 368 | isRGB:0 |
| 369 | isRGB:1 |
| 370 | #StdOut ## |
| 371 | ## |
| 372 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 373 | #SeeAlso SkSurfaceProps makeSurface |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 374 | |
| 375 | ## |
| 376 | |
| 377 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 378 | #Subtopic Utility |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 379 | #Line # rarely called management functions ## |
| 380 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 381 | |
| 382 | #Method void flush() |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 383 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 384 | #Line # triggers execution of all pending draw operations ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 385 | #Populate |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 386 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 387 | #NoExample |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 388 | ## |
| 389 | |
Cary Clark | abaffd8 | 2018-11-15 08:25:12 -0500 | [diff] [blame] | 390 | #SeeAlso peekPixels SkSurface::flush GrContext::flush GrContext::abandonContext |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 391 | |
| 392 | ## |
| 393 | |
| 394 | # ------------------------------------------------------------------------------ |
| 395 | |
| 396 | #Method virtual SkISize getBaseLayerSize() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 397 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 398 | #Line # returns size of base Layer in global coordinates ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 399 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 400 | |
| 401 | #Example |
| 402 | SkBitmap bitmap; |
| 403 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(20, 30)); |
| 404 | SkCanvas canvas(bitmap, SkSurfaceProps(0, kUnknown_SkPixelGeometry)); |
| 405 | canvas.clipRect(SkRect::MakeWH(10, 40)); |
| 406 | SkIRect clipDeviceBounds = canvas.getDeviceClipBounds(); |
| 407 | if (clipDeviceBounds.isEmpty()) { |
| 408 | SkDebugf("Empty clip bounds is unexpected!\n"); |
| 409 | } |
| 410 | SkDebugf("clip=%d,%d\n", clipDeviceBounds.width(), clipDeviceBounds.height()); |
| 411 | SkISize baseLayerSize = canvas.getBaseLayerSize(); |
| 412 | SkDebugf("size=%d,%d\n", baseLayerSize.width(), baseLayerSize.height()); |
| 413 | |
| 414 | #StdOut |
| 415 | clip=10,30 |
| 416 | size=20,30 |
| 417 | ## |
| 418 | ## |
| 419 | |
| 420 | #ToDo is this the same as the width and height of surface? ## |
| 421 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 422 | #SeeAlso getDeviceClipBounds |
| 423 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 424 | ## |
| 425 | |
| 426 | # ------------------------------------------------------------------------------ |
| 427 | |
| 428 | #Method sk_sp<SkSurface> makeSurface(const SkImageInfo& info, const SkSurfaceProps* props = nullptr) |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 429 | #In Constructors |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 430 | #Line # creates Surface matching SkImageInfo and SkSurfaceProps ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 431 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 432 | |
| 433 | #Example |
| 434 | sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(5, 6); |
| 435 | SkCanvas* smallCanvas = surface->getCanvas(); |
| 436 | SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(3, 4); |
| 437 | sk_sp<SkSurface> compatible = smallCanvas->makeSurface(imageInfo); |
| 438 | SkDebugf("compatible %c= nullptr\n", compatible == nullptr ? '=' : '!'); |
| 439 | SkDebugf("size = %d, %d\n", compatible->width(), compatible->height()); |
| 440 | |
| 441 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 442 | compatible != nullptr |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 443 | size = 3, 4 |
| 444 | ## |
| 445 | ## |
| 446 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 447 | #SeeAlso SkSurface SkSurface::makeSurface SkImageInfo SkSurfaceProps |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 448 | |
| 449 | ## |
| 450 | |
| 451 | # ------------------------------------------------------------------------------ |
| 452 | |
| 453 | #Method virtual GrContext* getGrContext() |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 454 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 455 | #Line # returns GPU_Context of the GPU_Surface ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 456 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 457 | |
| 458 | #Example |
| 459 | void draw(SkCanvas* canvas) { |
| 460 | if (canvas->getGrContext()) { |
| 461 | canvas->clear(SK_ColorRED); |
| 462 | } else { |
| 463 | canvas->clear(SK_ColorBLUE); |
| 464 | } |
| 465 | } |
| 466 | ## |
| 467 | |
| 468 | #ToDo fiddle should show both CPU and GPU out ## |
| 469 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 470 | #SeeAlso GrContext |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 471 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 472 | ## |
| 473 | |
| 474 | # ------------------------------------------------------------------------------ |
| 475 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 476 | #Method void* accessTopLayerPixels(SkImageInfo* info, size_t* rowBytes, SkIPoint* origin = nullptr) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 477 | #In Utility |
| 478 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 479 | #Line # returns writable pixel access if available ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 480 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 481 | |
| 482 | #Example |
| 483 | void draw(SkCanvas* canvas) { |
| 484 | if (canvas->accessTopLayerPixels(nullptr, nullptr)) { |
| 485 | canvas->clear(SK_ColorRED); |
| 486 | } else { |
| 487 | canvas->clear(SK_ColorBLUE); |
| 488 | } |
| 489 | } |
| 490 | ## |
| 491 | |
| 492 | #Example |
| 493 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 494 | Draws "ABC" on the device. Then draws "DEF" in Layer, and reads |
| 495 | Layer to add a large dotted "DEF". Finally blends Layer with the |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 496 | device. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 497 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 498 | 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] | 499 | "DEF" appear only on the CPU. |
| 500 | ## |
| 501 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 502 | SkPaint paint; |
Mike Reed | 33535cb | 2019-01-09 11:25:18 -0500 | [diff] [blame] | 503 | SkFont font(nullptr, 100); |
| 504 | canvas->drawString("ABC", 20, 160, font, paint); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 505 | SkRect layerBounds = SkRect::MakeXYWH(32, 32, 192, 192); |
| 506 | canvas->saveLayerAlpha(&layerBounds, 128); |
| 507 | canvas->clear(SK_ColorWHITE); |
Mike Reed | 33535cb | 2019-01-09 11:25:18 -0500 | [diff] [blame] | 508 | canvas->drawString("DEF", 20, 160, font, paint); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 509 | SkImageInfo imageInfo; |
| 510 | size_t rowBytes; |
| 511 | SkIPoint origin; |
| 512 | uint32_t* access = (uint32_t*) canvas->accessTopLayerPixels(&imageInfo, &rowBytes, &origin); |
| 513 | if (access) { |
| 514 | int h = imageInfo.height(); |
| 515 | int v = imageInfo.width(); |
| 516 | int rowWords = rowBytes / sizeof(uint32_t); |
| 517 | for (int y = 0; y < h; ++y) { |
| 518 | int newY = (y - h / 2) * 2 + h / 2; |
| 519 | if (newY < 0 || newY >= h) { |
| 520 | continue; |
| 521 | } |
| 522 | for (int x = 0; x < v; ++x) { |
| 523 | int newX = (x - v / 2) * 2 + v / 2; |
| 524 | if (newX < 0 || newX >= v) { |
| 525 | continue; |
| 526 | } |
| 527 | if (access[y * rowWords + x] == SK_ColorBLACK) { |
| 528 | access[newY * rowWords + newX] = SK_ColorGRAY; |
| 529 | } |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 534 | canvas->restore(); |
| 535 | } |
| 536 | ## |
| 537 | |
| 538 | #ToDo there are no callers of this that I can find. Deprecate? ## |
| 539 | #ToDo fiddle should show both CPU and GPU out ## |
| 540 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 541 | #SeeAlso SkImageInfo SkPixmap |
| 542 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 543 | ## |
| 544 | |
| 545 | # ------------------------------------------------------------------------------ |
| 546 | |
| 547 | #Method SkRasterHandleAllocator::Handle accessTopRasterHandle() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 548 | #In Utility |
| 549 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 550 | #Line # returns context that tracks Clip and Matrix ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 551 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 552 | |
| 553 | #Example |
| 554 | #Description |
| 555 | #ToDo ## |
| 556 | ## |
| 557 | #Function |
| 558 | static void DeleteCallback(void*, void* context) { |
| 559 | delete (char*) context; |
| 560 | } |
| 561 | |
| 562 | class CustomAllocator : public SkRasterHandleAllocator { |
| 563 | public: |
| 564 | bool allocHandle(const SkImageInfo& info, Rec* rec) override { |
| 565 | char* context = new char[4]{'s', 'k', 'i', 'a'}; |
| 566 | rec->fReleaseProc = DeleteCallback; |
| 567 | rec->fReleaseCtx = context; |
| 568 | rec->fHandle = context; |
| 569 | rec->fPixels = context; |
| 570 | rec->fRowBytes = 4; |
| 571 | return true; |
| 572 | } |
| 573 | |
| 574 | void updateHandle(Handle handle, const SkMatrix& ctm, const SkIRect& clip_bounds) override { |
| 575 | // apply canvas matrix and clip to custom environment |
| 576 | } |
| 577 | }; |
| 578 | |
| 579 | ## |
| 580 | void draw(SkCanvas* canvas) { |
| 581 | const SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1); |
| 582 | std::unique_ptr<SkCanvas> c2 = |
| 583 | SkRasterHandleAllocator::MakeCanvas(std::unique_ptr<CustomAllocator>( |
| 584 | new CustomAllocator()), info); |
| 585 | char* context = (char*) c2->accessTopRasterHandle(); |
| 586 | SkDebugf("context = %.4s\n", context); |
| 587 | |
| 588 | } |
| 589 | #StdOut |
| 590 | context = skia |
| 591 | ## |
| 592 | #ToDo skstd::make_unique could not be used because def is private -- note to fix in c++14? ## |
| 593 | ## |
| 594 | |
| 595 | #SeeAlso SkRasterHandleAllocator |
| 596 | |
| 597 | ## |
| 598 | |
| 599 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 600 | #Subtopic Pixels |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 601 | #Line # read and write pixel values ## |
| 602 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 603 | |
| 604 | #Method bool peekPixels(SkPixmap* pixmap) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 605 | #In Pixels |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 606 | #Line # returns if Canvas has direct access to its pixels ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 607 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 608 | |
| 609 | #Example |
| 610 | SkPixmap pixmap; |
| 611 | if (canvas->peekPixels(&pixmap)) { |
| 612 | SkDebugf("width=%d height=%d\n", pixmap.bounds().width(), pixmap.bounds().height()); |
| 613 | } |
| 614 | #StdOut |
| 615 | width=256 height=256 |
| 616 | ## |
| 617 | ## |
| 618 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 619 | #SeeAlso readPixels SkBitmap::peekPixels SkImage::peekPixels SkSurface::peekPixels |
| 620 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 621 | ## |
| 622 | |
| 623 | # ------------------------------------------------------------------------------ |
| 624 | |
| 625 | #Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, |
| 626 | int srcX, int srcY) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 627 | #In Pixels |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 628 | #Line # copies and converts rectangle of pixels from Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 629 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 630 | Copies Rect of pixels from Canvas into dstPixels. Matrix and Clip are |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 631 | ignored. |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 632 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 633 | Source Rect corners are (srcX, srcY) and (imageInfo().width(), imageInfo().height()). |
| 634 | Destination Rect corners are (0, 0) and (dstInfo.width(), dstInfo.height()). |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 635 | Copies each readable pixel intersecting both rectangles, without scaling, |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 636 | converting to dstInfo.colorType() and dstInfo.alphaType() if required. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 637 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 638 | Pixels are readable when Device is raster, or backed by a GPU. |
| 639 | Pixels are not readable when SkCanvas is returned by SkDocument::beginPage, |
| 640 | returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility |
Brian Osman | 46fe9c7 | 2018-03-09 15:44:34 -0500 | [diff] [blame] | 641 | class like SkDebugCanvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 642 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 643 | The destination pixel storage must be allocated by the caller. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 644 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 645 | Pixel values are converted only if Color_Type and Alpha_Type |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 646 | do not match. Only pixels within both source and destination rectangles |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 647 | are copied. dstPixels contents outside Rect intersection are unchanged. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 648 | |
| 649 | 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] | 650 | |
| 651 | Does not copy, and returns false if: |
| 652 | |
| 653 | #List |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 654 | # Source and destination rectangles do not intersect. ## |
| 655 | # Canvas pixels could not be converted to dstInfo.colorType() or dstInfo.alphaType(). ## |
| 656 | # Canvas pixels are not readable; for instance, Canvas is document-based. ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 657 | # dstRowBytes is too small to contain one row of pixels. ## |
| 658 | ## |
| 659 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 660 | #Param dstInfo width, height, Color_Type, and Alpha_Type of dstPixels ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 661 | #Param dstPixels storage for pixels; dstInfo.height() times dstRowBytes, or larger ## |
| 662 | #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] | 663 | #Param srcX offset into readable pixels on x-axis; may be negative ## |
| 664 | #Param srcY offset into readable pixels on y-axis; may be negative ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 665 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 666 | #Return true if pixels were copied ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 667 | |
| 668 | #Example |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 669 | #Width 64 |
| 670 | #Height 64 |
| 671 | #Description |
| 672 | A black circle drawn on a blue background provides an image to copy. |
| 673 | 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] | 674 | The copied quarter circles overdraw the original circle. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 675 | ## |
| 676 | canvas->clear(SK_ColorBLUE); |
| 677 | SkPaint paint; |
| 678 | canvas->drawCircle(32, 32, 28, paint); |
| 679 | SkImageInfo info = SkImageInfo::Make(64, 64, kBGRA_8888_SkColorType, kPremul_SkAlphaType); |
| 680 | sk_sp<SkData> data(SkData::MakeUninitialized(info.minRowBytes() * info.height())); |
| 681 | sk_bzero(data->writable_data(), info.minRowBytes() * info.height()); |
| 682 | for (int x : { 32, -32 } ) { |
| 683 | for (int y : { 32, -32 } ) { |
| 684 | canvas->readPixels(info, data->writable_data(), info.minRowBytes(), x, y); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 685 | } |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 686 | } |
| 687 | sk_sp<SkImage> image = SkImage::MakeRasterData(info, data, info.minRowBytes()); |
| 688 | canvas->drawImage(image, 0, 0); |
| 689 | ## |
| 690 | |
| 691 | #Example |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 692 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 693 | Canvas returned by Raster_Surface has Premultiplied pixel values. |
| 694 | clear() takes Unpremultiplied input with Color_Alpha equal 0x80 |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 695 | and RGB equal 0x55, 0xAA, 0xFF. RGB is multiplied by Color_Alpha |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 696 | to generate Premultiplied value 0x802B5580. readPixels converts pixel back |
| 697 | to Unpremultiplied value 0x8056A9FF, introducing error. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 698 | ## |
| 699 | canvas->clear(0x8055aaff); |
| 700 | for (SkAlphaType alphaType : { kPremul_SkAlphaType, kUnpremul_SkAlphaType } ) { |
| 701 | uint32_t pixel = 0; |
| 702 | SkImageInfo info = SkImageInfo::Make(1, 1, kBGRA_8888_SkColorType, alphaType); |
| 703 | if (canvas->readPixels(info, &pixel, 4, 0, 0)) { |
| 704 | SkDebugf("pixel = %08x\n", pixel); |
| 705 | } |
| 706 | } |
| 707 | |
| 708 | #StdOut |
| 709 | pixel = 802b5580 |
| 710 | pixel = 8056a9ff |
| 711 | ## |
| 712 | ## |
| 713 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 714 | #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] | 715 | |
| 716 | ## |
| 717 | |
| 718 | # ------------------------------------------------------------------------------ |
| 719 | |
| 720 | #Method bool readPixels(const SkPixmap& pixmap, int srcX, int srcY) |
| 721 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 722 | Copies Rect of pixels from Canvas into pixmap. Matrix and Clip are |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 723 | ignored. |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 724 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 725 | Source Rect corners are (srcX, srcY) and (imageInfo().width(), imageInfo().height()). |
| 726 | Destination Rect corners are (0, 0) and (pixmap.width(), pixmap.height()). |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 727 | Copies each readable pixel intersecting both rectangles, without scaling, |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 728 | converting to pixmap.colorType() and pixmap.alphaType() if required. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 729 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 730 | Pixels are readable when Device is raster, or backed by a GPU. |
| 731 | Pixels are not readable when SkCanvas is returned by SkDocument::beginPage, |
| 732 | returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility |
Brian Osman | 46fe9c7 | 2018-03-09 15:44:34 -0500 | [diff] [blame] | 733 | class like SkDebugCanvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 734 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 735 | Caller must allocate pixel storage in pixmap if needed. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 736 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 737 | Pixel values are converted only if Color_Type and Alpha_Type |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 738 | do not match. Only pixels within both source and destination Rects |
| 739 | are copied. pixmap pixels contents outside Rect intersection are unchanged. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 740 | |
| 741 | 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] | 742 | |
| 743 | Does not copy, and returns false if: |
| 744 | |
| 745 | #List |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 746 | # Source and destination rectangles do not intersect. ## |
| 747 | # Canvas pixels could not be converted to pixmap.colorType() or pixmap.alphaType(). ## |
| 748 | # Canvas pixels are not readable; for instance, Canvas is document-based. ## |
| 749 | # Pixmap pixels could not be allocated. ## |
| 750 | # pixmap.rowBytes() is too small to contain one row of pixels. ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 751 | ## |
| 752 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 753 | #Param pixmap storage for pixels copied from Canvas ## |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 754 | #Param srcX offset into readable pixels on x-axis; may be negative ## |
| 755 | #Param srcY offset into readable pixels on y-axis; may be negative ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 756 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 757 | #Return true if pixels were copied ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 758 | |
| 759 | #Example |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 760 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 761 | clear() takes Unpremultiplied input with Color_Alpha equal 0x80 |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 762 | and RGB equal 0x55, 0xAA, 0xFF. RGB is multiplied by Color_Alpha |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 763 | to generate Premultiplied value 0x802B5580. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 764 | ## |
| 765 | void draw(SkCanvas* canvas) { |
| 766 | canvas->clear(0x8055aaff); |
| 767 | uint32_t pixels[1] = { 0 }; |
| 768 | SkPixmap pixmap(SkImageInfo::MakeN32Premul(1, 1), pixels, 4); |
| 769 | canvas->readPixels(pixmap, 0, 0); |
| 770 | SkDebugf("pixel = %08x\n", pixels[0]); |
| 771 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 772 | #StdOut |
| 773 | pixel = 802b5580 |
| 774 | ## |
| 775 | ## |
| 776 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 777 | #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] | 778 | |
| 779 | ## |
| 780 | |
| 781 | # ------------------------------------------------------------------------------ |
| 782 | |
| 783 | #Method bool readPixels(const SkBitmap& bitmap, int srcX, int srcY) |
| 784 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 785 | Copies Rect of pixels from Canvas into bitmap. Matrix and Clip are |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 786 | ignored. |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 787 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 788 | Source Rect corners are (srcX, srcY) and (imageInfo().width(), imageInfo().height()). |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 789 | Destination Rect corners are (0, 0) and (bitmap.width(), bitmap.height()). |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 790 | Copies each readable pixel intersecting both rectangles, without scaling, |
| 791 | converting to bitmap.colorType() and bitmap.alphaType() if required. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 792 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 793 | Pixels are readable when Device is raster, or backed by a GPU. |
| 794 | Pixels are not readable when SkCanvas is returned by SkDocument::beginPage, |
| 795 | returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility |
Brian Osman | 46fe9c7 | 2018-03-09 15:44:34 -0500 | [diff] [blame] | 796 | class like SkDebugCanvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 797 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 798 | Caller must allocate pixel storage in bitmap if needed. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 799 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 800 | Bitmap values are converted only if Color_Type and Alpha_Type |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 801 | do not match. Only pixels within both source and destination rectangles |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 802 | are copied. Bitmap pixels outside Rect intersection are unchanged. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 803 | |
| 804 | 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] | 805 | |
| 806 | Does not copy, and returns false if: |
| 807 | |
| 808 | #List |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 809 | # Source and destination rectangles do not intersect. ## |
| 810 | # Canvas pixels could not be converted to bitmap.colorType() or bitmap.alphaType(). ## |
| 811 | # Canvas pixels are not readable; for instance, Canvas is document-based. ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 812 | # bitmap pixels could not be allocated. ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 813 | # bitmap.rowBytes() is too small to contain one row of pixels. ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 814 | ## |
| 815 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 816 | #Param bitmap storage for pixels copied from Canvas ## |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 817 | #Param srcX offset into readable pixels on x-axis; may be negative ## |
| 818 | #Param srcY offset into readable pixels on y-axis; may be negative ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 819 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 820 | #Return true if pixels were copied ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 821 | |
| 822 | #Example |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 823 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 824 | clear() takes Unpremultiplied input with Color_Alpha equal 0x80 |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 825 | and RGB equal 0x55, 0xAA, 0xFF. RGB is multiplied by Color_Alpha |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 826 | to generate Premultiplied value 0x802B5580. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 827 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 828 | void draw(SkCanvas* canvas) { |
| 829 | canvas->clear(0x8055aaff); |
| 830 | SkBitmap bitmap; |
| 831 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(1, 1)); |
| 832 | canvas->readPixels(bitmap, 0, 0); |
| 833 | SkDebugf("pixel = %08x\n", bitmap.getAddr32(0, 0)[0]); |
| 834 | } |
| 835 | #StdOut |
| 836 | pixel = 802b5580 |
| 837 | ## |
| 838 | ## |
| 839 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 840 | #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] | 841 | |
| 842 | ## |
| 843 | |
| 844 | # ------------------------------------------------------------------------------ |
| 845 | |
| 846 | #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] | 847 | #In Pixels |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 848 | #Line # copies and converts rectangle of pixels to Canvas ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 849 | Copies Rect from pixels to Canvas. Matrix and Clip are ignored. |
| 850 | Source Rect corners are (0, 0) and (info.width(), info.height()). |
| 851 | Destination Rect corners are (x, y) and |
| 852 | (imageInfo().width(), imageInfo().height()). |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 853 | |
| 854 | Copies each readable pixel intersecting both rectangles, without scaling, |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 855 | converting to imageInfo().colorType() and imageInfo().alphaType() if required. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 856 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 857 | Pixels are writable when Device is raster, or backed by a GPU. |
| 858 | Pixels are not writable when SkCanvas is returned by SkDocument::beginPage, |
| 859 | returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility |
Brian Osman | 46fe9c7 | 2018-03-09 15:44:34 -0500 | [diff] [blame] | 860 | class like SkDebugCanvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 861 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 862 | Pixel values are converted only if Color_Type and Alpha_Type |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 863 | do not match. Only pixels within both source and destination rectangles |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 864 | are copied. Canvas pixels outside Rect intersection are unchanged. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 865 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 866 | Pass negative values for x or y to offset pixels to the left or |
| 867 | above Canvas pixels. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 868 | |
| 869 | Does not copy, and returns false if: |
| 870 | |
| 871 | #List |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 872 | # Source and destination rectangles do not intersect. ## |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 873 | # pixels could not be converted to Canvas imageInfo().colorType() or |
| 874 | imageInfo().alphaType(). ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 875 | # Canvas pixels are not writable; for instance, Canvas is document-based. ## |
| 876 | # rowBytes is too small to contain one row of pixels. ## |
| 877 | ## |
| 878 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 879 | #Param info width, height, Color_Type, and Alpha_Type of pixels ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 880 | #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] | 881 | #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] | 882 | #Param x offset into Canvas writable pixels on x-axis; may be negative ## |
| 883 | #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] | 884 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 885 | #Return true if pixels were written to Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 886 | |
| 887 | #Example |
| 888 | SkImageInfo imageInfo = SkImageInfo::MakeN32(256, 1, kPremul_SkAlphaType); |
| 889 | for (int y = 0; y < 256; ++y) { |
| 890 | uint32_t pixels[256]; |
| 891 | for (int x = 0; x < 256; ++x) { |
| 892 | pixels[x] = SkColorSetARGB(x, x + y, x, x - y); |
| 893 | } |
| 894 | canvas->writePixels(imageInfo, &pixels, sizeof(pixels), 0, y); |
| 895 | } |
| 896 | ## |
| 897 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 898 | #SeeAlso readPixels drawBitmap drawImage SkBitmap::writePixels |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 899 | |
| 900 | ## |
| 901 | |
| 902 | # ------------------------------------------------------------------------------ |
| 903 | |
| 904 | #Method bool writePixels(const SkBitmap& bitmap, int x, int y) |
| 905 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 906 | Copies Rect from pixels to Canvas. Matrix and Clip are ignored. |
| 907 | Source Rect corners are (0, 0) and (bitmap.width(), bitmap.height()). |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 908 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 909 | Destination Rect corners are (x, y) and |
| 910 | (imageInfo().width(), imageInfo().height()). |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 911 | |
| 912 | Copies each readable pixel intersecting both rectangles, without scaling, |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 913 | converting to imageInfo().colorType() and imageInfo().alphaType() if required. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 914 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 915 | Pixels are writable when Device is raster, or backed by a GPU. |
| 916 | Pixels are not writable when SkCanvas is returned by SkDocument::beginPage, |
| 917 | returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility |
Brian Osman | 46fe9c7 | 2018-03-09 15:44:34 -0500 | [diff] [blame] | 918 | class like SkDebugCanvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 919 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 920 | Pixel values are converted only if Color_Type and Alpha_Type |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 921 | do not match. Only pixels within both source and destination rectangles |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 922 | are copied. Canvas pixels outside Rect intersection are unchanged. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 923 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 924 | Pass negative values for x or y to offset pixels to the left or |
| 925 | above Canvas pixels. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 926 | |
| 927 | Does not copy, and returns false if: |
| 928 | |
| 929 | #List |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 930 | # Source and destination rectangles do not intersect. ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 931 | # bitmap does not have allocated pixels. ## |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 932 | # bitmap pixels could not be converted to Canvas imageInfo().colorType() or |
| 933 | imageInfo().alphaType(). ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 934 | # Canvas pixels are not writable; for instance, Canvas is document based. ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 935 | # bitmap pixels are inaccessible; for instance, bitmap wraps a texture. ## |
| 936 | ## |
| 937 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 938 | #Param bitmap contains pixels copied to Canvas ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 939 | #Param x offset into Canvas writable pixels in x; may be negative ## |
| 940 | #Param y offset into Canvas writable pixels in y; may be negative ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 941 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 942 | #Return true if pixels were written to Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 943 | |
| 944 | #Example |
| 945 | void draw(SkCanvas* canvas) { |
| 946 | SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(2, 2); |
| 947 | SkBitmap bitmap; |
| 948 | bitmap.setInfo(imageInfo); |
| 949 | uint32_t pixels[4]; |
| 950 | bitmap.setPixels(pixels); |
| 951 | for (int y = 0; y < 256; y += 2) { |
| 952 | for (int x = 0; x < 256; x += 2) { |
| 953 | pixels[0] = SkColorSetRGB(x, y, x | y); |
| 954 | pixels[1] = SkColorSetRGB(x ^ y, y, x); |
| 955 | pixels[2] = SkColorSetRGB(x, x & y, y); |
| 956 | pixels[3] = SkColorSetRGB(~x, ~y, x); |
| 957 | canvas->writePixels(bitmap, x, y); |
| 958 | } |
| 959 | } |
| 960 | } |
| 961 | ## |
| 962 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 963 | #SeeAlso readPixels drawBitmap drawImage SkBitmap::writePixels |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 964 | |
| 965 | ## |
| 966 | |
| 967 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 968 | #Subtopic State_Stack |
| 969 | #Line # stack of state for hierarchical drawing ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 970 | |
| 971 | Canvas maintains a stack of state that allows hierarchical drawing, commonly used |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 972 | to implement windows and views. The initial state has an identity matrix and and |
| 973 | an infinite clip. Even with a wide-open clip, drawing is constrained by the |
| 974 | bounds of the Canvas Surface or Device. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 975 | |
Cary Clark | 939fd6c | 2018-07-12 08:40:13 -0400 | [diff] [blame] | 976 | Canvas savable state consists of Clip and Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 977 | Clip describes the area that may be drawn to. |
| 978 | Matrix transforms the geometry. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 979 | |
Mike Reed | 9a229e9 | 2019-01-08 10:52:52 -0500 | [diff] [blame] | 980 | save(), saveLayer, and saveLayerAlpha |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 981 | save state and return the depth of the stack. |
| 982 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 983 | restore(), restoreToCount, and ~SkCanvas() revert state to its value when saved. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 984 | |
| 985 | Each state on the stack intersects Clip with the previous Clip, |
| 986 | and concatenates Matrix with the previous Matrix. |
| 987 | The intersected Clip makes the drawing area the same or smaller; |
| 988 | the concatenated Matrix may move the origin and potentially scale or rotate |
| 989 | the coordinate space. |
| 990 | |
| 991 | Canvas does not require balancing the state stack but it is a good idea |
| 992 | to do so. Calling save() without restore() will eventually cause Skia to fail; |
| 993 | mismatched save() and restore() create hard to find bugs. |
| 994 | |
| 995 | It is not possible to use state to draw outside of the clip defined by the |
| 996 | previous state. |
| 997 | |
| 998 | #Example |
| 999 | #Description |
| 1000 | Draw to ever smaller clips; then restore drawing to full canvas. |
| 1001 | Note that the second clipRect is not permitted to enlarge Clip. |
| 1002 | ## |
| 1003 | #Height 160 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1004 | void draw(SkCanvas* canvas) { |
| 1005 | SkPaint paint; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1006 | canvas->save(); // records stack depth to restore |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1007 | canvas->clipRect(SkRect::MakeWH(100, 100)); // constrains drawing to clip |
| 1008 | canvas->clear(SK_ColorRED); // draws to limit of clip |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1009 | canvas->save(); // records stack depth to restore |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1010 | canvas->clipRect(SkRect::MakeWH(50, 150)); // Rect below 100 is ignored |
| 1011 | canvas->clear(SK_ColorBLUE); // draws to smaller clip |
| 1012 | canvas->restore(); // enlarges clip |
| 1013 | canvas->drawLine(20, 20, 150, 150, paint); // line below 100 is not drawn |
| 1014 | canvas->restore(); // enlarges clip |
| 1015 | canvas->drawLine(150, 20, 50, 120, paint); // line below 100 is drawn |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1016 | } |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1017 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1018 | |
| 1019 | Each Clip uses the current Matrix for its coordinates. |
| 1020 | |
| 1021 | #Example |
| 1022 | #Description |
| 1023 | While clipRect is given the same rectangle twice, Matrix makes the second |
| 1024 | clipRect draw at half the size of the first. |
| 1025 | ## |
| 1026 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1027 | void draw(SkCanvas* canvas) { |
| 1028 | canvas->clipRect(SkRect::MakeWH(100, 100)); |
| 1029 | canvas->clear(SK_ColorRED); |
| 1030 | canvas->scale(.5, .5); |
| 1031 | canvas->clipRect(SkRect::MakeWH(100, 100)); |
| 1032 | canvas->clear(SK_ColorBLUE); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1033 | } |
| 1034 | ## |
| 1035 | |
Mike Reed | 9a229e9 | 2019-01-08 10:52:52 -0500 | [diff] [blame] | 1036 | #SeeAlso save saveLayer saveLayerAlpha restore() restoreToCount |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1037 | |
| 1038 | #Method int save() |
| 1039 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1040 | #In State_Stack |
| 1041 | #Line # saves Clip and Matrix on stack ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1042 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1043 | |
| 1044 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1045 | #Description |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1046 | The black square is translated 50 pixels down and to the right. |
| 1047 | Restoring Canvas state removes translate() from Canvas stack; |
| 1048 | the red square is not translated, and is drawn at the origin. |
| 1049 | ## |
| 1050 | #Height 100 |
| 1051 | void draw(SkCanvas* canvas) { |
| 1052 | SkPaint paint; |
| 1053 | SkRect rect = { 0, 0, 25, 25 }; |
| 1054 | canvas->drawRect(rect, paint); |
| 1055 | canvas->save(); |
| 1056 | canvas->translate(50, 50); |
| 1057 | canvas->drawRect(rect, paint); |
| 1058 | canvas->restore(); |
| 1059 | paint.setColor(SK_ColorRED); |
| 1060 | canvas->drawRect(rect, paint); |
| 1061 | } |
| 1062 | ## |
| 1063 | |
Mike Reed | 9a229e9 | 2019-01-08 10:52:52 -0500 | [diff] [blame] | 1064 | #SeeAlso saveLayer saveLayerAlpha restore restoreToCount |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1065 | |
| 1066 | ## |
| 1067 | |
| 1068 | # ------------------------------------------------------------------------------ |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1069 | |
| 1070 | #Method void restore() |
| 1071 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1072 | #In State_Stack |
| 1073 | #Line # restores changes to Clip and Matrix, pops save stack ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1074 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1075 | |
| 1076 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1077 | void draw(SkCanvas* canvas) { |
| 1078 | SkCanvas simple; |
| 1079 | SkDebugf("depth = %d\n", simple.getSaveCount()); |
| 1080 | simple.restore(); |
| 1081 | SkDebugf("depth = %d\n", simple.getSaveCount()); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1082 | } |
| 1083 | ## |
| 1084 | |
Mike Reed | 9a229e9 | 2019-01-08 10:52:52 -0500 | [diff] [blame] | 1085 | #SeeAlso save saveLayer saveLayerAlpha restoreToCount |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1086 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1087 | ## |
| 1088 | |
| 1089 | # ------------------------------------------------------------------------------ |
| 1090 | |
| 1091 | #Method int getSaveCount() const |
| 1092 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1093 | #In State_Stack |
| 1094 | #Line # returns depth of stack containing Clip and Matrix ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1095 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1096 | |
| 1097 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1098 | void draw(SkCanvas* canvas) { |
| 1099 | SkCanvas simple; |
| 1100 | SkDebugf("depth = %d\n", simple.getSaveCount()); |
| 1101 | simple.save(); |
| 1102 | SkDebugf("depth = %d\n", simple.getSaveCount()); |
| 1103 | simple.restore(); |
| 1104 | SkDebugf("depth = %d\n", simple.getSaveCount()); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1105 | } |
| 1106 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1107 | depth = 1 |
| 1108 | depth = 2 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1109 | depth = 1 |
| 1110 | ## |
| 1111 | ## |
| 1112 | |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1113 | #SeeAlso save restore restoreToCount |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1114 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1115 | ## |
| 1116 | |
| 1117 | # ------------------------------------------------------------------------------ |
| 1118 | |
| 1119 | #Method void restoreToCount(int saveCount) |
| 1120 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1121 | #In State_Stack |
| 1122 | #Line # restores changes to Clip and Matrix to given depth ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1123 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1124 | |
| 1125 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1126 | void draw(SkCanvas* canvas) { |
| 1127 | SkDebugf("depth = %d\n", canvas->getSaveCount()); |
| 1128 | canvas->save(); |
| 1129 | canvas->save(); |
| 1130 | SkDebugf("depth = %d\n", canvas->getSaveCount()); |
| 1131 | canvas->restoreToCount(0); |
| 1132 | SkDebugf("depth = %d\n", canvas->getSaveCount()); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1133 | } |
| 1134 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1135 | depth = 1 |
| 1136 | depth = 3 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1137 | depth = 1 |
| 1138 | ## |
| 1139 | ## |
| 1140 | |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1141 | #SeeAlso restore getSaveCount save |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1142 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1143 | ## |
| 1144 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1145 | #Subtopic State_Stack ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1146 | |
| 1147 | # ------------------------------------------------------------------------------ |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1148 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1149 | #Subtopic Layer |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1150 | #Substitute layer |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1151 | #Alias Layers |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 1152 | #Substitute layers |
| 1153 | ## |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1154 | #Line # temporary Bitmap to draw into ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1155 | |
| 1156 | Layer allocates a temporary Bitmap to draw into. When the drawing is |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1157 | complete, the Bitmap is drawn into the Canvas. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1158 | |
| 1159 | Layer is saved in a stack along with other saved state. When state with a Layer |
| 1160 | is restored, the Bitmap is drawn into the previous Layer. |
| 1161 | |
| 1162 | Layer may be initialized with the contents of the previous Layer. When Layer is |
| 1163 | restored, its Bitmap can be modified by Paint passed to Layer to apply |
| 1164 | Color_Alpha, Color_Filter, Image_Filter, and Blend_Mode. |
| 1165 | |
| 1166 | #Method int saveLayer(const SkRect* bounds, const SkPaint* paint) |
| 1167 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1168 | #In Layer |
| 1169 | #Line # saves Clip and Matrix on stack; creates Layer ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1170 | #Populate |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1171 | |
| 1172 | #Example |
| 1173 | #Description |
| 1174 | Rectangles are blurred by Image_Filter when restore() draws Layer to main |
| 1175 | Canvas. |
| 1176 | ## |
| 1177 | #Height 128 |
Cary Clark | 81abc43 | 2018-06-25 16:30:08 -0400 | [diff] [blame] | 1178 | #Function |
| 1179 | ###$ |
| 1180 | #include "SkBlurImageFilter.h" |
| 1181 | $$$# |
| 1182 | ## |
| 1183 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1184 | void draw(SkCanvas* canvas) { |
| 1185 | SkPaint paint, blur; |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1186 | blur.setImageFilter(SkBlurImageFilter::Make(3, 3, nullptr)); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1187 | canvas->saveLayer(nullptr, &blur); |
| 1188 | SkRect rect = { 25, 25, 50, 50}; |
| 1189 | canvas->drawRect(rect, paint); |
| 1190 | canvas->translate(50, 50); |
| 1191 | paint.setColor(SK_ColorRED); |
| 1192 | canvas->drawRect(rect, paint); |
| 1193 | canvas->restore(); |
| 1194 | } |
| 1195 | ## |
| 1196 | |
Mike Reed | 9a229e9 | 2019-01-08 10:52:52 -0500 | [diff] [blame] | 1197 | #SeeAlso save restore saveLayer saveLayerAlpha SaveLayerRec |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1198 | |
| 1199 | ## |
| 1200 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1201 | #Method int saveLayer(const SkRect& bounds, const SkPaint* paint) |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1202 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1203 | #In Layer |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1204 | #Populate |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1205 | |
| 1206 | #Example |
| 1207 | #Description |
| 1208 | 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] | 1209 | The red rectangle is clipped; it does not fully fit on Layer. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1210 | Image_Filter blurs past edge of Layer so red rectangle is blurred on all sides. |
| 1211 | ## |
| 1212 | #Height 128 |
Cary Clark | 81abc43 | 2018-06-25 16:30:08 -0400 | [diff] [blame] | 1213 | #Function |
| 1214 | ###$ |
| 1215 | #include "SkBlurImageFilter.h" |
| 1216 | $$$# |
| 1217 | ## |
| 1218 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1219 | void draw(SkCanvas* canvas) { |
| 1220 | SkPaint paint, blur; |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1221 | blur.setImageFilter(SkBlurImageFilter::Make(3, 3, nullptr)); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1222 | canvas->saveLayer(SkRect::MakeWH(90, 90), &blur); |
| 1223 | SkRect rect = { 25, 25, 50, 50}; |
| 1224 | canvas->drawRect(rect, paint); |
| 1225 | canvas->translate(50, 50); |
| 1226 | paint.setColor(SK_ColorRED); |
| 1227 | canvas->drawRect(rect, paint); |
| 1228 | canvas->restore(); |
| 1229 | } |
| 1230 | ## |
| 1231 | |
Mike Reed | 9a229e9 | 2019-01-08 10:52:52 -0500 | [diff] [blame] | 1232 | #SeeAlso save restore saveLayerAlpha SaveLayerRec |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1233 | |
| 1234 | ## |
| 1235 | |
| 1236 | #Method int saveLayerAlpha(const SkRect* bounds, U8CPU alpha) |
| 1237 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1238 | #In Layer |
| 1239 | #Line # saves Clip and Matrix on stack; creates Layer; sets opacity ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1240 | #Populate |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1241 | |
| 1242 | #Example |
| 1243 | SkPaint paint; |
| 1244 | paint.setColor(SK_ColorRED); |
| 1245 | canvas->drawCircle(50, 50, 50, paint); |
| 1246 | canvas->saveLayerAlpha(nullptr, 128); |
| 1247 | paint.setColor(SK_ColorBLUE); |
| 1248 | canvas->drawCircle(100, 50, 50, paint); |
| 1249 | paint.setColor(SK_ColorGREEN); |
| 1250 | paint.setAlpha(128); |
| 1251 | canvas->drawCircle(75, 90, 50, paint); |
| 1252 | canvas->restore(); |
| 1253 | ## |
| 1254 | |
Mike Reed | 9a229e9 | 2019-01-08 10:52:52 -0500 | [diff] [blame] | 1255 | #SeeAlso save restore saveLayer SaveLayerRec |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1256 | |
| 1257 | ## |
| 1258 | |
Cary Clark | d98f78c | 2018-04-26 08:32:37 -0400 | [diff] [blame] | 1259 | #Enum SaveLayerFlagsSet |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1260 | #Line # sets SaveLayerRec options ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1261 | #Code |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1262 | #Populate |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1263 | ## |
| 1264 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1265 | |
| 1266 | #Typedef uint32_t SaveLayerFlags |
| 1267 | #Line # options for SaveLayerRec ## |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 1268 | ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1269 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1270 | SaveLayerFlags provides options that may be used in any combination in SaveLayerRec, |
Mike Reed | 9a229e9 | 2019-01-08 10:52:52 -0500 | [diff] [blame] | 1271 | defining how Layer allocated by saveLayer operates. It may be set to zero or |
| 1272 | kInitWithPrevious_SaveLayerFlag. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1273 | |
| 1274 | #Const kInitWithPrevious_SaveLayerFlag 4 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1275 | #Line # initializes with previous contents ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1276 | Initializes Layer with the contents of the previous Layer. |
| 1277 | ## |
| 1278 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1279 | #Example |
| 1280 | #Height 160 |
| 1281 | #Description |
| 1282 | Canvas Layer captures red and blue circles scaled up by four. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1283 | scalePaint blends Layer back with transparency. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1284 | ## |
| 1285 | void draw(SkCanvas* canvas) { |
| 1286 | SkPaint redPaint, bluePaint, scalePaint; |
| 1287 | redPaint.setColor(SK_ColorRED); |
| 1288 | canvas->drawCircle(21, 21, 8, redPaint); |
| 1289 | bluePaint.setColor(SK_ColorBLUE); |
| 1290 | canvas->drawCircle(31, 21, 8, bluePaint); |
| 1291 | SkMatrix matrix; |
| 1292 | matrix.setScale(4, 4); |
| 1293 | scalePaint.setAlpha(0x40); |
| 1294 | scalePaint.setImageFilter( |
| 1295 | SkImageFilter::MakeMatrixFilter(matrix, kNone_SkFilterQuality, nullptr)); |
| 1296 | SkCanvas::SaveLayerRec saveLayerRec(nullptr, &scalePaint, |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1297 | SkCanvas::kInitWithPrevious_SaveLayerFlag); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1298 | canvas->saveLayer(saveLayerRec); |
| 1299 | canvas->restore(); |
| 1300 | } |
| 1301 | ## |
| 1302 | |
Mike Reed | 9a229e9 | 2019-01-08 10:52:52 -0500 | [diff] [blame] | 1303 | #SeeAlso save restore saveLayer saveLayerAlpha SaveLayerRec |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1304 | |
| 1305 | #Enum ## |
| 1306 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1307 | #Subtopic SaveLayerRec |
| 1308 | #Line # contains the state used to create the Layer ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1309 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1310 | #Struct SaveLayerRec |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1311 | #Line # contains the state used to create the Layer ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1312 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1313 | #Code |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1314 | #Populate |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1315 | ## |
| 1316 | |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 1317 | SaveLayerRec contains the state used to create the Layer. |
| 1318 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1319 | #Member const SkRect* fBounds |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1320 | #Line # hints at Layer size limit ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1321 | fBounds is used as a hint to limit the size of Layer; may be nullptr. |
| 1322 | fBounds suggests but does not define Layer size. To clip drawing to |
| 1323 | a specific rectangle, use clipRect. |
| 1324 | ## |
| 1325 | |
| 1326 | #Member const SkPaint* fPaint |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1327 | #Line # modifies overlay ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1328 | fPaint modifies how Layer overlays the prior Layer; may be nullptr. |
| 1329 | Color_Alpha, Blend_Mode, Color_Filter, Draw_Looper, Image_Filter, and |
| 1330 | Mask_Filter affect Layer draw. |
| 1331 | ## |
| 1332 | |
| 1333 | #Member const SkImageFilter* fBackdrop |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1334 | #Line # applies Image_Filter to prior Layer ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1335 | fBackdrop applies Image_Filter to the prior Layer when copying to the Layer; |
| 1336 | may be nullptr. Use kInitWithPrevious_SaveLayerFlag to copy the |
| 1337 | prior Layer without an Image_Filter. |
| 1338 | ## |
| 1339 | |
| 1340 | #Member const SkImage* fClipMask |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1341 | #Line # clips Layer with Mask_Alpha ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1342 | restore() clips Layer by the Color_Alpha channel of fClipMask when |
| 1343 | Layer is copied to Device. fClipMask may be nullptr. . |
| 1344 | ## |
| 1345 | |
| 1346 | #Member const SkMatrix* fClipMatrix |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1347 | #Line # transforms Mask_Alpha used to clip ## |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1348 | fClipMatrix transforms fClipMask before it clips Layer. If |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1349 | fClipMask describes a translucent gradient, it may be scaled and rotated |
| 1350 | without introducing artifacts. fClipMatrix may be nullptr. |
| 1351 | ## |
| 1352 | |
| 1353 | #Member SaveLayerFlags fSaveLayerFlags |
Mike Reed | 9a229e9 | 2019-01-08 10:52:52 -0500 | [diff] [blame] | 1354 | #Line # creates with prior Layer contents ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1355 | fSaveLayerFlags are used to create Layer without transparency, |
Mike Reed | 9a229e9 | 2019-01-08 10:52:52 -0500 | [diff] [blame] | 1356 | and to create Layer with the ontents of the previous Layer. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1357 | ## |
| 1358 | |
| 1359 | #Example |
| 1360 | #Height 160 |
| 1361 | #Description |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1362 | 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] | 1363 | 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] | 1364 | transferred to the main canvas. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1365 | ## |
| 1366 | void draw(SkCanvas* canvas) { |
| 1367 | SkPaint redPaint, bluePaint; |
| 1368 | redPaint.setAntiAlias(true); |
| 1369 | redPaint.setColor(SK_ColorRED); |
| 1370 | canvas->drawCircle(21, 21, 8, redPaint); |
| 1371 | bluePaint.setColor(SK_ColorBLUE); |
| 1372 | canvas->drawCircle(31, 21, 8, bluePaint); |
| 1373 | SkMatrix matrix; |
| 1374 | matrix.setScale(4, 4); |
| 1375 | auto scaler = SkImageFilter::MakeMatrixFilter(matrix, kNone_SkFilterQuality, nullptr); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1376 | SkCanvas::SaveLayerRec saveLayerRec(nullptr, nullptr, scaler.get(), 0); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1377 | canvas->saveLayer(saveLayerRec); |
| 1378 | canvas->drawCircle(125, 85, 8, redPaint); |
| 1379 | canvas->restore(); |
| 1380 | } |
| 1381 | ## |
| 1382 | |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1383 | #Subtopic Constructors |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1384 | ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1385 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1386 | #Method SaveLayerRec() |
| 1387 | #Line # constructs SaveLayerRec ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1388 | #Populate |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1389 | |
| 1390 | #Example |
| 1391 | SkCanvas::SaveLayerRec rec1; |
Mike Reed | 9a229e9 | 2019-01-08 10:52:52 -0500 | [diff] [blame] | 1392 | rec1.fSaveLayerFlags = SkCanvas::kInitWithPrevious_SaveLayerFlag; |
| 1393 | SkCanvas::SaveLayerRec rec2(nullptr, nullptr, SkCanvas::kInitWithPrevious_SaveLayerFlag); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1394 | SkDebugf("rec1 %c= rec2\n", rec1.fBounds == rec2.fBounds |
| 1395 | && rec1.fPaint == rec2.fPaint |
| 1396 | && rec1.fBackdrop == rec2.fBackdrop |
| 1397 | && rec1.fSaveLayerFlags == rec2.fSaveLayerFlags ? '=' : '!'); |
| 1398 | #StdOut |
| 1399 | rec1 == rec2 |
| 1400 | ## |
| 1401 | ## |
| 1402 | |
Mike Reed | 9a229e9 | 2019-01-08 10:52:52 -0500 | [diff] [blame] | 1403 | #SeeAlso save restore saveLayer saveLayerAlpha |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1404 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1405 | ## |
| 1406 | |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 1407 | #Method SaveLayerRec(const SkRect* bounds, const SkPaint* paint, SaveLayerFlags saveLayerFlags = 0) |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1408 | #Populate |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1409 | |
| 1410 | #Example |
| 1411 | SkCanvas::SaveLayerRec rec1; |
| 1412 | SkCanvas::SaveLayerRec rec2(nullptr, nullptr); |
| 1413 | SkDebugf("rec1 %c= rec2\n", rec1.fBounds == rec2.fBounds |
| 1414 | && rec1.fPaint == rec2.fPaint |
| 1415 | && rec1.fBackdrop == rec2.fBackdrop |
| 1416 | && rec1.fSaveLayerFlags == rec2.fSaveLayerFlags ? '=' : '!'); |
| 1417 | #StdOut |
| 1418 | rec1 == rec2 |
| 1419 | ## |
| 1420 | ## |
| 1421 | |
Mike Reed | 9a229e9 | 2019-01-08 10:52:52 -0500 | [diff] [blame] | 1422 | #SeeAlso save restore saveLayer saveLayerAlpha |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1423 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1424 | ## |
| 1425 | |
| 1426 | #Method SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop, |
| 1427 | SaveLayerFlags saveLayerFlags) |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1428 | #Populate |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1429 | |
| 1430 | #Example |
| 1431 | SkCanvas::SaveLayerRec rec1; |
| 1432 | SkCanvas::SaveLayerRec rec2(nullptr, nullptr, nullptr, 0); |
| 1433 | SkDebugf("rec1 %c= rec2\n", rec1.fBounds == rec2.fBounds |
| 1434 | && rec1.fPaint == rec2.fPaint |
| 1435 | && rec1.fBackdrop == rec2.fBackdrop |
| 1436 | && rec1.fSaveLayerFlags == rec2.fSaveLayerFlags ? '=' : '!'); |
| 1437 | #StdOut |
| 1438 | rec1 == rec2 |
| 1439 | ## |
| 1440 | ## |
| 1441 | |
Mike Reed | 9a229e9 | 2019-01-08 10:52:52 -0500 | [diff] [blame] | 1442 | #SeeAlso save restore saveLayer saveLayerAlpha |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1443 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1444 | ## |
| 1445 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1446 | #Struct ## |
| 1447 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1448 | #Subtopic ## |
| 1449 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1450 | #Method int saveLayer(const SaveLayerRec& layerRec) |
| 1451 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1452 | #In Layer |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1453 | #Populate |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1454 | |
| 1455 | #Example |
| 1456 | #Description |
| 1457 | The example draws an image, and saves it into a Layer with kInitWithPrevious_SaveLayerFlag. |
| 1458 | Next it punches a hole in Layer and restore with SkBlendMode::kPlus. |
| 1459 | Where Layer was cleared, the original image will draw unchanged. |
| 1460 | Outside of the circle the mandrill is brightened. |
| 1461 | ## |
| 1462 | #Image 3 |
Hal Canary | c465d13 | 2017-12-08 10:21:31 -0500 | [diff] [blame] | 1463 | // sk_sp<SkImage> image = GetResourceAsImage("images/mandrill_256.png"); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1464 | canvas->drawImage(image, 0, 0, nullptr); |
| 1465 | SkCanvas::SaveLayerRec rec; |
| 1466 | SkPaint paint; |
| 1467 | paint.setBlendMode(SkBlendMode::kPlus); |
| 1468 | rec.fSaveLayerFlags = SkCanvas::kInitWithPrevious_SaveLayerFlag; |
| 1469 | rec.fPaint = &paint; |
| 1470 | canvas->saveLayer(rec); |
| 1471 | paint.setBlendMode(SkBlendMode::kClear); |
| 1472 | canvas->drawCircle(128, 128, 96, paint); |
| 1473 | canvas->restore(); |
| 1474 | ## |
| 1475 | |
| 1476 | #ToDo above example needs to replace GetResourceAsImage with way to select image in fiddle ## |
| 1477 | |
Mike Reed | 9a229e9 | 2019-01-08 10:52:52 -0500 | [diff] [blame] | 1478 | #SeeAlso save restore saveLayer saveLayerAlpha |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1479 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1480 | ## |
| 1481 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1482 | #Subtopic Layer ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1483 | |
| 1484 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1485 | #Subtopic Matrix |
| 1486 | #Line # coordinate transformation ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1487 | |
| 1488 | #Method void translate(SkScalar dx, SkScalar dy) |
| 1489 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1490 | #In Matrix |
| 1491 | #Line # translates Matrix ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1492 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1493 | |
| 1494 | #Example |
| 1495 | #Height 128 |
| 1496 | #Description |
| 1497 | scale() followed by translate() produces different results from translate() followed |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1498 | by scale(). |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1499 | |
| 1500 | The blue stroke follows translate of (50, 50); a black |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1501 | 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] | 1502 | Matrix, a red frame follows the same scale of (2, 1/2.f); a gray fill |
| 1503 | follows translate of (50, 50). |
| 1504 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1505 | void draw(SkCanvas* canvas) { |
| 1506 | SkPaint filledPaint; |
| 1507 | SkPaint outlinePaint; |
| 1508 | outlinePaint.setStyle(SkPaint::kStroke_Style); |
| 1509 | outlinePaint.setColor(SK_ColorBLUE); |
| 1510 | canvas->save(); |
| 1511 | canvas->translate(50, 50); |
| 1512 | canvas->drawCircle(28, 28, 15, outlinePaint); // blue center: (50+28, 50+28) |
| 1513 | canvas->scale(2, 1/2.f); |
| 1514 | canvas->drawCircle(28, 28, 15, filledPaint); // black center: (50+(28*2), 50+(28/2)) |
| 1515 | canvas->restore(); |
| 1516 | filledPaint.setColor(SK_ColorGRAY); |
| 1517 | outlinePaint.setColor(SK_ColorRED); |
| 1518 | canvas->scale(2, 1/2.f); |
| 1519 | canvas->drawCircle(28, 28, 15, outlinePaint); // red center: (28*2, 28/2) |
| 1520 | canvas->translate(50, 50); |
| 1521 | 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] | 1522 | } |
| 1523 | ## |
| 1524 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1525 | #SeeAlso concat() scale() skew() rotate() setMatrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1526 | |
| 1527 | ## |
| 1528 | |
| 1529 | # ------------------------------------------------------------------------------ |
| 1530 | |
| 1531 | #Method void scale(SkScalar sx, SkScalar sy) |
| 1532 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1533 | #In Matrix |
| 1534 | #Line # scales Matrix ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1535 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1536 | |
| 1537 | #Example |
| 1538 | #Height 160 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1539 | void draw(SkCanvas* canvas) { |
| 1540 | SkPaint paint; |
| 1541 | SkRect rect = { 10, 20, 60, 120 }; |
| 1542 | canvas->translate(20, 20); |
| 1543 | canvas->drawRect(rect, paint); |
| 1544 | canvas->scale(2, .5f); |
| 1545 | paint.setColor(SK_ColorGRAY); |
| 1546 | canvas->drawRect(rect, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1547 | } |
| 1548 | ## |
| 1549 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1550 | #SeeAlso concat() translate() skew() rotate() setMatrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1551 | |
| 1552 | ## |
| 1553 | |
| 1554 | # ------------------------------------------------------------------------------ |
| 1555 | |
| 1556 | #Method void rotate(SkScalar degrees) |
| 1557 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1558 | #In Matrix |
| 1559 | #Line # rotates Matrix ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1560 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1561 | |
| 1562 | #Example |
| 1563 | #Description |
| 1564 | Draw clock hands at time 5:10. The hour hand and minute hand point up and |
| 1565 | are rotated clockwise. |
| 1566 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1567 | void draw(SkCanvas* canvas) { |
| 1568 | SkPaint paint; |
| 1569 | paint.setStyle(SkPaint::kStroke_Style); |
| 1570 | canvas->translate(128, 128); |
| 1571 | canvas->drawCircle(0, 0, 60, paint); |
| 1572 | canvas->save(); |
| 1573 | 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] | 1574 | canvas->drawLine(0, 0, 0, -50, paint); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1575 | canvas->restore(); |
| 1576 | canvas->rotate((5 + 10.f/60) * 360 / 12); // 5 and 10/60 hours of 12 scaled to 360 degrees |
| 1577 | canvas->drawLine(0, 0, 0, -30, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1578 | } |
| 1579 | ## |
| 1580 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1581 | #SeeAlso concat() translate() skew() scale() setMatrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1582 | |
| 1583 | ## |
| 1584 | |
| 1585 | # ------------------------------------------------------------------------------ |
| 1586 | |
| 1587 | #Method void rotate(SkScalar degrees, SkScalar px, SkScalar py) |
| 1588 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1589 | #In Matrix |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1590 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1591 | |
| 1592 | #Example |
| 1593 | #Height 192 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1594 | void draw(SkCanvas* canvas) { |
| 1595 | SkPaint paint; |
Mike Reed | 33535cb | 2019-01-09 11:25:18 -0500 | [diff] [blame] | 1596 | SkFont font(nullptr, 96); |
| 1597 | canvas->drawString("A1", 130, 100, font, paint); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1598 | canvas->rotate(180, 130, 100); |
Mike Reed | 33535cb | 2019-01-09 11:25:18 -0500 | [diff] [blame] | 1599 | canvas->drawString("A1", 130, 100, font, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1600 | } |
| 1601 | ## |
| 1602 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1603 | #SeeAlso concat() translate() skew() scale() setMatrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1604 | |
| 1605 | ## |
| 1606 | |
| 1607 | # ------------------------------------------------------------------------------ |
| 1608 | |
| 1609 | #Method void skew(SkScalar sx, SkScalar sy) |
| 1610 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1611 | #In Matrix |
| 1612 | #Line # skews Matrix ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1613 | #Populate |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1614 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1615 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1616 | #Description |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 1617 | Black text mimics an oblique text style by using a negative skew on x-axis |
| 1618 | that shifts the geometry to the right as the y-axis values decrease. |
| 1619 | Red text uses a positive skew on y-axis to shift the geometry down |
| 1620 | as the x-axis values increase. |
| 1621 | Blue text combines sx and sy skew to rotate and scale. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1622 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1623 | SkPaint paint; |
Mike Reed | 33535cb | 2019-01-09 11:25:18 -0500 | [diff] [blame] | 1624 | SkFont font(nullptr, 128); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1625 | canvas->translate(30, 130); |
| 1626 | canvas->save(); |
| 1627 | canvas->skew(-.5, 0); |
Mike Reed | 33535cb | 2019-01-09 11:25:18 -0500 | [diff] [blame] | 1628 | canvas->drawString("A1", 0, 0, font, paint); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1629 | canvas->restore(); |
| 1630 | canvas->save(); |
| 1631 | canvas->skew(0, .5); |
| 1632 | paint.setColor(SK_ColorRED); |
Mike Reed | 33535cb | 2019-01-09 11:25:18 -0500 | [diff] [blame] | 1633 | canvas->drawString("A1", 0, 0, font, paint); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1634 | canvas->restore(); |
| 1635 | canvas->skew(-.5, .5); |
| 1636 | paint.setColor(SK_ColorBLUE); |
Mike Reed | 33535cb | 2019-01-09 11:25:18 -0500 | [diff] [blame] | 1637 | canvas->drawString("A1", 0, 0, font, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1638 | ## |
| 1639 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1640 | #SeeAlso concat() translate() rotate() scale() setMatrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1641 | |
| 1642 | ## |
| 1643 | |
| 1644 | # ------------------------------------------------------------------------------ |
| 1645 | |
| 1646 | #Method void concat(const SkMatrix& matrix) |
| 1647 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1648 | #In Matrix |
| 1649 | #Line # multiplies Matrix by Matrix ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1650 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1651 | |
| 1652 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1653 | void draw(SkCanvas* canvas) { |
| 1654 | SkPaint paint; |
Mike Reed | 33535cb | 2019-01-09 11:25:18 -0500 | [diff] [blame] | 1655 | SkFont font(nullptr, 80); |
| 1656 | font.setScaleX(.3); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1657 | SkMatrix matrix; |
| 1658 | SkRect rect[2] = {{ 10, 20, 90, 110 }, { 40, 130, 140, 180 }}; |
| 1659 | matrix.setRectToRect(rect[0], rect[1], SkMatrix::kFill_ScaleToFit); |
| 1660 | canvas->drawRect(rect[0], paint); |
| 1661 | canvas->drawRect(rect[1], paint); |
| 1662 | paint.setColor(SK_ColorWHITE); |
Mike Reed | 33535cb | 2019-01-09 11:25:18 -0500 | [diff] [blame] | 1663 | canvas->drawString("Here", rect[0].fLeft + 10, rect[0].fBottom - 10, font, paint); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1664 | canvas->concat(matrix); |
Mike Reed | 33535cb | 2019-01-09 11:25:18 -0500 | [diff] [blame] | 1665 | canvas->drawString("There", rect[0].fLeft + 10, rect[0].fBottom - 10, font, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1666 | } |
| 1667 | ## |
| 1668 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1669 | #SeeAlso translate() rotate() scale() skew() setMatrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1670 | |
| 1671 | ## |
| 1672 | |
| 1673 | # ------------------------------------------------------------------------------ |
| 1674 | |
| 1675 | #Method void setMatrix(const SkMatrix& matrix) |
| 1676 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1677 | #In Matrix |
| 1678 | #Line # sets Matrix ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1679 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1680 | |
| 1681 | #Example |
| 1682 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1683 | void draw(SkCanvas* canvas) { |
| 1684 | SkPaint paint; |
Mike Reed | 33535cb | 2019-01-09 11:25:18 -0500 | [diff] [blame] | 1685 | SkFont font; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1686 | canvas->scale(4, 6); |
Mike Reed | 33535cb | 2019-01-09 11:25:18 -0500 | [diff] [blame] | 1687 | canvas->drawString("truth", 2, 10, font, paint); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1688 | SkMatrix matrix; |
| 1689 | matrix.setScale(2.8f, 6); |
| 1690 | canvas->setMatrix(matrix); |
Mike Reed | 33535cb | 2019-01-09 11:25:18 -0500 | [diff] [blame] | 1691 | canvas->drawString("consequences", 2, 20, font, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1692 | } |
| 1693 | ## |
| 1694 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1695 | #SeeAlso resetMatrix concat() translate() rotate() scale() skew() |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1696 | |
| 1697 | ## |
| 1698 | |
| 1699 | # ------------------------------------------------------------------------------ |
| 1700 | |
| 1701 | #Method void resetMatrix() |
| 1702 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1703 | #In Matrix |
| 1704 | #Line # resets Matrix to identity ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1705 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1706 | |
| 1707 | #Example |
| 1708 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1709 | void draw(SkCanvas* canvas) { |
| 1710 | SkPaint paint; |
Mike Reed | 33535cb | 2019-01-09 11:25:18 -0500 | [diff] [blame] | 1711 | SkFont font; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1712 | canvas->scale(4, 6); |
Mike Reed | 33535cb | 2019-01-09 11:25:18 -0500 | [diff] [blame] | 1713 | canvas->drawString("truth", 2, 10, font, paint); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1714 | canvas->resetMatrix(); |
| 1715 | canvas->scale(2.8f, 6); |
Mike Reed | 33535cb | 2019-01-09 11:25:18 -0500 | [diff] [blame] | 1716 | canvas->drawString("consequences", 2, 20, font, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1717 | } |
| 1718 | ## |
| 1719 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1720 | #SeeAlso setMatrix concat() translate() rotate() scale() skew() |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1721 | |
| 1722 | ## |
| 1723 | |
| 1724 | # ------------------------------------------------------------------------------ |
| 1725 | |
| 1726 | #Method const SkMatrix& getTotalMatrix() const |
| 1727 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1728 | #In Matrix |
| 1729 | #Line # returns Matrix ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1730 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1731 | |
| 1732 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1733 | SkDebugf("isIdentity %s\n", canvas->getTotalMatrix().isIdentity() ? "true" : "false"); |
| 1734 | #StdOut |
| 1735 | isIdentity true |
| 1736 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1737 | ## |
| 1738 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1739 | #SeeAlso setMatrix resetMatrix concat() |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1740 | |
| 1741 | ## |
| 1742 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1743 | #Subtopic Matrix ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1744 | |
| 1745 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1746 | #Subtopic Clip |
| 1747 | #Line # stack of clipping Paths ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1748 | |
| 1749 | 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] | 1750 | stack can be constructed from one or more Path_Contour elements. The |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1751 | Path_Contour may be composed of any number of Path_Verb segments. Each |
| 1752 | Path_Contour forms a closed area; Path_Fill_Type defines the area enclosed |
| 1753 | by Path_Contour. |
| 1754 | |
| 1755 | Clip stack of Path elements successfully restrict the Path area. Each |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1756 | Path is transformed by Matrix, then intersected with or subtracted from the |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1757 | prior Clip to form the replacement Clip. Use SkClipOp::kDifference |
| 1758 | to subtract Path from Clip; use SkClipOp::kIntersect to intersect Path |
| 1759 | with Clip. |
| 1760 | |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1761 | A clipping Path may be Anti_Aliased; if Path, after transformation, is |
| 1762 | composed of horizontal and vertical lines, clearing Anti_Alias allows whole pixels |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1763 | to either be inside or outside the clip. The fastest drawing has a Aliased, |
| 1764 | rectangular clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1765 | |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1766 | 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] | 1767 | that drawing blend partially with the destination along the edge. A rotated |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1768 | rectangular Anti_Aliased clip looks smoother but draws slower. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1769 | |
| 1770 | Clip can combine with Rect and Round_Rect primitives; like |
| 1771 | Path, these are transformed by Matrix before they are combined with Clip. |
| 1772 | |
| 1773 | Clip can combine with Region. Region is assumed to be in Device coordinates |
| 1774 | and is unaffected by Matrix. |
| 1775 | |
| 1776 | #Example |
| 1777 | #Height 90 |
| 1778 | #Description |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1779 | 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] | 1780 | Use an image filter to zoom into the pixels drawn. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1781 | 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] | 1782 | 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] | 1783 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1784 | SkPaint redPaint, scalePaint; |
| 1785 | redPaint.setAntiAlias(true); |
| 1786 | redPaint.setColor(SK_ColorRED); |
| 1787 | canvas->save(); |
| 1788 | for (bool antialias : { false, true } ) { |
| 1789 | canvas->save(); |
| 1790 | canvas->clipRect(SkRect::MakeWH(19.5f, 11.5f), antialias); |
| 1791 | canvas->drawCircle(17, 11, 8, redPaint); |
| 1792 | canvas->restore(); |
| 1793 | canvas->translate(16, 0); |
| 1794 | } |
| 1795 | canvas->restore(); |
| 1796 | SkMatrix matrix; |
| 1797 | matrix.setScale(6, 6); |
| 1798 | scalePaint.setImageFilter( |
| 1799 | SkImageFilter::MakeMatrixFilter(matrix, kNone_SkFilterQuality, nullptr)); |
| 1800 | SkCanvas::SaveLayerRec saveLayerRec( |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1801 | nullptr, &scalePaint, SkCanvas::kInitWithPrevious_SaveLayerFlag); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1802 | canvas->saveLayer(saveLayerRec); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1803 | canvas->restore(); |
| 1804 | ## |
| 1805 | |
| 1806 | #Method void clipRect(const SkRect& rect, SkClipOp op, bool doAntiAlias) |
| 1807 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1808 | #In Clip |
| 1809 | #Line # combines Clip with Rect ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1810 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1811 | |
| 1812 | #Example |
| 1813 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1814 | void draw(SkCanvas* canvas) { |
| 1815 | canvas->rotate(10); |
| 1816 | SkPaint paint; |
| 1817 | paint.setAntiAlias(true); |
| 1818 | for (auto alias: { false, true } ) { |
| 1819 | canvas->save(); |
| 1820 | canvas->clipRect(SkRect::MakeWH(90, 80), SkClipOp::kIntersect, alias); |
| 1821 | canvas->drawCircle(100, 60, 60, paint); |
| 1822 | canvas->restore(); |
| 1823 | canvas->translate(80, 0); |
| 1824 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1825 | } |
| 1826 | ## |
| 1827 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1828 | #SeeAlso clipRRect clipPath clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1829 | |
| 1830 | ## |
| 1831 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1832 | #Method void clipRect(const SkRect& rect, SkClipOp op) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1833 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1834 | #In Clip |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1835 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1836 | |
| 1837 | #Example |
| 1838 | #Height 192 |
| 1839 | #Width 280 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1840 | void draw(SkCanvas* canvas) { |
| 1841 | SkPaint paint; |
| 1842 | for (SkClipOp op: { SkClipOp::kIntersect, SkClipOp::kDifference } ) { |
| 1843 | canvas->save(); |
| 1844 | canvas->clipRect(SkRect::MakeWH(90, 120), op, false); |
| 1845 | canvas->drawCircle(100, 100, 60, paint); |
| 1846 | canvas->restore(); |
| 1847 | canvas->translate(80, 0); |
| 1848 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1849 | } |
| 1850 | ## |
| 1851 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1852 | #SeeAlso clipRRect clipPath clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1853 | |
| 1854 | ## |
| 1855 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1856 | #Method void clipRect(const SkRect& rect, bool doAntiAlias = false) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1857 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1858 | #In Clip |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1859 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1860 | |
| 1861 | #Example |
| 1862 | #Height 133 |
| 1863 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1864 | A circle drawn in pieces looks uniform when drawn Aliased. |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1865 | 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] | 1866 | visible as a thin pair of lines through the right circle. |
| 1867 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1868 | void draw(SkCanvas* canvas) { |
| 1869 | canvas->clear(SK_ColorWHITE); |
| 1870 | SkPaint paint; |
| 1871 | paint.setAntiAlias(true); |
| 1872 | paint.setColor(0x8055aaff); |
| 1873 | SkRect clipRect = { 0, 0, 87.4f, 87.4f }; |
| 1874 | for (auto alias: { false, true } ) { |
| 1875 | canvas->save(); |
| 1876 | canvas->clipRect(clipRect, SkClipOp::kIntersect, alias); |
| 1877 | canvas->drawCircle(67, 67, 60, paint); |
| 1878 | canvas->restore(); |
| 1879 | canvas->save(); |
| 1880 | canvas->clipRect(clipRect, SkClipOp::kDifference, alias); |
| 1881 | canvas->drawCircle(67, 67, 60, paint); |
| 1882 | canvas->restore(); |
| 1883 | canvas->translate(120, 0); |
| 1884 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1885 | } |
| 1886 | ## |
| 1887 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1888 | #SeeAlso clipRRect clipPath clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1889 | |
| 1890 | ## |
| 1891 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1892 | #Method void clipRRect(const SkRRect& rrect, SkClipOp op, bool doAntiAlias) |
| 1893 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1894 | #In Clip |
| 1895 | #Line # combines Clip with Round_Rect ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1896 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1897 | |
| 1898 | #Example |
| 1899 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1900 | void draw(SkCanvas* canvas) { |
| 1901 | canvas->clear(SK_ColorWHITE); |
| 1902 | SkPaint paint; |
| 1903 | paint.setAntiAlias(true); |
| 1904 | paint.setColor(0x8055aaff); |
| 1905 | SkRRect oval; |
| 1906 | oval.setOval({10, 20, 90, 100}); |
| 1907 | canvas->clipRRect(oval, SkClipOp::kIntersect, true); |
| 1908 | canvas->drawCircle(70, 100, 60, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1909 | } |
| 1910 | ## |
| 1911 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1912 | #SeeAlso clipRect clipPath clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1913 | |
| 1914 | ## |
| 1915 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1916 | #Method void clipRRect(const SkRRect& rrect, SkClipOp op) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1917 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1918 | #In Clip |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1919 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1920 | |
| 1921 | #Example |
| 1922 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1923 | void draw(SkCanvas* canvas) { |
| 1924 | SkPaint paint; |
| 1925 | paint.setColor(0x8055aaff); |
| 1926 | auto oval = SkRRect::MakeOval({10, 20, 90, 100}); |
| 1927 | canvas->clipRRect(oval, SkClipOp::kIntersect); |
| 1928 | canvas->drawCircle(70, 100, 60, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1929 | } |
| 1930 | ## |
| 1931 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1932 | #SeeAlso clipRect clipPath clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1933 | |
| 1934 | ## |
| 1935 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1936 | #Method void clipRRect(const SkRRect& rrect, bool doAntiAlias = false) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1937 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1938 | #In Clip |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1939 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1940 | |
| 1941 | #Example |
| 1942 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1943 | void draw(SkCanvas* canvas) { |
| 1944 | SkPaint paint; |
| 1945 | paint.setAntiAlias(true); |
| 1946 | auto oval = SkRRect::MakeRectXY({10, 20, 90, 100}, 9, 13); |
| 1947 | canvas->clipRRect(oval, true); |
| 1948 | canvas->drawCircle(70, 100, 60, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1949 | } |
| 1950 | ## |
| 1951 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1952 | #SeeAlso clipRect clipPath clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1953 | |
| 1954 | ## |
| 1955 | |
| 1956 | #Method void clipPath(const SkPath& path, SkClipOp op, bool doAntiAlias) |
| 1957 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1958 | #In Clip |
| 1959 | #Line # combines Clip with Path ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1960 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1961 | |
| 1962 | #Example |
| 1963 | #Description |
| 1964 | Top figure uses SkPath::kInverseWinding_FillType and SkClipOp::kDifference; |
| 1965 | area outside clip is subtracted from circle. |
| 1966 | |
| 1967 | Bottom figure uses SkPath::kWinding_FillType and SkClipOp::kIntersect; |
| 1968 | area inside clip is intersected with circle. |
| 1969 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1970 | void draw(SkCanvas* canvas) { |
| 1971 | SkPaint paint; |
| 1972 | paint.setAntiAlias(true); |
| 1973 | SkPath path; |
| 1974 | path.addRect({20, 30, 100, 110}); |
| 1975 | path.setFillType(SkPath::kInverseWinding_FillType); |
| 1976 | canvas->save(); |
| 1977 | canvas->clipPath(path, SkClipOp::kDifference, false); |
| 1978 | canvas->drawCircle(70, 100, 60, paint); |
| 1979 | canvas->restore(); |
| 1980 | canvas->translate(100, 100); |
| 1981 | path.setFillType(SkPath::kWinding_FillType); |
| 1982 | canvas->clipPath(path, SkClipOp::kIntersect, false); |
| 1983 | canvas->drawCircle(70, 100, 60, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1984 | } |
| 1985 | ## |
| 1986 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1987 | #SeeAlso clipRect clipRRect clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1988 | |
| 1989 | ## |
| 1990 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1991 | #Method void clipPath(const SkPath& path, SkClipOp op) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1992 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1993 | #In Clip |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 1994 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1995 | |
| 1996 | #Example |
| 1997 | #Description |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 1998 | 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] | 1999 | SkPath::kWinding_FillType, the overlap is included. Set to |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2000 | SkPath::kEvenOdd_FillType, the overlap is excluded and forms a hole. |
| 2001 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2002 | void draw(SkCanvas* canvas) { |
| 2003 | SkPaint paint; |
| 2004 | paint.setAntiAlias(true); |
| 2005 | SkPath path; |
| 2006 | path.addRect({20, 15, 100, 95}); |
| 2007 | path.addRect({50, 65, 130, 135}); |
| 2008 | path.setFillType(SkPath::kWinding_FillType); |
| 2009 | canvas->save(); |
| 2010 | canvas->clipPath(path, SkClipOp::kIntersect); |
| 2011 | canvas->drawCircle(70, 85, 60, paint); |
| 2012 | canvas->restore(); |
| 2013 | canvas->translate(100, 100); |
| 2014 | path.setFillType(SkPath::kEvenOdd_FillType); |
| 2015 | canvas->clipPath(path, SkClipOp::kIntersect); |
| 2016 | canvas->drawCircle(70, 85, 60, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2017 | } |
| 2018 | ## |
| 2019 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2020 | #SeeAlso clipRect clipRRect clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2021 | |
| 2022 | ## |
| 2023 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2024 | #Method void clipPath(const SkPath& path, bool doAntiAlias = false) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2025 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2026 | #In Clip |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2027 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2028 | |
| 2029 | #Example |
| 2030 | #Height 212 |
| 2031 | #Description |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2032 | Clip loops over itself covering its center twice. When clip Path_Fill_Type |
| 2033 | is set to SkPath::kWinding_FillType, the overlap is included. Set to |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2034 | SkPath::kEvenOdd_FillType, the overlap is excluded and forms a hole. |
| 2035 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2036 | void draw(SkCanvas* canvas) { |
| 2037 | SkPaint paint; |
| 2038 | paint.setAntiAlias(true); |
| 2039 | SkPath path; |
| 2040 | SkPoint poly[] = {{20, 20}, { 80, 20}, { 80, 80}, {40, 80}, |
| 2041 | {40, 40}, {100, 40}, {100, 100}, {20, 100}}; |
| 2042 | path.addPoly(poly, SK_ARRAY_COUNT(poly), true); |
| 2043 | path.setFillType(SkPath::kWinding_FillType); |
| 2044 | canvas->save(); |
| 2045 | canvas->clipPath(path, SkClipOp::kIntersect); |
| 2046 | canvas->drawCircle(50, 50, 45, paint); |
| 2047 | canvas->restore(); |
| 2048 | canvas->translate(100, 100); |
| 2049 | path.setFillType(SkPath::kEvenOdd_FillType); |
| 2050 | canvas->clipPath(path, SkClipOp::kIntersect); |
| 2051 | canvas->drawCircle(50, 50, 45, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2052 | } |
| 2053 | ## |
| 2054 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2055 | #SeeAlso clipRect clipRRect clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2056 | |
| 2057 | ## |
| 2058 | |
| 2059 | # ------------------------------------------------------------------------------ |
| 2060 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2061 | #Method void clipRegion(const SkRegion& deviceRgn, SkClipOp op = SkClipOp::kIntersect) |
| 2062 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2063 | #In Clip |
| 2064 | #Line # combines Clip with Region ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2065 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2066 | |
| 2067 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2068 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2069 | region is unaffected by canvas rotation; iRect is affected by canvas rotation. |
| 2070 | 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] | 2071 | aligns to pixel boundaries. |
| 2072 | ## |
| 2073 | void draw(SkCanvas* canvas) { |
| 2074 | SkPaint paint; |
| 2075 | paint.setAntiAlias(true); |
| 2076 | SkIRect iRect = {30, 40, 120, 130 }; |
| 2077 | SkRegion region(iRect); |
| 2078 | canvas->rotate(10); |
| 2079 | canvas->save(); |
| 2080 | canvas->clipRegion(region, SkClipOp::kIntersect); |
| 2081 | canvas->drawCircle(50, 50, 45, paint); |
| 2082 | canvas->restore(); |
| 2083 | canvas->translate(100, 100); |
| 2084 | canvas->clipRect(SkRect::Make(iRect), SkClipOp::kIntersect); |
| 2085 | canvas->drawCircle(50, 50, 45, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2086 | } |
| 2087 | ## |
| 2088 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2089 | #SeeAlso clipRect clipRRect clipPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2090 | |
| 2091 | ## |
| 2092 | |
| 2093 | #Method bool quickReject(const SkRect& rect) const |
| 2094 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2095 | #In Clip |
| 2096 | #Line # returns if Rect is outside Clip ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2097 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2098 | |
| 2099 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2100 | void draw(SkCanvas* canvas) { |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2101 | SkRect testRect = {30, 30, 120, 129 }; |
| 2102 | SkRect clipRect = {30, 130, 120, 230 }; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2103 | canvas->save(); |
| 2104 | canvas->clipRect(clipRect); |
| 2105 | SkDebugf("quickReject %s\n", canvas->quickReject(testRect) ? "true" : "false"); |
| 2106 | canvas->restore(); |
| 2107 | canvas->rotate(10); |
| 2108 | canvas->clipRect(clipRect); |
| 2109 | SkDebugf("quickReject %s\n", canvas->quickReject(testRect) ? "true" : "false"); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2110 | } |
| 2111 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2112 | quickReject true |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2113 | quickReject false |
| 2114 | ## |
| 2115 | ## |
| 2116 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2117 | #SeeAlso getLocalClipBounds getTotalMatrix SkBitmap::drawsNothing |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2118 | |
| 2119 | ## |
| 2120 | |
| 2121 | #Method bool quickReject(const SkPath& path) const |
| 2122 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2123 | #In Clip |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2124 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2125 | |
| 2126 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2127 | void draw(SkCanvas* canvas) { |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2128 | SkPoint testPoints[] = {{30, 30}, {120, 30}, {120, 129} }; |
| 2129 | SkPoint clipPoints[] = {{30, 130}, {120, 130}, {120, 230} }; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2130 | SkPath testPath, clipPath; |
| 2131 | testPath.addPoly(testPoints, SK_ARRAY_COUNT(testPoints), true); |
| 2132 | clipPath.addPoly(clipPoints, SK_ARRAY_COUNT(clipPoints), true); |
| 2133 | canvas->save(); |
| 2134 | canvas->clipPath(clipPath); |
| 2135 | SkDebugf("quickReject %s\n", canvas->quickReject(testPath) ? "true" : "false"); |
| 2136 | canvas->restore(); |
| 2137 | canvas->rotate(10); |
| 2138 | canvas->clipPath(clipPath); |
| 2139 | SkDebugf("quickReject %s\n", canvas->quickReject(testPath) ? "true" : "false"); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2140 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2141 | quickReject true |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2142 | quickReject false |
| 2143 | ## |
| 2144 | } |
| 2145 | ## |
| 2146 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2147 | #SeeAlso getLocalClipBounds getTotalMatrix SkBitmap::drawsNothing |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2148 | |
| 2149 | ## |
| 2150 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2151 | #Method SkRect getLocalClipBounds() const |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2152 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2153 | #In Clip |
| 2154 | #Line # returns Clip bounds in source coordinates ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2155 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2156 | |
| 2157 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2158 | #Description |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2159 | Initial bounds is device bounds outset by 1 on all sides. |
| 2160 | Clipped bounds is clipPath bounds outset by 1 on all sides. |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 2161 | Scaling the canvas by two on both axes scales the local bounds by 1/2 |
| 2162 | on both axes. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2163 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2164 | SkCanvas local(256, 256); |
| 2165 | canvas = &local; |
| 2166 | SkRect bounds = canvas->getLocalClipBounds(); |
| 2167 | SkDebugf("left:%g top:%g right:%g bottom:%g\n", |
| 2168 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2169 | SkPoint clipPoints[] = {{30, 130}, {120, 130}, {120, 230} }; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2170 | SkPath clipPath; |
| 2171 | clipPath.addPoly(clipPoints, SK_ARRAY_COUNT(clipPoints), true); |
| 2172 | canvas->clipPath(clipPath); |
| 2173 | bounds = canvas->getLocalClipBounds(); |
| 2174 | SkDebugf("left:%g top:%g right:%g bottom:%g\n", |
| 2175 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
| 2176 | canvas->scale(2, 2); |
| 2177 | bounds = canvas->getLocalClipBounds(); |
| 2178 | SkDebugf("left:%g top:%g right:%g bottom:%g\n", |
| 2179 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
| 2180 | #StdOut |
| 2181 | left:-1 top:-1 right:257 bottom:257 |
| 2182 | left:29 top:129 right:121 bottom:231 |
| 2183 | left:14.5 top:64.5 right:60.5 bottom:115.5 |
| 2184 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2185 | ## |
| 2186 | |
| 2187 | # local canvas in example works around bug in fiddle ## |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2188 | #Bug 6524 |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2189 | #SeeAlso getDeviceClipBounds getBaseLayerSize quickReject |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2190 | |
| 2191 | ## |
| 2192 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2193 | #Method bool getLocalClipBounds(SkRect* bounds) const |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2194 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2195 | #In Clip |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2196 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2197 | |
| 2198 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2199 | void draw(SkCanvas* canvas) { |
| 2200 | SkCanvas local(256, 256); |
| 2201 | canvas = &local; |
| 2202 | SkRect bounds; |
| 2203 | SkDebugf("local bounds empty = %s\n", canvas->getLocalClipBounds(&bounds) |
| 2204 | ? "false" : "true"); |
| 2205 | SkPath path; |
| 2206 | canvas->clipPath(path); |
| 2207 | SkDebugf("local bounds empty = %s\n", canvas->getLocalClipBounds(&bounds) |
| 2208 | ? "false" : "true"); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2209 | } |
| 2210 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2211 | local bounds empty = false |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2212 | local bounds empty = true |
| 2213 | ## |
| 2214 | ## |
| 2215 | |
| 2216 | # local canvas in example works around bug in fiddle ## |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2217 | #Bug 6524 |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2218 | #SeeAlso getDeviceClipBounds getBaseLayerSize quickReject |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2219 | |
| 2220 | ## |
| 2221 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2222 | #Method SkIRect getDeviceClipBounds() const |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2223 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2224 | #In Clip |
| 2225 | #Line # returns IRect bounds of Clip ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2226 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2227 | |
| 2228 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2229 | void draw(SkCanvas* canvas) { |
| 2230 | #Description |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2231 | Initial bounds is device bounds, not outset. |
| 2232 | Clipped bounds is clipPath bounds, not outset. |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 2233 | Scaling the canvas by 1/2 on both axes scales the device bounds by 1/2 |
| 2234 | on both axes. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2235 | ## |
| 2236 | SkCanvas device(256, 256); |
| 2237 | canvas = &device; |
| 2238 | SkIRect bounds = canvas->getDeviceClipBounds(); |
| 2239 | SkDebugf("left:%d top:%d right:%d bottom:%d\n", |
| 2240 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2241 | SkPoint clipPoints[] = {{30, 130}, {120, 130}, {120, 230} }; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2242 | SkPath clipPath; |
| 2243 | clipPath.addPoly(clipPoints, SK_ARRAY_COUNT(clipPoints), true); |
| 2244 | canvas->save(); |
| 2245 | canvas->clipPath(clipPath); |
| 2246 | bounds = canvas->getDeviceClipBounds(); |
| 2247 | SkDebugf("left:%d top:%d right:%d bottom:%d\n", |
| 2248 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
| 2249 | canvas->restore(); |
| 2250 | canvas->scale(1.f/2, 1.f/2); |
| 2251 | canvas->clipPath(clipPath); |
| 2252 | bounds = canvas->getDeviceClipBounds(); |
| 2253 | SkDebugf("left:%d top:%d right:%d bottom:%d\n", |
| 2254 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2255 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2256 | left:0 top:0 right:256 bottom:256 |
| 2257 | left:30 top:130 right:120 bottom:230 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2258 | left:15 top:65 right:60 bottom:115 |
| 2259 | ## |
| 2260 | } |
| 2261 | ## |
| 2262 | |
| 2263 | #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] | 2264 | #SeeAlso getLocalClipBounds getBaseLayerSize quickReject |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2265 | |
| 2266 | # device canvas in example works around bug in fiddle ## |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2267 | #Bug 6524 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2268 | |
| 2269 | ## |
| 2270 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2271 | #Method bool getDeviceClipBounds(SkIRect* bounds) const |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2272 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2273 | #In Clip |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2274 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2275 | |
| 2276 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2277 | void draw(SkCanvas* canvas) { |
| 2278 | SkIRect bounds; |
| 2279 | SkDebugf("device bounds empty = %s\n", canvas->getDeviceClipBounds(&bounds) |
| 2280 | ? "false" : "true"); |
| 2281 | SkPath path; |
| 2282 | canvas->clipPath(path); |
| 2283 | SkDebugf("device bounds empty = %s\n", canvas->getDeviceClipBounds(&bounds) |
| 2284 | ? "false" : "true"); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2285 | } |
| 2286 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2287 | device bounds empty = false |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2288 | device bounds empty = true |
| 2289 | ## |
| 2290 | ## |
| 2291 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2292 | #SeeAlso getLocalClipBounds getBaseLayerSize quickReject |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2293 | |
| 2294 | ## |
| 2295 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2296 | #Subtopic Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2297 | |
| 2298 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2299 | #Subtopic Draw |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2300 | #Line # draws into Canvas ## |
| 2301 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2302 | |
| 2303 | #Method void drawColor(SkColor color, SkBlendMode mode = SkBlendMode::kSrcOver) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2304 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2305 | #Line # fills Clip with Color and Blend_Mode ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2306 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2307 | |
| 2308 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2309 | canvas->drawColor(SK_ColorRED); |
| 2310 | canvas->clipRect(SkRect::MakeWH(150, 150)); |
| 2311 | canvas->drawColor(SkColorSetARGB(0x80, 0x00, 0xFF, 0x00), SkBlendMode::kPlus); |
| 2312 | canvas->clipRect(SkRect::MakeWH(75, 75)); |
| 2313 | canvas->drawColor(SkColorSetARGB(0x80, 0x00, 0x00, 0xFF), SkBlendMode::kPlus); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2314 | ## |
| 2315 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2316 | #SeeAlso clear SkBitmap::erase drawPaint |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2317 | |
| 2318 | ## |
| 2319 | |
| 2320 | # ------------------------------------------------------------------------------ |
| 2321 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2322 | #Method void clear(SkColor color) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2323 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2324 | #Line # fills Clip with Color ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2325 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2326 | |
| 2327 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2328 | void draw(SkCanvas* canvas) { |
| 2329 | canvas->save(); |
| 2330 | canvas->clipRect(SkRect::MakeWH(256, 128)); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2331 | canvas->clear(SkColorSetARGB(0x80, 0xFF, 0x00, 0x00)); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2332 | canvas->restore(); |
| 2333 | canvas->save(); |
| 2334 | canvas->clipRect(SkRect::MakeWH(150, 192)); |
| 2335 | canvas->clear(SkColorSetARGB(0x80, 0x00, 0xFF, 0x00)); |
| 2336 | canvas->restore(); |
| 2337 | canvas->clipRect(SkRect::MakeWH(75, 256)); |
| 2338 | canvas->clear(SkColorSetARGB(0x80, 0x00, 0x00, 0xFF)); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2339 | } |
| 2340 | ## |
| 2341 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2342 | #SeeAlso drawColor SkBitmap::erase drawPaint |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2343 | |
| 2344 | ## |
| 2345 | |
| 2346 | # ------------------------------------------------------------------------------ |
| 2347 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2348 | #Method void discard() |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2349 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2350 | #Line # makes Canvas contents undefined ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2351 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2352 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2353 | #NoExample |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2354 | ## |
| 2355 | |
Cary Clark | abaffd8 | 2018-11-15 08:25:12 -0500 | [diff] [blame] | 2356 | #SeeAlso flush() GrContext::abandonContext |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2357 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2358 | ## |
| 2359 | |
| 2360 | # ------------------------------------------------------------------------------ |
| 2361 | |
| 2362 | #Method void drawPaint(const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2363 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2364 | #Line # fills Clip with Paint ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2365 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2366 | |
| 2367 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2368 | void draw(SkCanvas* canvas) { |
| 2369 | SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE }; |
| 2370 | SkScalar pos[] = { 0, SK_Scalar1/2, SK_Scalar1 }; |
| 2371 | SkPaint paint; |
| 2372 | paint.setShader(SkGradientShader::MakeSweep(256, 256, colors, pos, SK_ARRAY_COUNT(colors))); |
| 2373 | canvas->drawPaint(paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2374 | } |
| 2375 | ## |
| 2376 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2377 | #SeeAlso clear drawColor SkBitmap::erase |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2378 | |
| 2379 | ## |
| 2380 | |
| 2381 | # ------------------------------------------------------------------------------ |
| 2382 | |
| 2383 | #Enum PointMode |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2384 | #Line # sets drawPoints options ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2385 | |
| 2386 | #Code |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 2387 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2388 | ## |
| 2389 | |
| 2390 | Selects if an array of points are drawn as discrete points, as lines, or as |
| 2391 | an open polygon. |
| 2392 | |
| 2393 | #Const kPoints_PointMode 0 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2394 | #Line # draw each point separately ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2395 | ## |
| 2396 | |
| 2397 | #Const kLines_PointMode 1 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2398 | #Line # draw each pair of points as a line segment ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2399 | ## |
| 2400 | |
| 2401 | #Const kPolygon_PointMode 2 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2402 | #Line # draw the array of points as a open polygon ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2403 | ## |
| 2404 | |
| 2405 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2406 | #Description |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2407 | The upper left corner shows three squares when drawn as points. |
| 2408 | The upper right corner shows one line; when drawn as lines, two points are required per line. |
| 2409 | The lower right corner shows two lines; when draw as polygon, no miter is drawn at the corner. |
| 2410 | The lower left corner shows two lines with a miter when path contains polygon. |
| 2411 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2412 | void draw(SkCanvas* canvas) { |
| 2413 | SkPaint paint; |
| 2414 | paint.setStyle(SkPaint::kStroke_Style); |
| 2415 | paint.setStrokeWidth(10); |
| 2416 | SkPoint points[] = {{64, 32}, {96, 96}, {32, 96}}; |
| 2417 | canvas->drawPoints(SkCanvas::kPoints_PointMode, 3, points, paint); |
| 2418 | canvas->translate(128, 0); |
| 2419 | canvas->drawPoints(SkCanvas::kLines_PointMode, 3, points, paint); |
| 2420 | canvas->translate(0, 128); |
| 2421 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, 3, points, paint); |
| 2422 | SkPath path; |
| 2423 | path.addPoly(points, 3, false); |
| 2424 | canvas->translate(-128, 0); |
| 2425 | canvas->drawPath(path, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2426 | } |
| 2427 | ## |
| 2428 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2429 | #SeeAlso drawLine drawPoint drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2430 | |
| 2431 | ## |
| 2432 | |
| 2433 | # ------------------------------------------------------------------------------ |
| 2434 | |
| 2435 | #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] | 2436 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2437 | #Line # draws array as points, lines, polygon ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2438 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2439 | |
| 2440 | #Example |
| 2441 | #Height 200 |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2442 | #Description |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2443 | #List |
| 2444 | # The first column draws points. ## |
| 2445 | # The second column draws points as lines. ## |
| 2446 | # The third column draws points as a polygon. ## |
| 2447 | # The fourth column draws points as a polygonal path. ## |
| 2448 | # The first row uses a round cap and round join. ## |
| 2449 | # The second row uses a square cap and a miter join. ## |
| 2450 | # The third row uses a butt cap and a bevel join. ## |
| 2451 | ## |
| 2452 | The transparent color makes multiple line draws visible; |
| 2453 | the path is drawn all at once. |
| 2454 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2455 | void draw(SkCanvas* canvas) { |
| 2456 | SkPaint paint; |
| 2457 | paint.setAntiAlias(true); |
| 2458 | paint.setStyle(SkPaint::kStroke_Style); |
| 2459 | paint.setStrokeWidth(10); |
| 2460 | paint.setColor(0x80349a45); |
| 2461 | const SkPoint points[] = {{32, 16}, {48, 48}, {16, 32}}; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2462 | const SkPaint::Join join[] = { SkPaint::kRound_Join, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2463 | SkPaint::kMiter_Join, |
| 2464 | SkPaint::kBevel_Join }; |
| 2465 | int joinIndex = 0; |
| 2466 | SkPath path; |
| 2467 | path.addPoly(points, 3, false); |
| 2468 | for (const auto cap : { SkPaint::kRound_Cap, SkPaint::kSquare_Cap, SkPaint::kButt_Cap } ) { |
| 2469 | paint.setStrokeCap(cap); |
| 2470 | paint.setStrokeJoin(join[joinIndex++]); |
| 2471 | for (const auto mode : { SkCanvas::kPoints_PointMode, |
| 2472 | SkCanvas::kLines_PointMode, |
| 2473 | SkCanvas::kPolygon_PointMode } ) { |
| 2474 | canvas->drawPoints(mode, 3, points, paint); |
| 2475 | canvas->translate(64, 0); |
| 2476 | } |
| 2477 | canvas->drawPath(path, paint); |
| 2478 | canvas->translate(-192, 64); |
| 2479 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2480 | } |
| 2481 | ## |
| 2482 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2483 | #SeeAlso drawLine drawPoint drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2484 | |
| 2485 | ## |
| 2486 | |
| 2487 | # ------------------------------------------------------------------------------ |
| 2488 | |
| 2489 | #Method void drawPoint(SkScalar x, SkScalar y, const SkPaint& paint) |
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 # draws point at (x, y) position ## |
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 | SkPaint paint; |
| 2497 | paint.setAntiAlias(true); |
| 2498 | paint.setColor(0x80349a45); |
| 2499 | paint.setStyle(SkPaint::kStroke_Style); |
| 2500 | paint.setStrokeWidth(100); |
| 2501 | paint.setStrokeCap(SkPaint::kRound_Cap); |
| 2502 | canvas->scale(1, 1.2f); |
| 2503 | canvas->drawPoint(64, 96, paint); |
| 2504 | canvas->scale(.6f, .8f); |
| 2505 | paint.setColor(SK_ColorWHITE); |
| 2506 | canvas->drawPoint(106, 120, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2507 | } |
| 2508 | ## |
| 2509 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2510 | #SeeAlso drawPoints drawCircle drawRect drawLine drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2511 | |
| 2512 | ## |
| 2513 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2514 | #Method void drawPoint(SkPoint p, const SkPaint& paint) |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2515 | #Populate |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2516 | |
| 2517 | #Example |
| 2518 | void draw(SkCanvas* canvas) { |
| 2519 | SkPaint paint; |
| 2520 | paint.setAntiAlias(true); |
| 2521 | paint.setColor(0x80349a45); |
| 2522 | paint.setStyle(SkPaint::kStroke_Style); |
| 2523 | paint.setStrokeWidth(100); |
| 2524 | paint.setStrokeCap(SkPaint::kSquare_Cap); |
| 2525 | canvas->scale(1, 1.2f); |
| 2526 | canvas->drawPoint({64, 96}, paint); |
| 2527 | canvas->scale(.6f, .8f); |
| 2528 | paint.setColor(SK_ColorWHITE); |
| 2529 | canvas->drawPoint(106, 120, paint); |
| 2530 | } |
| 2531 | ## |
| 2532 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2533 | #SeeAlso drawPoints drawCircle drawRect drawLine drawPath |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2534 | |
| 2535 | ## |
| 2536 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2537 | # ------------------------------------------------------------------------------ |
| 2538 | |
| 2539 | #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] | 2540 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2541 | #Line # draws line segment between two points ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2542 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2543 | |
| 2544 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2545 | SkPaint paint; |
| 2546 | paint.setAntiAlias(true); |
| 2547 | paint.setColor(0xFF9a67be); |
| 2548 | paint.setStrokeWidth(20); |
| 2549 | canvas->skew(1, 0); |
| 2550 | canvas->drawLine(32, 96, 32, 160, paint); |
| 2551 | canvas->skew(-2, 0); |
| 2552 | canvas->drawLine(288, 96, 288, 160, paint); |
| 2553 | ## |
| 2554 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2555 | #SeeAlso drawPoint drawCircle drawRect drawPath |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2556 | |
| 2557 | ## |
| 2558 | |
| 2559 | #Method void drawLine(SkPoint p0, SkPoint p1, const SkPaint& paint) |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2560 | #Populate |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2561 | |
| 2562 | #Example |
| 2563 | SkPaint paint; |
| 2564 | paint.setAntiAlias(true); |
| 2565 | paint.setColor(0xFF9a67be); |
| 2566 | paint.setStrokeWidth(20); |
| 2567 | canvas->skew(1, 0); |
| 2568 | canvas->drawLine({32, 96}, {32, 160}, paint); |
| 2569 | canvas->skew(-2, 0); |
| 2570 | canvas->drawLine({288, 96}, {288, 160}, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2571 | ## |
| 2572 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2573 | #SeeAlso drawPoint drawCircle drawRect drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2574 | |
| 2575 | ## |
| 2576 | |
| 2577 | # ------------------------------------------------------------------------------ |
| 2578 | |
| 2579 | #Method void drawRect(const SkRect& rect, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2580 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2581 | #Line # draws Rect using Clip, Matrix, and Paint ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2582 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2583 | |
| 2584 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2585 | void draw(SkCanvas* canvas) { |
| 2586 | SkPoint rectPts[] = { {64, 48}, {192, 160} }; |
| 2587 | SkPaint paint; |
| 2588 | paint.setAntiAlias(true); |
| 2589 | paint.setStyle(SkPaint::kStroke_Style); |
| 2590 | paint.setStrokeWidth(20); |
| 2591 | paint.setStrokeJoin(SkPaint::kRound_Join); |
| 2592 | SkMatrix rotator; |
| 2593 | rotator.setRotate(30, 128, 128); |
| 2594 | for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorMAGENTA } ) { |
| 2595 | paint.setColor(color); |
| 2596 | SkRect rect; |
| 2597 | rect.set(rectPts[0], rectPts[1]); |
| 2598 | canvas->drawRect(rect, paint); |
| 2599 | rotator.mapPoints(rectPts, 2); |
| 2600 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2601 | } |
| 2602 | ## |
| 2603 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2604 | #SeeAlso drawIRect drawRRect drawRoundRect drawRegion drawPath drawLine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2605 | |
| 2606 | ## |
| 2607 | |
| 2608 | # ------------------------------------------------------------------------------ |
| 2609 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2610 | #Method void drawIRect(const SkIRect& rect, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2611 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2612 | #Line # draws IRect using Clip, Matrix, and Paint ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2613 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2614 | |
| 2615 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2616 | SkIRect rect = { 64, 48, 192, 160 }; |
| 2617 | SkPaint paint; |
| 2618 | paint.setAntiAlias(true); |
| 2619 | paint.setStyle(SkPaint::kStroke_Style); |
| 2620 | paint.setStrokeWidth(20); |
| 2621 | paint.setStrokeJoin(SkPaint::kRound_Join); |
| 2622 | for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorMAGENTA } ) { |
| 2623 | paint.setColor(color); |
| 2624 | canvas->drawIRect(rect, paint); |
| 2625 | canvas->rotate(30, 128, 128); |
| 2626 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2627 | ## |
| 2628 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2629 | #SeeAlso drawRect drawRRect drawRoundRect drawRegion drawPath drawLine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2630 | |
| 2631 | ## |
| 2632 | |
| 2633 | # ------------------------------------------------------------------------------ |
| 2634 | |
| 2635 | #Method void drawRegion(const SkRegion& region, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2636 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2637 | #Line # draws Region using Clip, Matrix, and Paint ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2638 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2639 | |
| 2640 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2641 | void draw(SkCanvas* canvas) { |
| 2642 | SkRegion region; |
| 2643 | region.op( 10, 10, 50, 50, SkRegion::kUnion_Op); |
| 2644 | region.op( 10, 50, 90, 90, SkRegion::kUnion_Op); |
| 2645 | SkPaint paint; |
| 2646 | paint.setAntiAlias(true); |
| 2647 | paint.setStyle(SkPaint::kStroke_Style); |
| 2648 | paint.setStrokeWidth(20); |
| 2649 | paint.setStrokeJoin(SkPaint::kRound_Join); |
| 2650 | canvas->drawRegion(region, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2651 | } |
| 2652 | ## |
| 2653 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2654 | #SeeAlso drawRect drawIRect drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2655 | |
| 2656 | ## |
| 2657 | |
| 2658 | # ------------------------------------------------------------------------------ |
| 2659 | |
| 2660 | #Method void drawOval(const SkRect& oval, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2661 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2662 | #Line # draws Oval using Clip, Matrix, and Paint ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2663 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2664 | |
| 2665 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2666 | void draw(SkCanvas* canvas) { |
| 2667 | canvas->clear(0xFF3f5f9f); |
| 2668 | SkColor kColor1 = SkColorSetARGB(0xff, 0xff, 0x7f, 0); |
| 2669 | SkColor g1Colors[] = { kColor1, SkColorSetA(kColor1, 0x20) }; |
| 2670 | SkPoint g1Points[] = { { 0, 0 }, { 0, 100 } }; |
| 2671 | SkScalar pos[] = { 0.2f, 1.0f }; |
| 2672 | SkRect bounds = SkRect::MakeWH(80, 70); |
| 2673 | SkPaint paint; |
| 2674 | paint.setAntiAlias(true); |
| 2675 | paint.setShader(SkGradientShader::MakeLinear(g1Points, g1Colors, pos, SK_ARRAY_COUNT(g1Colors), |
| 2676 | SkShader::kClamp_TileMode)); |
| 2677 | canvas->drawOval(bounds , paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2678 | } |
| 2679 | ## |
| 2680 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2681 | #SeeAlso drawCircle drawPoint drawPath drawRRect drawRoundRect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2682 | |
| 2683 | ## |
| 2684 | |
| 2685 | # ------------------------------------------------------------------------------ |
| 2686 | |
| 2687 | #Method void drawRRect(const SkRRect& rrect, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2688 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2689 | #Line # draws Round_Rect using Clip, Matrix, and Paint ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2690 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2691 | |
| 2692 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2693 | void draw(SkCanvas* canvas) { |
| 2694 | SkPaint paint; |
| 2695 | paint.setAntiAlias(true); |
| 2696 | SkRect outer = {30, 40, 210, 220}; |
| 2697 | SkRect radii = {30, 50, 70, 90 }; |
| 2698 | SkRRect rRect; |
| 2699 | rRect.setNinePatch(outer, radii.fLeft, radii.fTop, radii.fRight, radii.fBottom); |
| 2700 | canvas->drawRRect(rRect, paint); |
| 2701 | paint.setColor(SK_ColorWHITE); |
| 2702 | canvas->drawLine(outer.fLeft + radii.fLeft, outer.fTop, |
| 2703 | outer.fLeft + radii.fLeft, outer.fBottom, paint); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2704 | canvas->drawLine(outer.fRight - radii.fRight, outer.fTop, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2705 | outer.fRight - radii.fRight, outer.fBottom, paint); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2706 | canvas->drawLine(outer.fLeft, outer.fTop + radii.fTop, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2707 | outer.fRight, outer.fTop + radii.fTop, paint); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2708 | canvas->drawLine(outer.fLeft, outer.fBottom - radii.fBottom, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2709 | outer.fRight, outer.fBottom - radii.fBottom, paint); |
| 2710 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2711 | ## |
| 2712 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2713 | #SeeAlso drawRect drawRoundRect drawDRRect drawCircle drawOval drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2714 | |
| 2715 | ## |
| 2716 | |
| 2717 | # ------------------------------------------------------------------------------ |
| 2718 | |
| 2719 | #Method void drawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2720 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2721 | #Line # draws double Round_Rect stroked or filled ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2722 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2723 | |
| 2724 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2725 | void draw(SkCanvas* canvas) { |
| 2726 | SkRRect outer = SkRRect::MakeRect({20, 40, 210, 200}); |
| 2727 | SkRRect inner = SkRRect::MakeOval({60, 70, 170, 160}); |
| 2728 | SkPaint paint; |
| 2729 | canvas->drawDRRect(outer, inner, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2730 | } |
| 2731 | ## |
| 2732 | |
| 2733 | #Example |
| 2734 | #Description |
| 2735 | Outer Rect has no corner radii, but stroke join is rounded. |
| 2736 | Inner Round_Rect has corner radii; outset stroke increases radii of corners. |
| 2737 | Stroke join does not affect inner Round_Rect since it has no sharp corners. |
| 2738 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2739 | void draw(SkCanvas* canvas) { |
| 2740 | SkRRect outer = SkRRect::MakeRect({20, 40, 210, 200}); |
| 2741 | SkRRect inner = SkRRect::MakeRectXY({60, 70, 170, 160}, 10, 10); |
| 2742 | SkPaint paint; |
| 2743 | paint.setAntiAlias(true); |
| 2744 | paint.setStyle(SkPaint::kStroke_Style); |
| 2745 | paint.setStrokeWidth(20); |
| 2746 | paint.setStrokeJoin(SkPaint::kRound_Join); |
| 2747 | canvas->drawDRRect(outer, inner, paint); |
| 2748 | paint.setStrokeWidth(1); |
| 2749 | paint.setColor(SK_ColorWHITE); |
| 2750 | canvas->drawDRRect(outer, inner, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2751 | } |
| 2752 | ## |
| 2753 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2754 | #SeeAlso drawRect drawRoundRect drawRRect drawCircle drawOval drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2755 | |
| 2756 | ## |
| 2757 | |
| 2758 | # ------------------------------------------------------------------------------ |
| 2759 | |
| 2760 | #Method void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2761 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2762 | #Line # draws Circle using Clip, Matrix, and Paint ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2763 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2764 | |
| 2765 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2766 | void draw(SkCanvas* canvas) { |
| 2767 | SkPaint paint; |
| 2768 | paint.setAntiAlias(true); |
| 2769 | canvas->drawCircle(128, 128, 90, paint); |
| 2770 | paint.setColor(SK_ColorWHITE); |
| 2771 | canvas->drawCircle(86, 86, 20, paint); |
| 2772 | canvas->drawCircle(160, 76, 20, paint); |
| 2773 | canvas->drawCircle(140, 150, 35, paint); |
| 2774 | } |
| 2775 | ## |
| 2776 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2777 | #SeeAlso drawOval drawRRect drawRoundRect drawPath drawArc drawPoint drawLine |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2778 | |
| 2779 | ## |
| 2780 | |
| 2781 | #Method void drawCircle(SkPoint center, SkScalar radius, const SkPaint& paint) |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2782 | #Populate |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2783 | |
| 2784 | #Example |
| 2785 | void draw(SkCanvas* canvas) { |
| 2786 | SkPaint paint; |
| 2787 | paint.setAntiAlias(true); |
| 2788 | canvas->drawCircle(128, 128, 90, paint); |
| 2789 | paint.setColor(SK_ColorWHITE); |
| 2790 | canvas->drawCircle({86, 86}, 20, paint); |
| 2791 | canvas->drawCircle({160, 76}, 20, paint); |
| 2792 | canvas->drawCircle({140, 150}, 35, paint); |
| 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 drawOval drawRRect drawRoundRect drawPath drawArc drawPoint drawLine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2797 | |
| 2798 | ## |
| 2799 | |
| 2800 | # ------------------------------------------------------------------------------ |
| 2801 | |
| 2802 | #Method void drawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, |
| 2803 | bool useCenter, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2804 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2805 | #Line # draws Arc using Clip, Matrix, and Paint ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2806 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2807 | |
| 2808 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2809 | void draw(SkCanvas* canvas) { |
| 2810 | SkPaint paint; |
| 2811 | paint.setAntiAlias(true); |
| 2812 | SkRect oval = { 4, 4, 60, 60}; |
| 2813 | for (auto useCenter : { false, true } ) { |
| 2814 | for (auto style : { SkPaint::kFill_Style, SkPaint::kStroke_Style } ) { |
| 2815 | paint.setStyle(style); |
| 2816 | for (auto degrees : { 45, 90, 180, 360} ) { |
| 2817 | canvas->drawArc(oval, 0, degrees , useCenter, paint); |
| 2818 | canvas->translate(64, 0); |
| 2819 | } |
| 2820 | canvas->translate(-256, 64); |
| 2821 | } |
| 2822 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2823 | } |
| 2824 | ## |
| 2825 | |
| 2826 | #Example |
| 2827 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2828 | void draw(SkCanvas* canvas) { |
| 2829 | SkPaint paint; |
| 2830 | paint.setAntiAlias(true); |
| 2831 | paint.setStyle(SkPaint::kStroke_Style); |
| 2832 | paint.setStrokeWidth(4); |
| 2833 | SkRect oval = { 4, 4, 60, 60}; |
| 2834 | float intervals[] = { 5, 5 }; |
| 2835 | paint.setPathEffect(SkDashPathEffect::Make(intervals, 2, 2.5f)); |
| 2836 | for (auto degrees : { 270, 360, 540, 720 } ) { |
| 2837 | canvas->drawArc(oval, 0, degrees, false, paint); |
| 2838 | canvas->translate(64, 0); |
| 2839 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2840 | } |
| 2841 | ## |
| 2842 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2843 | #SeeAlso SkPath::arcTo drawCircle drawOval drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2844 | |
| 2845 | ## |
| 2846 | |
| 2847 | # ------------------------------------------------------------------------------ |
| 2848 | |
| 2849 | #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] | 2850 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2851 | #Line # draws Round_Rect using Clip, Matrix, and Paint ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2852 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2853 | |
| 2854 | #Example |
| 2855 | #Description |
| 2856 | Top row has a zero radius a generates a rectangle. |
| 2857 | Second row radii sum to less than sides. |
| 2858 | Third row radii sum equals sides. |
| 2859 | Fourth row radii sum exceeds sides; radii are scaled to fit. |
| 2860 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2861 | void draw(SkCanvas* canvas) { |
| 2862 | SkVector radii[] = { {0, 20}, {10, 10}, {10, 20}, {10, 40} }; |
| 2863 | SkPaint paint; |
| 2864 | paint.setStrokeWidth(15); |
| 2865 | paint.setStrokeJoin(SkPaint::kRound_Join); |
| 2866 | paint.setAntiAlias(true); |
| 2867 | for (auto style : { SkPaint::kStroke_Style, SkPaint::kFill_Style } ) { |
| 2868 | paint.setStyle(style ); |
| 2869 | for (size_t i = 0; i < SK_ARRAY_COUNT(radii); ++i) { |
| 2870 | canvas->drawRoundRect({10, 10, 60, 40}, radii[i].fX, radii[i].fY, paint); |
| 2871 | canvas->translate(0, 60); |
| 2872 | } |
| 2873 | canvas->translate(80, -240); |
| 2874 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2875 | } |
| 2876 | ## |
| 2877 | |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 2878 | #SeeAlso drawRRect drawRect drawDRRect drawPath drawCircle drawOval drawPoint |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2879 | |
| 2880 | ## |
| 2881 | |
| 2882 | # ------------------------------------------------------------------------------ |
| 2883 | |
| 2884 | #Method void drawPath(const SkPath& path, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2885 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2886 | #Line # draws Path using Clip, Matrix, and Paint ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2887 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2888 | |
| 2889 | #Example |
| 2890 | #Description |
| 2891 | Top rows draw stroked path with combinations of joins and caps. The open contour |
| 2892 | is affected by caps; the closed contour is affected by joins. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2893 | Bottom row draws fill the same for open and closed contour. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2894 | First bottom column shows winding fills overlap. |
| 2895 | Second bottom column shows even odd fills exclude overlap. |
| 2896 | Third bottom column shows inverse winding fills area outside both contours. |
| 2897 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2898 | void draw(SkCanvas* canvas) { |
| 2899 | SkPath path; |
| 2900 | path.moveTo(20, 20); |
| 2901 | path.quadTo(60, 20, 60, 60); |
| 2902 | path.close(); |
| 2903 | path.moveTo(60, 20); |
| 2904 | path.quadTo(60, 60, 20, 60); |
| 2905 | SkPaint paint; |
| 2906 | paint.setStrokeWidth(10); |
| 2907 | paint.setAntiAlias(true); |
| 2908 | paint.setStyle(SkPaint::kStroke_Style); |
| 2909 | for (auto join: { SkPaint::kBevel_Join, SkPaint::kRound_Join, SkPaint::kMiter_Join } ) { |
| 2910 | paint.setStrokeJoin(join); |
| 2911 | for (auto cap: { SkPaint::kButt_Cap, SkPaint::kSquare_Cap, SkPaint::kRound_Cap } ) { |
| 2912 | paint.setStrokeCap(cap); |
| 2913 | canvas->drawPath(path, paint); |
| 2914 | canvas->translate(80, 0); |
| 2915 | } |
| 2916 | canvas->translate(-240, 60); |
| 2917 | } |
| 2918 | paint.setStyle(SkPaint::kFill_Style); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2919 | for (auto fill : { SkPath::kWinding_FillType, |
| 2920 | SkPath::kEvenOdd_FillType, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2921 | SkPath::kInverseWinding_FillType } ) { |
| 2922 | path.setFillType(fill); |
| 2923 | canvas->save(); |
| 2924 | canvas->clipRect({0, 10, 80, 70}); |
| 2925 | canvas->drawPath(path, paint); |
| 2926 | canvas->restore(); |
| 2927 | canvas->translate(80, 0); |
| 2928 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2929 | } |
| 2930 | ## |
| 2931 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2932 | #SeeAlso SkPath drawLine drawArc drawRect drawPoints |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2933 | |
| 2934 | ## |
| 2935 | |
| 2936 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2937 | #Subtopic Draw_Image |
| 2938 | #Line # draws Image to Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2939 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2940 | drawImage, drawImageRect, and drawImageNine can be called with a bare pointer or |
| 2941 | 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] | 2942 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 2943 | #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] | 2944 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2945 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2946 | #Line # draws Image at (x, y) position ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2947 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2948 | |
| 2949 | #Example |
| 2950 | #Height 64 |
| 2951 | #Image 4 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2952 | void draw(SkCanvas* canvas) { |
| 2953 | // sk_sp<SkImage> image; |
| 2954 | SkImage* imagePtr = image.get(); |
| 2955 | canvas->drawImage(imagePtr, 0, 0); |
| 2956 | SkPaint paint; |
| 2957 | canvas->drawImage(imagePtr, 80, 0, &paint); |
| 2958 | paint.setAlpha(0x80); |
| 2959 | canvas->drawImage(imagePtr, 160, 0, &paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2960 | } |
| 2961 | ## |
| 2962 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2963 | #SeeAlso drawBitmap drawImageLattice drawImageNine drawImageRect SkPaint::setImageFilter |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2964 | |
| 2965 | ## |
| 2966 | |
| 2967 | # ------------------------------------------------------------------------------ |
| 2968 | |
| 2969 | #Method void drawImage(const sk_sp<SkImage>& image, SkScalar left, SkScalar top, |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2970 | const SkPaint* paint = nullptr) |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 2971 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2972 | |
| 2973 | #Example |
| 2974 | #Height 64 |
| 2975 | #Image 4 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2976 | void draw(SkCanvas* canvas) { |
| 2977 | // sk_sp<SkImage> image; |
| 2978 | canvas->drawImage(image, 0, 0); |
| 2979 | SkPaint paint; |
| 2980 | canvas->drawImage(image, 80, 0, &paint); |
| 2981 | paint.setAlpha(0x80); |
| 2982 | canvas->drawImage(image, 160, 0, &paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2983 | } |
| 2984 | ## |
| 2985 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2986 | #SeeAlso drawBitmap drawImageLattice drawImageNine drawImageRect SkPaint::setImageFilter |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2987 | |
| 2988 | ## |
| 2989 | |
| 2990 | # ------------------------------------------------------------------------------ |
| 2991 | |
| 2992 | #Enum SrcRectConstraint |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2993 | #Line # sets drawImageRect options ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2994 | |
| 2995 | #Code |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 2996 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2997 | ## |
| 2998 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2999 | SrcRectConstraint controls the behavior at the edge of source Rect, |
| 3000 | provided to drawImageRect, trading off speed for precision. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3001 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3002 | 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] | 3003 | 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] | 3004 | 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] | 3005 | SrcRectConstraint specifies whether an Image_Filter is allowed to read pixels |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3006 | outside source Rect. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3007 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3008 | #Const kStrict_SrcRectConstraint 0 |
| 3009 | #Line # sample only inside bounds; slower ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3010 | Requires Image_Filter to respect source Rect, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3011 | sampling only inside of its bounds, possibly with a performance penalty. |
| 3012 | ## |
| 3013 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3014 | #Const kFast_SrcRectConstraint 1 |
| 3015 | #Line # sample outside bounds; faster ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3016 | Permits Image_Filter to sample outside of source Rect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3017 | by half the width of Image_Filter, permitting it to run faster but with |
| 3018 | error at the image edges. |
| 3019 | ## |
| 3020 | |
| 3021 | #Example |
| 3022 | #Height 64 |
| 3023 | #Description |
| 3024 | redBorder contains a black and white checkerboard bordered by red. |
| 3025 | redBorder is drawn scaled by 16 on the left. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3026 | The middle and right bitmaps are filtered checkerboards. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3027 | Drawing the checkerboard with kStrict_SrcRectConstraint shows only a blur of black and white. |
| 3028 | Drawing the checkerboard with kFast_SrcRectConstraint allows red to bleed in the corners. |
| 3029 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3030 | void draw(SkCanvas* canvas) { |
| 3031 | SkBitmap redBorder; |
| 3032 | redBorder.allocPixels(SkImageInfo::MakeN32Premul(4, 4)); |
| 3033 | SkCanvas checkRed(redBorder); |
| 3034 | checkRed.clear(SK_ColorRED); |
| 3035 | uint32_t checkers[][2] = { { SK_ColorBLACK, SK_ColorWHITE }, |
| 3036 | { SK_ColorWHITE, SK_ColorBLACK } }; |
| 3037 | checkRed.writePixels( |
| 3038 | SkImageInfo::MakeN32Premul(2, 2), (void*) checkers, sizeof(checkers[0]), 1, 1); |
| 3039 | canvas->scale(16, 16); |
| 3040 | canvas->drawBitmap(redBorder, 0, 0, nullptr); |
| 3041 | canvas->resetMatrix(); |
| 3042 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(redBorder); |
| 3043 | SkPaint lowPaint; |
| 3044 | lowPaint.setFilterQuality(kLow_SkFilterQuality); |
| 3045 | for (auto constraint : { SkCanvas::kStrict_SrcRectConstraint, |
| 3046 | SkCanvas::kFast_SrcRectConstraint } ) { |
| 3047 | canvas->translate(80, 0); |
| 3048 | canvas->drawImageRect(image.get(), SkRect::MakeLTRB(1, 1, 3, 3), |
| 3049 | SkRect::MakeLTRB(16, 16, 48, 48), &lowPaint, constraint); |
| 3050 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3051 | } |
| 3052 | ## |
| 3053 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3054 | #SeeAlso drawImageRect drawImage SkPaint::setImageFilter |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3055 | |
| 3056 | ## |
| 3057 | |
| 3058 | # ------------------------------------------------------------------------------ |
| 3059 | |
| 3060 | #Method void drawImageRect(const SkImage* image, const SkRect& src, const SkRect& dst, |
| 3061 | const SkPaint* paint, |
| 3062 | SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3063 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3064 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3065 | #Line # draws Image, source Rect to destination Rect ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 3066 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3067 | |
| 3068 | #Example |
| 3069 | #Height 64 |
| 3070 | #Description |
| 3071 | The left bitmap draws with Paint default kNone_SkFilterQuality, and stays within |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3072 | its bounds; there is no bleeding with kFast_SrcRectConstraint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3073 | the middle and right bitmaps draw with kLow_SkFilterQuality; with |
| 3074 | kStrict_SrcRectConstraint, the filter remains within the checkerboard, and |
| 3075 | with kFast_SrcRectConstraint red bleeds on the edges. |
| 3076 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3077 | void draw(SkCanvas* canvas) { |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3078 | uint32_t pixels[][4] = { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3079 | { 0xFFFF0000, 0xFFFF0000, 0xFFFF0000, 0xFFFF0000 }, |
| 3080 | { 0xFFFF0000, 0xFF000000, 0xFFFFFFFF, 0xFFFF0000 }, |
| 3081 | { 0xFFFF0000, 0xFFFFFFFF, 0xFF000000, 0xFFFF0000 }, |
| 3082 | { 0xFFFF0000, 0xFFFF0000, 0xFFFF0000, 0xFFFF0000 } }; |
| 3083 | SkBitmap redBorder; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3084 | redBorder.installPixels(SkImageInfo::MakeN32Premul(4, 4), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3085 | (void*) pixels, sizeof(pixels[0])); |
| 3086 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(redBorder); |
| 3087 | SkPaint lowPaint; |
| 3088 | for (auto constraint : { |
| 3089 | SkCanvas::kFast_SrcRectConstraint, |
| 3090 | SkCanvas::kStrict_SrcRectConstraint, |
| 3091 | SkCanvas::kFast_SrcRectConstraint } ) { |
| 3092 | canvas->drawImageRect(image.get(), SkRect::MakeLTRB(1, 1, 3, 3), |
| 3093 | SkRect::MakeLTRB(16, 16, 48, 48), &lowPaint, constraint); |
| 3094 | lowPaint.setFilterQuality(kLow_SkFilterQuality); |
| 3095 | canvas->translate(80, 0); |
| 3096 | } |
| 3097 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3098 | ## |
| 3099 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3100 | #SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3101 | |
| 3102 | ## |
| 3103 | |
| 3104 | # ------------------------------------------------------------------------------ |
| 3105 | |
| 3106 | #Method void drawImageRect(const SkImage* image, const SkIRect& isrc, const SkRect& dst, |
| 3107 | const SkPaint* paint, SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3108 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3109 | #In Draw |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 3110 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3111 | |
| 3112 | #Example |
| 3113 | #Image 4 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3114 | void draw(SkCanvas* canvas) { |
| 3115 | // sk_sp<SkImage> image; |
| 3116 | for (auto i : { 1, 2, 4, 8 } ) { |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3117 | canvas->drawImageRect(image.get(), SkIRect::MakeLTRB(0, 0, 100, 100), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3118 | SkRect::MakeXYWH(i * 20, i * 20, i * 20, i * 20), nullptr); |
| 3119 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3120 | } |
| 3121 | ## |
| 3122 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3123 | #SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3124 | |
| 3125 | ## |
| 3126 | |
| 3127 | # ------------------------------------------------------------------------------ |
| 3128 | |
Cary Clark | 0ac0edd | 2018-10-29 11:28:43 -0400 | [diff] [blame] | 3129 | #Method void drawImageRect(const SkImage* image, const SkRect& dst, const SkPaint* paint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3130 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3131 | #In Draw |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 3132 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3133 | |
| 3134 | #Example |
| 3135 | #Image 4 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3136 | void draw(SkCanvas* canvas) { |
| 3137 | // sk_sp<SkImage> image; |
| 3138 | for (auto i : { 20, 40, 80, 160 } ) { |
| 3139 | canvas->drawImageRect(image.get(), SkRect::MakeXYWH(i, i, i, i), nullptr); |
| 3140 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3141 | } |
| 3142 | ## |
| 3143 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3144 | #SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3145 | |
| 3146 | ## |
| 3147 | |
| 3148 | # ------------------------------------------------------------------------------ |
| 3149 | |
| 3150 | #Method void drawImageRect(const sk_sp<SkImage>& image, const SkRect& src, const SkRect& dst, |
| 3151 | const SkPaint* paint, |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3152 | SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3153 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3154 | #In Draw |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 3155 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3156 | |
| 3157 | #Example |
| 3158 | #Height 64 |
| 3159 | #Description |
| 3160 | Canvas scales and translates; transformation from src to dst also scales. |
| 3161 | The two matrices are concatenated to create the final transformation. |
| 3162 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3163 | void draw(SkCanvas* canvas) { |
| 3164 | uint32_t pixels[][2] = { { SK_ColorBLACK, SK_ColorWHITE }, |
| 3165 | { SK_ColorWHITE, SK_ColorBLACK } }; |
| 3166 | SkBitmap bitmap; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3167 | bitmap.installPixels(SkImageInfo::MakeN32Premul(2, 2), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3168 | (void*) pixels, sizeof(pixels[0])); |
| 3169 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 3170 | SkPaint paint; |
| 3171 | canvas->scale(4, 4); |
| 3172 | for (auto alpha : { 50, 100, 150, 255 } ) { |
| 3173 | paint.setAlpha(alpha); |
| 3174 | canvas->drawImageRect(image, SkRect::MakeWH(2, 2), SkRect::MakeWH(8, 8), &paint); |
| 3175 | canvas->translate(8, 0); |
| 3176 | } |
| 3177 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3178 | ## |
| 3179 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3180 | #SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3181 | |
| 3182 | ## |
| 3183 | |
| 3184 | # ------------------------------------------------------------------------------ |
| 3185 | |
| 3186 | #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] | 3187 | const SkPaint* paint, SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3188 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3189 | #In Draw |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 3190 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3191 | |
| 3192 | #Example |
| 3193 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3194 | void draw(SkCanvas* canvas) { |
| 3195 | uint32_t pixels[][2] = { { 0x00000000, 0x55555555}, |
| 3196 | { 0xAAAAAAAA, 0xFFFFFFFF} }; |
| 3197 | SkBitmap bitmap; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3198 | bitmap.installPixels(SkImageInfo::MakeN32Premul(2, 2), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3199 | (void*) pixels, sizeof(pixels[0])); |
| 3200 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 3201 | SkPaint paint; |
| 3202 | canvas->scale(4, 4); |
| 3203 | for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN } ) { |
| 3204 | paint.setColorFilter(SkColorFilter::MakeModeFilter(color, SkBlendMode::kPlus)); |
| 3205 | canvas->drawImageRect(image, SkIRect::MakeWH(2, 2), SkRect::MakeWH(8, 8), &paint); |
| 3206 | canvas->translate(8, 0); |
| 3207 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3208 | } |
| 3209 | ## |
| 3210 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3211 | #SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine |
| 3212 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3213 | ## |
| 3214 | |
| 3215 | # ------------------------------------------------------------------------------ |
| 3216 | |
Cary Clark | 0ac0edd | 2018-10-29 11:28:43 -0400 | [diff] [blame] | 3217 | #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] | 3218 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3219 | #In Draw |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 3220 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3221 | |
| 3222 | #Example |
| 3223 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3224 | void draw(SkCanvas* canvas) { |
| 3225 | uint32_t pixels[][2] = { { 0x00000000, 0x55550000}, |
| 3226 | { 0xAAAA0000, 0xFFFF0000} }; |
| 3227 | SkBitmap bitmap; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3228 | bitmap.installPixels(SkImageInfo::MakeN32Premul(2, 2), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3229 | (void*) pixels, sizeof(pixels[0])); |
| 3230 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 3231 | SkPaint paint; |
| 3232 | canvas->scale(4, 4); |
| 3233 | for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN } ) { |
| 3234 | paint.setColorFilter(SkColorFilter::MakeModeFilter(color, SkBlendMode::kPlus)); |
| 3235 | canvas->drawImageRect(image, SkRect::MakeWH(8, 8), &paint); |
| 3236 | canvas->translate(8, 0); |
| 3237 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3238 | } |
| 3239 | ## |
| 3240 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3241 | #SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3242 | |
| 3243 | ## |
| 3244 | |
| 3245 | # ------------------------------------------------------------------------------ |
| 3246 | |
| 3247 | #Method void drawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst, |
| 3248 | const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3249 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3250 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3251 | #Line # draws Nine_Patch Image ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3252 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3253 | Draws Image image stretched proportionally to fit into Rect dst. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3254 | 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] | 3255 | the center. Corners are unmodified or scaled down proportionately if their sides |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3256 | 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] | 3257 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3258 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
| 3259 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3260 | #paint_as_used_by_draw_lattice_or_draw_nine(image)# |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3261 | |
| 3262 | If generated mask extends beyond image bounds, replicate image edge colors, just |
| 3263 | as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3264 | replicates the image edge color when it samples outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3265 | |
| 3266 | #Param image Image containing pixels, dimensions, and format ## |
| 3267 | #Param center IRect edge of image corners and sides ## |
| 3268 | #Param dst destination Rect of image to draw to ## |
| 3269 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 3270 | and so on; or nullptr |
| 3271 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3272 | |
| 3273 | #Example |
| 3274 | #Height 128 |
| 3275 | #Description |
| 3276 | 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] | 3277 | The second image equals the size of center; only corners are drawn without scaling. |
| 3278 | The remaining images are larger than center. All corners draw without scaling. |
| 3279 | 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] | 3280 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3281 | void draw(SkCanvas* canvas) { |
| 3282 | SkIRect center = { 20, 10, 50, 40 }; |
| 3283 | SkBitmap bitmap; |
| 3284 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60)); |
| 3285 | SkCanvas bitCanvas(bitmap); |
| 3286 | SkPaint paint; |
| 3287 | SkColor gray = 0xFF000000; |
| 3288 | int left = 0; |
| 3289 | for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) { |
| 3290 | int top = 0; |
| 3291 | for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) { |
| 3292 | paint.setColor(gray); |
| 3293 | bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint); |
| 3294 | gray += 0x001f1f1f; |
| 3295 | top = bottom; |
| 3296 | } |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3297 | left = right; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3298 | } |
| 3299 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 3300 | SkImage* imagePtr = image.get(); |
| 3301 | for (auto dest: { 20, 30, 40, 60, 90 } ) { |
| 3302 | canvas->drawImageNine(imagePtr, center, SkRect::MakeWH(dest, dest), nullptr); |
| 3303 | canvas->translate(dest + 4, 0); |
| 3304 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3305 | } |
| 3306 | ## |
| 3307 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3308 | #SeeAlso drawImage drawBitmapNine drawImageLattice drawImageRect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3309 | |
| 3310 | ## |
| 3311 | |
| 3312 | # ------------------------------------------------------------------------------ |
| 3313 | |
| 3314 | #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] | 3315 | const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3316 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3317 | #In Draw |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3318 | Draws Image image stretched proportionally to fit into Rect dst. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3319 | 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] | 3320 | 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] | 3321 | 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] | 3322 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3323 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
| 3324 | |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 3325 | #paint_as_used_by_draw_lattice_or_draw_nine(image)# |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3326 | |
| 3327 | If generated mask extends beyond image bounds, replicate image edge colors, just |
| 3328 | as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3329 | replicates the image edge color when it samples outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3330 | |
| 3331 | #Param image Image containing pixels, dimensions, and format ## |
| 3332 | #Param center IRect edge of image corners and sides ## |
| 3333 | #Param dst destination Rect of image to draw to ## |
| 3334 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 3335 | and so on; or nullptr |
| 3336 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3337 | |
| 3338 | #Example |
| 3339 | #Height 128 |
| 3340 | #Description |
| 3341 | The two leftmost images has four corners and sides to the left and right of center. |
| 3342 | The leftmost image scales the width of corners proportionately to fit. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3343 | 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] | 3344 | fill the remaining space. |
| 3345 | The rightmost image has four corners scaled vertically to fit, and uses sides above |
| 3346 | and below center to fill the remaining space. |
| 3347 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3348 | void draw(SkCanvas* canvas) { |
| 3349 | SkIRect center = { 20, 10, 50, 40 }; |
| 3350 | SkBitmap bitmap; |
| 3351 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60)); |
| 3352 | SkCanvas bitCanvas(bitmap); |
| 3353 | SkPaint paint; |
| 3354 | SkColor gray = 0xFF000000; |
| 3355 | int left = 0; |
| 3356 | for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) { |
| 3357 | int top = 0; |
| 3358 | for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) { |
| 3359 | paint.setColor(gray); |
| 3360 | bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint); |
| 3361 | gray += 0x001f1f1f; |
| 3362 | top = bottom; |
| 3363 | } |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3364 | left = right; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3365 | } |
| 3366 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 3367 | for (auto dest: { 20, 30, 40, 60, 90 } ) { |
| 3368 | canvas->drawImageNine(image, center, SkRect::MakeWH(dest, 110 - dest), nullptr); |
| 3369 | canvas->translate(dest + 4, 0); |
| 3370 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3371 | } |
| 3372 | ## |
| 3373 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3374 | #SeeAlso drawImage drawBitmapNine drawImageLattice drawImageRect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3375 | |
| 3376 | ## |
| 3377 | |
| 3378 | # ------------------------------------------------------------------------------ |
| 3379 | |
| 3380 | #Method void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3381 | const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3382 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3383 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3384 | #Line # draws Bitmap at (x, y) position ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 3385 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3386 | |
| 3387 | #Example |
| 3388 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3389 | void draw(SkCanvas* canvas) { |
| 3390 | uint8_t pixels[][8] = { { 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00}, |
| 3391 | { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00}, |
| 3392 | { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00}, |
| 3393 | { 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF}, |
| 3394 | { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, |
| 3395 | { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00}, |
| 3396 | { 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00}, |
| 3397 | { 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF} }; |
| 3398 | SkBitmap bitmap; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3399 | bitmap.installPixels(SkImageInfo::MakeA8(8, 8), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3400 | (void*) pixels, sizeof(pixels[0])); |
| 3401 | SkPaint paint; |
| 3402 | canvas->scale(4, 4); |
| 3403 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xFF007F00} ) { |
| 3404 | paint.setColor(color); |
| 3405 | canvas->drawBitmap(bitmap, 0, 0, &paint); |
| 3406 | canvas->translate(12, 0); |
| 3407 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3408 | } |
| 3409 | ## |
| 3410 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3411 | #SeeAlso drawImage drawBitmapLattice drawBitmapNine drawBitmapRect SkBitmap::readPixels SkBitmap::writePixels |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3412 | |
| 3413 | ## |
| 3414 | |
| 3415 | # ------------------------------------------------------------------------------ |
| 3416 | |
| 3417 | #Method void drawBitmapRect(const SkBitmap& bitmap, const SkRect& src, const SkRect& dst, |
| 3418 | const SkPaint* paint, SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3419 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3420 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3421 | #Line # draws Bitmap, source Rect to destination Rect ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 3422 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3423 | |
| 3424 | #Example |
| 3425 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3426 | void draw(SkCanvas* canvas) { |
| 3427 | uint8_t pixels[][8] = { { 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00}, |
| 3428 | { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00}, |
| 3429 | { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00}, |
| 3430 | { 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF}, |
| 3431 | { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, |
| 3432 | { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00}, |
| 3433 | { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00}, |
| 3434 | { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00} }; |
| 3435 | SkBitmap bitmap; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3436 | bitmap.installPixels(SkImageInfo::MakeA8(8, 8), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3437 | (void*) pixels, sizeof(pixels[0])); |
| 3438 | SkPaint paint; |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 3439 | paint.setMaskFilter(SkMaskFilter::MakeBlur(kSolid_SkBlurStyle, 6)); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3440 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xFF007F00} ) { |
| 3441 | paint.setColor(color); |
| 3442 | canvas->drawBitmapRect(bitmap, SkRect::MakeWH(8, 8), SkRect::MakeWH(32, 32), &paint); |
| 3443 | canvas->translate(48, 0); |
| 3444 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3445 | } |
| 3446 | ## |
| 3447 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3448 | #SeeAlso drawImageRect drawBitmap drawBitmapLattice drawBitmapNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3449 | |
| 3450 | ## |
| 3451 | |
| 3452 | # ------------------------------------------------------------------------------ |
| 3453 | |
| 3454 | #Method void drawBitmapRect(const SkBitmap& bitmap, const SkIRect& isrc, const SkRect& dst, |
| 3455 | const SkPaint* paint, SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3456 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3457 | #In Draw |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 3458 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3459 | |
| 3460 | #Example |
| 3461 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3462 | void draw(SkCanvas* canvas) { |
| 3463 | uint8_t pixels[][8] = { { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00}, |
| 3464 | { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00}, |
| 3465 | { 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF}, |
| 3466 | { 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF}, |
| 3467 | { 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF}, |
| 3468 | { 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF}, |
| 3469 | { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00}, |
| 3470 | { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00} }; |
| 3471 | SkBitmap bitmap; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3472 | bitmap.installPixels(SkImageInfo::MakeA8(8, 8), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3473 | (void*) pixels, sizeof(pixels[0])); |
| 3474 | SkPaint paint; |
| 3475 | paint.setFilterQuality(kHigh_SkFilterQuality); |
| 3476 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xFF007F00, 0xFF7f007f} ) { |
| 3477 | paint.setColor(color); |
| 3478 | canvas->drawBitmapRect(bitmap, SkIRect::MakeWH(8, 8), SkRect::MakeWH(32, 32), &paint); |
| 3479 | canvas->translate(48.25f, 0); |
| 3480 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3481 | } |
| 3482 | ## |
| 3483 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3484 | #SeeAlso drawImageRect drawBitmap drawBitmapLattice drawBitmapNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3485 | |
| 3486 | ## |
| 3487 | |
| 3488 | # ------------------------------------------------------------------------------ |
| 3489 | |
| 3490 | #Method void drawBitmapRect(const SkBitmap& bitmap, const SkRect& dst, const SkPaint* paint, |
| 3491 | SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3492 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3493 | #In Draw |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 3494 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3495 | |
| 3496 | #Example |
| 3497 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3498 | void draw(SkCanvas* canvas) { |
| 3499 | uint32_t pixels[][2] = { { 0x00000000, 0x55550000}, |
| 3500 | { 0xAAAA0000, 0xFFFF0000} }; |
| 3501 | SkBitmap bitmap; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3502 | bitmap.installPixels(SkImageInfo::MakeN32Premul(2, 2), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3503 | (void*) pixels, sizeof(pixels[0])); |
| 3504 | SkPaint paint; |
| 3505 | canvas->scale(4, 4); |
| 3506 | for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN } ) { |
| 3507 | paint.setColorFilter(SkColorFilter::MakeModeFilter(color, SkBlendMode::kPlus)); |
| 3508 | canvas->drawBitmapRect(bitmap, SkRect::MakeWH(8, 8), &paint); |
| 3509 | canvas->translate(8, 0); |
| 3510 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3511 | } |
| 3512 | ## |
| 3513 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3514 | #SeeAlso drawImageRect drawBitmap drawBitmapLattice drawBitmapNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3515 | |
| 3516 | ## |
| 3517 | |
| 3518 | # ------------------------------------------------------------------------------ |
| 3519 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3520 | #PhraseDef paint_as_used_by_draw_lattice_or_draw_nine(bitmap_or_image) |
| 3521 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 3522 | Blend_Mode, and Draw_Looper. If #bitmap_or_image# is kAlpha_8_SkColorType, apply Shader. |
| 3523 | If paint contains Mask_Filter, generate mask from #bitmap_or_image# bounds. If paint |
| 3524 | Filter_Quality set to kNone_SkFilterQuality, disable pixel filtering. For all |
| 3525 | other values of paint Filter_Quality, use kLow_SkFilterQuality to filter pixels. |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 3526 | Any SkMaskFilter on paint is ignored as is paint Anti_Aliasing state. |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3527 | ## |
| 3528 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3529 | #Method void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3530 | const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3531 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3532 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3533 | #Line # draws Nine_Patch Bitmap ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3534 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3535 | Draws Bitmap bitmap stretched proportionally to fit into Rect dst. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3536 | IRect center divides the bitmap into nine sections: four sides, four corners, |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3537 | 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] | 3538 | sides are larger than dst; center and four sides are scaled to fit remaining |
| 3539 | space, if any. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3540 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3541 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
| 3542 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3543 | #paint_as_used_by_draw_lattice_or_draw_nine(bitmap)# |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3544 | |
| 3545 | If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, |
| 3546 | just as Shader made from SkShader::MakeBitmapShader with |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3547 | SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3548 | outside of its bounds. |
| 3549 | |
| 3550 | #Param bitmap Bitmap containing pixels, dimensions, and format ## |
| 3551 | #Param center IRect edge of image corners and sides ## |
| 3552 | #Param dst destination Rect of image to draw to ## |
| 3553 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 3554 | and so on; or nullptr |
| 3555 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3556 | |
| 3557 | #Example |
| 3558 | #Height 128 |
| 3559 | #Description |
| 3560 | The two leftmost bitmap draws has four corners and sides to the left and right of center. |
| 3561 | The leftmost bitmap draw scales the width of corners proportionately to fit. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3562 | 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] | 3563 | fill the remaining space. |
| 3564 | The rightmost bitmap draw has four corners scaled vertically to fit, and uses sides above |
| 3565 | and below center to fill the remaining space. |
| 3566 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3567 | void draw(SkCanvas* canvas) { |
| 3568 | SkIRect center = { 20, 10, 50, 40 }; |
| 3569 | SkBitmap bitmap; |
| 3570 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60)); |
| 3571 | SkCanvas bitCanvas(bitmap); |
| 3572 | SkPaint paint; |
| 3573 | SkColor gray = 0xFF000000; |
| 3574 | int left = 0; |
| 3575 | for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) { |
| 3576 | int top = 0; |
| 3577 | for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) { |
| 3578 | paint.setColor(gray); |
| 3579 | bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint); |
| 3580 | gray += 0x001f1f1f; |
| 3581 | top = bottom; |
| 3582 | } |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3583 | left = right; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3584 | } |
| 3585 | for (auto dest: { 20, 30, 40, 60, 90 } ) { |
| 3586 | canvas->drawBitmapNine(bitmap, center, SkRect::MakeWH(dest, 110 - dest), nullptr); |
| 3587 | canvas->translate(dest + 4, 0); |
| 3588 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3589 | } |
| 3590 | ## |
| 3591 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3592 | #SeeAlso drawImageNine drawBitmap drawBitmapLattice drawBitmapRect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3593 | |
| 3594 | ## |
| 3595 | |
| 3596 | # ------------------------------------------------------------------------------ |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3597 | #Subtopic Lattice |
| 3598 | #Line # divides Bitmap or Image into a rectangular grid ## |
| 3599 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3600 | #Struct Lattice |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3601 | #Line # divides Bitmap or Image into a rectangular grid ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3602 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3603 | #Code |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 3604 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3605 | ## |
| 3606 | |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 3607 | Lattice divides Bitmap or Image into a rectangular grid. |
| 3608 | Grid entries on even columns and even rows are fixed; these entries are |
| 3609 | always drawn at their original size if the destination is large enough. |
| 3610 | If the destination side is too small to hold the fixed entries, all fixed |
| 3611 | entries are proportionately scaled down to fit. |
| 3612 | The grid entries not on even columns and rows are scaled to fit the |
| 3613 | remaining space, if any. |
| 3614 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 3615 | #Enum RectType |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3616 | #Line # optional setting per rectangular grid entry ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3617 | #Code |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 3618 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3619 | ## |
| 3620 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 3621 | Optional setting per rectangular grid entry to make it transparent, |
| 3622 | or to fill the grid entry with a color. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3623 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 3624 | #Const kDefault 0 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3625 | #Line # draws Bitmap into lattice rectangle ## |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 3626 | ## |
| 3627 | |
| 3628 | #Const kTransparent 1 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3629 | #Line # skips lattice rectangle by making it transparent ## |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 3630 | ## |
| 3631 | |
| 3632 | #Const kFixedColor 2 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3633 | #Line # draws one of fColors into lattice rectangle ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3634 | ## |
| 3635 | ## |
| 3636 | |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 3637 | #Subtopic Members |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3638 | ## |
| 3639 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3640 | #Member const int* fXDivs |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 3641 | #Line # x-axis values dividing bitmap ## |
| 3642 | Array of x-axis values that divide the bitmap vertically. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3643 | Array entries must be unique, increasing, greater than or equal to |
| 3644 | fBounds left edge, and less than fBounds right edge. |
| 3645 | Set the first element to fBounds left to collapse the left column of |
| 3646 | fixed grid entries. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3647 | ## |
| 3648 | |
| 3649 | #Member const int* fYDivs |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 3650 | #Line # y-axis values dividing bitmap ## |
| 3651 | Array of y-axis values that divide the bitmap horizontally. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3652 | Array entries must be unique, increasing, greater than or equal to |
| 3653 | fBounds top edge, and less than fBounds bottom edge. |
| 3654 | Set the first element to fBounds top to collapse the top row of fixed |
| 3655 | grid entries. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3656 | ## |
| 3657 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 3658 | #Member const RectType* fRectTypes |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3659 | #Line # array of fill types ## |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 3660 | Optional array of fill types, one per rectangular grid entry: |
Cary Clark | 2be81cf | 2018-09-13 12:04:30 -0400 | [diff] [blame] | 3661 | array length must be #Formula # (fXCount + 1) * (fYCount + 1) ##. |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 3662 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 3663 | Each RectType is one of: kDefault, kTransparent, kFixedColor. |
| 3664 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3665 | Array entries correspond to the rectangular grid entries, ascending |
| 3666 | left to right and then top to bottom. |
| 3667 | ## |
| 3668 | |
| 3669 | #Member int fXCount |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3670 | #Line # number of x-coordinates ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3671 | Number of entries in fXDivs array; one less than the number of |
| 3672 | horizontal divisions. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3673 | ## |
| 3674 | |
| 3675 | #Member int fYCount |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3676 | #Line # number of y-coordinates ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3677 | Number of entries in fYDivs array; one less than the number of vertical |
| 3678 | divisions. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3679 | ## |
| 3680 | |
| 3681 | #Member const SkIRect* fBounds |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3682 | #Line # source bounds to draw from ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3683 | Optional subset IRect source to draw from. |
| 3684 | If nullptr, source bounds is dimensions of Bitmap or Image. |
| 3685 | ## |
| 3686 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 3687 | #Member const SkColor* fColors |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3688 | #Line # array of colors ## |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 3689 | Optional array of colors, one per rectangular grid entry. |
Cary Clark | 2be81cf | 2018-09-13 12:04:30 -0400 | [diff] [blame] | 3690 | Array length must be #Formula # (fXCount + 1) * (fYCount + 1) ##. |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 3691 | |
| 3692 | Array entries correspond to the rectangular grid entries, ascending |
| 3693 | left to right, then top to bottom. |
| 3694 | ## |
| 3695 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3696 | #Struct Lattice ## |
| 3697 | |
| 3698 | #Method void drawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice, const SkRect& dst, |
| 3699 | const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3700 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3701 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3702 | #Line # draws proportionally stretched Bitmap ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3703 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3704 | Draws Bitmap bitmap stretched proportionally to fit into Rect dst. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3705 | |
| 3706 | Lattice lattice divides bitmap into a rectangular grid. |
| 3707 | 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] | 3708 | of drawBitmapNine, fixed lattice elements never scale larger than their initial |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3709 | size and shrink proportionately when all fixed elements exceed the bitmap |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3710 | 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] | 3711 | |
| 3712 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3713 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3714 | #paint_as_used_by_draw_lattice_or_draw_nine(bitmap)# |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3715 | |
| 3716 | If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, |
| 3717 | just as Shader made from SkShader::MakeBitmapShader with |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3718 | SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3719 | outside of its bounds. |
| 3720 | |
| 3721 | #Param bitmap Bitmap containing pixels, dimensions, and format ## |
| 3722 | #Param lattice division of bitmap into fixed and variable rectangles ## |
| 3723 | #Param dst destination Rect of image to draw to ## |
| 3724 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 3725 | and so on; or nullptr |
| 3726 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3727 | |
| 3728 | #Example |
| 3729 | #Height 128 |
| 3730 | #Description |
| 3731 | The two leftmost bitmap draws has four corners and sides to the left and right of center. |
| 3732 | The leftmost bitmap draw scales the width of corners proportionately to fit. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3733 | 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] | 3734 | fill the remaining space; the center is transparent. |
| 3735 | The rightmost bitmap draw has four corners scaled vertically to fit, and uses sides above |
| 3736 | and below center to fill the remaining space. |
| 3737 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3738 | void draw(SkCanvas* canvas) { |
| 3739 | SkIRect center = { 20, 10, 50, 40 }; |
| 3740 | SkBitmap bitmap; |
| 3741 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60)); |
| 3742 | SkCanvas bitCanvas(bitmap); |
| 3743 | SkPaint paint; |
| 3744 | SkColor gray = 0xFF000000; |
| 3745 | int left = 0; |
| 3746 | for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) { |
| 3747 | int top = 0; |
| 3748 | for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) { |
| 3749 | paint.setColor(gray); |
| 3750 | bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint); |
| 3751 | gray += 0x001f1f1f; |
| 3752 | top = bottom; |
| 3753 | } |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3754 | left = right; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3755 | } |
| 3756 | const int xDivs[] = { center.fLeft, center.fRight }; |
| 3757 | const int yDivs[] = { center.fTop, center.fBottom }; |
Cary Clark | ca3ebcd | 2017-12-12 11:22:38 -0500 | [diff] [blame] | 3758 | SkCanvas::Lattice::RectType fillTypes[3][3]; |
| 3759 | memset(fillTypes, 0, sizeof(fillTypes)); |
| 3760 | fillTypes[1][1] = SkCanvas::Lattice::kTransparent; |
| 3761 | SkColor dummy[9]; // temporary pending bug fix |
| 3762 | SkCanvas::Lattice lattice = { xDivs, yDivs, fillTypes[0], SK_ARRAY_COUNT(xDivs), |
| 3763 | SK_ARRAY_COUNT(yDivs), nullptr, dummy }; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3764 | for (auto dest: { 20, 30, 40, 60, 90 } ) { |
Cary Clark | ca3ebcd | 2017-12-12 11:22:38 -0500 | [diff] [blame] | 3765 | canvas->drawBitmapLattice(bitmap, lattice, SkRect::MakeWH(dest, 110 - dest), nullptr); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3766 | canvas->translate(dest + 4, 0); |
| 3767 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3768 | } |
| 3769 | ## |
| 3770 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3771 | #SeeAlso drawImageLattice drawBitmap drawBitmapNine Lattice |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3772 | |
| 3773 | ## |
| 3774 | |
| 3775 | # ------------------------------------------------------------------------------ |
| 3776 | |
| 3777 | #Method void drawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst, |
| 3778 | const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3779 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3780 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3781 | #Line # draws proportionally stretched Image ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3782 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3783 | Draws Image image stretched proportionally to fit into Rect dst. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3784 | |
| 3785 | Lattice lattice divides image into a rectangular grid. |
| 3786 | 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] | 3787 | of drawBitmapNine, fixed lattice elements never scale larger than their initial |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3788 | size and shrink proportionately when all fixed elements exceed the bitmap |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3789 | 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] | 3790 | |
| 3791 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3792 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3793 | #paint_as_used_by_draw_lattice_or_draw_nine(image)# |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3794 | |
| 3795 | If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, |
| 3796 | just as Shader made from SkShader::MakeBitmapShader with |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3797 | SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3798 | outside of its bounds. |
| 3799 | |
| 3800 | #Param image Image containing pixels, dimensions, and format ## |
| 3801 | #Param lattice division of bitmap into fixed and variable rectangles ## |
| 3802 | #Param dst destination Rect of image to draw to ## |
| 3803 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 3804 | and so on; or nullptr |
| 3805 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3806 | |
| 3807 | #Example |
| 3808 | #Height 128 |
| 3809 | #Description |
| 3810 | 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] | 3811 | The second image equals the size of center; only corners are drawn without scaling. |
| 3812 | 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] | 3813 | are scaled if needed to take up the remaining space; the center is transparent. |
| 3814 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3815 | void draw(SkCanvas* canvas) { |
| 3816 | SkIRect center = { 20, 10, 50, 40 }; |
| 3817 | SkBitmap bitmap; |
| 3818 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60)); |
| 3819 | SkCanvas bitCanvas(bitmap); |
| 3820 | SkPaint paint; |
| 3821 | SkColor gray = 0xFF000000; |
| 3822 | int left = 0; |
| 3823 | for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) { |
| 3824 | int top = 0; |
| 3825 | for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) { |
| 3826 | paint.setColor(gray); |
| 3827 | bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint); |
| 3828 | gray += 0x001f1f1f; |
| 3829 | top = bottom; |
| 3830 | } |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3831 | left = right; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3832 | } |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3833 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 3834 | SkImage* imagePtr = image.get(); |
| 3835 | for (auto dest: { 20, 30, 40, 60, 90 } ) { |
| 3836 | canvas->drawImageNine(imagePtr, center, SkRect::MakeWH(dest, dest), nullptr); |
| 3837 | canvas->translate(dest + 4, 0); |
| 3838 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3839 | } |
| 3840 | ## |
| 3841 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3842 | #SeeAlso drawBitmapLattice drawImage drawImageNine Lattice |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3843 | |
| 3844 | ## |
| 3845 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3846 | #Subtopic Lattice ## |
| 3847 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3848 | #Subtopic Draw_Image ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3849 | |
| 3850 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3851 | #Subtopic Draw_Text |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3852 | #Line # draws text into Canvas ## |
| 3853 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3854 | |
Mike Reed | cb268f6 | 2019-01-07 12:51:32 -0500 | [diff] [blame] | 3855 | #Method void drawSimpleText(const void* text, size_t byteLength, SkTextEncoding encoding, |
| 3856 | SkScalar x, SkScalar y, const SkFont& font, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3857 | #In Draw_Text |
| 3858 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3859 | #Line # draws text at (x, y), using font advance ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 3860 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3861 | |
| 3862 | #Example |
| 3863 | #Height 200 |
| 3864 | #Description |
Mike Reed | cb268f6 | 2019-01-07 12:51:32 -0500 | [diff] [blame] | 3865 | The same text is drawn varying Paint_Text_Size and varying |
| 3866 | Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3867 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3868 | void draw(SkCanvas* canvas) { |
| 3869 | SkPaint paint; |
Mike Reed | cb268f6 | 2019-01-07 12:51:32 -0500 | [diff] [blame] | 3870 | SkFont font; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3871 | float textSizes[] = { 12, 18, 24, 36 }; |
| 3872 | for (auto size: textSizes ) { |
Mike Reed | cb268f6 | 2019-01-07 12:51:32 -0500 | [diff] [blame] | 3873 | font.setSize(size); |
Hal Canary | 35d1470 | 2019-01-15 11:57:41 -0500 | [diff] [blame] | 3874 | canvas->drawSimpleText("Aa", 2, kUTF8_SkTextEncoding, 10, 20, font, paint); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3875 | canvas->translate(0, size * 2); |
| 3876 | } |
Mike Reed | cb268f6 | 2019-01-07 12:51:32 -0500 | [diff] [blame] | 3877 | font.setSize(12); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3878 | float yPos = 20; |
| 3879 | for (auto size: textSizes ) { |
| 3880 | float scale = size / 12.f; |
| 3881 | canvas->resetMatrix(); |
| 3882 | canvas->translate(100, 0); |
| 3883 | canvas->scale(scale, scale); |
Hal Canary | 35d1470 | 2019-01-15 11:57:41 -0500 | [diff] [blame] | 3884 | canvas->drawSimpleText("Aa", 2, kUTF8_SkTextEncoding, |
| 3885 | 10 / scale, yPos / scale, font, paint); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3886 | yPos += size * 2; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3887 | } |
| 3888 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3889 | ## |
| 3890 | |
Mike Reed | 53a11f5 | 2019-01-03 12:18:06 -0500 | [diff] [blame] | 3891 | #SeeAlso drawString drawTextBlob |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3892 | |
| 3893 | ## |
| 3894 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3895 | # ------------------------------------------------------------------------------ |
| 3896 | |
| 3897 | #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] | 3898 | #In Draw_Text |
| 3899 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3900 | #Line # draws text with arrays of positions and Paint ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3901 | 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] | 3902 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3903 | blob contains Glyphs, their positions, and paint attributes specific to text: |
Cary Clark | 3e73dcf | 2018-12-06 08:41:14 -0500 | [diff] [blame] | 3904 | #font_metrics#. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3905 | |
Mike Reed | 0f9d33e | 2018-12-05 10:54:05 -0500 | [diff] [blame] | 3906 | Paint_Text_Encoding must be set to kGlyphID_SkTextEncoding. |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 3907 | |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 3908 | Elements of paint: Anti_Alias, Blend_Mode, Color including Color_Alpha, |
| 3909 | Color_Filter, Paint_Dither, Draw_Looper, Mask_Filter, Path_Effect, Shader, and |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 3910 | Paint_Style; apply to blob. If Paint contains SkPaint::kStroke_Style: |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 3911 | Paint_Miter_Limit, Paint_Stroke_Cap, Paint_Stroke_Join, and Paint_Stroke_Width; |
| 3912 | apply to Path created from blob. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3913 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3914 | #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] | 3915 | #Param x horizontal offset applied to blob ## |
| 3916 | #Param y vertical offset applied to blob ## |
| 3917 | #Param paint blend, color, stroking, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3918 | |
| 3919 | #Example |
| 3920 | #Height 120 |
Cary Clark | e80cd44 | 2018-07-17 13:19:56 -0400 | [diff] [blame] | 3921 | void draw(SkCanvas* canvas) { |
Mike Reed | 0f9d33e | 2018-12-05 10:54:05 -0500 | [diff] [blame] | 3922 | SkTextBlobBuilder textBlobBuilder; |
| 3923 | const char bunny[] = "/(^x^)\\"; |
| 3924 | const int len = sizeof(bunny) - 1; |
| 3925 | uint16_t glyphs[len]; |
Mike Reed | 0f9d33e | 2018-12-05 10:54:05 -0500 | [diff] [blame] | 3926 | SkFont font; |
Cary Clark | 26d173f | 2019-01-07 15:16:56 -0500 | [diff] [blame] | 3927 | font.textToGlyphs(bunny, len, SkTextEncoding::kUTF8, glyphs, len); |
Mike Reed | 0f9d33e | 2018-12-05 10:54:05 -0500 | [diff] [blame] | 3928 | int runs[] = { 3, 1, 3 }; |
| 3929 | SkPoint textPos = { 20, 100 }; |
| 3930 | int glyphIndex = 0; |
| 3931 | for (auto runLen : runs) { |
| 3932 | font.setSize(1 == runLen ? 20 : 50); |
| 3933 | const SkTextBlobBuilder::RunBuffer& run = |
| 3934 | textBlobBuilder.allocRun(font, runLen, textPos.fX, textPos.fY); |
| 3935 | memcpy(run.glyphs, &glyphs[glyphIndex], sizeof(glyphs[0]) * runLen); |
Cary Clark | 26d173f | 2019-01-07 15:16:56 -0500 | [diff] [blame] | 3936 | font.setSize(1 == runLen ? 20 : 50); |
| 3937 | textPos.fX += font.measureText(&glyphs[glyphIndex], sizeof(glyphs[0]) * runLen, |
| 3938 | SkTextEncoding::kGlyphID); |
Mike Reed | 0f9d33e | 2018-12-05 10:54:05 -0500 | [diff] [blame] | 3939 | glyphIndex += runLen; |
| 3940 | } |
| 3941 | sk_sp<const SkTextBlob> blob = textBlobBuilder.make(); |
Cary Clark | 26d173f | 2019-01-07 15:16:56 -0500 | [diff] [blame] | 3942 | canvas->drawTextBlob(blob.get(), 0, 0, SkPaint()); |
Cary Clark | e80cd44 | 2018-07-17 13:19:56 -0400 | [diff] [blame] | 3943 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3944 | ## |
| 3945 | |
Mike Reed | 53a11f5 | 2019-01-03 12:18:06 -0500 | [diff] [blame] | 3946 | #SeeAlso drawText |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3947 | |
| 3948 | ## |
| 3949 | |
| 3950 | # ------------------------------------------------------------------------------ |
| 3951 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3952 | #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] | 3953 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3954 | 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] | 3955 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3956 | blob contains Glyphs, their positions, and paint attributes specific to text: |
Cary Clark | 3e73dcf | 2018-12-06 08:41:14 -0500 | [diff] [blame] | 3957 | #font_metrics#. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3958 | |
Mike Reed | 0f9d33e | 2018-12-05 10:54:05 -0500 | [diff] [blame] | 3959 | Paint_Text_Encoding must be set to kGlyphID_SkTextEncoding. |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 3960 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3961 | Elements of paint: Path_Effect, Mask_Filter, Shader, Color_Filter, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3962 | Image_Filter, and Draw_Looper; apply to blob. |
| 3963 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3964 | #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] | 3965 | #Param x horizontal offset applied to blob ## |
| 3966 | #Param y vertical offset applied to blob ## |
| 3967 | #Param paint blend, color, stroking, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3968 | |
| 3969 | #Example |
| 3970 | #Height 120 |
| 3971 | #Description |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3972 | Paint attributes related to text, like text size, have no effect on paint passed to drawTextBlob. |
| 3973 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3974 | void draw(SkCanvas* canvas) { |
| 3975 | SkTextBlobBuilder textBlobBuilder; |
Cary Clark | fc93eb0 | 2018-11-24 22:32:31 -0500 | [diff] [blame] | 3976 | SkFont font; |
| 3977 | font.setSize(50); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3978 | const SkTextBlobBuilder::RunBuffer& run = |
Cary Clark | fc93eb0 | 2018-11-24 22:32:31 -0500 | [diff] [blame] | 3979 | textBlobBuilder.allocRun(font, 1, 20, 100); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3980 | run.glyphs[0] = 20; |
| 3981 | sk_sp<const SkTextBlob> blob = textBlobBuilder.make(); |
Cary Clark | fc93eb0 | 2018-11-24 22:32:31 -0500 | [diff] [blame] | 3982 | SkPaint paint; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3983 | paint.setTextSize(10); |
| 3984 | paint.setColor(SK_ColorBLUE); |
| 3985 | canvas->drawTextBlob(blob.get(), 0, 0, paint); |
| 3986 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3987 | ## |
| 3988 | |
Mike Reed | 53a11f5 | 2019-01-03 12:18:06 -0500 | [diff] [blame] | 3989 | #SeeAlso drawText |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3990 | |
| 3991 | ## |
| 3992 | |
| 3993 | # ------------------------------------------------------------------------------ |
| 3994 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3995 | #Method void drawPicture(const SkPicture* picture) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3996 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3997 | #Line # draws Picture using Clip and Matrix ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 3998 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3999 | |
| 4000 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4001 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4002 | SkPictureRecorder recorder; |
| 4003 | SkCanvas* recordingCanvas = recorder.beginRecording(50, 50); |
| 4004 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) { |
| 4005 | SkPaint paint; |
| 4006 | paint.setColor(color); |
| 4007 | recordingCanvas->drawRect({10, 10, 30, 40}, paint); |
| 4008 | recordingCanvas->translate(10, 10); |
| 4009 | recordingCanvas->scale(1.2f, 1.4f); |
| 4010 | } |
| 4011 | sk_sp<SkPicture> playback = recorder.finishRecordingAsPicture(); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4012 | canvas->drawPicture(playback); |
| 4013 | canvas->scale(2, 2); |
| 4014 | canvas->translate(50, 0); |
| 4015 | canvas->drawPicture(playback); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4016 | } |
| 4017 | ## |
| 4018 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4019 | #SeeAlso drawDrawable SkPicture SkPicture::playback |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4020 | |
| 4021 | ## |
| 4022 | |
| 4023 | # ------------------------------------------------------------------------------ |
| 4024 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4025 | #Method void drawPicture(const sk_sp<SkPicture>& picture) |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4026 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4027 | |
| 4028 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4029 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4030 | SkPictureRecorder recorder; |
| 4031 | SkCanvas* recordingCanvas = recorder.beginRecording(50, 50); |
| 4032 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) { |
| 4033 | SkPaint paint; |
| 4034 | paint.setColor(color); |
| 4035 | recordingCanvas->drawRect({10, 10, 30, 40}, paint); |
| 4036 | recordingCanvas->translate(10, 10); |
| 4037 | recordingCanvas->scale(1.2f, 1.4f); |
| 4038 | } |
| 4039 | sk_sp<SkPicture> playback = recorder.finishRecordingAsPicture(); |
| 4040 | canvas->drawPicture(playback); |
| 4041 | canvas->scale(2, 2); |
| 4042 | canvas->translate(50, 0); |
| 4043 | canvas->drawPicture(playback); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4044 | } |
| 4045 | ## |
| 4046 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4047 | #SeeAlso drawDrawable SkPicture SkPicture::playback |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4048 | |
| 4049 | ## |
| 4050 | |
| 4051 | # ------------------------------------------------------------------------------ |
| 4052 | |
| 4053 | #Method void drawPicture(const SkPicture* picture, const SkMatrix* matrix, const SkPaint* paint) |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4054 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4055 | |
| 4056 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4057 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4058 | SkPaint paint; |
| 4059 | SkPictureRecorder recorder; |
| 4060 | SkCanvas* recordingCanvas = recorder.beginRecording(50, 50); |
| 4061 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) { |
| 4062 | paint.setColor(color); |
| 4063 | recordingCanvas->drawRect({10, 10, 30, 40}, paint); |
| 4064 | recordingCanvas->translate(10, 10); |
| 4065 | recordingCanvas->scale(1.2f, 1.4f); |
| 4066 | } |
| 4067 | sk_sp<SkPicture> playback = recorder.finishRecordingAsPicture(); |
| 4068 | const SkPicture* playbackPtr = playback.get(); |
| 4069 | SkMatrix matrix; |
| 4070 | matrix.reset(); |
| 4071 | for (auto alpha : { 70, 140, 210 } ) { |
| 4072 | paint.setAlpha(alpha); |
| 4073 | canvas->drawPicture(playbackPtr, &matrix, &paint); |
| 4074 | matrix.preTranslate(70, 70); |
| 4075 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4076 | } |
| 4077 | ## |
| 4078 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4079 | #SeeAlso drawDrawable SkPicture SkPicture::playback |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4080 | |
| 4081 | ## |
| 4082 | |
| 4083 | # ------------------------------------------------------------------------------ |
| 4084 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4085 | #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] | 4086 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4087 | |
| 4088 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4089 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4090 | SkPaint paint; |
| 4091 | SkPictureRecorder recorder; |
| 4092 | SkCanvas* recordingCanvas = recorder.beginRecording(50, 50); |
| 4093 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) { |
| 4094 | paint.setColor(color); |
| 4095 | recordingCanvas->drawRect({10, 10, 30, 40}, paint); |
| 4096 | recordingCanvas->translate(10, 10); |
| 4097 | recordingCanvas->scale(1.2f, 1.4f); |
| 4098 | } |
| 4099 | sk_sp<SkPicture> playback = recorder.finishRecordingAsPicture(); |
| 4100 | SkMatrix matrix; |
| 4101 | matrix.reset(); |
| 4102 | for (auto alpha : { 70, 140, 210 } ) { |
| 4103 | paint.setAlpha(alpha); |
| 4104 | canvas->drawPicture(playback, &matrix, &paint); |
| 4105 | matrix.preTranslate(70, 70); |
| 4106 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4107 | } |
| 4108 | ## |
| 4109 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4110 | #SeeAlso drawDrawable SkPicture SkPicture::playback |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4111 | |
| 4112 | ## |
| 4113 | |
| 4114 | # ------------------------------------------------------------------------------ |
| 4115 | |
| 4116 | #Method void drawVertices(const SkVertices* vertices, SkBlendMode mode, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4117 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4118 | #Line # draws Vertices, a triangle mesh ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4119 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4120 | |
| 4121 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4122 | void draw(SkCanvas* canvas) { |
| 4123 | SkPaint paint; |
| 4124 | SkPoint points[] = { { 0, 0 }, { 250, 0 }, { 100, 100 }, { 0, 250 } }; |
| 4125 | SkColor colors[] = { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorCYAN }; |
| 4126 | auto vertices = SkVertices::MakeCopy(SkVertices::kTriangleFan_VertexMode, |
| 4127 | SK_ARRAY_COUNT(points), points, nullptr, colors); |
| 4128 | canvas->drawVertices(vertices.get(), SkBlendMode::kSrc, paint); |
| 4129 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4130 | ## |
| 4131 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4132 | #SeeAlso drawPatch drawPicture |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4133 | |
| 4134 | ## |
| 4135 | |
| 4136 | # ------------------------------------------------------------------------------ |
| 4137 | |
| 4138 | #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] | 4139 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4140 | |
| 4141 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4142 | void draw(SkCanvas* canvas) { |
| 4143 | SkPaint paint; |
| 4144 | SkPoint points[] = { { 0, 0 }, { 250, 0 }, { 100, 100 }, { 0, 250 } }; |
| 4145 | SkPoint texs[] = { { 0, 0 }, { 0, 250 }, { 250, 250 }, { 250, 0 } }; |
| 4146 | SkColor colors[] = { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorCYAN }; |
| 4147 | paint.setShader(SkGradientShader::MakeLinear(points, colors, nullptr, 4, |
| 4148 | SkShader::kClamp_TileMode)); |
| 4149 | auto vertices = SkVertices::MakeCopy(SkVertices::kTriangleFan_VertexMode, |
| 4150 | SK_ARRAY_COUNT(points), points, texs, colors); |
Ruiqi Mao | 94d57c4 | 2018-07-02 15:20:10 -0400 | [diff] [blame] | 4151 | canvas->drawVertices(vertices, SkBlendMode::kDarken, paint); |
| 4152 | } |
| 4153 | ## |
| 4154 | |
| 4155 | #SeeAlso drawPatch drawPicture |
| 4156 | |
| 4157 | ## |
| 4158 | |
| 4159 | # ------------------------------------------------------------------------------ |
| 4160 | |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 4161 | #Method void drawVertices(const SkVertices* vertices, const SkVertices::Bone bones[], |
| 4162 | int boneCount, SkBlendMode mode, const SkPaint& paint) |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4163 | #Populate |
Ruiqi Mao | 94d57c4 | 2018-07-02 15:20:10 -0400 | [diff] [blame] | 4164 | |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 4165 | #NoExample |
Ruiqi Mao | 94d57c4 | 2018-07-02 15:20:10 -0400 | [diff] [blame] | 4166 | void draw(SkCanvas* canvas) { |
| 4167 | SkPaint paint; |
| 4168 | SkPoint points[] = { { 0, 0 }, { 250, 0 }, { 100, 100 }, { 0, 250 } }; |
| 4169 | SkPoint texs[] = { { 0, 0 }, { 0, 250 }, { 250, 250 }, { 250, 0 } }; |
| 4170 | SkColor colors[] = { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorCYAN }; |
| 4171 | SkVertices::BoneIndices boneIndices[] = { { 0, 0, 0, 0 }, |
| 4172 | { 1, 0, 0, 0 }, |
| 4173 | { 2, 0, 0, 0 }, |
| 4174 | { 3, 0, 0, 0 } }; |
| 4175 | SkVertices::BoneWeights boneWeights[] = { { 0.0f, 0.0f, 0.0f, 0.0f }, |
| 4176 | { 1.0f, 0.0f, 0.0f, 0.0f }, |
| 4177 | { 1.0f, 0.0f, 0.0f, 0.0f }, |
| 4178 | { 1.0f, 0.0f, 0.0f, 0.0f } }; |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 4179 | SkVertices::Bone bones[] = { {{ 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f }}, |
| 4180 | {{ 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 20.0f }}, |
| 4181 | {{ 1.0f, 0.0f, 0.0f, 1.0f, 50.0f, 50.0f }}, |
| 4182 | {{ 1.0f, 0.0f, 0.0f, 1.0f, 20.0f, 0.0f }} }; |
Ruiqi Mao | 94d57c4 | 2018-07-02 15:20:10 -0400 | [diff] [blame] | 4183 | paint.setShader(SkGradientShader::MakeLinear(points, colors, nullptr, 4, |
| 4184 | SkShader::kClamp_TileMode)); |
| 4185 | auto vertices = SkVertices::MakeCopy(SkVertices::kTriangleFan_VertexMode, |
| 4186 | SK_ARRAY_COUNT(points), points, texs, colors, boneIndices, boneWeights); |
| 4187 | canvas->drawVertices(vertices.get(), bones, SK_ARRAY_COUNT(bones), SkBlendMode::kDarken, paint); |
| 4188 | } |
| 4189 | ## |
| 4190 | |
| 4191 | #SeeAlso drawPatch drawPicture |
| 4192 | |
| 4193 | ## |
| 4194 | |
| 4195 | # ------------------------------------------------------------------------------ |
| 4196 | |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 4197 | #Method void drawVertices(const sk_sp<SkVertices>& vertices, const SkVertices::Bone bones[], |
| 4198 | int boneCount, SkBlendMode mode, const SkPaint& paint) |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4199 | #Populate |
Ruiqi Mao | 94d57c4 | 2018-07-02 15:20:10 -0400 | [diff] [blame] | 4200 | |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 4201 | #NoExample |
Ruiqi Mao | 94d57c4 | 2018-07-02 15:20:10 -0400 | [diff] [blame] | 4202 | void draw(SkCanvas* canvas) { |
| 4203 | SkPaint paint; |
| 4204 | SkPoint points[] = { { 0, 0 }, { 250, 0 }, { 100, 100 }, { 0, 250 } }; |
| 4205 | SkPoint texs[] = { { 0, 0 }, { 0, 250 }, { 250, 250 }, { 250, 0 } }; |
| 4206 | SkColor colors[] = { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorCYAN }; |
| 4207 | SkVertices::BoneIndices boneIndices[] = { { 0, 0, 0, 0 }, |
| 4208 | { 1, 0, 0, 0 }, |
| 4209 | { 2, 0, 0, 0 }, |
| 4210 | { 3, 0, 0, 0 } }; |
| 4211 | SkVertices::BoneWeights boneWeights[] = { { 0.0f, 0.0f, 0.0f, 0.0f }, |
| 4212 | { 1.0f, 0.0f, 0.0f, 0.0f }, |
| 4213 | { 1.0f, 0.0f, 0.0f, 0.0f }, |
| 4214 | { 1.0f, 0.0f, 0.0f, 0.0f } }; |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 4215 | SkVertices::Bone bones[] = { {{ 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f }}, |
| 4216 | {{ 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 20.0f }}, |
| 4217 | {{ 1.0f, 0.0f, 0.0f, 1.0f, 50.0f, 50.0f }}, |
| 4218 | {{ 1.0f, 0.0f, 0.0f, 1.0f, 20.0f, 0.0f }} }; |
Ruiqi Mao | 94d57c4 | 2018-07-02 15:20:10 -0400 | [diff] [blame] | 4219 | paint.setShader(SkGradientShader::MakeLinear(points, colors, nullptr, 4, |
| 4220 | SkShader::kClamp_TileMode)); |
| 4221 | auto vertices = SkVertices::MakeCopy(SkVertices::kTriangleFan_VertexMode, |
| 4222 | SK_ARRAY_COUNT(points), points, texs, colors, boneIndices, boneWeights); |
| 4223 | canvas->drawVertices(vertices, bones, SK_ARRAY_COUNT(bones), SkBlendMode::kDarken, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4224 | } |
| 4225 | ## |
| 4226 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4227 | #SeeAlso drawPatch drawPicture |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4228 | |
| 4229 | ## |
| 4230 | |
| 4231 | # ------------------------------------------------------------------------------ |
| 4232 | |
| 4233 | #Method void drawPatch(const SkPoint cubics[12], const SkColor colors[4], |
| 4234 | const SkPoint texCoords[4], SkBlendMode mode, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4235 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4236 | #Line # draws Coons_Patch ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4237 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4238 | |
| 4239 | #Example |
| 4240 | #Image 5 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4241 | void draw(SkCanvas* canvas) { |
| 4242 | // SkBitmap source = cmbkygk; |
| 4243 | SkPaint paint; |
| 4244 | paint.setFilterQuality(kLow_SkFilterQuality); |
| 4245 | paint.setAntiAlias(true); |
| 4246 | SkPoint cubics[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, |
| 4247 | /* { 7, 3 }, */ { 6, 4 }, { 7, 5 }, { 5, 7 }, |
| 4248 | /* { 5, 7 }, */ { 4, 6 }, { 3, 7 }, { 1, 5 }, |
| 4249 | /* { 1, 5 }, */ { 2, 4 }, { 1, 3 }, /* { 3, 1 } */ }; |
| 4250 | SkColor colors[] = { 0xbfff0000, 0xbf0000ff, 0xbfff00ff, 0xbf00ffff }; |
| 4251 | SkPoint texCoords[] = { { -30, -30 }, { 162, -30}, { 162, 162}, { -30, 162} }; |
| 4252 | paint.setShader(SkShader::MakeBitmapShader(source, SkShader::kClamp_TileMode, |
| 4253 | SkShader::kClamp_TileMode, nullptr)); |
| 4254 | canvas->scale(15, 15); |
| 4255 | for (auto blend : { SkBlendMode::kSrcOver, SkBlendMode::kModulate, SkBlendMode::kXor } ) { |
| 4256 | canvas->drawPatch(cubics, colors, texCoords, blend, paint); |
| 4257 | canvas->translate(4, 4); |
| 4258 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4259 | } |
| 4260 | ## |
| 4261 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4262 | #ToDo can patch use image filter? ## |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 4263 | #SeeAlso drawVertices drawPicture |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4264 | |
| 4265 | ## |
| 4266 | |
| 4267 | # ------------------------------------------------------------------------------ |
| 4268 | |
| 4269 | #Method void drawPatch(const SkPoint cubics[12], const SkColor colors[4], |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4270 | const SkPoint texCoords[4], const SkPaint& paint) |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4271 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4272 | |
| 4273 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4274 | void draw(SkCanvas* canvas) { |
| 4275 | SkPaint paint; |
| 4276 | paint.setAntiAlias(true); |
| 4277 | SkPoint cubics[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, |
| 4278 | /* { 7, 3 }, */ { 6, 4 }, { 7, 5 }, { 5, 7 }, |
| 4279 | /* { 5, 7 }, */ { 4, 6 }, { 3, 7 }, { 1, 5 }, |
| 4280 | /* { 1, 5 }, */ { 2, 4 }, { 1, 3 }, /* { 3, 1 } */ }; |
| 4281 | SkColor colors[] = { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorCYAN }; |
| 4282 | canvas->scale(30, 30); |
| 4283 | canvas->drawPatch(cubics, colors, nullptr, paint); |
| 4284 | SkPoint text[] = { {3,0.9f}, {4,2.5f}, {5,0.9f}, {7.5f,3.2f}, {5.5f,4.2f}, |
| 4285 | {7.5f,5.2f}, {5,7.5f}, {4,5.9f}, {3,7.5f}, {0.5f,5.2f}, {2.5f,4.2f}, |
| 4286 | {0.5f,3.2f} }; |
Mike Reed | 33535cb | 2019-01-09 11:25:18 -0500 | [diff] [blame] | 4287 | |
| 4288 | SkFont font(nullptr, 18.f / 30); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4289 | for (int i = 0; i< 10; ++i) { |
| 4290 | char digit = '0' + i; |
Mike Reed | 33535cb | 2019-01-09 11:25:18 -0500 | [diff] [blame] | 4291 | canvas->drawSimpleText(&digit, kUTF8_SkTextEncoding, 1, text[i].fX, text[i].fY, font, paint); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4292 | } |
Mike Reed | 33535cb | 2019-01-09 11:25:18 -0500 | [diff] [blame] | 4293 | canvas->drawString("10", text[10].fX, text[10].fY, font, paint); |
| 4294 | canvas->drawString("11", text[11].fX, text[11].fY, font, paint); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4295 | paint.setStyle(SkPaint::kStroke_Style); |
| 4296 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, 12, cubics, paint); |
| 4297 | 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] | 4298 | } |
| 4299 | ## |
| 4300 | |
| 4301 | #Example |
| 4302 | #Image 6 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4303 | void draw(SkCanvas* canvas) { |
| 4304 | // SkBitmap source = checkerboard; |
| 4305 | SkPaint paint; |
| 4306 | paint.setFilterQuality(kLow_SkFilterQuality); |
| 4307 | paint.setAntiAlias(true); |
| 4308 | SkPoint cubics[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, |
| 4309 | /* { 7, 3 }, */ { 6, 4 }, { 7, 5 }, { 5, 7 }, |
| 4310 | /* { 5, 7 }, */ { 4, 6 }, { 3, 7 }, { 1, 5 }, |
| 4311 | /* { 1, 5 }, */ { 2, 4 }, { 1, 3 }, /* { 3, 1 } */ }; |
| 4312 | SkPoint texCoords[] = { { 0, 0 }, { 0, 62}, { 62, 62}, { 62, 0 } }; |
| 4313 | paint.setShader(SkShader::MakeBitmapShader(source, SkShader::kClamp_TileMode, |
| 4314 | SkShader::kClamp_TileMode, nullptr)); |
| 4315 | canvas->scale(30, 30); |
| 4316 | canvas->drawPatch(cubics, nullptr, texCoords, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4317 | } |
| 4318 | ## |
| 4319 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4320 | #ToDo can patch use image filter? ## |
Cary Clark | 77b3f3a | 2018-11-07 14:59:03 -0500 | [diff] [blame] | 4321 | #SeeAlso drawVertices drawPicture |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4322 | |
| 4323 | ## |
| 4324 | |
| 4325 | # ------------------------------------------------------------------------------ |
| 4326 | |
| 4327 | #Method void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], |
| 4328 | const SkColor colors[], int count, SkBlendMode mode, const SkRect* cullRect, |
| 4329 | const SkPaint* paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4330 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4331 | #Line # draws sprites using Clip, Matrix, and Paint ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4332 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4333 | |
| 4334 | #Example |
| 4335 | #Image 3 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4336 | void draw(SkCanvas* canvas) { |
| 4337 | // SkBitmap source = mandrill; |
| 4338 | SkRSXform xforms[] = { { .5f, 0, 0, 0 }, {0, .5f, 200, 100 } }; |
| 4339 | SkRect tex[] = { { 0, 0, 250, 250 }, { 0, 0, 250, 250 } }; |
| 4340 | SkColor colors[] = { 0x7f55aa00, 0x7f3333bf }; |
| 4341 | const SkImage* imagePtr = image.get(); |
| 4342 | canvas->drawAtlas(imagePtr, xforms, tex, colors, 2, SkBlendMode::kSrcOver, nullptr, nullptr); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4343 | } |
| 4344 | ## |
| 4345 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4346 | #SeeAlso drawBitmap drawImage |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4347 | |
| 4348 | ## |
| 4349 | |
| 4350 | # ------------------------------------------------------------------------------ |
| 4351 | |
| 4352 | #Method void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[], |
| 4353 | const SkColor colors[], int count, SkBlendMode mode, const SkRect* cullRect, |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4354 | const SkPaint* paint) |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4355 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4356 | |
| 4357 | #Example |
| 4358 | #Image 3 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4359 | void draw(SkCanvas* canvas) { |
| 4360 | // SkBitmap source = mandrill; |
| 4361 | SkRSXform xforms[] = { { .5f, 0, 0, 0 }, {0, .5f, 200, 100 } }; |
| 4362 | SkRect tex[] = { { 0, 0, 250, 250 }, { 0, 0, 250, 250 } }; |
| 4363 | SkColor colors[] = { 0x7f55aa00, 0x7f3333bf }; |
| 4364 | SkPaint paint; |
| 4365 | paint.setAlpha(127); |
| 4366 | canvas->drawAtlas(image, xforms, tex, colors, 2, SkBlendMode::kPlus, nullptr, &paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4367 | } |
| 4368 | ## |
| 4369 | |
| 4370 | #ToDo bug in example on cpu side, gpu looks ok ## |
| 4371 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4372 | #SeeAlso drawBitmap drawImage |
| 4373 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4374 | ## |
| 4375 | |
| 4376 | # ------------------------------------------------------------------------------ |
| 4377 | |
| 4378 | #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] | 4379 | const SkRect* cullRect, const SkPaint* paint) |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4380 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4381 | |
| 4382 | #Example |
| 4383 | #Image 3 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4384 | void draw(SkCanvas* canvas) { |
| 4385 | // sk_sp<SkImage> image = mandrill; |
| 4386 | SkRSXform xforms[] = { { .5f, 0, 0, 0 }, {0, .5f, 200, 100 } }; |
| 4387 | SkRect tex[] = { { 0, 0, 250, 250 }, { 0, 0, 250, 250 } }; |
| 4388 | const SkImage* imagePtr = image.get(); |
| 4389 | canvas->drawAtlas(imagePtr, xforms, tex, 2, nullptr, nullptr); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4390 | } |
| 4391 | ## |
| 4392 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4393 | #SeeAlso drawBitmap drawImage |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4394 | |
| 4395 | ## |
| 4396 | |
| 4397 | # ------------------------------------------------------------------------------ |
| 4398 | |
| 4399 | #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] | 4400 | int count, const SkRect* cullRect, const SkPaint* paint) |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4401 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4402 | |
| 4403 | #Example |
| 4404 | #Image 3 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4405 | void draw(SkCanvas* canvas) { |
| 4406 | // sk_sp<SkImage> image = mandrill; |
| 4407 | SkRSXform xforms[] = { { 1, 0, 0, 0 }, {0, 1, 300, 100 } }; |
| 4408 | SkRect tex[] = { { 0, 0, 200, 200 }, { 200, 0, 400, 200 } }; |
| 4409 | canvas->drawAtlas(image, xforms, tex, 2, nullptr, nullptr); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4410 | } |
| 4411 | ## |
| 4412 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4413 | #SeeAlso drawBitmap drawImage |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4414 | |
| 4415 | ## |
| 4416 | |
| 4417 | # ------------------------------------------------------------------------------ |
| 4418 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4419 | #Method void drawDrawable(SkDrawable* drawable, const SkMatrix* matrix = nullptr) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4420 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4421 | #Line # draws Drawable, encapsulated drawing commands ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4422 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4423 | |
| 4424 | #Example |
| 4425 | #Height 100 |
| 4426 | #Function |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4427 | struct MyDrawable : public SkDrawable { |
| 4428 | SkRect onGetBounds() override { return SkRect::MakeWH(50, 100); } |
| 4429 | |
| 4430 | void onDraw(SkCanvas* canvas) override { |
| 4431 | SkPath path; |
| 4432 | path.conicTo(10, 90, 50, 90, 0.9f); |
| 4433 | SkPaint paint; |
| 4434 | paint.setColor(SK_ColorBLUE); |
| 4435 | canvas->drawRect(path.getBounds(), paint); |
| 4436 | paint.setAntiAlias(true); |
| 4437 | paint.setColor(SK_ColorWHITE); |
| 4438 | canvas->drawPath(path, paint); |
| 4439 | } |
| 4440 | }; |
| 4441 | |
| 4442 | #Function ## |
| 4443 | void draw(SkCanvas* canvas) { |
| 4444 | sk_sp<SkDrawable> drawable(new MyDrawable); |
| 4445 | SkMatrix matrix; |
| 4446 | matrix.setTranslate(10, 10); |
| 4447 | canvas->drawDrawable(drawable.get(), &matrix); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4448 | } |
| 4449 | ## |
| 4450 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4451 | #SeeAlso SkDrawable drawPicture |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4452 | |
| 4453 | ## |
| 4454 | |
| 4455 | # ------------------------------------------------------------------------------ |
| 4456 | |
| 4457 | #Method void drawDrawable(SkDrawable* drawable, SkScalar x, SkScalar y) |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4458 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4459 | |
| 4460 | #Example |
| 4461 | #Height 100 |
| 4462 | #Function |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4463 | struct MyDrawable : public SkDrawable { |
| 4464 | SkRect onGetBounds() override { return SkRect::MakeWH(50, 100); } |
| 4465 | |
| 4466 | void onDraw(SkCanvas* canvas) override { |
| 4467 | SkPath path; |
| 4468 | path.conicTo(10, 90, 50, 90, 0.9f); |
| 4469 | SkPaint paint; |
| 4470 | paint.setColor(SK_ColorBLUE); |
| 4471 | canvas->drawRect(path.getBounds(), paint); |
| 4472 | paint.setAntiAlias(true); |
| 4473 | paint.setColor(SK_ColorWHITE); |
| 4474 | canvas->drawPath(path, paint); |
| 4475 | } |
| 4476 | }; |
| 4477 | |
| 4478 | #Function ## |
| 4479 | void draw(SkCanvas* canvas) { |
| 4480 | sk_sp<SkDrawable> drawable(new MyDrawable); |
| 4481 | canvas->drawDrawable(drawable.get(), 10, 10); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4482 | } |
| 4483 | ## |
| 4484 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4485 | #SeeAlso SkDrawable drawPicture |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4486 | |
| 4487 | ## |
| 4488 | |
| 4489 | # ------------------------------------------------------------------------------ |
| 4490 | |
| 4491 | #Method void drawAnnotation(const SkRect& rect, const char key[], SkData* value) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4492 | #In Draw |
| 4493 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4494 | #Line # associates a Rect with a key-value pair ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4495 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4496 | |
| 4497 | #Example |
| 4498 | #Height 1 |
| 4499 | const char text[] = "Click this link!"; |
| 4500 | SkRect bounds; |
| 4501 | SkPaint paint; |
Cary Clark | 26d173f | 2019-01-07 15:16:56 -0500 | [diff] [blame] | 4502 | SkFont font(nullptr, 40); |
| 4503 | (void)font.measureText(text, strlen(text), SkTextEncoding::kUTF8, &bounds); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4504 | const char url[] = "https://www.google.com/"; |
| 4505 | sk_sp<SkData> urlData(SkData::MakeWithCString(url)); |
| 4506 | canvas->drawAnnotation(bounds, "url_key", urlData.get()); |
| 4507 | ## |
| 4508 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4509 | #SeeAlso SkPicture SkDocument |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4510 | |
| 4511 | ## |
| 4512 | |
| 4513 | # ------------------------------------------------------------------------------ |
| 4514 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4515 | #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] | 4516 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4517 | |
| 4518 | #Example |
| 4519 | #Height 1 |
| 4520 | const char text[] = "Click this link!"; |
| 4521 | SkRect bounds; |
| 4522 | SkPaint paint; |
Cary Clark | 26d173f | 2019-01-07 15:16:56 -0500 | [diff] [blame] | 4523 | SkFont font(nullptr, 40); |
| 4524 | (void)font.measureText(text, strlen(text), SkTextEncoding::kUTF8, &bounds); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4525 | const char url[] = "https://www.google.com/"; |
| 4526 | sk_sp<SkData> urlData(SkData::MakeWithCString(url)); |
| 4527 | canvas->drawAnnotation(bounds, "url_key", urlData.get()); |
| 4528 | ## |
| 4529 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4530 | #SeeAlso SkPicture SkDocument |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4531 | |
| 4532 | ## |
| 4533 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4534 | # ------------------------------------------------------------------------------ |
| 4535 | |
| 4536 | #Method virtual bool isClipEmpty() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4537 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4538 | #Line # returns if Clip is empty ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4539 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4540 | |
| 4541 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4542 | void draw(SkCanvas* canvas) { |
| 4543 | SkDebugf("clip is%s empty\n", canvas->isClipEmpty() ? "" : " not"); |
| 4544 | SkPath path; |
| 4545 | canvas->clipPath(path); |
| 4546 | SkDebugf("clip is%s empty\n", canvas->isClipEmpty() ? "" : " not"); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4547 | } |
| 4548 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4549 | clip is not empty |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4550 | clip is empty |
| 4551 | ## |
| 4552 | ## |
| 4553 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4554 | #SeeAlso isClipRect getLocalClipBounds getDeviceClipBounds |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4555 | |
| 4556 | ## |
| 4557 | |
| 4558 | # ------------------------------------------------------------------------------ |
| 4559 | |
| 4560 | #Method virtual bool isClipRect() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4561 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4562 | #Line # returns if Clip is Rect and not empty ## |
Cary Clark | 09d80c0 | 2018-10-31 12:14:03 -0400 | [diff] [blame] | 4563 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4564 | |
| 4565 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4566 | void draw(SkCanvas* canvas) { |
| 4567 | SkDebugf("clip is%s rect\n", canvas->isClipRect() ? "" : " not"); |
| 4568 | canvas->clipRect({0, 0, 0, 0}); |
| 4569 | SkDebugf("clip is%s rect\n", canvas->isClipRect() ? "" : " not"); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4570 | } |
| 4571 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4572 | clip is rect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4573 | clip is not rect |
| 4574 | ## |
| 4575 | ## |
| 4576 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4577 | #SeeAlso isClipEmpty getLocalClipBounds getDeviceClipBounds |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4578 | |
| 4579 | ## |
| 4580 | |
| 4581 | #Class SkCanvas ## |
Cary Clark | 884dd7d | 2017-10-11 10:37:52 -0400 | [diff] [blame] | 4582 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4583 | #Topic Canvas ## |