Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1 | #Topic Canvas |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 2 | #Alias Canvas_Reference ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3 | |
Cary Clark | e4aa371 | 2017-09-15 02:56:12 -0400 | [diff] [blame] | 4 | #Class SkCanvas |
| 5 | |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 6 | #Code |
| 7 | #Populate |
| 8 | ## |
| 9 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 10 | Canvas provides an interface for drawing, and how the drawing is clipped and transformed. |
| 11 | Canvas contains a stack of Matrix and Clip values. |
| 12 | |
| 13 | Canvas and Paint together provide the state to draw into Surface or Device. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 14 | Each Canvas draw call transforms the geometry of the object by the concatenation of all |
| 15 | Matrix values in the stack. The transformed geometry is clipped by the intersection |
| 16 | of all of Clip values in the stack. The Canvas draw calls use Paint to supply drawing |
| 17 | state such as Color, Typeface, text size, stroke width, Shader and so on. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 18 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 19 | To draw to a pixel-based destination, create Raster_Surface or GPU_Surface. |
| 20 | Request Canvas from Surface to obtain the interface to draw. |
| 21 | Canvas generated by Raster_Surface draws to memory visible to the CPU. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 22 | Canvas generated by GPU_Surface uses Vulkan or OpenGL to draw to the GPU. |
| 23 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 24 | To draw to a document, obtain Canvas from SVG_Canvas, Document_PDF, or Picture_Recorder. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 25 | Document based Canvas and other Canvas Subclasses reference Device describing the |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 26 | destination. |
| 27 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 28 | Canvas can be constructed to draw to Bitmap without first creating Raster_Surface. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 29 | This approach may be deprecated in the future. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 30 | |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 31 | #Subtopic Constructors |
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 | 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] | 34 | when no Surface is required, and some helpers implicitly create Raster_Surface. |
| 35 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 36 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 37 | |
| 38 | # ------------------------------------------------------------------------------ |
| 39 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 40 | #Method static std::unique_ptr<SkCanvas> MakeRasterDirect(const SkImageInfo& info, void* pixels, |
| 41 | size_t rowBytes, |
| 42 | const SkSurfaceProps* props = nullptr) |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 43 | #In Constructors |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 44 | #Line # creates from SkImageInfo and Pixel_Storage ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 45 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 46 | Allocates raster Canvas that will draw directly into pixels. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 47 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 48 | Canvas is returned if all parameters are valid. |
| 49 | Valid parameters include: |
| 50 | info dimensions are zero or positive; |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 51 | info contains Color_Type and Alpha_Type supported by Raster_Surface; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 52 | pixels is not nullptr; |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 53 | 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] | 54 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 55 | 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] | 56 | 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] | 57 | info width times bytes required for Color_Type. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 58 | |
| 59 | Pixel buffer size should be info height times computed rowBytes. |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 60 | Pixels are not initialized. |
| 61 | To access pixels after drawing, call flush() or peekPixels. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 62 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 63 | #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] | 64 | width, or height, or both, may be zero |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 65 | ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 66 | #Param pixels pointer to destination pixels buffer |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 67 | ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 68 | #Param rowBytes interval from one Surface row to the next, or zero |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 69 | ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 70 | #Param props LCD striping orientation and setting for device independent fonts; |
| 71 | may be nullptr |
| 72 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 73 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 74 | #Return Canvas if all parameters are valid; otherwise, nullptr ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 75 | |
| 76 | #Example |
| 77 | #Description |
| 78 | Allocates a three by three bitmap, clears it to white, and draws a black pixel |
| 79 | in the center. |
| 80 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 81 | void draw(SkCanvas* ) { |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 82 | SkImageInfo info = SkImageInfo::MakeN32Premul(3, 3); // device aligned, 32 bpp, Premultiplied |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 83 | const size_t minRowBytes = info.minRowBytes(); // bytes used by one bitmap row |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 84 | const size_t size = info.computeMinByteSize(); // bytes used by all rows |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 85 | SkAutoTMalloc<SkPMColor> storage(size); // allocate storage for pixels |
| 86 | SkPMColor* pixels = storage.get(); // get pointer to allocated storage |
| 87 | // create a SkCanvas backed by a raster device, and delete it when the |
| 88 | // function goes out of scope. |
| 89 | std::unique_ptr<SkCanvas> canvas = SkCanvas::MakeRasterDirect(info, pixels, minRowBytes); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 90 | canvas->clear(SK_ColorWHITE); // white is Unpremultiplied, in ARGB order |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 91 | canvas->flush(); // ensure that pixels are cleared |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 92 | SkPMColor pmWhite = pixels[0]; // the Premultiplied format may vary |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 93 | SkPaint paint; // by default, draws black |
| 94 | canvas->drawPoint(1, 1, paint); // draw in the center |
| 95 | canvas->flush(); // ensure that point was drawn |
| 96 | for (int y = 0; y < info.height(); ++y) { |
| 97 | for (int x = 0; x < info.width(); ++x) { |
| 98 | SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x'); |
| 99 | } |
| 100 | SkDebugf("\n"); |
| 101 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 102 | } |
| 103 | #StdOut |
| 104 | --- |
| 105 | -x- |
| 106 | --- |
| 107 | ## |
| 108 | ## |
| 109 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 110 | #SeeAlso MakeRasterDirectN32 SkSurface::MakeRasterDirect |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 111 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 112 | ## |
| 113 | |
| 114 | # ------------------------------------------------------------------------------ |
| 115 | |
| 116 | #Method static std::unique_ptr<SkCanvas> MakeRasterDirectN32(int width, int height, SkPMColor* pixels, |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 117 | size_t rowBytes) |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 118 | #In Constructors |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 119 | #Line # creates from image data and Pixel_Storage ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 120 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 121 | Allocates raster Canvas specified by inline image specification. Subsequent Canvas |
| 122 | calls draw into pixels. |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 123 | Color_Type is set to kN32_SkColorType. |
| 124 | Alpha_Type is set to kPremul_SkAlphaType. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 125 | To access pixels after drawing, call flush() or peekPixels. |
| 126 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 127 | Canvas is returned if all parameters are valid. |
| 128 | Valid parameters include: |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 129 | width and height are zero or positive; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 130 | pixels is not nullptr; |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 131 | 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] | 132 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 133 | 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] | 134 | 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] | 135 | width times bytes required for Color_Type. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 136 | |
| 137 | Pixel buffer size should be height times rowBytes. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 138 | |
| 139 | #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] | 140 | #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] | 141 | #Param pixels pointer to destination pixels buffer; buffer size should be height |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 142 | times rowBytes |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 143 | ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 144 | #Param rowBytes interval from one Surface row to the next, or zero |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 145 | ## |
| 146 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 147 | #Return Canvas if all parameters are valid; otherwise, nullptr ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 148 | |
| 149 | #Example |
| 150 | #Description |
| 151 | Allocates a three by three bitmap, clears it to white, and draws a black pixel |
| 152 | in the center. |
| 153 | ## |
| 154 | void draw(SkCanvas* ) { |
| 155 | const int width = 3; |
| 156 | const int height = 3; |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 157 | SkPMColor pixels[height][width]; // allocate a 3x3 Premultiplied bitmap on the stack |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 158 | // create a SkCanvas backed by a raster device, and delete it when the |
| 159 | // function goes out of scope. |
| 160 | std::unique_ptr<SkCanvas> canvas = SkCanvas::MakeRasterDirectN32( |
| 161 | width, |
| 162 | height, |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 163 | pixels[0], // top-left of the bitmap |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 164 | sizeof(pixels[0])); // byte width of the each row |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 165 | // write a Premultiplied value for white into all pixels in the bitmap |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 166 | canvas->clear(SK_ColorWHITE); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 167 | SkPMColor pmWhite = pixels[0][0]; // the Premultiplied format may vary |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 168 | SkPaint paint; // by default, draws black |
| 169 | canvas->drawPoint(1, 1, paint); // draw in the center |
| 170 | canvas->flush(); // ensure that pixels is ready to be read |
| 171 | for (int y = 0; y < height; ++y) { |
| 172 | for (int x = 0; x < width; ++x) { |
| 173 | SkDebugf("%c", pixels[y][x] == pmWhite ? '-' : 'x'); |
| 174 | } |
| 175 | SkDebugf("\n"); |
| 176 | } |
| 177 | } |
| 178 | #StdOut |
| 179 | --- |
| 180 | -x- |
| 181 | --- |
| 182 | ## |
| 183 | ## |
| 184 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 185 | #SeeAlso MakeRasterDirect SkSurface::MakeRasterDirect SkImageInfo::MakeN32Premul |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 186 | |
| 187 | ## |
| 188 | |
| 189 | # ------------------------------------------------------------------------------ |
| 190 | |
| 191 | #Method SkCanvas() |
| 192 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 193 | #Line # creates with no Surface, no dimensions ## |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 194 | Creates an empty Canvas with no backing device or pixels, with |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 195 | a width and height of zero. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 196 | |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 197 | #Return empty Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 198 | |
| 199 | #Example |
| 200 | |
| 201 | #Description |
| 202 | Passes a placeholder to a function that requires one. |
| 203 | ## |
| 204 | |
| 205 | #Function |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 206 | // Returns true if either the canvas rotates the text by 90 degrees, or the paint does. |
| 207 | static void check_for_up_and_down_text(const SkCanvas* canvas, const SkPaint& paint) { |
| 208 | bool paintHasVertical = paint.isVerticalText(); |
| 209 | const SkMatrix& matrix = canvas->getTotalMatrix(); |
| 210 | bool matrixIsVertical = matrix.preservesRightAngles() && !matrix.isScaleTranslate(); |
| 211 | SkDebugf("paint draws text %s\n", paintHasVertical != matrixIsVertical ? |
| 212 | "top to bottom" : "left to right"); |
| 213 | } |
| 214 | |
| 215 | static void check_for_up_and_down_text(const SkPaint& paint) { |
| 216 | SkCanvas canvas; // placeholder only, does not have an associated device |
| 217 | check_for_up_and_down_text(&canvas, paint); |
| 218 | } |
| 219 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 220 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 221 | void draw(SkCanvas* canvas) { |
| 222 | SkPaint paint; |
| 223 | check_for_up_and_down_text(paint); // paint draws text left to right |
| 224 | paint.setVerticalText(true); |
| 225 | check_for_up_and_down_text(paint); // paint draws text top to bottom |
| 226 | paint.setVerticalText(false); |
| 227 | canvas->rotate(90); |
| 228 | check_for_up_and_down_text(canvas, paint); // paint draws text top to bottom |
| 229 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 230 | |
| 231 | #StdOut |
| 232 | paint draws text left to right |
| 233 | paint draws text top to bottom |
| 234 | paint draws text top to bottom |
| 235 | ## |
| 236 | ## |
| 237 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 238 | #SeeAlso MakeRasterDirect SkRasterHandleAllocator::MakeCanvas SkSurface::getCanvas SkCreateColorSpaceXformCanvas |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 239 | |
| 240 | ## |
| 241 | |
| 242 | # ------------------------------------------------------------------------------ |
| 243 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 244 | #Method SkCanvas(int width, int height, const SkSurfaceProps* props = nullptr) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 245 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 246 | #Line # creates with no Surface, set dimensions, Surface_Properties ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 247 | Creates Canvas of the specified dimensions without a Surface. |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 248 | Used by Subclasses with custom implementations for draw member functions. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 249 | |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 250 | If props equals nullptr, Surface_Properties are created with |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 251 | Surface_Properties_Legacy_Font_Host settings, which choose the pixel striping |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 252 | direction and order. Since a platform may dynamically change its direction when |
| 253 | the device is rotated, and since a platform may have multiple monitors with |
| 254 | different characteristics, it is best not to rely on this legacy behavior. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 255 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 256 | #Param width zero or greater ## |
| 257 | #Param height zero or greater ## |
| 258 | #Param props LCD striping orientation and setting for device independent fonts; |
| 259 | may be nullptr |
| 260 | ## |
| 261 | |
| 262 | #Return Canvas placeholder with dimensions ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 263 | |
| 264 | #Example |
| 265 | SkCanvas canvas(10, 20); // 10 units wide, 20 units high |
| 266 | canvas.clipRect(SkRect::MakeXYWH(30, 40, 5, 10)); // clip is outside canvas' device |
| 267 | SkDebugf("canvas %s empty\n", canvas.getDeviceClipBounds().isEmpty() ? "is" : "is not"); |
| 268 | |
| 269 | #StdOut |
| 270 | canvas is empty |
| 271 | ## |
| 272 | ## |
| 273 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 274 | #SeeAlso MakeRasterDirect SkSurfaceProps SkPixelGeometry SkCreateColorSpaceXformCanvas |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 275 | |
| 276 | ## |
| 277 | |
| 278 | # ------------------------------------------------------------------------------ |
| 279 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 280 | #Method explicit SkCanvas(sk_sp<SkBaseDevice> device) |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 281 | #Deprecated soon |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 282 | ## |
| 283 | |
| 284 | # ------------------------------------------------------------------------------ |
| 285 | |
| 286 | #Method explicit SkCanvas(const SkBitmap& bitmap) |
| 287 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 288 | #Line # uses existing Bitmap ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 289 | Constructs a canvas that draws into bitmap. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 290 | Sets SkSurfaceProps::kLegacyFontHost_InitType in constructed Surface. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 291 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 292 | Bitmap is copied so that subsequently editing bitmap will not affect |
| 293 | constructed Canvas. |
| 294 | |
| 295 | May be deprecated in the future. |
| 296 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 297 | #ToDo Should be deprecated? ## |
| 298 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 299 | #Param bitmap width, height, Color_Type, Alpha_Type, and pixel |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 300 | storage of Raster_Surface |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 301 | ## |
| 302 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 303 | #Return Canvas that can be used to draw into bitmap ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 304 | |
| 305 | #Example |
| 306 | #Description |
| 307 | The actual output depends on the installed fonts. |
| 308 | ## |
| 309 | SkBitmap bitmap; |
| 310 | // create a bitmap 5 wide and 11 high |
| 311 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(5, 11)); |
| 312 | SkCanvas canvas(bitmap); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 313 | canvas.clear(SK_ColorWHITE); // white is Unpremultiplied, in ARGB order |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 314 | SkPixmap pixmap; // provides guaranteed access to the drawn pixels |
| 315 | if (!canvas.peekPixels(&pixmap)) { |
| 316 | SkDebugf("peekPixels should never fail.\n"); |
| 317 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 318 | const SkPMColor* pixels = pixmap.addr32(); // points to top-left of bitmap |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 319 | SkPMColor pmWhite = pixels[0]; // the Premultiplied format may vary |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 320 | SkPaint paint; // by default, draws black, 12 point text |
| 321 | canvas.drawString("!", 1, 10, paint); // 1 char at baseline (1, 10) |
| 322 | for (int y = 0; y < bitmap.height(); ++y) { |
| 323 | for (int x = 0; x < bitmap.width(); ++x) { |
| 324 | SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x'); |
| 325 | } |
| 326 | SkDebugf("\n"); |
| 327 | } |
| 328 | |
| 329 | #StdOut |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 330 | ----- |
| 331 | ---x- |
| 332 | ---x- |
| 333 | ---x- |
| 334 | ---x- |
| 335 | ---x- |
| 336 | ---x- |
| 337 | ----- |
| 338 | ---x- |
| 339 | ---x- |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 340 | ----- |
| 341 | #StdOut ## |
| 342 | ## |
| 343 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 344 | #SeeAlso MakeRasterDirect SkRasterHandleAllocator::MakeCanvas SkSurface::getCanvas SkCreateColorSpaceXformCanvas |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 345 | |
| 346 | ## |
| 347 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 348 | #EnumClass ColorBehavior |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 349 | #Line # exists for Android framework only ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 350 | #Private |
| 351 | Android framework only. |
| 352 | ## |
| 353 | |
| 354 | #Code |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 355 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 356 | ## |
| 357 | #Const kLegacy 0 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 358 | #Line # placeholder ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 359 | Is a placeholder to allow specialized constructor; has no meaning. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 360 | ## |
| 361 | ## |
| 362 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 363 | #Method SkCanvas(const SkBitmap& bitmap, ColorBehavior behavior) |
| 364 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 365 | #Line # exists for Android framework only ## |
| 366 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 367 | For use by Android framework only. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 368 | |
| 369 | #Param bitmap specifies a bitmap for the canvas to draw into ## |
| 370 | #Param behavior specializes this constructor; value is unused ## |
| 371 | #Return Canvas that can be used to draw into bitmap ## |
| 372 | |
| 373 | #NoExample |
| 374 | ## |
| 375 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 376 | |
| 377 | # ------------------------------------------------------------------------------ |
| 378 | |
| 379 | #Method SkCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props) |
| 380 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 381 | #Line # uses existing Bitmap and Surface_Properties ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 382 | Constructs a canvas that draws into bitmap. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 383 | Use props to match the device characteristics, like LCD striping. |
| 384 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 385 | bitmap is copied so that subsequently editing bitmap will not affect |
| 386 | constructed Canvas. |
| 387 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 388 | #Param bitmap width, height, Color_Type, Alpha_Type, |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 389 | and pixel storage of Raster_Surface |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 390 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 391 | #Param props order and orientation of RGB striping; and whether to use |
| 392 | device independent fonts |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 393 | ## |
| 394 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 395 | #Return Canvas that can be used to draw into bitmap ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 396 | |
| 397 | #Example |
| 398 | #Description |
| 399 | The actual output depends on the installed fonts. |
| 400 | ## |
| 401 | SkBitmap bitmap; |
| 402 | // create a bitmap 5 wide and 11 high |
| 403 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(5, 11)); |
| 404 | SkCanvas canvas(bitmap, SkSurfaceProps(0, kUnknown_SkPixelGeometry)); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 405 | canvas.clear(SK_ColorWHITE); // white is Unpremultiplied, in ARGB order |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 406 | SkPixmap pixmap; // provides guaranteed access to the drawn pixels |
| 407 | if (!canvas.peekPixels(&pixmap)) { |
| 408 | SkDebugf("peekPixels should never fail.\n"); |
| 409 | } |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 410 | const SkPMColor* pixels = pixmap.addr32(); // points to top-left of bitmap |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 411 | SkPMColor pmWhite = pixels[0]; // the Premultiplied format may vary |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 412 | SkPaint paint; // by default, draws black, 12 point text |
| 413 | canvas.drawString("!", 1, 10, paint); // 1 char at baseline (1, 10) |
| 414 | for (int y = 0; y < bitmap.height(); ++y) { |
| 415 | for (int x = 0; x < bitmap.width(); ++x) { |
| 416 | SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x'); |
| 417 | } |
| 418 | SkDebugf("\n"); |
| 419 | } |
| 420 | |
| 421 | #StdOut |
| 422 | ----- |
| 423 | ---x- |
| 424 | ---x- |
| 425 | ---x- |
| 426 | ---x- |
| 427 | ---x- |
| 428 | ---x- |
| 429 | ----- |
| 430 | ---x- |
| 431 | ---x- |
| 432 | ----- |
| 433 | #StdOut ## |
| 434 | ## |
| 435 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 436 | #SeeAlso MakeRasterDirect SkRasterHandleAllocator::MakeCanvas SkSurface::getCanvas SkCreateColorSpaceXformCanvas |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 437 | |
| 438 | ## |
| 439 | |
| 440 | # ------------------------------------------------------------------------------ |
| 441 | |
| 442 | #Method virtual ~SkCanvas() |
| 443 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 444 | #Line # draws saved Layers, frees resources ## |
Cary Clark | 5081eed | 2018-01-22 07:55:48 -0500 | [diff] [blame] | 445 | Draws saved Layers, if any. |
| 446 | Frees up resources used by Canvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 447 | |
| 448 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 449 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 450 | Canvas Layer draws into bitmap. saveLayerAlpha sets up an additional |
| 451 | drawing surface that blends with the bitmap. When Layer goes out of |
| 452 | scope, Layer Destructor is called. The saved Layer is restored, drawing |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 453 | transparent letters. |
| 454 | ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 455 | void draw(SkCanvas* canvas) { |
| 456 | SkBitmap bitmap; |
| 457 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(200, 200)); |
| 458 | { |
| 459 | SkCanvas offscreen(bitmap); |
| 460 | SkPaint paint; |
| 461 | paint.setTextSize(100); |
| 462 | offscreen.drawString("ABC", 20, 160, paint); |
| 463 | SkRect layerBounds = SkRect::MakeXYWH(32, 32, 192, 192); |
| 464 | offscreen.saveLayerAlpha(&layerBounds, 128); |
| 465 | offscreen.clear(SK_ColorWHITE); |
| 466 | offscreen.drawString("DEF", 20, 160, paint); |
| 467 | } |
| 468 | canvas->drawBitmap(bitmap, 0, 0, nullptr); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 469 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 470 | ## |
| 471 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 472 | #SeeAlso State_Stack |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 473 | |
| 474 | ## |
| 475 | |
| 476 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 477 | #Subtopic Property |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 478 | #Line # metrics and attributes ## |
| 479 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 480 | |
| 481 | #Method SkMetaData& getMetaData() |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 482 | #In Property |
| 483 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 484 | #Line # associates additional data with the canvas ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 485 | Returns storage to associate additional data with the canvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 486 | The storage is freed when Canvas is deleted. |
| 487 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 488 | #Return storage that can be read from and written to ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 489 | |
| 490 | #Example |
| 491 | const char* kHelloMetaData = "HelloMetaData"; |
| 492 | SkCanvas canvas; |
| 493 | SkMetaData& metaData = canvas.getMetaData(); |
| 494 | SkDebugf("before: %s\n", metaData.findString(kHelloMetaData)); |
| 495 | metaData.setString(kHelloMetaData, "Hello!"); |
| 496 | SkDebugf("during: %s\n", metaData.findString(kHelloMetaData)); |
| 497 | metaData.removeString(kHelloMetaData); |
| 498 | SkDebugf("after: %s\n", metaData.findString(kHelloMetaData)); |
| 499 | |
| 500 | #StdOut |
| 501 | before: (null) |
| 502 | during: Hello! |
| 503 | after: (null) |
| 504 | #StdOut ## |
| 505 | ## |
| 506 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 507 | #SeeAlso SkMetaData |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 508 | |
| 509 | ## |
| 510 | |
| 511 | # ------------------------------------------------------------------------------ |
| 512 | |
| 513 | #Method SkImageInfo imageInfo() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 514 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 515 | #Line # returns Image_Info for Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 516 | 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] | 517 | GPU_Surface, returned Color_Type is set to kUnknown_SkColorType. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 518 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 519 | #Return dimensions and Color_Type of Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 520 | |
| 521 | #Example |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 522 | SkCanvas emptyCanvas; |
| 523 | SkImageInfo canvasInfo = emptyCanvas.imageInfo(); |
| 524 | SkImageInfo emptyInfo; |
| 525 | SkDebugf("emptyInfo %c= canvasInfo\n", emptyInfo == canvasInfo ? '=' : '!'); |
| 526 | |
| 527 | #StdOut |
| 528 | emptyInfo == canvasInfo |
| 529 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 530 | ## |
| 531 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 532 | #SeeAlso SkImageInfo MakeRasterDirect makeSurface |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 533 | |
| 534 | ## |
| 535 | |
| 536 | # ------------------------------------------------------------------------------ |
| 537 | |
| 538 | #Method bool getProps(SkSurfaceProps* props) const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 539 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 540 | #Line # copies Surface_Properties if available ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 541 | Copies Surface_Properties, if Canvas is associated with Raster_Surface or |
| 542 | GPU_Surface, and returns true. Otherwise, returns false and leave props unchanged. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 543 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 544 | #Param props storage for writable SkSurfaceProps ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 545 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 546 | #Return true if Surface_Properties was copied ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 547 | |
| 548 | #ToDo This seems old style. Deprecate? ## |
| 549 | |
| 550 | #Example |
| 551 | SkBitmap bitmap; |
| 552 | SkCanvas canvas(bitmap, SkSurfaceProps(0, kRGB_V_SkPixelGeometry)); |
| 553 | SkSurfaceProps surfaceProps(0, kUnknown_SkPixelGeometry); |
| 554 | SkDebugf("isRGB:%d\n", SkPixelGeometryIsRGB(surfaceProps.pixelGeometry())); |
| 555 | if (!canvas.getProps(&surfaceProps)) { |
| 556 | SkDebugf("getProps failed unexpectedly.\n"); |
| 557 | } |
| 558 | SkDebugf("isRGB:%d\n", SkPixelGeometryIsRGB(surfaceProps.pixelGeometry())); |
| 559 | |
| 560 | #StdOut |
| 561 | isRGB:0 |
| 562 | isRGB:1 |
| 563 | #StdOut ## |
| 564 | ## |
| 565 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 566 | #SeeAlso SkSurfaceProps makeSurface |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 567 | |
| 568 | ## |
| 569 | |
| 570 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 571 | #Subtopic Utility |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 572 | #Line # rarely called management functions ## |
| 573 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 574 | |
| 575 | #Method void flush() |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 576 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 577 | #Line # triggers execution of all pending draw operations ## |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 578 | Triggers the immediate execution of all pending draw operations. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 579 | If Canvas is associated with GPU_Surface, resolves all pending GPU operations. |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 580 | If Canvas is associated with Raster_Surface, has no effect; raster draw |
| 581 | operations are never deferred. |
| 582 | |
| 583 | #ToDo |
| 584 | In an overview section on managing the GPU, include: |
| 585 | - flush should never change what is drawn |
| 586 | - call to kick off gpu work |
| 587 | - calling too much impacts performance |
| 588 | - some calls (peekPixels, prepareForExternalIO) call it internally |
| 589 | - canvas call is local, GrContext::flush is global |
| 590 | - diffentiate between flush, flushAndSignalSemaphores |
| 591 | - normally never needs to be called |
| 592 | - call it when sharing gpu resources, feeling memory pressure, swapping out app, and before |
| 593 | abandoning context |
| 594 | - also call to say "I'm finished drawing here", e.g., when drawing to a GPU-backed offscreen surface |
| 595 | (created with SkSurface::MakeRenderTarget) |
| 596 | |
| 597 | for posterity: this doesn't show a difference: fiddle.skia.org/c/@flushfail |
| 598 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 599 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 600 | #ToDo haven't thought of a useful example to put here ## |
| 601 | #NoExample |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 602 | ## |
| 603 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 604 | #SeeAlso peekPixels SkSurface::flush() GrContext::flush() SkSurface::prepareForExternalIO GrContext::abandonContext() |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 605 | |
| 606 | ## |
| 607 | |
| 608 | # ------------------------------------------------------------------------------ |
| 609 | |
| 610 | #Method virtual SkISize getBaseLayerSize() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 611 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 612 | #Line # returns size of base Layer in global coordinates ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 613 | Gets the size of the base or root Layer in global canvas coordinates. The |
| 614 | 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] | 615 | smaller (due to clipping or saveLayer). |
| 616 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 617 | #Return integral width and height of base Layer ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 618 | |
| 619 | #Example |
| 620 | SkBitmap bitmap; |
| 621 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(20, 30)); |
| 622 | SkCanvas canvas(bitmap, SkSurfaceProps(0, kUnknown_SkPixelGeometry)); |
| 623 | canvas.clipRect(SkRect::MakeWH(10, 40)); |
| 624 | SkIRect clipDeviceBounds = canvas.getDeviceClipBounds(); |
| 625 | if (clipDeviceBounds.isEmpty()) { |
| 626 | SkDebugf("Empty clip bounds is unexpected!\n"); |
| 627 | } |
| 628 | SkDebugf("clip=%d,%d\n", clipDeviceBounds.width(), clipDeviceBounds.height()); |
| 629 | SkISize baseLayerSize = canvas.getBaseLayerSize(); |
| 630 | SkDebugf("size=%d,%d\n", baseLayerSize.width(), baseLayerSize.height()); |
| 631 | |
| 632 | #StdOut |
| 633 | clip=10,30 |
| 634 | size=20,30 |
| 635 | ## |
| 636 | ## |
| 637 | |
| 638 | #ToDo is this the same as the width and height of surface? ## |
| 639 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 640 | #SeeAlso getDeviceClipBounds |
| 641 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 642 | ## |
| 643 | |
| 644 | # ------------------------------------------------------------------------------ |
| 645 | |
| 646 | #Method sk_sp<SkSurface> makeSurface(const SkImageInfo& info, const SkSurfaceProps* props = nullptr) |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 647 | #In Constructors |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 648 | #Line # creates Surface matching SkImageInfo and SkSurfaceProps ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 649 | Creates Surface matching info and props, and associates it with Canvas. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 650 | Returns nullptr if no match found. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 651 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 652 | If props is nullptr, matches Surface_Properties in Canvas. If props is nullptr and Canvas |
| 653 | does not have Surface_Properties, creates Surface with default Surface_Properties. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 654 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 655 | #Param info width, height, Color_Type, Alpha_Type, and Color_Space ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 656 | #Param props Surface_Properties to match; may be nullptr to match Canvas ## |
| 657 | |
| 658 | #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] | 659 | |
| 660 | #Example |
| 661 | sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(5, 6); |
| 662 | SkCanvas* smallCanvas = surface->getCanvas(); |
| 663 | SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(3, 4); |
| 664 | sk_sp<SkSurface> compatible = smallCanvas->makeSurface(imageInfo); |
| 665 | SkDebugf("compatible %c= nullptr\n", compatible == nullptr ? '=' : '!'); |
| 666 | SkDebugf("size = %d, %d\n", compatible->width(), compatible->height()); |
| 667 | |
| 668 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 669 | compatible != nullptr |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 670 | size = 3, 4 |
| 671 | ## |
| 672 | ## |
| 673 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 674 | #SeeAlso SkSurface SkSurface::makeSurface SkImageInfo SkSurfaceProps |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 675 | |
| 676 | ## |
| 677 | |
| 678 | # ------------------------------------------------------------------------------ |
| 679 | |
| 680 | #Method virtual GrContext* getGrContext() |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 681 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 682 | #Line # returns GPU_Context of the GPU_Surface ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 683 | Returns GPU_Context of the GPU_Surface associated with Canvas. |
| 684 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 685 | #Return GPU_Context, if available; nullptr otherwise ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 686 | |
| 687 | #Example |
| 688 | void draw(SkCanvas* canvas) { |
| 689 | if (canvas->getGrContext()) { |
| 690 | canvas->clear(SK_ColorRED); |
| 691 | } else { |
| 692 | canvas->clear(SK_ColorBLUE); |
| 693 | } |
| 694 | } |
| 695 | ## |
| 696 | |
| 697 | #ToDo fiddle should show both CPU and GPU out ## |
| 698 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 699 | #SeeAlso GrContext |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 700 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 701 | ## |
| 702 | |
| 703 | # ------------------------------------------------------------------------------ |
| 704 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 705 | #Method void* accessTopLayerPixels(SkImageInfo* info, size_t* rowBytes, SkIPoint* origin = nullptr) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 706 | #In Utility |
| 707 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 708 | #Line # returns writable pixel access if available ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 709 | 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] | 710 | can be read directly. The returned address is only valid |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 711 | while Canvas is in scope and unchanged. Any Canvas call or Surface call |
| 712 | may invalidate the returned address and other returned values. |
| 713 | |
| 714 | If pixels are inaccessible, info, rowBytes, and origin are unchanged. |
| 715 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 716 | #Param info storage for writable pixels' Image_Info; may be nullptr ## |
| 717 | #Param rowBytes storage for writable pixels' row bytes; may be nullptr ## |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 718 | #Param origin storage for Canvas top Layer origin, its top-left corner; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 719 | may be nullptr |
| 720 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 721 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 722 | #Return address of pixels, or nullptr if inaccessible ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 723 | |
| 724 | #Example |
| 725 | void draw(SkCanvas* canvas) { |
| 726 | if (canvas->accessTopLayerPixels(nullptr, nullptr)) { |
| 727 | canvas->clear(SK_ColorRED); |
| 728 | } else { |
| 729 | canvas->clear(SK_ColorBLUE); |
| 730 | } |
| 731 | } |
| 732 | ## |
| 733 | |
| 734 | #Example |
| 735 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 736 | Draws "ABC" on the device. Then draws "DEF" in Layer, and reads |
| 737 | Layer to add a large dotted "DEF". Finally blends Layer with the |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 738 | device. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 739 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 740 | 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] | 741 | "DEF" appear only on the CPU. |
| 742 | ## |
| 743 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 744 | SkPaint paint; |
| 745 | paint.setTextSize(100); |
| 746 | canvas->drawString("ABC", 20, 160, paint); |
| 747 | SkRect layerBounds = SkRect::MakeXYWH(32, 32, 192, 192); |
| 748 | canvas->saveLayerAlpha(&layerBounds, 128); |
| 749 | canvas->clear(SK_ColorWHITE); |
| 750 | canvas->drawString("DEF", 20, 160, paint); |
| 751 | SkImageInfo imageInfo; |
| 752 | size_t rowBytes; |
| 753 | SkIPoint origin; |
| 754 | uint32_t* access = (uint32_t*) canvas->accessTopLayerPixels(&imageInfo, &rowBytes, &origin); |
| 755 | if (access) { |
| 756 | int h = imageInfo.height(); |
| 757 | int v = imageInfo.width(); |
| 758 | int rowWords = rowBytes / sizeof(uint32_t); |
| 759 | for (int y = 0; y < h; ++y) { |
| 760 | int newY = (y - h / 2) * 2 + h / 2; |
| 761 | if (newY < 0 || newY >= h) { |
| 762 | continue; |
| 763 | } |
| 764 | for (int x = 0; x < v; ++x) { |
| 765 | int newX = (x - v / 2) * 2 + v / 2; |
| 766 | if (newX < 0 || newX >= v) { |
| 767 | continue; |
| 768 | } |
| 769 | if (access[y * rowWords + x] == SK_ColorBLACK) { |
| 770 | access[newY * rowWords + newX] = SK_ColorGRAY; |
| 771 | } |
| 772 | } |
| 773 | } |
| 774 | |
| 775 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 776 | canvas->restore(); |
| 777 | } |
| 778 | ## |
| 779 | |
| 780 | #ToDo there are no callers of this that I can find. Deprecate? ## |
| 781 | #ToDo fiddle should show both CPU and GPU out ## |
| 782 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 783 | #SeeAlso SkImageInfo SkPixmap |
| 784 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 785 | ## |
| 786 | |
| 787 | # ------------------------------------------------------------------------------ |
| 788 | |
| 789 | #Method SkRasterHandleAllocator::Handle accessTopRasterHandle() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 790 | #In Utility |
| 791 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 792 | #Line # returns context that tracks Clip and Matrix ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 793 | Returns custom context that tracks the Matrix and Clip. |
| 794 | |
| 795 | 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] | 796 | 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] | 797 | SkRasterHandleAllocator::MakeCanvas, which creates a custom canvas with raster storage for |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 798 | the drawing destination. |
| 799 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 800 | #Return context of custom allocation ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 801 | |
| 802 | #Example |
| 803 | #Description |
| 804 | #ToDo ## |
| 805 | ## |
| 806 | #Function |
| 807 | static void DeleteCallback(void*, void* context) { |
| 808 | delete (char*) context; |
| 809 | } |
| 810 | |
| 811 | class CustomAllocator : public SkRasterHandleAllocator { |
| 812 | public: |
| 813 | bool allocHandle(const SkImageInfo& info, Rec* rec) override { |
| 814 | char* context = new char[4]{'s', 'k', 'i', 'a'}; |
| 815 | rec->fReleaseProc = DeleteCallback; |
| 816 | rec->fReleaseCtx = context; |
| 817 | rec->fHandle = context; |
| 818 | rec->fPixels = context; |
| 819 | rec->fRowBytes = 4; |
| 820 | return true; |
| 821 | } |
| 822 | |
| 823 | void updateHandle(Handle handle, const SkMatrix& ctm, const SkIRect& clip_bounds) override { |
| 824 | // apply canvas matrix and clip to custom environment |
| 825 | } |
| 826 | }; |
| 827 | |
| 828 | ## |
| 829 | void draw(SkCanvas* canvas) { |
| 830 | const SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1); |
| 831 | std::unique_ptr<SkCanvas> c2 = |
| 832 | SkRasterHandleAllocator::MakeCanvas(std::unique_ptr<CustomAllocator>( |
| 833 | new CustomAllocator()), info); |
| 834 | char* context = (char*) c2->accessTopRasterHandle(); |
| 835 | SkDebugf("context = %.4s\n", context); |
| 836 | |
| 837 | } |
| 838 | #StdOut |
| 839 | context = skia |
| 840 | ## |
| 841 | #ToDo skstd::make_unique could not be used because def is private -- note to fix in c++14? ## |
| 842 | ## |
| 843 | |
| 844 | #SeeAlso SkRasterHandleAllocator |
| 845 | |
| 846 | ## |
| 847 | |
| 848 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 849 | #Subtopic Pixels |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 850 | #Line # read and write pixel values ## |
| 851 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 852 | |
| 853 | #Method bool peekPixels(SkPixmap* pixmap) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 854 | #In Pixels |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 855 | #Line # returns if Canvas has direct access to its pixels ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 856 | Returns true if Canvas has direct access to its pixels. |
| 857 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 858 | 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] | 859 | is returned from GPU_Surface, returned by SkDocument::beginPage, returned by |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 860 | SkPictureRecorder::beginRecording, or Canvas is the base of a utility class |
Brian Osman | 46fe9c7 | 2018-03-09 15:44:34 -0500 | [diff] [blame] | 861 | like SkDebugCanvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 862 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 863 | pixmap is valid only while Canvas is in scope and unchanged. Any |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 864 | Canvas or Surface call may invalidate the pixmap values. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 865 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 866 | #Param pixmap storage for pixel state if pixels are readable; otherwise, ignored ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 867 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 868 | #Return true if Canvas has direct access to pixels ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 869 | |
| 870 | #Example |
| 871 | SkPixmap pixmap; |
| 872 | if (canvas->peekPixels(&pixmap)) { |
| 873 | SkDebugf("width=%d height=%d\n", pixmap.bounds().width(), pixmap.bounds().height()); |
| 874 | } |
| 875 | #StdOut |
| 876 | width=256 height=256 |
| 877 | ## |
| 878 | ## |
| 879 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 880 | #SeeAlso readPixels SkBitmap::peekPixels SkImage::peekPixels SkSurface::peekPixels |
| 881 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 882 | ## |
| 883 | |
| 884 | # ------------------------------------------------------------------------------ |
| 885 | |
| 886 | #Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, |
| 887 | int srcX, int srcY) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 888 | #In Pixels |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 889 | #Line # copies and converts rectangle of pixels from Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 890 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 891 | Copies Rect of pixels from Canvas into dstPixels. Matrix and Clip are |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 892 | ignored. |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 893 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 894 | Source Rect corners are (srcX, srcY) and (imageInfo().width(), imageInfo().height()). |
| 895 | Destination Rect corners are (0, 0) and (dstInfo.width(), dstInfo.height()). |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 896 | Copies each readable pixel intersecting both rectangles, without scaling, |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 897 | converting to dstInfo.colorType() and dstInfo.alphaType() if required. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 898 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 899 | Pixels are readable when Device is raster, or backed by a GPU. |
| 900 | Pixels are not readable when SkCanvas is returned by SkDocument::beginPage, |
| 901 | returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility |
Brian Osman | 46fe9c7 | 2018-03-09 15:44:34 -0500 | [diff] [blame] | 902 | class like SkDebugCanvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 903 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 904 | The destination pixel storage must be allocated by the caller. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 905 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 906 | Pixel values are converted only if Color_Type and Alpha_Type |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 907 | do not match. Only pixels within both source and destination rectangles |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 908 | are copied. dstPixels contents outside Rect intersection are unchanged. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 909 | |
| 910 | 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] | 911 | |
| 912 | Does not copy, and returns false if: |
| 913 | |
| 914 | #List |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 915 | # Source and destination rectangles do not intersect. ## |
| 916 | # Canvas pixels could not be converted to dstInfo.colorType() or dstInfo.alphaType(). ## |
| 917 | # Canvas pixels are not readable; for instance, Canvas is document-based. ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 918 | # dstRowBytes is too small to contain one row of pixels. ## |
| 919 | ## |
| 920 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 921 | #Param dstInfo width, height, Color_Type, and Alpha_Type of dstPixels ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 922 | #Param dstPixels storage for pixels; dstInfo.height() times dstRowBytes, or larger ## |
| 923 | #Param dstRowBytes size of one destination row; dstInfo.width() times pixel size, or larger ## |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 924 | #Param srcX offset into readable pixels on x-axis; may be negative ## |
| 925 | #Param srcY offset into readable pixels on y-axis; may be negative ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 926 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 927 | #Return true if pixels were copied ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 928 | |
| 929 | #Example |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 930 | #Width 64 |
| 931 | #Height 64 |
| 932 | #Description |
| 933 | A black circle drawn on a blue background provides an image to copy. |
| 934 | 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] | 935 | The copied quarter circles overdraw the original circle. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 936 | ## |
| 937 | canvas->clear(SK_ColorBLUE); |
| 938 | SkPaint paint; |
| 939 | canvas->drawCircle(32, 32, 28, paint); |
| 940 | SkImageInfo info = SkImageInfo::Make(64, 64, kBGRA_8888_SkColorType, kPremul_SkAlphaType); |
| 941 | sk_sp<SkData> data(SkData::MakeUninitialized(info.minRowBytes() * info.height())); |
| 942 | sk_bzero(data->writable_data(), info.minRowBytes() * info.height()); |
| 943 | for (int x : { 32, -32 } ) { |
| 944 | for (int y : { 32, -32 } ) { |
| 945 | canvas->readPixels(info, data->writable_data(), info.minRowBytes(), x, y); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 946 | } |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 947 | } |
| 948 | sk_sp<SkImage> image = SkImage::MakeRasterData(info, data, info.minRowBytes()); |
| 949 | canvas->drawImage(image, 0, 0); |
| 950 | ## |
| 951 | |
| 952 | #Example |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 953 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 954 | Canvas returned by Raster_Surface has Premultiplied pixel values. |
| 955 | clear() takes Unpremultiplied input with Color_Alpha equal 0x80 |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 956 | and RGB equal 0x55, 0xAA, 0xFF. RGB is multiplied by Color_Alpha |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 957 | to generate Premultiplied value 0x802B5580. readPixels converts pixel back |
| 958 | to Unpremultiplied value 0x8056A9FF, introducing error. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 959 | ## |
| 960 | canvas->clear(0x8055aaff); |
| 961 | for (SkAlphaType alphaType : { kPremul_SkAlphaType, kUnpremul_SkAlphaType } ) { |
| 962 | uint32_t pixel = 0; |
| 963 | SkImageInfo info = SkImageInfo::Make(1, 1, kBGRA_8888_SkColorType, alphaType); |
| 964 | if (canvas->readPixels(info, &pixel, 4, 0, 0)) { |
| 965 | SkDebugf("pixel = %08x\n", pixel); |
| 966 | } |
| 967 | } |
| 968 | |
| 969 | #StdOut |
| 970 | pixel = 802b5580 |
| 971 | pixel = 8056a9ff |
| 972 | ## |
| 973 | ## |
| 974 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 975 | #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] | 976 | |
| 977 | ## |
| 978 | |
| 979 | # ------------------------------------------------------------------------------ |
| 980 | |
| 981 | #Method bool readPixels(const SkPixmap& pixmap, int srcX, int srcY) |
| 982 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 983 | Copies Rect of pixels from Canvas into pixmap. Matrix and Clip are |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 984 | ignored. |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 985 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 986 | Source Rect corners are (srcX, srcY) and (imageInfo().width(), imageInfo().height()). |
| 987 | Destination Rect corners are (0, 0) and (pixmap.width(), pixmap.height()). |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 988 | Copies each readable pixel intersecting both rectangles, without scaling, |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 989 | converting to pixmap.colorType() and pixmap.alphaType() if required. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 990 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 991 | Pixels are readable when Device is raster, or backed by a GPU. |
| 992 | Pixels are not readable when SkCanvas is returned by SkDocument::beginPage, |
| 993 | returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility |
Brian Osman | 46fe9c7 | 2018-03-09 15:44:34 -0500 | [diff] [blame] | 994 | class like SkDebugCanvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 995 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 996 | Caller must allocate pixel storage in pixmap if needed. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 997 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 998 | Pixel values are converted only if Color_Type and Alpha_Type |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 999 | do not match. Only pixels within both source and destination Rects |
| 1000 | are copied. pixmap pixels contents outside Rect intersection are unchanged. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1001 | |
| 1002 | 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] | 1003 | |
| 1004 | Does not copy, and returns false if: |
| 1005 | |
| 1006 | #List |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1007 | # Source and destination rectangles do not intersect. ## |
| 1008 | # Canvas pixels could not be converted to pixmap.colorType() or pixmap.alphaType(). ## |
| 1009 | # Canvas pixels are not readable; for instance, Canvas is document-based. ## |
| 1010 | # Pixmap pixels could not be allocated. ## |
| 1011 | # pixmap.rowBytes() is too small to contain one row of pixels. ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1012 | ## |
| 1013 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1014 | #Param pixmap storage for pixels copied from Canvas ## |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 1015 | #Param srcX offset into readable pixels on x-axis; may be negative ## |
| 1016 | #Param srcY offset into readable pixels on y-axis; may be negative ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1017 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1018 | #Return true if pixels were copied ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1019 | |
| 1020 | #Example |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1021 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1022 | clear() takes Unpremultiplied input with Color_Alpha equal 0x80 |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1023 | and RGB equal 0x55, 0xAA, 0xFF. RGB is multiplied by Color_Alpha |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1024 | to generate Premultiplied value 0x802B5580. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1025 | ## |
| 1026 | void draw(SkCanvas* canvas) { |
| 1027 | canvas->clear(0x8055aaff); |
| 1028 | uint32_t pixels[1] = { 0 }; |
| 1029 | SkPixmap pixmap(SkImageInfo::MakeN32Premul(1, 1), pixels, 4); |
| 1030 | canvas->readPixels(pixmap, 0, 0); |
| 1031 | SkDebugf("pixel = %08x\n", pixels[0]); |
| 1032 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1033 | #StdOut |
| 1034 | pixel = 802b5580 |
| 1035 | ## |
| 1036 | ## |
| 1037 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1038 | #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] | 1039 | |
| 1040 | ## |
| 1041 | |
| 1042 | # ------------------------------------------------------------------------------ |
| 1043 | |
| 1044 | #Method bool readPixels(const SkBitmap& bitmap, int srcX, int srcY) |
| 1045 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1046 | Copies Rect of pixels from Canvas into bitmap. Matrix and Clip are |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1047 | ignored. |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1048 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1049 | Source Rect corners are (srcX, srcY) and (imageInfo().width(), imageInfo().height()). |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1050 | Destination Rect corners are (0, 0) and (bitmap.width(), bitmap.height()). |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1051 | Copies each readable pixel intersecting both rectangles, without scaling, |
| 1052 | converting to bitmap.colorType() and bitmap.alphaType() if required. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1053 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1054 | Pixels are readable when Device is raster, or backed by a GPU. |
| 1055 | Pixels are not readable when SkCanvas is returned by SkDocument::beginPage, |
| 1056 | returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility |
Brian Osman | 46fe9c7 | 2018-03-09 15:44:34 -0500 | [diff] [blame] | 1057 | class like SkDebugCanvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1058 | |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1059 | Caller must allocate pixel storage in bitmap if needed. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1060 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1061 | Bitmap values are converted only if Color_Type and Alpha_Type |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1062 | do not match. Only pixels within both source and destination rectangles |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1063 | are copied. Bitmap pixels outside Rect intersection are unchanged. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1064 | |
| 1065 | 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] | 1066 | |
| 1067 | Does not copy, and returns false if: |
| 1068 | |
| 1069 | #List |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1070 | # Source and destination rectangles do not intersect. ## |
| 1071 | # Canvas pixels could not be converted to bitmap.colorType() or bitmap.alphaType(). ## |
| 1072 | # Canvas pixels are not readable; for instance, Canvas is document-based. ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1073 | # bitmap pixels could not be allocated. ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1074 | # bitmap.rowBytes() is too small to contain one row of pixels. ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1075 | ## |
| 1076 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1077 | #Param bitmap storage for pixels copied from Canvas ## |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 1078 | #Param srcX offset into readable pixels on x-axis; may be negative ## |
| 1079 | #Param srcY offset into readable pixels on y-axis; may be negative ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1080 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1081 | #Return true if pixels were copied ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1082 | |
| 1083 | #Example |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1084 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1085 | clear() takes Unpremultiplied input with Color_Alpha equal 0x80 |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1086 | and RGB equal 0x55, 0xAA, 0xFF. RGB is multiplied by Color_Alpha |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1087 | to generate Premultiplied value 0x802B5580. |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1088 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1089 | void draw(SkCanvas* canvas) { |
| 1090 | canvas->clear(0x8055aaff); |
| 1091 | SkBitmap bitmap; |
| 1092 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(1, 1)); |
| 1093 | canvas->readPixels(bitmap, 0, 0); |
| 1094 | SkDebugf("pixel = %08x\n", bitmap.getAddr32(0, 0)[0]); |
| 1095 | } |
| 1096 | #StdOut |
| 1097 | pixel = 802b5580 |
| 1098 | ## |
| 1099 | ## |
| 1100 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1101 | #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] | 1102 | |
| 1103 | ## |
| 1104 | |
| 1105 | # ------------------------------------------------------------------------------ |
| 1106 | |
| 1107 | #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] | 1108 | #In Pixels |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1109 | #Line # copies and converts rectangle of pixels to Canvas ## |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1110 | Copies Rect from pixels to Canvas. Matrix and Clip are ignored. |
| 1111 | Source Rect corners are (0, 0) and (info.width(), info.height()). |
| 1112 | Destination Rect corners are (x, y) and |
| 1113 | (imageInfo().width(), imageInfo().height()). |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1114 | |
| 1115 | Copies each readable pixel intersecting both rectangles, without scaling, |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1116 | converting to imageInfo().colorType() and imageInfo().alphaType() if required. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1117 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1118 | Pixels are writable when Device is raster, or backed by a GPU. |
| 1119 | Pixels are not writable when SkCanvas is returned by SkDocument::beginPage, |
| 1120 | returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility |
Brian Osman | 46fe9c7 | 2018-03-09 15:44:34 -0500 | [diff] [blame] | 1121 | class like SkDebugCanvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1122 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1123 | Pixel values are converted only if Color_Type and Alpha_Type |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1124 | do not match. Only pixels within both source and destination rectangles |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1125 | are copied. Canvas pixels outside Rect intersection are unchanged. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1126 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1127 | Pass negative values for x or y to offset pixels to the left or |
| 1128 | above Canvas pixels. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1129 | |
| 1130 | Does not copy, and returns false if: |
| 1131 | |
| 1132 | #List |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1133 | # Source and destination rectangles do not intersect. ## |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1134 | # pixels could not be converted to Canvas imageInfo().colorType() or |
| 1135 | imageInfo().alphaType(). ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1136 | # Canvas pixels are not writable; for instance, Canvas is document-based. ## |
| 1137 | # rowBytes is too small to contain one row of pixels. ## |
| 1138 | ## |
| 1139 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1140 | #Param info width, height, Color_Type, and Alpha_Type of pixels ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1141 | #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] | 1142 | #Param rowBytes size of one row of pixels; info.width() times pixel size, or larger ## |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 1143 | #Param x offset into Canvas writable pixels on x-axis; may be negative ## |
| 1144 | #Param y offset into Canvas writable pixels on y-axis; may be negative ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1145 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1146 | #Return true if pixels were written to Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1147 | |
| 1148 | #Example |
| 1149 | SkImageInfo imageInfo = SkImageInfo::MakeN32(256, 1, kPremul_SkAlphaType); |
| 1150 | for (int y = 0; y < 256; ++y) { |
| 1151 | uint32_t pixels[256]; |
| 1152 | for (int x = 0; x < 256; ++x) { |
| 1153 | pixels[x] = SkColorSetARGB(x, x + y, x, x - y); |
| 1154 | } |
| 1155 | canvas->writePixels(imageInfo, &pixels, sizeof(pixels), 0, y); |
| 1156 | } |
| 1157 | ## |
| 1158 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1159 | #SeeAlso readPixels drawBitmap drawImage SkBitmap::writePixels |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1160 | |
| 1161 | ## |
| 1162 | |
| 1163 | # ------------------------------------------------------------------------------ |
| 1164 | |
| 1165 | #Method bool writePixels(const SkBitmap& bitmap, int x, int y) |
| 1166 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1167 | Copies Rect from pixels to Canvas. Matrix and Clip are ignored. |
| 1168 | Source Rect corners are (0, 0) and (bitmap.width(), bitmap.height()). |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1169 | |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1170 | Destination Rect corners are (x, y) and |
| 1171 | (imageInfo().width(), imageInfo().height()). |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 1172 | |
| 1173 | Copies each readable pixel intersecting both rectangles, without scaling, |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1174 | converting to imageInfo().colorType() and imageInfo().alphaType() if required. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1175 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1176 | Pixels are writable when Device is raster, or backed by a GPU. |
| 1177 | Pixels are not writable when SkCanvas is returned by SkDocument::beginPage, |
| 1178 | returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility |
Brian Osman | 46fe9c7 | 2018-03-09 15:44:34 -0500 | [diff] [blame] | 1179 | class like SkDebugCanvas. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1180 | |
Cary Clark | 2dc84ad | 2018-01-26 12:56:22 -0500 | [diff] [blame] | 1181 | Pixel values are converted only if Color_Type and Alpha_Type |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1182 | do not match. Only pixels within both source and destination rectangles |
Cary Clark | 154beea | 2017-10-26 07:58:48 -0400 | [diff] [blame] | 1183 | are copied. Canvas pixels outside Rect intersection are unchanged. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1184 | |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1185 | Pass negative values for x or y to offset pixels to the left or |
| 1186 | above Canvas pixels. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1187 | |
| 1188 | Does not copy, and returns false if: |
| 1189 | |
| 1190 | #List |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1191 | # Source and destination rectangles do not intersect. ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1192 | # bitmap does not have allocated pixels. ## |
Cary Clark | ac47b88 | 2018-01-11 10:35:44 -0500 | [diff] [blame] | 1193 | # bitmap pixels could not be converted to Canvas imageInfo().colorType() or |
| 1194 | imageInfo().alphaType(). ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1195 | # Canvas pixels are not writable; for instance, Canvas is document based. ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1196 | # bitmap pixels are inaccessible; for instance, bitmap wraps a texture. ## |
| 1197 | ## |
| 1198 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1199 | #Param bitmap contains pixels copied to Canvas ## |
Cary Clark | f05bdda | 2017-08-24 12:59:48 -0400 | [diff] [blame] | 1200 | #Param x offset into Canvas writable pixels in x; may be negative ## |
| 1201 | #Param y offset into Canvas writable pixels in y; may be negative ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1202 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1203 | #Return true if pixels were written to Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1204 | |
| 1205 | #Example |
| 1206 | void draw(SkCanvas* canvas) { |
| 1207 | SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(2, 2); |
| 1208 | SkBitmap bitmap; |
| 1209 | bitmap.setInfo(imageInfo); |
| 1210 | uint32_t pixels[4]; |
| 1211 | bitmap.setPixels(pixels); |
| 1212 | for (int y = 0; y < 256; y += 2) { |
| 1213 | for (int x = 0; x < 256; x += 2) { |
| 1214 | pixels[0] = SkColorSetRGB(x, y, x | y); |
| 1215 | pixels[1] = SkColorSetRGB(x ^ y, y, x); |
| 1216 | pixels[2] = SkColorSetRGB(x, x & y, y); |
| 1217 | pixels[3] = SkColorSetRGB(~x, ~y, x); |
| 1218 | canvas->writePixels(bitmap, x, y); |
| 1219 | } |
| 1220 | } |
| 1221 | } |
| 1222 | ## |
| 1223 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1224 | #SeeAlso readPixels drawBitmap drawImage SkBitmap::writePixels |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1225 | |
| 1226 | ## |
| 1227 | |
| 1228 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1229 | #Subtopic State_Stack |
| 1230 | #Line # stack of state for hierarchical drawing ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1231 | |
| 1232 | Canvas maintains a stack of state that allows hierarchical drawing, commonly used |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1233 | to implement windows and views. The initial state has an identity matrix and and |
| 1234 | an infinite clip. Even with a wide-open clip, drawing is constrained by the |
| 1235 | bounds of the Canvas Surface or Device. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1236 | |
Cary Clark | 939fd6c | 2018-07-12 08:40:13 -0400 | [diff] [blame] | 1237 | Canvas savable state consists of Clip and Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1238 | Clip describes the area that may be drawn to. |
| 1239 | Matrix transforms the geometry. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1240 | |
| 1241 | save(), saveLayer, saveLayerPreserveLCDTextRequests, and saveLayerAlpha |
| 1242 | save state and return the depth of the stack. |
| 1243 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1244 | restore(), restoreToCount, and ~SkCanvas() revert state to its value when saved. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1245 | |
| 1246 | Each state on the stack intersects Clip with the previous Clip, |
| 1247 | and concatenates Matrix with the previous Matrix. |
| 1248 | The intersected Clip makes the drawing area the same or smaller; |
| 1249 | the concatenated Matrix may move the origin and potentially scale or rotate |
| 1250 | the coordinate space. |
| 1251 | |
| 1252 | Canvas does not require balancing the state stack but it is a good idea |
| 1253 | to do so. Calling save() without restore() will eventually cause Skia to fail; |
| 1254 | mismatched save() and restore() create hard to find bugs. |
| 1255 | |
| 1256 | It is not possible to use state to draw outside of the clip defined by the |
| 1257 | previous state. |
| 1258 | |
| 1259 | #Example |
| 1260 | #Description |
| 1261 | Draw to ever smaller clips; then restore drawing to full canvas. |
| 1262 | Note that the second clipRect is not permitted to enlarge Clip. |
| 1263 | ## |
| 1264 | #Height 160 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1265 | void draw(SkCanvas* canvas) { |
| 1266 | SkPaint paint; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1267 | canvas->save(); // records stack depth to restore |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1268 | canvas->clipRect(SkRect::MakeWH(100, 100)); // constrains drawing to clip |
| 1269 | canvas->clear(SK_ColorRED); // draws to limit of clip |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1270 | canvas->save(); // records stack depth to restore |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1271 | canvas->clipRect(SkRect::MakeWH(50, 150)); // Rect below 100 is ignored |
| 1272 | canvas->clear(SK_ColorBLUE); // draws to smaller clip |
| 1273 | canvas->restore(); // enlarges clip |
| 1274 | canvas->drawLine(20, 20, 150, 150, paint); // line below 100 is not drawn |
| 1275 | canvas->restore(); // enlarges clip |
| 1276 | canvas->drawLine(150, 20, 50, 120, paint); // line below 100 is drawn |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1277 | } |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1278 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1279 | |
| 1280 | Each Clip uses the current Matrix for its coordinates. |
| 1281 | |
| 1282 | #Example |
| 1283 | #Description |
| 1284 | While clipRect is given the same rectangle twice, Matrix makes the second |
| 1285 | clipRect draw at half the size of the first. |
| 1286 | ## |
| 1287 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1288 | void draw(SkCanvas* canvas) { |
| 1289 | canvas->clipRect(SkRect::MakeWH(100, 100)); |
| 1290 | canvas->clear(SK_ColorRED); |
| 1291 | canvas->scale(.5, .5); |
| 1292 | canvas->clipRect(SkRect::MakeWH(100, 100)); |
| 1293 | canvas->clear(SK_ColorBLUE); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1294 | } |
| 1295 | ## |
| 1296 | |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1297 | #SeeAlso save saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha restore() restoreToCount |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1298 | |
| 1299 | #Method int save() |
| 1300 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1301 | #In State_Stack |
| 1302 | #Line # saves Clip and Matrix on stack ## |
Cary Clark | 939fd6c | 2018-07-12 08:40:13 -0400 | [diff] [blame] | 1303 | Saves Matrix and Clip. |
| 1304 | Calling restore() discards changes to Matrix and Clip, |
| 1305 | restoring the Matrix and Clip to their state when save() was called. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1306 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1307 | Matrix may be changed by translate(), scale(), rotate(), skew(), concat(), setMatrix, |
| 1308 | and resetMatrix. Clip may be changed by clipRect, clipRRect, clipPath, clipRegion. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1309 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1310 | Saved Canvas state is put on a stack; multiple calls to save() should be balance |
| 1311 | by an equal number of calls to restore(). |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1312 | |
| 1313 | Call restoreToCount with result to restore this and subsequent saves. |
| 1314 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1315 | #Return depth of saved stack ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1316 | |
| 1317 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1318 | #Description |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1319 | The black square is translated 50 pixels down and to the right. |
| 1320 | Restoring Canvas state removes translate() from Canvas stack; |
| 1321 | the red square is not translated, and is drawn at the origin. |
| 1322 | ## |
| 1323 | #Height 100 |
| 1324 | void draw(SkCanvas* canvas) { |
| 1325 | SkPaint paint; |
| 1326 | SkRect rect = { 0, 0, 25, 25 }; |
| 1327 | canvas->drawRect(rect, paint); |
| 1328 | canvas->save(); |
| 1329 | canvas->translate(50, 50); |
| 1330 | canvas->drawRect(rect, paint); |
| 1331 | canvas->restore(); |
| 1332 | paint.setColor(SK_ColorRED); |
| 1333 | canvas->drawRect(rect, paint); |
| 1334 | } |
| 1335 | ## |
| 1336 | |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1337 | #SeeAlso saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha restore restoreToCount |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1338 | |
| 1339 | ## |
| 1340 | |
| 1341 | # ------------------------------------------------------------------------------ |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1342 | |
| 1343 | #Method void restore() |
| 1344 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1345 | #In State_Stack |
| 1346 | #Line # restores changes to Clip and Matrix, pops save stack ## |
Cary Clark | 939fd6c | 2018-07-12 08:40:13 -0400 | [diff] [blame] | 1347 | Removes changes to Matrix and Clip since Canvas state was |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1348 | last saved. The state is removed from the stack. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1349 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1350 | Does nothing if the stack is empty. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1351 | |
| 1352 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1353 | void draw(SkCanvas* canvas) { |
| 1354 | SkCanvas simple; |
| 1355 | SkDebugf("depth = %d\n", simple.getSaveCount()); |
| 1356 | simple.restore(); |
| 1357 | SkDebugf("depth = %d\n", simple.getSaveCount()); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1358 | } |
| 1359 | ## |
| 1360 | |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1361 | #SeeAlso save saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha restoreToCount |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1362 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1363 | ## |
| 1364 | |
| 1365 | # ------------------------------------------------------------------------------ |
| 1366 | |
| 1367 | #Method int getSaveCount() const |
| 1368 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1369 | #In State_Stack |
| 1370 | #Line # returns depth of stack containing Clip and Matrix ## |
Cary Clark | 939fd6c | 2018-07-12 08:40:13 -0400 | [diff] [blame] | 1371 | Returns the number of saved states, each containing: Matrix and Clip. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1372 | 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] | 1373 | The save count of a new canvas is one. |
| 1374 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1375 | #Return depth of save state stack ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1376 | |
| 1377 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1378 | void draw(SkCanvas* canvas) { |
| 1379 | SkCanvas simple; |
| 1380 | SkDebugf("depth = %d\n", simple.getSaveCount()); |
| 1381 | simple.save(); |
| 1382 | SkDebugf("depth = %d\n", simple.getSaveCount()); |
| 1383 | simple.restore(); |
| 1384 | SkDebugf("depth = %d\n", simple.getSaveCount()); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1385 | } |
| 1386 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1387 | depth = 1 |
| 1388 | depth = 2 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1389 | depth = 1 |
| 1390 | ## |
| 1391 | ## |
| 1392 | |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1393 | #SeeAlso save restore restoreToCount |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1394 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1395 | ## |
| 1396 | |
| 1397 | # ------------------------------------------------------------------------------ |
| 1398 | |
| 1399 | #Method void restoreToCount(int saveCount) |
| 1400 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1401 | #In State_Stack |
| 1402 | #Line # restores changes to Clip and Matrix to given depth ## |
Cary Clark | 939fd6c | 2018-07-12 08:40:13 -0400 | [diff] [blame] | 1403 | Restores state to Matrix and Clip values when save(), saveLayer, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1404 | saveLayerPreserveLCDTextRequests, or saveLayerAlpha returned saveCount. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1405 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1406 | Does nothing if saveCount is greater than state stack count. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1407 | Restores state to initial values if saveCount is less than or equal to one. |
| 1408 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1409 | #Param saveCount depth of state stack to restore ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1410 | |
| 1411 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1412 | void draw(SkCanvas* canvas) { |
| 1413 | SkDebugf("depth = %d\n", canvas->getSaveCount()); |
| 1414 | canvas->save(); |
| 1415 | canvas->save(); |
| 1416 | SkDebugf("depth = %d\n", canvas->getSaveCount()); |
| 1417 | canvas->restoreToCount(0); |
| 1418 | SkDebugf("depth = %d\n", canvas->getSaveCount()); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1419 | } |
| 1420 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1421 | depth = 1 |
| 1422 | depth = 3 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1423 | depth = 1 |
| 1424 | ## |
| 1425 | ## |
| 1426 | |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1427 | #SeeAlso restore getSaveCount save |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1428 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1429 | ## |
| 1430 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1431 | #Subtopic State_Stack ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1432 | |
| 1433 | # ------------------------------------------------------------------------------ |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1434 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1435 | #Subtopic Layer |
Cary Clark | d0530ba | 2017-09-14 11:25:39 -0400 | [diff] [blame] | 1436 | #Substitute layer |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1437 | #Alias Layers |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 1438 | #Substitute layers |
| 1439 | ## |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1440 | #Line # temporary Bitmap to draw into ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1441 | |
| 1442 | Layer allocates a temporary Bitmap to draw into. When the drawing is |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1443 | complete, the Bitmap is drawn into the Canvas. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1444 | |
| 1445 | Layer is saved in a stack along with other saved state. When state with a Layer |
| 1446 | is restored, the Bitmap is drawn into the previous Layer. |
| 1447 | |
| 1448 | Layer may be initialized with the contents of the previous Layer. When Layer is |
| 1449 | restored, its Bitmap can be modified by Paint passed to Layer to apply |
| 1450 | Color_Alpha, Color_Filter, Image_Filter, and Blend_Mode. |
| 1451 | |
| 1452 | #Method int saveLayer(const SkRect* bounds, const SkPaint* paint) |
| 1453 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1454 | #In Layer |
| 1455 | #Line # saves Clip and Matrix on stack; creates Layer ## |
Cary Clark | 939fd6c | 2018-07-12 08:40:13 -0400 | [diff] [blame] | 1456 | Saves Matrix and Clip, and allocates a Bitmap for subsequent drawing. |
| 1457 | Calling restore() discards changes to Matrix and Clip, and draws the Bitmap. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1458 | |
| 1459 | Matrix may be changed by translate(), scale(), rotate(), skew(), concat(), |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1460 | setMatrix, and resetMatrix. Clip may be changed by clipRect, clipRRect, |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1461 | clipPath, clipRegion. |
| 1462 | |
| 1463 | Rect bounds suggests but does not define the Bitmap size. To clip drawing to |
| 1464 | a specific rectangle, use clipRect. |
| 1465 | |
| 1466 | Optional Paint paint applies Color_Alpha, Color_Filter, Image_Filter, and |
| 1467 | Blend_Mode when restore() is called. |
| 1468 | |
| 1469 | Call restoreToCount with returned value to restore this and subsequent saves. |
| 1470 | |
| 1471 | #Param bounds hint to limit the size of the Layer; may be nullptr ## |
| 1472 | #Param paint graphics state for Layer; may be nullptr ## |
| 1473 | |
| 1474 | #Return depth of saved stack ## |
| 1475 | |
| 1476 | #Example |
| 1477 | #Description |
| 1478 | Rectangles are blurred by Image_Filter when restore() draws Layer to main |
| 1479 | Canvas. |
| 1480 | ## |
| 1481 | #Height 128 |
Cary Clark | 81abc43 | 2018-06-25 16:30:08 -0400 | [diff] [blame] | 1482 | #Function |
| 1483 | ###$ |
| 1484 | #include "SkBlurImageFilter.h" |
| 1485 | $$$# |
| 1486 | ## |
| 1487 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1488 | void draw(SkCanvas* canvas) { |
| 1489 | SkPaint paint, blur; |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1490 | blur.setImageFilter(SkBlurImageFilter::Make(3, 3, nullptr)); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1491 | canvas->saveLayer(nullptr, &blur); |
| 1492 | SkRect rect = { 25, 25, 50, 50}; |
| 1493 | canvas->drawRect(rect, paint); |
| 1494 | canvas->translate(50, 50); |
| 1495 | paint.setColor(SK_ColorRED); |
| 1496 | canvas->drawRect(rect, paint); |
| 1497 | canvas->restore(); |
| 1498 | } |
| 1499 | ## |
| 1500 | |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1501 | #SeeAlso save restore saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha SaveLayerRec |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1502 | |
| 1503 | ## |
| 1504 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1505 | #Method int saveLayer(const SkRect& bounds, const SkPaint* paint) |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1506 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1507 | #In Layer |
Cary Clark | 939fd6c | 2018-07-12 08:40:13 -0400 | [diff] [blame] | 1508 | Saves Matrix and Clip, and allocates a Bitmap for subsequent drawing. |
| 1509 | Calling restore() discards changes to Matrix and Clip, and draws the Bitmap. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1510 | |
| 1511 | Matrix may be changed by translate(), scale(), rotate(), skew(), concat(), |
| 1512 | setMatrix, and resetMatrix. Clip may be changed by clipRect, clipRRect, |
| 1513 | clipPath, clipRegion. |
| 1514 | |
| 1515 | Rect bounds suggests but does not define the Layer size. To clip drawing to |
| 1516 | a specific rectangle, use clipRect. |
| 1517 | |
| 1518 | Optional Paint paint applies Color_Alpha, Color_Filter, Image_Filter, and |
| 1519 | Blend_Mode when restore() is called. |
| 1520 | |
| 1521 | Call restoreToCount with returned value to restore this and subsequent saves. |
| 1522 | |
| 1523 | #Param bounds hint to limit the size of Layer; may be nullptr ## |
| 1524 | #Param paint graphics state for Layer; may be nullptr ## |
| 1525 | |
| 1526 | #Return depth of saved stack ## |
| 1527 | |
| 1528 | #Example |
| 1529 | #Description |
| 1530 | Rectangles are blurred by Image_Filter when restore() draws Layer to main Canvas. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1531 | The red rectangle is clipped; it does not fully fit on Layer. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1532 | Image_Filter blurs past edge of Layer so red rectangle is blurred on all sides. |
| 1533 | ## |
| 1534 | #Height 128 |
Cary Clark | 81abc43 | 2018-06-25 16:30:08 -0400 | [diff] [blame] | 1535 | #Function |
| 1536 | ###$ |
| 1537 | #include "SkBlurImageFilter.h" |
| 1538 | $$$# |
| 1539 | ## |
| 1540 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1541 | void draw(SkCanvas* canvas) { |
| 1542 | SkPaint paint, blur; |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1543 | blur.setImageFilter(SkBlurImageFilter::Make(3, 3, nullptr)); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1544 | canvas->saveLayer(SkRect::MakeWH(90, 90), &blur); |
| 1545 | SkRect rect = { 25, 25, 50, 50}; |
| 1546 | canvas->drawRect(rect, paint); |
| 1547 | canvas->translate(50, 50); |
| 1548 | paint.setColor(SK_ColorRED); |
| 1549 | canvas->drawRect(rect, paint); |
| 1550 | canvas->restore(); |
| 1551 | } |
| 1552 | ## |
| 1553 | |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1554 | #SeeAlso save restore saveLayerPreserveLCDTextRequests saveLayerAlpha SaveLayerRec |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1555 | |
| 1556 | ## |
| 1557 | |
| 1558 | #Method int saveLayerPreserveLCDTextRequests(const SkRect* bounds, const SkPaint* paint) |
| 1559 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1560 | #In Layer |
| 1561 | #Line # saves Clip and Matrix on stack; creates Layer for LCD text ## |
Cary Clark | 939fd6c | 2018-07-12 08:40:13 -0400 | [diff] [blame] | 1562 | Saves Matrix and Clip, and allocates a Bitmap for subsequent drawing. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1563 | LCD_Text is preserved when the Layer is drawn to the prior Layer. |
| 1564 | |
Cary Clark | 939fd6c | 2018-07-12 08:40:13 -0400 | [diff] [blame] | 1565 | Calling restore() discards changes to Matrix and Clip, and draws Layer. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1566 | |
| 1567 | Matrix may be changed by translate(), scale(), rotate(), skew(), concat(), |
| 1568 | setMatrix, and resetMatrix. Clip may be changed by clipRect, clipRRect, |
| 1569 | clipPath, clipRegion. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1570 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1571 | Rect bounds suggests but does not define the Layer size. To clip drawing to |
| 1572 | a specific rectangle, use clipRect. |
| 1573 | |
| 1574 | Optional Paint paint applies Color_Alpha, Color_Filter, Image_Filter, and |
| 1575 | Blend_Mode when restore() is called. |
| 1576 | |
| 1577 | Call restoreToCount with returned value to restore this and subsequent saves. |
| 1578 | |
| 1579 | Draw text on an opaque background so that LCD_Text blends correctly with the |
| 1580 | 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] | 1581 | incorrect blending. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1582 | |
| 1583 | #Param bounds hint to limit the size of Layer; may be nullptr ## |
| 1584 | #Param paint graphics state for Layer; may be nullptr ## |
| 1585 | |
| 1586 | #Return depth of saved stack ## |
| 1587 | |
| 1588 | #Example |
| 1589 | SkPaint paint; |
| 1590 | paint.setAntiAlias(true); |
| 1591 | paint.setLCDRenderText(true); |
| 1592 | paint.setTextSize(20); |
| 1593 | for (auto preserve : { false, true } ) { |
| 1594 | preserve ? canvas->saveLayerPreserveLCDTextRequests(nullptr, nullptr) |
| 1595 | : canvas->saveLayer(nullptr, nullptr); |
| 1596 | SkPaint p; |
| 1597 | p.setColor(SK_ColorWHITE); |
| 1598 | // Comment out the next line to draw on a non-opaque background. |
| 1599 | canvas->drawRect(SkRect::MakeLTRB(25, 40, 200, 70), p); |
| 1600 | canvas->drawString("Hamburgefons", 30, 60, paint); |
| 1601 | |
| 1602 | p.setColor(0xFFCCCCCC); |
| 1603 | canvas->drawRect(SkRect::MakeLTRB(25, 70, 200, 100), p); |
| 1604 | canvas->drawString("Hamburgefons", 30, 90, paint); |
| 1605 | |
| 1606 | canvas->restore(); |
| 1607 | canvas->translate(0, 80); |
| 1608 | } |
| 1609 | ## |
| 1610 | |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1611 | #SeeAlso save restore saveLayer saveLayerAlpha SaveLayerRec |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1612 | |
| 1613 | ## |
| 1614 | |
| 1615 | #Method int saveLayerAlpha(const SkRect* bounds, U8CPU alpha) |
| 1616 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1617 | #In Layer |
| 1618 | #Line # saves Clip and Matrix on stack; creates Layer; sets opacity ## |
Cary Clark | 939fd6c | 2018-07-12 08:40:13 -0400 | [diff] [blame] | 1619 | Saves Matrix and Clip, and allocates Bitmap for subsequent drawing. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1620 | |
Cary Clark | 939fd6c | 2018-07-12 08:40:13 -0400 | [diff] [blame] | 1621 | Calling restore() discards changes to Matrix and Clip, |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1622 | and blends Layer with alpha opacity onto prior Layer. |
| 1623 | |
| 1624 | Matrix may be changed by translate(), scale(), rotate(), skew(), concat(), |
| 1625 | setMatrix, and resetMatrix. Clip may be changed by clipRect, clipRRect, |
| 1626 | clipPath, clipRegion. |
| 1627 | |
| 1628 | Rect bounds suggests but does not define Layer size. To clip drawing to |
| 1629 | a specific rectangle, use clipRect. |
| 1630 | |
| 1631 | alpha of zero is fully transparent, 255 is fully opaque. |
| 1632 | |
| 1633 | Call restoreToCount with returned value to restore this and subsequent saves. |
| 1634 | |
| 1635 | #Param bounds hint to limit the size of Layer; may be nullptr ## |
| 1636 | #Param alpha opacity of Layer ## |
| 1637 | |
| 1638 | #Return depth of saved stack ## |
| 1639 | |
| 1640 | #Example |
| 1641 | SkPaint paint; |
| 1642 | paint.setColor(SK_ColorRED); |
| 1643 | canvas->drawCircle(50, 50, 50, paint); |
| 1644 | canvas->saveLayerAlpha(nullptr, 128); |
| 1645 | paint.setColor(SK_ColorBLUE); |
| 1646 | canvas->drawCircle(100, 50, 50, paint); |
| 1647 | paint.setColor(SK_ColorGREEN); |
| 1648 | paint.setAlpha(128); |
| 1649 | canvas->drawCircle(75, 90, 50, paint); |
| 1650 | canvas->restore(); |
| 1651 | ## |
| 1652 | |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1653 | #SeeAlso save restore saveLayer saveLayerPreserveLCDTextRequests SaveLayerRec |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1654 | |
| 1655 | ## |
| 1656 | |
Cary Clark | d98f78c | 2018-04-26 08:32:37 -0400 | [diff] [blame] | 1657 | #Enum SaveLayerFlagsSet |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1658 | #Line # sets SaveLayerRec options ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1659 | #Code |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1660 | #Populate |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1661 | ## |
| 1662 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1663 | |
| 1664 | #Typedef uint32_t SaveLayerFlags |
| 1665 | #Line # options for SaveLayerRec ## |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 1666 | ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1667 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1668 | SaveLayerFlags provides options that may be used in any combination in SaveLayerRec, |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1669 | defining how Layer allocated by saveLayer operates. It may be set to zero, |
| 1670 | kPreserveLCDText_SaveLayerFlag, kInitWithPrevious_SaveLayerFlag, or both flags. |
| 1671 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1672 | #Const kPreserveLCDText_SaveLayerFlag 2 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1673 | #Line # creates Layer for LCD text ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1674 | Creates Layer for LCD text. Flag is ignored if Layer Paint contains |
| 1675 | Image_Filter or Color_Filter. |
| 1676 | ## |
| 1677 | |
| 1678 | #Const kInitWithPrevious_SaveLayerFlag 4 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1679 | #Line # initializes with previous contents ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1680 | Initializes Layer with the contents of the previous Layer. |
| 1681 | ## |
| 1682 | |
Mike Reed | 910ca0f | 2018-04-25 13:04:05 -0400 | [diff] [blame] | 1683 | #Const kMaskAgainstCoverage_EXPERIMENTAL_DONT_USE_SaveLayerFlag 8 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1684 | #Experimental do not use |
Mike Reed | 910ca0f | 2018-04-25 13:04:05 -0400 | [diff] [blame] | 1685 | ## |
| 1686 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1687 | #Const kDontClipToLayer_Legacy_SaveLayerFlag 0x80000000 |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 1688 | #Deprecated soon |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1689 | ## |
| 1690 | |
| 1691 | #Example |
| 1692 | #Height 160 |
| 1693 | #Description |
| 1694 | Canvas Layer captures red and blue circles scaled up by four. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1695 | scalePaint blends Layer back with transparency. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1696 | ## |
| 1697 | void draw(SkCanvas* canvas) { |
| 1698 | SkPaint redPaint, bluePaint, scalePaint; |
| 1699 | redPaint.setColor(SK_ColorRED); |
| 1700 | canvas->drawCircle(21, 21, 8, redPaint); |
| 1701 | bluePaint.setColor(SK_ColorBLUE); |
| 1702 | canvas->drawCircle(31, 21, 8, bluePaint); |
| 1703 | SkMatrix matrix; |
| 1704 | matrix.setScale(4, 4); |
| 1705 | scalePaint.setAlpha(0x40); |
| 1706 | scalePaint.setImageFilter( |
| 1707 | SkImageFilter::MakeMatrixFilter(matrix, kNone_SkFilterQuality, nullptr)); |
| 1708 | SkCanvas::SaveLayerRec saveLayerRec(nullptr, &scalePaint, |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1709 | SkCanvas::kInitWithPrevious_SaveLayerFlag); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1710 | canvas->saveLayer(saveLayerRec); |
| 1711 | canvas->restore(); |
| 1712 | } |
| 1713 | ## |
| 1714 | |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1715 | #SeeAlso save restore saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha SaveLayerRec |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1716 | |
| 1717 | #Enum ## |
| 1718 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1719 | #Subtopic SaveLayerRec |
| 1720 | #Line # contains the state used to create the Layer ## |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 1721 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1722 | #Struct SaveLayerRec |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1723 | #Line # contains the state used to create the Layer ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1724 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1725 | #Code |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1726 | #Populate |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1727 | ## |
| 1728 | |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 1729 | SaveLayerRec contains the state used to create the Layer. |
| 1730 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1731 | #Member const SkRect* fBounds |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1732 | #Line # hints at Layer size limit ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1733 | fBounds is used as a hint to limit the size of Layer; may be nullptr. |
| 1734 | fBounds suggests but does not define Layer size. To clip drawing to |
| 1735 | a specific rectangle, use clipRect. |
| 1736 | ## |
| 1737 | |
| 1738 | #Member const SkPaint* fPaint |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1739 | #Line # modifies overlay ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1740 | fPaint modifies how Layer overlays the prior Layer; may be nullptr. |
| 1741 | Color_Alpha, Blend_Mode, Color_Filter, Draw_Looper, Image_Filter, and |
| 1742 | Mask_Filter affect Layer draw. |
| 1743 | ## |
| 1744 | |
| 1745 | #Member const SkImageFilter* fBackdrop |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1746 | #Line # applies Image_Filter to prior Layer ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1747 | fBackdrop applies Image_Filter to the prior Layer when copying to the Layer; |
| 1748 | may be nullptr. Use kInitWithPrevious_SaveLayerFlag to copy the |
| 1749 | prior Layer without an Image_Filter. |
| 1750 | ## |
| 1751 | |
| 1752 | #Member const SkImage* fClipMask |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1753 | #Line # clips Layer with Mask_Alpha ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1754 | restore() clips Layer by the Color_Alpha channel of fClipMask when |
| 1755 | Layer is copied to Device. fClipMask may be nullptr. . |
| 1756 | ## |
| 1757 | |
| 1758 | #Member const SkMatrix* fClipMatrix |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1759 | #Line # transforms Mask_Alpha used to clip ## |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1760 | fClipMatrix transforms fClipMask before it clips Layer. If |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1761 | fClipMask describes a translucent gradient, it may be scaled and rotated |
| 1762 | without introducing artifacts. fClipMatrix may be nullptr. |
| 1763 | ## |
| 1764 | |
| 1765 | #Member SaveLayerFlags fSaveLayerFlags |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1766 | #Line # preserves LCD Text, creates with prior Layer contents ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1767 | fSaveLayerFlags are used to create Layer without transparency, |
| 1768 | create Layer for LCD text, and to create Layer with the |
| 1769 | contents of the previous Layer. |
| 1770 | ## |
| 1771 | |
| 1772 | #Example |
| 1773 | #Height 160 |
| 1774 | #Description |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 1775 | Canvas Layer captures a red Anti_Aliased circle and a blue Aliased circle scaled |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1776 | up by four. After drawing another red circle without scaling on top, the Layer is |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1777 | transferred to the main canvas. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1778 | ## |
| 1779 | void draw(SkCanvas* canvas) { |
| 1780 | SkPaint redPaint, bluePaint; |
| 1781 | redPaint.setAntiAlias(true); |
| 1782 | redPaint.setColor(SK_ColorRED); |
| 1783 | canvas->drawCircle(21, 21, 8, redPaint); |
| 1784 | bluePaint.setColor(SK_ColorBLUE); |
| 1785 | canvas->drawCircle(31, 21, 8, bluePaint); |
| 1786 | SkMatrix matrix; |
| 1787 | matrix.setScale(4, 4); |
| 1788 | auto scaler = SkImageFilter::MakeMatrixFilter(matrix, kNone_SkFilterQuality, nullptr); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1789 | SkCanvas::SaveLayerRec saveLayerRec(nullptr, nullptr, scaler.get(), 0); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1790 | canvas->saveLayer(saveLayerRec); |
| 1791 | canvas->drawCircle(125, 85, 8, redPaint); |
| 1792 | canvas->restore(); |
| 1793 | } |
| 1794 | ## |
| 1795 | |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 1796 | #Subtopic Constructors |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1797 | ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1798 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1799 | #Method SaveLayerRec() |
| 1800 | #Line # constructs SaveLayerRec ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1801 | Sets fBounds, fPaint, and fBackdrop to nullptr. Clears fSaveLayerFlags. |
| 1802 | |
| 1803 | #Return empty SaveLayerRec ## |
| 1804 | |
| 1805 | #Example |
| 1806 | SkCanvas::SaveLayerRec rec1; |
Mike Klein | e083f7c | 2018-02-07 12:54:27 -0500 | [diff] [blame] | 1807 | rec1.fSaveLayerFlags = SkCanvas::kPreserveLCDText_SaveLayerFlag; |
| 1808 | SkCanvas::SaveLayerRec rec2(nullptr, nullptr, SkCanvas::kPreserveLCDText_SaveLayerFlag); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1809 | SkDebugf("rec1 %c= rec2\n", rec1.fBounds == rec2.fBounds |
| 1810 | && rec1.fPaint == rec2.fPaint |
| 1811 | && rec1.fBackdrop == rec2.fBackdrop |
| 1812 | && rec1.fSaveLayerFlags == rec2.fSaveLayerFlags ? '=' : '!'); |
| 1813 | #StdOut |
| 1814 | rec1 == rec2 |
| 1815 | ## |
| 1816 | ## |
| 1817 | |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1818 | #SeeAlso save restore saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1819 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1820 | ## |
| 1821 | |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 1822 | #Method SaveLayerRec(const SkRect* bounds, const SkPaint* paint, SaveLayerFlags saveLayerFlags = 0) |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1823 | |
| 1824 | Sets fBounds, fPaint, and fSaveLayerFlags; sets fBackdrop to nullptr. |
| 1825 | |
| 1826 | #Param bounds Layer dimensions; may be nullptr ## |
| 1827 | #Param paint applied to Layer when overlaying prior Layer; may be nullptr ## |
| 1828 | #Param saveLayerFlags SaveLayerRec options to modify Layer ## |
| 1829 | |
| 1830 | #Return SaveLayerRec with empty backdrop ## |
| 1831 | |
| 1832 | #Example |
| 1833 | SkCanvas::SaveLayerRec rec1; |
| 1834 | SkCanvas::SaveLayerRec rec2(nullptr, nullptr); |
| 1835 | SkDebugf("rec1 %c= rec2\n", rec1.fBounds == rec2.fBounds |
| 1836 | && rec1.fPaint == rec2.fPaint |
| 1837 | && rec1.fBackdrop == rec2.fBackdrop |
| 1838 | && rec1.fSaveLayerFlags == rec2.fSaveLayerFlags ? '=' : '!'); |
| 1839 | #StdOut |
| 1840 | rec1 == rec2 |
| 1841 | ## |
| 1842 | ## |
| 1843 | |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1844 | #SeeAlso save restore saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1845 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1846 | ## |
| 1847 | |
| 1848 | #Method SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop, |
| 1849 | SaveLayerFlags saveLayerFlags) |
| 1850 | |
| 1851 | Sets fBounds, fPaint, fBackdrop, and fSaveLayerFlags. |
| 1852 | |
| 1853 | #Param bounds Layer dimensions; may be nullptr ## |
| 1854 | #Param paint applied to Layer when overlaying prior Layer; |
| 1855 | may be nullptr |
| 1856 | ## |
| 1857 | #Param backdrop prior Layer copied with Image_Filter; may be nullptr |
| 1858 | ## |
| 1859 | #Param saveLayerFlags SaveLayerRec options to modify Layer ## |
| 1860 | |
| 1861 | #Return SaveLayerRec fully specified ## |
| 1862 | |
| 1863 | #Example |
| 1864 | SkCanvas::SaveLayerRec rec1; |
| 1865 | SkCanvas::SaveLayerRec rec2(nullptr, nullptr, nullptr, 0); |
| 1866 | SkDebugf("rec1 %c= rec2\n", rec1.fBounds == rec2.fBounds |
| 1867 | && rec1.fPaint == rec2.fPaint |
| 1868 | && rec1.fBackdrop == rec2.fBackdrop |
| 1869 | && rec1.fSaveLayerFlags == rec2.fSaveLayerFlags ? '=' : '!'); |
| 1870 | #StdOut |
| 1871 | rec1 == rec2 |
| 1872 | ## |
| 1873 | ## |
| 1874 | |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1875 | #SeeAlso save restore saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1876 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1877 | ## |
| 1878 | |
| 1879 | #Method SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop, |
| 1880 | const SkImage* clipMask, const SkMatrix* clipMatrix, |
| 1881 | SaveLayerFlags saveLayerFlags) |
| 1882 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1883 | #Experimental not ready |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1884 | |
| 1885 | Sets fBounds, fPaint, fBackdrop, fClipMask, fClipMatrix, and fSaveLayerFlags. |
| 1886 | clipMatrix uses Color_Alpha channel of image, transformed by clipMatrix, to clip |
| 1887 | Layer when drawn to Canvas. |
| 1888 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1889 | Implementation is not complete; has no effect if Device is GPU-backed. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1890 | |
| 1891 | #Param bounds Layer dimensions; may be nullptr ## |
| 1892 | #Param paint graphics state applied to Layer when overlaying prior |
| 1893 | Layer; may be nullptr |
| 1894 | ## |
| 1895 | #Param backdrop prior Layer copied with Image_Filter; |
| 1896 | may be nullptr |
| 1897 | ## |
| 1898 | #Param clipMask clip applied to Layer; may be nullptr ## |
| 1899 | #Param clipMatrix matrix applied to clipMask; may be nullptr to use |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1900 | identity matrix |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1901 | ## |
| 1902 | #Param saveLayerFlags SaveLayerRec options to modify Layer ## |
| 1903 | |
| 1904 | #Return SaveLayerRec fully specified ## |
| 1905 | |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1906 | #SeeAlso save restore saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1907 | |
| 1908 | ## |
| 1909 | |
| 1910 | #Struct ## |
| 1911 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 1912 | #Subtopic ## |
| 1913 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1914 | #Method int saveLayer(const SaveLayerRec& layerRec) |
| 1915 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1916 | #In Layer |
Cary Clark | 939fd6c | 2018-07-12 08:40:13 -0400 | [diff] [blame] | 1917 | Saves Matrix and Clip, and allocates Bitmap for subsequent drawing. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1918 | |
Cary Clark | 939fd6c | 2018-07-12 08:40:13 -0400 | [diff] [blame] | 1919 | Calling restore() discards changes to Matrix and Clip, |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1920 | and blends Bitmap with Color_Alpha opacity onto the prior Layer. |
| 1921 | |
| 1922 | Matrix may be changed by translate(), scale(), rotate(), skew(), concat(), |
| 1923 | setMatrix, and resetMatrix. Clip may be changed by clipRect, clipRRect, |
| 1924 | clipPath, clipRegion. |
| 1925 | |
| 1926 | SaveLayerRec contains the state used to create the Layer. |
| 1927 | |
| 1928 | Call restoreToCount with returned value to restore this and subsequent saves. |
| 1929 | |
| 1930 | #Param layerRec Layer state ## |
| 1931 | |
| 1932 | #Return depth of save state stack ## |
| 1933 | |
| 1934 | #Example |
| 1935 | #Description |
| 1936 | The example draws an image, and saves it into a Layer with kInitWithPrevious_SaveLayerFlag. |
| 1937 | Next it punches a hole in Layer and restore with SkBlendMode::kPlus. |
| 1938 | Where Layer was cleared, the original image will draw unchanged. |
| 1939 | Outside of the circle the mandrill is brightened. |
| 1940 | ## |
| 1941 | #Image 3 |
Hal Canary | c465d13 | 2017-12-08 10:21:31 -0500 | [diff] [blame] | 1942 | // sk_sp<SkImage> image = GetResourceAsImage("images/mandrill_256.png"); |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1943 | canvas->drawImage(image, 0, 0, nullptr); |
| 1944 | SkCanvas::SaveLayerRec rec; |
| 1945 | SkPaint paint; |
| 1946 | paint.setBlendMode(SkBlendMode::kPlus); |
| 1947 | rec.fSaveLayerFlags = SkCanvas::kInitWithPrevious_SaveLayerFlag; |
| 1948 | rec.fPaint = &paint; |
| 1949 | canvas->saveLayer(rec); |
| 1950 | paint.setBlendMode(SkBlendMode::kClear); |
| 1951 | canvas->drawCircle(128, 128, 96, paint); |
| 1952 | canvas->restore(); |
| 1953 | ## |
| 1954 | |
| 1955 | #ToDo above example needs to replace GetResourceAsImage with way to select image in fiddle ## |
| 1956 | |
Cary Clark | a90ea22 | 2018-10-16 10:30:28 -0400 | [diff] [blame] | 1957 | #SeeAlso save restore saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 1958 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1959 | ## |
| 1960 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1961 | #Subtopic Layer ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 1962 | |
| 1963 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 1964 | #Subtopic Matrix |
| 1965 | #Line # coordinate transformation ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1966 | |
| 1967 | #Method void translate(SkScalar dx, SkScalar dy) |
| 1968 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 1969 | #In Matrix |
| 1970 | #Line # translates Matrix ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 1971 | Translates Matrix by dx along the x-axis and dy along the y-axis. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1972 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 1973 | Mathematically, replaces Matrix with a translation matrix |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1974 | Premultiplied with Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1975 | |
| 1976 | This has the effect of moving the drawing by (dx, dy) before transforming |
| 1977 | the result with Matrix. |
| 1978 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1979 | #Param dx distance to translate in x ## |
| 1980 | #Param dy distance to translate in y ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1981 | |
| 1982 | #Example |
| 1983 | #Height 128 |
| 1984 | #Description |
| 1985 | scale() followed by translate() produces different results from translate() followed |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1986 | by scale(). |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 1987 | |
| 1988 | The blue stroke follows translate of (50, 50); a black |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 1989 | 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] | 1990 | Matrix, a red frame follows the same scale of (2, 1/2.f); a gray fill |
| 1991 | follows translate of (50, 50). |
| 1992 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 1993 | void draw(SkCanvas* canvas) { |
| 1994 | SkPaint filledPaint; |
| 1995 | SkPaint outlinePaint; |
| 1996 | outlinePaint.setStyle(SkPaint::kStroke_Style); |
| 1997 | outlinePaint.setColor(SK_ColorBLUE); |
| 1998 | canvas->save(); |
| 1999 | canvas->translate(50, 50); |
| 2000 | canvas->drawCircle(28, 28, 15, outlinePaint); // blue center: (50+28, 50+28) |
| 2001 | canvas->scale(2, 1/2.f); |
| 2002 | canvas->drawCircle(28, 28, 15, filledPaint); // black center: (50+(28*2), 50+(28/2)) |
| 2003 | canvas->restore(); |
| 2004 | filledPaint.setColor(SK_ColorGRAY); |
| 2005 | outlinePaint.setColor(SK_ColorRED); |
| 2006 | canvas->scale(2, 1/2.f); |
| 2007 | canvas->drawCircle(28, 28, 15, outlinePaint); // red center: (28*2, 28/2) |
| 2008 | canvas->translate(50, 50); |
| 2009 | 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] | 2010 | } |
| 2011 | ## |
| 2012 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2013 | #SeeAlso concat() scale() skew() rotate() setMatrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2014 | |
| 2015 | ## |
| 2016 | |
| 2017 | # ------------------------------------------------------------------------------ |
| 2018 | |
| 2019 | #Method void scale(SkScalar sx, SkScalar sy) |
| 2020 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2021 | #In Matrix |
| 2022 | #Line # scales Matrix ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2023 | Scales Matrix by sx on the x-axis and sy on the y-axis. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2024 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2025 | Mathematically, replaces Matrix with a scale matrix |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2026 | Premultiplied with Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2027 | |
| 2028 | This has the effect of scaling the drawing by (sx, sy) before transforming |
| 2029 | the result with Matrix. |
| 2030 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2031 | #Param sx amount to scale in x ## |
| 2032 | #Param sy amount to scale in y ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2033 | |
| 2034 | #Example |
| 2035 | #Height 160 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2036 | void draw(SkCanvas* canvas) { |
| 2037 | SkPaint paint; |
| 2038 | SkRect rect = { 10, 20, 60, 120 }; |
| 2039 | canvas->translate(20, 20); |
| 2040 | canvas->drawRect(rect, paint); |
| 2041 | canvas->scale(2, .5f); |
| 2042 | paint.setColor(SK_ColorGRAY); |
| 2043 | canvas->drawRect(rect, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2044 | } |
| 2045 | ## |
| 2046 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2047 | #SeeAlso concat() translate() skew() rotate() setMatrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2048 | |
| 2049 | ## |
| 2050 | |
| 2051 | # ------------------------------------------------------------------------------ |
| 2052 | |
| 2053 | #Method void rotate(SkScalar degrees) |
| 2054 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2055 | #In Matrix |
| 2056 | #Line # rotates Matrix ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2057 | Rotates Matrix by degrees. Positive degrees rotates clockwise. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2058 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2059 | Mathematically, replaces Matrix with a rotation matrix |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2060 | Premultiplied with Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2061 | |
| 2062 | This has the effect of rotating the drawing by degrees before transforming |
| 2063 | the result with Matrix. |
| 2064 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2065 | #Param degrees amount to rotate, in degrees ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2066 | |
| 2067 | #Example |
| 2068 | #Description |
| 2069 | Draw clock hands at time 5:10. The hour hand and minute hand point up and |
| 2070 | are rotated clockwise. |
| 2071 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2072 | void draw(SkCanvas* canvas) { |
| 2073 | SkPaint paint; |
| 2074 | paint.setStyle(SkPaint::kStroke_Style); |
| 2075 | canvas->translate(128, 128); |
| 2076 | canvas->drawCircle(0, 0, 60, paint); |
| 2077 | canvas->save(); |
| 2078 | canvas->rotate(10 * 360 / 60); // 10 minutes of 60 scaled to 360 degrees |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2079 | canvas->drawLine(0, 0, 0, -50, paint); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2080 | canvas->restore(); |
| 2081 | canvas->rotate((5 + 10.f/60) * 360 / 12); // 5 and 10/60 hours of 12 scaled to 360 degrees |
| 2082 | canvas->drawLine(0, 0, 0, -30, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2083 | } |
| 2084 | ## |
| 2085 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2086 | #SeeAlso concat() translate() skew() scale() setMatrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2087 | |
| 2088 | ## |
| 2089 | |
| 2090 | # ------------------------------------------------------------------------------ |
| 2091 | |
| 2092 | #Method void rotate(SkScalar degrees, SkScalar px, SkScalar py) |
| 2093 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2094 | #In Matrix |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2095 | Rotates Matrix by degrees about a point at (px, py). Positive degrees rotates |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2096 | clockwise. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2097 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2098 | Mathematically, constructs a rotation matrix; Premultiplies the rotation matrix by |
| 2099 | a translation matrix; then replaces Matrix with the resulting matrix |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2100 | Premultiplied with Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2101 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2102 | This has the effect of rotating the drawing about a given point before |
| 2103 | transforming the result with Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2104 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2105 | #Param degrees amount to rotate, in degrees ## |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 2106 | #Param px x-axis value of the point to rotate about ## |
| 2107 | #Param py y-axis value of the point to rotate about ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2108 | |
| 2109 | #Example |
| 2110 | #Height 192 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2111 | void draw(SkCanvas* canvas) { |
| 2112 | SkPaint paint; |
| 2113 | paint.setTextSize(96); |
| 2114 | canvas->drawString("A1", 130, 100, paint); |
| 2115 | canvas->rotate(180, 130, 100); |
| 2116 | canvas->drawString("A1", 130, 100, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2117 | } |
| 2118 | ## |
| 2119 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2120 | #SeeAlso concat() translate() skew() scale() setMatrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2121 | |
| 2122 | ## |
| 2123 | |
| 2124 | # ------------------------------------------------------------------------------ |
| 2125 | |
| 2126 | #Method void skew(SkScalar sx, SkScalar sy) |
| 2127 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2128 | #In Matrix |
| 2129 | #Line # skews Matrix ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2130 | Skews Matrix by sx on the x-axis and sy on the y-axis. A positive value of sx |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 2131 | skews the drawing right as y-axis values increase; a positive value of sy skews |
| 2132 | the drawing down as x-axis values increase. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2133 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2134 | Mathematically, replaces Matrix with a skew matrix Premultiplied with Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2135 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2136 | 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] | 2137 | the result with Matrix. |
| 2138 | |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 2139 | #Param sx amount to skew on x-axis ## |
| 2140 | #Param sy amount to skew on y-axis ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2141 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2142 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2143 | #Description |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 2144 | Black text mimics an oblique text style by using a negative skew on x-axis |
| 2145 | that shifts the geometry to the right as the y-axis values decrease. |
| 2146 | Red text uses a positive skew on y-axis to shift the geometry down |
| 2147 | as the x-axis values increase. |
| 2148 | Blue text combines sx and sy skew to rotate and scale. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2149 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2150 | SkPaint paint; |
| 2151 | paint.setTextSize(128); |
| 2152 | canvas->translate(30, 130); |
| 2153 | canvas->save(); |
| 2154 | canvas->skew(-.5, 0); |
| 2155 | canvas->drawString("A1", 0, 0, paint); |
| 2156 | canvas->restore(); |
| 2157 | canvas->save(); |
| 2158 | canvas->skew(0, .5); |
| 2159 | paint.setColor(SK_ColorRED); |
| 2160 | canvas->drawString("A1", 0, 0, paint); |
| 2161 | canvas->restore(); |
| 2162 | canvas->skew(-.5, .5); |
| 2163 | paint.setColor(SK_ColorBLUE); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2164 | canvas->drawString("A1", 0, 0, paint); |
| 2165 | ## |
| 2166 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2167 | #SeeAlso concat() translate() rotate() scale() setMatrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2168 | |
| 2169 | ## |
| 2170 | |
| 2171 | # ------------------------------------------------------------------------------ |
| 2172 | |
| 2173 | #Method void concat(const SkMatrix& matrix) |
| 2174 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2175 | #In Matrix |
| 2176 | #Line # multiplies Matrix by Matrix ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2177 | Replaces Matrix with matrix Premultiplied with existing Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2178 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2179 | This has the effect of transforming the drawn geometry by matrix, before |
| 2180 | transforming the result with existing Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2181 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2182 | #Param matrix matrix to Premultiply with existing Matrix ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2183 | |
| 2184 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2185 | void draw(SkCanvas* canvas) { |
| 2186 | SkPaint paint; |
| 2187 | paint.setTextSize(80); |
| 2188 | paint.setTextScaleX(.3); |
| 2189 | SkMatrix matrix; |
| 2190 | SkRect rect[2] = {{ 10, 20, 90, 110 }, { 40, 130, 140, 180 }}; |
| 2191 | matrix.setRectToRect(rect[0], rect[1], SkMatrix::kFill_ScaleToFit); |
| 2192 | canvas->drawRect(rect[0], paint); |
| 2193 | canvas->drawRect(rect[1], paint); |
| 2194 | paint.setColor(SK_ColorWHITE); |
| 2195 | canvas->drawString("Here", rect[0].fLeft + 10, rect[0].fBottom - 10, paint); |
| 2196 | canvas->concat(matrix); |
| 2197 | canvas->drawString("There", rect[0].fLeft + 10, rect[0].fBottom - 10, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2198 | } |
| 2199 | ## |
| 2200 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2201 | #SeeAlso translate() rotate() scale() skew() setMatrix |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2202 | |
| 2203 | ## |
| 2204 | |
| 2205 | # ------------------------------------------------------------------------------ |
| 2206 | |
| 2207 | #Method void setMatrix(const SkMatrix& matrix) |
| 2208 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2209 | #In Matrix |
| 2210 | #Line # sets Matrix ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2211 | Replaces Matrix with matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2212 | Unlike concat(), any prior matrix state is overwritten. |
| 2213 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2214 | #Param matrix matrix to copy, replacing existing Matrix ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2215 | |
| 2216 | #Example |
| 2217 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2218 | void draw(SkCanvas* canvas) { |
| 2219 | SkPaint paint; |
| 2220 | canvas->scale(4, 6); |
| 2221 | canvas->drawString("truth", 2, 10, paint); |
| 2222 | SkMatrix matrix; |
| 2223 | matrix.setScale(2.8f, 6); |
| 2224 | canvas->setMatrix(matrix); |
| 2225 | canvas->drawString("consequences", 2, 20, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2226 | } |
| 2227 | ## |
| 2228 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2229 | #SeeAlso resetMatrix concat() translate() rotate() scale() skew() |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2230 | |
| 2231 | ## |
| 2232 | |
| 2233 | # ------------------------------------------------------------------------------ |
| 2234 | |
| 2235 | #Method void resetMatrix() |
| 2236 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2237 | #In Matrix |
| 2238 | #Line # resets Matrix to identity ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2239 | Sets Matrix to the identity matrix. |
| 2240 | Any prior matrix state is overwritten. |
| 2241 | |
| 2242 | #Example |
| 2243 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2244 | void draw(SkCanvas* canvas) { |
| 2245 | SkPaint paint; |
| 2246 | canvas->scale(4, 6); |
| 2247 | canvas->drawString("truth", 2, 10, paint); |
| 2248 | canvas->resetMatrix(); |
| 2249 | canvas->scale(2.8f, 6); |
| 2250 | canvas->drawString("consequences", 2, 20, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2251 | } |
| 2252 | ## |
| 2253 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2254 | #SeeAlso setMatrix concat() translate() rotate() scale() skew() |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2255 | |
| 2256 | ## |
| 2257 | |
| 2258 | # ------------------------------------------------------------------------------ |
| 2259 | |
| 2260 | #Method const SkMatrix& getTotalMatrix() const |
| 2261 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2262 | #In Matrix |
| 2263 | #Line # returns Matrix ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2264 | Returns Matrix. |
| 2265 | This does not account for translation by Device or Surface. |
| 2266 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2267 | #Return Matrix in Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2268 | |
| 2269 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2270 | SkDebugf("isIdentity %s\n", canvas->getTotalMatrix().isIdentity() ? "true" : "false"); |
| 2271 | #StdOut |
| 2272 | isIdentity true |
| 2273 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2274 | ## |
| 2275 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2276 | #SeeAlso setMatrix resetMatrix concat() |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2277 | |
| 2278 | ## |
| 2279 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2280 | #Subtopic Matrix ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2281 | |
| 2282 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2283 | #Subtopic Clip |
| 2284 | #Line # stack of clipping Paths ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2285 | |
| 2286 | Clip is built from a stack of clipping paths. Each Path in the |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2287 | stack can be constructed from one or more Path_Contour elements. The |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2288 | Path_Contour may be composed of any number of Path_Verb segments. Each |
| 2289 | Path_Contour forms a closed area; Path_Fill_Type defines the area enclosed |
| 2290 | by Path_Contour. |
| 2291 | |
| 2292 | Clip stack of Path elements successfully restrict the Path area. Each |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2293 | Path is transformed by Matrix, then intersected with or subtracted from the |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2294 | prior Clip to form the replacement Clip. Use SkClipOp::kDifference |
| 2295 | to subtract Path from Clip; use SkClipOp::kIntersect to intersect Path |
| 2296 | with Clip. |
| 2297 | |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2298 | A clipping Path may be Anti_Aliased; if Path, after transformation, is |
| 2299 | composed of horizontal and vertical lines, clearing Anti_Alias allows whole pixels |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2300 | to either be inside or outside the clip. The fastest drawing has a Aliased, |
| 2301 | rectangular clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2302 | |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2303 | If clipping Path has Anti_Alias set, clip may partially clip a pixel, requiring |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2304 | that drawing blend partially with the destination along the edge. A rotated |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2305 | rectangular Anti_Aliased clip looks smoother but draws slower. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2306 | |
| 2307 | Clip can combine with Rect and Round_Rect primitives; like |
| 2308 | Path, these are transformed by Matrix before they are combined with Clip. |
| 2309 | |
| 2310 | Clip can combine with Region. Region is assumed to be in Device coordinates |
| 2311 | and is unaffected by Matrix. |
| 2312 | |
| 2313 | #Example |
| 2314 | #Height 90 |
| 2315 | #Description |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2316 | 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] | 2317 | Use an image filter to zoom into the pixels drawn. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2318 | The edge of the Aliased clip fully draws pixels in the red circle. |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2319 | 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] | 2320 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2321 | SkPaint redPaint, scalePaint; |
| 2322 | redPaint.setAntiAlias(true); |
| 2323 | redPaint.setColor(SK_ColorRED); |
| 2324 | canvas->save(); |
| 2325 | for (bool antialias : { false, true } ) { |
| 2326 | canvas->save(); |
| 2327 | canvas->clipRect(SkRect::MakeWH(19.5f, 11.5f), antialias); |
| 2328 | canvas->drawCircle(17, 11, 8, redPaint); |
| 2329 | canvas->restore(); |
| 2330 | canvas->translate(16, 0); |
| 2331 | } |
| 2332 | canvas->restore(); |
| 2333 | SkMatrix matrix; |
| 2334 | matrix.setScale(6, 6); |
| 2335 | scalePaint.setImageFilter( |
| 2336 | SkImageFilter::MakeMatrixFilter(matrix, kNone_SkFilterQuality, nullptr)); |
| 2337 | SkCanvas::SaveLayerRec saveLayerRec( |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2338 | nullptr, &scalePaint, SkCanvas::kInitWithPrevious_SaveLayerFlag); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2339 | canvas->saveLayer(saveLayerRec); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2340 | canvas->restore(); |
| 2341 | ## |
| 2342 | |
| 2343 | #Method void clipRect(const SkRect& rect, SkClipOp op, bool doAntiAlias) |
| 2344 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2345 | #In Clip |
| 2346 | #Line # combines Clip with Rect ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2347 | Replaces Clip with the intersection or difference of Clip and rect, |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2348 | 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] | 2349 | before it is combined with Clip. |
| 2350 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 2351 | #Param rect Rect to combine with Clip ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2352 | #Param op Clip_Op to apply to Clip ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2353 | #Param doAntiAlias true if Clip is to be Anti_Aliased ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2354 | |
| 2355 | #Example |
| 2356 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2357 | void draw(SkCanvas* canvas) { |
| 2358 | canvas->rotate(10); |
| 2359 | SkPaint paint; |
| 2360 | paint.setAntiAlias(true); |
| 2361 | for (auto alias: { false, true } ) { |
| 2362 | canvas->save(); |
| 2363 | canvas->clipRect(SkRect::MakeWH(90, 80), SkClipOp::kIntersect, alias); |
| 2364 | canvas->drawCircle(100, 60, 60, paint); |
| 2365 | canvas->restore(); |
| 2366 | canvas->translate(80, 0); |
| 2367 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2368 | } |
| 2369 | ## |
| 2370 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2371 | #SeeAlso clipRRect clipPath clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2372 | |
| 2373 | ## |
| 2374 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2375 | #Method void clipRect(const SkRect& rect, SkClipOp op) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2376 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2377 | #In Clip |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2378 | Replaces Clip with the intersection or difference of Clip and rect. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2379 | Resulting Clip is Aliased; pixels are fully contained by the clip. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2380 | rect is transformed by Matrix before it is combined with Clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2381 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 2382 | #Param rect Rect to combine with Clip ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2383 | #Param op Clip_Op to apply to Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2384 | |
| 2385 | #Example |
| 2386 | #Height 192 |
| 2387 | #Width 280 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2388 | void draw(SkCanvas* canvas) { |
| 2389 | SkPaint paint; |
| 2390 | for (SkClipOp op: { SkClipOp::kIntersect, SkClipOp::kDifference } ) { |
| 2391 | canvas->save(); |
| 2392 | canvas->clipRect(SkRect::MakeWH(90, 120), op, false); |
| 2393 | canvas->drawCircle(100, 100, 60, paint); |
| 2394 | canvas->restore(); |
| 2395 | canvas->translate(80, 0); |
| 2396 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2397 | } |
| 2398 | ## |
| 2399 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2400 | #SeeAlso clipRRect clipPath clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2401 | |
| 2402 | ## |
| 2403 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2404 | #Method void clipRect(const SkRect& rect, bool doAntiAlias = false) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2405 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2406 | #In Clip |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2407 | Replaces Clip with the intersection of Clip and rect. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2408 | Resulting Clip is Aliased; pixels are fully contained by the clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2409 | rect is transformed by Matrix |
| 2410 | before it is combined with Clip. |
| 2411 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 2412 | #Param rect Rect to combine with Clip ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2413 | #Param doAntiAlias true if Clip is to be Anti_Aliased ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2414 | |
| 2415 | #Example |
| 2416 | #Height 133 |
| 2417 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2418 | A circle drawn in pieces looks uniform when drawn Aliased. |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2419 | 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] | 2420 | visible as a thin pair of lines through the right circle. |
| 2421 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2422 | void draw(SkCanvas* canvas) { |
| 2423 | canvas->clear(SK_ColorWHITE); |
| 2424 | SkPaint paint; |
| 2425 | paint.setAntiAlias(true); |
| 2426 | paint.setColor(0x8055aaff); |
| 2427 | SkRect clipRect = { 0, 0, 87.4f, 87.4f }; |
| 2428 | for (auto alias: { false, true } ) { |
| 2429 | canvas->save(); |
| 2430 | canvas->clipRect(clipRect, SkClipOp::kIntersect, alias); |
| 2431 | canvas->drawCircle(67, 67, 60, paint); |
| 2432 | canvas->restore(); |
| 2433 | canvas->save(); |
| 2434 | canvas->clipRect(clipRect, SkClipOp::kDifference, alias); |
| 2435 | canvas->drawCircle(67, 67, 60, paint); |
| 2436 | canvas->restore(); |
| 2437 | canvas->translate(120, 0); |
| 2438 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2439 | } |
| 2440 | ## |
| 2441 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2442 | #SeeAlso clipRRect clipPath clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2443 | |
| 2444 | ## |
| 2445 | |
| 2446 | #Method void androidFramework_setDeviceClipRestriction(const SkIRect& rect) |
| 2447 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2448 | #In Clip |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2449 | #Line # exists for use by Android framework ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2450 | 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] | 2451 | clipPath and intersect the current clip with the specified rect. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2452 | The maximum clip affects only future clipping operations; it is not retroactive. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2453 | The clip restriction is not recorded in pictures. |
| 2454 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2455 | Pass an empty rect to disable maximum clip. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2456 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2457 | #Private |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 2458 | This private API is for use by Android framework only. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2459 | ## |
| 2460 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2461 | #Param rect maximum allowed clip in device coordinates |
Cary Clark | 579985c | 2017-07-31 11:48:27 -0400 | [diff] [blame] | 2462 | #Param ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2463 | |
| 2464 | ## |
| 2465 | |
| 2466 | #Method void clipRRect(const SkRRect& rrect, SkClipOp op, bool doAntiAlias) |
| 2467 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2468 | #In Clip |
| 2469 | #Line # combines Clip with Round_Rect ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2470 | Replaces Clip with the intersection or difference of Clip and rrect, |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2471 | with an Aliased or Anti_Aliased clip edge. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2472 | rrect is transformed by Matrix |
| 2473 | before it is combined with Clip. |
| 2474 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2475 | #Param rrect Round_Rect to combine with Clip ## |
| 2476 | #Param op Clip_Op to apply to Clip ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2477 | #Param doAntiAlias true if Clip is to be Anti_Aliased ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2478 | |
| 2479 | #Example |
| 2480 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2481 | void draw(SkCanvas* canvas) { |
| 2482 | canvas->clear(SK_ColorWHITE); |
| 2483 | SkPaint paint; |
| 2484 | paint.setAntiAlias(true); |
| 2485 | paint.setColor(0x8055aaff); |
| 2486 | SkRRect oval; |
| 2487 | oval.setOval({10, 20, 90, 100}); |
| 2488 | canvas->clipRRect(oval, SkClipOp::kIntersect, true); |
| 2489 | canvas->drawCircle(70, 100, 60, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2490 | } |
| 2491 | ## |
| 2492 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2493 | #SeeAlso clipRect clipPath clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2494 | |
| 2495 | ## |
| 2496 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2497 | #Method void clipRRect(const SkRRect& rrect, SkClipOp op) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2498 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2499 | #In Clip |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2500 | Replaces Clip with the intersection or difference of Clip and rrect. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2501 | Resulting Clip is Aliased; pixels are fully contained by the clip. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2502 | rrect is transformed by Matrix before it is combined with Clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2503 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2504 | #Param rrect Round_Rect to combine with Clip ## |
| 2505 | #Param op Clip_Op to apply to Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2506 | |
| 2507 | #Example |
| 2508 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2509 | void draw(SkCanvas* canvas) { |
| 2510 | SkPaint paint; |
| 2511 | paint.setColor(0x8055aaff); |
| 2512 | auto oval = SkRRect::MakeOval({10, 20, 90, 100}); |
| 2513 | canvas->clipRRect(oval, SkClipOp::kIntersect); |
| 2514 | canvas->drawCircle(70, 100, 60, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2515 | } |
| 2516 | ## |
| 2517 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2518 | #SeeAlso clipRect clipPath clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2519 | |
| 2520 | ## |
| 2521 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2522 | #Method void clipRRect(const SkRRect& rrect, bool doAntiAlias = false) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2523 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2524 | #In Clip |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2525 | Replaces Clip with the intersection of Clip and rrect, |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2526 | with an Aliased or Anti_Aliased clip edge. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2527 | rrect is transformed by Matrix before it is combined with Clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2528 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2529 | #Param rrect Round_Rect to combine with Clip ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2530 | #Param doAntiAlias true if Clip is to be Anti_Aliased ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2531 | |
| 2532 | #Example |
| 2533 | #Height 128 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2534 | void draw(SkCanvas* canvas) { |
| 2535 | SkPaint paint; |
| 2536 | paint.setAntiAlias(true); |
| 2537 | auto oval = SkRRect::MakeRectXY({10, 20, 90, 100}, 9, 13); |
| 2538 | canvas->clipRRect(oval, true); |
| 2539 | canvas->drawCircle(70, 100, 60, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2540 | } |
| 2541 | ## |
| 2542 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2543 | #SeeAlso clipRect clipPath clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2544 | |
| 2545 | ## |
| 2546 | |
| 2547 | #Method void clipPath(const SkPath& path, SkClipOp op, bool doAntiAlias) |
| 2548 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2549 | #In Clip |
| 2550 | #Line # combines Clip with Path ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2551 | Replaces Clip with the intersection or difference of Clip and path, |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2552 | 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] | 2553 | describes the area inside or outside its contours; and if Path_Contour overlaps |
| 2554 | 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] | 2555 | path is transformed by Matrix before it is combined with Clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2556 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2557 | #Param path Path to combine with Clip ## |
| 2558 | #Param op Clip_Op to apply to Clip ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2559 | #Param doAntiAlias true if Clip is to be Anti_Aliased ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2560 | |
| 2561 | #Example |
| 2562 | #Description |
| 2563 | Top figure uses SkPath::kInverseWinding_FillType and SkClipOp::kDifference; |
| 2564 | area outside clip is subtracted from circle. |
| 2565 | |
| 2566 | Bottom figure uses SkPath::kWinding_FillType and SkClipOp::kIntersect; |
| 2567 | area inside clip is intersected with circle. |
| 2568 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2569 | void draw(SkCanvas* canvas) { |
| 2570 | SkPaint paint; |
| 2571 | paint.setAntiAlias(true); |
| 2572 | SkPath path; |
| 2573 | path.addRect({20, 30, 100, 110}); |
| 2574 | path.setFillType(SkPath::kInverseWinding_FillType); |
| 2575 | canvas->save(); |
| 2576 | canvas->clipPath(path, SkClipOp::kDifference, false); |
| 2577 | canvas->drawCircle(70, 100, 60, paint); |
| 2578 | canvas->restore(); |
| 2579 | canvas->translate(100, 100); |
| 2580 | path.setFillType(SkPath::kWinding_FillType); |
| 2581 | canvas->clipPath(path, SkClipOp::kIntersect, false); |
| 2582 | canvas->drawCircle(70, 100, 60, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2583 | } |
| 2584 | ## |
| 2585 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2586 | #SeeAlso clipRect clipRRect clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2587 | |
| 2588 | ## |
| 2589 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2590 | #Method void clipPath(const SkPath& path, SkClipOp op) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2591 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2592 | #In Clip |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2593 | Replaces Clip with the intersection or difference of Clip and path. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2594 | Resulting Clip is Aliased; pixels are fully contained by the clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2595 | Path_Fill_Type determines if path |
| 2596 | describes the area inside or outside its contours; and if Path_Contour overlaps |
| 2597 | itself or another Path_Contour, whether the overlaps form part of the area. |
| 2598 | path is transformed by Matrix |
| 2599 | before it is combined with Clip. |
| 2600 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2601 | #Param path Path to combine with Clip ## |
| 2602 | #Param op Clip_Op to apply to Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2603 | |
| 2604 | #Example |
| 2605 | #Description |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 2606 | Overlapping Rects form a clip. When clip Path_Fill_Type is set to |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2607 | SkPath::kWinding_FillType, the overlap is included. Set to |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2608 | SkPath::kEvenOdd_FillType, the overlap is excluded and forms a hole. |
| 2609 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2610 | void draw(SkCanvas* canvas) { |
| 2611 | SkPaint paint; |
| 2612 | paint.setAntiAlias(true); |
| 2613 | SkPath path; |
| 2614 | path.addRect({20, 15, 100, 95}); |
| 2615 | path.addRect({50, 65, 130, 135}); |
| 2616 | path.setFillType(SkPath::kWinding_FillType); |
| 2617 | canvas->save(); |
| 2618 | canvas->clipPath(path, SkClipOp::kIntersect); |
| 2619 | canvas->drawCircle(70, 85, 60, paint); |
| 2620 | canvas->restore(); |
| 2621 | canvas->translate(100, 100); |
| 2622 | path.setFillType(SkPath::kEvenOdd_FillType); |
| 2623 | canvas->clipPath(path, SkClipOp::kIntersect); |
| 2624 | canvas->drawCircle(70, 85, 60, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2625 | } |
| 2626 | ## |
| 2627 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2628 | #SeeAlso clipRect clipRRect clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2629 | |
| 2630 | ## |
| 2631 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2632 | #Method void clipPath(const SkPath& path, bool doAntiAlias = false) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2633 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2634 | #In Clip |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2635 | Replaces Clip with the intersection of Clip and path. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2636 | Resulting Clip is Aliased; pixels are fully contained by the clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2637 | Path_Fill_Type determines if path |
| 2638 | describes the area inside or outside its contours; and if Path_Contour overlaps |
| 2639 | 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] | 2640 | path is transformed by Matrix before it is combined with Clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2641 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2642 | #Param path Path to combine with Clip ## |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2643 | #Param doAntiAlias true if Clip is to be Anti_Aliased ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2644 | |
| 2645 | #Example |
| 2646 | #Height 212 |
| 2647 | #Description |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2648 | Clip loops over itself covering its center twice. When clip Path_Fill_Type |
| 2649 | is set to SkPath::kWinding_FillType, the overlap is included. Set to |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2650 | SkPath::kEvenOdd_FillType, the overlap is excluded and forms a hole. |
| 2651 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2652 | void draw(SkCanvas* canvas) { |
| 2653 | SkPaint paint; |
| 2654 | paint.setAntiAlias(true); |
| 2655 | SkPath path; |
| 2656 | SkPoint poly[] = {{20, 20}, { 80, 20}, { 80, 80}, {40, 80}, |
| 2657 | {40, 40}, {100, 40}, {100, 100}, {20, 100}}; |
| 2658 | path.addPoly(poly, SK_ARRAY_COUNT(poly), true); |
| 2659 | path.setFillType(SkPath::kWinding_FillType); |
| 2660 | canvas->save(); |
| 2661 | canvas->clipPath(path, SkClipOp::kIntersect); |
| 2662 | canvas->drawCircle(50, 50, 45, paint); |
| 2663 | canvas->restore(); |
| 2664 | canvas->translate(100, 100); |
| 2665 | path.setFillType(SkPath::kEvenOdd_FillType); |
| 2666 | canvas->clipPath(path, SkClipOp::kIntersect); |
| 2667 | canvas->drawCircle(50, 50, 45, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2668 | } |
| 2669 | ## |
| 2670 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2671 | #SeeAlso clipRect clipRRect clipRegion |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2672 | |
| 2673 | ## |
| 2674 | |
| 2675 | # ------------------------------------------------------------------------------ |
| 2676 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2677 | #Method void setAllowSimplifyClip(bool allow) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2678 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2679 | #In Clip |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 2680 | #Experimental testing |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2681 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2682 | Set to simplify clip stack using PathOps. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2683 | |
| 2684 | ## |
| 2685 | |
| 2686 | # ------------------------------------------------------------------------------ |
| 2687 | |
| 2688 | #Method void clipRegion(const SkRegion& deviceRgn, SkClipOp op = SkClipOp::kIntersect) |
| 2689 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2690 | #In Clip |
| 2691 | #Line # combines Clip with Region ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2692 | Replaces Clip with the intersection or difference of Clip and Region deviceRgn. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2693 | Resulting Clip is Aliased; pixels are fully contained by the clip. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2694 | deviceRgn is unaffected by Matrix. |
| 2695 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2696 | #Param deviceRgn Region to combine with Clip ## |
| 2697 | #Param op Clip_Op to apply to Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2698 | |
| 2699 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2700 | #Description |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 2701 | region is unaffected by canvas rotation; iRect is affected by canvas rotation. |
| 2702 | 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] | 2703 | aligns to pixel boundaries. |
| 2704 | ## |
| 2705 | void draw(SkCanvas* canvas) { |
| 2706 | SkPaint paint; |
| 2707 | paint.setAntiAlias(true); |
| 2708 | SkIRect iRect = {30, 40, 120, 130 }; |
| 2709 | SkRegion region(iRect); |
| 2710 | canvas->rotate(10); |
| 2711 | canvas->save(); |
| 2712 | canvas->clipRegion(region, SkClipOp::kIntersect); |
| 2713 | canvas->drawCircle(50, 50, 45, paint); |
| 2714 | canvas->restore(); |
| 2715 | canvas->translate(100, 100); |
| 2716 | canvas->clipRect(SkRect::Make(iRect), SkClipOp::kIntersect); |
| 2717 | canvas->drawCircle(50, 50, 45, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2718 | } |
| 2719 | ## |
| 2720 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2721 | #SeeAlso clipRect clipRRect clipPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2722 | |
| 2723 | ## |
| 2724 | |
| 2725 | #Method bool quickReject(const SkRect& rect) const |
| 2726 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2727 | #In Clip |
| 2728 | #Line # returns if Rect is outside Clip ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2729 | Returns true if Rect rect, transformed by Matrix, can be quickly determined to be |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2730 | outside of Clip. May return false even though rect is outside of Clip. |
| 2731 | |
| 2732 | Use to check if an area to be drawn is clipped out, to skip subsequent draw calls. |
| 2733 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2734 | #Param rect Rect to compare with Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2735 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2736 | #Return true if rect, transformed by Matrix, does not intersect Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2737 | |
| 2738 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2739 | void draw(SkCanvas* canvas) { |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2740 | SkRect testRect = {30, 30, 120, 129 }; |
| 2741 | SkRect clipRect = {30, 130, 120, 230 }; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2742 | canvas->save(); |
| 2743 | canvas->clipRect(clipRect); |
| 2744 | SkDebugf("quickReject %s\n", canvas->quickReject(testRect) ? "true" : "false"); |
| 2745 | canvas->restore(); |
| 2746 | canvas->rotate(10); |
| 2747 | canvas->clipRect(clipRect); |
| 2748 | SkDebugf("quickReject %s\n", canvas->quickReject(testRect) ? "true" : "false"); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2749 | } |
| 2750 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2751 | quickReject true |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2752 | quickReject false |
| 2753 | ## |
| 2754 | ## |
| 2755 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2756 | #SeeAlso getLocalClipBounds getTotalMatrix SkBitmap::drawsNothing |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2757 | |
| 2758 | ## |
| 2759 | |
| 2760 | #Method bool quickReject(const SkPath& path) const |
| 2761 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2762 | #In Clip |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2763 | Returns true if path, transformed by Matrix, can be quickly determined to be |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2764 | outside of Clip. May return false even though path is outside of Clip. |
| 2765 | |
| 2766 | Use to check if an area to be drawn is clipped out, to skip subsequent draw calls. |
| 2767 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2768 | #Param path Path to compare with Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2769 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2770 | #Return true if path, transformed by Matrix, does not intersect Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2771 | |
| 2772 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2773 | void draw(SkCanvas* canvas) { |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2774 | SkPoint testPoints[] = {{30, 30}, {120, 30}, {120, 129} }; |
| 2775 | SkPoint clipPoints[] = {{30, 130}, {120, 130}, {120, 230} }; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2776 | SkPath testPath, clipPath; |
| 2777 | testPath.addPoly(testPoints, SK_ARRAY_COUNT(testPoints), true); |
| 2778 | clipPath.addPoly(clipPoints, SK_ARRAY_COUNT(clipPoints), true); |
| 2779 | canvas->save(); |
| 2780 | canvas->clipPath(clipPath); |
| 2781 | SkDebugf("quickReject %s\n", canvas->quickReject(testPath) ? "true" : "false"); |
| 2782 | canvas->restore(); |
| 2783 | canvas->rotate(10); |
| 2784 | canvas->clipPath(clipPath); |
| 2785 | SkDebugf("quickReject %s\n", canvas->quickReject(testPath) ? "true" : "false"); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2786 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2787 | quickReject true |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2788 | quickReject false |
| 2789 | ## |
| 2790 | } |
| 2791 | ## |
| 2792 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2793 | #SeeAlso getLocalClipBounds getTotalMatrix SkBitmap::drawsNothing |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2794 | |
| 2795 | ## |
| 2796 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2797 | #Method SkRect getLocalClipBounds() const |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2798 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2799 | #In Clip |
| 2800 | #Line # returns Clip bounds in source coordinates ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2801 | Returns bounds of Clip, transformed by inverse of Matrix. If Clip is empty, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2802 | return SkRect::MakeEmpty, where all Rect sides equal zero. |
| 2803 | |
| 2804 | Rect returned is outset by one to account for partial pixel coverage if Clip |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2805 | is Anti_Aliased. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2806 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2807 | #Return bounds of Clip in local coordinates ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2808 | |
| 2809 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2810 | #Description |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2811 | Initial bounds is device bounds outset by 1 on all sides. |
| 2812 | Clipped bounds is clipPath bounds outset by 1 on all sides. |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 2813 | Scaling the canvas by two on both axes scales the local bounds by 1/2 |
| 2814 | on both axes. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2815 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2816 | SkCanvas local(256, 256); |
| 2817 | canvas = &local; |
| 2818 | SkRect bounds = canvas->getLocalClipBounds(); |
| 2819 | SkDebugf("left:%g top:%g right:%g bottom:%g\n", |
| 2820 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2821 | SkPoint clipPoints[] = {{30, 130}, {120, 130}, {120, 230} }; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2822 | SkPath clipPath; |
| 2823 | clipPath.addPoly(clipPoints, SK_ARRAY_COUNT(clipPoints), true); |
| 2824 | canvas->clipPath(clipPath); |
| 2825 | bounds = canvas->getLocalClipBounds(); |
| 2826 | SkDebugf("left:%g top:%g right:%g bottom:%g\n", |
| 2827 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
| 2828 | canvas->scale(2, 2); |
| 2829 | bounds = canvas->getLocalClipBounds(); |
| 2830 | SkDebugf("left:%g top:%g right:%g bottom:%g\n", |
| 2831 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
| 2832 | #StdOut |
| 2833 | left:-1 top:-1 right:257 bottom:257 |
| 2834 | left:29 top:129 right:121 bottom:231 |
| 2835 | left:14.5 top:64.5 right:60.5 bottom:115.5 |
| 2836 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2837 | ## |
| 2838 | |
| 2839 | # local canvas in example works around bug in fiddle ## |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2840 | #Bug 6524 |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2841 | #SeeAlso getDeviceClipBounds getBaseLayerSize quickReject |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2842 | |
| 2843 | ## |
| 2844 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2845 | #Method bool getLocalClipBounds(SkRect* bounds) const |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2846 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2847 | #In Clip |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2848 | Returns bounds of Clip, transformed by inverse of Matrix. If Clip is empty, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2849 | return false, and set bounds to SkRect::MakeEmpty, where all Rect sides equal zero. |
| 2850 | |
| 2851 | bounds is outset by one to account for partial pixel coverage if Clip |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2852 | is Anti_Aliased. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2853 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2854 | #Param bounds Rect of Clip in local coordinates ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2855 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2856 | #Return true if Clip bounds is not empty ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2857 | |
| 2858 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2859 | void draw(SkCanvas* canvas) { |
| 2860 | SkCanvas local(256, 256); |
| 2861 | canvas = &local; |
| 2862 | SkRect bounds; |
| 2863 | SkDebugf("local bounds empty = %s\n", canvas->getLocalClipBounds(&bounds) |
| 2864 | ? "false" : "true"); |
| 2865 | SkPath path; |
| 2866 | canvas->clipPath(path); |
| 2867 | SkDebugf("local bounds empty = %s\n", canvas->getLocalClipBounds(&bounds) |
| 2868 | ? "false" : "true"); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2869 | } |
| 2870 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2871 | local bounds empty = false |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2872 | local bounds empty = true |
| 2873 | ## |
| 2874 | ## |
| 2875 | |
| 2876 | # local canvas in example works around bug in fiddle ## |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2877 | #Bug 6524 |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2878 | #SeeAlso getDeviceClipBounds getBaseLayerSize quickReject |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2879 | |
| 2880 | ## |
| 2881 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2882 | #Method SkIRect getDeviceClipBounds() const |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2883 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2884 | #In Clip |
| 2885 | #Line # returns IRect bounds of Clip ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2886 | Returns IRect bounds of Clip, unaffected by Matrix. If Clip is empty, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2887 | return SkRect::MakeEmpty, where all Rect sides equal zero. |
| 2888 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2889 | Unlike getLocalClipBounds, returned IRect is not outset. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2890 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2891 | #Return bounds of Clip in Device coordinates ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2892 | |
| 2893 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2894 | void draw(SkCanvas* canvas) { |
| 2895 | #Description |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2896 | Initial bounds is device bounds, not outset. |
| 2897 | Clipped bounds is clipPath bounds, not outset. |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 2898 | Scaling the canvas by 1/2 on both axes scales the device bounds by 1/2 |
| 2899 | on both axes. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2900 | ## |
| 2901 | SkCanvas device(256, 256); |
| 2902 | canvas = &device; |
| 2903 | SkIRect bounds = canvas->getDeviceClipBounds(); |
| 2904 | SkDebugf("left:%d top:%d right:%d bottom:%d\n", |
| 2905 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2906 | SkPoint clipPoints[] = {{30, 130}, {120, 130}, {120, 230} }; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2907 | SkPath clipPath; |
| 2908 | clipPath.addPoly(clipPoints, SK_ARRAY_COUNT(clipPoints), true); |
| 2909 | canvas->save(); |
| 2910 | canvas->clipPath(clipPath); |
| 2911 | bounds = canvas->getDeviceClipBounds(); |
| 2912 | SkDebugf("left:%d top:%d right:%d bottom:%d\n", |
| 2913 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
| 2914 | canvas->restore(); |
| 2915 | canvas->scale(1.f/2, 1.f/2); |
| 2916 | canvas->clipPath(clipPath); |
| 2917 | bounds = canvas->getDeviceClipBounds(); |
| 2918 | SkDebugf("left:%d top:%d right:%d bottom:%d\n", |
| 2919 | bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2920 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2921 | left:0 top:0 right:256 bottom:256 |
| 2922 | left:30 top:130 right:120 bottom:230 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2923 | left:15 top:65 right:60 bottom:115 |
| 2924 | ## |
| 2925 | } |
| 2926 | ## |
| 2927 | |
| 2928 | #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] | 2929 | #SeeAlso getLocalClipBounds getBaseLayerSize quickReject |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2930 | |
| 2931 | # device canvas in example works around bug in fiddle ## |
Cary Clark | 4855f78 | 2018-02-06 09:41:53 -0500 | [diff] [blame] | 2932 | #Bug 6524 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2933 | |
| 2934 | ## |
| 2935 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2936 | #Method bool getDeviceClipBounds(SkIRect* bounds) const |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2937 | |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2938 | #In Clip |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2939 | Returns IRect bounds of Clip, unaffected by Matrix. If Clip is empty, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2940 | return false, and set bounds to SkRect::MakeEmpty, where all Rect sides equal zero. |
| 2941 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2942 | Unlike getLocalClipBounds, bounds is not outset. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2943 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2944 | #Param bounds Rect of Clip in device coordinates ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2945 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2946 | #Return true if Clip bounds is not empty ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2947 | |
| 2948 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2949 | void draw(SkCanvas* canvas) { |
| 2950 | SkIRect bounds; |
| 2951 | SkDebugf("device bounds empty = %s\n", canvas->getDeviceClipBounds(&bounds) |
| 2952 | ? "false" : "true"); |
| 2953 | SkPath path; |
| 2954 | canvas->clipPath(path); |
| 2955 | SkDebugf("device bounds empty = %s\n", canvas->getDeviceClipBounds(&bounds) |
| 2956 | ? "false" : "true"); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2957 | } |
| 2958 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2959 | device bounds empty = false |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2960 | device bounds empty = true |
| 2961 | ## |
| 2962 | ## |
| 2963 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2964 | #SeeAlso getLocalClipBounds getBaseLayerSize quickReject |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2965 | |
| 2966 | ## |
| 2967 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 2968 | #Subtopic Clip ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2969 | |
| 2970 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2971 | #Subtopic Draw |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2972 | #Line # draws into Canvas ## |
| 2973 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2974 | |
| 2975 | #Method void drawColor(SkColor color, SkBlendMode mode = SkBlendMode::kSrcOver) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2976 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 2977 | #Line # fills Clip with Color and Blend_Mode ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 2978 | Fills Clip with Color color. |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2979 | mode determines how ARGB is combined with destination. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2980 | |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 2981 | #Param color Unpremultiplied ARGB ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2982 | #Param mode SkBlendMode used to combine source color and destination ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2983 | |
| 2984 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 2985 | canvas->drawColor(SK_ColorRED); |
| 2986 | canvas->clipRect(SkRect::MakeWH(150, 150)); |
| 2987 | canvas->drawColor(SkColorSetARGB(0x80, 0x00, 0xFF, 0x00), SkBlendMode::kPlus); |
| 2988 | canvas->clipRect(SkRect::MakeWH(75, 75)); |
| 2989 | canvas->drawColor(SkColorSetARGB(0x80, 0x00, 0x00, 0xFF), SkBlendMode::kPlus); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2990 | ## |
| 2991 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 2992 | #SeeAlso clear SkBitmap::erase drawPaint |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 2993 | |
| 2994 | ## |
| 2995 | |
| 2996 | # ------------------------------------------------------------------------------ |
| 2997 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 2998 | #Method void clear(SkColor color) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 2999 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3000 | #Line # fills Clip with Color ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3001 | Fills Clip with Color color using SkBlendMode::kSrc. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3002 | This has the effect of replacing all pixels contained by Clip with color. |
| 3003 | |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 3004 | #Param color Unpremultiplied ARGB ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3005 | |
| 3006 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3007 | void draw(SkCanvas* canvas) { |
| 3008 | canvas->save(); |
| 3009 | canvas->clipRect(SkRect::MakeWH(256, 128)); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3010 | canvas->clear(SkColorSetARGB(0x80, 0xFF, 0x00, 0x00)); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3011 | canvas->restore(); |
| 3012 | canvas->save(); |
| 3013 | canvas->clipRect(SkRect::MakeWH(150, 192)); |
| 3014 | canvas->clear(SkColorSetARGB(0x80, 0x00, 0xFF, 0x00)); |
| 3015 | canvas->restore(); |
| 3016 | canvas->clipRect(SkRect::MakeWH(75, 256)); |
| 3017 | canvas->clear(SkColorSetARGB(0x80, 0x00, 0x00, 0xFF)); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3018 | } |
| 3019 | ## |
| 3020 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3021 | #SeeAlso drawColor SkBitmap::erase drawPaint |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3022 | |
| 3023 | ## |
| 3024 | |
| 3025 | # ------------------------------------------------------------------------------ |
| 3026 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3027 | #Method void discard() |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3028 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3029 | #Line # makes Canvas contents undefined ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3030 | Makes Canvas contents undefined. Subsequent calls that read Canvas pixels, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3031 | such as drawing with SkBlendMode, return undefined results. discard() does |
| 3032 | not change Clip or Matrix. |
| 3033 | |
| 3034 | discard() may do nothing, depending on the implementation of Surface or Device |
| 3035 | that created Canvas. |
| 3036 | |
| 3037 | discard() allows optimized performance on subsequent draws by removing |
| 3038 | cached data associated with Surface or Device. |
| 3039 | It is not necessary to call discard() once done with Canvas; |
| 3040 | any cached data is deleted when owning Surface or Device is deleted. |
| 3041 | |
| 3042 | #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] | 3043 | #SeeAlso flush() SkSurface::prepareForExternalIO GrContext::abandonContext |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3044 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3045 | #NoExample |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3046 | ## |
| 3047 | |
| 3048 | ## |
| 3049 | |
| 3050 | # ------------------------------------------------------------------------------ |
| 3051 | |
| 3052 | #Method void drawPaint(const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3053 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3054 | #Line # fills Clip with Paint ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3055 | Fills Clip with Paint paint. Paint components Mask_Filter, Shader, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3056 | Color_Filter, Image_Filter, and Blend_Mode affect drawing; |
| 3057 | Path_Effect in paint is ignored. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3058 | |
| 3059 | # can Path_Effect in paint ever alter drawPaint? |
| 3060 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3061 | #Param paint graphics state used to fill Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3062 | |
| 3063 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3064 | void draw(SkCanvas* canvas) { |
| 3065 | SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE }; |
| 3066 | SkScalar pos[] = { 0, SK_Scalar1/2, SK_Scalar1 }; |
| 3067 | SkPaint paint; |
| 3068 | paint.setShader(SkGradientShader::MakeSweep(256, 256, colors, pos, SK_ARRAY_COUNT(colors))); |
| 3069 | canvas->drawPaint(paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3070 | } |
| 3071 | ## |
| 3072 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3073 | #SeeAlso clear drawColor SkBitmap::erase |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3074 | |
| 3075 | ## |
| 3076 | |
| 3077 | # ------------------------------------------------------------------------------ |
| 3078 | |
| 3079 | #Enum PointMode |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3080 | #Line # sets drawPoints options ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3081 | |
| 3082 | #Code |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 3083 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3084 | ## |
| 3085 | |
| 3086 | Selects if an array of points are drawn as discrete points, as lines, or as |
| 3087 | an open polygon. |
| 3088 | |
| 3089 | #Const kPoints_PointMode 0 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3090 | #Line # draw each point separately ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3091 | ## |
| 3092 | |
| 3093 | #Const kLines_PointMode 1 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3094 | #Line # draw each pair of points as a line segment ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3095 | ## |
| 3096 | |
| 3097 | #Const kPolygon_PointMode 2 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3098 | #Line # draw the array of points as a open polygon ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3099 | ## |
| 3100 | |
| 3101 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3102 | #Description |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3103 | The upper left corner shows three squares when drawn as points. |
| 3104 | The upper right corner shows one line; when drawn as lines, two points are required per line. |
| 3105 | The lower right corner shows two lines; when draw as polygon, no miter is drawn at the corner. |
| 3106 | The lower left corner shows two lines with a miter when path contains polygon. |
| 3107 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3108 | void draw(SkCanvas* canvas) { |
| 3109 | SkPaint paint; |
| 3110 | paint.setStyle(SkPaint::kStroke_Style); |
| 3111 | paint.setStrokeWidth(10); |
| 3112 | SkPoint points[] = {{64, 32}, {96, 96}, {32, 96}}; |
| 3113 | canvas->drawPoints(SkCanvas::kPoints_PointMode, 3, points, paint); |
| 3114 | canvas->translate(128, 0); |
| 3115 | canvas->drawPoints(SkCanvas::kLines_PointMode, 3, points, paint); |
| 3116 | canvas->translate(0, 128); |
| 3117 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, 3, points, paint); |
| 3118 | SkPath path; |
| 3119 | path.addPoly(points, 3, false); |
| 3120 | canvas->translate(-128, 0); |
| 3121 | canvas->drawPath(path, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3122 | } |
| 3123 | ## |
| 3124 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3125 | #SeeAlso drawLine drawPoint drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3126 | |
| 3127 | ## |
| 3128 | |
| 3129 | # ------------------------------------------------------------------------------ |
| 3130 | |
| 3131 | #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] | 3132 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3133 | #Line # draws array as points, lines, polygon ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3134 | Draws pts using Clip, Matrix and Paint paint. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3135 | 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] | 3136 | mode may be one of: kPoints_PointMode, kLines_PointMode, or kPolygon_PointMode. |
| 3137 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3138 | If mode is kPoints_PointMode, the shape of point drawn depends on paint |
| 3139 | Paint_Stroke_Cap. If paint is set to SkPaint::kRound_Cap, each point draws a |
| 3140 | circle of diameter Paint_Stroke_Width. If paint is set to SkPaint::kSquare_Cap |
| 3141 | or SkPaint::kButt_Cap, each point draws a square of width and height |
| 3142 | Paint_Stroke_Width. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3143 | |
| 3144 | If mode is kLines_PointMode, each pair of points draws a line segment. |
| 3145 | One line is drawn for every two points; each point is used once. If count is odd, |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3146 | the final point is ignored. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3147 | |
| 3148 | If mode is kPolygon_PointMode, each adjacent pair of points draws a line segment. |
| 3149 | count minus one lines are drawn; the first and last point are used once. |
| 3150 | |
| 3151 | Each line segment respects paint Paint_Stroke_Cap and Paint_Stroke_Width. |
| 3152 | Paint_Style is ignored, as if were set to SkPaint::kStroke_Style. |
| 3153 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3154 | Always draws each element one at a time; is not affected by |
| 3155 | Paint_Stroke_Join, and unlike drawPath, does not create a mask from all points |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3156 | and lines before drawing. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3157 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 3158 | #Param mode whether pts draws points or lines ## |
| 3159 | #Param count number of points in the array ## |
| 3160 | #Param pts array of points to draw ## |
| 3161 | #Param paint stroke, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3162 | |
| 3163 | #Example |
| 3164 | #Height 200 |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3165 | #Description |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3166 | #List |
| 3167 | # The first column draws points. ## |
| 3168 | # The second column draws points as lines. ## |
| 3169 | # The third column draws points as a polygon. ## |
| 3170 | # The fourth column draws points as a polygonal path. ## |
| 3171 | # The first row uses a round cap and round join. ## |
| 3172 | # The second row uses a square cap and a miter join. ## |
| 3173 | # The third row uses a butt cap and a bevel join. ## |
| 3174 | ## |
| 3175 | The transparent color makes multiple line draws visible; |
| 3176 | the path is drawn all at once. |
| 3177 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3178 | void draw(SkCanvas* canvas) { |
| 3179 | SkPaint paint; |
| 3180 | paint.setAntiAlias(true); |
| 3181 | paint.setStyle(SkPaint::kStroke_Style); |
| 3182 | paint.setStrokeWidth(10); |
| 3183 | paint.setColor(0x80349a45); |
| 3184 | const SkPoint points[] = {{32, 16}, {48, 48}, {16, 32}}; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3185 | const SkPaint::Join join[] = { SkPaint::kRound_Join, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3186 | SkPaint::kMiter_Join, |
| 3187 | SkPaint::kBevel_Join }; |
| 3188 | int joinIndex = 0; |
| 3189 | SkPath path; |
| 3190 | path.addPoly(points, 3, false); |
| 3191 | for (const auto cap : { SkPaint::kRound_Cap, SkPaint::kSquare_Cap, SkPaint::kButt_Cap } ) { |
| 3192 | paint.setStrokeCap(cap); |
| 3193 | paint.setStrokeJoin(join[joinIndex++]); |
| 3194 | for (const auto mode : { SkCanvas::kPoints_PointMode, |
| 3195 | SkCanvas::kLines_PointMode, |
| 3196 | SkCanvas::kPolygon_PointMode } ) { |
| 3197 | canvas->drawPoints(mode, 3, points, paint); |
| 3198 | canvas->translate(64, 0); |
| 3199 | } |
| 3200 | canvas->drawPath(path, paint); |
| 3201 | canvas->translate(-192, 64); |
| 3202 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3203 | } |
| 3204 | ## |
| 3205 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3206 | #SeeAlso drawLine drawPoint drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3207 | |
| 3208 | ## |
| 3209 | |
| 3210 | # ------------------------------------------------------------------------------ |
| 3211 | |
| 3212 | #Method void drawPoint(SkScalar x, SkScalar y, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3213 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3214 | #Line # draws point at (x, y) position ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3215 | Draws point at (x, y) using Clip, Matrix and Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3216 | |
| 3217 | The shape of point drawn depends on paint Paint_Stroke_Cap. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3218 | If paint is set to SkPaint::kRound_Cap, draw a circle of diameter |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3219 | 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] | 3220 | draw a square of width and height Paint_Stroke_Width. |
| 3221 | Paint_Style is ignored, as if were set to SkPaint::kStroke_Style. |
| 3222 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3223 | #Param x left edge of circle or square ## |
| 3224 | #Param y top edge of circle or square ## |
| 3225 | #Param paint stroke, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3226 | |
| 3227 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3228 | void draw(SkCanvas* canvas) { |
| 3229 | SkPaint paint; |
| 3230 | paint.setAntiAlias(true); |
| 3231 | paint.setColor(0x80349a45); |
| 3232 | paint.setStyle(SkPaint::kStroke_Style); |
| 3233 | paint.setStrokeWidth(100); |
| 3234 | paint.setStrokeCap(SkPaint::kRound_Cap); |
| 3235 | canvas->scale(1, 1.2f); |
| 3236 | canvas->drawPoint(64, 96, paint); |
| 3237 | canvas->scale(.6f, .8f); |
| 3238 | paint.setColor(SK_ColorWHITE); |
| 3239 | canvas->drawPoint(106, 120, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3240 | } |
| 3241 | ## |
| 3242 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3243 | #SeeAlso drawPoints drawCircle drawRect drawLine drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3244 | |
| 3245 | ## |
| 3246 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3247 | #Method void drawPoint(SkPoint p, const SkPaint& paint) |
| 3248 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3249 | Draws point p using Clip, Matrix and Paint paint. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3250 | |
| 3251 | The shape of point drawn depends on paint Paint_Stroke_Cap. |
| 3252 | If paint is set to SkPaint::kRound_Cap, draw a circle of diameter |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3253 | 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] | 3254 | draw a square of width and height Paint_Stroke_Width. |
| 3255 | Paint_Style is ignored, as if were set to SkPaint::kStroke_Style. |
| 3256 | |
| 3257 | #Param p top-left edge of circle or square ## |
| 3258 | #Param paint stroke, blend, color, and so on, used to draw ## |
| 3259 | |
| 3260 | #Example |
| 3261 | void draw(SkCanvas* canvas) { |
| 3262 | SkPaint paint; |
| 3263 | paint.setAntiAlias(true); |
| 3264 | paint.setColor(0x80349a45); |
| 3265 | paint.setStyle(SkPaint::kStroke_Style); |
| 3266 | paint.setStrokeWidth(100); |
| 3267 | paint.setStrokeCap(SkPaint::kSquare_Cap); |
| 3268 | canvas->scale(1, 1.2f); |
| 3269 | canvas->drawPoint({64, 96}, paint); |
| 3270 | canvas->scale(.6f, .8f); |
| 3271 | paint.setColor(SK_ColorWHITE); |
| 3272 | canvas->drawPoint(106, 120, paint); |
| 3273 | } |
| 3274 | ## |
| 3275 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3276 | #SeeAlso drawPoints drawCircle drawRect drawLine drawPath |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3277 | |
| 3278 | ## |
| 3279 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3280 | # ------------------------------------------------------------------------------ |
| 3281 | |
| 3282 | #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] | 3283 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3284 | #Line # draws line segment between two points ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3285 | Draws line segment from (x0, y0) to (x1, y1) using Clip, Matrix, and Paint paint. |
| 3286 | In paint: Paint_Stroke_Width describes the line thickness; |
| 3287 | Paint_Stroke_Cap draws the end rounded or square; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3288 | Paint_Style is ignored, as if were set to SkPaint::kStroke_Style. |
| 3289 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3290 | #Param x0 start of line segment on x-axis ## |
| 3291 | #Param y0 start of line segment on y-axis ## |
| 3292 | #Param x1 end of line segment on x-axis ## |
| 3293 | #Param y1 end of line segment on y-axis ## |
| 3294 | #Param paint stroke, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3295 | |
| 3296 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3297 | SkPaint paint; |
| 3298 | paint.setAntiAlias(true); |
| 3299 | paint.setColor(0xFF9a67be); |
| 3300 | paint.setStrokeWidth(20); |
| 3301 | canvas->skew(1, 0); |
| 3302 | canvas->drawLine(32, 96, 32, 160, paint); |
| 3303 | canvas->skew(-2, 0); |
| 3304 | canvas->drawLine(288, 96, 288, 160, paint); |
| 3305 | ## |
| 3306 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3307 | #SeeAlso drawPoint drawCircle drawRect drawPath |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3308 | |
| 3309 | ## |
| 3310 | |
| 3311 | #Method void drawLine(SkPoint p0, SkPoint p1, const SkPaint& paint) |
| 3312 | |
| 3313 | Draws line segment from p0 to p1 using Clip, Matrix, and Paint paint. |
| 3314 | In paint: Paint_Stroke_Width describes the line thickness; |
| 3315 | Paint_Stroke_Cap draws the end rounded or square; |
| 3316 | Paint_Style is ignored, as if were set to SkPaint::kStroke_Style. |
| 3317 | |
| 3318 | #Param p0 start of line segment ## |
| 3319 | #Param p1 end of line segment ## |
| 3320 | #Param paint stroke, blend, color, and so on, used to draw ## |
| 3321 | |
| 3322 | #Example |
| 3323 | SkPaint paint; |
| 3324 | paint.setAntiAlias(true); |
| 3325 | paint.setColor(0xFF9a67be); |
| 3326 | paint.setStrokeWidth(20); |
| 3327 | canvas->skew(1, 0); |
| 3328 | canvas->drawLine({32, 96}, {32, 160}, paint); |
| 3329 | canvas->skew(-2, 0); |
| 3330 | canvas->drawLine({288, 96}, {288, 160}, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3331 | ## |
| 3332 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3333 | #SeeAlso drawPoint drawCircle drawRect drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3334 | |
| 3335 | ## |
| 3336 | |
| 3337 | # ------------------------------------------------------------------------------ |
| 3338 | |
| 3339 | #Method void drawRect(const SkRect& rect, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3340 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3341 | #Line # draws Rect using Clip, Matrix, and Paint ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3342 | Draws Rect rect using Clip, Matrix, and Paint paint. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3343 | In paint: Paint_Style determines if rectangle is stroked or filled; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3344 | if stroked, Paint_Stroke_Width describes the line thickness, and |
| 3345 | Paint_Stroke_Join draws the corners rounded or square. |
| 3346 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3347 | #Param rect rectangle to draw ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3348 | #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] | 3349 | |
| 3350 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3351 | void draw(SkCanvas* canvas) { |
| 3352 | SkPoint rectPts[] = { {64, 48}, {192, 160} }; |
| 3353 | SkPaint paint; |
| 3354 | paint.setAntiAlias(true); |
| 3355 | paint.setStyle(SkPaint::kStroke_Style); |
| 3356 | paint.setStrokeWidth(20); |
| 3357 | paint.setStrokeJoin(SkPaint::kRound_Join); |
| 3358 | SkMatrix rotator; |
| 3359 | rotator.setRotate(30, 128, 128); |
| 3360 | for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorMAGENTA } ) { |
| 3361 | paint.setColor(color); |
| 3362 | SkRect rect; |
| 3363 | rect.set(rectPts[0], rectPts[1]); |
| 3364 | canvas->drawRect(rect, paint); |
| 3365 | rotator.mapPoints(rectPts, 2); |
| 3366 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3367 | } |
| 3368 | ## |
| 3369 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3370 | #SeeAlso drawIRect drawRRect drawRoundRect drawRegion drawPath drawLine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3371 | |
| 3372 | ## |
| 3373 | |
| 3374 | # ------------------------------------------------------------------------------ |
| 3375 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3376 | #Method void drawIRect(const SkIRect& rect, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3377 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3378 | #Line # draws IRect using Clip, Matrix, and Paint ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3379 | Draws IRect rect using Clip, Matrix, and Paint paint. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3380 | In paint: Paint_Style determines if rectangle is stroked or filled; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3381 | if stroked, Paint_Stroke_Width describes the line thickness, and |
| 3382 | Paint_Stroke_Join draws the corners rounded or square. |
| 3383 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3384 | #Param rect rectangle to draw ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3385 | #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] | 3386 | |
| 3387 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3388 | SkIRect rect = { 64, 48, 192, 160 }; |
| 3389 | SkPaint paint; |
| 3390 | paint.setAntiAlias(true); |
| 3391 | paint.setStyle(SkPaint::kStroke_Style); |
| 3392 | paint.setStrokeWidth(20); |
| 3393 | paint.setStrokeJoin(SkPaint::kRound_Join); |
| 3394 | for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorMAGENTA } ) { |
| 3395 | paint.setColor(color); |
| 3396 | canvas->drawIRect(rect, paint); |
| 3397 | canvas->rotate(30, 128, 128); |
| 3398 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3399 | ## |
| 3400 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3401 | #SeeAlso drawRect drawRRect drawRoundRect drawRegion drawPath drawLine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3402 | |
| 3403 | ## |
| 3404 | |
| 3405 | # ------------------------------------------------------------------------------ |
| 3406 | |
| 3407 | #Method void drawRegion(const SkRegion& region, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3408 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3409 | #Line # draws Region using Clip, Matrix, and Paint ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3410 | Draws Region region using Clip, Matrix, and Paint paint. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3411 | In paint: Paint_Style determines if rectangle is stroked or filled; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3412 | if stroked, Paint_Stroke_Width describes the line thickness, and |
| 3413 | Paint_Stroke_Join draws the corners rounded or square. |
| 3414 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3415 | #Param region region to draw ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3416 | #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] | 3417 | |
| 3418 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3419 | void draw(SkCanvas* canvas) { |
| 3420 | SkRegion region; |
| 3421 | region.op( 10, 10, 50, 50, SkRegion::kUnion_Op); |
| 3422 | region.op( 10, 50, 90, 90, SkRegion::kUnion_Op); |
| 3423 | SkPaint paint; |
| 3424 | paint.setAntiAlias(true); |
| 3425 | paint.setStyle(SkPaint::kStroke_Style); |
| 3426 | paint.setStrokeWidth(20); |
| 3427 | paint.setStrokeJoin(SkPaint::kRound_Join); |
| 3428 | canvas->drawRegion(region, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3429 | } |
| 3430 | ## |
| 3431 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3432 | #SeeAlso drawRect drawIRect drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3433 | |
| 3434 | ## |
| 3435 | |
| 3436 | # ------------------------------------------------------------------------------ |
| 3437 | |
| 3438 | #Method void drawOval(const SkRect& oval, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3439 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3440 | #Line # draws Oval using Clip, Matrix, and Paint ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3441 | Draws Oval oval using Clip, Matrix, and Paint. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3442 | In paint: Paint_Style determines if Oval is stroked or filled; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3443 | if stroked, Paint_Stroke_Width describes the line thickness. |
| 3444 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3445 | #Param oval Rect bounds of Oval ## |
| 3446 | #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] | 3447 | |
| 3448 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3449 | void draw(SkCanvas* canvas) { |
| 3450 | canvas->clear(0xFF3f5f9f); |
| 3451 | SkColor kColor1 = SkColorSetARGB(0xff, 0xff, 0x7f, 0); |
| 3452 | SkColor g1Colors[] = { kColor1, SkColorSetA(kColor1, 0x20) }; |
| 3453 | SkPoint g1Points[] = { { 0, 0 }, { 0, 100 } }; |
| 3454 | SkScalar pos[] = { 0.2f, 1.0f }; |
| 3455 | SkRect bounds = SkRect::MakeWH(80, 70); |
| 3456 | SkPaint paint; |
| 3457 | paint.setAntiAlias(true); |
| 3458 | paint.setShader(SkGradientShader::MakeLinear(g1Points, g1Colors, pos, SK_ARRAY_COUNT(g1Colors), |
| 3459 | SkShader::kClamp_TileMode)); |
| 3460 | canvas->drawOval(bounds , paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3461 | } |
| 3462 | ## |
| 3463 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3464 | #SeeAlso drawCircle drawPoint drawPath drawRRect drawRoundRect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3465 | |
| 3466 | ## |
| 3467 | |
| 3468 | # ------------------------------------------------------------------------------ |
| 3469 | |
| 3470 | #Method void drawRRect(const SkRRect& rrect, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3471 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3472 | #Line # draws Round_Rect using Clip, Matrix, and Paint ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3473 | Draws Round_Rect rrect using Clip, Matrix, and Paint paint. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3474 | In paint: Paint_Style determines if rrect is stroked or filled; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3475 | if stroked, Paint_Stroke_Width describes the line thickness. |
| 3476 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3477 | rrect may represent a rectangle, circle, oval, uniformly rounded rectangle, or |
| 3478 | 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] | 3479 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3480 | #Param rrect Round_Rect with up to eight corner radii to draw ## |
| 3481 | #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] | 3482 | |
| 3483 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3484 | void draw(SkCanvas* canvas) { |
| 3485 | SkPaint paint; |
| 3486 | paint.setAntiAlias(true); |
| 3487 | SkRect outer = {30, 40, 210, 220}; |
| 3488 | SkRect radii = {30, 50, 70, 90 }; |
| 3489 | SkRRect rRect; |
| 3490 | rRect.setNinePatch(outer, radii.fLeft, radii.fTop, radii.fRight, radii.fBottom); |
| 3491 | canvas->drawRRect(rRect, paint); |
| 3492 | paint.setColor(SK_ColorWHITE); |
| 3493 | canvas->drawLine(outer.fLeft + radii.fLeft, outer.fTop, |
| 3494 | outer.fLeft + radii.fLeft, outer.fBottom, paint); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3495 | canvas->drawLine(outer.fRight - radii.fRight, outer.fTop, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3496 | outer.fRight - radii.fRight, outer.fBottom, paint); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3497 | canvas->drawLine(outer.fLeft, outer.fTop + radii.fTop, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3498 | outer.fRight, outer.fTop + radii.fTop, paint); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3499 | canvas->drawLine(outer.fLeft, outer.fBottom - radii.fBottom, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3500 | outer.fRight, outer.fBottom - radii.fBottom, paint); |
| 3501 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3502 | ## |
| 3503 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3504 | #SeeAlso drawRect drawRoundRect drawDRRect drawCircle drawOval drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3505 | |
| 3506 | ## |
| 3507 | |
| 3508 | # ------------------------------------------------------------------------------ |
| 3509 | |
| 3510 | #Method void drawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3511 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3512 | #Line # draws double Round_Rect stroked or filled ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3513 | Draws Round_Rect outer and inner |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3514 | using Clip, Matrix, and Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3515 | outer must contain inner or the drawing is undefined. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3516 | In paint: Paint_Style determines if Round_Rect is stroked or filled; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3517 | if stroked, Paint_Stroke_Width describes the line thickness. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3518 | If stroked and Round_Rect corner has zero length radii, Paint_Stroke_Join can |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3519 | draw corners rounded or square. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3520 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3521 | GPU-backed platforms optimize drawing when both outer and inner are |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3522 | concave and outer contains inner. These platforms may not be able to draw |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3523 | Path built with identical data as fast. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3524 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3525 | #Param outer Round_Rect outer bounds to draw ## |
| 3526 | #Param inner Round_Rect inner bounds to draw ## |
| 3527 | #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] | 3528 | |
| 3529 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3530 | void draw(SkCanvas* canvas) { |
| 3531 | SkRRect outer = SkRRect::MakeRect({20, 40, 210, 200}); |
| 3532 | SkRRect inner = SkRRect::MakeOval({60, 70, 170, 160}); |
| 3533 | SkPaint paint; |
| 3534 | canvas->drawDRRect(outer, inner, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3535 | } |
| 3536 | ## |
| 3537 | |
| 3538 | #Example |
| 3539 | #Description |
| 3540 | Outer Rect has no corner radii, but stroke join is rounded. |
| 3541 | Inner Round_Rect has corner radii; outset stroke increases radii of corners. |
| 3542 | Stroke join does not affect inner Round_Rect since it has no sharp corners. |
| 3543 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3544 | void draw(SkCanvas* canvas) { |
| 3545 | SkRRect outer = SkRRect::MakeRect({20, 40, 210, 200}); |
| 3546 | SkRRect inner = SkRRect::MakeRectXY({60, 70, 170, 160}, 10, 10); |
| 3547 | SkPaint paint; |
| 3548 | paint.setAntiAlias(true); |
| 3549 | paint.setStyle(SkPaint::kStroke_Style); |
| 3550 | paint.setStrokeWidth(20); |
| 3551 | paint.setStrokeJoin(SkPaint::kRound_Join); |
| 3552 | canvas->drawDRRect(outer, inner, paint); |
| 3553 | paint.setStrokeWidth(1); |
| 3554 | paint.setColor(SK_ColorWHITE); |
| 3555 | canvas->drawDRRect(outer, inner, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3556 | } |
| 3557 | ## |
| 3558 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3559 | #SeeAlso drawRect drawRoundRect drawRRect drawCircle drawOval drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3560 | |
| 3561 | ## |
| 3562 | |
| 3563 | # ------------------------------------------------------------------------------ |
| 3564 | |
| 3565 | #Method void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3566 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3567 | #Line # draws Circle using Clip, Matrix, and Paint ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3568 | Draws Circle at (cx, cy) with radius using Clip, Matrix, and Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3569 | If radius is zero or less, nothing is drawn. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3570 | In paint: Paint_Style determines if Circle is stroked or filled; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3571 | if stroked, Paint_Stroke_Width describes the line thickness. |
| 3572 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3573 | #Param cx Circle center on the x-axis ## |
| 3574 | #Param cy Circle center on the y-axis ## |
| 3575 | #Param radius half the diameter of Circle ## |
| 3576 | #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] | 3577 | |
| 3578 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3579 | void draw(SkCanvas* canvas) { |
| 3580 | SkPaint paint; |
| 3581 | paint.setAntiAlias(true); |
| 3582 | canvas->drawCircle(128, 128, 90, paint); |
| 3583 | paint.setColor(SK_ColorWHITE); |
| 3584 | canvas->drawCircle(86, 86, 20, paint); |
| 3585 | canvas->drawCircle(160, 76, 20, paint); |
| 3586 | canvas->drawCircle(140, 150, 35, paint); |
| 3587 | } |
| 3588 | ## |
| 3589 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3590 | #SeeAlso drawOval drawRRect drawRoundRect drawPath drawArc drawPoint drawLine |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3591 | |
| 3592 | ## |
| 3593 | |
| 3594 | #Method void drawCircle(SkPoint center, SkScalar radius, const SkPaint& paint) |
| 3595 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3596 | Draws Circle at center with radius using Clip, Matrix, and Paint paint. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3597 | If radius is zero or less, nothing is drawn. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3598 | In paint: Paint_Style determines if Circle is stroked or filled; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3599 | if stroked, Paint_Stroke_Width describes the line thickness. |
| 3600 | |
| 3601 | #Param center Circle center ## |
| 3602 | #Param radius half the diameter of Circle ## |
| 3603 | #Param paint Paint stroke or fill, blend, color, and so on, used to draw ## |
| 3604 | |
| 3605 | #Example |
| 3606 | void draw(SkCanvas* canvas) { |
| 3607 | SkPaint paint; |
| 3608 | paint.setAntiAlias(true); |
| 3609 | canvas->drawCircle(128, 128, 90, paint); |
| 3610 | paint.setColor(SK_ColorWHITE); |
| 3611 | canvas->drawCircle({86, 86}, 20, paint); |
| 3612 | canvas->drawCircle({160, 76}, 20, paint); |
| 3613 | canvas->drawCircle({140, 150}, 35, paint); |
| 3614 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3615 | ## |
| 3616 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3617 | #SeeAlso drawOval drawRRect drawRoundRect drawPath drawArc drawPoint drawLine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3618 | |
| 3619 | ## |
| 3620 | |
| 3621 | # ------------------------------------------------------------------------------ |
| 3622 | |
| 3623 | #Method void drawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, |
| 3624 | bool useCenter, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3625 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3626 | #Line # draws Arc using Clip, Matrix, and Paint ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3627 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3628 | Draws Arc using Clip, Matrix, and Paint paint. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3629 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3630 | Arc is part of Oval bounded by oval, sweeping from startAngle to startAngle plus |
| 3631 | sweepAngle. startAngle and sweepAngle are in degrees. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3632 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3633 | startAngle of zero places start point at the right middle edge of oval. |
| 3634 | A positive sweepAngle places Arc end point clockwise from start point; |
| 3635 | a negative sweepAngle places Arc end point counterclockwise from start point. |
| 3636 | sweepAngle may exceed 360 degrees, a full circle. |
| 3637 | If useCenter is true, draw a wedge that includes lines from oval |
| 3638 | center to Arc end points. If useCenter is false, draw Arc between end points. |
| 3639 | |
| 3640 | If Rect oval is empty or sweepAngle is zero, nothing is drawn. |
| 3641 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3642 | #Param oval Rect bounds of Oval containing Arc to draw ## |
| 3643 | #Param startAngle angle in degrees where Arc begins ## |
| 3644 | #Param sweepAngle sweep angle in degrees; positive is clockwise ## |
| 3645 | #Param useCenter if true, include the center of the oval ## |
| 3646 | #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] | 3647 | |
| 3648 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3649 | void draw(SkCanvas* canvas) { |
| 3650 | SkPaint paint; |
| 3651 | paint.setAntiAlias(true); |
| 3652 | SkRect oval = { 4, 4, 60, 60}; |
| 3653 | for (auto useCenter : { false, true } ) { |
| 3654 | for (auto style : { SkPaint::kFill_Style, SkPaint::kStroke_Style } ) { |
| 3655 | paint.setStyle(style); |
| 3656 | for (auto degrees : { 45, 90, 180, 360} ) { |
| 3657 | canvas->drawArc(oval, 0, degrees , useCenter, paint); |
| 3658 | canvas->translate(64, 0); |
| 3659 | } |
| 3660 | canvas->translate(-256, 64); |
| 3661 | } |
| 3662 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3663 | } |
| 3664 | ## |
| 3665 | |
| 3666 | #Example |
| 3667 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3668 | void draw(SkCanvas* canvas) { |
| 3669 | SkPaint paint; |
| 3670 | paint.setAntiAlias(true); |
| 3671 | paint.setStyle(SkPaint::kStroke_Style); |
| 3672 | paint.setStrokeWidth(4); |
| 3673 | SkRect oval = { 4, 4, 60, 60}; |
| 3674 | float intervals[] = { 5, 5 }; |
| 3675 | paint.setPathEffect(SkDashPathEffect::Make(intervals, 2, 2.5f)); |
| 3676 | for (auto degrees : { 270, 360, 540, 720 } ) { |
| 3677 | canvas->drawArc(oval, 0, degrees, false, paint); |
| 3678 | canvas->translate(64, 0); |
| 3679 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3680 | } |
| 3681 | ## |
| 3682 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3683 | #SeeAlso SkPath::arcTo drawCircle drawOval drawPath |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3684 | |
| 3685 | ## |
| 3686 | |
| 3687 | # ------------------------------------------------------------------------------ |
| 3688 | |
| 3689 | #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] | 3690 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3691 | #Line # draws Round_Rect using Clip, Matrix, and Paint ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3692 | Draws Round_Rect bounded by Rect rect, with corner radii (rx, ry) using Clip, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3693 | Matrix, and Paint paint. |
| 3694 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3695 | In paint: Paint_Style determines if Round_Rect is stroked or filled; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3696 | if stroked, Paint_Stroke_Width describes the line thickness. |
| 3697 | If rx or ry are less than zero, they are treated as if they are zero. |
| 3698 | 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] | 3699 | If rx and ry are zero, Round_Rect is drawn as Rect and if stroked is affected by |
| 3700 | Paint_Stroke_Join. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3701 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3702 | #Param rect Rect bounds of Round_Rect to draw ## |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 3703 | #Param rx axis length on x-axis of oval describing rounded corners ## |
| 3704 | #Param ry axis length on y-axis of oval describing rounded corners ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3705 | #Param paint stroke, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3706 | |
| 3707 | #Example |
| 3708 | #Description |
| 3709 | Top row has a zero radius a generates a rectangle. |
| 3710 | Second row radii sum to less than sides. |
| 3711 | Third row radii sum equals sides. |
| 3712 | Fourth row radii sum exceeds sides; radii are scaled to fit. |
| 3713 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3714 | void draw(SkCanvas* canvas) { |
| 3715 | SkVector radii[] = { {0, 20}, {10, 10}, {10, 20}, {10, 40} }; |
| 3716 | SkPaint paint; |
| 3717 | paint.setStrokeWidth(15); |
| 3718 | paint.setStrokeJoin(SkPaint::kRound_Join); |
| 3719 | paint.setAntiAlias(true); |
| 3720 | for (auto style : { SkPaint::kStroke_Style, SkPaint::kFill_Style } ) { |
| 3721 | paint.setStyle(style ); |
| 3722 | for (size_t i = 0; i < SK_ARRAY_COUNT(radii); ++i) { |
| 3723 | canvas->drawRoundRect({10, 10, 60, 40}, radii[i].fX, radii[i].fY, paint); |
| 3724 | canvas->translate(0, 60); |
| 3725 | } |
| 3726 | canvas->translate(80, -240); |
| 3727 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3728 | } |
| 3729 | ## |
| 3730 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3731 | #SeeAlso DrawRRect drawRect drawDRRect drawPath drawCircle drawOval drawPoint |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3732 | |
| 3733 | ## |
| 3734 | |
| 3735 | # ------------------------------------------------------------------------------ |
| 3736 | |
| 3737 | #Method void drawPath(const SkPath& path, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3738 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3739 | #Line # draws Path using Clip, Matrix, and Paint ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3740 | Draws Path path using Clip, Matrix, and Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3741 | Path contains an array of Path_Contour, each of which may be open or closed. |
| 3742 | |
| 3743 | In paint: Paint_Style determines if Round_Rect is stroked or filled: |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3744 | if filled, Path_Fill_Type determines whether Path_Contour describes inside or |
| 3745 | outside of fill; if stroked, Paint_Stroke_Width describes the line thickness, |
| 3746 | Paint_Stroke_Cap describes line ends, and Paint_Stroke_Join describes how |
| 3747 | corners are drawn. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3748 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3749 | #Param path Path to draw ## |
| 3750 | #Param paint stroke, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3751 | |
| 3752 | #Example |
| 3753 | #Description |
| 3754 | Top rows draw stroked path with combinations of joins and caps. The open contour |
| 3755 | is affected by caps; the closed contour is affected by joins. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3756 | Bottom row draws fill the same for open and closed contour. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3757 | First bottom column shows winding fills overlap. |
| 3758 | Second bottom column shows even odd fills exclude overlap. |
| 3759 | Third bottom column shows inverse winding fills area outside both contours. |
| 3760 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3761 | void draw(SkCanvas* canvas) { |
| 3762 | SkPath path; |
| 3763 | path.moveTo(20, 20); |
| 3764 | path.quadTo(60, 20, 60, 60); |
| 3765 | path.close(); |
| 3766 | path.moveTo(60, 20); |
| 3767 | path.quadTo(60, 60, 20, 60); |
| 3768 | SkPaint paint; |
| 3769 | paint.setStrokeWidth(10); |
| 3770 | paint.setAntiAlias(true); |
| 3771 | paint.setStyle(SkPaint::kStroke_Style); |
| 3772 | for (auto join: { SkPaint::kBevel_Join, SkPaint::kRound_Join, SkPaint::kMiter_Join } ) { |
| 3773 | paint.setStrokeJoin(join); |
| 3774 | for (auto cap: { SkPaint::kButt_Cap, SkPaint::kSquare_Cap, SkPaint::kRound_Cap } ) { |
| 3775 | paint.setStrokeCap(cap); |
| 3776 | canvas->drawPath(path, paint); |
| 3777 | canvas->translate(80, 0); |
| 3778 | } |
| 3779 | canvas->translate(-240, 60); |
| 3780 | } |
| 3781 | paint.setStyle(SkPaint::kFill_Style); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3782 | for (auto fill : { SkPath::kWinding_FillType, |
| 3783 | SkPath::kEvenOdd_FillType, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3784 | SkPath::kInverseWinding_FillType } ) { |
| 3785 | path.setFillType(fill); |
| 3786 | canvas->save(); |
| 3787 | canvas->clipRect({0, 10, 80, 70}); |
| 3788 | canvas->drawPath(path, paint); |
| 3789 | canvas->restore(); |
| 3790 | canvas->translate(80, 0); |
| 3791 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3792 | } |
| 3793 | ## |
| 3794 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3795 | #SeeAlso SkPath drawLine drawArc drawRect drawPoints |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3796 | |
| 3797 | ## |
| 3798 | |
| 3799 | # ------------------------------------------------------------------------------ |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3800 | #Subtopic Draw_Image |
| 3801 | #Line # draws Image to Canvas ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3802 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3803 | drawImage, drawImageRect, and drawImageNine can be called with a bare pointer or |
| 3804 | 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] | 3805 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 3806 | #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] | 3807 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3808 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3809 | #Line # draws Image at (x, y) position ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3810 | Draws Image image, with its top-left corner at (left, top), |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3811 | using Clip, Matrix, and optional Paint paint. |
| 3812 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3813 | If paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, Blend_Mode, |
| 3814 | and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader. |
| 3815 | If paint contains Mask_Filter, generate mask from image bounds. If generated |
| 3816 | mask extends beyond image bounds, replicate image edge colors, just as Shader |
| 3817 | made from SkImage::makeShader with SkShader::kClamp_TileMode set replicates the |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3818 | image edge color when it samples outside of its bounds. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3819 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3820 | #Param image uncompressed rectangular map of pixels ## |
| 3821 | #Param left left side of image ## |
| 3822 | #Param top top side of image ## |
| 3823 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 3824 | and so on; or nullptr |
| 3825 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3826 | |
| 3827 | #Example |
| 3828 | #Height 64 |
| 3829 | #Image 4 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3830 | void draw(SkCanvas* canvas) { |
| 3831 | // sk_sp<SkImage> image; |
| 3832 | SkImage* imagePtr = image.get(); |
| 3833 | canvas->drawImage(imagePtr, 0, 0); |
| 3834 | SkPaint paint; |
| 3835 | canvas->drawImage(imagePtr, 80, 0, &paint); |
| 3836 | paint.setAlpha(0x80); |
| 3837 | canvas->drawImage(imagePtr, 160, 0, &paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3838 | } |
| 3839 | ## |
| 3840 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3841 | #SeeAlso drawBitmap drawImageLattice drawImageNine drawImageRect SkPaint::setImageFilter |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3842 | |
| 3843 | ## |
| 3844 | |
| 3845 | # ------------------------------------------------------------------------------ |
| 3846 | |
| 3847 | #Method void drawImage(const sk_sp<SkImage>& image, SkScalar left, SkScalar top, |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3848 | const SkPaint* paint = nullptr) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3849 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3850 | Draws Image image, with its top-left corner at (left, top), |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3851 | using Clip, Matrix, and optional Paint paint. |
| 3852 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3853 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 3854 | Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader. |
| 3855 | If paint contains Mask_Filter, generate mask from image bounds. If generated |
| 3856 | mask extends beyond image bounds, replicate image edge colors, just as Shader |
| 3857 | made from SkImage::makeShader with SkShader::kClamp_TileMode set replicates the |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3858 | image edge color when it samples outside of its bounds. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3859 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3860 | #Param image uncompressed rectangular map of pixels ## |
| 3861 | #Param left left side of image ## |
| 3862 | #Param top pop side of image ## |
| 3863 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 3864 | and so on; or nullptr |
| 3865 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3866 | |
| 3867 | #Example |
| 3868 | #Height 64 |
| 3869 | #Image 4 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3870 | void draw(SkCanvas* canvas) { |
| 3871 | // sk_sp<SkImage> image; |
| 3872 | canvas->drawImage(image, 0, 0); |
| 3873 | SkPaint paint; |
| 3874 | canvas->drawImage(image, 80, 0, &paint); |
| 3875 | paint.setAlpha(0x80); |
| 3876 | canvas->drawImage(image, 160, 0, &paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3877 | } |
| 3878 | ## |
| 3879 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3880 | #SeeAlso drawBitmap drawImageLattice drawImageNine drawImageRect SkPaint::setImageFilter |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3881 | |
| 3882 | ## |
| 3883 | |
| 3884 | # ------------------------------------------------------------------------------ |
| 3885 | |
| 3886 | #Enum SrcRectConstraint |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 3887 | #Line # sets drawImageRect options ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3888 | |
| 3889 | #Code |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 3890 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3891 | ## |
| 3892 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3893 | SrcRectConstraint controls the behavior at the edge of source Rect, |
| 3894 | provided to drawImageRect, trading off speed for precision. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3895 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3896 | 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] | 3897 | restricts the bounds of pixels that may be read. Image_Filter may slow down if |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3898 | 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] | 3899 | SrcRectConstraint specifies whether an Image_Filter is allowed to read pixels |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3900 | outside source Rect. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3901 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3902 | #Const kStrict_SrcRectConstraint 0 |
| 3903 | #Line # sample only inside bounds; slower ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3904 | Requires Image_Filter to respect source Rect, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3905 | sampling only inside of its bounds, possibly with a performance penalty. |
| 3906 | ## |
| 3907 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 3908 | #Const kFast_SrcRectConstraint 1 |
| 3909 | #Line # sample outside bounds; faster ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3910 | Permits Image_Filter to sample outside of source Rect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3911 | by half the width of Image_Filter, permitting it to run faster but with |
| 3912 | error at the image edges. |
| 3913 | ## |
| 3914 | |
| 3915 | #Example |
| 3916 | #Height 64 |
| 3917 | #Description |
| 3918 | redBorder contains a black and white checkerboard bordered by red. |
| 3919 | redBorder is drawn scaled by 16 on the left. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 3920 | The middle and right bitmaps are filtered checkerboards. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3921 | Drawing the checkerboard with kStrict_SrcRectConstraint shows only a blur of black and white. |
| 3922 | Drawing the checkerboard with kFast_SrcRectConstraint allows red to bleed in the corners. |
| 3923 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3924 | void draw(SkCanvas* canvas) { |
| 3925 | SkBitmap redBorder; |
| 3926 | redBorder.allocPixels(SkImageInfo::MakeN32Premul(4, 4)); |
| 3927 | SkCanvas checkRed(redBorder); |
| 3928 | checkRed.clear(SK_ColorRED); |
| 3929 | uint32_t checkers[][2] = { { SK_ColorBLACK, SK_ColorWHITE }, |
| 3930 | { SK_ColorWHITE, SK_ColorBLACK } }; |
| 3931 | checkRed.writePixels( |
| 3932 | SkImageInfo::MakeN32Premul(2, 2), (void*) checkers, sizeof(checkers[0]), 1, 1); |
| 3933 | canvas->scale(16, 16); |
| 3934 | canvas->drawBitmap(redBorder, 0, 0, nullptr); |
| 3935 | canvas->resetMatrix(); |
| 3936 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(redBorder); |
| 3937 | SkPaint lowPaint; |
| 3938 | lowPaint.setFilterQuality(kLow_SkFilterQuality); |
| 3939 | for (auto constraint : { SkCanvas::kStrict_SrcRectConstraint, |
| 3940 | SkCanvas::kFast_SrcRectConstraint } ) { |
| 3941 | canvas->translate(80, 0); |
| 3942 | canvas->drawImageRect(image.get(), SkRect::MakeLTRB(1, 1, 3, 3), |
| 3943 | SkRect::MakeLTRB(16, 16, 48, 48), &lowPaint, constraint); |
| 3944 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3945 | } |
| 3946 | ## |
| 3947 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 3948 | #SeeAlso drawImageRect drawImage SkPaint::setImageFilter |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3949 | |
| 3950 | ## |
| 3951 | |
| 3952 | # ------------------------------------------------------------------------------ |
| 3953 | |
| 3954 | #Method void drawImageRect(const SkImage* image, const SkRect& src, const SkRect& dst, |
| 3955 | const SkPaint* paint, |
| 3956 | SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3957 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 3958 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 3959 | #Line # draws Image, source Rect to destination Rect ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3960 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 3961 | Draws Rect src of Image image, scaled and translated to fill Rect dst. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3962 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3963 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3964 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 3965 | Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader. |
| 3966 | If paint contains Mask_Filter, generate mask from image bounds. |
| 3967 | |
| 3968 | If generated mask extends beyond image bounds, replicate image edge colors, just |
| 3969 | as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3970 | replicates the image edge color when it samples outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3971 | |
| 3972 | constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to |
| 3973 | sample within src; set to kFast_SrcRectConstraint allows sampling outside to |
| 3974 | improve performance. |
| 3975 | |
| 3976 | #Param image Image containing pixels, dimensions, and format ## |
| 3977 | #Param src source Rect of image to draw from ## |
| 3978 | #Param dst destination Rect of image to draw to ## |
| 3979 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 3980 | and so on; or nullptr |
| 3981 | ## |
| 3982 | #Param constraint filter strictly within src or draw faster ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3983 | |
| 3984 | #Example |
| 3985 | #Height 64 |
| 3986 | #Description |
| 3987 | The left bitmap draws with Paint default kNone_SkFilterQuality, and stays within |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 3988 | its bounds; there is no bleeding with kFast_SrcRectConstraint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 3989 | the middle and right bitmaps draw with kLow_SkFilterQuality; with |
| 3990 | kStrict_SrcRectConstraint, the filter remains within the checkerboard, and |
| 3991 | with kFast_SrcRectConstraint red bleeds on the edges. |
| 3992 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3993 | void draw(SkCanvas* canvas) { |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 3994 | uint32_t pixels[][4] = { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 3995 | { 0xFFFF0000, 0xFFFF0000, 0xFFFF0000, 0xFFFF0000 }, |
| 3996 | { 0xFFFF0000, 0xFF000000, 0xFFFFFFFF, 0xFFFF0000 }, |
| 3997 | { 0xFFFF0000, 0xFFFFFFFF, 0xFF000000, 0xFFFF0000 }, |
| 3998 | { 0xFFFF0000, 0xFFFF0000, 0xFFFF0000, 0xFFFF0000 } }; |
| 3999 | SkBitmap redBorder; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4000 | redBorder.installPixels(SkImageInfo::MakeN32Premul(4, 4), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4001 | (void*) pixels, sizeof(pixels[0])); |
| 4002 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(redBorder); |
| 4003 | SkPaint lowPaint; |
| 4004 | for (auto constraint : { |
| 4005 | SkCanvas::kFast_SrcRectConstraint, |
| 4006 | SkCanvas::kStrict_SrcRectConstraint, |
| 4007 | SkCanvas::kFast_SrcRectConstraint } ) { |
| 4008 | canvas->drawImageRect(image.get(), SkRect::MakeLTRB(1, 1, 3, 3), |
| 4009 | SkRect::MakeLTRB(16, 16, 48, 48), &lowPaint, constraint); |
| 4010 | lowPaint.setFilterQuality(kLow_SkFilterQuality); |
| 4011 | canvas->translate(80, 0); |
| 4012 | } |
| 4013 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4014 | ## |
| 4015 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4016 | #SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4017 | |
| 4018 | ## |
| 4019 | |
| 4020 | # ------------------------------------------------------------------------------ |
| 4021 | |
| 4022 | #Method void drawImageRect(const SkImage* image, const SkIRect& isrc, const SkRect& dst, |
| 4023 | const SkPaint* paint, SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4024 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4025 | #In Draw |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4026 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4027 | Draws IRect isrc of Image image, scaled and translated to fill Rect dst. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4028 | Note that isrc is on integer pixel boundaries; dst may include fractional |
| 4029 | boundaries. Additionally transform draw using Clip, Matrix, and optional Paint |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4030 | paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4031 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4032 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4033 | Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader. |
| 4034 | If paint contains Mask_Filter, generate mask from image bounds. |
| 4035 | |
| 4036 | If generated mask extends beyond image bounds, replicate image edge colors, just |
| 4037 | as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4038 | replicates the image edge color when it samples outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4039 | |
| 4040 | constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4041 | sample within isrc; set to kFast_SrcRectConstraint allows sampling outside to |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4042 | improve performance. |
| 4043 | |
| 4044 | #Param image Image containing pixels, dimensions, and format ## |
| 4045 | #Param isrc source IRect of image to draw from ## |
| 4046 | #Param dst destination Rect of image to draw to ## |
| 4047 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4048 | and so on; or nullptr |
| 4049 | ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4050 | #Param constraint filter strictly within isrc or draw faster ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4051 | |
| 4052 | #Example |
| 4053 | #Image 4 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4054 | void draw(SkCanvas* canvas) { |
| 4055 | // sk_sp<SkImage> image; |
| 4056 | for (auto i : { 1, 2, 4, 8 } ) { |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4057 | canvas->drawImageRect(image.get(), SkIRect::MakeLTRB(0, 0, 100, 100), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4058 | SkRect::MakeXYWH(i * 20, i * 20, i * 20, i * 20), nullptr); |
| 4059 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4060 | } |
| 4061 | ## |
| 4062 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4063 | #SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4064 | |
| 4065 | ## |
| 4066 | |
| 4067 | # ------------------------------------------------------------------------------ |
| 4068 | |
| 4069 | #Method void drawImageRect(const SkImage* image, const SkRect& dst, const SkPaint* paint, |
| 4070 | SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4071 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4072 | #In Draw |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4073 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4074 | Draws Image image, scaled and translated to fill Rect dst, using Clip, Matrix, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4075 | and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4076 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4077 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4078 | Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader. |
| 4079 | If paint contains Mask_Filter, generate mask from image bounds. |
| 4080 | |
| 4081 | If generated mask extends beyond image bounds, replicate image edge colors, just |
| 4082 | as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4083 | replicates the image edge color when it samples outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4084 | |
| 4085 | constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4086 | sample within image; set to kFast_SrcRectConstraint allows sampling outside to |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4087 | improve performance. |
| 4088 | |
| 4089 | #Param image Image containing pixels, dimensions, and format ## |
| 4090 | #Param dst destination Rect of image to draw to ## |
| 4091 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4092 | and so on; or nullptr |
| 4093 | ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4094 | #Param constraint filter strictly within image or draw faster ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4095 | |
| 4096 | #Example |
| 4097 | #Image 4 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4098 | void draw(SkCanvas* canvas) { |
| 4099 | // sk_sp<SkImage> image; |
| 4100 | for (auto i : { 20, 40, 80, 160 } ) { |
| 4101 | canvas->drawImageRect(image.get(), SkRect::MakeXYWH(i, i, i, i), nullptr); |
| 4102 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4103 | } |
| 4104 | ## |
| 4105 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4106 | #SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4107 | |
| 4108 | ## |
| 4109 | |
| 4110 | # ------------------------------------------------------------------------------ |
| 4111 | |
| 4112 | #Method void drawImageRect(const sk_sp<SkImage>& image, const SkRect& src, const SkRect& dst, |
| 4113 | const SkPaint* paint, |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4114 | SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4115 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4116 | #In Draw |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4117 | Draws Rect src of Image image, scaled and translated to fill Rect dst. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4118 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4119 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4120 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4121 | Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader. |
| 4122 | If paint contains Mask_Filter, generate mask from image bounds. |
| 4123 | |
| 4124 | If generated mask extends beyond image bounds, replicate image edge colors, just |
| 4125 | as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4126 | replicates the image edge color when it samples outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4127 | |
| 4128 | constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to |
| 4129 | sample within src; set to kFast_SrcRectConstraint allows sampling outside to |
| 4130 | improve performance. |
| 4131 | |
| 4132 | #Param image Image containing pixels, dimensions, and format ## |
| 4133 | #Param src source Rect of image to draw from ## |
| 4134 | #Param dst destination Rect of image to draw to ## |
| 4135 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4136 | and so on; or nullptr |
| 4137 | ## |
| 4138 | #Param constraint filter strictly within src or draw faster ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4139 | |
| 4140 | #Example |
| 4141 | #Height 64 |
| 4142 | #Description |
| 4143 | Canvas scales and translates; transformation from src to dst also scales. |
| 4144 | The two matrices are concatenated to create the final transformation. |
| 4145 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4146 | void draw(SkCanvas* canvas) { |
| 4147 | uint32_t pixels[][2] = { { SK_ColorBLACK, SK_ColorWHITE }, |
| 4148 | { SK_ColorWHITE, SK_ColorBLACK } }; |
| 4149 | SkBitmap bitmap; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4150 | bitmap.installPixels(SkImageInfo::MakeN32Premul(2, 2), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4151 | (void*) pixels, sizeof(pixels[0])); |
| 4152 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 4153 | SkPaint paint; |
| 4154 | canvas->scale(4, 4); |
| 4155 | for (auto alpha : { 50, 100, 150, 255 } ) { |
| 4156 | paint.setAlpha(alpha); |
| 4157 | canvas->drawImageRect(image, SkRect::MakeWH(2, 2), SkRect::MakeWH(8, 8), &paint); |
| 4158 | canvas->translate(8, 0); |
| 4159 | } |
| 4160 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4161 | ## |
| 4162 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4163 | #SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4164 | |
| 4165 | ## |
| 4166 | |
| 4167 | # ------------------------------------------------------------------------------ |
| 4168 | |
| 4169 | #Method void drawImageRect(const sk_sp<SkImage>& image, const SkIRect& isrc, const SkRect& dst, |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4170 | const SkPaint* paint, SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4171 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4172 | #In Draw |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4173 | Draws IRect isrc of Image image, scaled and translated to fill Rect dst. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4174 | isrc is on integer pixel boundaries; dst may include fractional boundaries. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4175 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4176 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4177 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4178 | Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader. |
| 4179 | If paint contains Mask_Filter, generate mask from image bounds. |
| 4180 | |
| 4181 | If generated mask extends beyond image bounds, replicate image edge colors, just |
| 4182 | as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4183 | replicates the image edge color when it samples outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4184 | |
| 4185 | constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4186 | sample within image; set to kFast_SrcRectConstraint allows sampling outside to |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4187 | improve performance. |
| 4188 | |
| 4189 | #Param image Image containing pixels, dimensions, and format ## |
| 4190 | #Param isrc source IRect of image to draw from ## |
| 4191 | #Param dst destination Rect of image to draw to ## |
| 4192 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4193 | and so on; or nullptr |
| 4194 | ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4195 | #Param constraint filter strictly within image or draw faster ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4196 | |
| 4197 | #Example |
| 4198 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4199 | void draw(SkCanvas* canvas) { |
| 4200 | uint32_t pixels[][2] = { { 0x00000000, 0x55555555}, |
| 4201 | { 0xAAAAAAAA, 0xFFFFFFFF} }; |
| 4202 | SkBitmap bitmap; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4203 | bitmap.installPixels(SkImageInfo::MakeN32Premul(2, 2), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4204 | (void*) pixels, sizeof(pixels[0])); |
| 4205 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 4206 | SkPaint paint; |
| 4207 | canvas->scale(4, 4); |
| 4208 | for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN } ) { |
| 4209 | paint.setColorFilter(SkColorFilter::MakeModeFilter(color, SkBlendMode::kPlus)); |
| 4210 | canvas->drawImageRect(image, SkIRect::MakeWH(2, 2), SkRect::MakeWH(8, 8), &paint); |
| 4211 | canvas->translate(8, 0); |
| 4212 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4213 | } |
| 4214 | ## |
| 4215 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4216 | #SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine |
| 4217 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4218 | ## |
| 4219 | |
| 4220 | # ------------------------------------------------------------------------------ |
| 4221 | |
| 4222 | #Method void drawImageRect(const sk_sp<SkImage>& image, const SkRect& dst, const SkPaint* paint, |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4223 | SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4224 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4225 | #In Draw |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4226 | Draws Image image, scaled and translated to fill Rect dst, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4227 | using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4228 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4229 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4230 | Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader. |
| 4231 | If paint contains Mask_Filter, generate mask from image bounds. |
| 4232 | |
| 4233 | If generated mask extends beyond image bounds, replicate image edge colors, just |
| 4234 | as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4235 | replicates the image edge color when it samples outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4236 | |
| 4237 | constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4238 | sample within image; set to kFast_SrcRectConstraint allows sampling outside to |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4239 | improve performance. |
| 4240 | |
| 4241 | #Param image Image containing pixels, dimensions, and format ## |
| 4242 | #Param dst destination Rect of image to draw to ## |
| 4243 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4244 | and so on; or nullptr |
| 4245 | ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4246 | #Param constraint filter strictly within image or draw faster ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4247 | |
| 4248 | #Example |
| 4249 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4250 | void draw(SkCanvas* canvas) { |
| 4251 | uint32_t pixels[][2] = { { 0x00000000, 0x55550000}, |
| 4252 | { 0xAAAA0000, 0xFFFF0000} }; |
| 4253 | SkBitmap bitmap; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4254 | bitmap.installPixels(SkImageInfo::MakeN32Premul(2, 2), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4255 | (void*) pixels, sizeof(pixels[0])); |
| 4256 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 4257 | SkPaint paint; |
| 4258 | canvas->scale(4, 4); |
| 4259 | for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN } ) { |
| 4260 | paint.setColorFilter(SkColorFilter::MakeModeFilter(color, SkBlendMode::kPlus)); |
| 4261 | canvas->drawImageRect(image, SkRect::MakeWH(8, 8), &paint); |
| 4262 | canvas->translate(8, 0); |
| 4263 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4264 | } |
| 4265 | ## |
| 4266 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4267 | #SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4268 | |
| 4269 | ## |
| 4270 | |
| 4271 | # ------------------------------------------------------------------------------ |
| 4272 | |
| 4273 | #Method void drawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst, |
| 4274 | const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4275 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4276 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4277 | #Line # draws Nine_Patch Image ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4278 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4279 | Draws Image image stretched proportionally to fit into Rect dst. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4280 | 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] | 4281 | the center. Corners are unmodified or scaled down proportionately if their sides |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4282 | 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] | 4283 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4284 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
| 4285 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4286 | #paint_as_used_by_draw_lattice_or_draw_nine(image)# |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4287 | |
| 4288 | If generated mask extends beyond image bounds, replicate image edge colors, just |
| 4289 | as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4290 | replicates the image edge color when it samples outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4291 | |
| 4292 | #Param image Image containing pixels, dimensions, and format ## |
| 4293 | #Param center IRect edge of image corners and sides ## |
| 4294 | #Param dst destination Rect of image to draw to ## |
| 4295 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4296 | and so on; or nullptr |
| 4297 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4298 | |
| 4299 | #Example |
| 4300 | #Height 128 |
| 4301 | #Description |
| 4302 | 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] | 4303 | The second image equals the size of center; only corners are drawn without scaling. |
| 4304 | The remaining images are larger than center. All corners draw without scaling. |
| 4305 | 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] | 4306 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4307 | void draw(SkCanvas* canvas) { |
| 4308 | SkIRect center = { 20, 10, 50, 40 }; |
| 4309 | SkBitmap bitmap; |
| 4310 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60)); |
| 4311 | SkCanvas bitCanvas(bitmap); |
| 4312 | SkPaint paint; |
| 4313 | SkColor gray = 0xFF000000; |
| 4314 | int left = 0; |
| 4315 | for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) { |
| 4316 | int top = 0; |
| 4317 | for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) { |
| 4318 | paint.setColor(gray); |
| 4319 | bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint); |
| 4320 | gray += 0x001f1f1f; |
| 4321 | top = bottom; |
| 4322 | } |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4323 | left = right; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4324 | } |
| 4325 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 4326 | SkImage* imagePtr = image.get(); |
| 4327 | for (auto dest: { 20, 30, 40, 60, 90 } ) { |
| 4328 | canvas->drawImageNine(imagePtr, center, SkRect::MakeWH(dest, dest), nullptr); |
| 4329 | canvas->translate(dest + 4, 0); |
| 4330 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4331 | } |
| 4332 | ## |
| 4333 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4334 | #SeeAlso drawImage drawBitmapNine drawImageLattice drawImageRect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4335 | |
| 4336 | ## |
| 4337 | |
| 4338 | # ------------------------------------------------------------------------------ |
| 4339 | |
| 4340 | #Method void drawImageNine(const sk_sp<SkImage>& image, const SkIRect& center, const SkRect& dst, |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4341 | const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4342 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4343 | #In Draw |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4344 | Draws Image image stretched proportionally to fit into Rect dst. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4345 | 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] | 4346 | 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] | 4347 | 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] | 4348 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4349 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
| 4350 | |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 4351 | #paint_as_used_by_draw_lattice_or_draw_nine(image)# |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4352 | |
| 4353 | If generated mask extends beyond image bounds, replicate image edge colors, just |
| 4354 | as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4355 | replicates the image edge color when it samples outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4356 | |
| 4357 | #Param image Image containing pixels, dimensions, and format ## |
| 4358 | #Param center IRect edge of image corners and sides ## |
| 4359 | #Param dst destination Rect of image to draw to ## |
| 4360 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4361 | and so on; or nullptr |
| 4362 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4363 | |
| 4364 | #Example |
| 4365 | #Height 128 |
| 4366 | #Description |
| 4367 | The two leftmost images has four corners and sides to the left and right of center. |
| 4368 | The leftmost image scales the width of corners proportionately to fit. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4369 | 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] | 4370 | fill the remaining space. |
| 4371 | The rightmost image has four corners scaled vertically to fit, and uses sides above |
| 4372 | and below center to fill the remaining space. |
| 4373 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4374 | void draw(SkCanvas* canvas) { |
| 4375 | SkIRect center = { 20, 10, 50, 40 }; |
| 4376 | SkBitmap bitmap; |
| 4377 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60)); |
| 4378 | SkCanvas bitCanvas(bitmap); |
| 4379 | SkPaint paint; |
| 4380 | SkColor gray = 0xFF000000; |
| 4381 | int left = 0; |
| 4382 | for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) { |
| 4383 | int top = 0; |
| 4384 | for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) { |
| 4385 | paint.setColor(gray); |
| 4386 | bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint); |
| 4387 | gray += 0x001f1f1f; |
| 4388 | top = bottom; |
| 4389 | } |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4390 | left = right; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4391 | } |
| 4392 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 4393 | for (auto dest: { 20, 30, 40, 60, 90 } ) { |
| 4394 | canvas->drawImageNine(image, center, SkRect::MakeWH(dest, 110 - dest), nullptr); |
| 4395 | canvas->translate(dest + 4, 0); |
| 4396 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4397 | } |
| 4398 | ## |
| 4399 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4400 | #SeeAlso drawImage drawBitmapNine drawImageLattice drawImageRect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4401 | |
| 4402 | ## |
| 4403 | |
| 4404 | # ------------------------------------------------------------------------------ |
| 4405 | |
| 4406 | #Method void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4407 | const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4408 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4409 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4410 | #Line # draws Bitmap at (x, y) position ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4411 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4412 | Draws Bitmap bitmap, with its top-left corner at (left, top), |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4413 | using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4414 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 4415 | 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] | 4416 | Blend_Mode, and Draw_Looper. If bitmap is kAlpha_8_SkColorType, apply Shader. |
| 4417 | If paint contains Mask_Filter, generate mask from bitmap bounds. |
| 4418 | |
| 4419 | If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, |
| 4420 | just as Shader made from SkShader::MakeBitmapShader with |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4421 | SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4422 | outside of its bounds. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4423 | |
| 4424 | #Param bitmap Bitmap containing pixels, dimensions, and format ## |
| 4425 | #Param left left side of bitmap ## |
| 4426 | #Param top top side of bitmap ## |
| 4427 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4428 | and so on; or nullptr |
| 4429 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4430 | |
| 4431 | #Example |
| 4432 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4433 | void draw(SkCanvas* canvas) { |
| 4434 | uint8_t pixels[][8] = { { 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00}, |
| 4435 | { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00}, |
| 4436 | { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00}, |
| 4437 | { 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF}, |
| 4438 | { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, |
| 4439 | { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00}, |
| 4440 | { 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00}, |
| 4441 | { 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF} }; |
| 4442 | SkBitmap bitmap; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4443 | bitmap.installPixels(SkImageInfo::MakeA8(8, 8), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4444 | (void*) pixels, sizeof(pixels[0])); |
| 4445 | SkPaint paint; |
| 4446 | canvas->scale(4, 4); |
| 4447 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xFF007F00} ) { |
| 4448 | paint.setColor(color); |
| 4449 | canvas->drawBitmap(bitmap, 0, 0, &paint); |
| 4450 | canvas->translate(12, 0); |
| 4451 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4452 | } |
| 4453 | ## |
| 4454 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4455 | #SeeAlso drawImage drawBitmapLattice drawBitmapNine drawBitmapRect SkBitmap::readPixels SkBitmap::writePixels |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4456 | |
| 4457 | ## |
| 4458 | |
| 4459 | # ------------------------------------------------------------------------------ |
| 4460 | |
| 4461 | #Method void drawBitmapRect(const SkBitmap& bitmap, const SkRect& src, const SkRect& dst, |
| 4462 | const SkPaint* paint, SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4463 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4464 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4465 | #Line # draws Bitmap, source Rect to destination Rect ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4466 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4467 | Draws Rect src of Bitmap bitmap, scaled and translated to fill Rect dst. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4468 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4469 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4470 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4471 | Blend_Mode, and Draw_Looper. If bitmap is kAlpha_8_SkColorType, apply Shader. |
| 4472 | If paint contains Mask_Filter, generate mask from bitmap bounds. |
| 4473 | |
| 4474 | If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, |
| 4475 | just as Shader made from SkShader::MakeBitmapShader with |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4476 | SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4477 | outside of its bounds. |
| 4478 | |
| 4479 | constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to |
| 4480 | sample within src; set to kFast_SrcRectConstraint allows sampling outside to |
| 4481 | improve performance. |
| 4482 | |
| 4483 | #Param bitmap Bitmap containing pixels, dimensions, and format ## |
| 4484 | #Param src source Rect of image to draw from ## |
| 4485 | #Param dst destination Rect of image to draw to ## |
| 4486 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4487 | and so on; or nullptr |
| 4488 | ## |
| 4489 | #Param constraint filter strictly within src or draw faster ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4490 | |
| 4491 | #Example |
| 4492 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4493 | void draw(SkCanvas* canvas) { |
| 4494 | uint8_t pixels[][8] = { { 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00}, |
| 4495 | { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00}, |
| 4496 | { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00}, |
| 4497 | { 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF}, |
| 4498 | { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, |
| 4499 | { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00}, |
| 4500 | { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00}, |
| 4501 | { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00} }; |
| 4502 | SkBitmap bitmap; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4503 | bitmap.installPixels(SkImageInfo::MakeA8(8, 8), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4504 | (void*) pixels, sizeof(pixels[0])); |
| 4505 | SkPaint paint; |
Cary Clark | 681287e | 2018-03-16 11:34:15 -0400 | [diff] [blame] | 4506 | paint.setMaskFilter(SkMaskFilter::MakeBlur(kSolid_SkBlurStyle, 6)); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4507 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xFF007F00} ) { |
| 4508 | paint.setColor(color); |
| 4509 | canvas->drawBitmapRect(bitmap, SkRect::MakeWH(8, 8), SkRect::MakeWH(32, 32), &paint); |
| 4510 | canvas->translate(48, 0); |
| 4511 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4512 | } |
| 4513 | ## |
| 4514 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4515 | #SeeAlso drawImageRect drawBitmap drawBitmapLattice drawBitmapNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4516 | |
| 4517 | ## |
| 4518 | |
| 4519 | # ------------------------------------------------------------------------------ |
| 4520 | |
| 4521 | #Method void drawBitmapRect(const SkBitmap& bitmap, const SkIRect& isrc, const SkRect& dst, |
| 4522 | const SkPaint* paint, SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4523 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4524 | #In Draw |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4525 | Draws IRect isrc of Bitmap bitmap, scaled and translated to fill Rect dst. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4526 | isrc is on integer pixel boundaries; dst may include fractional boundaries. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4527 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4528 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4529 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4530 | Blend_Mode, and Draw_Looper. If bitmap is kAlpha_8_SkColorType, apply Shader. |
| 4531 | If paint contains Mask_Filter, generate mask from bitmap bounds. |
| 4532 | |
| 4533 | If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, |
| 4534 | just as Shader made from SkShader::MakeBitmapShader with |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4535 | SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4536 | outside of its bounds. |
| 4537 | |
| 4538 | constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4539 | sample within isrc; set to kFast_SrcRectConstraint allows sampling outside to |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4540 | improve performance. |
| 4541 | |
| 4542 | #Param bitmap Bitmap containing pixels, dimensions, and format ## |
| 4543 | #Param isrc source IRect of image to draw from ## |
| 4544 | #Param dst destination Rect of image to draw to ## |
| 4545 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4546 | and so on; or nullptr |
| 4547 | ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4548 | #Param constraint sample strictly within isrc, or draw faster ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4549 | |
| 4550 | #Example |
| 4551 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4552 | void draw(SkCanvas* canvas) { |
| 4553 | uint8_t pixels[][8] = { { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00}, |
| 4554 | { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00}, |
| 4555 | { 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF}, |
| 4556 | { 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF}, |
| 4557 | { 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF}, |
| 4558 | { 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF}, |
| 4559 | { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00}, |
| 4560 | { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00} }; |
| 4561 | SkBitmap bitmap; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4562 | bitmap.installPixels(SkImageInfo::MakeA8(8, 8), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4563 | (void*) pixels, sizeof(pixels[0])); |
| 4564 | SkPaint paint; |
| 4565 | paint.setFilterQuality(kHigh_SkFilterQuality); |
| 4566 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xFF007F00, 0xFF7f007f} ) { |
| 4567 | paint.setColor(color); |
| 4568 | canvas->drawBitmapRect(bitmap, SkIRect::MakeWH(8, 8), SkRect::MakeWH(32, 32), &paint); |
| 4569 | canvas->translate(48.25f, 0); |
| 4570 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4571 | } |
| 4572 | ## |
| 4573 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4574 | #SeeAlso drawImageRect drawBitmap drawBitmapLattice drawBitmapNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4575 | |
| 4576 | ## |
| 4577 | |
| 4578 | # ------------------------------------------------------------------------------ |
| 4579 | |
| 4580 | #Method void drawBitmapRect(const SkBitmap& bitmap, const SkRect& dst, const SkPaint* paint, |
| 4581 | SrcRectConstraint constraint = kStrict_SrcRectConstraint) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4582 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4583 | #In Draw |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4584 | Draws Bitmap bitmap, scaled and translated to fill Rect dst. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4585 | bitmap bounds is on integer pixel boundaries; dst may include fractional boundaries. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4586 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4587 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4588 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4589 | Blend_Mode, and Draw_Looper. If bitmap is kAlpha_8_SkColorType, apply Shader. |
| 4590 | If paint contains Mask_Filter, generate mask from bitmap bounds. |
| 4591 | |
| 4592 | If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, |
| 4593 | just as Shader made from SkShader::MakeBitmapShader with |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4594 | SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4595 | outside of its bounds. |
| 4596 | |
| 4597 | constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4598 | sample within bitmap; set to kFast_SrcRectConstraint allows sampling outside to |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4599 | improve performance. |
| 4600 | |
| 4601 | #Param bitmap Bitmap containing pixels, dimensions, and format ## |
| 4602 | #Param dst destination Rect of image to draw to ## |
| 4603 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4604 | and so on; or nullptr |
| 4605 | ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4606 | #Param constraint filter strictly within bitmap or draw faster ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4607 | |
| 4608 | #Example |
| 4609 | #Height 64 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4610 | void draw(SkCanvas* canvas) { |
| 4611 | uint32_t pixels[][2] = { { 0x00000000, 0x55550000}, |
| 4612 | { 0xAAAA0000, 0xFFFF0000} }; |
| 4613 | SkBitmap bitmap; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4614 | bitmap.installPixels(SkImageInfo::MakeN32Premul(2, 2), |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4615 | (void*) pixels, sizeof(pixels[0])); |
| 4616 | SkPaint paint; |
| 4617 | canvas->scale(4, 4); |
| 4618 | for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN } ) { |
| 4619 | paint.setColorFilter(SkColorFilter::MakeModeFilter(color, SkBlendMode::kPlus)); |
| 4620 | canvas->drawBitmapRect(bitmap, SkRect::MakeWH(8, 8), &paint); |
| 4621 | canvas->translate(8, 0); |
| 4622 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4623 | } |
| 4624 | ## |
| 4625 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4626 | #SeeAlso drawImageRect drawBitmap drawBitmapLattice drawBitmapNine |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4627 | |
| 4628 | ## |
| 4629 | |
| 4630 | # ------------------------------------------------------------------------------ |
| 4631 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4632 | #PhraseDef paint_as_used_by_draw_lattice_or_draw_nine(bitmap_or_image) |
| 4633 | If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, |
| 4634 | Blend_Mode, and Draw_Looper. If #bitmap_or_image# is kAlpha_8_SkColorType, apply Shader. |
| 4635 | If paint contains Mask_Filter, generate mask from #bitmap_or_image# bounds. If paint |
| 4636 | Filter_Quality set to kNone_SkFilterQuality, disable pixel filtering. For all |
| 4637 | other values of paint Filter_Quality, use kLow_SkFilterQuality to filter pixels. |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 4638 | Any SkMaskFilter on paint is ignored as is paint Anti_Aliasing state. |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4639 | ## |
| 4640 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4641 | #Method void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst, |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 4642 | const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4643 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4644 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4645 | #Line # draws Nine_Patch Bitmap ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4646 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4647 | Draws Bitmap bitmap stretched proportionally to fit into Rect dst. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4648 | IRect center divides the bitmap into nine sections: four sides, four corners, |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 4649 | 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] | 4650 | sides are larger than dst; center and four sides are scaled to fit remaining |
| 4651 | space, if any. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4652 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4653 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
| 4654 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4655 | #paint_as_used_by_draw_lattice_or_draw_nine(bitmap)# |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4656 | |
| 4657 | If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, |
| 4658 | just as Shader made from SkShader::MakeBitmapShader with |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4659 | SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4660 | outside of its bounds. |
| 4661 | |
| 4662 | #Param bitmap Bitmap containing pixels, dimensions, and format ## |
| 4663 | #Param center IRect edge of image corners and sides ## |
| 4664 | #Param dst destination Rect of image to draw to ## |
| 4665 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4666 | and so on; or nullptr |
| 4667 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4668 | |
| 4669 | #Example |
| 4670 | #Height 128 |
| 4671 | #Description |
| 4672 | The two leftmost bitmap draws has four corners and sides to the left and right of center. |
| 4673 | The leftmost bitmap draw scales the width of corners proportionately to fit. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4674 | 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] | 4675 | fill the remaining space. |
| 4676 | The rightmost bitmap draw has four corners scaled vertically to fit, and uses sides above |
| 4677 | and below center to fill the remaining space. |
| 4678 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4679 | void draw(SkCanvas* canvas) { |
| 4680 | SkIRect center = { 20, 10, 50, 40 }; |
| 4681 | SkBitmap bitmap; |
| 4682 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60)); |
| 4683 | SkCanvas bitCanvas(bitmap); |
| 4684 | SkPaint paint; |
| 4685 | SkColor gray = 0xFF000000; |
| 4686 | int left = 0; |
| 4687 | for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) { |
| 4688 | int top = 0; |
| 4689 | for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) { |
| 4690 | paint.setColor(gray); |
| 4691 | bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint); |
| 4692 | gray += 0x001f1f1f; |
| 4693 | top = bottom; |
| 4694 | } |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4695 | left = right; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4696 | } |
| 4697 | for (auto dest: { 20, 30, 40, 60, 90 } ) { |
| 4698 | canvas->drawBitmapNine(bitmap, center, SkRect::MakeWH(dest, 110 - dest), nullptr); |
| 4699 | canvas->translate(dest + 4, 0); |
| 4700 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4701 | } |
| 4702 | ## |
| 4703 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4704 | #SeeAlso drawImageNine drawBitmap drawBitmapLattice drawBitmapRect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4705 | |
| 4706 | ## |
| 4707 | |
| 4708 | # ------------------------------------------------------------------------------ |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4709 | #Subtopic Lattice |
| 4710 | #Line # divides Bitmap or Image into a rectangular grid ## |
| 4711 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4712 | #Struct Lattice |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 4713 | #Line # divides Bitmap or Image into a rectangular grid ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4714 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4715 | #Code |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 4716 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4717 | ## |
| 4718 | |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 4719 | Lattice divides Bitmap or Image into a rectangular grid. |
| 4720 | Grid entries on even columns and even rows are fixed; these entries are |
| 4721 | always drawn at their original size if the destination is large enough. |
| 4722 | If the destination side is too small to hold the fixed entries, all fixed |
| 4723 | entries are proportionately scaled down to fit. |
| 4724 | The grid entries not on even columns and rows are scaled to fit the |
| 4725 | remaining space, if any. |
| 4726 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4727 | #Enum RectType |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4728 | #Line # optional setting per rectangular grid entry ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4729 | #Code |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 4730 | #Populate |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4731 | ## |
| 4732 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4733 | Optional setting per rectangular grid entry to make it transparent, |
| 4734 | or to fill the grid entry with a color. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4735 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4736 | #Const kDefault 0 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4737 | #Line # draws Bitmap into lattice rectangle ## |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4738 | ## |
| 4739 | |
| 4740 | #Const kTransparent 1 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4741 | #Line # skips lattice rectangle by making it transparent ## |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4742 | ## |
| 4743 | |
| 4744 | #Const kFixedColor 2 |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4745 | #Line # draws one of fColors into lattice rectangle ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4746 | ## |
| 4747 | ## |
| 4748 | |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 4749 | #Subtopic Members |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4750 | ## |
| 4751 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4752 | #Member const int* fXDivs |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 4753 | #Line # x-axis values dividing bitmap ## |
| 4754 | Array of x-axis values that divide the bitmap vertically. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4755 | Array entries must be unique, increasing, greater than or equal to |
| 4756 | fBounds left edge, and less than fBounds right edge. |
| 4757 | Set the first element to fBounds left to collapse the left column of |
| 4758 | fixed grid entries. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4759 | ## |
| 4760 | |
| 4761 | #Member const int* fYDivs |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 4762 | #Line # y-axis values dividing bitmap ## |
| 4763 | Array of y-axis values that divide the bitmap horizontally. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4764 | Array entries must be unique, increasing, greater than or equal to |
| 4765 | fBounds top edge, and less than fBounds bottom edge. |
| 4766 | Set the first element to fBounds top to collapse the top row of fixed |
| 4767 | grid entries. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4768 | ## |
| 4769 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4770 | #Member const RectType* fRectTypes |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4771 | #Line # array of fill types ## |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4772 | Optional array of fill types, one per rectangular grid entry: |
Cary Clark | 2be81cf | 2018-09-13 12:04:30 -0400 | [diff] [blame] | 4773 | array length must be #Formula # (fXCount + 1) * (fYCount + 1) ##. |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 4774 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4775 | Each RectType is one of: kDefault, kTransparent, kFixedColor. |
| 4776 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4777 | Array entries correspond to the rectangular grid entries, ascending |
| 4778 | left to right and then top to bottom. |
| 4779 | ## |
| 4780 | |
| 4781 | #Member int fXCount |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4782 | #Line # number of x-coordinates ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4783 | Number of entries in fXDivs array; one less than the number of |
| 4784 | horizontal divisions. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4785 | ## |
| 4786 | |
| 4787 | #Member int fYCount |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4788 | #Line # number of y-coordinates ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4789 | Number of entries in fYDivs array; one less than the number of vertical |
| 4790 | divisions. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4791 | ## |
| 4792 | |
| 4793 | #Member const SkIRect* fBounds |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4794 | #Line # source bounds to draw from ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4795 | Optional subset IRect source to draw from. |
| 4796 | If nullptr, source bounds is dimensions of Bitmap or Image. |
| 4797 | ## |
| 4798 | |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4799 | #Member const SkColor* fColors |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4800 | #Line # array of colors ## |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4801 | Optional array of colors, one per rectangular grid entry. |
Cary Clark | 2be81cf | 2018-09-13 12:04:30 -0400 | [diff] [blame] | 4802 | Array length must be #Formula # (fXCount + 1) * (fYCount + 1) ##. |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 4803 | |
| 4804 | Array entries correspond to the rectangular grid entries, ascending |
| 4805 | left to right, then top to bottom. |
| 4806 | ## |
| 4807 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4808 | #Struct Lattice ## |
| 4809 | |
| 4810 | #Method void drawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice, const SkRect& dst, |
| 4811 | const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4812 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4813 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4814 | #Line # draws proportionally stretched Bitmap ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4815 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4816 | Draws Bitmap bitmap stretched proportionally to fit into Rect dst. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4817 | |
| 4818 | Lattice lattice divides bitmap into a rectangular grid. |
| 4819 | 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] | 4820 | of drawBitmapNine, fixed lattice elements never scale larger than their initial |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4821 | size and shrink proportionately when all fixed elements exceed the bitmap |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4822 | 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] | 4823 | |
| 4824 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4825 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4826 | #paint_as_used_by_draw_lattice_or_draw_nine(bitmap)# |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4827 | |
| 4828 | If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, |
| 4829 | just as Shader made from SkShader::MakeBitmapShader with |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4830 | SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4831 | outside of its bounds. |
| 4832 | |
| 4833 | #Param bitmap Bitmap containing pixels, dimensions, and format ## |
| 4834 | #Param lattice division of bitmap into fixed and variable rectangles ## |
| 4835 | #Param dst destination Rect of image to draw to ## |
| 4836 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4837 | and so on; or nullptr |
| 4838 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4839 | |
| 4840 | #Example |
| 4841 | #Height 128 |
| 4842 | #Description |
| 4843 | The two leftmost bitmap draws has four corners and sides to the left and right of center. |
| 4844 | The leftmost bitmap draw scales the width of corners proportionately to fit. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4845 | 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] | 4846 | fill the remaining space; the center is transparent. |
| 4847 | The rightmost bitmap draw has four corners scaled vertically to fit, and uses sides above |
| 4848 | and below center to fill the remaining space. |
| 4849 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4850 | void draw(SkCanvas* canvas) { |
| 4851 | SkIRect center = { 20, 10, 50, 40 }; |
| 4852 | SkBitmap bitmap; |
| 4853 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60)); |
| 4854 | SkCanvas bitCanvas(bitmap); |
| 4855 | SkPaint paint; |
| 4856 | SkColor gray = 0xFF000000; |
| 4857 | int left = 0; |
| 4858 | for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) { |
| 4859 | int top = 0; |
| 4860 | for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) { |
| 4861 | paint.setColor(gray); |
| 4862 | bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint); |
| 4863 | gray += 0x001f1f1f; |
| 4864 | top = bottom; |
| 4865 | } |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4866 | left = right; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4867 | } |
| 4868 | const int xDivs[] = { center.fLeft, center.fRight }; |
| 4869 | const int yDivs[] = { center.fTop, center.fBottom }; |
Cary Clark | ca3ebcd | 2017-12-12 11:22:38 -0500 | [diff] [blame] | 4870 | SkCanvas::Lattice::RectType fillTypes[3][3]; |
| 4871 | memset(fillTypes, 0, sizeof(fillTypes)); |
| 4872 | fillTypes[1][1] = SkCanvas::Lattice::kTransparent; |
| 4873 | SkColor dummy[9]; // temporary pending bug fix |
| 4874 | SkCanvas::Lattice lattice = { xDivs, yDivs, fillTypes[0], SK_ARRAY_COUNT(xDivs), |
| 4875 | SK_ARRAY_COUNT(yDivs), nullptr, dummy }; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4876 | for (auto dest: { 20, 30, 40, 60, 90 } ) { |
Cary Clark | ca3ebcd | 2017-12-12 11:22:38 -0500 | [diff] [blame] | 4877 | canvas->drawBitmapLattice(bitmap, lattice, SkRect::MakeWH(dest, 110 - dest), nullptr); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4878 | canvas->translate(dest + 4, 0); |
| 4879 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4880 | } |
| 4881 | ## |
| 4882 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4883 | #SeeAlso drawImageLattice drawBitmap drawBitmapNine Lattice |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4884 | |
| 4885 | ## |
| 4886 | |
| 4887 | # ------------------------------------------------------------------------------ |
| 4888 | |
| 4889 | #Method void drawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst, |
| 4890 | const SkPaint* paint = nullptr) |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4891 | #In Draw_Image |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 4892 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 4893 | #Line # draws proportionally stretched Image ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4894 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 4895 | Draws Image image stretched proportionally to fit into Rect dst. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4896 | |
| 4897 | Lattice lattice divides image into a rectangular grid. |
| 4898 | 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] | 4899 | of drawBitmapNine, fixed lattice elements never scale larger than their initial |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4900 | size and shrink proportionately when all fixed elements exceed the bitmap |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4901 | 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] | 4902 | |
| 4903 | Additionally transform draw using Clip, Matrix, and optional Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4904 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4905 | #paint_as_used_by_draw_lattice_or_draw_nine(image)# |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4906 | |
| 4907 | If generated mask extends beyond bitmap bounds, replicate bitmap edge colors, |
| 4908 | just as Shader made from SkShader::MakeBitmapShader with |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 4909 | SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4910 | outside of its bounds. |
| 4911 | |
| 4912 | #Param image Image containing pixels, dimensions, and format ## |
| 4913 | #Param lattice division of bitmap into fixed and variable rectangles ## |
| 4914 | #Param dst destination Rect of image to draw to ## |
| 4915 | #Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter, |
| 4916 | and so on; or nullptr |
| 4917 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4918 | |
| 4919 | #Example |
| 4920 | #Height 128 |
| 4921 | #Description |
| 4922 | 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] | 4923 | The second image equals the size of center; only corners are drawn without scaling. |
| 4924 | 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] | 4925 | are scaled if needed to take up the remaining space; the center is transparent. |
| 4926 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4927 | void draw(SkCanvas* canvas) { |
| 4928 | SkIRect center = { 20, 10, 50, 40 }; |
| 4929 | SkBitmap bitmap; |
| 4930 | bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60)); |
| 4931 | SkCanvas bitCanvas(bitmap); |
| 4932 | SkPaint paint; |
| 4933 | SkColor gray = 0xFF000000; |
| 4934 | int left = 0; |
| 4935 | for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) { |
| 4936 | int top = 0; |
| 4937 | for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) { |
| 4938 | paint.setColor(gray); |
| 4939 | bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint); |
| 4940 | gray += 0x001f1f1f; |
| 4941 | top = bottom; |
| 4942 | } |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 4943 | left = right; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4944 | } |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 4945 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 4946 | SkImage* imagePtr = image.get(); |
| 4947 | for (auto dest: { 20, 30, 40, 60, 90 } ) { |
| 4948 | canvas->drawImageNine(imagePtr, center, SkRect::MakeWH(dest, dest), nullptr); |
| 4949 | canvas->translate(dest + 4, 0); |
| 4950 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4951 | } |
| 4952 | ## |
| 4953 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 4954 | #SeeAlso drawBitmapLattice drawImage drawImageNine Lattice |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 4955 | |
| 4956 | ## |
| 4957 | |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 4958 | #Subtopic Lattice ## |
| 4959 | |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 4960 | # ------------------------------------------------------------------------------ |
| 4961 | |
| 4962 | #Enum QuadAAFlags |
| 4963 | #Line # don't use this ## |
Brian Salomon | 5d87892 | 2018-10-12 16:33:11 -0400 | [diff] [blame] | 4964 | #Code |
| 4965 | #Populate |
| 4966 | ## |
| 4967 | |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 4968 | #Private |
Cary Clark | b0ba2ac | 2018-10-15 11:38:31 -0400 | [diff] [blame] | 4969 | Do not use. |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 4970 | ## |
Brian Salomon | 5d87892 | 2018-10-12 16:33:11 -0400 | [diff] [blame] | 4971 | |
| 4972 | #Const kLeft_QuadAAFlag 1 |
| 4973 | #Line # antialias the left edge ## |
| 4974 | ## |
| 4975 | |
| 4976 | #Const kTop_QuadAAFlag 2 |
| 4977 | #Line # antialias the top edge ## |
| 4978 | ## |
| 4979 | |
| 4980 | #Const kRight_QuadAAFlag 4 |
| 4981 | #Line # antialias the right edge ## |
| 4982 | ## |
| 4983 | |
| 4984 | #Const kBottom_QuadAAFlag 8 |
| 4985 | #Line # antialias the bottom edge ## |
| 4986 | ## |
| 4987 | |
| 4988 | #Const kNone_QuadAAFlags 0 |
| 4989 | #Line # antialias none of the edges ## |
| 4990 | ## |
| 4991 | |
| 4992 | #Const kAll_QuadAAFlags 15 |
| 4993 | #Line # antialias all of the edges ## |
| 4994 | ## |
| 4995 | |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 4996 | #NoExample |
| 4997 | ## |
| 4998 | ## |
| 4999 | |
| 5000 | # ------------------------------------------------------------------------------ |
| 5001 | |
| 5002 | #Struct ImageSetEntry |
| 5003 | #Line # don't use this ## |
Cary Clark | b0ba2ac | 2018-10-15 11:38:31 -0400 | [diff] [blame] | 5004 | |
| 5005 | #Code |
| 5006 | #Populate |
| 5007 | ## |
| 5008 | |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 5009 | #Private |
Cary Clark | b0ba2ac | 2018-10-15 11:38:31 -0400 | [diff] [blame] | 5010 | Do not use. |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 5011 | ## |
| 5012 | |
| 5013 | #Member SkImage* fImage |
| 5014 | #Line # image to draw ## |
| 5015 | ## |
| 5016 | |
| 5017 | #Member SkRect fSrcRect |
| 5018 | #Line # image src rectangle ## |
| 5019 | ## |
| 5020 | |
| 5021 | #Member SkRect fDstRect |
| 5022 | #Line # local space rectangle ## |
| 5023 | ## |
| 5024 | |
| 5025 | #Member unsigned fAAFlags |
| 5026 | #Line # antialiasing flags ## |
| 5027 | ## |
| 5028 | |
| 5029 | #NoExample |
| 5030 | ## |
| 5031 | |
| 5032 | ## |
| 5033 | |
| 5034 | # ------------------------------------------------------------------------------ |
| 5035 | |
| 5036 | #Method void experimental_DrawImageSetV0(const ImageSetEntry imageSet[], int cnt, float alpha, |
| 5037 | SkFilterQuality quality, SkBlendMode mode); |
| 5038 | #Private |
Cary Clark | b0ba2ac | 2018-10-15 11:38:31 -0400 | [diff] [blame] | 5039 | Do not use. |
Brian Salomon | d7065e7 | 2018-10-12 11:42:02 -0400 | [diff] [blame] | 5040 | ## |
| 5041 | #In Draw_Image |
| 5042 | #In Draw |
| 5043 | #Line # draws a set a of images (don't call this) ## |
| 5044 | |
| 5045 | Draws a set of images. Do not use this method. |
| 5046 | |
| 5047 | #Param imageSet images ## |
| 5048 | #Param cnt number of images ## |
| 5049 | #Param alpha alpha ## |
| 5050 | #Param quality filter quality ## |
| 5051 | #Param mode blend mode ## |
| 5052 | |
| 5053 | #NoExample |
| 5054 | ## |
| 5055 | |
| 5056 | ## |
| 5057 | |
Cary Clark | 08895c4 | 2018-02-01 09:37:32 -0500 | [diff] [blame] | 5058 | #Subtopic Draw_Image ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5059 | |
| 5060 | # ------------------------------------------------------------------------------ |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5061 | #Subtopic Draw_Text |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5062 | #Line # draws text into Canvas ## |
| 5063 | ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5064 | |
| 5065 | #Method void drawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, |
| 5066 | const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5067 | #In Draw_Text |
| 5068 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5069 | #Line # draws text at (x, y), using font advance ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5070 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5071 | Draws text, with origin at (x, y), using Clip, Matrix, and Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5072 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5073 | 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] | 5074 | UTF-8. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5075 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5076 | 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] | 5077 | text draws left to right, positioning the first glyph left side bearing at x |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5078 | 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] | 5079 | |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 5080 | All elements of paint: Path_Effect, Mask_Filter, Shader, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5081 | 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] | 5082 | filled 12 point black Glyphs. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5083 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5084 | #Param text character code points or Glyphs drawn ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5085 | #Param byteLength byte length of text array ## |
| 5086 | #Param x start of text on x-axis ## |
| 5087 | #Param y start of text on y-axis ## |
| 5088 | #Param paint text size, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5089 | |
| 5090 | #Example |
| 5091 | #Height 200 |
| 5092 | #Description |
| 5093 | The same text is drawn varying Paint_Text_Size and varying |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5094 | Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5095 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5096 | void draw(SkCanvas* canvas) { |
| 5097 | SkPaint paint; |
| 5098 | paint.setAntiAlias(true); |
| 5099 | float textSizes[] = { 12, 18, 24, 36 }; |
| 5100 | for (auto size: textSizes ) { |
| 5101 | paint.setTextSize(size); |
| 5102 | canvas->drawText("Aa", 2, 10, 20, paint); |
| 5103 | canvas->translate(0, size * 2); |
| 5104 | } |
| 5105 | paint.reset(); |
| 5106 | paint.setAntiAlias(true); |
| 5107 | float yPos = 20; |
| 5108 | for (auto size: textSizes ) { |
| 5109 | float scale = size / 12.f; |
| 5110 | canvas->resetMatrix(); |
| 5111 | canvas->translate(100, 0); |
| 5112 | canvas->scale(scale, scale); |
| 5113 | canvas->drawText("Aa", 2, 10 / scale, yPos / scale, paint); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5114 | yPos += size * 2; |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5115 | } |
| 5116 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5117 | ## |
| 5118 | |
Cary Clark | 153e76d | 2018-08-28 11:48:28 -0400 | [diff] [blame] | 5119 | #SeeAlso drawString drawPosText drawPosTextH drawTextBlob drawTextRSXform |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5120 | |
| 5121 | ## |
| 5122 | |
| 5123 | #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] | 5124 | #In Draw_Text |
| 5125 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5126 | #Line # draws null terminated string at (x, y) using font advance ## |
Cary Clark | 682c58d | 2018-05-16 07:07:07 -0400 | [diff] [blame] | 5127 | Draws null terminated string, with origin at (x, y), using Clip, Matrix, and |
| 5128 | Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5129 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5130 | string meaning depends on Paint_Text_Encoding; by default, strings are encoded |
| 5131 | 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] | 5132 | results, since zero bytes may be embedded in the string. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5133 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5134 | 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] | 5135 | string draws left to right, positioning the first glyph left side bearing at x |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5136 | 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] | 5137 | |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 5138 | All elements of paint: Path_Effect, Mask_Filter, Shader, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5139 | 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] | 5140 | filled 12 point black Glyphs. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5141 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5142 | #Param string character code points or Glyphs drawn, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5143 | ending with a char value of zero |
| 5144 | ## |
| 5145 | #Param x start of string on x-axis ## |
| 5146 | #Param y start of string on y-axis ## |
| 5147 | #Param paint text size, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5148 | |
| 5149 | #Example |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 5150 | #Height 48 |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5151 | SkPaint paint; |
| 5152 | canvas->drawString("a small hello", 20, 20, paint); |
| 5153 | ## |
| 5154 | |
Cary Clark | 153e76d | 2018-08-28 11:48:28 -0400 | [diff] [blame] | 5155 | #SeeAlso drawText drawPosText drawPosTextH drawTextBlob drawTextRSXform |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5156 | |
| 5157 | ## |
| 5158 | |
| 5159 | #Method void drawString(const SkString& string, SkScalar x, SkScalar y, const SkPaint& paint) |
| 5160 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5161 | Draws null terminated string, with origin at (x, y), using Clip, Matrix, and |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5162 | Paint paint. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5163 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5164 | string meaning depends on Paint_Text_Encoding; by default, strings are encoded |
| 5165 | 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] | 5166 | results, since zero bytes may be embedded in the string. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5167 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5168 | 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] | 5169 | string draws left to right, positioning the first glyph left side bearing at x |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5170 | 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] | 5171 | |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 5172 | All elements of paint: Path_Effect, Mask_Filter, Shader, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5173 | 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] | 5174 | filled 12 point black Glyphs. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5175 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5176 | #Param string character code points or Glyphs drawn, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5177 | ending with a char value of zero |
| 5178 | ## |
| 5179 | #Param x start of string on x-axis ## |
| 5180 | #Param y start of string on y-axis ## |
| 5181 | #Param paint text size, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5182 | |
| 5183 | #Example |
| 5184 | SkPaint paint; |
| 5185 | SkString string("a small hello"); |
| 5186 | canvas->drawString(string, 20, 20, paint); |
| 5187 | ## |
| 5188 | |
Cary Clark | 153e76d | 2018-08-28 11:48:28 -0400 | [diff] [blame] | 5189 | #SeeAlso drawText drawPosText drawPosTextH drawTextBlob drawTextRSXform |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5190 | |
| 5191 | ## |
| 5192 | |
| 5193 | # ------------------------------------------------------------------------------ |
| 5194 | |
| 5195 | #Method void drawPosText(const void* text, size_t byteLength, const SkPoint pos[], |
| 5196 | const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5197 | #In Draw_Text |
| 5198 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5199 | #Line # draws text at array of (x, y) positions ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5200 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5201 | Draws each glyph in text with the origin in pos array, using Clip, Matrix, and |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5202 | 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] | 5203 | described by byteLength of text. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5204 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5205 | text meaning depends on Paint_Text_Encoding; by default, text is encoded as |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 5206 | UTF-8. pos elements meaning depends on Paint_Vertical_Text; by default |
| 5207 | glyph left side bearing and baseline are relative to Point in pos array. |
| 5208 | Text size is affected by Matrix and Paint_Text_Size. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5209 | |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 5210 | All elements of paint: Path_Effect, Mask_Filter, Shader, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5211 | 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] | 5212 | filled 12 point black Glyphs. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5213 | |
| 5214 | Layout engines such as Harfbuzz typically position each glyph |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5215 | rather than using the font advance widths. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5216 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5217 | #Param text character code points or Glyphs drawn ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5218 | #Param byteLength byte length of text array ## |
| 5219 | #Param pos array of glyph origins ## |
| 5220 | #Param paint text size, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5221 | |
| 5222 | #Example |
| 5223 | #Height 120 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5224 | void draw(SkCanvas* canvas) { |
| 5225 | const char hello[] = "HeLLo!"; |
| 5226 | const SkPoint pos[] = { {40, 100}, {82, 95}, {115, 110}, {130, 95}, {145, 85}, |
| 5227 | {172, 100} }; |
| 5228 | SkPaint paint; |
| 5229 | paint.setTextSize(60); |
| 5230 | canvas->drawPosText(hello, strlen(hello), pos, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5231 | } |
| 5232 | ## |
| 5233 | |
Cary Clark | 153e76d | 2018-08-28 11:48:28 -0400 | [diff] [blame] | 5234 | #SeeAlso drawText drawPosTextH drawTextBlob drawTextRSXform |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5235 | |
| 5236 | ## |
| 5237 | |
| 5238 | # ------------------------------------------------------------------------------ |
| 5239 | |
| 5240 | #Method void drawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], SkScalar constY, |
| 5241 | const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5242 | #In Draw_Text |
| 5243 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5244 | #Line # draws text at x positions with common baseline ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5245 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5246 | Draws each glyph in text with its (x, y) origin composed from xpos array and |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5247 | 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] | 5248 | must match the number of Glyphs described by byteLength of text. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5249 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5250 | text meaning depends on Paint_Text_Encoding; by default, text is encoded as |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 5251 | UTF-8. xpos elements meaning depends on Paint_Vertical_Text; |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5252 | 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] | 5253 | its baseline is positioned at constY. Text size is affected by Matrix and |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5254 | Paint_Text_Size. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5255 | |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 5256 | All elements of paint: Path_Effect, Mask_Filter, Shader, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5257 | 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] | 5258 | filled 12 point black Glyphs. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5259 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5260 | Layout engines such as Harfbuzz typically position each glyph |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5261 | 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] | 5262 | baseline. |
| 5263 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5264 | #Param text character code points or Glyphs drawn ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5265 | #Param byteLength byte length of text array ## |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 5266 | #Param xpos array of x-axis positions, used to position each glyph ## |
| 5267 | #Param constY shared y-axis value for all of x-axis positions ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5268 | #Param paint text size, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5269 | |
| 5270 | #Example |
| 5271 | #Height 40 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5272 | void draw(SkCanvas* canvas) { |
| 5273 | SkScalar xpos[] = { 20, 40, 80, 160 }; |
| 5274 | SkPaint paint; |
| 5275 | canvas->drawPosTextH("XXXX", 4, xpos, 20, paint); |
| 5276 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5277 | ## |
| 5278 | |
Cary Clark | 153e76d | 2018-08-28 11:48:28 -0400 | [diff] [blame] | 5279 | #SeeAlso drawText drawPosText drawTextBlob drawTextRSXform |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5280 | |
| 5281 | ## |
| 5282 | |
| 5283 | # ------------------------------------------------------------------------------ |
| 5284 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5285 | #Method void drawTextRSXform(const void* text, size_t byteLength, const SkRSXform xform[], |
| 5286 | const SkRect* cullRect, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5287 | #In Draw_Text |
| 5288 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5289 | #Line # draws text with array of RSXform ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5290 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5291 | Draws text, transforming each glyph by the corresponding SkRSXform, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5292 | using Clip, Matrix, and Paint paint. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5293 | |
Cary Clark | 137b874 | 2018-05-30 09:21:49 -0400 | [diff] [blame] | 5294 | RSXform xform array specifies a separate square scale, rotation, and translation |
| 5295 | for each glyph. xform does not affect paint Shader. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5296 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5297 | Optional Rect cullRect is a conservative bounds of text, taking into account |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5298 | 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] | 5299 | |
Mike Reed | 8ad91a9 | 2018-01-19 19:09:32 -0500 | [diff] [blame] | 5300 | All elements of paint: Path_Effect, Mask_Filter, Shader, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5301 | Color_Filter, Image_Filter, and Draw_Looper; apply to text. By default, draws |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5302 | filled 12 point black Glyphs. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5303 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5304 | #Param text character code points or Glyphs drawn ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5305 | #Param byteLength byte length of text array ## |
| 5306 | #Param xform RSXform rotates, scales, and translates each glyph individually ## |
| 5307 | #Param cullRect Rect bounds of text for efficient clipping; or nullptr ## |
| 5308 | #Param paint text size, blend, color, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5309 | |
| 5310 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5311 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5312 | const int iterations = 26; |
| 5313 | SkRSXform transforms[iterations]; |
| 5314 | char alphabet[iterations]; |
| 5315 | SkScalar angle = 0; |
| 5316 | SkScalar scale = 1; |
| 5317 | for (size_t i = 0; i < SK_ARRAY_COUNT(transforms); ++i) { |
| 5318 | const SkScalar s = SkScalarSin(angle) * scale; |
| 5319 | const SkScalar c = SkScalarCos(angle) * scale; |
| 5320 | transforms[i] = SkRSXform::Make(-c, -s, -s * 16, c * 16); |
| 5321 | angle += .45; |
| 5322 | scale += .2; |
| 5323 | alphabet[i] = 'A' + i; |
| 5324 | } |
| 5325 | SkPaint paint; |
| 5326 | paint.setTextAlign(SkPaint::kCenter_Align); |
| 5327 | canvas->translate(110, 138); |
| 5328 | canvas->drawTextRSXform(alphabet, sizeof(alphabet), transforms, nullptr, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5329 | } |
| 5330 | ## |
| 5331 | |
Cary Clark | 153e76d | 2018-08-28 11:48:28 -0400 | [diff] [blame] | 5332 | #SeeAlso drawText drawPosText drawTextBlob |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5333 | |
| 5334 | ## |
| 5335 | |
| 5336 | # ------------------------------------------------------------------------------ |
| 5337 | |
| 5338 | #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] | 5339 | #In Draw_Text |
| 5340 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5341 | #Line # draws text with arrays of positions and Paint ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5342 | Draws Text_Blob blob at (x, y), using Clip, Matrix, and Paint paint. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5343 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5344 | blob contains Glyphs, their positions, and paint attributes specific to text: |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 5345 | #paint_font_metrics#. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5346 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 5347 | Paint_Text_Encoding must be set to SkPaint::kGlyphID_TextEncoding. |
| 5348 | |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 5349 | Elements of paint: Anti_Alias, Blend_Mode, Color including Color_Alpha, |
| 5350 | Color_Filter, Paint_Dither, Draw_Looper, Mask_Filter, Path_Effect, Shader, and |
Cary Clark | 61313f3 | 2018-10-08 14:57:48 -0400 | [diff] [blame] | 5351 | Paint_Style; apply to blob. If Paint contains SkPaint::kStroke_Style: |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 5352 | Paint_Miter_Limit, Paint_Stroke_Cap, Paint_Stroke_Join, and Paint_Stroke_Width; |
| 5353 | apply to Path created from blob. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5354 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5355 | #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] | 5356 | #Param x horizontal offset applied to blob ## |
| 5357 | #Param y vertical offset applied to blob ## |
| 5358 | #Param paint blend, color, stroking, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5359 | |
| 5360 | #Example |
| 5361 | #Height 120 |
Cary Clark | e80cd44 | 2018-07-17 13:19:56 -0400 | [diff] [blame] | 5362 | void draw(SkCanvas* canvas) { |
| 5363 | SkTextBlobBuilder textBlobBuilder; |
| 5364 | const char bunny[] = "/(^x^)\\"; |
| 5365 | const int len = sizeof(bunny) - 1; |
| 5366 | uint16_t glyphs[len]; |
| 5367 | SkPaint paint; |
| 5368 | paint.textToGlyphs(bunny, len, glyphs); |
| 5369 | paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 5370 | int runs[] = { 3, 1, 3 }; |
| 5371 | SkPoint textPos = { 20, 100 }; |
| 5372 | int glyphIndex = 0; |
| 5373 | for (auto runLen : runs) { |
| 5374 | paint.setTextSize(1 == runLen ? 20 : 50); |
| 5375 | const SkTextBlobBuilder::RunBuffer& run = |
| 5376 | textBlobBuilder.allocRun(paint, runLen, textPos.fX, textPos.fY); |
| 5377 | memcpy(run.glyphs, &glyphs[glyphIndex], sizeof(glyphs[0]) * runLen); |
| 5378 | textPos.fX += paint.measureText(&glyphs[glyphIndex], sizeof(glyphs[0]) * runLen, nullptr); |
| 5379 | glyphIndex += runLen; |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5380 | } |
Cary Clark | e80cd44 | 2018-07-17 13:19:56 -0400 | [diff] [blame] | 5381 | sk_sp<const SkTextBlob> blob = textBlobBuilder.make(); |
| 5382 | paint.reset(); |
| 5383 | canvas->drawTextBlob(blob.get(), 0, 0, paint); |
| 5384 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5385 | ## |
| 5386 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5387 | #SeeAlso drawText drawPosText drawPosTextH |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5388 | |
| 5389 | ## |
| 5390 | |
| 5391 | # ------------------------------------------------------------------------------ |
| 5392 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5393 | #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] | 5394 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5395 | Draws Text_Blob blob at (x, y), using Clip, Matrix, and Paint paint. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5396 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5397 | blob contains Glyphs, their positions, and paint attributes specific to text: |
Cary Clark | d2ca79c | 2018-08-10 13:09:13 -0400 | [diff] [blame] | 5398 | #paint_font_metrics#. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5399 | |
Cary Clark | 3cd22cc | 2017-12-01 11:49:58 -0500 | [diff] [blame] | 5400 | Paint_Text_Encoding must be set to SkPaint::kGlyphID_TextEncoding. |
| 5401 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5402 | Elements of paint: Path_Effect, Mask_Filter, Shader, Color_Filter, |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5403 | Image_Filter, and Draw_Looper; apply to blob. |
| 5404 | |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5405 | #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] | 5406 | #Param x horizontal offset applied to blob ## |
| 5407 | #Param y vertical offset applied to blob ## |
| 5408 | #Param paint blend, color, stroking, and so on, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5409 | |
| 5410 | #Example |
| 5411 | #Height 120 |
| 5412 | #Description |
| 5413 | Paint attributes unrelated to text, like color, have no effect on paint in allocated Text_Blob. |
| 5414 | Paint attributes related to text, like text size, have no effect on paint passed to drawTextBlob. |
| 5415 | ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5416 | void draw(SkCanvas* canvas) { |
| 5417 | SkTextBlobBuilder textBlobBuilder; |
| 5418 | SkPaint paint; |
| 5419 | paint.setTextSize(50); |
| 5420 | paint.setColor(SK_ColorRED); |
Cary Clark | 2f46624 | 2017-12-11 16:03:17 -0500 | [diff] [blame] | 5421 | paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5422 | const SkTextBlobBuilder::RunBuffer& run = |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5423 | textBlobBuilder.allocRun(paint, 1, 20, 100); |
| 5424 | run.glyphs[0] = 20; |
| 5425 | sk_sp<const SkTextBlob> blob = textBlobBuilder.make(); |
| 5426 | paint.setTextSize(10); |
| 5427 | paint.setColor(SK_ColorBLUE); |
| 5428 | canvas->drawTextBlob(blob.get(), 0, 0, paint); |
| 5429 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5430 | ## |
| 5431 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5432 | #SeeAlso drawText drawPosText drawPosTextH |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5433 | |
| 5434 | ## |
| 5435 | |
| 5436 | # ------------------------------------------------------------------------------ |
| 5437 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5438 | #Method void drawPicture(const SkPicture* picture) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5439 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5440 | #Line # draws Picture using Clip and Matrix ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5441 | Draws Picture picture, using Clip and Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5442 | Clip and Matrix are unchanged by picture contents, as if |
| 5443 | save() was called before and restore() was called after drawPicture. |
| 5444 | |
| 5445 | Picture records a series of draw commands for later playback. |
| 5446 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5447 | #Param picture recorded drawing commands to play ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5448 | |
| 5449 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5450 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5451 | SkPictureRecorder recorder; |
| 5452 | SkCanvas* recordingCanvas = recorder.beginRecording(50, 50); |
| 5453 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) { |
| 5454 | SkPaint paint; |
| 5455 | paint.setColor(color); |
| 5456 | recordingCanvas->drawRect({10, 10, 30, 40}, paint); |
| 5457 | recordingCanvas->translate(10, 10); |
| 5458 | recordingCanvas->scale(1.2f, 1.4f); |
| 5459 | } |
| 5460 | sk_sp<SkPicture> playback = recorder.finishRecordingAsPicture(); |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5461 | canvas->drawPicture(playback); |
| 5462 | canvas->scale(2, 2); |
| 5463 | canvas->translate(50, 0); |
| 5464 | canvas->drawPicture(playback); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5465 | } |
| 5466 | ## |
| 5467 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5468 | #SeeAlso drawDrawable SkPicture SkPicture::playback |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5469 | |
| 5470 | ## |
| 5471 | |
| 5472 | # ------------------------------------------------------------------------------ |
| 5473 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5474 | #Method void drawPicture(const sk_sp<SkPicture>& picture) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5475 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5476 | Draws Picture picture, using Clip and Matrix. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5477 | Clip and Matrix are unchanged by picture contents, as if |
| 5478 | save() was called before and restore() was called after drawPicture. |
| 5479 | |
| 5480 | Picture records a series of draw commands for later playback. |
| 5481 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5482 | #Param picture recorded drawing commands to play ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5483 | |
| 5484 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5485 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5486 | SkPictureRecorder recorder; |
| 5487 | SkCanvas* recordingCanvas = recorder.beginRecording(50, 50); |
| 5488 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) { |
| 5489 | SkPaint paint; |
| 5490 | paint.setColor(color); |
| 5491 | recordingCanvas->drawRect({10, 10, 30, 40}, paint); |
| 5492 | recordingCanvas->translate(10, 10); |
| 5493 | recordingCanvas->scale(1.2f, 1.4f); |
| 5494 | } |
| 5495 | sk_sp<SkPicture> playback = recorder.finishRecordingAsPicture(); |
| 5496 | canvas->drawPicture(playback); |
| 5497 | canvas->scale(2, 2); |
| 5498 | canvas->translate(50, 0); |
| 5499 | canvas->drawPicture(playback); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5500 | } |
| 5501 | ## |
| 5502 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5503 | #SeeAlso drawDrawable SkPicture SkPicture::playback |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5504 | |
| 5505 | ## |
| 5506 | |
| 5507 | # ------------------------------------------------------------------------------ |
| 5508 | |
| 5509 | #Method void drawPicture(const SkPicture* picture, const SkMatrix* matrix, const SkPaint* paint) |
| 5510 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5511 | Draws Picture picture, using Clip and Matrix; transforming picture with |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5512 | Matrix matrix, if provided; and use Paint paint Color_Alpha, Color_Filter, |
| 5513 | Image_Filter, and Blend_Mode, if provided. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5514 | |
| 5515 | matrix transformation is equivalent to: save(), concat(), drawPicture, restore(). |
| 5516 | paint use is equivalent to: saveLayer, drawPicture, restore(). |
| 5517 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5518 | #Param picture recorded drawing commands to play ## |
| 5519 | #Param matrix Matrix to rotate, scale, translate, and so on; may be nullptr ## |
| 5520 | #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] | 5521 | |
| 5522 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5523 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5524 | SkPaint paint; |
| 5525 | SkPictureRecorder recorder; |
| 5526 | SkCanvas* recordingCanvas = recorder.beginRecording(50, 50); |
| 5527 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) { |
| 5528 | paint.setColor(color); |
| 5529 | recordingCanvas->drawRect({10, 10, 30, 40}, paint); |
| 5530 | recordingCanvas->translate(10, 10); |
| 5531 | recordingCanvas->scale(1.2f, 1.4f); |
| 5532 | } |
| 5533 | sk_sp<SkPicture> playback = recorder.finishRecordingAsPicture(); |
| 5534 | const SkPicture* playbackPtr = playback.get(); |
| 5535 | SkMatrix matrix; |
| 5536 | matrix.reset(); |
| 5537 | for (auto alpha : { 70, 140, 210 } ) { |
| 5538 | paint.setAlpha(alpha); |
| 5539 | canvas->drawPicture(playbackPtr, &matrix, &paint); |
| 5540 | matrix.preTranslate(70, 70); |
| 5541 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5542 | } |
| 5543 | ## |
| 5544 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5545 | #SeeAlso drawDrawable SkPicture SkPicture::playback |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5546 | |
| 5547 | ## |
| 5548 | |
| 5549 | # ------------------------------------------------------------------------------ |
| 5550 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5551 | #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] | 5552 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5553 | Draws Picture picture, using Clip and Matrix; transforming picture with |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5554 | Matrix matrix, if provided; and use Paint paint Color_Alpha, Color_Filter, |
| 5555 | Image_Filter, and Blend_Mode, if provided. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5556 | |
| 5557 | matrix transformation is equivalent to: save(), concat(), drawPicture, restore(). |
| 5558 | paint use is equivalent to: saveLayer, drawPicture, restore(). |
| 5559 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5560 | #Param picture recorded drawing commands to play ## |
| 5561 | #Param matrix Matrix to rotate, scale, translate, and so on; may be nullptr ## |
| 5562 | #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] | 5563 | |
| 5564 | #Example |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5565 | void draw(SkCanvas* canvas) { |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5566 | SkPaint paint; |
| 5567 | SkPictureRecorder recorder; |
| 5568 | SkCanvas* recordingCanvas = recorder.beginRecording(50, 50); |
| 5569 | for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) { |
| 5570 | paint.setColor(color); |
| 5571 | recordingCanvas->drawRect({10, 10, 30, 40}, paint); |
| 5572 | recordingCanvas->translate(10, 10); |
| 5573 | recordingCanvas->scale(1.2f, 1.4f); |
| 5574 | } |
| 5575 | sk_sp<SkPicture> playback = recorder.finishRecordingAsPicture(); |
| 5576 | SkMatrix matrix; |
| 5577 | matrix.reset(); |
| 5578 | for (auto alpha : { 70, 140, 210 } ) { |
| 5579 | paint.setAlpha(alpha); |
| 5580 | canvas->drawPicture(playback, &matrix, &paint); |
| 5581 | matrix.preTranslate(70, 70); |
| 5582 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5583 | } |
| 5584 | ## |
| 5585 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5586 | #SeeAlso drawDrawable SkPicture SkPicture::playback |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5587 | |
| 5588 | ## |
| 5589 | |
| 5590 | # ------------------------------------------------------------------------------ |
| 5591 | |
| 5592 | #Method void drawVertices(const SkVertices* vertices, SkBlendMode mode, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5593 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5594 | #Line # draws Vertices, a triangle mesh ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5595 | Draws Vertices vertices, a triangle mesh, using Clip and Matrix. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5596 | If Vertices_Texs and Vertices_Colors are defined in vertices, and Paint paint |
| 5597 | contains Shader, Blend_Mode mode combines Vertices_Colors with Shader. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5598 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5599 | #Param vertices triangle mesh to draw ## |
| 5600 | #Param mode combines Vertices_Colors with Shader, if both are present ## |
| 5601 | #Param paint specifies the Shader, used as Vertices texture; may be nullptr ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5602 | |
| 5603 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5604 | void draw(SkCanvas* canvas) { |
| 5605 | SkPaint paint; |
| 5606 | SkPoint points[] = { { 0, 0 }, { 250, 0 }, { 100, 100 }, { 0, 250 } }; |
| 5607 | SkColor colors[] = { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorCYAN }; |
| 5608 | auto vertices = SkVertices::MakeCopy(SkVertices::kTriangleFan_VertexMode, |
| 5609 | SK_ARRAY_COUNT(points), points, nullptr, colors); |
| 5610 | canvas->drawVertices(vertices.get(), SkBlendMode::kSrc, paint); |
| 5611 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5612 | ## |
| 5613 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5614 | #SeeAlso drawPatch drawPicture |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5615 | |
| 5616 | ## |
| 5617 | |
| 5618 | # ------------------------------------------------------------------------------ |
| 5619 | |
| 5620 | #Method void drawVertices(const sk_sp<SkVertices>& vertices, SkBlendMode mode, const SkPaint& paint) |
| 5621 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5622 | Draws Vertices vertices, a triangle mesh, using Clip and Matrix. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5623 | If Vertices_Texs and Vertices_Colors are defined in vertices, and Paint paint |
| 5624 | contains Shader, Blend_Mode mode combines Vertices_Colors with Shader. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5625 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5626 | #Param vertices triangle mesh to draw ## |
| 5627 | #Param mode combines Vertices_Colors with Shader, if both are present ## |
| 5628 | #Param paint specifies the Shader, used as Vertices texture, may be nullptr ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5629 | |
| 5630 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5631 | void draw(SkCanvas* canvas) { |
| 5632 | SkPaint paint; |
| 5633 | SkPoint points[] = { { 0, 0 }, { 250, 0 }, { 100, 100 }, { 0, 250 } }; |
| 5634 | SkPoint texs[] = { { 0, 0 }, { 0, 250 }, { 250, 250 }, { 250, 0 } }; |
| 5635 | SkColor colors[] = { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorCYAN }; |
| 5636 | paint.setShader(SkGradientShader::MakeLinear(points, colors, nullptr, 4, |
| 5637 | SkShader::kClamp_TileMode)); |
| 5638 | auto vertices = SkVertices::MakeCopy(SkVertices::kTriangleFan_VertexMode, |
| 5639 | SK_ARRAY_COUNT(points), points, texs, colors); |
Ruiqi Mao | 94d57c4 | 2018-07-02 15:20:10 -0400 | [diff] [blame] | 5640 | canvas->drawVertices(vertices, SkBlendMode::kDarken, paint); |
| 5641 | } |
| 5642 | ## |
| 5643 | |
| 5644 | #SeeAlso drawPatch drawPicture |
| 5645 | |
| 5646 | ## |
| 5647 | |
| 5648 | # ------------------------------------------------------------------------------ |
| 5649 | |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 5650 | #Method void drawVertices(const SkVertices* vertices, const SkVertices::Bone bones[], |
| 5651 | int boneCount, SkBlendMode mode, const SkPaint& paint) |
Ruiqi Mao | 94d57c4 | 2018-07-02 15:20:10 -0400 | [diff] [blame] | 5652 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5653 | Draws Vertices vertices, a triangle mesh, using Clip and Matrix. Bone data is used to |
Ruiqi Mao | 94d57c4 | 2018-07-02 15:20:10 -0400 | [diff] [blame] | 5654 | deform vertices with bone weights. |
| 5655 | If Vertices_Texs and Vertices_Colors are defined in vertices, and Paint paint |
| 5656 | contains Shader, Blend_Mode mode combines Vertices_Colors with Shader. |
| 5657 | The first element of bones should be an object to world space transformation matrix that |
| 5658 | will be applied before performing mesh deformations. If no such transformation is needed, |
| 5659 | it should be the identity matrix. |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 5660 | boneCount must be at most 80, and thus the size of bones should be at most 80. |
Ruiqi Mao | 94d57c4 | 2018-07-02 15:20:10 -0400 | [diff] [blame] | 5661 | |
| 5662 | #Param vertices triangle mesh to draw ## |
| 5663 | #Param bones bone matrix data ## |
| 5664 | #Param boneCount number of bone matrices ## |
| 5665 | #Param mode combines Vertices_Colors with Shader, if both are present ## |
| 5666 | #Param paint specifies the Shader, used as Vertices texture, may be nullptr ## |
| 5667 | |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 5668 | #NoExample |
Ruiqi Mao | 94d57c4 | 2018-07-02 15:20:10 -0400 | [diff] [blame] | 5669 | void draw(SkCanvas* canvas) { |
| 5670 | SkPaint paint; |
| 5671 | SkPoint points[] = { { 0, 0 }, { 250, 0 }, { 100, 100 }, { 0, 250 } }; |
| 5672 | SkPoint texs[] = { { 0, 0 }, { 0, 250 }, { 250, 250 }, { 250, 0 } }; |
| 5673 | SkColor colors[] = { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorCYAN }; |
| 5674 | SkVertices::BoneIndices boneIndices[] = { { 0, 0, 0, 0 }, |
| 5675 | { 1, 0, 0, 0 }, |
| 5676 | { 2, 0, 0, 0 }, |
| 5677 | { 3, 0, 0, 0 } }; |
| 5678 | SkVertices::BoneWeights boneWeights[] = { { 0.0f, 0.0f, 0.0f, 0.0f }, |
| 5679 | { 1.0f, 0.0f, 0.0f, 0.0f }, |
| 5680 | { 1.0f, 0.0f, 0.0f, 0.0f }, |
| 5681 | { 1.0f, 0.0f, 0.0f, 0.0f } }; |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 5682 | SkVertices::Bone bones[] = { {{ 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f }}, |
| 5683 | {{ 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 20.0f }}, |
| 5684 | {{ 1.0f, 0.0f, 0.0f, 1.0f, 50.0f, 50.0f }}, |
| 5685 | {{ 1.0f, 0.0f, 0.0f, 1.0f, 20.0f, 0.0f }} }; |
Ruiqi Mao | 94d57c4 | 2018-07-02 15:20:10 -0400 | [diff] [blame] | 5686 | paint.setShader(SkGradientShader::MakeLinear(points, colors, nullptr, 4, |
| 5687 | SkShader::kClamp_TileMode)); |
| 5688 | auto vertices = SkVertices::MakeCopy(SkVertices::kTriangleFan_VertexMode, |
| 5689 | SK_ARRAY_COUNT(points), points, texs, colors, boneIndices, boneWeights); |
| 5690 | canvas->drawVertices(vertices.get(), bones, SK_ARRAY_COUNT(bones), SkBlendMode::kDarken, paint); |
| 5691 | } |
| 5692 | ## |
| 5693 | |
| 5694 | #SeeAlso drawPatch drawPicture |
| 5695 | |
| 5696 | ## |
| 5697 | |
| 5698 | # ------------------------------------------------------------------------------ |
| 5699 | |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 5700 | #Method void drawVertices(const sk_sp<SkVertices>& vertices, const SkVertices::Bone bones[], |
| 5701 | int boneCount, SkBlendMode mode, const SkPaint& paint) |
Ruiqi Mao | 94d57c4 | 2018-07-02 15:20:10 -0400 | [diff] [blame] | 5702 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5703 | Draws Vertices vertices, a triangle mesh, using Clip and Matrix. Bone data is used to |
Ruiqi Mao | 94d57c4 | 2018-07-02 15:20:10 -0400 | [diff] [blame] | 5704 | deform vertices with bone weights. |
| 5705 | If Vertices_Texs and Vertices_Colors are defined in vertices, and Paint paint |
| 5706 | contains Shader, Blend_Mode mode combines Vertices_Colors with Shader. |
| 5707 | The first element of bones should be an object to world space transformation matrix that |
| 5708 | will be applied before performing mesh deformations. If no such transformation is needed, |
| 5709 | it should be the identity matrix. |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 5710 | boneCount must be at most 80, and thus the size of bones should be at most 80. |
Ruiqi Mao | 94d57c4 | 2018-07-02 15:20:10 -0400 | [diff] [blame] | 5711 | |
| 5712 | #Param vertices triangle mesh to draw ## |
| 5713 | #Param bones bone matrix data ## |
| 5714 | #Param boneCount number of bone matrices ## |
| 5715 | #Param mode combines Vertices_Colors with Shader, if both are present ## |
| 5716 | #Param paint specifies the Shader, used as Vertices texture, may be nullptr ## |
| 5717 | |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 5718 | #NoExample |
Ruiqi Mao | 94d57c4 | 2018-07-02 15:20:10 -0400 | [diff] [blame] | 5719 | void draw(SkCanvas* canvas) { |
| 5720 | SkPaint paint; |
| 5721 | SkPoint points[] = { { 0, 0 }, { 250, 0 }, { 100, 100 }, { 0, 250 } }; |
| 5722 | SkPoint texs[] = { { 0, 0 }, { 0, 250 }, { 250, 250 }, { 250, 0 } }; |
| 5723 | SkColor colors[] = { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorCYAN }; |
| 5724 | SkVertices::BoneIndices boneIndices[] = { { 0, 0, 0, 0 }, |
| 5725 | { 1, 0, 0, 0 }, |
| 5726 | { 2, 0, 0, 0 }, |
| 5727 | { 3, 0, 0, 0 } }; |
| 5728 | SkVertices::BoneWeights boneWeights[] = { { 0.0f, 0.0f, 0.0f, 0.0f }, |
| 5729 | { 1.0f, 0.0f, 0.0f, 0.0f }, |
| 5730 | { 1.0f, 0.0f, 0.0f, 0.0f }, |
| 5731 | { 1.0f, 0.0f, 0.0f, 0.0f } }; |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 5732 | SkVertices::Bone bones[] = { {{ 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f }}, |
| 5733 | {{ 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 20.0f }}, |
| 5734 | {{ 1.0f, 0.0f, 0.0f, 1.0f, 50.0f, 50.0f }}, |
| 5735 | {{ 1.0f, 0.0f, 0.0f, 1.0f, 20.0f, 0.0f }} }; |
Ruiqi Mao | 94d57c4 | 2018-07-02 15:20:10 -0400 | [diff] [blame] | 5736 | paint.setShader(SkGradientShader::MakeLinear(points, colors, nullptr, 4, |
| 5737 | SkShader::kClamp_TileMode)); |
| 5738 | auto vertices = SkVertices::MakeCopy(SkVertices::kTriangleFan_VertexMode, |
| 5739 | SK_ARRAY_COUNT(points), points, texs, colors, boneIndices, boneWeights); |
| 5740 | canvas->drawVertices(vertices, bones, SK_ARRAY_COUNT(bones), SkBlendMode::kDarken, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5741 | } |
| 5742 | ## |
| 5743 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5744 | #SeeAlso drawPatch drawPicture |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5745 | |
| 5746 | ## |
| 5747 | |
| 5748 | # ------------------------------------------------------------------------------ |
| 5749 | |
| 5750 | #Method void drawPatch(const SkPoint cubics[12], const SkColor colors[4], |
| 5751 | const SkPoint texCoords[4], SkBlendMode mode, const SkPaint& paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5752 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5753 | #Line # draws Coons_Patch ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5754 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5755 | Draws a Coons_Patch: the interpolation of four cubics with shared corners, |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 5756 | associating a color, and optionally a texture Point, with each corner. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5757 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 5758 | Coons_Patch uses Clip and Matrix, paint Shader, Color_Filter, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5759 | 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] | 5760 | 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] | 5761 | both are provided. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5762 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5763 | Point array cubics specifies four Cubics starting at the top-left corner, |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5764 | 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] | 5765 | first point. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5766 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5767 | Color array color associates colors with corners in top-left, top-right, |
| 5768 | bottom-right, bottom-left order. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5769 | |
| 5770 | If paint contains Shader, Point array texCoords maps Shader as texture to |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5771 | corners in top-left, top-right, bottom-right, bottom-left order. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5772 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 5773 | #Param cubics Path_Cubic array, sharing common points ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5774 | #Param colors Color array, one for each corner ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5775 | #Param texCoords Point array of texture coordinates, mapping Shader to corners; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5776 | may be nullptr |
Cary Clark | 579985c | 2017-07-31 11:48:27 -0400 | [diff] [blame] | 5777 | #Param ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5778 | #Param mode Blend_Mode for colors, and for Shader if paint has one ## |
| 5779 | #Param paint Shader, Color_Filter, Blend_Mode, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5780 | |
| 5781 | #Example |
| 5782 | #Image 5 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5783 | void draw(SkCanvas* canvas) { |
| 5784 | // SkBitmap source = cmbkygk; |
| 5785 | SkPaint paint; |
| 5786 | paint.setFilterQuality(kLow_SkFilterQuality); |
| 5787 | paint.setAntiAlias(true); |
| 5788 | SkPoint cubics[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, |
| 5789 | /* { 7, 3 }, */ { 6, 4 }, { 7, 5 }, { 5, 7 }, |
| 5790 | /* { 5, 7 }, */ { 4, 6 }, { 3, 7 }, { 1, 5 }, |
| 5791 | /* { 1, 5 }, */ { 2, 4 }, { 1, 3 }, /* { 3, 1 } */ }; |
| 5792 | SkColor colors[] = { 0xbfff0000, 0xbf0000ff, 0xbfff00ff, 0xbf00ffff }; |
| 5793 | SkPoint texCoords[] = { { -30, -30 }, { 162, -30}, { 162, 162}, { -30, 162} }; |
| 5794 | paint.setShader(SkShader::MakeBitmapShader(source, SkShader::kClamp_TileMode, |
| 5795 | SkShader::kClamp_TileMode, nullptr)); |
| 5796 | canvas->scale(15, 15); |
| 5797 | for (auto blend : { SkBlendMode::kSrcOver, SkBlendMode::kModulate, SkBlendMode::kXor } ) { |
| 5798 | canvas->drawPatch(cubics, colors, texCoords, blend, paint); |
| 5799 | canvas->translate(4, 4); |
| 5800 | } |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5801 | } |
| 5802 | ## |
| 5803 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5804 | #ToDo can patch use image filter? ## |
| 5805 | #SeeAlso SeeAlso drawVertices drawPicture |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5806 | |
| 5807 | ## |
| 5808 | |
| 5809 | # ------------------------------------------------------------------------------ |
| 5810 | |
| 5811 | #Method void drawPatch(const SkPoint cubics[12], const SkColor colors[4], |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5812 | const SkPoint texCoords[4], const SkPaint& paint) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5813 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5814 | Draws Cubic Coons_Patch: the interpolation of four cubics with shared corners, |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 5815 | associating a color, and optionally a texture Point, with each corner. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5816 | |
Cary Clark | a560c47 | 2017-11-27 10:44:06 -0500 | [diff] [blame] | 5817 | Coons_Patch uses Clip and Matrix, paint Shader, Color_Filter, |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5818 | 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] | 5819 | 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] | 5820 | both are provided. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5821 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5822 | Point array cubics specifies four Cubics starting at the top-left corner, |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5823 | 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] | 5824 | first point. |
| 5825 | |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5826 | Color array color associates colors with corners in top-left, top-right, |
| 5827 | bottom-right, bottom-left order. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5828 | |
| 5829 | If paint contains Shader, Point array texCoords maps Shader as texture to |
Cary Clark | bc5697d | 2017-10-04 14:31:33 -0400 | [diff] [blame] | 5830 | corners in top-left, top-right, bottom-right, bottom-left order. |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5831 | |
Cary Clark | a523d2d | 2017-08-30 08:58:10 -0400 | [diff] [blame] | 5832 | #Param cubics Path_Cubic array, sharing common points ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5833 | #Param colors Color array, one for each corner ## |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5834 | #Param texCoords Point array of texture coordinates, mapping Shader to corners; |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5835 | may be nullptr |
Cary Clark | 579985c | 2017-07-31 11:48:27 -0400 | [diff] [blame] | 5836 | #Param ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5837 | #Param paint Shader, Color_Filter, Blend_Mode, used to draw ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5838 | |
| 5839 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5840 | void draw(SkCanvas* canvas) { |
| 5841 | SkPaint paint; |
| 5842 | paint.setAntiAlias(true); |
| 5843 | SkPoint cubics[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, |
| 5844 | /* { 7, 3 }, */ { 6, 4 }, { 7, 5 }, { 5, 7 }, |
| 5845 | /* { 5, 7 }, */ { 4, 6 }, { 3, 7 }, { 1, 5 }, |
| 5846 | /* { 1, 5 }, */ { 2, 4 }, { 1, 3 }, /* { 3, 1 } */ }; |
| 5847 | SkColor colors[] = { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorCYAN }; |
| 5848 | canvas->scale(30, 30); |
| 5849 | canvas->drawPatch(cubics, colors, nullptr, paint); |
| 5850 | SkPoint text[] = { {3,0.9f}, {4,2.5f}, {5,0.9f}, {7.5f,3.2f}, {5.5f,4.2f}, |
| 5851 | {7.5f,5.2f}, {5,7.5f}, {4,5.9f}, {3,7.5f}, {0.5f,5.2f}, {2.5f,4.2f}, |
| 5852 | {0.5f,3.2f} }; |
| 5853 | paint.setTextSize(18.f / 30); |
| 5854 | paint.setTextAlign(SkPaint::kCenter_Align); |
| 5855 | for (int i = 0; i< 10; ++i) { |
| 5856 | char digit = '0' + i; |
| 5857 | canvas->drawText(&digit, 1, text[i].fX, text[i].fY, paint); |
| 5858 | } |
| 5859 | canvas->drawString("10", text[10].fX, text[10].fY, paint); |
| 5860 | canvas->drawString("11", text[11].fX, text[11].fY, paint); |
| 5861 | paint.setStyle(SkPaint::kStroke_Style); |
| 5862 | canvas->drawPoints(SkCanvas::kPolygon_PointMode, 12, cubics, paint); |
| 5863 | 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] | 5864 | } |
| 5865 | ## |
| 5866 | |
| 5867 | #Example |
| 5868 | #Image 6 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5869 | void draw(SkCanvas* canvas) { |
| 5870 | // SkBitmap source = checkerboard; |
| 5871 | SkPaint paint; |
| 5872 | paint.setFilterQuality(kLow_SkFilterQuality); |
| 5873 | paint.setAntiAlias(true); |
| 5874 | SkPoint cubics[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, |
| 5875 | /* { 7, 3 }, */ { 6, 4 }, { 7, 5 }, { 5, 7 }, |
| 5876 | /* { 5, 7 }, */ { 4, 6 }, { 3, 7 }, { 1, 5 }, |
| 5877 | /* { 1, 5 }, */ { 2, 4 }, { 1, 3 }, /* { 3, 1 } */ }; |
| 5878 | SkPoint texCoords[] = { { 0, 0 }, { 0, 62}, { 62, 62}, { 62, 0 } }; |
| 5879 | paint.setShader(SkShader::MakeBitmapShader(source, SkShader::kClamp_TileMode, |
| 5880 | SkShader::kClamp_TileMode, nullptr)); |
| 5881 | canvas->scale(30, 30); |
| 5882 | canvas->drawPatch(cubics, nullptr, texCoords, paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5883 | } |
| 5884 | ## |
| 5885 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5886 | #ToDo can patch use image filter? ## |
| 5887 | #SeeAlso SeeAlso drawVertices drawPicture |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5888 | |
| 5889 | ## |
| 5890 | |
| 5891 | # ------------------------------------------------------------------------------ |
| 5892 | |
| 5893 | #Method void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], |
| 5894 | const SkColor colors[], int count, SkBlendMode mode, const SkRect* cullRect, |
| 5895 | const SkPaint* paint) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 5896 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 5897 | #Line # draws sprites using Clip, Matrix, and Paint ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5898 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5899 | Draws a set of sprites from atlas, using Clip, Matrix, and optional Paint paint. |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 5900 | paint uses Anti_Alias, Color_Alpha, Color_Filter, Image_Filter, and Blend_Mode |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5901 | to draw, if present. For each entry in the array, Rect tex locates sprite in |
| 5902 | atlas, and RSXform xform transforms it into destination space. |
| 5903 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5904 | xform, text, and colors if present, must contain count entries. |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 5905 | Optional colors are applied for each sprite using Blend_Mode mode, treating |
| 5906 | sprite as source and colors as destination. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5907 | Optional cullRect is a conservative bounds of all transformed sprites. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5908 | If cullRect is outside of Clip, canvas can skip drawing. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5909 | |
Cary Clark | 224c700 | 2018-06-27 11:00:21 -0400 | [diff] [blame] | 5910 | |
| 5911 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5912 | #Param atlas Image containing sprites ## |
| 5913 | #Param xform RSXform mappings for sprites in atlas ## |
| 5914 | #Param tex Rect locations of sprites in atlas ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 5915 | #Param colors one per sprite, blended with sprite using Blend_Mode; may be nullptr ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5916 | #Param count number of sprites to draw ## |
| 5917 | #Param mode Blend_Mode combining colors and sprites ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 5918 | #Param cullRect bounds of transformed sprites for efficient clipping; may be nullptr ## |
| 5919 | #Param paint Color_Filter, Image_Filter, Blend_Mode, and so on; may be nullptr ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5920 | |
| 5921 | #Example |
| 5922 | #Image 3 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5923 | void draw(SkCanvas* canvas) { |
| 5924 | // SkBitmap source = mandrill; |
| 5925 | SkRSXform xforms[] = { { .5f, 0, 0, 0 }, {0, .5f, 200, 100 } }; |
| 5926 | SkRect tex[] = { { 0, 0, 250, 250 }, { 0, 0, 250, 250 } }; |
| 5927 | SkColor colors[] = { 0x7f55aa00, 0x7f3333bf }; |
| 5928 | const SkImage* imagePtr = image.get(); |
| 5929 | canvas->drawAtlas(imagePtr, xforms, tex, colors, 2, SkBlendMode::kSrcOver, nullptr, nullptr); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5930 | } |
| 5931 | ## |
| 5932 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5933 | #SeeAlso drawBitmap drawImage |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5934 | |
| 5935 | ## |
| 5936 | |
| 5937 | # ------------------------------------------------------------------------------ |
| 5938 | |
| 5939 | #Method void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[], |
| 5940 | const SkColor colors[], int count, SkBlendMode mode, const SkRect* cullRect, |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5941 | const SkPaint* paint) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5942 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5943 | Draws a set of sprites from atlas, using Clip, Matrix, and optional Paint paint. |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 5944 | paint uses Anti_Alias, Color_Alpha, Color_Filter, Image_Filter, and Blend_Mode |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5945 | to draw, if present. For each entry in the array, Rect tex locates sprite in |
| 5946 | atlas, and RSXform xform transforms it into destination space. |
| 5947 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5948 | xform, text, and colors if present, must contain count entries. |
| 5949 | Optional colors is applied for each sprite using Blend_Mode. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5950 | Optional cullRect is a conservative bounds of all transformed sprites. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5951 | If cullRect is outside of Clip, canvas can skip drawing. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5952 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5953 | #Param atlas Image containing sprites ## |
| 5954 | #Param xform RSXform mappings for sprites in atlas ## |
| 5955 | #Param tex Rect locations of sprites in atlas ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 5956 | #Param colors one per sprite, blended with sprite using Blend_Mode; may be nullptr ## |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5957 | #Param count number of sprites to draw ## |
| 5958 | #Param mode Blend_Mode combining colors and sprites ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 5959 | #Param cullRect bounds of transformed sprites for efficient clipping; may be nullptr ## |
| 5960 | #Param paint Color_Filter, Image_Filter, Blend_Mode, and so on; may be nullptr ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5961 | |
| 5962 | #Example |
| 5963 | #Image 3 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5964 | void draw(SkCanvas* canvas) { |
| 5965 | // SkBitmap source = mandrill; |
| 5966 | SkRSXform xforms[] = { { .5f, 0, 0, 0 }, {0, .5f, 200, 100 } }; |
| 5967 | SkRect tex[] = { { 0, 0, 250, 250 }, { 0, 0, 250, 250 } }; |
| 5968 | SkColor colors[] = { 0x7f55aa00, 0x7f3333bf }; |
| 5969 | SkPaint paint; |
| 5970 | paint.setAlpha(127); |
| 5971 | canvas->drawAtlas(image, xforms, tex, colors, 2, SkBlendMode::kPlus, nullptr, &paint); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5972 | } |
| 5973 | ## |
| 5974 | |
| 5975 | #ToDo bug in example on cpu side, gpu looks ok ## |
| 5976 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 5977 | #SeeAlso drawBitmap drawImage |
| 5978 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5979 | ## |
| 5980 | |
| 5981 | # ------------------------------------------------------------------------------ |
| 5982 | |
| 5983 | #Method void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], int count, |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5984 | const SkRect* cullRect, const SkPaint* paint) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5985 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 5986 | Draws a set of sprites from atlas, using Clip, Matrix, and optional Paint paint. |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 5987 | paint uses Anti_Alias, Color_Alpha, Color_Filter, Image_Filter, and Blend_Mode |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5988 | to draw, if present. For each entry in the array, Rect tex locates sprite in |
| 5989 | atlas, and RSXform xform transforms it into destination space. |
| 5990 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5991 | xform and text must contain count entries. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 5992 | Optional cullRect is a conservative bounds of all transformed sprites. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 5993 | If cullRect is outside of Clip, canvas can skip drawing. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 5994 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 5995 | #Param atlas Image containing sprites ## |
| 5996 | #Param xform RSXform mappings for sprites in atlas ## |
| 5997 | #Param tex Rect locations of sprites in atlas ## |
| 5998 | #Param count number of sprites to draw ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 5999 | #Param cullRect bounds of transformed sprites for efficient clipping; may be nullptr ## |
| 6000 | #Param paint Color_Filter, Image_Filter, Blend_Mode, and so on; may be nullptr ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6001 | |
| 6002 | #Example |
| 6003 | #Image 3 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6004 | void draw(SkCanvas* canvas) { |
| 6005 | // sk_sp<SkImage> image = mandrill; |
| 6006 | SkRSXform xforms[] = { { .5f, 0, 0, 0 }, {0, .5f, 200, 100 } }; |
| 6007 | SkRect tex[] = { { 0, 0, 250, 250 }, { 0, 0, 250, 250 } }; |
| 6008 | const SkImage* imagePtr = image.get(); |
| 6009 | canvas->drawAtlas(imagePtr, xforms, tex, 2, nullptr, nullptr); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6010 | } |
| 6011 | ## |
| 6012 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 6013 | #SeeAlso drawBitmap drawImage |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6014 | |
| 6015 | ## |
| 6016 | |
| 6017 | # ------------------------------------------------------------------------------ |
| 6018 | |
| 6019 | #Method void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[], |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 6020 | int count, const SkRect* cullRect, const SkPaint* paint) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6021 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 6022 | Draws a set of sprites from atlas, using Clip, Matrix, and optional Paint paint. |
Cary Clark | ffb3d68 | 2018-05-17 12:17:28 -0400 | [diff] [blame] | 6023 | paint uses Anti_Alias, Color_Alpha, Color_Filter, Image_Filter, and Blend_Mode |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6024 | to draw, if present. For each entry in the array, Rect tex locates sprite in |
| 6025 | atlas, and RSXform xform transforms it into destination space. |
| 6026 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6027 | xform and text must contain count entries. |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 6028 | Optional cullRect is a conservative bounds of all transformed sprites. |
Cary Clark | ce10124 | 2017-09-01 15:51:02 -0400 | [diff] [blame] | 6029 | If cullRect is outside of Clip, canvas can skip drawing. |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6030 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6031 | #Param atlas Image containing sprites ## |
| 6032 | #Param xform RSXform mappings for sprites in atlas ## |
| 6033 | #Param tex Rect locations of sprites in atlas ## |
| 6034 | #Param count number of sprites to draw ## |
Cary Clark | 6fc5041 | 2017-09-21 12:31:06 -0400 | [diff] [blame] | 6035 | #Param cullRect bounds of transformed sprites for efficient clipping; may be nullptr ## |
| 6036 | #Param paint Color_Filter, Image_Filter, Blend_Mode, and so on; may be nullptr ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6037 | |
| 6038 | #Example |
| 6039 | #Image 3 |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6040 | void draw(SkCanvas* canvas) { |
| 6041 | // sk_sp<SkImage> image = mandrill; |
| 6042 | SkRSXform xforms[] = { { 1, 0, 0, 0 }, {0, 1, 300, 100 } }; |
| 6043 | SkRect tex[] = { { 0, 0, 200, 200 }, { 200, 0, 400, 200 } }; |
| 6044 | canvas->drawAtlas(image, xforms, tex, 2, nullptr, nullptr); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6045 | } |
| 6046 | ## |
| 6047 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 6048 | #SeeAlso drawBitmap drawImage |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6049 | |
| 6050 | ## |
| 6051 | |
| 6052 | # ------------------------------------------------------------------------------ |
| 6053 | |
Cary Clark | 73fa972 | 2017-08-29 17:36:51 -0400 | [diff] [blame] | 6054 | #Method void drawDrawable(SkDrawable* drawable, const SkMatrix* matrix = nullptr) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 6055 | #In Draw |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 6056 | #Line # draws Drawable, encapsulated drawing commands ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 6057 | Draws Drawable drawable using Clip and Matrix, concatenated with |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6058 | optional matrix. |
| 6059 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 6060 | If Canvas has an asynchronous implementation, as is the case |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6061 | when it is recording into Picture, then drawable will be referenced, |
| 6062 | so that SkDrawable::draw() can be called when the operation is finalized. To force |
| 6063 | immediate drawing, call SkDrawable::draw() instead. |
| 6064 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6065 | #Param drawable custom struct encapsulating drawing commands ## |
| 6066 | #Param matrix transformation applied to drawing; may be nullptr ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6067 | |
| 6068 | #Example |
| 6069 | #Height 100 |
| 6070 | #Function |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6071 | struct MyDrawable : public SkDrawable { |
| 6072 | SkRect onGetBounds() override { return SkRect::MakeWH(50, 100); } |
| 6073 | |
| 6074 | void onDraw(SkCanvas* canvas) override { |
| 6075 | SkPath path; |
| 6076 | path.conicTo(10, 90, 50, 90, 0.9f); |
| 6077 | SkPaint paint; |
| 6078 | paint.setColor(SK_ColorBLUE); |
| 6079 | canvas->drawRect(path.getBounds(), paint); |
| 6080 | paint.setAntiAlias(true); |
| 6081 | paint.setColor(SK_ColorWHITE); |
| 6082 | canvas->drawPath(path, paint); |
| 6083 | } |
| 6084 | }; |
| 6085 | |
| 6086 | #Function ## |
| 6087 | void draw(SkCanvas* canvas) { |
| 6088 | sk_sp<SkDrawable> drawable(new MyDrawable); |
| 6089 | SkMatrix matrix; |
| 6090 | matrix.setTranslate(10, 10); |
| 6091 | canvas->drawDrawable(drawable.get(), &matrix); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6092 | } |
| 6093 | ## |
| 6094 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 6095 | #SeeAlso SkDrawable drawPicture |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6096 | |
| 6097 | ## |
| 6098 | |
| 6099 | # ------------------------------------------------------------------------------ |
| 6100 | |
| 6101 | #Method void drawDrawable(SkDrawable* drawable, SkScalar x, SkScalar y) |
| 6102 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 6103 | Draws Drawable drawable using Clip and Matrix, offset by (x, y). |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6104 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 6105 | If Canvas has an asynchronous implementation, as is the case |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6106 | when it is recording into Picture, then drawable will be referenced, |
| 6107 | so that SkDrawable::draw() can be called when the operation is finalized. To force |
| 6108 | immediate drawing, call SkDrawable::draw() instead. |
| 6109 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6110 | #Param drawable custom struct encapsulating drawing commands ## |
Cary Clark | 5538c13 | 2018-06-14 12:28:14 -0400 | [diff] [blame] | 6111 | #Param x offset into Canvas writable pixels on x-axis ## |
| 6112 | #Param y offset into Canvas writable pixels on y-axis ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6113 | |
| 6114 | #Example |
| 6115 | #Height 100 |
| 6116 | #Function |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6117 | struct MyDrawable : public SkDrawable { |
| 6118 | SkRect onGetBounds() override { return SkRect::MakeWH(50, 100); } |
| 6119 | |
| 6120 | void onDraw(SkCanvas* canvas) override { |
| 6121 | SkPath path; |
| 6122 | path.conicTo(10, 90, 50, 90, 0.9f); |
| 6123 | SkPaint paint; |
| 6124 | paint.setColor(SK_ColorBLUE); |
| 6125 | canvas->drawRect(path.getBounds(), paint); |
| 6126 | paint.setAntiAlias(true); |
| 6127 | paint.setColor(SK_ColorWHITE); |
| 6128 | canvas->drawPath(path, paint); |
| 6129 | } |
| 6130 | }; |
| 6131 | |
| 6132 | #Function ## |
| 6133 | void draw(SkCanvas* canvas) { |
| 6134 | sk_sp<SkDrawable> drawable(new MyDrawable); |
| 6135 | canvas->drawDrawable(drawable.get(), 10, 10); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6136 | } |
| 6137 | ## |
| 6138 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 6139 | #SeeAlso SkDrawable drawPicture |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6140 | |
| 6141 | ## |
| 6142 | |
| 6143 | # ------------------------------------------------------------------------------ |
| 6144 | |
| 6145 | #Method void drawAnnotation(const SkRect& rect, const char key[], SkData* value) |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 6146 | #In Draw |
| 6147 | #In Utility |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 6148 | #Line # associates a Rect with a key-value pair ## |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 6149 | Associates Rect on Canvas with an annotation; a key-value pair, where the key is |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6150 | a null-terminated utf8 string, and optional value is stored as Data. |
| 6151 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 6152 | Only some canvas implementations, such as recording to Picture, or drawing to |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6153 | Document_PDF, use annotations. |
| 6154 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6155 | #Param rect Rect extent of canvas to annotate ## |
| 6156 | #Param key string used for lookup ## |
| 6157 | #Param value data holding value stored in annotation ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6158 | |
| 6159 | #Example |
| 6160 | #Height 1 |
| 6161 | const char text[] = "Click this link!"; |
| 6162 | SkRect bounds; |
| 6163 | SkPaint paint; |
| 6164 | paint.setTextSize(40); |
| 6165 | (void)paint.measureText(text, strlen(text), &bounds); |
| 6166 | const char url[] = "https://www.google.com/"; |
| 6167 | sk_sp<SkData> urlData(SkData::MakeWithCString(url)); |
| 6168 | canvas->drawAnnotation(bounds, "url_key", urlData.get()); |
| 6169 | ## |
| 6170 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 6171 | #SeeAlso SkPicture SkDocument |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6172 | |
| 6173 | ## |
| 6174 | |
| 6175 | # ------------------------------------------------------------------------------ |
| 6176 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 6177 | #Method void drawAnnotation(const SkRect& rect, const char key[], const sk_sp<SkData>& value) |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6178 | |
Cary Clark | 80247e5 | 2018-07-11 16:18:41 -0400 | [diff] [blame] | 6179 | Associates Rect on Canvas when an annotation; a key-value pair, where the key is |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6180 | a null-terminated utf8 string, and optional value is stored as Data. |
| 6181 | |
Herb Derby | efe39bc | 2018-05-01 17:06:20 -0400 | [diff] [blame] | 6182 | Only some canvas implementations, such as recording to Picture, or drawing to |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6183 | Document_PDF, use annotations. |
| 6184 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6185 | #Param rect Rect extent of canvas to annotate ## |
| 6186 | #Param key string used for lookup ## |
| 6187 | #Param value data holding value stored in annotation ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6188 | |
| 6189 | #Example |
| 6190 | #Height 1 |
| 6191 | const char text[] = "Click this link!"; |
| 6192 | SkRect bounds; |
| 6193 | SkPaint paint; |
| 6194 | paint.setTextSize(40); |
| 6195 | (void)paint.measureText(text, strlen(text), &bounds); |
| 6196 | const char url[] = "https://www.google.com/"; |
| 6197 | sk_sp<SkData> urlData(SkData::MakeWithCString(url)); |
| 6198 | canvas->drawAnnotation(bounds, "url_key", urlData.get()); |
| 6199 | ## |
| 6200 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 6201 | #SeeAlso SkPicture SkDocument |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6202 | |
| 6203 | ## |
| 6204 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6205 | # ------------------------------------------------------------------------------ |
| 6206 | |
| 6207 | #Method virtual bool isClipEmpty() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 6208 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 6209 | #Line # returns if Clip is empty ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6210 | Returns true if Clip is empty; that is, nothing will draw. |
| 6211 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6212 | May do work when called; it should not be called |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6213 | more often than needed. However, once called, subsequent calls perform no |
| 6214 | work until Clip changes. |
| 6215 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6216 | #Return true if Clip is empty ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6217 | |
| 6218 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6219 | void draw(SkCanvas* canvas) { |
| 6220 | SkDebugf("clip is%s empty\n", canvas->isClipEmpty() ? "" : " not"); |
| 6221 | SkPath path; |
| 6222 | canvas->clipPath(path); |
| 6223 | SkDebugf("clip is%s empty\n", canvas->isClipEmpty() ? "" : " not"); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6224 | } |
| 6225 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6226 | clip is not empty |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6227 | clip is empty |
| 6228 | ## |
| 6229 | ## |
| 6230 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 6231 | #SeeAlso isClipRect getLocalClipBounds getDeviceClipBounds |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6232 | |
| 6233 | ## |
| 6234 | |
| 6235 | # ------------------------------------------------------------------------------ |
| 6236 | |
| 6237 | #Method virtual bool isClipRect() const |
Cary Clark | 78de751 | 2018-02-07 07:27:09 -0500 | [diff] [blame] | 6238 | #In Property |
Cary Clark | ab2621d | 2018-01-30 10:08:57 -0500 | [diff] [blame] | 6239 | #Line # returns if Clip is Rect and not empty ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6240 | Returns true if Clip is Rect and not empty. |
| 6241 | Returns false if the clip is empty, or if it is not Rect. |
| 6242 | |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6243 | #Return true if Clip is Rect and not empty ## |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6244 | |
| 6245 | #Example |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6246 | void draw(SkCanvas* canvas) { |
| 6247 | SkDebugf("clip is%s rect\n", canvas->isClipRect() ? "" : " not"); |
| 6248 | canvas->clipRect({0, 0, 0, 0}); |
| 6249 | SkDebugf("clip is%s rect\n", canvas->isClipRect() ? "" : " not"); |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6250 | } |
| 6251 | #StdOut |
Cary Clark | bad5ad7 | 2017-08-03 17:14:08 -0400 | [diff] [blame] | 6252 | clip is rect |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6253 | clip is not rect |
| 6254 | ## |
| 6255 | ## |
| 6256 | |
Cary Clark | 2ade997 | 2017-11-02 17:49:34 -0400 | [diff] [blame] | 6257 | #SeeAlso isClipEmpty getLocalClipBounds getDeviceClipBounds |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6258 | |
| 6259 | ## |
| 6260 | |
| 6261 | #Class SkCanvas ## |
Cary Clark | 884dd7d | 2017-10-11 10:37:52 -0400 | [diff] [blame] | 6262 | |
Cary Clark | 8032b98 | 2017-07-28 11:04:54 -0400 | [diff] [blame] | 6263 | #Topic Canvas ## |