Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1 | #Topic Canvas |
Cary Clark | 12799e1 | 2017-07-28 15:18:29 -0400 | [diff] [blame] | 2 | #Alias Canvas_Reference |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 4 | #Subtopic Overview |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 5 | #Subtopic Subtopic |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 6 | #Populate |
| 7 | ## |
| 8 | ## |
| 9 | |
Cary Clark | e4aa371 | 2017-09-15 02:56:12 -0400 | [diff] [blame] | 10 | #Class SkCanvas |
| 11 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 12 | Canvas provides an interface for drawing, and how the drawing is clipped and transformed. |
| 13 | Canvas contains a stack of Matrix and Clip values. |
| 14 | |
| 15 | 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] | 16 | Each Canvas draw call transforms the geometry of the object by the concatenation of all |
| 17 | Matrix values in the stack. The transformed geometry is clipped by the intersection |
| 18 | of all of Clip values in the stack. The Canvas draw calls use Paint to supply drawing |
| 19 | 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] | 20 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 21 | To draw to a pixel-based destination, create Raster_Surface or GPU_Surface. |
| 22 | Request Canvas from Surface to obtain the interface to draw. |
| 23 | Canvas generated by Raster_Surface draws to memory visible to the CPU. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 24 | Canvas generated by GPU_Surface uses Vulkan or OpenGL to draw to the GPU. |
| 25 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 26 | 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] | 27 | Document based Canvas and other Canvas Subclasses reference Device describing the |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 28 | destination. |
| 29 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 30 | Canvas can be constructed to draw to Bitmap without first creating Raster_Surface. |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 31 | This approach may be deprecated in the future. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 32 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 33 | #Subtopic Related_Function |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 34 | #Populate |
| 35 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 36 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 37 | #Subtopic Constant |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 38 | #Populate |
| 39 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 40 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 41 | #Subtopic Class_or_Struct |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 42 | #Populate |
| 43 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 44 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 45 | #Subtopic Constructor |
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 | 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] | 48 | when no Surface is required, and some helpers implicitly create Raster_Surface. |
| 49 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 50 | #Populate |
| 51 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 52 | |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 53 | #Subtopic Member_Function |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 54 | #Populate |
| 55 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 56 | |
| 57 | # ------------------------------------------------------------------------------ |
| 58 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 59 | #Method static std::unique_ptr<SkCanvas> MakeRasterDirect(const SkImageInfo& info, void* pixels, |
| 60 | size_t rowBytes, |
| 61 | const SkSurfaceProps* props = nullptr) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 62 | #In Constructor |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 63 | #Line # creates from SkImageInfo and Pixel_Storage ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 64 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 65 | Allocates raster Canvas that will draw directly into pixels. |
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 | Canvas is returned if all parameters are valid. |
| 68 | Valid parameters include: |
| 69 | info dimensions are zero or positive; |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 70 | info contains Color_Type and Alpha_Type supported by Raster_Surface; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 71 | pixels is not nullptr; |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 72 | 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] | 73 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 74 | 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] | 75 | 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] | 76 | info width times bytes required for Color_Type. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 77 | |
| 78 | Pixel buffer size should be info height times computed rowBytes. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 79 | Pixels are not initialized. |
| 80 | To access pixels after drawing, call flush() or peekPixels. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 81 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 82 | #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] | 83 | width, or height, or both, may be zero |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 84 | ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 85 | #Param pixels pointer to destination pixels buffer |
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 rowBytes interval from one Surface row to the next, or zero |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 88 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 89 | #Param props LCD striping orientation and setting for device independent fonts; |
| 90 | may be nullptr |
| 91 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 92 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 93 | #Return Canvas if all parameters are valid; otherwise, nullptr ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 94 | |
| 95 | #Example |
| 96 | #Description |
| 97 | Allocates a three by three bitmap, clears it to white, and draws a black pixel |
| 98 | in the center. |
| 99 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 100 | void draw(SkCanvas* ) { |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 101 | SkImageInfo info = SkImageInfo::MakeN32Premul(3, 3); // device aligned, 32 bpp, Premultiplied |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 102 | const size_t minRowBytes = info.minRowBytes(); // bytes used by one bitmap row |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 103 | const size_t size = info.computeMinByteSize(); // bytes used by all rows |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 104 | SkAutoTMalloc<SkPMColor> storage(size); // allocate storage for pixels |
| 105 | SkPMColor* pixels = storage.get(); // get pointer to allocated storage |
| 106 | // create a SkCanvas backed by a raster device, and delete it when the |
| 107 | // function goes out of scope. |
| 108 | std::unique_ptr<SkCanvas> canvas = SkCanvas::MakeRasterDirect(info, pixels, minRowBytes); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 109 | canvas->clear(SK_ColorWHITE); // white is Unpremultiplied, in ARGB order |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 110 | canvas->flush(); // ensure that pixels are cleared |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 111 | SkPMColor pmWhite = pixels[0]; // the Premultiplied format may vary |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 112 | SkPaint paint; // by default, draws black |
| 113 | canvas->drawPoint(1, 1, paint); // draw in the center |
| 114 | canvas->flush(); // ensure that point was drawn |
| 115 | for (int y = 0; y < info.height(); ++y) { |
| 116 | for (int x = 0; x < info.width(); ++x) { |
| 117 | SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x'); |
| 118 | } |
| 119 | SkDebugf("\n"); |
| 120 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 121 | } |
| 122 | #StdOut |
| 123 | --- |
| 124 | -x- |
| 125 | --- |
| 126 | ## |
| 127 | ## |
| 128 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 129 | #SeeAlso MakeRasterDirectN32 SkSurface::MakeRasterDirect |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 130 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 131 | ## |
| 132 | |
| 133 | # ------------------------------------------------------------------------------ |
| 134 | |
| 135 | #Method static std::unique_ptr<SkCanvas> MakeRasterDirectN32(int width, int height, SkPMColor* pixels, |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 136 | size_t rowBytes) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 137 | #In Constructor |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 138 | #Line # creates from image data and Pixel_Storage ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 139 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 140 | Allocates raster Canvas specified by inline image specification. Subsequent Canvas |
| 141 | calls draw into pixels. |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 142 | Color_Type is set to kN32_SkColorType. |
| 143 | Alpha_Type is set to kPremul_SkAlphaType. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 144 | To access pixels after drawing, call flush() or peekPixels. |
| 145 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 146 | Canvas is returned if all parameters are valid. |
| 147 | Valid parameters include: |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 148 | width and height are zero or positive; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 149 | pixels is not nullptr; |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 150 | 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] | 151 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 152 | 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] | 153 | 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] | 154 | width times bytes required for Color_Type. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 155 | |
| 156 | Pixel buffer size should be height times rowBytes. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 157 | |
| 158 | #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] | 159 | #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] | 160 | #Param pixels pointer to destination pixels buffer; buffer size should be height |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 161 | times rowBytes |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 162 | ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 163 | #Param rowBytes interval from one Surface row to the next, or zero |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 164 | ## |
| 165 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 166 | #Return Canvas if all parameters are valid; otherwise, nullptr ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 167 | |
| 168 | #Example |
| 169 | #Description |
| 170 | Allocates a three by three bitmap, clears it to white, and draws a black pixel |
| 171 | in the center. |
| 172 | ## |
| 173 | void draw(SkCanvas* ) { |
| 174 | const int width = 3; |
| 175 | const int height = 3; |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 176 | SkPMColor pixels[height][width]; // allocate a 3x3 Premultiplied bitmap on the stack |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 177 | // create a SkCanvas backed by a raster device, and delete it when the |
| 178 | // function goes out of scope. |
| 179 | std::unique_ptr<SkCanvas> canvas = SkCanvas::MakeRasterDirectN32( |
| 180 | width, |
| 181 | height, |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 182 | pixels[0], // top-left of the bitmap |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 183 | sizeof(pixels[0])); // byte width of the each row |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 184 | // write a premultiplied value for white into all pixels in the bitmap |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 185 | canvas->clear(SK_ColorWHITE); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 186 | SkPMColor pmWhite = pixels[0][0]; // the Premultiplied format may vary |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 187 | SkPaint paint; // by default, draws black |
| 188 | canvas->drawPoint(1, 1, paint); // draw in the center |
| 189 | canvas->flush(); // ensure that pixels is ready to be read |
| 190 | for (int y = 0; y < height; ++y) { |
| 191 | for (int x = 0; x < width; ++x) { |
| 192 | SkDebugf("%c", pixels[y][x] == pmWhite ? '-' : 'x'); |
| 193 | } |
| 194 | SkDebugf("\n"); |
| 195 | } |
| 196 | } |
| 197 | #StdOut |
| 198 | --- |
| 199 | -x- |
| 200 | --- |
| 201 | ## |
| 202 | ## |
| 203 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 204 | #SeeAlso MakeRasterDirect SkSurface::MakeRasterDirect SkImageInfo::MakeN32Premul |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 205 | |
| 206 | ## |
| 207 | |
| 208 | # ------------------------------------------------------------------------------ |
| 209 | |
| 210 | #Method SkCanvas() |
| 211 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 212 | #Line # creates with no Surface, no dimensions ## |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 213 | Creates an empty Canvas with no backing device or pixels, with |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 214 | a width and height of zero. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 215 | |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 216 | #Return empty Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 217 | |
| 218 | #Example |
| 219 | |
| 220 | #Description |
| 221 | Passes a placeholder to a function that requires one. |
| 222 | ## |
| 223 | |
| 224 | #Function |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 225 | // Returns true if either the canvas rotates the text by 90 degrees, or the paint does. |
| 226 | static void check_for_up_and_down_text(const SkCanvas* canvas, const SkPaint& paint) { |
| 227 | bool paintHasVertical = paint.isVerticalText(); |
| 228 | const SkMatrix& matrix = canvas->getTotalMatrix(); |
| 229 | bool matrixIsVertical = matrix.preservesRightAngles() && !matrix.isScaleTranslate(); |
| 230 | SkDebugf("paint draws text %s\n", paintHasVertical != matrixIsVertical ? |
| 231 | "top to bottom" : "left to right"); |
| 232 | } |
| 233 | |
| 234 | static void check_for_up_and_down_text(const SkPaint& paint) { |
| 235 | SkCanvas canvas; // placeholder only, does not have an associated device |
| 236 | check_for_up_and_down_text(&canvas, paint); |
| 237 | } |
| 238 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 239 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 240 | void draw(SkCanvas* canvas) { |
| 241 | SkPaint paint; |
| 242 | check_for_up_and_down_text(paint); // paint draws text left to right |
| 243 | paint.setVerticalText(true); |
| 244 | check_for_up_and_down_text(paint); // paint draws text top to bottom |
| 245 | paint.setVerticalText(false); |
| 246 | canvas->rotate(90); |
| 247 | check_for_up_and_down_text(canvas, paint); // paint draws text top to bottom |
| 248 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 249 | |
| 250 | #StdOut |
| 251 | paint draws text left to right |
| 252 | paint draws text top to bottom |
| 253 | paint draws text top to bottom |
| 254 | ## |
| 255 | ## |
| 256 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 257 | #SeeAlso MakeRasterDirect SkRasterHandleAllocator::MakeCanvas SkSurface::getCanvas SkCreateColorSpaceXformCanvas |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 258 | |
| 259 | ## |
| 260 | |
| 261 | # ------------------------------------------------------------------------------ |
| 262 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 263 | #Method SkCanvas(int width, int height, const SkSurfaceProps* props = nullptr) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 264 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 265 | #Line # no Surface, set dimensions, Surface_Properties ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 266 | Creates Canvas of the specified dimensions without a Surface. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 267 | Used by Subclasses with custom implementations for draw methods. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 268 | |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 269 | If props equals nullptr, Surface_Properties are created with |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 270 | Surface_Properties_Legacy_Font_Host settings, which choose the pixel striping |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 271 | direction and order. Since a platform may dynamically change its direction when |
| 272 | the device is rotated, and since a platform may have multiple monitors with |
| 273 | different characteristics, it is best not to rely on this legacy behavior. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 274 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 275 | #Param width zero or greater ## |
| 276 | #Param height zero or greater ## |
| 277 | #Param props LCD striping orientation and setting for device independent fonts; |
| 278 | may be nullptr |
| 279 | ## |
| 280 | |
| 281 | #Return Canvas placeholder with dimensions ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 282 | |
| 283 | #Example |
| 284 | SkCanvas canvas(10, 20); // 10 units wide, 20 units high |
| 285 | canvas.clipRect(SkRect::MakeXYWH(30, 40, 5, 10)); // clip is outside canvas' device |
| 286 | SkDebugf("canvas %s empty\n", canvas.getDeviceClipBounds().isEmpty() ? "is" : "is not"); |
| 287 | |
| 288 | #StdOut |
| 289 | canvas is empty |
| 290 | ## |
| 291 | ## |
| 292 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 293 | #SeeAlso MakeRasterDirect SkSurfaceProps SkPixelGeometry SkCreateColorSpaceXformCanvas |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 294 | |
| 295 | ## |
| 296 | |
| 297 | # ------------------------------------------------------------------------------ |
| 298 | |
| 299 | #Method explicit SkCanvas(SkBaseDevice* device) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 300 | #Deprecated soon |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 301 | ## |
| 302 | |
| 303 | # ------------------------------------------------------------------------------ |
| 304 | |
| 305 | #Method explicit SkCanvas(const SkBitmap& bitmap) |
| 306 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 307 | #Line # uses existing Bitmap ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 308 | Construct a canvas that draws into bitmap. |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 309 | Sets SkSurfaceProps::kLegacyFontHost_InitType in constructed Surface. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 310 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 311 | Bitmap is copied so that subsequently editing bitmap will not affect |
| 312 | constructed Canvas. |
| 313 | |
| 314 | May be deprecated in the future. |
| 315 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 316 | #ToDo Should be deprecated? ## |
| 317 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 318 | #Param bitmap width, height, Color_Type, Alpha_Type, and pixel |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 319 | storage of Raster_Surface |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 320 | ## |
| 321 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 322 | #Return Canvas that can be used to draw into bitmap ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 323 | |
| 324 | #Example |
| 325 | #Description |
| 326 | The actual output depends on the installed fonts. |
| 327 | ## |
| 328 | SkBitmap bitmap; |
| 329 | // create a bitmap 5 wide and 11 high |
| 330 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(5, 11)); |
| 331 | SkCanvas canvas(bitmap); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 332 | canvas.clear(SK_ColorWHITE); // white is Unpremultiplied, in ARGB order |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 333 | SkPixmap pixmap; // provides guaranteed access to the drawn pixels |
| 334 | if (!canvas.peekPixels(&pixmap)) { |
| 335 | SkDebugf("peekPixels should never fail.\n"); |
| 336 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 337 | const SkPMColor* pixels = pixmap.addr32(); // points to top-left of bitmap |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 338 | SkPMColor pmWhite = pixels[0]; // the Premultiplied format may vary |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 339 | SkPaint paint; // by default, draws black, 12 point text |
| 340 | canvas.drawString("!", 1, 10, paint); // 1 char at baseline (1, 10) |
| 341 | for (int y = 0; y < bitmap.height(); ++y) { |
| 342 | for (int x = 0; x < bitmap.width(); ++x) { |
| 343 | SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x'); |
| 344 | } |
| 345 | SkDebugf("\n"); |
| 346 | } |
| 347 | |
| 348 | #StdOut |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 349 | ----- |
| 350 | ---x- |
| 351 | ---x- |
| 352 | ---x- |
| 353 | ---x- |
| 354 | ---x- |
| 355 | ---x- |
| 356 | ----- |
| 357 | ---x- |
| 358 | ---x- |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 359 | ----- |
| 360 | #StdOut ## |
| 361 | ## |
| 362 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 363 | #SeeAlso MakeRasterDirect SkRasterHandleAllocator::MakeCanvas SkSurface::getCanvas SkCreateColorSpaceXformCanvas |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 364 | |
| 365 | ## |
| 366 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 367 | #EnumClass ColorBehavior |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 368 | #Line # Android framework only ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 369 | #Private |
| 370 | Android framework only. |
| 371 | ## |
| 372 | |
| 373 | #Code |
| 374 | enum class ColorBehavior { |
| 375 | kLegacy, |
| 376 | }; |
| 377 | ## |
| 378 | #Const kLegacy 0 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 379 | Is a placeholder to allow specialized constructor; has no meaning. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 380 | ## |
| 381 | ## |
| 382 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 383 | #Method SkCanvas(const SkBitmap& bitmap, ColorBehavior behavior) |
| 384 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 385 | #Line # Android framework only ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 386 | #Private |
| 387 | Android framework only. |
| 388 | ## |
| 389 | |
| 390 | #Param bitmap specifies a bitmap for the canvas to draw into ## |
| 391 | #Param behavior specializes this constructor; value is unused ## |
| 392 | #Return Canvas that can be used to draw into bitmap ## |
| 393 | |
| 394 | #NoExample |
| 395 | ## |
| 396 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 397 | |
| 398 | # ------------------------------------------------------------------------------ |
| 399 | |
| 400 | #Method SkCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props) |
| 401 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 402 | #Line # uses existing Bitmap and Surface_Properties ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 403 | Construct a canvas that draws into bitmap. |
| 404 | Use props to match the device characteristics, like LCD striping. |
| 405 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 406 | bitmap is copied so that subsequently editing bitmap will not affect |
| 407 | constructed Canvas. |
| 408 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 409 | #Param bitmap width, height, Color_Type, Alpha_Type, |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 410 | and pixel storage of Raster_Surface |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 411 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 412 | #Param props order and orientation of RGB striping; and whether to use |
| 413 | device independent fonts |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 414 | ## |
| 415 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 416 | #Return Canvas that can be used to draw into bitmap ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 417 | |
| 418 | #Example |
| 419 | #Description |
| 420 | The actual output depends on the installed fonts. |
| 421 | ## |
| 422 | SkBitmap bitmap; |
| 423 | // create a bitmap 5 wide and 11 high |
| 424 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(5, 11)); |
| 425 | SkCanvas canvas(bitmap, SkSurfaceProps(0, kUnknown_SkPixelGeometry)); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 426 | canvas.clear(SK_ColorWHITE); // white is Unpremultiplied, in ARGB order |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 427 | SkPixmap pixmap; // provides guaranteed access to the drawn pixels |
| 428 | if (!canvas.peekPixels(&pixmap)) { |
| 429 | SkDebugf("peekPixels should never fail.\n"); |
| 430 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 431 | const SkPMColor* pixels = pixmap.addr32(); // points to top-left of bitmap |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 432 | SkPMColor pmWhite = pixels[0]; // the Premultiplied format may vary |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 433 | SkPaint paint; // by default, draws black, 12 point text |
| 434 | canvas.drawString("!", 1, 10, paint); // 1 char at baseline (1, 10) |
| 435 | for (int y = 0; y < bitmap.height(); ++y) { |
| 436 | for (int x = 0; x < bitmap.width(); ++x) { |
| 437 | SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x'); |
| 438 | } |
| 439 | SkDebugf("\n"); |
| 440 | } |
| 441 | |
| 442 | #StdOut |
| 443 | ----- |
| 444 | ---x- |
| 445 | ---x- |
| 446 | ---x- |
| 447 | ---x- |
| 448 | ---x- |
| 449 | ---x- |
| 450 | ----- |
| 451 | ---x- |
| 452 | ---x- |
| 453 | ----- |
| 454 | #StdOut ## |
| 455 | ## |
| 456 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 457 | #SeeAlso MakeRasterDirect SkRasterHandleAllocator::MakeCanvas SkSurface::getCanvas SkCreateColorSpaceXformCanvas |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 458 | |
| 459 | ## |
| 460 | |
| 461 | # ------------------------------------------------------------------------------ |
| 462 | |
| 463 | #Method virtual ~SkCanvas() |
| 464 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 465 | #Line # draws saved Layers, frees resources ## |
Cary Clark | 5081eed | 2018-01-22 07:55:48 -0500 | [diff] [blame] | 466 | Draws saved Layers, if any. |
| 467 | Frees up resources used by Canvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 468 | |
| 469 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 470 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 471 | Canvas Layer draws into bitmap. saveLayerAlpha sets up an additional |
| 472 | drawing surface that blends with the bitmap. When Layer goes out of |
| 473 | scope, Layer Destructor is called. The saved Layer is restored, drawing |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 474 | transparent letters. |
| 475 | ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 476 | void draw(SkCanvas* canvas) { |
| 477 | SkBitmap bitmap; |
| 478 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(200, 200)); |
| 479 | { |
| 480 | SkCanvas offscreen(bitmap); |
| 481 | SkPaint paint; |
| 482 | paint.setTextSize(100); |
| 483 | offscreen.drawString("ABC", 20, 160, paint); |
| 484 | SkRect layerBounds = SkRect::MakeXYWH(32, 32, 192, 192); |
| 485 | offscreen.saveLayerAlpha(&layerBounds, 128); |
| 486 | offscreen.clear(SK_ColorWHITE); |
| 487 | offscreen.drawString("DEF", 20, 160, paint); |
| 488 | } |
| 489 | canvas->drawBitmap(bitmap, 0, 0, nullptr); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 490 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 491 | ## |
| 492 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 493 | #SeeAlso State_Stack |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 494 | |
| 495 | ## |
| 496 | |
| 497 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 498 | #Subtopic Property |
| 499 | #Populate |
| 500 | #Line # metrics and attributes ## |
| 501 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 502 | |
| 503 | #Method SkMetaData& getMetaData() |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 504 | #In Property |
| 505 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 506 | #Line # associates additional data with the canvas ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 507 | Returns storage to associate additional data with the canvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 508 | The storage is freed when Canvas is deleted. |
| 509 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 510 | #Return storage that can be read from and written to ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 511 | |
| 512 | #Example |
| 513 | const char* kHelloMetaData = "HelloMetaData"; |
| 514 | SkCanvas canvas; |
| 515 | SkMetaData& metaData = canvas.getMetaData(); |
| 516 | SkDebugf("before: %s\n", metaData.findString(kHelloMetaData)); |
| 517 | metaData.setString(kHelloMetaData, "Hello!"); |
| 518 | SkDebugf("during: %s\n", metaData.findString(kHelloMetaData)); |
| 519 | metaData.removeString(kHelloMetaData); |
| 520 | SkDebugf("after: %s\n", metaData.findString(kHelloMetaData)); |
| 521 | |
| 522 | #StdOut |
| 523 | before: (null) |
| 524 | during: Hello! |
| 525 | after: (null) |
| 526 | #StdOut ## |
| 527 | ## |
| 528 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 529 | #SeeAlso SkMetaData |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 530 | |
| 531 | ## |
| 532 | |
| 533 | # ------------------------------------------------------------------------------ |
| 534 | |
| 535 | #Method SkImageInfo imageInfo() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 536 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 537 | #Line # returns Image_Info for Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 538 | 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] | 539 | GPU_Surface, returned Color_Type is set to kUnknown_SkColorType. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 540 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 541 | #Return dimensions and Color_Type of Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 542 | |
| 543 | #Example |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 544 | SkCanvas emptyCanvas; |
| 545 | SkImageInfo canvasInfo = emptyCanvas.imageInfo(); |
| 546 | SkImageInfo emptyInfo; |
| 547 | SkDebugf("emptyInfo %c= canvasInfo\n", emptyInfo == canvasInfo ? '=' : '!'); |
| 548 | |
| 549 | #StdOut |
| 550 | emptyInfo == canvasInfo |
| 551 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 552 | ## |
| 553 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 554 | #SeeAlso SkImageInfo MakeRasterDirect makeSurface |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 555 | |
| 556 | ## |
| 557 | |
| 558 | # ------------------------------------------------------------------------------ |
| 559 | |
| 560 | #Method bool getProps(SkSurfaceProps* props) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 561 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 562 | #Line # copies Surface_Properties if available ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 563 | If Canvas is associated with Raster_Surface or |
| 564 | GPU_Surface, copies Surface_Properties and returns true. Otherwise, |
| 565 | return false and leave props unchanged. |
| 566 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 567 | #Param props storage for writable SkSurfaceProps ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 568 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 569 | #Return true if Surface_Properties was copied ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 570 | |
| 571 | #ToDo This seems old style. Deprecate? ## |
| 572 | |
| 573 | #Example |
| 574 | SkBitmap bitmap; |
| 575 | SkCanvas canvas(bitmap, SkSurfaceProps(0, kRGB_V_SkPixelGeometry)); |
| 576 | SkSurfaceProps surfaceProps(0, kUnknown_SkPixelGeometry); |
| 577 | SkDebugf("isRGB:%d\n", SkPixelGeometryIsRGB(surfaceProps.pixelGeometry())); |
| 578 | if (!canvas.getProps(&surfaceProps)) { |
| 579 | SkDebugf("getProps failed unexpectedly.\n"); |
| 580 | } |
| 581 | SkDebugf("isRGB:%d\n", SkPixelGeometryIsRGB(surfaceProps.pixelGeometry())); |
| 582 | |
| 583 | #StdOut |
| 584 | isRGB:0 |
| 585 | isRGB:1 |
| 586 | #StdOut ## |
| 587 | ## |
| 588 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 589 | #SeeAlso SkSurfaceProps makeSurface |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 590 | |
| 591 | ## |
| 592 | |
| 593 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 594 | #Subtopic Utility |
| 595 | #Populate |
| 596 | #Line # rarely called management functions ## |
| 597 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 598 | |
| 599 | #Method void flush() |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 600 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 601 | #Line # triggers execution of all pending draw operations ## |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 602 | Triggers the immediate execution of all pending draw operations. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 603 | If Canvas is associated with GPU_Surface, resolves all pending GPU operations. |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 604 | If Canvas is associated with Raster_Surface, has no effect; raster draw |
| 605 | operations are never deferred. |
| 606 | |
| 607 | #ToDo |
| 608 | In an overview section on managing the GPU, include: |
| 609 | - flush should never change what is drawn |
| 610 | - call to kick off gpu work |
| 611 | - calling too much impacts performance |
| 612 | - some calls (peekPixels, prepareForExternalIO) call it internally |
| 613 | - canvas call is local, GrContext::flush is global |
| 614 | - diffentiate between flush, flushAndSignalSemaphores |
| 615 | - normally never needs to be called |
| 616 | - call it when sharing gpu resources, feeling memory pressure, swapping out app, and before |
| 617 | abandoning context |
| 618 | - also call to say "I'm finished drawing here", e.g., when drawing to a GPU-backed offscreen surface |
| 619 | (created with SkSurface::MakeRenderTarget) |
| 620 | |
| 621 | for posterity: this doesn't show a difference: fiddle.skia.org/c/@flushfail |
| 622 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 623 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 624 | #ToDo haven't thought of a useful example to put here ## |
| 625 | #NoExample |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 626 | ## |
| 627 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 628 | #SeeAlso peekPixels SkSurface::flush() GrContext::flush() SkSurface::prepareForExternalIO GrContext::abandonContext() |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 629 | |
| 630 | ## |
| 631 | |
| 632 | # ------------------------------------------------------------------------------ |
| 633 | |
| 634 | #Method virtual SkISize getBaseLayerSize() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 635 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 636 | #Line # returns size of base Layer in global coordinates ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 637 | Gets the size of the base or root Layer in global canvas coordinates. The |
| 638 | 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] | 639 | smaller (due to clipping or saveLayer). |
| 640 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 641 | #Return integral width and height of base Layer ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 642 | |
| 643 | #Example |
| 644 | SkBitmap bitmap; |
| 645 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(20, 30)); |
| 646 | SkCanvas canvas(bitmap, SkSurfaceProps(0, kUnknown_SkPixelGeometry)); |
| 647 | canvas.clipRect(SkRect::MakeWH(10, 40)); |
| 648 | SkIRect clipDeviceBounds = canvas.getDeviceClipBounds(); |
| 649 | if (clipDeviceBounds.isEmpty()) { |
| 650 | SkDebugf("Empty clip bounds is unexpected!\n"); |
| 651 | } |
| 652 | SkDebugf("clip=%d,%d\n", clipDeviceBounds.width(), clipDeviceBounds.height()); |
| 653 | SkISize baseLayerSize = canvas.getBaseLayerSize(); |
| 654 | SkDebugf("size=%d,%d\n", baseLayerSize.width(), baseLayerSize.height()); |
| 655 | |
| 656 | #StdOut |
| 657 | clip=10,30 |
| 658 | size=20,30 |
| 659 | ## |
| 660 | ## |
| 661 | |
| 662 | #ToDo is this the same as the width and height of surface? ## |
| 663 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 664 | #SeeAlso getDeviceClipBounds |
| 665 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 666 | ## |
| 667 | |
| 668 | # ------------------------------------------------------------------------------ |
| 669 | |
| 670 | #Method sk_sp<SkSurface> makeSurface(const SkImageInfo& info, const SkSurfaceProps* props = nullptr) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 671 | #In Constructor |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 672 | #Line # creates Surface matching SkImageInfo and SkSurfaceProps ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 673 | Creates Surface matching info and props, and associates it with Canvas. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 674 | Returns nullptr if no match found. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 675 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 676 | If props is nullptr, matches Surface_Properties in Canvas. If props is nullptr and Canvas |
| 677 | does not have Surface_Properties, creates Surface with default Surface_Properties. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 678 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 679 | #Param info width, height, Color_Type, Alpha_Type, and Color_Space ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 680 | #Param props Surface_Properties to match; may be nullptr to match Canvas ## |
| 681 | |
| 682 | #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] | 683 | |
| 684 | #Example |
| 685 | sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(5, 6); |
| 686 | SkCanvas* smallCanvas = surface->getCanvas(); |
| 687 | SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(3, 4); |
| 688 | sk_sp<SkSurface> compatible = smallCanvas->makeSurface(imageInfo); |
| 689 | SkDebugf("compatible %c= nullptr\n", compatible == nullptr ? '=' : '!'); |
| 690 | SkDebugf("size = %d, %d\n", compatible->width(), compatible->height()); |
| 691 | |
| 692 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 693 | compatible != nullptr |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 694 | size = 3, 4 |
| 695 | ## |
| 696 | ## |
| 697 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 698 | #SeeAlso SkSurface SkSurface::makeSurface SkImageInfo SkSurfaceProps |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 699 | |
| 700 | ## |
| 701 | |
| 702 | # ------------------------------------------------------------------------------ |
| 703 | |
| 704 | #Method virtual GrContext* getGrContext() |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 705 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 706 | #Line # returns GPU_Context of the GPU_Surface ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 707 | Returns GPU_Context of the GPU_Surface associated with Canvas. |
| 708 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 709 | #Return GPU_Context, if available; nullptr otherwise ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 710 | |
| 711 | #Example |
| 712 | void draw(SkCanvas* canvas) { |
| 713 | if (canvas->getGrContext()) { |
| 714 | canvas->clear(SK_ColorRED); |
| 715 | } else { |
| 716 | canvas->clear(SK_ColorBLUE); |
| 717 | } |
| 718 | } |
| 719 | ## |
| 720 | |
| 721 | #ToDo fiddle should show both CPU and GPU out ## |
| 722 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 723 | #SeeAlso GrContext |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 724 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 725 | ## |
| 726 | |
| 727 | # ------------------------------------------------------------------------------ |
| 728 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 729 | #Method void* accessTopLayerPixels(SkImageInfo* info, size_t* rowBytes, SkIPoint* origin = nullptr) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 730 | #In Utility |
| 731 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 732 | #Line # returns writable pixel access if available ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 733 | 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] | 734 | can be read directly. The returned address is only valid |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 735 | while Canvas is in scope and unchanged. Any Canvas call or Surface call |
| 736 | may invalidate the returned address and other returned values. |
| 737 | |
| 738 | If pixels are inaccessible, info, rowBytes, and origin are unchanged. |
| 739 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 740 | #Param info storage for writable pixels' Image_Info; may be nullptr ## |
| 741 | #Param rowBytes storage for writable pixels' row bytes; may be nullptr ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 742 | #Param origin storage for Canvas top Layer origin, its top-left corner; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 743 | may be nullptr |
| 744 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 745 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 746 | #Return address of pixels, or nullptr if inaccessible ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 747 | |
| 748 | #Example |
| 749 | void draw(SkCanvas* canvas) { |
| 750 | if (canvas->accessTopLayerPixels(nullptr, nullptr)) { |
| 751 | canvas->clear(SK_ColorRED); |
| 752 | } else { |
| 753 | canvas->clear(SK_ColorBLUE); |
| 754 | } |
| 755 | } |
| 756 | ## |
| 757 | |
| 758 | #Example |
| 759 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 760 | Draws "ABC" on the device. Then draws "DEF" in Layer, and reads |
| 761 | Layer to add a large dotted "DEF". Finally blends Layer with the |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 762 | device. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 763 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 764 | 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] | 765 | "DEF" appear only on the CPU. |
| 766 | ## |
| 767 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 768 | SkPaint paint; |
| 769 | paint.setTextSize(100); |
| 770 | canvas->drawString("ABC", 20, 160, paint); |
| 771 | SkRect layerBounds = SkRect::MakeXYWH(32, 32, 192, 192); |
| 772 | canvas->saveLayerAlpha(&layerBounds, 128); |
| 773 | canvas->clear(SK_ColorWHITE); |
| 774 | canvas->drawString("DEF", 20, 160, paint); |
| 775 | SkImageInfo imageInfo; |
| 776 | size_t rowBytes; |
| 777 | SkIPoint origin; |
| 778 | uint32_t* access = (uint32_t*) canvas->accessTopLayerPixels(&imageInfo, &rowBytes, &origin); |
| 779 | if (access) { |
| 780 | int h = imageInfo.height(); |
| 781 | int v = imageInfo.width(); |
| 782 | int rowWords = rowBytes / sizeof(uint32_t); |
| 783 | for (int y = 0; y < h; ++y) { |
| 784 | int newY = (y - h / 2) * 2 + h / 2; |
| 785 | if (newY < 0 || newY >= h) { |
| 786 | continue; |
| 787 | } |
| 788 | for (int x = 0; x < v; ++x) { |
| 789 | int newX = (x - v / 2) * 2 + v / 2; |
| 790 | if (newX < 0 || newX >= v) { |
| 791 | continue; |
| 792 | } |
| 793 | if (access[y * rowWords + x] == SK_ColorBLACK) { |
| 794 | access[newY * rowWords + newX] = SK_ColorGRAY; |
| 795 | } |
| 796 | } |
| 797 | } |
| 798 | |
| 799 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 800 | canvas->restore(); |
| 801 | } |
| 802 | ## |
| 803 | |
| 804 | #ToDo there are no callers of this that I can find. Deprecate? ## |
| 805 | #ToDo fiddle should show both CPU and GPU out ## |
| 806 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 807 | #SeeAlso SkImageInfo SkPixmap |
| 808 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 809 | ## |
| 810 | |
| 811 | # ------------------------------------------------------------------------------ |
| 812 | |
| 813 | #Method SkRasterHandleAllocator::Handle accessTopRasterHandle() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 814 | #In Utility |
| 815 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 816 | #Line # returns context that tracks Clip and Matrix ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 817 | Returns custom context that tracks the Matrix and Clip. |
| 818 | |
| 819 | 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] | 820 | 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] | 821 | SkRasterHandleAllocator::MakeCanvas, which creates a custom canvas with raster storage for |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 822 | the drawing destination. |
| 823 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 824 | #Return context of custom allocation ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 825 | |
| 826 | #Example |
| 827 | #Description |
| 828 | #ToDo ## |
| 829 | ## |
| 830 | #Function |
| 831 | static void DeleteCallback(void*, void* context) { |
| 832 | delete (char*) context; |
| 833 | } |
| 834 | |
| 835 | class CustomAllocator : public SkRasterHandleAllocator { |
| 836 | public: |
| 837 | bool allocHandle(const SkImageInfo& info, Rec* rec) override { |
| 838 | char* context = new char[4]{'s', 'k', 'i', 'a'}; |
| 839 | rec->fReleaseProc = DeleteCallback; |
| 840 | rec->fReleaseCtx = context; |
| 841 | rec->fHandle = context; |
| 842 | rec->fPixels = context; |
| 843 | rec->fRowBytes = 4; |
| 844 | return true; |
| 845 | } |
| 846 | |
| 847 | void updateHandle(Handle handle, const SkMatrix& ctm, const SkIRect& clip_bounds) override { |
| 848 | // apply canvas matrix and clip to custom environment |
| 849 | } |
| 850 | }; |
| 851 | |
| 852 | ## |
| 853 | void draw(SkCanvas* canvas) { |
| 854 | const SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1); |
| 855 | std::unique_ptr<SkCanvas> c2 = |
| 856 | SkRasterHandleAllocator::MakeCanvas(std::unique_ptr<CustomAllocator>( |
| 857 | new CustomAllocator()), info); |
| 858 | char* context = (char*) c2->accessTopRasterHandle(); |
| 859 | SkDebugf("context = %.4s\n", context); |
| 860 | |
| 861 | } |
| 862 | #StdOut |
| 863 | context = skia |
| 864 | ## |
| 865 | #ToDo skstd::make_unique could not be used because def is private -- note to fix in c++14? ## |
| 866 | ## |
| 867 | |
| 868 | #SeeAlso SkRasterHandleAllocator |
| 869 | |
| 870 | ## |
| 871 | |
| 872 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 873 | #Subtopic Pixels |
| 874 | #Populate |
| 875 | #Line # read and write pixel values ## |
| 876 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 877 | |
| 878 | #Method bool peekPixels(SkPixmap* pixmap) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 879 | #In Pixels |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 880 | #Line # returns if Canvas has direct access to its pixels ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 881 | Returns true if Canvas has direct access to its pixels. |
| 882 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 883 | 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] | 884 | is returned from GPU_Surface, returned by SkDocument::beginPage, returned by |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 885 | SkPictureRecorder::beginRecording, or Canvas is the base of a utility class |
Brian Osman | 46fe9c7 | 2018-03-09 15:44:34 -0500 | [diff] [blame] | 886 | like SkDebugCanvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 887 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 888 | pixmap is valid only while Canvas is in scope and unchanged. Any |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 889 | Canvas or Surface call may invalidate the pixmap values. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 890 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 891 | #Param pixmap storage for pixel state if pixels are readable; otherwise, ignored ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 892 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 893 | #Return true if Canvas has direct access to pixels ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 894 | |
| 895 | #Example |
| 896 | SkPixmap pixmap; |
| 897 | if (canvas->peekPixels(&pixmap)) { |
| 898 | SkDebugf("width=%d height=%d\n", pixmap.bounds().width(), pixmap.bounds().height()); |
| 899 | } |
| 900 | #StdOut |
| 901 | width=256 height=256 |
| 902 | ## |
| 903 | ## |
| 904 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 905 | #SeeAlso readPixels SkBitmap::peekPixels SkImage::peekPixels SkSurface::peekPixels |
| 906 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 907 | ## |
| 908 | |
| 909 | # ------------------------------------------------------------------------------ |
| 910 | |
| 911 | #Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, |
| 912 | int srcX, int srcY) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 913 | #In Pixels |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 914 | #Line # copies and converts rectangle of pixels from Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 915 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 916 | Copies Rect of pixels from Canvas into dstPixels. Matrix and Clip are |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 917 | ignored. |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 918 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 919 | Source Rect corners are (srcX, srcY) and (imageInfo().width(), imageInfo().height()). |
| 920 | Destination Rect corners are (0, 0) and (dstInfo.width(), dstInfo.height()). |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 921 | Copies each readable pixel intersecting both rectangles, without scaling, |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 922 | converting to dstInfo.colorType() and dstInfo.alphaType() if required. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 923 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 924 | Pixels are readable when Device is raster, or backed by a GPU. |
| 925 | Pixels are not readable when SkCanvas is returned by SkDocument::beginPage, |
| 926 | returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility |
Brian Osman | 46fe9c7 | 2018-03-09 15:44:34 -0500 | [diff] [blame] | 927 | class like SkDebugCanvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 928 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 929 | The destination pixel storage must be allocated by the caller. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 930 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 931 | Pixel values are converted only if Color_Type and Alpha_Type |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 932 | do not match. Only pixels within both source and destination rectangles |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 933 | are copied. dstPixels contents outside Rect intersection are unchanged. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 934 | |
| 935 | 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] | 936 | |
| 937 | Does not copy, and returns false if: |
| 938 | |
| 939 | #List |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 940 | # Source and destination rectangles do not intersect. ## |
| 941 | # Canvas pixels could not be converted to dstInfo.colorType() or dstInfo.alphaType(). ## |
| 942 | # Canvas pixels are not readable; for instance, Canvas is document-based. ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 943 | # dstRowBytes is too small to contain one row of pixels. ## |
| 944 | ## |
| 945 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 946 | #Param dstInfo width, height, Color_Type, and Alpha_Type of dstPixels ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 947 | #Param dstPixels storage for pixels; dstInfo.height() times dstRowBytes, or larger ## |
| 948 | #Param dstRowBytes size of one destination row; dstInfo.width() times pixel size, or larger ## |
| 949 | #Param srcX offset into readable pixels in x; may be negative ## |
| 950 | #Param srcY offset into readable pixels in y; may be negative ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 951 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 952 | #Return true if pixels were copied ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 953 | |
| 954 | #Example |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 955 | #Width 64 |
| 956 | #Height 64 |
| 957 | #Description |
| 958 | A black circle drawn on a blue background provides an image to copy. |
| 959 | 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] | 960 | The copied quarter circles overdraw the original circle. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 961 | ## |
| 962 | canvas->clear(SK_ColorBLUE); |
| 963 | SkPaint paint; |
| 964 | canvas->drawCircle(32, 32, 28, paint); |
| 965 | SkImageInfo info = SkImageInfo::Make(64, 64, kBGRA_8888_SkColorType, kPremul_SkAlphaType); |
| 966 | sk_sp<SkData> data(SkData::MakeUninitialized(info.minRowBytes() * info.height())); |
| 967 | sk_bzero(data->writable_data(), info.minRowBytes() * info.height()); |
| 968 | for (int x : { 32, -32 } ) { |
| 969 | for (int y : { 32, -32 } ) { |
| 970 | canvas->readPixels(info, data->writable_data(), info.minRowBytes(), x, y); |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 971 | } |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 972 | } |
| 973 | sk_sp<SkImage> image = SkImage::MakeRasterData(info, data, info.minRowBytes()); |
| 974 | canvas->drawImage(image, 0, 0); |
| 975 | ## |
| 976 | |
| 977 | #Example |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 978 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 979 | Canvas returned by Raster_Surface has Premultiplied pixel values. |
| 980 | clear() takes Unpremultiplied input with Color_Alpha equal 0x80 |
| 981 | and Color_RGB equal 0x55, 0xAA, 0xFF. Color_RGB is multiplied by Color_Alpha |
| 982 | to generate Premultiplied value 0x802B5580. readPixels converts pixel back |
| 983 | to Unpremultiplied value 0x8056A9FF, introducing error. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 984 | ## |
| 985 | canvas->clear(0x8055aaff); |
| 986 | for (SkAlphaType alphaType : { kPremul_SkAlphaType, kUnpremul_SkAlphaType } ) { |
| 987 | uint32_t pixel = 0; |
| 988 | SkImageInfo info = SkImageInfo::Make(1, 1, kBGRA_8888_SkColorType, alphaType); |
| 989 | if (canvas->readPixels(info, &pixel, 4, 0, 0)) { |
| 990 | SkDebugf("pixel = %08x\n", pixel); |
| 991 | } |
| 992 | } |
| 993 | |
| 994 | #StdOut |
| 995 | pixel = 802b5580 |
| 996 | pixel = 8056a9ff |
| 997 | ## |
| 998 | ## |
| 999 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1000 | #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] | 1001 | |
| 1002 | ## |
| 1003 | |
| 1004 | # ------------------------------------------------------------------------------ |
| 1005 | |
| 1006 | #Method bool readPixels(const SkPixmap& pixmap, int srcX, int srcY) |
| 1007 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1008 | Copies Rect of pixels from Canvas into pixmap. Matrix and Clip are |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1009 | ignored. |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1010 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1011 | Source Rect corners are (srcX, srcY) and (imageInfo().width(), imageInfo().height()). |
| 1012 | Destination Rect corners are (0, 0) and (pixmap.width(), pixmap.height()). |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1013 | Copies each readable pixel intersecting both rectangles, without scaling, |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1014 | converting to pixmap.colorType() and pixmap.alphaType() if required. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1015 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1016 | Pixels are readable when Device is raster, or backed by a GPU. |
| 1017 | Pixels are not readable when SkCanvas is returned by SkDocument::beginPage, |
| 1018 | returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility |
Brian Osman | 46fe9c7 | 2018-03-09 15:44:34 -0500 | [diff] [blame] | 1019 | class like SkDebugCanvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1020 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1021 | Caller must allocate pixel storage in pixmap if needed. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1022 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1023 | Pixel values are converted only if Color_Type and Alpha_Type |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1024 | do not match. Only pixels within both source and destination Rects |
| 1025 | are copied. pixmap pixels contents outside Rect intersection are unchanged. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1026 | |
| 1027 | 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] | 1028 | |
| 1029 | Does not copy, and returns false if: |
| 1030 | |
| 1031 | #List |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1032 | # Source and destination rectangles do not intersect. ## |
| 1033 | # Canvas pixels could not be converted to pixmap.colorType() or pixmap.alphaType(). ## |
| 1034 | # Canvas pixels are not readable; for instance, Canvas is document-based. ## |
| 1035 | # Pixmap pixels could not be allocated. ## |
| 1036 | # pixmap.rowBytes() is too small to contain one row of pixels. ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1037 | ## |
| 1038 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1039 | #Param pixmap storage for pixels copied from Canvas ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1040 | #Param srcX offset into readable pixels in x; may be negative ## |
| 1041 | #Param srcY offset into readable pixels in y; may be negative ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1042 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1043 | #Return true if pixels were copied ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1044 | |
| 1045 | #Example |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1046 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1047 | clear() takes Unpremultiplied input with Color_Alpha equal 0x80 |
| 1048 | and Color_RGB equal 0x55, 0xAA, 0xFF. Color_RGB is multiplied by Color_Alpha |
| 1049 | to generate Premultiplied value 0x802B5580. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1050 | ## |
| 1051 | void draw(SkCanvas* canvas) { |
| 1052 | canvas->clear(0x8055aaff); |
| 1053 | uint32_t pixels[1] = { 0 }; |
| 1054 | SkPixmap pixmap(SkImageInfo::MakeN32Premul(1, 1), pixels, 4); |
| 1055 | canvas->readPixels(pixmap, 0, 0); |
| 1056 | SkDebugf("pixel = %08x\n", pixels[0]); |
| 1057 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1058 | #StdOut |
| 1059 | pixel = 802b5580 |
| 1060 | ## |
| 1061 | ## |
| 1062 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1063 | #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] | 1064 | |
| 1065 | ## |
| 1066 | |
| 1067 | # ------------------------------------------------------------------------------ |
| 1068 | |
| 1069 | #Method bool readPixels(const SkBitmap& bitmap, int srcX, int srcY) |
| 1070 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1071 | Copies Rect of pixels from Canvas into bitmap. Matrix and Clip are |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1072 | ignored. |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1073 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1074 | Source Rect corners are (srcX, srcY) and (imageInfo().width(), imageInfo().height()). |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1075 | Destination Rect corners are (0, 0) and (bitmap.width(), bitmap.height()). |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1076 | Copies each readable pixel intersecting both rectangles, without scaling, |
| 1077 | converting to bitmap.colorType() and bitmap.alphaType() if required. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1078 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1079 | Pixels are readable when Device is raster, or backed by a GPU. |
| 1080 | Pixels are not readable when SkCanvas is returned by SkDocument::beginPage, |
| 1081 | returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility |
Brian Osman | 46fe9c7 | 2018-03-09 15:44:34 -0500 | [diff] [blame] | 1082 | class like SkDebugCanvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1083 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1084 | Caller must allocate pixel storage in bitmap if needed. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1085 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1086 | Bitmap values are converted only if Color_Type and Alpha_Type |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1087 | do not match. Only pixels within both source and destination rectangles |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1088 | are copied. Bitmap pixels outside Rect intersection are unchanged. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1089 | |
| 1090 | 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] | 1091 | |
| 1092 | Does not copy, and returns false if: |
| 1093 | |
| 1094 | #List |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1095 | # Source and destination rectangles do not intersect. ## |
| 1096 | # Canvas pixels could not be converted to bitmap.colorType() or bitmap.alphaType(). ## |
| 1097 | # Canvas pixels are not readable; for instance, Canvas is document-based. ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1098 | # bitmap pixels could not be allocated. ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1099 | # bitmap.rowBytes() is too small to contain one row of pixels. ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1100 | ## |
| 1101 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1102 | #Param bitmap storage for pixels copied from Canvas ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1103 | #Param srcX offset into readable pixels in x; may be negative ## |
| 1104 | #Param srcY offset into readable pixels in y; may be negative ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1105 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1106 | #Return true if pixels were copied ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1107 | |
| 1108 | #Example |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1109 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1110 | clear() takes Unpremultiplied input with Color_Alpha equal 0x80 |
| 1111 | and Color_RGB equal 0x55, 0xAA, 0xFF. Color_RGB is multiplied by Color_Alpha |
| 1112 | to generate Premultiplied value 0x802B5580. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1113 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1114 | void draw(SkCanvas* canvas) { |
| 1115 | canvas->clear(0x8055aaff); |
| 1116 | SkBitmap bitmap; |
| 1117 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(1, 1)); |
| 1118 | canvas->readPixels(bitmap, 0, 0); |
| 1119 | SkDebugf("pixel = %08x\n", bitmap.getAddr32(0, 0)[0]); |
| 1120 | } |
| 1121 | #StdOut |
| 1122 | pixel = 802b5580 |
| 1123 | ## |
| 1124 | ## |
| 1125 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1126 | #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] | 1127 | |
| 1128 | ## |
| 1129 | |
| 1130 | # ------------------------------------------------------------------------------ |
| 1131 | |
| 1132 | #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] | 1133 | #In Pixels |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1134 | #Line # copies and converts rectangle of pixels to Canvas ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1135 | Copies Rect from pixels to Canvas. Matrix and Clip are ignored. |
| 1136 | Source Rect corners are (0, 0) and (info.width(), info.height()). |
| 1137 | Destination Rect corners are (x, y) and |
| 1138 | (imageInfo().width(), imageInfo().height()). |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1139 | |
| 1140 | Copies each readable pixel intersecting both rectangles, without scaling, |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1141 | converting to imageInfo().colorType() and imageInfo().alphaType() if required. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1142 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1143 | Pixels are writable when Device is raster, or backed by a GPU. |
| 1144 | Pixels are not writable when SkCanvas is returned by SkDocument::beginPage, |
| 1145 | returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility |
Brian Osman | 46fe9c7 | 2018-03-09 15:44:34 -0500 | [diff] [blame] | 1146 | class like SkDebugCanvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1147 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1148 | Pixel values are converted only if Color_Type and Alpha_Type |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1149 | do not match. Only pixels within both source and destination rectangles |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1150 | are copied. Canvas pixels outside Rect intersection are unchanged. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1151 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1152 | Pass negative values for x or y to offset pixels to the left or |
| 1153 | above Canvas pixels. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1154 | |
| 1155 | Does not copy, and returns false if: |
| 1156 | |
| 1157 | #List |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1158 | # Source and destination rectangles do not intersect. ## |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1159 | # pixels could not be converted to Canvas imageInfo().colorType() or |
| 1160 | imageInfo().alphaType(). ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1161 | # Canvas pixels are not writable; for instance, Canvas is document-based. ## |
| 1162 | # rowBytes is too small to contain one row of pixels. ## |
| 1163 | ## |
| 1164 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1165 | #Param info width, height, Color_Type, and Alpha_Type of pixels ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1166 | #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] | 1167 | #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] | 1168 | #Param x offset into Canvas writable pixels in x; may be negative ## |
| 1169 | #Param y offset into Canvas writable pixels in y; may be negative ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1170 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1171 | #Return true if pixels were written to Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1172 | |
| 1173 | #Example |
| 1174 | SkImageInfo imageInfo = SkImageInfo::MakeN32(256, 1, kPremul_SkAlphaType); |
| 1175 | for (int y = 0; y < 256; ++y) { |
| 1176 | uint32_t pixels[256]; |
| 1177 | for (int x = 0; x < 256; ++x) { |
| 1178 | pixels[x] = SkColorSetARGB(x, x + y, x, x - y); |
| 1179 | } |
| 1180 | canvas->writePixels(imageInfo, &pixels, sizeof(pixels), 0, y); |
| 1181 | } |
| 1182 | ## |
| 1183 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1184 | #SeeAlso readPixels drawBitmap drawImage SkBitmap::writePixels |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1185 | |
| 1186 | ## |
| 1187 | |
| 1188 | # ------------------------------------------------------------------------------ |
| 1189 | |
| 1190 | #Method bool writePixels(const SkBitmap& bitmap, int x, int y) |
| 1191 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1192 | Copies Rect from pixels to Canvas. Matrix and Clip are ignored. |
| 1193 | Source Rect corners are (0, 0) and (bitmap.width(), bitmap.height()). |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1194 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1195 | Destination Rect corners are (x, y) and |
| 1196 | (imageInfo().width(), imageInfo().height()). |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1197 | |
| 1198 | Copies each readable pixel intersecting both rectangles, without scaling, |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1199 | converting to imageInfo().colorType() and imageInfo().alphaType() if required. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1200 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1201 | Pixels are writable when Device is raster, or backed by a GPU. |
| 1202 | Pixels are not writable when SkCanvas is returned by SkDocument::beginPage, |
| 1203 | returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility |
Brian Osman | 46fe9c7 | 2018-03-09 15:44:34 -0500 | [diff] [blame] | 1204 | class like SkDebugCanvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1205 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1206 | Pixel values are converted only if Color_Type and Alpha_Type |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1207 | do not match. Only pixels within both source and destination rectangles |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1208 | are copied. Canvas pixels outside Rect intersection are unchanged. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1209 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1210 | Pass negative values for x or y to offset pixels to the left or |
| 1211 | above Canvas pixels. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1212 | |
| 1213 | Does not copy, and returns false if: |
| 1214 | |
| 1215 | #List |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1216 | # Source and destination rectangles do not intersect. ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1217 | # bitmap does not have allocated pixels. ## |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1218 | # bitmap pixels could not be converted to Canvas imageInfo().colorType() or |
| 1219 | imageInfo().alphaType(). ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1220 | # Canvas pixels are not writable; for instance, Canvas is document based. ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1221 | # bitmap pixels are inaccessible; for instance, bitmap wraps a texture. ## |
| 1222 | ## |
| 1223 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1224 | #Param bitmap contains pixels copied to Canvas ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1225 | #Param x offset into Canvas writable pixels in x; may be negative ## |
| 1226 | #Param y offset into Canvas writable pixels in y; may be negative ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1227 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1228 | #Return true if pixels were written to Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1229 | |
| 1230 | #Example |
| 1231 | void draw(SkCanvas* canvas) { |
| 1232 | SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(2, 2); |
| 1233 | SkBitmap bitmap; |
| 1234 | bitmap.setInfo(imageInfo); |
| 1235 | uint32_t pixels[4]; |
| 1236 | bitmap.setPixels(pixels); |
| 1237 | for (int y = 0; y < 256; y += 2) { |
| 1238 | for (int x = 0; x < 256; x += 2) { |
| 1239 | pixels[0] = SkColorSetRGB(x, y, x | y); |
| 1240 | pixels[1] = SkColorSetRGB(x ^ y, y, x); |
| 1241 | pixels[2] = SkColorSetRGB(x, x & y, y); |
| 1242 | pixels[3] = SkColorSetRGB(~x, ~y, x); |
| 1243 | canvas->writePixels(bitmap, x, y); |
| 1244 | } |
| 1245 | } |
| 1246 | } |
| 1247 | ## |
| 1248 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1249 | #SeeAlso readPixels drawBitmap drawImage SkBitmap::writePixels |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1250 | |
| 1251 | ## |
| 1252 | |
| 1253 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1254 | #Subtopic State_Stack |
| 1255 | #Line # stack of state for hierarchical drawing ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1256 | |
| 1257 | Canvas maintains a stack of state that allows hierarchical drawing, commonly used |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1258 | to implement windows and views. The initial state has an identity matrix and and |
| 1259 | an infinite clip. Even with a wide-open clip, drawing is constrained by the |
| 1260 | bounds of the Canvas Surface or Device. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1261 | |
| 1262 | Canvas savable state consists of Clip, Matrix, and Draw_Filter. |
| 1263 | Clip describes the area that may be drawn to. |
| 1264 | Matrix transforms the geometry. |
| 1265 | Draw_Filter (deprecated on most platforms) modifies the paint before drawing. |
| 1266 | |
| 1267 | save(), saveLayer, saveLayerPreserveLCDTextRequests, and saveLayerAlpha |
| 1268 | save state and return the depth of the stack. |
| 1269 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1270 | restore(), restoreToCount, and ~SkCanvas() revert state to its value when saved. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1271 | |
| 1272 | Each state on the stack intersects Clip with the previous Clip, |
| 1273 | and concatenates Matrix with the previous Matrix. |
| 1274 | The intersected Clip makes the drawing area the same or smaller; |
| 1275 | the concatenated Matrix may move the origin and potentially scale or rotate |
| 1276 | the coordinate space. |
| 1277 | |
| 1278 | Canvas does not require balancing the state stack but it is a good idea |
| 1279 | to do so. Calling save() without restore() will eventually cause Skia to fail; |
| 1280 | mismatched save() and restore() create hard to find bugs. |
| 1281 | |
| 1282 | It is not possible to use state to draw outside of the clip defined by the |
| 1283 | previous state. |
| 1284 | |
| 1285 | #Example |
| 1286 | #Description |
| 1287 | Draw to ever smaller clips; then restore drawing to full canvas. |
| 1288 | Note that the second clipRect is not permitted to enlarge Clip. |
| 1289 | ## |
| 1290 | #Height 160 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1291 | void draw(SkCanvas* canvas) { |
| 1292 | SkPaint paint; |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 1293 | canvas->save(); // records stack depth to restore |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1294 | canvas->clipRect(SkRect::MakeWH(100, 100)); // constrains drawing to clip |
| 1295 | canvas->clear(SK_ColorRED); // draws to limit of clip |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 1296 | canvas->save(); // records stack depth to restore |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1297 | canvas->clipRect(SkRect::MakeWH(50, 150)); // Rect below 100 is ignored |
| 1298 | canvas->clear(SK_ColorBLUE); // draws to smaller clip |
| 1299 | canvas->restore(); // enlarges clip |
| 1300 | canvas->drawLine(20, 20, 150, 150, paint); // line below 100 is not drawn |
| 1301 | canvas->restore(); // enlarges clip |
| 1302 | canvas->drawLine(150, 20, 50, 120, paint); // line below 100 is drawn |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1303 | } |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 1304 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1305 | |
| 1306 | Each Clip uses the current Matrix for its coordinates. |
| 1307 | |
| 1308 | #Example |
| 1309 | #Description |
| 1310 | While clipRect is given the same rectangle twice, Matrix makes the second |
| 1311 | clipRect draw at half the size of the first. |
| 1312 | ## |
| 1313 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1314 | void draw(SkCanvas* canvas) { |
| 1315 | canvas->clipRect(SkRect::MakeWH(100, 100)); |
| 1316 | canvas->clear(SK_ColorRED); |
| 1317 | canvas->scale(.5, .5); |
| 1318 | canvas->clipRect(SkRect::MakeWH(100, 100)); |
| 1319 | canvas->clear(SK_ColorBLUE); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1320 | } |
| 1321 | ## |
| 1322 | |
| 1323 | #SeeAlso save() saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha restore() restoreToCount |
| 1324 | |
| 1325 | #Method int save() |
| 1326 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1327 | #In State_Stack |
| 1328 | #Line # saves Clip and Matrix on stack ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1329 | Saves Matrix, Clip, and Draw_Filter (Draw_Filter deprecated on most platforms). |
| 1330 | Calling restore() discards changes to Matrix, Clip, and Draw_Filter, |
| 1331 | restoring the Matrix, Clip, and Draw_Filter to their state when save() was called. |
| 1332 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1333 | Matrix may be changed by translate(), scale(), rotate(), skew(), concat(), setMatrix, |
| 1334 | and resetMatrix. Clip may be changed by clipRect, clipRRect, clipPath, clipRegion. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1335 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1336 | Saved Canvas state is put on a stack; multiple calls to save() should be balance |
| 1337 | by an equal number of calls to restore(). |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1338 | |
| 1339 | Call restoreToCount with result to restore this and subsequent saves. |
| 1340 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1341 | #Return depth of saved stack ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1342 | |
| 1343 | #Example |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 1344 | #Description |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1345 | The black square is translated 50 pixels down and to the right. |
| 1346 | Restoring Canvas state removes translate() from Canvas stack; |
| 1347 | the red square is not translated, and is drawn at the origin. |
| 1348 | ## |
| 1349 | #Height 100 |
| 1350 | void draw(SkCanvas* canvas) { |
| 1351 | SkPaint paint; |
| 1352 | SkRect rect = { 0, 0, 25, 25 }; |
| 1353 | canvas->drawRect(rect, paint); |
| 1354 | canvas->save(); |
| 1355 | canvas->translate(50, 50); |
| 1356 | canvas->drawRect(rect, paint); |
| 1357 | canvas->restore(); |
| 1358 | paint.setColor(SK_ColorRED); |
| 1359 | canvas->drawRect(rect, paint); |
| 1360 | } |
| 1361 | ## |
| 1362 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1363 | #SeeAlso saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha restore() restoreToCount |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1364 | |
| 1365 | ## |
| 1366 | |
| 1367 | # ------------------------------------------------------------------------------ |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1368 | |
| 1369 | #Method void restore() |
| 1370 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1371 | #In State_Stack |
| 1372 | #Line # restores changes to Clip and Matrix, pops save stack ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1373 | Removes changes to Matrix, Clip, and Draw_Filter since Canvas state was |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 1374 | last saved. The state is removed from the stack. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1375 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 1376 | Does nothing if the stack is empty. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1377 | |
| 1378 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1379 | void draw(SkCanvas* canvas) { |
| 1380 | SkCanvas simple; |
| 1381 | SkDebugf("depth = %d\n", simple.getSaveCount()); |
| 1382 | simple.restore(); |
| 1383 | SkDebugf("depth = %d\n", simple.getSaveCount()); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1384 | } |
| 1385 | ## |
| 1386 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1387 | #SeeAlso save() saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha restoreToCount |
| 1388 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1389 | ## |
| 1390 | |
| 1391 | # ------------------------------------------------------------------------------ |
| 1392 | |
| 1393 | #Method int getSaveCount() const |
| 1394 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1395 | #In State_Stack |
| 1396 | #Line # returns depth of stack containing Clip and Matrix ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1397 | Returns the number of saved states, each containing: Matrix, Clip, and Draw_Filter. |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 1398 | 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] | 1399 | The save count of a new canvas is one. |
| 1400 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1401 | #Return depth of save state stack ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1402 | |
| 1403 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1404 | void draw(SkCanvas* canvas) { |
| 1405 | SkCanvas simple; |
| 1406 | SkDebugf("depth = %d\n", simple.getSaveCount()); |
| 1407 | simple.save(); |
| 1408 | SkDebugf("depth = %d\n", simple.getSaveCount()); |
| 1409 | simple.restore(); |
| 1410 | SkDebugf("depth = %d\n", simple.getSaveCount()); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1411 | } |
| 1412 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1413 | depth = 1 |
| 1414 | depth = 2 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1415 | depth = 1 |
| 1416 | ## |
| 1417 | ## |
| 1418 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1419 | #SeeAlso save() restore() restoreToCount |
| 1420 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1421 | ## |
| 1422 | |
| 1423 | # ------------------------------------------------------------------------------ |
| 1424 | |
| 1425 | #Method void restoreToCount(int saveCount) |
| 1426 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1427 | #In State_Stack |
| 1428 | #Line # restores changes to Clip and Matrix to given depth ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1429 | Restores state to Matrix, Clip, and Draw_Filter values when save(), saveLayer, |
| 1430 | saveLayerPreserveLCDTextRequests, or saveLayerAlpha returned saveCount. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1431 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 1432 | Does nothing if saveCount is greater than state stack count. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1433 | Restores state to initial values if saveCount is less than or equal to one. |
| 1434 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1435 | #Param saveCount depth of state stack to restore ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1436 | |
| 1437 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1438 | void draw(SkCanvas* canvas) { |
| 1439 | SkDebugf("depth = %d\n", canvas->getSaveCount()); |
| 1440 | canvas->save(); |
| 1441 | canvas->save(); |
| 1442 | SkDebugf("depth = %d\n", canvas->getSaveCount()); |
| 1443 | canvas->restoreToCount(0); |
| 1444 | SkDebugf("depth = %d\n", canvas->getSaveCount()); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1445 | } |
| 1446 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1447 | depth = 1 |
| 1448 | depth = 3 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1449 | depth = 1 |
| 1450 | ## |
| 1451 | ## |
| 1452 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 1453 | #SeeAlso restore() getSaveCount save() |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1454 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1455 | ## |
| 1456 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1457 | #Subtopic State_Stack ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1458 | |
| 1459 | # ------------------------------------------------------------------------------ |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1460 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1461 | #Subtopic Layer |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1462 | #Substitute layer |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1463 | #Alias Layers |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1464 | #Line # temporary Bitmap to draw into ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1465 | |
| 1466 | Layer allocates a temporary Bitmap to draw into. When the drawing is |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 1467 | complete, the Bitmap is drawn into the Canvas. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1468 | |
| 1469 | Layer is saved in a stack along with other saved state. When state with a Layer |
| 1470 | is restored, the Bitmap is drawn into the previous Layer. |
| 1471 | |
| 1472 | Layer may be initialized with the contents of the previous Layer. When Layer is |
| 1473 | restored, its Bitmap can be modified by Paint passed to Layer to apply |
| 1474 | Color_Alpha, Color_Filter, Image_Filter, and Blend_Mode. |
| 1475 | |
| 1476 | #Method int saveLayer(const SkRect* bounds, const SkPaint* paint) |
| 1477 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1478 | #In Layer |
| 1479 | #Line # saves Clip and Matrix on stack; creates Layer ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1480 | Saves Matrix, Clip, and Draw_Filter (Draw_Filter deprecated on most platforms), |
| 1481 | and allocates a Bitmap for subsequent drawing. |
| 1482 | Calling restore() discards changes to Matrix, Clip, and Draw_Filter, |
| 1483 | and draws the Bitmap. |
| 1484 | |
| 1485 | Matrix may be changed by translate(), scale(), rotate(), skew(), concat(), |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 1486 | setMatrix, and resetMatrix. Clip may be changed by clipRect, clipRRect, |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1487 | clipPath, clipRegion. |
| 1488 | |
| 1489 | Rect bounds suggests but does not define the Bitmap size. To clip drawing to |
| 1490 | a specific rectangle, use clipRect. |
| 1491 | |
| 1492 | Optional Paint paint applies Color_Alpha, Color_Filter, Image_Filter, and |
| 1493 | Blend_Mode when restore() is called. |
| 1494 | |
| 1495 | Call restoreToCount with returned value to restore this and subsequent saves. |
| 1496 | |
| 1497 | #Param bounds hint to limit the size of the Layer; may be nullptr ## |
| 1498 | #Param paint graphics state for Layer; may be nullptr ## |
| 1499 | |
| 1500 | #Return depth of saved stack ## |
| 1501 | |
| 1502 | #Example |
| 1503 | #Description |
| 1504 | Rectangles are blurred by Image_Filter when restore() draws Layer to main |
| 1505 | Canvas. |
| 1506 | ## |
| 1507 | #Height 128 |
| 1508 | void draw(SkCanvas* canvas) { |
| 1509 | SkPaint paint, blur; |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1510 | blur.setImageFilter(SkBlurImageFilter::Make(3, 3, nullptr)); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1511 | canvas->saveLayer(nullptr, &blur); |
| 1512 | SkRect rect = { 25, 25, 50, 50}; |
| 1513 | canvas->drawRect(rect, paint); |
| 1514 | canvas->translate(50, 50); |
| 1515 | paint.setColor(SK_ColorRED); |
| 1516 | canvas->drawRect(rect, paint); |
| 1517 | canvas->restore(); |
| 1518 | } |
| 1519 | ## |
| 1520 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1521 | #SeeAlso save() restore() saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha SaveLayerRec |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1522 | |
| 1523 | ## |
| 1524 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 1525 | #Method int saveLayer(const SkRect& bounds, const SkPaint* paint) |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1526 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1527 | #In Layer |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1528 | Saves Matrix, Clip, and Draw_Filter (Draw_Filter deprecated on most platforms), |
| 1529 | and allocates a Bitmap for subsequent drawing. |
| 1530 | Calling restore() discards changes to Matrix, Clip, and Draw_Filter, |
| 1531 | and draws the Bitmap. |
| 1532 | |
| 1533 | Matrix may be changed by translate(), scale(), rotate(), skew(), concat(), |
| 1534 | setMatrix, and resetMatrix. Clip may be changed by clipRect, clipRRect, |
| 1535 | clipPath, clipRegion. |
| 1536 | |
| 1537 | Rect bounds suggests but does not define the Layer size. To clip drawing to |
| 1538 | a specific rectangle, use clipRect. |
| 1539 | |
| 1540 | Optional Paint paint applies Color_Alpha, Color_Filter, Image_Filter, and |
| 1541 | Blend_Mode when restore() is called. |
| 1542 | |
| 1543 | Call restoreToCount with returned value to restore this and subsequent saves. |
| 1544 | |
| 1545 | #Param bounds hint to limit the size of Layer; may be nullptr ## |
| 1546 | #Param paint graphics state for Layer; may be nullptr ## |
| 1547 | |
| 1548 | #Return depth of saved stack ## |
| 1549 | |
| 1550 | #Example |
| 1551 | #Description |
| 1552 | Rectangles are blurred by Image_Filter when restore() draws Layer to main Canvas. |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 1553 | The red rectangle is clipped; it does not fully fit on Layer. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1554 | Image_Filter blurs past edge of Layer so red rectangle is blurred on all sides. |
| 1555 | ## |
| 1556 | #Height 128 |
| 1557 | void draw(SkCanvas* canvas) { |
| 1558 | SkPaint paint, blur; |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1559 | blur.setImageFilter(SkBlurImageFilter::Make(3, 3, nullptr)); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1560 | canvas->saveLayer(SkRect::MakeWH(90, 90), &blur); |
| 1561 | SkRect rect = { 25, 25, 50, 50}; |
| 1562 | canvas->drawRect(rect, paint); |
| 1563 | canvas->translate(50, 50); |
| 1564 | paint.setColor(SK_ColorRED); |
| 1565 | canvas->drawRect(rect, paint); |
| 1566 | canvas->restore(); |
| 1567 | } |
| 1568 | ## |
| 1569 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1570 | #SeeAlso save() restore() saveLayerPreserveLCDTextRequests saveLayerAlpha SaveLayerRec |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1571 | |
| 1572 | ## |
| 1573 | |
| 1574 | #Method int saveLayerPreserveLCDTextRequests(const SkRect* bounds, const SkPaint* paint) |
| 1575 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1576 | #In Layer |
| 1577 | #Line # saves Clip and Matrix on stack; creates Layer for LCD text ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1578 | Saves Matrix, Clip, and Draw_Filter (Draw_Filter deprecated on most platforms), |
| 1579 | and allocates a Bitmap for subsequent drawing. |
| 1580 | LCD_Text is preserved when the Layer is drawn to the prior Layer. |
| 1581 | |
| 1582 | Calling restore() discards changes to Matrix, Clip, and Draw_Filter, |
| 1583 | and draws Layer. |
| 1584 | |
| 1585 | Matrix may be changed by translate(), scale(), rotate(), skew(), concat(), |
| 1586 | setMatrix, and resetMatrix. Clip may be changed by clipRect, clipRRect, |
| 1587 | clipPath, clipRegion. |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 1588 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1589 | Rect bounds suggests but does not define the Layer size. To clip drawing to |
| 1590 | a specific rectangle, use clipRect. |
| 1591 | |
| 1592 | Optional Paint paint applies Color_Alpha, Color_Filter, Image_Filter, and |
| 1593 | Blend_Mode when restore() is called. |
| 1594 | |
| 1595 | Call restoreToCount with returned value to restore this and subsequent saves. |
| 1596 | |
| 1597 | Draw text on an opaque background so that LCD_Text blends correctly with the |
| 1598 | 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] | 1599 | incorrect blending. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1600 | |
| 1601 | #Param bounds hint to limit the size of Layer; may be nullptr ## |
| 1602 | #Param paint graphics state for Layer; may be nullptr ## |
| 1603 | |
| 1604 | #Return depth of saved stack ## |
| 1605 | |
| 1606 | #Example |
| 1607 | SkPaint paint; |
| 1608 | paint.setAntiAlias(true); |
| 1609 | paint.setLCDRenderText(true); |
| 1610 | paint.setTextSize(20); |
| 1611 | for (auto preserve : { false, true } ) { |
| 1612 | preserve ? canvas->saveLayerPreserveLCDTextRequests(nullptr, nullptr) |
| 1613 | : canvas->saveLayer(nullptr, nullptr); |
| 1614 | SkPaint p; |
| 1615 | p.setColor(SK_ColorWHITE); |
| 1616 | // Comment out the next line to draw on a non-opaque background. |
| 1617 | canvas->drawRect(SkRect::MakeLTRB(25, 40, 200, 70), p); |
| 1618 | canvas->drawString("Hamburgefons", 30, 60, paint); |
| 1619 | |
| 1620 | p.setColor(0xFFCCCCCC); |
| 1621 | canvas->drawRect(SkRect::MakeLTRB(25, 70, 200, 100), p); |
| 1622 | canvas->drawString("Hamburgefons", 30, 90, paint); |
| 1623 | |
| 1624 | canvas->restore(); |
| 1625 | canvas->translate(0, 80); |
| 1626 | } |
| 1627 | ## |
| 1628 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1629 | #SeeAlso save() restore() saveLayer saveLayerAlpha SaveLayerRec |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1630 | |
| 1631 | ## |
| 1632 | |
| 1633 | #Method int saveLayerAlpha(const SkRect* bounds, U8CPU alpha) |
| 1634 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1635 | #In Layer |
| 1636 | #Line # saves Clip and Matrix on stack; creates Layer; sets opacity ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1637 | Saves Matrix, Clip, and Draw_Filter (Draw_Filter deprecated on most platforms), |
| 1638 | and allocates Bitmap for subsequent drawing. |
| 1639 | |
| 1640 | Calling restore() discards changes to Matrix, Clip, and Draw_Filter, |
| 1641 | and blends Layer with alpha opacity onto prior Layer. |
| 1642 | |
| 1643 | Matrix may be changed by translate(), scale(), rotate(), skew(), concat(), |
| 1644 | setMatrix, and resetMatrix. Clip may be changed by clipRect, clipRRect, |
| 1645 | clipPath, clipRegion. |
| 1646 | |
| 1647 | Rect bounds suggests but does not define Layer size. To clip drawing to |
| 1648 | a specific rectangle, use clipRect. |
| 1649 | |
| 1650 | alpha of zero is fully transparent, 255 is fully opaque. |
| 1651 | |
| 1652 | Call restoreToCount with returned value to restore this and subsequent saves. |
| 1653 | |
| 1654 | #Param bounds hint to limit the size of Layer; may be nullptr ## |
| 1655 | #Param alpha opacity of Layer ## |
| 1656 | |
| 1657 | #Return depth of saved stack ## |
| 1658 | |
| 1659 | #Example |
| 1660 | SkPaint paint; |
| 1661 | paint.setColor(SK_ColorRED); |
| 1662 | canvas->drawCircle(50, 50, 50, paint); |
| 1663 | canvas->saveLayerAlpha(nullptr, 128); |
| 1664 | paint.setColor(SK_ColorBLUE); |
| 1665 | canvas->drawCircle(100, 50, 50, paint); |
| 1666 | paint.setColor(SK_ColorGREEN); |
| 1667 | paint.setAlpha(128); |
| 1668 | canvas->drawCircle(75, 90, 50, paint); |
| 1669 | canvas->restore(); |
| 1670 | ## |
| 1671 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1672 | #SeeAlso save() restore() saveLayer saveLayerPreserveLCDTextRequests SaveLayerRec |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1673 | |
| 1674 | ## |
| 1675 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 1676 | #ToDo |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1677 | add new markup to associate typedef SaveLayerFlags with Enum so that, for |
| 1678 | documentation purposes, this enum is named rather than anonymous |
| 1679 | ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1680 | |
Cary Clark | d98f78c | 2018-04-26 08:32:37 -0400 | [diff] [blame^] | 1681 | #Enum SaveLayerFlagsSet |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1682 | #Line # sets SaveLayerRec options ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1683 | #Code |
Cary Clark | d98f78c | 2018-04-26 08:32:37 -0400 | [diff] [blame^] | 1684 | enum SaveLayerFlagsSet { |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1685 | kPreserveLCDText_SaveLayerFlag = 1 << 1, |
| 1686 | kInitWithPrevious_SaveLayerFlag = 1 << 2, |
Mike Reed | 910ca0f | 2018-04-25 13:04:05 -0400 | [diff] [blame] | 1687 | kMaskAgainstCoverage_EXPERIMENTAL_DONT_USE_SaveLayerFlag = 1 << 3, |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1688 | kDontClipToLayer_Legacy_SaveLayerFlag = kDontClipToLayer_PrivateSaveLayerFlag, |
| 1689 | }; |
Cary Clark | d98f78c | 2018-04-26 08:32:37 -0400 | [diff] [blame^] | 1690 | |
| 1691 | typedef uint32_t SaveLayerFlags; |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1692 | ## |
| 1693 | |
| 1694 | SaveLayerFlags provides options that may be used in any combination in SaveLayerRec, |
| 1695 | defining how Layer allocated by saveLayer operates. |
| 1696 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1697 | #Const kPreserveLCDText_SaveLayerFlag 2 |
| 1698 | Creates Layer for LCD text. Flag is ignored if Layer Paint contains |
| 1699 | Image_Filter or Color_Filter. |
| 1700 | ## |
| 1701 | |
| 1702 | #Const kInitWithPrevious_SaveLayerFlag 4 |
| 1703 | Initializes Layer with the contents of the previous Layer. |
| 1704 | ## |
| 1705 | |
Mike Reed | 910ca0f | 2018-04-25 13:04:05 -0400 | [diff] [blame] | 1706 | #Const kMaskAgainstCoverage_EXPERIMENTAL_DONT_USE_SaveLayerFlag 8 |
| 1707 | Experimental -- don't use |
| 1708 | ## |
| 1709 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1710 | #Const kDontClipToLayer_Legacy_SaveLayerFlag 0x80000000 |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1711 | #Deprecated soon |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1712 | ## |
| 1713 | |
| 1714 | #Example |
| 1715 | #Height 160 |
| 1716 | #Description |
| 1717 | Canvas Layer captures red and blue circles scaled up by four. |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 1718 | scalePaint blends Layer back with transparency. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1719 | ## |
| 1720 | void draw(SkCanvas* canvas) { |
| 1721 | SkPaint redPaint, bluePaint, scalePaint; |
| 1722 | redPaint.setColor(SK_ColorRED); |
| 1723 | canvas->drawCircle(21, 21, 8, redPaint); |
| 1724 | bluePaint.setColor(SK_ColorBLUE); |
| 1725 | canvas->drawCircle(31, 21, 8, bluePaint); |
| 1726 | SkMatrix matrix; |
| 1727 | matrix.setScale(4, 4); |
| 1728 | scalePaint.setAlpha(0x40); |
| 1729 | scalePaint.setImageFilter( |
| 1730 | SkImageFilter::MakeMatrixFilter(matrix, kNone_SkFilterQuality, nullptr)); |
| 1731 | SkCanvas::SaveLayerRec saveLayerRec(nullptr, &scalePaint, |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 1732 | SkCanvas::kInitWithPrevious_SaveLayerFlag); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1733 | canvas->saveLayer(saveLayerRec); |
| 1734 | canvas->restore(); |
| 1735 | } |
| 1736 | ## |
| 1737 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1738 | #SeeAlso save() restore() saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha SaveLayerRec |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1739 | |
| 1740 | #Enum ## |
| 1741 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1742 | #Typedef uint32_t SaveLayerFlags |
| 1743 | |
| 1744 | ## |
| 1745 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1746 | #Struct SaveLayerRec |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1747 | #Line # contains the state used to create the Layer ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1748 | #Code |
| 1749 | struct SaveLayerRec { |
| 1750 | SaveLayerRec*(... |
| 1751 | |
| 1752 | const SkRect* fBounds; |
| 1753 | const SkPaint* fPaint; |
| 1754 | const SkImageFilter* fBackdrop; |
| 1755 | SaveLayerFlags fSaveLayerFlags; |
| 1756 | }; |
| 1757 | ## |
| 1758 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 1759 | SaveLayerRec contains the state used to create the Layer. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1760 | |
| 1761 | #Member const SkRect* fBounds |
| 1762 | fBounds is used as a hint to limit the size of Layer; may be nullptr. |
| 1763 | fBounds suggests but does not define Layer size. To clip drawing to |
| 1764 | a specific rectangle, use clipRect. |
| 1765 | ## |
| 1766 | |
| 1767 | #Member const SkPaint* fPaint |
| 1768 | fPaint modifies how Layer overlays the prior Layer; may be nullptr. |
| 1769 | Color_Alpha, Blend_Mode, Color_Filter, Draw_Looper, Image_Filter, and |
| 1770 | Mask_Filter affect Layer draw. |
| 1771 | ## |
| 1772 | |
| 1773 | #Member const SkImageFilter* fBackdrop |
| 1774 | fBackdrop applies Image_Filter to the prior Layer when copying to the Layer; |
| 1775 | may be nullptr. Use kInitWithPrevious_SaveLayerFlag to copy the |
| 1776 | prior Layer without an Image_Filter. |
| 1777 | ## |
| 1778 | |
| 1779 | #Member const SkImage* fClipMask |
| 1780 | restore() clips Layer by the Color_Alpha channel of fClipMask when |
| 1781 | Layer is copied to Device. fClipMask may be nullptr. . |
| 1782 | ## |
| 1783 | |
| 1784 | #Member const SkMatrix* fClipMatrix |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 1785 | fClipMatrix transforms fClipMask before it clips Layer. If |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1786 | fClipMask describes a translucent gradient, it may be scaled and rotated |
| 1787 | without introducing artifacts. fClipMatrix may be nullptr. |
| 1788 | ## |
| 1789 | |
| 1790 | #Member SaveLayerFlags fSaveLayerFlags |
| 1791 | fSaveLayerFlags are used to create Layer without transparency, |
| 1792 | create Layer for LCD text, and to create Layer with the |
| 1793 | contents of the previous Layer. |
| 1794 | ## |
| 1795 | |
| 1796 | #Example |
| 1797 | #Height 160 |
| 1798 | #Description |
| 1799 | Canvas Layer captures a red Anti-aliased circle and a blue Aliased circle scaled |
| 1800 | up by four. After drawing another red circle without scaling on top, the Layer is |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 1801 | transferred to the main canvas. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1802 | ## |
| 1803 | void draw(SkCanvas* canvas) { |
| 1804 | SkPaint redPaint, bluePaint; |
| 1805 | redPaint.setAntiAlias(true); |
| 1806 | redPaint.setColor(SK_ColorRED); |
| 1807 | canvas->drawCircle(21, 21, 8, redPaint); |
| 1808 | bluePaint.setColor(SK_ColorBLUE); |
| 1809 | canvas->drawCircle(31, 21, 8, bluePaint); |
| 1810 | SkMatrix matrix; |
| 1811 | matrix.setScale(4, 4); |
| 1812 | auto scaler = SkImageFilter::MakeMatrixFilter(matrix, kNone_SkFilterQuality, nullptr); |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 1813 | SkCanvas::SaveLayerRec saveLayerRec(nullptr, nullptr, scaler.get(), 0); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1814 | canvas->saveLayer(saveLayerRec); |
| 1815 | canvas->drawCircle(125, 85, 8, redPaint); |
| 1816 | canvas->restore(); |
| 1817 | } |
| 1818 | ## |
| 1819 | |
| 1820 | #Method SaveLayerRec() |
| 1821 | |
| 1822 | Sets fBounds, fPaint, and fBackdrop to nullptr. Clears fSaveLayerFlags. |
| 1823 | |
| 1824 | #Return empty SaveLayerRec ## |
| 1825 | |
| 1826 | #Example |
| 1827 | SkCanvas::SaveLayerRec rec1; |
Mike Klein | e083f7c | 2018-02-07 12:54:27 -0500 | [diff] [blame] | 1828 | rec1.fSaveLayerFlags = SkCanvas::kPreserveLCDText_SaveLayerFlag; |
| 1829 | SkCanvas::SaveLayerRec rec2(nullptr, nullptr, SkCanvas::kPreserveLCDText_SaveLayerFlag); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1830 | SkDebugf("rec1 %c= rec2\n", rec1.fBounds == rec2.fBounds |
| 1831 | && rec1.fPaint == rec2.fPaint |
| 1832 | && rec1.fBackdrop == rec2.fBackdrop |
| 1833 | && rec1.fSaveLayerFlags == rec2.fSaveLayerFlags ? '=' : '!'); |
| 1834 | #StdOut |
| 1835 | rec1 == rec2 |
| 1836 | ## |
| 1837 | ## |
| 1838 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1839 | #SeeAlso save() restore() saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha |
| 1840 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1841 | ## |
| 1842 | |
Cary Clark | d98f78c | 2018-04-26 08:32:37 -0400 | [diff] [blame^] | 1843 | #Method SaveLayerRec(const SkRect* bounds, const SkPaint* paint, |
| 1844 | SaveLayerFlags saveLayerFlags = 0) |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1845 | |
| 1846 | Sets fBounds, fPaint, and fSaveLayerFlags; sets fBackdrop to nullptr. |
| 1847 | |
| 1848 | #Param bounds Layer dimensions; may be nullptr ## |
| 1849 | #Param paint applied to Layer when overlaying prior Layer; may be nullptr ## |
| 1850 | #Param saveLayerFlags SaveLayerRec options to modify Layer ## |
| 1851 | |
| 1852 | #Return SaveLayerRec with empty backdrop ## |
| 1853 | |
| 1854 | #Example |
| 1855 | SkCanvas::SaveLayerRec rec1; |
| 1856 | SkCanvas::SaveLayerRec rec2(nullptr, nullptr); |
| 1857 | SkDebugf("rec1 %c= rec2\n", rec1.fBounds == rec2.fBounds |
| 1858 | && rec1.fPaint == rec2.fPaint |
| 1859 | && rec1.fBackdrop == rec2.fBackdrop |
| 1860 | && rec1.fSaveLayerFlags == rec2.fSaveLayerFlags ? '=' : '!'); |
| 1861 | #StdOut |
| 1862 | rec1 == rec2 |
| 1863 | ## |
| 1864 | ## |
| 1865 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1866 | #SeeAlso save() restore() saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha |
| 1867 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1868 | ## |
| 1869 | |
| 1870 | #Method SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop, |
| 1871 | SaveLayerFlags saveLayerFlags) |
| 1872 | |
| 1873 | Sets fBounds, fPaint, fBackdrop, and fSaveLayerFlags. |
| 1874 | |
| 1875 | #Param bounds Layer dimensions; may be nullptr ## |
| 1876 | #Param paint applied to Layer when overlaying prior Layer; |
| 1877 | may be nullptr |
| 1878 | ## |
| 1879 | #Param backdrop prior Layer copied with Image_Filter; may be nullptr |
| 1880 | ## |
| 1881 | #Param saveLayerFlags SaveLayerRec options to modify Layer ## |
| 1882 | |
| 1883 | #Return SaveLayerRec fully specified ## |
| 1884 | |
| 1885 | #Example |
| 1886 | SkCanvas::SaveLayerRec rec1; |
| 1887 | SkCanvas::SaveLayerRec rec2(nullptr, nullptr, nullptr, 0); |
| 1888 | SkDebugf("rec1 %c= rec2\n", rec1.fBounds == rec2.fBounds |
| 1889 | && rec1.fPaint == rec2.fPaint |
| 1890 | && rec1.fBackdrop == rec2.fBackdrop |
| 1891 | && rec1.fSaveLayerFlags == rec2.fSaveLayerFlags ? '=' : '!'); |
| 1892 | #StdOut |
| 1893 | rec1 == rec2 |
| 1894 | ## |
| 1895 | ## |
| 1896 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1897 | #SeeAlso save() restore() saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha |
| 1898 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1899 | ## |
| 1900 | |
| 1901 | #Method SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop, |
| 1902 | const SkImage* clipMask, const SkMatrix* clipMatrix, |
| 1903 | SaveLayerFlags saveLayerFlags) |
| 1904 | |
| 1905 | #Experimental |
| 1906 | Not ready for general use. |
| 1907 | ## |
| 1908 | |
| 1909 | Sets fBounds, fPaint, fBackdrop, fClipMask, fClipMatrix, and fSaveLayerFlags. |
| 1910 | clipMatrix uses Color_Alpha channel of image, transformed by clipMatrix, to clip |
| 1911 | Layer when drawn to Canvas. |
| 1912 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1913 | Implementation is not complete; has no effect if Device is GPU-backed. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1914 | |
| 1915 | #Param bounds Layer dimensions; may be nullptr ## |
| 1916 | #Param paint graphics state applied to Layer when overlaying prior |
| 1917 | Layer; may be nullptr |
| 1918 | ## |
| 1919 | #Param backdrop prior Layer copied with Image_Filter; |
| 1920 | may be nullptr |
| 1921 | ## |
| 1922 | #Param clipMask clip applied to Layer; may be nullptr ## |
| 1923 | #Param clipMatrix matrix applied to clipMask; may be nullptr to use |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 1924 | identity matrix |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1925 | ## |
| 1926 | #Param saveLayerFlags SaveLayerRec options to modify Layer ## |
| 1927 | |
| 1928 | #Return SaveLayerRec fully specified ## |
| 1929 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1930 | #SeeAlso save() restore() saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1931 | |
| 1932 | ## |
| 1933 | |
| 1934 | #Struct ## |
| 1935 | |
| 1936 | #Method int saveLayer(const SaveLayerRec& layerRec) |
| 1937 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1938 | #In Layer |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1939 | Saves Matrix, Clip, and Draw_Filter (Draw_Filter deprecated on most platforms), |
| 1940 | and allocates Bitmap for subsequent drawing. |
| 1941 | |
| 1942 | Calling restore() discards changes to Matrix, Clip, and Draw_Filter, |
| 1943 | and blends Bitmap with Color_Alpha opacity onto the prior Layer. |
| 1944 | |
| 1945 | Matrix may be changed by translate(), scale(), rotate(), skew(), concat(), |
| 1946 | setMatrix, and resetMatrix. Clip may be changed by clipRect, clipRRect, |
| 1947 | clipPath, clipRegion. |
| 1948 | |
| 1949 | SaveLayerRec contains the state used to create the Layer. |
| 1950 | |
| 1951 | Call restoreToCount with returned value to restore this and subsequent saves. |
| 1952 | |
| 1953 | #Param layerRec Layer state ## |
| 1954 | |
| 1955 | #Return depth of save state stack ## |
| 1956 | |
| 1957 | #Example |
| 1958 | #Description |
| 1959 | The example draws an image, and saves it into a Layer with kInitWithPrevious_SaveLayerFlag. |
| 1960 | Next it punches a hole in Layer and restore with SkBlendMode::kPlus. |
| 1961 | Where Layer was cleared, the original image will draw unchanged. |
| 1962 | Outside of the circle the mandrill is brightened. |
| 1963 | ## |
| 1964 | #Image 3 |
Hal Canary | c465d13 | 2017-12-08 10:21:31 -0500 | [diff] [blame] | 1965 | // sk_sp<SkImage> image = GetResourceAsImage("images/mandrill_256.png"); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1966 | canvas->drawImage(image, 0, 0, nullptr); |
| 1967 | SkCanvas::SaveLayerRec rec; |
| 1968 | SkPaint paint; |
| 1969 | paint.setBlendMode(SkBlendMode::kPlus); |
| 1970 | rec.fSaveLayerFlags = SkCanvas::kInitWithPrevious_SaveLayerFlag; |
| 1971 | rec.fPaint = &paint; |
| 1972 | canvas->saveLayer(rec); |
| 1973 | paint.setBlendMode(SkBlendMode::kClear); |
| 1974 | canvas->drawCircle(128, 128, 96, paint); |
| 1975 | canvas->restore(); |
| 1976 | ## |
| 1977 | |
| 1978 | #ToDo above example needs to replace GetResourceAsImage with way to select image in fiddle ## |
| 1979 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1980 | #SeeAlso save() restore() saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha |
| 1981 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1982 | ## |
| 1983 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1984 | #Subtopic Layer ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1985 | |
| 1986 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1987 | #Subtopic Matrix |
| 1988 | #Line # coordinate transformation ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1989 | |
| 1990 | #Method void translate(SkScalar dx, SkScalar dy) |
| 1991 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1992 | #In Matrix |
| 1993 | #Line # translates Matrix ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1994 | Translate Matrix by dx along the x-axis and dy along the y-axis. |
| 1995 | |
| 1996 | Mathematically, replace Matrix with a translation matrix |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 1997 | Premultiplied with Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1998 | |
| 1999 | This has the effect of moving the drawing by (dx, dy) before transforming |
| 2000 | the result with Matrix. |
| 2001 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2002 | #Param dx distance to translate in x ## |
| 2003 | #Param dy distance to translate in y ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2004 | |
| 2005 | #Example |
| 2006 | #Height 128 |
| 2007 | #Description |
| 2008 | scale() followed by translate() produces different results from translate() followed |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 2009 | by scale(). |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2010 | |
| 2011 | The blue stroke follows translate of (50, 50); a black |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 2012 | 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] | 2013 | Matrix, a red frame follows the same scale of (2, 1/2.f); a gray fill |
| 2014 | follows translate of (50, 50). |
| 2015 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2016 | void draw(SkCanvas* canvas) { |
| 2017 | SkPaint filledPaint; |
| 2018 | SkPaint outlinePaint; |
| 2019 | outlinePaint.setStyle(SkPaint::kStroke_Style); |
| 2020 | outlinePaint.setColor(SK_ColorBLUE); |
| 2021 | canvas->save(); |
| 2022 | canvas->translate(50, 50); |
| 2023 | canvas->drawCircle(28, 28, 15, outlinePaint); // blue center: (50+28, 50+28) |
| 2024 | canvas->scale(2, 1/2.f); |
| 2025 | canvas->drawCircle(28, 28, 15, filledPaint); // black center: (50+(28*2), 50+(28/2)) |
| 2026 | canvas->restore(); |
| 2027 | filledPaint.setColor(SK_ColorGRAY); |
| 2028 | outlinePaint.setColor(SK_ColorRED); |
| 2029 | canvas->scale(2, 1/2.f); |
| 2030 | canvas->drawCircle(28, 28, 15, outlinePaint); // red center: (28*2, 28/2) |
| 2031 | canvas->translate(50, 50); |
| 2032 | 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] | 2033 | } |
| 2034 | ## |
| 2035 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2036 | #SeeAlso concat() scale() skew() rotate() setMatrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2037 | |
| 2038 | ## |
| 2039 | |
| 2040 | # ------------------------------------------------------------------------------ |
| 2041 | |
| 2042 | #Method void scale(SkScalar sx, SkScalar sy) |
| 2043 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2044 | #In Matrix |
| 2045 | #Line # scales Matrix ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2046 | Scale Matrix by sx on the x-axis and sy on the y-axis. |
| 2047 | |
| 2048 | Mathematically, replace Matrix with a scale matrix |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 2049 | Premultiplied with Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2050 | |
| 2051 | This has the effect of scaling the drawing by (sx, sy) before transforming |
| 2052 | the result with Matrix. |
| 2053 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2054 | #Param sx amount to scale in x ## |
| 2055 | #Param sy amount to scale in y ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2056 | |
| 2057 | #Example |
| 2058 | #Height 160 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2059 | void draw(SkCanvas* canvas) { |
| 2060 | SkPaint paint; |
| 2061 | SkRect rect = { 10, 20, 60, 120 }; |
| 2062 | canvas->translate(20, 20); |
| 2063 | canvas->drawRect(rect, paint); |
| 2064 | canvas->scale(2, .5f); |
| 2065 | paint.setColor(SK_ColorGRAY); |
| 2066 | canvas->drawRect(rect, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2067 | } |
| 2068 | ## |
| 2069 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2070 | #SeeAlso concat() translate() skew() rotate() setMatrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2071 | |
| 2072 | ## |
| 2073 | |
| 2074 | # ------------------------------------------------------------------------------ |
| 2075 | |
| 2076 | #Method void rotate(SkScalar degrees) |
| 2077 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2078 | #In Matrix |
| 2079 | #Line # rotates Matrix ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2080 | Rotate Matrix by degrees. Positive degrees rotates clockwise. |
| 2081 | |
| 2082 | Mathematically, replace Matrix with a rotation matrix |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 2083 | Premultiplied with Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2084 | |
| 2085 | This has the effect of rotating the drawing by degrees before transforming |
| 2086 | the result with Matrix. |
| 2087 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2088 | #Param degrees amount to rotate, in degrees ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2089 | |
| 2090 | #Example |
| 2091 | #Description |
| 2092 | Draw clock hands at time 5:10. The hour hand and minute hand point up and |
| 2093 | are rotated clockwise. |
| 2094 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2095 | void draw(SkCanvas* canvas) { |
| 2096 | SkPaint paint; |
| 2097 | paint.setStyle(SkPaint::kStroke_Style); |
| 2098 | canvas->translate(128, 128); |
| 2099 | canvas->drawCircle(0, 0, 60, paint); |
| 2100 | canvas->save(); |
| 2101 | canvas->rotate(10 * 360 / 60); // 10 minutes of 60 scaled to 360 degrees |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 2102 | canvas->drawLine(0, 0, 0, -50, paint); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2103 | canvas->restore(); |
| 2104 | canvas->rotate((5 + 10.f/60) * 360 / 12); // 5 and 10/60 hours of 12 scaled to 360 degrees |
| 2105 | canvas->drawLine(0, 0, 0, -30, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2106 | } |
| 2107 | ## |
| 2108 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2109 | #SeeAlso concat() translate() skew() scale() setMatrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2110 | |
| 2111 | ## |
| 2112 | |
| 2113 | # ------------------------------------------------------------------------------ |
| 2114 | |
| 2115 | #Method void rotate(SkScalar degrees, SkScalar px, SkScalar py) |
| 2116 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2117 | #In Matrix |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2118 | Rotate Matrix by degrees about a point at (px, py). Positive degrees rotates |
| 2119 | clockwise. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2120 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2121 | Mathematically, construct a rotation matrix. Premultiply the rotation matrix by |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2122 | a translation matrix, then replace Matrix with the resulting matrix |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 2123 | Premultiplied with Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2124 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2125 | This has the effect of rotating the drawing about a given point before |
| 2126 | transforming the result with Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2127 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2128 | #Param degrees amount to rotate, in degrees ## |
| 2129 | #Param px x-coordinate of the point to rotate about ## |
| 2130 | #Param py y-coordinate of the point to rotate about ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2131 | |
| 2132 | #Example |
| 2133 | #Height 192 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2134 | void draw(SkCanvas* canvas) { |
| 2135 | SkPaint paint; |
| 2136 | paint.setTextSize(96); |
| 2137 | canvas->drawString("A1", 130, 100, paint); |
| 2138 | canvas->rotate(180, 130, 100); |
| 2139 | canvas->drawString("A1", 130, 100, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2140 | } |
| 2141 | ## |
| 2142 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2143 | #SeeAlso concat() translate() skew() scale() setMatrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2144 | |
| 2145 | ## |
| 2146 | |
| 2147 | # ------------------------------------------------------------------------------ |
| 2148 | |
| 2149 | #Method void skew(SkScalar sx, SkScalar sy) |
| 2150 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2151 | #In Matrix |
| 2152 | #Line # skews Matrix ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2153 | Skew Matrix by sx on the x-axis and sy on the y-axis. A positive value of sx |
| 2154 | skews the drawing right as y increases; a positive value of sy skews the drawing |
| 2155 | down as x increases. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2156 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 2157 | Mathematically, replace Matrix with a skew matrix Premultiplied with Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2158 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2159 | 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] | 2160 | the result with Matrix. |
| 2161 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2162 | #Param sx amount to skew in x ## |
| 2163 | #Param sy amount to skew in y ## |
| 2164 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2165 | #Example |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 2166 | #Description |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2167 | Black text mimics an oblique text style by using a negative skew in x that |
| 2168 | shifts the geometry to the right as the y values decrease. |
| 2169 | Red text uses a positive skew in y to shift the geometry down as the x values |
| 2170 | increase. |
| 2171 | Blue text combines x and y skew to rotate and scale. |
| 2172 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2173 | SkPaint paint; |
| 2174 | paint.setTextSize(128); |
| 2175 | canvas->translate(30, 130); |
| 2176 | canvas->save(); |
| 2177 | canvas->skew(-.5, 0); |
| 2178 | canvas->drawString("A1", 0, 0, paint); |
| 2179 | canvas->restore(); |
| 2180 | canvas->save(); |
| 2181 | canvas->skew(0, .5); |
| 2182 | paint.setColor(SK_ColorRED); |
| 2183 | canvas->drawString("A1", 0, 0, paint); |
| 2184 | canvas->restore(); |
| 2185 | canvas->skew(-.5, .5); |
| 2186 | paint.setColor(SK_ColorBLUE); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2187 | canvas->drawString("A1", 0, 0, paint); |
| 2188 | ## |
| 2189 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2190 | #SeeAlso concat() translate() rotate() scale() setMatrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2191 | |
| 2192 | ## |
| 2193 | |
| 2194 | # ------------------------------------------------------------------------------ |
| 2195 | |
| 2196 | #Method void concat(const SkMatrix& matrix) |
| 2197 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2198 | #In Matrix |
| 2199 | #Line # multiplies Matrix by Matrix ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2200 | Replace Matrix with matrix Premultiplied with existing Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2201 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2202 | This has the effect of transforming the drawn geometry by matrix, before |
| 2203 | transforming the result with existing Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2204 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2205 | #Param matrix matrix to Premultiply with existing Matrix ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2206 | |
| 2207 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2208 | void draw(SkCanvas* canvas) { |
| 2209 | SkPaint paint; |
| 2210 | paint.setTextSize(80); |
| 2211 | paint.setTextScaleX(.3); |
| 2212 | SkMatrix matrix; |
| 2213 | SkRect rect[2] = {{ 10, 20, 90, 110 }, { 40, 130, 140, 180 }}; |
| 2214 | matrix.setRectToRect(rect[0], rect[1], SkMatrix::kFill_ScaleToFit); |
| 2215 | canvas->drawRect(rect[0], paint); |
| 2216 | canvas->drawRect(rect[1], paint); |
| 2217 | paint.setColor(SK_ColorWHITE); |
| 2218 | canvas->drawString("Here", rect[0].fLeft + 10, rect[0].fBottom - 10, paint); |
| 2219 | canvas->concat(matrix); |
| 2220 | canvas->drawString("There", rect[0].fLeft + 10, rect[0].fBottom - 10, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2221 | } |
| 2222 | ## |
| 2223 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2224 | #SeeAlso translate() rotate() scale() skew() setMatrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2225 | |
| 2226 | ## |
| 2227 | |
| 2228 | # ------------------------------------------------------------------------------ |
| 2229 | |
| 2230 | #Method void setMatrix(const SkMatrix& matrix) |
| 2231 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2232 | #In Matrix |
| 2233 | #Line # sets Matrix ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2234 | Replace Matrix with matrix. |
| 2235 | Unlike concat(), any prior matrix state is overwritten. |
| 2236 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2237 | #Param matrix matrix to copy, replacing existing Matrix ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2238 | |
| 2239 | #Example |
| 2240 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2241 | void draw(SkCanvas* canvas) { |
| 2242 | SkPaint paint; |
| 2243 | canvas->scale(4, 6); |
| 2244 | canvas->drawString("truth", 2, 10, paint); |
| 2245 | SkMatrix matrix; |
| 2246 | matrix.setScale(2.8f, 6); |
| 2247 | canvas->setMatrix(matrix); |
| 2248 | canvas->drawString("consequences", 2, 20, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2249 | } |
| 2250 | ## |
| 2251 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2252 | #SeeAlso resetMatrix concat() translate() rotate() scale() skew() |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2253 | |
| 2254 | ## |
| 2255 | |
| 2256 | # ------------------------------------------------------------------------------ |
| 2257 | |
| 2258 | #Method void resetMatrix() |
| 2259 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2260 | #In Matrix |
| 2261 | #Line # resets Matrix to identity ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2262 | Sets Matrix to the identity matrix. |
| 2263 | Any prior matrix state is overwritten. |
| 2264 | |
| 2265 | #Example |
| 2266 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2267 | void draw(SkCanvas* canvas) { |
| 2268 | SkPaint paint; |
| 2269 | canvas->scale(4, 6); |
| 2270 | canvas->drawString("truth", 2, 10, paint); |
| 2271 | canvas->resetMatrix(); |
| 2272 | canvas->scale(2.8f, 6); |
| 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 setMatrix concat() translate() rotate() scale() skew() |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2278 | |
| 2279 | ## |
| 2280 | |
| 2281 | # ------------------------------------------------------------------------------ |
| 2282 | |
| 2283 | #Method const SkMatrix& getTotalMatrix() const |
| 2284 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2285 | #In Matrix |
| 2286 | #Line # returns Matrix ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2287 | Returns Matrix. |
| 2288 | This does not account for translation by Device or Surface. |
| 2289 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2290 | #Return Matrix in Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2291 | |
| 2292 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2293 | SkDebugf("isIdentity %s\n", canvas->getTotalMatrix().isIdentity() ? "true" : "false"); |
| 2294 | #StdOut |
| 2295 | isIdentity true |
| 2296 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2297 | ## |
| 2298 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2299 | #SeeAlso setMatrix resetMatrix concat() |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2300 | |
| 2301 | ## |
| 2302 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2303 | #Subtopic Matrix ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2304 | |
| 2305 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2306 | #Subtopic Clip |
| 2307 | #Line # stack of clipping Paths ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2308 | |
| 2309 | Clip is built from a stack of clipping paths. Each Path in the |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 2310 | stack can be constructed from one or more Path_Contour elements. The |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2311 | Path_Contour may be composed of any number of Path_Verb segments. Each |
| 2312 | Path_Contour forms a closed area; Path_Fill_Type defines the area enclosed |
| 2313 | by Path_Contour. |
| 2314 | |
| 2315 | Clip stack of Path elements successfully restrict the Path area. Each |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 2316 | Path is transformed by Matrix, then intersected with or subtracted from the |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2317 | prior Clip to form the replacement Clip. Use SkClipOp::kDifference |
| 2318 | to subtract Path from Clip; use SkClipOp::kIntersect to intersect Path |
| 2319 | with Clip. |
| 2320 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2321 | A clipping Path may be Anti-aliased; if Path, after transformation, is |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2322 | composed of horizontal and vertical lines, clearing Anti-alias allows whole pixels |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2323 | to either be inside or outside the clip. The fastest drawing has a Aliased, |
| 2324 | rectangular clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2325 | |
| 2326 | If clipping Path has Anti-alias set, clip may partially clip a pixel, requiring |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 2327 | that drawing blend partially with the destination along the edge. A rotated |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2328 | rectangular Anti-aliased clip looks smoother but draws slower. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2329 | |
| 2330 | Clip can combine with Rect and Round_Rect primitives; like |
| 2331 | Path, these are transformed by Matrix before they are combined with Clip. |
| 2332 | |
| 2333 | Clip can combine with Region. Region is assumed to be in Device coordinates |
| 2334 | and is unaffected by Matrix. |
| 2335 | |
| 2336 | #Example |
| 2337 | #Height 90 |
| 2338 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2339 | 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] | 2340 | Use an image filter to zoom into the pixels drawn. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2341 | The edge of the Aliased clip fully draws pixels in the red circle. |
| 2342 | 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] | 2343 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2344 | SkPaint redPaint, scalePaint; |
| 2345 | redPaint.setAntiAlias(true); |
| 2346 | redPaint.setColor(SK_ColorRED); |
| 2347 | canvas->save(); |
| 2348 | for (bool antialias : { false, true } ) { |
| 2349 | canvas->save(); |
| 2350 | canvas->clipRect(SkRect::MakeWH(19.5f, 11.5f), antialias); |
| 2351 | canvas->drawCircle(17, 11, 8, redPaint); |
| 2352 | canvas->restore(); |
| 2353 | canvas->translate(16, 0); |
| 2354 | } |
| 2355 | canvas->restore(); |
| 2356 | SkMatrix matrix; |
| 2357 | matrix.setScale(6, 6); |
| 2358 | scalePaint.setImageFilter( |
| 2359 | SkImageFilter::MakeMatrixFilter(matrix, kNone_SkFilterQuality, nullptr)); |
| 2360 | SkCanvas::SaveLayerRec saveLayerRec( |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 2361 | nullptr, &scalePaint, SkCanvas::kInitWithPrevious_SaveLayerFlag); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2362 | canvas->saveLayer(saveLayerRec); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2363 | canvas->restore(); |
| 2364 | ## |
| 2365 | |
| 2366 | #Method void clipRect(const SkRect& rect, SkClipOp op, bool doAntiAlias) |
| 2367 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2368 | #In Clip |
| 2369 | #Line # combines Clip with Rect ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2370 | Replace Clip with the intersection or difference of Clip and rect, |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2371 | 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] | 2372 | before it is combined with Clip. |
| 2373 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 2374 | #Param rect Rect to combine with Clip ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2375 | #Param op Clip_Op to apply to Clip ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2376 | #Param doAntiAlias true if Clip is to be Anti-aliased ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2377 | |
| 2378 | #Example |
| 2379 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2380 | void draw(SkCanvas* canvas) { |
| 2381 | canvas->rotate(10); |
| 2382 | SkPaint paint; |
| 2383 | paint.setAntiAlias(true); |
| 2384 | for (auto alias: { false, true } ) { |
| 2385 | canvas->save(); |
| 2386 | canvas->clipRect(SkRect::MakeWH(90, 80), SkClipOp::kIntersect, alias); |
| 2387 | canvas->drawCircle(100, 60, 60, paint); |
| 2388 | canvas->restore(); |
| 2389 | canvas->translate(80, 0); |
| 2390 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2391 | } |
| 2392 | ## |
| 2393 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2394 | #SeeAlso clipRRect clipPath clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2395 | |
| 2396 | ## |
| 2397 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 2398 | #Method void clipRect(const SkRect& rect, SkClipOp op) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2399 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2400 | #In Clip |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2401 | Replace Clip with the intersection or difference of Clip and rect. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2402 | Resulting Clip is Aliased; pixels are fully contained by the clip. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2403 | rect is transformed by Matrix before it is combined with Clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2404 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 2405 | #Param rect Rect to combine with Clip ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2406 | #Param op Clip_Op to apply to Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2407 | |
| 2408 | #Example |
| 2409 | #Height 192 |
| 2410 | #Width 280 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2411 | void draw(SkCanvas* canvas) { |
| 2412 | SkPaint paint; |
| 2413 | for (SkClipOp op: { SkClipOp::kIntersect, SkClipOp::kDifference } ) { |
| 2414 | canvas->save(); |
| 2415 | canvas->clipRect(SkRect::MakeWH(90, 120), op, false); |
| 2416 | canvas->drawCircle(100, 100, 60, paint); |
| 2417 | canvas->restore(); |
| 2418 | canvas->translate(80, 0); |
| 2419 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2420 | } |
| 2421 | ## |
| 2422 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2423 | #SeeAlso clipRRect clipPath clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2424 | |
| 2425 | ## |
| 2426 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 2427 | #Method void clipRect(const SkRect& rect, bool doAntiAlias = false) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2428 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2429 | #In Clip |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2430 | Replace Clip with the intersection of Clip and rect. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2431 | Resulting Clip is Aliased; pixels are fully contained by the clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2432 | rect is transformed by Matrix |
| 2433 | before it is combined with Clip. |
| 2434 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 2435 | #Param rect Rect to combine with Clip ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2436 | #Param doAntiAlias true if Clip is to be Anti-aliased ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2437 | |
| 2438 | #Example |
| 2439 | #Height 133 |
| 2440 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2441 | A circle drawn in pieces looks uniform when drawn Aliased. |
| 2442 | 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] | 2443 | visible as a thin pair of lines through the right circle. |
| 2444 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2445 | void draw(SkCanvas* canvas) { |
| 2446 | canvas->clear(SK_ColorWHITE); |
| 2447 | SkPaint paint; |
| 2448 | paint.setAntiAlias(true); |
| 2449 | paint.setColor(0x8055aaff); |
| 2450 | SkRect clipRect = { 0, 0, 87.4f, 87.4f }; |
| 2451 | for (auto alias: { false, true } ) { |
| 2452 | canvas->save(); |
| 2453 | canvas->clipRect(clipRect, SkClipOp::kIntersect, alias); |
| 2454 | canvas->drawCircle(67, 67, 60, paint); |
| 2455 | canvas->restore(); |
| 2456 | canvas->save(); |
| 2457 | canvas->clipRect(clipRect, SkClipOp::kDifference, alias); |
| 2458 | canvas->drawCircle(67, 67, 60, paint); |
| 2459 | canvas->restore(); |
| 2460 | canvas->translate(120, 0); |
| 2461 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2462 | } |
| 2463 | ## |
| 2464 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2465 | #SeeAlso clipRRect clipPath clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2466 | |
| 2467 | ## |
| 2468 | |
| 2469 | #Method void androidFramework_setDeviceClipRestriction(const SkIRect& rect) |
| 2470 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2471 | #In Clip |
| 2472 | #Line # for use by Android framework ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2473 | 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] | 2474 | clipPath and intersect the current clip with the specified rect. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2475 | The maximum clip affects only future clipping operations; it is not retroactive. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2476 | The clip restriction is not recorded in pictures. |
| 2477 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 2478 | Pass an empty rect to disable maximum clip. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2479 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2480 | #Private |
| 2481 | This is private API to be used only by Android framework. |
| 2482 | ## |
| 2483 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2484 | #Param rect maximum allowed clip in device coordinates |
Cary Clark | 579985c | 2017-07-31 11:48:27 -0400 | [diff] [blame] | 2485 | #Param ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2486 | |
| 2487 | ## |
| 2488 | |
| 2489 | #Method void clipRRect(const SkRRect& rrect, SkClipOp op, bool doAntiAlias) |
| 2490 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2491 | #In Clip |
| 2492 | #Line # combines Clip with Round_Rect ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2493 | Replace Clip with the intersection or difference of Clip and rrect, |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2494 | with an Aliased or Anti-aliased clip edge. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2495 | rrect is transformed by Matrix |
| 2496 | before it is combined with Clip. |
| 2497 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2498 | #Param rrect Round_Rect to combine with Clip ## |
| 2499 | #Param op Clip_Op to apply to Clip ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2500 | #Param doAntiAlias true if Clip is to be Anti-aliased ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2501 | |
| 2502 | #Example |
| 2503 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2504 | void draw(SkCanvas* canvas) { |
| 2505 | canvas->clear(SK_ColorWHITE); |
| 2506 | SkPaint paint; |
| 2507 | paint.setAntiAlias(true); |
| 2508 | paint.setColor(0x8055aaff); |
| 2509 | SkRRect oval; |
| 2510 | oval.setOval({10, 20, 90, 100}); |
| 2511 | canvas->clipRRect(oval, SkClipOp::kIntersect, true); |
| 2512 | canvas->drawCircle(70, 100, 60, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2513 | } |
| 2514 | ## |
| 2515 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2516 | #SeeAlso clipRect clipPath clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2517 | |
| 2518 | ## |
| 2519 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 2520 | #Method void clipRRect(const SkRRect& rrect, SkClipOp op) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2521 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2522 | #In Clip |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2523 | Replace Clip with the intersection or difference of Clip and rrect. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2524 | Resulting Clip is Aliased; pixels are fully contained by the clip. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2525 | rrect is transformed by Matrix before it is combined with Clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2526 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2527 | #Param rrect Round_Rect to combine with Clip ## |
| 2528 | #Param op Clip_Op to apply to Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2529 | |
| 2530 | #Example |
| 2531 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2532 | void draw(SkCanvas* canvas) { |
| 2533 | SkPaint paint; |
| 2534 | paint.setColor(0x8055aaff); |
| 2535 | auto oval = SkRRect::MakeOval({10, 20, 90, 100}); |
| 2536 | canvas->clipRRect(oval, SkClipOp::kIntersect); |
| 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 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 2545 | #Method void clipRRect(const SkRRect& rrect, bool doAntiAlias = false) |
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 of Clip and rrect, |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2549 | with an Aliased or Anti-aliased clip edge. |
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 ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2553 | #Param doAntiAlias true if Clip is to be Anti-aliased ## |
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.setAntiAlias(true); |
| 2560 | auto oval = SkRRect::MakeRectXY({10, 20, 90, 100}, 9, 13); |
| 2561 | canvas->clipRRect(oval, true); |
| 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 | |
| 2570 | #Method void clipPath(const SkPath& path, SkClipOp op, bool doAntiAlias) |
| 2571 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2572 | #In Clip |
| 2573 | #Line # combines Clip with Path ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2574 | Replace Clip with the intersection or difference of Clip and path, |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2575 | 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] | 2576 | describes the area inside or outside its contours; and if Path_Contour overlaps |
| 2577 | 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] | 2578 | path is transformed by Matrix before it is combined with Clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2579 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2580 | #Param path Path to combine with Clip ## |
| 2581 | #Param op Clip_Op to apply to Clip ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2582 | #Param doAntiAlias true if Clip is to be Anti-aliased ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2583 | |
| 2584 | #Example |
| 2585 | #Description |
| 2586 | Top figure uses SkPath::kInverseWinding_FillType and SkClipOp::kDifference; |
| 2587 | area outside clip is subtracted from circle. |
| 2588 | |
| 2589 | Bottom figure uses SkPath::kWinding_FillType and SkClipOp::kIntersect; |
| 2590 | area inside clip is intersected with circle. |
| 2591 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2592 | void draw(SkCanvas* canvas) { |
| 2593 | SkPaint paint; |
| 2594 | paint.setAntiAlias(true); |
| 2595 | SkPath path; |
| 2596 | path.addRect({20, 30, 100, 110}); |
| 2597 | path.setFillType(SkPath::kInverseWinding_FillType); |
| 2598 | canvas->save(); |
| 2599 | canvas->clipPath(path, SkClipOp::kDifference, false); |
| 2600 | canvas->drawCircle(70, 100, 60, paint); |
| 2601 | canvas->restore(); |
| 2602 | canvas->translate(100, 100); |
| 2603 | path.setFillType(SkPath::kWinding_FillType); |
| 2604 | canvas->clipPath(path, SkClipOp::kIntersect, false); |
| 2605 | canvas->drawCircle(70, 100, 60, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2606 | } |
| 2607 | ## |
| 2608 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2609 | #SeeAlso clipRect clipRRect clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2610 | |
| 2611 | ## |
| 2612 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 2613 | #Method void clipPath(const SkPath& path, SkClipOp op) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2614 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2615 | #In Clip |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2616 | Replace Clip with the intersection or difference of Clip and path. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2617 | Resulting Clip is Aliased; pixels are fully contained by the clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2618 | Path_Fill_Type determines if path |
| 2619 | describes the area inside or outside its contours; and if Path_Contour overlaps |
| 2620 | itself or another Path_Contour, whether the overlaps form part of the area. |
| 2621 | path is transformed by Matrix |
| 2622 | before it is combined with Clip. |
| 2623 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2624 | #Param path Path to combine with Clip ## |
| 2625 | #Param op Clip_Op to apply to Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2626 | |
| 2627 | #Example |
| 2628 | #Description |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2629 | Overlapping Rects form a clip. When clip Path_Fill_Type is set to |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 2630 | SkPath::kWinding_FillType, the overlap is included. Set to |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2631 | SkPath::kEvenOdd_FillType, the overlap is excluded and forms a hole. |
| 2632 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2633 | void draw(SkCanvas* canvas) { |
| 2634 | SkPaint paint; |
| 2635 | paint.setAntiAlias(true); |
| 2636 | SkPath path; |
| 2637 | path.addRect({20, 15, 100, 95}); |
| 2638 | path.addRect({50, 65, 130, 135}); |
| 2639 | path.setFillType(SkPath::kWinding_FillType); |
| 2640 | canvas->save(); |
| 2641 | canvas->clipPath(path, SkClipOp::kIntersect); |
| 2642 | canvas->drawCircle(70, 85, 60, paint); |
| 2643 | canvas->restore(); |
| 2644 | canvas->translate(100, 100); |
| 2645 | path.setFillType(SkPath::kEvenOdd_FillType); |
| 2646 | canvas->clipPath(path, SkClipOp::kIntersect); |
| 2647 | canvas->drawCircle(70, 85, 60, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2648 | } |
| 2649 | ## |
| 2650 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2651 | #SeeAlso clipRect clipRRect clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2652 | |
| 2653 | ## |
| 2654 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 2655 | #Method void clipPath(const SkPath& path, bool doAntiAlias = false) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2656 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2657 | #In Clip |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2658 | Replace Clip with the intersection of Clip and path. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2659 | Resulting Clip is Aliased; pixels are fully contained by the clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2660 | Path_Fill_Type determines if path |
| 2661 | describes the area inside or outside its contours; and if Path_Contour overlaps |
| 2662 | 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] | 2663 | path is transformed by Matrix before it is combined with Clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2664 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2665 | #Param path Path to combine with Clip ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2666 | #Param doAntiAlias true if Clip is to be Anti-aliased ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2667 | |
| 2668 | #Example |
| 2669 | #Height 212 |
| 2670 | #Description |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 2671 | Clip loops over itself covering its center twice. When clip Path_Fill_Type |
| 2672 | is set to SkPath::kWinding_FillType, the overlap is included. Set to |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2673 | SkPath::kEvenOdd_FillType, the overlap is excluded and forms a hole. |
| 2674 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2675 | void draw(SkCanvas* canvas) { |
| 2676 | SkPaint paint; |
| 2677 | paint.setAntiAlias(true); |
| 2678 | SkPath path; |
| 2679 | SkPoint poly[] = {{20, 20}, { 80, 20}, { 80, 80}, {40, 80}, |
| 2680 | {40, 40}, {100, 40}, {100, 100}, {20, 100}}; |
| 2681 | path.addPoly(poly, SK_ARRAY_COUNT(poly), true); |
| 2682 | path.setFillType(SkPath::kWinding_FillType); |
| 2683 | canvas->save(); |
| 2684 | canvas->clipPath(path, SkClipOp::kIntersect); |
| 2685 | canvas->drawCircle(50, 50, 45, paint); |
| 2686 | canvas->restore(); |
| 2687 | canvas->translate(100, 100); |
| 2688 | path.setFillType(SkPath::kEvenOdd_FillType); |
| 2689 | canvas->clipPath(path, SkClipOp::kIntersect); |
| 2690 | canvas->drawCircle(50, 50, 45, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2691 | } |
| 2692 | ## |
| 2693 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2694 | #SeeAlso clipRect clipRRect clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2695 | |
| 2696 | ## |
| 2697 | |
| 2698 | # ------------------------------------------------------------------------------ |
| 2699 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 2700 | #Method void setAllowSimplifyClip(bool allow) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2701 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2702 | #In Clip |
| 2703 | #Line # experimental ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2704 | #Experimental |
| 2705 | Only used for testing. |
| 2706 | ## |
| 2707 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2708 | Set to simplify clip stack using PathOps. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2709 | |
| 2710 | ## |
| 2711 | |
| 2712 | # ------------------------------------------------------------------------------ |
| 2713 | |
| 2714 | #Method void clipRegion(const SkRegion& deviceRgn, SkClipOp op = SkClipOp::kIntersect) |
| 2715 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2716 | #In Clip |
| 2717 | #Line # combines Clip with Region ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2718 | Replace Clip with the intersection or difference of Clip and Region deviceRgn. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2719 | Resulting Clip is Aliased; pixels are fully contained by the clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2720 | deviceRgn is unaffected by Matrix. |
| 2721 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2722 | #Param deviceRgn Region to combine with Clip ## |
| 2723 | #Param op Clip_Op to apply to Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2724 | |
| 2725 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2726 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2727 | region is unaffected by canvas rotation; iRect is affected by canvas rotation. |
| 2728 | 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] | 2729 | aligns to pixel boundaries. |
| 2730 | ## |
| 2731 | void draw(SkCanvas* canvas) { |
| 2732 | SkPaint paint; |
| 2733 | paint.setAntiAlias(true); |
| 2734 | SkIRect iRect = {30, 40, 120, 130 }; |
| 2735 | SkRegion region(iRect); |
| 2736 | canvas->rotate(10); |
| 2737 | canvas->save(); |
| 2738 | canvas->clipRegion(region, SkClipOp::kIntersect); |
| 2739 | canvas->drawCircle(50, 50, 45, paint); |
| 2740 | canvas->restore(); |
| 2741 | canvas->translate(100, 100); |
| 2742 | canvas->clipRect(SkRect::Make(iRect), SkClipOp::kIntersect); |
| 2743 | canvas->drawCircle(50, 50, 45, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2744 | } |
| 2745 | ## |
| 2746 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2747 | #SeeAlso clipRect clipRRect clipPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2748 | |
| 2749 | ## |
| 2750 | |
| 2751 | #Method bool quickReject(const SkRect& rect) const |
| 2752 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2753 | #In Clip |
| 2754 | #Line # returns if Rect is outside Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2755 | Return true if Rect rect, transformed by Matrix, can be quickly determined to be |
| 2756 | outside of Clip. May return false even though rect is outside of Clip. |
| 2757 | |
| 2758 | Use to check if an area to be drawn is clipped out, to skip subsequent draw calls. |
| 2759 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2760 | #Param rect Rect to compare with Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2761 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2762 | #Return true if rect, transformed by Matrix, does not intersect Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2763 | |
| 2764 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2765 | void draw(SkCanvas* canvas) { |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 2766 | SkRect testRect = {30, 30, 120, 129 }; |
| 2767 | SkRect clipRect = {30, 130, 120, 230 }; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2768 | canvas->save(); |
| 2769 | canvas->clipRect(clipRect); |
| 2770 | SkDebugf("quickReject %s\n", canvas->quickReject(testRect) ? "true" : "false"); |
| 2771 | canvas->restore(); |
| 2772 | canvas->rotate(10); |
| 2773 | canvas->clipRect(clipRect); |
| 2774 | SkDebugf("quickReject %s\n", canvas->quickReject(testRect) ? "true" : "false"); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2775 | } |
| 2776 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2777 | quickReject true |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2778 | quickReject false |
| 2779 | ## |
| 2780 | ## |
| 2781 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2782 | #SeeAlso getLocalClipBounds getTotalMatrix SkBitmap::drawsNothing |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2783 | |
| 2784 | ## |
| 2785 | |
| 2786 | #Method bool quickReject(const SkPath& path) const |
| 2787 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2788 | #In Clip |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2789 | Return true if path, transformed by Matrix, can be quickly determined to be |
| 2790 | outside of Clip. May return false even though path is outside of Clip. |
| 2791 | |
| 2792 | Use to check if an area to be drawn is clipped out, to skip subsequent draw calls. |
| 2793 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2794 | #Param path Path to compare with Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2795 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2796 | #Return true if path, transformed by Matrix, does not intersect Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2797 | |
| 2798 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2799 | void draw(SkCanvas* canvas) { |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 2800 | SkPoint testPoints[] = {{30, 30}, {120, 30}, {120, 129} }; |
| 2801 | SkPoint clipPoints[] = {{30, 130}, {120, 130}, {120, 230} }; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2802 | SkPath testPath, clipPath; |
| 2803 | testPath.addPoly(testPoints, SK_ARRAY_COUNT(testPoints), true); |
| 2804 | clipPath.addPoly(clipPoints, SK_ARRAY_COUNT(clipPoints), true); |
| 2805 | canvas->save(); |
| 2806 | canvas->clipPath(clipPath); |
| 2807 | SkDebugf("quickReject %s\n", canvas->quickReject(testPath) ? "true" : "false"); |
| 2808 | canvas->restore(); |
| 2809 | canvas->rotate(10); |
| 2810 | canvas->clipPath(clipPath); |
| 2811 | SkDebugf("quickReject %s\n", canvas->quickReject(testPath) ? "true" : "false"); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2812 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2813 | quickReject true |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2814 | quickReject false |
| 2815 | ## |
| 2816 | } |
| 2817 | ## |
| 2818 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2819 | #SeeAlso getLocalClipBounds getTotalMatrix SkBitmap::drawsNothing |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2820 | |
| 2821 | ## |
| 2822 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 2823 | #Method SkRect getLocalClipBounds() const |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2824 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2825 | #In Clip |
| 2826 | #Line # returns Clip bounds in source coordinates ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2827 | Return bounds of Clip, transformed by inverse of Matrix. If Clip is empty, |
| 2828 | return SkRect::MakeEmpty, where all Rect sides equal zero. |
| 2829 | |
| 2830 | Rect returned is outset by one to account for partial pixel coverage if Clip |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2831 | is Anti-aliased. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2832 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2833 | #Return bounds of Clip in local coordinates ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2834 | |
| 2835 | #Example |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 2836 | #Description |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2837 | Initial bounds is device bounds outset by 1 on all sides. |
| 2838 | Clipped bounds is clipPath bounds outset by 1 on all sides. |
| 2839 | Scaling the canvas by two in x and y scales the local bounds by 1/2 in x and y. |
| 2840 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2841 | SkCanvas local(256, 256); |
| 2842 | canvas = &local; |
| 2843 | SkRect bounds = canvas->getLocalClipBounds(); |
| 2844 | SkDebugf("left:%g top:%g right:%g bottom:%g\n", |
| 2845 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 2846 | SkPoint clipPoints[] = {{30, 130}, {120, 130}, {120, 230} }; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2847 | SkPath clipPath; |
| 2848 | clipPath.addPoly(clipPoints, SK_ARRAY_COUNT(clipPoints), true); |
| 2849 | canvas->clipPath(clipPath); |
| 2850 | bounds = canvas->getLocalClipBounds(); |
| 2851 | SkDebugf("left:%g top:%g right:%g bottom:%g\n", |
| 2852 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
| 2853 | canvas->scale(2, 2); |
| 2854 | bounds = canvas->getLocalClipBounds(); |
| 2855 | SkDebugf("left:%g top:%g right:%g bottom:%g\n", |
| 2856 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
| 2857 | #StdOut |
| 2858 | left:-1 top:-1 right:257 bottom:257 |
| 2859 | left:29 top:129 right:121 bottom:231 |
| 2860 | left:14.5 top:64.5 right:60.5 bottom:115.5 |
| 2861 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2862 | ## |
| 2863 | |
| 2864 | # local canvas in example works around bug in fiddle ## |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2865 | #Bug 6524 |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2866 | #SeeAlso getDeviceClipBounds getBaseLayerSize quickReject |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2867 | |
| 2868 | ## |
| 2869 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 2870 | #Method bool getLocalClipBounds(SkRect* bounds) const |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2871 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2872 | #In Clip |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2873 | Return bounds of Clip, transformed by inverse of Matrix. If Clip is empty, |
| 2874 | return false, and set bounds to SkRect::MakeEmpty, where all Rect sides equal zero. |
| 2875 | |
| 2876 | bounds is outset by one to account for partial pixel coverage if Clip |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2877 | is Anti-aliased. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2878 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2879 | #Param bounds Rect of Clip in local coordinates ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2880 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2881 | #Return true if Clip bounds is not empty ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2882 | |
| 2883 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2884 | void draw(SkCanvas* canvas) { |
| 2885 | SkCanvas local(256, 256); |
| 2886 | canvas = &local; |
| 2887 | SkRect bounds; |
| 2888 | SkDebugf("local bounds empty = %s\n", canvas->getLocalClipBounds(&bounds) |
| 2889 | ? "false" : "true"); |
| 2890 | SkPath path; |
| 2891 | canvas->clipPath(path); |
| 2892 | SkDebugf("local bounds empty = %s\n", canvas->getLocalClipBounds(&bounds) |
| 2893 | ? "false" : "true"); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2894 | } |
| 2895 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2896 | local bounds empty = false |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2897 | local bounds empty = true |
| 2898 | ## |
| 2899 | ## |
| 2900 | |
| 2901 | # local canvas in example works around bug in fiddle ## |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2902 | #Bug 6524 |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2903 | #SeeAlso getDeviceClipBounds getBaseLayerSize quickReject |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2904 | |
| 2905 | ## |
| 2906 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 2907 | #Method SkIRect getDeviceClipBounds() const |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2908 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2909 | #In Clip |
| 2910 | #Line # returns IRect bounds of Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2911 | Return IRect bounds of Clip, unaffected by Matrix. If Clip is empty, |
| 2912 | return SkRect::MakeEmpty, where all Rect sides equal zero. |
| 2913 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 2914 | Unlike getLocalClipBounds, returned IRect is not outset. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2915 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2916 | #Return bounds of Clip in Device coordinates ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2917 | |
| 2918 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2919 | void draw(SkCanvas* canvas) { |
| 2920 | #Description |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2921 | Initial bounds is device bounds, not outset. |
| 2922 | Clipped bounds is clipPath bounds, not outset. |
| 2923 | 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] | 2924 | ## |
| 2925 | SkCanvas device(256, 256); |
| 2926 | canvas = &device; |
| 2927 | SkIRect bounds = canvas->getDeviceClipBounds(); |
| 2928 | SkDebugf("left:%d top:%d right:%d bottom:%d\n", |
| 2929 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 2930 | SkPoint clipPoints[] = {{30, 130}, {120, 130}, {120, 230} }; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2931 | SkPath clipPath; |
| 2932 | clipPath.addPoly(clipPoints, SK_ARRAY_COUNT(clipPoints), true); |
| 2933 | canvas->save(); |
| 2934 | canvas->clipPath(clipPath); |
| 2935 | bounds = canvas->getDeviceClipBounds(); |
| 2936 | SkDebugf("left:%d top:%d right:%d bottom:%d\n", |
| 2937 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
| 2938 | canvas->restore(); |
| 2939 | canvas->scale(1.f/2, 1.f/2); |
| 2940 | canvas->clipPath(clipPath); |
| 2941 | bounds = canvas->getDeviceClipBounds(); |
| 2942 | SkDebugf("left:%d top:%d right:%d bottom:%d\n", |
| 2943 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2944 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2945 | left:0 top:0 right:256 bottom:256 |
| 2946 | left:30 top:130 right:120 bottom:230 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2947 | left:15 top:65 right:60 bottom:115 |
| 2948 | ## |
| 2949 | } |
| 2950 | ## |
| 2951 | |
| 2952 | #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] | 2953 | #SeeAlso getLocalClipBounds getBaseLayerSize quickReject |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2954 | |
| 2955 | # device canvas in example works around bug in fiddle ## |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2956 | #Bug 6524 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2957 | |
| 2958 | ## |
| 2959 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 2960 | #Method bool getDeviceClipBounds(SkIRect* bounds) const |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2961 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2962 | #In Clip |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2963 | Return IRect bounds of Clip, unaffected by Matrix. If Clip is empty, |
| 2964 | return false, and set bounds to SkRect::MakeEmpty, where all Rect sides equal zero. |
| 2965 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 2966 | Unlike getLocalClipBounds, bounds is not outset. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2967 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2968 | #Param bounds Rect of Clip in device coordinates ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2969 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2970 | #Return true if Clip bounds is not empty ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2971 | |
| 2972 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2973 | void draw(SkCanvas* canvas) { |
| 2974 | SkIRect bounds; |
| 2975 | SkDebugf("device bounds empty = %s\n", canvas->getDeviceClipBounds(&bounds) |
| 2976 | ? "false" : "true"); |
| 2977 | SkPath path; |
| 2978 | canvas->clipPath(path); |
| 2979 | SkDebugf("device bounds empty = %s\n", canvas->getDeviceClipBounds(&bounds) |
| 2980 | ? "false" : "true"); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2981 | } |
| 2982 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2983 | device bounds empty = false |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2984 | device bounds empty = true |
| 2985 | ## |
| 2986 | ## |
| 2987 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2988 | #SeeAlso getLocalClipBounds getBaseLayerSize quickReject |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2989 | |
| 2990 | ## |
| 2991 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2992 | #Subtopic Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2993 | |
| 2994 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2995 | #Subtopic Draw |
| 2996 | #Populate |
| 2997 | #Line # draws into Canvas ## |
| 2998 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2999 | |
| 3000 | #Method void drawColor(SkColor color, SkBlendMode mode = SkBlendMode::kSrcOver) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3001 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3002 | #Line # fills Clip with Color and Blend_Mode ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3003 | Fill Clip with Color color. |
| 3004 | mode determines how Color_ARGB is combined with destination. |
| 3005 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3006 | #Param color Unpremultiplied Color_ARGB ## |
| 3007 | #Param mode SkBlendMode used to combine source color and destination ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3008 | |
| 3009 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3010 | canvas->drawColor(SK_ColorRED); |
| 3011 | canvas->clipRect(SkRect::MakeWH(150, 150)); |
| 3012 | canvas->drawColor(SkColorSetARGB(0x80, 0x00, 0xFF, 0x00), SkBlendMode::kPlus); |
| 3013 | canvas->clipRect(SkRect::MakeWH(75, 75)); |
| 3014 | canvas->drawColor(SkColorSetARGB(0x80, 0x00, 0x00, 0xFF), SkBlendMode::kPlus); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3015 | ## |
| 3016 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3017 | #SeeAlso clear SkBitmap::erase drawPaint |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3018 | |
| 3019 | ## |
| 3020 | |
| 3021 | # ------------------------------------------------------------------------------ |
| 3022 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 3023 | #Method void clear(SkColor color) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3024 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3025 | #Line # fills Clip with Color ## |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 3026 | Fill Clip with Color color using SkBlendMode::kSrc. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3027 | This has the effect of replacing all pixels contained by Clip with color. |
| 3028 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3029 | #Param color Unpremultiplied Color_ARGB ## |
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 | void draw(SkCanvas* canvas) { |
| 3033 | canvas->save(); |
| 3034 | canvas->clipRect(SkRect::MakeWH(256, 128)); |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 3035 | canvas->clear(SkColorSetARGB(0x80, 0xFF, 0x00, 0x00)); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3036 | canvas->restore(); |
| 3037 | canvas->save(); |
| 3038 | canvas->clipRect(SkRect::MakeWH(150, 192)); |
| 3039 | canvas->clear(SkColorSetARGB(0x80, 0x00, 0xFF, 0x00)); |
| 3040 | canvas->restore(); |
| 3041 | canvas->clipRect(SkRect::MakeWH(75, 256)); |
| 3042 | canvas->clear(SkColorSetARGB(0x80, 0x00, 0x00, 0xFF)); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3043 | } |
| 3044 | ## |
| 3045 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3046 | #SeeAlso drawColor SkBitmap::erase drawPaint |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3047 | |
| 3048 | ## |
| 3049 | |
| 3050 | # ------------------------------------------------------------------------------ |
| 3051 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 3052 | #Method void discard() |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3053 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3054 | #Line # makes Canvas contents undefined ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3055 | Make Canvas contents undefined. Subsequent calls that read Canvas pixels, |
| 3056 | such as drawing with SkBlendMode, return undefined results. discard() does |
| 3057 | not change Clip or Matrix. |
| 3058 | |
| 3059 | discard() may do nothing, depending on the implementation of Surface or Device |
| 3060 | that created Canvas. |
| 3061 | |
| 3062 | discard() allows optimized performance on subsequent draws by removing |
| 3063 | cached data associated with Surface or Device. |
| 3064 | It is not necessary to call discard() once done with Canvas; |
| 3065 | any cached data is deleted when owning Surface or Device is deleted. |
| 3066 | |
| 3067 | #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] | 3068 | #SeeAlso flush() SkSurface::prepareForExternalIO GrContext::abandonContext |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3069 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 3070 | #NoExample |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3071 | ## |
| 3072 | |
| 3073 | ## |
| 3074 | |
| 3075 | # ------------------------------------------------------------------------------ |
| 3076 | |
| 3077 | #Method void drawPaint(const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3078 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3079 | #Line # fills Clip with Paint ## |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 3080 | Fill Clip with Paint paint. Paint components Mask_Filter, Shader, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3081 | Color_Filter, Image_Filter, and Blend_Mode affect drawing; |
| 3082 | Path_Effect in paint is ignored. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3083 | |
| 3084 | # can Path_Effect in paint ever alter drawPaint? |
| 3085 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3086 | #Param paint graphics state used to fill Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3087 | |
| 3088 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3089 | void draw(SkCanvas* canvas) { |
| 3090 | SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE }; |
| 3091 | SkScalar pos[] = { 0, SK_Scalar1/2, SK_Scalar1 }; |
| 3092 | SkPaint paint; |
| 3093 | paint.setShader(SkGradientShader::MakeSweep(256, 256, colors, pos, SK_ARRAY_COUNT(colors))); |
| 3094 | canvas->drawPaint(paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3095 | } |
| 3096 | ## |
| 3097 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3098 | #SeeAlso clear drawColor SkBitmap::erase |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3099 | |
| 3100 | ## |
| 3101 | |
| 3102 | # ------------------------------------------------------------------------------ |
| 3103 | |
| 3104 | #Enum PointMode |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3105 | #Line # sets drawPoints options ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3106 | |
| 3107 | #Code |
| 3108 | enum PointMode { |
| 3109 | kPoints_PointMode, |
| 3110 | kLines_PointMode, |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 3111 | kPolygon_PointMode, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3112 | }; |
| 3113 | ## |
| 3114 | |
| 3115 | Selects if an array of points are drawn as discrete points, as lines, or as |
| 3116 | an open polygon. |
| 3117 | |
| 3118 | #Const kPoints_PointMode 0 |
| 3119 | Draw each point separately. |
| 3120 | ## |
| 3121 | |
| 3122 | #Const kLines_PointMode 1 |
| 3123 | Draw each pair of points as a line segment. |
| 3124 | ## |
| 3125 | |
| 3126 | #Const kPolygon_PointMode 2 |
| 3127 | Draw the array of points as a open polygon. |
| 3128 | ## |
| 3129 | |
| 3130 | #Example |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 3131 | #Description |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3132 | The upper left corner shows three squares when drawn as points. |
| 3133 | The upper right corner shows one line; when drawn as lines, two points are required per line. |
| 3134 | The lower right corner shows two lines; when draw as polygon, no miter is drawn at the corner. |
| 3135 | The lower left corner shows two lines with a miter when path contains polygon. |
| 3136 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3137 | void draw(SkCanvas* canvas) { |
| 3138 | SkPaint paint; |
| 3139 | paint.setStyle(SkPaint::kStroke_Style); |
| 3140 | paint.setStrokeWidth(10); |
| 3141 | SkPoint points[] = {{64, 32}, {96, 96}, {32, 96}}; |
| 3142 | canvas->drawPoints(SkCanvas::kPoints_PointMode, 3, points, paint); |
| 3143 | canvas->translate(128, 0); |
| 3144 | canvas->drawPoints(SkCanvas::kLines_PointMode, 3, points, paint); |
| 3145 | canvas->translate(0, 128); |
| 3146 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, 3, points, paint); |
| 3147 | SkPath path; |
| 3148 | path.addPoly(points, 3, false); |
| 3149 | canvas->translate(-128, 0); |
| 3150 | canvas->drawPath(path, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3151 | } |
| 3152 | ## |
| 3153 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3154 | #SeeAlso drawLine drawPoint drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3155 | |
| 3156 | ## |
| 3157 | |
| 3158 | # ------------------------------------------------------------------------------ |
| 3159 | |
| 3160 | #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] | 3161 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3162 | #Line # draws array as points, lines, polygon ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3163 | Draw pts using Clip, Matrix and Paint paint. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3164 | 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] | 3165 | mode may be one of: kPoints_PointMode, kLines_PointMode, or kPolygon_PointMode. |
| 3166 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3167 | If mode is kPoints_PointMode, the shape of point drawn depends on paint |
| 3168 | Paint_Stroke_Cap. If paint is set to SkPaint::kRound_Cap, each point draws a |
| 3169 | circle of diameter Paint_Stroke_Width. If paint is set to SkPaint::kSquare_Cap |
| 3170 | or SkPaint::kButt_Cap, each point draws a square of width and height |
| 3171 | Paint_Stroke_Width. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3172 | |
| 3173 | If mode is kLines_PointMode, each pair of points draws a line segment. |
| 3174 | One line is drawn for every two points; each point is used once. If count is odd, |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 3175 | the final point is ignored. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3176 | |
| 3177 | If mode is kPolygon_PointMode, each adjacent pair of points draws a line segment. |
| 3178 | count minus one lines are drawn; the first and last point are used once. |
| 3179 | |
| 3180 | Each line segment respects paint Paint_Stroke_Cap and Paint_Stroke_Width. |
| 3181 | Paint_Style is ignored, as if were set to SkPaint::kStroke_Style. |
| 3182 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3183 | Always draws each element one at a time; is not affected by |
| 3184 | Paint_Stroke_Join, and unlike drawPath, does not create a mask from all points |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 3185 | and lines before drawing. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3186 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 3187 | #Param mode whether pts draws points or lines ## |
| 3188 | #Param count number of points in the array ## |
| 3189 | #Param pts array of points to draw ## |
| 3190 | #Param paint stroke, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3191 | |
| 3192 | #Example |
| 3193 | #Height 200 |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 3194 | #Description |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3195 | #List |
| 3196 | # The first column draws points. ## |
| 3197 | # The second column draws points as lines. ## |
| 3198 | # The third column draws points as a polygon. ## |
| 3199 | # The fourth column draws points as a polygonal path. ## |
| 3200 | # The first row uses a round cap and round join. ## |
| 3201 | # The second row uses a square cap and a miter join. ## |
| 3202 | # The third row uses a butt cap and a bevel join. ## |
| 3203 | ## |
| 3204 | The transparent color makes multiple line draws visible; |
| 3205 | the path is drawn all at once. |
| 3206 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3207 | void draw(SkCanvas* canvas) { |
| 3208 | SkPaint paint; |
| 3209 | paint.setAntiAlias(true); |
| 3210 | paint.setStyle(SkPaint::kStroke_Style); |
| 3211 | paint.setStrokeWidth(10); |
| 3212 | paint.setColor(0x80349a45); |
| 3213 | const SkPoint points[] = {{32, 16}, {48, 48}, {16, 32}}; |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 3214 | const SkPaint::Join join[] = { SkPaint::kRound_Join, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3215 | SkPaint::kMiter_Join, |
| 3216 | SkPaint::kBevel_Join }; |
| 3217 | int joinIndex = 0; |
| 3218 | SkPath path; |
| 3219 | path.addPoly(points, 3, false); |
| 3220 | for (const auto cap : { SkPaint::kRound_Cap, SkPaint::kSquare_Cap, SkPaint::kButt_Cap } ) { |
| 3221 | paint.setStrokeCap(cap); |
| 3222 | paint.setStrokeJoin(join[joinIndex++]); |
| 3223 | for (const auto mode : { SkCanvas::kPoints_PointMode, |
| 3224 | SkCanvas::kLines_PointMode, |
| 3225 | SkCanvas::kPolygon_PointMode } ) { |
| 3226 | canvas->drawPoints(mode, 3, points, paint); |
| 3227 | canvas->translate(64, 0); |
| 3228 | } |
| 3229 | canvas->drawPath(path, paint); |
| 3230 | canvas->translate(-192, 64); |
| 3231 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3232 | } |
| 3233 | ## |
| 3234 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3235 | #SeeAlso drawLine drawPoint drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3236 | |
| 3237 | ## |
| 3238 | |
| 3239 | # ------------------------------------------------------------------------------ |
| 3240 | |
| 3241 | #Method void drawPoint(SkScalar x, SkScalar y, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3242 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3243 | #Line # draws point at (x, y) position ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3244 | Draw point at (x, y) using Clip, Matrix and Paint paint. |
| 3245 | |
| 3246 | The shape of point drawn depends on paint Paint_Stroke_Cap. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3247 | If paint is set to SkPaint::kRound_Cap, draw a circle of diameter |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 3248 | 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] | 3249 | draw a square of width and height Paint_Stroke_Width. |
| 3250 | Paint_Style is ignored, as if were set to SkPaint::kStroke_Style. |
| 3251 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3252 | #Param x left edge of circle or square ## |
| 3253 | #Param y top edge of circle or square ## |
| 3254 | #Param paint stroke, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3255 | |
| 3256 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3257 | void draw(SkCanvas* canvas) { |
| 3258 | SkPaint paint; |
| 3259 | paint.setAntiAlias(true); |
| 3260 | paint.setColor(0x80349a45); |
| 3261 | paint.setStyle(SkPaint::kStroke_Style); |
| 3262 | paint.setStrokeWidth(100); |
| 3263 | paint.setStrokeCap(SkPaint::kRound_Cap); |
| 3264 | canvas->scale(1, 1.2f); |
| 3265 | canvas->drawPoint(64, 96, paint); |
| 3266 | canvas->scale(.6f, .8f); |
| 3267 | paint.setColor(SK_ColorWHITE); |
| 3268 | canvas->drawPoint(106, 120, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3269 | } |
| 3270 | ## |
| 3271 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3272 | #SeeAlso drawPoints drawCircle drawRect drawLine drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3273 | |
| 3274 | ## |
| 3275 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3276 | #Method void drawPoint(SkPoint p, const SkPaint& paint) |
| 3277 | |
| 3278 | Draw point p using Clip, Matrix and Paint paint. |
| 3279 | |
| 3280 | The shape of point drawn depends on paint Paint_Stroke_Cap. |
| 3281 | If paint is set to SkPaint::kRound_Cap, draw a circle of diameter |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 3282 | 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] | 3283 | draw a square of width and height Paint_Stroke_Width. |
| 3284 | Paint_Style is ignored, as if were set to SkPaint::kStroke_Style. |
| 3285 | |
| 3286 | #Param p top-left edge of circle or square ## |
| 3287 | #Param paint stroke, blend, color, and so on, used to draw ## |
| 3288 | |
| 3289 | #Example |
| 3290 | void draw(SkCanvas* canvas) { |
| 3291 | SkPaint paint; |
| 3292 | paint.setAntiAlias(true); |
| 3293 | paint.setColor(0x80349a45); |
| 3294 | paint.setStyle(SkPaint::kStroke_Style); |
| 3295 | paint.setStrokeWidth(100); |
| 3296 | paint.setStrokeCap(SkPaint::kSquare_Cap); |
| 3297 | canvas->scale(1, 1.2f); |
| 3298 | canvas->drawPoint({64, 96}, paint); |
| 3299 | canvas->scale(.6f, .8f); |
| 3300 | paint.setColor(SK_ColorWHITE); |
| 3301 | canvas->drawPoint(106, 120, paint); |
| 3302 | } |
| 3303 | ## |
| 3304 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3305 | #SeeAlso drawPoints drawCircle drawRect drawLine drawPath |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3306 | |
| 3307 | ## |
| 3308 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3309 | # ------------------------------------------------------------------------------ |
| 3310 | |
| 3311 | #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] | 3312 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3313 | #Line # draws line segment between two points ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3314 | Draws line segment from (x0, y0) to (x1, y1) using Clip, Matrix, and Paint paint. |
| 3315 | In paint: Paint_Stroke_Width describes the line thickness; |
| 3316 | Paint_Stroke_Cap draws the end rounded or square; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3317 | Paint_Style is ignored, as if were set to SkPaint::kStroke_Style. |
| 3318 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3319 | #Param x0 start of line segment on x-axis ## |
| 3320 | #Param y0 start of line segment on y-axis ## |
| 3321 | #Param x1 end of line segment on x-axis ## |
| 3322 | #Param y1 end of line segment on y-axis ## |
| 3323 | #Param paint stroke, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3324 | |
| 3325 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3326 | SkPaint paint; |
| 3327 | paint.setAntiAlias(true); |
| 3328 | paint.setColor(0xFF9a67be); |
| 3329 | paint.setStrokeWidth(20); |
| 3330 | canvas->skew(1, 0); |
| 3331 | canvas->drawLine(32, 96, 32, 160, paint); |
| 3332 | canvas->skew(-2, 0); |
| 3333 | canvas->drawLine(288, 96, 288, 160, paint); |
| 3334 | ## |
| 3335 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3336 | #SeeAlso drawPoint drawCircle drawRect drawPath |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3337 | |
| 3338 | ## |
| 3339 | |
| 3340 | #Method void drawLine(SkPoint p0, SkPoint p1, const SkPaint& paint) |
| 3341 | |
| 3342 | Draws line segment from p0 to p1 using Clip, Matrix, and Paint paint. |
| 3343 | In paint: Paint_Stroke_Width describes the line thickness; |
| 3344 | Paint_Stroke_Cap draws the end rounded or square; |
| 3345 | Paint_Style is ignored, as if were set to SkPaint::kStroke_Style. |
| 3346 | |
| 3347 | #Param p0 start of line segment ## |
| 3348 | #Param p1 end of line segment ## |
| 3349 | #Param paint stroke, blend, color, and so on, used to draw ## |
| 3350 | |
| 3351 | #Example |
| 3352 | SkPaint paint; |
| 3353 | paint.setAntiAlias(true); |
| 3354 | paint.setColor(0xFF9a67be); |
| 3355 | paint.setStrokeWidth(20); |
| 3356 | canvas->skew(1, 0); |
| 3357 | canvas->drawLine({32, 96}, {32, 160}, paint); |
| 3358 | canvas->skew(-2, 0); |
| 3359 | canvas->drawLine({288, 96}, {288, 160}, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3360 | ## |
| 3361 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3362 | #SeeAlso drawPoint drawCircle drawRect drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3363 | |
| 3364 | ## |
| 3365 | |
| 3366 | # ------------------------------------------------------------------------------ |
| 3367 | |
| 3368 | #Method void drawRect(const SkRect& rect, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3369 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3370 | #Line # draws Rect using Clip, Matrix, and Paint ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3371 | Draw Rect rect using Clip, Matrix, and Paint paint. |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 3372 | In paint: Paint_Style determines if rectangle is stroked or filled; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3373 | if stroked, Paint_Stroke_Width describes the line thickness, and |
| 3374 | Paint_Stroke_Join draws the corners rounded or square. |
| 3375 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3376 | #Param rect rectangle to draw ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3377 | #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] | 3378 | |
| 3379 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3380 | void draw(SkCanvas* canvas) { |
| 3381 | SkPoint rectPts[] = { {64, 48}, {192, 160} }; |
| 3382 | SkPaint paint; |
| 3383 | paint.setAntiAlias(true); |
| 3384 | paint.setStyle(SkPaint::kStroke_Style); |
| 3385 | paint.setStrokeWidth(20); |
| 3386 | paint.setStrokeJoin(SkPaint::kRound_Join); |
| 3387 | SkMatrix rotator; |
| 3388 | rotator.setRotate(30, 128, 128); |
| 3389 | for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorMAGENTA } ) { |
| 3390 | paint.setColor(color); |
| 3391 | SkRect rect; |
| 3392 | rect.set(rectPts[0], rectPts[1]); |
| 3393 | canvas->drawRect(rect, paint); |
| 3394 | rotator.mapPoints(rectPts, 2); |
| 3395 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3396 | } |
| 3397 | ## |
| 3398 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 3399 | #SeeAlso drawIRect drawRRect drawRoundRect drawRegion drawPath drawLine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3400 | |
| 3401 | ## |
| 3402 | |
| 3403 | # ------------------------------------------------------------------------------ |
| 3404 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 3405 | #Method void drawIRect(const SkIRect& rect, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3406 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3407 | #Line # draws IRect using Clip, Matrix, and Paint ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3408 | Draw IRect rect using Clip, Matrix, and Paint paint. |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 3409 | In paint: Paint_Style determines if rectangle is stroked or filled; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3410 | if stroked, Paint_Stroke_Width describes the line thickness, and |
| 3411 | Paint_Stroke_Join draws the corners rounded or square. |
| 3412 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3413 | #Param rect rectangle to draw ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3414 | #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] | 3415 | |
| 3416 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3417 | SkIRect rect = { 64, 48, 192, 160 }; |
| 3418 | SkPaint paint; |
| 3419 | paint.setAntiAlias(true); |
| 3420 | paint.setStyle(SkPaint::kStroke_Style); |
| 3421 | paint.setStrokeWidth(20); |
| 3422 | paint.setStrokeJoin(SkPaint::kRound_Join); |
| 3423 | for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorMAGENTA } ) { |
| 3424 | paint.setColor(color); |
| 3425 | canvas->drawIRect(rect, paint); |
| 3426 | canvas->rotate(30, 128, 128); |
| 3427 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3428 | ## |
| 3429 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3430 | #SeeAlso drawRect drawRRect drawRoundRect drawRegion drawPath drawLine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3431 | |
| 3432 | ## |
| 3433 | |
| 3434 | # ------------------------------------------------------------------------------ |
| 3435 | |
| 3436 | #Method void drawRegion(const SkRegion& region, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3437 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3438 | #Line # draws Region using Clip, Matrix, and Paint ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3439 | Draw Region region using Clip, Matrix, and Paint paint. |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 3440 | In paint: Paint_Style determines if rectangle is stroked or filled; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3441 | if stroked, Paint_Stroke_Width describes the line thickness, and |
| 3442 | Paint_Stroke_Join draws the corners rounded or square. |
| 3443 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3444 | #Param region region to draw ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3445 | #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] | 3446 | |
| 3447 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3448 | void draw(SkCanvas* canvas) { |
| 3449 | SkRegion region; |
| 3450 | region.op( 10, 10, 50, 50, SkRegion::kUnion_Op); |
| 3451 | region.op( 10, 50, 90, 90, SkRegion::kUnion_Op); |
| 3452 | SkPaint paint; |
| 3453 | paint.setAntiAlias(true); |
| 3454 | paint.setStyle(SkPaint::kStroke_Style); |
| 3455 | paint.setStrokeWidth(20); |
| 3456 | paint.setStrokeJoin(SkPaint::kRound_Join); |
| 3457 | canvas->drawRegion(region, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3458 | } |
| 3459 | ## |
| 3460 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3461 | #SeeAlso drawRect drawIRect drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3462 | |
| 3463 | ## |
| 3464 | |
| 3465 | # ------------------------------------------------------------------------------ |
| 3466 | |
| 3467 | #Method void drawOval(const SkRect& oval, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3468 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3469 | #Line # draws Oval using Clip, Matrix, and Paint ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3470 | Draw Oval oval using Clip, Matrix, and Paint. |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 3471 | In paint: Paint_Style determines if Oval is stroked or filled; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3472 | if stroked, Paint_Stroke_Width describes the line thickness. |
| 3473 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3474 | #Param oval Rect bounds of Oval ## |
| 3475 | #Param paint Paint stroke or fill, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3476 | |
| 3477 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3478 | void draw(SkCanvas* canvas) { |
| 3479 | canvas->clear(0xFF3f5f9f); |
| 3480 | SkColor kColor1 = SkColorSetARGB(0xff, 0xff, 0x7f, 0); |
| 3481 | SkColor g1Colors[] = { kColor1, SkColorSetA(kColor1, 0x20) }; |
| 3482 | SkPoint g1Points[] = { { 0, 0 }, { 0, 100 } }; |
| 3483 | SkScalar pos[] = { 0.2f, 1.0f }; |
| 3484 | SkRect bounds = SkRect::MakeWH(80, 70); |
| 3485 | SkPaint paint; |
| 3486 | paint.setAntiAlias(true); |
| 3487 | paint.setShader(SkGradientShader::MakeLinear(g1Points, g1Colors, pos, SK_ARRAY_COUNT(g1Colors), |
| 3488 | SkShader::kClamp_TileMode)); |
| 3489 | canvas->drawOval(bounds , paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3490 | } |
| 3491 | ## |
| 3492 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3493 | #SeeAlso drawCircle drawPoint drawPath drawRRect drawRoundRect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3494 | |
| 3495 | ## |
| 3496 | |
| 3497 | # ------------------------------------------------------------------------------ |
| 3498 | |
| 3499 | #Method void drawRRect(const SkRRect& rrect, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3500 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3501 | #Line # draws Round_Rect using Clip, Matrix, and Paint ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3502 | Draw Round_Rect rrect using Clip, Matrix, and Paint paint. |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 3503 | In paint: Paint_Style determines if rrect is stroked or filled; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3504 | if stroked, Paint_Stroke_Width describes the line thickness. |
| 3505 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3506 | rrect may represent a rectangle, circle, oval, uniformly rounded rectangle, or |
| 3507 | 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] | 3508 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3509 | #Param rrect Round_Rect with up to eight corner radii to draw ## |
| 3510 | #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] | 3511 | |
| 3512 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3513 | void draw(SkCanvas* canvas) { |
| 3514 | SkPaint paint; |
| 3515 | paint.setAntiAlias(true); |
| 3516 | SkRect outer = {30, 40, 210, 220}; |
| 3517 | SkRect radii = {30, 50, 70, 90 }; |
| 3518 | SkRRect rRect; |
| 3519 | rRect.setNinePatch(outer, radii.fLeft, radii.fTop, radii.fRight, radii.fBottom); |
| 3520 | canvas->drawRRect(rRect, paint); |
| 3521 | paint.setColor(SK_ColorWHITE); |
| 3522 | canvas->drawLine(outer.fLeft + radii.fLeft, outer.fTop, |
| 3523 | outer.fLeft + radii.fLeft, outer.fBottom, paint); |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 3524 | canvas->drawLine(outer.fRight - radii.fRight, outer.fTop, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3525 | outer.fRight - radii.fRight, outer.fBottom, paint); |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 3526 | canvas->drawLine(outer.fLeft, outer.fTop + radii.fTop, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3527 | outer.fRight, outer.fTop + radii.fTop, paint); |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 3528 | canvas->drawLine(outer.fLeft, outer.fBottom - radii.fBottom, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3529 | outer.fRight, outer.fBottom - radii.fBottom, paint); |
| 3530 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3531 | ## |
| 3532 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3533 | #SeeAlso drawRect drawRoundRect drawDRRect drawCircle drawOval drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3534 | |
| 3535 | ## |
| 3536 | |
| 3537 | # ------------------------------------------------------------------------------ |
| 3538 | |
| 3539 | #Method void drawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3540 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3541 | #Line # draws double Round_Rect stroked or filled ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3542 | Draw Round_Rect outer and inner |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 3543 | using Clip, Matrix, and Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3544 | outer must contain inner or the drawing is undefined. |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 3545 | In paint: Paint_Style determines if Round_Rect is stroked or filled; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3546 | if stroked, Paint_Stroke_Width describes the line thickness. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3547 | If stroked and Round_Rect corner has zero length radii, Paint_Stroke_Join can |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 3548 | draw corners rounded or square. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3549 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3550 | GPU-backed platforms optimize drawing when both outer and inner are |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3551 | concave and outer contains inner. These platforms may not be able to draw |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 3552 | Path built with identical data as fast. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3553 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3554 | #Param outer Round_Rect outer bounds to draw ## |
| 3555 | #Param inner Round_Rect inner bounds to draw ## |
| 3556 | #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] | 3557 | |
| 3558 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3559 | void draw(SkCanvas* canvas) { |
| 3560 | SkRRect outer = SkRRect::MakeRect({20, 40, 210, 200}); |
| 3561 | SkRRect inner = SkRRect::MakeOval({60, 70, 170, 160}); |
| 3562 | SkPaint paint; |
| 3563 | canvas->drawDRRect(outer, inner, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3564 | } |
| 3565 | ## |
| 3566 | |
| 3567 | #Example |
| 3568 | #Description |
| 3569 | Outer Rect has no corner radii, but stroke join is rounded. |
| 3570 | Inner Round_Rect has corner radii; outset stroke increases radii of corners. |
| 3571 | Stroke join does not affect inner Round_Rect since it has no sharp corners. |
| 3572 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3573 | void draw(SkCanvas* canvas) { |
| 3574 | SkRRect outer = SkRRect::MakeRect({20, 40, 210, 200}); |
| 3575 | SkRRect inner = SkRRect::MakeRectXY({60, 70, 170, 160}, 10, 10); |
| 3576 | SkPaint paint; |
| 3577 | paint.setAntiAlias(true); |
| 3578 | paint.setStyle(SkPaint::kStroke_Style); |
| 3579 | paint.setStrokeWidth(20); |
| 3580 | paint.setStrokeJoin(SkPaint::kRound_Join); |
| 3581 | canvas->drawDRRect(outer, inner, paint); |
| 3582 | paint.setStrokeWidth(1); |
| 3583 | paint.setColor(SK_ColorWHITE); |
| 3584 | canvas->drawDRRect(outer, inner, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3585 | } |
| 3586 | ## |
| 3587 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3588 | #SeeAlso drawRect drawRoundRect drawRRect drawCircle drawOval drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3589 | |
| 3590 | ## |
| 3591 | |
| 3592 | # ------------------------------------------------------------------------------ |
| 3593 | |
| 3594 | #Method void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3595 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3596 | #Line # draws Circle using Clip, Matrix, and Paint ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3597 | Draw Circle at (cx, cy) with radius using Clip, Matrix, and Paint paint. |
| 3598 | If radius is zero or less, nothing is drawn. |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 3599 | In paint: Paint_Style determines if Circle is stroked or filled; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3600 | if stroked, Paint_Stroke_Width describes the line thickness. |
| 3601 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3602 | #Param cx Circle center on the x-axis ## |
| 3603 | #Param cy Circle center on the y-axis ## |
| 3604 | #Param radius half the diameter of Circle ## |
| 3605 | #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] | 3606 | |
| 3607 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3608 | void draw(SkCanvas* canvas) { |
| 3609 | SkPaint paint; |
| 3610 | paint.setAntiAlias(true); |
| 3611 | canvas->drawCircle(128, 128, 90, paint); |
| 3612 | paint.setColor(SK_ColorWHITE); |
| 3613 | canvas->drawCircle(86, 86, 20, paint); |
| 3614 | canvas->drawCircle(160, 76, 20, paint); |
| 3615 | canvas->drawCircle(140, 150, 35, paint); |
| 3616 | } |
| 3617 | ## |
| 3618 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3619 | #SeeAlso drawOval drawRRect drawRoundRect drawPath drawArc drawPoint drawLine |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3620 | |
| 3621 | ## |
| 3622 | |
| 3623 | #Method void drawCircle(SkPoint center, SkScalar radius, const SkPaint& paint) |
| 3624 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3625 | Draw Circle at center with radius using Clip, Matrix, and Paint paint. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3626 | If radius is zero or less, nothing is drawn. |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 3627 | In paint: Paint_Style determines if Circle is stroked or filled; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3628 | if stroked, Paint_Stroke_Width describes the line thickness. |
| 3629 | |
| 3630 | #Param center Circle center ## |
| 3631 | #Param radius half the diameter of Circle ## |
| 3632 | #Param paint Paint stroke or fill, blend, color, and so on, used to draw ## |
| 3633 | |
| 3634 | #Example |
| 3635 | void draw(SkCanvas* canvas) { |
| 3636 | SkPaint paint; |
| 3637 | paint.setAntiAlias(true); |
| 3638 | canvas->drawCircle(128, 128, 90, paint); |
| 3639 | paint.setColor(SK_ColorWHITE); |
| 3640 | canvas->drawCircle({86, 86}, 20, paint); |
| 3641 | canvas->drawCircle({160, 76}, 20, paint); |
| 3642 | canvas->drawCircle({140, 150}, 35, paint); |
| 3643 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3644 | ## |
| 3645 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3646 | #SeeAlso drawOval drawRRect drawRoundRect drawPath drawArc drawPoint drawLine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3647 | |
| 3648 | ## |
| 3649 | |
| 3650 | # ------------------------------------------------------------------------------ |
| 3651 | |
| 3652 | #Method void drawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, |
| 3653 | bool useCenter, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3654 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3655 | #Line # draws Arc using Clip, Matrix, and Paint ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3656 | |
| 3657 | Draw Arc using Clip, Matrix, and Paint paint. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3658 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3659 | Arc is part of Oval bounded by oval, sweeping from startAngle to startAngle plus |
| 3660 | sweepAngle. startAngle and sweepAngle are in degrees. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3661 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3662 | startAngle of zero places start point at the right middle edge of oval. |
| 3663 | A positive sweepAngle places Arc end point clockwise from start point; |
| 3664 | a negative sweepAngle places Arc end point counterclockwise from start point. |
| 3665 | sweepAngle may exceed 360 degrees, a full circle. |
| 3666 | If useCenter is true, draw a wedge that includes lines from oval |
| 3667 | center to Arc end points. If useCenter is false, draw Arc between end points. |
| 3668 | |
| 3669 | If Rect oval is empty or sweepAngle is zero, nothing is drawn. |
| 3670 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3671 | #Param oval Rect bounds of Oval containing Arc to draw ## |
| 3672 | #Param startAngle angle in degrees where Arc begins ## |
| 3673 | #Param sweepAngle sweep angle in degrees; positive is clockwise ## |
| 3674 | #Param useCenter if true, include the center of the oval ## |
| 3675 | #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] | 3676 | |
| 3677 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3678 | void draw(SkCanvas* canvas) { |
| 3679 | SkPaint paint; |
| 3680 | paint.setAntiAlias(true); |
| 3681 | SkRect oval = { 4, 4, 60, 60}; |
| 3682 | for (auto useCenter : { false, true } ) { |
| 3683 | for (auto style : { SkPaint::kFill_Style, SkPaint::kStroke_Style } ) { |
| 3684 | paint.setStyle(style); |
| 3685 | for (auto degrees : { 45, 90, 180, 360} ) { |
| 3686 | canvas->drawArc(oval, 0, degrees , useCenter, paint); |
| 3687 | canvas->translate(64, 0); |
| 3688 | } |
| 3689 | canvas->translate(-256, 64); |
| 3690 | } |
| 3691 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3692 | } |
| 3693 | ## |
| 3694 | |
| 3695 | #Example |
| 3696 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3697 | void draw(SkCanvas* canvas) { |
| 3698 | SkPaint paint; |
| 3699 | paint.setAntiAlias(true); |
| 3700 | paint.setStyle(SkPaint::kStroke_Style); |
| 3701 | paint.setStrokeWidth(4); |
| 3702 | SkRect oval = { 4, 4, 60, 60}; |
| 3703 | float intervals[] = { 5, 5 }; |
| 3704 | paint.setPathEffect(SkDashPathEffect::Make(intervals, 2, 2.5f)); |
| 3705 | for (auto degrees : { 270, 360, 540, 720 } ) { |
| 3706 | canvas->drawArc(oval, 0, degrees, false, paint); |
| 3707 | canvas->translate(64, 0); |
| 3708 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3709 | } |
| 3710 | ## |
| 3711 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3712 | #SeeAlso SkPath::arcTo drawCircle drawOval drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3713 | |
| 3714 | ## |
| 3715 | |
| 3716 | # ------------------------------------------------------------------------------ |
| 3717 | |
| 3718 | #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] | 3719 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3720 | #Line # draws Round_Rect using Clip, Matrix, and Paint ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3721 | Draw Round_Rect bounded by Rect rect, with corner radii (rx, ry) using Clip, |
| 3722 | Matrix, and Paint paint. |
| 3723 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 3724 | In paint: Paint_Style determines if Round_Rect is stroked or filled; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3725 | if stroked, Paint_Stroke_Width describes the line thickness. |
| 3726 | If rx or ry are less than zero, they are treated as if they are zero. |
| 3727 | 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] | 3728 | If rx and ry are zero, Round_Rect is drawn as Rect and if stroked is affected by |
| 3729 | Paint_Stroke_Join. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3730 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3731 | #Param rect Rect bounds of Round_Rect to draw ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3732 | #Param rx axis length in x of oval describing rounded corners ## |
| 3733 | #Param ry axis length in y of oval describing rounded corners ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3734 | #Param paint stroke, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3735 | |
| 3736 | #Example |
| 3737 | #Description |
| 3738 | Top row has a zero radius a generates a rectangle. |
| 3739 | Second row radii sum to less than sides. |
| 3740 | Third row radii sum equals sides. |
| 3741 | Fourth row radii sum exceeds sides; radii are scaled to fit. |
| 3742 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3743 | void draw(SkCanvas* canvas) { |
| 3744 | SkVector radii[] = { {0, 20}, {10, 10}, {10, 20}, {10, 40} }; |
| 3745 | SkPaint paint; |
| 3746 | paint.setStrokeWidth(15); |
| 3747 | paint.setStrokeJoin(SkPaint::kRound_Join); |
| 3748 | paint.setAntiAlias(true); |
| 3749 | for (auto style : { SkPaint::kStroke_Style, SkPaint::kFill_Style } ) { |
| 3750 | paint.setStyle(style ); |
| 3751 | for (size_t i = 0; i < SK_ARRAY_COUNT(radii); ++i) { |
| 3752 | canvas->drawRoundRect({10, 10, 60, 40}, radii[i].fX, radii[i].fY, paint); |
| 3753 | canvas->translate(0, 60); |
| 3754 | } |
| 3755 | canvas->translate(80, -240); |
| 3756 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3757 | } |
| 3758 | ## |
| 3759 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3760 | #SeeAlso DrawRRect drawRect drawDRRect drawPath drawCircle drawOval drawPoint |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3761 | |
| 3762 | ## |
| 3763 | |
| 3764 | # ------------------------------------------------------------------------------ |
| 3765 | |
| 3766 | #Method void drawPath(const SkPath& path, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3767 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3768 | #Line # draws Path using Clip, Matrix, and Paint ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3769 | Draw Path path using Clip, Matrix, and Paint paint. |
| 3770 | Path contains an array of Path_Contour, each of which may be open or closed. |
| 3771 | |
| 3772 | In paint: Paint_Style determines if Round_Rect is stroked or filled: |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3773 | if filled, Path_Fill_Type determines whether Path_Contour describes inside or |
| 3774 | outside of fill; if stroked, Paint_Stroke_Width describes the line thickness, |
| 3775 | Paint_Stroke_Cap describes line ends, and Paint_Stroke_Join describes how |
| 3776 | corners are drawn. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3777 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3778 | #Param path Path to draw ## |
| 3779 | #Param paint stroke, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3780 | |
| 3781 | #Example |
| 3782 | #Description |
| 3783 | Top rows draw stroked path with combinations of joins and caps. The open contour |
| 3784 | is affected by caps; the closed contour is affected by joins. |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 3785 | Bottom row draws fill the same for open and closed contour. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3786 | First bottom column shows winding fills overlap. |
| 3787 | Second bottom column shows even odd fills exclude overlap. |
| 3788 | Third bottom column shows inverse winding fills area outside both contours. |
| 3789 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3790 | void draw(SkCanvas* canvas) { |
| 3791 | SkPath path; |
| 3792 | path.moveTo(20, 20); |
| 3793 | path.quadTo(60, 20, 60, 60); |
| 3794 | path.close(); |
| 3795 | path.moveTo(60, 20); |
| 3796 | path.quadTo(60, 60, 20, 60); |
| 3797 | SkPaint paint; |
| 3798 | paint.setStrokeWidth(10); |
| 3799 | paint.setAntiAlias(true); |
| 3800 | paint.setStyle(SkPaint::kStroke_Style); |
| 3801 | for (auto join: { SkPaint::kBevel_Join, SkPaint::kRound_Join, SkPaint::kMiter_Join } ) { |
| 3802 | paint.setStrokeJoin(join); |
| 3803 | for (auto cap: { SkPaint::kButt_Cap, SkPaint::kSquare_Cap, SkPaint::kRound_Cap } ) { |
| 3804 | paint.setStrokeCap(cap); |
| 3805 | canvas->drawPath(path, paint); |
| 3806 | canvas->translate(80, 0); |
| 3807 | } |
| 3808 | canvas->translate(-240, 60); |
| 3809 | } |
| 3810 | paint.setStyle(SkPaint::kFill_Style); |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 3811 | for (auto fill : { SkPath::kWinding_FillType, |
| 3812 | SkPath::kEvenOdd_FillType, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3813 | SkPath::kInverseWinding_FillType } ) { |
| 3814 | path.setFillType(fill); |
| 3815 | canvas->save(); |
| 3816 | canvas->clipRect({0, 10, 80, 70}); |
| 3817 | canvas->drawPath(path, paint); |
| 3818 | canvas->restore(); |
| 3819 | canvas->translate(80, 0); |
| 3820 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3821 | } |
| 3822 | ## |
| 3823 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3824 | #SeeAlso SkPath drawLine drawArc drawRect drawPoints |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3825 | |
| 3826 | ## |
| 3827 | |
| 3828 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3829 | #Subtopic Draw_Image |
| 3830 | #Line # draws Image to Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3831 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3832 | drawImage, drawImageRect, and drawImageNine can be called with a bare pointer or |
| 3833 | 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] | 3834 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3835 | #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] | 3836 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3837 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3838 | #Line # draws Image at (x, y) position ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3839 | Draw Image image, with its top-left corner at (left, top), |
| 3840 | using Clip, Matrix, and optional Paint paint. |
| 3841 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3842 | If paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, Blend_Mode, |
| 3843 | and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader. |
| 3844 | If paint contains Mask_Filter, generate mask from image bounds. If generated |
| 3845 | mask extends beyond image bounds, replicate image edge colors, just as Shader |
| 3846 | made from SkImage::makeShader with SkShader::kClamp_TileMode set replicates the |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 3847 | image edge color when it samples outside of its bounds. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3848 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3849 | #Param image uncompressed rectangular map of pixels ## |
| 3850 | #Param left left side of image ## |
| 3851 | #Param top top side of image ## |
| 3852 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 3853 | and so on; or nullptr |
| 3854 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3855 | |
| 3856 | #Example |
| 3857 | #Height 64 |
| 3858 | #Image 4 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3859 | void draw(SkCanvas* canvas) { |
| 3860 | // sk_sp<SkImage> image; |
| 3861 | SkImage* imagePtr = image.get(); |
| 3862 | canvas->drawImage(imagePtr, 0, 0); |
| 3863 | SkPaint paint; |
| 3864 | canvas->drawImage(imagePtr, 80, 0, &paint); |
| 3865 | paint.setAlpha(0x80); |
| 3866 | canvas->drawImage(imagePtr, 160, 0, &paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3867 | } |
| 3868 | ## |
| 3869 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3870 | #SeeAlso drawBitmap drawImageLattice drawImageNine drawImageRect SkPaint::setImageFilter |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3871 | |
| 3872 | ## |
| 3873 | |
| 3874 | # ------------------------------------------------------------------------------ |
| 3875 | |
| 3876 | #Method void drawImage(const sk_sp<SkImage>& image, SkScalar left, SkScalar top, |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 3877 | const SkPaint* paint = nullptr) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3878 | |
| 3879 | Draw Image image, with its top-left corner at (left, top), |
| 3880 | using Clip, Matrix, and optional Paint paint. |
| 3881 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3882 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 3883 | Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader. |
| 3884 | If paint contains Mask_Filter, generate mask from image bounds. If generated |
| 3885 | mask extends beyond image bounds, replicate image edge colors, just as Shader |
| 3886 | made from SkImage::makeShader with SkShader::kClamp_TileMode set replicates the |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 3887 | image edge color when it samples outside of its bounds. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3888 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3889 | #Param image uncompressed rectangular map of pixels ## |
| 3890 | #Param left left side of image ## |
| 3891 | #Param top pop side of image ## |
| 3892 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 3893 | and so on; or nullptr |
| 3894 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3895 | |
| 3896 | #Example |
| 3897 | #Height 64 |
| 3898 | #Image 4 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3899 | void draw(SkCanvas* canvas) { |
| 3900 | // sk_sp<SkImage> image; |
| 3901 | canvas->drawImage(image, 0, 0); |
| 3902 | SkPaint paint; |
| 3903 | canvas->drawImage(image, 80, 0, &paint); |
| 3904 | paint.setAlpha(0x80); |
| 3905 | canvas->drawImage(image, 160, 0, &paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3906 | } |
| 3907 | ## |
| 3908 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3909 | #SeeAlso drawBitmap drawImageLattice drawImageNine drawImageRect SkPaint::setImageFilter |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3910 | |
| 3911 | ## |
| 3912 | |
| 3913 | # ------------------------------------------------------------------------------ |
| 3914 | |
| 3915 | #Enum SrcRectConstraint |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3916 | #Line # sets drawImageRect options ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3917 | |
| 3918 | #Code |
| 3919 | enum SrcRectConstraint { |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 3920 | kStrict_SrcRectConstraint, |
| 3921 | kFast_SrcRectConstraint, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3922 | }; |
| 3923 | ## |
| 3924 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3925 | SrcRectConstraint controls the behavior at the edge of source Rect, |
| 3926 | provided to drawImageRect, trading off speed for precision. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3927 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3928 | 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] | 3929 | restricts the bounds of pixels that may be read. Image_Filter may slow down if |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 3930 | 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] | 3931 | SrcRectConstraint specifies whether an Image_Filter is allowed to read pixels |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3932 | outside source Rect. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3933 | |
| 3934 | #Const kStrict_SrcRectConstraint |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3935 | Requires Image_Filter to respect source Rect, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3936 | sampling only inside of its bounds, possibly with a performance penalty. |
| 3937 | ## |
| 3938 | |
| 3939 | #Const kFast_SrcRectConstraint |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3940 | Permits Image_Filter to sample outside of source Rect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3941 | by half the width of Image_Filter, permitting it to run faster but with |
| 3942 | error at the image edges. |
| 3943 | ## |
| 3944 | |
| 3945 | #Example |
| 3946 | #Height 64 |
| 3947 | #Description |
| 3948 | redBorder contains a black and white checkerboard bordered by red. |
| 3949 | redBorder is drawn scaled by 16 on the left. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3950 | The middle and right bitmaps are filtered checkerboards. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3951 | Drawing the checkerboard with kStrict_SrcRectConstraint shows only a blur of black and white. |
| 3952 | Drawing the checkerboard with kFast_SrcRectConstraint allows red to bleed in the corners. |
| 3953 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3954 | void draw(SkCanvas* canvas) { |
| 3955 | SkBitmap redBorder; |
| 3956 | redBorder.allocPixels(SkImageInfo::MakeN32Premul(4, 4)); |
| 3957 | SkCanvas checkRed(redBorder); |
| 3958 | checkRed.clear(SK_ColorRED); |
| 3959 | uint32_t checkers[][2] = { { SK_ColorBLACK, SK_ColorWHITE }, |
| 3960 | { SK_ColorWHITE, SK_ColorBLACK } }; |
| 3961 | checkRed.writePixels( |
| 3962 | SkImageInfo::MakeN32Premul(2, 2), (void*) checkers, sizeof(checkers[0]), 1, 1); |
| 3963 | canvas->scale(16, 16); |
| 3964 | canvas->drawBitmap(redBorder, 0, 0, nullptr); |
| 3965 | canvas->resetMatrix(); |
| 3966 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(redBorder); |
| 3967 | SkPaint lowPaint; |
| 3968 | lowPaint.setFilterQuality(kLow_SkFilterQuality); |
| 3969 | for (auto constraint : { SkCanvas::kStrict_SrcRectConstraint, |
| 3970 | SkCanvas::kFast_SrcRectConstraint } ) { |
| 3971 | canvas->translate(80, 0); |
| 3972 | canvas->drawImageRect(image.get(), SkRect::MakeLTRB(1, 1, 3, 3), |
| 3973 | SkRect::MakeLTRB(16, 16, 48, 48), &lowPaint, constraint); |
| 3974 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3975 | } |
| 3976 | ## |
| 3977 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3978 | #SeeAlso drawImageRect drawImage SkPaint::setImageFilter |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3979 | |
| 3980 | ## |
| 3981 | |
| 3982 | # ------------------------------------------------------------------------------ |
| 3983 | |
| 3984 | #Method void drawImageRect(const SkImage* image, const SkRect& src, const SkRect& dst, |
| 3985 | const SkPaint* paint, |
| 3986 | SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3987 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3988 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3989 | #Line # draws Image, source Rect to destination Rect ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3990 | |
| 3991 | Draw Rect src of Image image, scaled and translated to fill Rect dst. |
| 3992 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3993 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3994 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 3995 | Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader. |
| 3996 | If paint contains Mask_Filter, generate mask from image bounds. |
| 3997 | |
| 3998 | If generated mask extends beyond image bounds, replicate image edge colors, just |
| 3999 | as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4000 | replicates the image edge color when it samples outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4001 | |
| 4002 | constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to |
| 4003 | sample within src; set to kFast_SrcRectConstraint allows sampling outside to |
| 4004 | improve performance. |
| 4005 | |
| 4006 | #Param image Image containing pixels, dimensions, and format ## |
| 4007 | #Param src source Rect of image to draw from ## |
| 4008 | #Param dst destination Rect of image to draw to ## |
| 4009 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4010 | and so on; or nullptr |
| 4011 | ## |
| 4012 | #Param constraint filter strictly within src or draw faster ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4013 | |
| 4014 | #Example |
| 4015 | #Height 64 |
| 4016 | #Description |
| 4017 | The left bitmap draws with Paint default kNone_SkFilterQuality, and stays within |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4018 | its bounds; there is no bleeding with kFast_SrcRectConstraint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4019 | the middle and right bitmaps draw with kLow_SkFilterQuality; with |
| 4020 | kStrict_SrcRectConstraint, the filter remains within the checkerboard, and |
| 4021 | with kFast_SrcRectConstraint red bleeds on the edges. |
| 4022 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4023 | void draw(SkCanvas* canvas) { |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 4024 | uint32_t pixels[][4] = { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4025 | { 0xFFFF0000, 0xFFFF0000, 0xFFFF0000, 0xFFFF0000 }, |
| 4026 | { 0xFFFF0000, 0xFF000000, 0xFFFFFFFF, 0xFFFF0000 }, |
| 4027 | { 0xFFFF0000, 0xFFFFFFFF, 0xFF000000, 0xFFFF0000 }, |
| 4028 | { 0xFFFF0000, 0xFFFF0000, 0xFFFF0000, 0xFFFF0000 } }; |
| 4029 | SkBitmap redBorder; |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 4030 | redBorder.installPixels(SkImageInfo::MakeN32Premul(4, 4), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4031 | (void*) pixels, sizeof(pixels[0])); |
| 4032 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(redBorder); |
| 4033 | SkPaint lowPaint; |
| 4034 | for (auto constraint : { |
| 4035 | SkCanvas::kFast_SrcRectConstraint, |
| 4036 | SkCanvas::kStrict_SrcRectConstraint, |
| 4037 | SkCanvas::kFast_SrcRectConstraint } ) { |
| 4038 | canvas->drawImageRect(image.get(), SkRect::MakeLTRB(1, 1, 3, 3), |
| 4039 | SkRect::MakeLTRB(16, 16, 48, 48), &lowPaint, constraint); |
| 4040 | lowPaint.setFilterQuality(kLow_SkFilterQuality); |
| 4041 | canvas->translate(80, 0); |
| 4042 | } |
| 4043 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4044 | ## |
| 4045 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4046 | #SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4047 | |
| 4048 | ## |
| 4049 | |
| 4050 | # ------------------------------------------------------------------------------ |
| 4051 | |
| 4052 | #Method void drawImageRect(const SkImage* image, const SkIRect& isrc, const SkRect& dst, |
| 4053 | const SkPaint* paint, SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4054 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4055 | #In Draw |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4056 | |
| 4057 | 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] | 4058 | Note that isrc is on integer pixel boundaries; dst may include fractional |
| 4059 | boundaries. Additionally transform draw using Clip, Matrix, and optional Paint |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 4060 | paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4061 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4062 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4063 | Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader. |
| 4064 | If paint contains Mask_Filter, generate mask from image bounds. |
| 4065 | |
| 4066 | If generated mask extends beyond image bounds, replicate image edge colors, just |
| 4067 | as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4068 | replicates the image edge color when it samples outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4069 | |
| 4070 | constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4071 | sample within isrc; set to kFast_SrcRectConstraint allows sampling outside to |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4072 | improve performance. |
| 4073 | |
| 4074 | #Param image Image containing pixels, dimensions, and format ## |
| 4075 | #Param isrc source IRect of image to draw from ## |
| 4076 | #Param dst destination Rect of image to draw to ## |
| 4077 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4078 | and so on; or nullptr |
| 4079 | ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4080 | #Param constraint filter strictly within isrc or draw faster ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4081 | |
| 4082 | #Example |
| 4083 | #Image 4 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4084 | void draw(SkCanvas* canvas) { |
| 4085 | // sk_sp<SkImage> image; |
| 4086 | for (auto i : { 1, 2, 4, 8 } ) { |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 4087 | canvas->drawImageRect(image.get(), SkIRect::MakeLTRB(0, 0, 100, 100), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4088 | SkRect::MakeXYWH(i * 20, i * 20, i * 20, i * 20), nullptr); |
| 4089 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4090 | } |
| 4091 | ## |
| 4092 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4093 | #SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4094 | |
| 4095 | ## |
| 4096 | |
| 4097 | # ------------------------------------------------------------------------------ |
| 4098 | |
| 4099 | #Method void drawImageRect(const SkImage* image, const SkRect& dst, const SkPaint* paint, |
| 4100 | SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4101 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4102 | #In Draw |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4103 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4104 | Draw Image image, scaled and translated to fill Rect dst, using Clip, Matrix, |
| 4105 | and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4106 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4107 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4108 | Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader. |
| 4109 | If paint contains Mask_Filter, generate mask from image bounds. |
| 4110 | |
| 4111 | If generated mask extends beyond image bounds, replicate image edge colors, just |
| 4112 | as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4113 | replicates the image edge color when it samples outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4114 | |
| 4115 | constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4116 | sample within image; set to kFast_SrcRectConstraint allows sampling outside to |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4117 | improve performance. |
| 4118 | |
| 4119 | #Param image Image containing pixels, dimensions, and format ## |
| 4120 | #Param dst destination Rect of image to draw to ## |
| 4121 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4122 | and so on; or nullptr |
| 4123 | ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4124 | #Param constraint filter strictly within image or draw faster ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4125 | |
| 4126 | #Example |
| 4127 | #Image 4 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4128 | void draw(SkCanvas* canvas) { |
| 4129 | // sk_sp<SkImage> image; |
| 4130 | for (auto i : { 20, 40, 80, 160 } ) { |
| 4131 | canvas->drawImageRect(image.get(), SkRect::MakeXYWH(i, i, i, i), nullptr); |
| 4132 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4133 | } |
| 4134 | ## |
| 4135 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4136 | #SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4137 | |
| 4138 | ## |
| 4139 | |
| 4140 | # ------------------------------------------------------------------------------ |
| 4141 | |
| 4142 | #Method void drawImageRect(const sk_sp<SkImage>& image, const SkRect& src, const SkRect& dst, |
| 4143 | const SkPaint* paint, |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 4144 | SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4145 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4146 | #In Draw |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4147 | Draw Rect src of Image image, scaled and translated to fill Rect dst. |
| 4148 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4149 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4150 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4151 | Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader. |
| 4152 | If paint contains Mask_Filter, generate mask from image bounds. |
| 4153 | |
| 4154 | If generated mask extends beyond image bounds, replicate image edge colors, just |
| 4155 | as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4156 | replicates the image edge color when it samples outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4157 | |
| 4158 | constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to |
| 4159 | sample within src; set to kFast_SrcRectConstraint allows sampling outside to |
| 4160 | improve performance. |
| 4161 | |
| 4162 | #Param image Image containing pixels, dimensions, and format ## |
| 4163 | #Param src source Rect of image to draw from ## |
| 4164 | #Param dst destination Rect of image to draw to ## |
| 4165 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4166 | and so on; or nullptr |
| 4167 | ## |
| 4168 | #Param constraint filter strictly within src or draw faster ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4169 | |
| 4170 | #Example |
| 4171 | #Height 64 |
| 4172 | #Description |
| 4173 | Canvas scales and translates; transformation from src to dst also scales. |
| 4174 | The two matrices are concatenated to create the final transformation. |
| 4175 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4176 | void draw(SkCanvas* canvas) { |
| 4177 | uint32_t pixels[][2] = { { SK_ColorBLACK, SK_ColorWHITE }, |
| 4178 | { SK_ColorWHITE, SK_ColorBLACK } }; |
| 4179 | SkBitmap bitmap; |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 4180 | bitmap.installPixels(SkImageInfo::MakeN32Premul(2, 2), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4181 | (void*) pixels, sizeof(pixels[0])); |
| 4182 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 4183 | SkPaint paint; |
| 4184 | canvas->scale(4, 4); |
| 4185 | for (auto alpha : { 50, 100, 150, 255 } ) { |
| 4186 | paint.setAlpha(alpha); |
| 4187 | canvas->drawImageRect(image, SkRect::MakeWH(2, 2), SkRect::MakeWH(8, 8), &paint); |
| 4188 | canvas->translate(8, 0); |
| 4189 | } |
| 4190 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4191 | ## |
| 4192 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4193 | #SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4194 | |
| 4195 | ## |
| 4196 | |
| 4197 | # ------------------------------------------------------------------------------ |
| 4198 | |
| 4199 | #Method void drawImageRect(const sk_sp<SkImage>& image, const SkIRect& isrc, const SkRect& dst, |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 4200 | const SkPaint* paint, SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4201 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4202 | #In Draw |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4203 | 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] | 4204 | isrc is on integer pixel boundaries; dst may include fractional boundaries. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4205 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4206 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4207 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4208 | Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader. |
| 4209 | If paint contains Mask_Filter, generate mask from image bounds. |
| 4210 | |
| 4211 | If generated mask extends beyond image bounds, replicate image edge colors, just |
| 4212 | as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4213 | replicates the image edge color when it samples outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4214 | |
| 4215 | constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4216 | sample within image; set to kFast_SrcRectConstraint allows sampling outside to |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4217 | improve performance. |
| 4218 | |
| 4219 | #Param image Image containing pixels, dimensions, and format ## |
| 4220 | #Param isrc source IRect of image to draw from ## |
| 4221 | #Param dst destination Rect of image to draw to ## |
| 4222 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4223 | and so on; or nullptr |
| 4224 | ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4225 | #Param constraint filter strictly within image or draw faster ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4226 | |
| 4227 | #Example |
| 4228 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4229 | void draw(SkCanvas* canvas) { |
| 4230 | uint32_t pixels[][2] = { { 0x00000000, 0x55555555}, |
| 4231 | { 0xAAAAAAAA, 0xFFFFFFFF} }; |
| 4232 | SkBitmap bitmap; |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 4233 | bitmap.installPixels(SkImageInfo::MakeN32Premul(2, 2), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4234 | (void*) pixels, sizeof(pixels[0])); |
| 4235 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 4236 | SkPaint paint; |
| 4237 | canvas->scale(4, 4); |
| 4238 | for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN } ) { |
| 4239 | paint.setColorFilter(SkColorFilter::MakeModeFilter(color, SkBlendMode::kPlus)); |
| 4240 | canvas->drawImageRect(image, SkIRect::MakeWH(2, 2), SkRect::MakeWH(8, 8), &paint); |
| 4241 | canvas->translate(8, 0); |
| 4242 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4243 | } |
| 4244 | ## |
| 4245 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4246 | #SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine |
| 4247 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4248 | ## |
| 4249 | |
| 4250 | # ------------------------------------------------------------------------------ |
| 4251 | |
| 4252 | #Method void drawImageRect(const sk_sp<SkImage>& image, const SkRect& dst, const SkPaint* paint, |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 4253 | SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4254 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4255 | #In Draw |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4256 | Draw Image image, scaled and translated to fill Rect dst, |
| 4257 | using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4258 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4259 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4260 | Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader. |
| 4261 | If paint contains Mask_Filter, generate mask from image bounds. |
| 4262 | |
| 4263 | If generated mask extends beyond image bounds, replicate image edge colors, just |
| 4264 | as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4265 | replicates the image edge color when it samples outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4266 | |
| 4267 | constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4268 | sample within image; set to kFast_SrcRectConstraint allows sampling outside to |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4269 | improve performance. |
| 4270 | |
| 4271 | #Param image Image containing pixels, dimensions, and format ## |
| 4272 | #Param dst destination Rect of image to draw to ## |
| 4273 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4274 | and so on; or nullptr |
| 4275 | ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4276 | #Param constraint filter strictly within image or draw faster ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4277 | |
| 4278 | #Example |
| 4279 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4280 | void draw(SkCanvas* canvas) { |
| 4281 | uint32_t pixels[][2] = { { 0x00000000, 0x55550000}, |
| 4282 | { 0xAAAA0000, 0xFFFF0000} }; |
| 4283 | SkBitmap bitmap; |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 4284 | bitmap.installPixels(SkImageInfo::MakeN32Premul(2, 2), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4285 | (void*) pixels, sizeof(pixels[0])); |
| 4286 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 4287 | SkPaint paint; |
| 4288 | canvas->scale(4, 4); |
| 4289 | for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN } ) { |
| 4290 | paint.setColorFilter(SkColorFilter::MakeModeFilter(color, SkBlendMode::kPlus)); |
| 4291 | canvas->drawImageRect(image, SkRect::MakeWH(8, 8), &paint); |
| 4292 | canvas->translate(8, 0); |
| 4293 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4294 | } |
| 4295 | ## |
| 4296 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4297 | #SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4298 | |
| 4299 | ## |
| 4300 | |
| 4301 | # ------------------------------------------------------------------------------ |
| 4302 | |
| 4303 | #Method void drawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst, |
| 4304 | const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4305 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4306 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4307 | #Line # draws Nine_Patch Image ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4308 | |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 4309 | Draw Image image stretched proportionally to fit into Rect dst. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4310 | 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] | 4311 | the center. Corners are unmodified or scaled down proportionately if their sides |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4312 | 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] | 4313 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4314 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
| 4315 | |
| 4316 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4317 | Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader. |
| 4318 | If paint contains Mask_Filter, generate mask from image bounds. |
| 4319 | |
| 4320 | If generated mask extends beyond image bounds, replicate image edge colors, just |
| 4321 | as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4322 | replicates the image edge color when it samples outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4323 | |
| 4324 | #Param image Image containing pixels, dimensions, and format ## |
| 4325 | #Param center IRect edge of image corners and sides ## |
| 4326 | #Param dst destination Rect of image to draw to ## |
| 4327 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4328 | and so on; or nullptr |
| 4329 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4330 | |
| 4331 | #Example |
| 4332 | #Height 128 |
| 4333 | #Description |
| 4334 | 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] | 4335 | The second image equals the size of center; only corners are drawn without scaling. |
| 4336 | The remaining images are larger than center. All corners draw without scaling. |
| 4337 | 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] | 4338 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4339 | void draw(SkCanvas* canvas) { |
| 4340 | SkIRect center = { 20, 10, 50, 40 }; |
| 4341 | SkBitmap bitmap; |
| 4342 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60)); |
| 4343 | SkCanvas bitCanvas(bitmap); |
| 4344 | SkPaint paint; |
| 4345 | SkColor gray = 0xFF000000; |
| 4346 | int left = 0; |
| 4347 | for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) { |
| 4348 | int top = 0; |
| 4349 | for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) { |
| 4350 | paint.setColor(gray); |
| 4351 | bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint); |
| 4352 | gray += 0x001f1f1f; |
| 4353 | top = bottom; |
| 4354 | } |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 4355 | left = right; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4356 | } |
| 4357 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 4358 | SkImage* imagePtr = image.get(); |
| 4359 | for (auto dest: { 20, 30, 40, 60, 90 } ) { |
| 4360 | canvas->drawImageNine(imagePtr, center, SkRect::MakeWH(dest, dest), nullptr); |
| 4361 | canvas->translate(dest + 4, 0); |
| 4362 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4363 | } |
| 4364 | ## |
| 4365 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4366 | #SeeAlso drawImage drawBitmapNine drawImageLattice drawImageRect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4367 | |
| 4368 | ## |
| 4369 | |
| 4370 | # ------------------------------------------------------------------------------ |
| 4371 | |
| 4372 | #Method void drawImageNine(const sk_sp<SkImage>& image, const SkIRect& center, const SkRect& dst, |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 4373 | const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4374 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4375 | #In Draw |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 4376 | Draw Image image stretched proportionally to fit into Rect dst. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4377 | 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] | 4378 | 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] | 4379 | 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] | 4380 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4381 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
| 4382 | |
| 4383 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4384 | Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader. |
| 4385 | If paint contains Mask_Filter, generate mask from image bounds. |
| 4386 | |
| 4387 | If generated mask extends beyond image bounds, replicate image edge colors, just |
| 4388 | as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4389 | replicates the image edge color when it samples outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4390 | |
| 4391 | #Param image Image containing pixels, dimensions, and format ## |
| 4392 | #Param center IRect edge of image corners and sides ## |
| 4393 | #Param dst destination Rect of image to draw to ## |
| 4394 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4395 | and so on; or nullptr |
| 4396 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4397 | |
| 4398 | #Example |
| 4399 | #Height 128 |
| 4400 | #Description |
| 4401 | The two leftmost images has four corners and sides to the left and right of center. |
| 4402 | The leftmost image scales the width of corners proportionately to fit. |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 4403 | 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] | 4404 | fill the remaining space. |
| 4405 | The rightmost image has four corners scaled vertically to fit, and uses sides above |
| 4406 | and below center to fill the remaining space. |
| 4407 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4408 | void draw(SkCanvas* canvas) { |
| 4409 | SkIRect center = { 20, 10, 50, 40 }; |
| 4410 | SkBitmap bitmap; |
| 4411 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60)); |
| 4412 | SkCanvas bitCanvas(bitmap); |
| 4413 | SkPaint paint; |
| 4414 | SkColor gray = 0xFF000000; |
| 4415 | int left = 0; |
| 4416 | for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) { |
| 4417 | int top = 0; |
| 4418 | for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) { |
| 4419 | paint.setColor(gray); |
| 4420 | bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint); |
| 4421 | gray += 0x001f1f1f; |
| 4422 | top = bottom; |
| 4423 | } |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 4424 | left = right; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4425 | } |
| 4426 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 4427 | for (auto dest: { 20, 30, 40, 60, 90 } ) { |
| 4428 | canvas->drawImageNine(image, center, SkRect::MakeWH(dest, 110 - dest), nullptr); |
| 4429 | canvas->translate(dest + 4, 0); |
| 4430 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4431 | } |
| 4432 | ## |
| 4433 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4434 | #SeeAlso drawImage drawBitmapNine drawImageLattice drawImageRect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4435 | |
| 4436 | ## |
| 4437 | |
| 4438 | # ------------------------------------------------------------------------------ |
| 4439 | |
| 4440 | #Method void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4441 | const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4442 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4443 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4444 | #Line # draws Bitmap at (x, y) position ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4445 | |
| 4446 | Draw Bitmap bitmap, with its top-left corner at (left, top), |
| 4447 | using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4448 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 4449 | 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] | 4450 | Blend_Mode, and Draw_Looper. If bitmap is kAlpha_8_SkColorType, apply Shader. |
| 4451 | If paint contains Mask_Filter, generate mask from bitmap bounds. |
| 4452 | |
| 4453 | If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, |
| 4454 | just as Shader made from SkShader::MakeBitmapShader with |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4455 | SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 4456 | outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4457 | |
| 4458 | #Param bitmap Bitmap containing pixels, dimensions, and format ## |
| 4459 | #Param left left side of bitmap ## |
| 4460 | #Param top top side of bitmap ## |
| 4461 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4462 | and so on; or nullptr |
| 4463 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4464 | |
| 4465 | #Example |
| 4466 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4467 | void draw(SkCanvas* canvas) { |
| 4468 | uint8_t pixels[][8] = { { 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00}, |
| 4469 | { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00}, |
| 4470 | { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00}, |
| 4471 | { 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF}, |
| 4472 | { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, |
| 4473 | { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00}, |
| 4474 | { 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00}, |
| 4475 | { 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF} }; |
| 4476 | SkBitmap bitmap; |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 4477 | bitmap.installPixels(SkImageInfo::MakeA8(8, 8), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4478 | (void*) pixels, sizeof(pixels[0])); |
| 4479 | SkPaint paint; |
| 4480 | canvas->scale(4, 4); |
| 4481 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xFF007F00} ) { |
| 4482 | paint.setColor(color); |
| 4483 | canvas->drawBitmap(bitmap, 0, 0, &paint); |
| 4484 | canvas->translate(12, 0); |
| 4485 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4486 | } |
| 4487 | ## |
| 4488 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4489 | #SeeAlso drawImage drawBitmapLattice drawBitmapNine drawBitmapRect SkBitmap::readPixels SkBitmap::writePixels |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4490 | |
| 4491 | ## |
| 4492 | |
| 4493 | # ------------------------------------------------------------------------------ |
| 4494 | |
| 4495 | #Method void drawBitmapRect(const SkBitmap& bitmap, const SkRect& src, const SkRect& dst, |
| 4496 | const SkPaint* paint, SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4497 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4498 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4499 | #Line # draws Bitmap, source Rect to destination Rect ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4500 | |
| 4501 | Draw Rect src of Bitmap bitmap, scaled and translated to fill Rect dst. |
| 4502 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4503 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4504 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4505 | Blend_Mode, and Draw_Looper. If bitmap is kAlpha_8_SkColorType, apply Shader. |
| 4506 | If paint contains Mask_Filter, generate mask from bitmap bounds. |
| 4507 | |
| 4508 | If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, |
| 4509 | just as Shader made from SkShader::MakeBitmapShader with |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4510 | SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4511 | outside of its bounds. |
| 4512 | |
| 4513 | constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to |
| 4514 | sample within src; set to kFast_SrcRectConstraint allows sampling outside to |
| 4515 | improve performance. |
| 4516 | |
| 4517 | #Param bitmap Bitmap containing pixels, dimensions, and format ## |
| 4518 | #Param src source Rect of image to draw from ## |
| 4519 | #Param dst destination Rect of image to draw to ## |
| 4520 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4521 | and so on; or nullptr |
| 4522 | ## |
| 4523 | #Param constraint filter strictly within src or draw faster ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4524 | |
| 4525 | #Example |
| 4526 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4527 | void draw(SkCanvas* canvas) { |
| 4528 | uint8_t pixels[][8] = { { 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00}, |
| 4529 | { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00}, |
| 4530 | { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00}, |
| 4531 | { 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF}, |
| 4532 | { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, |
| 4533 | { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00}, |
| 4534 | { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00}, |
| 4535 | { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00} }; |
| 4536 | SkBitmap bitmap; |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 4537 | bitmap.installPixels(SkImageInfo::MakeA8(8, 8), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4538 | (void*) pixels, sizeof(pixels[0])); |
| 4539 | SkPaint paint; |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 4540 | paint.setMaskFilter(SkMaskFilter::MakeBlur(kSolid_SkBlurStyle, 6)); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4541 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xFF007F00} ) { |
| 4542 | paint.setColor(color); |
| 4543 | canvas->drawBitmapRect(bitmap, SkRect::MakeWH(8, 8), SkRect::MakeWH(32, 32), &paint); |
| 4544 | canvas->translate(48, 0); |
| 4545 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4546 | } |
| 4547 | ## |
| 4548 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4549 | #SeeAlso drawImageRect drawBitmap drawBitmapLattice drawBitmapNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4550 | |
| 4551 | ## |
| 4552 | |
| 4553 | # ------------------------------------------------------------------------------ |
| 4554 | |
| 4555 | #Method void drawBitmapRect(const SkBitmap& bitmap, const SkIRect& isrc, const SkRect& dst, |
| 4556 | const SkPaint* paint, SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4557 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4558 | #In Draw |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4559 | 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] | 4560 | isrc is on integer pixel boundaries; dst may include fractional boundaries. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4561 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4562 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4563 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4564 | Blend_Mode, and Draw_Looper. If bitmap is kAlpha_8_SkColorType, apply Shader. |
| 4565 | If paint contains Mask_Filter, generate mask from bitmap bounds. |
| 4566 | |
| 4567 | If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, |
| 4568 | just as Shader made from SkShader::MakeBitmapShader with |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4569 | SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4570 | outside of its bounds. |
| 4571 | |
| 4572 | constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4573 | sample within isrc; set to kFast_SrcRectConstraint allows sampling outside to |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4574 | improve performance. |
| 4575 | |
| 4576 | #Param bitmap Bitmap containing pixels, dimensions, and format ## |
| 4577 | #Param isrc source IRect of image to draw from ## |
| 4578 | #Param dst destination Rect of image to draw to ## |
| 4579 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4580 | and so on; or nullptr |
| 4581 | ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4582 | #Param constraint sample strictly within isrc, or draw faster ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4583 | |
| 4584 | #Example |
| 4585 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4586 | void draw(SkCanvas* canvas) { |
| 4587 | uint8_t pixels[][8] = { { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00}, |
| 4588 | { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00}, |
| 4589 | { 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF}, |
| 4590 | { 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF}, |
| 4591 | { 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF}, |
| 4592 | { 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF}, |
| 4593 | { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00}, |
| 4594 | { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00} }; |
| 4595 | SkBitmap bitmap; |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 4596 | bitmap.installPixels(SkImageInfo::MakeA8(8, 8), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4597 | (void*) pixels, sizeof(pixels[0])); |
| 4598 | SkPaint paint; |
| 4599 | paint.setFilterQuality(kHigh_SkFilterQuality); |
| 4600 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xFF007F00, 0xFF7f007f} ) { |
| 4601 | paint.setColor(color); |
| 4602 | canvas->drawBitmapRect(bitmap, SkIRect::MakeWH(8, 8), SkRect::MakeWH(32, 32), &paint); |
| 4603 | canvas->translate(48.25f, 0); |
| 4604 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4605 | } |
| 4606 | ## |
| 4607 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4608 | #SeeAlso drawImageRect drawBitmap drawBitmapLattice drawBitmapNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4609 | |
| 4610 | ## |
| 4611 | |
| 4612 | # ------------------------------------------------------------------------------ |
| 4613 | |
| 4614 | #Method void drawBitmapRect(const SkBitmap& bitmap, const SkRect& dst, const SkPaint* paint, |
| 4615 | SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4616 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4617 | #In Draw |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4618 | Draw Bitmap bitmap, scaled and translated to fill Rect dst. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4619 | bitmap bounds is on integer pixel boundaries; dst may include fractional boundaries. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4620 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4621 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4622 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4623 | Blend_Mode, and Draw_Looper. If bitmap is kAlpha_8_SkColorType, apply Shader. |
| 4624 | If paint contains Mask_Filter, generate mask from bitmap bounds. |
| 4625 | |
| 4626 | If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, |
| 4627 | just as Shader made from SkShader::MakeBitmapShader with |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4628 | SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4629 | outside of its bounds. |
| 4630 | |
| 4631 | constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4632 | sample within bitmap; set to kFast_SrcRectConstraint allows sampling outside to |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4633 | improve performance. |
| 4634 | |
| 4635 | #Param bitmap Bitmap containing pixels, dimensions, and format ## |
| 4636 | #Param dst destination Rect of image to draw to ## |
| 4637 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4638 | and so on; or nullptr |
| 4639 | ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4640 | #Param constraint filter strictly within bitmap or draw faster ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4641 | |
| 4642 | #Example |
| 4643 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4644 | void draw(SkCanvas* canvas) { |
| 4645 | uint32_t pixels[][2] = { { 0x00000000, 0x55550000}, |
| 4646 | { 0xAAAA0000, 0xFFFF0000} }; |
| 4647 | SkBitmap bitmap; |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 4648 | bitmap.installPixels(SkImageInfo::MakeN32Premul(2, 2), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4649 | (void*) pixels, sizeof(pixels[0])); |
| 4650 | SkPaint paint; |
| 4651 | canvas->scale(4, 4); |
| 4652 | for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN } ) { |
| 4653 | paint.setColorFilter(SkColorFilter::MakeModeFilter(color, SkBlendMode::kPlus)); |
| 4654 | canvas->drawBitmapRect(bitmap, SkRect::MakeWH(8, 8), &paint); |
| 4655 | canvas->translate(8, 0); |
| 4656 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4657 | } |
| 4658 | ## |
| 4659 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4660 | #SeeAlso drawImageRect drawBitmap drawBitmapLattice drawBitmapNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4661 | |
| 4662 | ## |
| 4663 | |
| 4664 | # ------------------------------------------------------------------------------ |
| 4665 | |
| 4666 | #Method void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4667 | const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4668 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4669 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4670 | #Line # draws Nine_Patch Bitmap ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4671 | |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 4672 | Draw Bitmap bitmap stretched proportionally to fit into Rect dst. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4673 | IRect center divides the bitmap into nine sections: four sides, four corners, |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4674 | 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] | 4675 | sides are larger than dst; center and four sides are scaled to fit remaining |
| 4676 | space, if any. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4677 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4678 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
| 4679 | |
| 4680 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4681 | Blend_Mode, and Draw_Looper. If bitmap is kAlpha_8_SkColorType, apply Shader. |
| 4682 | If paint contains Mask_Filter, generate mask from bitmap bounds. |
| 4683 | |
| 4684 | If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, |
| 4685 | just as Shader made from SkShader::MakeBitmapShader with |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4686 | SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4687 | outside of its bounds. |
| 4688 | |
| 4689 | #Param bitmap Bitmap containing pixels, dimensions, and format ## |
| 4690 | #Param center IRect edge of image corners and sides ## |
| 4691 | #Param dst destination Rect of image to draw to ## |
| 4692 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4693 | and so on; or nullptr |
| 4694 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4695 | |
| 4696 | #Example |
| 4697 | #Height 128 |
| 4698 | #Description |
| 4699 | The two leftmost bitmap draws has four corners and sides to the left and right of center. |
| 4700 | The leftmost bitmap draw scales the width of corners proportionately to fit. |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 4701 | 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] | 4702 | fill the remaining space. |
| 4703 | The rightmost bitmap draw has four corners scaled vertically to fit, and uses sides above |
| 4704 | and below center to fill the remaining space. |
| 4705 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4706 | void draw(SkCanvas* canvas) { |
| 4707 | SkIRect center = { 20, 10, 50, 40 }; |
| 4708 | SkBitmap bitmap; |
| 4709 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60)); |
| 4710 | SkCanvas bitCanvas(bitmap); |
| 4711 | SkPaint paint; |
| 4712 | SkColor gray = 0xFF000000; |
| 4713 | int left = 0; |
| 4714 | for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) { |
| 4715 | int top = 0; |
| 4716 | for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) { |
| 4717 | paint.setColor(gray); |
| 4718 | bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint); |
| 4719 | gray += 0x001f1f1f; |
| 4720 | top = bottom; |
| 4721 | } |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 4722 | left = right; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4723 | } |
| 4724 | for (auto dest: { 20, 30, 40, 60, 90 } ) { |
| 4725 | canvas->drawBitmapNine(bitmap, center, SkRect::MakeWH(dest, 110 - dest), nullptr); |
| 4726 | canvas->translate(dest + 4, 0); |
| 4727 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4728 | } |
| 4729 | ## |
| 4730 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4731 | #SeeAlso drawImageNine drawBitmap drawBitmapLattice drawBitmapRect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4732 | |
| 4733 | ## |
| 4734 | |
| 4735 | # ------------------------------------------------------------------------------ |
| 4736 | #Struct Lattice |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 4737 | #Line # divides Bitmap or Image into a rectangular grid ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4738 | #Code |
| 4739 | struct Lattice { |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4740 | enum RectType ... |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4741 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4742 | const int* fXDivs; |
| 4743 | const int* fYDivs; |
| 4744 | const RectType* fRectTypes; |
| 4745 | int fXCount; |
| 4746 | int fYCount; |
| 4747 | const SkIRect* fBounds; |
| 4748 | const SkColor* fColors; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4749 | }; |
| 4750 | ## |
| 4751 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 4752 | Lattice divides Bitmap or Image into a rectangular grid. |
| 4753 | Grid entries on even columns and even rows are fixed; these entries are |
| 4754 | always drawn at their original size if the destination is large enough. |
| 4755 | If the destination side is too small to hold the fixed entries, all fixed |
| 4756 | entries are proportionately scaled down to fit. |
| 4757 | The grid entries not on even columns and rows are scaled to fit the |
| 4758 | remaining space, if any. |
| 4759 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4760 | #Enum RectType |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4761 | #Code |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4762 | enum RectType : uint8_t { |
| 4763 | kDefault = 0, |
| 4764 | kTransparent, |
| 4765 | kFixedColor, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4766 | }; |
| 4767 | ## |
| 4768 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4769 | Optional setting per rectangular grid entry to make it transparent, |
| 4770 | or to fill the grid entry with a color. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4771 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4772 | #Const kDefault 0 |
| 4773 | Draws Bitmap into lattice rectangle. |
| 4774 | ## |
| 4775 | |
| 4776 | #Const kTransparent 1 |
| 4777 | Skips lattice rectangle by making it transparent. |
| 4778 | ## |
| 4779 | |
| 4780 | #Const kFixedColor 2 |
| 4781 | Draws one of fColors into lattice rectangle. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4782 | ## |
| 4783 | ## |
| 4784 | |
| 4785 | #Member const int* fXDivs |
| 4786 | Array of x-coordinates that divide the bitmap vertically. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4787 | Array entries must be unique, increasing, greater than or equal to |
| 4788 | fBounds left edge, and less than fBounds right edge. |
| 4789 | Set the first element to fBounds left to collapse the left column of |
| 4790 | fixed grid entries. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4791 | ## |
| 4792 | |
| 4793 | #Member const int* fYDivs |
| 4794 | Array of y-coordinates that divide the bitmap horizontally. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4795 | Array entries must be unique, increasing, greater than or equal to |
| 4796 | fBounds top edge, and less than fBounds bottom edge. |
| 4797 | Set the first element to fBounds top to collapse the top row of fixed |
| 4798 | grid entries. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4799 | ## |
| 4800 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4801 | #Member const RectType* fRectTypes |
| 4802 | Optional array of fill types, one per rectangular grid entry: |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4803 | array length must be |
| 4804 | #Formula |
| 4805 | (fXCount + 1) * (fYCount + 1) |
| 4806 | ## |
| 4807 | . |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 4808 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4809 | Each RectType is one of: kDefault, kTransparent, kFixedColor. |
| 4810 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4811 | Array entries correspond to the rectangular grid entries, ascending |
| 4812 | left to right and then top to bottom. |
| 4813 | ## |
| 4814 | |
| 4815 | #Member int fXCount |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4816 | Number of entries in fXDivs array; one less than the number of |
| 4817 | horizontal divisions. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4818 | ## |
| 4819 | |
| 4820 | #Member int fYCount |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4821 | Number of entries in fYDivs array; one less than the number of vertical |
| 4822 | divisions. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4823 | ## |
| 4824 | |
| 4825 | #Member const SkIRect* fBounds |
| 4826 | Optional subset IRect source to draw from. |
| 4827 | If nullptr, source bounds is dimensions of Bitmap or Image. |
| 4828 | ## |
| 4829 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4830 | #Member const SkColor* fColors |
| 4831 | Optional array of colors, one per rectangular grid entry. |
| 4832 | Array length must be |
| 4833 | #Formula |
| 4834 | (fXCount + 1) * (fYCount + 1) |
| 4835 | ## |
| 4836 | . |
| 4837 | |
| 4838 | Array entries correspond to the rectangular grid entries, ascending |
| 4839 | left to right, then top to bottom. |
| 4840 | ## |
| 4841 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4842 | #Struct Lattice ## |
| 4843 | |
| 4844 | #Method void drawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice, const SkRect& dst, |
| 4845 | const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4846 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4847 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4848 | #Line # draws proportionally stretched Bitmap ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4849 | |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 4850 | Draw Bitmap bitmap stretched proportionally to fit into Rect dst. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4851 | |
| 4852 | Lattice lattice divides bitmap into a rectangular grid. |
| 4853 | 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] | 4854 | of drawBitmapNine, fixed lattice elements never scale larger than their initial |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4855 | size and shrink proportionately when all fixed elements exceed the bitmap |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4856 | 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] | 4857 | |
| 4858 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4859 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4860 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4861 | Blend_Mode, and Draw_Looper. If bitmap is kAlpha_8_SkColorType, apply Shader. |
| 4862 | If paint contains Mask_Filter, generate mask from bitmap bounds. |
| 4863 | |
| 4864 | If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, |
| 4865 | just as Shader made from SkShader::MakeBitmapShader with |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4866 | SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4867 | outside of its bounds. |
| 4868 | |
| 4869 | #Param bitmap Bitmap containing pixels, dimensions, and format ## |
| 4870 | #Param lattice division of bitmap into fixed and variable rectangles ## |
| 4871 | #Param dst destination Rect of image to draw to ## |
| 4872 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4873 | and so on; or nullptr |
| 4874 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4875 | |
| 4876 | #Example |
| 4877 | #Height 128 |
| 4878 | #Description |
| 4879 | The two leftmost bitmap draws has four corners and sides to the left and right of center. |
| 4880 | The leftmost bitmap draw scales the width of corners proportionately to fit. |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 4881 | 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] | 4882 | fill the remaining space; the center is transparent. |
| 4883 | The rightmost bitmap draw has four corners scaled vertically to fit, and uses sides above |
| 4884 | and below center to fill the remaining space. |
| 4885 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4886 | void draw(SkCanvas* canvas) { |
| 4887 | SkIRect center = { 20, 10, 50, 40 }; |
| 4888 | SkBitmap bitmap; |
| 4889 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60)); |
| 4890 | SkCanvas bitCanvas(bitmap); |
| 4891 | SkPaint paint; |
| 4892 | SkColor gray = 0xFF000000; |
| 4893 | int left = 0; |
| 4894 | for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) { |
| 4895 | int top = 0; |
| 4896 | for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) { |
| 4897 | paint.setColor(gray); |
| 4898 | bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint); |
| 4899 | gray += 0x001f1f1f; |
| 4900 | top = bottom; |
| 4901 | } |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 4902 | left = right; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4903 | } |
| 4904 | const int xDivs[] = { center.fLeft, center.fRight }; |
| 4905 | const int yDivs[] = { center.fTop, center.fBottom }; |
Cary Clark | ca3ebcd | 2017-12-12 11:22:38 -0500 | [diff] [blame] | 4906 | SkCanvas::Lattice::RectType fillTypes[3][3]; |
| 4907 | memset(fillTypes, 0, sizeof(fillTypes)); |
| 4908 | fillTypes[1][1] = SkCanvas::Lattice::kTransparent; |
| 4909 | SkColor dummy[9]; // temporary pending bug fix |
| 4910 | SkCanvas::Lattice lattice = { xDivs, yDivs, fillTypes[0], SK_ARRAY_COUNT(xDivs), |
| 4911 | SK_ARRAY_COUNT(yDivs), nullptr, dummy }; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4912 | for (auto dest: { 20, 30, 40, 60, 90 } ) { |
Cary Clark | ca3ebcd | 2017-12-12 11:22:38 -0500 | [diff] [blame] | 4913 | canvas->drawBitmapLattice(bitmap, lattice, SkRect::MakeWH(dest, 110 - dest), nullptr); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4914 | canvas->translate(dest + 4, 0); |
| 4915 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4916 | } |
| 4917 | ## |
| 4918 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4919 | #SeeAlso drawImageLattice drawBitmap drawBitmapNine Lattice |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4920 | |
| 4921 | ## |
| 4922 | |
| 4923 | # ------------------------------------------------------------------------------ |
| 4924 | |
| 4925 | #Method void drawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst, |
| 4926 | const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4927 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4928 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4929 | #Line # draws proportionally stretched Image ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4930 | |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 4931 | Draw Image image stretched proportionally to fit into Rect dst. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4932 | |
| 4933 | Lattice lattice divides image into a rectangular grid. |
| 4934 | 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] | 4935 | of drawBitmapNine, fixed lattice elements never scale larger than their initial |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4936 | size and shrink proportionately when all fixed elements exceed the bitmap |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4937 | 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] | 4938 | |
| 4939 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4940 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4941 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4942 | Blend_Mode, and Draw_Looper. If bitmap is kAlpha_8_SkColorType, apply Shader. |
| 4943 | If paint contains Mask_Filter, generate mask from bitmap bounds. |
| 4944 | |
| 4945 | If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, |
| 4946 | just as Shader made from SkShader::MakeBitmapShader with |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4947 | SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4948 | outside of its bounds. |
| 4949 | |
| 4950 | #Param image Image containing pixels, dimensions, and format ## |
| 4951 | #Param lattice division of bitmap into fixed and variable rectangles ## |
| 4952 | #Param dst destination Rect of image to draw to ## |
| 4953 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4954 | and so on; or nullptr |
| 4955 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4956 | |
| 4957 | #Example |
| 4958 | #Height 128 |
| 4959 | #Description |
| 4960 | 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] | 4961 | The second image equals the size of center; only corners are drawn without scaling. |
| 4962 | 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] | 4963 | are scaled if needed to take up the remaining space; the center is transparent. |
| 4964 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4965 | void draw(SkCanvas* canvas) { |
| 4966 | SkIRect center = { 20, 10, 50, 40 }; |
| 4967 | SkBitmap bitmap; |
| 4968 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60)); |
| 4969 | SkCanvas bitCanvas(bitmap); |
| 4970 | SkPaint paint; |
| 4971 | SkColor gray = 0xFF000000; |
| 4972 | int left = 0; |
| 4973 | for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) { |
| 4974 | int top = 0; |
| 4975 | for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) { |
| 4976 | paint.setColor(gray); |
| 4977 | bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint); |
| 4978 | gray += 0x001f1f1f; |
| 4979 | top = bottom; |
| 4980 | } |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 4981 | left = right; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4982 | } |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4983 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 4984 | SkImage* imagePtr = image.get(); |
| 4985 | for (auto dest: { 20, 30, 40, 60, 90 } ) { |
| 4986 | canvas->drawImageNine(imagePtr, center, SkRect::MakeWH(dest, dest), nullptr); |
| 4987 | canvas->translate(dest + 4, 0); |
| 4988 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4989 | } |
| 4990 | ## |
| 4991 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4992 | #SeeAlso drawBitmapLattice drawImage drawImageNine Lattice |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4993 | |
| 4994 | ## |
| 4995 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 4996 | #Subtopic Draw_Image ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4997 | |
| 4998 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4999 | #Subtopic Draw_Text |
| 5000 | #Populate |
| 5001 | #Line # draws text into Canvas ## |
| 5002 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5003 | |
| 5004 | #Method void drawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, |
| 5005 | const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5006 | #In Draw_Text |
| 5007 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5008 | #Line # draws text at (x, y), using font advance ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5009 | |
| 5010 | 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] | 5011 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5012 | 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] | 5013 | UTF-8. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5014 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5015 | 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] | 5016 | text draws left to right, positioning the first glyph left side bearing at x |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5017 | 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] | 5018 | |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 5019 | All elements of paint: Path_Effect, Mask_Filter, Shader, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5020 | 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] | 5021 | filled 12 point black Glyphs. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5022 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5023 | #Param text character code points or Glyphs drawn ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5024 | #Param byteLength byte length of text array ## |
| 5025 | #Param x start of text on x-axis ## |
| 5026 | #Param y start of text on y-axis ## |
| 5027 | #Param paint text size, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5028 | |
| 5029 | #Example |
| 5030 | #Height 200 |
| 5031 | #Description |
| 5032 | The same text is drawn varying Paint_Text_Size and varying |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5033 | Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5034 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5035 | void draw(SkCanvas* canvas) { |
| 5036 | SkPaint paint; |
| 5037 | paint.setAntiAlias(true); |
| 5038 | float textSizes[] = { 12, 18, 24, 36 }; |
| 5039 | for (auto size: textSizes ) { |
| 5040 | paint.setTextSize(size); |
| 5041 | canvas->drawText("Aa", 2, 10, 20, paint); |
| 5042 | canvas->translate(0, size * 2); |
| 5043 | } |
| 5044 | paint.reset(); |
| 5045 | paint.setAntiAlias(true); |
| 5046 | float yPos = 20; |
| 5047 | for (auto size: textSizes ) { |
| 5048 | float scale = size / 12.f; |
| 5049 | canvas->resetMatrix(); |
| 5050 | canvas->translate(100, 0); |
| 5051 | canvas->scale(scale, scale); |
| 5052 | canvas->drawText("Aa", 2, 10 / scale, yPos / scale, paint); |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5053 | yPos += size * 2; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5054 | } |
| 5055 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5056 | ## |
| 5057 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5058 | #SeeAlso drawString drawPosText drawPosTextH drawTextBlob drawTextOnPath drawTextRSXform |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5059 | |
| 5060 | ## |
| 5061 | |
| 5062 | #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] | 5063 | #In Draw_Text |
| 5064 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5065 | #Line # draws null terminated string at (x, y) using font advance ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5066 | Draw null terminated string, with origin at (x, y), using Clip, Matrix, and |
Mike Reed | 9c2916e | 2018-03-15 13:37:08 -0400 | [diff] [blame] | 5067 | Paint paint. Note that this per-glyph xform does not affect the shader (if present) |
| 5068 | on the paint, just the glyph's geometry. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5069 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5070 | string meaning depends on Paint_Text_Encoding; by default, strings are encoded |
| 5071 | 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] | 5072 | results, since zero bytes may be embedded in the string. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5073 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5074 | 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] | 5075 | string draws left to right, positioning the first glyph left side bearing at x |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5076 | 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] | 5077 | |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 5078 | All elements of paint: Path_Effect, Mask_Filter, Shader, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5079 | 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] | 5080 | filled 12 point black Glyphs. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5081 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5082 | #Param string character code points or Glyphs drawn, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5083 | ending with a char value of zero |
| 5084 | ## |
| 5085 | #Param x start of string on x-axis ## |
| 5086 | #Param y start of string on y-axis ## |
| 5087 | #Param paint text size, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5088 | |
| 5089 | #Example |
| 5090 | SkPaint paint; |
| 5091 | canvas->drawString("a small hello", 20, 20, paint); |
| 5092 | ## |
| 5093 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5094 | #SeeAlso drawText drawPosText drawPosTextH drawTextBlob drawTextOnPath drawTextRSXform |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5095 | |
| 5096 | ## |
| 5097 | |
| 5098 | #Method void drawString(const SkString& string, SkScalar x, SkScalar y, const SkPaint& paint) |
| 5099 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5100 | Draw null terminated string, with origin at (x, y), using Clip, Matrix, and |
| 5101 | Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5102 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5103 | string meaning depends on Paint_Text_Encoding; by default, strings are encoded |
| 5104 | 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] | 5105 | results, since zero bytes may be embedded in the string. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5106 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5107 | 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] | 5108 | string draws left to right, positioning the first glyph left side bearing at x |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5109 | 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] | 5110 | |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 5111 | All elements of paint: Path_Effect, Mask_Filter, Shader, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5112 | 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] | 5113 | filled 12 point black Glyphs. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5114 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5115 | #Param string character code points or Glyphs drawn, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5116 | ending with a char value of zero |
| 5117 | ## |
| 5118 | #Param x start of string on x-axis ## |
| 5119 | #Param y start of string on y-axis ## |
| 5120 | #Param paint text size, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5121 | |
| 5122 | #Example |
| 5123 | SkPaint paint; |
| 5124 | SkString string("a small hello"); |
| 5125 | canvas->drawString(string, 20, 20, paint); |
| 5126 | ## |
| 5127 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5128 | #SeeAlso drawText drawPosText drawPosTextH drawTextBlob drawTextOnPath drawTextRSXform |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5129 | |
| 5130 | ## |
| 5131 | |
| 5132 | # ------------------------------------------------------------------------------ |
| 5133 | |
| 5134 | #Method void drawPosText(const void* text, size_t byteLength, const SkPoint pos[], |
| 5135 | const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5136 | #In Draw_Text |
| 5137 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5138 | #Line # draws text at array of (x, y) positions ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5139 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5140 | 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] | 5141 | 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] | 5142 | described by byteLength of text. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5143 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5144 | 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] | 5145 | UTF-8. pos elements' meaning depends on Paint_Text_Align and Paint_Vertical_Text; |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5146 | 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] | 5147 | baseline is positioned at y. Text size is affected by Matrix and |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5148 | Paint_Text_Size. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5149 | |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 5150 | All elements of paint: Path_Effect, Mask_Filter, Shader, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5151 | 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] | 5152 | filled 12 point black Glyphs. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5153 | |
| 5154 | Layout engines such as Harfbuzz typically position each glyph |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5155 | rather than using the font advance widths. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5156 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5157 | #Param text character code points or Glyphs drawn ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5158 | #Param byteLength byte length of text array ## |
| 5159 | #Param pos array of glyph origins ## |
| 5160 | #Param paint text size, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5161 | |
| 5162 | #Example |
| 5163 | #Height 120 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5164 | void draw(SkCanvas* canvas) { |
| 5165 | const char hello[] = "HeLLo!"; |
| 5166 | const SkPoint pos[] = { {40, 100}, {82, 95}, {115, 110}, {130, 95}, {145, 85}, |
| 5167 | {172, 100} }; |
| 5168 | SkPaint paint; |
| 5169 | paint.setTextSize(60); |
| 5170 | canvas->drawPosText(hello, strlen(hello), pos, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5171 | } |
| 5172 | ## |
| 5173 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5174 | #SeeAlso drawText drawPosTextH drawTextBlob drawTextOnPath drawTextRSXform |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5175 | |
| 5176 | ## |
| 5177 | |
| 5178 | # ------------------------------------------------------------------------------ |
| 5179 | |
| 5180 | #Method void drawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], SkScalar constY, |
| 5181 | const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5182 | #In Draw_Text |
| 5183 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5184 | #Line # draws text at x positions with common baseline ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5185 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5186 | Draw each glyph in text with its (x, y) origin composed from xpos array and |
| 5187 | 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] | 5188 | must match the number of Glyphs described by byteLength of text. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5189 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5190 | text meaning depends on Paint_Text_Encoding; by default, text is encoded as |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5191 | UTF-8. xpos elements' meaning depends on Paint_Text_Align and Paint_Vertical_Text; |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5192 | 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] | 5193 | its baseline is positioned at constY. Text size is affected by Matrix and |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5194 | Paint_Text_Size. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5195 | |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 5196 | All elements of paint: Path_Effect, Mask_Filter, Shader, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5197 | 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] | 5198 | filled 12 point black Glyphs. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5199 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5200 | Layout engines such as Harfbuzz typically position each glyph |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5201 | 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] | 5202 | baseline. |
| 5203 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5204 | #Param text character code points or Glyphs drawn ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5205 | #Param byteLength byte length of text array ## |
| 5206 | #Param xpos array of x positions, used to position each glyph ## |
| 5207 | #Param constY shared y coordinate for all of x positions ## |
| 5208 | #Param paint text size, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5209 | |
| 5210 | #Example |
| 5211 | #Height 40 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5212 | void draw(SkCanvas* canvas) { |
| 5213 | SkScalar xpos[] = { 20, 40, 80, 160 }; |
| 5214 | SkPaint paint; |
| 5215 | canvas->drawPosTextH("XXXX", 4, xpos, 20, paint); |
| 5216 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5217 | ## |
| 5218 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5219 | #SeeAlso drawText drawPosText drawTextBlob drawTextOnPath drawTextRSXform |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5220 | |
| 5221 | ## |
| 5222 | |
| 5223 | # ------------------------------------------------------------------------------ |
| 5224 | |
| 5225 | #Method void drawTextOnPathHV(const void* text, size_t byteLength, const SkPath& path, SkScalar hOffset, |
| 5226 | SkScalar vOffset, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5227 | #In Draw_Text |
| 5228 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5229 | #Line # draws text following Path with offsets ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5230 | |
| 5231 | Draw text on Path path, using Clip, Matrix, and Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5232 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5233 | Origin of text is at distance hOffset along the path, offset by a perpendicular |
| 5234 | vector of length vOffset. If the path section corresponding the glyph advance is |
| 5235 | 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] | 5236 | 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] | 5237 | than the path length, the excess text is clipped. |
| 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 | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5240 | 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] | 5241 | default text positions the first glyph left side bearing at origin x and its |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5242 | 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] | 5243 | |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 5244 | All elements of paint: Path_Effect, Mask_Filter, Shader, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5245 | 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] | 5246 | filled 12 point black Glyphs. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5247 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5248 | #Param text character code points or Glyphs drawn ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5249 | #Param byteLength byte length of text array ## |
| 5250 | #Param path Path providing text baseline ## |
| 5251 | #Param hOffset distance along path to offset origin ## |
| 5252 | #Param vOffset offset of text above (if negative) or below (if positive) the path ## |
| 5253 | #Param paint text size, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5254 | |
| 5255 | #Example |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5256 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5257 | const char aero[] = "correo a" "\xC3" "\xA9" "reo"; |
| 5258 | const size_t len = sizeof(aero) - 1; |
| 5259 | SkPath path; |
| 5260 | path.addOval({43-26, 43-26, 43+26, 43+26}, SkPath::kCW_Direction, 3); |
| 5261 | SkPaint paint; |
| 5262 | paint.setTextSize(24); |
| 5263 | for (auto offset : { 0, 10, 20 } ) { |
| 5264 | canvas->drawTextOnPathHV(aero, len, path, 0, -offset, paint); |
| 5265 | canvas->translate(70 + offset, 70 + offset); |
| 5266 | } |
| 5267 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5268 | ## |
| 5269 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5270 | #SeeAlso drawTextOnPath drawText drawPosTextH drawTextBlob drawTextRSXform |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5271 | |
| 5272 | ## |
| 5273 | |
| 5274 | # ------------------------------------------------------------------------------ |
| 5275 | |
| 5276 | #Method void drawTextOnPath(const void* text, size_t byteLength, const SkPath& path, |
| 5277 | const SkMatrix* matrix, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5278 | #In Draw_Text |
| 5279 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5280 | #Line # draws text following Path contour ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5281 | |
| 5282 | Draw text on Path path, using Clip, Matrix, and Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5283 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5284 | Origin of text is at beginning of path offset by matrix, if provided, before it |
| 5285 | is mapped to path. If the path section corresponding the glyph advance is |
| 5286 | 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] | 5287 | 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] | 5288 | than the path length, the excess text is clipped. |
| 5289 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5290 | 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] | 5291 | 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] | 5292 | default text positions the first glyph left side bearing at origin x and its |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5293 | 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] | 5294 | |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 5295 | All elements of paint: Path_Effect, Mask_Filter, Shader, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5296 | 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] | 5297 | filled 12 point black Glyphs. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5298 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5299 | #Param text character code points or Glyphs drawn ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5300 | #Param byteLength byte length of text array ## |
| 5301 | #Param path Path providing text baseline ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5302 | #Param matrix transform of Glyphs before mapping to path; may be nullptr |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 5303 | to use identity Matrix |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5304 | ## |
| 5305 | #Param paint text size, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5306 | |
| 5307 | #Example |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5308 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5309 | const char roller[] = "rollercoaster"; |
| 5310 | const size_t len = sizeof(roller) - 1; |
| 5311 | SkPath path; |
| 5312 | path.cubicTo(40, -80, 120, 80, 160, -40); |
| 5313 | SkPaint paint; |
| 5314 | paint.setTextSize(32); |
| 5315 | paint.setStyle(SkPaint::kStroke_Style); |
| 5316 | SkMatrix matrix; |
| 5317 | matrix.setIdentity(); |
| 5318 | for (int i = 0; i < 3; ++i) { |
| 5319 | canvas->translate(25, 60); |
| 5320 | canvas->drawPath(path, paint); |
| 5321 | canvas->drawTextOnPath(roller, len, path, &matrix, paint); |
| 5322 | matrix.preTranslate(0, 10); |
| 5323 | } |
| 5324 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5325 | ## |
| 5326 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5327 | #SeeAlso drawTextOnPathHV drawText drawPosTextH drawTextBlob drawTextRSXform |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5328 | |
| 5329 | ## |
| 5330 | |
| 5331 | # ------------------------------------------------------------------------------ |
| 5332 | |
| 5333 | #Method void drawTextRSXform(const void* text, size_t byteLength, const SkRSXform xform[], |
| 5334 | const SkRect* cullRect, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5335 | #In Draw_Text |
| 5336 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5337 | #Line # draws text with array of RSXform ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5338 | |
| 5339 | Draw text, transforming each glyph by the corresponding SkRSXform, |
| 5340 | using Clip, Matrix, and Paint paint. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5341 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5342 | RSXform array specifies a separate square scale, rotation, and translation for |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5343 | each glyph. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5344 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5345 | Optional Rect cullRect is a conservative bounds of text, taking into account |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5346 | 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] | 5347 | |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 5348 | All elements of paint: Path_Effect, Mask_Filter, Shader, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5349 | 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] | 5350 | filled 12 point black Glyphs. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5351 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5352 | #Param text character code points or Glyphs drawn ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5353 | #Param byteLength byte length of text array ## |
| 5354 | #Param xform RSXform rotates, scales, and translates each glyph individually ## |
| 5355 | #Param cullRect Rect bounds of text for efficient clipping; or nullptr ## |
| 5356 | #Param paint text size, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5357 | |
| 5358 | #Example |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5359 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5360 | const int iterations = 26; |
| 5361 | SkRSXform transforms[iterations]; |
| 5362 | char alphabet[iterations]; |
| 5363 | SkScalar angle = 0; |
| 5364 | SkScalar scale = 1; |
| 5365 | for (size_t i = 0; i < SK_ARRAY_COUNT(transforms); ++i) { |
| 5366 | const SkScalar s = SkScalarSin(angle) * scale; |
| 5367 | const SkScalar c = SkScalarCos(angle) * scale; |
| 5368 | transforms[i] = SkRSXform::Make(-c, -s, -s * 16, c * 16); |
| 5369 | angle += .45; |
| 5370 | scale += .2; |
| 5371 | alphabet[i] = 'A' + i; |
| 5372 | } |
| 5373 | SkPaint paint; |
| 5374 | paint.setTextAlign(SkPaint::kCenter_Align); |
| 5375 | canvas->translate(110, 138); |
| 5376 | canvas->drawTextRSXform(alphabet, sizeof(alphabet), transforms, nullptr, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5377 | } |
| 5378 | ## |
| 5379 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5380 | #SeeAlso drawTextOnPath drawTextOnPathHV drawText drawPosText drawTextBlob |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5381 | |
| 5382 | ## |
| 5383 | |
| 5384 | # ------------------------------------------------------------------------------ |
| 5385 | |
| 5386 | #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] | 5387 | #In Draw_Text |
| 5388 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5389 | #Line # draws text with arrays of positions and Paint ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5390 | 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] | 5391 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5392 | blob contains Glyphs, their positions, and paint attributes specific to text: |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5393 | Typeface, Paint_Text_Size, Paint_Text_Scale_X, Paint_Text_Skew_X, |
| 5394 | Paint_Text_Align, Paint_Hinting, Anti-alias, Paint_Fake_Bold, |
| 5395 | Font_Embedded_Bitmaps, Full_Hinting_Spacing, LCD_Text, Linear_Text, |
| 5396 | Subpixel_Text, and Paint_Vertical_Text. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5397 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 5398 | Paint_Text_Encoding must be set to SkPaint::kGlyphID_TextEncoding. |
| 5399 | |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 5400 | Elements of paint: Path_Effect, Mask_Filter, Shader, Color_Filter, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5401 | Image_Filter, and Draw_Looper; apply to blob. |
| 5402 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5403 | #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] | 5404 | #Param x horizontal offset applied to blob ## |
| 5405 | #Param y vertical offset applied to blob ## |
| 5406 | #Param paint blend, color, stroking, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5407 | |
| 5408 | #Example |
| 5409 | #Height 120 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5410 | void draw(SkCanvas* canvas) { |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 5411 | SkTextBlobBuilder textBlobBuilder; |
| 5412 | const char bunny[] = "/(^x^)\\"; |
| 5413 | const int len = sizeof(bunny) - 1; |
| 5414 | uint16_t glyphs[len]; |
| 5415 | SkPaint paint; |
| 5416 | paint.textToGlyphs(bunny, len, glyphs); |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 5417 | paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 5418 | int runs[] = { 3, 1, 3 }; |
| 5419 | SkPoint textPos = { 20, 100 }; |
| 5420 | int glyphIndex = 0; |
| 5421 | for (auto runLen : runs) { |
| 5422 | paint.setTextSize(1 == runLen ? 20 : 50); |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5423 | const SkTextBlobBuilder::RunBuffer& run = |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 5424 | textBlobBuilder.allocRun(paint, runLen, textPos.fX, textPos.fY); |
| 5425 | memcpy(run.glyphs, &glyphs[glyphIndex], sizeof(glyphs[0]) * runLen); |
| 5426 | textPos.fX += paint.measureText(&glyphs[glyphIndex], sizeof(glyphs[0]) * runLen, nullptr); |
| 5427 | glyphIndex += runLen; |
| 5428 | } |
| 5429 | sk_sp<const SkTextBlob> blob = textBlobBuilder.make(); |
| 5430 | paint.reset(); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5431 | canvas->drawTextBlob(blob.get(), 0, 0, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5432 | } |
| 5433 | ## |
| 5434 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5435 | #SeeAlso drawText drawPosText drawPosTextH |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5436 | |
| 5437 | ## |
| 5438 | |
| 5439 | # ------------------------------------------------------------------------------ |
| 5440 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5441 | #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] | 5442 | |
| 5443 | 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] | 5444 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5445 | blob contains Glyphs, their positions, and paint attributes specific to text: |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5446 | Typeface, Paint_Text_Size, Paint_Text_Scale_X, Paint_Text_Skew_X, |
| 5447 | Paint_Text_Align, Paint_Hinting, Anti-alias, Paint_Fake_Bold, |
| 5448 | Font_Embedded_Bitmaps, Full_Hinting_Spacing, LCD_Text, Linear_Text, |
| 5449 | Subpixel_Text, and Paint_Vertical_Text. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5450 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 5451 | Paint_Text_Encoding must be set to SkPaint::kGlyphID_TextEncoding. |
| 5452 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5453 | Elements of paint: Path_Effect, Mask_Filter, Shader, Color_Filter, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5454 | Image_Filter, and Draw_Looper; apply to blob. |
| 5455 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5456 | #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] | 5457 | #Param x horizontal offset applied to blob ## |
| 5458 | #Param y vertical offset applied to blob ## |
| 5459 | #Param paint blend, color, stroking, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5460 | |
| 5461 | #Example |
| 5462 | #Height 120 |
| 5463 | #Description |
| 5464 | Paint attributes unrelated to text, like color, have no effect on paint in allocated Text_Blob. |
| 5465 | Paint attributes related to text, like text size, have no effect on paint passed to drawTextBlob. |
| 5466 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5467 | void draw(SkCanvas* canvas) { |
| 5468 | SkTextBlobBuilder textBlobBuilder; |
| 5469 | SkPaint paint; |
| 5470 | paint.setTextSize(50); |
| 5471 | paint.setColor(SK_ColorRED); |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 5472 | paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5473 | const SkTextBlobBuilder::RunBuffer& run = |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5474 | textBlobBuilder.allocRun(paint, 1, 20, 100); |
| 5475 | run.glyphs[0] = 20; |
| 5476 | sk_sp<const SkTextBlob> blob = textBlobBuilder.make(); |
| 5477 | paint.setTextSize(10); |
| 5478 | paint.setColor(SK_ColorBLUE); |
| 5479 | canvas->drawTextBlob(blob.get(), 0, 0, paint); |
| 5480 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5481 | ## |
| 5482 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5483 | #SeeAlso drawText drawPosText drawPosTextH |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5484 | |
| 5485 | ## |
| 5486 | |
| 5487 | # ------------------------------------------------------------------------------ |
| 5488 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5489 | #Method void drawPicture(const SkPicture* picture) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5490 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5491 | #Line # draws Picture using Clip and Matrix ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5492 | Draw Picture picture, using Clip and Matrix. |
| 5493 | Clip and Matrix are unchanged by picture contents, as if |
| 5494 | save() was called before and restore() was called after drawPicture. |
| 5495 | |
| 5496 | Picture records a series of draw commands for later playback. |
| 5497 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5498 | #Param picture recorded drawing commands to play ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5499 | |
| 5500 | #Example |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5501 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5502 | SkPictureRecorder recorder; |
| 5503 | SkCanvas* recordingCanvas = recorder.beginRecording(50, 50); |
| 5504 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) { |
| 5505 | SkPaint paint; |
| 5506 | paint.setColor(color); |
| 5507 | recordingCanvas->drawRect({10, 10, 30, 40}, paint); |
| 5508 | recordingCanvas->translate(10, 10); |
| 5509 | recordingCanvas->scale(1.2f, 1.4f); |
| 5510 | } |
| 5511 | sk_sp<SkPicture> playback = recorder.finishRecordingAsPicture(); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5512 | canvas->drawPicture(playback); |
| 5513 | canvas->scale(2, 2); |
| 5514 | canvas->translate(50, 0); |
| 5515 | canvas->drawPicture(playback); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5516 | } |
| 5517 | ## |
| 5518 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5519 | #SeeAlso drawDrawable SkPicture SkPicture::playback |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5520 | |
| 5521 | ## |
| 5522 | |
| 5523 | # ------------------------------------------------------------------------------ |
| 5524 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5525 | #Method void drawPicture(const sk_sp<SkPicture>& picture) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5526 | |
| 5527 | Draw Picture picture, using Clip and Matrix. |
| 5528 | Clip and Matrix are unchanged by picture contents, as if |
| 5529 | save() was called before and restore() was called after drawPicture. |
| 5530 | |
| 5531 | Picture records a series of draw commands for later playback. |
| 5532 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5533 | #Param picture recorded drawing commands to play ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5534 | |
| 5535 | #Example |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5536 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5537 | SkPictureRecorder recorder; |
| 5538 | SkCanvas* recordingCanvas = recorder.beginRecording(50, 50); |
| 5539 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) { |
| 5540 | SkPaint paint; |
| 5541 | paint.setColor(color); |
| 5542 | recordingCanvas->drawRect({10, 10, 30, 40}, paint); |
| 5543 | recordingCanvas->translate(10, 10); |
| 5544 | recordingCanvas->scale(1.2f, 1.4f); |
| 5545 | } |
| 5546 | sk_sp<SkPicture> playback = recorder.finishRecordingAsPicture(); |
| 5547 | canvas->drawPicture(playback); |
| 5548 | canvas->scale(2, 2); |
| 5549 | canvas->translate(50, 0); |
| 5550 | canvas->drawPicture(playback); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5551 | } |
| 5552 | ## |
| 5553 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5554 | #SeeAlso drawDrawable SkPicture SkPicture::playback |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5555 | |
| 5556 | ## |
| 5557 | |
| 5558 | # ------------------------------------------------------------------------------ |
| 5559 | |
| 5560 | #Method void drawPicture(const SkPicture* picture, const SkMatrix* matrix, const SkPaint* paint) |
| 5561 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5562 | Draw Picture picture, using Clip and Matrix; transforming picture with |
| 5563 | Matrix matrix, if provided; and use Paint paint Color_Alpha, Color_Filter, |
| 5564 | Image_Filter, and Blend_Mode, if provided. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5565 | |
| 5566 | matrix transformation is equivalent to: save(), concat(), drawPicture, restore(). |
| 5567 | paint use is equivalent to: saveLayer, drawPicture, restore(). |
| 5568 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5569 | #Param picture recorded drawing commands to play ## |
| 5570 | #Param matrix Matrix to rotate, scale, translate, and so on; may be nullptr ## |
| 5571 | #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] | 5572 | |
| 5573 | #Example |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5574 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5575 | SkPaint paint; |
| 5576 | SkPictureRecorder recorder; |
| 5577 | SkCanvas* recordingCanvas = recorder.beginRecording(50, 50); |
| 5578 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) { |
| 5579 | paint.setColor(color); |
| 5580 | recordingCanvas->drawRect({10, 10, 30, 40}, paint); |
| 5581 | recordingCanvas->translate(10, 10); |
| 5582 | recordingCanvas->scale(1.2f, 1.4f); |
| 5583 | } |
| 5584 | sk_sp<SkPicture> playback = recorder.finishRecordingAsPicture(); |
| 5585 | const SkPicture* playbackPtr = playback.get(); |
| 5586 | SkMatrix matrix; |
| 5587 | matrix.reset(); |
| 5588 | for (auto alpha : { 70, 140, 210 } ) { |
| 5589 | paint.setAlpha(alpha); |
| 5590 | canvas->drawPicture(playbackPtr, &matrix, &paint); |
| 5591 | matrix.preTranslate(70, 70); |
| 5592 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5593 | } |
| 5594 | ## |
| 5595 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5596 | #SeeAlso drawDrawable SkPicture SkPicture::playback |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5597 | |
| 5598 | ## |
| 5599 | |
| 5600 | # ------------------------------------------------------------------------------ |
| 5601 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5602 | #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] | 5603 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5604 | Draw Picture picture, using Clip and Matrix; transforming picture with |
| 5605 | Matrix matrix, if provided; and use Paint paint Color_Alpha, Color_Filter, |
| 5606 | Image_Filter, and Blend_Mode, if provided. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5607 | |
| 5608 | matrix transformation is equivalent to: save(), concat(), drawPicture, restore(). |
| 5609 | paint use is equivalent to: saveLayer, drawPicture, restore(). |
| 5610 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5611 | #Param picture recorded drawing commands to play ## |
| 5612 | #Param matrix Matrix to rotate, scale, translate, and so on; may be nullptr ## |
| 5613 | #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] | 5614 | |
| 5615 | #Example |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5616 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5617 | SkPaint paint; |
| 5618 | SkPictureRecorder recorder; |
| 5619 | SkCanvas* recordingCanvas = recorder.beginRecording(50, 50); |
| 5620 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) { |
| 5621 | paint.setColor(color); |
| 5622 | recordingCanvas->drawRect({10, 10, 30, 40}, paint); |
| 5623 | recordingCanvas->translate(10, 10); |
| 5624 | recordingCanvas->scale(1.2f, 1.4f); |
| 5625 | } |
| 5626 | sk_sp<SkPicture> playback = recorder.finishRecordingAsPicture(); |
| 5627 | SkMatrix matrix; |
| 5628 | matrix.reset(); |
| 5629 | for (auto alpha : { 70, 140, 210 } ) { |
| 5630 | paint.setAlpha(alpha); |
| 5631 | canvas->drawPicture(playback, &matrix, &paint); |
| 5632 | matrix.preTranslate(70, 70); |
| 5633 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5634 | } |
| 5635 | ## |
| 5636 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5637 | #SeeAlso drawDrawable SkPicture SkPicture::playback |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5638 | |
| 5639 | ## |
| 5640 | |
| 5641 | # ------------------------------------------------------------------------------ |
| 5642 | |
| 5643 | #Method void drawVertices(const SkVertices* vertices, SkBlendMode mode, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5644 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5645 | #Line # draws Vertices, a triangle mesh ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5646 | Draw Vertices vertices, a triangle mesh, using Clip and Matrix. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5647 | If Vertices_Texs and Vertices_Colors are defined in vertices, and Paint paint |
| 5648 | contains Shader, Blend_Mode mode combines Vertices_Colors with Shader. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5649 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5650 | #Param vertices triangle mesh to draw ## |
| 5651 | #Param mode combines Vertices_Colors with Shader, if both are present ## |
| 5652 | #Param paint specifies the Shader, used as Vertices texture; may be nullptr ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5653 | |
| 5654 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5655 | void draw(SkCanvas* canvas) { |
| 5656 | SkPaint paint; |
| 5657 | SkPoint points[] = { { 0, 0 }, { 250, 0 }, { 100, 100 }, { 0, 250 } }; |
| 5658 | SkColor colors[] = { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorCYAN }; |
| 5659 | auto vertices = SkVertices::MakeCopy(SkVertices::kTriangleFan_VertexMode, |
| 5660 | SK_ARRAY_COUNT(points), points, nullptr, colors); |
| 5661 | canvas->drawVertices(vertices.get(), SkBlendMode::kSrc, paint); |
| 5662 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5663 | ## |
| 5664 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5665 | #SeeAlso drawPatch drawPicture |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5666 | |
| 5667 | ## |
| 5668 | |
| 5669 | # ------------------------------------------------------------------------------ |
| 5670 | |
| 5671 | #Method void drawVertices(const sk_sp<SkVertices>& vertices, SkBlendMode mode, const SkPaint& paint) |
| 5672 | |
| 5673 | Draw Vertices vertices, a triangle mesh, using Clip and Matrix. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5674 | If Vertices_Texs and Vertices_Colors are defined in vertices, and Paint paint |
| 5675 | contains Shader, Blend_Mode mode combines Vertices_Colors with Shader. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5676 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5677 | #Param vertices triangle mesh to draw ## |
| 5678 | #Param mode combines Vertices_Colors with Shader, if both are present ## |
| 5679 | #Param paint specifies the Shader, used as Vertices texture, may be nullptr ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5680 | |
| 5681 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5682 | void draw(SkCanvas* canvas) { |
| 5683 | SkPaint paint; |
| 5684 | SkPoint points[] = { { 0, 0 }, { 250, 0 }, { 100, 100 }, { 0, 250 } }; |
| 5685 | SkPoint texs[] = { { 0, 0 }, { 0, 250 }, { 250, 250 }, { 250, 0 } }; |
| 5686 | SkColor colors[] = { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorCYAN }; |
| 5687 | paint.setShader(SkGradientShader::MakeLinear(points, colors, nullptr, 4, |
| 5688 | SkShader::kClamp_TileMode)); |
| 5689 | auto vertices = SkVertices::MakeCopy(SkVertices::kTriangleFan_VertexMode, |
| 5690 | SK_ARRAY_COUNT(points), points, texs, colors); |
| 5691 | canvas->drawVertices(vertices.get(), SkBlendMode::kDarken, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5692 | } |
| 5693 | ## |
| 5694 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5695 | #SeeAlso drawPatch drawPicture |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5696 | |
| 5697 | ## |
| 5698 | |
| 5699 | # ------------------------------------------------------------------------------ |
| 5700 | |
| 5701 | #Method void drawPatch(const SkPoint cubics[12], const SkColor colors[4], |
| 5702 | const SkPoint texCoords[4], SkBlendMode mode, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5703 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5704 | #Line # draws Coons_Patch ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5705 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5706 | Draws a Coons_Patch: the interpolation of four cubics with shared corners, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5707 | associating a color, and optionally a texture coordinate, with each corner. |
| 5708 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 5709 | Coons_Patch uses Clip and Matrix, paint Shader, Color_Filter, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5710 | 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] | 5711 | 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] | 5712 | both are provided. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5713 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5714 | Point array cubics specifies four Cubics starting at the top-left corner, |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5715 | 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] | 5716 | first point. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5717 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5718 | Color array color associates colors with corners in top-left, top-right, |
| 5719 | bottom-right, bottom-left order. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5720 | |
| 5721 | If paint contains Shader, Point array texCoords maps Shader as texture to |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5722 | corners in top-left, top-right, bottom-right, bottom-left order. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5723 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 5724 | #Param cubics Path_Cubic array, sharing common points ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5725 | #Param colors Color array, one for each corner ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5726 | #Param texCoords Point array of texture coordinates, mapping Shader to corners; |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5727 | may be nullptr |
Cary Clark | 579985c | 2017-07-31 11:48:27 -0400 | [diff] [blame] | 5728 | #Param ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5729 | #Param mode Blend_Mode for colors, and for Shader if paint has one ## |
| 5730 | #Param paint Shader, Color_Filter, Blend_Mode, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5731 | |
| 5732 | #Example |
| 5733 | #Image 5 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5734 | void draw(SkCanvas* canvas) { |
| 5735 | // SkBitmap source = cmbkygk; |
| 5736 | SkPaint paint; |
| 5737 | paint.setFilterQuality(kLow_SkFilterQuality); |
| 5738 | paint.setAntiAlias(true); |
| 5739 | SkPoint cubics[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, |
| 5740 | /* { 7, 3 }, */ { 6, 4 }, { 7, 5 }, { 5, 7 }, |
| 5741 | /* { 5, 7 }, */ { 4, 6 }, { 3, 7 }, { 1, 5 }, |
| 5742 | /* { 1, 5 }, */ { 2, 4 }, { 1, 3 }, /* { 3, 1 } */ }; |
| 5743 | SkColor colors[] = { 0xbfff0000, 0xbf0000ff, 0xbfff00ff, 0xbf00ffff }; |
| 5744 | SkPoint texCoords[] = { { -30, -30 }, { 162, -30}, { 162, 162}, { -30, 162} }; |
| 5745 | paint.setShader(SkShader::MakeBitmapShader(source, SkShader::kClamp_TileMode, |
| 5746 | SkShader::kClamp_TileMode, nullptr)); |
| 5747 | canvas->scale(15, 15); |
| 5748 | for (auto blend : { SkBlendMode::kSrcOver, SkBlendMode::kModulate, SkBlendMode::kXor } ) { |
| 5749 | canvas->drawPatch(cubics, colors, texCoords, blend, paint); |
| 5750 | canvas->translate(4, 4); |
| 5751 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5752 | } |
| 5753 | ## |
| 5754 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5755 | #ToDo can patch use image filter? ## |
| 5756 | #SeeAlso SeeAlso drawVertices drawPicture |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5757 | |
| 5758 | ## |
| 5759 | |
| 5760 | # ------------------------------------------------------------------------------ |
| 5761 | |
| 5762 | #Method void drawPatch(const SkPoint cubics[12], const SkColor colors[4], |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5763 | const SkPoint texCoords[4], const SkPaint& paint) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5764 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5765 | Draws Cubic Coons_Patch: the interpolation of four cubics with shared corners, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5766 | associating a color, and optionally a texture coordinate, with each corner. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5767 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 5768 | Coons_Patch uses Clip and Matrix, paint Shader, Color_Filter, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5769 | 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] | 5770 | 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] | 5771 | both are provided. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5772 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5773 | Point array cubics specifies four Cubics starting at the top-left corner, |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5774 | 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] | 5775 | first point. |
| 5776 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5777 | Color array color associates colors with corners in top-left, top-right, |
| 5778 | bottom-right, bottom-left order. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5779 | |
| 5780 | If paint contains Shader, Point array texCoords maps Shader as texture to |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5781 | corners in top-left, top-right, bottom-right, bottom-left order. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5782 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 5783 | #Param cubics Path_Cubic array, sharing common points ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5784 | #Param colors Color array, one for each corner ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5785 | #Param texCoords Point array of texture coordinates, mapping Shader to corners; |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5786 | may be nullptr |
Cary Clark | 579985c | 2017-07-31 11:48:27 -0400 | [diff] [blame] | 5787 | #Param ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5788 | #Param paint Shader, Color_Filter, Blend_Mode, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5789 | |
| 5790 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5791 | void draw(SkCanvas* canvas) { |
| 5792 | SkPaint paint; |
| 5793 | paint.setAntiAlias(true); |
| 5794 | SkPoint cubics[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, |
| 5795 | /* { 7, 3 }, */ { 6, 4 }, { 7, 5 }, { 5, 7 }, |
| 5796 | /* { 5, 7 }, */ { 4, 6 }, { 3, 7 }, { 1, 5 }, |
| 5797 | /* { 1, 5 }, */ { 2, 4 }, { 1, 3 }, /* { 3, 1 } */ }; |
| 5798 | SkColor colors[] = { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorCYAN }; |
| 5799 | canvas->scale(30, 30); |
| 5800 | canvas->drawPatch(cubics, colors, nullptr, paint); |
| 5801 | SkPoint text[] = { {3,0.9f}, {4,2.5f}, {5,0.9f}, {7.5f,3.2f}, {5.5f,4.2f}, |
| 5802 | {7.5f,5.2f}, {5,7.5f}, {4,5.9f}, {3,7.5f}, {0.5f,5.2f}, {2.5f,4.2f}, |
| 5803 | {0.5f,3.2f} }; |
| 5804 | paint.setTextSize(18.f / 30); |
| 5805 | paint.setTextAlign(SkPaint::kCenter_Align); |
| 5806 | for (int i = 0; i< 10; ++i) { |
| 5807 | char digit = '0' + i; |
| 5808 | canvas->drawText(&digit, 1, text[i].fX, text[i].fY, paint); |
| 5809 | } |
| 5810 | canvas->drawString("10", text[10].fX, text[10].fY, paint); |
| 5811 | canvas->drawString("11", text[11].fX, text[11].fY, paint); |
| 5812 | paint.setStyle(SkPaint::kStroke_Style); |
| 5813 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, 12, cubics, paint); |
| 5814 | 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] | 5815 | } |
| 5816 | ## |
| 5817 | |
| 5818 | #Example |
| 5819 | #Image 6 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5820 | void draw(SkCanvas* canvas) { |
| 5821 | // SkBitmap source = checkerboard; |
| 5822 | SkPaint paint; |
| 5823 | paint.setFilterQuality(kLow_SkFilterQuality); |
| 5824 | paint.setAntiAlias(true); |
| 5825 | SkPoint cubics[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, |
| 5826 | /* { 7, 3 }, */ { 6, 4 }, { 7, 5 }, { 5, 7 }, |
| 5827 | /* { 5, 7 }, */ { 4, 6 }, { 3, 7 }, { 1, 5 }, |
| 5828 | /* { 1, 5 }, */ { 2, 4 }, { 1, 3 }, /* { 3, 1 } */ }; |
| 5829 | SkPoint texCoords[] = { { 0, 0 }, { 0, 62}, { 62, 62}, { 62, 0 } }; |
| 5830 | paint.setShader(SkShader::MakeBitmapShader(source, SkShader::kClamp_TileMode, |
| 5831 | SkShader::kClamp_TileMode, nullptr)); |
| 5832 | canvas->scale(30, 30); |
| 5833 | canvas->drawPatch(cubics, nullptr, texCoords, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5834 | } |
| 5835 | ## |
| 5836 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5837 | #ToDo can patch use image filter? ## |
| 5838 | #SeeAlso SeeAlso drawVertices drawPicture |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5839 | |
| 5840 | ## |
| 5841 | |
| 5842 | # ------------------------------------------------------------------------------ |
| 5843 | |
| 5844 | #Method void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], |
| 5845 | const SkColor colors[], int count, SkBlendMode mode, const SkRect* cullRect, |
| 5846 | const SkPaint* paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5847 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5848 | #Line # draws sprites using Clip, Matrix, and Paint ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5849 | |
| 5850 | Draw a set of sprites from atlas, using Clip, Matrix, and optional Paint paint. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5851 | paint uses Anti-alias, Color_Alpha, Color_Filter, Image_Filter, and Blend_Mode |
| 5852 | to draw, if present. For each entry in the array, Rect tex locates sprite in |
| 5853 | atlas, and RSXform xform transforms it into destination space. |
| 5854 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5855 | xform, text, and colors if present, must contain count entries. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5856 | Optional colors are applied for each sprite using Blend_Mode. |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5857 | Optional cullRect is a conservative bounds of all transformed sprites. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5858 | If cullRect is outside of Clip, canvas can skip drawing. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5859 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5860 | #Param atlas Image containing sprites ## |
| 5861 | #Param xform RSXform mappings for sprites in atlas ## |
| 5862 | #Param tex Rect locations of sprites in atlas ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 5863 | #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] | 5864 | #Param count number of sprites to draw ## |
| 5865 | #Param mode Blend_Mode combining colors and sprites ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 5866 | #Param cullRect bounds of transformed sprites for efficient clipping; may be nullptr ## |
| 5867 | #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] | 5868 | |
| 5869 | #Example |
| 5870 | #Image 3 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5871 | void draw(SkCanvas* canvas) { |
| 5872 | // SkBitmap source = mandrill; |
| 5873 | SkRSXform xforms[] = { { .5f, 0, 0, 0 }, {0, .5f, 200, 100 } }; |
| 5874 | SkRect tex[] = { { 0, 0, 250, 250 }, { 0, 0, 250, 250 } }; |
| 5875 | SkColor colors[] = { 0x7f55aa00, 0x7f3333bf }; |
| 5876 | const SkImage* imagePtr = image.get(); |
| 5877 | canvas->drawAtlas(imagePtr, xforms, tex, colors, 2, SkBlendMode::kSrcOver, nullptr, nullptr); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5878 | } |
| 5879 | ## |
| 5880 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5881 | #SeeAlso drawBitmap drawImage |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5882 | |
| 5883 | ## |
| 5884 | |
| 5885 | # ------------------------------------------------------------------------------ |
| 5886 | |
| 5887 | #Method void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[], |
| 5888 | const SkColor colors[], int count, SkBlendMode mode, const SkRect* cullRect, |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5889 | const SkPaint* paint) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5890 | |
| 5891 | Draw a set of sprites from atlas, using Clip, Matrix, and optional Paint paint. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5892 | paint uses Anti-alias, Color_Alpha, Color_Filter, Image_Filter, and Blend_Mode |
| 5893 | to draw, if present. For each entry in the array, Rect tex locates sprite in |
| 5894 | atlas, and RSXform xform transforms it into destination space. |
| 5895 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5896 | xform, text, and colors if present, must contain count entries. |
| 5897 | Optional colors is applied for each sprite using Blend_Mode. |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5898 | Optional cullRect is a conservative bounds of all transformed sprites. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5899 | If cullRect is outside of Clip, canvas can skip drawing. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5900 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5901 | #Param atlas Image containing sprites ## |
| 5902 | #Param xform RSXform mappings for sprites in atlas ## |
| 5903 | #Param tex Rect locations of sprites in atlas ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 5904 | #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] | 5905 | #Param count number of sprites to draw ## |
| 5906 | #Param mode Blend_Mode combining colors and sprites ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 5907 | #Param cullRect bounds of transformed sprites for efficient clipping; may be nullptr ## |
| 5908 | #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] | 5909 | |
| 5910 | #Example |
| 5911 | #Image 3 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5912 | void draw(SkCanvas* canvas) { |
| 5913 | // SkBitmap source = mandrill; |
| 5914 | SkRSXform xforms[] = { { .5f, 0, 0, 0 }, {0, .5f, 200, 100 } }; |
| 5915 | SkRect tex[] = { { 0, 0, 250, 250 }, { 0, 0, 250, 250 } }; |
| 5916 | SkColor colors[] = { 0x7f55aa00, 0x7f3333bf }; |
| 5917 | SkPaint paint; |
| 5918 | paint.setAlpha(127); |
| 5919 | canvas->drawAtlas(image, xforms, tex, colors, 2, SkBlendMode::kPlus, nullptr, &paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5920 | } |
| 5921 | ## |
| 5922 | |
| 5923 | #ToDo bug in example on cpu side, gpu looks ok ## |
| 5924 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5925 | #SeeAlso drawBitmap drawImage |
| 5926 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5927 | ## |
| 5928 | |
| 5929 | # ------------------------------------------------------------------------------ |
| 5930 | |
| 5931 | #Method void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], int count, |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5932 | const SkRect* cullRect, const SkPaint* paint) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5933 | |
| 5934 | Draw a set of sprites from atlas, using Clip, Matrix, and optional Paint paint. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5935 | paint uses Anti-alias, Color_Alpha, Color_Filter, Image_Filter, and Blend_Mode |
| 5936 | to draw, if present. For each entry in the array, Rect tex locates sprite in |
| 5937 | atlas, and RSXform xform transforms it into destination space. |
| 5938 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5939 | xform and text must contain count entries. |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5940 | Optional cullRect is a conservative bounds of all transformed sprites. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5941 | If cullRect is outside of Clip, canvas can skip drawing. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5942 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5943 | #Param atlas Image containing sprites ## |
| 5944 | #Param xform RSXform mappings for sprites in atlas ## |
| 5945 | #Param tex Rect locations of sprites in atlas ## |
| 5946 | #Param count number of sprites to draw ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 5947 | #Param cullRect bounds of transformed sprites for efficient clipping; may be nullptr ## |
| 5948 | #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] | 5949 | |
| 5950 | #Example |
| 5951 | #Image 3 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5952 | void draw(SkCanvas* canvas) { |
| 5953 | // sk_sp<SkImage> image = mandrill; |
| 5954 | SkRSXform xforms[] = { { .5f, 0, 0, 0 }, {0, .5f, 200, 100 } }; |
| 5955 | SkRect tex[] = { { 0, 0, 250, 250 }, { 0, 0, 250, 250 } }; |
| 5956 | const SkImage* imagePtr = image.get(); |
| 5957 | canvas->drawAtlas(imagePtr, xforms, tex, 2, nullptr, nullptr); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5958 | } |
| 5959 | ## |
| 5960 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5961 | #SeeAlso drawBitmap drawImage |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5962 | |
| 5963 | ## |
| 5964 | |
| 5965 | # ------------------------------------------------------------------------------ |
| 5966 | |
| 5967 | #Method void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[], |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5968 | int count, const SkRect* cullRect, const SkPaint* paint) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5969 | |
| 5970 | Draw a set of sprites from atlas, using Clip, Matrix, and optional Paint paint. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5971 | paint uses Anti-alias, Color_Alpha, Color_Filter, Image_Filter, and Blend_Mode |
| 5972 | to draw, if present. For each entry in the array, Rect tex locates sprite in |
| 5973 | atlas, and RSXform xform transforms it into destination space. |
| 5974 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5975 | xform and text must contain count entries. |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 5976 | Optional cullRect is a conservative bounds of all transformed sprites. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5977 | If cullRect is outside of Clip, canvas can skip drawing. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5978 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5979 | #Param atlas Image containing sprites ## |
| 5980 | #Param xform RSXform mappings for sprites in atlas ## |
| 5981 | #Param tex Rect locations of sprites in atlas ## |
| 5982 | #Param count number of sprites to draw ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 5983 | #Param cullRect bounds of transformed sprites for efficient clipping; may be nullptr ## |
| 5984 | #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] | 5985 | |
| 5986 | #Example |
| 5987 | #Image 3 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5988 | void draw(SkCanvas* canvas) { |
| 5989 | // sk_sp<SkImage> image = mandrill; |
| 5990 | SkRSXform xforms[] = { { 1, 0, 0, 0 }, {0, 1, 300, 100 } }; |
| 5991 | SkRect tex[] = { { 0, 0, 200, 200 }, { 200, 0, 400, 200 } }; |
| 5992 | canvas->drawAtlas(image, xforms, tex, 2, nullptr, nullptr); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5993 | } |
| 5994 | ## |
| 5995 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5996 | #SeeAlso drawBitmap drawImage |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5997 | |
| 5998 | ## |
| 5999 | |
| 6000 | # ------------------------------------------------------------------------------ |
| 6001 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 6002 | #Method void drawDrawable(SkDrawable* drawable, const SkMatrix* matrix = nullptr) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 6003 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 6004 | #Line # draws Drawable, encapsulated drawing commands ## |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 6005 | Draw Drawable drawable using Clip and Matrix, concatenated with |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6006 | optional matrix. |
| 6007 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 6008 | If Canvas has an asynchronous implementation, as is the case |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6009 | when it is recording into Picture, then drawable will be referenced, |
| 6010 | so that SkDrawable::draw() can be called when the operation is finalized. To force |
| 6011 | immediate drawing, call SkDrawable::draw() instead. |
| 6012 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6013 | #Param drawable custom struct encapsulating drawing commands ## |
| 6014 | #Param matrix transformation applied to drawing; may be nullptr ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6015 | |
| 6016 | #Example |
| 6017 | #Height 100 |
| 6018 | #Function |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6019 | struct MyDrawable : public SkDrawable { |
| 6020 | SkRect onGetBounds() override { return SkRect::MakeWH(50, 100); } |
| 6021 | |
| 6022 | void onDraw(SkCanvas* canvas) override { |
| 6023 | SkPath path; |
| 6024 | path.conicTo(10, 90, 50, 90, 0.9f); |
| 6025 | SkPaint paint; |
| 6026 | paint.setColor(SK_ColorBLUE); |
| 6027 | canvas->drawRect(path.getBounds(), paint); |
| 6028 | paint.setAntiAlias(true); |
| 6029 | paint.setColor(SK_ColorWHITE); |
| 6030 | canvas->drawPath(path, paint); |
| 6031 | } |
| 6032 | }; |
| 6033 | |
| 6034 | #Function ## |
| 6035 | void draw(SkCanvas* canvas) { |
| 6036 | sk_sp<SkDrawable> drawable(new MyDrawable); |
| 6037 | SkMatrix matrix; |
| 6038 | matrix.setTranslate(10, 10); |
| 6039 | canvas->drawDrawable(drawable.get(), &matrix); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6040 | } |
| 6041 | ## |
| 6042 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 6043 | #SeeAlso SkDrawable drawPicture |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6044 | |
| 6045 | ## |
| 6046 | |
| 6047 | # ------------------------------------------------------------------------------ |
| 6048 | |
| 6049 | #Method void drawDrawable(SkDrawable* drawable, SkScalar x, SkScalar y) |
| 6050 | |
| 6051 | Draw Drawable drawable using Clip and Matrix, offset by (x, y). |
| 6052 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 6053 | If Canvas has an asynchronous implementation, as is the case |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6054 | when it is recording into Picture, then drawable will be referenced, |
| 6055 | so that SkDrawable::draw() can be called when the operation is finalized. To force |
| 6056 | immediate drawing, call SkDrawable::draw() instead. |
| 6057 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6058 | #Param drawable custom struct encapsulating drawing commands ## |
| 6059 | #Param x offset into Canvas writable pixels in x ## |
| 6060 | #Param y offset into Canvas writable pixels in y ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6061 | |
| 6062 | #Example |
| 6063 | #Height 100 |
| 6064 | #Function |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6065 | struct MyDrawable : public SkDrawable { |
| 6066 | SkRect onGetBounds() override { return SkRect::MakeWH(50, 100); } |
| 6067 | |
| 6068 | void onDraw(SkCanvas* canvas) override { |
| 6069 | SkPath path; |
| 6070 | path.conicTo(10, 90, 50, 90, 0.9f); |
| 6071 | SkPaint paint; |
| 6072 | paint.setColor(SK_ColorBLUE); |
| 6073 | canvas->drawRect(path.getBounds(), paint); |
| 6074 | paint.setAntiAlias(true); |
| 6075 | paint.setColor(SK_ColorWHITE); |
| 6076 | canvas->drawPath(path, paint); |
| 6077 | } |
| 6078 | }; |
| 6079 | |
| 6080 | #Function ## |
| 6081 | void draw(SkCanvas* canvas) { |
| 6082 | sk_sp<SkDrawable> drawable(new MyDrawable); |
| 6083 | canvas->drawDrawable(drawable.get(), 10, 10); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6084 | } |
| 6085 | ## |
| 6086 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 6087 | #SeeAlso SkDrawable drawPicture |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6088 | |
| 6089 | ## |
| 6090 | |
| 6091 | # ------------------------------------------------------------------------------ |
| 6092 | |
| 6093 | #Method void drawAnnotation(const SkRect& rect, const char key[], SkData* value) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 6094 | #In Draw |
| 6095 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 6096 | #Line # associates a Rect with a key-value pair ## |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 6097 | 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] | 6098 | a null-terminated utf8 string, and optional value is stored as Data. |
| 6099 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 6100 | Only some canvas implementations, such as recording to Picture, or drawing to |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6101 | Document_PDF, use annotations. |
| 6102 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6103 | #Param rect Rect extent of canvas to annotate ## |
| 6104 | #Param key string used for lookup ## |
| 6105 | #Param value data holding value stored in annotation ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6106 | |
| 6107 | #Example |
| 6108 | #Height 1 |
| 6109 | const char text[] = "Click this link!"; |
| 6110 | SkRect bounds; |
| 6111 | SkPaint paint; |
| 6112 | paint.setTextSize(40); |
| 6113 | (void)paint.measureText(text, strlen(text), &bounds); |
| 6114 | const char url[] = "https://www.google.com/"; |
| 6115 | sk_sp<SkData> urlData(SkData::MakeWithCString(url)); |
| 6116 | canvas->drawAnnotation(bounds, "url_key", urlData.get()); |
| 6117 | ## |
| 6118 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 6119 | #SeeAlso SkPicture SkDocument |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6120 | |
| 6121 | ## |
| 6122 | |
| 6123 | # ------------------------------------------------------------------------------ |
| 6124 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 6125 | #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] | 6126 | |
| 6127 | Associate Rect on Canvas when an annotation; a key-value pair, where the key is |
| 6128 | a null-terminated utf8 string, and optional value is stored as Data. |
| 6129 | |
Mike Klein | 9ff8c8c | 2018-02-07 01:58:51 +0000 | [diff] [blame] | 6130 | Only some canvas implementations, such as recording to Picture, or drawing to |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6131 | Document_PDF, use annotations. |
| 6132 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6133 | #Param rect Rect extent of canvas to annotate ## |
| 6134 | #Param key string used for lookup ## |
| 6135 | #Param value data holding value stored in annotation ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6136 | |
| 6137 | #Example |
| 6138 | #Height 1 |
| 6139 | const char text[] = "Click this link!"; |
| 6140 | SkRect bounds; |
| 6141 | SkPaint paint; |
| 6142 | paint.setTextSize(40); |
| 6143 | (void)paint.measureText(text, strlen(text), &bounds); |
| 6144 | const char url[] = "https://www.google.com/"; |
| 6145 | sk_sp<SkData> urlData(SkData::MakeWithCString(url)); |
| 6146 | canvas->drawAnnotation(bounds, "url_key", urlData.get()); |
| 6147 | ## |
| 6148 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 6149 | #SeeAlso SkPicture SkDocument |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6150 | |
| 6151 | ## |
| 6152 | |
| 6153 | #Method SkDrawFilter* getDrawFilter() const |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 6154 | #Deprecated soon |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6155 | ## |
| 6156 | |
| 6157 | #Method virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 6158 | #Deprecated soon |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6159 | ## |
| 6160 | |
| 6161 | # ------------------------------------------------------------------------------ |
| 6162 | |
| 6163 | #Method virtual bool isClipEmpty() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 6164 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 6165 | #Line # returns if Clip is empty ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6166 | Returns true if Clip is empty; that is, nothing will draw. |
| 6167 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6168 | May do work when called; it should not be called |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6169 | more often than needed. However, once called, subsequent calls perform no |
| 6170 | work until Clip changes. |
| 6171 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6172 | #Return true if Clip is empty ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6173 | |
| 6174 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6175 | void draw(SkCanvas* canvas) { |
| 6176 | SkDebugf("clip is%s empty\n", canvas->isClipEmpty() ? "" : " not"); |
| 6177 | SkPath path; |
| 6178 | canvas->clipPath(path); |
| 6179 | SkDebugf("clip is%s empty\n", canvas->isClipEmpty() ? "" : " not"); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6180 | } |
| 6181 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6182 | clip is not empty |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6183 | clip is empty |
| 6184 | ## |
| 6185 | ## |
| 6186 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 6187 | #SeeAlso isClipRect getLocalClipBounds getDeviceClipBounds |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6188 | |
| 6189 | ## |
| 6190 | |
| 6191 | # ------------------------------------------------------------------------------ |
| 6192 | |
| 6193 | #Method virtual bool isClipRect() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 6194 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 6195 | #Line # returns if Clip is Rect and not empty ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6196 | Returns true if Clip is Rect and not empty. |
| 6197 | Returns false if the clip is empty, or if it is not Rect. |
| 6198 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6199 | #Return true if Clip is Rect and not empty ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6200 | |
| 6201 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6202 | void draw(SkCanvas* canvas) { |
| 6203 | SkDebugf("clip is%s rect\n", canvas->isClipRect() ? "" : " not"); |
| 6204 | canvas->clipRect({0, 0, 0, 0}); |
| 6205 | SkDebugf("clip is%s rect\n", canvas->isClipRect() ? "" : " not"); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6206 | } |
| 6207 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6208 | clip is rect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6209 | clip is not rect |
| 6210 | ## |
| 6211 | ## |
| 6212 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 6213 | #SeeAlso isClipEmpty getLocalClipBounds getDeviceClipBounds |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6214 | |
| 6215 | ## |
| 6216 | |
| 6217 | #Class SkCanvas ## |
Cary Clark | 884dd7d | 2017-10-11 10:37:52 -0400 | [diff] [blame] | 6218 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6219 | #Topic Canvas ## |