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 | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6 | Canvas provides an interface for drawing, and how the drawing is clipped and transformed. |
| 7 | Canvas contains a stack of Matrix and Clip values. |
| 8 | |
| 9 | 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] | 10 | Each Canvas draw call transforms the geometry of the object by the concatenation of all |
| 11 | Matrix values in the stack. The transformed geometry is clipped by the intersection |
| 12 | of all of Clip values in the stack. The Canvas draw calls use Paint to supply drawing |
| 13 | 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] | 14 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 15 | To draw to a pixel-based destination, create Raster_Surface or GPU_Surface. |
| 16 | Request Canvas from Surface to obtain the interface to draw. |
| 17 | Canvas generated by Raster_Surface draws to memory visible to the CPU. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 18 | Canvas generated by GPU_Surface uses Vulkan or OpenGL to draw to the GPU. |
| 19 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 20 | To draw to a document, obtain Canvas from SVG_Canvas, Document_PDF, or Picture_Recorder. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 21 | Document based Canvas and other Canvas Subclasses reference Device describing the |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 22 | destination. |
| 23 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 24 | 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] | 25 | This approach may be deprecated in the future. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 26 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 27 | #Subtopic Overview |
| 28 | #Populate |
| 29 | ## |
| 30 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 31 | #Subtopic Related_Function |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 32 | #Populate |
| 33 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 34 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 35 | #Subtopic Constant |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 36 | #Populate |
| 37 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 38 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 39 | #Subtopic Struct |
| 40 | #Populate |
| 41 | ## |
| 42 | |
| 43 | #Subtopic Typedef |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 44 | #Populate |
| 45 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 46 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 47 | #Subtopic Constructor |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 48 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 49 | Create the desired type of Surface to obtain its Canvas when possible. Useful |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 50 | when no Surface is required, and some helpers implicitly create Raster_Surface. |
| 51 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 52 | #Populate |
| 53 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 54 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 55 | #Subtopic Member_Function |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 56 | #Populate |
| 57 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 58 | |
| 59 | # ------------------------------------------------------------------------------ |
| 60 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 61 | #Method static std::unique_ptr<SkCanvas> MakeRasterDirect(const SkImageInfo& info, void* pixels, |
| 62 | size_t rowBytes, |
| 63 | const SkSurfaceProps* props = nullptr) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 64 | #In Constructor |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 65 | #Line # creates from SkImageInfo and Pixel_Storage ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 66 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 67 | Allocates raster Canvas that will draw directly into pixels. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 68 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 69 | Canvas is returned if all parameters are valid. |
| 70 | Valid parameters include: |
| 71 | info dimensions are zero or positive; |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 72 | info contains Color_Type and Alpha_Type supported by Raster_Surface; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 73 | pixels is not nullptr; |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 74 | rowBytes is zero or large enough to contain info width pixels of Color_Type. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 75 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 76 | Pass zero for rowBytes to compute rowBytes from info width and size of pixel. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 77 | If rowBytes is greater than zero, it must be equal to or greater than |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 78 | info width times bytes required for Color_Type. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 79 | |
| 80 | Pixel buffer size should be info height times computed rowBytes. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 81 | Pixels are not initialized. |
| 82 | To access pixels after drawing, call flush() or peekPixels. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 83 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 84 | #Param info width, height, Color_Type, Alpha_Type, Color_Space, of Raster_Surface; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 85 | width, or height, or both, may be zero |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 86 | ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 87 | #Param pixels pointer to destination pixels buffer |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 88 | ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 89 | #Param rowBytes interval from one Surface row to the next, or zero |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 90 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 91 | #Param props LCD striping orientation and setting for device independent fonts; |
| 92 | may be nullptr |
| 93 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 94 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 95 | #Return Canvas if all parameters are valid; otherwise, nullptr ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 96 | |
| 97 | #Example |
| 98 | #Description |
| 99 | Allocates a three by three bitmap, clears it to white, and draws a black pixel |
| 100 | in the center. |
| 101 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 102 | void draw(SkCanvas* ) { |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 103 | SkImageInfo info = SkImageInfo::MakeN32Premul(3, 3); // device aligned, 32 bpp, Premultiplied |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 104 | const size_t minRowBytes = info.minRowBytes(); // bytes used by one bitmap row |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 105 | const size_t size = info.computeMinByteSize(); // bytes used by all rows |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 106 | SkAutoTMalloc<SkPMColor> storage(size); // allocate storage for pixels |
| 107 | SkPMColor* pixels = storage.get(); // get pointer to allocated storage |
| 108 | // create a SkCanvas backed by a raster device, and delete it when the |
| 109 | // function goes out of scope. |
| 110 | std::unique_ptr<SkCanvas> canvas = SkCanvas::MakeRasterDirect(info, pixels, minRowBytes); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 111 | canvas->clear(SK_ColorWHITE); // white is Unpremultiplied, in ARGB order |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 112 | canvas->flush(); // ensure that pixels are cleared |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 113 | SkPMColor pmWhite = pixels[0]; // the Premultiplied format may vary |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 114 | SkPaint paint; // by default, draws black |
| 115 | canvas->drawPoint(1, 1, paint); // draw in the center |
| 116 | canvas->flush(); // ensure that point was drawn |
| 117 | for (int y = 0; y < info.height(); ++y) { |
| 118 | for (int x = 0; x < info.width(); ++x) { |
| 119 | SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x'); |
| 120 | } |
| 121 | SkDebugf("\n"); |
| 122 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 123 | } |
| 124 | #StdOut |
| 125 | --- |
| 126 | -x- |
| 127 | --- |
| 128 | ## |
| 129 | ## |
| 130 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 131 | #SeeAlso MakeRasterDirectN32 SkSurface::MakeRasterDirect |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 132 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 133 | ## |
| 134 | |
| 135 | # ------------------------------------------------------------------------------ |
| 136 | |
| 137 | #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] | 138 | size_t rowBytes) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 139 | #In Constructor |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 140 | #Line # creates from image data and Pixel_Storage ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 141 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 142 | Allocates raster Canvas specified by inline image specification. Subsequent Canvas |
| 143 | calls draw into pixels. |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 144 | Color_Type is set to kN32_SkColorType. |
| 145 | Alpha_Type is set to kPremul_SkAlphaType. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 146 | To access pixels after drawing, call flush() or peekPixels. |
| 147 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 148 | Canvas is returned if all parameters are valid. |
| 149 | Valid parameters include: |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 150 | width and height are zero or positive; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 151 | pixels is not nullptr; |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 152 | rowBytes is zero or large enough to contain width pixels of kN32_SkColorType. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 153 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 154 | Pass zero for rowBytes to compute rowBytes from width and size of pixel. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 155 | If rowBytes is greater than zero, it must be equal to or greater than |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 156 | width times bytes required for Color_Type. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 157 | |
| 158 | Pixel buffer size should be height times rowBytes. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 159 | |
| 160 | #Param width pixel column count on Raster_Surface created; must be zero or greater ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 161 | #Param height pixel row count on Raster_Surface created; must be zero or greater ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 162 | #Param pixels pointer to destination pixels buffer; buffer size should be height |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 163 | times rowBytes |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 164 | ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 165 | #Param rowBytes interval from one Surface row to the next, or zero |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 166 | ## |
| 167 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 168 | #Return Canvas if all parameters are valid; otherwise, nullptr ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 169 | |
| 170 | #Example |
| 171 | #Description |
| 172 | Allocates a three by three bitmap, clears it to white, and draws a black pixel |
| 173 | in the center. |
| 174 | ## |
| 175 | void draw(SkCanvas* ) { |
| 176 | const int width = 3; |
| 177 | const int height = 3; |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 178 | SkPMColor pixels[height][width]; // allocate a 3x3 Premultiplied bitmap on the stack |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 179 | // create a SkCanvas backed by a raster device, and delete it when the |
| 180 | // function goes out of scope. |
| 181 | std::unique_ptr<SkCanvas> canvas = SkCanvas::MakeRasterDirectN32( |
| 182 | width, |
| 183 | height, |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 184 | pixels[0], // top-left of the bitmap |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 185 | sizeof(pixels[0])); // byte width of the each row |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 186 | // write a Premultiplied value for white into all pixels in the bitmap |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 187 | canvas->clear(SK_ColorWHITE); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 188 | SkPMColor pmWhite = pixels[0][0]; // the Premultiplied format may vary |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 189 | SkPaint paint; // by default, draws black |
| 190 | canvas->drawPoint(1, 1, paint); // draw in the center |
| 191 | canvas->flush(); // ensure that pixels is ready to be read |
| 192 | for (int y = 0; y < height; ++y) { |
| 193 | for (int x = 0; x < width; ++x) { |
| 194 | SkDebugf("%c", pixels[y][x] == pmWhite ? '-' : 'x'); |
| 195 | } |
| 196 | SkDebugf("\n"); |
| 197 | } |
| 198 | } |
| 199 | #StdOut |
| 200 | --- |
| 201 | -x- |
| 202 | --- |
| 203 | ## |
| 204 | ## |
| 205 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 206 | #SeeAlso MakeRasterDirect SkSurface::MakeRasterDirect SkImageInfo::MakeN32Premul |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 207 | |
| 208 | ## |
| 209 | |
| 210 | # ------------------------------------------------------------------------------ |
| 211 | |
| 212 | #Method SkCanvas() |
| 213 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 214 | #Line # creates with no Surface, no dimensions ## |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 215 | Creates an empty Canvas with no backing device or pixels, with |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 216 | a width and height of zero. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 217 | |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 218 | #Return empty Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 219 | |
| 220 | #Example |
| 221 | |
| 222 | #Description |
| 223 | Passes a placeholder to a function that requires one. |
| 224 | ## |
| 225 | |
| 226 | #Function |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 227 | // Returns true if either the canvas rotates the text by 90 degrees, or the paint does. |
| 228 | static void check_for_up_and_down_text(const SkCanvas* canvas, const SkPaint& paint) { |
| 229 | bool paintHasVertical = paint.isVerticalText(); |
| 230 | const SkMatrix& matrix = canvas->getTotalMatrix(); |
| 231 | bool matrixIsVertical = matrix.preservesRightAngles() && !matrix.isScaleTranslate(); |
| 232 | SkDebugf("paint draws text %s\n", paintHasVertical != matrixIsVertical ? |
| 233 | "top to bottom" : "left to right"); |
| 234 | } |
| 235 | |
| 236 | static void check_for_up_and_down_text(const SkPaint& paint) { |
| 237 | SkCanvas canvas; // placeholder only, does not have an associated device |
| 238 | check_for_up_and_down_text(&canvas, paint); |
| 239 | } |
| 240 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 241 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 242 | void draw(SkCanvas* canvas) { |
| 243 | SkPaint paint; |
| 244 | check_for_up_and_down_text(paint); // paint draws text left to right |
| 245 | paint.setVerticalText(true); |
| 246 | check_for_up_and_down_text(paint); // paint draws text top to bottom |
| 247 | paint.setVerticalText(false); |
| 248 | canvas->rotate(90); |
| 249 | check_for_up_and_down_text(canvas, paint); // paint draws text top to bottom |
| 250 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 251 | |
| 252 | #StdOut |
| 253 | paint draws text left to right |
| 254 | paint draws text top to bottom |
| 255 | paint draws text top to bottom |
| 256 | ## |
| 257 | ## |
| 258 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 259 | #SeeAlso MakeRasterDirect SkRasterHandleAllocator::MakeCanvas SkSurface::getCanvas SkCreateColorSpaceXformCanvas |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 260 | |
| 261 | ## |
| 262 | |
| 263 | # ------------------------------------------------------------------------------ |
| 264 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 265 | #Method SkCanvas(int width, int height, const SkSurfaceProps* props = nullptr) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 266 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 267 | #Line # creates with no Surface, set dimensions, Surface_Properties ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 268 | Creates Canvas of the specified dimensions without a Surface. |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 269 | Used by Subclasses with custom implementations for draw member functions. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 270 | |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 271 | If props equals nullptr, Surface_Properties are created with |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 272 | Surface_Properties_Legacy_Font_Host settings, which choose the pixel striping |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 273 | direction and order. Since a platform may dynamically change its direction when |
| 274 | the device is rotated, and since a platform may have multiple monitors with |
| 275 | different characteristics, it is best not to rely on this legacy behavior. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 276 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 277 | #Param width zero or greater ## |
| 278 | #Param height zero or greater ## |
| 279 | #Param props LCD striping orientation and setting for device independent fonts; |
| 280 | may be nullptr |
| 281 | ## |
| 282 | |
| 283 | #Return Canvas placeholder with dimensions ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 284 | |
| 285 | #Example |
| 286 | SkCanvas canvas(10, 20); // 10 units wide, 20 units high |
| 287 | canvas.clipRect(SkRect::MakeXYWH(30, 40, 5, 10)); // clip is outside canvas' device |
| 288 | SkDebugf("canvas %s empty\n", canvas.getDeviceClipBounds().isEmpty() ? "is" : "is not"); |
| 289 | |
| 290 | #StdOut |
| 291 | canvas is empty |
| 292 | ## |
| 293 | ## |
| 294 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 295 | #SeeAlso MakeRasterDirect SkSurfaceProps SkPixelGeometry SkCreateColorSpaceXformCanvas |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 296 | |
| 297 | ## |
| 298 | |
| 299 | # ------------------------------------------------------------------------------ |
| 300 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 301 | #Method explicit SkCanvas(sk_sp<SkBaseDevice> device) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 302 | #Deprecated soon |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 303 | ## |
| 304 | |
| 305 | # ------------------------------------------------------------------------------ |
| 306 | |
| 307 | #Method explicit SkCanvas(const SkBitmap& bitmap) |
| 308 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 309 | #Line # uses existing Bitmap ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 310 | Constructs a canvas that draws into bitmap. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 311 | Sets SkSurfaceProps::kLegacyFontHost_InitType in constructed Surface. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 312 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 313 | Bitmap is copied so that subsequently editing bitmap will not affect |
| 314 | constructed Canvas. |
| 315 | |
| 316 | May be deprecated in the future. |
| 317 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 318 | #ToDo Should be deprecated? ## |
| 319 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 320 | #Param bitmap width, height, Color_Type, Alpha_Type, and pixel |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 321 | storage of Raster_Surface |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 322 | ## |
| 323 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 324 | #Return Canvas that can be used to draw into bitmap ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 325 | |
| 326 | #Example |
| 327 | #Description |
| 328 | The actual output depends on the installed fonts. |
| 329 | ## |
| 330 | SkBitmap bitmap; |
| 331 | // create a bitmap 5 wide and 11 high |
| 332 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(5, 11)); |
| 333 | SkCanvas canvas(bitmap); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 334 | canvas.clear(SK_ColorWHITE); // white is Unpremultiplied, in ARGB order |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 335 | SkPixmap pixmap; // provides guaranteed access to the drawn pixels |
| 336 | if (!canvas.peekPixels(&pixmap)) { |
| 337 | SkDebugf("peekPixels should never fail.\n"); |
| 338 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 339 | const SkPMColor* pixels = pixmap.addr32(); // points to top-left of bitmap |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 340 | SkPMColor pmWhite = pixels[0]; // the Premultiplied format may vary |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 341 | SkPaint paint; // by default, draws black, 12 point text |
| 342 | canvas.drawString("!", 1, 10, paint); // 1 char at baseline (1, 10) |
| 343 | for (int y = 0; y < bitmap.height(); ++y) { |
| 344 | for (int x = 0; x < bitmap.width(); ++x) { |
| 345 | SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x'); |
| 346 | } |
| 347 | SkDebugf("\n"); |
| 348 | } |
| 349 | |
| 350 | #StdOut |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 351 | ----- |
| 352 | ---x- |
| 353 | ---x- |
| 354 | ---x- |
| 355 | ---x- |
| 356 | ---x- |
| 357 | ---x- |
| 358 | ----- |
| 359 | ---x- |
| 360 | ---x- |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 361 | ----- |
| 362 | #StdOut ## |
| 363 | ## |
| 364 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 365 | #SeeAlso MakeRasterDirect SkRasterHandleAllocator::MakeCanvas SkSurface::getCanvas SkCreateColorSpaceXformCanvas |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 366 | |
| 367 | ## |
| 368 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 369 | #EnumClass ColorBehavior |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 370 | #Line # exists for Android framework only ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 371 | #Private |
| 372 | Android framework only. |
| 373 | ## |
| 374 | |
| 375 | #Code |
| 376 | enum class ColorBehavior { |
| 377 | kLegacy, |
| 378 | }; |
| 379 | ## |
| 380 | #Const kLegacy 0 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 381 | #Line # placeholder ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 382 | Is a placeholder to allow specialized constructor; has no meaning. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 383 | ## |
| 384 | ## |
| 385 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 386 | #Method SkCanvas(const SkBitmap& bitmap, ColorBehavior behavior) |
| 387 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 388 | #Line # exists for Android framework only ## |
| 389 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 390 | For use by Android framework only. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 391 | |
| 392 | #Param bitmap specifies a bitmap for the canvas to draw into ## |
| 393 | #Param behavior specializes this constructor; value is unused ## |
| 394 | #Return Canvas that can be used to draw into bitmap ## |
| 395 | |
| 396 | #NoExample |
| 397 | ## |
| 398 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 399 | |
| 400 | # ------------------------------------------------------------------------------ |
| 401 | |
| 402 | #Method SkCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props) |
| 403 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 404 | #Line # uses existing Bitmap and Surface_Properties ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 405 | Constructs a canvas that draws into bitmap. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 406 | Use props to match the device characteristics, like LCD striping. |
| 407 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 408 | bitmap is copied so that subsequently editing bitmap will not affect |
| 409 | constructed Canvas. |
| 410 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 411 | #Param bitmap width, height, Color_Type, Alpha_Type, |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 412 | and pixel storage of Raster_Surface |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 413 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 414 | #Param props order and orientation of RGB striping; and whether to use |
| 415 | device independent fonts |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 416 | ## |
| 417 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 418 | #Return Canvas that can be used to draw into bitmap ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 419 | |
| 420 | #Example |
| 421 | #Description |
| 422 | The actual output depends on the installed fonts. |
| 423 | ## |
| 424 | SkBitmap bitmap; |
| 425 | // create a bitmap 5 wide and 11 high |
| 426 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(5, 11)); |
| 427 | SkCanvas canvas(bitmap, SkSurfaceProps(0, kUnknown_SkPixelGeometry)); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 428 | canvas.clear(SK_ColorWHITE); // white is Unpremultiplied, in ARGB order |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 429 | SkPixmap pixmap; // provides guaranteed access to the drawn pixels |
| 430 | if (!canvas.peekPixels(&pixmap)) { |
| 431 | SkDebugf("peekPixels should never fail.\n"); |
| 432 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 433 | const SkPMColor* pixels = pixmap.addr32(); // points to top-left of bitmap |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 434 | SkPMColor pmWhite = pixels[0]; // the Premultiplied format may vary |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 435 | SkPaint paint; // by default, draws black, 12 point text |
| 436 | canvas.drawString("!", 1, 10, paint); // 1 char at baseline (1, 10) |
| 437 | for (int y = 0; y < bitmap.height(); ++y) { |
| 438 | for (int x = 0; x < bitmap.width(); ++x) { |
| 439 | SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x'); |
| 440 | } |
| 441 | SkDebugf("\n"); |
| 442 | } |
| 443 | |
| 444 | #StdOut |
| 445 | ----- |
| 446 | ---x- |
| 447 | ---x- |
| 448 | ---x- |
| 449 | ---x- |
| 450 | ---x- |
| 451 | ---x- |
| 452 | ----- |
| 453 | ---x- |
| 454 | ---x- |
| 455 | ----- |
| 456 | #StdOut ## |
| 457 | ## |
| 458 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 459 | #SeeAlso MakeRasterDirect SkRasterHandleAllocator::MakeCanvas SkSurface::getCanvas SkCreateColorSpaceXformCanvas |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 460 | |
| 461 | ## |
| 462 | |
| 463 | # ------------------------------------------------------------------------------ |
| 464 | |
| 465 | #Method virtual ~SkCanvas() |
| 466 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 467 | #Line # draws saved Layers, frees resources ## |
Cary Clark | 5081eed | 2018-01-22 07:55:48 -0500 | [diff] [blame] | 468 | Draws saved Layers, if any. |
| 469 | Frees up resources used by Canvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 470 | |
| 471 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 472 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 473 | Canvas Layer draws into bitmap. saveLayerAlpha sets up an additional |
| 474 | drawing surface that blends with the bitmap. When Layer goes out of |
| 475 | scope, Layer Destructor is called. The saved Layer is restored, drawing |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 476 | transparent letters. |
| 477 | ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 478 | void draw(SkCanvas* canvas) { |
| 479 | SkBitmap bitmap; |
| 480 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(200, 200)); |
| 481 | { |
| 482 | SkCanvas offscreen(bitmap); |
| 483 | SkPaint paint; |
| 484 | paint.setTextSize(100); |
| 485 | offscreen.drawString("ABC", 20, 160, paint); |
| 486 | SkRect layerBounds = SkRect::MakeXYWH(32, 32, 192, 192); |
| 487 | offscreen.saveLayerAlpha(&layerBounds, 128); |
| 488 | offscreen.clear(SK_ColorWHITE); |
| 489 | offscreen.drawString("DEF", 20, 160, paint); |
| 490 | } |
| 491 | canvas->drawBitmap(bitmap, 0, 0, nullptr); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 492 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 493 | ## |
| 494 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 495 | #SeeAlso State_Stack |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 496 | |
| 497 | ## |
| 498 | |
| 499 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 500 | #Subtopic Property |
| 501 | #Populate |
| 502 | #Line # metrics and attributes ## |
| 503 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 504 | |
| 505 | #Method SkMetaData& getMetaData() |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 506 | #In Property |
| 507 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 508 | #Line # associates additional data with the canvas ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 509 | Returns storage to associate additional data with the canvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 510 | The storage is freed when Canvas is deleted. |
| 511 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 512 | #Return storage that can be read from and written to ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 513 | |
| 514 | #Example |
| 515 | const char* kHelloMetaData = "HelloMetaData"; |
| 516 | SkCanvas canvas; |
| 517 | SkMetaData& metaData = canvas.getMetaData(); |
| 518 | SkDebugf("before: %s\n", metaData.findString(kHelloMetaData)); |
| 519 | metaData.setString(kHelloMetaData, "Hello!"); |
| 520 | SkDebugf("during: %s\n", metaData.findString(kHelloMetaData)); |
| 521 | metaData.removeString(kHelloMetaData); |
| 522 | SkDebugf("after: %s\n", metaData.findString(kHelloMetaData)); |
| 523 | |
| 524 | #StdOut |
| 525 | before: (null) |
| 526 | during: Hello! |
| 527 | after: (null) |
| 528 | #StdOut ## |
| 529 | ## |
| 530 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 531 | #SeeAlso SkMetaData |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 532 | |
| 533 | ## |
| 534 | |
| 535 | # ------------------------------------------------------------------------------ |
| 536 | |
| 537 | #Method SkImageInfo imageInfo() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 538 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 539 | #Line # returns Image_Info for Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 540 | Returns Image_Info for Canvas. If Canvas is not associated with Raster_Surface or |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 541 | GPU_Surface, returned Color_Type is set to kUnknown_SkColorType. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 542 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 543 | #Return dimensions and Color_Type of Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 544 | |
| 545 | #Example |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 546 | SkCanvas emptyCanvas; |
| 547 | SkImageInfo canvasInfo = emptyCanvas.imageInfo(); |
| 548 | SkImageInfo emptyInfo; |
| 549 | SkDebugf("emptyInfo %c= canvasInfo\n", emptyInfo == canvasInfo ? '=' : '!'); |
| 550 | |
| 551 | #StdOut |
| 552 | emptyInfo == canvasInfo |
| 553 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 554 | ## |
| 555 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 556 | #SeeAlso SkImageInfo MakeRasterDirect makeSurface |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 557 | |
| 558 | ## |
| 559 | |
| 560 | # ------------------------------------------------------------------------------ |
| 561 | |
| 562 | #Method bool getProps(SkSurfaceProps* props) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 563 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 564 | #Line # copies Surface_Properties if available ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 565 | Copies Surface_Properties, if Canvas is associated with Raster_Surface or |
| 566 | GPU_Surface, and returns true. Otherwise, returns false and leave props unchanged. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 567 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 568 | #Param props storage for writable SkSurfaceProps ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 569 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 570 | #Return true if Surface_Properties was copied ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 571 | |
| 572 | #ToDo This seems old style. Deprecate? ## |
| 573 | |
| 574 | #Example |
| 575 | SkBitmap bitmap; |
| 576 | SkCanvas canvas(bitmap, SkSurfaceProps(0, kRGB_V_SkPixelGeometry)); |
| 577 | SkSurfaceProps surfaceProps(0, kUnknown_SkPixelGeometry); |
| 578 | SkDebugf("isRGB:%d\n", SkPixelGeometryIsRGB(surfaceProps.pixelGeometry())); |
| 579 | if (!canvas.getProps(&surfaceProps)) { |
| 580 | SkDebugf("getProps failed unexpectedly.\n"); |
| 581 | } |
| 582 | SkDebugf("isRGB:%d\n", SkPixelGeometryIsRGB(surfaceProps.pixelGeometry())); |
| 583 | |
| 584 | #StdOut |
| 585 | isRGB:0 |
| 586 | isRGB:1 |
| 587 | #StdOut ## |
| 588 | ## |
| 589 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 590 | #SeeAlso SkSurfaceProps makeSurface |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 591 | |
| 592 | ## |
| 593 | |
| 594 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 595 | #Subtopic Utility |
| 596 | #Populate |
| 597 | #Line # rarely called management functions ## |
| 598 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 599 | |
| 600 | #Method void flush() |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 601 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 602 | #Line # triggers execution of all pending draw operations ## |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 603 | Triggers the immediate execution of all pending draw operations. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 604 | If Canvas is associated with GPU_Surface, resolves all pending GPU operations. |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 605 | If Canvas is associated with Raster_Surface, has no effect; raster draw |
| 606 | operations are never deferred. |
| 607 | |
| 608 | #ToDo |
| 609 | In an overview section on managing the GPU, include: |
| 610 | - flush should never change what is drawn |
| 611 | - call to kick off gpu work |
| 612 | - calling too much impacts performance |
| 613 | - some calls (peekPixels, prepareForExternalIO) call it internally |
| 614 | - canvas call is local, GrContext::flush is global |
| 615 | - diffentiate between flush, flushAndSignalSemaphores |
| 616 | - normally never needs to be called |
| 617 | - call it when sharing gpu resources, feeling memory pressure, swapping out app, and before |
| 618 | abandoning context |
| 619 | - also call to say "I'm finished drawing here", e.g., when drawing to a GPU-backed offscreen surface |
| 620 | (created with SkSurface::MakeRenderTarget) |
| 621 | |
| 622 | for posterity: this doesn't show a difference: fiddle.skia.org/c/@flushfail |
| 623 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 624 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 625 | #ToDo haven't thought of a useful example to put here ## |
| 626 | #NoExample |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 627 | ## |
| 628 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 629 | #SeeAlso peekPixels SkSurface::flush() GrContext::flush() SkSurface::prepareForExternalIO GrContext::abandonContext() |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 630 | |
| 631 | ## |
| 632 | |
| 633 | # ------------------------------------------------------------------------------ |
| 634 | |
| 635 | #Method virtual SkISize getBaseLayerSize() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 636 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 637 | #Line # returns size of base Layer in global coordinates ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 638 | Gets the size of the base or root Layer in global canvas coordinates. The |
| 639 | origin of the base Layer is always (0,0). The area available for drawing may be |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 640 | smaller (due to clipping or saveLayer). |
| 641 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 642 | #Return integral width and height of base Layer ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 643 | |
| 644 | #Example |
| 645 | SkBitmap bitmap; |
| 646 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(20, 30)); |
| 647 | SkCanvas canvas(bitmap, SkSurfaceProps(0, kUnknown_SkPixelGeometry)); |
| 648 | canvas.clipRect(SkRect::MakeWH(10, 40)); |
| 649 | SkIRect clipDeviceBounds = canvas.getDeviceClipBounds(); |
| 650 | if (clipDeviceBounds.isEmpty()) { |
| 651 | SkDebugf("Empty clip bounds is unexpected!\n"); |
| 652 | } |
| 653 | SkDebugf("clip=%d,%d\n", clipDeviceBounds.width(), clipDeviceBounds.height()); |
| 654 | SkISize baseLayerSize = canvas.getBaseLayerSize(); |
| 655 | SkDebugf("size=%d,%d\n", baseLayerSize.width(), baseLayerSize.height()); |
| 656 | |
| 657 | #StdOut |
| 658 | clip=10,30 |
| 659 | size=20,30 |
| 660 | ## |
| 661 | ## |
| 662 | |
| 663 | #ToDo is this the same as the width and height of surface? ## |
| 664 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 665 | #SeeAlso getDeviceClipBounds |
| 666 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 667 | ## |
| 668 | |
| 669 | # ------------------------------------------------------------------------------ |
| 670 | |
| 671 | #Method sk_sp<SkSurface> makeSurface(const SkImageInfo& info, const SkSurfaceProps* props = nullptr) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 672 | #In Constructor |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 673 | #Line # creates Surface matching SkImageInfo and SkSurfaceProps ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 674 | Creates Surface matching info and props, and associates it with Canvas. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 675 | Returns nullptr if no match found. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 676 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 677 | If props is nullptr, matches Surface_Properties in Canvas. If props is nullptr and Canvas |
| 678 | does not have Surface_Properties, creates Surface with default Surface_Properties. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 679 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 680 | #Param info width, height, Color_Type, Alpha_Type, and Color_Space ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 681 | #Param props Surface_Properties to match; may be nullptr to match Canvas ## |
| 682 | |
| 683 | #Return Surface matching info and props, or nullptr if no match is available ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 684 | |
| 685 | #Example |
| 686 | sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(5, 6); |
| 687 | SkCanvas* smallCanvas = surface->getCanvas(); |
| 688 | SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(3, 4); |
| 689 | sk_sp<SkSurface> compatible = smallCanvas->makeSurface(imageInfo); |
| 690 | SkDebugf("compatible %c= nullptr\n", compatible == nullptr ? '=' : '!'); |
| 691 | SkDebugf("size = %d, %d\n", compatible->width(), compatible->height()); |
| 692 | |
| 693 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 694 | compatible != nullptr |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 695 | size = 3, 4 |
| 696 | ## |
| 697 | ## |
| 698 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 699 | #SeeAlso SkSurface SkSurface::makeSurface SkImageInfo SkSurfaceProps |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 700 | |
| 701 | ## |
| 702 | |
| 703 | # ------------------------------------------------------------------------------ |
| 704 | |
| 705 | #Method virtual GrContext* getGrContext() |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 706 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 707 | #Line # returns GPU_Context of the GPU_Surface ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 708 | Returns GPU_Context of the GPU_Surface associated with Canvas. |
| 709 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 710 | #Return GPU_Context, if available; nullptr otherwise ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 711 | |
| 712 | #Example |
| 713 | void draw(SkCanvas* canvas) { |
| 714 | if (canvas->getGrContext()) { |
| 715 | canvas->clear(SK_ColorRED); |
| 716 | } else { |
| 717 | canvas->clear(SK_ColorBLUE); |
| 718 | } |
| 719 | } |
| 720 | ## |
| 721 | |
| 722 | #ToDo fiddle should show both CPU and GPU out ## |
| 723 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 724 | #SeeAlso GrContext |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 725 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 726 | ## |
| 727 | |
| 728 | # ------------------------------------------------------------------------------ |
| 729 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 730 | #Method void* accessTopLayerPixels(SkImageInfo* info, size_t* rowBytes, SkIPoint* origin = nullptr) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 731 | #In Utility |
| 732 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 733 | #Line # returns writable pixel access if available ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 734 | Returns the pixel base address, Image_Info, rowBytes, and origin if the pixels |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 735 | can be read directly. The returned address is only valid |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 736 | while Canvas is in scope and unchanged. Any Canvas call or Surface call |
| 737 | may invalidate the returned address and other returned values. |
| 738 | |
| 739 | If pixels are inaccessible, info, rowBytes, and origin are unchanged. |
| 740 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 741 | #Param info storage for writable pixels' Image_Info; may be nullptr ## |
| 742 | #Param rowBytes storage for writable pixels' row bytes; may be nullptr ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 743 | #Param origin storage for Canvas top Layer origin, its top-left corner; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 744 | may be nullptr |
| 745 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 746 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 747 | #Return address of pixels, or nullptr if inaccessible ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 748 | |
| 749 | #Example |
| 750 | void draw(SkCanvas* canvas) { |
| 751 | if (canvas->accessTopLayerPixels(nullptr, nullptr)) { |
| 752 | canvas->clear(SK_ColorRED); |
| 753 | } else { |
| 754 | canvas->clear(SK_ColorBLUE); |
| 755 | } |
| 756 | } |
| 757 | ## |
| 758 | |
| 759 | #Example |
| 760 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 761 | Draws "ABC" on the device. Then draws "DEF" in Layer, and reads |
| 762 | Layer to add a large dotted "DEF". Finally blends Layer with the |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 763 | device. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 764 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 765 | 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] | 766 | "DEF" appear only on the CPU. |
| 767 | ## |
| 768 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 769 | SkPaint paint; |
| 770 | paint.setTextSize(100); |
| 771 | canvas->drawString("ABC", 20, 160, paint); |
| 772 | SkRect layerBounds = SkRect::MakeXYWH(32, 32, 192, 192); |
| 773 | canvas->saveLayerAlpha(&layerBounds, 128); |
| 774 | canvas->clear(SK_ColorWHITE); |
| 775 | canvas->drawString("DEF", 20, 160, paint); |
| 776 | SkImageInfo imageInfo; |
| 777 | size_t rowBytes; |
| 778 | SkIPoint origin; |
| 779 | uint32_t* access = (uint32_t*) canvas->accessTopLayerPixels(&imageInfo, &rowBytes, &origin); |
| 780 | if (access) { |
| 781 | int h = imageInfo.height(); |
| 782 | int v = imageInfo.width(); |
| 783 | int rowWords = rowBytes / sizeof(uint32_t); |
| 784 | for (int y = 0; y < h; ++y) { |
| 785 | int newY = (y - h / 2) * 2 + h / 2; |
| 786 | if (newY < 0 || newY >= h) { |
| 787 | continue; |
| 788 | } |
| 789 | for (int x = 0; x < v; ++x) { |
| 790 | int newX = (x - v / 2) * 2 + v / 2; |
| 791 | if (newX < 0 || newX >= v) { |
| 792 | continue; |
| 793 | } |
| 794 | if (access[y * rowWords + x] == SK_ColorBLACK) { |
| 795 | access[newY * rowWords + newX] = SK_ColorGRAY; |
| 796 | } |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 801 | canvas->restore(); |
| 802 | } |
| 803 | ## |
| 804 | |
| 805 | #ToDo there are no callers of this that I can find. Deprecate? ## |
| 806 | #ToDo fiddle should show both CPU and GPU out ## |
| 807 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 808 | #SeeAlso SkImageInfo SkPixmap |
| 809 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 810 | ## |
| 811 | |
| 812 | # ------------------------------------------------------------------------------ |
| 813 | |
| 814 | #Method SkRasterHandleAllocator::Handle accessTopRasterHandle() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 815 | #In Utility |
| 816 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 817 | #Line # returns context that tracks Clip and Matrix ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 818 | Returns custom context that tracks the Matrix and Clip. |
| 819 | |
| 820 | Use Raster_Handle_Allocator to blend Skia drawing with custom drawing, typically performed |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 821 | by the host platform user interface. The custom context returned is generated by |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 822 | SkRasterHandleAllocator::MakeCanvas, which creates a custom canvas with raster storage for |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 823 | the drawing destination. |
| 824 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 825 | #Return context of custom allocation ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 826 | |
| 827 | #Example |
| 828 | #Description |
| 829 | #ToDo ## |
| 830 | ## |
| 831 | #Function |
| 832 | static void DeleteCallback(void*, void* context) { |
| 833 | delete (char*) context; |
| 834 | } |
| 835 | |
| 836 | class CustomAllocator : public SkRasterHandleAllocator { |
| 837 | public: |
| 838 | bool allocHandle(const SkImageInfo& info, Rec* rec) override { |
| 839 | char* context = new char[4]{'s', 'k', 'i', 'a'}; |
| 840 | rec->fReleaseProc = DeleteCallback; |
| 841 | rec->fReleaseCtx = context; |
| 842 | rec->fHandle = context; |
| 843 | rec->fPixels = context; |
| 844 | rec->fRowBytes = 4; |
| 845 | return true; |
| 846 | } |
| 847 | |
| 848 | void updateHandle(Handle handle, const SkMatrix& ctm, const SkIRect& clip_bounds) override { |
| 849 | // apply canvas matrix and clip to custom environment |
| 850 | } |
| 851 | }; |
| 852 | |
| 853 | ## |
| 854 | void draw(SkCanvas* canvas) { |
| 855 | const SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1); |
| 856 | std::unique_ptr<SkCanvas> c2 = |
| 857 | SkRasterHandleAllocator::MakeCanvas(std::unique_ptr<CustomAllocator>( |
| 858 | new CustomAllocator()), info); |
| 859 | char* context = (char*) c2->accessTopRasterHandle(); |
| 860 | SkDebugf("context = %.4s\n", context); |
| 861 | |
| 862 | } |
| 863 | #StdOut |
| 864 | context = skia |
| 865 | ## |
| 866 | #ToDo skstd::make_unique could not be used because def is private -- note to fix in c++14? ## |
| 867 | ## |
| 868 | |
| 869 | #SeeAlso SkRasterHandleAllocator |
| 870 | |
| 871 | ## |
| 872 | |
| 873 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 874 | #Subtopic Pixels |
| 875 | #Populate |
| 876 | #Line # read and write pixel values ## |
| 877 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 878 | |
| 879 | #Method bool peekPixels(SkPixmap* pixmap) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 880 | #In Pixels |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 881 | #Line # returns if Canvas has direct access to its pixels ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 882 | Returns true if Canvas has direct access to its pixels. |
| 883 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 884 | Pixels are readable when Device is raster. Pixels are not readable when Canvas |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 885 | is returned from GPU_Surface, returned by SkDocument::beginPage, returned by |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 886 | SkPictureRecorder::beginRecording, or Canvas is the base of a utility class |
Brian Osman | 46fe9c7 | 2018-03-09 15:44:34 -0500 | [diff] [blame] | 887 | like SkDebugCanvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 888 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 889 | pixmap is valid only while Canvas is in scope and unchanged. Any |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 890 | Canvas or Surface call may invalidate the pixmap values. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 891 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 892 | #Param pixmap storage for pixel state if pixels are readable; otherwise, ignored ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 893 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 894 | #Return true if Canvas has direct access to pixels ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 895 | |
| 896 | #Example |
| 897 | SkPixmap pixmap; |
| 898 | if (canvas->peekPixels(&pixmap)) { |
| 899 | SkDebugf("width=%d height=%d\n", pixmap.bounds().width(), pixmap.bounds().height()); |
| 900 | } |
| 901 | #StdOut |
| 902 | width=256 height=256 |
| 903 | ## |
| 904 | ## |
| 905 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 906 | #SeeAlso readPixels SkBitmap::peekPixels SkImage::peekPixels SkSurface::peekPixels |
| 907 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 908 | ## |
| 909 | |
| 910 | # ------------------------------------------------------------------------------ |
| 911 | |
| 912 | #Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, |
| 913 | int srcX, int srcY) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 914 | #In Pixels |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 915 | #Line # copies and converts rectangle of pixels from Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 916 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 917 | Copies Rect of pixels from Canvas into dstPixels. Matrix and Clip are |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 918 | ignored. |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 919 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 920 | Source Rect corners are (srcX, srcY) and (imageInfo().width(), imageInfo().height()). |
| 921 | Destination Rect corners are (0, 0) and (dstInfo.width(), dstInfo.height()). |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 922 | Copies each readable pixel intersecting both rectangles, without scaling, |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 923 | converting to dstInfo.colorType() and dstInfo.alphaType() if required. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 924 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 925 | Pixels are readable when Device is raster, or backed by a GPU. |
| 926 | Pixels are not readable when SkCanvas is returned by SkDocument::beginPage, |
| 927 | returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility |
Brian Osman | 46fe9c7 | 2018-03-09 15:44:34 -0500 | [diff] [blame] | 928 | class like SkDebugCanvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 929 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 930 | The destination pixel storage must be allocated by the caller. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 931 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 932 | Pixel values are converted only if Color_Type and Alpha_Type |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 933 | do not match. Only pixels within both source and destination rectangles |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 934 | are copied. dstPixels contents outside Rect intersection are unchanged. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 935 | |
| 936 | 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] | 937 | |
| 938 | Does not copy, and returns false if: |
| 939 | |
| 940 | #List |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 941 | # Source and destination rectangles do not intersect. ## |
| 942 | # Canvas pixels could not be converted to dstInfo.colorType() or dstInfo.alphaType(). ## |
| 943 | # Canvas pixels are not readable; for instance, Canvas is document-based. ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 944 | # dstRowBytes is too small to contain one row of pixels. ## |
| 945 | ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 946 | . |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 947 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 948 | #Param dstInfo width, height, Color_Type, and Alpha_Type of dstPixels ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 949 | #Param dstPixels storage for pixels; dstInfo.height() times dstRowBytes, or larger ## |
| 950 | #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] | 951 | #Param srcX offset into readable pixels on x-axis; may be negative ## |
| 952 | #Param srcY offset into readable pixels on y-axis; may be negative ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 953 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 954 | #Return true if pixels were copied ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 955 | |
| 956 | #Example |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 957 | #Width 64 |
| 958 | #Height 64 |
| 959 | #Description |
| 960 | A black circle drawn on a blue background provides an image to copy. |
| 961 | 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] | 962 | The copied quarter circles overdraw the original circle. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 963 | ## |
| 964 | canvas->clear(SK_ColorBLUE); |
| 965 | SkPaint paint; |
| 966 | canvas->drawCircle(32, 32, 28, paint); |
| 967 | SkImageInfo info = SkImageInfo::Make(64, 64, kBGRA_8888_SkColorType, kPremul_SkAlphaType); |
| 968 | sk_sp<SkData> data(SkData::MakeUninitialized(info.minRowBytes() * info.height())); |
| 969 | sk_bzero(data->writable_data(), info.minRowBytes() * info.height()); |
| 970 | for (int x : { 32, -32 } ) { |
| 971 | for (int y : { 32, -32 } ) { |
| 972 | canvas->readPixels(info, data->writable_data(), info.minRowBytes(), x, y); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 973 | } |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 974 | } |
| 975 | sk_sp<SkImage> image = SkImage::MakeRasterData(info, data, info.minRowBytes()); |
| 976 | canvas->drawImage(image, 0, 0); |
| 977 | ## |
| 978 | |
| 979 | #Example |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 980 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 981 | Canvas returned by Raster_Surface has Premultiplied pixel values. |
| 982 | clear() takes Unpremultiplied input with Color_Alpha equal 0x80 |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 983 | and RGB equal 0x55, 0xAA, 0xFF. RGB is multiplied by Color_Alpha |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 984 | to generate Premultiplied value 0x802B5580. readPixels converts pixel back |
| 985 | to Unpremultiplied value 0x8056A9FF, introducing error. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 986 | ## |
| 987 | canvas->clear(0x8055aaff); |
| 988 | for (SkAlphaType alphaType : { kPremul_SkAlphaType, kUnpremul_SkAlphaType } ) { |
| 989 | uint32_t pixel = 0; |
| 990 | SkImageInfo info = SkImageInfo::Make(1, 1, kBGRA_8888_SkColorType, alphaType); |
| 991 | if (canvas->readPixels(info, &pixel, 4, 0, 0)) { |
| 992 | SkDebugf("pixel = %08x\n", pixel); |
| 993 | } |
| 994 | } |
| 995 | |
| 996 | #StdOut |
| 997 | pixel = 802b5580 |
| 998 | pixel = 8056a9ff |
| 999 | ## |
| 1000 | ## |
| 1001 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1002 | #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] | 1003 | |
| 1004 | ## |
| 1005 | |
| 1006 | # ------------------------------------------------------------------------------ |
| 1007 | |
| 1008 | #Method bool readPixels(const SkPixmap& pixmap, int srcX, int srcY) |
| 1009 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1010 | Copies Rect of pixels from Canvas into pixmap. Matrix and Clip are |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1011 | ignored. |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1012 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1013 | Source Rect corners are (srcX, srcY) and (imageInfo().width(), imageInfo().height()). |
| 1014 | Destination Rect corners are (0, 0) and (pixmap.width(), pixmap.height()). |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1015 | Copies each readable pixel intersecting both rectangles, without scaling, |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1016 | converting to pixmap.colorType() and pixmap.alphaType() if required. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1017 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1018 | Pixels are readable when Device is raster, or backed by a GPU. |
| 1019 | Pixels are not readable when SkCanvas is returned by SkDocument::beginPage, |
| 1020 | returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility |
Brian Osman | 46fe9c7 | 2018-03-09 15:44:34 -0500 | [diff] [blame] | 1021 | class like SkDebugCanvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1022 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1023 | Caller must allocate pixel storage in pixmap if needed. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1024 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1025 | Pixel values are converted only if Color_Type and Alpha_Type |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1026 | do not match. Only pixels within both source and destination Rects |
| 1027 | are copied. pixmap pixels contents outside Rect intersection are unchanged. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1028 | |
| 1029 | 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] | 1030 | |
| 1031 | Does not copy, and returns false if: |
| 1032 | |
| 1033 | #List |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1034 | # Source and destination rectangles do not intersect. ## |
| 1035 | # Canvas pixels could not be converted to pixmap.colorType() or pixmap.alphaType(). ## |
| 1036 | # Canvas pixels are not readable; for instance, Canvas is document-based. ## |
| 1037 | # Pixmap pixels could not be allocated. ## |
| 1038 | # pixmap.rowBytes() is too small to contain one row of pixels. ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1039 | ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 1040 | . |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1041 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1042 | #Param pixmap storage for pixels copied from Canvas ## |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 1043 | #Param srcX offset into readable pixels on x-axis; may be negative ## |
| 1044 | #Param srcY offset into readable pixels on y-axis; may be negative ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1045 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1046 | #Return true if pixels were copied ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1047 | |
| 1048 | #Example |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1049 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1050 | clear() takes Unpremultiplied input with Color_Alpha equal 0x80 |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1051 | and RGB equal 0x55, 0xAA, 0xFF. RGB is multiplied by Color_Alpha |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1052 | to generate Premultiplied value 0x802B5580. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1053 | ## |
| 1054 | void draw(SkCanvas* canvas) { |
| 1055 | canvas->clear(0x8055aaff); |
| 1056 | uint32_t pixels[1] = { 0 }; |
| 1057 | SkPixmap pixmap(SkImageInfo::MakeN32Premul(1, 1), pixels, 4); |
| 1058 | canvas->readPixels(pixmap, 0, 0); |
| 1059 | SkDebugf("pixel = %08x\n", pixels[0]); |
| 1060 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1061 | #StdOut |
| 1062 | pixel = 802b5580 |
| 1063 | ## |
| 1064 | ## |
| 1065 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1066 | #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] | 1067 | |
| 1068 | ## |
| 1069 | |
| 1070 | # ------------------------------------------------------------------------------ |
| 1071 | |
| 1072 | #Method bool readPixels(const SkBitmap& bitmap, int srcX, int srcY) |
| 1073 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1074 | Copies Rect of pixels from Canvas into bitmap. Matrix and Clip are |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1075 | ignored. |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1076 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1077 | Source Rect corners are (srcX, srcY) and (imageInfo().width(), imageInfo().height()). |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1078 | Destination Rect corners are (0, 0) and (bitmap.width(), bitmap.height()). |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1079 | Copies each readable pixel intersecting both rectangles, without scaling, |
| 1080 | converting to bitmap.colorType() and bitmap.alphaType() if required. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1081 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1082 | Pixels are readable when Device is raster, or backed by a GPU. |
| 1083 | Pixels are not readable when SkCanvas is returned by SkDocument::beginPage, |
| 1084 | returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility |
Brian Osman | 46fe9c7 | 2018-03-09 15:44:34 -0500 | [diff] [blame] | 1085 | class like SkDebugCanvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1086 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1087 | Caller must allocate pixel storage in bitmap if needed. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1088 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1089 | Bitmap values are converted only if Color_Type and Alpha_Type |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1090 | do not match. Only pixels within both source and destination rectangles |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1091 | are copied. Bitmap pixels outside Rect intersection are unchanged. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1092 | |
| 1093 | 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] | 1094 | |
| 1095 | Does not copy, and returns false if: |
| 1096 | |
| 1097 | #List |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1098 | # Source and destination rectangles do not intersect. ## |
| 1099 | # Canvas pixels could not be converted to bitmap.colorType() or bitmap.alphaType(). ## |
| 1100 | # Canvas pixels are not readable; for instance, Canvas is document-based. ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1101 | # bitmap pixels could not be allocated. ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1102 | # bitmap.rowBytes() is too small to contain one row of pixels. ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1103 | ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 1104 | . |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1105 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1106 | #Param bitmap storage for pixels copied from Canvas ## |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 1107 | #Param srcX offset into readable pixels on x-axis; may be negative ## |
| 1108 | #Param srcY offset into readable pixels on y-axis; may be negative ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1109 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1110 | #Return true if pixels were copied ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1111 | |
| 1112 | #Example |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1113 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1114 | clear() takes Unpremultiplied input with Color_Alpha equal 0x80 |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1115 | and RGB equal 0x55, 0xAA, 0xFF. RGB is multiplied by Color_Alpha |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1116 | to generate Premultiplied value 0x802B5580. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1117 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1118 | void draw(SkCanvas* canvas) { |
| 1119 | canvas->clear(0x8055aaff); |
| 1120 | SkBitmap bitmap; |
| 1121 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(1, 1)); |
| 1122 | canvas->readPixels(bitmap, 0, 0); |
| 1123 | SkDebugf("pixel = %08x\n", bitmap.getAddr32(0, 0)[0]); |
| 1124 | } |
| 1125 | #StdOut |
| 1126 | pixel = 802b5580 |
| 1127 | ## |
| 1128 | ## |
| 1129 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1130 | #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] | 1131 | |
| 1132 | ## |
| 1133 | |
| 1134 | # ------------------------------------------------------------------------------ |
| 1135 | |
| 1136 | #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] | 1137 | #In Pixels |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1138 | #Line # copies and converts rectangle of pixels to Canvas ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1139 | Copies Rect from pixels to Canvas. Matrix and Clip are ignored. |
| 1140 | Source Rect corners are (0, 0) and (info.width(), info.height()). |
| 1141 | Destination Rect corners are (x, y) and |
| 1142 | (imageInfo().width(), imageInfo().height()). |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1143 | |
| 1144 | Copies each readable pixel intersecting both rectangles, without scaling, |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1145 | converting to imageInfo().colorType() and imageInfo().alphaType() if required. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1146 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1147 | Pixels are writable when Device is raster, or backed by a GPU. |
| 1148 | Pixels are not writable when SkCanvas is returned by SkDocument::beginPage, |
| 1149 | returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility |
Brian Osman | 46fe9c7 | 2018-03-09 15:44:34 -0500 | [diff] [blame] | 1150 | class like SkDebugCanvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1151 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1152 | Pixel values are converted only if Color_Type and Alpha_Type |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1153 | do not match. Only pixels within both source and destination rectangles |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1154 | are copied. Canvas pixels outside Rect intersection are unchanged. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1155 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1156 | Pass negative values for x or y to offset pixels to the left or |
| 1157 | above Canvas pixels. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1158 | |
| 1159 | Does not copy, and returns false if: |
| 1160 | |
| 1161 | #List |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1162 | # Source and destination rectangles do not intersect. ## |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1163 | # pixels could not be converted to Canvas imageInfo().colorType() or |
| 1164 | imageInfo().alphaType(). ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1165 | # Canvas pixels are not writable; for instance, Canvas is document-based. ## |
| 1166 | # rowBytes is too small to contain one row of pixels. ## |
| 1167 | ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 1168 | . |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1169 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1170 | #Param info width, height, Color_Type, and Alpha_Type of pixels ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1171 | #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] | 1172 | #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] | 1173 | #Param x offset into Canvas writable pixels on x-axis; may be negative ## |
| 1174 | #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] | 1175 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1176 | #Return true if pixels were written to Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1177 | |
| 1178 | #Example |
| 1179 | SkImageInfo imageInfo = SkImageInfo::MakeN32(256, 1, kPremul_SkAlphaType); |
| 1180 | for (int y = 0; y < 256; ++y) { |
| 1181 | uint32_t pixels[256]; |
| 1182 | for (int x = 0; x < 256; ++x) { |
| 1183 | pixels[x] = SkColorSetARGB(x, x + y, x, x - y); |
| 1184 | } |
| 1185 | canvas->writePixels(imageInfo, &pixels, sizeof(pixels), 0, y); |
| 1186 | } |
| 1187 | ## |
| 1188 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1189 | #SeeAlso readPixels drawBitmap drawImage SkBitmap::writePixels |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1190 | |
| 1191 | ## |
| 1192 | |
| 1193 | # ------------------------------------------------------------------------------ |
| 1194 | |
| 1195 | #Method bool writePixels(const SkBitmap& bitmap, int x, int y) |
| 1196 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1197 | Copies Rect from pixels to Canvas. Matrix and Clip are ignored. |
| 1198 | Source Rect corners are (0, 0) and (bitmap.width(), bitmap.height()). |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1199 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1200 | Destination Rect corners are (x, y) and |
| 1201 | (imageInfo().width(), imageInfo().height()). |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1202 | |
| 1203 | Copies each readable pixel intersecting both rectangles, without scaling, |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1204 | converting to imageInfo().colorType() and imageInfo().alphaType() if required. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1205 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1206 | Pixels are writable when Device is raster, or backed by a GPU. |
| 1207 | Pixels are not writable when SkCanvas is returned by SkDocument::beginPage, |
| 1208 | returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility |
Brian Osman | 46fe9c7 | 2018-03-09 15:44:34 -0500 | [diff] [blame] | 1209 | class like SkDebugCanvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1210 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1211 | Pixel values are converted only if Color_Type and Alpha_Type |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1212 | do not match. Only pixels within both source and destination rectangles |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1213 | are copied. Canvas pixels outside Rect intersection are unchanged. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1214 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1215 | Pass negative values for x or y to offset pixels to the left or |
| 1216 | above Canvas pixels. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1217 | |
| 1218 | Does not copy, and returns false if: |
| 1219 | |
| 1220 | #List |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1221 | # Source and destination rectangles do not intersect. ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1222 | # bitmap does not have allocated pixels. ## |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1223 | # bitmap pixels could not be converted to Canvas imageInfo().colorType() or |
| 1224 | imageInfo().alphaType(). ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1225 | # Canvas pixels are not writable; for instance, Canvas is document based. ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1226 | # bitmap pixels are inaccessible; for instance, bitmap wraps a texture. ## |
| 1227 | ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 1228 | . |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1229 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1230 | #Param bitmap contains pixels copied to Canvas ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1231 | #Param x offset into Canvas writable pixels in x; may be negative ## |
| 1232 | #Param y offset into Canvas writable pixels in y; may be negative ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1233 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1234 | #Return true if pixels were written to Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1235 | |
| 1236 | #Example |
| 1237 | void draw(SkCanvas* canvas) { |
| 1238 | SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(2, 2); |
| 1239 | SkBitmap bitmap; |
| 1240 | bitmap.setInfo(imageInfo); |
| 1241 | uint32_t pixels[4]; |
| 1242 | bitmap.setPixels(pixels); |
| 1243 | for (int y = 0; y < 256; y += 2) { |
| 1244 | for (int x = 0; x < 256; x += 2) { |
| 1245 | pixels[0] = SkColorSetRGB(x, y, x | y); |
| 1246 | pixels[1] = SkColorSetRGB(x ^ y, y, x); |
| 1247 | pixels[2] = SkColorSetRGB(x, x & y, y); |
| 1248 | pixels[3] = SkColorSetRGB(~x, ~y, x); |
| 1249 | canvas->writePixels(bitmap, x, y); |
| 1250 | } |
| 1251 | } |
| 1252 | } |
| 1253 | ## |
| 1254 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1255 | #SeeAlso readPixels drawBitmap drawImage SkBitmap::writePixels |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1256 | |
| 1257 | ## |
| 1258 | |
| 1259 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1260 | #Subtopic State_Stack |
| 1261 | #Line # stack of state for hierarchical drawing ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1262 | |
| 1263 | Canvas maintains a stack of state that allows hierarchical drawing, commonly used |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1264 | to implement windows and views. The initial state has an identity matrix and and |
| 1265 | an infinite clip. Even with a wide-open clip, drawing is constrained by the |
| 1266 | bounds of the Canvas Surface or Device. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1267 | |
Cary Clark | 939fd6c | 2018-07-12 08:40:13 -0400 | [diff] [blame^] | 1268 | Canvas savable state consists of Clip and Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1269 | Clip describes the area that may be drawn to. |
| 1270 | Matrix transforms the geometry. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1271 | |
| 1272 | save(), saveLayer, saveLayerPreserveLCDTextRequests, and saveLayerAlpha |
| 1273 | save state and return the depth of the stack. |
| 1274 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1275 | restore(), restoreToCount, and ~SkCanvas() revert state to its value when saved. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1276 | |
| 1277 | Each state on the stack intersects Clip with the previous Clip, |
| 1278 | and concatenates Matrix with the previous Matrix. |
| 1279 | The intersected Clip makes the drawing area the same or smaller; |
| 1280 | the concatenated Matrix may move the origin and potentially scale or rotate |
| 1281 | the coordinate space. |
| 1282 | |
| 1283 | Canvas does not require balancing the state stack but it is a good idea |
| 1284 | to do so. Calling save() without restore() will eventually cause Skia to fail; |
| 1285 | mismatched save() and restore() create hard to find bugs. |
| 1286 | |
| 1287 | It is not possible to use state to draw outside of the clip defined by the |
| 1288 | previous state. |
| 1289 | |
| 1290 | #Example |
| 1291 | #Description |
| 1292 | Draw to ever smaller clips; then restore drawing to full canvas. |
| 1293 | Note that the second clipRect is not permitted to enlarge Clip. |
| 1294 | ## |
| 1295 | #Height 160 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1296 | void draw(SkCanvas* canvas) { |
| 1297 | SkPaint paint; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1298 | canvas->save(); // records stack depth to restore |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1299 | canvas->clipRect(SkRect::MakeWH(100, 100)); // constrains drawing to clip |
| 1300 | canvas->clear(SK_ColorRED); // draws to limit of clip |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1301 | canvas->save(); // records stack depth to restore |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1302 | canvas->clipRect(SkRect::MakeWH(50, 150)); // Rect below 100 is ignored |
| 1303 | canvas->clear(SK_ColorBLUE); // draws to smaller clip |
| 1304 | canvas->restore(); // enlarges clip |
| 1305 | canvas->drawLine(20, 20, 150, 150, paint); // line below 100 is not drawn |
| 1306 | canvas->restore(); // enlarges clip |
| 1307 | canvas->drawLine(150, 20, 50, 120, paint); // line below 100 is drawn |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1308 | } |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1309 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1310 | |
| 1311 | Each Clip uses the current Matrix for its coordinates. |
| 1312 | |
| 1313 | #Example |
| 1314 | #Description |
| 1315 | While clipRect is given the same rectangle twice, Matrix makes the second |
| 1316 | clipRect draw at half the size of the first. |
| 1317 | ## |
| 1318 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1319 | void draw(SkCanvas* canvas) { |
| 1320 | canvas->clipRect(SkRect::MakeWH(100, 100)); |
| 1321 | canvas->clear(SK_ColorRED); |
| 1322 | canvas->scale(.5, .5); |
| 1323 | canvas->clipRect(SkRect::MakeWH(100, 100)); |
| 1324 | canvas->clear(SK_ColorBLUE); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1325 | } |
| 1326 | ## |
| 1327 | |
| 1328 | #SeeAlso save() saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha restore() restoreToCount |
| 1329 | |
| 1330 | #Method int save() |
| 1331 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1332 | #In State_Stack |
| 1333 | #Line # saves Clip and Matrix on stack ## |
Cary Clark | 939fd6c | 2018-07-12 08:40:13 -0400 | [diff] [blame^] | 1334 | Saves Matrix and Clip. |
| 1335 | Calling restore() discards changes to Matrix and Clip, |
| 1336 | restoring the Matrix and Clip to their state when save() was called. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1337 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1338 | Matrix may be changed by translate(), scale(), rotate(), skew(), concat(), setMatrix, |
| 1339 | and resetMatrix. Clip may be changed by clipRect, clipRRect, clipPath, clipRegion. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1340 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1341 | Saved Canvas state is put on a stack; multiple calls to save() should be balance |
| 1342 | by an equal number of calls to restore(). |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1343 | |
| 1344 | Call restoreToCount with result to restore this and subsequent saves. |
| 1345 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1346 | #Return depth of saved stack ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1347 | |
| 1348 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1349 | #Description |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1350 | The black square is translated 50 pixels down and to the right. |
| 1351 | Restoring Canvas state removes translate() from Canvas stack; |
| 1352 | the red square is not translated, and is drawn at the origin. |
| 1353 | ## |
| 1354 | #Height 100 |
| 1355 | void draw(SkCanvas* canvas) { |
| 1356 | SkPaint paint; |
| 1357 | SkRect rect = { 0, 0, 25, 25 }; |
| 1358 | canvas->drawRect(rect, paint); |
| 1359 | canvas->save(); |
| 1360 | canvas->translate(50, 50); |
| 1361 | canvas->drawRect(rect, paint); |
| 1362 | canvas->restore(); |
| 1363 | paint.setColor(SK_ColorRED); |
| 1364 | canvas->drawRect(rect, paint); |
| 1365 | } |
| 1366 | ## |
| 1367 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1368 | #SeeAlso saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha restore() restoreToCount |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1369 | |
| 1370 | ## |
| 1371 | |
| 1372 | # ------------------------------------------------------------------------------ |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1373 | |
| 1374 | #Method void restore() |
| 1375 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1376 | #In State_Stack |
| 1377 | #Line # restores changes to Clip and Matrix, pops save stack ## |
Cary Clark | 939fd6c | 2018-07-12 08:40:13 -0400 | [diff] [blame^] | 1378 | Removes changes to Matrix and Clip since Canvas state was |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1379 | last saved. The state is removed from the stack. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1380 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1381 | Does nothing if the stack is empty. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1382 | |
| 1383 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1384 | void draw(SkCanvas* canvas) { |
| 1385 | SkCanvas simple; |
| 1386 | SkDebugf("depth = %d\n", simple.getSaveCount()); |
| 1387 | simple.restore(); |
| 1388 | SkDebugf("depth = %d\n", simple.getSaveCount()); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1389 | } |
| 1390 | ## |
| 1391 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1392 | #SeeAlso save() saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha restoreToCount |
| 1393 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1394 | ## |
| 1395 | |
| 1396 | # ------------------------------------------------------------------------------ |
| 1397 | |
| 1398 | #Method int getSaveCount() const |
| 1399 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1400 | #In State_Stack |
| 1401 | #Line # returns depth of stack containing Clip and Matrix ## |
Cary Clark | 939fd6c | 2018-07-12 08:40:13 -0400 | [diff] [blame^] | 1402 | Returns the number of saved states, each containing: Matrix and Clip. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1403 | Equals the number of save() calls less the number of restore() calls plus one. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1404 | The save count of a new canvas is one. |
| 1405 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1406 | #Return depth of save state stack ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1407 | |
| 1408 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1409 | void draw(SkCanvas* canvas) { |
| 1410 | SkCanvas simple; |
| 1411 | SkDebugf("depth = %d\n", simple.getSaveCount()); |
| 1412 | simple.save(); |
| 1413 | SkDebugf("depth = %d\n", simple.getSaveCount()); |
| 1414 | simple.restore(); |
| 1415 | SkDebugf("depth = %d\n", simple.getSaveCount()); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1416 | } |
| 1417 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1418 | depth = 1 |
| 1419 | depth = 2 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1420 | depth = 1 |
| 1421 | ## |
| 1422 | ## |
| 1423 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1424 | #SeeAlso save() restore() restoreToCount |
| 1425 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1426 | ## |
| 1427 | |
| 1428 | # ------------------------------------------------------------------------------ |
| 1429 | |
| 1430 | #Method void restoreToCount(int saveCount) |
| 1431 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1432 | #In State_Stack |
| 1433 | #Line # restores changes to Clip and Matrix to given depth ## |
Cary Clark | 939fd6c | 2018-07-12 08:40:13 -0400 | [diff] [blame^] | 1434 | Restores state to Matrix and Clip values when save(), saveLayer, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1435 | saveLayerPreserveLCDTextRequests, or saveLayerAlpha returned saveCount. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1436 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1437 | Does nothing if saveCount is greater than state stack count. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1438 | Restores state to initial values if saveCount is less than or equal to one. |
| 1439 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1440 | #Param saveCount depth of state stack to restore ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1441 | |
| 1442 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1443 | void draw(SkCanvas* canvas) { |
| 1444 | SkDebugf("depth = %d\n", canvas->getSaveCount()); |
| 1445 | canvas->save(); |
| 1446 | canvas->save(); |
| 1447 | SkDebugf("depth = %d\n", canvas->getSaveCount()); |
| 1448 | canvas->restoreToCount(0); |
| 1449 | SkDebugf("depth = %d\n", canvas->getSaveCount()); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1450 | } |
| 1451 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1452 | depth = 1 |
| 1453 | depth = 3 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1454 | depth = 1 |
| 1455 | ## |
| 1456 | ## |
| 1457 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1458 | #SeeAlso restore() getSaveCount save() |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1459 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1460 | ## |
| 1461 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1462 | #Subtopic State_Stack ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1463 | |
| 1464 | # ------------------------------------------------------------------------------ |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1465 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1466 | #Subtopic Layer |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1467 | #Substitute layer |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1468 | #Alias Layers |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 1469 | #Substitute layers |
| 1470 | ## |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1471 | #Line # temporary Bitmap to draw into ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1472 | |
| 1473 | Layer allocates a temporary Bitmap to draw into. When the drawing is |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1474 | complete, the Bitmap is drawn into the Canvas. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1475 | |
| 1476 | Layer is saved in a stack along with other saved state. When state with a Layer |
| 1477 | is restored, the Bitmap is drawn into the previous Layer. |
| 1478 | |
| 1479 | Layer may be initialized with the contents of the previous Layer. When Layer is |
| 1480 | restored, its Bitmap can be modified by Paint passed to Layer to apply |
| 1481 | Color_Alpha, Color_Filter, Image_Filter, and Blend_Mode. |
| 1482 | |
| 1483 | #Method int saveLayer(const SkRect* bounds, const SkPaint* paint) |
| 1484 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1485 | #In Layer |
| 1486 | #Line # saves Clip and Matrix on stack; creates Layer ## |
Cary Clark | 939fd6c | 2018-07-12 08:40:13 -0400 | [diff] [blame^] | 1487 | Saves Matrix and Clip, and allocates a Bitmap for subsequent drawing. |
| 1488 | Calling restore() discards changes to Matrix and Clip, and draws the Bitmap. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1489 | |
| 1490 | Matrix may be changed by translate(), scale(), rotate(), skew(), concat(), |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1491 | setMatrix, and resetMatrix. Clip may be changed by clipRect, clipRRect, |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1492 | clipPath, clipRegion. |
| 1493 | |
| 1494 | Rect bounds suggests but does not define the Bitmap size. To clip drawing to |
| 1495 | a specific rectangle, use clipRect. |
| 1496 | |
| 1497 | Optional Paint paint applies Color_Alpha, Color_Filter, Image_Filter, and |
| 1498 | Blend_Mode when restore() is called. |
| 1499 | |
| 1500 | Call restoreToCount with returned value to restore this and subsequent saves. |
| 1501 | |
| 1502 | #Param bounds hint to limit the size of the Layer; may be nullptr ## |
| 1503 | #Param paint graphics state for Layer; may be nullptr ## |
| 1504 | |
| 1505 | #Return depth of saved stack ## |
| 1506 | |
| 1507 | #Example |
| 1508 | #Description |
| 1509 | Rectangles are blurred by Image_Filter when restore() draws Layer to main |
| 1510 | Canvas. |
| 1511 | ## |
| 1512 | #Height 128 |
Cary Clark | 81abc43 | 2018-06-25 16:30:08 -0400 | [diff] [blame] | 1513 | #Function |
| 1514 | ###$ |
| 1515 | #include "SkBlurImageFilter.h" |
| 1516 | $$$# |
| 1517 | ## |
| 1518 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1519 | void draw(SkCanvas* canvas) { |
| 1520 | SkPaint paint, blur; |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1521 | blur.setImageFilter(SkBlurImageFilter::Make(3, 3, nullptr)); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1522 | canvas->saveLayer(nullptr, &blur); |
| 1523 | SkRect rect = { 25, 25, 50, 50}; |
| 1524 | canvas->drawRect(rect, paint); |
| 1525 | canvas->translate(50, 50); |
| 1526 | paint.setColor(SK_ColorRED); |
| 1527 | canvas->drawRect(rect, paint); |
| 1528 | canvas->restore(); |
| 1529 | } |
| 1530 | ## |
| 1531 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1532 | #SeeAlso save() restore() saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha SaveLayerRec |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1533 | |
| 1534 | ## |
| 1535 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1536 | #Method int saveLayer(const SkRect& bounds, const SkPaint* paint) |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1537 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1538 | #In Layer |
Cary Clark | 939fd6c | 2018-07-12 08:40:13 -0400 | [diff] [blame^] | 1539 | Saves Matrix and Clip, and allocates a Bitmap for subsequent drawing. |
| 1540 | Calling restore() discards changes to Matrix and Clip, and draws the Bitmap. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1541 | |
| 1542 | Matrix may be changed by translate(), scale(), rotate(), skew(), concat(), |
| 1543 | setMatrix, and resetMatrix. Clip may be changed by clipRect, clipRRect, |
| 1544 | clipPath, clipRegion. |
| 1545 | |
| 1546 | Rect bounds suggests but does not define the Layer size. To clip drawing to |
| 1547 | a specific rectangle, use clipRect. |
| 1548 | |
| 1549 | Optional Paint paint applies Color_Alpha, Color_Filter, Image_Filter, and |
| 1550 | Blend_Mode when restore() is called. |
| 1551 | |
| 1552 | Call restoreToCount with returned value to restore this and subsequent saves. |
| 1553 | |
| 1554 | #Param bounds hint to limit the size of Layer; may be nullptr ## |
| 1555 | #Param paint graphics state for Layer; may be nullptr ## |
| 1556 | |
| 1557 | #Return depth of saved stack ## |
| 1558 | |
| 1559 | #Example |
| 1560 | #Description |
| 1561 | 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] | 1562 | The red rectangle is clipped; it does not fully fit on Layer. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1563 | Image_Filter blurs past edge of Layer so red rectangle is blurred on all sides. |
| 1564 | ## |
| 1565 | #Height 128 |
Cary Clark | 81abc43 | 2018-06-25 16:30:08 -0400 | [diff] [blame] | 1566 | #Function |
| 1567 | ###$ |
| 1568 | #include "SkBlurImageFilter.h" |
| 1569 | $$$# |
| 1570 | ## |
| 1571 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1572 | void draw(SkCanvas* canvas) { |
| 1573 | SkPaint paint, blur; |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1574 | blur.setImageFilter(SkBlurImageFilter::Make(3, 3, nullptr)); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1575 | canvas->saveLayer(SkRect::MakeWH(90, 90), &blur); |
| 1576 | SkRect rect = { 25, 25, 50, 50}; |
| 1577 | canvas->drawRect(rect, paint); |
| 1578 | canvas->translate(50, 50); |
| 1579 | paint.setColor(SK_ColorRED); |
| 1580 | canvas->drawRect(rect, paint); |
| 1581 | canvas->restore(); |
| 1582 | } |
| 1583 | ## |
| 1584 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1585 | #SeeAlso save() restore() saveLayerPreserveLCDTextRequests saveLayerAlpha SaveLayerRec |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1586 | |
| 1587 | ## |
| 1588 | |
| 1589 | #Method int saveLayerPreserveLCDTextRequests(const SkRect* bounds, const SkPaint* paint) |
| 1590 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1591 | #In Layer |
| 1592 | #Line # saves Clip and Matrix on stack; creates Layer for LCD text ## |
Cary Clark | 939fd6c | 2018-07-12 08:40:13 -0400 | [diff] [blame^] | 1593 | Saves Matrix and Clip, and allocates a Bitmap for subsequent drawing. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1594 | LCD_Text is preserved when the Layer is drawn to the prior Layer. |
| 1595 | |
Cary Clark | 939fd6c | 2018-07-12 08:40:13 -0400 | [diff] [blame^] | 1596 | Calling restore() discards changes to Matrix and Clip, and draws Layer. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1597 | |
| 1598 | Matrix may be changed by translate(), scale(), rotate(), skew(), concat(), |
| 1599 | setMatrix, and resetMatrix. Clip may be changed by clipRect, clipRRect, |
| 1600 | clipPath, clipRegion. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1601 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1602 | Rect bounds suggests but does not define the Layer size. To clip drawing to |
| 1603 | a specific rectangle, use clipRect. |
| 1604 | |
| 1605 | Optional Paint paint applies Color_Alpha, Color_Filter, Image_Filter, and |
| 1606 | Blend_Mode when restore() is called. |
| 1607 | |
| 1608 | Call restoreToCount with returned value to restore this and subsequent saves. |
| 1609 | |
| 1610 | Draw text on an opaque background so that LCD_Text blends correctly with the |
| 1611 | prior Layer. LCD_Text drawn on a background with transparency may result in |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1612 | incorrect blending. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1613 | |
| 1614 | #Param bounds hint to limit the size of Layer; may be nullptr ## |
| 1615 | #Param paint graphics state for Layer; may be nullptr ## |
| 1616 | |
| 1617 | #Return depth of saved stack ## |
| 1618 | |
| 1619 | #Example |
| 1620 | SkPaint paint; |
| 1621 | paint.setAntiAlias(true); |
| 1622 | paint.setLCDRenderText(true); |
| 1623 | paint.setTextSize(20); |
| 1624 | for (auto preserve : { false, true } ) { |
| 1625 | preserve ? canvas->saveLayerPreserveLCDTextRequests(nullptr, nullptr) |
| 1626 | : canvas->saveLayer(nullptr, nullptr); |
| 1627 | SkPaint p; |
| 1628 | p.setColor(SK_ColorWHITE); |
| 1629 | // Comment out the next line to draw on a non-opaque background. |
| 1630 | canvas->drawRect(SkRect::MakeLTRB(25, 40, 200, 70), p); |
| 1631 | canvas->drawString("Hamburgefons", 30, 60, paint); |
| 1632 | |
| 1633 | p.setColor(0xFFCCCCCC); |
| 1634 | canvas->drawRect(SkRect::MakeLTRB(25, 70, 200, 100), p); |
| 1635 | canvas->drawString("Hamburgefons", 30, 90, paint); |
| 1636 | |
| 1637 | canvas->restore(); |
| 1638 | canvas->translate(0, 80); |
| 1639 | } |
| 1640 | ## |
| 1641 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1642 | #SeeAlso save() restore() saveLayer saveLayerAlpha SaveLayerRec |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1643 | |
| 1644 | ## |
| 1645 | |
| 1646 | #Method int saveLayerAlpha(const SkRect* bounds, U8CPU alpha) |
| 1647 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1648 | #In Layer |
| 1649 | #Line # saves Clip and Matrix on stack; creates Layer; sets opacity ## |
Cary Clark | 939fd6c | 2018-07-12 08:40:13 -0400 | [diff] [blame^] | 1650 | Saves Matrix and Clip, and allocates Bitmap for subsequent drawing. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1651 | |
Cary Clark | 939fd6c | 2018-07-12 08:40:13 -0400 | [diff] [blame^] | 1652 | Calling restore() discards changes to Matrix and Clip, |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1653 | and blends Layer with alpha opacity onto prior Layer. |
| 1654 | |
| 1655 | Matrix may be changed by translate(), scale(), rotate(), skew(), concat(), |
| 1656 | setMatrix, and resetMatrix. Clip may be changed by clipRect, clipRRect, |
| 1657 | clipPath, clipRegion. |
| 1658 | |
| 1659 | Rect bounds suggests but does not define Layer size. To clip drawing to |
| 1660 | a specific rectangle, use clipRect. |
| 1661 | |
| 1662 | alpha of zero is fully transparent, 255 is fully opaque. |
| 1663 | |
| 1664 | Call restoreToCount with returned value to restore this and subsequent saves. |
| 1665 | |
| 1666 | #Param bounds hint to limit the size of Layer; may be nullptr ## |
| 1667 | #Param alpha opacity of Layer ## |
| 1668 | |
| 1669 | #Return depth of saved stack ## |
| 1670 | |
| 1671 | #Example |
| 1672 | SkPaint paint; |
| 1673 | paint.setColor(SK_ColorRED); |
| 1674 | canvas->drawCircle(50, 50, 50, paint); |
| 1675 | canvas->saveLayerAlpha(nullptr, 128); |
| 1676 | paint.setColor(SK_ColorBLUE); |
| 1677 | canvas->drawCircle(100, 50, 50, paint); |
| 1678 | paint.setColor(SK_ColorGREEN); |
| 1679 | paint.setAlpha(128); |
| 1680 | canvas->drawCircle(75, 90, 50, paint); |
| 1681 | canvas->restore(); |
| 1682 | ## |
| 1683 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1684 | #SeeAlso save() restore() saveLayer saveLayerPreserveLCDTextRequests SaveLayerRec |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1685 | |
| 1686 | ## |
| 1687 | |
Cary Clark | d98f78c | 2018-04-26 08:32:37 -0400 | [diff] [blame] | 1688 | #Enum SaveLayerFlagsSet |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1689 | #Line # sets SaveLayerRec options ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1690 | #Code |
Cary Clark | d98f78c | 2018-04-26 08:32:37 -0400 | [diff] [blame] | 1691 | enum SaveLayerFlagsSet { |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1692 | kPreserveLCDText_SaveLayerFlag = 1 << 1, |
| 1693 | kInitWithPrevious_SaveLayerFlag = 1 << 2, |
Mike Reed | 910ca0f | 2018-04-25 13:04:05 -0400 | [diff] [blame] | 1694 | kMaskAgainstCoverage_EXPERIMENTAL_DONT_USE_SaveLayerFlag = 1 << 3, |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1695 | kDontClipToLayer_Legacy_SaveLayerFlag = kDontClipToLayer_PrivateSaveLayerFlag, |
| 1696 | }; |
Cary Clark | d98f78c | 2018-04-26 08:32:37 -0400 | [diff] [blame] | 1697 | |
| 1698 | typedef uint32_t SaveLayerFlags; |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1699 | ## |
| 1700 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1701 | |
| 1702 | #Typedef uint32_t SaveLayerFlags |
| 1703 | #Line # options for SaveLayerRec ## |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 1704 | ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1705 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1706 | SaveLayerFlags provides options that may be used in any combination in SaveLayerRec, |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1707 | defining how Layer allocated by saveLayer operates. It may be set to zero, |
| 1708 | kPreserveLCDText_SaveLayerFlag, kInitWithPrevious_SaveLayerFlag, or both flags. |
| 1709 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1710 | #Const kPreserveLCDText_SaveLayerFlag 2 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1711 | #Line # creates Layer for LCD text ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1712 | Creates Layer for LCD text. Flag is ignored if Layer Paint contains |
| 1713 | Image_Filter or Color_Filter. |
| 1714 | ## |
| 1715 | |
| 1716 | #Const kInitWithPrevious_SaveLayerFlag 4 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1717 | #Line # initializes with previous contents ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1718 | Initializes Layer with the contents of the previous Layer. |
| 1719 | ## |
| 1720 | |
Mike Reed | 910ca0f | 2018-04-25 13:04:05 -0400 | [diff] [blame] | 1721 | #Const kMaskAgainstCoverage_EXPERIMENTAL_DONT_USE_SaveLayerFlag 8 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1722 | #Experimental do not use |
Mike Reed | 910ca0f | 2018-04-25 13:04:05 -0400 | [diff] [blame] | 1723 | ## |
| 1724 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1725 | #Const kDontClipToLayer_Legacy_SaveLayerFlag 0x80000000 |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1726 | #Deprecated soon |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1727 | ## |
| 1728 | |
| 1729 | #Example |
| 1730 | #Height 160 |
| 1731 | #Description |
| 1732 | Canvas Layer captures red and blue circles scaled up by four. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1733 | scalePaint blends Layer back with transparency. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1734 | ## |
| 1735 | void draw(SkCanvas* canvas) { |
| 1736 | SkPaint redPaint, bluePaint, scalePaint; |
| 1737 | redPaint.setColor(SK_ColorRED); |
| 1738 | canvas->drawCircle(21, 21, 8, redPaint); |
| 1739 | bluePaint.setColor(SK_ColorBLUE); |
| 1740 | canvas->drawCircle(31, 21, 8, bluePaint); |
| 1741 | SkMatrix matrix; |
| 1742 | matrix.setScale(4, 4); |
| 1743 | scalePaint.setAlpha(0x40); |
| 1744 | scalePaint.setImageFilter( |
| 1745 | SkImageFilter::MakeMatrixFilter(matrix, kNone_SkFilterQuality, nullptr)); |
| 1746 | SkCanvas::SaveLayerRec saveLayerRec(nullptr, &scalePaint, |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1747 | SkCanvas::kInitWithPrevious_SaveLayerFlag); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1748 | canvas->saveLayer(saveLayerRec); |
| 1749 | canvas->restore(); |
| 1750 | } |
| 1751 | ## |
| 1752 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1753 | #SeeAlso save() restore() saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha SaveLayerRec |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1754 | |
| 1755 | #Enum ## |
| 1756 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1757 | #Subtopic SaveLayerRec |
| 1758 | #Line # contains the state used to create the Layer ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1759 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1760 | #Struct SaveLayerRec |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1761 | #Line # contains the state used to create the Layer ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1762 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1763 | #Code |
| 1764 | struct SaveLayerRec { |
| 1765 | SaveLayerRec*(... |
| 1766 | |
| 1767 | const SkRect* fBounds; |
| 1768 | const SkPaint* fPaint; |
| 1769 | const SkImageFilter* fBackdrop; |
| 1770 | SaveLayerFlags fSaveLayerFlags; |
| 1771 | }; |
| 1772 | ## |
| 1773 | |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 1774 | SaveLayerRec contains the state used to create the Layer. |
| 1775 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1776 | #Subtopic Overview |
| 1777 | #Populate |
| 1778 | ## |
| 1779 | |
| 1780 | #Subtopic Member |
| 1781 | #Populate |
| 1782 | ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1783 | |
| 1784 | #Member const SkRect* fBounds |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1785 | #Line # hints at Layer size limit ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1786 | fBounds is used as a hint to limit the size of Layer; may be nullptr. |
| 1787 | fBounds suggests but does not define Layer size. To clip drawing to |
| 1788 | a specific rectangle, use clipRect. |
| 1789 | ## |
| 1790 | |
| 1791 | #Member const SkPaint* fPaint |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1792 | #Line # modifies overlay ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1793 | fPaint modifies how Layer overlays the prior Layer; may be nullptr. |
| 1794 | Color_Alpha, Blend_Mode, Color_Filter, Draw_Looper, Image_Filter, and |
| 1795 | Mask_Filter affect Layer draw. |
| 1796 | ## |
| 1797 | |
| 1798 | #Member const SkImageFilter* fBackdrop |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1799 | #Line # applies Image_Filter to prior Layer ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1800 | fBackdrop applies Image_Filter to the prior Layer when copying to the Layer; |
| 1801 | may be nullptr. Use kInitWithPrevious_SaveLayerFlag to copy the |
| 1802 | prior Layer without an Image_Filter. |
| 1803 | ## |
| 1804 | |
| 1805 | #Member const SkImage* fClipMask |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1806 | #Line # clips Layer with Mask_Alpha ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1807 | restore() clips Layer by the Color_Alpha channel of fClipMask when |
| 1808 | Layer is copied to Device. fClipMask may be nullptr. . |
| 1809 | ## |
| 1810 | |
| 1811 | #Member const SkMatrix* fClipMatrix |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1812 | #Line # transforms Mask_Alpha used to clip ## |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1813 | fClipMatrix transforms fClipMask before it clips Layer. If |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1814 | fClipMask describes a translucent gradient, it may be scaled and rotated |
| 1815 | without introducing artifacts. fClipMatrix may be nullptr. |
| 1816 | ## |
| 1817 | |
| 1818 | #Member SaveLayerFlags fSaveLayerFlags |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1819 | #Line # preserves LCD Text, creates with prior Layer contents ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1820 | fSaveLayerFlags are used to create Layer without transparency, |
| 1821 | create Layer for LCD text, and to create Layer with the |
| 1822 | contents of the previous Layer. |
| 1823 | ## |
| 1824 | |
| 1825 | #Example |
| 1826 | #Height 160 |
| 1827 | #Description |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1828 | 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] | 1829 | 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] | 1830 | transferred to the main canvas. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1831 | ## |
| 1832 | void draw(SkCanvas* canvas) { |
| 1833 | SkPaint redPaint, bluePaint; |
| 1834 | redPaint.setAntiAlias(true); |
| 1835 | redPaint.setColor(SK_ColorRED); |
| 1836 | canvas->drawCircle(21, 21, 8, redPaint); |
| 1837 | bluePaint.setColor(SK_ColorBLUE); |
| 1838 | canvas->drawCircle(31, 21, 8, bluePaint); |
| 1839 | SkMatrix matrix; |
| 1840 | matrix.setScale(4, 4); |
| 1841 | auto scaler = SkImageFilter::MakeMatrixFilter(matrix, kNone_SkFilterQuality, nullptr); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1842 | SkCanvas::SaveLayerRec saveLayerRec(nullptr, nullptr, scaler.get(), 0); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1843 | canvas->saveLayer(saveLayerRec); |
| 1844 | canvas->drawCircle(125, 85, 8, redPaint); |
| 1845 | canvas->restore(); |
| 1846 | } |
| 1847 | ## |
| 1848 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1849 | #Subtopic Constructor |
| 1850 | #Populate |
| 1851 | ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1852 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1853 | #Method SaveLayerRec() |
| 1854 | #Line # constructs SaveLayerRec ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1855 | Sets fBounds, fPaint, and fBackdrop to nullptr. Clears fSaveLayerFlags. |
| 1856 | |
| 1857 | #Return empty SaveLayerRec ## |
| 1858 | |
| 1859 | #Example |
| 1860 | SkCanvas::SaveLayerRec rec1; |
Mike Klein | e083f7c | 2018-02-07 12:54:27 -0500 | [diff] [blame] | 1861 | rec1.fSaveLayerFlags = SkCanvas::kPreserveLCDText_SaveLayerFlag; |
| 1862 | SkCanvas::SaveLayerRec rec2(nullptr, nullptr, SkCanvas::kPreserveLCDText_SaveLayerFlag); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1863 | SkDebugf("rec1 %c= rec2\n", rec1.fBounds == rec2.fBounds |
| 1864 | && rec1.fPaint == rec2.fPaint |
| 1865 | && rec1.fBackdrop == rec2.fBackdrop |
| 1866 | && rec1.fSaveLayerFlags == rec2.fSaveLayerFlags ? '=' : '!'); |
| 1867 | #StdOut |
| 1868 | rec1 == rec2 |
| 1869 | ## |
| 1870 | ## |
| 1871 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1872 | #SeeAlso save() restore() saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha |
| 1873 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1874 | ## |
| 1875 | |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 1876 | #Method SaveLayerRec(const SkRect* bounds, const SkPaint* paint, SaveLayerFlags saveLayerFlags = 0) |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1877 | |
| 1878 | Sets fBounds, fPaint, and fSaveLayerFlags; sets fBackdrop to nullptr. |
| 1879 | |
| 1880 | #Param bounds Layer dimensions; may be nullptr ## |
| 1881 | #Param paint applied to Layer when overlaying prior Layer; may be nullptr ## |
| 1882 | #Param saveLayerFlags SaveLayerRec options to modify Layer ## |
| 1883 | |
| 1884 | #Return SaveLayerRec with empty backdrop ## |
| 1885 | |
| 1886 | #Example |
| 1887 | SkCanvas::SaveLayerRec rec1; |
| 1888 | SkCanvas::SaveLayerRec rec2(nullptr, nullptr); |
| 1889 | SkDebugf("rec1 %c= rec2\n", rec1.fBounds == rec2.fBounds |
| 1890 | && rec1.fPaint == rec2.fPaint |
| 1891 | && rec1.fBackdrop == rec2.fBackdrop |
| 1892 | && rec1.fSaveLayerFlags == rec2.fSaveLayerFlags ? '=' : '!'); |
| 1893 | #StdOut |
| 1894 | rec1 == rec2 |
| 1895 | ## |
| 1896 | ## |
| 1897 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1898 | #SeeAlso save() restore() saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha |
| 1899 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1900 | ## |
| 1901 | |
| 1902 | #Method SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop, |
| 1903 | SaveLayerFlags saveLayerFlags) |
| 1904 | |
| 1905 | Sets fBounds, fPaint, fBackdrop, and fSaveLayerFlags. |
| 1906 | |
| 1907 | #Param bounds Layer dimensions; may be nullptr ## |
| 1908 | #Param paint applied to Layer when overlaying prior Layer; |
| 1909 | may be nullptr |
| 1910 | ## |
| 1911 | #Param backdrop prior Layer copied with Image_Filter; may be nullptr |
| 1912 | ## |
| 1913 | #Param saveLayerFlags SaveLayerRec options to modify Layer ## |
| 1914 | |
| 1915 | #Return SaveLayerRec fully specified ## |
| 1916 | |
| 1917 | #Example |
| 1918 | SkCanvas::SaveLayerRec rec1; |
| 1919 | SkCanvas::SaveLayerRec rec2(nullptr, nullptr, nullptr, 0); |
| 1920 | SkDebugf("rec1 %c= rec2\n", rec1.fBounds == rec2.fBounds |
| 1921 | && rec1.fPaint == rec2.fPaint |
| 1922 | && rec1.fBackdrop == rec2.fBackdrop |
| 1923 | && rec1.fSaveLayerFlags == rec2.fSaveLayerFlags ? '=' : '!'); |
| 1924 | #StdOut |
| 1925 | rec1 == rec2 |
| 1926 | ## |
| 1927 | ## |
| 1928 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1929 | #SeeAlso save() restore() saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha |
| 1930 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1931 | ## |
| 1932 | |
| 1933 | #Method SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop, |
| 1934 | const SkImage* clipMask, const SkMatrix* clipMatrix, |
| 1935 | SaveLayerFlags saveLayerFlags) |
| 1936 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1937 | #Experimental not ready |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1938 | |
| 1939 | Sets fBounds, fPaint, fBackdrop, fClipMask, fClipMatrix, and fSaveLayerFlags. |
| 1940 | clipMatrix uses Color_Alpha channel of image, transformed by clipMatrix, to clip |
| 1941 | Layer when drawn to Canvas. |
| 1942 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1943 | Implementation is not complete; has no effect if Device is GPU-backed. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1944 | |
| 1945 | #Param bounds Layer dimensions; may be nullptr ## |
| 1946 | #Param paint graphics state applied to Layer when overlaying prior |
| 1947 | Layer; may be nullptr |
| 1948 | ## |
| 1949 | #Param backdrop prior Layer copied with Image_Filter; |
| 1950 | may be nullptr |
| 1951 | ## |
| 1952 | #Param clipMask clip applied to Layer; may be nullptr ## |
| 1953 | #Param clipMatrix matrix applied to clipMask; may be nullptr to use |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1954 | identity matrix |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1955 | ## |
| 1956 | #Param saveLayerFlags SaveLayerRec options to modify Layer ## |
| 1957 | |
| 1958 | #Return SaveLayerRec fully specified ## |
| 1959 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1960 | #SeeAlso save() restore() saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1961 | |
| 1962 | ## |
| 1963 | |
| 1964 | #Struct ## |
| 1965 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1966 | #Subtopic ## |
| 1967 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1968 | #Method int saveLayer(const SaveLayerRec& layerRec) |
| 1969 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1970 | #In Layer |
Cary Clark | 939fd6c | 2018-07-12 08:40:13 -0400 | [diff] [blame^] | 1971 | Saves Matrix and Clip, and allocates Bitmap for subsequent drawing. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1972 | |
Cary Clark | 939fd6c | 2018-07-12 08:40:13 -0400 | [diff] [blame^] | 1973 | Calling restore() discards changes to Matrix and Clip, |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1974 | and blends Bitmap with Color_Alpha opacity onto the prior Layer. |
| 1975 | |
| 1976 | Matrix may be changed by translate(), scale(), rotate(), skew(), concat(), |
| 1977 | setMatrix, and resetMatrix. Clip may be changed by clipRect, clipRRect, |
| 1978 | clipPath, clipRegion. |
| 1979 | |
| 1980 | SaveLayerRec contains the state used to create the Layer. |
| 1981 | |
| 1982 | Call restoreToCount with returned value to restore this and subsequent saves. |
| 1983 | |
| 1984 | #Param layerRec Layer state ## |
| 1985 | |
| 1986 | #Return depth of save state stack ## |
| 1987 | |
| 1988 | #Example |
| 1989 | #Description |
| 1990 | The example draws an image, and saves it into a Layer with kInitWithPrevious_SaveLayerFlag. |
| 1991 | Next it punches a hole in Layer and restore with SkBlendMode::kPlus. |
| 1992 | Where Layer was cleared, the original image will draw unchanged. |
| 1993 | Outside of the circle the mandrill is brightened. |
| 1994 | ## |
| 1995 | #Image 3 |
Hal Canary | c465d13 | 2017-12-08 10:21:31 -0500 | [diff] [blame] | 1996 | // sk_sp<SkImage> image = GetResourceAsImage("images/mandrill_256.png"); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1997 | canvas->drawImage(image, 0, 0, nullptr); |
| 1998 | SkCanvas::SaveLayerRec rec; |
| 1999 | SkPaint paint; |
| 2000 | paint.setBlendMode(SkBlendMode::kPlus); |
| 2001 | rec.fSaveLayerFlags = SkCanvas::kInitWithPrevious_SaveLayerFlag; |
| 2002 | rec.fPaint = &paint; |
| 2003 | canvas->saveLayer(rec); |
| 2004 | paint.setBlendMode(SkBlendMode::kClear); |
| 2005 | canvas->drawCircle(128, 128, 96, paint); |
| 2006 | canvas->restore(); |
| 2007 | ## |
| 2008 | |
| 2009 | #ToDo above example needs to replace GetResourceAsImage with way to select image in fiddle ## |
| 2010 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2011 | #SeeAlso save() restore() saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha |
| 2012 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2013 | ## |
| 2014 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2015 | #Subtopic Layer ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2016 | |
| 2017 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2018 | #Subtopic Matrix |
| 2019 | #Line # coordinate transformation ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2020 | |
| 2021 | #Method void translate(SkScalar dx, SkScalar dy) |
| 2022 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2023 | #In Matrix |
| 2024 | #Line # translates Matrix ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2025 | Translates Matrix by dx along the x-axis and dy along the y-axis. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2026 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2027 | Mathematically, replaces Matrix with a translation matrix |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2028 | Premultiplied with Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2029 | |
| 2030 | This has the effect of moving the drawing by (dx, dy) before transforming |
| 2031 | the result with Matrix. |
| 2032 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2033 | #Param dx distance to translate in x ## |
| 2034 | #Param dy distance to translate in y ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2035 | |
| 2036 | #Example |
| 2037 | #Height 128 |
| 2038 | #Description |
| 2039 | scale() followed by translate() produces different results from translate() followed |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2040 | by scale(). |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2041 | |
| 2042 | The blue stroke follows translate of (50, 50); a black |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2043 | 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] | 2044 | Matrix, a red frame follows the same scale of (2, 1/2.f); a gray fill |
| 2045 | follows translate of (50, 50). |
| 2046 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2047 | void draw(SkCanvas* canvas) { |
| 2048 | SkPaint filledPaint; |
| 2049 | SkPaint outlinePaint; |
| 2050 | outlinePaint.setStyle(SkPaint::kStroke_Style); |
| 2051 | outlinePaint.setColor(SK_ColorBLUE); |
| 2052 | canvas->save(); |
| 2053 | canvas->translate(50, 50); |
| 2054 | canvas->drawCircle(28, 28, 15, outlinePaint); // blue center: (50+28, 50+28) |
| 2055 | canvas->scale(2, 1/2.f); |
| 2056 | canvas->drawCircle(28, 28, 15, filledPaint); // black center: (50+(28*2), 50+(28/2)) |
| 2057 | canvas->restore(); |
| 2058 | filledPaint.setColor(SK_ColorGRAY); |
| 2059 | outlinePaint.setColor(SK_ColorRED); |
| 2060 | canvas->scale(2, 1/2.f); |
| 2061 | canvas->drawCircle(28, 28, 15, outlinePaint); // red center: (28*2, 28/2) |
| 2062 | canvas->translate(50, 50); |
| 2063 | 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] | 2064 | } |
| 2065 | ## |
| 2066 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2067 | #SeeAlso concat() scale() skew() rotate() setMatrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2068 | |
| 2069 | ## |
| 2070 | |
| 2071 | # ------------------------------------------------------------------------------ |
| 2072 | |
| 2073 | #Method void scale(SkScalar sx, SkScalar sy) |
| 2074 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2075 | #In Matrix |
| 2076 | #Line # scales Matrix ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2077 | Scales Matrix by sx on the x-axis and sy on the y-axis. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2078 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2079 | Mathematically, replaces Matrix with a scale matrix |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2080 | Premultiplied with Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2081 | |
| 2082 | This has the effect of scaling the drawing by (sx, sy) before transforming |
| 2083 | the result with Matrix. |
| 2084 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2085 | #Param sx amount to scale in x ## |
| 2086 | #Param sy amount to scale in y ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2087 | |
| 2088 | #Example |
| 2089 | #Height 160 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2090 | void draw(SkCanvas* canvas) { |
| 2091 | SkPaint paint; |
| 2092 | SkRect rect = { 10, 20, 60, 120 }; |
| 2093 | canvas->translate(20, 20); |
| 2094 | canvas->drawRect(rect, paint); |
| 2095 | canvas->scale(2, .5f); |
| 2096 | paint.setColor(SK_ColorGRAY); |
| 2097 | canvas->drawRect(rect, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2098 | } |
| 2099 | ## |
| 2100 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2101 | #SeeAlso concat() translate() skew() rotate() setMatrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2102 | |
| 2103 | ## |
| 2104 | |
| 2105 | # ------------------------------------------------------------------------------ |
| 2106 | |
| 2107 | #Method void rotate(SkScalar degrees) |
| 2108 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2109 | #In Matrix |
| 2110 | #Line # rotates Matrix ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2111 | Rotates Matrix by degrees. Positive degrees rotates clockwise. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2112 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2113 | Mathematically, replaces Matrix with a rotation matrix |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2114 | Premultiplied with Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2115 | |
| 2116 | This has the effect of rotating the drawing by degrees before transforming |
| 2117 | the result with Matrix. |
| 2118 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2119 | #Param degrees amount to rotate, in degrees ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2120 | |
| 2121 | #Example |
| 2122 | #Description |
| 2123 | Draw clock hands at time 5:10. The hour hand and minute hand point up and |
| 2124 | are rotated clockwise. |
| 2125 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2126 | void draw(SkCanvas* canvas) { |
| 2127 | SkPaint paint; |
| 2128 | paint.setStyle(SkPaint::kStroke_Style); |
| 2129 | canvas->translate(128, 128); |
| 2130 | canvas->drawCircle(0, 0, 60, paint); |
| 2131 | canvas->save(); |
| 2132 | 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] | 2133 | canvas->drawLine(0, 0, 0, -50, paint); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2134 | canvas->restore(); |
| 2135 | canvas->rotate((5 + 10.f/60) * 360 / 12); // 5 and 10/60 hours of 12 scaled to 360 degrees |
| 2136 | canvas->drawLine(0, 0, 0, -30, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2137 | } |
| 2138 | ## |
| 2139 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2140 | #SeeAlso concat() translate() skew() scale() setMatrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2141 | |
| 2142 | ## |
| 2143 | |
| 2144 | # ------------------------------------------------------------------------------ |
| 2145 | |
| 2146 | #Method void rotate(SkScalar degrees, SkScalar px, SkScalar py) |
| 2147 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2148 | #In Matrix |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2149 | Rotates Matrix by degrees about a point at (px, py). Positive degrees rotates |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2150 | clockwise. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2151 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2152 | Mathematically, constructs a rotation matrix; Premultiplies the rotation matrix by |
| 2153 | a translation matrix; then replaces Matrix with the resulting matrix |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2154 | Premultiplied with Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2155 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2156 | This has the effect of rotating the drawing about a given point before |
| 2157 | transforming the result with Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2158 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2159 | #Param degrees amount to rotate, in degrees ## |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 2160 | #Param px x-axis value of the point to rotate about ## |
| 2161 | #Param py y-axis value of the point to rotate about ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2162 | |
| 2163 | #Example |
| 2164 | #Height 192 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2165 | void draw(SkCanvas* canvas) { |
| 2166 | SkPaint paint; |
| 2167 | paint.setTextSize(96); |
| 2168 | canvas->drawString("A1", 130, 100, paint); |
| 2169 | canvas->rotate(180, 130, 100); |
| 2170 | canvas->drawString("A1", 130, 100, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2171 | } |
| 2172 | ## |
| 2173 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2174 | #SeeAlso concat() translate() skew() scale() setMatrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2175 | |
| 2176 | ## |
| 2177 | |
| 2178 | # ------------------------------------------------------------------------------ |
| 2179 | |
| 2180 | #Method void skew(SkScalar sx, SkScalar sy) |
| 2181 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2182 | #In Matrix |
| 2183 | #Line # skews Matrix ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2184 | Skews Matrix by sx on the x-axis and sy on the y-axis. A positive value of sx |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 2185 | skews the drawing right as y-axis values increase; a positive value of sy skews |
| 2186 | the drawing down as x-axis values increase. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2187 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2188 | Mathematically, replaces Matrix with a skew matrix Premultiplied with Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2189 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2190 | This has the effect of skewing the drawing by (sx, sy) before transforming |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2191 | the result with Matrix. |
| 2192 | |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 2193 | #Param sx amount to skew on x-axis ## |
| 2194 | #Param sy amount to skew on y-axis ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2195 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2196 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2197 | #Description |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 2198 | Black text mimics an oblique text style by using a negative skew on x-axis |
| 2199 | that shifts the geometry to the right as the y-axis values decrease. |
| 2200 | Red text uses a positive skew on y-axis to shift the geometry down |
| 2201 | as the x-axis values increase. |
| 2202 | Blue text combines sx and sy skew to rotate and scale. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2203 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2204 | SkPaint paint; |
| 2205 | paint.setTextSize(128); |
| 2206 | canvas->translate(30, 130); |
| 2207 | canvas->save(); |
| 2208 | canvas->skew(-.5, 0); |
| 2209 | canvas->drawString("A1", 0, 0, paint); |
| 2210 | canvas->restore(); |
| 2211 | canvas->save(); |
| 2212 | canvas->skew(0, .5); |
| 2213 | paint.setColor(SK_ColorRED); |
| 2214 | canvas->drawString("A1", 0, 0, paint); |
| 2215 | canvas->restore(); |
| 2216 | canvas->skew(-.5, .5); |
| 2217 | paint.setColor(SK_ColorBLUE); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2218 | canvas->drawString("A1", 0, 0, paint); |
| 2219 | ## |
| 2220 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2221 | #SeeAlso concat() translate() rotate() scale() setMatrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2222 | |
| 2223 | ## |
| 2224 | |
| 2225 | # ------------------------------------------------------------------------------ |
| 2226 | |
| 2227 | #Method void concat(const SkMatrix& matrix) |
| 2228 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2229 | #In Matrix |
| 2230 | #Line # multiplies Matrix by Matrix ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2231 | Replaces Matrix with matrix Premultiplied with existing Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2232 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2233 | This has the effect of transforming the drawn geometry by matrix, before |
| 2234 | transforming the result with existing Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2235 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2236 | #Param matrix matrix to Premultiply with existing Matrix ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2237 | |
| 2238 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2239 | void draw(SkCanvas* canvas) { |
| 2240 | SkPaint paint; |
| 2241 | paint.setTextSize(80); |
| 2242 | paint.setTextScaleX(.3); |
| 2243 | SkMatrix matrix; |
| 2244 | SkRect rect[2] = {{ 10, 20, 90, 110 }, { 40, 130, 140, 180 }}; |
| 2245 | matrix.setRectToRect(rect[0], rect[1], SkMatrix::kFill_ScaleToFit); |
| 2246 | canvas->drawRect(rect[0], paint); |
| 2247 | canvas->drawRect(rect[1], paint); |
| 2248 | paint.setColor(SK_ColorWHITE); |
| 2249 | canvas->drawString("Here", rect[0].fLeft + 10, rect[0].fBottom - 10, paint); |
| 2250 | canvas->concat(matrix); |
| 2251 | canvas->drawString("There", rect[0].fLeft + 10, rect[0].fBottom - 10, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2252 | } |
| 2253 | ## |
| 2254 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2255 | #SeeAlso translate() rotate() scale() skew() setMatrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2256 | |
| 2257 | ## |
| 2258 | |
| 2259 | # ------------------------------------------------------------------------------ |
| 2260 | |
| 2261 | #Method void setMatrix(const SkMatrix& matrix) |
| 2262 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2263 | #In Matrix |
| 2264 | #Line # sets Matrix ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2265 | Replaces Matrix with matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2266 | Unlike concat(), any prior matrix state is overwritten. |
| 2267 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2268 | #Param matrix matrix to copy, replacing existing Matrix ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2269 | |
| 2270 | #Example |
| 2271 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2272 | void draw(SkCanvas* canvas) { |
| 2273 | SkPaint paint; |
| 2274 | canvas->scale(4, 6); |
| 2275 | canvas->drawString("truth", 2, 10, paint); |
| 2276 | SkMatrix matrix; |
| 2277 | matrix.setScale(2.8f, 6); |
| 2278 | canvas->setMatrix(matrix); |
| 2279 | canvas->drawString("consequences", 2, 20, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2280 | } |
| 2281 | ## |
| 2282 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2283 | #SeeAlso resetMatrix concat() translate() rotate() scale() skew() |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2284 | |
| 2285 | ## |
| 2286 | |
| 2287 | # ------------------------------------------------------------------------------ |
| 2288 | |
| 2289 | #Method void resetMatrix() |
| 2290 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2291 | #In Matrix |
| 2292 | #Line # resets Matrix to identity ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2293 | Sets Matrix to the identity matrix. |
| 2294 | Any prior matrix state is overwritten. |
| 2295 | |
| 2296 | #Example |
| 2297 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2298 | void draw(SkCanvas* canvas) { |
| 2299 | SkPaint paint; |
| 2300 | canvas->scale(4, 6); |
| 2301 | canvas->drawString("truth", 2, 10, paint); |
| 2302 | canvas->resetMatrix(); |
| 2303 | canvas->scale(2.8f, 6); |
| 2304 | canvas->drawString("consequences", 2, 20, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2305 | } |
| 2306 | ## |
| 2307 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2308 | #SeeAlso setMatrix concat() translate() rotate() scale() skew() |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2309 | |
| 2310 | ## |
| 2311 | |
| 2312 | # ------------------------------------------------------------------------------ |
| 2313 | |
| 2314 | #Method const SkMatrix& getTotalMatrix() const |
| 2315 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2316 | #In Matrix |
| 2317 | #Line # returns Matrix ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2318 | Returns Matrix. |
| 2319 | This does not account for translation by Device or Surface. |
| 2320 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2321 | #Return Matrix in Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2322 | |
| 2323 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2324 | SkDebugf("isIdentity %s\n", canvas->getTotalMatrix().isIdentity() ? "true" : "false"); |
| 2325 | #StdOut |
| 2326 | isIdentity true |
| 2327 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2328 | ## |
| 2329 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2330 | #SeeAlso setMatrix resetMatrix concat() |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2331 | |
| 2332 | ## |
| 2333 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2334 | #Subtopic Matrix ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2335 | |
| 2336 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2337 | #Subtopic Clip |
| 2338 | #Line # stack of clipping Paths ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2339 | |
| 2340 | 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] | 2341 | stack can be constructed from one or more Path_Contour elements. The |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2342 | Path_Contour may be composed of any number of Path_Verb segments. Each |
| 2343 | Path_Contour forms a closed area; Path_Fill_Type defines the area enclosed |
| 2344 | by Path_Contour. |
| 2345 | |
| 2346 | Clip stack of Path elements successfully restrict the Path area. Each |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2347 | Path is transformed by Matrix, then intersected with or subtracted from the |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2348 | prior Clip to form the replacement Clip. Use SkClipOp::kDifference |
| 2349 | to subtract Path from Clip; use SkClipOp::kIntersect to intersect Path |
| 2350 | with Clip. |
| 2351 | |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2352 | A clipping Path may be Anti_Aliased; if Path, after transformation, is |
| 2353 | composed of horizontal and vertical lines, clearing Anti_Alias allows whole pixels |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2354 | to either be inside or outside the clip. The fastest drawing has a Aliased, |
| 2355 | rectangular clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2356 | |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2357 | 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] | 2358 | that drawing blend partially with the destination along the edge. A rotated |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2359 | rectangular Anti_Aliased clip looks smoother but draws slower. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2360 | |
| 2361 | Clip can combine with Rect and Round_Rect primitives; like |
| 2362 | Path, these are transformed by Matrix before they are combined with Clip. |
| 2363 | |
| 2364 | Clip can combine with Region. Region is assumed to be in Device coordinates |
| 2365 | and is unaffected by Matrix. |
| 2366 | |
| 2367 | #Example |
| 2368 | #Height 90 |
| 2369 | #Description |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2370 | 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] | 2371 | Use an image filter to zoom into the pixels drawn. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2372 | 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] | 2373 | 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] | 2374 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2375 | SkPaint redPaint, scalePaint; |
| 2376 | redPaint.setAntiAlias(true); |
| 2377 | redPaint.setColor(SK_ColorRED); |
| 2378 | canvas->save(); |
| 2379 | for (bool antialias : { false, true } ) { |
| 2380 | canvas->save(); |
| 2381 | canvas->clipRect(SkRect::MakeWH(19.5f, 11.5f), antialias); |
| 2382 | canvas->drawCircle(17, 11, 8, redPaint); |
| 2383 | canvas->restore(); |
| 2384 | canvas->translate(16, 0); |
| 2385 | } |
| 2386 | canvas->restore(); |
| 2387 | SkMatrix matrix; |
| 2388 | matrix.setScale(6, 6); |
| 2389 | scalePaint.setImageFilter( |
| 2390 | SkImageFilter::MakeMatrixFilter(matrix, kNone_SkFilterQuality, nullptr)); |
| 2391 | SkCanvas::SaveLayerRec saveLayerRec( |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2392 | nullptr, &scalePaint, SkCanvas::kInitWithPrevious_SaveLayerFlag); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2393 | canvas->saveLayer(saveLayerRec); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2394 | canvas->restore(); |
| 2395 | ## |
| 2396 | |
| 2397 | #Method void clipRect(const SkRect& rect, SkClipOp op, bool doAntiAlias) |
| 2398 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2399 | #In Clip |
| 2400 | #Line # combines Clip with Rect ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2401 | Replaces Clip with the intersection or difference of Clip and rect, |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2402 | with an Aliased or Anti_Aliased clip edge. rect is transformed by Matrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2403 | before it is combined with Clip. |
| 2404 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 2405 | #Param rect Rect to combine with Clip ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2406 | #Param op Clip_Op to apply to Clip ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2407 | #Param doAntiAlias true if Clip is to be Anti_Aliased ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2408 | |
| 2409 | #Example |
| 2410 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2411 | void draw(SkCanvas* canvas) { |
| 2412 | canvas->rotate(10); |
| 2413 | SkPaint paint; |
| 2414 | paint.setAntiAlias(true); |
| 2415 | for (auto alias: { false, true } ) { |
| 2416 | canvas->save(); |
| 2417 | canvas->clipRect(SkRect::MakeWH(90, 80), SkClipOp::kIntersect, alias); |
| 2418 | canvas->drawCircle(100, 60, 60, paint); |
| 2419 | canvas->restore(); |
| 2420 | canvas->translate(80, 0); |
| 2421 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2422 | } |
| 2423 | ## |
| 2424 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2425 | #SeeAlso clipRRect clipPath clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2426 | |
| 2427 | ## |
| 2428 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2429 | #Method void clipRect(const SkRect& rect, SkClipOp op) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2430 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2431 | #In Clip |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2432 | Replaces Clip with the intersection or difference of Clip and rect. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2433 | Resulting Clip is Aliased; pixels are fully contained by the clip. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2434 | rect is transformed by Matrix before it is combined with Clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2435 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 2436 | #Param rect Rect to combine with Clip ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2437 | #Param op Clip_Op to apply to Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2438 | |
| 2439 | #Example |
| 2440 | #Height 192 |
| 2441 | #Width 280 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2442 | void draw(SkCanvas* canvas) { |
| 2443 | SkPaint paint; |
| 2444 | for (SkClipOp op: { SkClipOp::kIntersect, SkClipOp::kDifference } ) { |
| 2445 | canvas->save(); |
| 2446 | canvas->clipRect(SkRect::MakeWH(90, 120), op, false); |
| 2447 | canvas->drawCircle(100, 100, 60, paint); |
| 2448 | canvas->restore(); |
| 2449 | canvas->translate(80, 0); |
| 2450 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2451 | } |
| 2452 | ## |
| 2453 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2454 | #SeeAlso clipRRect clipPath clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2455 | |
| 2456 | ## |
| 2457 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2458 | #Method void clipRect(const SkRect& rect, bool doAntiAlias = false) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2459 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2460 | #In Clip |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2461 | Replaces Clip with the intersection of Clip and rect. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2462 | Resulting Clip is Aliased; pixels are fully contained by the clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2463 | rect is transformed by Matrix |
| 2464 | before it is combined with Clip. |
| 2465 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 2466 | #Param rect Rect to combine with Clip ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2467 | #Param doAntiAlias true if Clip is to be Anti_Aliased ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2468 | |
| 2469 | #Example |
| 2470 | #Height 133 |
| 2471 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2472 | A circle drawn in pieces looks uniform when drawn Aliased. |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2473 | 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] | 2474 | visible as a thin pair of lines through the right circle. |
| 2475 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2476 | void draw(SkCanvas* canvas) { |
| 2477 | canvas->clear(SK_ColorWHITE); |
| 2478 | SkPaint paint; |
| 2479 | paint.setAntiAlias(true); |
| 2480 | paint.setColor(0x8055aaff); |
| 2481 | SkRect clipRect = { 0, 0, 87.4f, 87.4f }; |
| 2482 | for (auto alias: { false, true } ) { |
| 2483 | canvas->save(); |
| 2484 | canvas->clipRect(clipRect, SkClipOp::kIntersect, alias); |
| 2485 | canvas->drawCircle(67, 67, 60, paint); |
| 2486 | canvas->restore(); |
| 2487 | canvas->save(); |
| 2488 | canvas->clipRect(clipRect, SkClipOp::kDifference, alias); |
| 2489 | canvas->drawCircle(67, 67, 60, paint); |
| 2490 | canvas->restore(); |
| 2491 | canvas->translate(120, 0); |
| 2492 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2493 | } |
| 2494 | ## |
| 2495 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2496 | #SeeAlso clipRRect clipPath clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2497 | |
| 2498 | ## |
| 2499 | |
| 2500 | #Method void androidFramework_setDeviceClipRestriction(const SkIRect& rect) |
| 2501 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2502 | #In Clip |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2503 | #Line # exists for use by Android framework ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2504 | Sets the maximum clip rectangle, which can be set by clipRect, clipRRect and |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2505 | clipPath and intersect the current clip with the specified rect. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2506 | The maximum clip affects only future clipping operations; it is not retroactive. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2507 | The clip restriction is not recorded in pictures. |
| 2508 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2509 | Pass an empty rect to disable maximum clip. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2510 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2511 | #Private |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 2512 | This private API is for use by Android framework only. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2513 | ## |
| 2514 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2515 | #Param rect maximum allowed clip in device coordinates |
Cary Clark | 579985c | 2017-07-31 11:48:27 -0400 | [diff] [blame] | 2516 | #Param ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2517 | |
| 2518 | ## |
| 2519 | |
| 2520 | #Method void clipRRect(const SkRRect& rrect, SkClipOp op, bool doAntiAlias) |
| 2521 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2522 | #In Clip |
| 2523 | #Line # combines Clip with Round_Rect ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2524 | Replaces Clip with the intersection or difference of Clip and rrect, |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2525 | with an Aliased or Anti_Aliased clip edge. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2526 | rrect is transformed by Matrix |
| 2527 | before it is combined with Clip. |
| 2528 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2529 | #Param rrect Round_Rect to combine with Clip ## |
| 2530 | #Param op Clip_Op to apply to Clip ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2531 | #Param doAntiAlias true if Clip is to be Anti_Aliased ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2532 | |
| 2533 | #Example |
| 2534 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2535 | void draw(SkCanvas* canvas) { |
| 2536 | canvas->clear(SK_ColorWHITE); |
| 2537 | SkPaint paint; |
| 2538 | paint.setAntiAlias(true); |
| 2539 | paint.setColor(0x8055aaff); |
| 2540 | SkRRect oval; |
| 2541 | oval.setOval({10, 20, 90, 100}); |
| 2542 | canvas->clipRRect(oval, SkClipOp::kIntersect, true); |
| 2543 | canvas->drawCircle(70, 100, 60, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2544 | } |
| 2545 | ## |
| 2546 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2547 | #SeeAlso clipRect clipPath clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2548 | |
| 2549 | ## |
| 2550 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2551 | #Method void clipRRect(const SkRRect& rrect, SkClipOp op) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2552 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2553 | #In Clip |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2554 | Replaces Clip with the intersection or difference of Clip and rrect. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2555 | Resulting Clip is Aliased; pixels are fully contained by the clip. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2556 | rrect is transformed by Matrix before it is combined with Clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2557 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2558 | #Param rrect Round_Rect to combine with Clip ## |
| 2559 | #Param op Clip_Op to apply to Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2560 | |
| 2561 | #Example |
| 2562 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2563 | void draw(SkCanvas* canvas) { |
| 2564 | SkPaint paint; |
| 2565 | paint.setColor(0x8055aaff); |
| 2566 | auto oval = SkRRect::MakeOval({10, 20, 90, 100}); |
| 2567 | canvas->clipRRect(oval, SkClipOp::kIntersect); |
| 2568 | canvas->drawCircle(70, 100, 60, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2569 | } |
| 2570 | ## |
| 2571 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2572 | #SeeAlso clipRect clipPath clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2573 | |
| 2574 | ## |
| 2575 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2576 | #Method void clipRRect(const SkRRect& rrect, bool doAntiAlias = false) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2577 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2578 | #In Clip |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2579 | Replaces Clip with the intersection of Clip and rrect, |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2580 | with an Aliased or Anti_Aliased clip edge. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2581 | rrect is transformed by Matrix before it is combined with Clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2582 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2583 | #Param rrect Round_Rect to combine with Clip ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2584 | #Param doAntiAlias true if Clip is to be Anti_Aliased ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2585 | |
| 2586 | #Example |
| 2587 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2588 | void draw(SkCanvas* canvas) { |
| 2589 | SkPaint paint; |
| 2590 | paint.setAntiAlias(true); |
| 2591 | auto oval = SkRRect::MakeRectXY({10, 20, 90, 100}, 9, 13); |
| 2592 | canvas->clipRRect(oval, true); |
| 2593 | canvas->drawCircle(70, 100, 60, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2594 | } |
| 2595 | ## |
| 2596 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2597 | #SeeAlso clipRect clipPath clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2598 | |
| 2599 | ## |
| 2600 | |
| 2601 | #Method void clipPath(const SkPath& path, SkClipOp op, bool doAntiAlias) |
| 2602 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2603 | #In Clip |
| 2604 | #Line # combines Clip with Path ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2605 | Replaces Clip with the intersection or difference of Clip and path, |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2606 | with an Aliased or Anti_Aliased clip edge. Path_Fill_Type determines if path |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2607 | describes the area inside or outside its contours; and if Path_Contour overlaps |
| 2608 | itself or another Path_Contour, whether the overlaps form part of the area. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2609 | path is transformed by Matrix before it is combined with Clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2610 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2611 | #Param path Path to combine with Clip ## |
| 2612 | #Param op Clip_Op to apply to Clip ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2613 | #Param doAntiAlias true if Clip is to be Anti_Aliased ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2614 | |
| 2615 | #Example |
| 2616 | #Description |
| 2617 | Top figure uses SkPath::kInverseWinding_FillType and SkClipOp::kDifference; |
| 2618 | area outside clip is subtracted from circle. |
| 2619 | |
| 2620 | Bottom figure uses SkPath::kWinding_FillType and SkClipOp::kIntersect; |
| 2621 | area inside clip is intersected with circle. |
| 2622 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2623 | void draw(SkCanvas* canvas) { |
| 2624 | SkPaint paint; |
| 2625 | paint.setAntiAlias(true); |
| 2626 | SkPath path; |
| 2627 | path.addRect({20, 30, 100, 110}); |
| 2628 | path.setFillType(SkPath::kInverseWinding_FillType); |
| 2629 | canvas->save(); |
| 2630 | canvas->clipPath(path, SkClipOp::kDifference, false); |
| 2631 | canvas->drawCircle(70, 100, 60, paint); |
| 2632 | canvas->restore(); |
| 2633 | canvas->translate(100, 100); |
| 2634 | path.setFillType(SkPath::kWinding_FillType); |
| 2635 | canvas->clipPath(path, SkClipOp::kIntersect, false); |
| 2636 | canvas->drawCircle(70, 100, 60, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2637 | } |
| 2638 | ## |
| 2639 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2640 | #SeeAlso clipRect clipRRect clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2641 | |
| 2642 | ## |
| 2643 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2644 | #Method void clipPath(const SkPath& path, SkClipOp op) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2645 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2646 | #In Clip |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2647 | Replaces Clip with the intersection or difference of Clip and path. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2648 | Resulting Clip is Aliased; pixels are fully contained by the clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2649 | Path_Fill_Type determines if path |
| 2650 | describes the area inside or outside its contours; and if Path_Contour overlaps |
| 2651 | itself or another Path_Contour, whether the overlaps form part of the area. |
| 2652 | path is transformed by Matrix |
| 2653 | before it is combined with Clip. |
| 2654 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2655 | #Param path Path to combine with Clip ## |
| 2656 | #Param op Clip_Op to apply to Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2657 | |
| 2658 | #Example |
| 2659 | #Description |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2660 | 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] | 2661 | SkPath::kWinding_FillType, the overlap is included. Set to |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2662 | SkPath::kEvenOdd_FillType, the overlap is excluded and forms a hole. |
| 2663 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2664 | void draw(SkCanvas* canvas) { |
| 2665 | SkPaint paint; |
| 2666 | paint.setAntiAlias(true); |
| 2667 | SkPath path; |
| 2668 | path.addRect({20, 15, 100, 95}); |
| 2669 | path.addRect({50, 65, 130, 135}); |
| 2670 | path.setFillType(SkPath::kWinding_FillType); |
| 2671 | canvas->save(); |
| 2672 | canvas->clipPath(path, SkClipOp::kIntersect); |
| 2673 | canvas->drawCircle(70, 85, 60, paint); |
| 2674 | canvas->restore(); |
| 2675 | canvas->translate(100, 100); |
| 2676 | path.setFillType(SkPath::kEvenOdd_FillType); |
| 2677 | canvas->clipPath(path, SkClipOp::kIntersect); |
| 2678 | canvas->drawCircle(70, 85, 60, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2679 | } |
| 2680 | ## |
| 2681 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2682 | #SeeAlso clipRect clipRRect clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2683 | |
| 2684 | ## |
| 2685 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2686 | #Method void clipPath(const SkPath& path, bool doAntiAlias = false) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2687 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2688 | #In Clip |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2689 | Replaces Clip with the intersection of Clip and path. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2690 | Resulting Clip is Aliased; pixels are fully contained by the clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2691 | Path_Fill_Type determines if path |
| 2692 | describes the area inside or outside its contours; and if Path_Contour overlaps |
| 2693 | itself or another Path_Contour, whether the overlaps form part of the area. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2694 | path is transformed by Matrix before it is combined with Clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2695 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2696 | #Param path Path to combine with Clip ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2697 | #Param doAntiAlias true if Clip is to be Anti_Aliased ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2698 | |
| 2699 | #Example |
| 2700 | #Height 212 |
| 2701 | #Description |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2702 | Clip loops over itself covering its center twice. When clip Path_Fill_Type |
| 2703 | is set to SkPath::kWinding_FillType, the overlap is included. Set to |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2704 | SkPath::kEvenOdd_FillType, the overlap is excluded and forms a hole. |
| 2705 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2706 | void draw(SkCanvas* canvas) { |
| 2707 | SkPaint paint; |
| 2708 | paint.setAntiAlias(true); |
| 2709 | SkPath path; |
| 2710 | SkPoint poly[] = {{20, 20}, { 80, 20}, { 80, 80}, {40, 80}, |
| 2711 | {40, 40}, {100, 40}, {100, 100}, {20, 100}}; |
| 2712 | path.addPoly(poly, SK_ARRAY_COUNT(poly), true); |
| 2713 | path.setFillType(SkPath::kWinding_FillType); |
| 2714 | canvas->save(); |
| 2715 | canvas->clipPath(path, SkClipOp::kIntersect); |
| 2716 | canvas->drawCircle(50, 50, 45, paint); |
| 2717 | canvas->restore(); |
| 2718 | canvas->translate(100, 100); |
| 2719 | path.setFillType(SkPath::kEvenOdd_FillType); |
| 2720 | canvas->clipPath(path, SkClipOp::kIntersect); |
| 2721 | canvas->drawCircle(50, 50, 45, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2722 | } |
| 2723 | ## |
| 2724 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2725 | #SeeAlso clipRect clipRRect clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2726 | |
| 2727 | ## |
| 2728 | |
| 2729 | # ------------------------------------------------------------------------------ |
| 2730 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2731 | #Method void setAllowSimplifyClip(bool allow) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2732 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2733 | #In Clip |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2734 | #Experimental testing |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2735 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2736 | Set to simplify clip stack using PathOps. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2737 | |
| 2738 | ## |
| 2739 | |
| 2740 | # ------------------------------------------------------------------------------ |
| 2741 | |
| 2742 | #Method void clipRegion(const SkRegion& deviceRgn, SkClipOp op = SkClipOp::kIntersect) |
| 2743 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2744 | #In Clip |
| 2745 | #Line # combines Clip with Region ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2746 | Replaces Clip with the intersection or difference of Clip and Region deviceRgn. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2747 | Resulting Clip is Aliased; pixels are fully contained by the clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2748 | deviceRgn is unaffected by Matrix. |
| 2749 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2750 | #Param deviceRgn Region to combine with Clip ## |
| 2751 | #Param op Clip_Op to apply to Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2752 | |
| 2753 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2754 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2755 | region is unaffected by canvas rotation; iRect is affected by canvas rotation. |
| 2756 | 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] | 2757 | aligns to pixel boundaries. |
| 2758 | ## |
| 2759 | void draw(SkCanvas* canvas) { |
| 2760 | SkPaint paint; |
| 2761 | paint.setAntiAlias(true); |
| 2762 | SkIRect iRect = {30, 40, 120, 130 }; |
| 2763 | SkRegion region(iRect); |
| 2764 | canvas->rotate(10); |
| 2765 | canvas->save(); |
| 2766 | canvas->clipRegion(region, SkClipOp::kIntersect); |
| 2767 | canvas->drawCircle(50, 50, 45, paint); |
| 2768 | canvas->restore(); |
| 2769 | canvas->translate(100, 100); |
| 2770 | canvas->clipRect(SkRect::Make(iRect), SkClipOp::kIntersect); |
| 2771 | canvas->drawCircle(50, 50, 45, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2772 | } |
| 2773 | ## |
| 2774 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2775 | #SeeAlso clipRect clipRRect clipPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2776 | |
| 2777 | ## |
| 2778 | |
| 2779 | #Method bool quickReject(const SkRect& rect) const |
| 2780 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2781 | #In Clip |
| 2782 | #Line # returns if Rect is outside Clip ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2783 | Returns true if Rect rect, transformed by Matrix, can be quickly determined to be |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2784 | outside of Clip. May return false even though rect is outside of Clip. |
| 2785 | |
| 2786 | Use to check if an area to be drawn is clipped out, to skip subsequent draw calls. |
| 2787 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2788 | #Param rect Rect to compare with Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2789 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2790 | #Return true if rect, transformed by Matrix, does not intersect Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2791 | |
| 2792 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2793 | void draw(SkCanvas* canvas) { |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2794 | SkRect testRect = {30, 30, 120, 129 }; |
| 2795 | SkRect clipRect = {30, 130, 120, 230 }; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2796 | canvas->save(); |
| 2797 | canvas->clipRect(clipRect); |
| 2798 | SkDebugf("quickReject %s\n", canvas->quickReject(testRect) ? "true" : "false"); |
| 2799 | canvas->restore(); |
| 2800 | canvas->rotate(10); |
| 2801 | canvas->clipRect(clipRect); |
| 2802 | SkDebugf("quickReject %s\n", canvas->quickReject(testRect) ? "true" : "false"); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2803 | } |
| 2804 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2805 | quickReject true |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2806 | quickReject false |
| 2807 | ## |
| 2808 | ## |
| 2809 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2810 | #SeeAlso getLocalClipBounds getTotalMatrix SkBitmap::drawsNothing |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2811 | |
| 2812 | ## |
| 2813 | |
| 2814 | #Method bool quickReject(const SkPath& path) const |
| 2815 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2816 | #In Clip |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2817 | Returns true if path, transformed by Matrix, can be quickly determined to be |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2818 | outside of Clip. May return false even though path is outside of Clip. |
| 2819 | |
| 2820 | Use to check if an area to be drawn is clipped out, to skip subsequent draw calls. |
| 2821 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2822 | #Param path Path to compare with Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2823 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2824 | #Return true if path, transformed by Matrix, does not intersect Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2825 | |
| 2826 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2827 | void draw(SkCanvas* canvas) { |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2828 | SkPoint testPoints[] = {{30, 30}, {120, 30}, {120, 129} }; |
| 2829 | SkPoint clipPoints[] = {{30, 130}, {120, 130}, {120, 230} }; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2830 | SkPath testPath, clipPath; |
| 2831 | testPath.addPoly(testPoints, SK_ARRAY_COUNT(testPoints), true); |
| 2832 | clipPath.addPoly(clipPoints, SK_ARRAY_COUNT(clipPoints), true); |
| 2833 | canvas->save(); |
| 2834 | canvas->clipPath(clipPath); |
| 2835 | SkDebugf("quickReject %s\n", canvas->quickReject(testPath) ? "true" : "false"); |
| 2836 | canvas->restore(); |
| 2837 | canvas->rotate(10); |
| 2838 | canvas->clipPath(clipPath); |
| 2839 | SkDebugf("quickReject %s\n", canvas->quickReject(testPath) ? "true" : "false"); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2840 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2841 | quickReject true |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2842 | quickReject false |
| 2843 | ## |
| 2844 | } |
| 2845 | ## |
| 2846 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2847 | #SeeAlso getLocalClipBounds getTotalMatrix SkBitmap::drawsNothing |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2848 | |
| 2849 | ## |
| 2850 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2851 | #Method SkRect getLocalClipBounds() const |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2852 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2853 | #In Clip |
| 2854 | #Line # returns Clip bounds in source coordinates ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2855 | Returns bounds of Clip, transformed by inverse of Matrix. If Clip is empty, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2856 | return SkRect::MakeEmpty, where all Rect sides equal zero. |
| 2857 | |
| 2858 | Rect returned is outset by one to account for partial pixel coverage if Clip |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2859 | is Anti_Aliased. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2860 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2861 | #Return bounds of Clip in local coordinates ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2862 | |
| 2863 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2864 | #Description |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2865 | Initial bounds is device bounds outset by 1 on all sides. |
| 2866 | Clipped bounds is clipPath bounds outset by 1 on all sides. |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 2867 | Scaling the canvas by two on both axes scales the local bounds by 1/2 |
| 2868 | on both axes. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2869 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2870 | SkCanvas local(256, 256); |
| 2871 | canvas = &local; |
| 2872 | SkRect bounds = canvas->getLocalClipBounds(); |
| 2873 | SkDebugf("left:%g top:%g right:%g bottom:%g\n", |
| 2874 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2875 | SkPoint clipPoints[] = {{30, 130}, {120, 130}, {120, 230} }; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2876 | SkPath clipPath; |
| 2877 | clipPath.addPoly(clipPoints, SK_ARRAY_COUNT(clipPoints), true); |
| 2878 | canvas->clipPath(clipPath); |
| 2879 | bounds = canvas->getLocalClipBounds(); |
| 2880 | SkDebugf("left:%g top:%g right:%g bottom:%g\n", |
| 2881 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
| 2882 | canvas->scale(2, 2); |
| 2883 | bounds = canvas->getLocalClipBounds(); |
| 2884 | SkDebugf("left:%g top:%g right:%g bottom:%g\n", |
| 2885 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
| 2886 | #StdOut |
| 2887 | left:-1 top:-1 right:257 bottom:257 |
| 2888 | left:29 top:129 right:121 bottom:231 |
| 2889 | left:14.5 top:64.5 right:60.5 bottom:115.5 |
| 2890 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2891 | ## |
| 2892 | |
| 2893 | # local canvas in example works around bug in fiddle ## |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2894 | #Bug 6524 |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2895 | #SeeAlso getDeviceClipBounds getBaseLayerSize quickReject |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2896 | |
| 2897 | ## |
| 2898 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2899 | #Method bool getLocalClipBounds(SkRect* bounds) const |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2900 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2901 | #In Clip |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2902 | Returns bounds of Clip, transformed by inverse of Matrix. If Clip is empty, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2903 | return false, and set bounds to SkRect::MakeEmpty, where all Rect sides equal zero. |
| 2904 | |
| 2905 | bounds is outset by one to account for partial pixel coverage if Clip |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2906 | is Anti_Aliased. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2907 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2908 | #Param bounds Rect of Clip in local coordinates ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2909 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2910 | #Return true if Clip bounds is not empty ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2911 | |
| 2912 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2913 | void draw(SkCanvas* canvas) { |
| 2914 | SkCanvas local(256, 256); |
| 2915 | canvas = &local; |
| 2916 | SkRect bounds; |
| 2917 | SkDebugf("local bounds empty = %s\n", canvas->getLocalClipBounds(&bounds) |
| 2918 | ? "false" : "true"); |
| 2919 | SkPath path; |
| 2920 | canvas->clipPath(path); |
| 2921 | SkDebugf("local bounds empty = %s\n", canvas->getLocalClipBounds(&bounds) |
| 2922 | ? "false" : "true"); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2923 | } |
| 2924 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2925 | local bounds empty = false |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2926 | local bounds empty = true |
| 2927 | ## |
| 2928 | ## |
| 2929 | |
| 2930 | # local canvas in example works around bug in fiddle ## |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2931 | #Bug 6524 |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2932 | #SeeAlso getDeviceClipBounds getBaseLayerSize quickReject |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2933 | |
| 2934 | ## |
| 2935 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2936 | #Method SkIRect getDeviceClipBounds() const |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2937 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2938 | #In Clip |
| 2939 | #Line # returns IRect bounds of Clip ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2940 | Returns IRect bounds of Clip, unaffected by Matrix. If Clip is empty, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2941 | return SkRect::MakeEmpty, where all Rect sides equal zero. |
| 2942 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2943 | Unlike getLocalClipBounds, returned IRect is not outset. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2944 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2945 | #Return bounds of Clip in Device coordinates ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2946 | |
| 2947 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2948 | void draw(SkCanvas* canvas) { |
| 2949 | #Description |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2950 | Initial bounds is device bounds, not outset. |
| 2951 | Clipped bounds is clipPath bounds, not outset. |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 2952 | Scaling the canvas by 1/2 on both axes scales the device bounds by 1/2 |
| 2953 | on both axes. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2954 | ## |
| 2955 | SkCanvas device(256, 256); |
| 2956 | canvas = &device; |
| 2957 | SkIRect bounds = canvas->getDeviceClipBounds(); |
| 2958 | SkDebugf("left:%d top:%d right:%d bottom:%d\n", |
| 2959 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2960 | SkPoint clipPoints[] = {{30, 130}, {120, 130}, {120, 230} }; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2961 | SkPath clipPath; |
| 2962 | clipPath.addPoly(clipPoints, SK_ARRAY_COUNT(clipPoints), true); |
| 2963 | canvas->save(); |
| 2964 | canvas->clipPath(clipPath); |
| 2965 | bounds = canvas->getDeviceClipBounds(); |
| 2966 | SkDebugf("left:%d top:%d right:%d bottom:%d\n", |
| 2967 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
| 2968 | canvas->restore(); |
| 2969 | canvas->scale(1.f/2, 1.f/2); |
| 2970 | canvas->clipPath(clipPath); |
| 2971 | bounds = canvas->getDeviceClipBounds(); |
| 2972 | SkDebugf("left:%d top:%d right:%d bottom:%d\n", |
| 2973 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2974 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2975 | left:0 top:0 right:256 bottom:256 |
| 2976 | left:30 top:130 right:120 bottom:230 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2977 | left:15 top:65 right:60 bottom:115 |
| 2978 | ## |
| 2979 | } |
| 2980 | ## |
| 2981 | |
| 2982 | #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] | 2983 | #SeeAlso getLocalClipBounds getBaseLayerSize quickReject |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2984 | |
| 2985 | # device canvas in example works around bug in fiddle ## |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2986 | #Bug 6524 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2987 | |
| 2988 | ## |
| 2989 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2990 | #Method bool getDeviceClipBounds(SkIRect* bounds) const |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2991 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2992 | #In Clip |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2993 | Returns IRect bounds of Clip, unaffected by Matrix. If Clip is empty, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2994 | return false, and set bounds to SkRect::MakeEmpty, where all Rect sides equal zero. |
| 2995 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2996 | Unlike getLocalClipBounds, bounds is not outset. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2997 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2998 | #Param bounds Rect of Clip in device coordinates ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2999 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3000 | #Return true if Clip bounds is not empty ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3001 | |
| 3002 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3003 | void draw(SkCanvas* canvas) { |
| 3004 | SkIRect bounds; |
| 3005 | SkDebugf("device bounds empty = %s\n", canvas->getDeviceClipBounds(&bounds) |
| 3006 | ? "false" : "true"); |
| 3007 | SkPath path; |
| 3008 | canvas->clipPath(path); |
| 3009 | SkDebugf("device bounds empty = %s\n", canvas->getDeviceClipBounds(&bounds) |
| 3010 | ? "false" : "true"); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3011 | } |
| 3012 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3013 | device bounds empty = false |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3014 | device bounds empty = true |
| 3015 | ## |
| 3016 | ## |
| 3017 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3018 | #SeeAlso getLocalClipBounds getBaseLayerSize quickReject |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3019 | |
| 3020 | ## |
| 3021 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3022 | #Subtopic Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3023 | |
| 3024 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3025 | #Subtopic Draw |
| 3026 | #Populate |
| 3027 | #Line # draws into Canvas ## |
| 3028 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3029 | |
| 3030 | #Method void drawColor(SkColor color, SkBlendMode mode = SkBlendMode::kSrcOver) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3031 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3032 | #Line # fills Clip with Color and Blend_Mode ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3033 | Fills Clip with Color color. |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 3034 | mode determines how ARGB is combined with destination. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3035 | |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 3036 | #Param color Unpremultiplied ARGB ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3037 | #Param mode SkBlendMode used to combine source color and destination ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3038 | |
| 3039 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3040 | canvas->drawColor(SK_ColorRED); |
| 3041 | canvas->clipRect(SkRect::MakeWH(150, 150)); |
| 3042 | canvas->drawColor(SkColorSetARGB(0x80, 0x00, 0xFF, 0x00), SkBlendMode::kPlus); |
| 3043 | canvas->clipRect(SkRect::MakeWH(75, 75)); |
| 3044 | canvas->drawColor(SkColorSetARGB(0x80, 0x00, 0x00, 0xFF), SkBlendMode::kPlus); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3045 | ## |
| 3046 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3047 | #SeeAlso clear SkBitmap::erase drawPaint |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3048 | |
| 3049 | ## |
| 3050 | |
| 3051 | # ------------------------------------------------------------------------------ |
| 3052 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3053 | #Method void clear(SkColor color) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3054 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3055 | #Line # fills Clip with Color ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3056 | Fills Clip with Color color using SkBlendMode::kSrc. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3057 | This has the effect of replacing all pixels contained by Clip with color. |
| 3058 | |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 3059 | #Param color Unpremultiplied ARGB ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3060 | |
| 3061 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3062 | void draw(SkCanvas* canvas) { |
| 3063 | canvas->save(); |
| 3064 | canvas->clipRect(SkRect::MakeWH(256, 128)); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3065 | canvas->clear(SkColorSetARGB(0x80, 0xFF, 0x00, 0x00)); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3066 | canvas->restore(); |
| 3067 | canvas->save(); |
| 3068 | canvas->clipRect(SkRect::MakeWH(150, 192)); |
| 3069 | canvas->clear(SkColorSetARGB(0x80, 0x00, 0xFF, 0x00)); |
| 3070 | canvas->restore(); |
| 3071 | canvas->clipRect(SkRect::MakeWH(75, 256)); |
| 3072 | canvas->clear(SkColorSetARGB(0x80, 0x00, 0x00, 0xFF)); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3073 | } |
| 3074 | ## |
| 3075 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3076 | #SeeAlso drawColor SkBitmap::erase drawPaint |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3077 | |
| 3078 | ## |
| 3079 | |
| 3080 | # ------------------------------------------------------------------------------ |
| 3081 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3082 | #Method void discard() |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3083 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3084 | #Line # makes Canvas contents undefined ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3085 | Makes Canvas contents undefined. Subsequent calls that read Canvas pixels, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3086 | such as drawing with SkBlendMode, return undefined results. discard() does |
| 3087 | not change Clip or Matrix. |
| 3088 | |
| 3089 | discard() may do nothing, depending on the implementation of Surface or Device |
| 3090 | that created Canvas. |
| 3091 | |
| 3092 | discard() allows optimized performance on subsequent draws by removing |
| 3093 | cached data associated with Surface or Device. |
| 3094 | It is not necessary to call discard() once done with Canvas; |
| 3095 | any cached data is deleted when owning Surface or Device is deleted. |
| 3096 | |
| 3097 | #ToDo example? not sure how to make this meaningful w/o more implementation detail ## |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3098 | #SeeAlso flush() SkSurface::prepareForExternalIO GrContext::abandonContext |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3099 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3100 | #NoExample |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3101 | ## |
| 3102 | |
| 3103 | ## |
| 3104 | |
| 3105 | # ------------------------------------------------------------------------------ |
| 3106 | |
| 3107 | #Method void drawPaint(const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3108 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3109 | #Line # fills Clip with Paint ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3110 | Fills Clip with Paint paint. Paint components Mask_Filter, Shader, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3111 | Color_Filter, Image_Filter, and Blend_Mode affect drawing; |
| 3112 | Path_Effect in paint is ignored. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3113 | |
| 3114 | # can Path_Effect in paint ever alter drawPaint? |
| 3115 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3116 | #Param paint graphics state used to fill Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3117 | |
| 3118 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3119 | void draw(SkCanvas* canvas) { |
| 3120 | SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE }; |
| 3121 | SkScalar pos[] = { 0, SK_Scalar1/2, SK_Scalar1 }; |
| 3122 | SkPaint paint; |
| 3123 | paint.setShader(SkGradientShader::MakeSweep(256, 256, colors, pos, SK_ARRAY_COUNT(colors))); |
| 3124 | canvas->drawPaint(paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3125 | } |
| 3126 | ## |
| 3127 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3128 | #SeeAlso clear drawColor SkBitmap::erase |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3129 | |
| 3130 | ## |
| 3131 | |
| 3132 | # ------------------------------------------------------------------------------ |
| 3133 | |
| 3134 | #Enum PointMode |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3135 | #Line # sets drawPoints options ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3136 | |
| 3137 | #Code |
| 3138 | enum PointMode { |
| 3139 | kPoints_PointMode, |
| 3140 | kLines_PointMode, |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 3141 | kPolygon_PointMode, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3142 | }; |
| 3143 | ## |
| 3144 | |
| 3145 | Selects if an array of points are drawn as discrete points, as lines, or as |
| 3146 | an open polygon. |
| 3147 | |
| 3148 | #Const kPoints_PointMode 0 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3149 | #Line # draw each point separately ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3150 | ## |
| 3151 | |
| 3152 | #Const kLines_PointMode 1 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3153 | #Line # draw each pair of points as a line segment ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3154 | ## |
| 3155 | |
| 3156 | #Const kPolygon_PointMode 2 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3157 | #Line # draw the array of points as a open polygon ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3158 | ## |
| 3159 | |
| 3160 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3161 | #Description |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3162 | The upper left corner shows three squares when drawn as points. |
| 3163 | The upper right corner shows one line; when drawn as lines, two points are required per line. |
| 3164 | The lower right corner shows two lines; when draw as polygon, no miter is drawn at the corner. |
| 3165 | The lower left corner shows two lines with a miter when path contains polygon. |
| 3166 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3167 | void draw(SkCanvas* canvas) { |
| 3168 | SkPaint paint; |
| 3169 | paint.setStyle(SkPaint::kStroke_Style); |
| 3170 | paint.setStrokeWidth(10); |
| 3171 | SkPoint points[] = {{64, 32}, {96, 96}, {32, 96}}; |
| 3172 | canvas->drawPoints(SkCanvas::kPoints_PointMode, 3, points, paint); |
| 3173 | canvas->translate(128, 0); |
| 3174 | canvas->drawPoints(SkCanvas::kLines_PointMode, 3, points, paint); |
| 3175 | canvas->translate(0, 128); |
| 3176 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, 3, points, paint); |
| 3177 | SkPath path; |
| 3178 | path.addPoly(points, 3, false); |
| 3179 | canvas->translate(-128, 0); |
| 3180 | canvas->drawPath(path, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3181 | } |
| 3182 | ## |
| 3183 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3184 | #SeeAlso drawLine drawPoint drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3185 | |
| 3186 | ## |
| 3187 | |
| 3188 | # ------------------------------------------------------------------------------ |
| 3189 | |
| 3190 | #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] | 3191 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3192 | #Line # draws array as points, lines, polygon ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3193 | Draws pts using Clip, Matrix and Paint paint. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3194 | count is the number of points; if count is less than one, has no effect. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3195 | mode may be one of: kPoints_PointMode, kLines_PointMode, or kPolygon_PointMode. |
| 3196 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3197 | If mode is kPoints_PointMode, the shape of point drawn depends on paint |
| 3198 | Paint_Stroke_Cap. If paint is set to SkPaint::kRound_Cap, each point draws a |
| 3199 | circle of diameter Paint_Stroke_Width. If paint is set to SkPaint::kSquare_Cap |
| 3200 | or SkPaint::kButt_Cap, each point draws a square of width and height |
| 3201 | Paint_Stroke_Width. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3202 | |
| 3203 | If mode is kLines_PointMode, each pair of points draws a line segment. |
| 3204 | One line is drawn for every two points; each point is used once. If count is odd, |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3205 | the final point is ignored. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3206 | |
| 3207 | If mode is kPolygon_PointMode, each adjacent pair of points draws a line segment. |
| 3208 | count minus one lines are drawn; the first and last point are used once. |
| 3209 | |
| 3210 | Each line segment respects paint Paint_Stroke_Cap and Paint_Stroke_Width. |
| 3211 | Paint_Style is ignored, as if were set to SkPaint::kStroke_Style. |
| 3212 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3213 | Always draws each element one at a time; is not affected by |
| 3214 | Paint_Stroke_Join, and unlike drawPath, does not create a mask from all points |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3215 | and lines before drawing. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3216 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 3217 | #Param mode whether pts draws points or lines ## |
| 3218 | #Param count number of points in the array ## |
| 3219 | #Param pts array of points to draw ## |
| 3220 | #Param paint stroke, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3221 | |
| 3222 | #Example |
| 3223 | #Height 200 |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3224 | #Description |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3225 | #List |
| 3226 | # The first column draws points. ## |
| 3227 | # The second column draws points as lines. ## |
| 3228 | # The third column draws points as a polygon. ## |
| 3229 | # The fourth column draws points as a polygonal path. ## |
| 3230 | # The first row uses a round cap and round join. ## |
| 3231 | # The second row uses a square cap and a miter join. ## |
| 3232 | # The third row uses a butt cap and a bevel join. ## |
| 3233 | ## |
| 3234 | The transparent color makes multiple line draws visible; |
| 3235 | the path is drawn all at once. |
| 3236 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3237 | void draw(SkCanvas* canvas) { |
| 3238 | SkPaint paint; |
| 3239 | paint.setAntiAlias(true); |
| 3240 | paint.setStyle(SkPaint::kStroke_Style); |
| 3241 | paint.setStrokeWidth(10); |
| 3242 | paint.setColor(0x80349a45); |
| 3243 | const SkPoint points[] = {{32, 16}, {48, 48}, {16, 32}}; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3244 | const SkPaint::Join join[] = { SkPaint::kRound_Join, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3245 | SkPaint::kMiter_Join, |
| 3246 | SkPaint::kBevel_Join }; |
| 3247 | int joinIndex = 0; |
| 3248 | SkPath path; |
| 3249 | path.addPoly(points, 3, false); |
| 3250 | for (const auto cap : { SkPaint::kRound_Cap, SkPaint::kSquare_Cap, SkPaint::kButt_Cap } ) { |
| 3251 | paint.setStrokeCap(cap); |
| 3252 | paint.setStrokeJoin(join[joinIndex++]); |
| 3253 | for (const auto mode : { SkCanvas::kPoints_PointMode, |
| 3254 | SkCanvas::kLines_PointMode, |
| 3255 | SkCanvas::kPolygon_PointMode } ) { |
| 3256 | canvas->drawPoints(mode, 3, points, paint); |
| 3257 | canvas->translate(64, 0); |
| 3258 | } |
| 3259 | canvas->drawPath(path, paint); |
| 3260 | canvas->translate(-192, 64); |
| 3261 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3262 | } |
| 3263 | ## |
| 3264 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3265 | #SeeAlso drawLine drawPoint drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3266 | |
| 3267 | ## |
| 3268 | |
| 3269 | # ------------------------------------------------------------------------------ |
| 3270 | |
| 3271 | #Method void drawPoint(SkScalar x, SkScalar y, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3272 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3273 | #Line # draws point at (x, y) position ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3274 | Draws point at (x, y) using Clip, Matrix and Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3275 | |
| 3276 | The shape of point drawn depends on paint Paint_Stroke_Cap. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3277 | If paint is set to SkPaint::kRound_Cap, draw a circle of diameter |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3278 | Paint_Stroke_Width. If paint is set to SkPaint::kSquare_Cap or SkPaint::kButt_Cap, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3279 | draw a square of width and height Paint_Stroke_Width. |
| 3280 | Paint_Style is ignored, as if were set to SkPaint::kStroke_Style. |
| 3281 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3282 | #Param x left edge of circle or square ## |
| 3283 | #Param y top edge of circle or square ## |
| 3284 | #Param paint stroke, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3285 | |
| 3286 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3287 | void draw(SkCanvas* canvas) { |
| 3288 | SkPaint paint; |
| 3289 | paint.setAntiAlias(true); |
| 3290 | paint.setColor(0x80349a45); |
| 3291 | paint.setStyle(SkPaint::kStroke_Style); |
| 3292 | paint.setStrokeWidth(100); |
| 3293 | paint.setStrokeCap(SkPaint::kRound_Cap); |
| 3294 | canvas->scale(1, 1.2f); |
| 3295 | canvas->drawPoint(64, 96, paint); |
| 3296 | canvas->scale(.6f, .8f); |
| 3297 | paint.setColor(SK_ColorWHITE); |
| 3298 | canvas->drawPoint(106, 120, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3299 | } |
| 3300 | ## |
| 3301 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3302 | #SeeAlso drawPoints drawCircle drawRect drawLine drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3303 | |
| 3304 | ## |
| 3305 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3306 | #Method void drawPoint(SkPoint p, const SkPaint& paint) |
| 3307 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3308 | Draws point p using Clip, Matrix and Paint paint. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3309 | |
| 3310 | The shape of point drawn depends on paint Paint_Stroke_Cap. |
| 3311 | If paint is set to SkPaint::kRound_Cap, draw a circle of diameter |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3312 | Paint_Stroke_Width. If paint is set to SkPaint::kSquare_Cap or SkPaint::kButt_Cap, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3313 | draw a square of width and height Paint_Stroke_Width. |
| 3314 | Paint_Style is ignored, as if were set to SkPaint::kStroke_Style. |
| 3315 | |
| 3316 | #Param p top-left edge of circle or square ## |
| 3317 | #Param paint stroke, blend, color, and so on, used to draw ## |
| 3318 | |
| 3319 | #Example |
| 3320 | void draw(SkCanvas* canvas) { |
| 3321 | SkPaint paint; |
| 3322 | paint.setAntiAlias(true); |
| 3323 | paint.setColor(0x80349a45); |
| 3324 | paint.setStyle(SkPaint::kStroke_Style); |
| 3325 | paint.setStrokeWidth(100); |
| 3326 | paint.setStrokeCap(SkPaint::kSquare_Cap); |
| 3327 | canvas->scale(1, 1.2f); |
| 3328 | canvas->drawPoint({64, 96}, paint); |
| 3329 | canvas->scale(.6f, .8f); |
| 3330 | paint.setColor(SK_ColorWHITE); |
| 3331 | canvas->drawPoint(106, 120, paint); |
| 3332 | } |
| 3333 | ## |
| 3334 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3335 | #SeeAlso drawPoints drawCircle drawRect drawLine drawPath |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3336 | |
| 3337 | ## |
| 3338 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3339 | # ------------------------------------------------------------------------------ |
| 3340 | |
| 3341 | #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] | 3342 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3343 | #Line # draws line segment between two points ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3344 | Draws line segment from (x0, y0) to (x1, y1) using Clip, Matrix, and Paint paint. |
| 3345 | In paint: Paint_Stroke_Width describes the line thickness; |
| 3346 | Paint_Stroke_Cap draws the end rounded or square; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3347 | Paint_Style is ignored, as if were set to SkPaint::kStroke_Style. |
| 3348 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3349 | #Param x0 start of line segment on x-axis ## |
| 3350 | #Param y0 start of line segment on y-axis ## |
| 3351 | #Param x1 end of line segment on x-axis ## |
| 3352 | #Param y1 end of line segment on y-axis ## |
| 3353 | #Param paint stroke, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3354 | |
| 3355 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3356 | SkPaint paint; |
| 3357 | paint.setAntiAlias(true); |
| 3358 | paint.setColor(0xFF9a67be); |
| 3359 | paint.setStrokeWidth(20); |
| 3360 | canvas->skew(1, 0); |
| 3361 | canvas->drawLine(32, 96, 32, 160, paint); |
| 3362 | canvas->skew(-2, 0); |
| 3363 | canvas->drawLine(288, 96, 288, 160, paint); |
| 3364 | ## |
| 3365 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3366 | #SeeAlso drawPoint drawCircle drawRect drawPath |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3367 | |
| 3368 | ## |
| 3369 | |
| 3370 | #Method void drawLine(SkPoint p0, SkPoint p1, const SkPaint& paint) |
| 3371 | |
| 3372 | Draws line segment from p0 to p1 using Clip, Matrix, and Paint paint. |
| 3373 | In paint: Paint_Stroke_Width describes the line thickness; |
| 3374 | Paint_Stroke_Cap draws the end rounded or square; |
| 3375 | Paint_Style is ignored, as if were set to SkPaint::kStroke_Style. |
| 3376 | |
| 3377 | #Param p0 start of line segment ## |
| 3378 | #Param p1 end of line segment ## |
| 3379 | #Param paint stroke, blend, color, and so on, used to draw ## |
| 3380 | |
| 3381 | #Example |
| 3382 | SkPaint paint; |
| 3383 | paint.setAntiAlias(true); |
| 3384 | paint.setColor(0xFF9a67be); |
| 3385 | paint.setStrokeWidth(20); |
| 3386 | canvas->skew(1, 0); |
| 3387 | canvas->drawLine({32, 96}, {32, 160}, paint); |
| 3388 | canvas->skew(-2, 0); |
| 3389 | canvas->drawLine({288, 96}, {288, 160}, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3390 | ## |
| 3391 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3392 | #SeeAlso drawPoint drawCircle drawRect drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3393 | |
| 3394 | ## |
| 3395 | |
| 3396 | # ------------------------------------------------------------------------------ |
| 3397 | |
| 3398 | #Method void drawRect(const SkRect& rect, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3399 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3400 | #Line # draws Rect using Clip, Matrix, and Paint ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3401 | Draws Rect rect using Clip, Matrix, and Paint paint. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3402 | In paint: Paint_Style determines if rectangle is stroked or filled; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3403 | if stroked, Paint_Stroke_Width describes the line thickness, and |
| 3404 | Paint_Stroke_Join draws the corners rounded or square. |
| 3405 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3406 | #Param rect rectangle to draw ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3407 | #Param paint stroke or fill, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3408 | |
| 3409 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3410 | void draw(SkCanvas* canvas) { |
| 3411 | SkPoint rectPts[] = { {64, 48}, {192, 160} }; |
| 3412 | SkPaint paint; |
| 3413 | paint.setAntiAlias(true); |
| 3414 | paint.setStyle(SkPaint::kStroke_Style); |
| 3415 | paint.setStrokeWidth(20); |
| 3416 | paint.setStrokeJoin(SkPaint::kRound_Join); |
| 3417 | SkMatrix rotator; |
| 3418 | rotator.setRotate(30, 128, 128); |
| 3419 | for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorMAGENTA } ) { |
| 3420 | paint.setColor(color); |
| 3421 | SkRect rect; |
| 3422 | rect.set(rectPts[0], rectPts[1]); |
| 3423 | canvas->drawRect(rect, paint); |
| 3424 | rotator.mapPoints(rectPts, 2); |
| 3425 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3426 | } |
| 3427 | ## |
| 3428 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3429 | #SeeAlso drawIRect drawRRect drawRoundRect drawRegion drawPath drawLine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3430 | |
| 3431 | ## |
| 3432 | |
| 3433 | # ------------------------------------------------------------------------------ |
| 3434 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3435 | #Method void drawIRect(const SkIRect& rect, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3436 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3437 | #Line # draws IRect using Clip, Matrix, and Paint ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3438 | Draws IRect rect using Clip, Matrix, and Paint paint. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3439 | In paint: Paint_Style determines if rectangle is stroked or filled; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3440 | if stroked, Paint_Stroke_Width describes the line thickness, and |
| 3441 | Paint_Stroke_Join draws the corners rounded or square. |
| 3442 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3443 | #Param rect rectangle to draw ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3444 | #Param paint stroke or fill, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3445 | |
| 3446 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3447 | SkIRect rect = { 64, 48, 192, 160 }; |
| 3448 | SkPaint paint; |
| 3449 | paint.setAntiAlias(true); |
| 3450 | paint.setStyle(SkPaint::kStroke_Style); |
| 3451 | paint.setStrokeWidth(20); |
| 3452 | paint.setStrokeJoin(SkPaint::kRound_Join); |
| 3453 | for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorMAGENTA } ) { |
| 3454 | paint.setColor(color); |
| 3455 | canvas->drawIRect(rect, paint); |
| 3456 | canvas->rotate(30, 128, 128); |
| 3457 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3458 | ## |
| 3459 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3460 | #SeeAlso drawRect drawRRect drawRoundRect drawRegion drawPath drawLine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3461 | |
| 3462 | ## |
| 3463 | |
| 3464 | # ------------------------------------------------------------------------------ |
| 3465 | |
| 3466 | #Method void drawRegion(const SkRegion& region, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3467 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3468 | #Line # draws Region using Clip, Matrix, and Paint ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3469 | Draws Region region using Clip, Matrix, and Paint paint. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3470 | In paint: Paint_Style determines if rectangle is stroked or filled; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3471 | if stroked, Paint_Stroke_Width describes the line thickness, and |
| 3472 | Paint_Stroke_Join draws the corners rounded or square. |
| 3473 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3474 | #Param region region to draw ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3475 | #Param paint Paint stroke or fill, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3476 | |
| 3477 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3478 | void draw(SkCanvas* canvas) { |
| 3479 | SkRegion region; |
| 3480 | region.op( 10, 10, 50, 50, SkRegion::kUnion_Op); |
| 3481 | region.op( 10, 50, 90, 90, SkRegion::kUnion_Op); |
| 3482 | SkPaint paint; |
| 3483 | paint.setAntiAlias(true); |
| 3484 | paint.setStyle(SkPaint::kStroke_Style); |
| 3485 | paint.setStrokeWidth(20); |
| 3486 | paint.setStrokeJoin(SkPaint::kRound_Join); |
| 3487 | canvas->drawRegion(region, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3488 | } |
| 3489 | ## |
| 3490 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3491 | #SeeAlso drawRect drawIRect drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3492 | |
| 3493 | ## |
| 3494 | |
| 3495 | # ------------------------------------------------------------------------------ |
| 3496 | |
| 3497 | #Method void drawOval(const SkRect& oval, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3498 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3499 | #Line # draws Oval using Clip, Matrix, and Paint ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3500 | Draws Oval oval using Clip, Matrix, and Paint. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3501 | In paint: Paint_Style determines if Oval is stroked or filled; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3502 | if stroked, Paint_Stroke_Width describes the line thickness. |
| 3503 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3504 | #Param oval Rect bounds of Oval ## |
| 3505 | #Param paint Paint stroke or fill, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3506 | |
| 3507 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3508 | void draw(SkCanvas* canvas) { |
| 3509 | canvas->clear(0xFF3f5f9f); |
| 3510 | SkColor kColor1 = SkColorSetARGB(0xff, 0xff, 0x7f, 0); |
| 3511 | SkColor g1Colors[] = { kColor1, SkColorSetA(kColor1, 0x20) }; |
| 3512 | SkPoint g1Points[] = { { 0, 0 }, { 0, 100 } }; |
| 3513 | SkScalar pos[] = { 0.2f, 1.0f }; |
| 3514 | SkRect bounds = SkRect::MakeWH(80, 70); |
| 3515 | SkPaint paint; |
| 3516 | paint.setAntiAlias(true); |
| 3517 | paint.setShader(SkGradientShader::MakeLinear(g1Points, g1Colors, pos, SK_ARRAY_COUNT(g1Colors), |
| 3518 | SkShader::kClamp_TileMode)); |
| 3519 | canvas->drawOval(bounds , paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3520 | } |
| 3521 | ## |
| 3522 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3523 | #SeeAlso drawCircle drawPoint drawPath drawRRect drawRoundRect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3524 | |
| 3525 | ## |
| 3526 | |
| 3527 | # ------------------------------------------------------------------------------ |
| 3528 | |
| 3529 | #Method void drawRRect(const SkRRect& rrect, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3530 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3531 | #Line # draws Round_Rect using Clip, Matrix, and Paint ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3532 | Draws Round_Rect rrect using Clip, Matrix, and Paint paint. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3533 | In paint: Paint_Style determines if rrect is stroked or filled; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3534 | if stroked, Paint_Stroke_Width describes the line thickness. |
| 3535 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3536 | rrect may represent a rectangle, circle, oval, uniformly rounded rectangle, or |
| 3537 | may have any combination of positive non-square radii for the four corners. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3538 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3539 | #Param rrect Round_Rect with up to eight corner radii to draw ## |
| 3540 | #Param paint Paint stroke or fill, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3541 | |
| 3542 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3543 | void draw(SkCanvas* canvas) { |
| 3544 | SkPaint paint; |
| 3545 | paint.setAntiAlias(true); |
| 3546 | SkRect outer = {30, 40, 210, 220}; |
| 3547 | SkRect radii = {30, 50, 70, 90 }; |
| 3548 | SkRRect rRect; |
| 3549 | rRect.setNinePatch(outer, radii.fLeft, radii.fTop, radii.fRight, radii.fBottom); |
| 3550 | canvas->drawRRect(rRect, paint); |
| 3551 | paint.setColor(SK_ColorWHITE); |
| 3552 | canvas->drawLine(outer.fLeft + radii.fLeft, outer.fTop, |
| 3553 | outer.fLeft + radii.fLeft, outer.fBottom, paint); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3554 | canvas->drawLine(outer.fRight - radii.fRight, outer.fTop, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3555 | outer.fRight - radii.fRight, outer.fBottom, paint); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3556 | canvas->drawLine(outer.fLeft, outer.fTop + radii.fTop, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3557 | outer.fRight, outer.fTop + radii.fTop, paint); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3558 | canvas->drawLine(outer.fLeft, outer.fBottom - radii.fBottom, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3559 | outer.fRight, outer.fBottom - radii.fBottom, paint); |
| 3560 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3561 | ## |
| 3562 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3563 | #SeeAlso drawRect drawRoundRect drawDRRect drawCircle drawOval drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3564 | |
| 3565 | ## |
| 3566 | |
| 3567 | # ------------------------------------------------------------------------------ |
| 3568 | |
| 3569 | #Method void drawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3570 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3571 | #Line # draws double Round_Rect stroked or filled ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3572 | Draws Round_Rect outer and inner |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3573 | using Clip, Matrix, and Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3574 | outer must contain inner or the drawing is undefined. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3575 | In paint: Paint_Style determines if Round_Rect is stroked or filled; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3576 | if stroked, Paint_Stroke_Width describes the line thickness. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3577 | If stroked and Round_Rect corner has zero length radii, Paint_Stroke_Join can |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3578 | draw corners rounded or square. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3579 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3580 | GPU-backed platforms optimize drawing when both outer and inner are |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3581 | concave and outer contains inner. These platforms may not be able to draw |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3582 | Path built with identical data as fast. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3583 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3584 | #Param outer Round_Rect outer bounds to draw ## |
| 3585 | #Param inner Round_Rect inner bounds to draw ## |
| 3586 | #Param paint Paint stroke or fill, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3587 | |
| 3588 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3589 | void draw(SkCanvas* canvas) { |
| 3590 | SkRRect outer = SkRRect::MakeRect({20, 40, 210, 200}); |
| 3591 | SkRRect inner = SkRRect::MakeOval({60, 70, 170, 160}); |
| 3592 | SkPaint paint; |
| 3593 | canvas->drawDRRect(outer, inner, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3594 | } |
| 3595 | ## |
| 3596 | |
| 3597 | #Example |
| 3598 | #Description |
| 3599 | Outer Rect has no corner radii, but stroke join is rounded. |
| 3600 | Inner Round_Rect has corner radii; outset stroke increases radii of corners. |
| 3601 | Stroke join does not affect inner Round_Rect since it has no sharp corners. |
| 3602 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3603 | void draw(SkCanvas* canvas) { |
| 3604 | SkRRect outer = SkRRect::MakeRect({20, 40, 210, 200}); |
| 3605 | SkRRect inner = SkRRect::MakeRectXY({60, 70, 170, 160}, 10, 10); |
| 3606 | SkPaint paint; |
| 3607 | paint.setAntiAlias(true); |
| 3608 | paint.setStyle(SkPaint::kStroke_Style); |
| 3609 | paint.setStrokeWidth(20); |
| 3610 | paint.setStrokeJoin(SkPaint::kRound_Join); |
| 3611 | canvas->drawDRRect(outer, inner, paint); |
| 3612 | paint.setStrokeWidth(1); |
| 3613 | paint.setColor(SK_ColorWHITE); |
| 3614 | canvas->drawDRRect(outer, inner, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3615 | } |
| 3616 | ## |
| 3617 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3618 | #SeeAlso drawRect drawRoundRect drawRRect drawCircle drawOval drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3619 | |
| 3620 | ## |
| 3621 | |
| 3622 | # ------------------------------------------------------------------------------ |
| 3623 | |
| 3624 | #Method void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3625 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3626 | #Line # draws Circle using Clip, Matrix, and Paint ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3627 | Draws Circle at (cx, cy) with radius using Clip, Matrix, and Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3628 | If radius is zero or less, nothing is drawn. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3629 | In paint: Paint_Style determines if Circle is stroked or filled; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3630 | if stroked, Paint_Stroke_Width describes the line thickness. |
| 3631 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3632 | #Param cx Circle center on the x-axis ## |
| 3633 | #Param cy Circle center on the y-axis ## |
| 3634 | #Param radius half the diameter of Circle ## |
| 3635 | #Param paint Paint stroke or fill, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3636 | |
| 3637 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3638 | void draw(SkCanvas* canvas) { |
| 3639 | SkPaint paint; |
| 3640 | paint.setAntiAlias(true); |
| 3641 | canvas->drawCircle(128, 128, 90, paint); |
| 3642 | paint.setColor(SK_ColorWHITE); |
| 3643 | canvas->drawCircle(86, 86, 20, paint); |
| 3644 | canvas->drawCircle(160, 76, 20, paint); |
| 3645 | canvas->drawCircle(140, 150, 35, paint); |
| 3646 | } |
| 3647 | ## |
| 3648 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3649 | #SeeAlso drawOval drawRRect drawRoundRect drawPath drawArc drawPoint drawLine |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3650 | |
| 3651 | ## |
| 3652 | |
| 3653 | #Method void drawCircle(SkPoint center, SkScalar radius, const SkPaint& paint) |
| 3654 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3655 | Draws Circle at center with radius using Clip, Matrix, and Paint paint. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3656 | If radius is zero or less, nothing is drawn. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3657 | In paint: Paint_Style determines if Circle is stroked or filled; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3658 | if stroked, Paint_Stroke_Width describes the line thickness. |
| 3659 | |
| 3660 | #Param center Circle center ## |
| 3661 | #Param radius half the diameter of Circle ## |
| 3662 | #Param paint Paint stroke or fill, blend, color, and so on, used to draw ## |
| 3663 | |
| 3664 | #Example |
| 3665 | void draw(SkCanvas* canvas) { |
| 3666 | SkPaint paint; |
| 3667 | paint.setAntiAlias(true); |
| 3668 | canvas->drawCircle(128, 128, 90, paint); |
| 3669 | paint.setColor(SK_ColorWHITE); |
| 3670 | canvas->drawCircle({86, 86}, 20, paint); |
| 3671 | canvas->drawCircle({160, 76}, 20, paint); |
| 3672 | canvas->drawCircle({140, 150}, 35, paint); |
| 3673 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3674 | ## |
| 3675 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3676 | #SeeAlso drawOval drawRRect drawRoundRect drawPath drawArc drawPoint drawLine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3677 | |
| 3678 | ## |
| 3679 | |
| 3680 | # ------------------------------------------------------------------------------ |
| 3681 | |
| 3682 | #Method void drawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, |
| 3683 | bool useCenter, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3684 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3685 | #Line # draws Arc using Clip, Matrix, and Paint ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3686 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3687 | Draws Arc using Clip, Matrix, and Paint paint. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3688 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3689 | Arc is part of Oval bounded by oval, sweeping from startAngle to startAngle plus |
| 3690 | sweepAngle. startAngle and sweepAngle are in degrees. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3691 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3692 | startAngle of zero places start point at the right middle edge of oval. |
| 3693 | A positive sweepAngle places Arc end point clockwise from start point; |
| 3694 | a negative sweepAngle places Arc end point counterclockwise from start point. |
| 3695 | sweepAngle may exceed 360 degrees, a full circle. |
| 3696 | If useCenter is true, draw a wedge that includes lines from oval |
| 3697 | center to Arc end points. If useCenter is false, draw Arc between end points. |
| 3698 | |
| 3699 | If Rect oval is empty or sweepAngle is zero, nothing is drawn. |
| 3700 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3701 | #Param oval Rect bounds of Oval containing Arc to draw ## |
| 3702 | #Param startAngle angle in degrees where Arc begins ## |
| 3703 | #Param sweepAngle sweep angle in degrees; positive is clockwise ## |
| 3704 | #Param useCenter if true, include the center of the oval ## |
| 3705 | #Param paint Paint stroke or fill, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3706 | |
| 3707 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3708 | void draw(SkCanvas* canvas) { |
| 3709 | SkPaint paint; |
| 3710 | paint.setAntiAlias(true); |
| 3711 | SkRect oval = { 4, 4, 60, 60}; |
| 3712 | for (auto useCenter : { false, true } ) { |
| 3713 | for (auto style : { SkPaint::kFill_Style, SkPaint::kStroke_Style } ) { |
| 3714 | paint.setStyle(style); |
| 3715 | for (auto degrees : { 45, 90, 180, 360} ) { |
| 3716 | canvas->drawArc(oval, 0, degrees , useCenter, paint); |
| 3717 | canvas->translate(64, 0); |
| 3718 | } |
| 3719 | canvas->translate(-256, 64); |
| 3720 | } |
| 3721 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3722 | } |
| 3723 | ## |
| 3724 | |
| 3725 | #Example |
| 3726 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3727 | void draw(SkCanvas* canvas) { |
| 3728 | SkPaint paint; |
| 3729 | paint.setAntiAlias(true); |
| 3730 | paint.setStyle(SkPaint::kStroke_Style); |
| 3731 | paint.setStrokeWidth(4); |
| 3732 | SkRect oval = { 4, 4, 60, 60}; |
| 3733 | float intervals[] = { 5, 5 }; |
| 3734 | paint.setPathEffect(SkDashPathEffect::Make(intervals, 2, 2.5f)); |
| 3735 | for (auto degrees : { 270, 360, 540, 720 } ) { |
| 3736 | canvas->drawArc(oval, 0, degrees, false, paint); |
| 3737 | canvas->translate(64, 0); |
| 3738 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3739 | } |
| 3740 | ## |
| 3741 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3742 | #SeeAlso SkPath::arcTo drawCircle drawOval drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3743 | |
| 3744 | ## |
| 3745 | |
| 3746 | # ------------------------------------------------------------------------------ |
| 3747 | |
| 3748 | #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] | 3749 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3750 | #Line # draws Round_Rect using Clip, Matrix, and Paint ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3751 | Draws Round_Rect bounded by Rect rect, with corner radii (rx, ry) using Clip, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3752 | Matrix, and Paint paint. |
| 3753 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3754 | In paint: Paint_Style determines if Round_Rect is stroked or filled; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3755 | if stroked, Paint_Stroke_Width describes the line thickness. |
| 3756 | If rx or ry are less than zero, they are treated as if they are zero. |
| 3757 | If rx plus ry exceeds rect width or rect height, radii are scaled down to fit. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3758 | If rx and ry are zero, Round_Rect is drawn as Rect and if stroked is affected by |
| 3759 | Paint_Stroke_Join. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3760 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3761 | #Param rect Rect bounds of Round_Rect to draw ## |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 3762 | #Param rx axis length on x-axis of oval describing rounded corners ## |
| 3763 | #Param ry axis length on y-axis of oval describing rounded corners ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3764 | #Param paint stroke, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3765 | |
| 3766 | #Example |
| 3767 | #Description |
| 3768 | Top row has a zero radius a generates a rectangle. |
| 3769 | Second row radii sum to less than sides. |
| 3770 | Third row radii sum equals sides. |
| 3771 | Fourth row radii sum exceeds sides; radii are scaled to fit. |
| 3772 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3773 | void draw(SkCanvas* canvas) { |
| 3774 | SkVector radii[] = { {0, 20}, {10, 10}, {10, 20}, {10, 40} }; |
| 3775 | SkPaint paint; |
| 3776 | paint.setStrokeWidth(15); |
| 3777 | paint.setStrokeJoin(SkPaint::kRound_Join); |
| 3778 | paint.setAntiAlias(true); |
| 3779 | for (auto style : { SkPaint::kStroke_Style, SkPaint::kFill_Style } ) { |
| 3780 | paint.setStyle(style ); |
| 3781 | for (size_t i = 0; i < SK_ARRAY_COUNT(radii); ++i) { |
| 3782 | canvas->drawRoundRect({10, 10, 60, 40}, radii[i].fX, radii[i].fY, paint); |
| 3783 | canvas->translate(0, 60); |
| 3784 | } |
| 3785 | canvas->translate(80, -240); |
| 3786 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3787 | } |
| 3788 | ## |
| 3789 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3790 | #SeeAlso DrawRRect drawRect drawDRRect drawPath drawCircle drawOval drawPoint |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3791 | |
| 3792 | ## |
| 3793 | |
| 3794 | # ------------------------------------------------------------------------------ |
| 3795 | |
| 3796 | #Method void drawPath(const SkPath& path, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3797 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3798 | #Line # draws Path using Clip, Matrix, and Paint ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3799 | Draws Path path using Clip, Matrix, and Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3800 | Path contains an array of Path_Contour, each of which may be open or closed. |
| 3801 | |
| 3802 | In paint: Paint_Style determines if Round_Rect is stroked or filled: |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3803 | if filled, Path_Fill_Type determines whether Path_Contour describes inside or |
| 3804 | outside of fill; if stroked, Paint_Stroke_Width describes the line thickness, |
| 3805 | Paint_Stroke_Cap describes line ends, and Paint_Stroke_Join describes how |
| 3806 | corners are drawn. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3807 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3808 | #Param path Path to draw ## |
| 3809 | #Param paint stroke, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3810 | |
| 3811 | #Example |
| 3812 | #Description |
| 3813 | Top rows draw stroked path with combinations of joins and caps. The open contour |
| 3814 | is affected by caps; the closed contour is affected by joins. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3815 | Bottom row draws fill the same for open and closed contour. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3816 | First bottom column shows winding fills overlap. |
| 3817 | Second bottom column shows even odd fills exclude overlap. |
| 3818 | Third bottom column shows inverse winding fills area outside both contours. |
| 3819 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3820 | void draw(SkCanvas* canvas) { |
| 3821 | SkPath path; |
| 3822 | path.moveTo(20, 20); |
| 3823 | path.quadTo(60, 20, 60, 60); |
| 3824 | path.close(); |
| 3825 | path.moveTo(60, 20); |
| 3826 | path.quadTo(60, 60, 20, 60); |
| 3827 | SkPaint paint; |
| 3828 | paint.setStrokeWidth(10); |
| 3829 | paint.setAntiAlias(true); |
| 3830 | paint.setStyle(SkPaint::kStroke_Style); |
| 3831 | for (auto join: { SkPaint::kBevel_Join, SkPaint::kRound_Join, SkPaint::kMiter_Join } ) { |
| 3832 | paint.setStrokeJoin(join); |
| 3833 | for (auto cap: { SkPaint::kButt_Cap, SkPaint::kSquare_Cap, SkPaint::kRound_Cap } ) { |
| 3834 | paint.setStrokeCap(cap); |
| 3835 | canvas->drawPath(path, paint); |
| 3836 | canvas->translate(80, 0); |
| 3837 | } |
| 3838 | canvas->translate(-240, 60); |
| 3839 | } |
| 3840 | paint.setStyle(SkPaint::kFill_Style); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3841 | for (auto fill : { SkPath::kWinding_FillType, |
| 3842 | SkPath::kEvenOdd_FillType, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3843 | SkPath::kInverseWinding_FillType } ) { |
| 3844 | path.setFillType(fill); |
| 3845 | canvas->save(); |
| 3846 | canvas->clipRect({0, 10, 80, 70}); |
| 3847 | canvas->drawPath(path, paint); |
| 3848 | canvas->restore(); |
| 3849 | canvas->translate(80, 0); |
| 3850 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3851 | } |
| 3852 | ## |
| 3853 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3854 | #SeeAlso SkPath drawLine drawArc drawRect drawPoints |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3855 | |
| 3856 | ## |
| 3857 | |
| 3858 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3859 | #Subtopic Draw_Image |
| 3860 | #Line # draws Image to Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3861 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3862 | drawImage, drawImageRect, and drawImageNine can be called with a bare pointer or |
| 3863 | 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] | 3864 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3865 | #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] | 3866 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3867 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3868 | #Line # draws Image at (x, y) position ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3869 | Draws Image image, with its top-left corner at (left, top), |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3870 | using Clip, Matrix, and optional Paint paint. |
| 3871 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3872 | If paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, Blend_Mode, |
| 3873 | and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader. |
| 3874 | If paint contains Mask_Filter, generate mask from image bounds. If generated |
| 3875 | mask extends beyond image bounds, replicate image edge colors, just as Shader |
| 3876 | made from SkImage::makeShader with SkShader::kClamp_TileMode set replicates the |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3877 | image edge color when it samples outside of its bounds. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3878 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3879 | #Param image uncompressed rectangular map of pixels ## |
| 3880 | #Param left left side of image ## |
| 3881 | #Param top top side of image ## |
| 3882 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 3883 | and so on; or nullptr |
| 3884 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3885 | |
| 3886 | #Example |
| 3887 | #Height 64 |
| 3888 | #Image 4 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3889 | void draw(SkCanvas* canvas) { |
| 3890 | // sk_sp<SkImage> image; |
| 3891 | SkImage* imagePtr = image.get(); |
| 3892 | canvas->drawImage(imagePtr, 0, 0); |
| 3893 | SkPaint paint; |
| 3894 | canvas->drawImage(imagePtr, 80, 0, &paint); |
| 3895 | paint.setAlpha(0x80); |
| 3896 | canvas->drawImage(imagePtr, 160, 0, &paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3897 | } |
| 3898 | ## |
| 3899 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3900 | #SeeAlso drawBitmap drawImageLattice drawImageNine drawImageRect SkPaint::setImageFilter |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3901 | |
| 3902 | ## |
| 3903 | |
| 3904 | # ------------------------------------------------------------------------------ |
| 3905 | |
| 3906 | #Method void drawImage(const sk_sp<SkImage>& image, SkScalar left, SkScalar top, |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3907 | const SkPaint* paint = nullptr) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3908 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3909 | Draws Image image, with its top-left corner at (left, top), |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3910 | using Clip, Matrix, and optional Paint paint. |
| 3911 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3912 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 3913 | Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader. |
| 3914 | If paint contains Mask_Filter, generate mask from image bounds. If generated |
| 3915 | mask extends beyond image bounds, replicate image edge colors, just as Shader |
| 3916 | made from SkImage::makeShader with SkShader::kClamp_TileMode set replicates the |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3917 | image edge color when it samples outside of its bounds. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3918 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3919 | #Param image uncompressed rectangular map of pixels ## |
| 3920 | #Param left left side of image ## |
| 3921 | #Param top pop side of image ## |
| 3922 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 3923 | and so on; or nullptr |
| 3924 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3925 | |
| 3926 | #Example |
| 3927 | #Height 64 |
| 3928 | #Image 4 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3929 | void draw(SkCanvas* canvas) { |
| 3930 | // sk_sp<SkImage> image; |
| 3931 | canvas->drawImage(image, 0, 0); |
| 3932 | SkPaint paint; |
| 3933 | canvas->drawImage(image, 80, 0, &paint); |
| 3934 | paint.setAlpha(0x80); |
| 3935 | canvas->drawImage(image, 160, 0, &paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3936 | } |
| 3937 | ## |
| 3938 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3939 | #SeeAlso drawBitmap drawImageLattice drawImageNine drawImageRect SkPaint::setImageFilter |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3940 | |
| 3941 | ## |
| 3942 | |
| 3943 | # ------------------------------------------------------------------------------ |
| 3944 | |
| 3945 | #Enum SrcRectConstraint |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3946 | #Line # sets drawImageRect options ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3947 | |
| 3948 | #Code |
| 3949 | enum SrcRectConstraint { |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3950 | kStrict_SrcRectConstraint, |
| 3951 | kFast_SrcRectConstraint, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3952 | }; |
| 3953 | ## |
| 3954 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3955 | SrcRectConstraint controls the behavior at the edge of source Rect, |
| 3956 | provided to drawImageRect, trading off speed for precision. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3957 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3958 | 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] | 3959 | 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] | 3960 | 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] | 3961 | SrcRectConstraint specifies whether an Image_Filter is allowed to read pixels |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3962 | outside source Rect. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3963 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3964 | #Const kStrict_SrcRectConstraint 0 |
| 3965 | #Line # sample only inside bounds; slower ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3966 | Requires Image_Filter to respect source Rect, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3967 | sampling only inside of its bounds, possibly with a performance penalty. |
| 3968 | ## |
| 3969 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3970 | #Const kFast_SrcRectConstraint 1 |
| 3971 | #Line # sample outside bounds; faster ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3972 | Permits Image_Filter to sample outside of source Rect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3973 | by half the width of Image_Filter, permitting it to run faster but with |
| 3974 | error at the image edges. |
| 3975 | ## |
| 3976 | |
| 3977 | #Example |
| 3978 | #Height 64 |
| 3979 | #Description |
| 3980 | redBorder contains a black and white checkerboard bordered by red. |
| 3981 | redBorder is drawn scaled by 16 on the left. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3982 | The middle and right bitmaps are filtered checkerboards. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3983 | Drawing the checkerboard with kStrict_SrcRectConstraint shows only a blur of black and white. |
| 3984 | Drawing the checkerboard with kFast_SrcRectConstraint allows red to bleed in the corners. |
| 3985 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3986 | void draw(SkCanvas* canvas) { |
| 3987 | SkBitmap redBorder; |
| 3988 | redBorder.allocPixels(SkImageInfo::MakeN32Premul(4, 4)); |
| 3989 | SkCanvas checkRed(redBorder); |
| 3990 | checkRed.clear(SK_ColorRED); |
| 3991 | uint32_t checkers[][2] = { { SK_ColorBLACK, SK_ColorWHITE }, |
| 3992 | { SK_ColorWHITE, SK_ColorBLACK } }; |
| 3993 | checkRed.writePixels( |
| 3994 | SkImageInfo::MakeN32Premul(2, 2), (void*) checkers, sizeof(checkers[0]), 1, 1); |
| 3995 | canvas->scale(16, 16); |
| 3996 | canvas->drawBitmap(redBorder, 0, 0, nullptr); |
| 3997 | canvas->resetMatrix(); |
| 3998 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(redBorder); |
| 3999 | SkPaint lowPaint; |
| 4000 | lowPaint.setFilterQuality(kLow_SkFilterQuality); |
| 4001 | for (auto constraint : { SkCanvas::kStrict_SrcRectConstraint, |
| 4002 | SkCanvas::kFast_SrcRectConstraint } ) { |
| 4003 | canvas->translate(80, 0); |
| 4004 | canvas->drawImageRect(image.get(), SkRect::MakeLTRB(1, 1, 3, 3), |
| 4005 | SkRect::MakeLTRB(16, 16, 48, 48), &lowPaint, constraint); |
| 4006 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4007 | } |
| 4008 | ## |
| 4009 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4010 | #SeeAlso drawImageRect drawImage SkPaint::setImageFilter |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4011 | |
| 4012 | ## |
| 4013 | |
| 4014 | # ------------------------------------------------------------------------------ |
| 4015 | |
| 4016 | #Method void drawImageRect(const SkImage* image, const SkRect& src, const SkRect& dst, |
| 4017 | const SkPaint* paint, |
| 4018 | SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4019 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4020 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4021 | #Line # draws Image, source Rect to destination Rect ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4022 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4023 | Draws Rect src of Image image, scaled and translated to fill Rect dst. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4024 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4025 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4026 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4027 | Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader. |
| 4028 | If paint contains Mask_Filter, generate mask from image bounds. |
| 4029 | |
| 4030 | If generated mask extends beyond image bounds, replicate image edge colors, just |
| 4031 | as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4032 | replicates the image edge color when it samples outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4033 | |
| 4034 | constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to |
| 4035 | sample within src; set to kFast_SrcRectConstraint allows sampling outside to |
| 4036 | improve performance. |
| 4037 | |
| 4038 | #Param image Image containing pixels, dimensions, and format ## |
| 4039 | #Param src source Rect of image to draw from ## |
| 4040 | #Param dst destination Rect of image to draw to ## |
| 4041 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4042 | and so on; or nullptr |
| 4043 | ## |
| 4044 | #Param constraint filter strictly within src or draw faster ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4045 | |
| 4046 | #Example |
| 4047 | #Height 64 |
| 4048 | #Description |
| 4049 | The left bitmap draws with Paint default kNone_SkFilterQuality, and stays within |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4050 | its bounds; there is no bleeding with kFast_SrcRectConstraint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4051 | the middle and right bitmaps draw with kLow_SkFilterQuality; with |
| 4052 | kStrict_SrcRectConstraint, the filter remains within the checkerboard, and |
| 4053 | with kFast_SrcRectConstraint red bleeds on the edges. |
| 4054 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4055 | void draw(SkCanvas* canvas) { |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4056 | uint32_t pixels[][4] = { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4057 | { 0xFFFF0000, 0xFFFF0000, 0xFFFF0000, 0xFFFF0000 }, |
| 4058 | { 0xFFFF0000, 0xFF000000, 0xFFFFFFFF, 0xFFFF0000 }, |
| 4059 | { 0xFFFF0000, 0xFFFFFFFF, 0xFF000000, 0xFFFF0000 }, |
| 4060 | { 0xFFFF0000, 0xFFFF0000, 0xFFFF0000, 0xFFFF0000 } }; |
| 4061 | SkBitmap redBorder; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4062 | redBorder.installPixels(SkImageInfo::MakeN32Premul(4, 4), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4063 | (void*) pixels, sizeof(pixels[0])); |
| 4064 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(redBorder); |
| 4065 | SkPaint lowPaint; |
| 4066 | for (auto constraint : { |
| 4067 | SkCanvas::kFast_SrcRectConstraint, |
| 4068 | SkCanvas::kStrict_SrcRectConstraint, |
| 4069 | SkCanvas::kFast_SrcRectConstraint } ) { |
| 4070 | canvas->drawImageRect(image.get(), SkRect::MakeLTRB(1, 1, 3, 3), |
| 4071 | SkRect::MakeLTRB(16, 16, 48, 48), &lowPaint, constraint); |
| 4072 | lowPaint.setFilterQuality(kLow_SkFilterQuality); |
| 4073 | canvas->translate(80, 0); |
| 4074 | } |
| 4075 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4076 | ## |
| 4077 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4078 | #SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4079 | |
| 4080 | ## |
| 4081 | |
| 4082 | # ------------------------------------------------------------------------------ |
| 4083 | |
| 4084 | #Method void drawImageRect(const SkImage* image, const SkIRect& isrc, const SkRect& dst, |
| 4085 | const SkPaint* paint, SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4086 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4087 | #In Draw |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4088 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4089 | Draws IRect isrc of Image image, scaled and translated to fill Rect dst. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4090 | Note that isrc is on integer pixel boundaries; dst may include fractional |
| 4091 | boundaries. Additionally transform draw using Clip, Matrix, and optional Paint |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4092 | paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4093 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4094 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4095 | Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader. |
| 4096 | If paint contains Mask_Filter, generate mask from image bounds. |
| 4097 | |
| 4098 | If generated mask extends beyond image bounds, replicate image edge colors, just |
| 4099 | as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4100 | replicates the image edge color when it samples outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4101 | |
| 4102 | constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4103 | sample within isrc; set to kFast_SrcRectConstraint allows sampling outside to |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4104 | improve performance. |
| 4105 | |
| 4106 | #Param image Image containing pixels, dimensions, and format ## |
| 4107 | #Param isrc source IRect of image to draw from ## |
| 4108 | #Param dst destination Rect of image to draw to ## |
| 4109 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4110 | and so on; or nullptr |
| 4111 | ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4112 | #Param constraint filter strictly within isrc or draw faster ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4113 | |
| 4114 | #Example |
| 4115 | #Image 4 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4116 | void draw(SkCanvas* canvas) { |
| 4117 | // sk_sp<SkImage> image; |
| 4118 | for (auto i : { 1, 2, 4, 8 } ) { |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4119 | canvas->drawImageRect(image.get(), SkIRect::MakeLTRB(0, 0, 100, 100), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4120 | SkRect::MakeXYWH(i * 20, i * 20, i * 20, i * 20), nullptr); |
| 4121 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4122 | } |
| 4123 | ## |
| 4124 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4125 | #SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4126 | |
| 4127 | ## |
| 4128 | |
| 4129 | # ------------------------------------------------------------------------------ |
| 4130 | |
| 4131 | #Method void drawImageRect(const SkImage* image, const SkRect& dst, const SkPaint* paint, |
| 4132 | SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4133 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4134 | #In Draw |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4135 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4136 | Draws Image image, scaled and translated to fill Rect dst, using Clip, Matrix, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4137 | and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4138 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4139 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4140 | Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader. |
| 4141 | If paint contains Mask_Filter, generate mask from image bounds. |
| 4142 | |
| 4143 | If generated mask extends beyond image bounds, replicate image edge colors, just |
| 4144 | as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4145 | replicates the image edge color when it samples outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4146 | |
| 4147 | constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4148 | sample within image; set to kFast_SrcRectConstraint allows sampling outside to |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4149 | improve performance. |
| 4150 | |
| 4151 | #Param image Image containing pixels, dimensions, and format ## |
| 4152 | #Param dst destination Rect of image to draw to ## |
| 4153 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4154 | and so on; or nullptr |
| 4155 | ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4156 | #Param constraint filter strictly within image or draw faster ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4157 | |
| 4158 | #Example |
| 4159 | #Image 4 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4160 | void draw(SkCanvas* canvas) { |
| 4161 | // sk_sp<SkImage> image; |
| 4162 | for (auto i : { 20, 40, 80, 160 } ) { |
| 4163 | canvas->drawImageRect(image.get(), SkRect::MakeXYWH(i, i, i, i), nullptr); |
| 4164 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4165 | } |
| 4166 | ## |
| 4167 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4168 | #SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4169 | |
| 4170 | ## |
| 4171 | |
| 4172 | # ------------------------------------------------------------------------------ |
| 4173 | |
| 4174 | #Method void drawImageRect(const sk_sp<SkImage>& image, const SkRect& src, const SkRect& dst, |
| 4175 | const SkPaint* paint, |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4176 | SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4177 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4178 | #In Draw |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4179 | Draws Rect src of Image image, scaled and translated to fill Rect dst. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4180 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4181 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4182 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4183 | Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader. |
| 4184 | If paint contains Mask_Filter, generate mask from image bounds. |
| 4185 | |
| 4186 | If generated mask extends beyond image bounds, replicate image edge colors, just |
| 4187 | as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4188 | replicates the image edge color when it samples outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4189 | |
| 4190 | constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to |
| 4191 | sample within src; set to kFast_SrcRectConstraint allows sampling outside to |
| 4192 | improve performance. |
| 4193 | |
| 4194 | #Param image Image containing pixels, dimensions, and format ## |
| 4195 | #Param src source Rect of image to draw from ## |
| 4196 | #Param dst destination Rect of image to draw to ## |
| 4197 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4198 | and so on; or nullptr |
| 4199 | ## |
| 4200 | #Param constraint filter strictly within src or draw faster ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4201 | |
| 4202 | #Example |
| 4203 | #Height 64 |
| 4204 | #Description |
| 4205 | Canvas scales and translates; transformation from src to dst also scales. |
| 4206 | The two matrices are concatenated to create the final transformation. |
| 4207 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4208 | void draw(SkCanvas* canvas) { |
| 4209 | uint32_t pixels[][2] = { { SK_ColorBLACK, SK_ColorWHITE }, |
| 4210 | { SK_ColorWHITE, SK_ColorBLACK } }; |
| 4211 | SkBitmap bitmap; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4212 | bitmap.installPixels(SkImageInfo::MakeN32Premul(2, 2), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4213 | (void*) pixels, sizeof(pixels[0])); |
| 4214 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 4215 | SkPaint paint; |
| 4216 | canvas->scale(4, 4); |
| 4217 | for (auto alpha : { 50, 100, 150, 255 } ) { |
| 4218 | paint.setAlpha(alpha); |
| 4219 | canvas->drawImageRect(image, SkRect::MakeWH(2, 2), SkRect::MakeWH(8, 8), &paint); |
| 4220 | canvas->translate(8, 0); |
| 4221 | } |
| 4222 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4223 | ## |
| 4224 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4225 | #SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4226 | |
| 4227 | ## |
| 4228 | |
| 4229 | # ------------------------------------------------------------------------------ |
| 4230 | |
| 4231 | #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] | 4232 | const SkPaint* paint, SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4233 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4234 | #In Draw |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4235 | Draws IRect isrc of Image image, scaled and translated to fill Rect dst. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4236 | isrc is on integer pixel boundaries; dst may include fractional boundaries. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4237 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4238 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4239 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4240 | Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader. |
| 4241 | If paint contains Mask_Filter, generate mask from image bounds. |
| 4242 | |
| 4243 | If generated mask extends beyond image bounds, replicate image edge colors, just |
| 4244 | as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4245 | replicates the image edge color when it samples outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4246 | |
| 4247 | constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4248 | sample within image; set to kFast_SrcRectConstraint allows sampling outside to |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4249 | improve performance. |
| 4250 | |
| 4251 | #Param image Image containing pixels, dimensions, and format ## |
| 4252 | #Param isrc source IRect of image to draw from ## |
| 4253 | #Param dst destination Rect of image to draw to ## |
| 4254 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4255 | and so on; or nullptr |
| 4256 | ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4257 | #Param constraint filter strictly within image or draw faster ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4258 | |
| 4259 | #Example |
| 4260 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4261 | void draw(SkCanvas* canvas) { |
| 4262 | uint32_t pixels[][2] = { { 0x00000000, 0x55555555}, |
| 4263 | { 0xAAAAAAAA, 0xFFFFFFFF} }; |
| 4264 | SkBitmap bitmap; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4265 | bitmap.installPixels(SkImageInfo::MakeN32Premul(2, 2), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4266 | (void*) pixels, sizeof(pixels[0])); |
| 4267 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 4268 | SkPaint paint; |
| 4269 | canvas->scale(4, 4); |
| 4270 | for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN } ) { |
| 4271 | paint.setColorFilter(SkColorFilter::MakeModeFilter(color, SkBlendMode::kPlus)); |
| 4272 | canvas->drawImageRect(image, SkIRect::MakeWH(2, 2), SkRect::MakeWH(8, 8), &paint); |
| 4273 | canvas->translate(8, 0); |
| 4274 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4275 | } |
| 4276 | ## |
| 4277 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4278 | #SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine |
| 4279 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4280 | ## |
| 4281 | |
| 4282 | # ------------------------------------------------------------------------------ |
| 4283 | |
| 4284 | #Method void drawImageRect(const sk_sp<SkImage>& image, const SkRect& dst, const SkPaint* paint, |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4285 | SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4286 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4287 | #In Draw |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4288 | Draws Image image, scaled and translated to fill Rect dst, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4289 | using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4290 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4291 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4292 | Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader. |
| 4293 | If paint contains Mask_Filter, generate mask from image bounds. |
| 4294 | |
| 4295 | If generated mask extends beyond image bounds, replicate image edge colors, just |
| 4296 | as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4297 | replicates the image edge color when it samples outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4298 | |
| 4299 | constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4300 | sample within image; set to kFast_SrcRectConstraint allows sampling outside to |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4301 | improve performance. |
| 4302 | |
| 4303 | #Param image Image containing pixels, dimensions, and format ## |
| 4304 | #Param dst destination Rect of image to draw to ## |
| 4305 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4306 | and so on; or nullptr |
| 4307 | ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4308 | #Param constraint filter strictly within image or draw faster ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4309 | |
| 4310 | #Example |
| 4311 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4312 | void draw(SkCanvas* canvas) { |
| 4313 | uint32_t pixels[][2] = { { 0x00000000, 0x55550000}, |
| 4314 | { 0xAAAA0000, 0xFFFF0000} }; |
| 4315 | SkBitmap bitmap; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4316 | bitmap.installPixels(SkImageInfo::MakeN32Premul(2, 2), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4317 | (void*) pixels, sizeof(pixels[0])); |
| 4318 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 4319 | SkPaint paint; |
| 4320 | canvas->scale(4, 4); |
| 4321 | for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN } ) { |
| 4322 | paint.setColorFilter(SkColorFilter::MakeModeFilter(color, SkBlendMode::kPlus)); |
| 4323 | canvas->drawImageRect(image, SkRect::MakeWH(8, 8), &paint); |
| 4324 | canvas->translate(8, 0); |
| 4325 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4326 | } |
| 4327 | ## |
| 4328 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4329 | #SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4330 | |
| 4331 | ## |
| 4332 | |
| 4333 | # ------------------------------------------------------------------------------ |
| 4334 | |
| 4335 | #Method void drawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst, |
| 4336 | const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4337 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4338 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4339 | #Line # draws Nine_Patch Image ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4340 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4341 | Draws Image image stretched proportionally to fit into Rect dst. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4342 | 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] | 4343 | the center. Corners are unmodified or scaled down proportionately if their sides |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4344 | 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] | 4345 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4346 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
| 4347 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4348 | #paint_as_used_by_draw_lattice_or_draw_nine(image)# |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4349 | |
| 4350 | If generated mask extends beyond image bounds, replicate image edge colors, just |
| 4351 | as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4352 | replicates the image edge color when it samples outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4353 | |
| 4354 | #Param image Image containing pixels, dimensions, and format ## |
| 4355 | #Param center IRect edge of image corners and sides ## |
| 4356 | #Param dst destination Rect of image to draw to ## |
| 4357 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4358 | and so on; or nullptr |
| 4359 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4360 | |
| 4361 | #Example |
| 4362 | #Height 128 |
| 4363 | #Description |
| 4364 | 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] | 4365 | The second image equals the size of center; only corners are drawn without scaling. |
| 4366 | The remaining images are larger than center. All corners draw without scaling. |
| 4367 | 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] | 4368 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4369 | void draw(SkCanvas* canvas) { |
| 4370 | SkIRect center = { 20, 10, 50, 40 }; |
| 4371 | SkBitmap bitmap; |
| 4372 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60)); |
| 4373 | SkCanvas bitCanvas(bitmap); |
| 4374 | SkPaint paint; |
| 4375 | SkColor gray = 0xFF000000; |
| 4376 | int left = 0; |
| 4377 | for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) { |
| 4378 | int top = 0; |
| 4379 | for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) { |
| 4380 | paint.setColor(gray); |
| 4381 | bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint); |
| 4382 | gray += 0x001f1f1f; |
| 4383 | top = bottom; |
| 4384 | } |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4385 | left = right; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4386 | } |
| 4387 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 4388 | SkImage* imagePtr = image.get(); |
| 4389 | for (auto dest: { 20, 30, 40, 60, 90 } ) { |
| 4390 | canvas->drawImageNine(imagePtr, center, SkRect::MakeWH(dest, dest), nullptr); |
| 4391 | canvas->translate(dest + 4, 0); |
| 4392 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4393 | } |
| 4394 | ## |
| 4395 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4396 | #SeeAlso drawImage drawBitmapNine drawImageLattice drawImageRect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4397 | |
| 4398 | ## |
| 4399 | |
| 4400 | # ------------------------------------------------------------------------------ |
| 4401 | |
| 4402 | #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] | 4403 | const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4404 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4405 | #In Draw |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4406 | Draws Image image stretched proportionally to fit into Rect dst. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4407 | 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] | 4408 | 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] | 4409 | 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] | 4410 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4411 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
| 4412 | |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 4413 | #paint_as_used_by_draw_lattice_or_draw_nine(image)# |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4414 | |
| 4415 | If generated mask extends beyond image bounds, replicate image edge colors, just |
| 4416 | as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4417 | replicates the image edge color when it samples outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4418 | |
| 4419 | #Param image Image containing pixels, dimensions, and format ## |
| 4420 | #Param center IRect edge of image corners and sides ## |
| 4421 | #Param dst destination Rect of image to draw to ## |
| 4422 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4423 | and so on; or nullptr |
| 4424 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4425 | |
| 4426 | #Example |
| 4427 | #Height 128 |
| 4428 | #Description |
| 4429 | The two leftmost images has four corners and sides to the left and right of center. |
| 4430 | The leftmost image scales the width of corners proportionately to fit. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4431 | 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] | 4432 | fill the remaining space. |
| 4433 | The rightmost image has four corners scaled vertically to fit, and uses sides above |
| 4434 | and below center to fill the remaining space. |
| 4435 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4436 | void draw(SkCanvas* canvas) { |
| 4437 | SkIRect center = { 20, 10, 50, 40 }; |
| 4438 | SkBitmap bitmap; |
| 4439 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60)); |
| 4440 | SkCanvas bitCanvas(bitmap); |
| 4441 | SkPaint paint; |
| 4442 | SkColor gray = 0xFF000000; |
| 4443 | int left = 0; |
| 4444 | for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) { |
| 4445 | int top = 0; |
| 4446 | for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) { |
| 4447 | paint.setColor(gray); |
| 4448 | bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint); |
| 4449 | gray += 0x001f1f1f; |
| 4450 | top = bottom; |
| 4451 | } |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4452 | left = right; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4453 | } |
| 4454 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 4455 | for (auto dest: { 20, 30, 40, 60, 90 } ) { |
| 4456 | canvas->drawImageNine(image, center, SkRect::MakeWH(dest, 110 - dest), nullptr); |
| 4457 | canvas->translate(dest + 4, 0); |
| 4458 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4459 | } |
| 4460 | ## |
| 4461 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4462 | #SeeAlso drawImage drawBitmapNine drawImageLattice drawImageRect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4463 | |
| 4464 | ## |
| 4465 | |
| 4466 | # ------------------------------------------------------------------------------ |
| 4467 | |
| 4468 | #Method void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4469 | const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4470 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4471 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4472 | #Line # draws Bitmap at (x, y) position ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4473 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4474 | Draws Bitmap bitmap, with its top-left corner at (left, top), |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4475 | using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4476 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 4477 | If Paint paint is not nullptr, apply Color_Filter, Color_Alpha, Image_Filter, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4478 | Blend_Mode, and Draw_Looper. If bitmap is kAlpha_8_SkColorType, apply Shader. |
| 4479 | If paint contains Mask_Filter, generate mask from bitmap bounds. |
| 4480 | |
| 4481 | If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, |
| 4482 | just as Shader made from SkShader::MakeBitmapShader with |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4483 | SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4484 | outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4485 | |
| 4486 | #Param bitmap Bitmap containing pixels, dimensions, and format ## |
| 4487 | #Param left left side of bitmap ## |
| 4488 | #Param top top side of bitmap ## |
| 4489 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4490 | and so on; or nullptr |
| 4491 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4492 | |
| 4493 | #Example |
| 4494 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4495 | void draw(SkCanvas* canvas) { |
| 4496 | uint8_t pixels[][8] = { { 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00}, |
| 4497 | { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00}, |
| 4498 | { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00}, |
| 4499 | { 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF}, |
| 4500 | { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, |
| 4501 | { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00}, |
| 4502 | { 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00}, |
| 4503 | { 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF} }; |
| 4504 | SkBitmap bitmap; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4505 | bitmap.installPixels(SkImageInfo::MakeA8(8, 8), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4506 | (void*) pixels, sizeof(pixels[0])); |
| 4507 | SkPaint paint; |
| 4508 | canvas->scale(4, 4); |
| 4509 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xFF007F00} ) { |
| 4510 | paint.setColor(color); |
| 4511 | canvas->drawBitmap(bitmap, 0, 0, &paint); |
| 4512 | canvas->translate(12, 0); |
| 4513 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4514 | } |
| 4515 | ## |
| 4516 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4517 | #SeeAlso drawImage drawBitmapLattice drawBitmapNine drawBitmapRect SkBitmap::readPixels SkBitmap::writePixels |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4518 | |
| 4519 | ## |
| 4520 | |
| 4521 | # ------------------------------------------------------------------------------ |
| 4522 | |
| 4523 | #Method void drawBitmapRect(const SkBitmap& bitmap, const SkRect& src, const SkRect& dst, |
| 4524 | const SkPaint* paint, SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4525 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4526 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4527 | #Line # draws Bitmap, source Rect to destination Rect ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4528 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4529 | Draws Rect src of Bitmap bitmap, scaled and translated to fill Rect dst. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4530 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4531 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4532 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4533 | Blend_Mode, and Draw_Looper. If bitmap is kAlpha_8_SkColorType, apply Shader. |
| 4534 | If paint contains Mask_Filter, generate mask from bitmap bounds. |
| 4535 | |
| 4536 | If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, |
| 4537 | just as Shader made from SkShader::MakeBitmapShader with |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4538 | SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4539 | outside of its bounds. |
| 4540 | |
| 4541 | constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to |
| 4542 | sample within src; set to kFast_SrcRectConstraint allows sampling outside to |
| 4543 | improve performance. |
| 4544 | |
| 4545 | #Param bitmap Bitmap containing pixels, dimensions, and format ## |
| 4546 | #Param src source Rect of image to draw from ## |
| 4547 | #Param dst destination Rect of image to draw to ## |
| 4548 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4549 | and so on; or nullptr |
| 4550 | ## |
| 4551 | #Param constraint filter strictly within src or draw faster ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4552 | |
| 4553 | #Example |
| 4554 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4555 | void draw(SkCanvas* canvas) { |
| 4556 | uint8_t pixels[][8] = { { 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00}, |
| 4557 | { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00}, |
| 4558 | { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00}, |
| 4559 | { 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF}, |
| 4560 | { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, |
| 4561 | { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00}, |
| 4562 | { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00}, |
| 4563 | { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00} }; |
| 4564 | SkBitmap bitmap; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4565 | bitmap.installPixels(SkImageInfo::MakeA8(8, 8), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4566 | (void*) pixels, sizeof(pixels[0])); |
| 4567 | SkPaint paint; |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 4568 | paint.setMaskFilter(SkMaskFilter::MakeBlur(kSolid_SkBlurStyle, 6)); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4569 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xFF007F00} ) { |
| 4570 | paint.setColor(color); |
| 4571 | canvas->drawBitmapRect(bitmap, SkRect::MakeWH(8, 8), SkRect::MakeWH(32, 32), &paint); |
| 4572 | canvas->translate(48, 0); |
| 4573 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4574 | } |
| 4575 | ## |
| 4576 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4577 | #SeeAlso drawImageRect drawBitmap drawBitmapLattice drawBitmapNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4578 | |
| 4579 | ## |
| 4580 | |
| 4581 | # ------------------------------------------------------------------------------ |
| 4582 | |
| 4583 | #Method void drawBitmapRect(const SkBitmap& bitmap, const SkIRect& isrc, const SkRect& dst, |
| 4584 | const SkPaint* paint, SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4585 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4586 | #In Draw |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4587 | Draws IRect isrc of Bitmap bitmap, scaled and translated to fill Rect dst. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4588 | isrc is on integer pixel boundaries; dst may include fractional boundaries. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4589 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4590 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4591 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4592 | Blend_Mode, and Draw_Looper. If bitmap is kAlpha_8_SkColorType, apply Shader. |
| 4593 | If paint contains Mask_Filter, generate mask from bitmap bounds. |
| 4594 | |
| 4595 | If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, |
| 4596 | just as Shader made from SkShader::MakeBitmapShader with |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4597 | SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4598 | outside of its bounds. |
| 4599 | |
| 4600 | constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4601 | sample within isrc; set to kFast_SrcRectConstraint allows sampling outside to |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4602 | improve performance. |
| 4603 | |
| 4604 | #Param bitmap Bitmap containing pixels, dimensions, and format ## |
| 4605 | #Param isrc source IRect of image to draw from ## |
| 4606 | #Param dst destination Rect of image to draw to ## |
| 4607 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4608 | and so on; or nullptr |
| 4609 | ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4610 | #Param constraint sample strictly within isrc, or draw faster ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4611 | |
| 4612 | #Example |
| 4613 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4614 | void draw(SkCanvas* canvas) { |
| 4615 | uint8_t pixels[][8] = { { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00}, |
| 4616 | { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00}, |
| 4617 | { 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF}, |
| 4618 | { 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF}, |
| 4619 | { 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF}, |
| 4620 | { 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF}, |
| 4621 | { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00}, |
| 4622 | { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00} }; |
| 4623 | SkBitmap bitmap; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4624 | bitmap.installPixels(SkImageInfo::MakeA8(8, 8), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4625 | (void*) pixels, sizeof(pixels[0])); |
| 4626 | SkPaint paint; |
| 4627 | paint.setFilterQuality(kHigh_SkFilterQuality); |
| 4628 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xFF007F00, 0xFF7f007f} ) { |
| 4629 | paint.setColor(color); |
| 4630 | canvas->drawBitmapRect(bitmap, SkIRect::MakeWH(8, 8), SkRect::MakeWH(32, 32), &paint); |
| 4631 | canvas->translate(48.25f, 0); |
| 4632 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4633 | } |
| 4634 | ## |
| 4635 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4636 | #SeeAlso drawImageRect drawBitmap drawBitmapLattice drawBitmapNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4637 | |
| 4638 | ## |
| 4639 | |
| 4640 | # ------------------------------------------------------------------------------ |
| 4641 | |
| 4642 | #Method void drawBitmapRect(const SkBitmap& bitmap, const SkRect& dst, const SkPaint* paint, |
| 4643 | SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4644 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4645 | #In Draw |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4646 | Draws Bitmap bitmap, scaled and translated to fill Rect dst. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4647 | bitmap bounds is on integer pixel boundaries; dst may include fractional boundaries. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4648 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4649 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4650 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4651 | Blend_Mode, and Draw_Looper. If bitmap is kAlpha_8_SkColorType, apply Shader. |
| 4652 | If paint contains Mask_Filter, generate mask from bitmap bounds. |
| 4653 | |
| 4654 | If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, |
| 4655 | just as Shader made from SkShader::MakeBitmapShader with |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4656 | SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4657 | outside of its bounds. |
| 4658 | |
| 4659 | constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4660 | sample within bitmap; set to kFast_SrcRectConstraint allows sampling outside to |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4661 | improve performance. |
| 4662 | |
| 4663 | #Param bitmap Bitmap containing pixels, dimensions, and format ## |
| 4664 | #Param dst destination Rect of image to draw to ## |
| 4665 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4666 | and so on; or nullptr |
| 4667 | ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4668 | #Param constraint filter strictly within bitmap or draw faster ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4669 | |
| 4670 | #Example |
| 4671 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4672 | void draw(SkCanvas* canvas) { |
| 4673 | uint32_t pixels[][2] = { { 0x00000000, 0x55550000}, |
| 4674 | { 0xAAAA0000, 0xFFFF0000} }; |
| 4675 | SkBitmap bitmap; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4676 | bitmap.installPixels(SkImageInfo::MakeN32Premul(2, 2), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4677 | (void*) pixels, sizeof(pixels[0])); |
| 4678 | SkPaint paint; |
| 4679 | canvas->scale(4, 4); |
| 4680 | for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN } ) { |
| 4681 | paint.setColorFilter(SkColorFilter::MakeModeFilter(color, SkBlendMode::kPlus)); |
| 4682 | canvas->drawBitmapRect(bitmap, SkRect::MakeWH(8, 8), &paint); |
| 4683 | canvas->translate(8, 0); |
| 4684 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4685 | } |
| 4686 | ## |
| 4687 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4688 | #SeeAlso drawImageRect drawBitmap drawBitmapLattice drawBitmapNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4689 | |
| 4690 | ## |
| 4691 | |
| 4692 | # ------------------------------------------------------------------------------ |
| 4693 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4694 | #PhraseDef paint_as_used_by_draw_lattice_or_draw_nine(bitmap_or_image) |
| 4695 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4696 | Blend_Mode, and Draw_Looper. If #bitmap_or_image# is kAlpha_8_SkColorType, apply Shader. |
| 4697 | If paint contains Mask_Filter, generate mask from #bitmap_or_image# bounds. If paint |
| 4698 | Filter_Quality set to kNone_SkFilterQuality, disable pixel filtering. For all |
| 4699 | other values of paint Filter_Quality, use kLow_SkFilterQuality to filter pixels. |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 4700 | Any SkMaskFilter on paint is ignored as is paint Anti_Aliasing state. |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4701 | ## |
| 4702 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4703 | #Method void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4704 | const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4705 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4706 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4707 | #Line # draws Nine_Patch Bitmap ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4708 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4709 | Draws Bitmap bitmap stretched proportionally to fit into Rect dst. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4710 | IRect center divides the bitmap into nine sections: four sides, four corners, |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4711 | 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] | 4712 | sides are larger than dst; center and four sides are scaled to fit remaining |
| 4713 | space, if any. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4714 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4715 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
| 4716 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4717 | #paint_as_used_by_draw_lattice_or_draw_nine(bitmap)# |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4718 | |
| 4719 | If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, |
| 4720 | just as Shader made from SkShader::MakeBitmapShader with |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4721 | SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4722 | outside of its bounds. |
| 4723 | |
| 4724 | #Param bitmap Bitmap containing pixels, dimensions, and format ## |
| 4725 | #Param center IRect edge of image corners and sides ## |
| 4726 | #Param dst destination Rect of image to draw to ## |
| 4727 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4728 | and so on; or nullptr |
| 4729 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4730 | |
| 4731 | #Example |
| 4732 | #Height 128 |
| 4733 | #Description |
| 4734 | The two leftmost bitmap draws has four corners and sides to the left and right of center. |
| 4735 | The leftmost bitmap draw scales the width of corners proportionately to fit. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4736 | 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] | 4737 | fill the remaining space. |
| 4738 | The rightmost bitmap draw has four corners scaled vertically to fit, and uses sides above |
| 4739 | and below center to fill the remaining space. |
| 4740 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4741 | void draw(SkCanvas* canvas) { |
| 4742 | SkIRect center = { 20, 10, 50, 40 }; |
| 4743 | SkBitmap bitmap; |
| 4744 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60)); |
| 4745 | SkCanvas bitCanvas(bitmap); |
| 4746 | SkPaint paint; |
| 4747 | SkColor gray = 0xFF000000; |
| 4748 | int left = 0; |
| 4749 | for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) { |
| 4750 | int top = 0; |
| 4751 | for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) { |
| 4752 | paint.setColor(gray); |
| 4753 | bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint); |
| 4754 | gray += 0x001f1f1f; |
| 4755 | top = bottom; |
| 4756 | } |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4757 | left = right; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4758 | } |
| 4759 | for (auto dest: { 20, 30, 40, 60, 90 } ) { |
| 4760 | canvas->drawBitmapNine(bitmap, center, SkRect::MakeWH(dest, 110 - dest), nullptr); |
| 4761 | canvas->translate(dest + 4, 0); |
| 4762 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4763 | } |
| 4764 | ## |
| 4765 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4766 | #SeeAlso drawImageNine drawBitmap drawBitmapLattice drawBitmapRect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4767 | |
| 4768 | ## |
| 4769 | |
| 4770 | # ------------------------------------------------------------------------------ |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4771 | #Subtopic Lattice |
| 4772 | #Line # divides Bitmap or Image into a rectangular grid ## |
| 4773 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4774 | #Struct Lattice |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 4775 | #Line # divides Bitmap or Image into a rectangular grid ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4776 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4777 | #Code |
| 4778 | struct Lattice { |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4779 | enum RectType ... |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4780 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4781 | const int* fXDivs; |
| 4782 | const int* fYDivs; |
| 4783 | const RectType* fRectTypes; |
| 4784 | int fXCount; |
| 4785 | int fYCount; |
| 4786 | const SkIRect* fBounds; |
| 4787 | const SkColor* fColors; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4788 | }; |
| 4789 | ## |
| 4790 | |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 4791 | Lattice divides Bitmap or Image into a rectangular grid. |
| 4792 | Grid entries on even columns and even rows are fixed; these entries are |
| 4793 | always drawn at their original size if the destination is large enough. |
| 4794 | If the destination side is too small to hold the fixed entries, all fixed |
| 4795 | entries are proportionately scaled down to fit. |
| 4796 | The grid entries not on even columns and rows are scaled to fit the |
| 4797 | remaining space, if any. |
| 4798 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4799 | #Subtopic Overview |
| 4800 | #Populate |
| 4801 | ## |
| 4802 | |
| 4803 | #Subtopic Constant |
| 4804 | #Populate |
| 4805 | ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4806 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4807 | #Enum RectType |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4808 | #Line # optional setting per rectangular grid entry ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4809 | #Code |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4810 | enum RectType : uint8_t { |
| 4811 | kDefault = 0, |
| 4812 | kTransparent, |
| 4813 | kFixedColor, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4814 | }; |
| 4815 | ## |
| 4816 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4817 | Optional setting per rectangular grid entry to make it transparent, |
| 4818 | or to fill the grid entry with a color. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4819 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4820 | #Const kDefault 0 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4821 | #Line # draws Bitmap into lattice rectangle ## |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4822 | ## |
| 4823 | |
| 4824 | #Const kTransparent 1 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4825 | #Line # skips lattice rectangle by making it transparent ## |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4826 | ## |
| 4827 | |
| 4828 | #Const kFixedColor 2 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4829 | #Line # draws one of fColors into lattice rectangle ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4830 | ## |
| 4831 | ## |
| 4832 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4833 | #Subtopic Member |
| 4834 | #Populate |
| 4835 | ## |
| 4836 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4837 | #Member const int* fXDivs |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 4838 | #Line # x-axis values dividing bitmap ## |
| 4839 | Array of x-axis values that divide the bitmap vertically. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4840 | Array entries must be unique, increasing, greater than or equal to |
| 4841 | fBounds left edge, and less than fBounds right edge. |
| 4842 | Set the first element to fBounds left to collapse the left column of |
| 4843 | fixed grid entries. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4844 | ## |
| 4845 | |
| 4846 | #Member const int* fYDivs |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 4847 | #Line # y-axis values dividing bitmap ## |
| 4848 | Array of y-axis values that divide the bitmap horizontally. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4849 | Array entries must be unique, increasing, greater than or equal to |
| 4850 | fBounds top edge, and less than fBounds bottom edge. |
| 4851 | Set the first element to fBounds top to collapse the top row of fixed |
| 4852 | grid entries. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4853 | ## |
| 4854 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4855 | #Member const RectType* fRectTypes |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4856 | #Line # array of fill types ## |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4857 | Optional array of fill types, one per rectangular grid entry: |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4858 | array length must be |
| 4859 | #Formula |
| 4860 | (fXCount + 1) * (fYCount + 1) |
| 4861 | ## |
| 4862 | . |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 4863 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4864 | Each RectType is one of: kDefault, kTransparent, kFixedColor. |
| 4865 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4866 | Array entries correspond to the rectangular grid entries, ascending |
| 4867 | left to right and then top to bottom. |
| 4868 | ## |
| 4869 | |
| 4870 | #Member int fXCount |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4871 | #Line # number of x-coordinates ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4872 | Number of entries in fXDivs array; one less than the number of |
| 4873 | horizontal divisions. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4874 | ## |
| 4875 | |
| 4876 | #Member int fYCount |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4877 | #Line # number of y-coordinates ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4878 | Number of entries in fYDivs array; one less than the number of vertical |
| 4879 | divisions. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4880 | ## |
| 4881 | |
| 4882 | #Member const SkIRect* fBounds |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4883 | #Line # source bounds to draw from ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4884 | Optional subset IRect source to draw from. |
| 4885 | If nullptr, source bounds is dimensions of Bitmap or Image. |
| 4886 | ## |
| 4887 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4888 | #Member const SkColor* fColors |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4889 | #Line # array of colors ## |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4890 | Optional array of colors, one per rectangular grid entry. |
| 4891 | Array length must be |
| 4892 | #Formula |
| 4893 | (fXCount + 1) * (fYCount + 1) |
| 4894 | ## |
| 4895 | . |
| 4896 | |
| 4897 | Array entries correspond to the rectangular grid entries, ascending |
| 4898 | left to right, then top to bottom. |
| 4899 | ## |
| 4900 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4901 | #Struct Lattice ## |
| 4902 | |
| 4903 | #Method void drawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice, const SkRect& dst, |
| 4904 | const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4905 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4906 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4907 | #Line # draws proportionally stretched Bitmap ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4908 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4909 | Draws Bitmap bitmap stretched proportionally to fit into Rect dst. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4910 | |
| 4911 | Lattice lattice divides bitmap into a rectangular grid. |
| 4912 | 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] | 4913 | of drawBitmapNine, fixed lattice elements never scale larger than their initial |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4914 | size and shrink proportionately when all fixed elements exceed the bitmap |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4915 | 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] | 4916 | |
| 4917 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4918 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4919 | #paint_as_used_by_draw_lattice_or_draw_nine(bitmap)# |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4920 | |
| 4921 | If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, |
| 4922 | just as Shader made from SkShader::MakeBitmapShader with |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4923 | SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4924 | outside of its bounds. |
| 4925 | |
| 4926 | #Param bitmap Bitmap containing pixels, dimensions, and format ## |
| 4927 | #Param lattice division of bitmap into fixed and variable rectangles ## |
| 4928 | #Param dst destination Rect of image to draw to ## |
| 4929 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4930 | and so on; or nullptr |
| 4931 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4932 | |
| 4933 | #Example |
| 4934 | #Height 128 |
| 4935 | #Description |
| 4936 | The two leftmost bitmap draws has four corners and sides to the left and right of center. |
| 4937 | The leftmost bitmap draw scales the width of corners proportionately to fit. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4938 | 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] | 4939 | fill the remaining space; the center is transparent. |
| 4940 | The rightmost bitmap draw has four corners scaled vertically to fit, and uses sides above |
| 4941 | and below center to fill the remaining space. |
| 4942 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4943 | void draw(SkCanvas* canvas) { |
| 4944 | SkIRect center = { 20, 10, 50, 40 }; |
| 4945 | SkBitmap bitmap; |
| 4946 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60)); |
| 4947 | SkCanvas bitCanvas(bitmap); |
| 4948 | SkPaint paint; |
| 4949 | SkColor gray = 0xFF000000; |
| 4950 | int left = 0; |
| 4951 | for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) { |
| 4952 | int top = 0; |
| 4953 | for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) { |
| 4954 | paint.setColor(gray); |
| 4955 | bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint); |
| 4956 | gray += 0x001f1f1f; |
| 4957 | top = bottom; |
| 4958 | } |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4959 | left = right; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4960 | } |
| 4961 | const int xDivs[] = { center.fLeft, center.fRight }; |
| 4962 | const int yDivs[] = { center.fTop, center.fBottom }; |
Cary Clark | ca3ebcd | 2017-12-12 11:22:38 -0500 | [diff] [blame] | 4963 | SkCanvas::Lattice::RectType fillTypes[3][3]; |
| 4964 | memset(fillTypes, 0, sizeof(fillTypes)); |
| 4965 | fillTypes[1][1] = SkCanvas::Lattice::kTransparent; |
| 4966 | SkColor dummy[9]; // temporary pending bug fix |
| 4967 | SkCanvas::Lattice lattice = { xDivs, yDivs, fillTypes[0], SK_ARRAY_COUNT(xDivs), |
| 4968 | SK_ARRAY_COUNT(yDivs), nullptr, dummy }; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4969 | for (auto dest: { 20, 30, 40, 60, 90 } ) { |
Cary Clark | ca3ebcd | 2017-12-12 11:22:38 -0500 | [diff] [blame] | 4970 | canvas->drawBitmapLattice(bitmap, lattice, SkRect::MakeWH(dest, 110 - dest), nullptr); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4971 | canvas->translate(dest + 4, 0); |
| 4972 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4973 | } |
| 4974 | ## |
| 4975 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4976 | #SeeAlso drawImageLattice drawBitmap drawBitmapNine Lattice |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4977 | |
| 4978 | ## |
| 4979 | |
| 4980 | # ------------------------------------------------------------------------------ |
| 4981 | |
| 4982 | #Method void drawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst, |
| 4983 | const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4984 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4985 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4986 | #Line # draws proportionally stretched Image ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4987 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4988 | Draws Image image stretched proportionally to fit into Rect dst. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4989 | |
| 4990 | Lattice lattice divides image into a rectangular grid. |
| 4991 | 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] | 4992 | of drawBitmapNine, fixed lattice elements never scale larger than their initial |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4993 | size and shrink proportionately when all fixed elements exceed the bitmap |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4994 | 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] | 4995 | |
| 4996 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4997 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4998 | #paint_as_used_by_draw_lattice_or_draw_nine(image)# |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4999 | |
| 5000 | If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, |
| 5001 | just as Shader made from SkShader::MakeBitmapShader with |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5002 | SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5003 | outside of its bounds. |
| 5004 | |
| 5005 | #Param image Image containing pixels, dimensions, and format ## |
| 5006 | #Param lattice division of bitmap into fixed and variable rectangles ## |
| 5007 | #Param dst destination Rect of image to draw to ## |
| 5008 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 5009 | and so on; or nullptr |
| 5010 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5011 | |
| 5012 | #Example |
| 5013 | #Height 128 |
| 5014 | #Description |
| 5015 | 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] | 5016 | The second image equals the size of center; only corners are drawn without scaling. |
| 5017 | 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] | 5018 | are scaled if needed to take up the remaining space; the center is transparent. |
| 5019 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5020 | void draw(SkCanvas* canvas) { |
| 5021 | SkIRect center = { 20, 10, 50, 40 }; |
| 5022 | SkBitmap bitmap; |
| 5023 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60)); |
| 5024 | SkCanvas bitCanvas(bitmap); |
| 5025 | SkPaint paint; |
| 5026 | SkColor gray = 0xFF000000; |
| 5027 | int left = 0; |
| 5028 | for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) { |
| 5029 | int top = 0; |
| 5030 | for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) { |
| 5031 | paint.setColor(gray); |
| 5032 | bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint); |
| 5033 | gray += 0x001f1f1f; |
| 5034 | top = bottom; |
| 5035 | } |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5036 | left = right; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5037 | } |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5038 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 5039 | SkImage* imagePtr = image.get(); |
| 5040 | for (auto dest: { 20, 30, 40, 60, 90 } ) { |
| 5041 | canvas->drawImageNine(imagePtr, center, SkRect::MakeWH(dest, dest), nullptr); |
| 5042 | canvas->translate(dest + 4, 0); |
| 5043 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5044 | } |
| 5045 | ## |
| 5046 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5047 | #SeeAlso drawBitmapLattice drawImage drawImageNine Lattice |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5048 | |
| 5049 | ## |
| 5050 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5051 | #Subtopic Lattice ## |
| 5052 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 5053 | #Subtopic Draw_Image ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5054 | |
| 5055 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5056 | #Subtopic Draw_Text |
| 5057 | #Populate |
| 5058 | #Line # draws text into Canvas ## |
| 5059 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5060 | |
| 5061 | #Method void drawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, |
| 5062 | const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5063 | #In Draw_Text |
| 5064 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5065 | #Line # draws text at (x, y), using font advance ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5066 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5067 | Draws text, with origin at (x, y), using Clip, Matrix, and Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5068 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5069 | text meaning depends on Paint_Text_Encoding; by default, text is encoded as |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5070 | UTF-8. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5071 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5072 | x and y meaning depends on Paint_Text_Align and Paint_Vertical_Text; by default |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5073 | text draws left to right, positioning the first glyph left side bearing at x |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5074 | and its baseline at y. Text size is affected by Matrix and Paint_Text_Size. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5075 | |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 5076 | All elements of paint: Path_Effect, Mask_Filter, Shader, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5077 | Color_Filter, Image_Filter, and Draw_Looper; apply to text. By default, draws |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5078 | filled 12 point black Glyphs. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5079 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5080 | #Param text character code points or Glyphs drawn ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5081 | #Param byteLength byte length of text array ## |
| 5082 | #Param x start of text on x-axis ## |
| 5083 | #Param y start of text on y-axis ## |
| 5084 | #Param paint text size, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5085 | |
| 5086 | #Example |
| 5087 | #Height 200 |
| 5088 | #Description |
| 5089 | The same text is drawn varying Paint_Text_Size and varying |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5090 | Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5091 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5092 | void draw(SkCanvas* canvas) { |
| 5093 | SkPaint paint; |
| 5094 | paint.setAntiAlias(true); |
| 5095 | float textSizes[] = { 12, 18, 24, 36 }; |
| 5096 | for (auto size: textSizes ) { |
| 5097 | paint.setTextSize(size); |
| 5098 | canvas->drawText("Aa", 2, 10, 20, paint); |
| 5099 | canvas->translate(0, size * 2); |
| 5100 | } |
| 5101 | paint.reset(); |
| 5102 | paint.setAntiAlias(true); |
| 5103 | float yPos = 20; |
| 5104 | for (auto size: textSizes ) { |
| 5105 | float scale = size / 12.f; |
| 5106 | canvas->resetMatrix(); |
| 5107 | canvas->translate(100, 0); |
| 5108 | canvas->scale(scale, scale); |
| 5109 | canvas->drawText("Aa", 2, 10 / scale, yPos / scale, paint); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5110 | yPos += size * 2; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5111 | } |
| 5112 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5113 | ## |
| 5114 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5115 | #SeeAlso drawString drawPosText drawPosTextH drawTextBlob drawTextOnPath drawTextRSXform |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5116 | |
| 5117 | ## |
| 5118 | |
| 5119 | #Method void drawString(const char* string, SkScalar x, SkScalar y, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5120 | #In Draw_Text |
| 5121 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5122 | #Line # draws null terminated string at (x, y) using font advance ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5123 | Draws null terminated string, with origin at (x, y), using Clip, Matrix, and |
| 5124 | Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5125 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5126 | string meaning depends on Paint_Text_Encoding; by default, strings are encoded |
| 5127 | as UTF-8. Other values of Paint_Text_Encoding are unlikely to produce the desired |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5128 | results, since zero bytes may be embedded in the string. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5129 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5130 | x and y meaning depends on Paint_Text_Align and Paint_Vertical_Text; by default |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5131 | string draws left to right, positioning the first glyph left side bearing at x |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5132 | and its baseline at y. Text size is affected by Matrix and Paint_Text_Size. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5133 | |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 5134 | All elements of paint: Path_Effect, Mask_Filter, Shader, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5135 | Color_Filter, Image_Filter, and Draw_Looper; apply to text. By default, draws |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5136 | filled 12 point black Glyphs. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5137 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5138 | #Param string character code points or Glyphs drawn, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5139 | ending with a char value of zero |
| 5140 | ## |
| 5141 | #Param x start of string on x-axis ## |
| 5142 | #Param y start of string on y-axis ## |
| 5143 | #Param paint text size, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5144 | |
| 5145 | #Example |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 5146 | #Height 48 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5147 | SkPaint paint; |
| 5148 | canvas->drawString("a small hello", 20, 20, paint); |
| 5149 | ## |
| 5150 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5151 | #SeeAlso drawText drawPosText drawPosTextH drawTextBlob drawTextOnPath drawTextRSXform |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5152 | |
| 5153 | ## |
| 5154 | |
| 5155 | #Method void drawString(const SkString& string, SkScalar x, SkScalar y, const SkPaint& paint) |
| 5156 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5157 | Draws null terminated string, with origin at (x, y), using Clip, Matrix, and |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5158 | Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5159 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5160 | string meaning depends on Paint_Text_Encoding; by default, strings are encoded |
| 5161 | as UTF-8. Other values of Paint_Text_Encoding are unlikely to produce the desired |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5162 | results, since zero bytes may be embedded in the string. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5163 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5164 | x and y meaning depends on Paint_Text_Align and Paint_Vertical_Text; by default |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5165 | string draws left to right, positioning the first glyph left side bearing at x |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5166 | and its baseline at y. Text size is affected by Matrix and Paint_Text_Size. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5167 | |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 5168 | All elements of paint: Path_Effect, Mask_Filter, Shader, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5169 | Color_Filter, Image_Filter, and Draw_Looper; apply to text. By default, draws |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5170 | filled 12 point black Glyphs. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5171 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5172 | #Param string character code points or Glyphs drawn, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5173 | ending with a char value of zero |
| 5174 | ## |
| 5175 | #Param x start of string on x-axis ## |
| 5176 | #Param y start of string on y-axis ## |
| 5177 | #Param paint text size, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5178 | |
| 5179 | #Example |
| 5180 | SkPaint paint; |
| 5181 | SkString string("a small hello"); |
| 5182 | canvas->drawString(string, 20, 20, paint); |
| 5183 | ## |
| 5184 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5185 | #SeeAlso drawText drawPosText drawPosTextH drawTextBlob drawTextOnPath drawTextRSXform |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5186 | |
| 5187 | ## |
| 5188 | |
| 5189 | # ------------------------------------------------------------------------------ |
| 5190 | |
| 5191 | #Method void drawPosText(const void* text, size_t byteLength, const SkPoint pos[], |
| 5192 | const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5193 | #In Draw_Text |
| 5194 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5195 | #Line # draws text at array of (x, y) positions ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5196 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5197 | Draws each glyph in text with the origin in pos array, using Clip, Matrix, and |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5198 | Paint paint. The number of entries in pos array must match the number of Glyphs |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5199 | described by byteLength of text. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5200 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5201 | text meaning depends on Paint_Text_Encoding; by default, text is encoded as |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 5202 | UTF-8. pos elements meaning depends on Paint_Vertical_Text; by default |
| 5203 | glyph left side bearing and baseline are relative to Point in pos array. |
| 5204 | Text size is affected by Matrix and Paint_Text_Size. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5205 | |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 5206 | All elements of paint: Path_Effect, Mask_Filter, Shader, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5207 | Color_Filter, Image_Filter, and Draw_Looper; apply to text. By default, draws |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5208 | filled 12 point black Glyphs. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5209 | |
| 5210 | Layout engines such as Harfbuzz typically position each glyph |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5211 | rather than using the font advance widths. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5212 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5213 | #Param text character code points or Glyphs drawn ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5214 | #Param byteLength byte length of text array ## |
| 5215 | #Param pos array of glyph origins ## |
| 5216 | #Param paint text size, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5217 | |
| 5218 | #Example |
| 5219 | #Height 120 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5220 | void draw(SkCanvas* canvas) { |
| 5221 | const char hello[] = "HeLLo!"; |
| 5222 | const SkPoint pos[] = { {40, 100}, {82, 95}, {115, 110}, {130, 95}, {145, 85}, |
| 5223 | {172, 100} }; |
| 5224 | SkPaint paint; |
| 5225 | paint.setTextSize(60); |
| 5226 | canvas->drawPosText(hello, strlen(hello), pos, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5227 | } |
| 5228 | ## |
| 5229 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5230 | #SeeAlso drawText drawPosTextH drawTextBlob drawTextOnPath drawTextRSXform |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5231 | |
| 5232 | ## |
| 5233 | |
| 5234 | # ------------------------------------------------------------------------------ |
| 5235 | |
| 5236 | #Method void drawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], SkScalar constY, |
| 5237 | const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5238 | #In Draw_Text |
| 5239 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5240 | #Line # draws text at x positions with common baseline ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5241 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5242 | Draws each glyph in text with its (x, y) origin composed from xpos array and |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5243 | constY, using Clip, Matrix, and Paint paint. The number of entries in xpos array |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5244 | must match the number of Glyphs described by byteLength of text. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5245 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5246 | text meaning depends on Paint_Text_Encoding; by default, text is encoded as |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 5247 | UTF-8. xpos elements meaning depends on Paint_Vertical_Text; |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5248 | by default each glyph left side bearing is positioned at an xpos element and |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5249 | its baseline is positioned at constY. Text size is affected by Matrix and |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5250 | Paint_Text_Size. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5251 | |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 5252 | All elements of paint: Path_Effect, Mask_Filter, Shader, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5253 | Color_Filter, Image_Filter, and Draw_Looper; apply to text. By default, draws |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5254 | filled 12 point black Glyphs. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5255 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5256 | Layout engines such as Harfbuzz typically position each glyph |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5257 | rather than using the font advance widths if all Glyphs share the same |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5258 | baseline. |
| 5259 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5260 | #Param text character code points or Glyphs drawn ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5261 | #Param byteLength byte length of text array ## |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 5262 | #Param xpos array of x-axis positions, used to position each glyph ## |
| 5263 | #Param constY shared y-axis value for all of x-axis positions ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5264 | #Param paint text size, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5265 | |
| 5266 | #Example |
| 5267 | #Height 40 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5268 | void draw(SkCanvas* canvas) { |
| 5269 | SkScalar xpos[] = { 20, 40, 80, 160 }; |
| 5270 | SkPaint paint; |
| 5271 | canvas->drawPosTextH("XXXX", 4, xpos, 20, paint); |
| 5272 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5273 | ## |
| 5274 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5275 | #SeeAlso drawText drawPosText drawTextBlob drawTextOnPath drawTextRSXform |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5276 | |
| 5277 | ## |
| 5278 | |
| 5279 | # ------------------------------------------------------------------------------ |
| 5280 | |
| 5281 | #Method void drawTextOnPathHV(const void* text, size_t byteLength, const SkPath& path, SkScalar hOffset, |
| 5282 | SkScalar vOffset, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5283 | #In Draw_Text |
| 5284 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5285 | #Line # draws text following Path with offsets ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5286 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5287 | Draws text on Path path, using Clip, Matrix, and Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5288 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5289 | Origin of text is at distance hOffset along the path, offset by a perpendicular |
| 5290 | vector of length vOffset. If the path section corresponding the glyph advance is |
| 5291 | curved, the glyph is drawn curved to match; control points in the glyph are |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5292 | mapped to projected points parallel to the path. If the text advance is larger |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5293 | than the path length, the excess text is clipped. |
| 5294 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5295 | text meaning depends on Paint_Text_Encoding; by default, text is encoded as |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5296 | UTF-8. Origin meaning depends on Paint_Text_Align and Paint_Vertical_Text; by |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 5297 | default text positions the first glyph left side bearing and baseline relative |
| 5298 | to origin. Text size is affected by Matrix and Paint_Text_Size. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5299 | |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 5300 | All elements of paint: Path_Effect, Mask_Filter, Shader, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5301 | Color_Filter, Image_Filter, and Draw_Looper; apply to text. By default, draws |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5302 | filled 12 point black Glyphs. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5303 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5304 | #Param text character code points or Glyphs drawn ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5305 | #Param byteLength byte length of text array ## |
| 5306 | #Param path Path providing text baseline ## |
| 5307 | #Param hOffset distance along path to offset origin ## |
| 5308 | #Param vOffset offset of text above (if negative) or below (if positive) the path ## |
| 5309 | #Param paint text size, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5310 | |
| 5311 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5312 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5313 | const char aero[] = "correo a" "\xC3" "\xA9" "reo"; |
| 5314 | const size_t len = sizeof(aero) - 1; |
| 5315 | SkPath path; |
| 5316 | path.addOval({43-26, 43-26, 43+26, 43+26}, SkPath::kCW_Direction, 3); |
| 5317 | SkPaint paint; |
| 5318 | paint.setTextSize(24); |
| 5319 | for (auto offset : { 0, 10, 20 } ) { |
| 5320 | canvas->drawTextOnPathHV(aero, len, path, 0, -offset, paint); |
| 5321 | canvas->translate(70 + offset, 70 + offset); |
| 5322 | } |
| 5323 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5324 | ## |
| 5325 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5326 | #SeeAlso drawTextOnPath drawText drawPosTextH drawTextBlob drawTextRSXform |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5327 | |
| 5328 | ## |
| 5329 | |
| 5330 | # ------------------------------------------------------------------------------ |
| 5331 | |
| 5332 | #Method void drawTextOnPath(const void* text, size_t byteLength, const SkPath& path, |
| 5333 | const SkMatrix* matrix, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5334 | #In Draw_Text |
| 5335 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5336 | #Line # draws text following Path contour ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5337 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5338 | Draws text on Path path, using Clip, Matrix, and Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5339 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5340 | Origin of text is at beginning of path offset by matrix, if not nullptr. |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 5341 | matrix transforms text before text is mapped to path. If the path section |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5342 | corresponding the glyph advance is curved, the glyph is drawn curved to match; |
| 5343 | control points in the glyph are mapped to projected points parallel to the path. |
| 5344 | If the text advance is larger than the path length, the excess text is clipped. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5345 | |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 5346 | matrix does not effect paint Shader. |
| 5347 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5348 | text meaning depends on Paint_Text_Encoding; by default, text is encoded as |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5349 | UTF-8. Origin meaning depends on Paint_Text_Align and Paint_Vertical_Text; by |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 5350 | default text positions the first glyph left side bearing and baseline relative |
| 5351 | to origin. Text size is affected by matrix parameter, Canvas Matrix, |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5352 | and Paint_Text_Size. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5353 | |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 5354 | All elements of paint: Path_Effect, Mask_Filter, Shader, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5355 | Color_Filter, Image_Filter, and Draw_Looper; apply to text. By default, draws |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 5356 | filled 12 point black Glyphs. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5357 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5358 | #Param text character code points or Glyphs drawn ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5359 | #Param byteLength byte length of text array ## |
| 5360 | #Param path Path providing text baseline ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5361 | #Param matrix transform of Glyphs before mapping to path; may be nullptr |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 5362 | to use identity Matrix |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5363 | ## |
| 5364 | #Param paint text size, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5365 | |
| 5366 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5367 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5368 | const char roller[] = "rollercoaster"; |
| 5369 | const size_t len = sizeof(roller) - 1; |
| 5370 | SkPath path; |
| 5371 | path.cubicTo(40, -80, 120, 80, 160, -40); |
| 5372 | SkPaint paint; |
| 5373 | paint.setTextSize(32); |
| 5374 | paint.setStyle(SkPaint::kStroke_Style); |
| 5375 | SkMatrix matrix; |
| 5376 | matrix.setIdentity(); |
| 5377 | for (int i = 0; i < 3; ++i) { |
| 5378 | canvas->translate(25, 60); |
| 5379 | canvas->drawPath(path, paint); |
| 5380 | canvas->drawTextOnPath(roller, len, path, &matrix, paint); |
| 5381 | matrix.preTranslate(0, 10); |
| 5382 | } |
| 5383 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5384 | ## |
| 5385 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5386 | #SeeAlso drawTextOnPathHV drawText drawPosTextH drawTextBlob drawTextRSXform |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5387 | |
| 5388 | ## |
| 5389 | |
| 5390 | # ------------------------------------------------------------------------------ |
| 5391 | |
| 5392 | #Method void drawTextRSXform(const void* text, size_t byteLength, const SkRSXform xform[], |
| 5393 | const SkRect* cullRect, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5394 | #In Draw_Text |
| 5395 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5396 | #Line # draws text with array of RSXform ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5397 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5398 | Draws text, transforming each glyph by the corresponding SkRSXform, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5399 | using Clip, Matrix, and Paint paint. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5400 | |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 5401 | RSXform xform array specifies a separate square scale, rotation, and translation |
| 5402 | for each glyph. xform does not affect paint Shader. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5403 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5404 | Optional Rect cullRect is a conservative bounds of text, taking into account |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5405 | RSXform and paint. If cullRect is outside of Clip, canvas can skip drawing. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5406 | |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 5407 | All elements of paint: Path_Effect, Mask_Filter, Shader, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5408 | Color_Filter, Image_Filter, and Draw_Looper; apply to text. By default, draws |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5409 | filled 12 point black Glyphs. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5410 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5411 | #Param text character code points or Glyphs drawn ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5412 | #Param byteLength byte length of text array ## |
| 5413 | #Param xform RSXform rotates, scales, and translates each glyph individually ## |
| 5414 | #Param cullRect Rect bounds of text for efficient clipping; or nullptr ## |
| 5415 | #Param paint text size, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5416 | |
| 5417 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5418 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5419 | const int iterations = 26; |
| 5420 | SkRSXform transforms[iterations]; |
| 5421 | char alphabet[iterations]; |
| 5422 | SkScalar angle = 0; |
| 5423 | SkScalar scale = 1; |
| 5424 | for (size_t i = 0; i < SK_ARRAY_COUNT(transforms); ++i) { |
| 5425 | const SkScalar s = SkScalarSin(angle) * scale; |
| 5426 | const SkScalar c = SkScalarCos(angle) * scale; |
| 5427 | transforms[i] = SkRSXform::Make(-c, -s, -s * 16, c * 16); |
| 5428 | angle += .45; |
| 5429 | scale += .2; |
| 5430 | alphabet[i] = 'A' + i; |
| 5431 | } |
| 5432 | SkPaint paint; |
| 5433 | paint.setTextAlign(SkPaint::kCenter_Align); |
| 5434 | canvas->translate(110, 138); |
| 5435 | canvas->drawTextRSXform(alphabet, sizeof(alphabet), transforms, nullptr, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5436 | } |
| 5437 | ## |
| 5438 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5439 | #SeeAlso drawTextOnPath drawTextOnPathHV drawText drawPosText drawTextBlob |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5440 | |
| 5441 | ## |
| 5442 | |
| 5443 | # ------------------------------------------------------------------------------ |
| 5444 | |
| 5445 | #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] | 5446 | #In Draw_Text |
| 5447 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5448 | #Line # draws text with arrays of positions and Paint ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5449 | 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] | 5450 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5451 | blob contains Glyphs, their positions, and paint attributes specific to text: |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5452 | Typeface, Paint_Text_Size, Paint_Text_Scale_X, Paint_Text_Skew_X, |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 5453 | Paint_Text_Align, Paint_Hinting, Anti_Alias, Paint_Fake_Bold, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5454 | Font_Embedded_Bitmaps, Full_Hinting_Spacing, LCD_Text, Linear_Text, |
| 5455 | Subpixel_Text, and Paint_Vertical_Text. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5456 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 5457 | Paint_Text_Encoding must be set to SkPaint::kGlyphID_TextEncoding. |
| 5458 | |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 5459 | Elements of paint: Path_Effect, Mask_Filter, Shader, Color_Filter, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5460 | Image_Filter, and Draw_Looper; apply to blob. |
| 5461 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5462 | #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] | 5463 | #Param x horizontal offset applied to blob ## |
| 5464 | #Param y vertical offset applied to blob ## |
| 5465 | #Param paint blend, color, stroking, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5466 | |
| 5467 | #Example |
| 5468 | #Height 120 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5469 | void draw(SkCanvas* canvas) { |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 5470 | SkTextBlobBuilder textBlobBuilder; |
| 5471 | const char bunny[] = "/(^x^)\\"; |
| 5472 | const int len = sizeof(bunny) - 1; |
| 5473 | uint16_t glyphs[len]; |
| 5474 | SkPaint paint; |
| 5475 | paint.textToGlyphs(bunny, len, glyphs); |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 5476 | paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 5477 | int runs[] = { 3, 1, 3 }; |
| 5478 | SkPoint textPos = { 20, 100 }; |
| 5479 | int glyphIndex = 0; |
| 5480 | for (auto runLen : runs) { |
| 5481 | paint.setTextSize(1 == runLen ? 20 : 50); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5482 | const SkTextBlobBuilder::RunBuffer& run = |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 5483 | textBlobBuilder.allocRun(paint, runLen, textPos.fX, textPos.fY); |
| 5484 | memcpy(run.glyphs, &glyphs[glyphIndex], sizeof(glyphs[0]) * runLen); |
| 5485 | textPos.fX += paint.measureText(&glyphs[glyphIndex], sizeof(glyphs[0]) * runLen, nullptr); |
| 5486 | glyphIndex += runLen; |
| 5487 | } |
| 5488 | sk_sp<const SkTextBlob> blob = textBlobBuilder.make(); |
| 5489 | paint.reset(); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5490 | canvas->drawTextBlob(blob.get(), 0, 0, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5491 | } |
| 5492 | ## |
| 5493 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5494 | #SeeAlso drawText drawPosText drawPosTextH |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5495 | |
| 5496 | ## |
| 5497 | |
| 5498 | # ------------------------------------------------------------------------------ |
| 5499 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5500 | #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] | 5501 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5502 | 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] | 5503 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5504 | blob contains Glyphs, their positions, and paint attributes specific to text: |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5505 | Typeface, Paint_Text_Size, Paint_Text_Scale_X, Paint_Text_Skew_X, |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 5506 | Paint_Text_Align, Paint_Hinting, Anti_Alias, Paint_Fake_Bold, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5507 | Font_Embedded_Bitmaps, Full_Hinting_Spacing, LCD_Text, Linear_Text, |
| 5508 | Subpixel_Text, and Paint_Vertical_Text. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5509 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 5510 | Paint_Text_Encoding must be set to SkPaint::kGlyphID_TextEncoding. |
| 5511 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5512 | Elements of paint: Path_Effect, Mask_Filter, Shader, Color_Filter, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5513 | Image_Filter, and Draw_Looper; apply to blob. |
| 5514 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5515 | #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] | 5516 | #Param x horizontal offset applied to blob ## |
| 5517 | #Param y vertical offset applied to blob ## |
| 5518 | #Param paint blend, color, stroking, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5519 | |
| 5520 | #Example |
| 5521 | #Height 120 |
| 5522 | #Description |
| 5523 | Paint attributes unrelated to text, like color, have no effect on paint in allocated Text_Blob. |
| 5524 | Paint attributes related to text, like text size, have no effect on paint passed to drawTextBlob. |
| 5525 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5526 | void draw(SkCanvas* canvas) { |
| 5527 | SkTextBlobBuilder textBlobBuilder; |
| 5528 | SkPaint paint; |
| 5529 | paint.setTextSize(50); |
| 5530 | paint.setColor(SK_ColorRED); |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 5531 | paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5532 | const SkTextBlobBuilder::RunBuffer& run = |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5533 | textBlobBuilder.allocRun(paint, 1, 20, 100); |
| 5534 | run.glyphs[0] = 20; |
| 5535 | sk_sp<const SkTextBlob> blob = textBlobBuilder.make(); |
| 5536 | paint.setTextSize(10); |
| 5537 | paint.setColor(SK_ColorBLUE); |
| 5538 | canvas->drawTextBlob(blob.get(), 0, 0, paint); |
| 5539 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5540 | ## |
| 5541 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5542 | #SeeAlso drawText drawPosText drawPosTextH |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5543 | |
| 5544 | ## |
| 5545 | |
| 5546 | # ------------------------------------------------------------------------------ |
| 5547 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5548 | #Method void drawPicture(const SkPicture* picture) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5549 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5550 | #Line # draws Picture using Clip and Matrix ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5551 | Draws Picture picture, using Clip and Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5552 | Clip and Matrix are unchanged by picture contents, as if |
| 5553 | save() was called before and restore() was called after drawPicture. |
| 5554 | |
| 5555 | Picture records a series of draw commands for later playback. |
| 5556 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5557 | #Param picture recorded drawing commands to play ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5558 | |
| 5559 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5560 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5561 | SkPictureRecorder recorder; |
| 5562 | SkCanvas* recordingCanvas = recorder.beginRecording(50, 50); |
| 5563 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) { |
| 5564 | SkPaint paint; |
| 5565 | paint.setColor(color); |
| 5566 | recordingCanvas->drawRect({10, 10, 30, 40}, paint); |
| 5567 | recordingCanvas->translate(10, 10); |
| 5568 | recordingCanvas->scale(1.2f, 1.4f); |
| 5569 | } |
| 5570 | sk_sp<SkPicture> playback = recorder.finishRecordingAsPicture(); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5571 | canvas->drawPicture(playback); |
| 5572 | canvas->scale(2, 2); |
| 5573 | canvas->translate(50, 0); |
| 5574 | canvas->drawPicture(playback); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5575 | } |
| 5576 | ## |
| 5577 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5578 | #SeeAlso drawDrawable SkPicture SkPicture::playback |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5579 | |
| 5580 | ## |
| 5581 | |
| 5582 | # ------------------------------------------------------------------------------ |
| 5583 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5584 | #Method void drawPicture(const sk_sp<SkPicture>& picture) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5585 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5586 | Draws Picture picture, using Clip and Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5587 | Clip and Matrix are unchanged by picture contents, as if |
| 5588 | save() was called before and restore() was called after drawPicture. |
| 5589 | |
| 5590 | Picture records a series of draw commands for later playback. |
| 5591 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5592 | #Param picture recorded drawing commands to play ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5593 | |
| 5594 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5595 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5596 | SkPictureRecorder recorder; |
| 5597 | SkCanvas* recordingCanvas = recorder.beginRecording(50, 50); |
| 5598 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) { |
| 5599 | SkPaint paint; |
| 5600 | paint.setColor(color); |
| 5601 | recordingCanvas->drawRect({10, 10, 30, 40}, paint); |
| 5602 | recordingCanvas->translate(10, 10); |
| 5603 | recordingCanvas->scale(1.2f, 1.4f); |
| 5604 | } |
| 5605 | sk_sp<SkPicture> playback = recorder.finishRecordingAsPicture(); |
| 5606 | canvas->drawPicture(playback); |
| 5607 | canvas->scale(2, 2); |
| 5608 | canvas->translate(50, 0); |
| 5609 | canvas->drawPicture(playback); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5610 | } |
| 5611 | ## |
| 5612 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5613 | #SeeAlso drawDrawable SkPicture SkPicture::playback |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5614 | |
| 5615 | ## |
| 5616 | |
| 5617 | # ------------------------------------------------------------------------------ |
| 5618 | |
| 5619 | #Method void drawPicture(const SkPicture* picture, const SkMatrix* matrix, const SkPaint* paint) |
| 5620 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5621 | Draws Picture picture, using Clip and Matrix; transforming picture with |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5622 | Matrix matrix, if provided; and use Paint paint Color_Alpha, Color_Filter, |
| 5623 | Image_Filter, and Blend_Mode, if provided. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5624 | |
| 5625 | matrix transformation is equivalent to: save(), concat(), drawPicture, restore(). |
| 5626 | paint use is equivalent to: saveLayer, drawPicture, restore(). |
| 5627 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5628 | #Param picture recorded drawing commands to play ## |
| 5629 | #Param matrix Matrix to rotate, scale, translate, and so on; may be nullptr ## |
| 5630 | #Param paint Paint to apply transparency, filtering, and so on; may be nullptr ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5631 | |
| 5632 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5633 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5634 | SkPaint paint; |
| 5635 | SkPictureRecorder recorder; |
| 5636 | SkCanvas* recordingCanvas = recorder.beginRecording(50, 50); |
| 5637 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) { |
| 5638 | paint.setColor(color); |
| 5639 | recordingCanvas->drawRect({10, 10, 30, 40}, paint); |
| 5640 | recordingCanvas->translate(10, 10); |
| 5641 | recordingCanvas->scale(1.2f, 1.4f); |
| 5642 | } |
| 5643 | sk_sp<SkPicture> playback = recorder.finishRecordingAsPicture(); |
| 5644 | const SkPicture* playbackPtr = playback.get(); |
| 5645 | SkMatrix matrix; |
| 5646 | matrix.reset(); |
| 5647 | for (auto alpha : { 70, 140, 210 } ) { |
| 5648 | paint.setAlpha(alpha); |
| 5649 | canvas->drawPicture(playbackPtr, &matrix, &paint); |
| 5650 | matrix.preTranslate(70, 70); |
| 5651 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5652 | } |
| 5653 | ## |
| 5654 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5655 | #SeeAlso drawDrawable SkPicture SkPicture::playback |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5656 | |
| 5657 | ## |
| 5658 | |
| 5659 | # ------------------------------------------------------------------------------ |
| 5660 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5661 | #Method void drawPicture(const sk_sp<SkPicture>& picture, const SkMatrix* matrix, const SkPaint* paint) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5662 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5663 | Draws Picture picture, using Clip and Matrix; transforming picture with |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5664 | Matrix matrix, if provided; and use Paint paint Color_Alpha, Color_Filter, |
| 5665 | Image_Filter, and Blend_Mode, if provided. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5666 | |
| 5667 | matrix transformation is equivalent to: save(), concat(), drawPicture, restore(). |
| 5668 | paint use is equivalent to: saveLayer, drawPicture, restore(). |
| 5669 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5670 | #Param picture recorded drawing commands to play ## |
| 5671 | #Param matrix Matrix to rotate, scale, translate, and so on; may be nullptr ## |
| 5672 | #Param paint Paint to apply transparency, filtering, and so on; may be nullptr ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5673 | |
| 5674 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5675 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5676 | SkPaint paint; |
| 5677 | SkPictureRecorder recorder; |
| 5678 | SkCanvas* recordingCanvas = recorder.beginRecording(50, 50); |
| 5679 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) { |
| 5680 | paint.setColor(color); |
| 5681 | recordingCanvas->drawRect({10, 10, 30, 40}, paint); |
| 5682 | recordingCanvas->translate(10, 10); |
| 5683 | recordingCanvas->scale(1.2f, 1.4f); |
| 5684 | } |
| 5685 | sk_sp<SkPicture> playback = recorder.finishRecordingAsPicture(); |
| 5686 | SkMatrix matrix; |
| 5687 | matrix.reset(); |
| 5688 | for (auto alpha : { 70, 140, 210 } ) { |
| 5689 | paint.setAlpha(alpha); |
| 5690 | canvas->drawPicture(playback, &matrix, &paint); |
| 5691 | matrix.preTranslate(70, 70); |
| 5692 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5693 | } |
| 5694 | ## |
| 5695 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5696 | #SeeAlso drawDrawable SkPicture SkPicture::playback |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5697 | |
| 5698 | ## |
| 5699 | |
| 5700 | # ------------------------------------------------------------------------------ |
| 5701 | |
| 5702 | #Method void drawVertices(const SkVertices* vertices, SkBlendMode mode, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5703 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5704 | #Line # draws Vertices, a triangle mesh ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5705 | Draws Vertices vertices, a triangle mesh, using Clip and Matrix. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5706 | If Vertices_Texs and Vertices_Colors are defined in vertices, and Paint paint |
| 5707 | contains Shader, Blend_Mode mode combines Vertices_Colors with Shader. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5708 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5709 | #Param vertices triangle mesh to draw ## |
| 5710 | #Param mode combines Vertices_Colors with Shader, if both are present ## |
| 5711 | #Param paint specifies the Shader, used as Vertices texture; may be nullptr ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5712 | |
| 5713 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5714 | void draw(SkCanvas* canvas) { |
| 5715 | SkPaint paint; |
| 5716 | SkPoint points[] = { { 0, 0 }, { 250, 0 }, { 100, 100 }, { 0, 250 } }; |
| 5717 | SkColor colors[] = { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorCYAN }; |
| 5718 | auto vertices = SkVertices::MakeCopy(SkVertices::kTriangleFan_VertexMode, |
| 5719 | SK_ARRAY_COUNT(points), points, nullptr, colors); |
| 5720 | canvas->drawVertices(vertices.get(), SkBlendMode::kSrc, paint); |
| 5721 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5722 | ## |
| 5723 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5724 | #SeeAlso drawPatch drawPicture |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5725 | |
| 5726 | ## |
| 5727 | |
| 5728 | # ------------------------------------------------------------------------------ |
| 5729 | |
| 5730 | #Method void drawVertices(const sk_sp<SkVertices>& vertices, SkBlendMode mode, const SkPaint& paint) |
| 5731 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5732 | Draws Vertices vertices, a triangle mesh, using Clip and Matrix. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5733 | If Vertices_Texs and Vertices_Colors are defined in vertices, and Paint paint |
| 5734 | contains Shader, Blend_Mode mode combines Vertices_Colors with Shader. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5735 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5736 | #Param vertices triangle mesh to draw ## |
| 5737 | #Param mode combines Vertices_Colors with Shader, if both are present ## |
| 5738 | #Param paint specifies the Shader, used as Vertices texture, may be nullptr ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5739 | |
| 5740 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5741 | void draw(SkCanvas* canvas) { |
| 5742 | SkPaint paint; |
| 5743 | SkPoint points[] = { { 0, 0 }, { 250, 0 }, { 100, 100 }, { 0, 250 } }; |
| 5744 | SkPoint texs[] = { { 0, 0 }, { 0, 250 }, { 250, 250 }, { 250, 0 } }; |
| 5745 | SkColor colors[] = { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorCYAN }; |
| 5746 | paint.setShader(SkGradientShader::MakeLinear(points, colors, nullptr, 4, |
| 5747 | SkShader::kClamp_TileMode)); |
| 5748 | auto vertices = SkVertices::MakeCopy(SkVertices::kTriangleFan_VertexMode, |
| 5749 | SK_ARRAY_COUNT(points), points, texs, colors); |
Ruiqi Mao | 94d57c4 | 2018-07-02 15:20:10 -0400 | [diff] [blame] | 5750 | canvas->drawVertices(vertices, SkBlendMode::kDarken, paint); |
| 5751 | } |
| 5752 | ## |
| 5753 | |
| 5754 | #SeeAlso drawPatch drawPicture |
| 5755 | |
| 5756 | ## |
| 5757 | |
| 5758 | # ------------------------------------------------------------------------------ |
| 5759 | |
| 5760 | #Method void drawVertices(const SkVertices* vertices, const SkMatrix* bones, int boneCount, |
| 5761 | SkBlendMode mode, const SkPaint& paint) |
| 5762 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5763 | Draws Vertices vertices, a triangle mesh, using Clip and Matrix. Bone data is used to |
Ruiqi Mao | 94d57c4 | 2018-07-02 15:20:10 -0400 | [diff] [blame] | 5764 | deform vertices with bone weights. |
| 5765 | If Vertices_Texs and Vertices_Colors are defined in vertices, and Paint paint |
| 5766 | contains Shader, Blend_Mode mode combines Vertices_Colors with Shader. |
| 5767 | The first element of bones should be an object to world space transformation matrix that |
| 5768 | will be applied before performing mesh deformations. If no such transformation is needed, |
| 5769 | it should be the identity matrix. |
Ruiqi Mao | 9a6e42f | 2018-07-09 14:16:56 -0400 | [diff] [blame] | 5770 | boneCount must be at most 100, and thus the size of bones should be at most 100. |
Ruiqi Mao | 94d57c4 | 2018-07-02 15:20:10 -0400 | [diff] [blame] | 5771 | |
| 5772 | #Param vertices triangle mesh to draw ## |
| 5773 | #Param bones bone matrix data ## |
| 5774 | #Param boneCount number of bone matrices ## |
| 5775 | #Param mode combines Vertices_Colors with Shader, if both are present ## |
| 5776 | #Param paint specifies the Shader, used as Vertices texture, may be nullptr ## |
| 5777 | |
| 5778 | #Example |
| 5779 | void draw(SkCanvas* canvas) { |
| 5780 | SkPaint paint; |
| 5781 | SkPoint points[] = { { 0, 0 }, { 250, 0 }, { 100, 100 }, { 0, 250 } }; |
| 5782 | SkPoint texs[] = { { 0, 0 }, { 0, 250 }, { 250, 250 }, { 250, 0 } }; |
| 5783 | SkColor colors[] = { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorCYAN }; |
| 5784 | SkVertices::BoneIndices boneIndices[] = { { 0, 0, 0, 0 }, |
| 5785 | { 1, 0, 0, 0 }, |
| 5786 | { 2, 0, 0, 0 }, |
| 5787 | { 3, 0, 0, 0 } }; |
| 5788 | SkVertices::BoneWeights boneWeights[] = { { 0.0f, 0.0f, 0.0f, 0.0f }, |
| 5789 | { 1.0f, 0.0f, 0.0f, 0.0f }, |
| 5790 | { 1.0f, 0.0f, 0.0f, 0.0f }, |
| 5791 | { 1.0f, 0.0f, 0.0f, 0.0f } }; |
| 5792 | SkMatrix bones[] = { SkMatrix::I(), |
| 5793 | SkMatrix::MakeTrans(0, 20), |
| 5794 | SkMatrix::MakeTrans(50, 50), |
| 5795 | SkMatrix::MakeTrans(20, 0) }; |
| 5796 | paint.setShader(SkGradientShader::MakeLinear(points, colors, nullptr, 4, |
| 5797 | SkShader::kClamp_TileMode)); |
| 5798 | auto vertices = SkVertices::MakeCopy(SkVertices::kTriangleFan_VertexMode, |
| 5799 | SK_ARRAY_COUNT(points), points, texs, colors, boneIndices, boneWeights); |
| 5800 | canvas->drawVertices(vertices.get(), bones, SK_ARRAY_COUNT(bones), SkBlendMode::kDarken, paint); |
| 5801 | } |
| 5802 | ## |
| 5803 | |
| 5804 | #SeeAlso drawPatch drawPicture |
| 5805 | |
| 5806 | ## |
| 5807 | |
| 5808 | # ------------------------------------------------------------------------------ |
| 5809 | |
| 5810 | #Method void drawVertices(const sk_sp<SkVertices>& vertices, const SkMatrix* bones, int boneCount, |
| 5811 | SkBlendMode mode, const SkPaint& paint) |
| 5812 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5813 | Draws Vertices vertices, a triangle mesh, using Clip and Matrix. Bone data is used to |
Ruiqi Mao | 94d57c4 | 2018-07-02 15:20:10 -0400 | [diff] [blame] | 5814 | deform vertices with bone weights. |
| 5815 | If Vertices_Texs and Vertices_Colors are defined in vertices, and Paint paint |
| 5816 | contains Shader, Blend_Mode mode combines Vertices_Colors with Shader. |
| 5817 | The first element of bones should be an object to world space transformation matrix that |
| 5818 | will be applied before performing mesh deformations. If no such transformation is needed, |
| 5819 | it should be the identity matrix. |
Ruiqi Mao | 9a6e42f | 2018-07-09 14:16:56 -0400 | [diff] [blame] | 5820 | boneCount must be at most 100, and thus the size of bones should be at most 100. |
Ruiqi Mao | 94d57c4 | 2018-07-02 15:20:10 -0400 | [diff] [blame] | 5821 | |
| 5822 | #Param vertices triangle mesh to draw ## |
| 5823 | #Param bones bone matrix data ## |
| 5824 | #Param boneCount number of bone matrices ## |
| 5825 | #Param mode combines Vertices_Colors with Shader, if both are present ## |
| 5826 | #Param paint specifies the Shader, used as Vertices texture, may be nullptr ## |
| 5827 | |
| 5828 | #Example |
| 5829 | void draw(SkCanvas* canvas) { |
| 5830 | SkPaint paint; |
| 5831 | SkPoint points[] = { { 0, 0 }, { 250, 0 }, { 100, 100 }, { 0, 250 } }; |
| 5832 | SkPoint texs[] = { { 0, 0 }, { 0, 250 }, { 250, 250 }, { 250, 0 } }; |
| 5833 | SkColor colors[] = { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorCYAN }; |
| 5834 | SkVertices::BoneIndices boneIndices[] = { { 0, 0, 0, 0 }, |
| 5835 | { 1, 0, 0, 0 }, |
| 5836 | { 2, 0, 0, 0 }, |
| 5837 | { 3, 0, 0, 0 } }; |
| 5838 | SkVertices::BoneWeights boneWeights[] = { { 0.0f, 0.0f, 0.0f, 0.0f }, |
| 5839 | { 1.0f, 0.0f, 0.0f, 0.0f }, |
| 5840 | { 1.0f, 0.0f, 0.0f, 0.0f }, |
| 5841 | { 1.0f, 0.0f, 0.0f, 0.0f } }; |
| 5842 | SkMatrix bones[] = { SkMatrix::I(), |
| 5843 | SkMatrix::MakeTrans(0, 20), |
| 5844 | SkMatrix::MakeTrans(50, 50), |
| 5845 | SkMatrix::MakeTrans(20, 0) }; |
| 5846 | paint.setShader(SkGradientShader::MakeLinear(points, colors, nullptr, 4, |
| 5847 | SkShader::kClamp_TileMode)); |
| 5848 | auto vertices = SkVertices::MakeCopy(SkVertices::kTriangleFan_VertexMode, |
| 5849 | SK_ARRAY_COUNT(points), points, texs, colors, boneIndices, boneWeights); |
| 5850 | canvas->drawVertices(vertices, bones, SK_ARRAY_COUNT(bones), SkBlendMode::kDarken, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5851 | } |
| 5852 | ## |
| 5853 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5854 | #SeeAlso drawPatch drawPicture |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5855 | |
| 5856 | ## |
| 5857 | |
| 5858 | # ------------------------------------------------------------------------------ |
| 5859 | |
| 5860 | #Method void drawPatch(const SkPoint cubics[12], const SkColor colors[4], |
| 5861 | const SkPoint texCoords[4], SkBlendMode mode, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5862 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5863 | #Line # draws Coons_Patch ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5864 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5865 | Draws a Coons_Patch: the interpolation of four cubics with shared corners, |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 5866 | associating a color, and optionally a texture Point, with each corner. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5867 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 5868 | Coons_Patch uses Clip and Matrix, paint Shader, Color_Filter, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5869 | Color_Alpha, Image_Filter, and Blend_Mode. If Shader is provided it is treated |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 5870 | as Coons_Patch texture; Blend_Mode mode combines Color colors and Shader if |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5871 | both are provided. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5872 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5873 | Point array cubics specifies four Cubics starting at the top-left corner, |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5874 | in clockwise order, sharing every fourth point. The last Cubic ends at the |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5875 | first point. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5876 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5877 | Color array color associates colors with corners in top-left, top-right, |
| 5878 | bottom-right, bottom-left order. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5879 | |
| 5880 | If paint contains Shader, Point array texCoords maps Shader as texture to |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5881 | corners in top-left, top-right, bottom-right, bottom-left order. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5882 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 5883 | #Param cubics Path_Cubic array, sharing common points ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5884 | #Param colors Color array, one for each corner ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5885 | #Param texCoords Point array of texture coordinates, mapping Shader to corners; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5886 | may be nullptr |
Cary Clark | 579985c | 2017-07-31 11:48:27 -0400 | [diff] [blame] | 5887 | #Param ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5888 | #Param mode Blend_Mode for colors, and for Shader if paint has one ## |
| 5889 | #Param paint Shader, Color_Filter, Blend_Mode, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5890 | |
| 5891 | #Example |
| 5892 | #Image 5 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5893 | void draw(SkCanvas* canvas) { |
| 5894 | // SkBitmap source = cmbkygk; |
| 5895 | SkPaint paint; |
| 5896 | paint.setFilterQuality(kLow_SkFilterQuality); |
| 5897 | paint.setAntiAlias(true); |
| 5898 | SkPoint cubics[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, |
| 5899 | /* { 7, 3 }, */ { 6, 4 }, { 7, 5 }, { 5, 7 }, |
| 5900 | /* { 5, 7 }, */ { 4, 6 }, { 3, 7 }, { 1, 5 }, |
| 5901 | /* { 1, 5 }, */ { 2, 4 }, { 1, 3 }, /* { 3, 1 } */ }; |
| 5902 | SkColor colors[] = { 0xbfff0000, 0xbf0000ff, 0xbfff00ff, 0xbf00ffff }; |
| 5903 | SkPoint texCoords[] = { { -30, -30 }, { 162, -30}, { 162, 162}, { -30, 162} }; |
| 5904 | paint.setShader(SkShader::MakeBitmapShader(source, SkShader::kClamp_TileMode, |
| 5905 | SkShader::kClamp_TileMode, nullptr)); |
| 5906 | canvas->scale(15, 15); |
| 5907 | for (auto blend : { SkBlendMode::kSrcOver, SkBlendMode::kModulate, SkBlendMode::kXor } ) { |
| 5908 | canvas->drawPatch(cubics, colors, texCoords, blend, paint); |
| 5909 | canvas->translate(4, 4); |
| 5910 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5911 | } |
| 5912 | ## |
| 5913 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5914 | #ToDo can patch use image filter? ## |
| 5915 | #SeeAlso SeeAlso drawVertices drawPicture |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5916 | |
| 5917 | ## |
| 5918 | |
| 5919 | # ------------------------------------------------------------------------------ |
| 5920 | |
| 5921 | #Method void drawPatch(const SkPoint cubics[12], const SkColor colors[4], |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5922 | const SkPoint texCoords[4], const SkPaint& paint) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5923 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5924 | Draws Cubic Coons_Patch: the interpolation of four cubics with shared corners, |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 5925 | associating a color, and optionally a texture Point, with each corner. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5926 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 5927 | Coons_Patch uses Clip and Matrix, paint Shader, Color_Filter, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5928 | Color_Alpha, Image_Filter, and Blend_Mode. If Shader is provided it is treated |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 5929 | as Coons_Patch texture; Blend_Mode mode combines Color colors and Shader if |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5930 | both are provided. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5931 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5932 | Point array cubics specifies four Cubics starting at the top-left corner, |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5933 | in clockwise order, sharing every fourth point. The last Cubic ends at the |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5934 | first point. |
| 5935 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5936 | Color array color associates colors with corners in top-left, top-right, |
| 5937 | bottom-right, bottom-left order. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5938 | |
| 5939 | If paint contains Shader, Point array texCoords maps Shader as texture to |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5940 | corners in top-left, top-right, bottom-right, bottom-left order. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5941 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 5942 | #Param cubics Path_Cubic array, sharing common points ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5943 | #Param colors Color array, one for each corner ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5944 | #Param texCoords Point array of texture coordinates, mapping Shader to corners; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5945 | may be nullptr |
Cary Clark | 579985c | 2017-07-31 11:48:27 -0400 | [diff] [blame] | 5946 | #Param ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5947 | #Param paint Shader, Color_Filter, Blend_Mode, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5948 | |
| 5949 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5950 | void draw(SkCanvas* canvas) { |
| 5951 | SkPaint paint; |
| 5952 | paint.setAntiAlias(true); |
| 5953 | SkPoint cubics[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, |
| 5954 | /* { 7, 3 }, */ { 6, 4 }, { 7, 5 }, { 5, 7 }, |
| 5955 | /* { 5, 7 }, */ { 4, 6 }, { 3, 7 }, { 1, 5 }, |
| 5956 | /* { 1, 5 }, */ { 2, 4 }, { 1, 3 }, /* { 3, 1 } */ }; |
| 5957 | SkColor colors[] = { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorCYAN }; |
| 5958 | canvas->scale(30, 30); |
| 5959 | canvas->drawPatch(cubics, colors, nullptr, paint); |
| 5960 | SkPoint text[] = { {3,0.9f}, {4,2.5f}, {5,0.9f}, {7.5f,3.2f}, {5.5f,4.2f}, |
| 5961 | {7.5f,5.2f}, {5,7.5f}, {4,5.9f}, {3,7.5f}, {0.5f,5.2f}, {2.5f,4.2f}, |
| 5962 | {0.5f,3.2f} }; |
| 5963 | paint.setTextSize(18.f / 30); |
| 5964 | paint.setTextAlign(SkPaint::kCenter_Align); |
| 5965 | for (int i = 0; i< 10; ++i) { |
| 5966 | char digit = '0' + i; |
| 5967 | canvas->drawText(&digit, 1, text[i].fX, text[i].fY, paint); |
| 5968 | } |
| 5969 | canvas->drawString("10", text[10].fX, text[10].fY, paint); |
| 5970 | canvas->drawString("11", text[11].fX, text[11].fY, paint); |
| 5971 | paint.setStyle(SkPaint::kStroke_Style); |
| 5972 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, 12, cubics, paint); |
| 5973 | 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] | 5974 | } |
| 5975 | ## |
| 5976 | |
| 5977 | #Example |
| 5978 | #Image 6 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5979 | void draw(SkCanvas* canvas) { |
| 5980 | // SkBitmap source = checkerboard; |
| 5981 | SkPaint paint; |
| 5982 | paint.setFilterQuality(kLow_SkFilterQuality); |
| 5983 | paint.setAntiAlias(true); |
| 5984 | SkPoint cubics[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, |
| 5985 | /* { 7, 3 }, */ { 6, 4 }, { 7, 5 }, { 5, 7 }, |
| 5986 | /* { 5, 7 }, */ { 4, 6 }, { 3, 7 }, { 1, 5 }, |
| 5987 | /* { 1, 5 }, */ { 2, 4 }, { 1, 3 }, /* { 3, 1 } */ }; |
| 5988 | SkPoint texCoords[] = { { 0, 0 }, { 0, 62}, { 62, 62}, { 62, 0 } }; |
| 5989 | paint.setShader(SkShader::MakeBitmapShader(source, SkShader::kClamp_TileMode, |
| 5990 | SkShader::kClamp_TileMode, nullptr)); |
| 5991 | canvas->scale(30, 30); |
| 5992 | canvas->drawPatch(cubics, nullptr, texCoords, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5993 | } |
| 5994 | ## |
| 5995 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5996 | #ToDo can patch use image filter? ## |
| 5997 | #SeeAlso SeeAlso drawVertices drawPicture |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5998 | |
| 5999 | ## |
| 6000 | |
| 6001 | # ------------------------------------------------------------------------------ |
| 6002 | |
| 6003 | #Method void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], |
| 6004 | const SkColor colors[], int count, SkBlendMode mode, const SkRect* cullRect, |
| 6005 | const SkPaint* paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 6006 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 6007 | #Line # draws sprites using Clip, Matrix, and Paint ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6008 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 6009 | Draws a set of sprites from atlas, using Clip, Matrix, and optional Paint paint. |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 6010 | paint uses Anti_Alias, Color_Alpha, Color_Filter, Image_Filter, and Blend_Mode |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6011 | to draw, if present. For each entry in the array, Rect tex locates sprite in |
| 6012 | atlas, and RSXform xform transforms it into destination space. |
| 6013 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6014 | xform, text, and colors if present, must contain count entries. |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 6015 | Optional colors are applied for each sprite using Blend_Mode mode, treating |
| 6016 | sprite as source and colors as destination. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 6017 | Optional cullRect is a conservative bounds of all transformed sprites. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 6018 | If cullRect is outside of Clip, canvas can skip drawing. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6019 | |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 6020 | |
| 6021 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6022 | #Param atlas Image containing sprites ## |
| 6023 | #Param xform RSXform mappings for sprites in atlas ## |
| 6024 | #Param tex Rect locations of sprites in atlas ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 6025 | #Param colors one per sprite, blended with sprite using Blend_Mode; may be nullptr ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6026 | #Param count number of sprites to draw ## |
| 6027 | #Param mode Blend_Mode combining colors and sprites ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 6028 | #Param cullRect bounds of transformed sprites for efficient clipping; may be nullptr ## |
| 6029 | #Param paint Color_Filter, Image_Filter, Blend_Mode, and so on; may be nullptr ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6030 | |
| 6031 | #Example |
| 6032 | #Image 3 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6033 | void draw(SkCanvas* canvas) { |
| 6034 | // SkBitmap source = mandrill; |
| 6035 | SkRSXform xforms[] = { { .5f, 0, 0, 0 }, {0, .5f, 200, 100 } }; |
| 6036 | SkRect tex[] = { { 0, 0, 250, 250 }, { 0, 0, 250, 250 } }; |
| 6037 | SkColor colors[] = { 0x7f55aa00, 0x7f3333bf }; |
| 6038 | const SkImage* imagePtr = image.get(); |
| 6039 | canvas->drawAtlas(imagePtr, xforms, tex, colors, 2, SkBlendMode::kSrcOver, nullptr, nullptr); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6040 | } |
| 6041 | ## |
| 6042 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 6043 | #SeeAlso drawBitmap drawImage |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6044 | |
| 6045 | ## |
| 6046 | |
| 6047 | # ------------------------------------------------------------------------------ |
| 6048 | |
| 6049 | #Method void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[], |
| 6050 | const SkColor colors[], int count, SkBlendMode mode, const SkRect* cullRect, |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 6051 | const SkPaint* paint) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6052 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 6053 | Draws a set of sprites from atlas, using Clip, Matrix, and optional Paint paint. |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 6054 | paint uses Anti_Alias, Color_Alpha, Color_Filter, Image_Filter, and Blend_Mode |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6055 | to draw, if present. For each entry in the array, Rect tex locates sprite in |
| 6056 | atlas, and RSXform xform transforms it into destination space. |
| 6057 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6058 | xform, text, and colors if present, must contain count entries. |
| 6059 | Optional colors is applied for each sprite using Blend_Mode. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 6060 | Optional cullRect is a conservative bounds of all transformed sprites. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 6061 | If cullRect is outside of Clip, canvas can skip drawing. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6062 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6063 | #Param atlas Image containing sprites ## |
| 6064 | #Param xform RSXform mappings for sprites in atlas ## |
| 6065 | #Param tex Rect locations of sprites in atlas ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 6066 | #Param colors one per sprite, blended with sprite using Blend_Mode; may be nullptr ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6067 | #Param count number of sprites to draw ## |
| 6068 | #Param mode Blend_Mode combining colors and sprites ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 6069 | #Param cullRect bounds of transformed sprites for efficient clipping; may be nullptr ## |
| 6070 | #Param paint Color_Filter, Image_Filter, Blend_Mode, and so on; may be nullptr ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6071 | |
| 6072 | #Example |
| 6073 | #Image 3 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6074 | void draw(SkCanvas* canvas) { |
| 6075 | // SkBitmap source = mandrill; |
| 6076 | SkRSXform xforms[] = { { .5f, 0, 0, 0 }, {0, .5f, 200, 100 } }; |
| 6077 | SkRect tex[] = { { 0, 0, 250, 250 }, { 0, 0, 250, 250 } }; |
| 6078 | SkColor colors[] = { 0x7f55aa00, 0x7f3333bf }; |
| 6079 | SkPaint paint; |
| 6080 | paint.setAlpha(127); |
| 6081 | canvas->drawAtlas(image, xforms, tex, colors, 2, SkBlendMode::kPlus, nullptr, &paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6082 | } |
| 6083 | ## |
| 6084 | |
| 6085 | #ToDo bug in example on cpu side, gpu looks ok ## |
| 6086 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 6087 | #SeeAlso drawBitmap drawImage |
| 6088 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6089 | ## |
| 6090 | |
| 6091 | # ------------------------------------------------------------------------------ |
| 6092 | |
| 6093 | #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] | 6094 | const SkRect* cullRect, const SkPaint* paint) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6095 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 6096 | Draws a set of sprites from atlas, using Clip, Matrix, and optional Paint paint. |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 6097 | paint uses Anti_Alias, Color_Alpha, Color_Filter, Image_Filter, and Blend_Mode |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6098 | to draw, if present. For each entry in the array, Rect tex locates sprite in |
| 6099 | atlas, and RSXform xform transforms it into destination space. |
| 6100 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6101 | xform and text must contain count entries. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 6102 | Optional cullRect is a conservative bounds of all transformed sprites. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 6103 | If cullRect is outside of Clip, canvas can skip drawing. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6104 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6105 | #Param atlas Image containing sprites ## |
| 6106 | #Param xform RSXform mappings for sprites in atlas ## |
| 6107 | #Param tex Rect locations of sprites in atlas ## |
| 6108 | #Param count number of sprites to draw ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 6109 | #Param cullRect bounds of transformed sprites for efficient clipping; may be nullptr ## |
| 6110 | #Param paint Color_Filter, Image_Filter, Blend_Mode, and so on; may be nullptr ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6111 | |
| 6112 | #Example |
| 6113 | #Image 3 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6114 | void draw(SkCanvas* canvas) { |
| 6115 | // sk_sp<SkImage> image = mandrill; |
| 6116 | SkRSXform xforms[] = { { .5f, 0, 0, 0 }, {0, .5f, 200, 100 } }; |
| 6117 | SkRect tex[] = { { 0, 0, 250, 250 }, { 0, 0, 250, 250 } }; |
| 6118 | const SkImage* imagePtr = image.get(); |
| 6119 | canvas->drawAtlas(imagePtr, xforms, tex, 2, nullptr, nullptr); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6120 | } |
| 6121 | ## |
| 6122 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 6123 | #SeeAlso drawBitmap drawImage |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6124 | |
| 6125 | ## |
| 6126 | |
| 6127 | # ------------------------------------------------------------------------------ |
| 6128 | |
| 6129 | #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] | 6130 | int count, const SkRect* cullRect, const SkPaint* paint) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6131 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 6132 | Draws a set of sprites from atlas, using Clip, Matrix, and optional Paint paint. |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 6133 | paint uses Anti_Alias, Color_Alpha, Color_Filter, Image_Filter, and Blend_Mode |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6134 | to draw, if present. For each entry in the array, Rect tex locates sprite in |
| 6135 | atlas, and RSXform xform transforms it into destination space. |
| 6136 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6137 | xform and text must contain count entries. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 6138 | Optional cullRect is a conservative bounds of all transformed sprites. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 6139 | If cullRect is outside of Clip, canvas can skip drawing. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6140 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6141 | #Param atlas Image containing sprites ## |
| 6142 | #Param xform RSXform mappings for sprites in atlas ## |
| 6143 | #Param tex Rect locations of sprites in atlas ## |
| 6144 | #Param count number of sprites to draw ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 6145 | #Param cullRect bounds of transformed sprites for efficient clipping; may be nullptr ## |
| 6146 | #Param paint Color_Filter, Image_Filter, Blend_Mode, and so on; may be nullptr ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6147 | |
| 6148 | #Example |
| 6149 | #Image 3 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6150 | void draw(SkCanvas* canvas) { |
| 6151 | // sk_sp<SkImage> image = mandrill; |
| 6152 | SkRSXform xforms[] = { { 1, 0, 0, 0 }, {0, 1, 300, 100 } }; |
| 6153 | SkRect tex[] = { { 0, 0, 200, 200 }, { 200, 0, 400, 200 } }; |
| 6154 | canvas->drawAtlas(image, xforms, tex, 2, nullptr, nullptr); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6155 | } |
| 6156 | ## |
| 6157 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 6158 | #SeeAlso drawBitmap drawImage |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6159 | |
| 6160 | ## |
| 6161 | |
| 6162 | # ------------------------------------------------------------------------------ |
| 6163 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 6164 | #Method void drawDrawable(SkDrawable* drawable, const SkMatrix* matrix = nullptr) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 6165 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 6166 | #Line # draws Drawable, encapsulated drawing commands ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 6167 | Draws Drawable drawable using Clip and Matrix, concatenated with |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6168 | optional matrix. |
| 6169 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 6170 | If Canvas has an asynchronous implementation, as is the case |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6171 | when it is recording into Picture, then drawable will be referenced, |
| 6172 | so that SkDrawable::draw() can be called when the operation is finalized. To force |
| 6173 | immediate drawing, call SkDrawable::draw() instead. |
| 6174 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6175 | #Param drawable custom struct encapsulating drawing commands ## |
| 6176 | #Param matrix transformation applied to drawing; may be nullptr ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6177 | |
| 6178 | #Example |
| 6179 | #Height 100 |
| 6180 | #Function |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6181 | struct MyDrawable : public SkDrawable { |
| 6182 | SkRect onGetBounds() override { return SkRect::MakeWH(50, 100); } |
| 6183 | |
| 6184 | void onDraw(SkCanvas* canvas) override { |
| 6185 | SkPath path; |
| 6186 | path.conicTo(10, 90, 50, 90, 0.9f); |
| 6187 | SkPaint paint; |
| 6188 | paint.setColor(SK_ColorBLUE); |
| 6189 | canvas->drawRect(path.getBounds(), paint); |
| 6190 | paint.setAntiAlias(true); |
| 6191 | paint.setColor(SK_ColorWHITE); |
| 6192 | canvas->drawPath(path, paint); |
| 6193 | } |
| 6194 | }; |
| 6195 | |
| 6196 | #Function ## |
| 6197 | void draw(SkCanvas* canvas) { |
| 6198 | sk_sp<SkDrawable> drawable(new MyDrawable); |
| 6199 | SkMatrix matrix; |
| 6200 | matrix.setTranslate(10, 10); |
| 6201 | canvas->drawDrawable(drawable.get(), &matrix); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6202 | } |
| 6203 | ## |
| 6204 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 6205 | #SeeAlso SkDrawable drawPicture |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6206 | |
| 6207 | ## |
| 6208 | |
| 6209 | # ------------------------------------------------------------------------------ |
| 6210 | |
| 6211 | #Method void drawDrawable(SkDrawable* drawable, SkScalar x, SkScalar y) |
| 6212 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 6213 | Draws Drawable drawable using Clip and Matrix, offset by (x, y). |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6214 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 6215 | If Canvas has an asynchronous implementation, as is the case |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6216 | when it is recording into Picture, then drawable will be referenced, |
| 6217 | so that SkDrawable::draw() can be called when the operation is finalized. To force |
| 6218 | immediate drawing, call SkDrawable::draw() instead. |
| 6219 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6220 | #Param drawable custom struct encapsulating drawing commands ## |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 6221 | #Param x offset into Canvas writable pixels on x-axis ## |
| 6222 | #Param y offset into Canvas writable pixels on y-axis ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6223 | |
| 6224 | #Example |
| 6225 | #Height 100 |
| 6226 | #Function |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6227 | struct MyDrawable : public SkDrawable { |
| 6228 | SkRect onGetBounds() override { return SkRect::MakeWH(50, 100); } |
| 6229 | |
| 6230 | void onDraw(SkCanvas* canvas) override { |
| 6231 | SkPath path; |
| 6232 | path.conicTo(10, 90, 50, 90, 0.9f); |
| 6233 | SkPaint paint; |
| 6234 | paint.setColor(SK_ColorBLUE); |
| 6235 | canvas->drawRect(path.getBounds(), paint); |
| 6236 | paint.setAntiAlias(true); |
| 6237 | paint.setColor(SK_ColorWHITE); |
| 6238 | canvas->drawPath(path, paint); |
| 6239 | } |
| 6240 | }; |
| 6241 | |
| 6242 | #Function ## |
| 6243 | void draw(SkCanvas* canvas) { |
| 6244 | sk_sp<SkDrawable> drawable(new MyDrawable); |
| 6245 | canvas->drawDrawable(drawable.get(), 10, 10); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6246 | } |
| 6247 | ## |
| 6248 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 6249 | #SeeAlso SkDrawable drawPicture |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6250 | |
| 6251 | ## |
| 6252 | |
| 6253 | # ------------------------------------------------------------------------------ |
| 6254 | |
| 6255 | #Method void drawAnnotation(const SkRect& rect, const char key[], SkData* value) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 6256 | #In Draw |
| 6257 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 6258 | #Line # associates a Rect with a key-value pair ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 6259 | Associates Rect on Canvas with an annotation; a key-value pair, where the key is |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6260 | a null-terminated utf8 string, and optional value is stored as Data. |
| 6261 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 6262 | Only some canvas implementations, such as recording to Picture, or drawing to |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6263 | Document_PDF, use annotations. |
| 6264 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6265 | #Param rect Rect extent of canvas to annotate ## |
| 6266 | #Param key string used for lookup ## |
| 6267 | #Param value data holding value stored in annotation ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6268 | |
| 6269 | #Example |
| 6270 | #Height 1 |
| 6271 | const char text[] = "Click this link!"; |
| 6272 | SkRect bounds; |
| 6273 | SkPaint paint; |
| 6274 | paint.setTextSize(40); |
| 6275 | (void)paint.measureText(text, strlen(text), &bounds); |
| 6276 | const char url[] = "https://www.google.com/"; |
| 6277 | sk_sp<SkData> urlData(SkData::MakeWithCString(url)); |
| 6278 | canvas->drawAnnotation(bounds, "url_key", urlData.get()); |
| 6279 | ## |
| 6280 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 6281 | #SeeAlso SkPicture SkDocument |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6282 | |
| 6283 | ## |
| 6284 | |
| 6285 | # ------------------------------------------------------------------------------ |
| 6286 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 6287 | #Method void drawAnnotation(const SkRect& rect, const char key[], const sk_sp<SkData>& value) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6288 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 6289 | Associates Rect on Canvas when an annotation; a key-value pair, where the key is |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6290 | a null-terminated utf8 string, and optional value is stored as Data. |
| 6291 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 6292 | Only some canvas implementations, such as recording to Picture, or drawing to |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6293 | Document_PDF, use annotations. |
| 6294 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6295 | #Param rect Rect extent of canvas to annotate ## |
| 6296 | #Param key string used for lookup ## |
| 6297 | #Param value data holding value stored in annotation ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6298 | |
| 6299 | #Example |
| 6300 | #Height 1 |
| 6301 | const char text[] = "Click this link!"; |
| 6302 | SkRect bounds; |
| 6303 | SkPaint paint; |
| 6304 | paint.setTextSize(40); |
| 6305 | (void)paint.measureText(text, strlen(text), &bounds); |
| 6306 | const char url[] = "https://www.google.com/"; |
| 6307 | sk_sp<SkData> urlData(SkData::MakeWithCString(url)); |
| 6308 | canvas->drawAnnotation(bounds, "url_key", urlData.get()); |
| 6309 | ## |
| 6310 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 6311 | #SeeAlso SkPicture SkDocument |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6312 | |
| 6313 | ## |
| 6314 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6315 | # ------------------------------------------------------------------------------ |
| 6316 | |
| 6317 | #Method virtual bool isClipEmpty() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 6318 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 6319 | #Line # returns if Clip is empty ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6320 | Returns true if Clip is empty; that is, nothing will draw. |
| 6321 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6322 | May do work when called; it should not be called |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6323 | more often than needed. However, once called, subsequent calls perform no |
| 6324 | work until Clip changes. |
| 6325 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6326 | #Return true if Clip is empty ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6327 | |
| 6328 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6329 | void draw(SkCanvas* canvas) { |
| 6330 | SkDebugf("clip is%s empty\n", canvas->isClipEmpty() ? "" : " not"); |
| 6331 | SkPath path; |
| 6332 | canvas->clipPath(path); |
| 6333 | SkDebugf("clip is%s empty\n", canvas->isClipEmpty() ? "" : " not"); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6334 | } |
| 6335 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6336 | clip is not empty |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6337 | clip is empty |
| 6338 | ## |
| 6339 | ## |
| 6340 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 6341 | #SeeAlso isClipRect getLocalClipBounds getDeviceClipBounds |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6342 | |
| 6343 | ## |
| 6344 | |
| 6345 | # ------------------------------------------------------------------------------ |
| 6346 | |
| 6347 | #Method virtual bool isClipRect() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 6348 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 6349 | #Line # returns if Clip is Rect and not empty ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6350 | Returns true if Clip is Rect and not empty. |
| 6351 | Returns false if the clip is empty, or if it is not Rect. |
| 6352 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6353 | #Return true if Clip is Rect and not empty ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6354 | |
| 6355 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6356 | void draw(SkCanvas* canvas) { |
| 6357 | SkDebugf("clip is%s rect\n", canvas->isClipRect() ? "" : " not"); |
| 6358 | canvas->clipRect({0, 0, 0, 0}); |
| 6359 | SkDebugf("clip is%s rect\n", canvas->isClipRect() ? "" : " not"); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6360 | } |
| 6361 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6362 | clip is rect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6363 | clip is not rect |
| 6364 | ## |
| 6365 | ## |
| 6366 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 6367 | #SeeAlso isClipEmpty getLocalClipBounds getDeviceClipBounds |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6368 | |
| 6369 | ## |
| 6370 | |
| 6371 | #Class SkCanvas ## |
Cary Clark | 884dd7d | 2017-10-11 10:37:52 -0400 | [diff] [blame] | 6372 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6373 | #Topic Canvas ## |