2017-07-28 15:04:54 +00:00
|
|
|
#Topic Canvas
|
2017-07-28 19:18:29 +00:00
|
|
|
#Alias Canvas_Reference
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-02-01 14:37:32 +00:00
|
|
|
#Subtopic Overview
|
2018-02-06 14:41:53 +00:00
|
|
|
#Subtopic Subtopic
|
2018-02-01 14:37:32 +00:00
|
|
|
#Populate
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
2017-09-15 06:56:12 +00:00
|
|
|
#Class SkCanvas
|
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
Canvas provides an interface for drawing, and how the drawing is clipped and transformed.
|
|
|
|
Canvas contains a stack of Matrix and Clip values.
|
|
|
|
|
|
|
|
Canvas and Paint together provide the state to draw into Surface or Device.
|
2017-08-03 21:14:08 +00:00
|
|
|
Each Canvas draw call transforms the geometry of the object by the concatenation of all
|
|
|
|
Matrix values in the stack. The transformed geometry is clipped by the intersection
|
|
|
|
of all of Clip values in the stack. The Canvas draw calls use Paint to supply drawing
|
|
|
|
state such as Color, Typeface, text size, stroke width, Shader and so on.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
To draw to a pixel-based destination, create Raster_Surface or GPU_Surface.
|
|
|
|
Request Canvas from Surface to obtain the interface to draw.
|
|
|
|
Canvas generated by Raster_Surface draws to memory visible to the CPU.
|
2017-07-28 15:04:54 +00:00
|
|
|
Canvas generated by GPU_Surface uses Vulkan or OpenGL to draw to the GPU.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
To draw to a document, obtain Canvas from SVG_Canvas, Document_PDF, or Picture_Recorder.
|
2017-09-01 19:51:02 +00:00
|
|
|
Document based Canvas and other Canvas Subclasses reference Device describing the
|
2017-08-03 21:14:08 +00:00
|
|
|
destination.
|
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
Canvas can be constructed to draw to Bitmap without first creating Raster_Surface.
|
2018-02-07 01:58:51 +00:00
|
|
|
This approach may be deprecated in the future.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-02-06 14:41:53 +00:00
|
|
|
#Subtopic Related_Function
|
2018-02-01 14:37:32 +00:00
|
|
|
#Populate
|
|
|
|
##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-02-06 14:41:53 +00:00
|
|
|
#Subtopic Constant
|
2018-02-01 14:37:32 +00:00
|
|
|
#Populate
|
|
|
|
##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-02-06 14:41:53 +00:00
|
|
|
#Subtopic Class_or_Struct
|
2018-02-01 14:37:32 +00:00
|
|
|
#Populate
|
|
|
|
##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-02-06 14:41:53 +00:00
|
|
|
#Subtopic Constructor
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-02-06 14:41:53 +00:00
|
|
|
Create the desired type of Surface to obtain its Canvas when possible. Useful
|
2017-07-28 15:04:54 +00:00
|
|
|
when no Surface is required, and some helpers implicitly create Raster_Surface.
|
|
|
|
|
2018-02-01 14:37:32 +00:00
|
|
|
#Populate
|
|
|
|
##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-02-06 14:41:53 +00:00
|
|
|
#Subtopic Member_Function
|
2018-02-01 14:37:32 +00:00
|
|
|
#Populate
|
|
|
|
##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2017-11-27 15:44:06 +00:00
|
|
|
#Method static std::unique_ptr<SkCanvas> MakeRasterDirect(const SkImageInfo& info, void* pixels,
|
|
|
|
size_t rowBytes,
|
|
|
|
const SkSurfaceProps* props = nullptr)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Constructor
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # creates from SkImageInfo and Pixel_Storage ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
Allocates raster Canvas that will draw directly into pixels.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
Canvas is returned if all parameters are valid.
|
|
|
|
Valid parameters include:
|
|
|
|
info dimensions are zero or positive;
|
2018-01-26 17:56:22 +00:00
|
|
|
info contains Color_Type and Alpha_Type supported by Raster_Surface;
|
2017-08-03 21:14:08 +00:00
|
|
|
pixels is not nullptr;
|
2018-01-26 17:56:22 +00:00
|
|
|
rowBytes is zero or large enough to contain info width pixels of Color_Type.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
Pass zero for rowBytes to compute rowBytes from info width and size of pixel.
|
2017-08-24 16:59:48 +00:00
|
|
|
If rowBytes is greater than zero, it must be equal to or greater than
|
2018-01-26 17:56:22 +00:00
|
|
|
info width times bytes required for Color_Type.
|
2017-08-24 16:59:48 +00:00
|
|
|
|
|
|
|
Pixel buffer size should be info height times computed rowBytes.
|
2017-11-27 15:44:06 +00:00
|
|
|
Pixels are not initialized.
|
|
|
|
To access pixels after drawing, call flush() or peekPixels.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
2018-01-26 17:56:22 +00:00
|
|
|
#Param info width, height, Color_Type, Alpha_Type, Color_Space, of Raster_Surface;
|
2017-08-03 21:14:08 +00:00
|
|
|
width, or height, or both, may be zero
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
2017-08-24 16:59:48 +00:00
|
|
|
#Param pixels pointer to destination pixels buffer
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
2017-08-24 16:59:48 +00:00
|
|
|
#Param rowBytes interval from one Surface row to the next, or zero
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
2017-11-27 15:44:06 +00:00
|
|
|
#Param props LCD striping orientation and setting for device independent fonts;
|
|
|
|
may be nullptr
|
|
|
|
##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Return Canvas if all parameters are valid; otherwise, nullptr ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Description
|
|
|
|
Allocates a three by three bitmap, clears it to white, and draws a black pixel
|
|
|
|
in the center.
|
|
|
|
##
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* ) {
|
2017-09-01 19:51:02 +00:00
|
|
|
SkImageInfo info = SkImageInfo::MakeN32Premul(3, 3); // device aligned, 32 bpp, Premultiplied
|
2017-08-03 21:14:08 +00:00
|
|
|
const size_t minRowBytes = info.minRowBytes(); // bytes used by one bitmap row
|
2017-11-27 15:44:06 +00:00
|
|
|
const size_t size = info.computeMinByteSize(); // bytes used by all rows
|
2017-08-03 21:14:08 +00:00
|
|
|
SkAutoTMalloc<SkPMColor> storage(size); // allocate storage for pixels
|
|
|
|
SkPMColor* pixels = storage.get(); // get pointer to allocated storage
|
|
|
|
// create a SkCanvas backed by a raster device, and delete it when the
|
|
|
|
// function goes out of scope.
|
|
|
|
std::unique_ptr<SkCanvas> canvas = SkCanvas::MakeRasterDirect(info, pixels, minRowBytes);
|
2017-09-01 19:51:02 +00:00
|
|
|
canvas->clear(SK_ColorWHITE); // white is Unpremultiplied, in ARGB order
|
2017-08-03 21:14:08 +00:00
|
|
|
canvas->flush(); // ensure that pixels are cleared
|
2017-09-01 19:51:02 +00:00
|
|
|
SkPMColor pmWhite = pixels[0]; // the Premultiplied format may vary
|
2017-08-03 21:14:08 +00:00
|
|
|
SkPaint paint; // by default, draws black
|
|
|
|
canvas->drawPoint(1, 1, paint); // draw in the center
|
|
|
|
canvas->flush(); // ensure that point was drawn
|
|
|
|
for (int y = 0; y < info.height(); ++y) {
|
|
|
|
for (int x = 0; x < info.width(); ++x) {
|
|
|
|
SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x');
|
|
|
|
}
|
|
|
|
SkDebugf("\n");
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
#StdOut
|
|
|
|
---
|
|
|
|
-x-
|
|
|
|
---
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso MakeRasterDirectN32 SkSurface::MakeRasterDirect
|
2017-11-02 21:49:34 +00:00
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method static std::unique_ptr<SkCanvas> MakeRasterDirectN32(int width, int height, SkPMColor* pixels,
|
2018-02-07 01:58:51 +00:00
|
|
|
size_t rowBytes)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Constructor
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # creates from image data and Pixel_Storage ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
Allocates raster Canvas specified by inline image specification. Subsequent Canvas
|
|
|
|
calls draw into pixels.
|
2018-01-26 17:56:22 +00:00
|
|
|
Color_Type is set to kN32_SkColorType.
|
|
|
|
Alpha_Type is set to kPremul_SkAlphaType.
|
2017-07-28 15:04:54 +00:00
|
|
|
To access pixels after drawing, call flush() or peekPixels.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
Canvas is returned if all parameters are valid.
|
|
|
|
Valid parameters include:
|
2017-08-24 16:59:48 +00:00
|
|
|
width and height are zero or positive;
|
2017-08-03 21:14:08 +00:00
|
|
|
pixels is not nullptr;
|
2017-08-24 16:59:48 +00:00
|
|
|
rowBytes is zero or large enough to contain width pixels of kN32_SkColorType.
|
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
Pass zero for rowBytes to compute rowBytes from width and size of pixel.
|
2017-08-24 16:59:48 +00:00
|
|
|
If rowBytes is greater than zero, it must be equal to or greater than
|
2018-01-26 17:56:22 +00:00
|
|
|
width times bytes required for Color_Type.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
2017-08-24 16:59:48 +00:00
|
|
|
Pixel buffer size should be height times rowBytes.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
|
|
|
#Param width pixel column count on Raster_Surface created; must be zero or greater ##
|
2017-10-04 18:31:33 +00:00
|
|
|
#Param height pixel row count on Raster_Surface created; must be zero or greater ##
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param pixels pointer to destination pixels buffer; buffer size should be height
|
2017-08-24 16:59:48 +00:00
|
|
|
times rowBytes
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
2017-08-24 16:59:48 +00:00
|
|
|
#Param rowBytes interval from one Surface row to the next, or zero
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Return Canvas if all parameters are valid; otherwise, nullptr ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Description
|
|
|
|
Allocates a three by three bitmap, clears it to white, and draws a black pixel
|
|
|
|
in the center.
|
|
|
|
##
|
|
|
|
void draw(SkCanvas* ) {
|
|
|
|
const int width = 3;
|
|
|
|
const int height = 3;
|
2017-09-01 19:51:02 +00:00
|
|
|
SkPMColor pixels[height][width]; // allocate a 3x3 Premultiplied bitmap on the stack
|
2017-07-28 15:04:54 +00:00
|
|
|
// create a SkCanvas backed by a raster device, and delete it when the
|
|
|
|
// function goes out of scope.
|
|
|
|
std::unique_ptr<SkCanvas> canvas = SkCanvas::MakeRasterDirectN32(
|
|
|
|
width,
|
|
|
|
height,
|
2017-10-04 18:31:33 +00:00
|
|
|
pixels[0], // top-left of the bitmap
|
2017-07-28 15:04:54 +00:00
|
|
|
sizeof(pixels[0])); // byte width of the each row
|
2017-09-01 19:51:02 +00:00
|
|
|
// write a premultiplied value for white into all pixels in the bitmap
|
2017-07-28 15:04:54 +00:00
|
|
|
canvas->clear(SK_ColorWHITE);
|
2017-09-01 19:51:02 +00:00
|
|
|
SkPMColor pmWhite = pixels[0][0]; // the Premultiplied format may vary
|
2017-07-28 15:04:54 +00:00
|
|
|
SkPaint paint; // by default, draws black
|
|
|
|
canvas->drawPoint(1, 1, paint); // draw in the center
|
|
|
|
canvas->flush(); // ensure that pixels is ready to be read
|
|
|
|
for (int y = 0; y < height; ++y) {
|
|
|
|
for (int x = 0; x < width; ++x) {
|
|
|
|
SkDebugf("%c", pixels[y][x] == pmWhite ? '-' : 'x');
|
|
|
|
}
|
|
|
|
SkDebugf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#StdOut
|
|
|
|
---
|
|
|
|
-x-
|
|
|
|
---
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso MakeRasterDirect SkSurface::MakeRasterDirect SkImageInfo::MakeN32Premul
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method SkCanvas()
|
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # creates with no Surface, no dimensions ##
|
2018-02-07 01:58:51 +00:00
|
|
|
Creates an empty Canvas with no backing device or pixels, with
|
2017-08-24 16:59:48 +00:00
|
|
|
a width and height of zero.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-09-14 15:25:39 +00:00
|
|
|
#Return empty Canvas ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
|
|
|
|
#Description
|
|
|
|
Passes a placeholder to a function that requires one.
|
|
|
|
##
|
|
|
|
|
|
|
|
#Function
|
2017-08-03 21:14:08 +00:00
|
|
|
// Returns true if either the canvas rotates the text by 90 degrees, or the paint does.
|
|
|
|
static void check_for_up_and_down_text(const SkCanvas* canvas, const SkPaint& paint) {
|
|
|
|
bool paintHasVertical = paint.isVerticalText();
|
|
|
|
const SkMatrix& matrix = canvas->getTotalMatrix();
|
|
|
|
bool matrixIsVertical = matrix.preservesRightAngles() && !matrix.isScaleTranslate();
|
|
|
|
SkDebugf("paint draws text %s\n", paintHasVertical != matrixIsVertical ?
|
|
|
|
"top to bottom" : "left to right");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void check_for_up_and_down_text(const SkPaint& paint) {
|
|
|
|
SkCanvas canvas; // placeholder only, does not have an associated device
|
|
|
|
check_for_up_and_down_text(&canvas, paint);
|
|
|
|
}
|
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
|
|
|
check_for_up_and_down_text(paint); // paint draws text left to right
|
|
|
|
paint.setVerticalText(true);
|
|
|
|
check_for_up_and_down_text(paint); // paint draws text top to bottom
|
|
|
|
paint.setVerticalText(false);
|
|
|
|
canvas->rotate(90);
|
|
|
|
check_for_up_and_down_text(canvas, paint); // paint draws text top to bottom
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#StdOut
|
|
|
|
paint draws text left to right
|
|
|
|
paint draws text top to bottom
|
|
|
|
paint draws text top to bottom
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso MakeRasterDirect SkRasterHandleAllocator::MakeCanvas SkSurface::getCanvas SkCreateColorSpaceXformCanvas
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2017-08-29 21:36:51 +00:00
|
|
|
#Method SkCanvas(int width, int height, const SkSurfaceProps* props = nullptr)
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # no Surface, set dimensions, Surface_Properties ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Creates Canvas of the specified dimensions without a Surface.
|
2017-09-01 19:51:02 +00:00
|
|
|
Used by Subclasses with custom implementations for draw methods.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-09-14 15:25:39 +00:00
|
|
|
If props equals nullptr, Surface_Properties are created with
|
2018-02-07 01:58:51 +00:00
|
|
|
Surface_Properties_Legacy_Font_Host settings, which choose the pixel striping
|
2017-09-14 15:25:39 +00:00
|
|
|
direction and order. Since a platform may dynamically change its direction when
|
|
|
|
the device is rotated, and since a platform may have multiple monitors with
|
|
|
|
different characteristics, it is best not to rely on this legacy behavior.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param width zero or greater ##
|
|
|
|
#Param height zero or greater ##
|
|
|
|
#Param props LCD striping orientation and setting for device independent fonts;
|
|
|
|
may be nullptr
|
|
|
|
##
|
|
|
|
|
|
|
|
#Return Canvas placeholder with dimensions ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
SkCanvas canvas(10, 20); // 10 units wide, 20 units high
|
|
|
|
canvas.clipRect(SkRect::MakeXYWH(30, 40, 5, 10)); // clip is outside canvas' device
|
|
|
|
SkDebugf("canvas %s empty\n", canvas.getDeviceClipBounds().isEmpty() ? "is" : "is not");
|
|
|
|
|
|
|
|
#StdOut
|
|
|
|
canvas is empty
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso MakeRasterDirect SkSurfaceProps SkPixelGeometry SkCreateColorSpaceXformCanvas
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method explicit SkCanvas(SkBaseDevice* device)
|
2018-02-06 14:41:53 +00:00
|
|
|
#Deprecated soon
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method explicit SkCanvas(const SkBitmap& bitmap)
|
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # uses existing Bitmap ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Construct a canvas that draws into bitmap.
|
2018-02-07 01:58:51 +00:00
|
|
|
Sets SkSurfaceProps::kLegacyFontHost_InitType in constructed Surface.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
Bitmap is copied so that subsequently editing bitmap will not affect
|
|
|
|
constructed Canvas.
|
|
|
|
|
|
|
|
May be deprecated in the future.
|
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
#ToDo Should be deprecated? ##
|
|
|
|
|
2018-01-26 17:56:22 +00:00
|
|
|
#Param bitmap width, height, Color_Type, Alpha_Type, and pixel
|
2017-08-03 21:14:08 +00:00
|
|
|
storage of Raster_Surface
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Return Canvas that can be used to draw into bitmap ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Description
|
|
|
|
The actual output depends on the installed fonts.
|
|
|
|
##
|
|
|
|
SkBitmap bitmap;
|
|
|
|
// create a bitmap 5 wide and 11 high
|
|
|
|
bitmap.allocPixels(SkImageInfo::MakeN32Premul(5, 11));
|
|
|
|
SkCanvas canvas(bitmap);
|
2017-09-01 19:51:02 +00:00
|
|
|
canvas.clear(SK_ColorWHITE); // white is Unpremultiplied, in ARGB order
|
2017-07-28 15:04:54 +00:00
|
|
|
SkPixmap pixmap; // provides guaranteed access to the drawn pixels
|
|
|
|
if (!canvas.peekPixels(&pixmap)) {
|
|
|
|
SkDebugf("peekPixels should never fail.\n");
|
|
|
|
}
|
2017-10-04 18:31:33 +00:00
|
|
|
const SkPMColor* pixels = pixmap.addr32(); // points to top-left of bitmap
|
2017-09-01 19:51:02 +00:00
|
|
|
SkPMColor pmWhite = pixels[0]; // the Premultiplied format may vary
|
2017-07-28 15:04:54 +00:00
|
|
|
SkPaint paint; // by default, draws black, 12 point text
|
|
|
|
canvas.drawString("!", 1, 10, paint); // 1 char at baseline (1, 10)
|
|
|
|
for (int y = 0; y < bitmap.height(); ++y) {
|
|
|
|
for (int x = 0; x < bitmap.width(); ++x) {
|
|
|
|
SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x');
|
|
|
|
}
|
|
|
|
SkDebugf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#StdOut
|
2017-09-14 15:25:39 +00:00
|
|
|
-----
|
|
|
|
---x-
|
|
|
|
---x-
|
|
|
|
---x-
|
|
|
|
---x-
|
|
|
|
---x-
|
|
|
|
---x-
|
|
|
|
-----
|
|
|
|
---x-
|
|
|
|
---x-
|
2017-07-28 15:04:54 +00:00
|
|
|
-----
|
|
|
|
#StdOut ##
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso MakeRasterDirect SkRasterHandleAllocator::MakeCanvas SkSurface::getCanvas SkCreateColorSpaceXformCanvas
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#EnumClass ColorBehavior
|
2018-02-01 14:37:32 +00:00
|
|
|
#Line # Android framework only ##
|
2017-07-28 15:04:54 +00:00
|
|
|
#Private
|
|
|
|
Android framework only.
|
|
|
|
##
|
|
|
|
|
|
|
|
#Code
|
|
|
|
enum class ColorBehavior {
|
|
|
|
kLegacy,
|
|
|
|
};
|
|
|
|
##
|
|
|
|
#Const kLegacy 0
|
2017-08-03 21:14:08 +00:00
|
|
|
Is a placeholder to allow specialized constructor; has no meaning.
|
|
|
|
##
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
2017-08-03 21:14:08 +00:00
|
|
|
|
|
|
|
#Method SkCanvas(const SkBitmap& bitmap, ColorBehavior behavior)
|
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # Android framework only ##
|
2017-08-03 21:14:08 +00:00
|
|
|
#Private
|
|
|
|
Android framework only.
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param bitmap specifies a bitmap for the canvas to draw into ##
|
|
|
|
#Param behavior specializes this constructor; value is unused ##
|
|
|
|
#Return Canvas that can be used to draw into bitmap ##
|
|
|
|
|
|
|
|
#NoExample
|
|
|
|
##
|
|
|
|
##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method SkCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props)
|
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # uses existing Bitmap and Surface_Properties ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Construct a canvas that draws into bitmap.
|
|
|
|
Use props to match the device characteristics, like LCD striping.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
bitmap is copied so that subsequently editing bitmap will not affect
|
|
|
|
constructed Canvas.
|
|
|
|
|
2018-01-26 17:56:22 +00:00
|
|
|
#Param bitmap width, height, Color_Type, Alpha_Type,
|
2018-02-07 01:58:51 +00:00
|
|
|
and pixel storage of Raster_Surface
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param props order and orientation of RGB striping; and whether to use
|
|
|
|
device independent fonts
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Return Canvas that can be used to draw into bitmap ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Description
|
|
|
|
The actual output depends on the installed fonts.
|
|
|
|
##
|
|
|
|
SkBitmap bitmap;
|
|
|
|
// create a bitmap 5 wide and 11 high
|
|
|
|
bitmap.allocPixels(SkImageInfo::MakeN32Premul(5, 11));
|
|
|
|
SkCanvas canvas(bitmap, SkSurfaceProps(0, kUnknown_SkPixelGeometry));
|
2017-09-01 19:51:02 +00:00
|
|
|
canvas.clear(SK_ColorWHITE); // white is Unpremultiplied, in ARGB order
|
2017-07-28 15:04:54 +00:00
|
|
|
SkPixmap pixmap; // provides guaranteed access to the drawn pixels
|
|
|
|
if (!canvas.peekPixels(&pixmap)) {
|
|
|
|
SkDebugf("peekPixels should never fail.\n");
|
|
|
|
}
|
2017-10-04 18:31:33 +00:00
|
|
|
const SkPMColor* pixels = pixmap.addr32(); // points to top-left of bitmap
|
2017-09-01 19:51:02 +00:00
|
|
|
SkPMColor pmWhite = pixels[0]; // the Premultiplied format may vary
|
2017-07-28 15:04:54 +00:00
|
|
|
SkPaint paint; // by default, draws black, 12 point text
|
|
|
|
canvas.drawString("!", 1, 10, paint); // 1 char at baseline (1, 10)
|
|
|
|
for (int y = 0; y < bitmap.height(); ++y) {
|
|
|
|
for (int x = 0; x < bitmap.width(); ++x) {
|
|
|
|
SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x');
|
|
|
|
}
|
|
|
|
SkDebugf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#StdOut
|
|
|
|
-----
|
|
|
|
---x-
|
|
|
|
---x-
|
|
|
|
---x-
|
|
|
|
---x-
|
|
|
|
---x-
|
|
|
|
---x-
|
|
|
|
-----
|
|
|
|
---x-
|
|
|
|
---x-
|
|
|
|
-----
|
|
|
|
#StdOut ##
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso MakeRasterDirect SkRasterHandleAllocator::MakeCanvas SkSurface::getCanvas SkCreateColorSpaceXformCanvas
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method virtual ~SkCanvas()
|
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # draws saved Layers, frees resources ##
|
2018-01-22 12:55:48 +00:00
|
|
|
Draws saved Layers, if any.
|
|
|
|
Frees up resources used by Canvas.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2017-08-03 21:14:08 +00:00
|
|
|
#Description
|
2017-09-01 19:51:02 +00:00
|
|
|
Canvas Layer draws into bitmap. saveLayerAlpha sets up an additional
|
|
|
|
drawing surface that blends with the bitmap. When Layer goes out of
|
|
|
|
scope, Layer Destructor is called. The saved Layer is restored, drawing
|
2017-08-03 21:14:08 +00:00
|
|
|
transparent letters.
|
|
|
|
##
|
2017-08-24 16:59:48 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.allocPixels(SkImageInfo::MakeN32Premul(200, 200));
|
|
|
|
{
|
|
|
|
SkCanvas offscreen(bitmap);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setTextSize(100);
|
|
|
|
offscreen.drawString("ABC", 20, 160, paint);
|
|
|
|
SkRect layerBounds = SkRect::MakeXYWH(32, 32, 192, 192);
|
|
|
|
offscreen.saveLayerAlpha(&layerBounds, 128);
|
|
|
|
offscreen.clear(SK_ColorWHITE);
|
|
|
|
offscreen.drawString("DEF", 20, 160, paint);
|
|
|
|
}
|
|
|
|
canvas->drawBitmap(bitmap, 0, 0, nullptr);
|
2017-08-03 21:14:08 +00:00
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#SeeAlso State_Stack
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
2018-02-07 12:27:09 +00:00
|
|
|
#Subtopic Property
|
|
|
|
#Populate
|
|
|
|
#Line # metrics and attributes ##
|
|
|
|
##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Method SkMetaData& getMetaData()
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
|
|
|
#In Utility
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # associates additional data with the canvas ##
|
2017-08-24 16:59:48 +00:00
|
|
|
Returns storage to associate additional data with the canvas.
|
2017-07-28 15:04:54 +00:00
|
|
|
The storage is freed when Canvas is deleted.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Return storage that can be read from and written to ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
const char* kHelloMetaData = "HelloMetaData";
|
|
|
|
SkCanvas canvas;
|
|
|
|
SkMetaData& metaData = canvas.getMetaData();
|
|
|
|
SkDebugf("before: %s\n", metaData.findString(kHelloMetaData));
|
|
|
|
metaData.setString(kHelloMetaData, "Hello!");
|
|
|
|
SkDebugf("during: %s\n", metaData.findString(kHelloMetaData));
|
|
|
|
metaData.removeString(kHelloMetaData);
|
|
|
|
SkDebugf("after: %s\n", metaData.findString(kHelloMetaData));
|
|
|
|
|
|
|
|
#StdOut
|
|
|
|
before: (null)
|
|
|
|
during: Hello!
|
|
|
|
after: (null)
|
|
|
|
#StdOut ##
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso SkMetaData
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method SkImageInfo imageInfo() const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns Image_Info for Canvas ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Returns Image_Info for Canvas. If Canvas is not associated with Raster_Surface or
|
2018-01-26 17:56:22 +00:00
|
|
|
GPU_Surface, returned Color_Type is set to kUnknown_SkColorType.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-01-26 17:56:22 +00:00
|
|
|
#Return dimensions and Color_Type of Canvas ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2017-08-24 16:59:48 +00:00
|
|
|
SkCanvas emptyCanvas;
|
|
|
|
SkImageInfo canvasInfo = emptyCanvas.imageInfo();
|
|
|
|
SkImageInfo emptyInfo;
|
|
|
|
SkDebugf("emptyInfo %c= canvasInfo\n", emptyInfo == canvasInfo ? '=' : '!');
|
|
|
|
|
|
|
|
#StdOut
|
|
|
|
emptyInfo == canvasInfo
|
|
|
|
##
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso SkImageInfo MakeRasterDirect makeSurface
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method bool getProps(SkSurfaceProps* props) const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # copies Surface_Properties if available ##
|
2017-07-28 15:04:54 +00:00
|
|
|
If Canvas is associated with Raster_Surface or
|
|
|
|
GPU_Surface, copies Surface_Properties and returns true. Otherwise,
|
|
|
|
return false and leave props unchanged.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param props storage for writable SkSurfaceProps ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Return true if Surface_Properties was copied ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#ToDo This seems old style. Deprecate? ##
|
|
|
|
|
|
|
|
#Example
|
|
|
|
SkBitmap bitmap;
|
|
|
|
SkCanvas canvas(bitmap, SkSurfaceProps(0, kRGB_V_SkPixelGeometry));
|
|
|
|
SkSurfaceProps surfaceProps(0, kUnknown_SkPixelGeometry);
|
|
|
|
SkDebugf("isRGB:%d\n", SkPixelGeometryIsRGB(surfaceProps.pixelGeometry()));
|
|
|
|
if (!canvas.getProps(&surfaceProps)) {
|
|
|
|
SkDebugf("getProps failed unexpectedly.\n");
|
|
|
|
}
|
|
|
|
SkDebugf("isRGB:%d\n", SkPixelGeometryIsRGB(surfaceProps.pixelGeometry()));
|
|
|
|
|
|
|
|
#StdOut
|
|
|
|
isRGB:0
|
|
|
|
isRGB:1
|
|
|
|
#StdOut ##
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso SkSurfaceProps makeSurface
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
2018-02-07 12:27:09 +00:00
|
|
|
#Subtopic Utility
|
|
|
|
#Populate
|
|
|
|
#Line # rarely called management functions ##
|
|
|
|
##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Method void flush()
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Utility
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # triggers execution of all pending draw operations ##
|
2018-02-07 01:58:51 +00:00
|
|
|
Triggers the immediate execution of all pending draw operations.
|
2017-08-03 21:14:08 +00:00
|
|
|
If Canvas is associated with GPU_Surface, resolves all pending GPU operations.
|
2017-11-02 21:49:34 +00:00
|
|
|
If Canvas is associated with Raster_Surface, has no effect; raster draw
|
|
|
|
operations are never deferred.
|
|
|
|
|
|
|
|
#ToDo
|
|
|
|
In an overview section on managing the GPU, include:
|
|
|
|
- flush should never change what is drawn
|
|
|
|
- call to kick off gpu work
|
|
|
|
- calling too much impacts performance
|
|
|
|
- some calls (peekPixels, prepareForExternalIO) call it internally
|
|
|
|
- canvas call is local, GrContext::flush is global
|
|
|
|
- diffentiate between flush, flushAndSignalSemaphores
|
|
|
|
- normally never needs to be called
|
|
|
|
- call it when sharing gpu resources, feeling memory pressure, swapping out app, and before
|
|
|
|
abandoning context
|
|
|
|
- also call to say "I'm finished drawing here", e.g., when drawing to a GPU-backed offscreen surface
|
|
|
|
(created with SkSurface::MakeRenderTarget)
|
|
|
|
|
|
|
|
for posterity: this doesn't show a difference: fiddle.skia.org/c/@flushfail
|
|
|
|
##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-02-01 14:37:32 +00:00
|
|
|
#ToDo haven't thought of a useful example to put here ##
|
|
|
|
#NoExample
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso peekPixels SkSurface::flush() GrContext::flush() SkSurface::prepareForExternalIO GrContext::abandonContext()
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method virtual SkISize getBaseLayerSize() const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns size of base Layer in global coordinates ##
|
2017-09-01 19:51:02 +00:00
|
|
|
Gets the size of the base or root Layer in global canvas coordinates. The
|
|
|
|
origin of the base Layer is always (0,0). The area available for drawing may be
|
2017-07-28 15:04:54 +00:00
|
|
|
smaller (due to clipping or saveLayer).
|
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
#Return integral width and height of base Layer ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.allocPixels(SkImageInfo::MakeN32Premul(20, 30));
|
|
|
|
SkCanvas canvas(bitmap, SkSurfaceProps(0, kUnknown_SkPixelGeometry));
|
|
|
|
canvas.clipRect(SkRect::MakeWH(10, 40));
|
|
|
|
SkIRect clipDeviceBounds = canvas.getDeviceClipBounds();
|
|
|
|
if (clipDeviceBounds.isEmpty()) {
|
|
|
|
SkDebugf("Empty clip bounds is unexpected!\n");
|
|
|
|
}
|
|
|
|
SkDebugf("clip=%d,%d\n", clipDeviceBounds.width(), clipDeviceBounds.height());
|
|
|
|
SkISize baseLayerSize = canvas.getBaseLayerSize();
|
|
|
|
SkDebugf("size=%d,%d\n", baseLayerSize.width(), baseLayerSize.height());
|
|
|
|
|
|
|
|
#StdOut
|
|
|
|
clip=10,30
|
|
|
|
size=20,30
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
|
|
|
#ToDo is this the same as the width and height of surface? ##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso getDeviceClipBounds
|
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method sk_sp<SkSurface> makeSurface(const SkImageInfo& info, const SkSurfaceProps* props = nullptr)
|
2018-02-06 14:41:53 +00:00
|
|
|
#In Constructor
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # creates Surface matching SkImageInfo and SkSurfaceProps ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Creates Surface matching info and props, and associates it with Canvas.
|
2017-08-03 21:14:08 +00:00
|
|
|
Returns nullptr if no match found.
|
|
|
|
|
|
|
|
If props is nullptr, matches Surface_Properties in Canvas. If props is nullptr and Canvas
|
|
|
|
does not have Surface_Properties, creates Surface with default Surface_Properties.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-01-26 17:56:22 +00:00
|
|
|
#Param info width, height, Color_Type, Alpha_Type, and Color_Space ##
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param props Surface_Properties to match; may be nullptr to match Canvas ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Return Surface matching info and props, or nullptr if no match is available ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(5, 6);
|
|
|
|
SkCanvas* smallCanvas = surface->getCanvas();
|
|
|
|
SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(3, 4);
|
|
|
|
sk_sp<SkSurface> compatible = smallCanvas->makeSurface(imageInfo);
|
|
|
|
SkDebugf("compatible %c= nullptr\n", compatible == nullptr ? '=' : '!');
|
|
|
|
SkDebugf("size = %d, %d\n", compatible->width(), compatible->height());
|
|
|
|
|
|
|
|
#StdOut
|
2017-08-03 21:14:08 +00:00
|
|
|
compatible != nullptr
|
2017-07-28 15:04:54 +00:00
|
|
|
size = 3, 4
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso SkSurface SkSurface::makeSurface SkImageInfo SkSurfaceProps
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method virtual GrContext* getGrContext()
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns GPU_Context of the GPU_Surface ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Returns GPU_Context of the GPU_Surface associated with Canvas.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Return GPU_Context, if available; nullptr otherwise ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
if (canvas->getGrContext()) {
|
|
|
|
canvas->clear(SK_ColorRED);
|
|
|
|
} else {
|
|
|
|
canvas->clear(SK_ColorBLUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
##
|
|
|
|
|
|
|
|
#ToDo fiddle should show both CPU and GPU out ##
|
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
#SeeAlso GrContext
|
2017-11-02 21:49:34 +00:00
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2017-08-29 21:36:51 +00:00
|
|
|
#Method void* accessTopLayerPixels(SkImageInfo* info, size_t* rowBytes, SkIPoint* origin = nullptr)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Utility
|
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns writable pixel access if available ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Returns the pixel base address, Image_Info, rowBytes, and origin if the pixels
|
2017-08-03 21:14:08 +00:00
|
|
|
can be read directly. The returned address is only valid
|
2017-07-28 15:04:54 +00:00
|
|
|
while Canvas is in scope and unchanged. Any Canvas call or Surface call
|
|
|
|
may invalidate the returned address and other returned values.
|
|
|
|
|
|
|
|
If pixels are inaccessible, info, rowBytes, and origin are unchanged.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param info storage for writable pixels' Image_Info; may be nullptr ##
|
|
|
|
#Param rowBytes storage for writable pixels' row bytes; may be nullptr ##
|
2017-10-04 18:31:33 +00:00
|
|
|
#Param origin storage for Canvas top Layer origin, its top-left corner;
|
2017-08-03 21:14:08 +00:00
|
|
|
may be nullptr
|
|
|
|
##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-30 12:58:10 +00:00
|
|
|
#Return address of pixels, or nullptr if inaccessible ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
if (canvas->accessTopLayerPixels(nullptr, nullptr)) {
|
|
|
|
canvas->clear(SK_ColorRED);
|
|
|
|
} else {
|
|
|
|
canvas->clear(SK_ColorBLUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
##
|
|
|
|
|
|
|
|
#Example
|
|
|
|
#Description
|
2017-09-01 19:51:02 +00:00
|
|
|
Draws "ABC" on the device. Then draws "DEF" in Layer, and reads
|
|
|
|
Layer to add a large dotted "DEF". Finally blends Layer with the
|
2018-02-07 01:58:51 +00:00
|
|
|
device.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
The Layer and blended result appear on the CPU and GPU but the large dotted
|
2017-07-28 15:04:54 +00:00
|
|
|
"DEF" appear only on the CPU.
|
|
|
|
##
|
|
|
|
void draw(SkCanvas* canvas) {
|
2017-08-03 21:14:08 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setTextSize(100);
|
|
|
|
canvas->drawString("ABC", 20, 160, paint);
|
|
|
|
SkRect layerBounds = SkRect::MakeXYWH(32, 32, 192, 192);
|
|
|
|
canvas->saveLayerAlpha(&layerBounds, 128);
|
|
|
|
canvas->clear(SK_ColorWHITE);
|
|
|
|
canvas->drawString("DEF", 20, 160, paint);
|
|
|
|
SkImageInfo imageInfo;
|
|
|
|
size_t rowBytes;
|
|
|
|
SkIPoint origin;
|
|
|
|
uint32_t* access = (uint32_t*) canvas->accessTopLayerPixels(&imageInfo, &rowBytes, &origin);
|
|
|
|
if (access) {
|
|
|
|
int h = imageInfo.height();
|
|
|
|
int v = imageInfo.width();
|
|
|
|
int rowWords = rowBytes / sizeof(uint32_t);
|
|
|
|
for (int y = 0; y < h; ++y) {
|
|
|
|
int newY = (y - h / 2) * 2 + h / 2;
|
|
|
|
if (newY < 0 || newY >= h) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (int x = 0; x < v; ++x) {
|
|
|
|
int newX = (x - v / 2) * 2 + v / 2;
|
|
|
|
if (newX < 0 || newX >= v) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (access[y * rowWords + x] == SK_ColorBLACK) {
|
|
|
|
access[newY * rowWords + newX] = SK_ColorGRAY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
##
|
|
|
|
|
|
|
|
#ToDo there are no callers of this that I can find. Deprecate? ##
|
|
|
|
#ToDo fiddle should show both CPU and GPU out ##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso SkImageInfo SkPixmap
|
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method SkRasterHandleAllocator::Handle accessTopRasterHandle() const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Utility
|
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns context that tracks Clip and Matrix ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Returns custom context that tracks the Matrix and Clip.
|
|
|
|
|
|
|
|
Use Raster_Handle_Allocator to blend Skia drawing with custom drawing, typically performed
|
2017-10-04 18:31:33 +00:00
|
|
|
by the host platform user interface. The custom context returned is generated by
|
2017-08-03 21:14:08 +00:00
|
|
|
SkRasterHandleAllocator::MakeCanvas, which creates a custom canvas with raster storage for
|
2017-07-28 15:04:54 +00:00
|
|
|
the drawing destination.
|
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
#Return context of custom allocation ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Description
|
|
|
|
#ToDo ##
|
|
|
|
##
|
|
|
|
#Function
|
|
|
|
static void DeleteCallback(void*, void* context) {
|
|
|
|
delete (char*) context;
|
|
|
|
}
|
|
|
|
|
|
|
|
class CustomAllocator : public SkRasterHandleAllocator {
|
|
|
|
public:
|
|
|
|
bool allocHandle(const SkImageInfo& info, Rec* rec) override {
|
|
|
|
char* context = new char[4]{'s', 'k', 'i', 'a'};
|
|
|
|
rec->fReleaseProc = DeleteCallback;
|
|
|
|
rec->fReleaseCtx = context;
|
|
|
|
rec->fHandle = context;
|
|
|
|
rec->fPixels = context;
|
|
|
|
rec->fRowBytes = 4;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateHandle(Handle handle, const SkMatrix& ctm, const SkIRect& clip_bounds) override {
|
|
|
|
// apply canvas matrix and clip to custom environment
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
##
|
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
const SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1);
|
|
|
|
std::unique_ptr<SkCanvas> c2 =
|
|
|
|
SkRasterHandleAllocator::MakeCanvas(std::unique_ptr<CustomAllocator>(
|
|
|
|
new CustomAllocator()), info);
|
|
|
|
char* context = (char*) c2->accessTopRasterHandle();
|
|
|
|
SkDebugf("context = %.4s\n", context);
|
|
|
|
|
|
|
|
}
|
|
|
|
#StdOut
|
|
|
|
context = skia
|
|
|
|
##
|
|
|
|
#ToDo skstd::make_unique could not be used because def is private -- note to fix in c++14? ##
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso SkRasterHandleAllocator
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
2018-02-07 12:27:09 +00:00
|
|
|
#Subtopic Pixels
|
|
|
|
#Populate
|
|
|
|
#Line # read and write pixel values ##
|
|
|
|
##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Method bool peekPixels(SkPixmap* pixmap)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Pixels
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns if Canvas has direct access to its pixels ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Returns true if Canvas has direct access to its pixels.
|
|
|
|
|
2017-08-24 16:59:48 +00:00
|
|
|
Pixels are readable when Device is raster. Pixels are not readable when Canvas
|
2017-08-03 21:14:08 +00:00
|
|
|
is returned from GPU_Surface, returned by SkDocument::beginPage, returned by
|
2017-08-24 16:59:48 +00:00
|
|
|
SkPictureRecorder::beginRecording, or Canvas is the base of a utility class
|
2017-08-03 21:14:08 +00:00
|
|
|
like SkDumpCanvas.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-24 16:59:48 +00:00
|
|
|
pixmap is valid only while Canvas is in scope and unchanged. Any
|
2017-08-03 21:14:08 +00:00
|
|
|
Canvas or Surface call may invalidate the pixmap values.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-10-04 18:31:33 +00:00
|
|
|
#Param pixmap storage for pixel state if pixels are readable; otherwise, ignored ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Return true if Canvas has direct access to pixels ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
SkPixmap pixmap;
|
|
|
|
if (canvas->peekPixels(&pixmap)) {
|
|
|
|
SkDebugf("width=%d height=%d\n", pixmap.bounds().width(), pixmap.bounds().height());
|
|
|
|
}
|
|
|
|
#StdOut
|
|
|
|
width=256 height=256
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso readPixels SkBitmap::peekPixels SkImage::peekPixels SkSurface::peekPixels
|
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
|
|
|
|
int srcX, int srcY)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Pixels
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # copies and converts rectangle of pixels from Canvas ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-10-26 11:58:48 +00:00
|
|
|
Copies Rect of pixels from Canvas into dstPixels. Matrix and Clip are
|
2018-02-07 01:58:51 +00:00
|
|
|
ignored.
|
2017-09-21 16:31:06 +00:00
|
|
|
|
2017-11-27 15:44:06 +00:00
|
|
|
Source Rect corners are (srcX, srcY) and (imageInfo().width(), imageInfo().height()).
|
|
|
|
Destination Rect corners are (0, 0) and (dstInfo.width(), dstInfo.height()).
|
2017-09-21 16:31:06 +00:00
|
|
|
Copies each readable pixel intersecting both rectangles, without scaling,
|
2017-08-24 16:59:48 +00:00
|
|
|
converting to dstInfo.colorType() and dstInfo.alphaType() if required.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-24 16:59:48 +00:00
|
|
|
Pixels are readable when Device is raster, or backed by a GPU.
|
|
|
|
Pixels are not readable when SkCanvas is returned by SkDocument::beginPage,
|
|
|
|
returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility
|
|
|
|
class like SkDumpCanvas.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-24 16:59:48 +00:00
|
|
|
The destination pixel storage must be allocated by the caller.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-01-26 17:56:22 +00:00
|
|
|
Pixel values are converted only if Color_Type and Alpha_Type
|
2017-08-24 16:59:48 +00:00
|
|
|
do not match. Only pixels within both source and destination rectangles
|
2017-10-26 11:58:48 +00:00
|
|
|
are copied. dstPixels contents outside Rect intersection are unchanged.
|
2017-08-24 16:59:48 +00:00
|
|
|
|
|
|
|
Pass negative values for srcX or srcY to offset pixels across or down destination.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Does not copy, and returns false if:
|
|
|
|
|
|
|
|
#List
|
2017-08-24 16:59:48 +00:00
|
|
|
# Source and destination rectangles do not intersect. ##
|
|
|
|
# Canvas pixels could not be converted to dstInfo.colorType() or dstInfo.alphaType(). ##
|
|
|
|
# Canvas pixels are not readable; for instance, Canvas is document-based. ##
|
2017-07-28 15:04:54 +00:00
|
|
|
# dstRowBytes is too small to contain one row of pixels. ##
|
|
|
|
##
|
|
|
|
|
2018-01-26 17:56:22 +00:00
|
|
|
#Param dstInfo width, height, Color_Type, and Alpha_Type of dstPixels ##
|
2017-08-24 16:59:48 +00:00
|
|
|
#Param dstPixels storage for pixels; dstInfo.height() times dstRowBytes, or larger ##
|
|
|
|
#Param dstRowBytes size of one destination row; dstInfo.width() times pixel size, or larger ##
|
|
|
|
#Param srcX offset into readable pixels in x; may be negative ##
|
|
|
|
#Param srcY offset into readable pixels in y; may be negative ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Return true if pixels were copied ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-24 16:59:48 +00:00
|
|
|
#Example
|
|
|
|
#Width 64
|
|
|
|
#Height 64
|
|
|
|
#Description
|
|
|
|
A black circle drawn on a blue background provides an image to copy.
|
|
|
|
readPixels copies one quarter of the canvas into each of the four corners.
|
2017-11-27 15:44:06 +00:00
|
|
|
The copied quarter circles overdraw the original circle.
|
2017-08-24 16:59:48 +00:00
|
|
|
##
|
|
|
|
canvas->clear(SK_ColorBLUE);
|
|
|
|
SkPaint paint;
|
|
|
|
canvas->drawCircle(32, 32, 28, paint);
|
|
|
|
SkImageInfo info = SkImageInfo::Make(64, 64, kBGRA_8888_SkColorType, kPremul_SkAlphaType);
|
|
|
|
sk_sp<SkData> data(SkData::MakeUninitialized(info.minRowBytes() * info.height()));
|
|
|
|
sk_bzero(data->writable_data(), info.minRowBytes() * info.height());
|
|
|
|
for (int x : { 32, -32 } ) {
|
|
|
|
for (int y : { 32, -32 } ) {
|
|
|
|
canvas->readPixels(info, data->writable_data(), info.minRowBytes(), x, y);
|
2018-02-07 01:58:51 +00:00
|
|
|
}
|
2017-08-24 16:59:48 +00:00
|
|
|
}
|
|
|
|
sk_sp<SkImage> image = SkImage::MakeRasterData(info, data, info.minRowBytes());
|
|
|
|
canvas->drawImage(image, 0, 0);
|
|
|
|
##
|
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
#Example
|
|
|
|
#Description
|
2017-09-01 19:51:02 +00:00
|
|
|
Canvas returned by Raster_Surface has Premultiplied pixel values.
|
|
|
|
clear() takes Unpremultiplied input with Color_Alpha equal 0x80
|
|
|
|
and Color_RGB equal 0x55, 0xAA, 0xFF. Color_RGB is multiplied by Color_Alpha
|
|
|
|
to generate Premultiplied value 0x802B5580. readPixels converts pixel back
|
|
|
|
to Unpremultiplied value 0x8056A9FF, introducing error.
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
canvas->clear(0x8055aaff);
|
|
|
|
for (SkAlphaType alphaType : { kPremul_SkAlphaType, kUnpremul_SkAlphaType } ) {
|
|
|
|
uint32_t pixel = 0;
|
|
|
|
SkImageInfo info = SkImageInfo::Make(1, 1, kBGRA_8888_SkColorType, alphaType);
|
|
|
|
if (canvas->readPixels(info, &pixel, 4, 0, 0)) {
|
|
|
|
SkDebugf("pixel = %08x\n", pixel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#StdOut
|
|
|
|
pixel = 802b5580
|
|
|
|
pixel = 8056a9ff
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso peekPixels writePixels drawBitmap drawImage SkBitmap::readPixels SkPixmap::readPixels SkImage::readPixels SkSurface::readPixels
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method bool readPixels(const SkPixmap& pixmap, int srcX, int srcY)
|
|
|
|
|
2017-10-26 11:58:48 +00:00
|
|
|
Copies Rect of pixels from Canvas into pixmap. Matrix and Clip are
|
2017-11-27 15:44:06 +00:00
|
|
|
ignored.
|
2017-09-21 16:31:06 +00:00
|
|
|
|
2017-11-27 15:44:06 +00:00
|
|
|
Source Rect corners are (srcX, srcY) and (imageInfo().width(), imageInfo().height()).
|
|
|
|
Destination Rect corners are (0, 0) and (pixmap.width(), pixmap.height()).
|
2017-09-21 16:31:06 +00:00
|
|
|
Copies each readable pixel intersecting both rectangles, without scaling,
|
2017-08-24 16:59:48 +00:00
|
|
|
converting to pixmap.colorType() and pixmap.alphaType() if required.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-24 16:59:48 +00:00
|
|
|
Pixels are readable when Device is raster, or backed by a GPU.
|
|
|
|
Pixels are not readable when SkCanvas is returned by SkDocument::beginPage,
|
|
|
|
returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility
|
|
|
|
class like SkDumpCanvas.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-09-21 16:31:06 +00:00
|
|
|
Caller must allocate pixel storage in pixmap if needed.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-01-26 17:56:22 +00:00
|
|
|
Pixel values are converted only if Color_Type and Alpha_Type
|
2017-10-26 11:58:48 +00:00
|
|
|
do not match. Only pixels within both source and destination Rects
|
|
|
|
are copied. pixmap pixels contents outside Rect intersection are unchanged.
|
2017-08-24 16:59:48 +00:00
|
|
|
|
|
|
|
Pass negative values for srcX or srcY to offset pixels across or down pixmap.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Does not copy, and returns false if:
|
|
|
|
|
|
|
|
#List
|
2017-08-24 16:59:48 +00:00
|
|
|
# Source and destination rectangles do not intersect. ##
|
|
|
|
# Canvas pixels could not be converted to pixmap.colorType() or pixmap.alphaType(). ##
|
|
|
|
# Canvas pixels are not readable; for instance, Canvas is document-based. ##
|
|
|
|
# Pixmap pixels could not be allocated. ##
|
|
|
|
# pixmap.rowBytes() is too small to contain one row of pixels. ##
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param pixmap storage for pixels copied from Canvas ##
|
2017-08-24 16:59:48 +00:00
|
|
|
#Param srcX offset into readable pixels in x; may be negative ##
|
|
|
|
#Param srcY offset into readable pixels in y; may be negative ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Return true if pixels were copied ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2017-08-24 16:59:48 +00:00
|
|
|
#Description
|
2017-09-01 19:51:02 +00:00
|
|
|
clear() takes Unpremultiplied input with Color_Alpha equal 0x80
|
|
|
|
and Color_RGB equal 0x55, 0xAA, 0xFF. Color_RGB is multiplied by Color_Alpha
|
|
|
|
to generate Premultiplied value 0x802B5580.
|
2017-08-24 16:59:48 +00:00
|
|
|
##
|
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
canvas->clear(0x8055aaff);
|
|
|
|
uint32_t pixels[1] = { 0 };
|
|
|
|
SkPixmap pixmap(SkImageInfo::MakeN32Premul(1, 1), pixels, 4);
|
|
|
|
canvas->readPixels(pixmap, 0, 0);
|
|
|
|
SkDebugf("pixel = %08x\n", pixels[0]);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
#StdOut
|
|
|
|
pixel = 802b5580
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso peekPixels writePixels drawBitmap drawImage SkBitmap::readPixels SkPixmap::readPixels SkImage::readPixels SkSurface::readPixels
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method bool readPixels(const SkBitmap& bitmap, int srcX, int srcY)
|
|
|
|
|
2017-10-26 11:58:48 +00:00
|
|
|
Copies Rect of pixels from Canvas into bitmap. Matrix and Clip are
|
2017-11-27 15:44:06 +00:00
|
|
|
ignored.
|
2017-09-21 16:31:06 +00:00
|
|
|
|
2017-11-27 15:44:06 +00:00
|
|
|
Source Rect corners are (srcX, srcY) and (imageInfo().width(), imageInfo().height()).
|
2017-10-26 11:58:48 +00:00
|
|
|
Destination Rect corners are (0, 0) and (bitmap.width(), bitmap.height()).
|
2017-08-24 16:59:48 +00:00
|
|
|
Copies each readable pixel intersecting both rectangles, without scaling,
|
|
|
|
converting to bitmap.colorType() and bitmap.alphaType() if required.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-24 16:59:48 +00:00
|
|
|
Pixels are readable when Device is raster, or backed by a GPU.
|
|
|
|
Pixels are not readable when SkCanvas is returned by SkDocument::beginPage,
|
|
|
|
returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility
|
|
|
|
class like SkDumpCanvas.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-09-21 16:31:06 +00:00
|
|
|
Caller must allocate pixel storage in bitmap if needed.
|
2017-08-24 16:59:48 +00:00
|
|
|
|
2018-01-26 17:56:22 +00:00
|
|
|
Bitmap values are converted only if Color_Type and Alpha_Type
|
2017-08-24 16:59:48 +00:00
|
|
|
do not match. Only pixels within both source and destination rectangles
|
2017-10-26 11:58:48 +00:00
|
|
|
are copied. Bitmap pixels outside Rect intersection are unchanged.
|
2017-08-24 16:59:48 +00:00
|
|
|
|
|
|
|
Pass negative values for srcX or srcY to offset pixels across or down bitmap.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Does not copy, and returns false if:
|
|
|
|
|
|
|
|
#List
|
2017-08-24 16:59:48 +00:00
|
|
|
# Source and destination rectangles do not intersect. ##
|
|
|
|
# Canvas pixels could not be converted to bitmap.colorType() or bitmap.alphaType(). ##
|
|
|
|
# Canvas pixels are not readable; for instance, Canvas is document-based. ##
|
2017-07-28 15:04:54 +00:00
|
|
|
# bitmap pixels could not be allocated. ##
|
2017-08-24 16:59:48 +00:00
|
|
|
# bitmap.rowBytes() is too small to contain one row of pixels. ##
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param bitmap storage for pixels copied from Canvas ##
|
2017-08-24 16:59:48 +00:00
|
|
|
#Param srcX offset into readable pixels in x; may be negative ##
|
|
|
|
#Param srcY offset into readable pixels in y; may be negative ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Return true if pixels were copied ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2017-08-24 16:59:48 +00:00
|
|
|
#Description
|
2017-09-01 19:51:02 +00:00
|
|
|
clear() takes Unpremultiplied input with Color_Alpha equal 0x80
|
|
|
|
and Color_RGB equal 0x55, 0xAA, 0xFF. Color_RGB is multiplied by Color_Alpha
|
|
|
|
to generate Premultiplied value 0x802B5580.
|
2017-08-24 16:59:48 +00:00
|
|
|
##
|
2017-07-28 15:04:54 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
canvas->clear(0x8055aaff);
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.allocPixels(SkImageInfo::MakeN32Premul(1, 1));
|
|
|
|
canvas->readPixels(bitmap, 0, 0);
|
|
|
|
SkDebugf("pixel = %08x\n", bitmap.getAddr32(0, 0)[0]);
|
|
|
|
}
|
|
|
|
#StdOut
|
|
|
|
pixel = 802b5580
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso peekPixels writePixels drawBitmap drawImage SkBitmap::readPixels SkPixmap::readPixels SkImage::readPixels SkSurface::readPixels
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method bool writePixels(const SkImageInfo& info, const void* pixels, size_t rowBytes, int x, int y)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Pixels
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # copies and converts rectangle of pixels to Canvas ##
|
2017-10-26 11:58:48 +00:00
|
|
|
Copies Rect from pixels to Canvas. Matrix and Clip are ignored.
|
|
|
|
Source Rect corners are (0, 0) and (info.width(), info.height()).
|
|
|
|
Destination Rect corners are (x, y) and
|
|
|
|
(imageInfo().width(), imageInfo().height()).
|
2017-09-21 16:31:06 +00:00
|
|
|
|
|
|
|
Copies each readable pixel intersecting both rectangles, without scaling,
|
2017-10-26 11:58:48 +00:00
|
|
|
converting to imageInfo().colorType() and imageInfo().alphaType() if required.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-24 16:59:48 +00:00
|
|
|
Pixels are writable when Device is raster, or backed by a GPU.
|
|
|
|
Pixels are not writable when SkCanvas is returned by SkDocument::beginPage,
|
|
|
|
returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility
|
|
|
|
class like SkDumpCanvas.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-01-26 17:56:22 +00:00
|
|
|
Pixel values are converted only if Color_Type and Alpha_Type
|
2017-08-24 16:59:48 +00:00
|
|
|
do not match. Only pixels within both source and destination rectangles
|
2017-10-26 11:58:48 +00:00
|
|
|
are copied. Canvas pixels outside Rect intersection are unchanged.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-24 16:59:48 +00:00
|
|
|
Pass negative values for x or y to offset pixels to the left or
|
|
|
|
above Canvas pixels.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Does not copy, and returns false if:
|
|
|
|
|
|
|
|
#List
|
2017-08-24 16:59:48 +00:00
|
|
|
# Source and destination rectangles do not intersect. ##
|
2018-01-11 15:35:44 +00:00
|
|
|
# pixels could not be converted to Canvas imageInfo().colorType() or
|
|
|
|
imageInfo().alphaType(). ##
|
2017-07-28 15:04:54 +00:00
|
|
|
# Canvas pixels are not writable; for instance, Canvas is document-based. ##
|
|
|
|
# rowBytes is too small to contain one row of pixels. ##
|
|
|
|
##
|
|
|
|
|
2018-01-26 17:56:22 +00:00
|
|
|
#Param info width, height, Color_Type, and Alpha_Type of pixels ##
|
2017-08-24 16:59:48 +00:00
|
|
|
#Param pixels pixels to copy, of size info.height() times rowBytes, or larger ##
|
2017-09-14 15:25:39 +00:00
|
|
|
#Param rowBytes size of one row of pixels; info.width() times pixel size, or larger ##
|
2017-08-24 16:59:48 +00:00
|
|
|
#Param x offset into Canvas writable pixels in x; may be negative ##
|
|
|
|
#Param y offset into Canvas writable pixels in y; may be negative ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Return true if pixels were written to Canvas ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
SkImageInfo imageInfo = SkImageInfo::MakeN32(256, 1, kPremul_SkAlphaType);
|
|
|
|
for (int y = 0; y < 256; ++y) {
|
|
|
|
uint32_t pixels[256];
|
|
|
|
for (int x = 0; x < 256; ++x) {
|
|
|
|
pixels[x] = SkColorSetARGB(x, x + y, x, x - y);
|
|
|
|
}
|
|
|
|
canvas->writePixels(imageInfo, &pixels, sizeof(pixels), 0, y);
|
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso readPixels drawBitmap drawImage SkBitmap::writePixels
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method bool writePixels(const SkBitmap& bitmap, int x, int y)
|
|
|
|
|
2017-10-26 11:58:48 +00:00
|
|
|
Copies Rect from pixels to Canvas. Matrix and Clip are ignored.
|
|
|
|
Source Rect corners are (0, 0) and (bitmap.width(), bitmap.height()).
|
2017-09-21 16:31:06 +00:00
|
|
|
|
2017-10-26 11:58:48 +00:00
|
|
|
Destination Rect corners are (x, y) and
|
|
|
|
(imageInfo().width(), imageInfo().height()).
|
2017-09-21 16:31:06 +00:00
|
|
|
|
|
|
|
Copies each readable pixel intersecting both rectangles, without scaling,
|
2017-10-26 11:58:48 +00:00
|
|
|
converting to imageInfo().colorType() and imageInfo().alphaType() if required.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-24 16:59:48 +00:00
|
|
|
Pixels are writable when Device is raster, or backed by a GPU.
|
|
|
|
Pixels are not writable when SkCanvas is returned by SkDocument::beginPage,
|
|
|
|
returned by SkPictureRecorder::beginRecording, or Canvas is the base of a utility
|
|
|
|
class like SkDumpCanvas.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-01-26 17:56:22 +00:00
|
|
|
Pixel values are converted only if Color_Type and Alpha_Type
|
2017-08-24 16:59:48 +00:00
|
|
|
do not match. Only pixels within both source and destination rectangles
|
2017-10-26 11:58:48 +00:00
|
|
|
are copied. Canvas pixels outside Rect intersection are unchanged.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-24 16:59:48 +00:00
|
|
|
Pass negative values for x or y to offset pixels to the left or
|
|
|
|
above Canvas pixels.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Does not copy, and returns false if:
|
|
|
|
|
|
|
|
#List
|
2017-08-24 16:59:48 +00:00
|
|
|
# Source and destination rectangles do not intersect. ##
|
2017-07-28 15:04:54 +00:00
|
|
|
# bitmap does not have allocated pixels. ##
|
2018-01-11 15:35:44 +00:00
|
|
|
# bitmap pixels could not be converted to Canvas imageInfo().colorType() or
|
|
|
|
imageInfo().alphaType(). ##
|
2017-09-01 19:51:02 +00:00
|
|
|
# Canvas pixels are not writable; for instance, Canvas is document based. ##
|
2017-07-28 15:04:54 +00:00
|
|
|
# bitmap pixels are inaccessible; for instance, bitmap wraps a texture. ##
|
|
|
|
##
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param bitmap contains pixels copied to Canvas ##
|
2017-08-24 16:59:48 +00:00
|
|
|
#Param x offset into Canvas writable pixels in x; may be negative ##
|
|
|
|
#Param y offset into Canvas writable pixels in y; may be negative ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Return true if pixels were written to Canvas ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(2, 2);
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.setInfo(imageInfo);
|
|
|
|
uint32_t pixels[4];
|
|
|
|
bitmap.setPixels(pixels);
|
|
|
|
for (int y = 0; y < 256; y += 2) {
|
|
|
|
for (int x = 0; x < 256; x += 2) {
|
|
|
|
pixels[0] = SkColorSetRGB(x, y, x | y);
|
|
|
|
pixels[1] = SkColorSetRGB(x ^ y, y, x);
|
|
|
|
pixels[2] = SkColorSetRGB(x, x & y, y);
|
|
|
|
pixels[3] = SkColorSetRGB(~x, ~y, x);
|
|
|
|
canvas->writePixels(bitmap, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso readPixels drawBitmap drawImage SkBitmap::writePixels
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
2018-02-01 14:37:32 +00:00
|
|
|
#Subtopic State_Stack
|
|
|
|
#Line # stack of state for hierarchical drawing ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Canvas maintains a stack of state that allows hierarchical drawing, commonly used
|
2017-08-03 21:14:08 +00:00
|
|
|
to implement windows and views. The initial state has an identity matrix and and
|
|
|
|
an infinite clip. Even with a wide-open clip, drawing is constrained by the
|
|
|
|
bounds of the Canvas Surface or Device.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Canvas savable state consists of Clip, Matrix, and Draw_Filter.
|
|
|
|
Clip describes the area that may be drawn to.
|
|
|
|
Matrix transforms the geometry.
|
|
|
|
Draw_Filter (deprecated on most platforms) modifies the paint before drawing.
|
|
|
|
|
|
|
|
save(), saveLayer, saveLayerPreserveLCDTextRequests, and saveLayerAlpha
|
|
|
|
save state and return the depth of the stack.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
restore(), restoreToCount, and ~SkCanvas() revert state to its value when saved.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Each state on the stack intersects Clip with the previous Clip,
|
|
|
|
and concatenates Matrix with the previous Matrix.
|
|
|
|
The intersected Clip makes the drawing area the same or smaller;
|
|
|
|
the concatenated Matrix may move the origin and potentially scale or rotate
|
|
|
|
the coordinate space.
|
|
|
|
|
|
|
|
Canvas does not require balancing the state stack but it is a good idea
|
|
|
|
to do so. Calling save() without restore() will eventually cause Skia to fail;
|
|
|
|
mismatched save() and restore() create hard to find bugs.
|
|
|
|
|
|
|
|
It is not possible to use state to draw outside of the clip defined by the
|
|
|
|
previous state.
|
|
|
|
|
|
|
|
#Example
|
|
|
|
#Description
|
|
|
|
Draw to ever smaller clips; then restore drawing to full canvas.
|
|
|
|
Note that the second clipRect is not permitted to enlarge Clip.
|
|
|
|
##
|
|
|
|
#Height 160
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
2018-02-07 01:58:51 +00:00
|
|
|
canvas->save(); // records stack depth to restore
|
2017-08-03 21:14:08 +00:00
|
|
|
canvas->clipRect(SkRect::MakeWH(100, 100)); // constrains drawing to clip
|
|
|
|
canvas->clear(SK_ColorRED); // draws to limit of clip
|
2018-02-07 01:58:51 +00:00
|
|
|
canvas->save(); // records stack depth to restore
|
2017-08-03 21:14:08 +00:00
|
|
|
canvas->clipRect(SkRect::MakeWH(50, 150)); // Rect below 100 is ignored
|
|
|
|
canvas->clear(SK_ColorBLUE); // draws to smaller clip
|
|
|
|
canvas->restore(); // enlarges clip
|
|
|
|
canvas->drawLine(20, 20, 150, 150, paint); // line below 100 is not drawn
|
|
|
|
canvas->restore(); // enlarges clip
|
|
|
|
canvas->drawLine(150, 20, 50, 120, paint); // line below 100 is drawn
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
2018-02-07 01:58:51 +00:00
|
|
|
##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Each Clip uses the current Matrix for its coordinates.
|
|
|
|
|
|
|
|
#Example
|
|
|
|
#Description
|
|
|
|
While clipRect is given the same rectangle twice, Matrix makes the second
|
|
|
|
clipRect draw at half the size of the first.
|
|
|
|
##
|
|
|
|
#Height 128
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
canvas->clipRect(SkRect::MakeWH(100, 100));
|
|
|
|
canvas->clear(SK_ColorRED);
|
|
|
|
canvas->scale(.5, .5);
|
|
|
|
canvas->clipRect(SkRect::MakeWH(100, 100));
|
|
|
|
canvas->clear(SK_ColorBLUE);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
|
|
|
#SeeAlso save() saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha restore() restoreToCount
|
|
|
|
|
|
|
|
#Method int save()
|
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#In State_Stack
|
|
|
|
#Line # saves Clip and Matrix on stack ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Saves Matrix, Clip, and Draw_Filter (Draw_Filter deprecated on most platforms).
|
|
|
|
Calling restore() discards changes to Matrix, Clip, and Draw_Filter,
|
|
|
|
restoring the Matrix, Clip, and Draw_Filter to their state when save() was called.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
Matrix may be changed by translate(), scale(), rotate(), skew(), concat(), setMatrix,
|
|
|
|
and resetMatrix. Clip may be changed by clipRect, clipRRect, clipPath, clipRegion.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
Saved Canvas state is put on a stack; multiple calls to save() should be balance
|
|
|
|
by an equal number of calls to restore().
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Call restoreToCount with result to restore this and subsequent saves.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Return depth of saved stack ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2018-02-07 01:58:51 +00:00
|
|
|
#Description
|
2017-07-28 15:04:54 +00:00
|
|
|
The black square is translated 50 pixels down and to the right.
|
|
|
|
Restoring Canvas state removes translate() from Canvas stack;
|
|
|
|
the red square is not translated, and is drawn at the origin.
|
|
|
|
##
|
|
|
|
#Height 100
|
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
|
|
|
SkRect rect = { 0, 0, 25, 25 };
|
|
|
|
canvas->drawRect(rect, paint);
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(50, 50);
|
|
|
|
canvas->drawRect(rect, paint);
|
|
|
|
canvas->restore();
|
|
|
|
paint.setColor(SK_ColorRED);
|
|
|
|
canvas->drawRect(rect, paint);
|
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha restore() restoreToCount
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
#Method void restore()
|
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#In State_Stack
|
|
|
|
#Line # restores changes to Clip and Matrix, pops save stack ##
|
2017-09-01 19:51:02 +00:00
|
|
|
Removes changes to Matrix, Clip, and Draw_Filter since Canvas state was
|
2018-02-07 01:58:51 +00:00
|
|
|
last saved. The state is removed from the stack.
|
2017-09-01 19:51:02 +00:00
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
Does nothing if the stack is empty.
|
2017-09-01 19:51:02 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkCanvas simple;
|
|
|
|
SkDebugf("depth = %d\n", simple.getSaveCount());
|
|
|
|
simple.restore();
|
|
|
|
SkDebugf("depth = %d\n", simple.getSaveCount());
|
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso save() saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha restoreToCount
|
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method int getSaveCount() const
|
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#In State_Stack
|
|
|
|
#Line # returns depth of stack containing Clip and Matrix ##
|
2017-09-01 19:51:02 +00:00
|
|
|
Returns the number of saved states, each containing: Matrix, Clip, and Draw_Filter.
|
2018-02-07 01:58:51 +00:00
|
|
|
Equals the number of save() calls less the number of restore() calls plus one.
|
2017-09-01 19:51:02 +00:00
|
|
|
The save count of a new canvas is one.
|
|
|
|
|
|
|
|
#Return depth of save state stack ##
|
|
|
|
|
|
|
|
#Example
|
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkCanvas simple;
|
|
|
|
SkDebugf("depth = %d\n", simple.getSaveCount());
|
|
|
|
simple.save();
|
|
|
|
SkDebugf("depth = %d\n", simple.getSaveCount());
|
|
|
|
simple.restore();
|
|
|
|
SkDebugf("depth = %d\n", simple.getSaveCount());
|
|
|
|
}
|
|
|
|
#StdOut
|
|
|
|
depth = 1
|
|
|
|
depth = 2
|
|
|
|
depth = 1
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso save() restore() restoreToCount
|
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void restoreToCount(int saveCount)
|
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#In State_Stack
|
|
|
|
#Line # restores changes to Clip and Matrix to given depth ##
|
2017-09-01 19:51:02 +00:00
|
|
|
Restores state to Matrix, Clip, and Draw_Filter values when save(), saveLayer,
|
|
|
|
saveLayerPreserveLCDTextRequests, or saveLayerAlpha returned saveCount.
|
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
Does nothing if saveCount is greater than state stack count.
|
2017-09-01 19:51:02 +00:00
|
|
|
Restores state to initial values if saveCount is less than or equal to one.
|
|
|
|
|
|
|
|
#Param saveCount depth of state stack to restore ##
|
|
|
|
|
|
|
|
#Example
|
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkDebugf("depth = %d\n", canvas->getSaveCount());
|
|
|
|
canvas->save();
|
|
|
|
canvas->save();
|
|
|
|
SkDebugf("depth = %d\n", canvas->getSaveCount());
|
|
|
|
canvas->restoreToCount(0);
|
|
|
|
SkDebugf("depth = %d\n", canvas->getSaveCount());
|
|
|
|
}
|
|
|
|
#StdOut
|
|
|
|
depth = 1
|
|
|
|
depth = 3
|
|
|
|
depth = 1
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
#SeeAlso restore() getSaveCount save()
|
2017-11-02 21:49:34 +00:00
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
##
|
|
|
|
|
2018-02-01 14:37:32 +00:00
|
|
|
#Subtopic State_Stack ##
|
2017-09-01 19:51:02 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2018-02-01 14:37:32 +00:00
|
|
|
#Subtopic Layer
|
2017-09-14 15:25:39 +00:00
|
|
|
#Substitute layer
|
2017-09-01 19:51:02 +00:00
|
|
|
#Alias Layers
|
2018-02-01 14:37:32 +00:00
|
|
|
#Line # temporary Bitmap to draw into ##
|
2017-09-01 19:51:02 +00:00
|
|
|
|
|
|
|
Layer allocates a temporary Bitmap to draw into. When the drawing is
|
2018-02-07 01:58:51 +00:00
|
|
|
complete, the Bitmap is drawn into the Canvas.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Layer is saved in a stack along with other saved state. When state with a Layer
|
2017-09-01 19:51:02 +00:00
|
|
|
is restored, the Bitmap is drawn into the previous Layer.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
Layer may be initialized with the contents of the previous Layer. When Layer is
|
2017-08-03 21:14:08 +00:00
|
|
|
restored, its Bitmap can be modified by Paint passed to Layer to apply
|
|
|
|
Color_Alpha, Color_Filter, Image_Filter, and Blend_Mode.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Method int saveLayer(const SkRect* bounds, const SkPaint* paint)
|
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Layer
|
|
|
|
#Line # saves Clip and Matrix on stack; creates Layer ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Saves Matrix, Clip, and Draw_Filter (Draw_Filter deprecated on most platforms),
|
2017-09-01 19:51:02 +00:00
|
|
|
and allocates a Bitmap for subsequent drawing.
|
2017-07-28 15:04:54 +00:00
|
|
|
Calling restore() discards changes to Matrix, Clip, and Draw_Filter,
|
2017-09-01 19:51:02 +00:00
|
|
|
and draws the Bitmap.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
Matrix may be changed by translate(), scale(), rotate(), skew(), concat(),
|
2018-02-07 01:58:51 +00:00
|
|
|
setMatrix, and resetMatrix. Clip may be changed by clipRect, clipRRect,
|
2017-08-03 21:14:08 +00:00
|
|
|
clipPath, clipRegion.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
Rect bounds suggests but does not define the Bitmap size. To clip drawing to
|
2017-08-03 21:14:08 +00:00
|
|
|
a specific rectangle, use clipRect.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
Optional Paint paint applies Color_Alpha, Color_Filter, Image_Filter, and
|
|
|
|
Blend_Mode when restore() is called.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
Call restoreToCount with returned value to restore this and subsequent saves.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param bounds hint to limit the size of the Layer; may be nullptr ##
|
|
|
|
#Param paint graphics state for Layer; may be nullptr ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Return depth of saved stack ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Description
|
2017-09-01 19:51:02 +00:00
|
|
|
Rectangles are blurred by Image_Filter when restore() draws Layer to main
|
2017-08-03 21:14:08 +00:00
|
|
|
Canvas.
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
#Height 128
|
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkPaint paint, blur;
|
2017-11-27 15:44:06 +00:00
|
|
|
blur.setImageFilter(SkBlurImageFilter::Make(3, 3, nullptr));
|
2017-07-28 15:04:54 +00:00
|
|
|
canvas->saveLayer(nullptr, &blur);
|
|
|
|
SkRect rect = { 25, 25, 50, 50};
|
|
|
|
canvas->drawRect(rect, paint);
|
|
|
|
canvas->translate(50, 50);
|
|
|
|
paint.setColor(SK_ColorRED);
|
|
|
|
canvas->drawRect(rect, paint);
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso save() restore() saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha SaveLayerRec
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
#Method int saveLayer(const SkRect& bounds, const SkPaint* paint)
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Layer
|
2017-07-28 15:04:54 +00:00
|
|
|
Saves Matrix, Clip, and Draw_Filter (Draw_Filter deprecated on most platforms),
|
2017-09-01 19:51:02 +00:00
|
|
|
and allocates a Bitmap for subsequent drawing.
|
2017-07-28 15:04:54 +00:00
|
|
|
Calling restore() discards changes to Matrix, Clip, and Draw_Filter,
|
2017-09-01 19:51:02 +00:00
|
|
|
and draws the Bitmap.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
Matrix may be changed by translate(), scale(), rotate(), skew(), concat(),
|
|
|
|
setMatrix, and resetMatrix. Clip may be changed by clipRect, clipRRect,
|
|
|
|
clipPath, clipRegion.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
Rect bounds suggests but does not define the Layer size. To clip drawing to
|
2017-08-03 21:14:08 +00:00
|
|
|
a specific rectangle, use clipRect.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
Optional Paint paint applies Color_Alpha, Color_Filter, Image_Filter, and
|
|
|
|
Blend_Mode when restore() is called.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
Call restoreToCount with returned value to restore this and subsequent saves.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param bounds hint to limit the size of Layer; may be nullptr ##
|
|
|
|
#Param paint graphics state for Layer; may be nullptr ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Return depth of saved stack ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Description
|
2017-09-01 19:51:02 +00:00
|
|
|
Rectangles are blurred by Image_Filter when restore() draws Layer to main Canvas.
|
2018-02-07 01:58:51 +00:00
|
|
|
The red rectangle is clipped; it does not fully fit on Layer.
|
2017-09-01 19:51:02 +00:00
|
|
|
Image_Filter blurs past edge of Layer so red rectangle is blurred on all sides.
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
#Height 128
|
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkPaint paint, blur;
|
2017-11-27 15:44:06 +00:00
|
|
|
blur.setImageFilter(SkBlurImageFilter::Make(3, 3, nullptr));
|
2017-07-28 15:04:54 +00:00
|
|
|
canvas->saveLayer(SkRect::MakeWH(90, 90), &blur);
|
|
|
|
SkRect rect = { 25, 25, 50, 50};
|
|
|
|
canvas->drawRect(rect, paint);
|
|
|
|
canvas->translate(50, 50);
|
|
|
|
paint.setColor(SK_ColorRED);
|
|
|
|
canvas->drawRect(rect, paint);
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso save() restore() saveLayerPreserveLCDTextRequests saveLayerAlpha SaveLayerRec
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
#Method int saveLayerPreserveLCDTextRequests(const SkRect* bounds, const SkPaint* paint)
|
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Layer
|
|
|
|
#Line # saves Clip and Matrix on stack; creates Layer for LCD text ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Saves Matrix, Clip, and Draw_Filter (Draw_Filter deprecated on most platforms),
|
2017-09-01 19:51:02 +00:00
|
|
|
and allocates a Bitmap for subsequent drawing.
|
|
|
|
LCD_Text is preserved when the Layer is drawn to the prior Layer.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Calling restore() discards changes to Matrix, Clip, and Draw_Filter,
|
2017-09-01 19:51:02 +00:00
|
|
|
and draws Layer.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
Matrix may be changed by translate(), scale(), rotate(), skew(), concat(),
|
|
|
|
setMatrix, and resetMatrix. Clip may be changed by clipRect, clipRRect,
|
|
|
|
clipPath, clipRegion.
|
2018-02-07 01:58:51 +00:00
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
Rect bounds suggests but does not define the Layer size. To clip drawing to
|
2017-08-03 21:14:08 +00:00
|
|
|
a specific rectangle, use clipRect.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
Optional Paint paint applies Color_Alpha, Color_Filter, Image_Filter, and
|
|
|
|
Blend_Mode when restore() is called.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
Call restoreToCount with returned value to restore this and subsequent saves.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
Draw text on an opaque background so that LCD_Text blends correctly with the
|
2017-09-01 19:51:02 +00:00
|
|
|
prior Layer. LCD_Text drawn on a background with transparency may result in
|
2017-09-21 16:31:06 +00:00
|
|
|
incorrect blending.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param bounds hint to limit the size of Layer; may be nullptr ##
|
|
|
|
#Param paint graphics state for Layer; may be nullptr ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Return depth of saved stack ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2017-08-03 21:14:08 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setLCDRenderText(true);
|
|
|
|
paint.setTextSize(20);
|
|
|
|
for (auto preserve : { false, true } ) {
|
|
|
|
preserve ? canvas->saveLayerPreserveLCDTextRequests(nullptr, nullptr)
|
|
|
|
: canvas->saveLayer(nullptr, nullptr);
|
|
|
|
SkPaint p;
|
|
|
|
p.setColor(SK_ColorWHITE);
|
|
|
|
// Comment out the next line to draw on a non-opaque background.
|
|
|
|
canvas->drawRect(SkRect::MakeLTRB(25, 40, 200, 70), p);
|
|
|
|
canvas->drawString("Hamburgefons", 30, 60, paint);
|
|
|
|
|
|
|
|
p.setColor(0xFFCCCCCC);
|
|
|
|
canvas->drawRect(SkRect::MakeLTRB(25, 70, 200, 100), p);
|
|
|
|
canvas->drawString("Hamburgefons", 30, 90, paint);
|
|
|
|
|
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(0, 80);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso save() restore() saveLayer saveLayerAlpha SaveLayerRec
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
#Method int saveLayerAlpha(const SkRect* bounds, U8CPU alpha)
|
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Layer
|
|
|
|
#Line # saves Clip and Matrix on stack; creates Layer; sets opacity ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Saves Matrix, Clip, and Draw_Filter (Draw_Filter deprecated on most platforms),
|
2017-09-01 19:51:02 +00:00
|
|
|
and allocates Bitmap for subsequent drawing.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Calling restore() discards changes to Matrix, Clip, and Draw_Filter,
|
2017-09-01 19:51:02 +00:00
|
|
|
and blends Layer with alpha opacity onto prior Layer.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
Matrix may be changed by translate(), scale(), rotate(), skew(), concat(),
|
|
|
|
setMatrix, and resetMatrix. Clip may be changed by clipRect, clipRRect,
|
|
|
|
clipPath, clipRegion.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
Rect bounds suggests but does not define Layer size. To clip drawing to
|
2017-08-03 21:14:08 +00:00
|
|
|
a specific rectangle, use clipRect.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
alpha of zero is fully transparent, 255 is fully opaque.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
Call restoreToCount with returned value to restore this and subsequent saves.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param bounds hint to limit the size of Layer; may be nullptr ##
|
|
|
|
#Param alpha opacity of Layer ##
|
2017-08-03 21:14:08 +00:00
|
|
|
|
|
|
|
#Return depth of saved stack ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2017-08-03 21:14:08 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(SK_ColorRED);
|
|
|
|
canvas->drawCircle(50, 50, 50, paint);
|
|
|
|
canvas->saveLayerAlpha(nullptr, 128);
|
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
canvas->drawCircle(100, 50, 50, paint);
|
|
|
|
paint.setColor(SK_ColorGREEN);
|
|
|
|
paint.setAlpha(128);
|
|
|
|
canvas->drawCircle(75, 90, 50, paint);
|
2017-07-28 15:04:54 +00:00
|
|
|
canvas->restore();
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso save() restore() saveLayer saveLayerPreserveLCDTextRequests SaveLayerRec
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
#ToDo
|
2018-02-01 14:37:32 +00:00
|
|
|
add new markup to associate typedef SaveLayerFlags with Enum so that, for
|
|
|
|
documentation purposes, this enum is named rather than anonymous
|
|
|
|
##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-02-01 14:37:32 +00:00
|
|
|
#Enum
|
|
|
|
#Line # sets SaveLayerRec options ##
|
2017-07-28 15:04:54 +00:00
|
|
|
#Code
|
|
|
|
enum {
|
|
|
|
kPreserveLCDText_SaveLayerFlag = 1 << 1,
|
|
|
|
kInitWithPrevious_SaveLayerFlag = 1 << 2,
|
2017-08-03 21:14:08 +00:00
|
|
|
kDontClipToLayer_Legacy_SaveLayerFlag = kDontClipToLayer_PrivateSaveLayerFlag,
|
2017-07-28 15:04:54 +00:00
|
|
|
};
|
|
|
|
##
|
|
|
|
|
|
|
|
SaveLayerFlags provides options that may be used in any combination in SaveLayerRec,
|
2017-09-01 19:51:02 +00:00
|
|
|
defining how Layer allocated by saveLayer operates.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Const kPreserveLCDText_SaveLayerFlag 2
|
2017-09-01 19:51:02 +00:00
|
|
|
Creates Layer for LCD text. Flag is ignored if Layer Paint contains
|
2017-07-28 15:04:54 +00:00
|
|
|
Image_Filter or Color_Filter.
|
|
|
|
##
|
|
|
|
|
|
|
|
#Const kInitWithPrevious_SaveLayerFlag 4
|
2017-09-01 19:51:02 +00:00
|
|
|
Initializes Layer with the contents of the previous Layer.
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Const kDontClipToLayer_Legacy_SaveLayerFlag 0x80000000
|
2018-02-06 14:41:53 +00:00
|
|
|
#Deprecated soon
|
2017-08-03 21:14:08 +00:00
|
|
|
##
|
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
#Example
|
|
|
|
#Height 160
|
|
|
|
#Description
|
2017-09-01 19:51:02 +00:00
|
|
|
Canvas Layer captures red and blue circles scaled up by four.
|
2018-02-07 01:58:51 +00:00
|
|
|
scalePaint blends Layer back with transparency.
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkPaint redPaint, bluePaint, scalePaint;
|
|
|
|
redPaint.setColor(SK_ColorRED);
|
|
|
|
canvas->drawCircle(21, 21, 8, redPaint);
|
|
|
|
bluePaint.setColor(SK_ColorBLUE);
|
|
|
|
canvas->drawCircle(31, 21, 8, bluePaint);
|
|
|
|
SkMatrix matrix;
|
|
|
|
matrix.setScale(4, 4);
|
|
|
|
scalePaint.setAlpha(0x40);
|
|
|
|
scalePaint.setImageFilter(
|
|
|
|
SkImageFilter::MakeMatrixFilter(matrix, kNone_SkFilterQuality, nullptr));
|
|
|
|
SkCanvas::SaveLayerRec saveLayerRec(nullptr, &scalePaint,
|
2018-02-07 01:58:51 +00:00
|
|
|
SkCanvas::kInitWithPrevious_SaveLayerFlag);
|
2017-08-03 21:14:08 +00:00
|
|
|
canvas->saveLayer(saveLayerRec);
|
|
|
|
canvas->restore();
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso save() restore() saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha SaveLayerRec
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Enum ##
|
|
|
|
|
2017-11-27 15:44:06 +00:00
|
|
|
#Typedef uint32_t SaveLayerFlags
|
|
|
|
|
|
|
|
##
|
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
#Struct SaveLayerRec
|
2018-02-01 14:37:32 +00:00
|
|
|
#Line # contains the state used to create the Layer ##
|
2017-07-28 15:04:54 +00:00
|
|
|
#Code
|
|
|
|
struct SaveLayerRec {
|
|
|
|
SaveLayerRec*(...
|
|
|
|
|
|
|
|
const SkRect* fBounds;
|
|
|
|
const SkPaint* fPaint;
|
|
|
|
const SkImageFilter* fBackdrop;
|
|
|
|
SaveLayerFlags fSaveLayerFlags;
|
|
|
|
};
|
|
|
|
##
|
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
SaveLayerRec contains the state used to create the Layer.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Member const SkRect* fBounds
|
2017-09-01 19:51:02 +00:00
|
|
|
fBounds is used as a hint to limit the size of Layer; may be nullptr.
|
|
|
|
fBounds suggests but does not define Layer size. To clip drawing to
|
2017-08-03 21:14:08 +00:00
|
|
|
a specific rectangle, use clipRect.
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#Member const SkPaint* fPaint
|
2017-09-01 19:51:02 +00:00
|
|
|
fPaint modifies how Layer overlays the prior Layer; may be nullptr.
|
2017-08-03 21:14:08 +00:00
|
|
|
Color_Alpha, Blend_Mode, Color_Filter, Draw_Looper, Image_Filter, and
|
2017-09-01 19:51:02 +00:00
|
|
|
Mask_Filter affect Layer draw.
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#Member const SkImageFilter* fBackdrop
|
2017-09-01 19:51:02 +00:00
|
|
|
fBackdrop applies Image_Filter to the prior Layer when copying to the Layer;
|
|
|
|
may be nullptr. Use kInitWithPrevious_SaveLayerFlag to copy the
|
|
|
|
prior Layer without an Image_Filter.
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#Member const SkImage* fClipMask
|
2017-09-01 19:51:02 +00:00
|
|
|
restore() clips Layer by the Color_Alpha channel of fClipMask when
|
|
|
|
Layer is copied to Device. fClipMask may be nullptr. .
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#Member const SkMatrix* fClipMatrix
|
2018-02-07 01:58:51 +00:00
|
|
|
fClipMatrix transforms fClipMask before it clips Layer. If
|
2017-08-03 21:14:08 +00:00
|
|
|
fClipMask describes a translucent gradient, it may be scaled and rotated
|
|
|
|
without introducing artifacts. fClipMatrix may be nullptr.
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#Member SaveLayerFlags fSaveLayerFlags
|
2017-09-01 19:51:02 +00:00
|
|
|
fSaveLayerFlags are used to create Layer without transparency,
|
|
|
|
create Layer for LCD text, and to create Layer with the
|
|
|
|
contents of the previous Layer.
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 160
|
|
|
|
#Description
|
2017-09-01 19:51:02 +00:00
|
|
|
Canvas Layer captures a red Anti-aliased circle and a blue Aliased circle scaled
|
|
|
|
up by four. After drawing another red circle without scaling on top, the Layer is
|
2018-02-07 01:58:51 +00:00
|
|
|
transferred to the main canvas.
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkPaint redPaint, bluePaint;
|
|
|
|
redPaint.setAntiAlias(true);
|
|
|
|
redPaint.setColor(SK_ColorRED);
|
|
|
|
canvas->drawCircle(21, 21, 8, redPaint);
|
|
|
|
bluePaint.setColor(SK_ColorBLUE);
|
|
|
|
canvas->drawCircle(31, 21, 8, bluePaint);
|
|
|
|
SkMatrix matrix;
|
|
|
|
matrix.setScale(4, 4);
|
|
|
|
auto scaler = SkImageFilter::MakeMatrixFilter(matrix, kNone_SkFilterQuality, nullptr);
|
2018-02-07 01:58:51 +00:00
|
|
|
SkCanvas::SaveLayerRec saveLayerRec(nullptr, nullptr, scaler.get(), 0);
|
2017-08-03 21:14:08 +00:00
|
|
|
canvas->saveLayer(saveLayerRec);
|
|
|
|
canvas->drawCircle(125, 85, 8, redPaint);
|
|
|
|
canvas->restore();
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
|
|
|
#Method SaveLayerRec()
|
|
|
|
|
|
|
|
Sets fBounds, fPaint, and fBackdrop to nullptr. Clears fSaveLayerFlags.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Return empty SaveLayerRec ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2017-08-03 21:14:08 +00:00
|
|
|
SkCanvas::SaveLayerRec rec1;
|
2018-02-07 17:54:27 +00:00
|
|
|
rec1.fSaveLayerFlags = SkCanvas::kPreserveLCDText_SaveLayerFlag;
|
|
|
|
SkCanvas::SaveLayerRec rec2(nullptr, nullptr, SkCanvas::kPreserveLCDText_SaveLayerFlag);
|
2017-08-03 21:14:08 +00:00
|
|
|
SkDebugf("rec1 %c= rec2\n", rec1.fBounds == rec2.fBounds
|
|
|
|
&& rec1.fPaint == rec2.fPaint
|
|
|
|
&& rec1.fBackdrop == rec2.fBackdrop
|
2017-07-28 15:04:54 +00:00
|
|
|
&& rec1.fSaveLayerFlags == rec2.fSaveLayerFlags ? '=' : '!');
|
|
|
|
#StdOut
|
|
|
|
rec1 == rec2
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso save() restore() saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha
|
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#Method SaveLayerRec(const SkRect* bounds, const SkPaint* paint, SaveLayerFlags saveLayerFlags = 0)
|
|
|
|
|
|
|
|
Sets fBounds, fPaint, and fSaveLayerFlags; sets fBackdrop to nullptr.
|
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param bounds Layer dimensions; may be nullptr ##
|
|
|
|
#Param paint applied to Layer when overlaying prior Layer; may be nullptr ##
|
|
|
|
#Param saveLayerFlags SaveLayerRec options to modify Layer ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Return SaveLayerRec with empty backdrop ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2017-08-03 21:14:08 +00:00
|
|
|
SkCanvas::SaveLayerRec rec1;
|
|
|
|
SkCanvas::SaveLayerRec rec2(nullptr, nullptr);
|
|
|
|
SkDebugf("rec1 %c= rec2\n", rec1.fBounds == rec2.fBounds
|
|
|
|
&& rec1.fPaint == rec2.fPaint
|
|
|
|
&& rec1.fBackdrop == rec2.fBackdrop
|
2017-07-28 15:04:54 +00:00
|
|
|
&& rec1.fSaveLayerFlags == rec2.fSaveLayerFlags ? '=' : '!');
|
|
|
|
#StdOut
|
|
|
|
rec1 == rec2
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso save() restore() saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha
|
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#Method SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop,
|
|
|
|
SaveLayerFlags saveLayerFlags)
|
|
|
|
|
|
|
|
Sets fBounds, fPaint, fBackdrop, and fSaveLayerFlags.
|
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param bounds Layer dimensions; may be nullptr ##
|
|
|
|
#Param paint applied to Layer when overlaying prior Layer;
|
2017-08-03 21:14:08 +00:00
|
|
|
may be nullptr
|
|
|
|
##
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param backdrop prior Layer copied with Image_Filter; may be nullptr
|
2017-08-03 21:14:08 +00:00
|
|
|
##
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param saveLayerFlags SaveLayerRec options to modify Layer ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Return SaveLayerRec fully specified ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2017-08-03 21:14:08 +00:00
|
|
|
SkCanvas::SaveLayerRec rec1;
|
|
|
|
SkCanvas::SaveLayerRec rec2(nullptr, nullptr, nullptr, 0);
|
|
|
|
SkDebugf("rec1 %c= rec2\n", rec1.fBounds == rec2.fBounds
|
|
|
|
&& rec1.fPaint == rec2.fPaint
|
|
|
|
&& rec1.fBackdrop == rec2.fBackdrop
|
2017-07-28 15:04:54 +00:00
|
|
|
&& rec1.fSaveLayerFlags == rec2.fSaveLayerFlags ? '=' : '!');
|
|
|
|
#StdOut
|
|
|
|
rec1 == rec2
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso save() restore() saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha
|
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#Method SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop,
|
|
|
|
const SkImage* clipMask, const SkMatrix* clipMatrix,
|
|
|
|
SaveLayerFlags saveLayerFlags)
|
|
|
|
|
|
|
|
#Experimental
|
|
|
|
Not ready for general use.
|
|
|
|
##
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
Sets fBounds, fPaint, fBackdrop, fClipMask, fClipMatrix, and fSaveLayerFlags.
|
2017-09-01 19:51:02 +00:00
|
|
|
clipMatrix uses Color_Alpha channel of image, transformed by clipMatrix, to clip
|
|
|
|
Layer when drawn to Canvas.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
Implementation is not complete; has no effect if Device is GPU-backed.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param bounds Layer dimensions; may be nullptr ##
|
|
|
|
#Param paint graphics state applied to Layer when overlaying prior
|
|
|
|
Layer; may be nullptr
|
2017-08-03 21:14:08 +00:00
|
|
|
##
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param backdrop prior Layer copied with Image_Filter;
|
2017-08-03 21:14:08 +00:00
|
|
|
may be nullptr
|
|
|
|
##
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param clipMask clip applied to Layer; may be nullptr ##
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param clipMatrix matrix applied to clipMask; may be nullptr to use
|
2018-02-07 01:58:51 +00:00
|
|
|
identity matrix
|
2017-08-03 21:14:08 +00:00
|
|
|
##
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param saveLayerFlags SaveLayerRec options to modify Layer ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Return SaveLayerRec fully specified ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso save() restore() saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
#Struct ##
|
|
|
|
|
|
|
|
#Method int saveLayer(const SaveLayerRec& layerRec)
|
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Layer
|
2017-07-28 15:04:54 +00:00
|
|
|
Saves Matrix, Clip, and Draw_Filter (Draw_Filter deprecated on most platforms),
|
2017-09-01 19:51:02 +00:00
|
|
|
and allocates Bitmap for subsequent drawing.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Calling restore() discards changes to Matrix, Clip, and Draw_Filter,
|
2017-09-01 19:51:02 +00:00
|
|
|
and blends Bitmap with Color_Alpha opacity onto the prior Layer.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
Matrix may be changed by translate(), scale(), rotate(), skew(), concat(),
|
|
|
|
setMatrix, and resetMatrix. Clip may be changed by clipRect, clipRRect,
|
|
|
|
clipPath, clipRegion.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
SaveLayerRec contains the state used to create the Layer.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
Call restoreToCount with returned value to restore this and subsequent saves.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param layerRec Layer state ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Return depth of save state stack ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Description
|
2017-09-01 19:51:02 +00:00
|
|
|
The example draws an image, and saves it into a Layer with kInitWithPrevious_SaveLayerFlag.
|
|
|
|
Next it punches a hole in Layer and restore with SkBlendMode::kPlus.
|
|
|
|
Where Layer was cleared, the original image will draw unchanged.
|
2017-07-28 15:04:54 +00:00
|
|
|
Outside of the circle the mandrill is brightened.
|
|
|
|
##
|
|
|
|
#Image 3
|
2017-12-08 15:21:31 +00:00
|
|
|
// sk_sp<SkImage> image = GetResourceAsImage("images/mandrill_256.png");
|
2017-07-28 15:04:54 +00:00
|
|
|
canvas->drawImage(image, 0, 0, nullptr);
|
|
|
|
SkCanvas::SaveLayerRec rec;
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setBlendMode(SkBlendMode::kPlus);
|
|
|
|
rec.fSaveLayerFlags = SkCanvas::kInitWithPrevious_SaveLayerFlag;
|
|
|
|
rec.fPaint = &paint;
|
|
|
|
canvas->saveLayer(rec);
|
|
|
|
paint.setBlendMode(SkBlendMode::kClear);
|
|
|
|
canvas->drawCircle(128, 128, 96, paint);
|
|
|
|
canvas->restore();
|
|
|
|
##
|
|
|
|
|
|
|
|
#ToDo above example needs to replace GetResourceAsImage with way to select image in fiddle ##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso save() restore() saveLayer saveLayerPreserveLCDTextRequests saveLayerAlpha
|
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
2018-02-01 14:37:32 +00:00
|
|
|
#Subtopic Layer ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
2018-02-01 14:37:32 +00:00
|
|
|
#Subtopic Matrix
|
|
|
|
#Line # coordinate transformation ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Method void translate(SkScalar dx, SkScalar dy)
|
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Matrix
|
|
|
|
#Line # translates Matrix ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Translate Matrix by dx along the x-axis and dy along the y-axis.
|
|
|
|
|
|
|
|
Mathematically, replace Matrix with a translation matrix
|
2018-02-07 01:58:51 +00:00
|
|
|
Premultiplied with Matrix.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
This has the effect of moving the drawing by (dx, dy) before transforming
|
|
|
|
the result with Matrix.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param dx distance to translate in x ##
|
|
|
|
#Param dy distance to translate in y ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 128
|
|
|
|
#Description
|
|
|
|
scale() followed by translate() produces different results from translate() followed
|
2018-02-07 01:58:51 +00:00
|
|
|
by scale().
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
The blue stroke follows translate of (50, 50); a black
|
2018-02-07 01:58:51 +00:00
|
|
|
fill follows scale of (2, 1/2.f). After restoring the clip, which resets
|
2017-07-28 15:04:54 +00:00
|
|
|
Matrix, a red frame follows the same scale of (2, 1/2.f); a gray fill
|
|
|
|
follows translate of (50, 50).
|
|
|
|
##
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkPaint filledPaint;
|
|
|
|
SkPaint outlinePaint;
|
|
|
|
outlinePaint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
outlinePaint.setColor(SK_ColorBLUE);
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(50, 50);
|
|
|
|
canvas->drawCircle(28, 28, 15, outlinePaint); // blue center: (50+28, 50+28)
|
|
|
|
canvas->scale(2, 1/2.f);
|
|
|
|
canvas->drawCircle(28, 28, 15, filledPaint); // black center: (50+(28*2), 50+(28/2))
|
|
|
|
canvas->restore();
|
|
|
|
filledPaint.setColor(SK_ColorGRAY);
|
|
|
|
outlinePaint.setColor(SK_ColorRED);
|
|
|
|
canvas->scale(2, 1/2.f);
|
|
|
|
canvas->drawCircle(28, 28, 15, outlinePaint); // red center: (28*2, 28/2)
|
|
|
|
canvas->translate(50, 50);
|
|
|
|
canvas->drawCircle(28, 28, 15, filledPaint); // gray center: ((50+28)*2, (50+28)/2)
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso concat() scale() skew() rotate() setMatrix
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void scale(SkScalar sx, SkScalar sy)
|
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Matrix
|
|
|
|
#Line # scales Matrix ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Scale Matrix by sx on the x-axis and sy on the y-axis.
|
|
|
|
|
|
|
|
Mathematically, replace Matrix with a scale matrix
|
2018-02-07 01:58:51 +00:00
|
|
|
Premultiplied with Matrix.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
This has the effect of scaling the drawing by (sx, sy) before transforming
|
|
|
|
the result with Matrix.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param sx amount to scale in x ##
|
|
|
|
#Param sy amount to scale in y ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 160
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
|
|
|
SkRect rect = { 10, 20, 60, 120 };
|
|
|
|
canvas->translate(20, 20);
|
|
|
|
canvas->drawRect(rect, paint);
|
|
|
|
canvas->scale(2, .5f);
|
|
|
|
paint.setColor(SK_ColorGRAY);
|
|
|
|
canvas->drawRect(rect, paint);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso concat() translate() skew() rotate() setMatrix
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void rotate(SkScalar degrees)
|
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Matrix
|
|
|
|
#Line # rotates Matrix ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Rotate Matrix by degrees. Positive degrees rotates clockwise.
|
|
|
|
|
|
|
|
Mathematically, replace Matrix with a rotation matrix
|
2018-02-07 01:58:51 +00:00
|
|
|
Premultiplied with Matrix.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
This has the effect of rotating the drawing by degrees before transforming
|
|
|
|
the result with Matrix.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param degrees amount to rotate, in degrees ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Description
|
|
|
|
Draw clock hands at time 5:10. The hour hand and minute hand point up and
|
|
|
|
are rotated clockwise.
|
|
|
|
##
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
canvas->translate(128, 128);
|
|
|
|
canvas->drawCircle(0, 0, 60, paint);
|
|
|
|
canvas->save();
|
|
|
|
canvas->rotate(10 * 360 / 60); // 10 minutes of 60 scaled to 360 degrees
|
2018-02-07 01:58:51 +00:00
|
|
|
canvas->drawLine(0, 0, 0, -50, paint);
|
2017-08-03 21:14:08 +00:00
|
|
|
canvas->restore();
|
|
|
|
canvas->rotate((5 + 10.f/60) * 360 / 12); // 5 and 10/60 hours of 12 scaled to 360 degrees
|
|
|
|
canvas->drawLine(0, 0, 0, -30, paint);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso concat() translate() skew() scale() setMatrix
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void rotate(SkScalar degrees, SkScalar px, SkScalar py)
|
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Matrix
|
2017-08-03 21:14:08 +00:00
|
|
|
Rotate Matrix by degrees about a point at (px, py). Positive degrees rotates
|
|
|
|
clockwise.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
Mathematically, construct a rotation matrix. Premultiply the rotation matrix by
|
2017-07-28 15:04:54 +00:00
|
|
|
a translation matrix, then replace Matrix with the resulting matrix
|
2018-02-07 01:58:51 +00:00
|
|
|
Premultiplied with Matrix.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
This has the effect of rotating the drawing about a given point before
|
|
|
|
transforming the result with Matrix.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param degrees amount to rotate, in degrees ##
|
|
|
|
#Param px x-coordinate of the point to rotate about ##
|
|
|
|
#Param py y-coordinate of the point to rotate about ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 192
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setTextSize(96);
|
|
|
|
canvas->drawString("A1", 130, 100, paint);
|
|
|
|
canvas->rotate(180, 130, 100);
|
|
|
|
canvas->drawString("A1", 130, 100, paint);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso concat() translate() skew() scale() setMatrix
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void skew(SkScalar sx, SkScalar sy)
|
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Matrix
|
|
|
|
#Line # skews Matrix ##
|
2017-08-03 21:14:08 +00:00
|
|
|
Skew Matrix by sx on the x-axis and sy on the y-axis. A positive value of sx
|
|
|
|
skews the drawing right as y increases; a positive value of sy skews the drawing
|
|
|
|
down as x increases.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
Mathematically, replace Matrix with a skew matrix Premultiplied with Matrix.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
This has the effect of skewing the drawing by (sx, sy) before transforming
|
2017-07-28 15:04:54 +00:00
|
|
|
the result with Matrix.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param sx amount to skew in x ##
|
|
|
|
#Param sy amount to skew in y ##
|
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
#Example
|
2018-02-07 01:58:51 +00:00
|
|
|
#Description
|
2017-07-28 15:04:54 +00:00
|
|
|
Black text mimics an oblique text style by using a negative skew in x that
|
|
|
|
shifts the geometry to the right as the y values decrease.
|
|
|
|
Red text uses a positive skew in y to shift the geometry down as the x values
|
|
|
|
increase.
|
|
|
|
Blue text combines x and y skew to rotate and scale.
|
|
|
|
##
|
2017-08-03 21:14:08 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setTextSize(128);
|
|
|
|
canvas->translate(30, 130);
|
|
|
|
canvas->save();
|
|
|
|
canvas->skew(-.5, 0);
|
|
|
|
canvas->drawString("A1", 0, 0, paint);
|
|
|
|
canvas->restore();
|
|
|
|
canvas->save();
|
|
|
|
canvas->skew(0, .5);
|
|
|
|
paint.setColor(SK_ColorRED);
|
|
|
|
canvas->drawString("A1", 0, 0, paint);
|
|
|
|
canvas->restore();
|
|
|
|
canvas->skew(-.5, .5);
|
|
|
|
paint.setColor(SK_ColorBLUE);
|
2017-07-28 15:04:54 +00:00
|
|
|
canvas->drawString("A1", 0, 0, paint);
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso concat() translate() rotate() scale() setMatrix
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void concat(const SkMatrix& matrix)
|
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Matrix
|
|
|
|
#Line # multiplies Matrix by Matrix ##
|
2017-09-01 19:51:02 +00:00
|
|
|
Replace Matrix with matrix Premultiplied with existing Matrix.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
This has the effect of transforming the drawn geometry by matrix, before
|
|
|
|
transforming the result with existing Matrix.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param matrix matrix to Premultiply with existing Matrix ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setTextSize(80);
|
|
|
|
paint.setTextScaleX(.3);
|
|
|
|
SkMatrix matrix;
|
|
|
|
SkRect rect[2] = {{ 10, 20, 90, 110 }, { 40, 130, 140, 180 }};
|
|
|
|
matrix.setRectToRect(rect[0], rect[1], SkMatrix::kFill_ScaleToFit);
|
|
|
|
canvas->drawRect(rect[0], paint);
|
|
|
|
canvas->drawRect(rect[1], paint);
|
|
|
|
paint.setColor(SK_ColorWHITE);
|
|
|
|
canvas->drawString("Here", rect[0].fLeft + 10, rect[0].fBottom - 10, paint);
|
|
|
|
canvas->concat(matrix);
|
|
|
|
canvas->drawString("There", rect[0].fLeft + 10, rect[0].fBottom - 10, paint);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso translate() rotate() scale() skew() setMatrix
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void setMatrix(const SkMatrix& matrix)
|
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Matrix
|
|
|
|
#Line # sets Matrix ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Replace Matrix with matrix.
|
|
|
|
Unlike concat(), any prior matrix state is overwritten.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param matrix matrix to copy, replacing existing Matrix ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 128
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
|
|
|
canvas->scale(4, 6);
|
|
|
|
canvas->drawString("truth", 2, 10, paint);
|
|
|
|
SkMatrix matrix;
|
|
|
|
matrix.setScale(2.8f, 6);
|
|
|
|
canvas->setMatrix(matrix);
|
|
|
|
canvas->drawString("consequences", 2, 20, paint);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso resetMatrix concat() translate() rotate() scale() skew()
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void resetMatrix()
|
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Matrix
|
|
|
|
#Line # resets Matrix to identity ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Sets Matrix to the identity matrix.
|
|
|
|
Any prior matrix state is overwritten.
|
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 128
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
|
|
|
canvas->scale(4, 6);
|
|
|
|
canvas->drawString("truth", 2, 10, paint);
|
|
|
|
canvas->resetMatrix();
|
|
|
|
canvas->scale(2.8f, 6);
|
|
|
|
canvas->drawString("consequences", 2, 20, paint);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso setMatrix concat() translate() rotate() scale() skew()
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method const SkMatrix& getTotalMatrix() const
|
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Matrix
|
|
|
|
#Line # returns Matrix ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Returns Matrix.
|
|
|
|
This does not account for translation by Device or Surface.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Return Matrix in Canvas ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2017-08-03 21:14:08 +00:00
|
|
|
SkDebugf("isIdentity %s\n", canvas->getTotalMatrix().isIdentity() ? "true" : "false");
|
|
|
|
#StdOut
|
|
|
|
isIdentity true
|
|
|
|
##
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso setMatrix resetMatrix concat()
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
2018-02-01 14:37:32 +00:00
|
|
|
#Subtopic Matrix ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
2018-02-01 14:37:32 +00:00
|
|
|
#Subtopic Clip
|
|
|
|
#Line # stack of clipping Paths ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Clip is built from a stack of clipping paths. Each Path in the
|
2018-02-07 01:58:51 +00:00
|
|
|
stack can be constructed from one or more Path_Contour elements. The
|
2017-07-28 15:04:54 +00:00
|
|
|
Path_Contour may be composed of any number of Path_Verb segments. Each
|
|
|
|
Path_Contour forms a closed area; Path_Fill_Type defines the area enclosed
|
|
|
|
by Path_Contour.
|
|
|
|
|
|
|
|
Clip stack of Path elements successfully restrict the Path area. Each
|
2018-02-07 01:58:51 +00:00
|
|
|
Path is transformed by Matrix, then intersected with or subtracted from the
|
2017-07-28 15:04:54 +00:00
|
|
|
prior Clip to form the replacement Clip. Use SkClipOp::kDifference
|
|
|
|
to subtract Path from Clip; use SkClipOp::kIntersect to intersect Path
|
|
|
|
with Clip.
|
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
A clipping Path may be Anti-aliased; if Path, after transformation, is
|
2017-07-28 15:04:54 +00:00
|
|
|
composed of horizontal and vertical lines, clearing Anti-alias allows whole pixels
|
2017-09-01 19:51:02 +00:00
|
|
|
to either be inside or outside the clip. The fastest drawing has a Aliased,
|
|
|
|
rectangular clip.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
If clipping Path has Anti-alias set, clip may partially clip a pixel, requiring
|
2018-02-07 01:58:51 +00:00
|
|
|
that drawing blend partially with the destination along the edge. A rotated
|
2017-09-01 19:51:02 +00:00
|
|
|
rectangular Anti-aliased clip looks smoother but draws slower.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Clip can combine with Rect and Round_Rect primitives; like
|
|
|
|
Path, these are transformed by Matrix before they are combined with Clip.
|
|
|
|
|
|
|
|
Clip can combine with Region. Region is assumed to be in Device coordinates
|
|
|
|
and is unaffected by Matrix.
|
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 90
|
|
|
|
#Description
|
2017-09-01 19:51:02 +00:00
|
|
|
Draw a red circle with an Aliased clip and an Anti-aliased clip.
|
2017-07-28 15:04:54 +00:00
|
|
|
Use an image filter to zoom into the pixels drawn.
|
2017-09-01 19:51:02 +00:00
|
|
|
The edge of the Aliased clip fully draws pixels in the red circle.
|
|
|
|
The edge of the Anti-aliased clip partially draws pixels in the red circle.
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
2017-08-03 21:14:08 +00:00
|
|
|
SkPaint redPaint, scalePaint;
|
|
|
|
redPaint.setAntiAlias(true);
|
|
|
|
redPaint.setColor(SK_ColorRED);
|
|
|
|
canvas->save();
|
|
|
|
for (bool antialias : { false, true } ) {
|
|
|
|
canvas->save();
|
|
|
|
canvas->clipRect(SkRect::MakeWH(19.5f, 11.5f), antialias);
|
|
|
|
canvas->drawCircle(17, 11, 8, redPaint);
|
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(16, 0);
|
|
|
|
}
|
|
|
|
canvas->restore();
|
|
|
|
SkMatrix matrix;
|
|
|
|
matrix.setScale(6, 6);
|
|
|
|
scalePaint.setImageFilter(
|
|
|
|
SkImageFilter::MakeMatrixFilter(matrix, kNone_SkFilterQuality, nullptr));
|
|
|
|
SkCanvas::SaveLayerRec saveLayerRec(
|
2018-02-07 01:58:51 +00:00
|
|
|
nullptr, &scalePaint, SkCanvas::kInitWithPrevious_SaveLayerFlag);
|
2017-08-03 21:14:08 +00:00
|
|
|
canvas->saveLayer(saveLayerRec);
|
2017-07-28 15:04:54 +00:00
|
|
|
canvas->restore();
|
|
|
|
##
|
|
|
|
|
|
|
|
#Method void clipRect(const SkRect& rect, SkClipOp op, bool doAntiAlias)
|
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Clip
|
|
|
|
#Line # combines Clip with Rect ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Replace Clip with the intersection or difference of Clip and rect,
|
2017-09-01 19:51:02 +00:00
|
|
|
with an Aliased or Anti-aliased clip edge. rect is transformed by Matrix
|
2017-07-28 15:04:54 +00:00
|
|
|
before it is combined with Clip.
|
|
|
|
|
2017-08-30 12:58:10 +00:00
|
|
|
#Param rect Rect to combine with Clip ##
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param op Clip_Op to apply to Clip ##
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param doAntiAlias true if Clip is to be Anti-aliased ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 128
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
canvas->rotate(10);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
for (auto alias: { false, true } ) {
|
|
|
|
canvas->save();
|
|
|
|
canvas->clipRect(SkRect::MakeWH(90, 80), SkClipOp::kIntersect, alias);
|
|
|
|
canvas->drawCircle(100, 60, 60, paint);
|
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(80, 0);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso clipRRect clipPath clipRegion
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
#Method void clipRect(const SkRect& rect, SkClipOp op)
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Clip
|
2017-07-28 15:04:54 +00:00
|
|
|
Replace Clip with the intersection or difference of Clip and rect.
|
2017-09-01 19:51:02 +00:00
|
|
|
Resulting Clip is Aliased; pixels are fully contained by the clip.
|
2017-08-03 21:14:08 +00:00
|
|
|
rect is transformed by Matrix before it is combined with Clip.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-30 12:58:10 +00:00
|
|
|
#Param rect Rect to combine with Clip ##
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param op Clip_Op to apply to Clip ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 192
|
|
|
|
#Width 280
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
|
|
|
for (SkClipOp op: { SkClipOp::kIntersect, SkClipOp::kDifference } ) {
|
|
|
|
canvas->save();
|
|
|
|
canvas->clipRect(SkRect::MakeWH(90, 120), op, false);
|
|
|
|
canvas->drawCircle(100, 100, 60, paint);
|
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(80, 0);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso clipRRect clipPath clipRegion
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
#Method void clipRect(const SkRect& rect, bool doAntiAlias = false)
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Clip
|
2017-07-28 15:04:54 +00:00
|
|
|
Replace Clip with the intersection of Clip and rect.
|
2017-09-01 19:51:02 +00:00
|
|
|
Resulting Clip is Aliased; pixels are fully contained by the clip.
|
2017-07-28 15:04:54 +00:00
|
|
|
rect is transformed by Matrix
|
|
|
|
before it is combined with Clip.
|
|
|
|
|
2017-08-30 12:58:10 +00:00
|
|
|
#Param rect Rect to combine with Clip ##
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param doAntiAlias true if Clip is to be Anti-aliased ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 133
|
|
|
|
#Description
|
2017-09-01 19:51:02 +00:00
|
|
|
A circle drawn in pieces looks uniform when drawn Aliased.
|
|
|
|
The same circle pieces blend with pixels more than once when Anti-aliased,
|
2017-07-28 15:04:54 +00:00
|
|
|
visible as a thin pair of lines through the right circle.
|
|
|
|
##
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
canvas->clear(SK_ColorWHITE);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setColor(0x8055aaff);
|
|
|
|
SkRect clipRect = { 0, 0, 87.4f, 87.4f };
|
|
|
|
for (auto alias: { false, true } ) {
|
|
|
|
canvas->save();
|
|
|
|
canvas->clipRect(clipRect, SkClipOp::kIntersect, alias);
|
|
|
|
canvas->drawCircle(67, 67, 60, paint);
|
|
|
|
canvas->restore();
|
|
|
|
canvas->save();
|
|
|
|
canvas->clipRect(clipRect, SkClipOp::kDifference, alias);
|
|
|
|
canvas->drawCircle(67, 67, 60, paint);
|
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(120, 0);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso clipRRect clipPath clipRegion
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
#Method void androidFramework_setDeviceClipRestriction(const SkIRect& rect)
|
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Clip
|
|
|
|
#Line # for use by Android framework ##
|
2017-09-01 19:51:02 +00:00
|
|
|
Sets the maximum clip rectangle, which can be set by clipRect, clipRRect and
|
2017-07-28 15:04:54 +00:00
|
|
|
clipPath and intersect the current clip with the specified rect.
|
2017-09-01 19:51:02 +00:00
|
|
|
The maximum clip affects only future clipping operations; it is not retroactive.
|
2017-07-28 15:04:54 +00:00
|
|
|
The clip restriction is not recorded in pictures.
|
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
Pass an empty rect to disable maximum clip.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
#Private
|
|
|
|
This is private API to be used only by Android framework.
|
|
|
|
##
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param rect maximum allowed clip in device coordinates
|
2017-07-31 15:48:27 +00:00
|
|
|
#Param ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
#Method void clipRRect(const SkRRect& rrect, SkClipOp op, bool doAntiAlias)
|
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Clip
|
|
|
|
#Line # combines Clip with Round_Rect ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Replace Clip with the intersection or difference of Clip and rrect,
|
2017-09-01 19:51:02 +00:00
|
|
|
with an Aliased or Anti-aliased clip edge.
|
2017-07-28 15:04:54 +00:00
|
|
|
rrect is transformed by Matrix
|
|
|
|
before it is combined with Clip.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param rrect Round_Rect to combine with Clip ##
|
|
|
|
#Param op Clip_Op to apply to Clip ##
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param doAntiAlias true if Clip is to be Anti-aliased ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 128
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
canvas->clear(SK_ColorWHITE);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setColor(0x8055aaff);
|
|
|
|
SkRRect oval;
|
|
|
|
oval.setOval({10, 20, 90, 100});
|
|
|
|
canvas->clipRRect(oval, SkClipOp::kIntersect, true);
|
|
|
|
canvas->drawCircle(70, 100, 60, paint);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso clipRect clipPath clipRegion
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
#Method void clipRRect(const SkRRect& rrect, SkClipOp op)
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Clip
|
2017-07-28 15:04:54 +00:00
|
|
|
Replace Clip with the intersection or difference of Clip and rrect.
|
2017-09-01 19:51:02 +00:00
|
|
|
Resulting Clip is Aliased; pixels are fully contained by the clip.
|
2017-08-03 21:14:08 +00:00
|
|
|
rrect is transformed by Matrix before it is combined with Clip.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param rrect Round_Rect to combine with Clip ##
|
|
|
|
#Param op Clip_Op to apply to Clip ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 128
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(0x8055aaff);
|
|
|
|
auto oval = SkRRect::MakeOval({10, 20, 90, 100});
|
|
|
|
canvas->clipRRect(oval, SkClipOp::kIntersect);
|
|
|
|
canvas->drawCircle(70, 100, 60, paint);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso clipRect clipPath clipRegion
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
#Method void clipRRect(const SkRRect& rrect, bool doAntiAlias = false)
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Clip
|
2017-07-28 15:04:54 +00:00
|
|
|
Replace Clip with the intersection of Clip and rrect,
|
2017-09-01 19:51:02 +00:00
|
|
|
with an Aliased or Anti-aliased clip edge.
|
2017-08-03 21:14:08 +00:00
|
|
|
rrect is transformed by Matrix before it is combined with Clip.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param rrect Round_Rect to combine with Clip ##
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param doAntiAlias true if Clip is to be Anti-aliased ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 128
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
auto oval = SkRRect::MakeRectXY({10, 20, 90, 100}, 9, 13);
|
|
|
|
canvas->clipRRect(oval, true);
|
|
|
|
canvas->drawCircle(70, 100, 60, paint);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso clipRect clipPath clipRegion
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
#Method void clipPath(const SkPath& path, SkClipOp op, bool doAntiAlias)
|
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Clip
|
|
|
|
#Line # combines Clip with Path ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Replace Clip with the intersection or difference of Clip and path,
|
2017-09-01 19:51:02 +00:00
|
|
|
with an Aliased or Anti-aliased clip edge. Path_Fill_Type determines if path
|
2017-07-28 15:04:54 +00:00
|
|
|
describes the area inside or outside its contours; and if Path_Contour overlaps
|
|
|
|
itself or another Path_Contour, whether the overlaps form part of the area.
|
2017-08-03 21:14:08 +00:00
|
|
|
path is transformed by Matrix before it is combined with Clip.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param path Path to combine with Clip ##
|
|
|
|
#Param op Clip_Op to apply to Clip ##
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param doAntiAlias true if Clip is to be Anti-aliased ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Description
|
|
|
|
Top figure uses SkPath::kInverseWinding_FillType and SkClipOp::kDifference;
|
|
|
|
area outside clip is subtracted from circle.
|
|
|
|
|
|
|
|
Bottom figure uses SkPath::kWinding_FillType and SkClipOp::kIntersect;
|
|
|
|
area inside clip is intersected with circle.
|
|
|
|
##
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
SkPath path;
|
|
|
|
path.addRect({20, 30, 100, 110});
|
|
|
|
path.setFillType(SkPath::kInverseWinding_FillType);
|
|
|
|
canvas->save();
|
|
|
|
canvas->clipPath(path, SkClipOp::kDifference, false);
|
|
|
|
canvas->drawCircle(70, 100, 60, paint);
|
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(100, 100);
|
|
|
|
path.setFillType(SkPath::kWinding_FillType);
|
|
|
|
canvas->clipPath(path, SkClipOp::kIntersect, false);
|
|
|
|
canvas->drawCircle(70, 100, 60, paint);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso clipRect clipRRect clipRegion
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
#Method void clipPath(const SkPath& path, SkClipOp op)
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Clip
|
2017-07-28 15:04:54 +00:00
|
|
|
Replace Clip with the intersection or difference of Clip and path.
|
2017-09-01 19:51:02 +00:00
|
|
|
Resulting Clip is Aliased; pixels are fully contained by the clip.
|
2017-07-28 15:04:54 +00:00
|
|
|
Path_Fill_Type determines if path
|
|
|
|
describes the area inside or outside its contours; and if Path_Contour overlaps
|
|
|
|
itself or another Path_Contour, whether the overlaps form part of the area.
|
|
|
|
path is transformed by Matrix
|
|
|
|
before it is combined with Clip.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param path Path to combine with Clip ##
|
|
|
|
#Param op Clip_Op to apply to Clip ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Description
|
2017-10-04 18:31:33 +00:00
|
|
|
Overlapping Rects form a clip. When clip Path_Fill_Type is set to
|
2018-02-07 01:58:51 +00:00
|
|
|
SkPath::kWinding_FillType, the overlap is included. Set to
|
2017-07-28 15:04:54 +00:00
|
|
|
SkPath::kEvenOdd_FillType, the overlap is excluded and forms a hole.
|
|
|
|
##
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
SkPath path;
|
|
|
|
path.addRect({20, 15, 100, 95});
|
|
|
|
path.addRect({50, 65, 130, 135});
|
|
|
|
path.setFillType(SkPath::kWinding_FillType);
|
|
|
|
canvas->save();
|
|
|
|
canvas->clipPath(path, SkClipOp::kIntersect);
|
|
|
|
canvas->drawCircle(70, 85, 60, paint);
|
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(100, 100);
|
|
|
|
path.setFillType(SkPath::kEvenOdd_FillType);
|
|
|
|
canvas->clipPath(path, SkClipOp::kIntersect);
|
|
|
|
canvas->drawCircle(70, 85, 60, paint);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso clipRect clipRRect clipRegion
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
#Method void clipPath(const SkPath& path, bool doAntiAlias = false)
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Clip
|
2017-07-28 15:04:54 +00:00
|
|
|
Replace Clip with the intersection of Clip and path.
|
2017-09-01 19:51:02 +00:00
|
|
|
Resulting Clip is Aliased; pixels are fully contained by the clip.
|
2017-07-28 15:04:54 +00:00
|
|
|
Path_Fill_Type determines if path
|
|
|
|
describes the area inside or outside its contours; and if Path_Contour overlaps
|
|
|
|
itself or another Path_Contour, whether the overlaps form part of the area.
|
2017-08-03 21:14:08 +00:00
|
|
|
path is transformed by Matrix before it is combined with Clip.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param path Path to combine with Clip ##
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param doAntiAlias true if Clip is to be Anti-aliased ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 212
|
|
|
|
#Description
|
2018-02-07 01:58:51 +00:00
|
|
|
Clip loops over itself covering its center twice. When clip Path_Fill_Type
|
|
|
|
is set to SkPath::kWinding_FillType, the overlap is included. Set to
|
2017-07-28 15:04:54 +00:00
|
|
|
SkPath::kEvenOdd_FillType, the overlap is excluded and forms a hole.
|
|
|
|
##
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
SkPath path;
|
|
|
|
SkPoint poly[] = {{20, 20}, { 80, 20}, { 80, 80}, {40, 80},
|
|
|
|
{40, 40}, {100, 40}, {100, 100}, {20, 100}};
|
|
|
|
path.addPoly(poly, SK_ARRAY_COUNT(poly), true);
|
|
|
|
path.setFillType(SkPath::kWinding_FillType);
|
|
|
|
canvas->save();
|
|
|
|
canvas->clipPath(path, SkClipOp::kIntersect);
|
|
|
|
canvas->drawCircle(50, 50, 45, paint);
|
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(100, 100);
|
|
|
|
path.setFillType(SkPath::kEvenOdd_FillType);
|
|
|
|
canvas->clipPath(path, SkClipOp::kIntersect);
|
|
|
|
canvas->drawCircle(50, 50, 45, paint);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso clipRect clipRRect clipRegion
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
#Method void setAllowSimplifyClip(bool allow)
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Clip
|
|
|
|
#Line # experimental ##
|
2017-07-28 15:04:54 +00:00
|
|
|
#Experimental
|
|
|
|
Only used for testing.
|
|
|
|
##
|
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
Set to simplify clip stack using PathOps.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void clipRegion(const SkRegion& deviceRgn, SkClipOp op = SkClipOp::kIntersect)
|
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Clip
|
|
|
|
#Line # combines Clip with Region ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Replace Clip with the intersection or difference of Clip and Region deviceRgn.
|
2017-09-01 19:51:02 +00:00
|
|
|
Resulting Clip is Aliased; pixels are fully contained by the clip.
|
2017-07-28 15:04:54 +00:00
|
|
|
deviceRgn is unaffected by Matrix.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param deviceRgn Region to combine with Clip ##
|
|
|
|
#Param op Clip_Op to apply to Clip ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2017-08-03 21:14:08 +00:00
|
|
|
#Description
|
2017-09-01 19:51:02 +00:00
|
|
|
region is unaffected by canvas rotation; iRect is affected by canvas rotation.
|
|
|
|
Both clips are Aliased; this is not noticeable on Region clip because it
|
2017-08-03 21:14:08 +00:00
|
|
|
aligns to pixel boundaries.
|
|
|
|
##
|
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
SkIRect iRect = {30, 40, 120, 130 };
|
|
|
|
SkRegion region(iRect);
|
|
|
|
canvas->rotate(10);
|
|
|
|
canvas->save();
|
|
|
|
canvas->clipRegion(region, SkClipOp::kIntersect);
|
|
|
|
canvas->drawCircle(50, 50, 45, paint);
|
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(100, 100);
|
|
|
|
canvas->clipRect(SkRect::Make(iRect), SkClipOp::kIntersect);
|
|
|
|
canvas->drawCircle(50, 50, 45, paint);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso clipRect clipRRect clipPath
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
#Method bool quickReject(const SkRect& rect) const
|
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Clip
|
|
|
|
#Line # returns if Rect is outside Clip ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Return true if Rect rect, transformed by Matrix, can be quickly determined to be
|
|
|
|
outside of Clip. May return false even though rect is outside of Clip.
|
|
|
|
|
|
|
|
Use to check if an area to be drawn is clipped out, to skip subsequent draw calls.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param rect Rect to compare with Clip ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Return true if rect, transformed by Matrix, does not intersect Clip ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
2018-02-07 01:58:51 +00:00
|
|
|
SkRect testRect = {30, 30, 120, 129 };
|
|
|
|
SkRect clipRect = {30, 130, 120, 230 };
|
2017-08-03 21:14:08 +00:00
|
|
|
canvas->save();
|
|
|
|
canvas->clipRect(clipRect);
|
|
|
|
SkDebugf("quickReject %s\n", canvas->quickReject(testRect) ? "true" : "false");
|
|
|
|
canvas->restore();
|
|
|
|
canvas->rotate(10);
|
|
|
|
canvas->clipRect(clipRect);
|
|
|
|
SkDebugf("quickReject %s\n", canvas->quickReject(testRect) ? "true" : "false");
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
#StdOut
|
2017-08-03 21:14:08 +00:00
|
|
|
quickReject true
|
2017-07-28 15:04:54 +00:00
|
|
|
quickReject false
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso getLocalClipBounds getTotalMatrix SkBitmap::drawsNothing
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
#Method bool quickReject(const SkPath& path) const
|
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Clip
|
2017-07-28 15:04:54 +00:00
|
|
|
Return true if path, transformed by Matrix, can be quickly determined to be
|
|
|
|
outside of Clip. May return false even though path is outside of Clip.
|
|
|
|
|
|
|
|
Use to check if an area to be drawn is clipped out, to skip subsequent draw calls.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param path Path to compare with Clip ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Return true if path, transformed by Matrix, does not intersect Clip ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
2018-02-07 01:58:51 +00:00
|
|
|
SkPoint testPoints[] = {{30, 30}, {120, 30}, {120, 129} };
|
|
|
|
SkPoint clipPoints[] = {{30, 130}, {120, 130}, {120, 230} };
|
2017-08-03 21:14:08 +00:00
|
|
|
SkPath testPath, clipPath;
|
|
|
|
testPath.addPoly(testPoints, SK_ARRAY_COUNT(testPoints), true);
|
|
|
|
clipPath.addPoly(clipPoints, SK_ARRAY_COUNT(clipPoints), true);
|
|
|
|
canvas->save();
|
|
|
|
canvas->clipPath(clipPath);
|
|
|
|
SkDebugf("quickReject %s\n", canvas->quickReject(testPath) ? "true" : "false");
|
|
|
|
canvas->restore();
|
|
|
|
canvas->rotate(10);
|
|
|
|
canvas->clipPath(clipPath);
|
|
|
|
SkDebugf("quickReject %s\n", canvas->quickReject(testPath) ? "true" : "false");
|
2017-07-28 15:04:54 +00:00
|
|
|
#StdOut
|
2017-08-03 21:14:08 +00:00
|
|
|
quickReject true
|
2017-07-28 15:04:54 +00:00
|
|
|
quickReject false
|
|
|
|
##
|
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso getLocalClipBounds getTotalMatrix SkBitmap::drawsNothing
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
#Method SkRect getLocalClipBounds() const
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Clip
|
|
|
|
#Line # returns Clip bounds in source coordinates ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Return bounds of Clip, transformed by inverse of Matrix. If Clip is empty,
|
|
|
|
return SkRect::MakeEmpty, where all Rect sides equal zero.
|
|
|
|
|
|
|
|
Rect returned is outset by one to account for partial pixel coverage if Clip
|
2017-09-01 19:51:02 +00:00
|
|
|
is Anti-aliased.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Return bounds of Clip in local coordinates ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2018-02-07 01:58:51 +00:00
|
|
|
#Description
|
2017-07-28 15:04:54 +00:00
|
|
|
Initial bounds is device bounds outset by 1 on all sides.
|
|
|
|
Clipped bounds is clipPath bounds outset by 1 on all sides.
|
|
|
|
Scaling the canvas by two in x and y scales the local bounds by 1/2 in x and y.
|
|
|
|
##
|
2017-08-03 21:14:08 +00:00
|
|
|
SkCanvas local(256, 256);
|
|
|
|
canvas = &local;
|
|
|
|
SkRect bounds = canvas->getLocalClipBounds();
|
|
|
|
SkDebugf("left:%g top:%g right:%g bottom:%g\n",
|
|
|
|
bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom);
|
2018-02-07 01:58:51 +00:00
|
|
|
SkPoint clipPoints[] = {{30, 130}, {120, 130}, {120, 230} };
|
2017-08-03 21:14:08 +00:00
|
|
|
SkPath clipPath;
|
|
|
|
clipPath.addPoly(clipPoints, SK_ARRAY_COUNT(clipPoints), true);
|
|
|
|
canvas->clipPath(clipPath);
|
|
|
|
bounds = canvas->getLocalClipBounds();
|
|
|
|
SkDebugf("left:%g top:%g right:%g bottom:%g\n",
|
|
|
|
bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom);
|
|
|
|
canvas->scale(2, 2);
|
|
|
|
bounds = canvas->getLocalClipBounds();
|
|
|
|
SkDebugf("left:%g top:%g right:%g bottom:%g\n",
|
|
|
|
bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom);
|
|
|
|
#StdOut
|
|
|
|
left:-1 top:-1 right:257 bottom:257
|
|
|
|
left:29 top:129 right:121 bottom:231
|
|
|
|
left:14.5 top:64.5 right:60.5 bottom:115.5
|
|
|
|
##
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
# local canvas in example works around bug in fiddle ##
|
2018-02-06 14:41:53 +00:00
|
|
|
#Bug 6524
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso getDeviceClipBounds getBaseLayerSize quickReject
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
#Method bool getLocalClipBounds(SkRect* bounds) const
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Clip
|
2017-07-28 15:04:54 +00:00
|
|
|
Return bounds of Clip, transformed by inverse of Matrix. If Clip is empty,
|
|
|
|
return false, and set bounds to SkRect::MakeEmpty, where all Rect sides equal zero.
|
|
|
|
|
|
|
|
bounds is outset by one to account for partial pixel coverage if Clip
|
2017-09-01 19:51:02 +00:00
|
|
|
is Anti-aliased.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param bounds Rect of Clip in local coordinates ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Return true if Clip bounds is not empty ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkCanvas local(256, 256);
|
|
|
|
canvas = &local;
|
|
|
|
SkRect bounds;
|
|
|
|
SkDebugf("local bounds empty = %s\n", canvas->getLocalClipBounds(&bounds)
|
|
|
|
? "false" : "true");
|
|
|
|
SkPath path;
|
|
|
|
canvas->clipPath(path);
|
|
|
|
SkDebugf("local bounds empty = %s\n", canvas->getLocalClipBounds(&bounds)
|
|
|
|
? "false" : "true");
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
#StdOut
|
2017-08-03 21:14:08 +00:00
|
|
|
local bounds empty = false
|
2017-07-28 15:04:54 +00:00
|
|
|
local bounds empty = true
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
|
|
|
# local canvas in example works around bug in fiddle ##
|
2018-02-06 14:41:53 +00:00
|
|
|
#Bug 6524
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso getDeviceClipBounds getBaseLayerSize quickReject
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
#Method SkIRect getDeviceClipBounds() const
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Clip
|
|
|
|
#Line # returns IRect bounds of Clip ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Return IRect bounds of Clip, unaffected by Matrix. If Clip is empty,
|
|
|
|
return SkRect::MakeEmpty, where all Rect sides equal zero.
|
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
Unlike getLocalClipBounds, returned IRect is not outset.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Return bounds of Clip in Device coordinates ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
#Description
|
2017-07-28 15:04:54 +00:00
|
|
|
Initial bounds is device bounds, not outset.
|
|
|
|
Clipped bounds is clipPath bounds, not outset.
|
|
|
|
Scaling the canvas by 1/2 in x and y scales the device bounds by 1/2 in x and y.
|
2017-08-03 21:14:08 +00:00
|
|
|
##
|
|
|
|
SkCanvas device(256, 256);
|
|
|
|
canvas = &device;
|
|
|
|
SkIRect bounds = canvas->getDeviceClipBounds();
|
|
|
|
SkDebugf("left:%d top:%d right:%d bottom:%d\n",
|
|
|
|
bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom);
|
2018-02-07 01:58:51 +00:00
|
|
|
SkPoint clipPoints[] = {{30, 130}, {120, 130}, {120, 230} };
|
2017-08-03 21:14:08 +00:00
|
|
|
SkPath clipPath;
|
|
|
|
clipPath.addPoly(clipPoints, SK_ARRAY_COUNT(clipPoints), true);
|
|
|
|
canvas->save();
|
|
|
|
canvas->clipPath(clipPath);
|
|
|
|
bounds = canvas->getDeviceClipBounds();
|
|
|
|
SkDebugf("left:%d top:%d right:%d bottom:%d\n",
|
|
|
|
bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom);
|
|
|
|
canvas->restore();
|
|
|
|
canvas->scale(1.f/2, 1.f/2);
|
|
|
|
canvas->clipPath(clipPath);
|
|
|
|
bounds = canvas->getDeviceClipBounds();
|
|
|
|
SkDebugf("left:%d top:%d right:%d bottom:%d\n",
|
|
|
|
bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom);
|
2017-07-28 15:04:54 +00:00
|
|
|
#StdOut
|
2017-08-03 21:14:08 +00:00
|
|
|
left:0 top:0 right:256 bottom:256
|
|
|
|
left:30 top:130 right:120 bottom:230
|
2017-07-28 15:04:54 +00:00
|
|
|
left:15 top:65 right:60 bottom:115
|
|
|
|
##
|
|
|
|
}
|
|
|
|
##
|
|
|
|
|
|
|
|
#ToDo some confusion on why with an identity Matrix local and device are different ##
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso getLocalClipBounds getBaseLayerSize quickReject
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
# device canvas in example works around bug in fiddle ##
|
2018-02-06 14:41:53 +00:00
|
|
|
#Bug 6524
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
#Method bool getDeviceClipBounds(SkIRect* bounds) const
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Clip
|
2017-07-28 15:04:54 +00:00
|
|
|
Return IRect bounds of Clip, unaffected by Matrix. If Clip is empty,
|
|
|
|
return false, and set bounds to SkRect::MakeEmpty, where all Rect sides equal zero.
|
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
Unlike getLocalClipBounds, bounds is not outset.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param bounds Rect of Clip in device coordinates ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Return true if Clip bounds is not empty ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkIRect bounds;
|
|
|
|
SkDebugf("device bounds empty = %s\n", canvas->getDeviceClipBounds(&bounds)
|
|
|
|
? "false" : "true");
|
|
|
|
SkPath path;
|
|
|
|
canvas->clipPath(path);
|
|
|
|
SkDebugf("device bounds empty = %s\n", canvas->getDeviceClipBounds(&bounds)
|
|
|
|
? "false" : "true");
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
#StdOut
|
2017-08-03 21:14:08 +00:00
|
|
|
device bounds empty = false
|
2017-07-28 15:04:54 +00:00
|
|
|
device bounds empty = true
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso getLocalClipBounds getBaseLayerSize quickReject
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
2018-02-01 14:37:32 +00:00
|
|
|
#Subtopic Clip ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
2018-02-07 12:27:09 +00:00
|
|
|
#Subtopic Draw
|
|
|
|
#Populate
|
|
|
|
#Line # draws into Canvas ##
|
|
|
|
##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Method void drawColor(SkColor color, SkBlendMode mode = SkBlendMode::kSrcOver)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # fills Clip with Color and Blend_Mode ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Fill Clip with Color color.
|
|
|
|
mode determines how Color_ARGB is combined with destination.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param color Unpremultiplied Color_ARGB ##
|
|
|
|
#Param mode SkBlendMode used to combine source color and destination ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2017-08-03 21:14:08 +00:00
|
|
|
canvas->drawColor(SK_ColorRED);
|
|
|
|
canvas->clipRect(SkRect::MakeWH(150, 150));
|
|
|
|
canvas->drawColor(SkColorSetARGB(0x80, 0x00, 0xFF, 0x00), SkBlendMode::kPlus);
|
|
|
|
canvas->clipRect(SkRect::MakeWH(75, 75));
|
|
|
|
canvas->drawColor(SkColorSetARGB(0x80, 0x00, 0x00, 0xFF), SkBlendMode::kPlus);
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso clear SkBitmap::erase drawPaint
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
#Method void clear(SkColor color)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # fills Clip with Color ##
|
2018-02-07 01:58:51 +00:00
|
|
|
Fill Clip with Color color using SkBlendMode::kSrc.
|
2017-07-28 15:04:54 +00:00
|
|
|
This has the effect of replacing all pixels contained by Clip with color.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param color Unpremultiplied Color_ARGB ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
canvas->save();
|
|
|
|
canvas->clipRect(SkRect::MakeWH(256, 128));
|
2018-02-07 01:58:51 +00:00
|
|
|
canvas->clear(SkColorSetARGB(0x80, 0xFF, 0x00, 0x00));
|
2017-08-03 21:14:08 +00:00
|
|
|
canvas->restore();
|
|
|
|
canvas->save();
|
|
|
|
canvas->clipRect(SkRect::MakeWH(150, 192));
|
|
|
|
canvas->clear(SkColorSetARGB(0x80, 0x00, 0xFF, 0x00));
|
|
|
|
canvas->restore();
|
|
|
|
canvas->clipRect(SkRect::MakeWH(75, 256));
|
|
|
|
canvas->clear(SkColorSetARGB(0x80, 0x00, 0x00, 0xFF));
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawColor SkBitmap::erase drawPaint
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
#Method void discard()
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Utility
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # makes Canvas contents undefined ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Make Canvas contents undefined. Subsequent calls that read Canvas pixels,
|
|
|
|
such as drawing with SkBlendMode, return undefined results. discard() does
|
|
|
|
not change Clip or Matrix.
|
|
|
|
|
|
|
|
discard() may do nothing, depending on the implementation of Surface or Device
|
|
|
|
that created Canvas.
|
|
|
|
|
|
|
|
discard() allows optimized performance on subsequent draws by removing
|
|
|
|
cached data associated with Surface or Device.
|
|
|
|
It is not necessary to call discard() once done with Canvas;
|
|
|
|
any cached data is deleted when owning Surface or Device is deleted.
|
|
|
|
|
|
|
|
#ToDo example? not sure how to make this meaningful w/o more implementation detail ##
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso flush() SkSurface::prepareForExternalIO GrContext::abandonContext
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
#NoExample
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawPaint(const SkPaint& paint)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # fills Clip with Paint ##
|
2018-01-20 00:09:32 +00:00
|
|
|
Fill Clip with Paint paint. Paint components Mask_Filter, Shader,
|
2017-08-03 21:14:08 +00:00
|
|
|
Color_Filter, Image_Filter, and Blend_Mode affect drawing;
|
|
|
|
Path_Effect in paint is ignored.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
# can Path_Effect in paint ever alter drawPaint?
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param paint graphics state used to fill Canvas ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE };
|
|
|
|
SkScalar pos[] = { 0, SK_Scalar1/2, SK_Scalar1 };
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setShader(SkGradientShader::MakeSweep(256, 256, colors, pos, SK_ARRAY_COUNT(colors)));
|
|
|
|
canvas->drawPaint(paint);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso clear drawColor SkBitmap::erase
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Enum PointMode
|
2018-02-01 14:37:32 +00:00
|
|
|
#Line # sets drawPoints options ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Code
|
|
|
|
enum PointMode {
|
|
|
|
kPoints_PointMode,
|
|
|
|
kLines_PointMode,
|
2017-09-14 15:25:39 +00:00
|
|
|
kPolygon_PointMode,
|
2017-07-28 15:04:54 +00:00
|
|
|
};
|
|
|
|
##
|
|
|
|
|
|
|
|
Selects if an array of points are drawn as discrete points, as lines, or as
|
|
|
|
an open polygon.
|
|
|
|
|
|
|
|
#Const kPoints_PointMode 0
|
|
|
|
Draw each point separately.
|
|
|
|
##
|
|
|
|
|
|
|
|
#Const kLines_PointMode 1
|
|
|
|
Draw each pair of points as a line segment.
|
|
|
|
##
|
|
|
|
|
|
|
|
#Const kPolygon_PointMode 2
|
|
|
|
Draw the array of points as a open polygon.
|
|
|
|
##
|
|
|
|
|
|
|
|
#Example
|
2018-02-07 01:58:51 +00:00
|
|
|
#Description
|
2017-07-28 15:04:54 +00:00
|
|
|
The upper left corner shows three squares when drawn as points.
|
|
|
|
The upper right corner shows one line; when drawn as lines, two points are required per line.
|
|
|
|
The lower right corner shows two lines; when draw as polygon, no miter is drawn at the corner.
|
|
|
|
The lower left corner shows two lines with a miter when path contains polygon.
|
|
|
|
##
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(10);
|
|
|
|
SkPoint points[] = {{64, 32}, {96, 96}, {32, 96}};
|
|
|
|
canvas->drawPoints(SkCanvas::kPoints_PointMode, 3, points, paint);
|
|
|
|
canvas->translate(128, 0);
|
|
|
|
canvas->drawPoints(SkCanvas::kLines_PointMode, 3, points, paint);
|
|
|
|
canvas->translate(0, 128);
|
|
|
|
canvas->drawPoints(SkCanvas::kPolygon_PointMode, 3, points, paint);
|
|
|
|
SkPath path;
|
|
|
|
path.addPoly(points, 3, false);
|
|
|
|
canvas->translate(-128, 0);
|
|
|
|
canvas->drawPath(path, paint);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawLine drawPoint drawPath
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint& paint)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # draws array as points, lines, polygon ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Draw pts using Clip, Matrix and Paint paint.
|
2017-08-03 21:14:08 +00:00
|
|
|
count is the number of points; if count is less than one, has no effect.
|
2017-07-28 15:04:54 +00:00
|
|
|
mode may be one of: kPoints_PointMode, kLines_PointMode, or kPolygon_PointMode.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
If mode is kPoints_PointMode, the shape of point drawn depends on paint
|
|
|
|
Paint_Stroke_Cap. If paint is set to SkPaint::kRound_Cap, each point draws a
|
|
|
|
circle of diameter Paint_Stroke_Width. If paint is set to SkPaint::kSquare_Cap
|
|
|
|
or SkPaint::kButt_Cap, each point draws a square of width and height
|
|
|
|
Paint_Stroke_Width.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
If mode is kLines_PointMode, each pair of points draws a line segment.
|
|
|
|
One line is drawn for every two points; each point is used once. If count is odd,
|
2018-02-07 01:58:51 +00:00
|
|
|
the final point is ignored.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
If mode is kPolygon_PointMode, each adjacent pair of points draws a line segment.
|
|
|
|
count minus one lines are drawn; the first and last point are used once.
|
|
|
|
|
|
|
|
Each line segment respects paint Paint_Stroke_Cap and Paint_Stroke_Width.
|
|
|
|
Paint_Style is ignored, as if were set to SkPaint::kStroke_Style.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
Always draws each element one at a time; is not affected by
|
|
|
|
Paint_Stroke_Join, and unlike drawPath, does not create a mask from all points
|
2018-02-07 01:58:51 +00:00
|
|
|
and lines before drawing.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-30 12:58:10 +00:00
|
|
|
#Param mode whether pts draws points or lines ##
|
|
|
|
#Param count number of points in the array ##
|
|
|
|
#Param pts array of points to draw ##
|
|
|
|
#Param paint stroke, blend, color, and so on, used to draw ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 200
|
2018-02-07 01:58:51 +00:00
|
|
|
#Description
|
2017-07-28 15:04:54 +00:00
|
|
|
#List
|
|
|
|
# The first column draws points. ##
|
|
|
|
# The second column draws points as lines. ##
|
|
|
|
# The third column draws points as a polygon. ##
|
|
|
|
# The fourth column draws points as a polygonal path. ##
|
|
|
|
# The first row uses a round cap and round join. ##
|
|
|
|
# The second row uses a square cap and a miter join. ##
|
|
|
|
# The third row uses a butt cap and a bevel join. ##
|
|
|
|
##
|
|
|
|
The transparent color makes multiple line draws visible;
|
|
|
|
the path is drawn all at once.
|
|
|
|
##
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(10);
|
|
|
|
paint.setColor(0x80349a45);
|
|
|
|
const SkPoint points[] = {{32, 16}, {48, 48}, {16, 32}};
|
2018-02-07 01:58:51 +00:00
|
|
|
const SkPaint::Join join[] = { SkPaint::kRound_Join,
|
2017-08-03 21:14:08 +00:00
|
|
|
SkPaint::kMiter_Join,
|
|
|
|
SkPaint::kBevel_Join };
|
|
|
|
int joinIndex = 0;
|
|
|
|
SkPath path;
|
|
|
|
path.addPoly(points, 3, false);
|
|
|
|
for (const auto cap : { SkPaint::kRound_Cap, SkPaint::kSquare_Cap, SkPaint::kButt_Cap } ) {
|
|
|
|
paint.setStrokeCap(cap);
|
|
|
|
paint.setStrokeJoin(join[joinIndex++]);
|
|
|
|
for (const auto mode : { SkCanvas::kPoints_PointMode,
|
|
|
|
SkCanvas::kLines_PointMode,
|
|
|
|
SkCanvas::kPolygon_PointMode } ) {
|
|
|
|
canvas->drawPoints(mode, 3, points, paint);
|
|
|
|
canvas->translate(64, 0);
|
|
|
|
}
|
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
canvas->translate(-192, 64);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawLine drawPoint drawPath
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawPoint(SkScalar x, SkScalar y, const SkPaint& paint)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # draws point at (x, y) position ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Draw point at (x, y) using Clip, Matrix and Paint paint.
|
|
|
|
|
|
|
|
The shape of point drawn depends on paint Paint_Stroke_Cap.
|
2017-08-03 21:14:08 +00:00
|
|
|
If paint is set to SkPaint::kRound_Cap, draw a circle of diameter
|
2018-02-07 01:58:51 +00:00
|
|
|
Paint_Stroke_Width. If paint is set to SkPaint::kSquare_Cap or SkPaint::kButt_Cap,
|
2017-07-28 15:04:54 +00:00
|
|
|
draw a square of width and height Paint_Stroke_Width.
|
|
|
|
Paint_Style is ignored, as if were set to SkPaint::kStroke_Style.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param x left edge of circle or square ##
|
|
|
|
#Param y top edge of circle or square ##
|
|
|
|
#Param paint stroke, blend, color, and so on, used to draw ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setColor(0x80349a45);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(100);
|
|
|
|
paint.setStrokeCap(SkPaint::kRound_Cap);
|
|
|
|
canvas->scale(1, 1.2f);
|
|
|
|
canvas->drawPoint(64, 96, paint);
|
|
|
|
canvas->scale(.6f, .8f);
|
|
|
|
paint.setColor(SK_ColorWHITE);
|
|
|
|
canvas->drawPoint(106, 120, paint);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawPoints drawCircle drawRect drawLine drawPath
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Method void drawPoint(SkPoint p, const SkPaint& paint)
|
|
|
|
|
|
|
|
Draw point p using Clip, Matrix and Paint paint.
|
|
|
|
|
|
|
|
The shape of point drawn depends on paint Paint_Stroke_Cap.
|
|
|
|
If paint is set to SkPaint::kRound_Cap, draw a circle of diameter
|
2018-02-07 01:58:51 +00:00
|
|
|
Paint_Stroke_Width. If paint is set to SkPaint::kSquare_Cap or SkPaint::kButt_Cap,
|
2017-08-03 21:14:08 +00:00
|
|
|
draw a square of width and height Paint_Stroke_Width.
|
|
|
|
Paint_Style is ignored, as if were set to SkPaint::kStroke_Style.
|
|
|
|
|
|
|
|
#Param p top-left edge of circle or square ##
|
|
|
|
#Param paint stroke, blend, color, and so on, used to draw ##
|
|
|
|
|
|
|
|
#Example
|
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setColor(0x80349a45);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(100);
|
|
|
|
paint.setStrokeCap(SkPaint::kSquare_Cap);
|
|
|
|
canvas->scale(1, 1.2f);
|
|
|
|
canvas->drawPoint({64, 96}, paint);
|
|
|
|
canvas->scale(.6f, .8f);
|
|
|
|
paint.setColor(SK_ColorWHITE);
|
|
|
|
canvas->drawPoint(106, 120, paint);
|
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawPoints drawCircle drawRect drawLine drawPath
|
2017-08-03 21:14:08 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint& paint)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # draws line segment between two points ##
|
2017-08-03 21:14:08 +00:00
|
|
|
Draws line segment from (x0, y0) to (x1, y1) using Clip, Matrix, and Paint paint.
|
|
|
|
In paint: Paint_Stroke_Width describes the line thickness;
|
|
|
|
Paint_Stroke_Cap draws the end rounded or square;
|
2017-07-28 15:04:54 +00:00
|
|
|
Paint_Style is ignored, as if were set to SkPaint::kStroke_Style.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param x0 start of line segment on x-axis ##
|
|
|
|
#Param y0 start of line segment on y-axis ##
|
|
|
|
#Param x1 end of line segment on x-axis ##
|
|
|
|
#Param y1 end of line segment on y-axis ##
|
|
|
|
#Param paint stroke, blend, color, and so on, used to draw ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2017-08-03 21:14:08 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setColor(0xFF9a67be);
|
|
|
|
paint.setStrokeWidth(20);
|
|
|
|
canvas->skew(1, 0);
|
|
|
|
canvas->drawLine(32, 96, 32, 160, paint);
|
|
|
|
canvas->skew(-2, 0);
|
|
|
|
canvas->drawLine(288, 96, 288, 160, paint);
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawPoint drawCircle drawRect drawPath
|
2017-08-03 21:14:08 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
#Method void drawLine(SkPoint p0, SkPoint p1, const SkPaint& paint)
|
|
|
|
|
|
|
|
Draws line segment from p0 to p1 using Clip, Matrix, and Paint paint.
|
|
|
|
In paint: Paint_Stroke_Width describes the line thickness;
|
|
|
|
Paint_Stroke_Cap draws the end rounded or square;
|
|
|
|
Paint_Style is ignored, as if were set to SkPaint::kStroke_Style.
|
|
|
|
|
|
|
|
#Param p0 start of line segment ##
|
|
|
|
#Param p1 end of line segment ##
|
|
|
|
#Param paint stroke, blend, color, and so on, used to draw ##
|
|
|
|
|
|
|
|
#Example
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setColor(0xFF9a67be);
|
|
|
|
paint.setStrokeWidth(20);
|
|
|
|
canvas->skew(1, 0);
|
|
|
|
canvas->drawLine({32, 96}, {32, 160}, paint);
|
|
|
|
canvas->skew(-2, 0);
|
|
|
|
canvas->drawLine({288, 96}, {288, 160}, paint);
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawPoint drawCircle drawRect drawPath
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawRect(const SkRect& rect, const SkPaint& paint)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # draws Rect using Clip, Matrix, and Paint ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Draw Rect rect using Clip, Matrix, and Paint paint.
|
2018-02-07 01:58:51 +00:00
|
|
|
In paint: Paint_Style determines if rectangle is stroked or filled;
|
2017-07-28 15:04:54 +00:00
|
|
|
if stroked, Paint_Stroke_Width describes the line thickness, and
|
|
|
|
Paint_Stroke_Join draws the corners rounded or square.
|
|
|
|
|
2017-10-04 18:31:33 +00:00
|
|
|
#Param rect rectangle to draw ##
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param paint stroke or fill, blend, color, and so on, used to draw ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkPoint rectPts[] = { {64, 48}, {192, 160} };
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(20);
|
|
|
|
paint.setStrokeJoin(SkPaint::kRound_Join);
|
|
|
|
SkMatrix rotator;
|
|
|
|
rotator.setRotate(30, 128, 128);
|
|
|
|
for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorMAGENTA } ) {
|
|
|
|
paint.setColor(color);
|
|
|
|
SkRect rect;
|
|
|
|
rect.set(rectPts[0], rectPts[1]);
|
|
|
|
canvas->drawRect(rect, paint);
|
|
|
|
rotator.mapPoints(rectPts, 2);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
#SeeAlso drawIRect drawRRect drawRoundRect drawRegion drawPath drawLine
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
#Method void drawIRect(const SkIRect& rect, const SkPaint& paint)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # draws IRect using Clip, Matrix, and Paint ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Draw IRect rect using Clip, Matrix, and Paint paint.
|
2018-02-07 01:58:51 +00:00
|
|
|
In paint: Paint_Style determines if rectangle is stroked or filled;
|
2017-07-28 15:04:54 +00:00
|
|
|
if stroked, Paint_Stroke_Width describes the line thickness, and
|
|
|
|
Paint_Stroke_Join draws the corners rounded or square.
|
|
|
|
|
2017-10-04 18:31:33 +00:00
|
|
|
#Param rect rectangle to draw ##
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param paint stroke or fill, blend, color, and so on, used to draw ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2017-08-03 21:14:08 +00:00
|
|
|
SkIRect rect = { 64, 48, 192, 160 };
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(20);
|
|
|
|
paint.setStrokeJoin(SkPaint::kRound_Join);
|
|
|
|
for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorMAGENTA } ) {
|
|
|
|
paint.setColor(color);
|
|
|
|
canvas->drawIRect(rect, paint);
|
|
|
|
canvas->rotate(30, 128, 128);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawRect drawRRect drawRoundRect drawRegion drawPath drawLine
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawRegion(const SkRegion& region, const SkPaint& paint)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # draws Region using Clip, Matrix, and Paint ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Draw Region region using Clip, Matrix, and Paint paint.
|
2018-02-07 01:58:51 +00:00
|
|
|
In paint: Paint_Style determines if rectangle is stroked or filled;
|
2017-07-28 15:04:54 +00:00
|
|
|
if stroked, Paint_Stroke_Width describes the line thickness, and
|
|
|
|
Paint_Stroke_Join draws the corners rounded or square.
|
|
|
|
|
2017-10-04 18:31:33 +00:00
|
|
|
#Param region region to draw ##
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param paint Paint stroke or fill, blend, color, and so on, used to draw ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkRegion region;
|
|
|
|
region.op( 10, 10, 50, 50, SkRegion::kUnion_Op);
|
|
|
|
region.op( 10, 50, 90, 90, SkRegion::kUnion_Op);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(20);
|
|
|
|
paint.setStrokeJoin(SkPaint::kRound_Join);
|
|
|
|
canvas->drawRegion(region, paint);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawRect drawIRect drawPath
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawOval(const SkRect& oval, const SkPaint& paint)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # draws Oval using Clip, Matrix, and Paint ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Draw Oval oval using Clip, Matrix, and Paint.
|
2018-02-07 01:58:51 +00:00
|
|
|
In paint: Paint_Style determines if Oval is stroked or filled;
|
2017-07-28 15:04:54 +00:00
|
|
|
if stroked, Paint_Stroke_Width describes the line thickness.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param oval Rect bounds of Oval ##
|
|
|
|
#Param paint Paint stroke or fill, blend, color, and so on, used to draw ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
canvas->clear(0xFF3f5f9f);
|
|
|
|
SkColor kColor1 = SkColorSetARGB(0xff, 0xff, 0x7f, 0);
|
|
|
|
SkColor g1Colors[] = { kColor1, SkColorSetA(kColor1, 0x20) };
|
|
|
|
SkPoint g1Points[] = { { 0, 0 }, { 0, 100 } };
|
|
|
|
SkScalar pos[] = { 0.2f, 1.0f };
|
|
|
|
SkRect bounds = SkRect::MakeWH(80, 70);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setShader(SkGradientShader::MakeLinear(g1Points, g1Colors, pos, SK_ARRAY_COUNT(g1Colors),
|
|
|
|
SkShader::kClamp_TileMode));
|
|
|
|
canvas->drawOval(bounds , paint);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawCircle drawPoint drawPath drawRRect drawRoundRect
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawRRect(const SkRRect& rrect, const SkPaint& paint)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # draws Round_Rect using Clip, Matrix, and Paint ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Draw Round_Rect rrect using Clip, Matrix, and Paint paint.
|
2018-02-07 01:58:51 +00:00
|
|
|
In paint: Paint_Style determines if rrect is stroked or filled;
|
2017-07-28 15:04:54 +00:00
|
|
|
if stroked, Paint_Stroke_Width describes the line thickness.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
rrect may represent a rectangle, circle, oval, uniformly rounded rectangle, or
|
|
|
|
may have any combination of positive non-square radii for the four corners.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param rrect Round_Rect with up to eight corner radii to draw ##
|
|
|
|
#Param paint Paint stroke or fill, blend, color, and so on, used to draw ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
SkRect outer = {30, 40, 210, 220};
|
|
|
|
SkRect radii = {30, 50, 70, 90 };
|
|
|
|
SkRRect rRect;
|
|
|
|
rRect.setNinePatch(outer, radii.fLeft, radii.fTop, radii.fRight, radii.fBottom);
|
|
|
|
canvas->drawRRect(rRect, paint);
|
|
|
|
paint.setColor(SK_ColorWHITE);
|
|
|
|
canvas->drawLine(outer.fLeft + radii.fLeft, outer.fTop,
|
|
|
|
outer.fLeft + radii.fLeft, outer.fBottom, paint);
|
2018-02-07 01:58:51 +00:00
|
|
|
canvas->drawLine(outer.fRight - radii.fRight, outer.fTop,
|
2017-08-03 21:14:08 +00:00
|
|
|
outer.fRight - radii.fRight, outer.fBottom, paint);
|
2018-02-07 01:58:51 +00:00
|
|
|
canvas->drawLine(outer.fLeft, outer.fTop + radii.fTop,
|
2017-08-03 21:14:08 +00:00
|
|
|
outer.fRight, outer.fTop + radii.fTop, paint);
|
2018-02-07 01:58:51 +00:00
|
|
|
canvas->drawLine(outer.fLeft, outer.fBottom - radii.fBottom,
|
2017-08-03 21:14:08 +00:00
|
|
|
outer.fRight, outer.fBottom - radii.fBottom, paint);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawRect drawRoundRect drawDRRect drawCircle drawOval drawPath
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # draws double Round_Rect stroked or filled ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Draw Round_Rect outer and inner
|
2018-02-07 01:58:51 +00:00
|
|
|
using Clip, Matrix, and Paint paint.
|
2017-07-28 15:04:54 +00:00
|
|
|
outer must contain inner or the drawing is undefined.
|
2018-02-07 01:58:51 +00:00
|
|
|
In paint: Paint_Style determines if Round_Rect is stroked or filled;
|
2017-07-28 15:04:54 +00:00
|
|
|
if stroked, Paint_Stroke_Width describes the line thickness.
|
2017-08-03 21:14:08 +00:00
|
|
|
If stroked and Round_Rect corner has zero length radii, Paint_Stroke_Join can
|
2018-02-07 01:58:51 +00:00
|
|
|
draw corners rounded or square.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
GPU-backed platforms optimize drawing when both outer and inner are
|
2017-07-28 15:04:54 +00:00
|
|
|
concave and outer contains inner. These platforms may not be able to draw
|
2018-02-07 01:58:51 +00:00
|
|
|
Path built with identical data as fast.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param outer Round_Rect outer bounds to draw ##
|
|
|
|
#Param inner Round_Rect inner bounds to draw ##
|
|
|
|
#Param paint Paint stroke or fill, blend, color, and so on, used to draw ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkRRect outer = SkRRect::MakeRect({20, 40, 210, 200});
|
|
|
|
SkRRect inner = SkRRect::MakeOval({60, 70, 170, 160});
|
|
|
|
SkPaint paint;
|
|
|
|
canvas->drawDRRect(outer, inner, paint);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
|
|
|
#Example
|
|
|
|
#Description
|
|
|
|
Outer Rect has no corner radii, but stroke join is rounded.
|
|
|
|
Inner Round_Rect has corner radii; outset stroke increases radii of corners.
|
|
|
|
Stroke join does not affect inner Round_Rect since it has no sharp corners.
|
|
|
|
##
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkRRect outer = SkRRect::MakeRect({20, 40, 210, 200});
|
|
|
|
SkRRect inner = SkRRect::MakeRectXY({60, 70, 170, 160}, 10, 10);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(20);
|
|
|
|
paint.setStrokeJoin(SkPaint::kRound_Join);
|
|
|
|
canvas->drawDRRect(outer, inner, paint);
|
|
|
|
paint.setStrokeWidth(1);
|
|
|
|
paint.setColor(SK_ColorWHITE);
|
|
|
|
canvas->drawDRRect(outer, inner, paint);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawRect drawRoundRect drawRRect drawCircle drawOval drawPath
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint& paint)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # draws Circle using Clip, Matrix, and Paint ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Draw Circle at (cx, cy) with radius using Clip, Matrix, and Paint paint.
|
|
|
|
If radius is zero or less, nothing is drawn.
|
2018-02-07 01:58:51 +00:00
|
|
|
In paint: Paint_Style determines if Circle is stroked or filled;
|
2017-07-28 15:04:54 +00:00
|
|
|
if stroked, Paint_Stroke_Width describes the line thickness.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param cx Circle center on the x-axis ##
|
|
|
|
#Param cy Circle center on the y-axis ##
|
|
|
|
#Param radius half the diameter of Circle ##
|
|
|
|
#Param paint Paint stroke or fill, blend, color, and so on, used to draw ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
canvas->drawCircle(128, 128, 90, paint);
|
|
|
|
paint.setColor(SK_ColorWHITE);
|
|
|
|
canvas->drawCircle(86, 86, 20, paint);
|
|
|
|
canvas->drawCircle(160, 76, 20, paint);
|
|
|
|
canvas->drawCircle(140, 150, 35, paint);
|
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawOval drawRRect drawRoundRect drawPath drawArc drawPoint drawLine
|
2017-08-03 21:14:08 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
#Method void drawCircle(SkPoint center, SkScalar radius, const SkPaint& paint)
|
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
Draw Circle at center with radius using Clip, Matrix, and Paint paint.
|
2017-08-03 21:14:08 +00:00
|
|
|
If radius is zero or less, nothing is drawn.
|
2018-02-07 01:58:51 +00:00
|
|
|
In paint: Paint_Style determines if Circle is stroked or filled;
|
2017-08-03 21:14:08 +00:00
|
|
|
if stroked, Paint_Stroke_Width describes the line thickness.
|
|
|
|
|
|
|
|
#Param center Circle center ##
|
|
|
|
#Param radius half the diameter of Circle ##
|
|
|
|
#Param paint Paint stroke or fill, blend, color, and so on, used to draw ##
|
|
|
|
|
|
|
|
#Example
|
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
canvas->drawCircle(128, 128, 90, paint);
|
|
|
|
paint.setColor(SK_ColorWHITE);
|
|
|
|
canvas->drawCircle({86, 86}, 20, paint);
|
|
|
|
canvas->drawCircle({160, 76}, 20, paint);
|
|
|
|
canvas->drawCircle({140, 150}, 35, paint);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawOval drawRRect drawRoundRect drawPath drawArc drawPoint drawLine
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle,
|
|
|
|
bool useCenter, const SkPaint& paint)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # draws Arc using Clip, Matrix, and Paint ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Draw Arc using Clip, Matrix, and Paint paint.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
Arc is part of Oval bounded by oval, sweeping from startAngle to startAngle plus
|
|
|
|
sweepAngle. startAngle and sweepAngle are in degrees.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
startAngle of zero places start point at the right middle edge of oval.
|
|
|
|
A positive sweepAngle places Arc end point clockwise from start point;
|
|
|
|
a negative sweepAngle places Arc end point counterclockwise from start point.
|
|
|
|
sweepAngle may exceed 360 degrees, a full circle.
|
|
|
|
If useCenter is true, draw a wedge that includes lines from oval
|
|
|
|
center to Arc end points. If useCenter is false, draw Arc between end points.
|
|
|
|
|
|
|
|
If Rect oval is empty or sweepAngle is zero, nothing is drawn.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param oval Rect bounds of Oval containing Arc to draw ##
|
|
|
|
#Param startAngle angle in degrees where Arc begins ##
|
|
|
|
#Param sweepAngle sweep angle in degrees; positive is clockwise ##
|
|
|
|
#Param useCenter if true, include the center of the oval ##
|
|
|
|
#Param paint Paint stroke or fill, blend, color, and so on, used to draw ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
SkRect oval = { 4, 4, 60, 60};
|
|
|
|
for (auto useCenter : { false, true } ) {
|
|
|
|
for (auto style : { SkPaint::kFill_Style, SkPaint::kStroke_Style } ) {
|
|
|
|
paint.setStyle(style);
|
|
|
|
for (auto degrees : { 45, 90, 180, 360} ) {
|
|
|
|
canvas->drawArc(oval, 0, degrees , useCenter, paint);
|
|
|
|
canvas->translate(64, 0);
|
|
|
|
}
|
|
|
|
canvas->translate(-256, 64);
|
|
|
|
}
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 64
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(4);
|
|
|
|
SkRect oval = { 4, 4, 60, 60};
|
|
|
|
float intervals[] = { 5, 5 };
|
|
|
|
paint.setPathEffect(SkDashPathEffect::Make(intervals, 2, 2.5f));
|
|
|
|
for (auto degrees : { 270, 360, 540, 720 } ) {
|
|
|
|
canvas->drawArc(oval, 0, degrees, false, paint);
|
|
|
|
canvas->translate(64, 0);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso SkPath::arcTo drawCircle drawOval drawPath
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry, const SkPaint& paint)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # draws Round_Rect using Clip, Matrix, and Paint ##
|
2017-08-03 21:14:08 +00:00
|
|
|
Draw Round_Rect bounded by Rect rect, with corner radii (rx, ry) using Clip,
|
|
|
|
Matrix, and Paint paint.
|
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
In paint: Paint_Style determines if Round_Rect is stroked or filled;
|
2017-07-28 15:04:54 +00:00
|
|
|
if stroked, Paint_Stroke_Width describes the line thickness.
|
|
|
|
If rx or ry are less than zero, they are treated as if they are zero.
|
|
|
|
If rx plus ry exceeds rect width or rect height, radii are scaled down to fit.
|
2017-08-03 21:14:08 +00:00
|
|
|
If rx and ry are zero, Round_Rect is drawn as Rect and if stroked is affected by
|
|
|
|
Paint_Stroke_Join.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param rect Rect bounds of Round_Rect to draw ##
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param rx axis length in x of oval describing rounded corners ##
|
|
|
|
#Param ry axis length in y of oval describing rounded corners ##
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param paint stroke, blend, color, and so on, used to draw ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Description
|
|
|
|
Top row has a zero radius a generates a rectangle.
|
|
|
|
Second row radii sum to less than sides.
|
|
|
|
Third row radii sum equals sides.
|
|
|
|
Fourth row radii sum exceeds sides; radii are scaled to fit.
|
|
|
|
##
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkVector radii[] = { {0, 20}, {10, 10}, {10, 20}, {10, 40} };
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setStrokeWidth(15);
|
|
|
|
paint.setStrokeJoin(SkPaint::kRound_Join);
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
for (auto style : { SkPaint::kStroke_Style, SkPaint::kFill_Style } ) {
|
|
|
|
paint.setStyle(style );
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(radii); ++i) {
|
|
|
|
canvas->drawRoundRect({10, 10, 60, 40}, radii[i].fX, radii[i].fY, paint);
|
|
|
|
canvas->translate(0, 60);
|
|
|
|
}
|
|
|
|
canvas->translate(80, -240);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso DrawRRect drawRect drawDRRect drawPath drawCircle drawOval drawPoint
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawPath(const SkPath& path, const SkPaint& paint)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # draws Path using Clip, Matrix, and Paint ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Draw Path path using Clip, Matrix, and Paint paint.
|
|
|
|
Path contains an array of Path_Contour, each of which may be open or closed.
|
|
|
|
|
|
|
|
In paint: Paint_Style determines if Round_Rect is stroked or filled:
|
2017-08-03 21:14:08 +00:00
|
|
|
if filled, Path_Fill_Type determines whether Path_Contour describes inside or
|
|
|
|
outside of fill; if stroked, Paint_Stroke_Width describes the line thickness,
|
|
|
|
Paint_Stroke_Cap describes line ends, and Paint_Stroke_Join describes how
|
|
|
|
corners are drawn.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param path Path to draw ##
|
|
|
|
#Param paint stroke, blend, color, and so on, used to draw ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Description
|
|
|
|
Top rows draw stroked path with combinations of joins and caps. The open contour
|
|
|
|
is affected by caps; the closed contour is affected by joins.
|
2018-02-07 01:58:51 +00:00
|
|
|
Bottom row draws fill the same for open and closed contour.
|
2017-07-28 15:04:54 +00:00
|
|
|
First bottom column shows winding fills overlap.
|
|
|
|
Second bottom column shows even odd fills exclude overlap.
|
|
|
|
Third bottom column shows inverse winding fills area outside both contours.
|
|
|
|
##
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkPath path;
|
|
|
|
path.moveTo(20, 20);
|
|
|
|
path.quadTo(60, 20, 60, 60);
|
|
|
|
path.close();
|
|
|
|
path.moveTo(60, 20);
|
|
|
|
path.quadTo(60, 60, 20, 60);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setStrokeWidth(10);
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
for (auto join: { SkPaint::kBevel_Join, SkPaint::kRound_Join, SkPaint::kMiter_Join } ) {
|
|
|
|
paint.setStrokeJoin(join);
|
|
|
|
for (auto cap: { SkPaint::kButt_Cap, SkPaint::kSquare_Cap, SkPaint::kRound_Cap } ) {
|
|
|
|
paint.setStrokeCap(cap);
|
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
canvas->translate(80, 0);
|
|
|
|
}
|
|
|
|
canvas->translate(-240, 60);
|
|
|
|
}
|
|
|
|
paint.setStyle(SkPaint::kFill_Style);
|
2018-02-07 01:58:51 +00:00
|
|
|
for (auto fill : { SkPath::kWinding_FillType,
|
|
|
|
SkPath::kEvenOdd_FillType,
|
2017-08-03 21:14:08 +00:00
|
|
|
SkPath::kInverseWinding_FillType } ) {
|
|
|
|
path.setFillType(fill);
|
|
|
|
canvas->save();
|
|
|
|
canvas->clipRect({0, 10, 80, 70});
|
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(80, 0);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso SkPath drawLine drawArc drawRect drawPoints
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
2018-02-01 14:37:32 +00:00
|
|
|
#Subtopic Draw_Image
|
|
|
|
#Line # draws Image to Canvas ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
drawImage, drawImageRect, and drawImageNine can be called with a bare pointer or
|
|
|
|
a smart pointer as a convenience. The pairs of calls are otherwise identical.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-29 21:36:51 +00:00
|
|
|
#Method void drawImage(const SkImage* image, SkScalar left, SkScalar top, const SkPaint* paint = nullptr)
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Draw_Image
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # draws Image at (x, y) position ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Draw Image image, with its top-left corner at (left, top),
|
|
|
|
using Clip, Matrix, and optional Paint paint.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
If paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter, Blend_Mode,
|
|
|
|
and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader.
|
|
|
|
If paint contains Mask_Filter, generate mask from image bounds. If generated
|
|
|
|
mask extends beyond image bounds, replicate image edge colors, just as Shader
|
|
|
|
made from SkImage::makeShader with SkShader::kClamp_TileMode set replicates the
|
2018-02-07 01:58:51 +00:00
|
|
|
image edge color when it samples outside of its bounds.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param image uncompressed rectangular map of pixels ##
|
|
|
|
#Param left left side of image ##
|
|
|
|
#Param top top side of image ##
|
|
|
|
#Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter,
|
|
|
|
and so on; or nullptr
|
|
|
|
##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 64
|
|
|
|
#Image 4
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
// sk_sp<SkImage> image;
|
|
|
|
SkImage* imagePtr = image.get();
|
|
|
|
canvas->drawImage(imagePtr, 0, 0);
|
|
|
|
SkPaint paint;
|
|
|
|
canvas->drawImage(imagePtr, 80, 0, &paint);
|
|
|
|
paint.setAlpha(0x80);
|
|
|
|
canvas->drawImage(imagePtr, 160, 0, &paint);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawBitmap drawImageLattice drawImageNine drawImageRect SkPaint::setImageFilter
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawImage(const sk_sp<SkImage>& image, SkScalar left, SkScalar top,
|
2018-02-07 01:58:51 +00:00
|
|
|
const SkPaint* paint = nullptr)
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Draw Image image, with its top-left corner at (left, top),
|
|
|
|
using Clip, Matrix, and optional Paint paint.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter,
|
|
|
|
Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader.
|
|
|
|
If paint contains Mask_Filter, generate mask from image bounds. If generated
|
|
|
|
mask extends beyond image bounds, replicate image edge colors, just as Shader
|
|
|
|
made from SkImage::makeShader with SkShader::kClamp_TileMode set replicates the
|
2018-02-07 01:58:51 +00:00
|
|
|
image edge color when it samples outside of its bounds.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param image uncompressed rectangular map of pixels ##
|
|
|
|
#Param left left side of image ##
|
|
|
|
#Param top pop side of image ##
|
|
|
|
#Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter,
|
|
|
|
and so on; or nullptr
|
|
|
|
##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 64
|
|
|
|
#Image 4
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
// sk_sp<SkImage> image;
|
|
|
|
canvas->drawImage(image, 0, 0);
|
|
|
|
SkPaint paint;
|
|
|
|
canvas->drawImage(image, 80, 0, &paint);
|
|
|
|
paint.setAlpha(0x80);
|
|
|
|
canvas->drawImage(image, 160, 0, &paint);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawBitmap drawImageLattice drawImageNine drawImageRect SkPaint::setImageFilter
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Enum SrcRectConstraint
|
2018-02-01 14:37:32 +00:00
|
|
|
#Line # sets drawImageRect options ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Code
|
|
|
|
enum SrcRectConstraint {
|
2018-02-07 01:58:51 +00:00
|
|
|
kStrict_SrcRectConstraint,
|
|
|
|
kFast_SrcRectConstraint,
|
2017-07-28 15:04:54 +00:00
|
|
|
};
|
|
|
|
##
|
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
SrcRectConstraint controls the behavior at the edge of source Rect,
|
|
|
|
provided to drawImageRect, trading off speed for precision.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
Image_Filter in Paint may sample multiple pixels in the image. Source Rect
|
2017-08-03 21:14:08 +00:00
|
|
|
restricts the bounds of pixels that may be read. Image_Filter may slow down if
|
2018-02-07 01:58:51 +00:00
|
|
|
it cannot read outside the bounds, when sampling near the edge of source Rect.
|
2017-07-28 15:04:54 +00:00
|
|
|
SrcRectConstraint specifies whether an Image_Filter is allowed to read pixels
|
2017-09-01 19:51:02 +00:00
|
|
|
outside source Rect.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Const kStrict_SrcRectConstraint
|
2017-09-01 19:51:02 +00:00
|
|
|
Requires Image_Filter to respect source Rect,
|
2017-07-28 15:04:54 +00:00
|
|
|
sampling only inside of its bounds, possibly with a performance penalty.
|
|
|
|
##
|
|
|
|
|
|
|
|
#Const kFast_SrcRectConstraint
|
2017-09-01 19:51:02 +00:00
|
|
|
Permits Image_Filter to sample outside of source Rect
|
2017-07-28 15:04:54 +00:00
|
|
|
by half the width of Image_Filter, permitting it to run faster but with
|
|
|
|
error at the image edges.
|
|
|
|
##
|
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 64
|
|
|
|
#Description
|
|
|
|
redBorder contains a black and white checkerboard bordered by red.
|
|
|
|
redBorder is drawn scaled by 16 on the left.
|
2017-09-01 19:51:02 +00:00
|
|
|
The middle and right bitmaps are filtered checkerboards.
|
2017-07-28 15:04:54 +00:00
|
|
|
Drawing the checkerboard with kStrict_SrcRectConstraint shows only a blur of black and white.
|
|
|
|
Drawing the checkerboard with kFast_SrcRectConstraint allows red to bleed in the corners.
|
|
|
|
##
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkBitmap redBorder;
|
|
|
|
redBorder.allocPixels(SkImageInfo::MakeN32Premul(4, 4));
|
|
|
|
SkCanvas checkRed(redBorder);
|
|
|
|
checkRed.clear(SK_ColorRED);
|
|
|
|
uint32_t checkers[][2] = { { SK_ColorBLACK, SK_ColorWHITE },
|
|
|
|
{ SK_ColorWHITE, SK_ColorBLACK } };
|
|
|
|
checkRed.writePixels(
|
|
|
|
SkImageInfo::MakeN32Premul(2, 2), (void*) checkers, sizeof(checkers[0]), 1, 1);
|
|
|
|
canvas->scale(16, 16);
|
|
|
|
canvas->drawBitmap(redBorder, 0, 0, nullptr);
|
|
|
|
canvas->resetMatrix();
|
|
|
|
sk_sp<SkImage> image = SkImage::MakeFromBitmap(redBorder);
|
|
|
|
SkPaint lowPaint;
|
|
|
|
lowPaint.setFilterQuality(kLow_SkFilterQuality);
|
|
|
|
for (auto constraint : { SkCanvas::kStrict_SrcRectConstraint,
|
|
|
|
SkCanvas::kFast_SrcRectConstraint } ) {
|
|
|
|
canvas->translate(80, 0);
|
|
|
|
canvas->drawImageRect(image.get(), SkRect::MakeLTRB(1, 1, 3, 3),
|
|
|
|
SkRect::MakeLTRB(16, 16, 48, 48), &lowPaint, constraint);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawImageRect drawImage SkPaint::setImageFilter
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawImageRect(const SkImage* image, const SkRect& src, const SkRect& dst,
|
|
|
|
const SkPaint* paint,
|
|
|
|
SrcRectConstraint constraint = kStrict_SrcRectConstraint)
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Draw_Image
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # draws Image, source Rect to destination Rect ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Draw Rect src of Image image, scaled and translated to fill Rect dst.
|
|
|
|
Additionally transform draw using Clip, Matrix, and optional Paint paint.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
|
|
|
If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter,
|
|
|
|
Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader.
|
|
|
|
If paint contains Mask_Filter, generate mask from image bounds.
|
|
|
|
|
|
|
|
If generated mask extends beyond image bounds, replicate image edge colors, just
|
|
|
|
as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set
|
2017-10-04 18:31:33 +00:00
|
|
|
replicates the image edge color when it samples outside of its bounds.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
|
|
|
constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to
|
|
|
|
sample within src; set to kFast_SrcRectConstraint allows sampling outside to
|
|
|
|
improve performance.
|
|
|
|
|
|
|
|
#Param image Image containing pixels, dimensions, and format ##
|
|
|
|
#Param src source Rect of image to draw from ##
|
|
|
|
#Param dst destination Rect of image to draw to ##
|
|
|
|
#Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter,
|
|
|
|
and so on; or nullptr
|
|
|
|
##
|
|
|
|
#Param constraint filter strictly within src or draw faster ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 64
|
|
|
|
#Description
|
|
|
|
The left bitmap draws with Paint default kNone_SkFilterQuality, and stays within
|
2017-10-04 18:31:33 +00:00
|
|
|
its bounds; there is no bleeding with kFast_SrcRectConstraint.
|
2017-07-28 15:04:54 +00:00
|
|
|
the middle and right bitmaps draw with kLow_SkFilterQuality; with
|
|
|
|
kStrict_SrcRectConstraint, the filter remains within the checkerboard, and
|
|
|
|
with kFast_SrcRectConstraint red bleeds on the edges.
|
|
|
|
##
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
2018-02-07 01:58:51 +00:00
|
|
|
uint32_t pixels[][4] = {
|
2017-08-03 21:14:08 +00:00
|
|
|
{ 0xFFFF0000, 0xFFFF0000, 0xFFFF0000, 0xFFFF0000 },
|
|
|
|
{ 0xFFFF0000, 0xFF000000, 0xFFFFFFFF, 0xFFFF0000 },
|
|
|
|
{ 0xFFFF0000, 0xFFFFFFFF, 0xFF000000, 0xFFFF0000 },
|
|
|
|
{ 0xFFFF0000, 0xFFFF0000, 0xFFFF0000, 0xFFFF0000 } };
|
|
|
|
SkBitmap redBorder;
|
2018-02-07 01:58:51 +00:00
|
|
|
redBorder.installPixels(SkImageInfo::MakeN32Premul(4, 4),
|
2017-08-03 21:14:08 +00:00
|
|
|
(void*) pixels, sizeof(pixels[0]));
|
|
|
|
sk_sp<SkImage> image = SkImage::MakeFromBitmap(redBorder);
|
|
|
|
SkPaint lowPaint;
|
|
|
|
for (auto constraint : {
|
|
|
|
SkCanvas::kFast_SrcRectConstraint,
|
|
|
|
SkCanvas::kStrict_SrcRectConstraint,
|
|
|
|
SkCanvas::kFast_SrcRectConstraint } ) {
|
|
|
|
canvas->drawImageRect(image.get(), SkRect::MakeLTRB(1, 1, 3, 3),
|
|
|
|
SkRect::MakeLTRB(16, 16, 48, 48), &lowPaint, constraint);
|
|
|
|
lowPaint.setFilterQuality(kLow_SkFilterQuality);
|
|
|
|
canvas->translate(80, 0);
|
|
|
|
}
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawImageRect(const SkImage* image, const SkIRect& isrc, const SkRect& dst,
|
|
|
|
const SkPaint* paint, SrcRectConstraint constraint = kStrict_SrcRectConstraint)
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Draw_Image
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Draw IRect isrc of Image image, scaled and translated to fill Rect dst.
|
2017-08-03 21:14:08 +00:00
|
|
|
Note that isrc is on integer pixel boundaries; dst may include fractional
|
|
|
|
boundaries. Additionally transform draw using Clip, Matrix, and optional Paint
|
2018-02-07 01:58:51 +00:00
|
|
|
paint.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
|
|
|
If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter,
|
|
|
|
Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader.
|
|
|
|
If paint contains Mask_Filter, generate mask from image bounds.
|
|
|
|
|
|
|
|
If generated mask extends beyond image bounds, replicate image edge colors, just
|
|
|
|
as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set
|
2017-10-04 18:31:33 +00:00
|
|
|
replicates the image edge color when it samples outside of its bounds.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
|
|
|
constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to
|
2017-09-01 19:51:02 +00:00
|
|
|
sample within isrc; set to kFast_SrcRectConstraint allows sampling outside to
|
2017-08-03 21:14:08 +00:00
|
|
|
improve performance.
|
|
|
|
|
|
|
|
#Param image Image containing pixels, dimensions, and format ##
|
|
|
|
#Param isrc source IRect of image to draw from ##
|
|
|
|
#Param dst destination Rect of image to draw to ##
|
|
|
|
#Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter,
|
|
|
|
and so on; or nullptr
|
|
|
|
##
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param constraint filter strictly within isrc or draw faster ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Image 4
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
// sk_sp<SkImage> image;
|
|
|
|
for (auto i : { 1, 2, 4, 8 } ) {
|
2018-02-07 01:58:51 +00:00
|
|
|
canvas->drawImageRect(image.get(), SkIRect::MakeLTRB(0, 0, 100, 100),
|
2017-08-03 21:14:08 +00:00
|
|
|
SkRect::MakeXYWH(i * 20, i * 20, i * 20, i * 20), nullptr);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawImageRect(const SkImage* image, const SkRect& dst, const SkPaint* paint,
|
|
|
|
SrcRectConstraint constraint = kStrict_SrcRectConstraint)
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Draw_Image
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
Draw Image image, scaled and translated to fill Rect dst, using Clip, Matrix,
|
|
|
|
and optional Paint paint.
|
|
|
|
|
|
|
|
If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter,
|
|
|
|
Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader.
|
|
|
|
If paint contains Mask_Filter, generate mask from image bounds.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
If generated mask extends beyond image bounds, replicate image edge colors, just
|
|
|
|
as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set
|
2017-10-04 18:31:33 +00:00
|
|
|
replicates the image edge color when it samples outside of its bounds.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
|
|
|
constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to
|
2017-09-01 19:51:02 +00:00
|
|
|
sample within image; set to kFast_SrcRectConstraint allows sampling outside to
|
2017-08-03 21:14:08 +00:00
|
|
|
improve performance.
|
|
|
|
|
|
|
|
#Param image Image containing pixels, dimensions, and format ##
|
|
|
|
#Param dst destination Rect of image to draw to ##
|
|
|
|
#Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter,
|
|
|
|
and so on; or nullptr
|
|
|
|
##
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param constraint filter strictly within image or draw faster ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Image 4
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
// sk_sp<SkImage> image;
|
|
|
|
for (auto i : { 20, 40, 80, 160 } ) {
|
|
|
|
canvas->drawImageRect(image.get(), SkRect::MakeXYWH(i, i, i, i), nullptr);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawImageRect(const sk_sp<SkImage>& image, const SkRect& src, const SkRect& dst,
|
|
|
|
const SkPaint* paint,
|
2018-02-07 01:58:51 +00:00
|
|
|
SrcRectConstraint constraint = kStrict_SrcRectConstraint)
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Draw_Image
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2017-07-28 15:04:54 +00:00
|
|
|
Draw Rect src of Image image, scaled and translated to fill Rect dst.
|
|
|
|
Additionally transform draw using Clip, Matrix, and optional Paint paint.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
|
|
|
If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter,
|
|
|
|
Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader.
|
|
|
|
If paint contains Mask_Filter, generate mask from image bounds.
|
|
|
|
|
|
|
|
If generated mask extends beyond image bounds, replicate image edge colors, just
|
|
|
|
as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set
|
2017-10-04 18:31:33 +00:00
|
|
|
replicates the image edge color when it samples outside of its bounds.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
|
|
|
constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to
|
|
|
|
sample within src; set to kFast_SrcRectConstraint allows sampling outside to
|
|
|
|
improve performance.
|
|
|
|
|
|
|
|
#Param image Image containing pixels, dimensions, and format ##
|
|
|
|
#Param src source Rect of image to draw from ##
|
|
|
|
#Param dst destination Rect of image to draw to ##
|
|
|
|
#Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter,
|
|
|
|
and so on; or nullptr
|
|
|
|
##
|
|
|
|
#Param constraint filter strictly within src or draw faster ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 64
|
|
|
|
#Description
|
|
|
|
Canvas scales and translates; transformation from src to dst also scales.
|
|
|
|
The two matrices are concatenated to create the final transformation.
|
|
|
|
##
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
uint32_t pixels[][2] = { { SK_ColorBLACK, SK_ColorWHITE },
|
|
|
|
{ SK_ColorWHITE, SK_ColorBLACK } };
|
|
|
|
SkBitmap bitmap;
|
2018-02-07 01:58:51 +00:00
|
|
|
bitmap.installPixels(SkImageInfo::MakeN32Premul(2, 2),
|
2017-08-03 21:14:08 +00:00
|
|
|
(void*) pixels, sizeof(pixels[0]));
|
|
|
|
sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap);
|
|
|
|
SkPaint paint;
|
|
|
|
canvas->scale(4, 4);
|
|
|
|
for (auto alpha : { 50, 100, 150, 255 } ) {
|
|
|
|
paint.setAlpha(alpha);
|
|
|
|
canvas->drawImageRect(image, SkRect::MakeWH(2, 2), SkRect::MakeWH(8, 8), &paint);
|
|
|
|
canvas->translate(8, 0);
|
|
|
|
}
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawImageRect(const sk_sp<SkImage>& image, const SkIRect& isrc, const SkRect& dst,
|
2018-02-07 01:58:51 +00:00
|
|
|
const SkPaint* paint, SrcRectConstraint constraint = kStrict_SrcRectConstraint)
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Draw_Image
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2017-07-28 15:04:54 +00:00
|
|
|
Draw IRect isrc of Image image, scaled and translated to fill Rect dst.
|
2017-08-03 21:14:08 +00:00
|
|
|
isrc is on integer pixel boundaries; dst may include fractional boundaries.
|
2017-07-28 15:04:54 +00:00
|
|
|
Additionally transform draw using Clip, Matrix, and optional Paint paint.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
|
|
|
If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter,
|
|
|
|
Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader.
|
|
|
|
If paint contains Mask_Filter, generate mask from image bounds.
|
|
|
|
|
|
|
|
If generated mask extends beyond image bounds, replicate image edge colors, just
|
|
|
|
as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set
|
2017-10-04 18:31:33 +00:00
|
|
|
replicates the image edge color when it samples outside of its bounds.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
|
|
|
constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to
|
2017-09-01 19:51:02 +00:00
|
|
|
sample within image; set to kFast_SrcRectConstraint allows sampling outside to
|
2017-08-03 21:14:08 +00:00
|
|
|
improve performance.
|
|
|
|
|
|
|
|
#Param image Image containing pixels, dimensions, and format ##
|
|
|
|
#Param isrc source IRect of image to draw from ##
|
|
|
|
#Param dst destination Rect of image to draw to ##
|
|
|
|
#Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter,
|
|
|
|
and so on; or nullptr
|
|
|
|
##
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param constraint filter strictly within image or draw faster ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 64
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
uint32_t pixels[][2] = { { 0x00000000, 0x55555555},
|
|
|
|
{ 0xAAAAAAAA, 0xFFFFFFFF} };
|
|
|
|
SkBitmap bitmap;
|
2018-02-07 01:58:51 +00:00
|
|
|
bitmap.installPixels(SkImageInfo::MakeN32Premul(2, 2),
|
2017-08-03 21:14:08 +00:00
|
|
|
(void*) pixels, sizeof(pixels[0]));
|
|
|
|
sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap);
|
|
|
|
SkPaint paint;
|
|
|
|
canvas->scale(4, 4);
|
|
|
|
for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN } ) {
|
|
|
|
paint.setColorFilter(SkColorFilter::MakeModeFilter(color, SkBlendMode::kPlus));
|
|
|
|
canvas->drawImageRect(image, SkIRect::MakeWH(2, 2), SkRect::MakeWH(8, 8), &paint);
|
|
|
|
canvas->translate(8, 0);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine
|
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawImageRect(const sk_sp<SkImage>& image, const SkRect& dst, const SkPaint* paint,
|
2018-02-07 01:58:51 +00:00
|
|
|
SrcRectConstraint constraint = kStrict_SrcRectConstraint)
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Draw_Image
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2017-07-28 15:04:54 +00:00
|
|
|
Draw Image image, scaled and translated to fill Rect dst,
|
|
|
|
using Clip, Matrix, and optional Paint paint.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter,
|
|
|
|
Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader.
|
|
|
|
If paint contains Mask_Filter, generate mask from image bounds.
|
|
|
|
|
|
|
|
If generated mask extends beyond image bounds, replicate image edge colors, just
|
|
|
|
as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set
|
2017-10-04 18:31:33 +00:00
|
|
|
replicates the image edge color when it samples outside of its bounds.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
|
|
|
constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to
|
2017-09-01 19:51:02 +00:00
|
|
|
sample within image; set to kFast_SrcRectConstraint allows sampling outside to
|
2017-08-03 21:14:08 +00:00
|
|
|
improve performance.
|
|
|
|
|
|
|
|
#Param image Image containing pixels, dimensions, and format ##
|
|
|
|
#Param dst destination Rect of image to draw to ##
|
|
|
|
#Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter,
|
|
|
|
and so on; or nullptr
|
|
|
|
##
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param constraint filter strictly within image or draw faster ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 64
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
uint32_t pixels[][2] = { { 0x00000000, 0x55550000},
|
|
|
|
{ 0xAAAA0000, 0xFFFF0000} };
|
|
|
|
SkBitmap bitmap;
|
2018-02-07 01:58:51 +00:00
|
|
|
bitmap.installPixels(SkImageInfo::MakeN32Premul(2, 2),
|
2017-08-03 21:14:08 +00:00
|
|
|
(void*) pixels, sizeof(pixels[0]));
|
|
|
|
sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap);
|
|
|
|
SkPaint paint;
|
|
|
|
canvas->scale(4, 4);
|
|
|
|
for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN } ) {
|
|
|
|
paint.setColorFilter(SkColorFilter::MakeModeFilter(color, SkBlendMode::kPlus));
|
|
|
|
canvas->drawImageRect(image, SkRect::MakeWH(8, 8), &paint);
|
|
|
|
canvas->translate(8, 0);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso SrcRectConstraint drawImage drawImageLattice drawImageNine
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst,
|
|
|
|
const SkPaint* paint = nullptr)
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Draw_Image
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # draws Nine_Patch Image ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-09-14 15:25:39 +00:00
|
|
|
Draw Image image stretched proportionally to fit into Rect dst.
|
2017-08-03 21:14:08 +00:00
|
|
|
IRect center divides the image into nine sections: four sides, four corners, and
|
2017-09-01 19:51:02 +00:00
|
|
|
the center. Corners are unmodified or scaled down proportionately if their sides
|
2017-08-03 21:14:08 +00:00
|
|
|
are larger than dst; center and four sides are scaled to fit remaining space, if any.
|
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
Additionally transform draw using Clip, Matrix, and optional Paint paint.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter,
|
|
|
|
Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader.
|
|
|
|
If paint contains Mask_Filter, generate mask from image bounds.
|
|
|
|
|
|
|
|
If generated mask extends beyond image bounds, replicate image edge colors, just
|
|
|
|
as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set
|
2017-10-04 18:31:33 +00:00
|
|
|
replicates the image edge color when it samples outside of its bounds.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
|
|
|
#Param image Image containing pixels, dimensions, and format ##
|
|
|
|
#Param center IRect edge of image corners and sides ##
|
|
|
|
#Param dst destination Rect of image to draw to ##
|
|
|
|
#Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter,
|
|
|
|
and so on; or nullptr
|
|
|
|
##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 128
|
|
|
|
#Description
|
|
|
|
The leftmost image is smaller than center; only corners are drawn, all scaled to fit.
|
2017-09-01 19:51:02 +00:00
|
|
|
The second image equals the size of center; only corners are drawn without scaling.
|
|
|
|
The remaining images are larger than center. All corners draw without scaling.
|
|
|
|
The sides and center are scaled if needed to take up the remaining space.
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkIRect center = { 20, 10, 50, 40 };
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60));
|
|
|
|
SkCanvas bitCanvas(bitmap);
|
|
|
|
SkPaint paint;
|
|
|
|
SkColor gray = 0xFF000000;
|
|
|
|
int left = 0;
|
|
|
|
for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) {
|
|
|
|
int top = 0;
|
|
|
|
for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) {
|
|
|
|
paint.setColor(gray);
|
|
|
|
bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint);
|
|
|
|
gray += 0x001f1f1f;
|
|
|
|
top = bottom;
|
|
|
|
}
|
2018-02-07 01:58:51 +00:00
|
|
|
left = right;
|
2017-08-03 21:14:08 +00:00
|
|
|
}
|
|
|
|
sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap);
|
|
|
|
SkImage* imagePtr = image.get();
|
|
|
|
for (auto dest: { 20, 30, 40, 60, 90 } ) {
|
|
|
|
canvas->drawImageNine(imagePtr, center, SkRect::MakeWH(dest, dest), nullptr);
|
|
|
|
canvas->translate(dest + 4, 0);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawImage drawBitmapNine drawImageLattice drawImageRect
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawImageNine(const sk_sp<SkImage>& image, const SkIRect& center, const SkRect& dst,
|
2018-02-07 01:58:51 +00:00
|
|
|
const SkPaint* paint = nullptr)
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Draw_Image
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2017-09-14 15:25:39 +00:00
|
|
|
Draw Image image stretched proportionally to fit into Rect dst.
|
2017-08-03 21:14:08 +00:00
|
|
|
IRect center divides the image into nine sections: four sides, four corners, and
|
2017-09-01 19:51:02 +00:00
|
|
|
the center. Corners are not scaled, or scaled down proportionately if their sides
|
2017-08-03 21:14:08 +00:00
|
|
|
are larger than dst; center and four sides are scaled to fit remaining space, if any.
|
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
Additionally transform draw using Clip, Matrix, and optional Paint paint.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter,
|
|
|
|
Blend_Mode, and Draw_Looper. If image is kAlpha_8_SkColorType, apply Shader.
|
|
|
|
If paint contains Mask_Filter, generate mask from image bounds.
|
|
|
|
|
|
|
|
If generated mask extends beyond image bounds, replicate image edge colors, just
|
|
|
|
as Shader made from SkImage::makeShader with SkShader::kClamp_TileMode set
|
2017-10-04 18:31:33 +00:00
|
|
|
replicates the image edge color when it samples outside of its bounds.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
|
|
|
#Param image Image containing pixels, dimensions, and format ##
|
|
|
|
#Param center IRect edge of image corners and sides ##
|
|
|
|
#Param dst destination Rect of image to draw to ##
|
|
|
|
#Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter,
|
|
|
|
and so on; or nullptr
|
|
|
|
##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 128
|
|
|
|
#Description
|
|
|
|
The two leftmost images has four corners and sides to the left and right of center.
|
|
|
|
The leftmost image scales the width of corners proportionately to fit.
|
2018-02-07 01:58:51 +00:00
|
|
|
The third and fourth image corners are not scaled; the sides and center are scaled to
|
2017-07-28 15:04:54 +00:00
|
|
|
fill the remaining space.
|
|
|
|
The rightmost image has four corners scaled vertically to fit, and uses sides above
|
|
|
|
and below center to fill the remaining space.
|
|
|
|
##
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkIRect center = { 20, 10, 50, 40 };
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60));
|
|
|
|
SkCanvas bitCanvas(bitmap);
|
|
|
|
SkPaint paint;
|
|
|
|
SkColor gray = 0xFF000000;
|
|
|
|
int left = 0;
|
|
|
|
for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) {
|
|
|
|
int top = 0;
|
|
|
|
for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) {
|
|
|
|
paint.setColor(gray);
|
|
|
|
bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint);
|
|
|
|
gray += 0x001f1f1f;
|
|
|
|
top = bottom;
|
|
|
|
}
|
2018-02-07 01:58:51 +00:00
|
|
|
left = right;
|
2017-08-03 21:14:08 +00:00
|
|
|
}
|
|
|
|
sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap);
|
|
|
|
for (auto dest: { 20, 30, 40, 60, 90 } ) {
|
|
|
|
canvas->drawImageNine(image, center, SkRect::MakeWH(dest, 110 - dest), nullptr);
|
|
|
|
canvas->translate(dest + 4, 0);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawImage drawBitmapNine drawImageLattice drawImageRect
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
|
2017-08-29 21:36:51 +00:00
|
|
|
const SkPaint* paint = nullptr)
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Draw_Image
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # draws Bitmap at (x, y) position ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Draw Bitmap bitmap, with its top-left corner at (left, top),
|
|
|
|
using Clip, Matrix, and optional Paint paint.
|
|
|
|
|
2017-11-27 15:44:06 +00:00
|
|
|
If Paint paint is not nullptr, apply Color_Filter, Color_Alpha, Image_Filter,
|
2017-08-03 21:14:08 +00:00
|
|
|
Blend_Mode, and Draw_Looper. If bitmap is kAlpha_8_SkColorType, apply Shader.
|
|
|
|
If paint contains Mask_Filter, generate mask from bitmap bounds.
|
|
|
|
|
|
|
|
If generated mask extends beyond bitmap bounds, replicate bitmap edge colors,
|
|
|
|
just as Shader made from SkShader::MakeBitmapShader with
|
2017-10-04 18:31:33 +00:00
|
|
|
SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples
|
2018-02-07 01:58:51 +00:00
|
|
|
outside of its bounds.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
|
|
|
#Param bitmap Bitmap containing pixels, dimensions, and format ##
|
|
|
|
#Param left left side of bitmap ##
|
|
|
|
#Param top top side of bitmap ##
|
|
|
|
#Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter,
|
|
|
|
and so on; or nullptr
|
|
|
|
##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 64
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
uint8_t pixels[][8] = { { 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00},
|
|
|
|
{ 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00},
|
|
|
|
{ 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00},
|
|
|
|
{ 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF},
|
|
|
|
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
|
|
|
|
{ 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00},
|
|
|
|
{ 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00},
|
|
|
|
{ 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF} };
|
|
|
|
SkBitmap bitmap;
|
2018-02-07 01:58:51 +00:00
|
|
|
bitmap.installPixels(SkImageInfo::MakeA8(8, 8),
|
2017-08-03 21:14:08 +00:00
|
|
|
(void*) pixels, sizeof(pixels[0]));
|
|
|
|
SkPaint paint;
|
|
|
|
canvas->scale(4, 4);
|
|
|
|
for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xFF007F00} ) {
|
|
|
|
paint.setColor(color);
|
|
|
|
canvas->drawBitmap(bitmap, 0, 0, &paint);
|
|
|
|
canvas->translate(12, 0);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawImage drawBitmapLattice drawBitmapNine drawBitmapRect SkBitmap::readPixels SkBitmap::writePixels
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawBitmapRect(const SkBitmap& bitmap, const SkRect& src, const SkRect& dst,
|
|
|
|
const SkPaint* paint, SrcRectConstraint constraint = kStrict_SrcRectConstraint)
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Draw_Image
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # draws Bitmap, source Rect to destination Rect ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Draw Rect src of Bitmap bitmap, scaled and translated to fill Rect dst.
|
|
|
|
Additionally transform draw using Clip, Matrix, and optional Paint paint.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
|
|
|
If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter,
|
|
|
|
Blend_Mode, and Draw_Looper. If bitmap is kAlpha_8_SkColorType, apply Shader.
|
|
|
|
If paint contains Mask_Filter, generate mask from bitmap bounds.
|
|
|
|
|
|
|
|
If generated mask extends beyond bitmap bounds, replicate bitmap edge colors,
|
|
|
|
just as Shader made from SkShader::MakeBitmapShader with
|
2017-10-04 18:31:33 +00:00
|
|
|
SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples
|
2017-08-03 21:14:08 +00:00
|
|
|
outside of its bounds.
|
|
|
|
|
|
|
|
constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to
|
|
|
|
sample within src; set to kFast_SrcRectConstraint allows sampling outside to
|
|
|
|
improve performance.
|
|
|
|
|
|
|
|
#Param bitmap Bitmap containing pixels, dimensions, and format ##
|
|
|
|
#Param src source Rect of image to draw from ##
|
|
|
|
#Param dst destination Rect of image to draw to ##
|
|
|
|
#Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter,
|
|
|
|
and so on; or nullptr
|
|
|
|
##
|
|
|
|
#Param constraint filter strictly within src or draw faster ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 64
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
uint8_t pixels[][8] = { { 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00},
|
|
|
|
{ 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00},
|
|
|
|
{ 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00},
|
|
|
|
{ 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF},
|
|
|
|
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
|
|
|
|
{ 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00},
|
|
|
|
{ 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00},
|
|
|
|
{ 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00} };
|
|
|
|
SkBitmap bitmap;
|
2018-02-07 01:58:51 +00:00
|
|
|
bitmap.installPixels(SkImageInfo::MakeA8(8, 8),
|
2017-08-03 21:14:08 +00:00
|
|
|
(void*) pixels, sizeof(pixels[0]));
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setMaskFilter(SkBlurMaskFilter::Make(kSolid_SkBlurStyle, 6));
|
|
|
|
for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xFF007F00} ) {
|
|
|
|
paint.setColor(color);
|
|
|
|
canvas->drawBitmapRect(bitmap, SkRect::MakeWH(8, 8), SkRect::MakeWH(32, 32), &paint);
|
|
|
|
canvas->translate(48, 0);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawImageRect drawBitmap drawBitmapLattice drawBitmapNine
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawBitmapRect(const SkBitmap& bitmap, const SkIRect& isrc, const SkRect& dst,
|
|
|
|
const SkPaint* paint, SrcRectConstraint constraint = kStrict_SrcRectConstraint)
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Draw_Image
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2017-07-28 15:04:54 +00:00
|
|
|
Draw IRect isrc of Bitmap bitmap, scaled and translated to fill Rect dst.
|
2017-08-03 21:14:08 +00:00
|
|
|
isrc is on integer pixel boundaries; dst may include fractional boundaries.
|
2017-07-28 15:04:54 +00:00
|
|
|
Additionally transform draw using Clip, Matrix, and optional Paint paint.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
|
|
|
If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter,
|
|
|
|
Blend_Mode, and Draw_Looper. If bitmap is kAlpha_8_SkColorType, apply Shader.
|
|
|
|
If paint contains Mask_Filter, generate mask from bitmap bounds.
|
|
|
|
|
|
|
|
If generated mask extends beyond bitmap bounds, replicate bitmap edge colors,
|
|
|
|
just as Shader made from SkShader::MakeBitmapShader with
|
2017-10-04 18:31:33 +00:00
|
|
|
SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples
|
2017-08-03 21:14:08 +00:00
|
|
|
outside of its bounds.
|
|
|
|
|
|
|
|
constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to
|
2017-09-01 19:51:02 +00:00
|
|
|
sample within isrc; set to kFast_SrcRectConstraint allows sampling outside to
|
2017-08-03 21:14:08 +00:00
|
|
|
improve performance.
|
|
|
|
|
|
|
|
#Param bitmap Bitmap containing pixels, dimensions, and format ##
|
|
|
|
#Param isrc source IRect of image to draw from ##
|
|
|
|
#Param dst destination Rect of image to draw to ##
|
|
|
|
#Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter,
|
|
|
|
and so on; or nullptr
|
|
|
|
##
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param constraint sample strictly within isrc, or draw faster ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 64
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
uint8_t pixels[][8] = { { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00},
|
|
|
|
{ 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00},
|
|
|
|
{ 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF},
|
|
|
|
{ 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF},
|
|
|
|
{ 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF},
|
|
|
|
{ 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF},
|
|
|
|
{ 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00},
|
|
|
|
{ 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00} };
|
|
|
|
SkBitmap bitmap;
|
2018-02-07 01:58:51 +00:00
|
|
|
bitmap.installPixels(SkImageInfo::MakeA8(8, 8),
|
2017-08-03 21:14:08 +00:00
|
|
|
(void*) pixels, sizeof(pixels[0]));
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setFilterQuality(kHigh_SkFilterQuality);
|
|
|
|
for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xFF007F00, 0xFF7f007f} ) {
|
|
|
|
paint.setColor(color);
|
|
|
|
canvas->drawBitmapRect(bitmap, SkIRect::MakeWH(8, 8), SkRect::MakeWH(32, 32), &paint);
|
|
|
|
canvas->translate(48.25f, 0);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawImageRect drawBitmap drawBitmapLattice drawBitmapNine
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawBitmapRect(const SkBitmap& bitmap, const SkRect& dst, const SkPaint* paint,
|
|
|
|
SrcRectConstraint constraint = kStrict_SrcRectConstraint)
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Draw_Image
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2017-07-28 15:04:54 +00:00
|
|
|
Draw Bitmap bitmap, scaled and translated to fill Rect dst.
|
2017-09-01 19:51:02 +00:00
|
|
|
bitmap bounds is on integer pixel boundaries; dst may include fractional boundaries.
|
2017-07-28 15:04:54 +00:00
|
|
|
Additionally transform draw using Clip, Matrix, and optional Paint paint.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter,
|
|
|
|
Blend_Mode, and Draw_Looper. If bitmap is kAlpha_8_SkColorType, apply Shader.
|
|
|
|
If paint contains Mask_Filter, generate mask from bitmap bounds.
|
|
|
|
|
|
|
|
If generated mask extends beyond bitmap bounds, replicate bitmap edge colors,
|
|
|
|
just as Shader made from SkShader::MakeBitmapShader with
|
2017-10-04 18:31:33 +00:00
|
|
|
SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples
|
2017-08-03 21:14:08 +00:00
|
|
|
outside of its bounds.
|
|
|
|
|
|
|
|
constraint set to kStrict_SrcRectConstraint limits Paint Filter_Quality to
|
2017-09-01 19:51:02 +00:00
|
|
|
sample within bitmap; set to kFast_SrcRectConstraint allows sampling outside to
|
2017-08-03 21:14:08 +00:00
|
|
|
improve performance.
|
|
|
|
|
|
|
|
#Param bitmap Bitmap containing pixels, dimensions, and format ##
|
|
|
|
#Param dst destination Rect of image to draw to ##
|
|
|
|
#Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter,
|
|
|
|
and so on; or nullptr
|
|
|
|
##
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param constraint filter strictly within bitmap or draw faster ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 64
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
uint32_t pixels[][2] = { { 0x00000000, 0x55550000},
|
|
|
|
{ 0xAAAA0000, 0xFFFF0000} };
|
|
|
|
SkBitmap bitmap;
|
2018-02-07 01:58:51 +00:00
|
|
|
bitmap.installPixels(SkImageInfo::MakeN32Premul(2, 2),
|
2017-08-03 21:14:08 +00:00
|
|
|
(void*) pixels, sizeof(pixels[0]));
|
|
|
|
SkPaint paint;
|
|
|
|
canvas->scale(4, 4);
|
|
|
|
for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN } ) {
|
|
|
|
paint.setColorFilter(SkColorFilter::MakeModeFilter(color, SkBlendMode::kPlus));
|
|
|
|
canvas->drawBitmapRect(bitmap, SkRect::MakeWH(8, 8), &paint);
|
|
|
|
canvas->translate(8, 0);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawImageRect drawBitmap drawBitmapLattice drawBitmapNine
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst,
|
2017-08-29 21:36:51 +00:00
|
|
|
const SkPaint* paint = nullptr)
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Draw_Image
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # draws Nine_Patch Bitmap ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-09-14 15:25:39 +00:00
|
|
|
Draw Bitmap bitmap stretched proportionally to fit into Rect dst.
|
2017-08-03 21:14:08 +00:00
|
|
|
IRect center divides the bitmap into nine sections: four sides, four corners,
|
2017-09-01 19:51:02 +00:00
|
|
|
and the center. Corners are not scaled, or scaled down proportionately if their
|
2017-08-03 21:14:08 +00:00
|
|
|
sides are larger than dst; center and four sides are scaled to fit remaining
|
|
|
|
space, if any.
|
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
Additionally transform draw using Clip, Matrix, and optional Paint paint.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter,
|
|
|
|
Blend_Mode, and Draw_Looper. If bitmap is kAlpha_8_SkColorType, apply Shader.
|
|
|
|
If paint contains Mask_Filter, generate mask from bitmap bounds.
|
|
|
|
|
|
|
|
If generated mask extends beyond bitmap bounds, replicate bitmap edge colors,
|
|
|
|
just as Shader made from SkShader::MakeBitmapShader with
|
2017-10-04 18:31:33 +00:00
|
|
|
SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples
|
2017-08-03 21:14:08 +00:00
|
|
|
outside of its bounds.
|
|
|
|
|
|
|
|
#Param bitmap Bitmap containing pixels, dimensions, and format ##
|
|
|
|
#Param center IRect edge of image corners and sides ##
|
|
|
|
#Param dst destination Rect of image to draw to ##
|
|
|
|
#Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter,
|
|
|
|
and so on; or nullptr
|
|
|
|
##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 128
|
|
|
|
#Description
|
|
|
|
The two leftmost bitmap draws has four corners and sides to the left and right of center.
|
|
|
|
The leftmost bitmap draw scales the width of corners proportionately to fit.
|
2018-02-07 01:58:51 +00:00
|
|
|
The third and fourth draw corners are not scaled; the sides and center are scaled to
|
2017-07-28 15:04:54 +00:00
|
|
|
fill the remaining space.
|
|
|
|
The rightmost bitmap draw has four corners scaled vertically to fit, and uses sides above
|
|
|
|
and below center to fill the remaining space.
|
|
|
|
##
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkIRect center = { 20, 10, 50, 40 };
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60));
|
|
|
|
SkCanvas bitCanvas(bitmap);
|
|
|
|
SkPaint paint;
|
|
|
|
SkColor gray = 0xFF000000;
|
|
|
|
int left = 0;
|
|
|
|
for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) {
|
|
|
|
int top = 0;
|
|
|
|
for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) {
|
|
|
|
paint.setColor(gray);
|
|
|
|
bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint);
|
|
|
|
gray += 0x001f1f1f;
|
|
|
|
top = bottom;
|
|
|
|
}
|
2018-02-07 01:58:51 +00:00
|
|
|
left = right;
|
2017-08-03 21:14:08 +00:00
|
|
|
}
|
|
|
|
for (auto dest: { 20, 30, 40, 60, 90 } ) {
|
|
|
|
canvas->drawBitmapNine(bitmap, center, SkRect::MakeWH(dest, 110 - dest), nullptr);
|
|
|
|
canvas->translate(dest + 4, 0);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawImageNine drawBitmap drawBitmapLattice drawBitmapRect
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
#Struct Lattice
|
2018-02-01 14:37:32 +00:00
|
|
|
#Line # divides Bitmap or Image into a rectangular grid ##
|
2017-07-28 15:04:54 +00:00
|
|
|
#Code
|
|
|
|
struct Lattice {
|
2017-12-11 21:03:17 +00:00
|
|
|
enum RectType ...
|
|
|
|
|
|
|
|
const int* fXDivs;
|
|
|
|
const int* fYDivs;
|
|
|
|
const RectType* fRectTypes;
|
|
|
|
int fXCount;
|
|
|
|
int fYCount;
|
|
|
|
const SkIRect* fBounds;
|
|
|
|
const SkColor* fColors;
|
2017-07-28 15:04:54 +00:00
|
|
|
};
|
|
|
|
##
|
|
|
|
|
2017-10-26 11:58:48 +00:00
|
|
|
Lattice divides Bitmap or Image into a rectangular grid.
|
|
|
|
Grid entries on even columns and even rows are fixed; these entries are
|
|
|
|
always drawn at their original size if the destination is large enough.
|
|
|
|
If the destination side is too small to hold the fixed entries, all fixed
|
|
|
|
entries are proportionately scaled down to fit.
|
|
|
|
The grid entries not on even columns and rows are scaled to fit the
|
|
|
|
remaining space, if any.
|
|
|
|
|
2017-12-11 21:03:17 +00:00
|
|
|
#Enum RectType
|
2017-07-28 15:04:54 +00:00
|
|
|
#Code
|
2017-12-11 21:03:17 +00:00
|
|
|
enum RectType : uint8_t {
|
|
|
|
kDefault = 0,
|
|
|
|
kTransparent,
|
|
|
|
kFixedColor,
|
2017-07-28 15:04:54 +00:00
|
|
|
};
|
|
|
|
##
|
|
|
|
|
2017-12-11 21:03:17 +00:00
|
|
|
Optional setting per rectangular grid entry to make it transparent,
|
|
|
|
or to fill the grid entry with a color.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-12-11 21:03:17 +00:00
|
|
|
#Const kDefault 0
|
|
|
|
Draws Bitmap into lattice rectangle.
|
|
|
|
##
|
|
|
|
|
|
|
|
#Const kTransparent 1
|
|
|
|
Skips lattice rectangle by making it transparent.
|
|
|
|
##
|
|
|
|
|
|
|
|
#Const kFixedColor 2
|
|
|
|
Draws one of fColors into lattice rectangle.
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
##
|
|
|
|
|
|
|
|
#Member const int* fXDivs
|
|
|
|
Array of x-coordinates that divide the bitmap vertically.
|
2017-08-03 21:14:08 +00:00
|
|
|
Array entries must be unique, increasing, greater than or equal to
|
|
|
|
fBounds left edge, and less than fBounds right edge.
|
|
|
|
Set the first element to fBounds left to collapse the left column of
|
|
|
|
fixed grid entries.
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#Member const int* fYDivs
|
|
|
|
Array of y-coordinates that divide the bitmap horizontally.
|
2017-08-03 21:14:08 +00:00
|
|
|
Array entries must be unique, increasing, greater than or equal to
|
|
|
|
fBounds top edge, and less than fBounds bottom edge.
|
|
|
|
Set the first element to fBounds top to collapse the top row of fixed
|
|
|
|
grid entries.
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
2017-12-11 21:03:17 +00:00
|
|
|
#Member const RectType* fRectTypes
|
|
|
|
Optional array of fill types, one per rectangular grid entry:
|
2017-08-03 21:14:08 +00:00
|
|
|
array length must be
|
|
|
|
#Formula
|
|
|
|
(fXCount + 1) * (fYCount + 1)
|
|
|
|
##
|
|
|
|
.
|
2017-09-21 16:31:06 +00:00
|
|
|
|
2017-12-11 21:03:17 +00:00
|
|
|
Each RectType is one of: kDefault, kTransparent, kFixedColor.
|
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
Array entries correspond to the rectangular grid entries, ascending
|
|
|
|
left to right and then top to bottom.
|
|
|
|
##
|
|
|
|
|
|
|
|
#Member int fXCount
|
2017-08-03 21:14:08 +00:00
|
|
|
Number of entries in fXDivs array; one less than the number of
|
|
|
|
horizontal divisions.
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#Member int fYCount
|
2017-08-03 21:14:08 +00:00
|
|
|
Number of entries in fYDivs array; one less than the number of vertical
|
|
|
|
divisions.
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#Member const SkIRect* fBounds
|
|
|
|
Optional subset IRect source to draw from.
|
|
|
|
If nullptr, source bounds is dimensions of Bitmap or Image.
|
|
|
|
##
|
|
|
|
|
2017-12-11 21:03:17 +00:00
|
|
|
#Member const SkColor* fColors
|
|
|
|
Optional array of colors, one per rectangular grid entry.
|
|
|
|
Array length must be
|
|
|
|
#Formula
|
|
|
|
(fXCount + 1) * (fYCount + 1)
|
|
|
|
##
|
|
|
|
.
|
|
|
|
|
|
|
|
Array entries correspond to the rectangular grid entries, ascending
|
|
|
|
left to right, then top to bottom.
|
|
|
|
##
|
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
#Struct Lattice ##
|
|
|
|
|
|
|
|
#Method void drawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice, const SkRect& dst,
|
|
|
|
const SkPaint* paint = nullptr)
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Draw_Image
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # draws proportionally stretched Bitmap ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-09-14 15:25:39 +00:00
|
|
|
Draw Bitmap bitmap stretched proportionally to fit into Rect dst.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Lattice lattice divides bitmap into a rectangular grid.
|
|
|
|
Each intersection of an even-numbered row and column is fixed; like the corners
|
2017-08-03 21:14:08 +00:00
|
|
|
of drawBitmapNine, fixed lattice elements never scale larger than their initial
|
2017-10-04 18:31:33 +00:00
|
|
|
size and shrink proportionately when all fixed elements exceed the bitmap
|
2017-08-03 21:14:08 +00:00
|
|
|
dimension. All other grid elements scale to fill the available space, if any.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Additionally transform draw using Clip, Matrix, and optional Paint paint.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter,
|
|
|
|
Blend_Mode, and Draw_Looper. If bitmap is kAlpha_8_SkColorType, apply Shader.
|
|
|
|
If paint contains Mask_Filter, generate mask from bitmap bounds.
|
|
|
|
|
|
|
|
If generated mask extends beyond bitmap bounds, replicate bitmap edge colors,
|
|
|
|
just as Shader made from SkShader::MakeBitmapShader with
|
2017-10-04 18:31:33 +00:00
|
|
|
SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples
|
2017-08-03 21:14:08 +00:00
|
|
|
outside of its bounds.
|
|
|
|
|
|
|
|
#Param bitmap Bitmap containing pixels, dimensions, and format ##
|
|
|
|
#Param lattice division of bitmap into fixed and variable rectangles ##
|
|
|
|
#Param dst destination Rect of image to draw to ##
|
|
|
|
#Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter,
|
|
|
|
and so on; or nullptr
|
|
|
|
##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 128
|
|
|
|
#Description
|
|
|
|
The two leftmost bitmap draws has four corners and sides to the left and right of center.
|
|
|
|
The leftmost bitmap draw scales the width of corners proportionately to fit.
|
2018-02-07 01:58:51 +00:00
|
|
|
The third and fourth draw corners are not scaled; the sides are scaled to
|
2017-07-28 15:04:54 +00:00
|
|
|
fill the remaining space; the center is transparent.
|
|
|
|
The rightmost bitmap draw has four corners scaled vertically to fit, and uses sides above
|
|
|
|
and below center to fill the remaining space.
|
|
|
|
##
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkIRect center = { 20, 10, 50, 40 };
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60));
|
|
|
|
SkCanvas bitCanvas(bitmap);
|
|
|
|
SkPaint paint;
|
|
|
|
SkColor gray = 0xFF000000;
|
|
|
|
int left = 0;
|
|
|
|
for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) {
|
|
|
|
int top = 0;
|
|
|
|
for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) {
|
|
|
|
paint.setColor(gray);
|
|
|
|
bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint);
|
|
|
|
gray += 0x001f1f1f;
|
|
|
|
top = bottom;
|
|
|
|
}
|
2018-02-07 01:58:51 +00:00
|
|
|
left = right;
|
2017-08-03 21:14:08 +00:00
|
|
|
}
|
|
|
|
const int xDivs[] = { center.fLeft, center.fRight };
|
|
|
|
const int yDivs[] = { center.fTop, center.fBottom };
|
2017-12-12 16:22:38 +00:00
|
|
|
SkCanvas::Lattice::RectType fillTypes[3][3];
|
|
|
|
memset(fillTypes, 0, sizeof(fillTypes));
|
|
|
|
fillTypes[1][1] = SkCanvas::Lattice::kTransparent;
|
|
|
|
SkColor dummy[9]; // temporary pending bug fix
|
|
|
|
SkCanvas::Lattice lattice = { xDivs, yDivs, fillTypes[0], SK_ARRAY_COUNT(xDivs),
|
|
|
|
SK_ARRAY_COUNT(yDivs), nullptr, dummy };
|
2017-08-03 21:14:08 +00:00
|
|
|
for (auto dest: { 20, 30, 40, 60, 90 } ) {
|
2017-12-12 16:22:38 +00:00
|
|
|
canvas->drawBitmapLattice(bitmap, lattice, SkRect::MakeWH(dest, 110 - dest), nullptr);
|
2017-08-03 21:14:08 +00:00
|
|
|
canvas->translate(dest + 4, 0);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawImageLattice drawBitmap drawBitmapNine Lattice
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst,
|
|
|
|
const SkPaint* paint = nullptr)
|
2018-01-30 15:08:57 +00:00
|
|
|
#In Draw_Image
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # draws proportionally stretched Image ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-09-14 15:25:39 +00:00
|
|
|
Draw Image image stretched proportionally to fit into Rect dst.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Lattice lattice divides image into a rectangular grid.
|
|
|
|
Each intersection of an even-numbered row and column is fixed; like the corners
|
2017-08-03 21:14:08 +00:00
|
|
|
of drawBitmapNine, fixed lattice elements never scale larger than their initial
|
2017-10-04 18:31:33 +00:00
|
|
|
size and shrink proportionately when all fixed elements exceed the bitmap
|
2017-08-03 21:14:08 +00:00
|
|
|
dimension. All other grid elements scale to fill the available space, if any.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Additionally transform draw using Clip, Matrix, and optional Paint paint.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
If Paint paint is supplied, apply Color_Filter, Color_Alpha, Image_Filter,
|
|
|
|
Blend_Mode, and Draw_Looper. If bitmap is kAlpha_8_SkColorType, apply Shader.
|
|
|
|
If paint contains Mask_Filter, generate mask from bitmap bounds.
|
|
|
|
|
|
|
|
If generated mask extends beyond bitmap bounds, replicate bitmap edge colors,
|
|
|
|
just as Shader made from SkShader::MakeBitmapShader with
|
2017-10-04 18:31:33 +00:00
|
|
|
SkShader::kClamp_TileMode set replicates the bitmap edge color when it samples
|
2017-08-03 21:14:08 +00:00
|
|
|
outside of its bounds.
|
|
|
|
|
|
|
|
#Param image Image containing pixels, dimensions, and format ##
|
|
|
|
#Param lattice division of bitmap into fixed and variable rectangles ##
|
|
|
|
#Param dst destination Rect of image to draw to ##
|
|
|
|
#Param paint Paint containing Blend_Mode, Color_Filter, Image_Filter,
|
|
|
|
and so on; or nullptr
|
|
|
|
##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 128
|
|
|
|
#Description
|
|
|
|
The leftmost image is smaller than center; only corners are drawn, all scaled to fit.
|
2017-09-01 19:51:02 +00:00
|
|
|
The second image equals the size of center; only corners are drawn without scaling.
|
|
|
|
The remaining images are larger than center. All corners draw without scaling. The sides
|
2017-07-28 15:04:54 +00:00
|
|
|
are scaled if needed to take up the remaining space; the center is transparent.
|
|
|
|
##
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkIRect center = { 20, 10, 50, 40 };
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60));
|
|
|
|
SkCanvas bitCanvas(bitmap);
|
|
|
|
SkPaint paint;
|
|
|
|
SkColor gray = 0xFF000000;
|
|
|
|
int left = 0;
|
|
|
|
for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) {
|
|
|
|
int top = 0;
|
|
|
|
for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) {
|
|
|
|
paint.setColor(gray);
|
|
|
|
bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint);
|
|
|
|
gray += 0x001f1f1f;
|
|
|
|
top = bottom;
|
|
|
|
}
|
2018-02-07 01:58:51 +00:00
|
|
|
left = right;
|
2017-08-03 21:14:08 +00:00
|
|
|
}
|
|
|
|
const int xDivs[] = { center.fLeft, center.fRight };
|
|
|
|
const int yDivs[] = { center.fTop, center.fBottom };
|
2017-12-12 16:22:38 +00:00
|
|
|
SkCanvas::Lattice::RectType fillTypes[3][3];
|
2018-02-07 01:58:51 +00:00
|
|
|
memset(fillTypes, 0, sizeof(fillTypes));
|
2017-12-12 16:22:38 +00:00
|
|
|
fillTypes[1][1] = SkCanvas::Lattice::kTransparent;
|
|
|
|
SkColor dummy[9]; // temporary pending bug fix
|
|
|
|
SkCanvas::Lattice lattice = { xDivs, yDivs, fillTypes[0], SK_ARRAY_COUNT(xDivs),
|
|
|
|
SK_ARRAY_COUNT(yDivs), nullptr, dummy };
|
2017-08-03 21:14:08 +00:00
|
|
|
sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap);
|
|
|
|
SkImage* imagePtr = image.get();
|
|
|
|
for (auto dest: { 20, 30, 40, 60, 90 } ) {
|
|
|
|
canvas->drawImageNine(imagePtr, center, SkRect::MakeWH(dest, dest), nullptr);
|
|
|
|
canvas->translate(dest + 4, 0);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawBitmapLattice drawImage drawImageNine Lattice
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
2018-02-01 14:37:32 +00:00
|
|
|
#Subtopic Draw_Image ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
2018-02-07 12:27:09 +00:00
|
|
|
#Subtopic Draw_Text
|
|
|
|
#Populate
|
|
|
|
#Line # draws text into Canvas ##
|
|
|
|
##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Method void drawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
|
|
|
|
const SkPaint& paint)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw_Text
|
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # draws text at (x, y), using font advance ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Draw text, with origin at (x, y), using Clip, Matrix, and Paint paint.
|
|
|
|
|
2017-10-04 18:31:33 +00:00
|
|
|
text meaning depends on Paint_Text_Encoding; by default, text is encoded as
|
2017-08-03 21:14:08 +00:00
|
|
|
UTF-8.
|
|
|
|
|
|
|
|
x and y meaning depends on Paint_Text_Align and Paint_Vertical_Text; by default
|
2017-10-04 18:31:33 +00:00
|
|
|
text draws left to right, positioning the first glyph left side bearing at x
|
2018-02-07 01:58:51 +00:00
|
|
|
and its baseline at y. Text size is affected by Matrix and Paint_Text_Size.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
2018-01-20 00:09:32 +00:00
|
|
|
All elements of paint: Path_Effect, Mask_Filter, Shader,
|
2017-08-03 21:14:08 +00:00
|
|
|
Color_Filter, Image_Filter, and Draw_Looper; apply to text. By default, draws
|
2017-09-01 19:51:02 +00:00
|
|
|
filled 12 point black Glyphs.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param text character code points or Glyphs drawn ##
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param byteLength byte length of text array ##
|
|
|
|
#Param x start of text on x-axis ##
|
|
|
|
#Param y start of text on y-axis ##
|
|
|
|
#Param paint text size, blend, color, and so on, used to draw ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 200
|
|
|
|
#Description
|
|
|
|
The same text is drawn varying Paint_Text_Size and varying
|
2018-02-07 01:58:51 +00:00
|
|
|
Matrix.
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
float textSizes[] = { 12, 18, 24, 36 };
|
|
|
|
for (auto size: textSizes ) {
|
|
|
|
paint.setTextSize(size);
|
|
|
|
canvas->drawText("Aa", 2, 10, 20, paint);
|
|
|
|
canvas->translate(0, size * 2);
|
|
|
|
}
|
|
|
|
paint.reset();
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
float yPos = 20;
|
|
|
|
for (auto size: textSizes ) {
|
|
|
|
float scale = size / 12.f;
|
|
|
|
canvas->resetMatrix();
|
|
|
|
canvas->translate(100, 0);
|
|
|
|
canvas->scale(scale, scale);
|
|
|
|
canvas->drawText("Aa", 2, 10 / scale, yPos / scale, paint);
|
2018-02-07 01:58:51 +00:00
|
|
|
yPos += size * 2;
|
2017-08-03 21:14:08 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawString drawPosText drawPosTextH drawTextBlob drawTextOnPath drawTextRSXform
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
#Method void drawString(const char* string, SkScalar x, SkScalar y, const SkPaint& paint)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw_Text
|
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # draws null terminated string at (x, y) using font advance ##
|
2017-08-03 21:14:08 +00:00
|
|
|
Draw null terminated string, with origin at (x, y), using Clip, Matrix, and
|
|
|
|
Paint paint.
|
|
|
|
|
2017-10-04 18:31:33 +00:00
|
|
|
string meaning depends on Paint_Text_Encoding; by default, strings are encoded
|
|
|
|
as UTF-8. Other values of Paint_Text_Encoding are unlikely to produce the desired
|
2017-08-03 21:14:08 +00:00
|
|
|
results, since zero bytes may be embedded in the string.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
x and y meaning depends on Paint_Text_Align and Paint_Vertical_Text; by default
|
2017-10-04 18:31:33 +00:00
|
|
|
string draws left to right, positioning the first glyph left side bearing at x
|
2018-02-07 01:58:51 +00:00
|
|
|
and its baseline at y. Text size is affected by Matrix and Paint_Text_Size.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-01-20 00:09:32 +00:00
|
|
|
All elements of paint: Path_Effect, Mask_Filter, Shader,
|
2017-08-03 21:14:08 +00:00
|
|
|
Color_Filter, Image_Filter, and Draw_Looper; apply to text. By default, draws
|
2017-09-01 19:51:02 +00:00
|
|
|
filled 12 point black Glyphs.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param string character code points or Glyphs drawn,
|
2017-08-03 21:14:08 +00:00
|
|
|
ending with a char value of zero
|
|
|
|
##
|
|
|
|
#Param x start of string on x-axis ##
|
|
|
|
#Param y start of string on y-axis ##
|
|
|
|
#Param paint text size, blend, color, and so on, used to draw ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
SkPaint paint;
|
|
|
|
canvas->drawString("a small hello", 20, 20, paint);
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawText drawPosText drawPosTextH drawTextBlob drawTextOnPath drawTextRSXform
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
#Method void drawString(const SkString& string, SkScalar x, SkScalar y, const SkPaint& paint)
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
Draw null terminated string, with origin at (x, y), using Clip, Matrix, and
|
|
|
|
Paint paint.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-10-04 18:31:33 +00:00
|
|
|
string meaning depends on Paint_Text_Encoding; by default, strings are encoded
|
|
|
|
as UTF-8. Other values of Paint_Text_Encoding are unlikely to produce the desired
|
2017-08-03 21:14:08 +00:00
|
|
|
results, since zero bytes may be embedded in the string.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
x and y meaning depends on Paint_Text_Align and Paint_Vertical_Text; by default
|
2017-10-04 18:31:33 +00:00
|
|
|
string draws left to right, positioning the first glyph left side bearing at x
|
2018-02-07 01:58:51 +00:00
|
|
|
and its baseline at y. Text size is affected by Matrix and Paint_Text_Size.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
2018-01-20 00:09:32 +00:00
|
|
|
All elements of paint: Path_Effect, Mask_Filter, Shader,
|
2017-08-03 21:14:08 +00:00
|
|
|
Color_Filter, Image_Filter, and Draw_Looper; apply to text. By default, draws
|
2017-09-01 19:51:02 +00:00
|
|
|
filled 12 point black Glyphs.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param string character code points or Glyphs drawn,
|
2017-08-03 21:14:08 +00:00
|
|
|
ending with a char value of zero
|
|
|
|
##
|
|
|
|
#Param x start of string on x-axis ##
|
|
|
|
#Param y start of string on y-axis ##
|
|
|
|
#Param paint text size, blend, color, and so on, used to draw ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
SkPaint paint;
|
|
|
|
SkString string("a small hello");
|
|
|
|
canvas->drawString(string, 20, 20, paint);
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawText drawPosText drawPosTextH drawTextBlob drawTextOnPath drawTextRSXform
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawPosText(const void* text, size_t byteLength, const SkPoint pos[],
|
|
|
|
const SkPaint& paint)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw_Text
|
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # draws text at array of (x, y) positions ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
Draw each glyph in text with the origin in pos array, using Clip, Matrix, and
|
2017-09-01 19:51:02 +00:00
|
|
|
Paint paint. The number of entries in pos array must match the number of Glyphs
|
2017-08-03 21:14:08 +00:00
|
|
|
described by byteLength of text.
|
|
|
|
|
2017-10-04 18:31:33 +00:00
|
|
|
text meaning depends on Paint_Text_Encoding; by default, text is encoded as
|
2017-08-03 21:14:08 +00:00
|
|
|
UTF-8. pos elements' meaning depends on Paint_Text_Align and Paint_Vertical_Text;
|
2017-10-04 18:31:33 +00:00
|
|
|
by default each glyph left side bearing is positioned at x and its
|
2017-08-03 21:14:08 +00:00
|
|
|
baseline is positioned at y. Text size is affected by Matrix and
|
2018-02-07 01:58:51 +00:00
|
|
|
Paint_Text_Size.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-01-20 00:09:32 +00:00
|
|
|
All elements of paint: Path_Effect, Mask_Filter, Shader,
|
2017-08-03 21:14:08 +00:00
|
|
|
Color_Filter, Image_Filter, and Draw_Looper; apply to text. By default, draws
|
2017-09-01 19:51:02 +00:00
|
|
|
filled 12 point black Glyphs.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
Layout engines such as Harfbuzz typically position each glyph
|
2017-10-04 18:31:33 +00:00
|
|
|
rather than using the font advance widths.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param text character code points or Glyphs drawn ##
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param byteLength byte length of text array ##
|
|
|
|
#Param pos array of glyph origins ##
|
|
|
|
#Param paint text size, blend, color, and so on, used to draw ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 120
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
const char hello[] = "HeLLo!";
|
|
|
|
const SkPoint pos[] = { {40, 100}, {82, 95}, {115, 110}, {130, 95}, {145, 85},
|
|
|
|
{172, 100} };
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setTextSize(60);
|
|
|
|
canvas->drawPosText(hello, strlen(hello), pos, paint);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawText drawPosTextH drawTextBlob drawTextOnPath drawTextRSXform
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], SkScalar constY,
|
|
|
|
const SkPaint& paint)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw_Text
|
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # draws text at x positions with common baseline ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
Draw each glyph in text with its (x, y) origin composed from xpos array and
|
|
|
|
constY, using Clip, Matrix, and Paint paint. The number of entries in xpos array
|
2017-09-01 19:51:02 +00:00
|
|
|
must match the number of Glyphs described by byteLength of text.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
2017-10-04 18:31:33 +00:00
|
|
|
text meaning depends on Paint_Text_Encoding; by default, text is encoded as
|
2017-09-01 19:51:02 +00:00
|
|
|
UTF-8. xpos elements' meaning depends on Paint_Text_Align and Paint_Vertical_Text;
|
2017-10-04 18:31:33 +00:00
|
|
|
by default each glyph left side bearing is positioned at an xpos element and
|
2017-08-03 21:14:08 +00:00
|
|
|
its baseline is positioned at constY. Text size is affected by Matrix and
|
2018-02-07 01:58:51 +00:00
|
|
|
Paint_Text_Size.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-01-20 00:09:32 +00:00
|
|
|
All elements of paint: Path_Effect, Mask_Filter, Shader,
|
2017-08-03 21:14:08 +00:00
|
|
|
Color_Filter, Image_Filter, and Draw_Looper; apply to text. By default, draws
|
2017-09-01 19:51:02 +00:00
|
|
|
filled 12 point black Glyphs.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
Layout engines such as Harfbuzz typically position each glyph
|
2017-10-04 18:31:33 +00:00
|
|
|
rather than using the font advance widths if all Glyphs share the same
|
2017-08-03 21:14:08 +00:00
|
|
|
baseline.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param text character code points or Glyphs drawn ##
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param byteLength byte length of text array ##
|
|
|
|
#Param xpos array of x positions, used to position each glyph ##
|
|
|
|
#Param constY shared y coordinate for all of x positions ##
|
|
|
|
#Param paint text size, blend, color, and so on, used to draw ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 40
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkScalar xpos[] = { 20, 40, 80, 160 };
|
|
|
|
SkPaint paint;
|
|
|
|
canvas->drawPosTextH("XXXX", 4, xpos, 20, paint);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawText drawPosText drawTextBlob drawTextOnPath drawTextRSXform
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawTextOnPathHV(const void* text, size_t byteLength, const SkPath& path, SkScalar hOffset,
|
|
|
|
SkScalar vOffset, const SkPaint& paint)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw_Text
|
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # draws text following Path with offsets ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Draw text on Path path, using Clip, Matrix, and Paint paint.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
Origin of text is at distance hOffset along the path, offset by a perpendicular
|
|
|
|
vector of length vOffset. If the path section corresponding the glyph advance is
|
|
|
|
curved, the glyph is drawn curved to match; control points in the glyph are
|
2017-10-04 18:31:33 +00:00
|
|
|
mapped to projected points parallel to the path. If the text advance is larger
|
2017-08-03 21:14:08 +00:00
|
|
|
than the path length, the excess text is clipped.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-10-04 18:31:33 +00:00
|
|
|
text meaning depends on Paint_Text_Encoding; by default, text is encoded as
|
2017-08-03 21:14:08 +00:00
|
|
|
UTF-8. Origin meaning depends on Paint_Text_Align and Paint_Vertical_Text; by
|
2017-10-04 18:31:33 +00:00
|
|
|
default text positions the first glyph left side bearing at origin x and its
|
2018-02-07 01:58:51 +00:00
|
|
|
baseline at origin y. Text size is affected by Matrix and Paint_Text_Size.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-01-20 00:09:32 +00:00
|
|
|
All elements of paint: Path_Effect, Mask_Filter, Shader,
|
2017-08-03 21:14:08 +00:00
|
|
|
Color_Filter, Image_Filter, and Draw_Looper; apply to text. By default, draws
|
2017-09-01 19:51:02 +00:00
|
|
|
filled 12 point black Glyphs.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param text character code points or Glyphs drawn ##
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param byteLength byte length of text array ##
|
|
|
|
#Param path Path providing text baseline ##
|
|
|
|
#Param hOffset distance along path to offset origin ##
|
|
|
|
#Param vOffset offset of text above (if negative) or below (if positive) the path ##
|
|
|
|
#Param paint text size, blend, color, and so on, used to draw ##
|
|
|
|
|
|
|
|
#Example
|
2018-02-07 01:58:51 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
2017-08-03 21:14:08 +00:00
|
|
|
const char aero[] = "correo a" "\xC3" "\xA9" "reo";
|
|
|
|
const size_t len = sizeof(aero) - 1;
|
|
|
|
SkPath path;
|
|
|
|
path.addOval({43-26, 43-26, 43+26, 43+26}, SkPath::kCW_Direction, 3);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setTextSize(24);
|
|
|
|
for (auto offset : { 0, 10, 20 } ) {
|
|
|
|
canvas->drawTextOnPathHV(aero, len, path, 0, -offset, paint);
|
|
|
|
canvas->translate(70 + offset, 70 + offset);
|
|
|
|
}
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawTextOnPath drawText drawPosTextH drawTextBlob drawTextRSXform
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
|
|
|
|
const SkMatrix* matrix, const SkPaint& paint)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw_Text
|
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # draws text following Path contour ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Draw text on Path path, using Clip, Matrix, and Paint paint.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
Origin of text is at beginning of path offset by matrix, if provided, before it
|
|
|
|
is mapped to path. If the path section corresponding the glyph advance is
|
|
|
|
curved, the glyph is drawn curved to match; control points in the glyph are
|
2017-10-04 18:31:33 +00:00
|
|
|
mapped to projected points parallel to the path. If the text advance is larger
|
2017-08-03 21:14:08 +00:00
|
|
|
than the path length, the excess text is clipped.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-10-04 18:31:33 +00:00
|
|
|
text meaning depends on Paint_Text_Encoding; by default, text is encoded as
|
2017-08-03 21:14:08 +00:00
|
|
|
UTF-8. Origin meaning depends on Paint_Text_Align and Paint_Vertical_Text; by
|
2017-10-04 18:31:33 +00:00
|
|
|
default text positions the first glyph left side bearing at origin x and its
|
2018-02-07 01:58:51 +00:00
|
|
|
baseline at origin y. Text size is affected by Matrix and Paint_Text_Size.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-01-20 00:09:32 +00:00
|
|
|
All elements of paint: Path_Effect, Mask_Filter, Shader,
|
2017-08-03 21:14:08 +00:00
|
|
|
Color_Filter, Image_Filter, and Draw_Looper; apply to text. By default, draws
|
2017-09-01 19:51:02 +00:00
|
|
|
filled 12 point black Glyphs.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param text character code points or Glyphs drawn ##
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param byteLength byte length of text array ##
|
|
|
|
#Param path Path providing text baseline ##
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param matrix transform of Glyphs before mapping to path; may be nullptr
|
2017-08-30 12:58:10 +00:00
|
|
|
to use identity Matrix
|
2017-08-03 21:14:08 +00:00
|
|
|
##
|
|
|
|
#Param paint text size, blend, color, and so on, used to draw ##
|
|
|
|
|
|
|
|
#Example
|
2018-02-07 01:58:51 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
2017-08-03 21:14:08 +00:00
|
|
|
const char roller[] = "rollercoaster";
|
|
|
|
const size_t len = sizeof(roller) - 1;
|
|
|
|
SkPath path;
|
|
|
|
path.cubicTo(40, -80, 120, 80, 160, -40);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setTextSize(32);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
SkMatrix matrix;
|
|
|
|
matrix.setIdentity();
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
canvas->translate(25, 60);
|
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
canvas->drawTextOnPath(roller, len, path, &matrix, paint);
|
|
|
|
matrix.preTranslate(0, 10);
|
|
|
|
}
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawTextOnPathHV drawText drawPosTextH drawTextBlob drawTextRSXform
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawTextRSXform(const void* text, size_t byteLength, const SkRSXform xform[],
|
|
|
|
const SkRect* cullRect, const SkPaint& paint)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw_Text
|
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # draws text with array of RSXform ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Draw text, transforming each glyph by the corresponding SkRSXform,
|
|
|
|
using Clip, Matrix, and Paint paint.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
RSXform array specifies a separate square scale, rotation, and translation for
|
2017-07-28 15:04:54 +00:00
|
|
|
each glyph.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
|
|
|
Optional Rect cullRect is a conservative bounds of text, taking into account
|
2017-09-01 19:51:02 +00:00
|
|
|
RSXform and paint. If cullRect is outside of Clip, canvas can skip drawing.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
2018-01-20 00:09:32 +00:00
|
|
|
All elements of paint: Path_Effect, Mask_Filter, Shader,
|
2017-08-03 21:14:08 +00:00
|
|
|
Color_Filter, Image_Filter, and Draw_Looper; apply to text. By default, draws
|
2017-09-01 19:51:02 +00:00
|
|
|
filled 12 point black Glyphs.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param text character code points or Glyphs drawn ##
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param byteLength byte length of text array ##
|
|
|
|
#Param xform RSXform rotates, scales, and translates each glyph individually ##
|
|
|
|
#Param cullRect Rect bounds of text for efficient clipping; or nullptr ##
|
|
|
|
#Param paint text size, blend, color, and so on, used to draw ##
|
|
|
|
|
|
|
|
#Example
|
2018-02-07 01:58:51 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
2017-08-03 21:14:08 +00:00
|
|
|
const int iterations = 26;
|
|
|
|
SkRSXform transforms[iterations];
|
|
|
|
char alphabet[iterations];
|
|
|
|
SkScalar angle = 0;
|
|
|
|
SkScalar scale = 1;
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(transforms); ++i) {
|
|
|
|
const SkScalar s = SkScalarSin(angle) * scale;
|
|
|
|
const SkScalar c = SkScalarCos(angle) * scale;
|
|
|
|
transforms[i] = SkRSXform::Make(-c, -s, -s * 16, c * 16);
|
|
|
|
angle += .45;
|
|
|
|
scale += .2;
|
|
|
|
alphabet[i] = 'A' + i;
|
|
|
|
}
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setTextAlign(SkPaint::kCenter_Align);
|
|
|
|
canvas->translate(110, 138);
|
|
|
|
canvas->drawTextRSXform(alphabet, sizeof(alphabet), transforms, nullptr, paint);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawTextOnPath drawTextOnPathHV drawText drawPosText drawTextBlob
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPaint& paint)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw_Text
|
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # draws text with arrays of positions and Paint ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Draw Text_Blob blob at (x, y), using Clip, Matrix, and Paint paint.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
blob contains Glyphs, their positions, and paint attributes specific to text:
|
2017-08-03 21:14:08 +00:00
|
|
|
Typeface, Paint_Text_Size, Paint_Text_Scale_X, Paint_Text_Skew_X,
|
|
|
|
Paint_Text_Align, Paint_Hinting, Anti-alias, Paint_Fake_Bold,
|
|
|
|
Font_Embedded_Bitmaps, Full_Hinting_Spacing, LCD_Text, Linear_Text,
|
|
|
|
Subpixel_Text, and Paint_Vertical_Text.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-12-01 16:49:58 +00:00
|
|
|
Paint_Text_Encoding must be set to SkPaint::kGlyphID_TextEncoding.
|
|
|
|
|
2018-01-20 00:09:32 +00:00
|
|
|
Elements of paint: Path_Effect, Mask_Filter, Shader, Color_Filter,
|
2017-07-28 15:04:54 +00:00
|
|
|
Image_Filter, and Draw_Looper; apply to blob.
|
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param blob Glyphs, positions, and their paints' text size, typeface, and so on ##
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param x horizontal offset applied to blob ##
|
|
|
|
#Param y vertical offset applied to blob ##
|
|
|
|
#Param paint blend, color, stroking, and so on, used to draw ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 120
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
2017-12-11 21:03:17 +00:00
|
|
|
SkTextBlobBuilder textBlobBuilder;
|
|
|
|
const char bunny[] = "/(^x^)\\";
|
|
|
|
const int len = sizeof(bunny) - 1;
|
|
|
|
uint16_t glyphs[len];
|
|
|
|
SkPaint paint;
|
|
|
|
paint.textToGlyphs(bunny, len, glyphs);
|
2017-12-01 16:49:58 +00:00
|
|
|
paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
|
2017-12-11 21:03:17 +00:00
|
|
|
int runs[] = { 3, 1, 3 };
|
|
|
|
SkPoint textPos = { 20, 100 };
|
|
|
|
int glyphIndex = 0;
|
|
|
|
for (auto runLen : runs) {
|
|
|
|
paint.setTextSize(1 == runLen ? 20 : 50);
|
2018-02-07 01:58:51 +00:00
|
|
|
const SkTextBlobBuilder::RunBuffer& run =
|
2017-12-11 21:03:17 +00:00
|
|
|
textBlobBuilder.allocRun(paint, runLen, textPos.fX, textPos.fY);
|
|
|
|
memcpy(run.glyphs, &glyphs[glyphIndex], sizeof(glyphs[0]) * runLen);
|
|
|
|
textPos.fX += paint.measureText(&glyphs[glyphIndex], sizeof(glyphs[0]) * runLen, nullptr);
|
|
|
|
glyphIndex += runLen;
|
|
|
|
}
|
|
|
|
sk_sp<const SkTextBlob> blob = textBlobBuilder.make();
|
|
|
|
paint.reset();
|
2017-08-03 21:14:08 +00:00
|
|
|
canvas->drawTextBlob(blob.get(), 0, 0, paint);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawText drawPosText drawPosTextH
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
#Method void drawTextBlob(const sk_sp<SkTextBlob>& blob, SkScalar x, SkScalar y, const SkPaint& paint)
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Draw Text_Blob blob at (x, y), using Clip, Matrix, and Paint paint.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
blob contains Glyphs, their positions, and paint attributes specific to text:
|
2017-08-03 21:14:08 +00:00
|
|
|
Typeface, Paint_Text_Size, Paint_Text_Scale_X, Paint_Text_Skew_X,
|
|
|
|
Paint_Text_Align, Paint_Hinting, Anti-alias, Paint_Fake_Bold,
|
|
|
|
Font_Embedded_Bitmaps, Full_Hinting_Spacing, LCD_Text, Linear_Text,
|
|
|
|
Subpixel_Text, and Paint_Vertical_Text.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-12-01 16:49:58 +00:00
|
|
|
Paint_Text_Encoding must be set to SkPaint::kGlyphID_TextEncoding.
|
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
Elements of paint: Path_Effect, Mask_Filter, Shader, Color_Filter,
|
2017-07-28 15:04:54 +00:00
|
|
|
Image_Filter, and Draw_Looper; apply to blob.
|
|
|
|
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param blob Glyphs, positions, and their paints' text size, typeface, and so on ##
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param x horizontal offset applied to blob ##
|
|
|
|
#Param y vertical offset applied to blob ##
|
|
|
|
#Param paint blend, color, stroking, and so on, used to draw ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 120
|
|
|
|
#Description
|
|
|
|
Paint attributes unrelated to text, like color, have no effect on paint in allocated Text_Blob.
|
|
|
|
Paint attributes related to text, like text size, have no effect on paint passed to drawTextBlob.
|
|
|
|
##
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkTextBlobBuilder textBlobBuilder;
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setTextSize(50);
|
|
|
|
paint.setColor(SK_ColorRED);
|
2017-12-11 21:03:17 +00:00
|
|
|
paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
|
2018-02-07 01:58:51 +00:00
|
|
|
const SkTextBlobBuilder::RunBuffer& run =
|
2017-08-03 21:14:08 +00:00
|
|
|
textBlobBuilder.allocRun(paint, 1, 20, 100);
|
|
|
|
run.glyphs[0] = 20;
|
|
|
|
sk_sp<const SkTextBlob> blob = textBlobBuilder.make();
|
|
|
|
paint.setTextSize(10);
|
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
canvas->drawTextBlob(blob.get(), 0, 0, paint);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawText drawPosText drawPosTextH
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
#Method void drawPicture(const SkPicture* picture)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # draws Picture using Clip and Matrix ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Draw Picture picture, using Clip and Matrix.
|
|
|
|
Clip and Matrix are unchanged by picture contents, as if
|
|
|
|
save() was called before and restore() was called after drawPicture.
|
|
|
|
|
|
|
|
Picture records a series of draw commands for later playback.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param picture recorded drawing commands to play ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2018-02-07 01:58:51 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
2017-08-03 21:14:08 +00:00
|
|
|
SkPictureRecorder recorder;
|
|
|
|
SkCanvas* recordingCanvas = recorder.beginRecording(50, 50);
|
|
|
|
for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(color);
|
|
|
|
recordingCanvas->drawRect({10, 10, 30, 40}, paint);
|
|
|
|
recordingCanvas->translate(10, 10);
|
|
|
|
recordingCanvas->scale(1.2f, 1.4f);
|
|
|
|
}
|
|
|
|
sk_sp<SkPicture> playback = recorder.finishRecordingAsPicture();
|
|
|
|
const SkPicture* playbackPtr = playback.get();
|
|
|
|
canvas->drawPicture(playback);
|
|
|
|
canvas->scale(2, 2);
|
|
|
|
canvas->translate(50, 0);
|
|
|
|
canvas->drawPicture(playback);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawDrawable SkPicture SkPicture::playback
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
#Method void drawPicture(const sk_sp<SkPicture>& picture)
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Draw Picture picture, using Clip and Matrix.
|
|
|
|
Clip and Matrix are unchanged by picture contents, as if
|
|
|
|
save() was called before and restore() was called after drawPicture.
|
|
|
|
|
|
|
|
Picture records a series of draw commands for later playback.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param picture recorded drawing commands to play ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2018-02-07 01:58:51 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
2017-08-03 21:14:08 +00:00
|
|
|
SkPictureRecorder recorder;
|
|
|
|
SkCanvas* recordingCanvas = recorder.beginRecording(50, 50);
|
|
|
|
for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(color);
|
|
|
|
recordingCanvas->drawRect({10, 10, 30, 40}, paint);
|
|
|
|
recordingCanvas->translate(10, 10);
|
|
|
|
recordingCanvas->scale(1.2f, 1.4f);
|
|
|
|
}
|
|
|
|
sk_sp<SkPicture> playback = recorder.finishRecordingAsPicture();
|
|
|
|
canvas->drawPicture(playback);
|
|
|
|
canvas->scale(2, 2);
|
|
|
|
canvas->translate(50, 0);
|
|
|
|
canvas->drawPicture(playback);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawDrawable SkPicture SkPicture::playback
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawPicture(const SkPicture* picture, const SkMatrix* matrix, const SkPaint* paint)
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
Draw Picture picture, using Clip and Matrix; transforming picture with
|
|
|
|
Matrix matrix, if provided; and use Paint paint Color_Alpha, Color_Filter,
|
|
|
|
Image_Filter, and Blend_Mode, if provided.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
matrix transformation is equivalent to: save(), concat(), drawPicture, restore().
|
|
|
|
paint use is equivalent to: saveLayer, drawPicture, restore().
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param picture recorded drawing commands to play ##
|
|
|
|
#Param matrix Matrix to rotate, scale, translate, and so on; may be nullptr ##
|
|
|
|
#Param paint Paint to apply transparency, filtering, and so on; may be nullptr ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2018-02-07 01:58:51 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
2017-08-03 21:14:08 +00:00
|
|
|
SkPaint paint;
|
|
|
|
SkPictureRecorder recorder;
|
|
|
|
SkCanvas* recordingCanvas = recorder.beginRecording(50, 50);
|
|
|
|
for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) {
|
|
|
|
paint.setColor(color);
|
|
|
|
recordingCanvas->drawRect({10, 10, 30, 40}, paint);
|
|
|
|
recordingCanvas->translate(10, 10);
|
|
|
|
recordingCanvas->scale(1.2f, 1.4f);
|
|
|
|
}
|
|
|
|
sk_sp<SkPicture> playback = recorder.finishRecordingAsPicture();
|
|
|
|
const SkPicture* playbackPtr = playback.get();
|
|
|
|
SkMatrix matrix;
|
|
|
|
matrix.reset();
|
|
|
|
for (auto alpha : { 70, 140, 210 } ) {
|
|
|
|
paint.setAlpha(alpha);
|
|
|
|
canvas->drawPicture(playbackPtr, &matrix, &paint);
|
|
|
|
matrix.preTranslate(70, 70);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawDrawable SkPicture SkPicture::playback
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
#Method void drawPicture(const sk_sp<SkPicture>& picture, const SkMatrix* matrix, const SkPaint* paint)
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
Draw Picture picture, using Clip and Matrix; transforming picture with
|
|
|
|
Matrix matrix, if provided; and use Paint paint Color_Alpha, Color_Filter,
|
|
|
|
Image_Filter, and Blend_Mode, if provided.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
matrix transformation is equivalent to: save(), concat(), drawPicture, restore().
|
|
|
|
paint use is equivalent to: saveLayer, drawPicture, restore().
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param picture recorded drawing commands to play ##
|
|
|
|
#Param matrix Matrix to rotate, scale, translate, and so on; may be nullptr ##
|
|
|
|
#Param paint Paint to apply transparency, filtering, and so on; may be nullptr ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2018-02-07 01:58:51 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
2017-08-03 21:14:08 +00:00
|
|
|
SkPaint paint;
|
|
|
|
SkPictureRecorder recorder;
|
|
|
|
SkCanvas* recordingCanvas = recorder.beginRecording(50, 50);
|
|
|
|
for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) {
|
|
|
|
paint.setColor(color);
|
|
|
|
recordingCanvas->drawRect({10, 10, 30, 40}, paint);
|
|
|
|
recordingCanvas->translate(10, 10);
|
|
|
|
recordingCanvas->scale(1.2f, 1.4f);
|
|
|
|
}
|
|
|
|
sk_sp<SkPicture> playback = recorder.finishRecordingAsPicture();
|
|
|
|
SkMatrix matrix;
|
|
|
|
matrix.reset();
|
|
|
|
for (auto alpha : { 70, 140, 210 } ) {
|
|
|
|
paint.setAlpha(alpha);
|
|
|
|
canvas->drawPicture(playback, &matrix, &paint);
|
|
|
|
matrix.preTranslate(70, 70);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawDrawable SkPicture SkPicture::playback
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawVertices(const SkVertices* vertices, SkBlendMode mode, const SkPaint& paint)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # draws Vertices, a triangle mesh ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Draw Vertices vertices, a triangle mesh, using Clip and Matrix.
|
2017-08-03 21:14:08 +00:00
|
|
|
If Vertices_Texs and Vertices_Colors are defined in vertices, and Paint paint
|
|
|
|
contains Shader, Blend_Mode mode combines Vertices_Colors with Shader.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param vertices triangle mesh to draw ##
|
|
|
|
#Param mode combines Vertices_Colors with Shader, if both are present ##
|
|
|
|
#Param paint specifies the Shader, used as Vertices texture; may be nullptr ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
|
|
|
SkPoint points[] = { { 0, 0 }, { 250, 0 }, { 100, 100 }, { 0, 250 } };
|
|
|
|
SkColor colors[] = { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorCYAN };
|
|
|
|
auto vertices = SkVertices::MakeCopy(SkVertices::kTriangleFan_VertexMode,
|
|
|
|
SK_ARRAY_COUNT(points), points, nullptr, colors);
|
|
|
|
canvas->drawVertices(vertices.get(), SkBlendMode::kSrc, paint);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawPatch drawPicture
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawVertices(const sk_sp<SkVertices>& vertices, SkBlendMode mode, const SkPaint& paint)
|
|
|
|
|
|
|
|
Draw Vertices vertices, a triangle mesh, using Clip and Matrix.
|
2017-08-03 21:14:08 +00:00
|
|
|
If Vertices_Texs and Vertices_Colors are defined in vertices, and Paint paint
|
|
|
|
contains Shader, Blend_Mode mode combines Vertices_Colors with Shader.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param vertices triangle mesh to draw ##
|
|
|
|
#Param mode combines Vertices_Colors with Shader, if both are present ##
|
|
|
|
#Param paint specifies the Shader, used as Vertices texture, may be nullptr ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
|
|
|
SkPoint points[] = { { 0, 0 }, { 250, 0 }, { 100, 100 }, { 0, 250 } };
|
|
|
|
SkPoint texs[] = { { 0, 0 }, { 0, 250 }, { 250, 250 }, { 250, 0 } };
|
|
|
|
SkColor colors[] = { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorCYAN };
|
|
|
|
paint.setShader(SkGradientShader::MakeLinear(points, colors, nullptr, 4,
|
|
|
|
SkShader::kClamp_TileMode));
|
|
|
|
auto vertices = SkVertices::MakeCopy(SkVertices::kTriangleFan_VertexMode,
|
|
|
|
SK_ARRAY_COUNT(points), points, texs, colors);
|
|
|
|
canvas->drawVertices(vertices.get(), SkBlendMode::kDarken, paint);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawPatch drawPicture
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawPatch(const SkPoint cubics[12], const SkColor colors[4],
|
|
|
|
const SkPoint texCoords[4], SkBlendMode mode, const SkPaint& paint)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # draws Coons_Patch ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
Draws a Coons_Patch: the interpolation of four cubics with shared corners,
|
2017-07-28 15:04:54 +00:00
|
|
|
associating a color, and optionally a texture coordinate, with each corner.
|
|
|
|
|
2017-11-27 15:44:06 +00:00
|
|
|
Coons_Patch uses Clip and Matrix, paint Shader, Color_Filter,
|
2017-08-03 21:14:08 +00:00
|
|
|
Color_Alpha, Image_Filter, and Blend_Mode. If Shader is provided it is treated
|
2017-11-27 15:44:06 +00:00
|
|
|
as Coons_Patch texture; Blend_Mode mode combines Color colors and Shader if
|
2017-08-03 21:14:08 +00:00
|
|
|
both are provided.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
Point array cubics specifies four Cubics starting at the top-left corner,
|
2017-09-01 19:51:02 +00:00
|
|
|
in clockwise order, sharing every fourth point. The last Cubic ends at the
|
2017-08-03 21:14:08 +00:00
|
|
|
first point.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-10-04 18:31:33 +00:00
|
|
|
Color array color associates colors with corners in top-left, top-right,
|
|
|
|
bottom-right, bottom-left order.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
|
|
|
If paint contains Shader, Point array texCoords maps Shader as texture to
|
2017-10-04 18:31:33 +00:00
|
|
|
corners in top-left, top-right, bottom-right, bottom-left order.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
2017-08-30 12:58:10 +00:00
|
|
|
#Param cubics Path_Cubic array, sharing common points ##
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param colors Color array, one for each corner ##
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param texCoords Point array of texture coordinates, mapping Shader to corners;
|
2018-02-07 01:58:51 +00:00
|
|
|
may be nullptr
|
2017-07-31 15:48:27 +00:00
|
|
|
#Param ##
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param mode Blend_Mode for colors, and for Shader if paint has one ##
|
|
|
|
#Param paint Shader, Color_Filter, Blend_Mode, used to draw ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Image 5
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
// SkBitmap source = cmbkygk;
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setFilterQuality(kLow_SkFilterQuality);
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
SkPoint cubics[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 },
|
|
|
|
/* { 7, 3 }, */ { 6, 4 }, { 7, 5 }, { 5, 7 },
|
|
|
|
/* { 5, 7 }, */ { 4, 6 }, { 3, 7 }, { 1, 5 },
|
|
|
|
/* { 1, 5 }, */ { 2, 4 }, { 1, 3 }, /* { 3, 1 } */ };
|
|
|
|
SkColor colors[] = { 0xbfff0000, 0xbf0000ff, 0xbfff00ff, 0xbf00ffff };
|
|
|
|
SkPoint texCoords[] = { { -30, -30 }, { 162, -30}, { 162, 162}, { -30, 162} };
|
|
|
|
paint.setShader(SkShader::MakeBitmapShader(source, SkShader::kClamp_TileMode,
|
|
|
|
SkShader::kClamp_TileMode, nullptr));
|
|
|
|
canvas->scale(15, 15);
|
|
|
|
for (auto blend : { SkBlendMode::kSrcOver, SkBlendMode::kModulate, SkBlendMode::kXor } ) {
|
|
|
|
canvas->drawPatch(cubics, colors, texCoords, blend, paint);
|
|
|
|
canvas->translate(4, 4);
|
|
|
|
}
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#ToDo can patch use image filter? ##
|
|
|
|
#SeeAlso SeeAlso drawVertices drawPicture
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawPatch(const SkPoint cubics[12], const SkColor colors[4],
|
2018-02-07 01:58:51 +00:00
|
|
|
const SkPoint texCoords[4], const SkPaint& paint)
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
Draws Cubic Coons_Patch: the interpolation of four cubics with shared corners,
|
2017-08-03 21:14:08 +00:00
|
|
|
associating a color, and optionally a texture coordinate, with each corner.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-11-27 15:44:06 +00:00
|
|
|
Coons_Patch uses Clip and Matrix, paint Shader, Color_Filter,
|
2017-08-03 21:14:08 +00:00
|
|
|
Color_Alpha, Image_Filter, and Blend_Mode. If Shader is provided it is treated
|
2017-11-27 15:44:06 +00:00
|
|
|
as Coons_Patch texture; Blend_Mode mode combines Color colors and Shader if
|
2017-08-03 21:14:08 +00:00
|
|
|
both are provided.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
Point array cubics specifies four Cubics starting at the top-left corner,
|
2017-09-01 19:51:02 +00:00
|
|
|
in clockwise order, sharing every fourth point. The last Cubic ends at the
|
2017-08-03 21:14:08 +00:00
|
|
|
first point.
|
|
|
|
|
2017-10-04 18:31:33 +00:00
|
|
|
Color array color associates colors with corners in top-left, top-right,
|
|
|
|
bottom-right, bottom-left order.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
|
|
|
If paint contains Shader, Point array texCoords maps Shader as texture to
|
2017-10-04 18:31:33 +00:00
|
|
|
corners in top-left, top-right, bottom-right, bottom-left order.
|
2017-08-03 21:14:08 +00:00
|
|
|
|
2017-08-30 12:58:10 +00:00
|
|
|
#Param cubics Path_Cubic array, sharing common points ##
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param colors Color array, one for each corner ##
|
2017-09-01 19:51:02 +00:00
|
|
|
#Param texCoords Point array of texture coordinates, mapping Shader to corners;
|
2018-02-07 01:58:51 +00:00
|
|
|
may be nullptr
|
2017-07-31 15:48:27 +00:00
|
|
|
#Param ##
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param paint Shader, Color_Filter, Blend_Mode, used to draw ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
SkPoint cubics[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 },
|
|
|
|
/* { 7, 3 }, */ { 6, 4 }, { 7, 5 }, { 5, 7 },
|
|
|
|
/* { 5, 7 }, */ { 4, 6 }, { 3, 7 }, { 1, 5 },
|
|
|
|
/* { 1, 5 }, */ { 2, 4 }, { 1, 3 }, /* { 3, 1 } */ };
|
|
|
|
SkColor colors[] = { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorCYAN };
|
|
|
|
canvas->scale(30, 30);
|
|
|
|
canvas->drawPatch(cubics, colors, nullptr, paint);
|
|
|
|
SkPoint text[] = { {3,0.9f}, {4,2.5f}, {5,0.9f}, {7.5f,3.2f}, {5.5f,4.2f},
|
|
|
|
{7.5f,5.2f}, {5,7.5f}, {4,5.9f}, {3,7.5f}, {0.5f,5.2f}, {2.5f,4.2f},
|
|
|
|
{0.5f,3.2f} };
|
|
|
|
paint.setTextSize(18.f / 30);
|
|
|
|
paint.setTextAlign(SkPaint::kCenter_Align);
|
|
|
|
for (int i = 0; i< 10; ++i) {
|
|
|
|
char digit = '0' + i;
|
|
|
|
canvas->drawText(&digit, 1, text[i].fX, text[i].fY, paint);
|
|
|
|
}
|
|
|
|
canvas->drawString("10", text[10].fX, text[10].fY, paint);
|
|
|
|
canvas->drawString("11", text[11].fX, text[11].fY, paint);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
canvas->drawPoints(SkCanvas::kPolygon_PointMode, 12, cubics, paint);
|
|
|
|
canvas->drawLine(cubics[11].fX, cubics[11].fY, cubics[0].fX, cubics[0].fY, paint);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
|
|
|
#Example
|
|
|
|
#Image 6
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
// SkBitmap source = checkerboard;
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setFilterQuality(kLow_SkFilterQuality);
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
SkPoint cubics[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 },
|
|
|
|
/* { 7, 3 }, */ { 6, 4 }, { 7, 5 }, { 5, 7 },
|
|
|
|
/* { 5, 7 }, */ { 4, 6 }, { 3, 7 }, { 1, 5 },
|
|
|
|
/* { 1, 5 }, */ { 2, 4 }, { 1, 3 }, /* { 3, 1 } */ };
|
|
|
|
SkPoint texCoords[] = { { 0, 0 }, { 0, 62}, { 62, 62}, { 62, 0 } };
|
|
|
|
paint.setShader(SkShader::MakeBitmapShader(source, SkShader::kClamp_TileMode,
|
|
|
|
SkShader::kClamp_TileMode, nullptr));
|
|
|
|
canvas->scale(30, 30);
|
|
|
|
canvas->drawPatch(cubics, nullptr, texCoords, paint);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#ToDo can patch use image filter? ##
|
|
|
|
#SeeAlso SeeAlso drawVertices drawPicture
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[],
|
|
|
|
const SkColor colors[], int count, SkBlendMode mode, const SkRect* cullRect,
|
|
|
|
const SkPaint* paint)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # draws sprites using Clip, Matrix, and Paint ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Draw a set of sprites from atlas, using Clip, Matrix, and optional Paint paint.
|
2017-08-03 21:14:08 +00:00
|
|
|
paint uses Anti-alias, Color_Alpha, Color_Filter, Image_Filter, and Blend_Mode
|
|
|
|
to draw, if present. For each entry in the array, Rect tex locates sprite in
|
|
|
|
atlas, and RSXform xform transforms it into destination space.
|
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
xform, text, and colors if present, must contain count entries.
|
2017-08-03 21:14:08 +00:00
|
|
|
Optional colors are applied for each sprite using Blend_Mode.
|
2018-02-07 01:58:51 +00:00
|
|
|
Optional cullRect is a conservative bounds of all transformed sprites.
|
2017-09-01 19:51:02 +00:00
|
|
|
If cullRect is outside of Clip, canvas can skip drawing.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param atlas Image containing sprites ##
|
|
|
|
#Param xform RSXform mappings for sprites in atlas ##
|
|
|
|
#Param tex Rect locations of sprites in atlas ##
|
2017-09-21 16:31:06 +00:00
|
|
|
#Param colors one per sprite, blended with sprite using Blend_Mode; may be nullptr ##
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param count number of sprites to draw ##
|
|
|
|
#Param mode Blend_Mode combining colors and sprites ##
|
2017-09-21 16:31:06 +00:00
|
|
|
#Param cullRect bounds of transformed sprites for efficient clipping; may be nullptr ##
|
|
|
|
#Param paint Color_Filter, Image_Filter, Blend_Mode, and so on; may be nullptr ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Image 3
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
// SkBitmap source = mandrill;
|
|
|
|
SkRSXform xforms[] = { { .5f, 0, 0, 0 }, {0, .5f, 200, 100 } };
|
|
|
|
SkRect tex[] = { { 0, 0, 250, 250 }, { 0, 0, 250, 250 } };
|
|
|
|
SkColor colors[] = { 0x7f55aa00, 0x7f3333bf };
|
|
|
|
const SkImage* imagePtr = image.get();
|
|
|
|
canvas->drawAtlas(imagePtr, xforms, tex, colors, 2, SkBlendMode::kSrcOver, nullptr, nullptr);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawBitmap drawImage
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[],
|
|
|
|
const SkColor colors[], int count, SkBlendMode mode, const SkRect* cullRect,
|
2018-02-07 01:58:51 +00:00
|
|
|
const SkPaint* paint)
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Draw a set of sprites from atlas, using Clip, Matrix, and optional Paint paint.
|
2017-08-03 21:14:08 +00:00
|
|
|
paint uses Anti-alias, Color_Alpha, Color_Filter, Image_Filter, and Blend_Mode
|
|
|
|
to draw, if present. For each entry in the array, Rect tex locates sprite in
|
|
|
|
atlas, and RSXform xform transforms it into destination space.
|
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
xform, text, and colors if present, must contain count entries.
|
|
|
|
Optional colors is applied for each sprite using Blend_Mode.
|
2018-02-07 01:58:51 +00:00
|
|
|
Optional cullRect is a conservative bounds of all transformed sprites.
|
2017-09-01 19:51:02 +00:00
|
|
|
If cullRect is outside of Clip, canvas can skip drawing.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param atlas Image containing sprites ##
|
|
|
|
#Param xform RSXform mappings for sprites in atlas ##
|
|
|
|
#Param tex Rect locations of sprites in atlas ##
|
2017-09-21 16:31:06 +00:00
|
|
|
#Param colors one per sprite, blended with sprite using Blend_Mode; may be nullptr ##
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param count number of sprites to draw ##
|
|
|
|
#Param mode Blend_Mode combining colors and sprites ##
|
2017-09-21 16:31:06 +00:00
|
|
|
#Param cullRect bounds of transformed sprites for efficient clipping; may be nullptr ##
|
|
|
|
#Param paint Color_Filter, Image_Filter, Blend_Mode, and so on; may be nullptr ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Image 3
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
// SkBitmap source = mandrill;
|
|
|
|
SkRSXform xforms[] = { { .5f, 0, 0, 0 }, {0, .5f, 200, 100 } };
|
|
|
|
SkRect tex[] = { { 0, 0, 250, 250 }, { 0, 0, 250, 250 } };
|
|
|
|
SkColor colors[] = { 0x7f55aa00, 0x7f3333bf };
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAlpha(127);
|
|
|
|
canvas->drawAtlas(image, xforms, tex, colors, 2, SkBlendMode::kPlus, nullptr, &paint);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
|
|
|
#ToDo bug in example on cpu side, gpu looks ok ##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawBitmap drawImage
|
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], int count,
|
2018-02-07 01:58:51 +00:00
|
|
|
const SkRect* cullRect, const SkPaint* paint)
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Draw a set of sprites from atlas, using Clip, Matrix, and optional Paint paint.
|
2017-08-03 21:14:08 +00:00
|
|
|
paint uses Anti-alias, Color_Alpha, Color_Filter, Image_Filter, and Blend_Mode
|
|
|
|
to draw, if present. For each entry in the array, Rect tex locates sprite in
|
|
|
|
atlas, and RSXform xform transforms it into destination space.
|
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
xform and text must contain count entries.
|
2018-02-07 01:58:51 +00:00
|
|
|
Optional cullRect is a conservative bounds of all transformed sprites.
|
2017-09-01 19:51:02 +00:00
|
|
|
If cullRect is outside of Clip, canvas can skip drawing.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param atlas Image containing sprites ##
|
|
|
|
#Param xform RSXform mappings for sprites in atlas ##
|
|
|
|
#Param tex Rect locations of sprites in atlas ##
|
|
|
|
#Param count number of sprites to draw ##
|
2017-09-21 16:31:06 +00:00
|
|
|
#Param cullRect bounds of transformed sprites for efficient clipping; may be nullptr ##
|
|
|
|
#Param paint Color_Filter, Image_Filter, Blend_Mode, and so on; may be nullptr ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Image 3
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
// sk_sp<SkImage> image = mandrill;
|
|
|
|
SkRSXform xforms[] = { { .5f, 0, 0, 0 }, {0, .5f, 200, 100 } };
|
|
|
|
SkRect tex[] = { { 0, 0, 250, 250 }, { 0, 0, 250, 250 } };
|
|
|
|
const SkImage* imagePtr = image.get();
|
|
|
|
canvas->drawAtlas(imagePtr, xforms, tex, 2, nullptr, nullptr);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawBitmap drawImage
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[],
|
2018-02-07 01:58:51 +00:00
|
|
|
int count, const SkRect* cullRect, const SkPaint* paint)
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Draw a set of sprites from atlas, using Clip, Matrix, and optional Paint paint.
|
2017-08-03 21:14:08 +00:00
|
|
|
paint uses Anti-alias, Color_Alpha, Color_Filter, Image_Filter, and Blend_Mode
|
|
|
|
to draw, if present. For each entry in the array, Rect tex locates sprite in
|
|
|
|
atlas, and RSXform xform transforms it into destination space.
|
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
xform and text must contain count entries.
|
2018-02-07 01:58:51 +00:00
|
|
|
Optional cullRect is a conservative bounds of all transformed sprites.
|
2017-09-01 19:51:02 +00:00
|
|
|
If cullRect is outside of Clip, canvas can skip drawing.
|
2017-07-28 15:04:54 +00:00
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param atlas Image containing sprites ##
|
|
|
|
#Param xform RSXform mappings for sprites in atlas ##
|
|
|
|
#Param tex Rect locations of sprites in atlas ##
|
|
|
|
#Param count number of sprites to draw ##
|
2017-09-21 16:31:06 +00:00
|
|
|
#Param cullRect bounds of transformed sprites for efficient clipping; may be nullptr ##
|
|
|
|
#Param paint Color_Filter, Image_Filter, Blend_Mode, and so on; may be nullptr ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Image 3
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
// sk_sp<SkImage> image = mandrill;
|
|
|
|
SkRSXform xforms[] = { { 1, 0, 0, 0 }, {0, 1, 300, 100 } };
|
|
|
|
SkRect tex[] = { { 0, 0, 200, 200 }, { 200, 0, 400, 200 } };
|
|
|
|
canvas->drawAtlas(image, xforms, tex, 2, nullptr, nullptr);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso drawBitmap drawImage
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2017-08-29 21:36:51 +00:00
|
|
|
#Method void drawDrawable(SkDrawable* drawable, const SkMatrix* matrix = nullptr)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # draws Drawable, encapsulated drawing commands ##
|
2018-02-07 01:58:51 +00:00
|
|
|
Draw Drawable drawable using Clip and Matrix, concatenated with
|
2017-07-28 15:04:54 +00:00
|
|
|
optional matrix.
|
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
If Canvas has an asynchronous implementation, as is the case
|
2017-07-28 15:04:54 +00:00
|
|
|
when it is recording into Picture, then drawable will be referenced,
|
|
|
|
so that SkDrawable::draw() can be called when the operation is finalized. To force
|
|
|
|
immediate drawing, call SkDrawable::draw() instead.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param drawable custom struct encapsulating drawing commands ##
|
|
|
|
#Param matrix transformation applied to drawing; may be nullptr ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 100
|
|
|
|
#Function
|
2017-08-03 21:14:08 +00:00
|
|
|
struct MyDrawable : public SkDrawable {
|
|
|
|
SkRect onGetBounds() override { return SkRect::MakeWH(50, 100); }
|
|
|
|
|
|
|
|
void onDraw(SkCanvas* canvas) override {
|
|
|
|
SkPath path;
|
|
|
|
path.conicTo(10, 90, 50, 90, 0.9f);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
canvas->drawRect(path.getBounds(), paint);
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setColor(SK_ColorWHITE);
|
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#Function ##
|
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
sk_sp<SkDrawable> drawable(new MyDrawable);
|
|
|
|
SkMatrix matrix;
|
|
|
|
matrix.setTranslate(10, 10);
|
|
|
|
canvas->drawDrawable(drawable.get(), &matrix);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso SkDrawable drawPicture
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawDrawable(SkDrawable* drawable, SkScalar x, SkScalar y)
|
|
|
|
|
|
|
|
Draw Drawable drawable using Clip and Matrix, offset by (x, y).
|
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
If Canvas has an asynchronous implementation, as is the case
|
2017-07-28 15:04:54 +00:00
|
|
|
when it is recording into Picture, then drawable will be referenced,
|
|
|
|
so that SkDrawable::draw() can be called when the operation is finalized. To force
|
|
|
|
immediate drawing, call SkDrawable::draw() instead.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param drawable custom struct encapsulating drawing commands ##
|
|
|
|
#Param x offset into Canvas writable pixels in x ##
|
|
|
|
#Param y offset into Canvas writable pixels in y ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 100
|
|
|
|
#Function
|
2017-08-03 21:14:08 +00:00
|
|
|
struct MyDrawable : public SkDrawable {
|
|
|
|
SkRect onGetBounds() override { return SkRect::MakeWH(50, 100); }
|
|
|
|
|
|
|
|
void onDraw(SkCanvas* canvas) override {
|
|
|
|
SkPath path;
|
|
|
|
path.conicTo(10, 90, 50, 90, 0.9f);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
canvas->drawRect(path.getBounds(), paint);
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setColor(SK_ColorWHITE);
|
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#Function ##
|
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
sk_sp<SkDrawable> drawable(new MyDrawable);
|
|
|
|
canvas->drawDrawable(drawable.get(), 10, 10);
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso SkDrawable drawPicture
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method void drawAnnotation(const SkRect& rect, const char key[], SkData* value)
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Draw
|
|
|
|
#In Utility
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # associates a Rect with a key-value pair ##
|
2018-02-07 12:27:09 +00:00
|
|
|
Associate Rect on Canvas with an annotation; a key-value pair, where the key is
|
2017-07-28 15:04:54 +00:00
|
|
|
a null-terminated utf8 string, and optional value is stored as Data.
|
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
Only some canvas implementations, such as recording to Picture, or drawing to
|
2017-07-28 15:04:54 +00:00
|
|
|
Document_PDF, use annotations.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param rect Rect extent of canvas to annotate ##
|
|
|
|
#Param key string used for lookup ##
|
|
|
|
#Param value data holding value stored in annotation ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 1
|
|
|
|
const char text[] = "Click this link!";
|
|
|
|
SkRect bounds;
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setTextSize(40);
|
|
|
|
(void)paint.measureText(text, strlen(text), &bounds);
|
|
|
|
const char url[] = "https://www.google.com/";
|
|
|
|
sk_sp<SkData> urlData(SkData::MakeWithCString(url));
|
|
|
|
canvas->drawAnnotation(bounds, "url_key", urlData.get());
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso SkPicture SkDocument
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
#Method void drawAnnotation(const SkRect& rect, const char key[], const sk_sp<SkData>& value)
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
Associate Rect on Canvas when an annotation; a key-value pair, where the key is
|
|
|
|
a null-terminated utf8 string, and optional value is stored as Data.
|
|
|
|
|
2018-02-07 01:58:51 +00:00
|
|
|
Only some canvas implementations, such as recording to Picture, or drawing to
|
2017-07-28 15:04:54 +00:00
|
|
|
Document_PDF, use annotations.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Param rect Rect extent of canvas to annotate ##
|
|
|
|
#Param key string used for lookup ##
|
|
|
|
#Param value data holding value stored in annotation ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
|
|
|
#Height 1
|
|
|
|
const char text[] = "Click this link!";
|
|
|
|
SkRect bounds;
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setTextSize(40);
|
|
|
|
(void)paint.measureText(text, strlen(text), &bounds);
|
|
|
|
const char url[] = "https://www.google.com/";
|
|
|
|
sk_sp<SkData> urlData(SkData::MakeWithCString(url));
|
|
|
|
canvas->drawAnnotation(bounds, "url_key", urlData.get());
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso SkPicture SkDocument
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
#Method SkDrawFilter* getDrawFilter() const
|
2018-02-06 14:41:53 +00:00
|
|
|
#Deprecated soon
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
#Method virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter)
|
2018-02-06 14:41:53 +00:00
|
|
|
#Deprecated soon
|
2017-07-28 15:04:54 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method virtual bool isClipEmpty() const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns if Clip is empty ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Returns true if Clip is empty; that is, nothing will draw.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
May do work when called; it should not be called
|
2017-07-28 15:04:54 +00:00
|
|
|
more often than needed. However, once called, subsequent calls perform no
|
|
|
|
work until Clip changes.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Return true if Clip is empty ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkDebugf("clip is%s empty\n", canvas->isClipEmpty() ? "" : " not");
|
|
|
|
SkPath path;
|
|
|
|
canvas->clipPath(path);
|
|
|
|
SkDebugf("clip is%s empty\n", canvas->isClipEmpty() ? "" : " not");
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
#StdOut
|
2017-08-03 21:14:08 +00:00
|
|
|
clip is not empty
|
2017-07-28 15:04:54 +00:00
|
|
|
clip is empty
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso isClipRect getLocalClipBounds getDeviceClipBounds
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#Method virtual bool isClipRect() const
|
2018-02-07 12:27:09 +00:00
|
|
|
#In Property
|
2018-01-30 15:08:57 +00:00
|
|
|
#Line # returns if Clip is Rect and not empty ##
|
2017-07-28 15:04:54 +00:00
|
|
|
Returns true if Clip is Rect and not empty.
|
|
|
|
Returns false if the clip is empty, or if it is not Rect.
|
|
|
|
|
2017-08-03 21:14:08 +00:00
|
|
|
#Return true if Clip is Rect and not empty ##
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
#Example
|
2017-08-03 21:14:08 +00:00
|
|
|
void draw(SkCanvas* canvas) {
|
|
|
|
SkDebugf("clip is%s rect\n", canvas->isClipRect() ? "" : " not");
|
|
|
|
canvas->clipRect({0, 0, 0, 0});
|
|
|
|
SkDebugf("clip is%s rect\n", canvas->isClipRect() ? "" : " not");
|
2017-07-28 15:04:54 +00:00
|
|
|
}
|
|
|
|
#StdOut
|
2017-08-03 21:14:08 +00:00
|
|
|
clip is rect
|
2017-07-28 15:04:54 +00:00
|
|
|
clip is not rect
|
|
|
|
##
|
|
|
|
##
|
|
|
|
|
2017-11-02 21:49:34 +00:00
|
|
|
#SeeAlso isClipEmpty getLocalClipBounds getDeviceClipBounds
|
2017-07-28 15:04:54 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
#Class SkCanvas ##
|
2017-10-11 14:37:52 +00:00
|
|
|
|
2017-07-28 15:04:54 +00:00
|
|
|
#Topic Canvas ##
|