Class Canvas

java.lang.Object
icyllis.arc3d.core.Canvas
All Implemented Interfaces:
AutoCloseable
Direct Known Subclasses:
NoDrawCanvas

public class Canvas extends Object implements AutoCloseable
A Canvas provides an interface for drawing 2D geometries, images, and how the drawing is clipped and transformed. 2D geometries may include points, lines, triangles, rectangles, rounded rectangles, circular arcs, quadratic curves, etc.

A Canvas and a Paint together provide the state to draw into Surface or Device. Each Canvas draw call transforms the geometry of the object by the pre-multiplication of all transform matrices in the stack. The transformed geometry is clipped by the intersection of all clip values in the stack. The Canvas draw calls use Paint to supply drawing state such as color, text size, stroke width, filter and so on.

A surface canvas will quickly compute, optimize and generate the data required by the underlying 3D graphics API on the application side (client rendering pipeline). The render tasks will be transmitted to GPU on render thread (deferred rendering), determined by the drawing device.

A recording canvas records draw calls to a surface canvas. Although deferred rendering has been done in surface canvas, sometimes we don't need to update animations or transformations on the client side, so we can save draw calls, and don't need to update the buffer in GPU. This is not recommended for frequently updated scenes.

The Canvas supports multiple color buffers in one off-screen rendering target, which can be used for many complex color blending and temporary operations. Note that depth buffer and depth test is not enabled, Z ordering or transparency sorting is required on the client pipeline before drawing onto the Canvas. All layers are considered translucent and drawn from far to near.

