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 | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 310 | Construct 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 | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 390 | 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 | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 405 | Construct a canvas that draws into bitmap. |
| 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 | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 565 | If Canvas is associated with Raster_Surface or |
| 566 | GPU_Surface, copies Surface_Properties and returns true. Otherwise, |
| 567 | return false and leave props unchanged. |
| 568 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 569 | #Param props storage for writable SkSurfaceProps ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 570 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 571 | #Return true if Surface_Properties was copied ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 572 | |
| 573 | #ToDo This seems old style. Deprecate? ## |
| 574 | |
| 575 | #Example |
| 576 | SkBitmap bitmap; |
| 577 | SkCanvas canvas(bitmap, SkSurfaceProps(0, kRGB_V_SkPixelGeometry)); |
| 578 | SkSurfaceProps surfaceProps(0, kUnknown_SkPixelGeometry); |
| 579 | SkDebugf("isRGB:%d\n", SkPixelGeometryIsRGB(surfaceProps.pixelGeometry())); |
| 580 | if (!canvas.getProps(&surfaceProps)) { |
| 581 | SkDebugf("getProps failed unexpectedly.\n"); |
| 582 | } |
| 583 | SkDebugf("isRGB:%d\n", SkPixelGeometryIsRGB(surfaceProps.pixelGeometry())); |
| 584 | |
| 585 | #StdOut |
| 586 | isRGB:0 |
| 587 | isRGB:1 |
| 588 | #StdOut ## |
| 589 | ## |
| 590 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 591 | #SeeAlso SkSurfaceProps makeSurface |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 592 | |
| 593 | ## |
| 594 | |
| 595 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 596 | #Subtopic Utility |
| 597 | #Populate |
| 598 | #Line # rarely called management functions ## |
| 599 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 600 | |
| 601 | #Method void flush() |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 602 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 603 | #Line # triggers execution of all pending draw operations ## |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 604 | Triggers the immediate execution of all pending draw operations. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 605 | If Canvas is associated with GPU_Surface, resolves all pending GPU operations. |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 606 | If Canvas is associated with Raster_Surface, has no effect; raster draw |
| 607 | operations are never deferred. |
| 608 | |
| 609 | #ToDo |
| 610 | In an overview section on managing the GPU, include: |
| 611 | - flush should never change what is drawn |
| 612 | - call to kick off gpu work |
| 613 | - calling too much impacts performance |
| 614 | - some calls (peekPixels, prepareForExternalIO) call it internally |
| 615 | - canvas call is local, GrContext::flush is global |
| 616 | - diffentiate between flush, flushAndSignalSemaphores |
| 617 | - normally never needs to be called |
| 618 | - call it when sharing gpu resources, feeling memory pressure, swapping out app, and before |
| 619 | abandoning context |
| 620 | - also call to say "I'm finished drawing here", e.g., when drawing to a GPU-backed offscreen surface |
| 621 | (created with SkSurface::MakeRenderTarget) |
| 622 | |
| 623 | for posterity: this doesn't show a difference: fiddle.skia.org/c/@flushfail |
| 624 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 625 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 626 | #ToDo haven't thought of a useful example to put here ## |
| 627 | #NoExample |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 628 | ## |
| 629 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 630 | #SeeAlso peekPixels SkSurface::flush() GrContext::flush() SkSurface::prepareForExternalIO GrContext::abandonContext() |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 631 | |
| 632 | ## |
| 633 | |
| 634 | # ------------------------------------------------------------------------------ |
| 635 | |
| 636 | #Method virtual SkISize getBaseLayerSize() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 637 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 638 | #Line # returns size of base Layer in global coordinates ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 639 | Gets the size of the base or root Layer in global canvas coordinates. The |
| 640 | 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] | 641 | smaller (due to clipping or saveLayer). |
| 642 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 643 | #Return integral width and height of base Layer ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 644 | |
| 645 | #Example |
| 646 | SkBitmap bitmap; |
| 647 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(20, 30)); |
| 648 | SkCanvas canvas(bitmap, SkSurfaceProps(0, kUnknown_SkPixelGeometry)); |
| 649 | canvas.clipRect(SkRect::MakeWH(10, 40)); |
| 650 | SkIRect clipDeviceBounds = canvas.getDeviceClipBounds(); |
| 651 | if (clipDeviceBounds.isEmpty()) { |
| 652 | SkDebugf("Empty clip bounds is unexpected!\n"); |
| 653 | } |
| 654 | SkDebugf("clip=%d,%d\n", clipDeviceBounds.width(), clipDeviceBounds.height()); |
| 655 | SkISize baseLayerSize = canvas.getBaseLayerSize(); |
| 656 | SkDebugf("size=%d,%d\n", baseLayerSize.width(), baseLayerSize.height()); |
| 657 | |
| 658 | #StdOut |
| 659 | clip=10,30 |
| 660 | size=20,30 |
| 661 | ## |
| 662 | ## |
| 663 | |
| 664 | #ToDo is this the same as the width and height of surface? ## |
| 665 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 666 | #SeeAlso getDeviceClipBounds |
| 667 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 668 | ## |
| 669 | |
| 670 | # ------------------------------------------------------------------------------ |
| 671 | |
| 672 | #Method sk_sp<SkSurface> makeSurface(const SkImageInfo& info, const SkSurfaceProps* props = nullptr) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 673 | #In Constructor |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 674 | #Line # creates Surface matching SkImageInfo and SkSurfaceProps ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 675 | Creates Surface matching info and props, and associates it with Canvas. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 676 | Returns nullptr if no match found. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 677 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 678 | If props is nullptr, matches Surface_Properties in Canvas. If props is nullptr and Canvas |
| 679 | does not have Surface_Properties, creates Surface with default Surface_Properties. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 680 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 681 | #Param info width, height, Color_Type, Alpha_Type, and Color_Space ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 682 | #Param props Surface_Properties to match; may be nullptr to match Canvas ## |
| 683 | |
| 684 | #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] | 685 | |
| 686 | #Example |
| 687 | sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(5, 6); |
| 688 | SkCanvas* smallCanvas = surface->getCanvas(); |
| 689 | SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(3, 4); |
| 690 | sk_sp<SkSurface> compatible = smallCanvas->makeSurface(imageInfo); |
| 691 | SkDebugf("compatible %c= nullptr\n", compatible == nullptr ? '=' : '!'); |
| 692 | SkDebugf("size = %d, %d\n", compatible->width(), compatible->height()); |
| 693 | |
| 694 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 695 | compatible != nullptr |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 696 | size = 3, 4 |
| 697 | ## |
| 698 | ## |
| 699 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 700 | #SeeAlso SkSurface SkSurface::makeSurface SkImageInfo SkSurfaceProps |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 701 | |
| 702 | ## |
| 703 | |
| 704 | # ------------------------------------------------------------------------------ |
| 705 | |
| 706 | #Method virtual GrContext* getGrContext() |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 707 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 708 | #Line # returns GPU_Context of the GPU_Surface ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 709 | Returns GPU_Context of the GPU_Surface associated with Canvas. |
| 710 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 711 | #Return GPU_Context, if available; nullptr otherwise ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 712 | |
| 713 | #Example |
| 714 | void draw(SkCanvas* canvas) { |
| 715 | if (canvas->getGrContext()) { |
| 716 | canvas->clear(SK_ColorRED); |
| 717 | } else { |
| 718 | canvas->clear(SK_ColorBLUE); |
| 719 | } |
| 720 | } |
| 721 | ## |
| 722 | |
| 723 | #ToDo fiddle should show both CPU and GPU out ## |
| 724 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 725 | #SeeAlso GrContext |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 726 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 727 | ## |
| 728 | |
| 729 | # ------------------------------------------------------------------------------ |
| 730 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 731 | #Method void* accessTopLayerPixels(SkImageInfo* info, size_t* rowBytes, SkIPoint* origin = nullptr) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 732 | #In Utility |
| 733 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 734 | #Line # returns writable pixel access if available ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 735 | 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] | 736 | can be read directly. The returned address is only valid |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 737 | while Canvas is in scope and unchanged. Any Canvas call or Surface call |
| 738 | may invalidate the returned address and other returned values. |
| 739 | |
| 740 | If pixels are inaccessible, info, rowBytes, and origin are unchanged. |
| 741 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 742 | #Param info storage for writable pixels' Image_Info; may be nullptr ## |
| 743 | #Param rowBytes storage for writable pixels' row bytes; may be nullptr ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 744 | #Param origin storage for Canvas top Layer origin, its top-left corner; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 745 | may be nullptr |
| 746 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 747 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 748 | #Return address of pixels, or nullptr if inaccessible ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 749 | |
| 750 | #Example |
| 751 | void draw(SkCanvas* canvas) { |
| 752 | if (canvas->accessTopLayerPixels(nullptr, nullptr)) { |
| 753 | canvas->clear(SK_ColorRED); |
| 754 | } else { |
| 755 | canvas->clear(SK_ColorBLUE); |
| 756 | } |
| 757 | } |
| 758 | ## |
| 759 | |
| 760 | #Example |
| 761 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 762 | Draws "ABC" on the device. Then draws "DEF" in Layer, and reads |
| 763 | Layer to add a large dotted "DEF". Finally blends Layer with the |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 764 | device. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 765 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 766 | 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] | 767 | "DEF" appear only on the CPU. |
| 768 | ## |
| 769 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 770 | SkPaint paint; |
| 771 | paint.setTextSize(100); |
| 772 | canvas->drawString("ABC", 20, 160, paint); |
| 773 | SkRect layerBounds = SkRect::MakeXYWH(32, 32, 192, 192); |
| 774 | canvas->saveLayerAlpha(&layerBounds, 128); |
| 775 | canvas->clear(SK_ColorWHITE); |
| 776 | canvas->drawString("DEF", 20, 160, paint); |
| 777 | SkImageInfo imageInfo; |
| 778 | size_t rowBytes; |
| 779 | SkIPoint origin; |
| 780 | uint32_t* access = (uint32_t*) canvas->accessTopLayerPixels(&imageInfo, &rowBytes, &origin); |
| 781 | if (access) { |
| 782 | int h = imageInfo.height(); |
| 783 | int v = imageInfo.width(); |
| 784 | int rowWords = rowBytes / sizeof(uint32_t); |
| 785 | for (int y = 0; y < h; ++y) { |
| 786 | int newY = (y - h / 2) * 2 + h / 2; |
| 787 | if (newY < 0 || newY >= h) { |
| 788 | continue; |
| 789 | } |
| 790 | for (int x = 0; x < v; ++x) { |
| 791 | int newX = (x - v / 2) * 2 + v / 2; |
| 792 | if (newX < 0 || newX >= v) { |
| 793 | continue; |
| 794 | } |
| 795 | if (access[y * rowWords + x] == SK_ColorBLACK) { |
| 796 | access[newY * rowWords + newX] = SK_ColorGRAY; |
| 797 | } |
| 798 | } |
| 799 | } |
| 800 | |
| 801 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 802 | canvas->restore(); |
| 803 | } |
| 804 | ## |
| 805 | |
| 806 | #ToDo there are no callers of this that I can find. Deprecate? ## |
| 807 | #ToDo fiddle should show both CPU and GPU out ## |
| 808 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 809 | #SeeAlso SkImageInfo SkPixmap |
| 810 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 811 | ## |
| 812 | |
| 813 | # ------------------------------------------------------------------------------ |
| 814 | |
| 815 | #Method SkRasterHandleAllocator::Handle accessTopRasterHandle() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 816 | #In Utility |
| 817 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 818 | #Line # returns context that tracks Clip and Matrix ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 819 | Returns custom context that tracks the Matrix and Clip. |
| 820 | |
| 821 | 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] | 822 | 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] | 823 | SkRasterHandleAllocator::MakeCanvas, which creates a custom canvas with raster storage for |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 824 | the drawing destination. |
| 825 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 826 | #Return context of custom allocation ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 827 | |
| 828 | #Example |
| 829 | #Description |
| 830 | #ToDo ## |
| 831 | ## |
| 832 | #Function |
| 833 | static void DeleteCallback(void*, void* context) { |
| 834 | delete (char*) context; |
| 835 | } |
| 836 | |
| 837 | class CustomAllocator : public SkRasterHandleAllocator { |
| 838 | public: |
| 839 | bool allocHandle(const SkImageInfo& info, Rec* rec) override { |
| 840 | char* context = new char[4]{'s', 'k', 'i', 'a'}; |
| 841 | rec->fReleaseProc = DeleteCallback; |
| 842 | rec->fReleaseCtx = context; |
| 843 | rec->fHandle = context; |
| 844 | rec->fPixels = context; |
| 845 | rec->fRowBytes = 4; |
| 846 | return true; |
| 847 | } |
| 848 | |
| 849 | void updateHandle(Handle handle, const SkMatrix& ctm, const SkIRect& clip_bounds) override { |
| 850 | // apply canvas matrix and clip to custom environment |
| 851 | } |
| 852 | }; |
| 853 | |
| 854 | ## |
| 855 | void draw(SkCanvas* canvas) { |
| 856 | const SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1); |
| 857 | std::unique_ptr<SkCanvas> c2 = |
| 858 | SkRasterHandleAllocator::MakeCanvas(std::unique_ptr<CustomAllocator>( |
| 859 | new CustomAllocator()), info); |
| 860 | char* context = (char*) c2->accessTopRasterHandle(); |
| 861 | SkDebugf("context = %.4s\n", context); |
| 862 | |
| 863 | } |
| 864 | #StdOut |
| 865 | context = skia |
| 866 | ## |
| 867 | #ToDo skstd::make_unique could not be used because def is private -- note to fix in c++14? ## |
| 868 | ## |
| 869 | |
| 870 | #SeeAlso SkRasterHandleAllocator |
| 871 | |
| 872 | ## |
| 873 | |
| 874 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 875 | #Subtopic Pixels |
| 876 | #Populate |
| 877 | #Line # read and write pixel values ## |
| 878 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 879 | |
| 880 | #Method bool peekPixels(SkPixmap* pixmap) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 881 | #In Pixels |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 882 | #Line # returns if Canvas has direct access to its pixels ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 883 | Returns true if Canvas has direct access to its pixels. |
| 884 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 885 | 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] | 886 | is returned from GPU_Surface, returned by SkDocument::beginPage, returned by |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 887 | SkPictureRecorder::beginRecording, or Canvas is the base of a utility class |
Brian Osman | 46fe9c7 | 2018-03-09 15:44:34 -0500 | [diff] [blame] | 888 | like SkDebugCanvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 889 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 890 | pixmap is valid only while Canvas is in scope and unchanged. Any |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 891 | Canvas or Surface call may invalidate the pixmap values. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 892 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 893 | #Param pixmap storage for pixel state if pixels are readable; otherwise, ignored ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 894 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 895 | #Return true if Canvas has direct access to pixels ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 896 | |
| 897 | #Example |
| 898 | SkPixmap pixmap; |
| 899 | if (canvas->peekPixels(&pixmap)) { |
| 900 | SkDebugf("width=%d height=%d\n", pixmap.bounds().width(), pixmap.bounds().height()); |
| 901 | } |
| 902 | #StdOut |
| 903 | width=256 height=256 |
| 904 | ## |
| 905 | ## |
| 906 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 907 | #SeeAlso readPixels SkBitmap::peekPixels SkImage::peekPixels SkSurface::peekPixels |
| 908 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 909 | ## |
| 910 | |
| 911 | # ------------------------------------------------------------------------------ |
| 912 | |
| 913 | #Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, |
| 914 | int srcX, int srcY) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 915 | #In Pixels |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 916 | #Line # copies and converts rectangle of pixels from Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 917 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 918 | Copies Rect of pixels from Canvas into dstPixels. Matrix and Clip are |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 919 | ignored. |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 920 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 921 | Source Rect corners are (srcX, srcY) and (imageInfo().width(), imageInfo().height()). |
| 922 | Destination Rect corners are (0, 0) and (dstInfo.width(), dstInfo.height()). |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 923 | Copies each readable pixel intersecting both rectangles, without scaling, |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 924 | converting to dstInfo.colorType() and dstInfo.alphaType() if required. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 925 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 926 | Pixels are readable when Device is raster, or backed by a GPU. |
| 927 | Pixels are not readable when SkCanvas is returned by SkDocument::beginPage, |
| 928 | returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility |
Brian Osman | 46fe9c7 | 2018-03-09 15:44:34 -0500 | [diff] [blame] | 929 | class like SkDebugCanvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 930 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 931 | The destination pixel storage must be allocated by the caller. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 932 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 933 | Pixel values are converted only if Color_Type and Alpha_Type |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 934 | do not match. Only pixels within both source and destination rectangles |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 935 | are copied. dstPixels contents outside Rect intersection are unchanged. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 936 | |
| 937 | 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] | 938 | |
| 939 | Does not copy, and returns false if: |
| 940 | |
| 941 | #List |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 942 | # Source and destination rectangles do not intersect. ## |
| 943 | # Canvas pixels could not be converted to dstInfo.colorType() or dstInfo.alphaType(). ## |
| 944 | # Canvas pixels are not readable; for instance, Canvas is document-based. ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 945 | # dstRowBytes is too small to contain one row of pixels. ## |
| 946 | ## |
| 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 ## |
| 951 | #Param srcX offset into readable pixels in x; may be negative ## |
| 952 | #Param srcY offset into readable pixels in y; 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 | ## |
| 1040 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1041 | #Param pixmap storage for pixels copied from Canvas ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1042 | #Param srcX offset into readable pixels in x; may be negative ## |
| 1043 | #Param srcY offset into readable pixels in y; may be negative ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1044 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1045 | #Return true if pixels were copied ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1046 | |
| 1047 | #Example |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1048 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1049 | clear() takes Unpremultiplied input with Color_Alpha equal 0x80 |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1050 | and RGB equal 0x55, 0xAA, 0xFF. RGB is multiplied by Color_Alpha |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1051 | to generate Premultiplied value 0x802B5580. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1052 | ## |
| 1053 | void draw(SkCanvas* canvas) { |
| 1054 | canvas->clear(0x8055aaff); |
| 1055 | uint32_t pixels[1] = { 0 }; |
| 1056 | SkPixmap pixmap(SkImageInfo::MakeN32Premul(1, 1), pixels, 4); |
| 1057 | canvas->readPixels(pixmap, 0, 0); |
| 1058 | SkDebugf("pixel = %08x\n", pixels[0]); |
| 1059 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1060 | #StdOut |
| 1061 | pixel = 802b5580 |
| 1062 | ## |
| 1063 | ## |
| 1064 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1065 | #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] | 1066 | |
| 1067 | ## |
| 1068 | |
| 1069 | # ------------------------------------------------------------------------------ |
| 1070 | |
| 1071 | #Method bool readPixels(const SkBitmap& bitmap, int srcX, int srcY) |
| 1072 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1073 | Copies Rect of pixels from Canvas into bitmap. Matrix and Clip are |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1074 | ignored. |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1075 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1076 | Source Rect corners are (srcX, srcY) and (imageInfo().width(), imageInfo().height()). |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1077 | Destination Rect corners are (0, 0) and (bitmap.width(), bitmap.height()). |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1078 | Copies each readable pixel intersecting both rectangles, without scaling, |
| 1079 | converting to bitmap.colorType() and bitmap.alphaType() if required. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1080 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1081 | Pixels are readable when Device is raster, or backed by a GPU. |
| 1082 | Pixels are not readable when SkCanvas is returned by SkDocument::beginPage, |
| 1083 | returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility |
Brian Osman | 46fe9c7 | 2018-03-09 15:44:34 -0500 | [diff] [blame] | 1084 | class like SkDebugCanvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1085 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1086 | Caller must allocate pixel storage in bitmap if needed. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1087 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1088 | Bitmap values are converted only if Color_Type and Alpha_Type |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1089 | do not match. Only pixels within both source and destination rectangles |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1090 | are copied. Bitmap pixels outside Rect intersection are unchanged. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1091 | |
| 1092 | 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] | 1093 | |
| 1094 | Does not copy, and returns false if: |
| 1095 | |
| 1096 | #List |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1097 | # Source and destination rectangles do not intersect. ## |
| 1098 | # Canvas pixels could not be converted to bitmap.colorType() or bitmap.alphaType(). ## |
| 1099 | # Canvas pixels are not readable; for instance, Canvas is document-based. ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1100 | # bitmap pixels could not be allocated. ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1101 | # bitmap.rowBytes() is too small to contain one row of pixels. ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1102 | ## |
| 1103 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1104 | #Param bitmap storage for pixels copied from Canvas ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1105 | #Param srcX offset into readable pixels in x; may be negative ## |
| 1106 | #Param srcY offset into readable pixels in y; may be negative ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1107 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1108 | #Return true if pixels were copied ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1109 | |
| 1110 | #Example |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1111 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1112 | clear() takes Unpremultiplied input with Color_Alpha equal 0x80 |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1113 | and RGB equal 0x55, 0xAA, 0xFF. RGB is multiplied by Color_Alpha |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1114 | to generate Premultiplied value 0x802B5580. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1115 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1116 | void draw(SkCanvas* canvas) { |
| 1117 | canvas->clear(0x8055aaff); |
| 1118 | SkBitmap bitmap; |
| 1119 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(1, 1)); |
| 1120 | canvas->readPixels(bitmap, 0, 0); |
| 1121 | SkDebugf("pixel = %08x\n", bitmap.getAddr32(0, 0)[0]); |
| 1122 | } |
| 1123 | #StdOut |
| 1124 | pixel = 802b5580 |
| 1125 | ## |
| 1126 | ## |
| 1127 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1128 | #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] | 1129 | |
| 1130 | ## |
| 1131 | |
| 1132 | # ------------------------------------------------------------------------------ |
| 1133 | |
| 1134 | #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] | 1135 | #In Pixels |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1136 | #Line # copies and converts rectangle of pixels to Canvas ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1137 | Copies Rect from pixels to Canvas. Matrix and Clip are ignored. |
| 1138 | Source Rect corners are (0, 0) and (info.width(), info.height()). |
| 1139 | Destination Rect corners are (x, y) and |
| 1140 | (imageInfo().width(), imageInfo().height()). |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1141 | |
| 1142 | Copies each readable pixel intersecting both rectangles, without scaling, |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1143 | converting to imageInfo().colorType() and imageInfo().alphaType() if required. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1144 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1145 | Pixels are writable when Device is raster, or backed by a GPU. |
| 1146 | Pixels are not writable when SkCanvas is returned by SkDocument::beginPage, |
| 1147 | returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility |
Brian Osman | 46fe9c7 | 2018-03-09 15:44:34 -0500 | [diff] [blame] | 1148 | class like SkDebugCanvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1149 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1150 | Pixel values are converted only if Color_Type and Alpha_Type |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1151 | do not match. Only pixels within both source and destination rectangles |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1152 | are copied. Canvas pixels outside Rect intersection are unchanged. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1153 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1154 | Pass negative values for x or y to offset pixels to the left or |
| 1155 | above Canvas pixels. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1156 | |
| 1157 | Does not copy, and returns false if: |
| 1158 | |
| 1159 | #List |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1160 | # Source and destination rectangles do not intersect. ## |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1161 | # pixels could not be converted to Canvas imageInfo().colorType() or |
| 1162 | imageInfo().alphaType(). ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1163 | # Canvas pixels are not writable; for instance, Canvas is document-based. ## |
| 1164 | # rowBytes is too small to contain one row of pixels. ## |
| 1165 | ## |
| 1166 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1167 | #Param info width, height, Color_Type, and Alpha_Type of pixels ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1168 | #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] | 1169 | #Param rowBytes size of one row of pixels; info.width() times pixel size, or larger ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1170 | #Param x offset into Canvas writable pixels in x; may be negative ## |
| 1171 | #Param y offset into Canvas writable pixels in y; may be negative ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1172 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1173 | #Return true if pixels were written to Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1174 | |
| 1175 | #Example |
| 1176 | SkImageInfo imageInfo = SkImageInfo::MakeN32(256, 1, kPremul_SkAlphaType); |
| 1177 | for (int y = 0; y < 256; ++y) { |
| 1178 | uint32_t pixels[256]; |
| 1179 | for (int x = 0; x < 256; ++x) { |
| 1180 | pixels[x] = SkColorSetARGB(x, x + y, x, x - y); |
| 1181 | } |
| 1182 | canvas->writePixels(imageInfo, &pixels, sizeof(pixels), 0, y); |
| 1183 | } |
| 1184 | ## |
| 1185 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1186 | #SeeAlso readPixels drawBitmap drawImage SkBitmap::writePixels |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1187 | |
| 1188 | ## |
| 1189 | |
| 1190 | # ------------------------------------------------------------------------------ |
| 1191 | |
| 1192 | #Method bool writePixels(const SkBitmap& bitmap, int x, int y) |
| 1193 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1194 | Copies Rect from pixels to Canvas. Matrix and Clip are ignored. |
| 1195 | Source Rect corners are (0, 0) and (bitmap.width(), bitmap.height()). |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1196 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1197 | Destination Rect corners are (x, y) and |
| 1198 | (imageInfo().width(), imageInfo().height()). |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1199 | |
| 1200 | Copies each readable pixel intersecting both rectangles, without scaling, |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1201 | converting to imageInfo().colorType() and imageInfo().alphaType() if required. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1202 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1203 | Pixels are writable when Device is raster, or backed by a GPU. |
| 1204 | Pixels are not writable when SkCanvas is returned by SkDocument::beginPage, |
| 1205 | returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility |
Brian Osman | 46fe9c7 | 2018-03-09 15:44:34 -0500 | [diff] [blame] | 1206 | class like SkDebugCanvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1207 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1208 | Pixel values are converted only if Color_Type and Alpha_Type |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1209 | do not match. Only pixels within both source and destination rectangles |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1210 | are copied. Canvas pixels outside Rect intersection are unchanged. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1211 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1212 | Pass negative values for x or y to offset pixels to the left or |
| 1213 | above Canvas pixels. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1214 | |
| 1215 | Does not copy, and returns false if: |
| 1216 | |
| 1217 | #List |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1218 | # Source and destination rectangles do not intersect. ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1219 | # bitmap does not have allocated pixels. ## |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1220 | # bitmap pixels could not be converted to Canvas imageInfo().colorType() or |
| 1221 | imageInfo().alphaType(). ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1222 | # Canvas pixels are not writable; for instance, Canvas is document based. ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1223 | # bitmap pixels are inaccessible; for instance, bitmap wraps a texture. ## |
| 1224 | ## |
| 1225 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1226 | #Param bitmap contains pixels copied to Canvas ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1227 | #Param x offset into Canvas writable pixels in x; may be negative ## |
| 1228 | #Param y offset into Canvas writable pixels in y; may be negative ## |
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 | #Return true if pixels were written to Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1231 | |
| 1232 | #Example |
| 1233 | void draw(SkCanvas* canvas) { |
| 1234 | SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(2, 2); |
| 1235 | SkBitmap bitmap; |
| 1236 | bitmap.setInfo(imageInfo); |
| 1237 | uint32_t pixels[4]; |
| 1238 | bitmap.setPixels(pixels); |
| 1239 | for (int y = 0; y < 256; y += 2) { |
| 1240 | for (int x = 0; x < 256; x += 2) { |
| 1241 | pixels[0] = SkColorSetRGB(x, y, x | y); |
| 1242 | pixels[1] = SkColorSetRGB(x ^ y, y, x); |
| 1243 | pixels[2] = SkColorSetRGB(x, x & y, y); |
| 1244 | pixels[3] = SkColorSetRGB(~x, ~y, x); |
| 1245 | canvas->writePixels(bitmap, x, y); |
| 1246 | } |
| 1247 | } |
| 1248 | } |
| 1249 | ## |
| 1250 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1251 | #SeeAlso readPixels drawBitmap drawImage SkBitmap::writePixels |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1252 | |
| 1253 | ## |
| 1254 | |
| 1255 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1256 | #Subtopic State_Stack |
| 1257 | #Line # stack of state for hierarchical drawing ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1258 | |
| 1259 | Canvas maintains a stack of state that allows hierarchical drawing, commonly used |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1260 | to implement windows and views. The initial state has an identity matrix and and |
| 1261 | an infinite clip. Even with a wide-open clip, drawing is constrained by the |
| 1262 | bounds of the Canvas Surface or Device. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1263 | |
| 1264 | Canvas savable state consists of Clip, Matrix, and Draw_Filter. |
| 1265 | Clip describes the area that may be drawn to. |
| 1266 | Matrix transforms the geometry. |
| 1267 | Draw_Filter (deprecated on most platforms) modifies the paint before drawing. |
| 1268 | |
| 1269 | save(), saveLayer, saveLayerPreserveLCDTextRequests, and saveLayerAlpha |
| 1270 | save state and return the depth of the stack. |
| 1271 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1272 | restore(), restoreToCount, and ~SkCanvas() revert state to its value when saved. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1273 | |
| 1274 | Each state on the stack intersects Clip with the previous Clip, |
| 1275 | and concatenates Matrix with the previous Matrix. |
| 1276 | The intersected Clip makes the drawing area the same or smaller; |
| 1277 | the concatenated Matrix may move the origin and potentially scale or rotate |
| 1278 | the coordinate space. |
| 1279 | |
| 1280 | Canvas does not require balancing the state stack but it is a good idea |
| 1281 | to do so. Calling save() without restore() will eventually cause Skia to fail; |
| 1282 | mismatched save() and restore() create hard to find bugs. |
| 1283 | |
| 1284 | It is not possible to use state to draw outside of the clip defined by the |
| 1285 | previous state. |
| 1286 | |
| 1287 | #Example |
| 1288 | #Description |
| 1289 | Draw to ever smaller clips; then restore drawing to full canvas. |
| 1290 | Note that the second clipRect is not permitted to enlarge Clip. |
| 1291 | ## |
| 1292 | #Height 160 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1293 | void draw(SkCanvas* canvas) { |
| 1294 | SkPaint paint; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1295 | canvas->save(); // records stack depth to restore |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1296 | canvas->clipRect(SkRect::MakeWH(100, 100)); // constrains drawing to clip |
| 1297 | canvas->clear(SK_ColorRED); // draws to limit of clip |
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(50, 150)); // Rect below 100 is ignored |
| 1300 | canvas->clear(SK_ColorBLUE); // draws to smaller clip |
| 1301 | canvas->restore(); // enlarges clip |
| 1302 | canvas->drawLine(20, 20, 150, 150, paint); // line below 100 is not drawn |
| 1303 | canvas->restore(); // enlarges clip |
| 1304 | canvas->drawLine(150, 20, 50, 120, paint); // line below 100 is drawn |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1305 | } |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1306 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1307 | |
| 1308 | Each Clip uses the current Matrix for its coordinates. |
| 1309 | |
| 1310 | #Example |
| 1311 | #Description |
| 1312 | While clipRect is given the same rectangle twice, Matrix makes the second |
| 1313 | clipRect draw at half the size of the first. |
| 1314 | ## |
| 1315 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1316 | void draw(SkCanvas* canvas) { |
| 1317 | canvas->clipRect(SkRect::MakeWH(100, 100)); |
| 1318 | canvas->clear(SK_ColorRED); |
| 1319 | canvas->scale(.5, .5); |
| 1320 | canvas->clipRect(SkRect::MakeWH(100, 100)); |
| 1321 | canvas->clear(SK_ColorBLUE); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1322 | } |
| 1323 | ## |
| 1324 | |
| 1325 | #SeeAlso save() saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha restore() restoreToCount |
| 1326 | |
| 1327 | #Method int save() |
| 1328 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1329 | #In State_Stack |
| 1330 | #Line # saves Clip and Matrix on stack ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1331 | Saves Matrix, Clip, and Draw_Filter (Draw_Filter deprecated on most platforms). |
| 1332 | Calling restore() discards changes to Matrix, Clip, and Draw_Filter, |
| 1333 | restoring the Matrix, Clip, and Draw_Filter to their state when save() was called. |
| 1334 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1335 | Matrix may be changed by translate(), scale(), rotate(), skew(), concat(), setMatrix, |
| 1336 | and resetMatrix. Clip may be changed by clipRect, clipRRect, clipPath, clipRegion. |
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 | Saved Canvas state is put on a stack; multiple calls to save() should be balance |
| 1339 | by an equal number of calls to restore(). |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1340 | |
| 1341 | Call restoreToCount with result to restore this and subsequent saves. |
| 1342 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1343 | #Return depth of saved stack ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1344 | |
| 1345 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1346 | #Description |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1347 | The black square is translated 50 pixels down and to the right. |
| 1348 | Restoring Canvas state removes translate() from Canvas stack; |
| 1349 | the red square is not translated, and is drawn at the origin. |
| 1350 | ## |
| 1351 | #Height 100 |
| 1352 | void draw(SkCanvas* canvas) { |
| 1353 | SkPaint paint; |
| 1354 | SkRect rect = { 0, 0, 25, 25 }; |
| 1355 | canvas->drawRect(rect, paint); |
| 1356 | canvas->save(); |
| 1357 | canvas->translate(50, 50); |
| 1358 | canvas->drawRect(rect, paint); |
| 1359 | canvas->restore(); |
| 1360 | paint.setColor(SK_ColorRED); |
| 1361 | canvas->drawRect(rect, paint); |
| 1362 | } |
| 1363 | ## |
| 1364 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1365 | #SeeAlso saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha restore() restoreToCount |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1366 | |
| 1367 | ## |
| 1368 | |
| 1369 | # ------------------------------------------------------------------------------ |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1370 | |
| 1371 | #Method void restore() |
| 1372 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1373 | #In State_Stack |
| 1374 | #Line # restores changes to Clip and Matrix, pops save stack ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1375 | Removes changes to Matrix, Clip, and Draw_Filter since Canvas state was |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1376 | last saved. The state is removed from the stack. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1377 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1378 | Does nothing if the stack is empty. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1379 | |
| 1380 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1381 | void draw(SkCanvas* canvas) { |
| 1382 | SkCanvas simple; |
| 1383 | SkDebugf("depth = %d\n", simple.getSaveCount()); |
| 1384 | simple.restore(); |
| 1385 | SkDebugf("depth = %d\n", simple.getSaveCount()); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1386 | } |
| 1387 | ## |
| 1388 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1389 | #SeeAlso save() saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha restoreToCount |
| 1390 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1391 | ## |
| 1392 | |
| 1393 | # ------------------------------------------------------------------------------ |
| 1394 | |
| 1395 | #Method int getSaveCount() const |
| 1396 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1397 | #In State_Stack |
| 1398 | #Line # returns depth of stack containing Clip and Matrix ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1399 | Returns the number of saved states, each containing: Matrix, Clip, and Draw_Filter. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1400 | 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] | 1401 | The save count of a new canvas is one. |
| 1402 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1403 | #Return depth of save state stack ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1404 | |
| 1405 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1406 | void draw(SkCanvas* canvas) { |
| 1407 | SkCanvas simple; |
| 1408 | SkDebugf("depth = %d\n", simple.getSaveCount()); |
| 1409 | simple.save(); |
| 1410 | SkDebugf("depth = %d\n", simple.getSaveCount()); |
| 1411 | simple.restore(); |
| 1412 | SkDebugf("depth = %d\n", simple.getSaveCount()); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1413 | } |
| 1414 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1415 | depth = 1 |
| 1416 | depth = 2 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1417 | depth = 1 |
| 1418 | ## |
| 1419 | ## |
| 1420 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1421 | #SeeAlso save() restore() restoreToCount |
| 1422 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1423 | ## |
| 1424 | |
| 1425 | # ------------------------------------------------------------------------------ |
| 1426 | |
| 1427 | #Method void restoreToCount(int saveCount) |
| 1428 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1429 | #In State_Stack |
| 1430 | #Line # restores changes to Clip and Matrix to given depth ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1431 | Restores state to Matrix, Clip, and Draw_Filter values when save(), saveLayer, |
| 1432 | saveLayerPreserveLCDTextRequests, or saveLayerAlpha returned saveCount. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1433 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1434 | Does nothing if saveCount is greater than state stack count. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1435 | Restores state to initial values if saveCount is less than or equal to one. |
| 1436 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1437 | #Param saveCount depth of state stack to restore ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1438 | |
| 1439 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1440 | void draw(SkCanvas* canvas) { |
| 1441 | SkDebugf("depth = %d\n", canvas->getSaveCount()); |
| 1442 | canvas->save(); |
| 1443 | canvas->save(); |
| 1444 | SkDebugf("depth = %d\n", canvas->getSaveCount()); |
| 1445 | canvas->restoreToCount(0); |
| 1446 | SkDebugf("depth = %d\n", canvas->getSaveCount()); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1447 | } |
| 1448 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1449 | depth = 1 |
| 1450 | depth = 3 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1451 | depth = 1 |
| 1452 | ## |
| 1453 | ## |
| 1454 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1455 | #SeeAlso restore() getSaveCount save() |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1456 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1457 | ## |
| 1458 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1459 | #Subtopic State_Stack ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1460 | |
| 1461 | # ------------------------------------------------------------------------------ |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1462 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1463 | #Subtopic Layer |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1464 | #Substitute layer |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1465 | #Alias Layers |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 1466 | #Substitute layers |
| 1467 | ## |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1468 | #Line # temporary Bitmap to draw into ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1469 | |
| 1470 | Layer allocates a temporary Bitmap to draw into. When the drawing is |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1471 | complete, the Bitmap is drawn into the Canvas. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1472 | |
| 1473 | Layer is saved in a stack along with other saved state. When state with a Layer |
| 1474 | is restored, the Bitmap is drawn into the previous Layer. |
| 1475 | |
| 1476 | Layer may be initialized with the contents of the previous Layer. When Layer is |
| 1477 | restored, its Bitmap can be modified by Paint passed to Layer to apply |
| 1478 | Color_Alpha, Color_Filter, Image_Filter, and Blend_Mode. |
| 1479 | |
| 1480 | #Method int saveLayer(const SkRect* bounds, const SkPaint* paint) |
| 1481 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1482 | #In Layer |
| 1483 | #Line # saves Clip and Matrix on stack; creates Layer ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1484 | Saves Matrix, Clip, and Draw_Filter (Draw_Filter deprecated on most platforms), |
| 1485 | and allocates a Bitmap for subsequent drawing. |
| 1486 | Calling restore() discards changes to Matrix, Clip, and Draw_Filter, |
| 1487 | and draws the Bitmap. |
| 1488 | |
| 1489 | Matrix may be changed by translate(), scale(), rotate(), skew(), concat(), |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1490 | setMatrix, and resetMatrix. Clip may be changed by clipRect, clipRRect, |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1491 | clipPath, clipRegion. |
| 1492 | |
| 1493 | Rect bounds suggests but does not define the Bitmap size. To clip drawing to |
| 1494 | a specific rectangle, use clipRect. |
| 1495 | |
| 1496 | Optional Paint paint applies Color_Alpha, Color_Filter, Image_Filter, and |
| 1497 | Blend_Mode when restore() is called. |
| 1498 | |
| 1499 | Call restoreToCount with returned value to restore this and subsequent saves. |
| 1500 | |
| 1501 | #Param bounds hint to limit the size of the Layer; may be nullptr ## |
| 1502 | #Param paint graphics state for Layer; may be nullptr ## |
| 1503 | |
| 1504 | #Return depth of saved stack ## |
| 1505 | |
| 1506 | #Example |
| 1507 | #Description |
| 1508 | Rectangles are blurred by Image_Filter when restore() draws Layer to main |
| 1509 | Canvas. |
| 1510 | ## |
| 1511 | #Height 128 |
| 1512 | void draw(SkCanvas* canvas) { |
| 1513 | SkPaint paint, blur; |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1514 | blur.setImageFilter(SkBlurImageFilter::Make(3, 3, nullptr)); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1515 | canvas->saveLayer(nullptr, &blur); |
| 1516 | SkRect rect = { 25, 25, 50, 50}; |
| 1517 | canvas->drawRect(rect, paint); |
| 1518 | canvas->translate(50, 50); |
| 1519 | paint.setColor(SK_ColorRED); |
| 1520 | canvas->drawRect(rect, paint); |
| 1521 | canvas->restore(); |
| 1522 | } |
| 1523 | ## |
| 1524 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1525 | #SeeAlso save() restore() saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha SaveLayerRec |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1526 | |
| 1527 | ## |
| 1528 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1529 | #Method int saveLayer(const SkRect& bounds, const SkPaint* paint) |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1530 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1531 | #In Layer |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1532 | Saves Matrix, Clip, and Draw_Filter (Draw_Filter deprecated on most platforms), |
| 1533 | and allocates a Bitmap for subsequent drawing. |
| 1534 | Calling restore() discards changes to Matrix, Clip, and Draw_Filter, |
| 1535 | and draws the Bitmap. |
| 1536 | |
| 1537 | Matrix may be changed by translate(), scale(), rotate(), skew(), concat(), |
| 1538 | setMatrix, and resetMatrix. Clip may be changed by clipRect, clipRRect, |
| 1539 | clipPath, clipRegion. |
| 1540 | |
| 1541 | Rect bounds suggests but does not define the Layer size. To clip drawing to |
| 1542 | a specific rectangle, use clipRect. |
| 1543 | |
| 1544 | Optional Paint paint applies Color_Alpha, Color_Filter, Image_Filter, and |
| 1545 | Blend_Mode when restore() is called. |
| 1546 | |
| 1547 | Call restoreToCount with returned value to restore this and subsequent saves. |
| 1548 | |
| 1549 | #Param bounds hint to limit the size of Layer; may be nullptr ## |
| 1550 | #Param paint graphics state for Layer; may be nullptr ## |
| 1551 | |
| 1552 | #Return depth of saved stack ## |
| 1553 | |
| 1554 | #Example |
| 1555 | #Description |
| 1556 | 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] | 1557 | The red rectangle is clipped; it does not fully fit on Layer. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1558 | Image_Filter blurs past edge of Layer so red rectangle is blurred on all sides. |
| 1559 | ## |
| 1560 | #Height 128 |
| 1561 | void draw(SkCanvas* canvas) { |
| 1562 | SkPaint paint, blur; |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1563 | blur.setImageFilter(SkBlurImageFilter::Make(3, 3, nullptr)); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1564 | canvas->saveLayer(SkRect::MakeWH(90, 90), &blur); |
| 1565 | SkRect rect = { 25, 25, 50, 50}; |
| 1566 | canvas->drawRect(rect, paint); |
| 1567 | canvas->translate(50, 50); |
| 1568 | paint.setColor(SK_ColorRED); |
| 1569 | canvas->drawRect(rect, paint); |
| 1570 | canvas->restore(); |
| 1571 | } |
| 1572 | ## |
| 1573 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1574 | #SeeAlso save() restore() saveLayerPreserveLCDTextRequests saveLayerAlpha SaveLayerRec |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1575 | |
| 1576 | ## |
| 1577 | |
| 1578 | #Method int saveLayerPreserveLCDTextRequests(const SkRect* bounds, const SkPaint* paint) |
| 1579 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1580 | #In Layer |
| 1581 | #Line # saves Clip and Matrix on stack; creates Layer for LCD text ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1582 | Saves Matrix, Clip, and Draw_Filter (Draw_Filter deprecated on most platforms), |
| 1583 | and allocates a Bitmap for subsequent drawing. |
| 1584 | LCD_Text is preserved when the Layer is drawn to the prior Layer. |
| 1585 | |
| 1586 | Calling restore() discards changes to Matrix, Clip, and Draw_Filter, |
| 1587 | and draws Layer. |
| 1588 | |
| 1589 | Matrix may be changed by translate(), scale(), rotate(), skew(), concat(), |
| 1590 | setMatrix, and resetMatrix. Clip may be changed by clipRect, clipRRect, |
| 1591 | clipPath, clipRegion. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1592 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1593 | Rect bounds suggests but does not define the Layer size. To clip drawing to |
| 1594 | a specific rectangle, use clipRect. |
| 1595 | |
| 1596 | Optional Paint paint applies Color_Alpha, Color_Filter, Image_Filter, and |
| 1597 | Blend_Mode when restore() is called. |
| 1598 | |
| 1599 | Call restoreToCount with returned value to restore this and subsequent saves. |
| 1600 | |
| 1601 | Draw text on an opaque background so that LCD_Text blends correctly with the |
| 1602 | 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] | 1603 | incorrect blending. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1604 | |
| 1605 | #Param bounds hint to limit the size of Layer; may be nullptr ## |
| 1606 | #Param paint graphics state for Layer; may be nullptr ## |
| 1607 | |
| 1608 | #Return depth of saved stack ## |
| 1609 | |
| 1610 | #Example |
| 1611 | SkPaint paint; |
| 1612 | paint.setAntiAlias(true); |
| 1613 | paint.setLCDRenderText(true); |
| 1614 | paint.setTextSize(20); |
| 1615 | for (auto preserve : { false, true } ) { |
| 1616 | preserve ? canvas->saveLayerPreserveLCDTextRequests(nullptr, nullptr) |
| 1617 | : canvas->saveLayer(nullptr, nullptr); |
| 1618 | SkPaint p; |
| 1619 | p.setColor(SK_ColorWHITE); |
| 1620 | // Comment out the next line to draw on a non-opaque background. |
| 1621 | canvas->drawRect(SkRect::MakeLTRB(25, 40, 200, 70), p); |
| 1622 | canvas->drawString("Hamburgefons", 30, 60, paint); |
| 1623 | |
| 1624 | p.setColor(0xFFCCCCCC); |
| 1625 | canvas->drawRect(SkRect::MakeLTRB(25, 70, 200, 100), p); |
| 1626 | canvas->drawString("Hamburgefons", 30, 90, paint); |
| 1627 | |
| 1628 | canvas->restore(); |
| 1629 | canvas->translate(0, 80); |
| 1630 | } |
| 1631 | ## |
| 1632 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1633 | #SeeAlso save() restore() saveLayer saveLayerAlpha SaveLayerRec |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1634 | |
| 1635 | ## |
| 1636 | |
| 1637 | #Method int saveLayerAlpha(const SkRect* bounds, U8CPU alpha) |
| 1638 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1639 | #In Layer |
| 1640 | #Line # saves Clip and Matrix on stack; creates Layer; sets opacity ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1641 | Saves Matrix, Clip, and Draw_Filter (Draw_Filter deprecated on most platforms), |
| 1642 | and allocates Bitmap for subsequent drawing. |
| 1643 | |
| 1644 | Calling restore() discards changes to Matrix, Clip, and Draw_Filter, |
| 1645 | and blends Layer with alpha opacity onto prior Layer. |
| 1646 | |
| 1647 | Matrix may be changed by translate(), scale(), rotate(), skew(), concat(), |
| 1648 | setMatrix, and resetMatrix. Clip may be changed by clipRect, clipRRect, |
| 1649 | clipPath, clipRegion. |
| 1650 | |
| 1651 | Rect bounds suggests but does not define Layer size. To clip drawing to |
| 1652 | a specific rectangle, use clipRect. |
| 1653 | |
| 1654 | alpha of zero is fully transparent, 255 is fully opaque. |
| 1655 | |
| 1656 | Call restoreToCount with returned value to restore this and subsequent saves. |
| 1657 | |
| 1658 | #Param bounds hint to limit the size of Layer; may be nullptr ## |
| 1659 | #Param alpha opacity of Layer ## |
| 1660 | |
| 1661 | #Return depth of saved stack ## |
| 1662 | |
| 1663 | #Example |
| 1664 | SkPaint paint; |
| 1665 | paint.setColor(SK_ColorRED); |
| 1666 | canvas->drawCircle(50, 50, 50, paint); |
| 1667 | canvas->saveLayerAlpha(nullptr, 128); |
| 1668 | paint.setColor(SK_ColorBLUE); |
| 1669 | canvas->drawCircle(100, 50, 50, paint); |
| 1670 | paint.setColor(SK_ColorGREEN); |
| 1671 | paint.setAlpha(128); |
| 1672 | canvas->drawCircle(75, 90, 50, paint); |
| 1673 | canvas->restore(); |
| 1674 | ## |
| 1675 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1676 | #SeeAlso save() restore() saveLayer saveLayerPreserveLCDTextRequests SaveLayerRec |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1677 | |
| 1678 | ## |
| 1679 | |
Cary Clark | d98f78c | 2018-04-26 08:32:37 -0400 | [diff] [blame] | 1680 | #Enum SaveLayerFlagsSet |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1681 | #Line # sets SaveLayerRec options ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1682 | #Code |
Cary Clark | d98f78c | 2018-04-26 08:32:37 -0400 | [diff] [blame] | 1683 | enum SaveLayerFlagsSet { |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1684 | kPreserveLCDText_SaveLayerFlag = 1 << 1, |
| 1685 | kInitWithPrevious_SaveLayerFlag = 1 << 2, |
Mike Reed | 910ca0f | 2018-04-25 13:04:05 -0400 | [diff] [blame] | 1686 | kMaskAgainstCoverage_EXPERIMENTAL_DONT_USE_SaveLayerFlag = 1 << 3, |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1687 | kDontClipToLayer_Legacy_SaveLayerFlag = kDontClipToLayer_PrivateSaveLayerFlag, |
| 1688 | }; |
Cary Clark | d98f78c | 2018-04-26 08:32:37 -0400 | [diff] [blame] | 1689 | |
| 1690 | typedef uint32_t SaveLayerFlags; |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1691 | ## |
| 1692 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1693 | |
| 1694 | #Typedef uint32_t SaveLayerFlags |
| 1695 | #Line # options for SaveLayerRec ## |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 1696 | ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1697 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1698 | SaveLayerFlags provides options that may be used in any combination in SaveLayerRec, |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1699 | defining how Layer allocated by saveLayer operates. It may be set to zero, |
| 1700 | kPreserveLCDText_SaveLayerFlag, kInitWithPrevious_SaveLayerFlag, or both flags. |
| 1701 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1702 | #Const kPreserveLCDText_SaveLayerFlag 2 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1703 | #Line # creates Layer for LCD text ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1704 | Creates Layer for LCD text. Flag is ignored if Layer Paint contains |
| 1705 | Image_Filter or Color_Filter. |
| 1706 | ## |
| 1707 | |
| 1708 | #Const kInitWithPrevious_SaveLayerFlag 4 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1709 | #Line # initializes with previous contents ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1710 | Initializes Layer with the contents of the previous Layer. |
| 1711 | ## |
| 1712 | |
Mike Reed | 910ca0f | 2018-04-25 13:04:05 -0400 | [diff] [blame] | 1713 | #Const kMaskAgainstCoverage_EXPERIMENTAL_DONT_USE_SaveLayerFlag 8 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1714 | #Experimental do not use |
Mike Reed | 910ca0f | 2018-04-25 13:04:05 -0400 | [diff] [blame] | 1715 | ## |
| 1716 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1717 | #Const kDontClipToLayer_Legacy_SaveLayerFlag 0x80000000 |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1718 | #Deprecated soon |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1719 | ## |
| 1720 | |
| 1721 | #Example |
| 1722 | #Height 160 |
| 1723 | #Description |
| 1724 | Canvas Layer captures red and blue circles scaled up by four. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1725 | scalePaint blends Layer back with transparency. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1726 | ## |
| 1727 | void draw(SkCanvas* canvas) { |
| 1728 | SkPaint redPaint, bluePaint, scalePaint; |
| 1729 | redPaint.setColor(SK_ColorRED); |
| 1730 | canvas->drawCircle(21, 21, 8, redPaint); |
| 1731 | bluePaint.setColor(SK_ColorBLUE); |
| 1732 | canvas->drawCircle(31, 21, 8, bluePaint); |
| 1733 | SkMatrix matrix; |
| 1734 | matrix.setScale(4, 4); |
| 1735 | scalePaint.setAlpha(0x40); |
| 1736 | scalePaint.setImageFilter( |
| 1737 | SkImageFilter::MakeMatrixFilter(matrix, kNone_SkFilterQuality, nullptr)); |
| 1738 | SkCanvas::SaveLayerRec saveLayerRec(nullptr, &scalePaint, |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1739 | SkCanvas::kInitWithPrevious_SaveLayerFlag); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1740 | canvas->saveLayer(saveLayerRec); |
| 1741 | canvas->restore(); |
| 1742 | } |
| 1743 | ## |
| 1744 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1745 | #SeeAlso save() restore() saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha SaveLayerRec |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1746 | |
| 1747 | #Enum ## |
| 1748 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1749 | #Subtopic SaveLayerRec |
| 1750 | #Line # contains the state used to create the Layer ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1751 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1752 | #Struct SaveLayerRec |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1753 | #Line # contains the state used to create the Layer ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1754 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1755 | #Code |
| 1756 | struct SaveLayerRec { |
| 1757 | SaveLayerRec*(... |
| 1758 | |
| 1759 | const SkRect* fBounds; |
| 1760 | const SkPaint* fPaint; |
| 1761 | const SkImageFilter* fBackdrop; |
| 1762 | SaveLayerFlags fSaveLayerFlags; |
| 1763 | }; |
| 1764 | ## |
| 1765 | |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 1766 | SaveLayerRec contains the state used to create the Layer. |
| 1767 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1768 | #Subtopic Overview |
| 1769 | #Populate |
| 1770 | ## |
| 1771 | |
| 1772 | #Subtopic Member |
| 1773 | #Populate |
| 1774 | ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1775 | |
| 1776 | #Member const SkRect* fBounds |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1777 | #Line # hints at Layer size limit ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1778 | fBounds is used as a hint to limit the size of Layer; may be nullptr. |
| 1779 | fBounds suggests but does not define Layer size. To clip drawing to |
| 1780 | a specific rectangle, use clipRect. |
| 1781 | ## |
| 1782 | |
| 1783 | #Member const SkPaint* fPaint |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1784 | #Line # modifies overlay ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1785 | fPaint modifies how Layer overlays the prior Layer; may be nullptr. |
| 1786 | Color_Alpha, Blend_Mode, Color_Filter, Draw_Looper, Image_Filter, and |
| 1787 | Mask_Filter affect Layer draw. |
| 1788 | ## |
| 1789 | |
| 1790 | #Member const SkImageFilter* fBackdrop |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1791 | #Line # applies Image_Filter to prior Layer ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1792 | fBackdrop applies Image_Filter to the prior Layer when copying to the Layer; |
| 1793 | may be nullptr. Use kInitWithPrevious_SaveLayerFlag to copy the |
| 1794 | prior Layer without an Image_Filter. |
| 1795 | ## |
| 1796 | |
| 1797 | #Member const SkImage* fClipMask |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1798 | #Line # clips Layer with Mask_Alpha ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1799 | restore() clips Layer by the Color_Alpha channel of fClipMask when |
| 1800 | Layer is copied to Device. fClipMask may be nullptr. . |
| 1801 | ## |
| 1802 | |
| 1803 | #Member const SkMatrix* fClipMatrix |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1804 | #Line # transforms Mask_Alpha used to clip ## |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1805 | fClipMatrix transforms fClipMask before it clips Layer. If |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1806 | fClipMask describes a translucent gradient, it may be scaled and rotated |
| 1807 | without introducing artifacts. fClipMatrix may be nullptr. |
| 1808 | ## |
| 1809 | |
| 1810 | #Member SaveLayerFlags fSaveLayerFlags |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1811 | #Line # preserves LCD Text, creates with prior Layer contents ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1812 | fSaveLayerFlags are used to create Layer without transparency, |
| 1813 | create Layer for LCD text, and to create Layer with the |
| 1814 | contents of the previous Layer. |
| 1815 | ## |
| 1816 | |
| 1817 | #Example |
| 1818 | #Height 160 |
| 1819 | #Description |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1820 | 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] | 1821 | 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] | 1822 | transferred to the main canvas. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1823 | ## |
| 1824 | void draw(SkCanvas* canvas) { |
| 1825 | SkPaint redPaint, bluePaint; |
| 1826 | redPaint.setAntiAlias(true); |
| 1827 | redPaint.setColor(SK_ColorRED); |
| 1828 | canvas->drawCircle(21, 21, 8, redPaint); |
| 1829 | bluePaint.setColor(SK_ColorBLUE); |
| 1830 | canvas->drawCircle(31, 21, 8, bluePaint); |
| 1831 | SkMatrix matrix; |
| 1832 | matrix.setScale(4, 4); |
| 1833 | auto scaler = SkImageFilter::MakeMatrixFilter(matrix, kNone_SkFilterQuality, nullptr); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1834 | SkCanvas::SaveLayerRec saveLayerRec(nullptr, nullptr, scaler.get(), 0); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1835 | canvas->saveLayer(saveLayerRec); |
| 1836 | canvas->drawCircle(125, 85, 8, redPaint); |
| 1837 | canvas->restore(); |
| 1838 | } |
| 1839 | ## |
| 1840 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1841 | #Subtopic Constructor |
| 1842 | #Populate |
| 1843 | ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1844 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1845 | #Method SaveLayerRec() |
| 1846 | #Line # constructs SaveLayerRec ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1847 | Sets fBounds, fPaint, and fBackdrop to nullptr. Clears fSaveLayerFlags. |
| 1848 | |
| 1849 | #Return empty SaveLayerRec ## |
| 1850 | |
| 1851 | #Example |
| 1852 | SkCanvas::SaveLayerRec rec1; |
Mike Klein | e083f7c | 2018-02-07 12:54:27 -0500 | [diff] [blame] | 1853 | rec1.fSaveLayerFlags = SkCanvas::kPreserveLCDText_SaveLayerFlag; |
| 1854 | SkCanvas::SaveLayerRec rec2(nullptr, nullptr, SkCanvas::kPreserveLCDText_SaveLayerFlag); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1855 | SkDebugf("rec1 %c= rec2\n", rec1.fBounds == rec2.fBounds |
| 1856 | && rec1.fPaint == rec2.fPaint |
| 1857 | && rec1.fBackdrop == rec2.fBackdrop |
| 1858 | && rec1.fSaveLayerFlags == rec2.fSaveLayerFlags ? '=' : '!'); |
| 1859 | #StdOut |
| 1860 | rec1 == rec2 |
| 1861 | ## |
| 1862 | ## |
| 1863 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1864 | #SeeAlso save() restore() saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha |
| 1865 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1866 | ## |
| 1867 | |
Cary Clark | d98f78c | 2018-04-26 08:32:37 -0400 | [diff] [blame] | 1868 | #Method SaveLayerRec(const SkRect* bounds, const SkPaint* paint, |
| 1869 | SaveLayerFlags saveLayerFlags = 0) |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1870 | |
| 1871 | Sets fBounds, fPaint, and fSaveLayerFlags; sets fBackdrop to nullptr. |
| 1872 | |
| 1873 | #Param bounds Layer dimensions; may be nullptr ## |
| 1874 | #Param paint applied to Layer when overlaying prior Layer; may be nullptr ## |
| 1875 | #Param saveLayerFlags SaveLayerRec options to modify Layer ## |
| 1876 | |
| 1877 | #Return SaveLayerRec with empty backdrop ## |
| 1878 | |
| 1879 | #Example |
| 1880 | SkCanvas::SaveLayerRec rec1; |
| 1881 | SkCanvas::SaveLayerRec rec2(nullptr, nullptr); |
| 1882 | SkDebugf("rec1 %c= rec2\n", rec1.fBounds == rec2.fBounds |
| 1883 | && rec1.fPaint == rec2.fPaint |
| 1884 | && rec1.fBackdrop == rec2.fBackdrop |
| 1885 | && rec1.fSaveLayerFlags == rec2.fSaveLayerFlags ? '=' : '!'); |
| 1886 | #StdOut |
| 1887 | rec1 == rec2 |
| 1888 | ## |
| 1889 | ## |
| 1890 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1891 | #SeeAlso save() restore() saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha |
| 1892 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1893 | ## |
| 1894 | |
| 1895 | #Method SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop, |
| 1896 | SaveLayerFlags saveLayerFlags) |
| 1897 | |
| 1898 | Sets fBounds, fPaint, fBackdrop, and fSaveLayerFlags. |
| 1899 | |
| 1900 | #Param bounds Layer dimensions; may be nullptr ## |
| 1901 | #Param paint applied to Layer when overlaying prior Layer; |
| 1902 | may be nullptr |
| 1903 | ## |
| 1904 | #Param backdrop prior Layer copied with Image_Filter; may be nullptr |
| 1905 | ## |
| 1906 | #Param saveLayerFlags SaveLayerRec options to modify Layer ## |
| 1907 | |
| 1908 | #Return SaveLayerRec fully specified ## |
| 1909 | |
| 1910 | #Example |
| 1911 | SkCanvas::SaveLayerRec rec1; |
| 1912 | SkCanvas::SaveLayerRec rec2(nullptr, nullptr, nullptr, 0); |
| 1913 | SkDebugf("rec1 %c= rec2\n", rec1.fBounds == rec2.fBounds |
| 1914 | && rec1.fPaint == rec2.fPaint |
| 1915 | && rec1.fBackdrop == rec2.fBackdrop |
| 1916 | && rec1.fSaveLayerFlags == rec2.fSaveLayerFlags ? '=' : '!'); |
| 1917 | #StdOut |
| 1918 | rec1 == rec2 |
| 1919 | ## |
| 1920 | ## |
| 1921 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1922 | #SeeAlso save() restore() saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha |
| 1923 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1924 | ## |
| 1925 | |
| 1926 | #Method SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop, |
| 1927 | const SkImage* clipMask, const SkMatrix* clipMatrix, |
| 1928 | SaveLayerFlags saveLayerFlags) |
| 1929 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1930 | #Experimental not ready |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1931 | |
| 1932 | Sets fBounds, fPaint, fBackdrop, fClipMask, fClipMatrix, and fSaveLayerFlags. |
| 1933 | clipMatrix uses Color_Alpha channel of image, transformed by clipMatrix, to clip |
| 1934 | Layer when drawn to Canvas. |
| 1935 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1936 | Implementation is not complete; has no effect if Device is GPU-backed. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1937 | |
| 1938 | #Param bounds Layer dimensions; may be nullptr ## |
| 1939 | #Param paint graphics state applied to Layer when overlaying prior |
| 1940 | Layer; may be nullptr |
| 1941 | ## |
| 1942 | #Param backdrop prior Layer copied with Image_Filter; |
| 1943 | may be nullptr |
| 1944 | ## |
| 1945 | #Param clipMask clip applied to Layer; may be nullptr ## |
| 1946 | #Param clipMatrix matrix applied to clipMask; may be nullptr to use |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1947 | identity matrix |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1948 | ## |
| 1949 | #Param saveLayerFlags SaveLayerRec options to modify Layer ## |
| 1950 | |
| 1951 | #Return SaveLayerRec fully specified ## |
| 1952 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1953 | #SeeAlso save() restore() saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1954 | |
| 1955 | ## |
| 1956 | |
| 1957 | #Struct ## |
| 1958 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1959 | #Subtopic ## |
| 1960 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1961 | #Method int saveLayer(const SaveLayerRec& layerRec) |
| 1962 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1963 | #In Layer |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1964 | Saves Matrix, Clip, and Draw_Filter (Draw_Filter deprecated on most platforms), |
| 1965 | and allocates Bitmap for subsequent drawing. |
| 1966 | |
| 1967 | Calling restore() discards changes to Matrix, Clip, and Draw_Filter, |
| 1968 | and blends Bitmap with Color_Alpha opacity onto the prior Layer. |
| 1969 | |
| 1970 | Matrix may be changed by translate(), scale(), rotate(), skew(), concat(), |
| 1971 | setMatrix, and resetMatrix. Clip may be changed by clipRect, clipRRect, |
| 1972 | clipPath, clipRegion. |
| 1973 | |
| 1974 | SaveLayerRec contains the state used to create the Layer. |
| 1975 | |
| 1976 | Call restoreToCount with returned value to restore this and subsequent saves. |
| 1977 | |
| 1978 | #Param layerRec Layer state ## |
| 1979 | |
| 1980 | #Return depth of save state stack ## |
| 1981 | |
| 1982 | #Example |
| 1983 | #Description |
| 1984 | The example draws an image, and saves it into a Layer with kInitWithPrevious_SaveLayerFlag. |
| 1985 | Next it punches a hole in Layer and restore with SkBlendMode::kPlus. |
| 1986 | Where Layer was cleared, the original image will draw unchanged. |
| 1987 | Outside of the circle the mandrill is brightened. |
| 1988 | ## |
| 1989 | #Image 3 |
Hal Canary | c465d13 | 2017-12-08 10:21:31 -0500 | [diff] [blame] | 1990 | // sk_sp<SkImage> image = GetResourceAsImage("images/mandrill_256.png"); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1991 | canvas->drawImage(image, 0, 0, nullptr); |
| 1992 | SkCanvas::SaveLayerRec rec; |
| 1993 | SkPaint paint; |
| 1994 | paint.setBlendMode(SkBlendMode::kPlus); |
| 1995 | rec.fSaveLayerFlags = SkCanvas::kInitWithPrevious_SaveLayerFlag; |
| 1996 | rec.fPaint = &paint; |
| 1997 | canvas->saveLayer(rec); |
| 1998 | paint.setBlendMode(SkBlendMode::kClear); |
| 1999 | canvas->drawCircle(128, 128, 96, paint); |
| 2000 | canvas->restore(); |
| 2001 | ## |
| 2002 | |
| 2003 | #ToDo above example needs to replace GetResourceAsImage with way to select image in fiddle ## |
| 2004 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2005 | #SeeAlso save() restore() saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha |
| 2006 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2007 | ## |
| 2008 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2009 | #Subtopic Layer ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2010 | |
| 2011 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2012 | #Subtopic Matrix |
| 2013 | #Line # coordinate transformation ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2014 | |
| 2015 | #Method void translate(SkScalar dx, SkScalar dy) |
| 2016 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2017 | #In Matrix |
| 2018 | #Line # translates Matrix ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2019 | Translate Matrix by dx along the x-axis and dy along the y-axis. |
| 2020 | |
| 2021 | Mathematically, replace Matrix with a translation matrix |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2022 | Premultiplied with Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2023 | |
| 2024 | This has the effect of moving the drawing by (dx, dy) before transforming |
| 2025 | the result with Matrix. |
| 2026 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2027 | #Param dx distance to translate in x ## |
| 2028 | #Param dy distance to translate in y ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2029 | |
| 2030 | #Example |
| 2031 | #Height 128 |
| 2032 | #Description |
| 2033 | scale() followed by translate() produces different results from translate() followed |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2034 | by scale(). |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2035 | |
| 2036 | The blue stroke follows translate of (50, 50); a black |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2037 | 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] | 2038 | Matrix, a red frame follows the same scale of (2, 1/2.f); a gray fill |
| 2039 | follows translate of (50, 50). |
| 2040 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2041 | void draw(SkCanvas* canvas) { |
| 2042 | SkPaint filledPaint; |
| 2043 | SkPaint outlinePaint; |
| 2044 | outlinePaint.setStyle(SkPaint::kStroke_Style); |
| 2045 | outlinePaint.setColor(SK_ColorBLUE); |
| 2046 | canvas->save(); |
| 2047 | canvas->translate(50, 50); |
| 2048 | canvas->drawCircle(28, 28, 15, outlinePaint); // blue center: (50+28, 50+28) |
| 2049 | canvas->scale(2, 1/2.f); |
| 2050 | canvas->drawCircle(28, 28, 15, filledPaint); // black center: (50+(28*2), 50+(28/2)) |
| 2051 | canvas->restore(); |
| 2052 | filledPaint.setColor(SK_ColorGRAY); |
| 2053 | outlinePaint.setColor(SK_ColorRED); |
| 2054 | canvas->scale(2, 1/2.f); |
| 2055 | canvas->drawCircle(28, 28, 15, outlinePaint); // red center: (28*2, 28/2) |
| 2056 | canvas->translate(50, 50); |
| 2057 | 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] | 2058 | } |
| 2059 | ## |
| 2060 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2061 | #SeeAlso concat() scale() skew() rotate() setMatrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2062 | |
| 2063 | ## |
| 2064 | |
| 2065 | # ------------------------------------------------------------------------------ |
| 2066 | |
| 2067 | #Method void scale(SkScalar sx, SkScalar sy) |
| 2068 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2069 | #In Matrix |
| 2070 | #Line # scales Matrix ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2071 | Scale Matrix by sx on the x-axis and sy on the y-axis. |
| 2072 | |
| 2073 | Mathematically, replace Matrix with a scale matrix |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2074 | Premultiplied with Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2075 | |
| 2076 | This has the effect of scaling the drawing by (sx, sy) before transforming |
| 2077 | the result with Matrix. |
| 2078 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2079 | #Param sx amount to scale in x ## |
| 2080 | #Param sy amount to scale in y ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2081 | |
| 2082 | #Example |
| 2083 | #Height 160 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2084 | void draw(SkCanvas* canvas) { |
| 2085 | SkPaint paint; |
| 2086 | SkRect rect = { 10, 20, 60, 120 }; |
| 2087 | canvas->translate(20, 20); |
| 2088 | canvas->drawRect(rect, paint); |
| 2089 | canvas->scale(2, .5f); |
| 2090 | paint.setColor(SK_ColorGRAY); |
| 2091 | canvas->drawRect(rect, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2092 | } |
| 2093 | ## |
| 2094 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2095 | #SeeAlso concat() translate() skew() rotate() setMatrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2096 | |
| 2097 | ## |
| 2098 | |
| 2099 | # ------------------------------------------------------------------------------ |
| 2100 | |
| 2101 | #Method void rotate(SkScalar degrees) |
| 2102 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2103 | #In Matrix |
| 2104 | #Line # rotates Matrix ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2105 | Rotate Matrix by degrees. Positive degrees rotates clockwise. |
| 2106 | |
| 2107 | Mathematically, replace Matrix with a rotation matrix |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2108 | Premultiplied with Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2109 | |
| 2110 | This has the effect of rotating the drawing by degrees before transforming |
| 2111 | the result with Matrix. |
| 2112 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2113 | #Param degrees amount to rotate, in degrees ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2114 | |
| 2115 | #Example |
| 2116 | #Description |
| 2117 | Draw clock hands at time 5:10. The hour hand and minute hand point up and |
| 2118 | are rotated clockwise. |
| 2119 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2120 | void draw(SkCanvas* canvas) { |
| 2121 | SkPaint paint; |
| 2122 | paint.setStyle(SkPaint::kStroke_Style); |
| 2123 | canvas->translate(128, 128); |
| 2124 | canvas->drawCircle(0, 0, 60, paint); |
| 2125 | canvas->save(); |
| 2126 | 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] | 2127 | canvas->drawLine(0, 0, 0, -50, paint); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2128 | canvas->restore(); |
| 2129 | canvas->rotate((5 + 10.f/60) * 360 / 12); // 5 and 10/60 hours of 12 scaled to 360 degrees |
| 2130 | canvas->drawLine(0, 0, 0, -30, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2131 | } |
| 2132 | ## |
| 2133 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2134 | #SeeAlso concat() translate() skew() scale() setMatrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2135 | |
| 2136 | ## |
| 2137 | |
| 2138 | # ------------------------------------------------------------------------------ |
| 2139 | |
| 2140 | #Method void rotate(SkScalar degrees, SkScalar px, SkScalar py) |
| 2141 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2142 | #In Matrix |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2143 | Rotate Matrix by degrees about a point at (px, py). Positive degrees rotates |
| 2144 | clockwise. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2145 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2146 | Mathematically, construct a rotation matrix. Premultiply the rotation matrix by |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2147 | a translation matrix, then replace Matrix with the resulting matrix |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2148 | Premultiplied with Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2149 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2150 | This has the effect of rotating the drawing about a given point before |
| 2151 | transforming the result with Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2152 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2153 | #Param degrees amount to rotate, in degrees ## |
| 2154 | #Param px x-coordinate of the point to rotate about ## |
| 2155 | #Param py y-coordinate of the point to rotate about ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2156 | |
| 2157 | #Example |
| 2158 | #Height 192 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2159 | void draw(SkCanvas* canvas) { |
| 2160 | SkPaint paint; |
| 2161 | paint.setTextSize(96); |
| 2162 | canvas->drawString("A1", 130, 100, paint); |
| 2163 | canvas->rotate(180, 130, 100); |
| 2164 | canvas->drawString("A1", 130, 100, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2165 | } |
| 2166 | ## |
| 2167 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2168 | #SeeAlso concat() translate() skew() scale() setMatrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2169 | |
| 2170 | ## |
| 2171 | |
| 2172 | # ------------------------------------------------------------------------------ |
| 2173 | |
| 2174 | #Method void skew(SkScalar sx, SkScalar sy) |
| 2175 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2176 | #In Matrix |
| 2177 | #Line # skews Matrix ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2178 | Skew Matrix by sx on the x-axis and sy on the y-axis. A positive value of sx |
| 2179 | skews the drawing right as y increases; a positive value of sy skews the drawing |
| 2180 | down as x increases. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2181 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2182 | Mathematically, replace Matrix with a skew matrix Premultiplied with Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2183 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2184 | 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] | 2185 | the result with Matrix. |
| 2186 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2187 | #Param sx amount to skew in x ## |
| 2188 | #Param sy amount to skew in y ## |
| 2189 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2190 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2191 | #Description |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2192 | Black text mimics an oblique text style by using a negative skew in x that |
| 2193 | shifts the geometry to the right as the y values decrease. |
| 2194 | Red text uses a positive skew in y to shift the geometry down as the x values |
| 2195 | increase. |
| 2196 | Blue text combines x and y skew to rotate and scale. |
| 2197 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2198 | SkPaint paint; |
| 2199 | paint.setTextSize(128); |
| 2200 | canvas->translate(30, 130); |
| 2201 | canvas->save(); |
| 2202 | canvas->skew(-.5, 0); |
| 2203 | canvas->drawString("A1", 0, 0, paint); |
| 2204 | canvas->restore(); |
| 2205 | canvas->save(); |
| 2206 | canvas->skew(0, .5); |
| 2207 | paint.setColor(SK_ColorRED); |
| 2208 | canvas->drawString("A1", 0, 0, paint); |
| 2209 | canvas->restore(); |
| 2210 | canvas->skew(-.5, .5); |
| 2211 | paint.setColor(SK_ColorBLUE); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2212 | canvas->drawString("A1", 0, 0, paint); |
| 2213 | ## |
| 2214 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2215 | #SeeAlso concat() translate() rotate() scale() setMatrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2216 | |
| 2217 | ## |
| 2218 | |
| 2219 | # ------------------------------------------------------------------------------ |
| 2220 | |
| 2221 | #Method void concat(const SkMatrix& matrix) |
| 2222 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2223 | #In Matrix |
| 2224 | #Line # multiplies Matrix by Matrix ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2225 | Replace Matrix with matrix Premultiplied with existing Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2226 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2227 | This has the effect of transforming the drawn geometry by matrix, before |
| 2228 | transforming the result with existing Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2229 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2230 | #Param matrix matrix to Premultiply with existing Matrix ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2231 | |
| 2232 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2233 | void draw(SkCanvas* canvas) { |
| 2234 | SkPaint paint; |
| 2235 | paint.setTextSize(80); |
| 2236 | paint.setTextScaleX(.3); |
| 2237 | SkMatrix matrix; |
| 2238 | SkRect rect[2] = {{ 10, 20, 90, 110 }, { 40, 130, 140, 180 }}; |
| 2239 | matrix.setRectToRect(rect[0], rect[1], SkMatrix::kFill_ScaleToFit); |
| 2240 | canvas->drawRect(rect[0], paint); |
| 2241 | canvas->drawRect(rect[1], paint); |
| 2242 | paint.setColor(SK_ColorWHITE); |
| 2243 | canvas->drawString("Here", rect[0].fLeft + 10, rect[0].fBottom - 10, paint); |
| 2244 | canvas->concat(matrix); |
| 2245 | canvas->drawString("There", rect[0].fLeft + 10, rect[0].fBottom - 10, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2246 | } |
| 2247 | ## |
| 2248 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2249 | #SeeAlso translate() rotate() scale() skew() setMatrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2250 | |
| 2251 | ## |
| 2252 | |
| 2253 | # ------------------------------------------------------------------------------ |
| 2254 | |
| 2255 | #Method void setMatrix(const SkMatrix& matrix) |
| 2256 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2257 | #In Matrix |
| 2258 | #Line # sets Matrix ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2259 | Replace Matrix with matrix. |
| 2260 | Unlike concat(), any prior matrix state is overwritten. |
| 2261 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2262 | #Param matrix matrix to copy, replacing existing Matrix ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2263 | |
| 2264 | #Example |
| 2265 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2266 | void draw(SkCanvas* canvas) { |
| 2267 | SkPaint paint; |
| 2268 | canvas->scale(4, 6); |
| 2269 | canvas->drawString("truth", 2, 10, paint); |
| 2270 | SkMatrix matrix; |
| 2271 | matrix.setScale(2.8f, 6); |
| 2272 | canvas->setMatrix(matrix); |
| 2273 | canvas->drawString("consequences", 2, 20, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2274 | } |
| 2275 | ## |
| 2276 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2277 | #SeeAlso resetMatrix concat() translate() rotate() scale() skew() |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2278 | |
| 2279 | ## |
| 2280 | |
| 2281 | # ------------------------------------------------------------------------------ |
| 2282 | |
| 2283 | #Method void resetMatrix() |
| 2284 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2285 | #In Matrix |
| 2286 | #Line # resets Matrix to identity ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2287 | Sets Matrix to the identity matrix. |
| 2288 | Any prior matrix state is overwritten. |
| 2289 | |
| 2290 | #Example |
| 2291 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2292 | void draw(SkCanvas* canvas) { |
| 2293 | SkPaint paint; |
| 2294 | canvas->scale(4, 6); |
| 2295 | canvas->drawString("truth", 2, 10, paint); |
| 2296 | canvas->resetMatrix(); |
| 2297 | canvas->scale(2.8f, 6); |
| 2298 | canvas->drawString("consequences", 2, 20, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2299 | } |
| 2300 | ## |
| 2301 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2302 | #SeeAlso setMatrix concat() translate() rotate() scale() skew() |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2303 | |
| 2304 | ## |
| 2305 | |
| 2306 | # ------------------------------------------------------------------------------ |
| 2307 | |
| 2308 | #Method const SkMatrix& getTotalMatrix() const |
| 2309 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2310 | #In Matrix |
| 2311 | #Line # returns Matrix ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2312 | Returns Matrix. |
| 2313 | This does not account for translation by Device or Surface. |
| 2314 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2315 | #Return Matrix in Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2316 | |
| 2317 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2318 | SkDebugf("isIdentity %s\n", canvas->getTotalMatrix().isIdentity() ? "true" : "false"); |
| 2319 | #StdOut |
| 2320 | isIdentity true |
| 2321 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2322 | ## |
| 2323 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2324 | #SeeAlso setMatrix resetMatrix concat() |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2325 | |
| 2326 | ## |
| 2327 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2328 | #Subtopic Matrix ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2329 | |
| 2330 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2331 | #Subtopic Clip |
| 2332 | #Line # stack of clipping Paths ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2333 | |
| 2334 | 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] | 2335 | stack can be constructed from one or more Path_Contour elements. The |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2336 | Path_Contour may be composed of any number of Path_Verb segments. Each |
| 2337 | Path_Contour forms a closed area; Path_Fill_Type defines the area enclosed |
| 2338 | by Path_Contour. |
| 2339 | |
| 2340 | Clip stack of Path elements successfully restrict the Path area. Each |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2341 | Path is transformed by Matrix, then intersected with or subtracted from the |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2342 | prior Clip to form the replacement Clip. Use SkClipOp::kDifference |
| 2343 | to subtract Path from Clip; use SkClipOp::kIntersect to intersect Path |
| 2344 | with Clip. |
| 2345 | |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2346 | A clipping Path may be Anti_Aliased; if Path, after transformation, is |
| 2347 | composed of horizontal and vertical lines, clearing Anti_Alias allows whole pixels |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2348 | to either be inside or outside the clip. The fastest drawing has a Aliased, |
| 2349 | rectangular clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2350 | |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2351 | 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] | 2352 | that drawing blend partially with the destination along the edge. A rotated |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2353 | rectangular Anti_Aliased clip looks smoother but draws slower. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2354 | |
| 2355 | Clip can combine with Rect and Round_Rect primitives; like |
| 2356 | Path, these are transformed by Matrix before they are combined with Clip. |
| 2357 | |
| 2358 | Clip can combine with Region. Region is assumed to be in Device coordinates |
| 2359 | and is unaffected by Matrix. |
| 2360 | |
| 2361 | #Example |
| 2362 | #Height 90 |
| 2363 | #Description |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2364 | 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] | 2365 | Use an image filter to zoom into the pixels drawn. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2366 | 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] | 2367 | 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] | 2368 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2369 | SkPaint redPaint, scalePaint; |
| 2370 | redPaint.setAntiAlias(true); |
| 2371 | redPaint.setColor(SK_ColorRED); |
| 2372 | canvas->save(); |
| 2373 | for (bool antialias : { false, true } ) { |
| 2374 | canvas->save(); |
| 2375 | canvas->clipRect(SkRect::MakeWH(19.5f, 11.5f), antialias); |
| 2376 | canvas->drawCircle(17, 11, 8, redPaint); |
| 2377 | canvas->restore(); |
| 2378 | canvas->translate(16, 0); |
| 2379 | } |
| 2380 | canvas->restore(); |
| 2381 | SkMatrix matrix; |
| 2382 | matrix.setScale(6, 6); |
| 2383 | scalePaint.setImageFilter( |
| 2384 | SkImageFilter::MakeMatrixFilter(matrix, kNone_SkFilterQuality, nullptr)); |
| 2385 | SkCanvas::SaveLayerRec saveLayerRec( |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2386 | nullptr, &scalePaint, SkCanvas::kInitWithPrevious_SaveLayerFlag); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2387 | canvas->saveLayer(saveLayerRec); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2388 | canvas->restore(); |
| 2389 | ## |
| 2390 | |
| 2391 | #Method void clipRect(const SkRect& rect, SkClipOp op, bool doAntiAlias) |
| 2392 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2393 | #In Clip |
| 2394 | #Line # combines Clip with Rect ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2395 | Replace Clip with the intersection or difference of Clip and rect, |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2396 | 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] | 2397 | before it is combined with Clip. |
| 2398 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 2399 | #Param rect Rect to combine with Clip ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2400 | #Param op Clip_Op to apply to Clip ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2401 | #Param doAntiAlias true if Clip is to be Anti_Aliased ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2402 | |
| 2403 | #Example |
| 2404 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2405 | void draw(SkCanvas* canvas) { |
| 2406 | canvas->rotate(10); |
| 2407 | SkPaint paint; |
| 2408 | paint.setAntiAlias(true); |
| 2409 | for (auto alias: { false, true } ) { |
| 2410 | canvas->save(); |
| 2411 | canvas->clipRect(SkRect::MakeWH(90, 80), SkClipOp::kIntersect, alias); |
| 2412 | canvas->drawCircle(100, 60, 60, paint); |
| 2413 | canvas->restore(); |
| 2414 | canvas->translate(80, 0); |
| 2415 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2416 | } |
| 2417 | ## |
| 2418 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2419 | #SeeAlso clipRRect clipPath clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2420 | |
| 2421 | ## |
| 2422 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2423 | #Method void clipRect(const SkRect& rect, SkClipOp op) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2424 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2425 | #In Clip |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2426 | Replace Clip with the intersection or difference of Clip and rect. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2427 | Resulting Clip is Aliased; pixels are fully contained by the clip. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2428 | rect is transformed by Matrix before it is combined with Clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2429 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 2430 | #Param rect Rect to combine with Clip ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2431 | #Param op Clip_Op to apply to Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2432 | |
| 2433 | #Example |
| 2434 | #Height 192 |
| 2435 | #Width 280 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2436 | void draw(SkCanvas* canvas) { |
| 2437 | SkPaint paint; |
| 2438 | for (SkClipOp op: { SkClipOp::kIntersect, SkClipOp::kDifference } ) { |
| 2439 | canvas->save(); |
| 2440 | canvas->clipRect(SkRect::MakeWH(90, 120), op, false); |
| 2441 | canvas->drawCircle(100, 100, 60, paint); |
| 2442 | canvas->restore(); |
| 2443 | canvas->translate(80, 0); |
| 2444 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2445 | } |
| 2446 | ## |
| 2447 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2448 | #SeeAlso clipRRect clipPath clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2449 | |
| 2450 | ## |
| 2451 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2452 | #Method void clipRect(const SkRect& rect, bool doAntiAlias = false) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2453 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2454 | #In Clip |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2455 | Replace Clip with the intersection of Clip and rect. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2456 | Resulting Clip is Aliased; pixels are fully contained by the clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2457 | rect is transformed by Matrix |
| 2458 | before it is combined with Clip. |
| 2459 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 2460 | #Param rect Rect to combine with Clip ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2461 | #Param doAntiAlias true if Clip is to be Anti_Aliased ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2462 | |
| 2463 | #Example |
| 2464 | #Height 133 |
| 2465 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2466 | A circle drawn in pieces looks uniform when drawn Aliased. |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2467 | 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] | 2468 | visible as a thin pair of lines through the right circle. |
| 2469 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2470 | void draw(SkCanvas* canvas) { |
| 2471 | canvas->clear(SK_ColorWHITE); |
| 2472 | SkPaint paint; |
| 2473 | paint.setAntiAlias(true); |
| 2474 | paint.setColor(0x8055aaff); |
| 2475 | SkRect clipRect = { 0, 0, 87.4f, 87.4f }; |
| 2476 | for (auto alias: { false, true } ) { |
| 2477 | canvas->save(); |
| 2478 | canvas->clipRect(clipRect, SkClipOp::kIntersect, alias); |
| 2479 | canvas->drawCircle(67, 67, 60, paint); |
| 2480 | canvas->restore(); |
| 2481 | canvas->save(); |
| 2482 | canvas->clipRect(clipRect, SkClipOp::kDifference, alias); |
| 2483 | canvas->drawCircle(67, 67, 60, paint); |
| 2484 | canvas->restore(); |
| 2485 | canvas->translate(120, 0); |
| 2486 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2487 | } |
| 2488 | ## |
| 2489 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2490 | #SeeAlso clipRRect clipPath clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2491 | |
| 2492 | ## |
| 2493 | |
| 2494 | #Method void androidFramework_setDeviceClipRestriction(const SkIRect& rect) |
| 2495 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2496 | #In Clip |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2497 | #Line # exists for use by Android framework ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2498 | 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] | 2499 | clipPath and intersect the current clip with the specified rect. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2500 | The maximum clip affects only future clipping operations; it is not retroactive. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2501 | The clip restriction is not recorded in pictures. |
| 2502 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2503 | Pass an empty rect to disable maximum clip. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2504 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2505 | #Private |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 2506 | This private API is for use by Android framework only. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2507 | ## |
| 2508 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2509 | #Param rect maximum allowed clip in device coordinates |
Cary Clark | 579985c | 2017-07-31 11:48:27 -0400 | [diff] [blame] | 2510 | #Param ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2511 | |
| 2512 | ## |
| 2513 | |
| 2514 | #Method void clipRRect(const SkRRect& rrect, SkClipOp op, bool doAntiAlias) |
| 2515 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2516 | #In Clip |
| 2517 | #Line # combines Clip with Round_Rect ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2518 | Replace Clip with the intersection or difference of Clip and rrect, |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2519 | with an Aliased or Anti_Aliased clip edge. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2520 | rrect is transformed by Matrix |
| 2521 | before it is combined with Clip. |
| 2522 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2523 | #Param rrect Round_Rect to combine with Clip ## |
| 2524 | #Param op Clip_Op to apply to Clip ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2525 | #Param doAntiAlias true if Clip is to be Anti_Aliased ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2526 | |
| 2527 | #Example |
| 2528 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2529 | void draw(SkCanvas* canvas) { |
| 2530 | canvas->clear(SK_ColorWHITE); |
| 2531 | SkPaint paint; |
| 2532 | paint.setAntiAlias(true); |
| 2533 | paint.setColor(0x8055aaff); |
| 2534 | SkRRect oval; |
| 2535 | oval.setOval({10, 20, 90, 100}); |
| 2536 | canvas->clipRRect(oval, SkClipOp::kIntersect, true); |
| 2537 | canvas->drawCircle(70, 100, 60, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2538 | } |
| 2539 | ## |
| 2540 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2541 | #SeeAlso clipRect clipPath clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2542 | |
| 2543 | ## |
| 2544 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2545 | #Method void clipRRect(const SkRRect& rrect, SkClipOp op) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2546 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2547 | #In Clip |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2548 | Replace Clip with the intersection or difference of Clip and rrect. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2549 | Resulting Clip is Aliased; pixels are fully contained by the clip. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2550 | rrect is transformed by Matrix before it is combined with Clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2551 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2552 | #Param rrect Round_Rect to combine with Clip ## |
| 2553 | #Param op Clip_Op to apply to Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2554 | |
| 2555 | #Example |
| 2556 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2557 | void draw(SkCanvas* canvas) { |
| 2558 | SkPaint paint; |
| 2559 | paint.setColor(0x8055aaff); |
| 2560 | auto oval = SkRRect::MakeOval({10, 20, 90, 100}); |
| 2561 | canvas->clipRRect(oval, SkClipOp::kIntersect); |
| 2562 | canvas->drawCircle(70, 100, 60, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2563 | } |
| 2564 | ## |
| 2565 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2566 | #SeeAlso clipRect clipPath clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2567 | |
| 2568 | ## |
| 2569 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2570 | #Method void clipRRect(const SkRRect& rrect, bool doAntiAlias = false) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2571 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2572 | #In Clip |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2573 | Replace Clip with the intersection of Clip and rrect, |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2574 | with an Aliased or Anti_Aliased clip edge. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2575 | rrect is transformed by Matrix before it is combined with Clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2576 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2577 | #Param rrect Round_Rect to combine with Clip ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2578 | #Param doAntiAlias true if Clip is to be Anti_Aliased ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2579 | |
| 2580 | #Example |
| 2581 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2582 | void draw(SkCanvas* canvas) { |
| 2583 | SkPaint paint; |
| 2584 | paint.setAntiAlias(true); |
| 2585 | auto oval = SkRRect::MakeRectXY({10, 20, 90, 100}, 9, 13); |
| 2586 | canvas->clipRRect(oval, true); |
| 2587 | canvas->drawCircle(70, 100, 60, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2588 | } |
| 2589 | ## |
| 2590 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2591 | #SeeAlso clipRect clipPath clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2592 | |
| 2593 | ## |
| 2594 | |
| 2595 | #Method void clipPath(const SkPath& path, SkClipOp op, bool doAntiAlias) |
| 2596 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2597 | #In Clip |
| 2598 | #Line # combines Clip with Path ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2599 | Replace Clip with the intersection or difference of Clip and path, |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2600 | 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] | 2601 | describes the area inside or outside its contours; and if Path_Contour overlaps |
| 2602 | 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] | 2603 | path is transformed by Matrix before it is combined with Clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2604 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2605 | #Param path Path to combine with Clip ## |
| 2606 | #Param op Clip_Op to apply to Clip ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2607 | #Param doAntiAlias true if Clip is to be Anti_Aliased ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2608 | |
| 2609 | #Example |
| 2610 | #Description |
| 2611 | Top figure uses SkPath::kInverseWinding_FillType and SkClipOp::kDifference; |
| 2612 | area outside clip is subtracted from circle. |
| 2613 | |
| 2614 | Bottom figure uses SkPath::kWinding_FillType and SkClipOp::kIntersect; |
| 2615 | area inside clip is intersected with circle. |
| 2616 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2617 | void draw(SkCanvas* canvas) { |
| 2618 | SkPaint paint; |
| 2619 | paint.setAntiAlias(true); |
| 2620 | SkPath path; |
| 2621 | path.addRect({20, 30, 100, 110}); |
| 2622 | path.setFillType(SkPath::kInverseWinding_FillType); |
| 2623 | canvas->save(); |
| 2624 | canvas->clipPath(path, SkClipOp::kDifference, false); |
| 2625 | canvas->drawCircle(70, 100, 60, paint); |
| 2626 | canvas->restore(); |
| 2627 | canvas->translate(100, 100); |
| 2628 | path.setFillType(SkPath::kWinding_FillType); |
| 2629 | canvas->clipPath(path, SkClipOp::kIntersect, false); |
| 2630 | canvas->drawCircle(70, 100, 60, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2631 | } |
| 2632 | ## |
| 2633 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2634 | #SeeAlso clipRect clipRRect clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2635 | |
| 2636 | ## |
| 2637 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2638 | #Method void clipPath(const SkPath& path, SkClipOp op) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2639 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2640 | #In Clip |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2641 | Replace Clip with the intersection or difference of Clip and path. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2642 | Resulting Clip is Aliased; pixels are fully contained by the clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2643 | Path_Fill_Type determines if path |
| 2644 | describes the area inside or outside its contours; and if Path_Contour overlaps |
| 2645 | itself or another Path_Contour, whether the overlaps form part of the area. |
| 2646 | path is transformed by Matrix |
| 2647 | before it is combined with Clip. |
| 2648 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2649 | #Param path Path to combine with Clip ## |
| 2650 | #Param op Clip_Op to apply to Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2651 | |
| 2652 | #Example |
| 2653 | #Description |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2654 | 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] | 2655 | SkPath::kWinding_FillType, the overlap is included. Set to |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2656 | SkPath::kEvenOdd_FillType, the overlap is excluded and forms a hole. |
| 2657 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2658 | void draw(SkCanvas* canvas) { |
| 2659 | SkPaint paint; |
| 2660 | paint.setAntiAlias(true); |
| 2661 | SkPath path; |
| 2662 | path.addRect({20, 15, 100, 95}); |
| 2663 | path.addRect({50, 65, 130, 135}); |
| 2664 | path.setFillType(SkPath::kWinding_FillType); |
| 2665 | canvas->save(); |
| 2666 | canvas->clipPath(path, SkClipOp::kIntersect); |
| 2667 | canvas->drawCircle(70, 85, 60, paint); |
| 2668 | canvas->restore(); |
| 2669 | canvas->translate(100, 100); |
| 2670 | path.setFillType(SkPath::kEvenOdd_FillType); |
| 2671 | canvas->clipPath(path, SkClipOp::kIntersect); |
| 2672 | canvas->drawCircle(70, 85, 60, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2673 | } |
| 2674 | ## |
| 2675 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2676 | #SeeAlso clipRect clipRRect clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2677 | |
| 2678 | ## |
| 2679 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2680 | #Method void clipPath(const SkPath& path, bool doAntiAlias = false) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2681 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2682 | #In Clip |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2683 | Replace Clip with the intersection of Clip and path. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2684 | Resulting Clip is Aliased; pixels are fully contained by the clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2685 | Path_Fill_Type determines if path |
| 2686 | describes the area inside or outside its contours; and if Path_Contour overlaps |
| 2687 | 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] | 2688 | path is transformed by Matrix before it is combined with Clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2689 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2690 | #Param path Path to combine with Clip ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2691 | #Param doAntiAlias true if Clip is to be Anti_Aliased ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2692 | |
| 2693 | #Example |
| 2694 | #Height 212 |
| 2695 | #Description |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2696 | Clip loops over itself covering its center twice. When clip Path_Fill_Type |
| 2697 | is set to SkPath::kWinding_FillType, the overlap is included. Set to |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2698 | SkPath::kEvenOdd_FillType, the overlap is excluded and forms a hole. |
| 2699 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2700 | void draw(SkCanvas* canvas) { |
| 2701 | SkPaint paint; |
| 2702 | paint.setAntiAlias(true); |
| 2703 | SkPath path; |
| 2704 | SkPoint poly[] = {{20, 20}, { 80, 20}, { 80, 80}, {40, 80}, |
| 2705 | {40, 40}, {100, 40}, {100, 100}, {20, 100}}; |
| 2706 | path.addPoly(poly, SK_ARRAY_COUNT(poly), true); |
| 2707 | path.setFillType(SkPath::kWinding_FillType); |
| 2708 | canvas->save(); |
| 2709 | canvas->clipPath(path, SkClipOp::kIntersect); |
| 2710 | canvas->drawCircle(50, 50, 45, paint); |
| 2711 | canvas->restore(); |
| 2712 | canvas->translate(100, 100); |
| 2713 | path.setFillType(SkPath::kEvenOdd_FillType); |
| 2714 | canvas->clipPath(path, SkClipOp::kIntersect); |
| 2715 | canvas->drawCircle(50, 50, 45, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2716 | } |
| 2717 | ## |
| 2718 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2719 | #SeeAlso clipRect clipRRect clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2720 | |
| 2721 | ## |
| 2722 | |
| 2723 | # ------------------------------------------------------------------------------ |
| 2724 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2725 | #Method void setAllowSimplifyClip(bool allow) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2726 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2727 | #In Clip |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2728 | #Experimental testing |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2729 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2730 | Set to simplify clip stack using PathOps. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2731 | |
| 2732 | ## |
| 2733 | |
| 2734 | # ------------------------------------------------------------------------------ |
| 2735 | |
| 2736 | #Method void clipRegion(const SkRegion& deviceRgn, SkClipOp op = SkClipOp::kIntersect) |
| 2737 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2738 | #In Clip |
| 2739 | #Line # combines Clip with Region ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2740 | Replace Clip with the intersection or difference of Clip and Region deviceRgn. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2741 | Resulting Clip is Aliased; pixels are fully contained by the clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2742 | deviceRgn is unaffected by Matrix. |
| 2743 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2744 | #Param deviceRgn Region to combine with Clip ## |
| 2745 | #Param op Clip_Op to apply to Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2746 | |
| 2747 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2748 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2749 | region is unaffected by canvas rotation; iRect is affected by canvas rotation. |
| 2750 | 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] | 2751 | aligns to pixel boundaries. |
| 2752 | ## |
| 2753 | void draw(SkCanvas* canvas) { |
| 2754 | SkPaint paint; |
| 2755 | paint.setAntiAlias(true); |
| 2756 | SkIRect iRect = {30, 40, 120, 130 }; |
| 2757 | SkRegion region(iRect); |
| 2758 | canvas->rotate(10); |
| 2759 | canvas->save(); |
| 2760 | canvas->clipRegion(region, SkClipOp::kIntersect); |
| 2761 | canvas->drawCircle(50, 50, 45, paint); |
| 2762 | canvas->restore(); |
| 2763 | canvas->translate(100, 100); |
| 2764 | canvas->clipRect(SkRect::Make(iRect), SkClipOp::kIntersect); |
| 2765 | canvas->drawCircle(50, 50, 45, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2766 | } |
| 2767 | ## |
| 2768 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2769 | #SeeAlso clipRect clipRRect clipPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2770 | |
| 2771 | ## |
| 2772 | |
| 2773 | #Method bool quickReject(const SkRect& rect) const |
| 2774 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2775 | #In Clip |
| 2776 | #Line # returns if Rect is outside Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2777 | Return true if Rect rect, transformed by Matrix, can be quickly determined to be |
| 2778 | outside of Clip. May return false even though rect is outside of Clip. |
| 2779 | |
| 2780 | Use to check if an area to be drawn is clipped out, to skip subsequent draw calls. |
| 2781 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2782 | #Param rect Rect to compare with Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2783 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2784 | #Return true if rect, transformed by Matrix, does not intersect Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2785 | |
| 2786 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2787 | void draw(SkCanvas* canvas) { |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2788 | SkRect testRect = {30, 30, 120, 129 }; |
| 2789 | SkRect clipRect = {30, 130, 120, 230 }; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2790 | canvas->save(); |
| 2791 | canvas->clipRect(clipRect); |
| 2792 | SkDebugf("quickReject %s\n", canvas->quickReject(testRect) ? "true" : "false"); |
| 2793 | canvas->restore(); |
| 2794 | canvas->rotate(10); |
| 2795 | canvas->clipRect(clipRect); |
| 2796 | SkDebugf("quickReject %s\n", canvas->quickReject(testRect) ? "true" : "false"); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2797 | } |
| 2798 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2799 | quickReject true |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2800 | quickReject false |
| 2801 | ## |
| 2802 | ## |
| 2803 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2804 | #SeeAlso getLocalClipBounds getTotalMatrix SkBitmap::drawsNothing |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2805 | |
| 2806 | ## |
| 2807 | |
| 2808 | #Method bool quickReject(const SkPath& path) const |
| 2809 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2810 | #In Clip |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2811 | Return true if path, transformed by Matrix, can be quickly determined to be |
| 2812 | outside of Clip. May return false even though path is outside of Clip. |
| 2813 | |
| 2814 | Use to check if an area to be drawn is clipped out, to skip subsequent draw calls. |
| 2815 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2816 | #Param path Path to compare with Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2817 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2818 | #Return true if path, transformed by Matrix, does not intersect Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2819 | |
| 2820 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2821 | void draw(SkCanvas* canvas) { |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2822 | SkPoint testPoints[] = {{30, 30}, {120, 30}, {120, 129} }; |
| 2823 | SkPoint clipPoints[] = {{30, 130}, {120, 130}, {120, 230} }; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2824 | SkPath testPath, clipPath; |
| 2825 | testPath.addPoly(testPoints, SK_ARRAY_COUNT(testPoints), true); |
| 2826 | clipPath.addPoly(clipPoints, SK_ARRAY_COUNT(clipPoints), true); |
| 2827 | canvas->save(); |
| 2828 | canvas->clipPath(clipPath); |
| 2829 | SkDebugf("quickReject %s\n", canvas->quickReject(testPath) ? "true" : "false"); |
| 2830 | canvas->restore(); |
| 2831 | canvas->rotate(10); |
| 2832 | canvas->clipPath(clipPath); |
| 2833 | SkDebugf("quickReject %s\n", canvas->quickReject(testPath) ? "true" : "false"); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2834 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2835 | quickReject true |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2836 | quickReject false |
| 2837 | ## |
| 2838 | } |
| 2839 | ## |
| 2840 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2841 | #SeeAlso getLocalClipBounds getTotalMatrix SkBitmap::drawsNothing |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2842 | |
| 2843 | ## |
| 2844 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2845 | #Method SkRect getLocalClipBounds() const |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2846 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2847 | #In Clip |
| 2848 | #Line # returns Clip bounds in source coordinates ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2849 | Return bounds of Clip, transformed by inverse of Matrix. If Clip is empty, |
| 2850 | return SkRect::MakeEmpty, where all Rect sides equal zero. |
| 2851 | |
| 2852 | 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] | 2853 | is Anti_Aliased. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2854 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2855 | #Return bounds of Clip in local coordinates ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2856 | |
| 2857 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2858 | #Description |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2859 | Initial bounds is device bounds outset by 1 on all sides. |
| 2860 | Clipped bounds is clipPath bounds outset by 1 on all sides. |
| 2861 | Scaling the canvas by two in x and y scales the local bounds by 1/2 in x and y. |
| 2862 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2863 | SkCanvas local(256, 256); |
| 2864 | canvas = &local; |
| 2865 | SkRect bounds = canvas->getLocalClipBounds(); |
| 2866 | SkDebugf("left:%g top:%g right:%g bottom:%g\n", |
| 2867 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2868 | SkPoint clipPoints[] = {{30, 130}, {120, 130}, {120, 230} }; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2869 | SkPath clipPath; |
| 2870 | clipPath.addPoly(clipPoints, SK_ARRAY_COUNT(clipPoints), true); |
| 2871 | canvas->clipPath(clipPath); |
| 2872 | bounds = canvas->getLocalClipBounds(); |
| 2873 | SkDebugf("left:%g top:%g right:%g bottom:%g\n", |
| 2874 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
| 2875 | canvas->scale(2, 2); |
| 2876 | bounds = canvas->getLocalClipBounds(); |
| 2877 | SkDebugf("left:%g top:%g right:%g bottom:%g\n", |
| 2878 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
| 2879 | #StdOut |
| 2880 | left:-1 top:-1 right:257 bottom:257 |
| 2881 | left:29 top:129 right:121 bottom:231 |
| 2882 | left:14.5 top:64.5 right:60.5 bottom:115.5 |
| 2883 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2884 | ## |
| 2885 | |
| 2886 | # local canvas in example works around bug in fiddle ## |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2887 | #Bug 6524 |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2888 | #SeeAlso getDeviceClipBounds getBaseLayerSize quickReject |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2889 | |
| 2890 | ## |
| 2891 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2892 | #Method bool getLocalClipBounds(SkRect* bounds) const |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2893 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2894 | #In Clip |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2895 | Return bounds of Clip, transformed by inverse of Matrix. If Clip is empty, |
| 2896 | return false, and set bounds to SkRect::MakeEmpty, where all Rect sides equal zero. |
| 2897 | |
| 2898 | 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] | 2899 | is Anti_Aliased. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2900 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2901 | #Param bounds Rect of Clip in local coordinates ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2902 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2903 | #Return true if Clip bounds is not empty ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2904 | |
| 2905 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2906 | void draw(SkCanvas* canvas) { |
| 2907 | SkCanvas local(256, 256); |
| 2908 | canvas = &local; |
| 2909 | SkRect bounds; |
| 2910 | SkDebugf("local bounds empty = %s\n", canvas->getLocalClipBounds(&bounds) |
| 2911 | ? "false" : "true"); |
| 2912 | SkPath path; |
| 2913 | canvas->clipPath(path); |
| 2914 | SkDebugf("local bounds empty = %s\n", canvas->getLocalClipBounds(&bounds) |
| 2915 | ? "false" : "true"); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2916 | } |
| 2917 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2918 | local bounds empty = false |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2919 | local bounds empty = true |
| 2920 | ## |
| 2921 | ## |
| 2922 | |
| 2923 | # local canvas in example works around bug in fiddle ## |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2924 | #Bug 6524 |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2925 | #SeeAlso getDeviceClipBounds getBaseLayerSize quickReject |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2926 | |
| 2927 | ## |
| 2928 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2929 | #Method SkIRect getDeviceClipBounds() const |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2930 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2931 | #In Clip |
| 2932 | #Line # returns IRect bounds of Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2933 | Return IRect bounds of Clip, unaffected by Matrix. If Clip is empty, |
| 2934 | return SkRect::MakeEmpty, where all Rect sides equal zero. |
| 2935 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2936 | Unlike getLocalClipBounds, returned IRect is not outset. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2937 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2938 | #Return bounds of Clip in Device coordinates ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2939 | |
| 2940 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2941 | void draw(SkCanvas* canvas) { |
| 2942 | #Description |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2943 | Initial bounds is device bounds, not outset. |
| 2944 | Clipped bounds is clipPath bounds, not outset. |
| 2945 | Scaling the canvas by 1/2 in x and y scales the device bounds by 1/2 in x and y. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2946 | ## |
| 2947 | SkCanvas device(256, 256); |
| 2948 | canvas = &device; |
| 2949 | SkIRect bounds = canvas->getDeviceClipBounds(); |
| 2950 | SkDebugf("left:%d top:%d right:%d bottom:%d\n", |
| 2951 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2952 | SkPoint clipPoints[] = {{30, 130}, {120, 130}, {120, 230} }; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2953 | SkPath clipPath; |
| 2954 | clipPath.addPoly(clipPoints, SK_ARRAY_COUNT(clipPoints), true); |
| 2955 | canvas->save(); |
| 2956 | canvas->clipPath(clipPath); |
| 2957 | bounds = canvas->getDeviceClipBounds(); |
| 2958 | SkDebugf("left:%d top:%d right:%d bottom:%d\n", |
| 2959 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
| 2960 | canvas->restore(); |
| 2961 | canvas->scale(1.f/2, 1.f/2); |
| 2962 | canvas->clipPath(clipPath); |
| 2963 | bounds = canvas->getDeviceClipBounds(); |
| 2964 | SkDebugf("left:%d top:%d right:%d bottom:%d\n", |
| 2965 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2966 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2967 | left:0 top:0 right:256 bottom:256 |
| 2968 | left:30 top:130 right:120 bottom:230 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2969 | left:15 top:65 right:60 bottom:115 |
| 2970 | ## |
| 2971 | } |
| 2972 | ## |
| 2973 | |
| 2974 | #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] | 2975 | #SeeAlso getLocalClipBounds getBaseLayerSize quickReject |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2976 | |
| 2977 | # device canvas in example works around bug in fiddle ## |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2978 | #Bug 6524 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2979 | |
| 2980 | ## |
| 2981 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2982 | #Method bool getDeviceClipBounds(SkIRect* bounds) const |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2983 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2984 | #In Clip |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2985 | Return IRect bounds of Clip, unaffected by Matrix. If Clip is empty, |
| 2986 | return false, and set bounds to SkRect::MakeEmpty, where all Rect sides equal zero. |
| 2987 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2988 | Unlike getLocalClipBounds, bounds is not outset. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2989 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2990 | #Param bounds Rect of Clip in device coordinates ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2991 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2992 | #Return true if Clip bounds is not empty ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2993 | |
| 2994 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2995 | void draw(SkCanvas* canvas) { |
| 2996 | SkIRect bounds; |
| 2997 | SkDebugf("device bounds empty = %s\n", canvas->getDeviceClipBounds(&bounds) |
| 2998 | ? "false" : "true"); |
| 2999 | SkPath path; |
| 3000 | canvas->clipPath(path); |
| 3001 | SkDebugf("device bounds empty = %s\n", canvas->getDeviceClipBounds(&bounds) |
| 3002 | ? "false" : "true"); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3003 | } |
| 3004 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3005 | device bounds empty = false |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3006 | device bounds empty = true |
| 3007 | ## |
| 3008 | ## |
| 3009 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3010 | #SeeAlso getLocalClipBounds getBaseLayerSize quickReject |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3011 | |
| 3012 | ## |
| 3013 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3014 | #Subtopic Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3015 | |
| 3016 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3017 | #Subtopic Draw |
| 3018 | #Populate |
| 3019 | #Line # draws into Canvas ## |
| 3020 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3021 | |
| 3022 | #Method void drawColor(SkColor color, SkBlendMode mode = SkBlendMode::kSrcOver) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3023 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3024 | #Line # fills Clip with Color and Blend_Mode ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3025 | Fill Clip with Color color. |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 3026 | mode determines how ARGB is combined with destination. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3027 | |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 3028 | #Param color Unpremultiplied ARGB ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3029 | #Param mode SkBlendMode used to combine source color and destination ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3030 | |
| 3031 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3032 | canvas->drawColor(SK_ColorRED); |
| 3033 | canvas->clipRect(SkRect::MakeWH(150, 150)); |
| 3034 | canvas->drawColor(SkColorSetARGB(0x80, 0x00, 0xFF, 0x00), SkBlendMode::kPlus); |
| 3035 | canvas->clipRect(SkRect::MakeWH(75, 75)); |
| 3036 | canvas->drawColor(SkColorSetARGB(0x80, 0x00, 0x00, 0xFF), SkBlendMode::kPlus); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3037 | ## |
| 3038 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3039 | #SeeAlso clear SkBitmap::erase drawPaint |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3040 | |
| 3041 | ## |
| 3042 | |
| 3043 | # ------------------------------------------------------------------------------ |
| 3044 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3045 | #Method void clear(SkColor color) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3046 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3047 | #Line # fills Clip with Color ## |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3048 | Fill Clip with Color color using SkBlendMode::kSrc. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3049 | This has the effect of replacing all pixels contained by Clip with color. |
| 3050 | |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 3051 | #Param color Unpremultiplied ARGB ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3052 | |
| 3053 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3054 | void draw(SkCanvas* canvas) { |
| 3055 | canvas->save(); |
| 3056 | canvas->clipRect(SkRect::MakeWH(256, 128)); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3057 | canvas->clear(SkColorSetARGB(0x80, 0xFF, 0x00, 0x00)); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3058 | canvas->restore(); |
| 3059 | canvas->save(); |
| 3060 | canvas->clipRect(SkRect::MakeWH(150, 192)); |
| 3061 | canvas->clear(SkColorSetARGB(0x80, 0x00, 0xFF, 0x00)); |
| 3062 | canvas->restore(); |
| 3063 | canvas->clipRect(SkRect::MakeWH(75, 256)); |
| 3064 | canvas->clear(SkColorSetARGB(0x80, 0x00, 0x00, 0xFF)); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3065 | } |
| 3066 | ## |
| 3067 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3068 | #SeeAlso drawColor SkBitmap::erase drawPaint |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3069 | |
| 3070 | ## |
| 3071 | |
| 3072 | # ------------------------------------------------------------------------------ |
| 3073 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3074 | #Method void discard() |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3075 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3076 | #Line # makes Canvas contents undefined ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3077 | Make Canvas contents undefined. Subsequent calls that read Canvas pixels, |
| 3078 | such as drawing with SkBlendMode, return undefined results. discard() does |
| 3079 | not change Clip or Matrix. |
| 3080 | |
| 3081 | discard() may do nothing, depending on the implementation of Surface or Device |
| 3082 | that created Canvas. |
| 3083 | |
| 3084 | discard() allows optimized performance on subsequent draws by removing |
| 3085 | cached data associated with Surface or Device. |
| 3086 | It is not necessary to call discard() once done with Canvas; |
| 3087 | any cached data is deleted when owning Surface or Device is deleted. |
| 3088 | |
| 3089 | #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] | 3090 | #SeeAlso flush() SkSurface::prepareForExternalIO GrContext::abandonContext |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3091 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3092 | #NoExample |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3093 | ## |
| 3094 | |
| 3095 | ## |
| 3096 | |
| 3097 | # ------------------------------------------------------------------------------ |
| 3098 | |
| 3099 | #Method void drawPaint(const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3100 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3101 | #Line # fills Clip with Paint ## |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 3102 | Fill Clip with Paint paint. Paint components Mask_Filter, Shader, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3103 | Color_Filter, Image_Filter, and Blend_Mode affect drawing; |
| 3104 | Path_Effect in paint is ignored. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3105 | |
| 3106 | # can Path_Effect in paint ever alter drawPaint? |
| 3107 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3108 | #Param paint graphics state used to fill Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3109 | |
| 3110 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3111 | void draw(SkCanvas* canvas) { |
| 3112 | SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE }; |
| 3113 | SkScalar pos[] = { 0, SK_Scalar1/2, SK_Scalar1 }; |
| 3114 | SkPaint paint; |
| 3115 | paint.setShader(SkGradientShader::MakeSweep(256, 256, colors, pos, SK_ARRAY_COUNT(colors))); |
| 3116 | canvas->drawPaint(paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3117 | } |
| 3118 | ## |
| 3119 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3120 | #SeeAlso clear drawColor SkBitmap::erase |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3121 | |
| 3122 | ## |
| 3123 | |
| 3124 | # ------------------------------------------------------------------------------ |
| 3125 | |
| 3126 | #Enum PointMode |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3127 | #Line # sets drawPoints options ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3128 | |
| 3129 | #Code |
| 3130 | enum PointMode { |
| 3131 | kPoints_PointMode, |
| 3132 | kLines_PointMode, |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 3133 | kPolygon_PointMode, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3134 | }; |
| 3135 | ## |
| 3136 | |
| 3137 | Selects if an array of points are drawn as discrete points, as lines, or as |
| 3138 | an open polygon. |
| 3139 | |
| 3140 | #Const kPoints_PointMode 0 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3141 | #Line # draw each point separately ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3142 | ## |
| 3143 | |
| 3144 | #Const kLines_PointMode 1 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3145 | #Line # draw each pair of points as a line segment ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3146 | ## |
| 3147 | |
| 3148 | #Const kPolygon_PointMode 2 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3149 | #Line # draw the array of points as a open polygon ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3150 | ## |
| 3151 | |
| 3152 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3153 | #Description |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3154 | The upper left corner shows three squares when drawn as points. |
| 3155 | The upper right corner shows one line; when drawn as lines, two points are required per line. |
| 3156 | The lower right corner shows two lines; when draw as polygon, no miter is drawn at the corner. |
| 3157 | The lower left corner shows two lines with a miter when path contains polygon. |
| 3158 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3159 | void draw(SkCanvas* canvas) { |
| 3160 | SkPaint paint; |
| 3161 | paint.setStyle(SkPaint::kStroke_Style); |
| 3162 | paint.setStrokeWidth(10); |
| 3163 | SkPoint points[] = {{64, 32}, {96, 96}, {32, 96}}; |
| 3164 | canvas->drawPoints(SkCanvas::kPoints_PointMode, 3, points, paint); |
| 3165 | canvas->translate(128, 0); |
| 3166 | canvas->drawPoints(SkCanvas::kLines_PointMode, 3, points, paint); |
| 3167 | canvas->translate(0, 128); |
| 3168 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, 3, points, paint); |
| 3169 | SkPath path; |
| 3170 | path.addPoly(points, 3, false); |
| 3171 | canvas->translate(-128, 0); |
| 3172 | canvas->drawPath(path, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3173 | } |
| 3174 | ## |
| 3175 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3176 | #SeeAlso drawLine drawPoint drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3177 | |
| 3178 | ## |
| 3179 | |
| 3180 | # ------------------------------------------------------------------------------ |
| 3181 | |
| 3182 | #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] | 3183 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3184 | #Line # draws array as points, lines, polygon ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3185 | Draw pts using Clip, Matrix and Paint paint. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3186 | 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] | 3187 | mode may be one of: kPoints_PointMode, kLines_PointMode, or kPolygon_PointMode. |
| 3188 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3189 | If mode is kPoints_PointMode, the shape of point drawn depends on paint |
| 3190 | Paint_Stroke_Cap. If paint is set to SkPaint::kRound_Cap, each point draws a |
| 3191 | circle of diameter Paint_Stroke_Width. If paint is set to SkPaint::kSquare_Cap |
| 3192 | or SkPaint::kButt_Cap, each point draws a square of width and height |
| 3193 | Paint_Stroke_Width. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3194 | |
| 3195 | If mode is kLines_PointMode, each pair of points draws a line segment. |
| 3196 | 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] | 3197 | the final point is ignored. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3198 | |
| 3199 | If mode is kPolygon_PointMode, each adjacent pair of points draws a line segment. |
| 3200 | count minus one lines are drawn; the first and last point are used once. |
| 3201 | |
| 3202 | Each line segment respects paint Paint_Stroke_Cap and Paint_Stroke_Width. |
| 3203 | Paint_Style is ignored, as if were set to SkPaint::kStroke_Style. |
| 3204 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3205 | Always draws each element one at a time; is not affected by |
| 3206 | 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] | 3207 | and lines before drawing. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3208 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 3209 | #Param mode whether pts draws points or lines ## |
| 3210 | #Param count number of points in the array ## |
| 3211 | #Param pts array of points to draw ## |
| 3212 | #Param paint stroke, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3213 | |
| 3214 | #Example |
| 3215 | #Height 200 |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3216 | #Description |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3217 | #List |
| 3218 | # The first column draws points. ## |
| 3219 | # The second column draws points as lines. ## |
| 3220 | # The third column draws points as a polygon. ## |
| 3221 | # The fourth column draws points as a polygonal path. ## |
| 3222 | # The first row uses a round cap and round join. ## |
| 3223 | # The second row uses a square cap and a miter join. ## |
| 3224 | # The third row uses a butt cap and a bevel join. ## |
| 3225 | ## |
| 3226 | The transparent color makes multiple line draws visible; |
| 3227 | the path is drawn all at once. |
| 3228 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3229 | void draw(SkCanvas* canvas) { |
| 3230 | SkPaint paint; |
| 3231 | paint.setAntiAlias(true); |
| 3232 | paint.setStyle(SkPaint::kStroke_Style); |
| 3233 | paint.setStrokeWidth(10); |
| 3234 | paint.setColor(0x80349a45); |
| 3235 | const SkPoint points[] = {{32, 16}, {48, 48}, {16, 32}}; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3236 | const SkPaint::Join join[] = { SkPaint::kRound_Join, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3237 | SkPaint::kMiter_Join, |
| 3238 | SkPaint::kBevel_Join }; |
| 3239 | int joinIndex = 0; |
| 3240 | SkPath path; |
| 3241 | path.addPoly(points, 3, false); |
| 3242 | for (const auto cap : { SkPaint::kRound_Cap, SkPaint::kSquare_Cap, SkPaint::kButt_Cap } ) { |
| 3243 | paint.setStrokeCap(cap); |
| 3244 | paint.setStrokeJoin(join[joinIndex++]); |
| 3245 | for (const auto mode : { SkCanvas::kPoints_PointMode, |
| 3246 | SkCanvas::kLines_PointMode, |
| 3247 | SkCanvas::kPolygon_PointMode } ) { |
| 3248 | canvas->drawPoints(mode, 3, points, paint); |
| 3249 | canvas->translate(64, 0); |
| 3250 | } |
| 3251 | canvas->drawPath(path, paint); |
| 3252 | canvas->translate(-192, 64); |
| 3253 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3254 | } |
| 3255 | ## |
| 3256 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3257 | #SeeAlso drawLine drawPoint drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3258 | |
| 3259 | ## |
| 3260 | |
| 3261 | # ------------------------------------------------------------------------------ |
| 3262 | |
| 3263 | #Method void drawPoint(SkScalar x, SkScalar y, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3264 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3265 | #Line # draws point at (x, y) position ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3266 | Draw point at (x, y) using Clip, Matrix and Paint paint. |
| 3267 | |
| 3268 | The shape of point drawn depends on paint Paint_Stroke_Cap. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3269 | 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] | 3270 | 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] | 3271 | draw a square of width and height Paint_Stroke_Width. |
| 3272 | Paint_Style is ignored, as if were set to SkPaint::kStroke_Style. |
| 3273 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3274 | #Param x left edge of circle or square ## |
| 3275 | #Param y top edge of circle or square ## |
| 3276 | #Param paint stroke, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3277 | |
| 3278 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3279 | void draw(SkCanvas* canvas) { |
| 3280 | SkPaint paint; |
| 3281 | paint.setAntiAlias(true); |
| 3282 | paint.setColor(0x80349a45); |
| 3283 | paint.setStyle(SkPaint::kStroke_Style); |
| 3284 | paint.setStrokeWidth(100); |
| 3285 | paint.setStrokeCap(SkPaint::kRound_Cap); |
| 3286 | canvas->scale(1, 1.2f); |
| 3287 | canvas->drawPoint(64, 96, paint); |
| 3288 | canvas->scale(.6f, .8f); |
| 3289 | paint.setColor(SK_ColorWHITE); |
| 3290 | canvas->drawPoint(106, 120, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3291 | } |
| 3292 | ## |
| 3293 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3294 | #SeeAlso drawPoints drawCircle drawRect drawLine drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3295 | |
| 3296 | ## |
| 3297 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3298 | #Method void drawPoint(SkPoint p, const SkPaint& paint) |
| 3299 | |
| 3300 | Draw point p using Clip, Matrix and Paint paint. |
| 3301 | |
| 3302 | The shape of point drawn depends on paint Paint_Stroke_Cap. |
| 3303 | 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] | 3304 | 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] | 3305 | draw a square of width and height Paint_Stroke_Width. |
| 3306 | Paint_Style is ignored, as if were set to SkPaint::kStroke_Style. |
| 3307 | |
| 3308 | #Param p top-left edge of circle or square ## |
| 3309 | #Param paint stroke, blend, color, and so on, used to draw ## |
| 3310 | |
| 3311 | #Example |
| 3312 | void draw(SkCanvas* canvas) { |
| 3313 | SkPaint paint; |
| 3314 | paint.setAntiAlias(true); |
| 3315 | paint.setColor(0x80349a45); |
| 3316 | paint.setStyle(SkPaint::kStroke_Style); |
| 3317 | paint.setStrokeWidth(100); |
| 3318 | paint.setStrokeCap(SkPaint::kSquare_Cap); |
| 3319 | canvas->scale(1, 1.2f); |
| 3320 | canvas->drawPoint({64, 96}, paint); |
| 3321 | canvas->scale(.6f, .8f); |
| 3322 | paint.setColor(SK_ColorWHITE); |
| 3323 | canvas->drawPoint(106, 120, paint); |
| 3324 | } |
| 3325 | ## |
| 3326 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3327 | #SeeAlso drawPoints drawCircle drawRect drawLine drawPath |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3328 | |
| 3329 | ## |
| 3330 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3331 | # ------------------------------------------------------------------------------ |
| 3332 | |
| 3333 | #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] | 3334 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3335 | #Line # draws line segment between two points ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3336 | Draws line segment from (x0, y0) to (x1, y1) using Clip, Matrix, and Paint paint. |
| 3337 | In paint: Paint_Stroke_Width describes the line thickness; |
| 3338 | Paint_Stroke_Cap draws the end rounded or square; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3339 | Paint_Style is ignored, as if were set to SkPaint::kStroke_Style. |
| 3340 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3341 | #Param x0 start of line segment on x-axis ## |
| 3342 | #Param y0 start of line segment on y-axis ## |
| 3343 | #Param x1 end of line segment on x-axis ## |
| 3344 | #Param y1 end of line segment on y-axis ## |
| 3345 | #Param paint stroke, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3346 | |
| 3347 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3348 | SkPaint paint; |
| 3349 | paint.setAntiAlias(true); |
| 3350 | paint.setColor(0xFF9a67be); |
| 3351 | paint.setStrokeWidth(20); |
| 3352 | canvas->skew(1, 0); |
| 3353 | canvas->drawLine(32, 96, 32, 160, paint); |
| 3354 | canvas->skew(-2, 0); |
| 3355 | canvas->drawLine(288, 96, 288, 160, paint); |
| 3356 | ## |
| 3357 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3358 | #SeeAlso drawPoint drawCircle drawRect drawPath |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3359 | |
| 3360 | ## |
| 3361 | |
| 3362 | #Method void drawLine(SkPoint p0, SkPoint p1, const SkPaint& paint) |
| 3363 | |
| 3364 | Draws line segment from p0 to p1 using Clip, Matrix, and Paint paint. |
| 3365 | In paint: Paint_Stroke_Width describes the line thickness; |
| 3366 | Paint_Stroke_Cap draws the end rounded or square; |
| 3367 | Paint_Style is ignored, as if were set to SkPaint::kStroke_Style. |
| 3368 | |
| 3369 | #Param p0 start of line segment ## |
| 3370 | #Param p1 end of line segment ## |
| 3371 | #Param paint stroke, blend, color, and so on, used to draw ## |
| 3372 | |
| 3373 | #Example |
| 3374 | SkPaint paint; |
| 3375 | paint.setAntiAlias(true); |
| 3376 | paint.setColor(0xFF9a67be); |
| 3377 | paint.setStrokeWidth(20); |
| 3378 | canvas->skew(1, 0); |
| 3379 | canvas->drawLine({32, 96}, {32, 160}, paint); |
| 3380 | canvas->skew(-2, 0); |
| 3381 | canvas->drawLine({288, 96}, {288, 160}, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3382 | ## |
| 3383 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3384 | #SeeAlso drawPoint drawCircle drawRect drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3385 | |
| 3386 | ## |
| 3387 | |
| 3388 | # ------------------------------------------------------------------------------ |
| 3389 | |
| 3390 | #Method void drawRect(const SkRect& rect, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3391 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3392 | #Line # draws Rect using Clip, Matrix, and Paint ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3393 | Draw Rect rect using Clip, Matrix, and Paint paint. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3394 | In paint: Paint_Style determines if rectangle is stroked or filled; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3395 | if stroked, Paint_Stroke_Width describes the line thickness, and |
| 3396 | Paint_Stroke_Join draws the corners rounded or square. |
| 3397 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3398 | #Param rect rectangle to draw ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3399 | #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] | 3400 | |
| 3401 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3402 | void draw(SkCanvas* canvas) { |
| 3403 | SkPoint rectPts[] = { {64, 48}, {192, 160} }; |
| 3404 | SkPaint paint; |
| 3405 | paint.setAntiAlias(true); |
| 3406 | paint.setStyle(SkPaint::kStroke_Style); |
| 3407 | paint.setStrokeWidth(20); |
| 3408 | paint.setStrokeJoin(SkPaint::kRound_Join); |
| 3409 | SkMatrix rotator; |
| 3410 | rotator.setRotate(30, 128, 128); |
| 3411 | for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorMAGENTA } ) { |
| 3412 | paint.setColor(color); |
| 3413 | SkRect rect; |
| 3414 | rect.set(rectPts[0], rectPts[1]); |
| 3415 | canvas->drawRect(rect, paint); |
| 3416 | rotator.mapPoints(rectPts, 2); |
| 3417 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3418 | } |
| 3419 | ## |
| 3420 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3421 | #SeeAlso drawIRect drawRRect drawRoundRect drawRegion drawPath drawLine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3422 | |
| 3423 | ## |
| 3424 | |
| 3425 | # ------------------------------------------------------------------------------ |
| 3426 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3427 | #Method void drawIRect(const SkIRect& rect, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3428 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3429 | #Line # draws IRect using Clip, Matrix, and Paint ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3430 | Draw IRect rect using Clip, Matrix, and Paint paint. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3431 | In paint: Paint_Style determines if rectangle is stroked or filled; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3432 | if stroked, Paint_Stroke_Width describes the line thickness, and |
| 3433 | Paint_Stroke_Join draws the corners rounded or square. |
| 3434 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3435 | #Param rect rectangle to draw ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3436 | #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] | 3437 | |
| 3438 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3439 | SkIRect rect = { 64, 48, 192, 160 }; |
| 3440 | SkPaint paint; |
| 3441 | paint.setAntiAlias(true); |
| 3442 | paint.setStyle(SkPaint::kStroke_Style); |
| 3443 | paint.setStrokeWidth(20); |
| 3444 | paint.setStrokeJoin(SkPaint::kRound_Join); |
| 3445 | for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorMAGENTA } ) { |
| 3446 | paint.setColor(color); |
| 3447 | canvas->drawIRect(rect, paint); |
| 3448 | canvas->rotate(30, 128, 128); |
| 3449 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3450 | ## |
| 3451 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3452 | #SeeAlso drawRect drawRRect drawRoundRect drawRegion drawPath drawLine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3453 | |
| 3454 | ## |
| 3455 | |
| 3456 | # ------------------------------------------------------------------------------ |
| 3457 | |
| 3458 | #Method void drawRegion(const SkRegion& region, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3459 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3460 | #Line # draws Region using Clip, Matrix, and Paint ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3461 | Draw Region region using Clip, Matrix, and Paint paint. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3462 | In paint: Paint_Style determines if rectangle is stroked or filled; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3463 | if stroked, Paint_Stroke_Width describes the line thickness, and |
| 3464 | Paint_Stroke_Join draws the corners rounded or square. |
| 3465 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3466 | #Param region region to draw ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3467 | #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] | 3468 | |
| 3469 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3470 | void draw(SkCanvas* canvas) { |
| 3471 | SkRegion region; |
| 3472 | region.op( 10, 10, 50, 50, SkRegion::kUnion_Op); |
| 3473 | region.op( 10, 50, 90, 90, SkRegion::kUnion_Op); |
| 3474 | SkPaint paint; |
| 3475 | paint.setAntiAlias(true); |
| 3476 | paint.setStyle(SkPaint::kStroke_Style); |
| 3477 | paint.setStrokeWidth(20); |
| 3478 | paint.setStrokeJoin(SkPaint::kRound_Join); |
| 3479 | canvas->drawRegion(region, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3480 | } |
| 3481 | ## |
| 3482 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3483 | #SeeAlso drawRect drawIRect drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3484 | |
| 3485 | ## |
| 3486 | |
| 3487 | # ------------------------------------------------------------------------------ |
| 3488 | |
| 3489 | #Method void drawOval(const SkRect& oval, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3490 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3491 | #Line # draws Oval using Clip, Matrix, and Paint ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3492 | Draw Oval oval using Clip, Matrix, and Paint. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3493 | In paint: Paint_Style determines if Oval is stroked or filled; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3494 | if stroked, Paint_Stroke_Width describes the line thickness. |
| 3495 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3496 | #Param oval Rect bounds of Oval ## |
| 3497 | #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] | 3498 | |
| 3499 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3500 | void draw(SkCanvas* canvas) { |
| 3501 | canvas->clear(0xFF3f5f9f); |
| 3502 | SkColor kColor1 = SkColorSetARGB(0xff, 0xff, 0x7f, 0); |
| 3503 | SkColor g1Colors[] = { kColor1, SkColorSetA(kColor1, 0x20) }; |
| 3504 | SkPoint g1Points[] = { { 0, 0 }, { 0, 100 } }; |
| 3505 | SkScalar pos[] = { 0.2f, 1.0f }; |
| 3506 | SkRect bounds = SkRect::MakeWH(80, 70); |
| 3507 | SkPaint paint; |
| 3508 | paint.setAntiAlias(true); |
| 3509 | paint.setShader(SkGradientShader::MakeLinear(g1Points, g1Colors, pos, SK_ARRAY_COUNT(g1Colors), |
| 3510 | SkShader::kClamp_TileMode)); |
| 3511 | canvas->drawOval(bounds , paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3512 | } |
| 3513 | ## |
| 3514 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3515 | #SeeAlso drawCircle drawPoint drawPath drawRRect drawRoundRect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3516 | |
| 3517 | ## |
| 3518 | |
| 3519 | # ------------------------------------------------------------------------------ |
| 3520 | |
| 3521 | #Method void drawRRect(const SkRRect& rrect, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3522 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3523 | #Line # draws Round_Rect using Clip, Matrix, and Paint ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3524 | Draw Round_Rect rrect using Clip, Matrix, and Paint paint. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3525 | In paint: Paint_Style determines if rrect is stroked or filled; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3526 | if stroked, Paint_Stroke_Width describes the line thickness. |
| 3527 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3528 | rrect may represent a rectangle, circle, oval, uniformly rounded rectangle, or |
| 3529 | 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] | 3530 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3531 | #Param rrect Round_Rect with up to eight corner radii to draw ## |
| 3532 | #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] | 3533 | |
| 3534 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3535 | void draw(SkCanvas* canvas) { |
| 3536 | SkPaint paint; |
| 3537 | paint.setAntiAlias(true); |
| 3538 | SkRect outer = {30, 40, 210, 220}; |
| 3539 | SkRect radii = {30, 50, 70, 90 }; |
| 3540 | SkRRect rRect; |
| 3541 | rRect.setNinePatch(outer, radii.fLeft, radii.fTop, radii.fRight, radii.fBottom); |
| 3542 | canvas->drawRRect(rRect, paint); |
| 3543 | paint.setColor(SK_ColorWHITE); |
| 3544 | canvas->drawLine(outer.fLeft + radii.fLeft, outer.fTop, |
| 3545 | outer.fLeft + radii.fLeft, outer.fBottom, paint); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3546 | canvas->drawLine(outer.fRight - radii.fRight, outer.fTop, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3547 | outer.fRight - radii.fRight, outer.fBottom, paint); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3548 | canvas->drawLine(outer.fLeft, outer.fTop + radii.fTop, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3549 | outer.fRight, outer.fTop + radii.fTop, paint); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3550 | canvas->drawLine(outer.fLeft, outer.fBottom - radii.fBottom, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3551 | outer.fRight, outer.fBottom - radii.fBottom, paint); |
| 3552 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3553 | ## |
| 3554 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3555 | #SeeAlso drawRect drawRoundRect drawDRRect drawCircle drawOval drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3556 | |
| 3557 | ## |
| 3558 | |
| 3559 | # ------------------------------------------------------------------------------ |
| 3560 | |
| 3561 | #Method void drawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3562 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3563 | #Line # draws double Round_Rect stroked or filled ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3564 | Draw Round_Rect outer and inner |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3565 | using Clip, Matrix, and Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3566 | outer must contain inner or the drawing is undefined. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3567 | In paint: Paint_Style determines if Round_Rect is stroked or filled; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3568 | if stroked, Paint_Stroke_Width describes the line thickness. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3569 | 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] | 3570 | draw corners rounded or square. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3571 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3572 | GPU-backed platforms optimize drawing when both outer and inner are |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3573 | 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] | 3574 | Path built with identical data as fast. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3575 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3576 | #Param outer Round_Rect outer bounds to draw ## |
| 3577 | #Param inner Round_Rect inner bounds to draw ## |
| 3578 | #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] | 3579 | |
| 3580 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3581 | void draw(SkCanvas* canvas) { |
| 3582 | SkRRect outer = SkRRect::MakeRect({20, 40, 210, 200}); |
| 3583 | SkRRect inner = SkRRect::MakeOval({60, 70, 170, 160}); |
| 3584 | SkPaint paint; |
| 3585 | canvas->drawDRRect(outer, inner, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3586 | } |
| 3587 | ## |
| 3588 | |
| 3589 | #Example |
| 3590 | #Description |
| 3591 | Outer Rect has no corner radii, but stroke join is rounded. |
| 3592 | Inner Round_Rect has corner radii; outset stroke increases radii of corners. |
| 3593 | Stroke join does not affect inner Round_Rect since it has no sharp corners. |
| 3594 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3595 | void draw(SkCanvas* canvas) { |
| 3596 | SkRRect outer = SkRRect::MakeRect({20, 40, 210, 200}); |
| 3597 | SkRRect inner = SkRRect::MakeRectXY({60, 70, 170, 160}, 10, 10); |
| 3598 | SkPaint paint; |
| 3599 | paint.setAntiAlias(true); |
| 3600 | paint.setStyle(SkPaint::kStroke_Style); |
| 3601 | paint.setStrokeWidth(20); |
| 3602 | paint.setStrokeJoin(SkPaint::kRound_Join); |
| 3603 | canvas->drawDRRect(outer, inner, paint); |
| 3604 | paint.setStrokeWidth(1); |
| 3605 | paint.setColor(SK_ColorWHITE); |
| 3606 | canvas->drawDRRect(outer, inner, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3607 | } |
| 3608 | ## |
| 3609 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3610 | #SeeAlso drawRect drawRoundRect drawRRect drawCircle drawOval drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3611 | |
| 3612 | ## |
| 3613 | |
| 3614 | # ------------------------------------------------------------------------------ |
| 3615 | |
| 3616 | #Method void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3617 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3618 | #Line # draws Circle using Clip, Matrix, and Paint ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3619 | Draw Circle at (cx, cy) with radius using Clip, Matrix, and Paint paint. |
| 3620 | If radius is zero or less, nothing is drawn. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3621 | In paint: Paint_Style determines if Circle is stroked or filled; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3622 | if stroked, Paint_Stroke_Width describes the line thickness. |
| 3623 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3624 | #Param cx Circle center on the x-axis ## |
| 3625 | #Param cy Circle center on the y-axis ## |
| 3626 | #Param radius half the diameter of Circle ## |
| 3627 | #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] | 3628 | |
| 3629 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3630 | void draw(SkCanvas* canvas) { |
| 3631 | SkPaint paint; |
| 3632 | paint.setAntiAlias(true); |
| 3633 | canvas->drawCircle(128, 128, 90, paint); |
| 3634 | paint.setColor(SK_ColorWHITE); |
| 3635 | canvas->drawCircle(86, 86, 20, paint); |
| 3636 | canvas->drawCircle(160, 76, 20, paint); |
| 3637 | canvas->drawCircle(140, 150, 35, paint); |
| 3638 | } |
| 3639 | ## |
| 3640 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3641 | #SeeAlso drawOval drawRRect drawRoundRect drawPath drawArc drawPoint drawLine |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3642 | |
| 3643 | ## |
| 3644 | |
| 3645 | #Method void drawCircle(SkPoint center, SkScalar radius, const SkPaint& paint) |
| 3646 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3647 | Draw Circle at center with radius using Clip, Matrix, and Paint paint. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3648 | If radius is zero or less, nothing is drawn. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3649 | In paint: Paint_Style determines if Circle is stroked or filled; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3650 | if stroked, Paint_Stroke_Width describes the line thickness. |
| 3651 | |
| 3652 | #Param center Circle center ## |
| 3653 | #Param radius half the diameter of Circle ## |
| 3654 | #Param paint Paint stroke or fill, blend, color, and so on, used to draw ## |
| 3655 | |
| 3656 | #Example |
| 3657 | void draw(SkCanvas* canvas) { |
| 3658 | SkPaint paint; |
| 3659 | paint.setAntiAlias(true); |
| 3660 | canvas->drawCircle(128, 128, 90, paint); |
| 3661 | paint.setColor(SK_ColorWHITE); |
| 3662 | canvas->drawCircle({86, 86}, 20, paint); |
| 3663 | canvas->drawCircle({160, 76}, 20, paint); |
| 3664 | canvas->drawCircle({140, 150}, 35, paint); |
| 3665 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3666 | ## |
| 3667 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3668 | #SeeAlso drawOval drawRRect drawRoundRect drawPath drawArc drawPoint drawLine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3669 | |
| 3670 | ## |
| 3671 | |
| 3672 | # ------------------------------------------------------------------------------ |
| 3673 | |
| 3674 | #Method void drawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, |
| 3675 | bool useCenter, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3676 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3677 | #Line # draws Arc using Clip, Matrix, and Paint ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3678 | |
| 3679 | Draw Arc using Clip, Matrix, and Paint paint. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3680 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3681 | Arc is part of Oval bounded by oval, sweeping from startAngle to startAngle plus |
| 3682 | sweepAngle. startAngle and sweepAngle are in degrees. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3683 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3684 | startAngle of zero places start point at the right middle edge of oval. |
| 3685 | A positive sweepAngle places Arc end point clockwise from start point; |
| 3686 | a negative sweepAngle places Arc end point counterclockwise from start point. |
| 3687 | sweepAngle may exceed 360 degrees, a full circle. |
| 3688 | If useCenter is true, draw a wedge that includes lines from oval |
| 3689 | center to Arc end points. If useCenter is false, draw Arc between end points. |
| 3690 | |
| 3691 | If Rect oval is empty or sweepAngle is zero, nothing is drawn. |
| 3692 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3693 | #Param oval Rect bounds of Oval containing Arc to draw ## |
| 3694 | #Param startAngle angle in degrees where Arc begins ## |
| 3695 | #Param sweepAngle sweep angle in degrees; positive is clockwise ## |
| 3696 | #Param useCenter if true, include the center of the oval ## |
| 3697 | #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] | 3698 | |
| 3699 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3700 | void draw(SkCanvas* canvas) { |
| 3701 | SkPaint paint; |
| 3702 | paint.setAntiAlias(true); |
| 3703 | SkRect oval = { 4, 4, 60, 60}; |
| 3704 | for (auto useCenter : { false, true } ) { |
| 3705 | for (auto style : { SkPaint::kFill_Style, SkPaint::kStroke_Style } ) { |
| 3706 | paint.setStyle(style); |
| 3707 | for (auto degrees : { 45, 90, 180, 360} ) { |
| 3708 | canvas->drawArc(oval, 0, degrees , useCenter, paint); |
| 3709 | canvas->translate(64, 0); |
| 3710 | } |
| 3711 | canvas->translate(-256, 64); |
| 3712 | } |
| 3713 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3714 | } |
| 3715 | ## |
| 3716 | |
| 3717 | #Example |
| 3718 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3719 | void draw(SkCanvas* canvas) { |
| 3720 | SkPaint paint; |
| 3721 | paint.setAntiAlias(true); |
| 3722 | paint.setStyle(SkPaint::kStroke_Style); |
| 3723 | paint.setStrokeWidth(4); |
| 3724 | SkRect oval = { 4, 4, 60, 60}; |
| 3725 | float intervals[] = { 5, 5 }; |
| 3726 | paint.setPathEffect(SkDashPathEffect::Make(intervals, 2, 2.5f)); |
| 3727 | for (auto degrees : { 270, 360, 540, 720 } ) { |
| 3728 | canvas->drawArc(oval, 0, degrees, false, paint); |
| 3729 | canvas->translate(64, 0); |
| 3730 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3731 | } |
| 3732 | ## |
| 3733 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3734 | #SeeAlso SkPath::arcTo drawCircle drawOval drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3735 | |
| 3736 | ## |
| 3737 | |
| 3738 | # ------------------------------------------------------------------------------ |
| 3739 | |
| 3740 | #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] | 3741 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3742 | #Line # draws Round_Rect using Clip, Matrix, and Paint ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3743 | Draw Round_Rect bounded by Rect rect, with corner radii (rx, ry) using Clip, |
| 3744 | Matrix, and Paint paint. |
| 3745 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3746 | In paint: Paint_Style determines if Round_Rect is stroked or filled; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3747 | if stroked, Paint_Stroke_Width describes the line thickness. |
| 3748 | If rx or ry are less than zero, they are treated as if they are zero. |
| 3749 | 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] | 3750 | If rx and ry are zero, Round_Rect is drawn as Rect and if stroked is affected by |
| 3751 | Paint_Stroke_Join. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3752 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3753 | #Param rect Rect bounds of Round_Rect to draw ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3754 | #Param rx axis length in x of oval describing rounded corners ## |
| 3755 | #Param ry axis length in y of oval describing rounded corners ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3756 | #Param paint stroke, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3757 | |
| 3758 | #Example |
| 3759 | #Description |
| 3760 | Top row has a zero radius a generates a rectangle. |
| 3761 | Second row radii sum to less than sides. |
| 3762 | Third row radii sum equals sides. |
| 3763 | Fourth row radii sum exceeds sides; radii are scaled to fit. |
| 3764 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3765 | void draw(SkCanvas* canvas) { |
| 3766 | SkVector radii[] = { {0, 20}, {10, 10}, {10, 20}, {10, 40} }; |
| 3767 | SkPaint paint; |
| 3768 | paint.setStrokeWidth(15); |
| 3769 | paint.setStrokeJoin(SkPaint::kRound_Join); |
| 3770 | paint.setAntiAlias(true); |
| 3771 | for (auto style : { SkPaint::kStroke_Style, SkPaint::kFill_Style } ) { |
| 3772 | paint.setStyle(style ); |
| 3773 | for (size_t i = 0; i < SK_ARRAY_COUNT(radii); ++i) { |
| 3774 | canvas->drawRoundRect({10, 10, 60, 40}, radii[i].fX, radii[i].fY, paint); |
| 3775 | canvas->translate(0, 60); |
| 3776 | } |
| 3777 | canvas->translate(80, -240); |
| 3778 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3779 | } |
| 3780 | ## |
| 3781 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3782 | #SeeAlso DrawRRect drawRect drawDRRect drawPath drawCircle drawOval drawPoint |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3783 | |
| 3784 | ## |
| 3785 | |
| 3786 | # ------------------------------------------------------------------------------ |
| 3787 | |
| 3788 | #Method void drawPath(const SkPath& path, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3789 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3790 | #Line # draws Path using Clip, Matrix, and Paint ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3791 | Draw Path path using Clip, Matrix, and Paint paint. |
| 3792 | Path contains an array of Path_Contour, each of which may be open or closed. |
| 3793 | |
| 3794 | In paint: Paint_Style determines if Round_Rect is stroked or filled: |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3795 | if filled, Path_Fill_Type determines whether Path_Contour describes inside or |
| 3796 | outside of fill; if stroked, Paint_Stroke_Width describes the line thickness, |
| 3797 | Paint_Stroke_Cap describes line ends, and Paint_Stroke_Join describes how |
| 3798 | corners are drawn. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3799 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3800 | #Param path Path to draw ## |
| 3801 | #Param paint stroke, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3802 | |
| 3803 | #Example |
| 3804 | #Description |
| 3805 | Top rows draw stroked path with combinations of joins and caps. The open contour |
| 3806 | is affected by caps; the closed contour is affected by joins. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3807 | Bottom row draws fill the same for open and closed contour. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3808 | First bottom column shows winding fills overlap. |
| 3809 | Second bottom column shows even odd fills exclude overlap. |
| 3810 | Third bottom column shows inverse winding fills area outside both contours. |
| 3811 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3812 | void draw(SkCanvas* canvas) { |
| 3813 | SkPath path; |
| 3814 | path.moveTo(20, 20); |
| 3815 | path.quadTo(60, 20, 60, 60); |
| 3816 | path.close(); |
| 3817 | path.moveTo(60, 20); |
| 3818 | path.quadTo(60, 60, 20, 60); |
| 3819 | SkPaint paint; |
| 3820 | paint.setStrokeWidth(10); |
| 3821 | paint.setAntiAlias(true); |
| 3822 | paint.setStyle(SkPaint::kStroke_Style); |
| 3823 | for (auto join: { SkPaint::kBevel_Join, SkPaint::kRound_Join, SkPaint::kMiter_Join } ) { |
| 3824 | paint.setStrokeJoin(join); |
| 3825 | for (auto cap: { SkPaint::kButt_Cap, SkPaint::kSquare_Cap, SkPaint::kRound_Cap } ) { |
| 3826 | paint.setStrokeCap(cap); |
| 3827 | canvas->drawPath(path, paint); |
| 3828 | canvas->translate(80, 0); |
| 3829 | } |
| 3830 | canvas->translate(-240, 60); |
| 3831 | } |
| 3832 | paint.setStyle(SkPaint::kFill_Style); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3833 | for (auto fill : { SkPath::kWinding_FillType, |
| 3834 | SkPath::kEvenOdd_FillType, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3835 | SkPath::kInverseWinding_FillType } ) { |
| 3836 | path.setFillType(fill); |
| 3837 | canvas->save(); |
| 3838 | canvas->clipRect({0, 10, 80, 70}); |
| 3839 | canvas->drawPath(path, paint); |
| 3840 | canvas->restore(); |
| 3841 | canvas->translate(80, 0); |
| 3842 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3843 | } |
| 3844 | ## |
| 3845 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3846 | #SeeAlso SkPath drawLine drawArc drawRect drawPoints |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3847 | |
| 3848 | ## |
| 3849 | |
| 3850 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3851 | #Subtopic Draw_Image |
| 3852 | #Line # draws Image to Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3853 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3854 | drawImage, drawImageRect, and drawImageNine can be called with a bare pointer or |
| 3855 | 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] | 3856 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3857 | #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] | 3858 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3859 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3860 | #Line # draws Image at (x, y) position ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3861 | Draw Image image, with its top-left corner at (left, top), |
| 3862 | using Clip, Matrix, and optional Paint paint. |
| 3863 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3864 | If paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, Blend_Mode, |
| 3865 | and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader. |
| 3866 | If paint contains Mask_Filter, generate mask from image bounds. If generated |
| 3867 | mask extends beyond image bounds, replicate image edge colors, just as Shader |
| 3868 | made from SkImage::makeShader with SkShader::kClamp_TileMode set replicates the |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3869 | image edge color when it samples outside of its bounds. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3870 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3871 | #Param image uncompressed rectangular map of pixels ## |
| 3872 | #Param left left side of image ## |
| 3873 | #Param top top side of image ## |
| 3874 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 3875 | and so on; or nullptr |
| 3876 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3877 | |
| 3878 | #Example |
| 3879 | #Height 64 |
| 3880 | #Image 4 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3881 | void draw(SkCanvas* canvas) { |
| 3882 | // sk_sp<SkImage> image; |
| 3883 | SkImage* imagePtr = image.get(); |
| 3884 | canvas->drawImage(imagePtr, 0, 0); |
| 3885 | SkPaint paint; |
| 3886 | canvas->drawImage(imagePtr, 80, 0, &paint); |
| 3887 | paint.setAlpha(0x80); |
| 3888 | canvas->drawImage(imagePtr, 160, 0, &paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3889 | } |
| 3890 | ## |
| 3891 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3892 | #SeeAlso drawBitmap drawImageLattice drawImageNine drawImageRect SkPaint::setImageFilter |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3893 | |
| 3894 | ## |
| 3895 | |
| 3896 | # ------------------------------------------------------------------------------ |
| 3897 | |
| 3898 | #Method void drawImage(const sk_sp<SkImage>& image, SkScalar left, SkScalar top, |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3899 | const SkPaint* paint = nullptr) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3900 | |
| 3901 | Draw Image image, with its top-left corner at (left, top), |
| 3902 | using Clip, Matrix, and optional Paint paint. |
| 3903 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3904 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 3905 | Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader. |
| 3906 | If paint contains Mask_Filter, generate mask from image bounds. If generated |
| 3907 | mask extends beyond image bounds, replicate image edge colors, just as Shader |
| 3908 | made from SkImage::makeShader with SkShader::kClamp_TileMode set replicates the |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3909 | image edge color when it samples outside of its bounds. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3910 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3911 | #Param image uncompressed rectangular map of pixels ## |
| 3912 | #Param left left side of image ## |
| 3913 | #Param top pop side of image ## |
| 3914 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 3915 | and so on; or nullptr |
| 3916 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3917 | |
| 3918 | #Example |
| 3919 | #Height 64 |
| 3920 | #Image 4 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3921 | void draw(SkCanvas* canvas) { |
| 3922 | // sk_sp<SkImage> image; |
| 3923 | canvas->drawImage(image, 0, 0); |
| 3924 | SkPaint paint; |
| 3925 | canvas->drawImage(image, 80, 0, &paint); |
| 3926 | paint.setAlpha(0x80); |
| 3927 | canvas->drawImage(image, 160, 0, &paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3928 | } |
| 3929 | ## |
| 3930 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3931 | #SeeAlso drawBitmap drawImageLattice drawImageNine drawImageRect SkPaint::setImageFilter |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3932 | |
| 3933 | ## |
| 3934 | |
| 3935 | # ------------------------------------------------------------------------------ |
| 3936 | |
| 3937 | #Enum SrcRectConstraint |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3938 | #Line # sets drawImageRect options ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3939 | |
| 3940 | #Code |
| 3941 | enum SrcRectConstraint { |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3942 | kStrict_SrcRectConstraint, |
| 3943 | kFast_SrcRectConstraint, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3944 | }; |
| 3945 | ## |
| 3946 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3947 | SrcRectConstraint controls the behavior at the edge of source Rect, |
| 3948 | provided to drawImageRect, trading off speed for precision. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3949 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3950 | 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] | 3951 | 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] | 3952 | 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] | 3953 | SrcRectConstraint specifies whether an Image_Filter is allowed to read pixels |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3954 | outside source Rect. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3955 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3956 | #Const kStrict_SrcRectConstraint 0 |
| 3957 | #Line # sample only inside bounds; slower ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3958 | Requires Image_Filter to respect source Rect, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3959 | sampling only inside of its bounds, possibly with a performance penalty. |
| 3960 | ## |
| 3961 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3962 | #Const kFast_SrcRectConstraint 1 |
| 3963 | #Line # sample outside bounds; faster ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3964 | Permits Image_Filter to sample outside of source Rect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3965 | by half the width of Image_Filter, permitting it to run faster but with |
| 3966 | error at the image edges. |
| 3967 | ## |
| 3968 | |
| 3969 | #Example |
| 3970 | #Height 64 |
| 3971 | #Description |
| 3972 | redBorder contains a black and white checkerboard bordered by red. |
| 3973 | redBorder is drawn scaled by 16 on the left. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3974 | The middle and right bitmaps are filtered checkerboards. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3975 | Drawing the checkerboard with kStrict_SrcRectConstraint shows only a blur of black and white. |
| 3976 | Drawing the checkerboard with kFast_SrcRectConstraint allows red to bleed in the corners. |
| 3977 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3978 | void draw(SkCanvas* canvas) { |
| 3979 | SkBitmap redBorder; |
| 3980 | redBorder.allocPixels(SkImageInfo::MakeN32Premul(4, 4)); |
| 3981 | SkCanvas checkRed(redBorder); |
| 3982 | checkRed.clear(SK_ColorRED); |
| 3983 | uint32_t checkers[][2] = { { SK_ColorBLACK, SK_ColorWHITE }, |
| 3984 | { SK_ColorWHITE, SK_ColorBLACK } }; |
| 3985 | checkRed.writePixels( |
| 3986 | SkImageInfo::MakeN32Premul(2, 2), (void*) checkers, sizeof(checkers[0]), 1, 1); |
| 3987 | canvas->scale(16, 16); |
| 3988 | canvas->drawBitmap(redBorder, 0, 0, nullptr); |
| 3989 | canvas->resetMatrix(); |
| 3990 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(redBorder); |
| 3991 | SkPaint lowPaint; |
| 3992 | lowPaint.setFilterQuality(kLow_SkFilterQuality); |
| 3993 | for (auto constraint : { SkCanvas::kStrict_SrcRectConstraint, |
| 3994 | SkCanvas::kFast_SrcRectConstraint } ) { |
| 3995 | canvas->translate(80, 0); |
| 3996 | canvas->drawImageRect(image.get(), SkRect::MakeLTRB(1, 1, 3, 3), |
| 3997 | SkRect::MakeLTRB(16, 16, 48, 48), &lowPaint, constraint); |
| 3998 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3999 | } |
| 4000 | ## |
| 4001 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4002 | #SeeAlso drawImageRect drawImage SkPaint::setImageFilter |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4003 | |
| 4004 | ## |
| 4005 | |
| 4006 | # ------------------------------------------------------------------------------ |
| 4007 | |
| 4008 | #Method void drawImageRect(const SkImage* image, const SkRect& src, const SkRect& dst, |
| 4009 | const SkPaint* paint, |
| 4010 | SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4011 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4012 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4013 | #Line # draws Image, source Rect to destination Rect ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4014 | |
| 4015 | Draw Rect src of Image image, scaled and translated to fill Rect dst. |
| 4016 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4017 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4018 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4019 | Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader. |
| 4020 | If paint contains Mask_Filter, generate mask from image bounds. |
| 4021 | |
| 4022 | If generated mask extends beyond image bounds, replicate image edge colors, just |
| 4023 | as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4024 | replicates the image edge color when it samples outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4025 | |
| 4026 | constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to |
| 4027 | sample within src; set to kFast_SrcRectConstraint allows sampling outside to |
| 4028 | improve performance. |
| 4029 | |
| 4030 | #Param image Image containing pixels, dimensions, and format ## |
| 4031 | #Param src source Rect of image to draw from ## |
| 4032 | #Param dst destination Rect of image to draw to ## |
| 4033 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4034 | and so on; or nullptr |
| 4035 | ## |
| 4036 | #Param constraint filter strictly within src or draw faster ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4037 | |
| 4038 | #Example |
| 4039 | #Height 64 |
| 4040 | #Description |
| 4041 | The left bitmap draws with Paint default kNone_SkFilterQuality, and stays within |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4042 | its bounds; there is no bleeding with kFast_SrcRectConstraint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4043 | the middle and right bitmaps draw with kLow_SkFilterQuality; with |
| 4044 | kStrict_SrcRectConstraint, the filter remains within the checkerboard, and |
| 4045 | with kFast_SrcRectConstraint red bleeds on the edges. |
| 4046 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4047 | void draw(SkCanvas* canvas) { |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4048 | uint32_t pixels[][4] = { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4049 | { 0xFFFF0000, 0xFFFF0000, 0xFFFF0000, 0xFFFF0000 }, |
| 4050 | { 0xFFFF0000, 0xFF000000, 0xFFFFFFFF, 0xFFFF0000 }, |
| 4051 | { 0xFFFF0000, 0xFFFFFFFF, 0xFF000000, 0xFFFF0000 }, |
| 4052 | { 0xFFFF0000, 0xFFFF0000, 0xFFFF0000, 0xFFFF0000 } }; |
| 4053 | SkBitmap redBorder; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4054 | redBorder.installPixels(SkImageInfo::MakeN32Premul(4, 4), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4055 | (void*) pixels, sizeof(pixels[0])); |
| 4056 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(redBorder); |
| 4057 | SkPaint lowPaint; |
| 4058 | for (auto constraint : { |
| 4059 | SkCanvas::kFast_SrcRectConstraint, |
| 4060 | SkCanvas::kStrict_SrcRectConstraint, |
| 4061 | SkCanvas::kFast_SrcRectConstraint } ) { |
| 4062 | canvas->drawImageRect(image.get(), SkRect::MakeLTRB(1, 1, 3, 3), |
| 4063 | SkRect::MakeLTRB(16, 16, 48, 48), &lowPaint, constraint); |
| 4064 | lowPaint.setFilterQuality(kLow_SkFilterQuality); |
| 4065 | canvas->translate(80, 0); |
| 4066 | } |
| 4067 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4068 | ## |
| 4069 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4070 | #SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4071 | |
| 4072 | ## |
| 4073 | |
| 4074 | # ------------------------------------------------------------------------------ |
| 4075 | |
| 4076 | #Method void drawImageRect(const SkImage* image, const SkIRect& isrc, const SkRect& dst, |
| 4077 | const SkPaint* paint, SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4078 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4079 | #In Draw |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4080 | |
| 4081 | Draw IRect isrc of Image image, scaled and translated to fill Rect dst. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4082 | Note that isrc is on integer pixel boundaries; dst may include fractional |
| 4083 | boundaries. Additionally transform draw using Clip, Matrix, and optional Paint |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4084 | paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4085 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4086 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4087 | Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader. |
| 4088 | If paint contains Mask_Filter, generate mask from image bounds. |
| 4089 | |
| 4090 | If generated mask extends beyond image bounds, replicate image edge colors, just |
| 4091 | as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4092 | replicates the image edge color when it samples outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4093 | |
| 4094 | constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4095 | sample within isrc; set to kFast_SrcRectConstraint allows sampling outside to |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4096 | improve performance. |
| 4097 | |
| 4098 | #Param image Image containing pixels, dimensions, and format ## |
| 4099 | #Param isrc source IRect of image to draw from ## |
| 4100 | #Param dst destination Rect of image to draw to ## |
| 4101 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4102 | and so on; or nullptr |
| 4103 | ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4104 | #Param constraint filter strictly within isrc or draw faster ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4105 | |
| 4106 | #Example |
| 4107 | #Image 4 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4108 | void draw(SkCanvas* canvas) { |
| 4109 | // sk_sp<SkImage> image; |
| 4110 | for (auto i : { 1, 2, 4, 8 } ) { |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4111 | canvas->drawImageRect(image.get(), SkIRect::MakeLTRB(0, 0, 100, 100), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4112 | SkRect::MakeXYWH(i * 20, i * 20, i * 20, i * 20), nullptr); |
| 4113 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4114 | } |
| 4115 | ## |
| 4116 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4117 | #SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4118 | |
| 4119 | ## |
| 4120 | |
| 4121 | # ------------------------------------------------------------------------------ |
| 4122 | |
| 4123 | #Method void drawImageRect(const SkImage* image, const SkRect& dst, const SkPaint* paint, |
| 4124 | SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4125 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4126 | #In Draw |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4127 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4128 | Draw Image image, scaled and translated to fill Rect dst, using Clip, Matrix, |
| 4129 | and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4130 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4131 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4132 | Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader. |
| 4133 | If paint contains Mask_Filter, generate mask from image bounds. |
| 4134 | |
| 4135 | If generated mask extends beyond image bounds, replicate image edge colors, just |
| 4136 | as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4137 | replicates the image edge color when it samples outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4138 | |
| 4139 | constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4140 | sample within image; set to kFast_SrcRectConstraint allows sampling outside to |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4141 | improve performance. |
| 4142 | |
| 4143 | #Param image Image containing pixels, dimensions, and format ## |
| 4144 | #Param dst destination Rect of image to draw to ## |
| 4145 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4146 | and so on; or nullptr |
| 4147 | ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4148 | #Param constraint filter strictly within image or draw faster ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4149 | |
| 4150 | #Example |
| 4151 | #Image 4 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4152 | void draw(SkCanvas* canvas) { |
| 4153 | // sk_sp<SkImage> image; |
| 4154 | for (auto i : { 20, 40, 80, 160 } ) { |
| 4155 | canvas->drawImageRect(image.get(), SkRect::MakeXYWH(i, i, i, i), nullptr); |
| 4156 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4157 | } |
| 4158 | ## |
| 4159 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4160 | #SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4161 | |
| 4162 | ## |
| 4163 | |
| 4164 | # ------------------------------------------------------------------------------ |
| 4165 | |
| 4166 | #Method void drawImageRect(const sk_sp<SkImage>& image, const SkRect& src, const SkRect& dst, |
| 4167 | const SkPaint* paint, |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4168 | SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4169 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4170 | #In Draw |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4171 | Draw Rect src of Image image, scaled and translated to fill Rect dst. |
| 4172 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4173 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4174 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4175 | Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader. |
| 4176 | If paint contains Mask_Filter, generate mask from image bounds. |
| 4177 | |
| 4178 | If generated mask extends beyond image bounds, replicate image edge colors, just |
| 4179 | as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4180 | replicates the image edge color when it samples outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4181 | |
| 4182 | constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to |
| 4183 | sample within src; set to kFast_SrcRectConstraint allows sampling outside to |
| 4184 | improve performance. |
| 4185 | |
| 4186 | #Param image Image containing pixels, dimensions, and format ## |
| 4187 | #Param src source Rect of image to draw from ## |
| 4188 | #Param dst destination Rect of image to draw to ## |
| 4189 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4190 | and so on; or nullptr |
| 4191 | ## |
| 4192 | #Param constraint filter strictly within src or draw faster ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4193 | |
| 4194 | #Example |
| 4195 | #Height 64 |
| 4196 | #Description |
| 4197 | Canvas scales and translates; transformation from src to dst also scales. |
| 4198 | The two matrices are concatenated to create the final transformation. |
| 4199 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4200 | void draw(SkCanvas* canvas) { |
| 4201 | uint32_t pixels[][2] = { { SK_ColorBLACK, SK_ColorWHITE }, |
| 4202 | { SK_ColorWHITE, SK_ColorBLACK } }; |
| 4203 | SkBitmap bitmap; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4204 | bitmap.installPixels(SkImageInfo::MakeN32Premul(2, 2), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4205 | (void*) pixels, sizeof(pixels[0])); |
| 4206 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 4207 | SkPaint paint; |
| 4208 | canvas->scale(4, 4); |
| 4209 | for (auto alpha : { 50, 100, 150, 255 } ) { |
| 4210 | paint.setAlpha(alpha); |
| 4211 | canvas->drawImageRect(image, SkRect::MakeWH(2, 2), SkRect::MakeWH(8, 8), &paint); |
| 4212 | canvas->translate(8, 0); |
| 4213 | } |
| 4214 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4215 | ## |
| 4216 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4217 | #SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4218 | |
| 4219 | ## |
| 4220 | |
| 4221 | # ------------------------------------------------------------------------------ |
| 4222 | |
| 4223 | #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] | 4224 | const SkPaint* paint, SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4225 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4226 | #In Draw |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4227 | Draw IRect isrc of Image image, scaled and translated to fill Rect dst. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4228 | isrc is on integer pixel boundaries; dst may include fractional boundaries. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4229 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4230 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4231 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4232 | Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader. |
| 4233 | If paint contains Mask_Filter, generate mask from image bounds. |
| 4234 | |
| 4235 | If generated mask extends beyond image bounds, replicate image edge colors, just |
| 4236 | as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4237 | replicates the image edge color when it samples outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4238 | |
| 4239 | constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4240 | sample within image; set to kFast_SrcRectConstraint allows sampling outside to |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4241 | improve performance. |
| 4242 | |
| 4243 | #Param image Image containing pixels, dimensions, and format ## |
| 4244 | #Param isrc source IRect of image to draw from ## |
| 4245 | #Param dst destination Rect of image to draw to ## |
| 4246 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4247 | and so on; or nullptr |
| 4248 | ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4249 | #Param constraint filter strictly within image or draw faster ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4250 | |
| 4251 | #Example |
| 4252 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4253 | void draw(SkCanvas* canvas) { |
| 4254 | uint32_t pixels[][2] = { { 0x00000000, 0x55555555}, |
| 4255 | { 0xAAAAAAAA, 0xFFFFFFFF} }; |
| 4256 | SkBitmap bitmap; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4257 | bitmap.installPixels(SkImageInfo::MakeN32Premul(2, 2), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4258 | (void*) pixels, sizeof(pixels[0])); |
| 4259 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 4260 | SkPaint paint; |
| 4261 | canvas->scale(4, 4); |
| 4262 | for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN } ) { |
| 4263 | paint.setColorFilter(SkColorFilter::MakeModeFilter(color, SkBlendMode::kPlus)); |
| 4264 | canvas->drawImageRect(image, SkIRect::MakeWH(2, 2), SkRect::MakeWH(8, 8), &paint); |
| 4265 | canvas->translate(8, 0); |
| 4266 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4267 | } |
| 4268 | ## |
| 4269 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4270 | #SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine |
| 4271 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4272 | ## |
| 4273 | |
| 4274 | # ------------------------------------------------------------------------------ |
| 4275 | |
| 4276 | #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] | 4277 | SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4278 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4279 | #In Draw |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4280 | Draw Image image, scaled and translated to fill Rect dst, |
| 4281 | using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4282 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4283 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4284 | Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader. |
| 4285 | If paint contains Mask_Filter, generate mask from image bounds. |
| 4286 | |
| 4287 | If generated mask extends beyond image bounds, replicate image edge colors, just |
| 4288 | as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4289 | replicates the image edge color when it samples outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4290 | |
| 4291 | constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4292 | sample within image; set to kFast_SrcRectConstraint allows sampling outside to |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4293 | improve performance. |
| 4294 | |
| 4295 | #Param image Image containing pixels, dimensions, and format ## |
| 4296 | #Param dst destination Rect of image to draw to ## |
| 4297 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4298 | and so on; or nullptr |
| 4299 | ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4300 | #Param constraint filter strictly within image or draw faster ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4301 | |
| 4302 | #Example |
| 4303 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4304 | void draw(SkCanvas* canvas) { |
| 4305 | uint32_t pixels[][2] = { { 0x00000000, 0x55550000}, |
| 4306 | { 0xAAAA0000, 0xFFFF0000} }; |
| 4307 | SkBitmap bitmap; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4308 | bitmap.installPixels(SkImageInfo::MakeN32Premul(2, 2), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4309 | (void*) pixels, sizeof(pixels[0])); |
| 4310 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 4311 | SkPaint paint; |
| 4312 | canvas->scale(4, 4); |
| 4313 | for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN } ) { |
| 4314 | paint.setColorFilter(SkColorFilter::MakeModeFilter(color, SkBlendMode::kPlus)); |
| 4315 | canvas->drawImageRect(image, SkRect::MakeWH(8, 8), &paint); |
| 4316 | canvas->translate(8, 0); |
| 4317 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4318 | } |
| 4319 | ## |
| 4320 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4321 | #SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4322 | |
| 4323 | ## |
| 4324 | |
| 4325 | # ------------------------------------------------------------------------------ |
| 4326 | |
| 4327 | #Method void drawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst, |
| 4328 | const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4329 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4330 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4331 | #Line # draws Nine_Patch Image ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4332 | |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 4333 | Draw Image image stretched proportionally to fit into Rect dst. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4334 | 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] | 4335 | the center. Corners are unmodified or scaled down proportionately if their sides |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4336 | 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] | 4337 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4338 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
| 4339 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4340 | #paint_as_used_by_draw_lattice_or_draw_nine(image)# |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4341 | |
| 4342 | If generated mask extends beyond image bounds, replicate image edge colors, just |
| 4343 | as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4344 | replicates the image edge color when it samples outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4345 | |
| 4346 | #Param image Image containing pixels, dimensions, and format ## |
| 4347 | #Param center IRect edge of image corners and sides ## |
| 4348 | #Param dst destination Rect of image to draw to ## |
| 4349 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4350 | and so on; or nullptr |
| 4351 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4352 | |
| 4353 | #Example |
| 4354 | #Height 128 |
| 4355 | #Description |
| 4356 | 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] | 4357 | The second image equals the size of center; only corners are drawn without scaling. |
| 4358 | The remaining images are larger than center. All corners draw without scaling. |
| 4359 | 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] | 4360 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4361 | void draw(SkCanvas* canvas) { |
| 4362 | SkIRect center = { 20, 10, 50, 40 }; |
| 4363 | SkBitmap bitmap; |
| 4364 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60)); |
| 4365 | SkCanvas bitCanvas(bitmap); |
| 4366 | SkPaint paint; |
| 4367 | SkColor gray = 0xFF000000; |
| 4368 | int left = 0; |
| 4369 | for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) { |
| 4370 | int top = 0; |
| 4371 | for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) { |
| 4372 | paint.setColor(gray); |
| 4373 | bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint); |
| 4374 | gray += 0x001f1f1f; |
| 4375 | top = bottom; |
| 4376 | } |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4377 | left = right; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4378 | } |
| 4379 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 4380 | SkImage* imagePtr = image.get(); |
| 4381 | for (auto dest: { 20, 30, 40, 60, 90 } ) { |
| 4382 | canvas->drawImageNine(imagePtr, center, SkRect::MakeWH(dest, dest), nullptr); |
| 4383 | canvas->translate(dest + 4, 0); |
| 4384 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4385 | } |
| 4386 | ## |
| 4387 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4388 | #SeeAlso drawImage drawBitmapNine drawImageLattice drawImageRect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4389 | |
| 4390 | ## |
| 4391 | |
| 4392 | # ------------------------------------------------------------------------------ |
| 4393 | |
| 4394 | #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] | 4395 | const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4396 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4397 | #In Draw |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 4398 | Draw Image image stretched proportionally to fit into Rect dst. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4399 | 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] | 4400 | 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] | 4401 | 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] | 4402 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4403 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
| 4404 | |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 4405 | #paint_as_used_by_draw_lattice_or_draw_nine(image)# |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4406 | |
| 4407 | If generated mask extends beyond image bounds, replicate image edge colors, just |
| 4408 | as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4409 | replicates the image edge color when it samples outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4410 | |
| 4411 | #Param image Image containing pixels, dimensions, and format ## |
| 4412 | #Param center IRect edge of image corners and sides ## |
| 4413 | #Param dst destination Rect of image to draw to ## |
| 4414 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4415 | and so on; or nullptr |
| 4416 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4417 | |
| 4418 | #Example |
| 4419 | #Height 128 |
| 4420 | #Description |
| 4421 | The two leftmost images has four corners and sides to the left and right of center. |
| 4422 | The leftmost image scales the width of corners proportionately to fit. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4423 | 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] | 4424 | fill the remaining space. |
| 4425 | The rightmost image has four corners scaled vertically to fit, and uses sides above |
| 4426 | and below center to fill the remaining space. |
| 4427 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4428 | void draw(SkCanvas* canvas) { |
| 4429 | SkIRect center = { 20, 10, 50, 40 }; |
| 4430 | SkBitmap bitmap; |
| 4431 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60)); |
| 4432 | SkCanvas bitCanvas(bitmap); |
| 4433 | SkPaint paint; |
| 4434 | SkColor gray = 0xFF000000; |
| 4435 | int left = 0; |
| 4436 | for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) { |
| 4437 | int top = 0; |
| 4438 | for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) { |
| 4439 | paint.setColor(gray); |
| 4440 | bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint); |
| 4441 | gray += 0x001f1f1f; |
| 4442 | top = bottom; |
| 4443 | } |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4444 | left = right; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4445 | } |
| 4446 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 4447 | for (auto dest: { 20, 30, 40, 60, 90 } ) { |
| 4448 | canvas->drawImageNine(image, center, SkRect::MakeWH(dest, 110 - dest), nullptr); |
| 4449 | canvas->translate(dest + 4, 0); |
| 4450 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4451 | } |
| 4452 | ## |
| 4453 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4454 | #SeeAlso drawImage drawBitmapNine drawImageLattice drawImageRect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4455 | |
| 4456 | ## |
| 4457 | |
| 4458 | # ------------------------------------------------------------------------------ |
| 4459 | |
| 4460 | #Method void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4461 | const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4462 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4463 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4464 | #Line # draws Bitmap at (x, y) position ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4465 | |
| 4466 | Draw Bitmap bitmap, with its top-left corner at (left, top), |
| 4467 | using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4468 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 4469 | 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] | 4470 | Blend_Mode, and Draw_Looper. If bitmap is kAlpha_8_SkColorType, apply Shader. |
| 4471 | If paint contains Mask_Filter, generate mask from bitmap bounds. |
| 4472 | |
| 4473 | If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, |
| 4474 | just as Shader made from SkShader::MakeBitmapShader with |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4475 | SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4476 | outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4477 | |
| 4478 | #Param bitmap Bitmap containing pixels, dimensions, and format ## |
| 4479 | #Param left left side of bitmap ## |
| 4480 | #Param top top side of bitmap ## |
| 4481 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4482 | and so on; or nullptr |
| 4483 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4484 | |
| 4485 | #Example |
| 4486 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4487 | void draw(SkCanvas* canvas) { |
| 4488 | uint8_t pixels[][8] = { { 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00}, |
| 4489 | { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00}, |
| 4490 | { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00}, |
| 4491 | { 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF}, |
| 4492 | { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, |
| 4493 | { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00}, |
| 4494 | { 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00}, |
| 4495 | { 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF} }; |
| 4496 | SkBitmap bitmap; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4497 | bitmap.installPixels(SkImageInfo::MakeA8(8, 8), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4498 | (void*) pixels, sizeof(pixels[0])); |
| 4499 | SkPaint paint; |
| 4500 | canvas->scale(4, 4); |
| 4501 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xFF007F00} ) { |
| 4502 | paint.setColor(color); |
| 4503 | canvas->drawBitmap(bitmap, 0, 0, &paint); |
| 4504 | canvas->translate(12, 0); |
| 4505 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4506 | } |
| 4507 | ## |
| 4508 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4509 | #SeeAlso drawImage drawBitmapLattice drawBitmapNine drawBitmapRect SkBitmap::readPixels SkBitmap::writePixels |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4510 | |
| 4511 | ## |
| 4512 | |
| 4513 | # ------------------------------------------------------------------------------ |
| 4514 | |
| 4515 | #Method void drawBitmapRect(const SkBitmap& bitmap, const SkRect& src, const SkRect& dst, |
| 4516 | const SkPaint* paint, SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4517 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4518 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4519 | #Line # draws Bitmap, source Rect to destination Rect ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4520 | |
| 4521 | Draw Rect src of Bitmap bitmap, scaled and translated to fill Rect dst. |
| 4522 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4523 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4524 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4525 | Blend_Mode, and Draw_Looper. If bitmap is kAlpha_8_SkColorType, apply Shader. |
| 4526 | If paint contains Mask_Filter, generate mask from bitmap bounds. |
| 4527 | |
| 4528 | If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, |
| 4529 | just as Shader made from SkShader::MakeBitmapShader with |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4530 | SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4531 | outside of its bounds. |
| 4532 | |
| 4533 | constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to |
| 4534 | sample within src; set to kFast_SrcRectConstraint allows sampling outside to |
| 4535 | improve performance. |
| 4536 | |
| 4537 | #Param bitmap Bitmap containing pixels, dimensions, and format ## |
| 4538 | #Param src source Rect of image to draw from ## |
| 4539 | #Param dst destination Rect of image to draw to ## |
| 4540 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4541 | and so on; or nullptr |
| 4542 | ## |
| 4543 | #Param constraint filter strictly within src or draw faster ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4544 | |
| 4545 | #Example |
| 4546 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4547 | void draw(SkCanvas* canvas) { |
| 4548 | uint8_t pixels[][8] = { { 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00}, |
| 4549 | { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00}, |
| 4550 | { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00}, |
| 4551 | { 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF}, |
| 4552 | { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, |
| 4553 | { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00}, |
| 4554 | { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00}, |
| 4555 | { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00} }; |
| 4556 | SkBitmap bitmap; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4557 | bitmap.installPixels(SkImageInfo::MakeA8(8, 8), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4558 | (void*) pixels, sizeof(pixels[0])); |
| 4559 | SkPaint paint; |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 4560 | paint.setMaskFilter(SkMaskFilter::MakeBlur(kSolid_SkBlurStyle, 6)); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4561 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xFF007F00} ) { |
| 4562 | paint.setColor(color); |
| 4563 | canvas->drawBitmapRect(bitmap, SkRect::MakeWH(8, 8), SkRect::MakeWH(32, 32), &paint); |
| 4564 | canvas->translate(48, 0); |
| 4565 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4566 | } |
| 4567 | ## |
| 4568 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4569 | #SeeAlso drawImageRect drawBitmap drawBitmapLattice drawBitmapNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4570 | |
| 4571 | ## |
| 4572 | |
| 4573 | # ------------------------------------------------------------------------------ |
| 4574 | |
| 4575 | #Method void drawBitmapRect(const SkBitmap& bitmap, const SkIRect& isrc, const SkRect& dst, |
| 4576 | const SkPaint* paint, SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4577 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4578 | #In Draw |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4579 | Draw IRect isrc of Bitmap bitmap, scaled and translated to fill Rect dst. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4580 | isrc is on integer pixel boundaries; dst may include fractional boundaries. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4581 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4582 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4583 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4584 | Blend_Mode, and Draw_Looper. If bitmap is kAlpha_8_SkColorType, apply Shader. |
| 4585 | If paint contains Mask_Filter, generate mask from bitmap bounds. |
| 4586 | |
| 4587 | If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, |
| 4588 | just as Shader made from SkShader::MakeBitmapShader with |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4589 | SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4590 | outside of its bounds. |
| 4591 | |
| 4592 | constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4593 | sample within isrc; set to kFast_SrcRectConstraint allows sampling outside to |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4594 | improve performance. |
| 4595 | |
| 4596 | #Param bitmap Bitmap containing pixels, dimensions, and format ## |
| 4597 | #Param isrc source IRect of image to draw from ## |
| 4598 | #Param dst destination Rect of image to draw to ## |
| 4599 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4600 | and so on; or nullptr |
| 4601 | ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4602 | #Param constraint sample strictly within isrc, or draw faster ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4603 | |
| 4604 | #Example |
| 4605 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4606 | void draw(SkCanvas* canvas) { |
| 4607 | uint8_t pixels[][8] = { { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00}, |
| 4608 | { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00}, |
| 4609 | { 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF}, |
| 4610 | { 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF}, |
| 4611 | { 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF}, |
| 4612 | { 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF}, |
| 4613 | { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00}, |
| 4614 | { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00} }; |
| 4615 | SkBitmap bitmap; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4616 | bitmap.installPixels(SkImageInfo::MakeA8(8, 8), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4617 | (void*) pixels, sizeof(pixels[0])); |
| 4618 | SkPaint paint; |
| 4619 | paint.setFilterQuality(kHigh_SkFilterQuality); |
| 4620 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xFF007F00, 0xFF7f007f} ) { |
| 4621 | paint.setColor(color); |
| 4622 | canvas->drawBitmapRect(bitmap, SkIRect::MakeWH(8, 8), SkRect::MakeWH(32, 32), &paint); |
| 4623 | canvas->translate(48.25f, 0); |
| 4624 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4625 | } |
| 4626 | ## |
| 4627 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4628 | #SeeAlso drawImageRect drawBitmap drawBitmapLattice drawBitmapNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4629 | |
| 4630 | ## |
| 4631 | |
| 4632 | # ------------------------------------------------------------------------------ |
| 4633 | |
| 4634 | #Method void drawBitmapRect(const SkBitmap& bitmap, const SkRect& dst, const SkPaint* paint, |
| 4635 | SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4636 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4637 | #In Draw |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4638 | Draw Bitmap bitmap, scaled and translated to fill Rect dst. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4639 | bitmap bounds is on integer pixel boundaries; dst may include fractional boundaries. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4640 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4641 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4642 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4643 | Blend_Mode, and Draw_Looper. If bitmap is kAlpha_8_SkColorType, apply Shader. |
| 4644 | If paint contains Mask_Filter, generate mask from bitmap bounds. |
| 4645 | |
| 4646 | If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, |
| 4647 | just as Shader made from SkShader::MakeBitmapShader with |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4648 | SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4649 | outside of its bounds. |
| 4650 | |
| 4651 | constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4652 | sample within bitmap; set to kFast_SrcRectConstraint allows sampling outside to |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4653 | improve performance. |
| 4654 | |
| 4655 | #Param bitmap Bitmap containing pixels, dimensions, and format ## |
| 4656 | #Param dst destination Rect of image to draw to ## |
| 4657 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4658 | and so on; or nullptr |
| 4659 | ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4660 | #Param constraint filter strictly within bitmap or draw faster ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4661 | |
| 4662 | #Example |
| 4663 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4664 | void draw(SkCanvas* canvas) { |
| 4665 | uint32_t pixels[][2] = { { 0x00000000, 0x55550000}, |
| 4666 | { 0xAAAA0000, 0xFFFF0000} }; |
| 4667 | SkBitmap bitmap; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4668 | bitmap.installPixels(SkImageInfo::MakeN32Premul(2, 2), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4669 | (void*) pixels, sizeof(pixels[0])); |
| 4670 | SkPaint paint; |
| 4671 | canvas->scale(4, 4); |
| 4672 | for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN } ) { |
| 4673 | paint.setColorFilter(SkColorFilter::MakeModeFilter(color, SkBlendMode::kPlus)); |
| 4674 | canvas->drawBitmapRect(bitmap, SkRect::MakeWH(8, 8), &paint); |
| 4675 | canvas->translate(8, 0); |
| 4676 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4677 | } |
| 4678 | ## |
| 4679 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4680 | #SeeAlso drawImageRect drawBitmap drawBitmapLattice drawBitmapNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4681 | |
| 4682 | ## |
| 4683 | |
| 4684 | # ------------------------------------------------------------------------------ |
| 4685 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4686 | #PhraseDef paint_as_used_by_draw_lattice_or_draw_nine(bitmap_or_image) |
| 4687 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4688 | Blend_Mode, and Draw_Looper. If #bitmap_or_image# is kAlpha_8_SkColorType, apply Shader. |
| 4689 | If paint contains Mask_Filter, generate mask from #bitmap_or_image# bounds. If paint |
| 4690 | Filter_Quality set to kNone_SkFilterQuality, disable pixel filtering. For all |
| 4691 | other values of paint Filter_Quality, use kLow_SkFilterQuality to filter pixels. |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 4692 | Any SkMaskFilter on paint is ignored as is paint Anti_Aliasing state. |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4693 | ## |
| 4694 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4695 | #Method void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4696 | const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4697 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4698 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4699 | #Line # draws Nine_Patch Bitmap ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4700 | |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 4701 | Draw Bitmap bitmap stretched proportionally to fit into Rect dst. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4702 | IRect center divides the bitmap into nine sections: four sides, four corners, |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4703 | 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] | 4704 | sides are larger than dst; center and four sides are scaled to fit remaining |
| 4705 | space, if any. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4706 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4707 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
| 4708 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4709 | #paint_as_used_by_draw_lattice_or_draw_nine(bitmap)# |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4710 | |
| 4711 | If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, |
| 4712 | just as Shader made from SkShader::MakeBitmapShader with |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4713 | SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4714 | outside of its bounds. |
| 4715 | |
| 4716 | #Param bitmap Bitmap containing pixels, dimensions, and format ## |
| 4717 | #Param center IRect edge of image corners and sides ## |
| 4718 | #Param dst destination Rect of image to draw to ## |
| 4719 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4720 | and so on; or nullptr |
| 4721 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4722 | |
| 4723 | #Example |
| 4724 | #Height 128 |
| 4725 | #Description |
| 4726 | The two leftmost bitmap draws has four corners and sides to the left and right of center. |
| 4727 | The leftmost bitmap draw scales the width of corners proportionately to fit. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4728 | 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] | 4729 | fill the remaining space. |
| 4730 | The rightmost bitmap draw has four corners scaled vertically to fit, and uses sides above |
| 4731 | and below center to fill the remaining space. |
| 4732 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4733 | void draw(SkCanvas* canvas) { |
| 4734 | SkIRect center = { 20, 10, 50, 40 }; |
| 4735 | SkBitmap bitmap; |
| 4736 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60)); |
| 4737 | SkCanvas bitCanvas(bitmap); |
| 4738 | SkPaint paint; |
| 4739 | SkColor gray = 0xFF000000; |
| 4740 | int left = 0; |
| 4741 | for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) { |
| 4742 | int top = 0; |
| 4743 | for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) { |
| 4744 | paint.setColor(gray); |
| 4745 | bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint); |
| 4746 | gray += 0x001f1f1f; |
| 4747 | top = bottom; |
| 4748 | } |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4749 | left = right; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4750 | } |
| 4751 | for (auto dest: { 20, 30, 40, 60, 90 } ) { |
| 4752 | canvas->drawBitmapNine(bitmap, center, SkRect::MakeWH(dest, 110 - dest), nullptr); |
| 4753 | canvas->translate(dest + 4, 0); |
| 4754 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4755 | } |
| 4756 | ## |
| 4757 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4758 | #SeeAlso drawImageNine drawBitmap drawBitmapLattice drawBitmapRect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4759 | |
| 4760 | ## |
| 4761 | |
| 4762 | # ------------------------------------------------------------------------------ |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4763 | #Subtopic Lattice |
| 4764 | #Line # divides Bitmap or Image into a rectangular grid ## |
| 4765 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4766 | #Struct Lattice |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 4767 | #Line # divides Bitmap or Image into a rectangular grid ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4768 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4769 | #Code |
| 4770 | struct Lattice { |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4771 | enum RectType ... |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4772 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4773 | const int* fXDivs; |
| 4774 | const int* fYDivs; |
| 4775 | const RectType* fRectTypes; |
| 4776 | int fXCount; |
| 4777 | int fYCount; |
| 4778 | const SkIRect* fBounds; |
| 4779 | const SkColor* fColors; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4780 | }; |
| 4781 | ## |
| 4782 | |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 4783 | Lattice divides Bitmap or Image into a rectangular grid. |
| 4784 | Grid entries on even columns and even rows are fixed; these entries are |
| 4785 | always drawn at their original size if the destination is large enough. |
| 4786 | If the destination side is too small to hold the fixed entries, all fixed |
| 4787 | entries are proportionately scaled down to fit. |
| 4788 | The grid entries not on even columns and rows are scaled to fit the |
| 4789 | remaining space, if any. |
| 4790 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4791 | #Subtopic Overview |
| 4792 | #Populate |
| 4793 | ## |
| 4794 | |
| 4795 | #Subtopic Constant |
| 4796 | #Populate |
| 4797 | ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4798 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4799 | #Enum RectType |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4800 | #Line # optional setting per rectangular grid entry ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4801 | #Code |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4802 | enum RectType : uint8_t { |
| 4803 | kDefault = 0, |
| 4804 | kTransparent, |
| 4805 | kFixedColor, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4806 | }; |
| 4807 | ## |
| 4808 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4809 | Optional setting per rectangular grid entry to make it transparent, |
| 4810 | or to fill the grid entry with a color. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4811 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4812 | #Const kDefault 0 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4813 | #Line # draws Bitmap into lattice rectangle ## |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4814 | ## |
| 4815 | |
| 4816 | #Const kTransparent 1 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4817 | #Line # skips lattice rectangle by making it transparent ## |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4818 | ## |
| 4819 | |
| 4820 | #Const kFixedColor 2 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4821 | #Line # draws one of fColors into lattice rectangle ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4822 | ## |
| 4823 | ## |
| 4824 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4825 | #Subtopic Member |
| 4826 | #Populate |
| 4827 | ## |
| 4828 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4829 | #Member const int* fXDivs |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4830 | #Line # x-coordinates dividing bitmap ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4831 | Array of x-coordinates that divide the bitmap vertically. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4832 | Array entries must be unique, increasing, greater than or equal to |
| 4833 | fBounds left edge, and less than fBounds right edge. |
| 4834 | Set the first element to fBounds left to collapse the left column of |
| 4835 | fixed grid entries. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4836 | ## |
| 4837 | |
| 4838 | #Member const int* fYDivs |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4839 | #Line # y-coordinates dividing bitmap ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4840 | Array of y-coordinates that divide the bitmap horizontally. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4841 | Array entries must be unique, increasing, greater than or equal to |
| 4842 | fBounds top edge, and less than fBounds bottom edge. |
| 4843 | Set the first element to fBounds top to collapse the top row of fixed |
| 4844 | grid entries. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4845 | ## |
| 4846 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4847 | #Member const RectType* fRectTypes |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4848 | #Line # array of fill types ## |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4849 | Optional array of fill types, one per rectangular grid entry: |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4850 | array length must be |
| 4851 | #Formula |
| 4852 | (fXCount + 1) * (fYCount + 1) |
| 4853 | ## |
| 4854 | . |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 4855 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4856 | Each RectType is one of: kDefault, kTransparent, kFixedColor. |
| 4857 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4858 | Array entries correspond to the rectangular grid entries, ascending |
| 4859 | left to right and then top to bottom. |
| 4860 | ## |
| 4861 | |
| 4862 | #Member int fXCount |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4863 | #Line # number of x-coordinates ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4864 | Number of entries in fXDivs array; one less than the number of |
| 4865 | horizontal divisions. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4866 | ## |
| 4867 | |
| 4868 | #Member int fYCount |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4869 | #Line # number of y-coordinates ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4870 | Number of entries in fYDivs array; one less than the number of vertical |
| 4871 | divisions. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4872 | ## |
| 4873 | |
| 4874 | #Member const SkIRect* fBounds |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4875 | #Line # source bounds to draw from ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4876 | Optional subset IRect source to draw from. |
| 4877 | If nullptr, source bounds is dimensions of Bitmap or Image. |
| 4878 | ## |
| 4879 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4880 | #Member const SkColor* fColors |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4881 | #Line # array of colors ## |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4882 | Optional array of colors, one per rectangular grid entry. |
| 4883 | Array length must be |
| 4884 | #Formula |
| 4885 | (fXCount + 1) * (fYCount + 1) |
| 4886 | ## |
| 4887 | . |
| 4888 | |
| 4889 | Array entries correspond to the rectangular grid entries, ascending |
| 4890 | left to right, then top to bottom. |
| 4891 | ## |
| 4892 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4893 | #Struct Lattice ## |
| 4894 | |
| 4895 | #Method void drawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice, const SkRect& dst, |
| 4896 | const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4897 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4898 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4899 | #Line # draws proportionally stretched Bitmap ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4900 | |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 4901 | Draw Bitmap bitmap stretched proportionally to fit into Rect dst. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4902 | |
| 4903 | Lattice lattice divides bitmap into a rectangular grid. |
| 4904 | 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] | 4905 | of drawBitmapNine, fixed lattice elements never scale larger than their initial |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4906 | size and shrink proportionately when all fixed elements exceed the bitmap |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4907 | 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] | 4908 | |
| 4909 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4910 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4911 | #paint_as_used_by_draw_lattice_or_draw_nine(bitmap)# |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4912 | |
| 4913 | If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, |
| 4914 | just as Shader made from SkShader::MakeBitmapShader with |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4915 | SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4916 | outside of its bounds. |
| 4917 | |
| 4918 | #Param bitmap Bitmap containing pixels, dimensions, and format ## |
| 4919 | #Param lattice division of bitmap into fixed and variable rectangles ## |
| 4920 | #Param dst destination Rect of image to draw to ## |
| 4921 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4922 | and so on; or nullptr |
| 4923 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4924 | |
| 4925 | #Example |
| 4926 | #Height 128 |
| 4927 | #Description |
| 4928 | The two leftmost bitmap draws has four corners and sides to the left and right of center. |
| 4929 | The leftmost bitmap draw scales the width of corners proportionately to fit. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4930 | 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] | 4931 | fill the remaining space; the center is transparent. |
| 4932 | The rightmost bitmap draw has four corners scaled vertically to fit, and uses sides above |
| 4933 | and below center to fill the remaining space. |
| 4934 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4935 | void draw(SkCanvas* canvas) { |
| 4936 | SkIRect center = { 20, 10, 50, 40 }; |
| 4937 | SkBitmap bitmap; |
| 4938 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60)); |
| 4939 | SkCanvas bitCanvas(bitmap); |
| 4940 | SkPaint paint; |
| 4941 | SkColor gray = 0xFF000000; |
| 4942 | int left = 0; |
| 4943 | for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) { |
| 4944 | int top = 0; |
| 4945 | for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) { |
| 4946 | paint.setColor(gray); |
| 4947 | bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint); |
| 4948 | gray += 0x001f1f1f; |
| 4949 | top = bottom; |
| 4950 | } |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4951 | left = right; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4952 | } |
| 4953 | const int xDivs[] = { center.fLeft, center.fRight }; |
| 4954 | const int yDivs[] = { center.fTop, center.fBottom }; |
Cary Clark | ca3ebcd | 2017-12-12 11:22:38 -0500 | [diff] [blame] | 4955 | SkCanvas::Lattice::RectType fillTypes[3][3]; |
| 4956 | memset(fillTypes, 0, sizeof(fillTypes)); |
| 4957 | fillTypes[1][1] = SkCanvas::Lattice::kTransparent; |
| 4958 | SkColor dummy[9]; // temporary pending bug fix |
| 4959 | SkCanvas::Lattice lattice = { xDivs, yDivs, fillTypes[0], SK_ARRAY_COUNT(xDivs), |
| 4960 | SK_ARRAY_COUNT(yDivs), nullptr, dummy }; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4961 | for (auto dest: { 20, 30, 40, 60, 90 } ) { |
Cary Clark | ca3ebcd | 2017-12-12 11:22:38 -0500 | [diff] [blame] | 4962 | canvas->drawBitmapLattice(bitmap, lattice, SkRect::MakeWH(dest, 110 - dest), nullptr); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4963 | canvas->translate(dest + 4, 0); |
| 4964 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4965 | } |
| 4966 | ## |
| 4967 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4968 | #SeeAlso drawImageLattice drawBitmap drawBitmapNine Lattice |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4969 | |
| 4970 | ## |
| 4971 | |
| 4972 | # ------------------------------------------------------------------------------ |
| 4973 | |
| 4974 | #Method void drawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst, |
| 4975 | const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4976 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4977 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4978 | #Line # draws proportionally stretched Image ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4979 | |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 4980 | Draw Image image stretched proportionally to fit into Rect dst. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4981 | |
| 4982 | Lattice lattice divides image into a rectangular grid. |
| 4983 | 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] | 4984 | of drawBitmapNine, fixed lattice elements never scale larger than their initial |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4985 | size and shrink proportionately when all fixed elements exceed the bitmap |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4986 | 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] | 4987 | |
| 4988 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4989 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4990 | #paint_as_used_by_draw_lattice_or_draw_nine(image)# |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4991 | |
| 4992 | If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, |
| 4993 | just as Shader made from SkShader::MakeBitmapShader with |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4994 | SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4995 | outside of its bounds. |
| 4996 | |
| 4997 | #Param image Image containing pixels, dimensions, and format ## |
| 4998 | #Param lattice division of bitmap into fixed and variable rectangles ## |
| 4999 | #Param dst destination Rect of image to draw to ## |
| 5000 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 5001 | and so on; or nullptr |
| 5002 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5003 | |
| 5004 | #Example |
| 5005 | #Height 128 |
| 5006 | #Description |
| 5007 | 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] | 5008 | The second image equals the size of center; only corners are drawn without scaling. |
| 5009 | 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] | 5010 | are scaled if needed to take up the remaining space; the center is transparent. |
| 5011 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5012 | void draw(SkCanvas* canvas) { |
| 5013 | SkIRect center = { 20, 10, 50, 40 }; |
| 5014 | SkBitmap bitmap; |
| 5015 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60)); |
| 5016 | SkCanvas bitCanvas(bitmap); |
| 5017 | SkPaint paint; |
| 5018 | SkColor gray = 0xFF000000; |
| 5019 | int left = 0; |
| 5020 | for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) { |
| 5021 | int top = 0; |
| 5022 | for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) { |
| 5023 | paint.setColor(gray); |
| 5024 | bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint); |
| 5025 | gray += 0x001f1f1f; |
| 5026 | top = bottom; |
| 5027 | } |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5028 | left = right; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5029 | } |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5030 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 5031 | SkImage* imagePtr = image.get(); |
| 5032 | for (auto dest: { 20, 30, 40, 60, 90 } ) { |
| 5033 | canvas->drawImageNine(imagePtr, center, SkRect::MakeWH(dest, dest), nullptr); |
| 5034 | canvas->translate(dest + 4, 0); |
| 5035 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5036 | } |
| 5037 | ## |
| 5038 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5039 | #SeeAlso drawBitmapLattice drawImage drawImageNine Lattice |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5040 | |
| 5041 | ## |
| 5042 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5043 | #Subtopic Lattice ## |
| 5044 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 5045 | #Subtopic Draw_Image ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5046 | |
| 5047 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5048 | #Subtopic Draw_Text |
| 5049 | #Populate |
| 5050 | #Line # draws text into Canvas ## |
| 5051 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5052 | |
| 5053 | #Method void drawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, |
| 5054 | const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5055 | #In Draw_Text |
| 5056 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5057 | #Line # draws text at (x, y), using font advance ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5058 | |
| 5059 | Draw text, with origin at (x, y), using Clip, Matrix, and Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5060 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5061 | 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] | 5062 | UTF-8. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5063 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5064 | 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] | 5065 | 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] | 5066 | 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] | 5067 | |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 5068 | All elements of paint: Path_Effect, Mask_Filter, Shader, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5069 | 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] | 5070 | filled 12 point black Glyphs. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5071 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5072 | #Param text character code points or Glyphs drawn ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5073 | #Param byteLength byte length of text array ## |
| 5074 | #Param x start of text on x-axis ## |
| 5075 | #Param y start of text on y-axis ## |
| 5076 | #Param paint text size, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5077 | |
| 5078 | #Example |
| 5079 | #Height 200 |
| 5080 | #Description |
| 5081 | The same text is drawn varying Paint_Text_Size and varying |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5082 | Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5083 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5084 | void draw(SkCanvas* canvas) { |
| 5085 | SkPaint paint; |
| 5086 | paint.setAntiAlias(true); |
| 5087 | float textSizes[] = { 12, 18, 24, 36 }; |
| 5088 | for (auto size: textSizes ) { |
| 5089 | paint.setTextSize(size); |
| 5090 | canvas->drawText("Aa", 2, 10, 20, paint); |
| 5091 | canvas->translate(0, size * 2); |
| 5092 | } |
| 5093 | paint.reset(); |
| 5094 | paint.setAntiAlias(true); |
| 5095 | float yPos = 20; |
| 5096 | for (auto size: textSizes ) { |
| 5097 | float scale = size / 12.f; |
| 5098 | canvas->resetMatrix(); |
| 5099 | canvas->translate(100, 0); |
| 5100 | canvas->scale(scale, scale); |
| 5101 | canvas->drawText("Aa", 2, 10 / scale, yPos / scale, paint); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5102 | yPos += size * 2; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5103 | } |
| 5104 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5105 | ## |
| 5106 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5107 | #SeeAlso drawString drawPosText drawPosTextH drawTextBlob drawTextOnPath drawTextRSXform |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5108 | |
| 5109 | ## |
| 5110 | |
| 5111 | #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] | 5112 | #In Draw_Text |
| 5113 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5114 | #Line # draws null terminated string at (x, y) using font advance ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5115 | Draws null terminated string, with origin at (x, y), using Clip, Matrix, and |
| 5116 | Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5117 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5118 | string meaning depends on Paint_Text_Encoding; by default, strings are encoded |
| 5119 | 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] | 5120 | results, since zero bytes may be embedded in the string. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5121 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5122 | 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] | 5123 | 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] | 5124 | 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] | 5125 | |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 5126 | All elements of paint: Path_Effect, Mask_Filter, Shader, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5127 | 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] | 5128 | filled 12 point black Glyphs. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5129 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5130 | #Param string character code points or Glyphs drawn, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5131 | ending with a char value of zero |
| 5132 | ## |
| 5133 | #Param x start of string on x-axis ## |
| 5134 | #Param y start of string on y-axis ## |
| 5135 | #Param paint text size, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5136 | |
| 5137 | #Example |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 5138 | #Height 48 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5139 | SkPaint paint; |
| 5140 | canvas->drawString("a small hello", 20, 20, paint); |
| 5141 | ## |
| 5142 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5143 | #SeeAlso drawText drawPosText drawPosTextH drawTextBlob drawTextOnPath drawTextRSXform |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5144 | |
| 5145 | ## |
| 5146 | |
| 5147 | #Method void drawString(const SkString& string, SkScalar x, SkScalar y, const SkPaint& paint) |
| 5148 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5149 | Draw null terminated string, with origin at (x, y), using Clip, Matrix, and |
| 5150 | Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5151 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5152 | string meaning depends on Paint_Text_Encoding; by default, strings are encoded |
| 5153 | 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] | 5154 | results, since zero bytes may be embedded in the string. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5155 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5156 | 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] | 5157 | 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] | 5158 | 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] | 5159 | |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 5160 | All elements of paint: Path_Effect, Mask_Filter, Shader, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5161 | 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] | 5162 | filled 12 point black Glyphs. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5163 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5164 | #Param string character code points or Glyphs drawn, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5165 | ending with a char value of zero |
| 5166 | ## |
| 5167 | #Param x start of string on x-axis ## |
| 5168 | #Param y start of string on y-axis ## |
| 5169 | #Param paint text size, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5170 | |
| 5171 | #Example |
| 5172 | SkPaint paint; |
| 5173 | SkString string("a small hello"); |
| 5174 | canvas->drawString(string, 20, 20, paint); |
| 5175 | ## |
| 5176 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5177 | #SeeAlso drawText drawPosText drawPosTextH drawTextBlob drawTextOnPath drawTextRSXform |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5178 | |
| 5179 | ## |
| 5180 | |
| 5181 | # ------------------------------------------------------------------------------ |
| 5182 | |
| 5183 | #Method void drawPosText(const void* text, size_t byteLength, const SkPoint pos[], |
| 5184 | const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5185 | #In Draw_Text |
| 5186 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5187 | #Line # draws text at array of (x, y) positions ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5188 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5189 | Draw 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] | 5190 | 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] | 5191 | described by byteLength of text. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5192 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5193 | 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] | 5194 | UTF-8. pos elements meaning depends on Paint_Vertical_Text; |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5195 | by default each glyph left side bearing is positioned at x and its |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5196 | baseline is positioned at y. Text size is affected by Matrix and |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5197 | Paint_Text_Size. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5198 | |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 5199 | All elements of paint: Path_Effect, Mask_Filter, Shader, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5200 | 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] | 5201 | filled 12 point black Glyphs. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5202 | |
| 5203 | Layout engines such as Harfbuzz typically position each glyph |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5204 | rather than using the font advance widths. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5205 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5206 | #Param text character code points or Glyphs drawn ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5207 | #Param byteLength byte length of text array ## |
| 5208 | #Param pos array of glyph origins ## |
| 5209 | #Param paint text size, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5210 | |
| 5211 | #Example |
| 5212 | #Height 120 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5213 | void draw(SkCanvas* canvas) { |
| 5214 | const char hello[] = "HeLLo!"; |
| 5215 | const SkPoint pos[] = { {40, 100}, {82, 95}, {115, 110}, {130, 95}, {145, 85}, |
| 5216 | {172, 100} }; |
| 5217 | SkPaint paint; |
| 5218 | paint.setTextSize(60); |
| 5219 | canvas->drawPosText(hello, strlen(hello), pos, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5220 | } |
| 5221 | ## |
| 5222 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5223 | #SeeAlso drawText drawPosTextH drawTextBlob drawTextOnPath drawTextRSXform |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5224 | |
| 5225 | ## |
| 5226 | |
| 5227 | # ------------------------------------------------------------------------------ |
| 5228 | |
| 5229 | #Method void drawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], SkScalar constY, |
| 5230 | const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5231 | #In Draw_Text |
| 5232 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5233 | #Line # draws text at x positions with common baseline ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5234 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5235 | Draw each glyph in text with its (x, y) origin composed from xpos array and |
| 5236 | 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] | 5237 | must match the number of Glyphs described by byteLength of text. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5238 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5239 | 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] | 5240 | UTF-8. xpos elements meaning depends on Paint_Vertical_Text; |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5241 | 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] | 5242 | 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] | 5243 | Paint_Text_Size. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5244 | |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 5245 | All elements of paint: Path_Effect, Mask_Filter, Shader, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5246 | 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] | 5247 | filled 12 point black Glyphs. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5248 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5249 | Layout engines such as Harfbuzz typically position each glyph |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5250 | 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] | 5251 | baseline. |
| 5252 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5253 | #Param text character code points or Glyphs drawn ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5254 | #Param byteLength byte length of text array ## |
| 5255 | #Param xpos array of x positions, used to position each glyph ## |
| 5256 | #Param constY shared y coordinate for all of x positions ## |
| 5257 | #Param paint text size, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5258 | |
| 5259 | #Example |
| 5260 | #Height 40 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5261 | void draw(SkCanvas* canvas) { |
| 5262 | SkScalar xpos[] = { 20, 40, 80, 160 }; |
| 5263 | SkPaint paint; |
| 5264 | canvas->drawPosTextH("XXXX", 4, xpos, 20, paint); |
| 5265 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5266 | ## |
| 5267 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5268 | #SeeAlso drawText drawPosText drawTextBlob drawTextOnPath drawTextRSXform |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5269 | |
| 5270 | ## |
| 5271 | |
| 5272 | # ------------------------------------------------------------------------------ |
| 5273 | |
| 5274 | #Method void drawTextOnPathHV(const void* text, size_t byteLength, const SkPath& path, SkScalar hOffset, |
| 5275 | SkScalar vOffset, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5276 | #In Draw_Text |
| 5277 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5278 | #Line # draws text following Path with offsets ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5279 | |
| 5280 | Draw text on Path path, using Clip, Matrix, and Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5281 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5282 | Origin of text is at distance hOffset along the path, offset by a perpendicular |
| 5283 | vector of length vOffset. If the path section corresponding the glyph advance is |
| 5284 | 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] | 5285 | 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] | 5286 | than the path length, the excess text is clipped. |
| 5287 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5288 | 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] | 5289 | UTF-8. Origin meaning depends on Paint_Text_Align and Paint_Vertical_Text; by |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5290 | default text positions the first glyph left side bearing at origin x and its |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5291 | baseline at origin y. Text size is affected by Matrix and Paint_Text_Size. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5292 | |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 5293 | All elements of paint: Path_Effect, Mask_Filter, Shader, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5294 | 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] | 5295 | filled 12 point black Glyphs. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5296 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5297 | #Param text character code points or Glyphs drawn ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5298 | #Param byteLength byte length of text array ## |
| 5299 | #Param path Path providing text baseline ## |
| 5300 | #Param hOffset distance along path to offset origin ## |
| 5301 | #Param vOffset offset of text above (if negative) or below (if positive) the path ## |
| 5302 | #Param paint text size, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5303 | |
| 5304 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5305 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5306 | const char aero[] = "correo a" "\xC3" "\xA9" "reo"; |
| 5307 | const size_t len = sizeof(aero) - 1; |
| 5308 | SkPath path; |
| 5309 | path.addOval({43-26, 43-26, 43+26, 43+26}, SkPath::kCW_Direction, 3); |
| 5310 | SkPaint paint; |
| 5311 | paint.setTextSize(24); |
| 5312 | for (auto offset : { 0, 10, 20 } ) { |
| 5313 | canvas->drawTextOnPathHV(aero, len, path, 0, -offset, paint); |
| 5314 | canvas->translate(70 + offset, 70 + offset); |
| 5315 | } |
| 5316 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5317 | ## |
| 5318 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5319 | #SeeAlso drawTextOnPath drawText drawPosTextH drawTextBlob drawTextRSXform |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5320 | |
| 5321 | ## |
| 5322 | |
| 5323 | # ------------------------------------------------------------------------------ |
| 5324 | |
| 5325 | #Method void drawTextOnPath(const void* text, size_t byteLength, const SkPath& path, |
| 5326 | const SkMatrix* matrix, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5327 | #In Draw_Text |
| 5328 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5329 | #Line # draws text following Path contour ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5330 | |
| 5331 | Draw text on Path path, using Clip, Matrix, and Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5332 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5333 | 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] | 5334 | 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] | 5335 | corresponding the glyph advance is curved, the glyph is drawn curved to match; |
| 5336 | control points in the glyph are mapped to projected points parallel to the path. |
| 5337 | 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] | 5338 | |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 5339 | matrix does not effect paint Shader. |
| 5340 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5341 | 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] | 5342 | UTF-8. Origin meaning depends on Paint_Text_Align and Paint_Vertical_Text; by |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5343 | default text positions the first glyph left side bearing at origin x and its |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 5344 | baseline at origin y. Text size is affected by matrix parameter, Canvas Matrix, |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5345 | and Paint_Text_Size. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5346 | |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 5347 | All elements of paint: Path_Effect, Mask_Filter, Shader, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5348 | 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] | 5349 | filled 12 point black Glyphs. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5350 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5351 | #Param text character code points or Glyphs drawn ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5352 | #Param byteLength byte length of text array ## |
| 5353 | #Param path Path providing text baseline ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5354 | #Param matrix transform of Glyphs before mapping to path; may be nullptr |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 5355 | to use identity Matrix |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5356 | ## |
| 5357 | #Param paint text size, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5358 | |
| 5359 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5360 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5361 | const char roller[] = "rollercoaster"; |
| 5362 | const size_t len = sizeof(roller) - 1; |
| 5363 | SkPath path; |
| 5364 | path.cubicTo(40, -80, 120, 80, 160, -40); |
| 5365 | SkPaint paint; |
| 5366 | paint.setTextSize(32); |
| 5367 | paint.setStyle(SkPaint::kStroke_Style); |
| 5368 | SkMatrix matrix; |
| 5369 | matrix.setIdentity(); |
| 5370 | for (int i = 0; i < 3; ++i) { |
| 5371 | canvas->translate(25, 60); |
| 5372 | canvas->drawPath(path, paint); |
| 5373 | canvas->drawTextOnPath(roller, len, path, &matrix, paint); |
| 5374 | matrix.preTranslate(0, 10); |
| 5375 | } |
| 5376 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5377 | ## |
| 5378 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5379 | #SeeAlso drawTextOnPathHV drawText drawPosTextH drawTextBlob drawTextRSXform |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5380 | |
| 5381 | ## |
| 5382 | |
| 5383 | # ------------------------------------------------------------------------------ |
| 5384 | |
| 5385 | #Method void drawTextRSXform(const void* text, size_t byteLength, const SkRSXform xform[], |
| 5386 | const SkRect* cullRect, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5387 | #In Draw_Text |
| 5388 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5389 | #Line # draws text with array of RSXform ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5390 | |
| 5391 | Draw text, transforming each glyph by the corresponding SkRSXform, |
| 5392 | using Clip, Matrix, and Paint paint. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5393 | |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 5394 | RSXform xform array specifies a separate square scale, rotation, and translation |
| 5395 | for each glyph. xform does not affect paint Shader. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5396 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5397 | Optional Rect cullRect is a conservative bounds of text, taking into account |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5398 | 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] | 5399 | |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 5400 | All elements of paint: Path_Effect, Mask_Filter, Shader, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5401 | 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] | 5402 | filled 12 point black Glyphs. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5403 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5404 | #Param text character code points or Glyphs drawn ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5405 | #Param byteLength byte length of text array ## |
| 5406 | #Param xform RSXform rotates, scales, and translates each glyph individually ## |
| 5407 | #Param cullRect Rect bounds of text for efficient clipping; or nullptr ## |
| 5408 | #Param paint text size, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5409 | |
| 5410 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5411 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5412 | const int iterations = 26; |
| 5413 | SkRSXform transforms[iterations]; |
| 5414 | char alphabet[iterations]; |
| 5415 | SkScalar angle = 0; |
| 5416 | SkScalar scale = 1; |
| 5417 | for (size_t i = 0; i < SK_ARRAY_COUNT(transforms); ++i) { |
| 5418 | const SkScalar s = SkScalarSin(angle) * scale; |
| 5419 | const SkScalar c = SkScalarCos(angle) * scale; |
| 5420 | transforms[i] = SkRSXform::Make(-c, -s, -s * 16, c * 16); |
| 5421 | angle += .45; |
| 5422 | scale += .2; |
| 5423 | alphabet[i] = 'A' + i; |
| 5424 | } |
| 5425 | SkPaint paint; |
| 5426 | paint.setTextAlign(SkPaint::kCenter_Align); |
| 5427 | canvas->translate(110, 138); |
| 5428 | canvas->drawTextRSXform(alphabet, sizeof(alphabet), transforms, nullptr, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5429 | } |
| 5430 | ## |
| 5431 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5432 | #SeeAlso drawTextOnPath drawTextOnPathHV drawText drawPosText drawTextBlob |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5433 | |
| 5434 | ## |
| 5435 | |
| 5436 | # ------------------------------------------------------------------------------ |
| 5437 | |
| 5438 | #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] | 5439 | #In Draw_Text |
| 5440 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5441 | #Line # draws text with arrays of positions and Paint ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5442 | Draw Text_Blob blob at (x, y), using Clip, Matrix, and Paint paint. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5443 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5444 | blob contains Glyphs, their positions, and paint attributes specific to text: |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5445 | Typeface, Paint_Text_Size, Paint_Text_Scale_X, Paint_Text_Skew_X, |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 5446 | Paint_Text_Align, Paint_Hinting, Anti_Alias, Paint_Fake_Bold, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5447 | Font_Embedded_Bitmaps, Full_Hinting_Spacing, LCD_Text, Linear_Text, |
| 5448 | Subpixel_Text, and Paint_Vertical_Text. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5449 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 5450 | Paint_Text_Encoding must be set to SkPaint::kGlyphID_TextEncoding. |
| 5451 | |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 5452 | Elements of paint: Path_Effect, Mask_Filter, Shader, Color_Filter, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5453 | Image_Filter, and Draw_Looper; apply to blob. |
| 5454 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5455 | #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] | 5456 | #Param x horizontal offset applied to blob ## |
| 5457 | #Param y vertical offset applied to blob ## |
| 5458 | #Param paint blend, color, stroking, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5459 | |
| 5460 | #Example |
| 5461 | #Height 120 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5462 | void draw(SkCanvas* canvas) { |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 5463 | SkTextBlobBuilder textBlobBuilder; |
| 5464 | const char bunny[] = "/(^x^)\\"; |
| 5465 | const int len = sizeof(bunny) - 1; |
| 5466 | uint16_t glyphs[len]; |
| 5467 | SkPaint paint; |
| 5468 | paint.textToGlyphs(bunny, len, glyphs); |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 5469 | paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 5470 | int runs[] = { 3, 1, 3 }; |
| 5471 | SkPoint textPos = { 20, 100 }; |
| 5472 | int glyphIndex = 0; |
| 5473 | for (auto runLen : runs) { |
| 5474 | paint.setTextSize(1 == runLen ? 20 : 50); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5475 | const SkTextBlobBuilder::RunBuffer& run = |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 5476 | textBlobBuilder.allocRun(paint, runLen, textPos.fX, textPos.fY); |
| 5477 | memcpy(run.glyphs, &glyphs[glyphIndex], sizeof(glyphs[0]) * runLen); |
| 5478 | textPos.fX += paint.measureText(&glyphs[glyphIndex], sizeof(glyphs[0]) * runLen, nullptr); |
| 5479 | glyphIndex += runLen; |
| 5480 | } |
| 5481 | sk_sp<const SkTextBlob> blob = textBlobBuilder.make(); |
| 5482 | paint.reset(); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5483 | canvas->drawTextBlob(blob.get(), 0, 0, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5484 | } |
| 5485 | ## |
| 5486 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5487 | #SeeAlso drawText drawPosText drawPosTextH |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5488 | |
| 5489 | ## |
| 5490 | |
| 5491 | # ------------------------------------------------------------------------------ |
| 5492 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5493 | #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] | 5494 | |
| 5495 | Draw Text_Blob blob at (x, y), using Clip, Matrix, and Paint paint. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5496 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5497 | blob contains Glyphs, their positions, and paint attributes specific to text: |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5498 | Typeface, Paint_Text_Size, Paint_Text_Scale_X, Paint_Text_Skew_X, |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 5499 | Paint_Text_Align, Paint_Hinting, Anti_Alias, Paint_Fake_Bold, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5500 | Font_Embedded_Bitmaps, Full_Hinting_Spacing, LCD_Text, Linear_Text, |
| 5501 | Subpixel_Text, and Paint_Vertical_Text. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5502 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 5503 | Paint_Text_Encoding must be set to SkPaint::kGlyphID_TextEncoding. |
| 5504 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5505 | Elements of paint: Path_Effect, Mask_Filter, Shader, Color_Filter, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5506 | Image_Filter, and Draw_Looper; apply to blob. |
| 5507 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5508 | #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] | 5509 | #Param x horizontal offset applied to blob ## |
| 5510 | #Param y vertical offset applied to blob ## |
| 5511 | #Param paint blend, color, stroking, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5512 | |
| 5513 | #Example |
| 5514 | #Height 120 |
| 5515 | #Description |
| 5516 | Paint attributes unrelated to text, like color, have no effect on paint in allocated Text_Blob. |
| 5517 | Paint attributes related to text, like text size, have no effect on paint passed to drawTextBlob. |
| 5518 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5519 | void draw(SkCanvas* canvas) { |
| 5520 | SkTextBlobBuilder textBlobBuilder; |
| 5521 | SkPaint paint; |
| 5522 | paint.setTextSize(50); |
| 5523 | paint.setColor(SK_ColorRED); |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 5524 | paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5525 | const SkTextBlobBuilder::RunBuffer& run = |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5526 | textBlobBuilder.allocRun(paint, 1, 20, 100); |
| 5527 | run.glyphs[0] = 20; |
| 5528 | sk_sp<const SkTextBlob> blob = textBlobBuilder.make(); |
| 5529 | paint.setTextSize(10); |
| 5530 | paint.setColor(SK_ColorBLUE); |
| 5531 | canvas->drawTextBlob(blob.get(), 0, 0, paint); |
| 5532 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5533 | ## |
| 5534 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5535 | #SeeAlso drawText drawPosText drawPosTextH |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5536 | |
| 5537 | ## |
| 5538 | |
| 5539 | # ------------------------------------------------------------------------------ |
| 5540 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5541 | #Method void drawPicture(const SkPicture* picture) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5542 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5543 | #Line # draws Picture using Clip and Matrix ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5544 | Draw Picture picture, using Clip and Matrix. |
| 5545 | Clip and Matrix are unchanged by picture contents, as if |
| 5546 | save() was called before and restore() was called after drawPicture. |
| 5547 | |
| 5548 | Picture records a series of draw commands for later playback. |
| 5549 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5550 | #Param picture recorded drawing commands to play ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5551 | |
| 5552 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5553 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5554 | SkPictureRecorder recorder; |
| 5555 | SkCanvas* recordingCanvas = recorder.beginRecording(50, 50); |
| 5556 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) { |
| 5557 | SkPaint paint; |
| 5558 | paint.setColor(color); |
| 5559 | recordingCanvas->drawRect({10, 10, 30, 40}, paint); |
| 5560 | recordingCanvas->translate(10, 10); |
| 5561 | recordingCanvas->scale(1.2f, 1.4f); |
| 5562 | } |
| 5563 | sk_sp<SkPicture> playback = recorder.finishRecordingAsPicture(); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5564 | canvas->drawPicture(playback); |
| 5565 | canvas->scale(2, 2); |
| 5566 | canvas->translate(50, 0); |
| 5567 | canvas->drawPicture(playback); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5568 | } |
| 5569 | ## |
| 5570 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5571 | #SeeAlso drawDrawable SkPicture SkPicture::playback |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5572 | |
| 5573 | ## |
| 5574 | |
| 5575 | # ------------------------------------------------------------------------------ |
| 5576 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5577 | #Method void drawPicture(const sk_sp<SkPicture>& picture) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5578 | |
| 5579 | Draw Picture picture, using Clip and Matrix. |
| 5580 | Clip and Matrix are unchanged by picture contents, as if |
| 5581 | save() was called before and restore() was called after drawPicture. |
| 5582 | |
| 5583 | Picture records a series of draw commands for later playback. |
| 5584 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5585 | #Param picture recorded drawing commands to play ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5586 | |
| 5587 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5588 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5589 | SkPictureRecorder recorder; |
| 5590 | SkCanvas* recordingCanvas = recorder.beginRecording(50, 50); |
| 5591 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) { |
| 5592 | SkPaint paint; |
| 5593 | paint.setColor(color); |
| 5594 | recordingCanvas->drawRect({10, 10, 30, 40}, paint); |
| 5595 | recordingCanvas->translate(10, 10); |
| 5596 | recordingCanvas->scale(1.2f, 1.4f); |
| 5597 | } |
| 5598 | sk_sp<SkPicture> playback = recorder.finishRecordingAsPicture(); |
| 5599 | canvas->drawPicture(playback); |
| 5600 | canvas->scale(2, 2); |
| 5601 | canvas->translate(50, 0); |
| 5602 | canvas->drawPicture(playback); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5603 | } |
| 5604 | ## |
| 5605 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5606 | #SeeAlso drawDrawable SkPicture SkPicture::playback |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5607 | |
| 5608 | ## |
| 5609 | |
| 5610 | # ------------------------------------------------------------------------------ |
| 5611 | |
| 5612 | #Method void drawPicture(const SkPicture* picture, const SkMatrix* matrix, const SkPaint* paint) |
| 5613 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5614 | Draw Picture picture, using Clip and Matrix; transforming picture with |
| 5615 | Matrix matrix, if provided; and use Paint paint Color_Alpha, Color_Filter, |
| 5616 | Image_Filter, and Blend_Mode, if provided. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5617 | |
| 5618 | matrix transformation is equivalent to: save(), concat(), drawPicture, restore(). |
| 5619 | paint use is equivalent to: saveLayer, drawPicture, restore(). |
| 5620 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5621 | #Param picture recorded drawing commands to play ## |
| 5622 | #Param matrix Matrix to rotate, scale, translate, and so on; may be nullptr ## |
| 5623 | #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] | 5624 | |
| 5625 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5626 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5627 | SkPaint paint; |
| 5628 | SkPictureRecorder recorder; |
| 5629 | SkCanvas* recordingCanvas = recorder.beginRecording(50, 50); |
| 5630 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) { |
| 5631 | paint.setColor(color); |
| 5632 | recordingCanvas->drawRect({10, 10, 30, 40}, paint); |
| 5633 | recordingCanvas->translate(10, 10); |
| 5634 | recordingCanvas->scale(1.2f, 1.4f); |
| 5635 | } |
| 5636 | sk_sp<SkPicture> playback = recorder.finishRecordingAsPicture(); |
| 5637 | const SkPicture* playbackPtr = playback.get(); |
| 5638 | SkMatrix matrix; |
| 5639 | matrix.reset(); |
| 5640 | for (auto alpha : { 70, 140, 210 } ) { |
| 5641 | paint.setAlpha(alpha); |
| 5642 | canvas->drawPicture(playbackPtr, &matrix, &paint); |
| 5643 | matrix.preTranslate(70, 70); |
| 5644 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5645 | } |
| 5646 | ## |
| 5647 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5648 | #SeeAlso drawDrawable SkPicture SkPicture::playback |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5649 | |
| 5650 | ## |
| 5651 | |
| 5652 | # ------------------------------------------------------------------------------ |
| 5653 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5654 | #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] | 5655 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5656 | Draw Picture picture, using Clip and Matrix; transforming picture with |
| 5657 | Matrix matrix, if provided; and use Paint paint Color_Alpha, Color_Filter, |
| 5658 | Image_Filter, and Blend_Mode, if provided. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5659 | |
| 5660 | matrix transformation is equivalent to: save(), concat(), drawPicture, restore(). |
| 5661 | paint use is equivalent to: saveLayer, drawPicture, restore(). |
| 5662 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5663 | #Param picture recorded drawing commands to play ## |
| 5664 | #Param matrix Matrix to rotate, scale, translate, and so on; may be nullptr ## |
| 5665 | #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] | 5666 | |
| 5667 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5668 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5669 | SkPaint paint; |
| 5670 | SkPictureRecorder recorder; |
| 5671 | SkCanvas* recordingCanvas = recorder.beginRecording(50, 50); |
| 5672 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) { |
| 5673 | paint.setColor(color); |
| 5674 | recordingCanvas->drawRect({10, 10, 30, 40}, paint); |
| 5675 | recordingCanvas->translate(10, 10); |
| 5676 | recordingCanvas->scale(1.2f, 1.4f); |
| 5677 | } |
| 5678 | sk_sp<SkPicture> playback = recorder.finishRecordingAsPicture(); |
| 5679 | SkMatrix matrix; |
| 5680 | matrix.reset(); |
| 5681 | for (auto alpha : { 70, 140, 210 } ) { |
| 5682 | paint.setAlpha(alpha); |
| 5683 | canvas->drawPicture(playback, &matrix, &paint); |
| 5684 | matrix.preTranslate(70, 70); |
| 5685 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5686 | } |
| 5687 | ## |
| 5688 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5689 | #SeeAlso drawDrawable SkPicture SkPicture::playback |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5690 | |
| 5691 | ## |
| 5692 | |
| 5693 | # ------------------------------------------------------------------------------ |
| 5694 | |
| 5695 | #Method void drawVertices(const SkVertices* vertices, SkBlendMode mode, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5696 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5697 | #Line # draws Vertices, a triangle mesh ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5698 | Draw Vertices vertices, a triangle mesh, using Clip and Matrix. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5699 | If Vertices_Texs and Vertices_Colors are defined in vertices, and Paint paint |
| 5700 | contains Shader, Blend_Mode mode combines Vertices_Colors with Shader. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5701 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5702 | #Param vertices triangle mesh to draw ## |
| 5703 | #Param mode combines Vertices_Colors with Shader, if both are present ## |
| 5704 | #Param paint specifies the Shader, used as Vertices texture; may be nullptr ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5705 | |
| 5706 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5707 | void draw(SkCanvas* canvas) { |
| 5708 | SkPaint paint; |
| 5709 | SkPoint points[] = { { 0, 0 }, { 250, 0 }, { 100, 100 }, { 0, 250 } }; |
| 5710 | SkColor colors[] = { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorCYAN }; |
| 5711 | auto vertices = SkVertices::MakeCopy(SkVertices::kTriangleFan_VertexMode, |
| 5712 | SK_ARRAY_COUNT(points), points, nullptr, colors); |
| 5713 | canvas->drawVertices(vertices.get(), SkBlendMode::kSrc, paint); |
| 5714 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5715 | ## |
| 5716 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5717 | #SeeAlso drawPatch drawPicture |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5718 | |
| 5719 | ## |
| 5720 | |
| 5721 | # ------------------------------------------------------------------------------ |
| 5722 | |
| 5723 | #Method void drawVertices(const sk_sp<SkVertices>& vertices, SkBlendMode mode, const SkPaint& paint) |
| 5724 | |
| 5725 | Draw Vertices vertices, a triangle mesh, using Clip and Matrix. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5726 | If Vertices_Texs and Vertices_Colors are defined in vertices, and Paint paint |
| 5727 | contains Shader, Blend_Mode mode combines Vertices_Colors with Shader. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5728 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5729 | #Param vertices triangle mesh to draw ## |
| 5730 | #Param mode combines Vertices_Colors with Shader, if both are present ## |
| 5731 | #Param paint specifies the Shader, used as Vertices texture, may be nullptr ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5732 | |
| 5733 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5734 | void draw(SkCanvas* canvas) { |
| 5735 | SkPaint paint; |
| 5736 | SkPoint points[] = { { 0, 0 }, { 250, 0 }, { 100, 100 }, { 0, 250 } }; |
| 5737 | SkPoint texs[] = { { 0, 0 }, { 0, 250 }, { 250, 250 }, { 250, 0 } }; |
| 5738 | SkColor colors[] = { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorCYAN }; |
| 5739 | paint.setShader(SkGradientShader::MakeLinear(points, colors, nullptr, 4, |
| 5740 | SkShader::kClamp_TileMode)); |
| 5741 | auto vertices = SkVertices::MakeCopy(SkVertices::kTriangleFan_VertexMode, |
| 5742 | SK_ARRAY_COUNT(points), points, texs, colors); |
| 5743 | canvas->drawVertices(vertices.get(), SkBlendMode::kDarken, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5744 | } |
| 5745 | ## |
| 5746 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5747 | #SeeAlso drawPatch drawPicture |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5748 | |
| 5749 | ## |
| 5750 | |
| 5751 | # ------------------------------------------------------------------------------ |
| 5752 | |
| 5753 | #Method void drawPatch(const SkPoint cubics[12], const SkColor colors[4], |
| 5754 | const SkPoint texCoords[4], SkBlendMode mode, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5755 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5756 | #Line # draws Coons_Patch ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5757 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5758 | Draws a Coons_Patch: the interpolation of four cubics with shared corners, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5759 | associating a color, and optionally a texture coordinate, with each corner. |
| 5760 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 5761 | Coons_Patch uses Clip and Matrix, paint Shader, Color_Filter, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5762 | 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] | 5763 | 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] | 5764 | both are provided. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5765 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5766 | Point array cubics specifies four Cubics starting at the top-left corner, |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5767 | 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] | 5768 | first point. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5769 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5770 | Color array color associates colors with corners in top-left, top-right, |
| 5771 | bottom-right, bottom-left order. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5772 | |
| 5773 | If paint contains Shader, Point array texCoords maps Shader as texture to |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5774 | corners in top-left, top-right, bottom-right, bottom-left order. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5775 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 5776 | #Param cubics Path_Cubic array, sharing common points ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5777 | #Param colors Color array, one for each corner ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5778 | #Param texCoords Point array of texture coordinates, mapping Shader to corners; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5779 | may be nullptr |
Cary Clark | 579985c | 2017-07-31 11:48:27 -0400 | [diff] [blame] | 5780 | #Param ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5781 | #Param mode Blend_Mode for colors, and for Shader if paint has one ## |
| 5782 | #Param paint Shader, Color_Filter, Blend_Mode, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5783 | |
| 5784 | #Example |
| 5785 | #Image 5 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5786 | void draw(SkCanvas* canvas) { |
| 5787 | // SkBitmap source = cmbkygk; |
| 5788 | SkPaint paint; |
| 5789 | paint.setFilterQuality(kLow_SkFilterQuality); |
| 5790 | paint.setAntiAlias(true); |
| 5791 | SkPoint cubics[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, |
| 5792 | /* { 7, 3 }, */ { 6, 4 }, { 7, 5 }, { 5, 7 }, |
| 5793 | /* { 5, 7 }, */ { 4, 6 }, { 3, 7 }, { 1, 5 }, |
| 5794 | /* { 1, 5 }, */ { 2, 4 }, { 1, 3 }, /* { 3, 1 } */ }; |
| 5795 | SkColor colors[] = { 0xbfff0000, 0xbf0000ff, 0xbfff00ff, 0xbf00ffff }; |
| 5796 | SkPoint texCoords[] = { { -30, -30 }, { 162, -30}, { 162, 162}, { -30, 162} }; |
| 5797 | paint.setShader(SkShader::MakeBitmapShader(source, SkShader::kClamp_TileMode, |
| 5798 | SkShader::kClamp_TileMode, nullptr)); |
| 5799 | canvas->scale(15, 15); |
| 5800 | for (auto blend : { SkBlendMode::kSrcOver, SkBlendMode::kModulate, SkBlendMode::kXor } ) { |
| 5801 | canvas->drawPatch(cubics, colors, texCoords, blend, paint); |
| 5802 | canvas->translate(4, 4); |
| 5803 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5804 | } |
| 5805 | ## |
| 5806 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5807 | #ToDo can patch use image filter? ## |
| 5808 | #SeeAlso SeeAlso drawVertices drawPicture |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5809 | |
| 5810 | ## |
| 5811 | |
| 5812 | # ------------------------------------------------------------------------------ |
| 5813 | |
| 5814 | #Method void drawPatch(const SkPoint cubics[12], const SkColor colors[4], |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5815 | const SkPoint texCoords[4], const SkPaint& paint) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5816 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5817 | Draws Cubic Coons_Patch: the interpolation of four cubics with shared corners, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5818 | associating a color, and optionally a texture coordinate, with each corner. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5819 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 5820 | Coons_Patch uses Clip and Matrix, paint Shader, Color_Filter, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5821 | 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] | 5822 | 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] | 5823 | both are provided. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5824 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5825 | Point array cubics specifies four Cubics starting at the top-left corner, |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5826 | 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] | 5827 | first point. |
| 5828 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5829 | Color array color associates colors with corners in top-left, top-right, |
| 5830 | bottom-right, bottom-left order. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5831 | |
| 5832 | If paint contains Shader, Point array texCoords maps Shader as texture to |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5833 | corners in top-left, top-right, bottom-right, bottom-left order. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5834 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 5835 | #Param cubics Path_Cubic array, sharing common points ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5836 | #Param colors Color array, one for each corner ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5837 | #Param texCoords Point array of texture coordinates, mapping Shader to corners; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5838 | may be nullptr |
Cary Clark | 579985c | 2017-07-31 11:48:27 -0400 | [diff] [blame] | 5839 | #Param ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5840 | #Param paint Shader, Color_Filter, Blend_Mode, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5841 | |
| 5842 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5843 | void draw(SkCanvas* canvas) { |
| 5844 | SkPaint paint; |
| 5845 | paint.setAntiAlias(true); |
| 5846 | SkPoint cubics[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, |
| 5847 | /* { 7, 3 }, */ { 6, 4 }, { 7, 5 }, { 5, 7 }, |
| 5848 | /* { 5, 7 }, */ { 4, 6 }, { 3, 7 }, { 1, 5 }, |
| 5849 | /* { 1, 5 }, */ { 2, 4 }, { 1, 3 }, /* { 3, 1 } */ }; |
| 5850 | SkColor colors[] = { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorCYAN }; |
| 5851 | canvas->scale(30, 30); |
| 5852 | canvas->drawPatch(cubics, colors, nullptr, paint); |
| 5853 | SkPoint text[] = { {3,0.9f}, {4,2.5f}, {5,0.9f}, {7.5f,3.2f}, {5.5f,4.2f}, |
| 5854 | {7.5f,5.2f}, {5,7.5f}, {4,5.9f}, {3,7.5f}, {0.5f,5.2f}, {2.5f,4.2f}, |
| 5855 | {0.5f,3.2f} }; |
| 5856 | paint.setTextSize(18.f / 30); |
| 5857 | paint.setTextAlign(SkPaint::kCenter_Align); |
| 5858 | for (int i = 0; i< 10; ++i) { |
| 5859 | char digit = '0' + i; |
| 5860 | canvas->drawText(&digit, 1, text[i].fX, text[i].fY, paint); |
| 5861 | } |
| 5862 | canvas->drawString("10", text[10].fX, text[10].fY, paint); |
| 5863 | canvas->drawString("11", text[11].fX, text[11].fY, paint); |
| 5864 | paint.setStyle(SkPaint::kStroke_Style); |
| 5865 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, 12, cubics, paint); |
| 5866 | 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] | 5867 | } |
| 5868 | ## |
| 5869 | |
| 5870 | #Example |
| 5871 | #Image 6 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5872 | void draw(SkCanvas* canvas) { |
| 5873 | // SkBitmap source = checkerboard; |
| 5874 | SkPaint paint; |
| 5875 | paint.setFilterQuality(kLow_SkFilterQuality); |
| 5876 | paint.setAntiAlias(true); |
| 5877 | SkPoint cubics[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, |
| 5878 | /* { 7, 3 }, */ { 6, 4 }, { 7, 5 }, { 5, 7 }, |
| 5879 | /* { 5, 7 }, */ { 4, 6 }, { 3, 7 }, { 1, 5 }, |
| 5880 | /* { 1, 5 }, */ { 2, 4 }, { 1, 3 }, /* { 3, 1 } */ }; |
| 5881 | SkPoint texCoords[] = { { 0, 0 }, { 0, 62}, { 62, 62}, { 62, 0 } }; |
| 5882 | paint.setShader(SkShader::MakeBitmapShader(source, SkShader::kClamp_TileMode, |
| 5883 | SkShader::kClamp_TileMode, nullptr)); |
| 5884 | canvas->scale(30, 30); |
| 5885 | canvas->drawPatch(cubics, nullptr, texCoords, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5886 | } |
| 5887 | ## |
| 5888 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5889 | #ToDo can patch use image filter? ## |
| 5890 | #SeeAlso SeeAlso drawVertices drawPicture |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5891 | |
| 5892 | ## |
| 5893 | |
| 5894 | # ------------------------------------------------------------------------------ |
| 5895 | |
| 5896 | #Method void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], |
| 5897 | const SkColor colors[], int count, SkBlendMode mode, const SkRect* cullRect, |
| 5898 | const SkPaint* paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5899 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5900 | #Line # draws sprites using Clip, Matrix, and Paint ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5901 | |
| 5902 | Draw 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] | 5903 | 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] | 5904 | to draw, if present. For each entry in the array, Rect tex locates sprite in |
| 5905 | atlas, and RSXform xform transforms it into destination space. |
| 5906 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5907 | xform, text, and colors if present, must contain count entries. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5908 | Optional colors are applied for each sprite using Blend_Mode. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5909 | Optional cullRect is a conservative bounds of all transformed sprites. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5910 | If cullRect is outside of Clip, canvas can skip drawing. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5911 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5912 | #Param atlas Image containing sprites ## |
| 5913 | #Param xform RSXform mappings for sprites in atlas ## |
| 5914 | #Param tex Rect locations of sprites in atlas ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 5915 | #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] | 5916 | #Param count number of sprites to draw ## |
| 5917 | #Param mode Blend_Mode combining colors and sprites ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 5918 | #Param cullRect bounds of transformed sprites for efficient clipping; may be nullptr ## |
| 5919 | #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] | 5920 | |
| 5921 | #Example |
| 5922 | #Image 3 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5923 | void draw(SkCanvas* canvas) { |
| 5924 | // SkBitmap source = mandrill; |
| 5925 | SkRSXform xforms[] = { { .5f, 0, 0, 0 }, {0, .5f, 200, 100 } }; |
| 5926 | SkRect tex[] = { { 0, 0, 250, 250 }, { 0, 0, 250, 250 } }; |
| 5927 | SkColor colors[] = { 0x7f55aa00, 0x7f3333bf }; |
| 5928 | const SkImage* imagePtr = image.get(); |
| 5929 | canvas->drawAtlas(imagePtr, xforms, tex, colors, 2, SkBlendMode::kSrcOver, nullptr, nullptr); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5930 | } |
| 5931 | ## |
| 5932 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5933 | #SeeAlso drawBitmap drawImage |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5934 | |
| 5935 | ## |
| 5936 | |
| 5937 | # ------------------------------------------------------------------------------ |
| 5938 | |
| 5939 | #Method void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[], |
| 5940 | const SkColor colors[], int count, SkBlendMode mode, const SkRect* cullRect, |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5941 | const SkPaint* paint) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5942 | |
| 5943 | Draw 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] | 5944 | 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] | 5945 | to draw, if present. For each entry in the array, Rect tex locates sprite in |
| 5946 | atlas, and RSXform xform transforms it into destination space. |
| 5947 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5948 | xform, text, and colors if present, must contain count entries. |
| 5949 | Optional colors is applied for each sprite using Blend_Mode. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5950 | Optional cullRect is a conservative bounds of all transformed sprites. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5951 | If cullRect is outside of Clip, canvas can skip drawing. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5952 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5953 | #Param atlas Image containing sprites ## |
| 5954 | #Param xform RSXform mappings for sprites in atlas ## |
| 5955 | #Param tex Rect locations of sprites in atlas ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 5956 | #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] | 5957 | #Param count number of sprites to draw ## |
| 5958 | #Param mode Blend_Mode combining colors and sprites ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 5959 | #Param cullRect bounds of transformed sprites for efficient clipping; may be nullptr ## |
| 5960 | #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] | 5961 | |
| 5962 | #Example |
| 5963 | #Image 3 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5964 | void draw(SkCanvas* canvas) { |
| 5965 | // SkBitmap source = mandrill; |
| 5966 | SkRSXform xforms[] = { { .5f, 0, 0, 0 }, {0, .5f, 200, 100 } }; |
| 5967 | SkRect tex[] = { { 0, 0, 250, 250 }, { 0, 0, 250, 250 } }; |
| 5968 | SkColor colors[] = { 0x7f55aa00, 0x7f3333bf }; |
| 5969 | SkPaint paint; |
| 5970 | paint.setAlpha(127); |
| 5971 | canvas->drawAtlas(image, xforms, tex, colors, 2, SkBlendMode::kPlus, nullptr, &paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5972 | } |
| 5973 | ## |
| 5974 | |
| 5975 | #ToDo bug in example on cpu side, gpu looks ok ## |
| 5976 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5977 | #SeeAlso drawBitmap drawImage |
| 5978 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5979 | ## |
| 5980 | |
| 5981 | # ------------------------------------------------------------------------------ |
| 5982 | |
| 5983 | #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] | 5984 | const SkRect* cullRect, const SkPaint* paint) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5985 | |
| 5986 | Draw 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] | 5987 | 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] | 5988 | to draw, if present. For each entry in the array, Rect tex locates sprite in |
| 5989 | atlas, and RSXform xform transforms it into destination space. |
| 5990 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5991 | xform and text must contain count entries. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5992 | Optional cullRect is a conservative bounds of all transformed sprites. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5993 | If cullRect is outside of Clip, canvas can skip drawing. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5994 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5995 | #Param atlas Image containing sprites ## |
| 5996 | #Param xform RSXform mappings for sprites in atlas ## |
| 5997 | #Param tex Rect locations of sprites in atlas ## |
| 5998 | #Param count number of sprites to draw ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 5999 | #Param cullRect bounds of transformed sprites for efficient clipping; may be nullptr ## |
| 6000 | #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] | 6001 | |
| 6002 | #Example |
| 6003 | #Image 3 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6004 | void draw(SkCanvas* canvas) { |
| 6005 | // sk_sp<SkImage> image = mandrill; |
| 6006 | SkRSXform xforms[] = { { .5f, 0, 0, 0 }, {0, .5f, 200, 100 } }; |
| 6007 | SkRect tex[] = { { 0, 0, 250, 250 }, { 0, 0, 250, 250 } }; |
| 6008 | const SkImage* imagePtr = image.get(); |
| 6009 | canvas->drawAtlas(imagePtr, xforms, tex, 2, nullptr, nullptr); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6010 | } |
| 6011 | ## |
| 6012 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 6013 | #SeeAlso drawBitmap drawImage |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6014 | |
| 6015 | ## |
| 6016 | |
| 6017 | # ------------------------------------------------------------------------------ |
| 6018 | |
| 6019 | #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] | 6020 | int count, const SkRect* cullRect, const SkPaint* paint) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6021 | |
| 6022 | Draw 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] | 6023 | 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] | 6024 | to draw, if present. For each entry in the array, Rect tex locates sprite in |
| 6025 | atlas, and RSXform xform transforms it into destination space. |
| 6026 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6027 | xform and text must contain count entries. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 6028 | Optional cullRect is a conservative bounds of all transformed sprites. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 6029 | If cullRect is outside of Clip, canvas can skip drawing. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6030 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6031 | #Param atlas Image containing sprites ## |
| 6032 | #Param xform RSXform mappings for sprites in atlas ## |
| 6033 | #Param tex Rect locations of sprites in atlas ## |
| 6034 | #Param count number of sprites to draw ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 6035 | #Param cullRect bounds of transformed sprites for efficient clipping; may be nullptr ## |
| 6036 | #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] | 6037 | |
| 6038 | #Example |
| 6039 | #Image 3 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6040 | void draw(SkCanvas* canvas) { |
| 6041 | // sk_sp<SkImage> image = mandrill; |
| 6042 | SkRSXform xforms[] = { { 1, 0, 0, 0 }, {0, 1, 300, 100 } }; |
| 6043 | SkRect tex[] = { { 0, 0, 200, 200 }, { 200, 0, 400, 200 } }; |
| 6044 | canvas->drawAtlas(image, xforms, tex, 2, nullptr, nullptr); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6045 | } |
| 6046 | ## |
| 6047 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 6048 | #SeeAlso drawBitmap drawImage |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6049 | |
| 6050 | ## |
| 6051 | |
| 6052 | # ------------------------------------------------------------------------------ |
| 6053 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 6054 | #Method void drawDrawable(SkDrawable* drawable, const SkMatrix* matrix = nullptr) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 6055 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 6056 | #Line # draws Drawable, encapsulated drawing commands ## |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 6057 | Draw Drawable drawable using Clip and Matrix, concatenated with |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6058 | optional matrix. |
| 6059 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 6060 | If Canvas has an asynchronous implementation, as is the case |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6061 | when it is recording into Picture, then drawable will be referenced, |
| 6062 | so that SkDrawable::draw() can be called when the operation is finalized. To force |
| 6063 | immediate drawing, call SkDrawable::draw() instead. |
| 6064 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6065 | #Param drawable custom struct encapsulating drawing commands ## |
| 6066 | #Param matrix transformation applied to drawing; may be nullptr ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6067 | |
| 6068 | #Example |
| 6069 | #Height 100 |
| 6070 | #Function |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6071 | struct MyDrawable : public SkDrawable { |
| 6072 | SkRect onGetBounds() override { return SkRect::MakeWH(50, 100); } |
| 6073 | |
| 6074 | void onDraw(SkCanvas* canvas) override { |
| 6075 | SkPath path; |
| 6076 | path.conicTo(10, 90, 50, 90, 0.9f); |
| 6077 | SkPaint paint; |
| 6078 | paint.setColor(SK_ColorBLUE); |
| 6079 | canvas->drawRect(path.getBounds(), paint); |
| 6080 | paint.setAntiAlias(true); |
| 6081 | paint.setColor(SK_ColorWHITE); |
| 6082 | canvas->drawPath(path, paint); |
| 6083 | } |
| 6084 | }; |
| 6085 | |
| 6086 | #Function ## |
| 6087 | void draw(SkCanvas* canvas) { |
| 6088 | sk_sp<SkDrawable> drawable(new MyDrawable); |
| 6089 | SkMatrix matrix; |
| 6090 | matrix.setTranslate(10, 10); |
| 6091 | canvas->drawDrawable(drawable.get(), &matrix); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6092 | } |
| 6093 | ## |
| 6094 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 6095 | #SeeAlso SkDrawable drawPicture |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6096 | |
| 6097 | ## |
| 6098 | |
| 6099 | # ------------------------------------------------------------------------------ |
| 6100 | |
| 6101 | #Method void drawDrawable(SkDrawable* drawable, SkScalar x, SkScalar y) |
| 6102 | |
| 6103 | Draw Drawable drawable using Clip and Matrix, offset by (x, y). |
| 6104 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 6105 | If Canvas has an asynchronous implementation, as is the case |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6106 | when it is recording into Picture, then drawable will be referenced, |
| 6107 | so that SkDrawable::draw() can be called when the operation is finalized. To force |
| 6108 | immediate drawing, call SkDrawable::draw() instead. |
| 6109 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6110 | #Param drawable custom struct encapsulating drawing commands ## |
| 6111 | #Param x offset into Canvas writable pixels in x ## |
| 6112 | #Param y offset into Canvas writable pixels in y ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6113 | |
| 6114 | #Example |
| 6115 | #Height 100 |
| 6116 | #Function |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6117 | struct MyDrawable : public SkDrawable { |
| 6118 | SkRect onGetBounds() override { return SkRect::MakeWH(50, 100); } |
| 6119 | |
| 6120 | void onDraw(SkCanvas* canvas) override { |
| 6121 | SkPath path; |
| 6122 | path.conicTo(10, 90, 50, 90, 0.9f); |
| 6123 | SkPaint paint; |
| 6124 | paint.setColor(SK_ColorBLUE); |
| 6125 | canvas->drawRect(path.getBounds(), paint); |
| 6126 | paint.setAntiAlias(true); |
| 6127 | paint.setColor(SK_ColorWHITE); |
| 6128 | canvas->drawPath(path, paint); |
| 6129 | } |
| 6130 | }; |
| 6131 | |
| 6132 | #Function ## |
| 6133 | void draw(SkCanvas* canvas) { |
| 6134 | sk_sp<SkDrawable> drawable(new MyDrawable); |
| 6135 | canvas->drawDrawable(drawable.get(), 10, 10); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6136 | } |
| 6137 | ## |
| 6138 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 6139 | #SeeAlso SkDrawable drawPicture |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6140 | |
| 6141 | ## |
| 6142 | |
| 6143 | # ------------------------------------------------------------------------------ |
| 6144 | |
| 6145 | #Method void drawAnnotation(const SkRect& rect, const char key[], SkData* value) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 6146 | #In Draw |
| 6147 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 6148 | #Line # associates a Rect with a key-value pair ## |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 6149 | Associate 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] | 6150 | a null-terminated utf8 string, and optional value is stored as Data. |
| 6151 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 6152 | Only some canvas implementations, such as recording to Picture, or drawing to |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6153 | Document_PDF, use annotations. |
| 6154 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6155 | #Param rect Rect extent of canvas to annotate ## |
| 6156 | #Param key string used for lookup ## |
| 6157 | #Param value data holding value stored in annotation ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6158 | |
| 6159 | #Example |
| 6160 | #Height 1 |
| 6161 | const char text[] = "Click this link!"; |
| 6162 | SkRect bounds; |
| 6163 | SkPaint paint; |
| 6164 | paint.setTextSize(40); |
| 6165 | (void)paint.measureText(text, strlen(text), &bounds); |
| 6166 | const char url[] = "https://www.google.com/"; |
| 6167 | sk_sp<SkData> urlData(SkData::MakeWithCString(url)); |
| 6168 | canvas->drawAnnotation(bounds, "url_key", urlData.get()); |
| 6169 | ## |
| 6170 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 6171 | #SeeAlso SkPicture SkDocument |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6172 | |
| 6173 | ## |
| 6174 | |
| 6175 | # ------------------------------------------------------------------------------ |
| 6176 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 6177 | #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] | 6178 | |
| 6179 | Associate Rect on Canvas when an annotation; a key-value pair, where the key is |
| 6180 | a null-terminated utf8 string, and optional value is stored as Data. |
| 6181 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 6182 | Only some canvas implementations, such as recording to Picture, or drawing to |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6183 | Document_PDF, use annotations. |
| 6184 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6185 | #Param rect Rect extent of canvas to annotate ## |
| 6186 | #Param key string used for lookup ## |
| 6187 | #Param value data holding value stored in annotation ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6188 | |
| 6189 | #Example |
| 6190 | #Height 1 |
| 6191 | const char text[] = "Click this link!"; |
| 6192 | SkRect bounds; |
| 6193 | SkPaint paint; |
| 6194 | paint.setTextSize(40); |
| 6195 | (void)paint.measureText(text, strlen(text), &bounds); |
| 6196 | const char url[] = "https://www.google.com/"; |
| 6197 | sk_sp<SkData> urlData(SkData::MakeWithCString(url)); |
| 6198 | canvas->drawAnnotation(bounds, "url_key", urlData.get()); |
| 6199 | ## |
| 6200 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 6201 | #SeeAlso SkPicture SkDocument |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6202 | |
| 6203 | ## |
| 6204 | |
| 6205 | #Method SkDrawFilter* getDrawFilter() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 6206 | #Deprecated soon |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6207 | ## |
| 6208 | |
| 6209 | #Method virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 6210 | #Deprecated soon |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6211 | ## |
| 6212 | |
| 6213 | # ------------------------------------------------------------------------------ |
| 6214 | |
| 6215 | #Method virtual bool isClipEmpty() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 6216 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 6217 | #Line # returns if Clip is empty ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6218 | Returns true if Clip is empty; that is, nothing will draw. |
| 6219 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6220 | May do work when called; it should not be called |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6221 | more often than needed. However, once called, subsequent calls perform no |
| 6222 | work until Clip changes. |
| 6223 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6224 | #Return true if Clip is empty ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6225 | |
| 6226 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6227 | void draw(SkCanvas* canvas) { |
| 6228 | SkDebugf("clip is%s empty\n", canvas->isClipEmpty() ? "" : " not"); |
| 6229 | SkPath path; |
| 6230 | canvas->clipPath(path); |
| 6231 | SkDebugf("clip is%s empty\n", canvas->isClipEmpty() ? "" : " not"); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6232 | } |
| 6233 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6234 | clip is not empty |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6235 | clip is empty |
| 6236 | ## |
| 6237 | ## |
| 6238 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 6239 | #SeeAlso isClipRect getLocalClipBounds getDeviceClipBounds |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6240 | |
| 6241 | ## |
| 6242 | |
| 6243 | # ------------------------------------------------------------------------------ |
| 6244 | |
| 6245 | #Method virtual bool isClipRect() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 6246 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 6247 | #Line # returns if Clip is Rect and not empty ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6248 | Returns true if Clip is Rect and not empty. |
| 6249 | Returns false if the clip is empty, or if it is not Rect. |
| 6250 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6251 | #Return true if Clip is Rect and not empty ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6252 | |
| 6253 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6254 | void draw(SkCanvas* canvas) { |
| 6255 | SkDebugf("clip is%s rect\n", canvas->isClipRect() ? "" : " not"); |
| 6256 | canvas->clipRect({0, 0, 0, 0}); |
| 6257 | SkDebugf("clip is%s rect\n", canvas->isClipRect() ? "" : " not"); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6258 | } |
| 6259 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6260 | clip is rect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6261 | clip is not rect |
| 6262 | ## |
| 6263 | ## |
| 6264 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 6265 | #SeeAlso isClipEmpty getLocalClipBounds getDeviceClipBounds |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6266 | |
| 6267 | ## |
| 6268 | |
| 6269 | #Class SkCanvas ## |
Cary Clark | 884dd7d | 2017-10-11 10:37:52 -0400 | [diff] [blame] | 6270 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6271 | #Topic Canvas ## |