You may never access the pixels of the canvas directly on the current thread, because canvas is backed by GPU and uses deferred rendering. You must wait for GPU to finish all rendering tasks and then use thread scheduling before you can download the surface data to CPU side memory.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static @interface 
    The PointMode selects if an array of points is drawn as discrete points, as lines, or as an open polygon.
    static @interface 
    SaveLayerFlags provides options that may be used in any combination in SaveLayerRec, defining how layer allocated by saveLayer() operates.
    static @interface 
    The SrcRectConstraint controls the behavior at the edge of source rect, provided to drawImageRect() when there is any filtering.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Instead of matching previous layer's color type, use F16.
    protected static final int
     
    static final int
    Initializes with previous contents.
    protected static final int
     
    static final int
    Draw each pair of points as a line segment.
    static final int
    Draw each point separately.
    static final int
    Draw the array of points as an open polygon.
    static final int
    Sample outside bounds; faster
    static final int
    Sample only inside bounds; slower.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
     
    Creates an empty Canvas with no backing device or pixels, with a width and height of zero.
     
    Canvas(int width, int height)
    Creates Canvas of the specified dimensions without a Surface.
     
     
    protected
    Canvas(Rect2ic bounds)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    final void
    clear(float r, float g, float b, float a)
    Fills the current clip with the specified color, using SRC blend mode.
    final void
    clear(int color)
    Fills the current clip with the specified color, using SRC blend mode.
    final void
    clipRect(float left, float top, float right, float bottom)
    Intersect the current clip with the specified rectangle and updates the stencil buffer if changed, which is expressed in local coordinates.
    final void
    clipRect(float left, float top, float right, float bottom, boolean doAA)
    Intersect the current clip with the specified rectangle and updates the stencil buffer if changed, which is expressed in local coordinates, with an aliased or anti-aliased clip edge.
    final void
    clipRect(float left, float top, float right, float bottom, int clipOp)
    Replaces the current clip with the intersection or difference of the current clip and the given rect, with an aliased or anti-aliased clip edge.
    final void
    Intersect the current clip with the specified rectangle and updates the stencil buffer if changed, which is expressed in local coordinates.
    final void
    clipRect(Rect2fc rect, boolean doAA)
    Intersect the current clip with the specified rectangle and updates the stencil buffer if changed, which is expressed in local coordinates, with an aliased or anti-aliased clip edge.
    final void
    clipRect(Rect2fc rect, int clipOp)
    Replaces the current clip with the intersection or difference of the current clip and the given rect, with an aliased or anti-aliased clip edge.
    final void
    clipRect(Rect2fc rect, int clipOp, boolean doAA)
    Replaces the current clip with the intersection or difference of the current clip and the given rect, with an aliased or anti-aliased clip edge.
    final void
    Intersect the current clip with the specified rectangle and updates the stencil buffer if changed, which is expressed in local coordinates.
    final void
    clipRect(Rect2ic rect, int clipOp)
    Replaces the current clip with the intersection or difference of the current clip and the given rect, with an aliased or anti-aliased clip edge.
    void
    Draws saved layers, if any.
    final void
    concat(Matrix4c matrix)
    Pre-multiply the current matrix by the specified matrix.
    final void
    concat(Matrixc matrix)
    Pre-multiply the current matrix by the specified matrix.
    protected void
     
    protected void
     
    protected void
    didScale(float sx, float sy, float sz)
     
    protected void
     
    protected void
    didTranslate(float dx, float dy, float dz)
     
    final void
    Makes Canvas contents undefined.
    final void
    drawArc(float cx, float cy, float radius, float startAngle, float sweepAngle, int cap, float width, Paint paint)
    Draw a circular arc at (cx, cy) with radius using the current matrix, clip and specified paint.
    final void
    drawArc(float cx, float cy, float radius, float startAngle, float sweepAngle, Paint paint)
    Draw a circular arc at (cx, cy) with radius using the current matrix, clip and specified paint.
    final void
    drawChord(float cx, float cy, float radius, float startAngle, float sweepAngle, Paint paint)
    Draw a circular segment (i.e., a cut disk) at (cx, cy) with radius using the current matrix, clip and specified paint.
    final void
    drawCircle(float cx, float cy, float radius, Paint paint)
    Draw the specified circle at (cx, cy) with radius using the specified paint.
    final void
    drawColor(float r, float g, float b, float a)
    Fill the current clip with the specified color, using SRC_OVER blend mode.
    final void
    drawColor(float r, float g, float b, float a, BlendMode mode)
    Fill the current clip with the specified color, the blend mode determines how color is combined with destination.
    final void
    drawColor(int color)
    Fill the current clip with the specified color, using SRC_OVER blend mode.
    final void
    drawColor(int color, BlendMode mode)
    Fill the current clip with the specified color, the blend mode determines how color is combined with destination.
    final void
    drawGlyphs(int[] glyphs, int glyphOffset, float[] positions, int positionOffset, int glyphCount, float originX, float originY, Font font, Paint paint)
    Draws count glyphs, at positions relative to origin styled with font and paint.
    final void
    drawImage(@RawPtr Image image, float x, float y, SamplingOptions sampling, Paint paint)
    Draw the specified image with its top/left corner at (x,y), using the specified paint, transformed by the current matrix.
    final void
    drawImageRect(@RawPtr Image image, Rect2fc src, Rect2fc dst, SamplingOptions sampling, Paint paint, int constraint)
    Draw the specified image, scaling/translating automatically to fill the destination rectangle.
    final void
    drawImageRect(@RawPtr Image image, Rect2fc dst, SamplingOptions sampling, Paint paint)
    Draw the specified image, scaling/translating automatically to fill the destination rectangle.
    final void
    drawLine(float x0, float y0, float x1, float y1, int cap, float width, Paint paint)
    Draw a line segment from (x0, y0) to (x1, y1) using the current matrix, clip and specified paint.
    final void
    drawLine(float x0, float y0, float x1, float y1, Paint paint)
    Draws line segment from (x0, y0) to (x1, y1) using the current matrix, clip and specified paint.
    final void
    Fills the current clip with the specified paint.
    final void
    drawPie(float cx, float cy, float radius, float startAngle, float sweepAngle, Paint paint)
    Draw a circular sector (i.e., a pie) at (cx, cy) with radius using the current matrix, clip and specified paint.
    final void
    drawPoint(float x, float y, int cap, float size, Paint paint)
    Draws point at (x, y) using the current matrix, clip and specified paint.
    final void
    drawPoint(float x, float y, Paint paint)
    Draws point at (x, y) using the current matrix, clip and specified paint.
    final void
    drawPoints(int mode, float[] pts, int offset, int count, Paint paint)
    Draws pts using the current matrix, clip and specified paint.
    void
    drawRect(float left, float top, float right, float bottom, Paint paint)
    Draw the specified Rect using the specified paint.
    final void
    drawRect(Rect2fc r, Paint paint)
    Draw the specified Rect using the specified paint.
    final void
    drawRect(Rect2ic r, Paint paint)
    Draw the specified Rect using the specified paint.
    void
    drawRoundRect(float left, float top, float right, float bottom, float rUL, float rUR, float rLR, float rLL, Paint paint)
    Draw a rectangle with rounded corners within a rectangular bounds.
    final void
    drawRoundRect(float left, float top, float right, float bottom, float radius, Paint paint)
    Draw a rectangle with rounded corners within a rectangular bounds.
    final void
    drawRoundRect(Rect2fc rect, float radius, Paint paint)
    Draw a rectangle with rounded corners within a rectangular bounds.
    final void
    drawRoundRect(Rect2f rect, float rUL, float rUR, float rLR, float rLL, Paint paint)
    Draw a rectangle with rounded corners within a rectangular bounds.
    void
    drawRoundRect(RoundRect roundRect, Paint paint)
     
    final void
    drawTextBlob(TextBlob blob, float originX, float originY, Paint paint)
    Draws TextBlob blob at (x, y), using the current matrix, clip and specified paint.
    void
    drawTriangle(float x0, float y0, float x1, float y1, float x2, float y2, Paint paint)
    Draw a triangle using the specified paint.
    final void
    drawVertices(Vertices vertices, @SharedPtr Blender blender, Paint paint)
    Draws the vertices, a triangle mesh, using current clip and matrix.
    int
    Gets the size of the base or root layer in global canvas coordinates.
    int
    Gets the size of the base or root layer in global canvas coordinates.
    final boolean
    Returns the bounds of clip, unaffected by the transform matrix.
    final ImageInfo
    Returns ImageInfo for Canvas.
    final boolean
    Returns the bounds of clip, transformed by inverse of the transform matrix.
    final void
    Returns the current transform from local coordinates to the 'device', which for most purposes means pixels.
    final void
    Returns the current transform from local coordinates to the 'device', which for most purposes means pixels.
    Returns GPU context of the GPU surface associated with Canvas.
    protected @RawPtr Device
     
    final int
    Returns the depth of saved matrix/clip states on the Canvas' private stack.
    protected int
    getSaveLayerStrategy(Rect2f bounds, Paint paint, ImageFilter backdrop, int saveLayerFlags)
     
    Sometimes a canvas is owned by a surface.
    boolean
    Returns true if clip is empty; that is, nothing will draw.
    boolean
    Returns true if clip is a Rect and not empty.
    Creates Surface matching info, and associates it with Canvas.
    protected void
    onClipRect(Rect2fc rect, int clipOp, boolean doAA)
     
    protected void
     
    protected void
    onDrawArc(float cx, float cy, float radius, float startAngle, float sweepAngle, int cap, float width, Paint paint)
     
    protected void
    onDrawChord(float cx, float cy, float radius, float startAngle, float sweepAngle, Paint paint)
     
    protected void
    onDrawCircle(float cx, float cy, float radius, Paint paint)
     
    protected void
    onDrawGlyphRunList(GlyphRunList glyphRunList, Paint paint)
     
    protected void
    onDrawImageRect(@RawPtr Image image, Rect2fc src, Rect2fc dst, SamplingOptions sampling, Paint paint, int constraint)
     
    protected void
    onDrawLine(float x0, float y0, float x1, float y1, int cap, float width, Paint paint)
     
    protected void
     
    protected void
    onDrawPie(float cx, float cy, float radius, float startAngle, float sweepAngle, Paint paint)
     
    protected void
    onDrawPoints(int mode, float[] pts, int offset, int count, Paint paint)
     
    protected void
     
    protected void
     
    protected void
    onDrawTextBlob(TextBlob blob, float originX, float originY, Paint paint)
     
    protected void
    onDrawVertices(Vertices vertices, @SharedPtr Blender blender, Paint paint)
     
    protected ImageInfo
     
     
    final boolean
    quickReject(float left, float top, float right, float bottom)
    Return true if the specified rectangle, after being transformed by the current matrix, would lie completely outside the current clip.
    final boolean
    Return true if the specified rectangle, after being transformed by the current matrix, would lie completely outside the current clip.
    final void
    Sets the current matrix to the identity matrix.
    final void
    This call balances a previous call to save(), and is used to remove all modifications to the matrix/clip state since the last save call.
    final void
    restoreToCount(int saveCount)
    Efficient way to pop any calls to save() that happened after the save count reached saveCount.
    final void
    rotate(float degrees)
    Rotates the current matrix by degrees clockwise about the Z axis.
    final void
    rotate(float degrees, float px, float py)
    Rotates the current matrix by degrees clockwise about the Z axis at (px, py).
    final int
    Saves the current matrix and clip onto a private stack.
    final int
    saveLayer(float left, float top, float right, float bottom, Paint paint)
    Convenience for saveLayer(Rect2f, Paint) that takes the four float coordinates of the bounds' rectangle.
    final int
    saveLayer(float left, float top, float right, float bottom, Paint paint, ImageFilter backdrop, int saveLayerFlags)
    Convenience for saveLayer(Rect2f, Paint, ImageFilter, int) that takes the four float coordinates of the bounds' rectangle.
    final int
    saveLayer(Rect2f bounds, Paint paint)
    This behaves the same as save(), but in addition it allocates and redirects drawing to an offscreen rendering target (a drawing layer).
    final int
    saveLayer(Rect2f bounds, Paint paint, ImageFilter backdrop, int saveLayerFlags)
    This behaves the same as save(), but in addition it allocates and redirects drawing to an offscreen rendering target (a drawing layer).
    final int
    saveLayerAlpha(float left, float top, float right, float bottom, int alpha)
    Convenience for saveLayerAlpha(Rect2f, int) that takes the four float coordinates of the bounds' rectangle.
    final int
    saveLayerAlpha(Rect2f bounds, int alpha)
    This behaves the same as save(), but in addition it allocates and redirects drawing to an offscreen rendering target (a drawing layer).
    final void
    scale(float sx, float sy)
    Scales the current matrix by sx on the x-axis and sy on the y-axis.
    final void
    scale(float sx, float sy, float sz)
    Scales the current matrix by sx on the x-axis, sy on the y-axis, and sz on the z-axis.
    final void
    scale(float sx, float sy, float px, float py)
    Scales the current matrix by sx on the x-axis and sy on the y-axis at (px, py).
    final void
    Replaces the current matrix with the specified matrix.
    final void
    shear(float sx, float sy)
    Shears the current matrix by sx on the x-axis and sy on the y-axis.
    final void
    shear(float sx, float sy, float px, float py)
    Pre-multiply the current matrix by the specified shearing.
    final void
    translate(float dx, float dy)
    Translates the current matrix by dx along the x-axis and dy along the y-axis.
    final void
    translate(float dx, float dy, float dz)
    Translates the current matrix by dx along the x-axis, dy along the y-axis, and dz along the z-axis.
    protected void
     
    protected void
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • INIT_WITH_PREVIOUS_SAVE_LAYER_FLAG

      public static final int INIT_WITH_PREVIOUS_SAVE_LAYER_FLAG
      Initializes with previous contents.
      See Also:
    • F16_COLOR_TYPE_SAVE_LAYER_FLAG

      public static final int F16_COLOR_TYPE_SAVE_LAYER_FLAG
      Instead of matching previous layer's color type, use F16.
      See Also:
    • FULL_LAYER_SAVE_LAYER_STRATEGY

      protected static final int FULL_LAYER_SAVE_LAYER_STRATEGY
      See Also:
    • NO_LAYER_SAVE_LAYER_STRATEGY

      protected static final int NO_LAYER_SAVE_LAYER_STRATEGY
      See Also:
    • POINT_MODE_POINTS

      public static final int POINT_MODE_POINTS
      Draw each point separately.
      See Also:
    • POINT_MODE_LINES

      public static final int POINT_MODE_LINES
      Draw each pair of points as a line segment.
      See Also:
    • POINT_MODE_POLYGON

      public static final int POINT_MODE_POLYGON
      Draw the array of points as an open polygon.
      See Also:
    • SRC_RECT_CONSTRAINT_FAST

      public static final int SRC_RECT_CONSTRAINT_FAST
      Sample outside bounds; faster
      See Also:
    • SRC_RECT_CONSTRAINT_STRICT

      public static final int SRC_RECT_CONSTRAINT_STRICT
      Sample only inside bounds; slower.
      See Also:
  • Constructor Details

    • Canvas

      public Canvas()
      Creates an empty Canvas with no backing device or pixels, with a width and height of zero.
    • Canvas

      public Canvas(int width, int height)
      Creates Canvas of the specified dimensions without a Surface. Used by subclasses with custom implementations for draw member functions.
      Parameters:
      width - zero or greater
      height - zero or greater
    • Canvas

      protected Canvas(@Nonnull Rect2ic bounds)
    • Canvas

      @Internal public Canvas(@SharedPtr @SharedPtr Device device)
  • Method Details

    • getImageInfo

      @Nonnull public final ImageInfo getImageInfo()
      Returns ImageInfo for Canvas. If Canvas is not associated with raster surface or GPU surface, returned ColorType is set to ColorInfo.CT_UNKNOWN.
      Returns:
      dimensions and ColorType of Canvas
    • getBaseLayerWidth

      public int getBaseLayerWidth()
      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 smaller (due to clipping or saveLayer).
      Returns:
      integral width of base layer
    • getBaseLayerHeight

      public int getBaseLayerHeight()
      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 smaller (due to clipping or saveLayer).
      Returns:
      integral height of base layer
    • makeSurface

      @Nullable @SharedPtr public final @SharedPtr Surface makeSurface(ImageInfo info)
      Creates Surface matching info, and associates it with Canvas. Returns null if no match found.
      Parameters:
      info - width, height, ColorType and AlphaType
      Returns:
      Surface matching info, or null if no match is available
    • getRecordingContext

      @RawPtr @Nullable public @RawPtr RecordingContext getRecordingContext()
      Returns GPU context of the GPU surface associated with Canvas.
      Returns:
      GPU context, if available; null otherwise
    • getSurface

      @RawPtr @Nullable public final @RawPtr Surface getSurface()
      Sometimes a canvas is owned by a surface. If it is, getSurface() will return a bare pointer to that surface, else this will return null.
    • save

      public final int save()
      Saves the current matrix and clip onto a private stack.

      Subsequent calls to translate, scale, rotate, shear, concat or clipRect, clipPath will all operate as usual, but when the balancing call to restore() is made, those calls will be forgotten, and the settings that existed before the save() will be reinstated.

      Saved Canvas state is put on a stack; multiple calls to save() should be balance by an equal number of calls to restore(). Call restoreToCount() with the return value of this method to restore this and subsequent saves.

      Returns:
      depth of saved stack to pass to restoreToCount() to balance this call
    • saveLayer

      public final int saveLayer(@Nullable Rect2f bounds, @Nullable Paint paint)
      This behaves the same as save(), but in addition it allocates and redirects drawing to an offscreen rendering target (a drawing layer).

      Note: this method is very expensive, incurring more than double rendering cost for contained content. Avoid using this method when possible.

      All drawing calls are directed to a newly allocated offscreen rendering target. Only when the balancing call to restore() is made, is that offscreen buffer drawn back to the current target of the Canvas (which can potentially be a previous layer if these calls are nested).

      Optional paint applies alpha, ColorFilter, ImageFilter, and BlendMode when restore() is called.

      Call restoreToCount() with returned value to restore this and subsequent saves.

      Parameters:
      bounds - the maximum size the offscreen render target needs to be (in local coordinates), may be null
      paint - the paint is applied to the offscreen when restore() is called, may be null
      Returns:
      depth of saved stack to pass to restoreToCount() to balance this call
    • saveLayer

      public final int saveLayer(float left, float top, float right, float bottom, @Nullable Paint paint)
      Convenience for saveLayer(Rect2f, Paint) that takes the four float coordinates of the bounds' rectangle.
      See Also:
    • saveLayerAlpha

      public final int saveLayerAlpha(@Nullable Rect2f bounds, int alpha)
      This behaves the same as save(), but in addition it allocates and redirects drawing to an offscreen rendering target (a drawing layer).

      Note: this method is very expensive, incurring more than double rendering cost for contained content. Avoid using this method when possible.

      All drawing calls are directed to a newly allocated offscreen rendering target. Only when the balancing call to restore() is made, is that offscreen buffer drawn back to the current target of the Canvas (which can potentially be a previous layer if these calls are nested).

      Alpha of zero is fully transparent, 255 is fully opaque.

      Call restoreToCount() with returned value to restore this and subsequent saves.

      Parameters:
      bounds - the maximum size the offscreen render target needs to be (in local coordinates), may be null
      alpha - the alpha to apply to the offscreen when restore() is called
      Returns:
      depth of saved stack to pass to restoreToCount() to balance this call
    • saveLayerAlpha

      public final int saveLayerAlpha(float left, float top, float right, float bottom, int alpha)
      Convenience for saveLayerAlpha(Rect2f, int) that takes the four float coordinates of the bounds' rectangle.
      See Also:
    • saveLayer

      public final int saveLayer(@Nullable Rect2f bounds, @Nullable Paint paint, @Nullable ImageFilter backdrop, int saveLayerFlags)
      This behaves the same as save(), but in addition it allocates and redirects drawing to an offscreen rendering target (a drawing layer).

      Note: this method is very expensive, incurring more than double rendering cost for contained content. Avoid using this method when possible.

      All drawing calls are directed to a newly allocated offscreen rendering target. Only when the balancing call to restore() is made, is that offscreen buffer drawn back to the current target of the Canvas (which can potentially be a previous layer if these calls are nested).

      Optional paint applies alpha, ColorFilter, ImageFilter, and BlendMode when restore() is called.

      If backdrop is not null, it triggers the same initialization behavior as setting INIT_WITH_PREVIOUS_SAVE_LAYER_FLAG on saveLayerFlags: the current layer is copied into the new layer, rather than initializing the new layer with transparent-black. This is then filtered by backdrop (respecting the current clip).

      Call restoreToCount() with returned value to restore this and subsequent saves.

      Parameters:
      bounds - the maximum size the offscreen render target needs to be (in local coordinates), may be null
      paint - the paint is applied to the offscreen when restore() is called, may be null
      backdrop - if not null, this causes the current layer to be filtered by backdrop, and then drawn into the new layer (respecting the current clip)
      saveLayerFlags - options to modify layer, may be zero
      Returns:
      depth of saved stack to pass to restoreToCount() to balance this call
    • saveLayer

      public final int saveLayer(float left, float top, float right, float bottom, @Nullable Paint paint, @Nullable ImageFilter backdrop, int saveLayerFlags)
      Convenience for saveLayer(Rect2f, Paint, ImageFilter, int) that takes the four float coordinates of the bounds' rectangle.
      See Also:
    • restore

      public final void restore()
      This call balances a previous call to save(), and is used to remove all modifications to the matrix/clip state since the last save call. The state is removed from the stack. It is an error to call restore() more or less times than save() was called in the final state.
      Throws:
      IllegalStateException - stack underflow
    • getSaveCount

      public final int getSaveCount()
      Returns the depth of saved matrix/clip states on the Canvas' private stack. This will equal save() calls minus restore() calls, and the number of save() calls less the number of restore() calls plus one. The save count of a new canvas is one.
      Returns:
      depth of save state stack
    • restoreToCount

      public final void restoreToCount(int saveCount)
      Efficient way to pop any calls to save() that happened after the save count reached saveCount. It is an error for saveCount to be less than 1.

      Example:

       int count = canvas.save();
       ... // more calls potentially to save()
       canvas.restoreToCount(count);
       // now the canvas is back in the same state it
       // was before the initial call to save().
       
      Parameters:
      saveCount - the depth of state stack to restore
      Throws:
      IllegalStateException - stack underflow (i.e. saveCount is less than 1)
    • translate

      public final void translate(float dx, float dy)
      Translates the current matrix by dx along the x-axis and dy along the y-axis. Mathematically, pre-multiply the current matrix with a translation matrix.

      This has the effect of moving the drawing by (dx, dy) before transforming the result with the current matrix.

      Parameters:
      dx - the distance to translate on x-axis
      dy - the distance to translate on y-axis
    • translate

      public final void translate(float dx, float dy, float dz)
      Translates the current matrix by dx along the x-axis, dy along the y-axis, and dz along the z-axis. Mathematically, pre-multiply the current matrix with a translation matrix.

      This has the effect of moving the drawing by (dx, dy, dz) before transforming the result with the current matrix.

      Parameters:
      dx - the distance to translate on x-axis
      dy - the distance to translate on y-axis
      dz - the distance to translate on z-axis
    • scale

      public final void scale(float sx, float sy)
      Scales the current matrix by sx on the x-axis and sy on the y-axis. Mathematically, pre-multiply the current matrix with a scaling matrix.

      This has the effect of scaling the drawing by (sx, sy) before transforming the result with the current matrix.

      Parameters:
      sx - the amount to scale on x-axis
      sy - the amount to scale on y-axis
    • scale

      public final void scale(float sx, float sy, float sz)
      Scales the current matrix by sx on the x-axis, sy on the y-axis, and sz on the z-axis. Mathematically, pre-multiply the current matrix with a scaling matrix.

      This has the effect of scaling the drawing by (sx, sy, sz) before transforming the result with the current matrix.

      Parameters:
      sx - the amount to scale on x-axis
      sy - the amount to scale on y-axis
      sz - the amount to scale on z-axis
    • scale

      public final void scale(float sx, float sy, float px, float py)
      Scales the current matrix by sx on the x-axis and sy on the y-axis at (px, py). Mathematically, pre-multiply the current matrix with a translation matrix; pre-multiply the current matrix with a scaling matrix; then pre-multiply the current matrix with a negative translation matrix;

      This has the effect of scaling the drawing by (sx, sy) before transforming the result with the current matrix.

      Parameters:
      sx - the amount to scale on x-axis
      sy - the amount to scale on y-axis
      px - the x-coord for the pivot point (unchanged by the scale)
      py - the y-coord for the pivot point (unchanged by the scale)
    • rotate

      public final void rotate(float degrees)
      Rotates the current matrix by degrees clockwise about the Z axis. Mathematically, pre-multiply the current matrix with a rotation matrix;

      This has the effect of rotating the drawing by degrees before transforming the result with the current matrix.

      Parameters:
      degrees - the amount to rotate, in degrees
    • rotate

      public final void rotate(float degrees, float px, float py)
      Rotates the current matrix by degrees clockwise about the Z axis at (px, py). Mathematically, pre-multiply the current matrix with a translation matrix; pre-multiply the current matrix with a rotation matrix; then pre-multiply the current matrix with a negative translation matrix;

      This has the effect of rotating the drawing by degrees before transforming the result with the current matrix.

      Parameters:
      degrees - the amount to rotate, in degrees
      px - the x-coord for the pivot point (unchanged by the rotation)
      py - the y-coord for the pivot point (unchanged by the rotation)
    • shear

      public final void shear(float sx, float sy)
      Shears the current matrix by sx on the x-axis and sy on the y-axis. A positive value of sx shears the drawing right as y-axis values increase; a positive value of sy shears the drawing down as x-axis values increase.

      Mathematically, pre-multiply the current matrix with a shearing matrix.

      This has the effect of shearing the drawing by (sx, sy) before transforming the result with the current matrix.

      Parameters:
      sx - the amount to shear on x-axis
      sy - the amount to shear on y-axis
    • shear

      public final void shear(float sx, float sy, float px, float py)
      Pre-multiply the current matrix by the specified shearing.
      Parameters:
      sx - the x-component of the shearing, y is unchanged
      sy - the y-component of the shearing, x is unchanged
      px - the x-component of the pivot (unchanged by the shear)
      py - the y-component of the pivot (unchanged by the shear)
    • concat

      public final void concat(@Nonnull Matrixc matrix)
      Pre-multiply the current matrix by the specified matrix.

      This has the effect of transforming the drawn geometry by matrix, before transforming the result with the current matrix.

      Parameters:
      matrix - the matrix to premultiply with the current matrix
    • concat

      public final void concat(@Nonnull Matrix4c matrix)
      Pre-multiply the current matrix by the specified matrix.

      This has the effect of transforming the drawn geometry by matrix, before transforming the result with the current matrix.

      Parameters:
      matrix - the matrix to premultiply with the current matrix
    • setMatrix

      public final void setMatrix(@Nonnull Matrix4c matrix)
      Replaces the current matrix with the specified matrix. Unlike concat(), any prior matrix state is overwritten.
      Parameters:
      matrix - matrix to copy, replacing the current matrix
    • resetMatrix

      public final void resetMatrix()
      Sets the current matrix to the identity matrix. Any prior matrix state is overwritten.
    • clipRect

      public final void clipRect(Rect2ic rect)
      Intersect the current clip with the specified rectangle and updates the stencil buffer if changed, which is expressed in local coordinates. Resulting clip is aliased. The clip bounds cannot be expanded unless restore() is called.
      Parameters:
      rect - the rectangle to intersect with the current clip
    • clipRect

      public final void clipRect(Rect2fc rect)
      Intersect the current clip with the specified rectangle and updates the stencil buffer if changed, which is expressed in local coordinates. Resulting clip is aliased. The clip bounds cannot be expanded unless restore() is called.
      Parameters:
      rect - the rectangle to intersect with the current clip
    • clipRect

      public final void clipRect(float left, float top, float right, float bottom)
      Intersect the current clip with the specified rectangle and updates the stencil buffer if changed, which is expressed in local coordinates. Resulting clip is aliased. The clip bounds cannot be expanded unless restore() is called.
      Parameters:
      left - the left side of the rectangle to intersect with the current clip
      top - the top of the rectangle to intersect with the current clip
      right - the right side of the rectangle to intersect with the current clip
      bottom - the bottom of the rectangle to intersect with the current clip
    • clipRect

      public final void clipRect(Rect2fc rect, boolean doAA)
      Intersect the current clip with the specified rectangle and updates the stencil buffer if changed, which is expressed in local coordinates, with an aliased or anti-aliased clip edge. The clip bounds cannot be expanded unless restore() is called.
      Parameters:
      rect - the rectangle to intersect with the current clip
      doAA - true if clip is to be anti-aliased
    • clipRect

      public final void clipRect(float left, float top, float right, float bottom, boolean doAA)
      Intersect the current clip with the specified rectangle and updates the stencil buffer if changed, which is expressed in local coordinates, with an aliased or anti-aliased clip edge. The clip bounds cannot be expanded unless restore() is called.
      Parameters:
      left - the left side of the rectangle to intersect with the current clip
      top - the top of the rectangle to intersect with the current clip
      right - the right side of the rectangle to intersect with the current clip
      bottom - the bottom of the rectangle to intersect with the current clip
      doAA - true if clip is to be anti-aliased
    • clipRect

      public final void clipRect(Rect2ic rect, int clipOp)
      Replaces the current clip with the intersection or difference of the current clip and the given rect, with an aliased or anti-aliased clip edge. The rectangle is transformed by the current matrix before it is combined with clip.
      Parameters:
      rect - rectangle to combine with clip
      clipOp - ClipOp to apply to clip
    • clipRect

      public final void clipRect(Rect2fc rect, int clipOp)
      Replaces the current clip with the intersection or difference of the current clip and the given rect, with an aliased or anti-aliased clip edge. The rectangle is transformed by the current matrix before it is combined with clip.
      Parameters:
      rect - rectangle to combine with clip
      clipOp - ClipOp to apply to clip
    • clipRect

      public final void clipRect(float left, float top, float right, float bottom, int clipOp)
      Replaces the current clip with the intersection or difference of the current clip and the given rect, with an aliased or anti-aliased clip edge. The rectangle is transformed by the current matrix before it is combined with clip.
      Parameters:
      clipOp - ClipOp to apply to clip
    • clipRect

      public final void clipRect(Rect2fc rect, int clipOp, boolean doAA)
      Replaces the current clip with the intersection or difference of the current clip and the given rect, with an aliased or anti-aliased clip edge. The rectangle is transformed by the current matrix before it is combined with clip.
      Parameters:
      rect - rectangle to combine with clip
      clipOp - ClipOp to apply to clip
      doAA - true if clip mask is requested to be anti-aliased
    • quickReject

      public final boolean quickReject(Rect2fc rect)
      Return true if the specified rectangle, after being transformed by the current matrix, would lie completely outside the current clip. Call this to check if an area you intend to draw into is clipped out (and therefore you can skip making the draw calls). May return false even though rect is outside of clip (conservative).

      Note that each draw all will check this internally. This is used to skip subsequent draw calls.

      Parameters:
      rect - the rect to compare with the current clip
      Returns:
      true if the given rect (transformed by the canvas' matrix) intersecting with the maximum rect representing the canvas' clip is empty
    • quickReject

      public final boolean quickReject(float left, float top, float right, float bottom)
      Return true if the specified rectangle, after being transformed by the current matrix, would lie completely outside the current clip. Call this to check if an area you intend to draw into is clipped out (and therefore you can skip making the draw calls). May return false even though rect is outside of clip (conservative).

      Note that each draw all will check this internally. This is used to skip subsequent draw calls.

      Parameters:
      left - the left side of the rectangle to compare with the current clip
      top - the top of the rectangle to compare with the current clip
      right - the right side of the rectangle to compare with the current clip
      bottom - the bottom of the rectangle to compare with the current clip
      Returns:
      true if the given rect (transformed by the canvas' matrix) intersecting with the maximum rect representing the canvas' clip is empty
    • getLocalClipBounds

      public final boolean getLocalClipBounds(Rect2f bounds)
      Returns the bounds of clip, transformed by inverse of the transform matrix. If clip is empty, return false, and set bounds to empty, where all rect sides equal zero.

      The bounds is outset by one to account for partial pixel coverage if clip is anti-aliased.

      Parameters:
      bounds - the bounds of clip in local coordinates
      Returns:
      true if clip bounds is not empty
    • getDeviceClipBounds

      public final boolean getDeviceClipBounds(Rect2i bounds)
      Returns the bounds of clip, unaffected by the transform matrix. If clip is empty, return false, and set bounds to empty, where all rect sides equal zero.

      Unlike getLocalClipBounds(), bounds is not outset.

      Parameters:
      bounds - the bounds of clip in device coordinates
      Returns:
      true if clip bounds is not empty
    • clear

      public final void clear(@ColorInt int color)
      Fills the current clip with the specified color, using SRC blend mode. This has the effect of replacing all pixels contained by clip with color.
      Parameters:
      color - the un-premultiplied (straight) color to draw onto the canvas
    • clear

      public final void clear(float r, float g, float b, float a)
      Fills the current clip with the specified color, using SRC blend mode. This has the effect of replacing all pixels contained by clip with color.
      Parameters:
      r - the red component of the straight color to draw onto the canvas
      g - the red component of the straight color to draw onto the canvas
      b - the red component of the straight color to draw onto the canvas
      a - the red component of the straight color to draw onto the canvas
    • discard

      public final void discard()
      Makes Canvas contents undefined. Subsequent calls that read Canvas pixels, such as drawing with BlendMode, 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.

    • drawColor

      public final void drawColor(@ColorInt int color)
      Fill the current clip with the specified color, using SRC_OVER blend mode.
      Parameters:
      color - the straight color to draw onto the canvas
    • drawColor

      public final void drawColor(float r, float g, float b, float a)
      Fill the current clip with the specified color, using SRC_OVER blend mode.
      Parameters:
      r - the red component of the straight color to draw onto the canvas
      g - the red component of the straight color to draw onto the canvas
      b - the red component of the straight color to draw onto the canvas
      a - the red component of the straight color to draw onto the canvas
    • drawColor

      public final void drawColor(@ColorInt int color, BlendMode mode)
      Fill the current clip with the specified color, the blend mode determines how color is combined with destination.
      Parameters:
      color - the straight color to draw onto the canvas
      mode - the blend mode used to combine source color and destination
    • drawColor

      public final void drawColor(float r, float g, float b, float a, BlendMode mode)
      Fill the current clip with the specified color, the blend mode determines how color is combined with destination.
      Parameters:
      r - the red component of the straight color to draw onto the canvas
      g - the red component of the straight color to draw onto the canvas
      b - the red component of the straight color to draw onto the canvas
      a - the red component of the straight color to draw onto the canvas
      mode - the blend mode used to combine source color and destination
    • drawPaint

      public final void drawPaint(Paint paint)
      Fills the current clip with the specified paint. Paint components, Shader, ColorFilter, ImageFilter, and BlendMode affect drawing.

      This is equivalent (but faster) to drawing an infinitely large rectangle with the specified paint.

      Parameters:
      paint - the paint used to draw onto the canvas
    • drawPoints

      public final void drawPoints(int mode, float[] pts, int offset, int count, Paint paint)
      Draws pts using the current matrix, clip and specified paint. count is the number of points; if count is less than one, has no effect. mode may be one of: POINT_MODE_POINTS, POINT_MODE_LINES, or POINT_MODE_POLYGON.

      If mode is POINT_MODE_POINTS, the shape of point drawn depends on paint Cap. If paint is set to Paint.CAP_ROUND, each point draws a circle of diameter paint stroke width. If paint is set to Paint.CAP_SQUARE or Paint.CAP_BUTT, each point draws a square of width and height paint stroke width.

      If mode is POINT_MODE_LINES, 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, the last point is ignored.

      If mode is POINT_MODE_POLYGON, 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 Cap and paint stroke width. Paint style is ignored, as if were set to Paint.STROKE.

      Always draws each element one at a time; is not affected by paint join, and unlike drawPath(), does not create a mask from all points and lines before drawing.

      Parameters:
      mode - whether pts draws points or lines
      pts - array of points to draw
      offset - offset in pts array, i.e., number of floats to skip
      count - number of points in pts array
      paint - stroke, blend, color, and so on, used to draw
    • drawPoint

      public final void drawPoint(float x, float y, Paint paint)
      Draws point at (x, y) using the current matrix, clip and specified paint.

      The shape of point drawn depends on paint cap. If paint is set to Paint.CAP_ROUND, draw a circle of diameter paint stroke width. If paint is set to Paint.CAP_SQUARE or Paint.CAP_BUTT, draw a square of width and height paint stroke width. Paint style is ignored, as if were set to Paint.STROKE.

      Parameters:
      x - center X of circle or square
      y - center Y of circle or square
      paint - stroke, blend, color, and so on, used to draw
    • drawPoint

      public final void drawPoint(float x, float y, int cap, float size, Paint paint)
      Draws point at (x, y) using the current matrix, clip and specified paint.

      The shape of point drawn depends on cap. If cap is Paint.CAP_ROUND, draw a circle of diameter size. If cap is Paint.CAP_SQUARE or Paint.CAP_BUTT, draw a square of width and height size. In paint: Style determines if point is stroked or filled; If stroked (i.e. double stroke), stroke width describes the shape outline thickness, Cap describes line ends, Join draws the corners rounded or square, and Align determines the position or direction to stroke.

      Parameters:
      x - center X of circle or square
      y - center Y of circle or square
      cap - the line end used to determine the shape of point
      size - the diameter of circle or width and height of square
      paint - stroke, blend, color, and so on, used to draw
    • drawLine

      public final void drawLine(float x0, float y0, float x1, float y1, Paint paint)
      Draws line segment from (x0, y0) to (x1, y1) using the current matrix, clip and specified paint. In paint: stroke width describes the line thickness; Cap draws the end rounded or square; Style is ignored, as if were set to Paint.STROKE.
      Parameters:
      x0 - start of line segment on x-axis
      y0 - start of line segment on y-axis
      x1 - end of line segment on x-axis
      y1 - end of line segment on y-axis
      paint - the paint used to draw the line
    • drawLine

      public final void drawLine(float x0, float y0, float x1, float y1, int cap, float width, Paint paint)
      Draw a line segment from (x0, y0) to (x1, y1) using the current matrix, clip and specified paint. Note that line shape is a stroked line rather than a line path, you can fill or stroke the stroked line.

      The cap describes the end of the line shape, the width describes the line shape thickness. In paint: Style determines if line shape is stroked or filled; If stroked (i.e. double stroke), stroke width describes the shape outline thickness, Cap describes line ends, Join draws the corners rounded or square, and Align determines the position or direction to stroke.

      Parameters:
      x0 - the start of line segment on x-axis
      y0 - the start of line segment on y-axis
      x1 - the end of line segment on x-axis
      y1 - the end of line segment on y-axis
      cap - the line end used to determine the shape of the line
      width - the thickness of line segment
      paint - the paint used to draw the line
    • drawRect

      public final void drawRect(Rect2fc r, Paint paint)
      Draw the specified Rect using the specified paint. In paint: Paint's style determines if rectangle is stroked or filled; if stroked, Paint's stroke width describes the line thickness, and Paint's join draws the corners rounded or square.
      Parameters:
      r - the rectangle to be drawn.
      paint - the paint used to draw the rectangle
    • drawRect

      public final void drawRect(Rect2ic r, Paint paint)
      Draw the specified Rect using the specified paint. In paint: Paint's style determines if rectangle is stroked or filled; if stroked, Paint's stroke width describes the line thickness, and Paint's join draws the corners rounded or square.
      Parameters:
      r - the rectangle to be drawn.
      paint - the paint used to draw the rectangle
    • drawRect

      public void drawRect(float left, float top, float right, float bottom, Paint paint)
      Draw the specified Rect using the specified paint. In paint: Paint's style determines if rectangle is stroked or filled; if stroked, Paint's stroke width describes the line thickness, and Paint's join draws the corners rounded or square.
      Parameters:
      left - the left side of the rectangle to be drawn
      top - the top side of the rectangle to be drawn
      right - the right side of the rectangle to be drawn
      bottom - the bottom side of the rectangle to be drawn
      paint - the paint used to draw the rect
    • drawRoundRect

      public final void drawRoundRect(Rect2fc rect, float radius, Paint paint)
      Draw a rectangle with rounded corners within a rectangular bounds. The round rectangle will be filled or framed based on the Style in the paint.
      Parameters:
      rect - The rectangular bounds of the round rect to be drawn
      radius - the radius used to round the corners
      paint - the paint used to draw the round rectangle
    • drawRoundRect

      public final void drawRoundRect(float left, float top, float right, float bottom, float radius, Paint paint)
      Draw a rectangle with rounded corners within a rectangular bounds. The round rectangle will be filled or framed based on the Style in the paint.
      Parameters:
      left - the left of the rectangular bounds
      top - the top of the rectangular bounds
      right - the right of the rectangular bounds
      bottom - the bottom of the rectangular bounds
      radius - the radius used to round the corners
      paint - the paint used to draw the round rectangle
    • drawRoundRect

      public final void drawRoundRect(Rect2f rect, float rUL, float rUR, float rLR, float rLL, Paint paint)
      Draw a rectangle with rounded corners within a rectangular bounds. The round rectangle will be filled or framed based on the Style in the paint.
      Parameters:
      rect - The rectangular bounds of the round rect to be drawn
      rUL - the radius used to round the upper left corner
      rUR - the radius used to round the upper right corner
      rLR - the radius used to round the lower right corner
      rLL - the radius used to round the lower left corner
      paint - the paint used to draw the round rectangle
    • drawRoundRect

      public void drawRoundRect(float left, float top, float right, float bottom, float rUL, float rUR, float rLR, float rLL, Paint paint)
      Draw a rectangle with rounded corners within a rectangular bounds. The round rectangle will be filled or framed based on the Style in the paint.
      Parameters:
      left - the left of the rectangular bounds
      top - the top of the rectangular bounds
      right - the right of the rectangular bounds
      bottom - the bottom of the rectangular bounds
      rUL - the radius used to round the upper left corner
      rUR - the radius used to round the upper right corner
      rLR - the radius used to round the lower right corner
      rLL - the radius used to round the lower left corner
      paint - the paint used to draw the round rectangle
    • drawRoundRect

      public void drawRoundRect(RoundRect roundRect, Paint paint)
    • drawCircle

      public final void drawCircle(float cx, float cy, float radius, Paint paint)
      Draw the specified circle at (cx, cy) with radius using the specified paint. If radius is zero or less, nothing is drawn. In paint: Paint's style determines if circle is stroked or filled; if stroked, paint's stroke width describes the line thickness.
      Parameters:
      cx - the x-coordinate of the center of the circle to be drawn
      cy - the y-coordinate of the center of the circle to be drawn
      radius - the radius of the circle to be drawn
      paint - the paint used to draw the circle
    • drawArc

      public final void drawArc(float cx, float cy, float radius, float startAngle, float sweepAngle, Paint paint)
      Draw a circular arc at (cx, cy) with radius using the current matrix, clip and specified paint.

      If the start angle is negative or >= 360, the start angle is treated as start angle modulo 360. If the sweep angle is >= 360, then the circle is drawn completely. If the sweep angle is negative, the sweep angle is treated as sweep angle modulo 360.

      The arc is drawn clockwise. An angle of 0 degrees correspond to the geometric angle of 0 degrees (3 o'clock on a watch). If radius is non-positive or sweep angle is zero, nothing is drawn.

      Parameters:
      cx - the x-coordinate of the center of the arc to be drawn
      cy - the y-coordinate of the center of the arc to be drawn
      radius - the radius of the circular arc to be drawn
      startAngle - starting angle (in degrees) where the arc begins
      sweepAngle - sweep angle or angular extent (in degrees); positive is clockwise
      paint - the paint used to draw the arc
    • drawArc

      public final void drawArc(float cx, float cy, float radius, float startAngle, float sweepAngle, int cap, float width, Paint paint)
      Draw a circular arc at (cx, cy) with radius using the current matrix, clip and specified paint. Note that arc shape is a stroked arc rather than an arc path, you can fill or stroke the stroked arc.

      If the start angle is negative or >= 360, the start angle is treated as start angle modulo 360. If the sweep angle is >= 360, then the circle is drawn completely. If the sweep angle is negative, the sweep angle is treated as sweep angle modulo 360.

      The arc is drawn clockwise. An angle of 0 degrees correspond to the geometric angle of 0 degrees (3 o'clock on a watch). If radius is non-positive or sweep angle is zero, nothing is drawn.

      The cap describes the end of the arc shape, the width describes the arc shape thickness. In paint: Style determines if arc shape is stroked or filled; If stroked (i.e. double stroke), stroke width describes the shape outline thickness, Cap describes line ends, Join draws the corners rounded or square, and Align determines the position or direction to stroke.

      Parameters:
      cx - the x-coordinate of the center of the arc to be drawn
      cy - the y-coordinate of the center of the arc to be drawn
      radius - the radius of the circular arc to be drawn
      startAngle - starting angle (in degrees) where the arc begins
      sweepAngle - sweep angle or angular extent (in degrees); positive is clockwise
      cap - the line end used to determine the shape of the arc
      width - the thickness of arc segment
      paint - the paint used to draw the arc
    • drawPie

      public final void drawPie(float cx, float cy, float radius, float startAngle, float sweepAngle, Paint paint)
      Draw a circular sector (i.e., a pie) at (cx, cy) with radius using the current matrix, clip and specified paint.

      Similar to drawArc(float, float, float, float, float, Paint), but when the shape is not a full circle, the geometry is closed by the arc and two line segments from the end of the arc to the center of the circle.

      Parameters:
      cx - the x-coordinate of the center of the arc to be drawn
      cy - the y-coordinate of the center of the arc to be drawn
      radius - the radius of the circular arc to be drawn
      startAngle - starting angle (in degrees) where the arc begins
      sweepAngle - sweep angle or angular extent (in degrees); positive is clockwise
      paint - the paint used to draw the arc
    • drawChord

      public final void drawChord(float cx, float cy, float radius, float startAngle, float sweepAngle, Paint paint)
      Draw a circular segment (i.e., a cut disk) at (cx, cy) with radius using the current matrix, clip and specified paint.

      Similar to drawArc(float, float, float, float, float, Paint), but when the shape is not a full circle, the geometry is closed by the arc and a line segment from the start of the arc segment to the end of the arc segment.

      Parameters:
      cx - the x-coordinate of the center of the arc to be drawn
      cy - the y-coordinate of the center of the arc to be drawn
      radius - the radius of the circular arc to be drawn
      startAngle - starting angle (in degrees) where the arc begins
      sweepAngle - sweep angle or angular extent (in degrees); positive is clockwise
      paint - the paint used to draw the arc
    • drawTriangle

      public void drawTriangle(float x0, float y0, float x1, float y1, float x2, float y2, Paint paint)
      Draw a triangle using the specified paint. The three vertices are in counter-clockwise order.

      The Style is ignored in the paint, triangles are always "filled". The smooth radius and gradient color are ignored as well.

      Parameters:
      x0 - the x-coordinate of the first vertex
      y0 - the y-coordinate of the first vertex
      x1 - the x-coordinate of the second vertex
      y1 - the y-coordinate of the second vertex
      x2 - the x-coordinate of the last vertex
      y2 - the y-coordinate of the last vertex
      paint - the paint used to draw the triangle
    • drawImage

      public final void drawImage(@RawPtr @RawPtr Image image, float x, float y, SamplingOptions sampling, @Nullable Paint paint)
      Draw the specified image with its top/left corner at (x,y), using the specified paint, transformed by the current matrix. The Style and smooth radius is ignored in the paint, images are always filled.
      Parameters:
      image - the image to be drawn
      x - the position of the left side of the image being drawn
      y - the position of the top side of the image being drawn
      paint - the paint used to draw the image, null meaning a default paint
    • drawImageRect

      public final void drawImageRect(@RawPtr @RawPtr Image image, Rect2fc dst, SamplingOptions sampling, @Nullable Paint paint)
      Draw the specified image, scaling/translating automatically to fill the destination rectangle. If the source rectangle is not null, it specifies the subset of the image to draw. The Style and smooth radius is ignored in the paint, images are always filled.
      Parameters:
      image - the image to be drawn
      dst - the rectangle that the image will be scaled/translated to fit into
      paint - the paint used to draw the image, null meaning a default paint
    • drawImageRect

      public final void drawImageRect(@RawPtr @RawPtr Image image, Rect2fc src, Rect2fc dst, SamplingOptions sampling, @Nullable Paint paint, int constraint)
      Draw the specified image, scaling/translating automatically to fill the destination rectangle. If the source rectangle is not null, it specifies the subset of the image to draw. The Style and smooth radius is ignored in the paint, images are always filled.
      Parameters:
      image - the image to be drawn
      src - the subset of the image to be drawn, null meaning full image
      dst - the rectangle that the image will be scaled/translated to fit into
      paint - the paint used to draw the image, null meaning a default paint
    • drawGlyphs

      public final void drawGlyphs(@Nonnull int[] glyphs, int glyphOffset, @Nonnull float[] positions, int positionOffset, int glyphCount, float originX, float originY, @Nonnull Font font, @Nonnull Paint paint)
      Draws count glyphs, at positions relative to origin styled with font and paint.

      This function draw glyphs at the given positions relative to the given origin. It does not perform typeface fallback for glyphs not found in the Typeface in font.

      The drawing obeys the current transform matrix and clipping.

      All elements of paint: PathEffect, Shader, and ColorFilter; apply to text. By default, draws filled white glyphs.

      Parameters:
      glyphs - the array of glyphIDs to draw
      positions - where to draw each glyph relative to origin
      glyphCount - number of glyphs to draw
      originX - the origin X of all the positions
      originY - the origin Y of all the positions
      font - typeface, text size and so, used to describe the text
      paint - blend, color, and so on, used to draw
    • drawTextBlob

      public final void drawTextBlob(TextBlob blob, float originX, float originY, @Nonnull Paint paint)
      Draws TextBlob blob at (x, y), using the current matrix, clip and specified paint.

      blob contains glyphs, their positions, and Font.

      Elements of paint: anti-alias, Blender, color including alpha, ColorFilter, Paint dither, PathEffect, Shader, and Paint style; apply to blob. If Paint contains stroke: Paint miter limit, Cap, Join, and Paint stroke width; apply to Path created from blob.

      Parameters:
      blob - glyphs, positions, and their paints' text size, typeface, and so on
      originX - horizontal offset applied to blob
      originY - vertical offset applied to blob
      paint - blend, color, stroking, and so on, used to draw
    • drawVertices

      public final void drawVertices(Vertices vertices, @SharedPtr @SharedPtr Blender blender, Paint paint)
      Draws the vertices, a triangle mesh, using current clip and matrix. If paint contains a Shader and vertices does not contain texCoords, the shader is mapped using the vertices' positions.

      Blender is ignored if vertices does not have colors. Otherwise, it combines - the Shader if Paint contains Shader - or the solid Paint color if Paint does not contain Shader as the src of the blend and the interpolated vertex colors as the dst.

      PathEffect, and antialiasing on Paint are ignored.

      Parameters:
      vertices - triangle mesh to draw
      blender - combines vertices' colors with Shader if present or Paint opaque color if not. Ignored if the vertices do not contain color.
      paint - specifies the Shader, used as Vertices texture, and ColorFilter.
    • isClipEmpty

      public boolean isClipEmpty()
      Returns true if clip is empty; that is, nothing will draw.

      May do work when called; it should not be called more often than needed. However, once called, subsequent calls perform no work until clip changes.

      Returns:
      true if clip is empty
    • isClipRect

      public boolean isClipRect()
      Returns true if clip is a Rect and not empty. Returns false if the clip is empty, or if it is complex.
      Returns:
      true if clip is a Rect and not empty
    • getLocalToDevice

      public final void getLocalToDevice(@Nonnull Matrix4 storage)
      Returns the current transform from local coordinates to the 'device', which for most purposes means pixels.
      Parameters:
      storage - transformation from local coordinates to device / pixels.
    • getLocalToDevice

      public final void getLocalToDevice(@Nonnull Matrix storage)
      Returns the current transform from local coordinates to the 'device', which for most purposes means pixels. Discards the 3rd row and column in the matrix, so be warned.
      Parameters:
      storage - transformation from local coordinates to device / pixels.
    • close

      public void close()
      Draws saved layers, if any. Frees up resources used by Canvas.
      Specified by:
      close in interface AutoCloseable
    • onGetImageInfo

      @Nonnull protected ImageInfo onGetImageInfo()
    • onNewSurface

      @Nullable @SharedPtr protected @SharedPtr Surface onNewSurface(ImageInfo info)
    • getRootDevice

      @RawPtr protected @RawPtr Device getRootDevice()
    • willSave

      protected void willSave()
    • getSaveLayerStrategy

      protected int getSaveLayerStrategy(@Nullable Rect2f bounds, @Nullable Paint paint, @Nullable ImageFilter backdrop, int saveLayerFlags)
    • willRestore

      protected void willRestore()
    • didRestore

      protected void didRestore()
    • didTranslate

      protected void didTranslate(float dx, float dy, float dz)
    • didScale

      protected void didScale(float sx, float sy, float sz)
    • didConcat

      protected void didConcat(Matrix4c matrix)
    • didSetMatrix

      protected void didSetMatrix(Matrix4c matrix)
    • onDiscard

      protected void onDiscard()
    • onDrawPaint

      protected void onDrawPaint(Paint paint)
    • onDrawPoints

      protected void onDrawPoints(int mode, float[] pts, int offset, int count, Paint paint)
    • onDrawLine

      protected void onDrawLine(float x0, float y0, float x1, float y1, int cap, float width, Paint paint)
    • onDrawRect

      protected void onDrawRect(Rect2fc r, Paint paint)
    • onDrawRoundRect

      protected void onDrawRoundRect(RoundRect rr, Paint paint)
    • onDrawCircle

      protected void onDrawCircle(float cx, float cy, float radius, Paint paint)
    • onDrawArc

      protected void onDrawArc(float cx, float cy, float radius, float startAngle, float sweepAngle, int cap, float width, Paint paint)
    • onDrawPie

      protected void onDrawPie(float cx, float cy, float radius, float startAngle, float sweepAngle, Paint paint)
    • onDrawChord

      protected void onDrawChord(float cx, float cy, float radius, float startAngle, float sweepAngle, Paint paint)
    • onDrawImageRect

      protected void onDrawImageRect(@RawPtr @RawPtr Image image, Rect2fc src, Rect2fc dst, SamplingOptions sampling, Paint paint, int constraint)
    • onDrawTextBlob

      protected void onDrawTextBlob(TextBlob blob, float originX, float originY, Paint paint)
    • onDrawGlyphRunList

      protected void onDrawGlyphRunList(GlyphRunList glyphRunList, Paint paint)
    • onDrawVertices

      protected void onDrawVertices(Vertices vertices, @SharedPtr @SharedPtr Blender blender, Paint paint)
    • onClipRect

      protected void onClipRect(Rect2fc rect, int clipOp, boolean doAA)