/* * Copyright 2006 The Android Open Source Project * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file.
*/
namespace sktext { class GlyphRunBuilder; class GlyphRunList;
}
class AutoLayerForImageFilter; class GrRecordingContext;
class SkBitmap; class SkBlender; class SkColorSpace; class SkData; class SkDevice; class SkDrawable; class SkFont; class SkImage; class SkMesh; class SkPaintFilterCanvas; class SkPath; class SkPicture; class SkPixmap; class SkRRect; class SkRegion; class SkShader; class SkSpecialImage; class SkSurface; class SkSurface_Base; class SkTextBlob; class SkVertices; struct SkDrawShadowRec; struct SkRSXform;
template<typename E> class SkEnumBitMask;
namespace skgpu::graphite { class Recorder; } namespace sktext::gpu { class Slug; } namespace SkRecords { class Draw; } namespace skiatest { template <typename Key> class TestCanvas;// IWYU pragma: keep
}
/** \class SkCanvas SkCanvas provides an interface for drawing, and how the drawing is clipped and transformed. SkCanvas contains a stack of SkMatrix and clip values.
SkCanvas and SkPaint together provide the state to draw into SkSurface or SkDevice. Each SkCanvas draw call transforms the geometry of the object by the concatenation of all SkMatrix values in the stack. The transformed geometry is clipped by the intersection of all of clip values in the stack. The SkCanvas draw calls use SkPaint to supply drawing state such as color, SkTypeface, text size, stroke width, SkShader and so on.
To draw to a pixel-based destination, create raster surface or GPU surface. Request SkCanvas from SkSurface to obtain the interface to draw. SkCanvas generated by raster surface draws to memory visible to the CPU. SkCanvas generated by GPU surface uses Vulkan or OpenGL to draw to the GPU.
To draw to a document, obtain SkCanvas from SVG canvas, document PDF, or SkPictureRecorder. SkDocument based SkCanvas and other SkCanvas subclasses reference SkDevice describing the destination.
SkCanvas can be constructed to draw to SkBitmap without first creating raster surface. This approach may be deprecated in the future.
*/ class SK_API SkCanvas { public:
/** Allocates raster SkCanvas that will draw directly into pixels.
SkCanvas is returned if all parameters are valid. Valid parameters include: info dimensions are zero or positive; info contains SkColorType and SkAlphaType supported by raster surface; pixels is not nullptr; rowBytes is zero or large enough to contain info width pixels of SkColorType.
Pass zero for rowBytes to compute rowBytes from info width and size of pixel. If rowBytes is greater than zero, it must be equal to or greater than info width times bytes required for SkColorType.
Pixel buffer size should be info height times computed rowBytes. Pixels are not initialized. To access pixels after drawing, call flush() or peekPixels().
@param info width, height, SkColorType, SkAlphaType, SkColorSpace, of raster surface; width, or height, or both, may be zero @param pixels pointer to destination pixels buffer @param rowBytes interval from one SkSurface row to the next, or zero @param props LCD striping orientation and setting for device independent fonts; may be nullptr @return SkCanvas if all parameters are valid; otherwise, nullptr
*/ static std::unique_ptr<SkCanvas> MakeRasterDirect(const SkImageInfo& info, void* pixels,
size_t rowBytes, const SkSurfaceProps* props = nullptr);
/** Allocates raster SkCanvas specified by inline image specification. Subsequent SkCanvas calls draw into pixels. SkColorType is set to kN32_SkColorType. SkAlphaType is set to kPremul_SkAlphaType. To access pixels after drawing, call flush() or peekPixels().
SkCanvas is returned if all parameters are valid. Valid parameters include: width and height are zero or positive; pixels is not nullptr; rowBytes is zero or large enough to contain width pixels of kN32_SkColorType.
Pass zero for rowBytes to compute rowBytes from width and size of pixel. If rowBytes is greater than zero, it must be equal to or greater than width times bytes required for SkColorType.
Pixel buffer size should be height times rowBytes.
@param width pixel column count on raster surface created; must be zero or greater @param height pixel row count on raster surface created; must be zero or greater @param pixels pointer to destination pixels buffer; buffer size should be height times rowBytes @param rowBytes interval from one SkSurface row to the next, or zero @return SkCanvas if all parameters are valid; otherwise, nullptr
*/ static std::unique_ptr<SkCanvas> MakeRasterDirectN32(int width, int height, SkPMColor* pixels,
size_t rowBytes) { return MakeRasterDirect(SkImageInfo::MakeN32Premul(width, height), pixels, rowBytes);
}
/** Creates an empty SkCanvas with no backing device or pixels, with a width and height of zero.
/** Creates SkCanvas of the specified dimensions without a SkSurface. Used by subclasses with custom implementations for draw member functions.
If props equals nullptr, SkSurfaceProps are created with SkSurfaceProps::InitType settings, which choose the pixel striping 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.
@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 SkCanvas placeholder with dimensions
@param bitmap specifies a bitmap for the canvas to draw into @param behavior specializes this constructor; value is unused @return SkCanvas that can be used to draw into bitmap
*/
SkCanvas(const SkBitmap& bitmap, ColorBehavior behavior); #endif
/** Constructs a canvas that draws into bitmap. Use props to match the device characteristics, like LCD striping.
bitmap is copied so that subsequently editing bitmap will not affect constructed SkCanvas.
@param bitmap width, height, SkColorType, SkAlphaType, and pixel storage of raster surface @param props order and orientation of RGB striping; and whether to use device independent fonts @return SkCanvas that can be used to draw into bitmap
/** Returns SkImageInfo for SkCanvas. If SkCanvas is not associated with raster surface or GPU surface, returned SkColorType is set to kUnknown_SkColorType.
/** Copies SkSurfaceProps, if SkCanvas is associated with raster surface or GPU surface, and returns true. Otherwise, returns false and leave props unchanged.
@param props storage for writable SkSurfaceProps @return true if SkSurfaceProps was copied
DEPRECATED: Replace usage with getBaseProps() or getTopProps()
/** Returns the SkSurfaceProps associated with the canvas (i.e., at the base of the layer stack).
@return base SkSurfaceProps
*/
SkSurfaceProps getBaseProps() const;
/** Returns the SkSurfaceProps associated with the canvas that are currently active (i.e., at the top of the layer stack). This can differ from getBaseProps depending on the flags passed to saveLayer (see SaveLayerFlagsSet).
@return SkSurfaceProps active in the current/top layer
*/
SkSurfaceProps getTopProps() const;
/** 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).
/** Creates SkSurface matching info and props, and associates it with SkCanvas. Returns nullptr if no match found.
If props is nullptr, matches SkSurfaceProps in SkCanvas. If props is nullptr and SkCanvas does not have SkSurfaceProps, creates SkSurface with default SkSurfaceProps.
@param info width, height, SkColorType, SkAlphaType, and SkColorSpace @param props SkSurfaceProps to match; may be nullptr to match SkCanvas @return SkSurface matching info and props, or nullptr if no match is available
/** Sometimes a canvas is owned by a surface. If it is, getSurface() will return a bare * pointer to that surface, else this will return nullptr.
*/
SkSurface* getSurface() const;
/** Returns the pixel base address, SkImageInfo, rowBytes, and origin if the pixels can be read directly. The returned address is only valid while SkCanvas is in scope and unchanged. Any SkCanvas call or SkSurface call may invalidate the returned address and other returned values.
If pixels are inaccessible, info, rowBytes, and origin are unchanged.
@param info storage for writable pixels' SkImageInfo; may be nullptr @param rowBytes storage for writable pixels' row bytes; may be nullptr @param origin storage for SkCanvas top layer origin, its top-left corner; may be nullptr @return address of pixels, or nullptr if inaccessible
/** Returns custom context that tracks the SkMatrix and clip.
Use SkRasterHandleAllocator to blend Skia drawing with custom drawing, typically performed by the host platform user interface. The custom context returned is generated by SkRasterHandleAllocator::MakeCanvas, which creates a custom canvas with raster storage for the drawing destination.
/** Returns true if SkCanvas has direct access to its pixels.
Pixels are readable when SkDevice is raster. Pixels are not readable when SkCanvas is returned from GPU surface, returned by SkDocument::beginPage, returned by SkPictureRecorder::beginRecording, or SkCanvas is the base of a utility class like DebugCanvas.
pixmap is valid only while SkCanvas is in scope and unchanged. Any SkCanvas or SkSurface call may invalidate the pixmap values.
@param pixmap storage for pixel state if pixels are readable; otherwise, ignored @return true if SkCanvas has direct access to pixels
/** Copies SkRect of pixels from SkCanvas into dstPixels. SkMatrix and clip are ignored.
Source SkRect corners are (srcX, srcY) and (imageInfo().width(), imageInfo().height()). Destination SkRect corners are (0, 0) and (dstInfo.width(), dstInfo.height()). Copies each readable pixel intersecting both rectangles, without scaling, converting to dstInfo.colorType() and dstInfo.alphaType() if required.
Pixels are readable when SkDevice is raster, or backed by a GPU. Pixels are not readable when SkCanvas is returned by SkDocument::beginPage, returned by SkPictureRecorder::beginRecording, or SkCanvas is the base of a utility class like DebugCanvas.
The destination pixel storage must be allocated by the caller.
Pixel values are converted only if SkColorType and SkAlphaType do not match. Only pixels within both source and destination rectangles are copied. dstPixels contents outside SkRect intersection are unchanged.
Pass negative values for srcX or srcY to offset pixels across or down destination.
Does not copy, and returns false if: - Source and destination rectangles do not intersect. - SkCanvas pixels could not be converted to dstInfo.colorType() or dstInfo.alphaType(). - SkCanvas pixels are not readable; for instance, SkCanvas is document-based. - dstRowBytes is too small to contain one row of pixels.
@param dstInfo width, height, SkColorType, and SkAlphaType of dstPixels @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 on x-axis; may be negative @param srcY offset into readable pixels on y-axis; may be negative @return true if pixels were copied
*/ bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, int srcX, int srcY);
/** Copies SkRect of pixels from SkCanvas into pixmap. SkMatrix and clip are ignored.
Source SkRect corners are (srcX, srcY) and (imageInfo().width(), imageInfo().height()). Destination SkRect corners are (0, 0) and (pixmap.width(), pixmap.height()). Copies each readable pixel intersecting both rectangles, without scaling, converting to pixmap.colorType() and pixmap.alphaType() if required.
Pixels are readable when SkDevice is raster, or backed by a GPU. Pixels are not readable when SkCanvas is returned by SkDocument::beginPage, returned by SkPictureRecorder::beginRecording, or SkCanvas is the base of a utility class like DebugCanvas.
Caller must allocate pixel storage in pixmap if needed.
Pixel values are converted only if SkColorType and SkAlphaType do not match. Only pixels within both source and destination SkRect are copied. pixmap pixels contents outside SkRect intersection are unchanged.
Pass negative values for srcX or srcY to offset pixels across or down pixmap.
Does not copy, and returns false if: - Source and destination rectangles do not intersect. - SkCanvas pixels could not be converted to pixmap.colorType() or pixmap.alphaType(). - SkCanvas pixels are not readable; for instance, SkCanvas is document-based. - SkPixmap pixels could not be allocated. - pixmap.rowBytes() is too small to contain one row of pixels.
@param pixmap storage for pixels copied from SkCanvas @param srcX offset into readable pixels on x-axis; may be negative @param srcY offset into readable pixels on y-axis; may be negative @return true if pixels were copied
/** Copies SkRect of pixels from SkCanvas into bitmap. SkMatrix and clip are ignored.
Source SkRect corners are (srcX, srcY) and (imageInfo().width(), imageInfo().height()). Destination SkRect corners are (0, 0) and (bitmap.width(), bitmap.height()). Copies each readable pixel intersecting both rectangles, without scaling, converting to bitmap.colorType() and bitmap.alphaType() if required.
Pixels are readable when SkDevice is raster, or backed by a GPU. Pixels are not readable when SkCanvas is returned by SkDocument::beginPage, returned by SkPictureRecorder::beginRecording, or SkCanvas is the base of a utility class like DebugCanvas.
Caller must allocate pixel storage in bitmap if needed.
SkBitmap values are converted only if SkColorType and SkAlphaType do not match. Only pixels within both source and destination rectangles are copied. SkBitmap pixels outside SkRect intersection are unchanged.
Pass negative values for srcX or srcY to offset pixels across or down bitmap.
Does not copy, and returns false if: - Source and destination rectangles do not intersect. - SkCanvas pixels could not be converted to bitmap.colorType() or bitmap.alphaType(). - SkCanvas pixels are not readable; for instance, SkCanvas is document-based. - bitmap pixels could not be allocated. - bitmap.rowBytes() is too small to contain one row of pixels.
@param bitmap storage for pixels copied from SkCanvas @param srcX offset into readable pixels on x-axis; may be negative @param srcY offset into readable pixels on y-axis; may be negative @return true if pixels were copied
/** Copies SkRect from pixels to SkCanvas. SkMatrix and clip are ignored. Source SkRect corners are (0, 0) and (info.width(), info.height()). Destination SkRect corners are (x, y) and (imageInfo().width(), imageInfo().height()).
Copies each readable pixel intersecting both rectangles, without scaling, converting to imageInfo().colorType() and imageInfo().alphaType() if required.
Pixels are writable when SkDevice is raster, or backed by a GPU. Pixels are not writable when SkCanvas is returned by SkDocument::beginPage, returned by SkPictureRecorder::beginRecording, or SkCanvas is the base of a utility class like DebugCanvas.
Pixel values are converted only if SkColorType and SkAlphaType do not match. Only pixels within both source and destination rectangles are copied. SkCanvas pixels outside SkRect intersection are unchanged.
Pass negative values for x or y to offset pixels to the left or above SkCanvas pixels.
Does not copy, and returns false if: - Source and destination rectangles do not intersect. - pixels could not be converted to SkCanvas imageInfo().colorType() or imageInfo().alphaType(). - SkCanvas pixels are not writable; for instance, SkCanvas is document-based. - rowBytes is too small to contain one row of pixels.
@param info width, height, SkColorType, and SkAlphaType of pixels @param pixels pixels to copy, of size info.height() times rowBytes, or larger @param rowBytes size of one row of pixels; info.width() times pixel size, or larger @param x offset into SkCanvas writable pixels on x-axis; may be negative @param y offset into SkCanvas writable pixels on y-axis; may be negative @return true if pixels were written to SkCanvas
/** Copies SkRect from pixels to SkCanvas. SkMatrix and clip are ignored. Source SkRect corners are (0, 0) and (bitmap.width(), bitmap.height()).
Destination SkRect corners are (x, y) and (imageInfo().width(), imageInfo().height()).
Copies each readable pixel intersecting both rectangles, without scaling, converting to imageInfo().colorType() and imageInfo().alphaType() if required.
Pixels are writable when SkDevice is raster, or backed by a GPU. Pixels are not writable when SkCanvas is returned by SkDocument::beginPage, returned by SkPictureRecorder::beginRecording, or SkCanvas is the base of a utility class like DebugCanvas.
Pixel values are converted only if SkColorType and SkAlphaType do not match. Only pixels within both source and destination rectangles are copied. SkCanvas pixels outside SkRect intersection are unchanged.
Pass negative values for x or y to offset pixels to the left or above SkCanvas pixels.
Does not copy, and returns false if: - Source and destination rectangles do not intersect. - bitmap does not have allocated pixels. - bitmap pixels could not be converted to SkCanvas imageInfo().colorType() or imageInfo().alphaType(). - SkCanvas pixels are not writable; for instance, SkCanvas is document based. - bitmap pixels are inaccessible; for instance, bitmap wraps a texture.
@param bitmap contains pixels copied to SkCanvas @param x offset into SkCanvas writable pixels on x-axis; may be negative @param y offset into SkCanvas writable pixels on y-axis; may be negative @return true if pixels were written to SkCanvas
/** Saves SkMatrix and clip. Calling restore() discards changes to SkMatrix and clip, restoring the SkMatrix and clip to their state when save() was called.
SkMatrix may be changed by translate(), scale(), rotate(), skew(), concat(), setMatrix(), and resetMatrix(). Clip may be changed by clipRect(), clipRRect(), clipPath(), clipRegion().
Saved SkCanvas state is put on a stack; multiple calls to save() should be balance by an equal number of calls to restore().
Call restoreToCount() with result to restore this and subsequent saves.
/** Saves SkMatrix and clip, and allocates a SkSurface for subsequent drawing. Calling restore() discards changes to SkMatrix and clip, and draws the SkSurface.
SkMatrix may be changed by translate(), scale(), rotate(), skew(), concat(), setMatrix(), and resetMatrix(). Clip may be changed by clipRect(), clipRRect(), clipPath(), clipRegion().
SkRect bounds suggests but does not define the SkSurface size. To clip drawing to a specific rectangle, use clipRect().
Optional SkPaint paint applies alpha, SkColorFilter, SkImageFilter, and SkBlendMode when restore() is called.
Call restoreToCount() with returned value to restore this and subsequent saves.
@param bounds hint to limit the size of the layer; may be nullptr @param paint graphics state for layer; may be nullptr @return depth of saved stack
/** Saves SkMatrix and clip, and allocates a SkSurface for subsequent drawing. Calling restore() discards changes to SkMatrix and clip, and draws the SkSurface.
SkMatrix may be changed by translate(), scale(), rotate(), skew(), concat(), setMatrix(), and resetMatrix(). Clip may be changed by clipRect(), clipRRect(), clipPath(), clipRegion().
SkRect bounds suggests but does not define the layer size. To clip drawing to a specific rectangle, use clipRect().
Optional SkPaint paint applies alpha, SkColorFilter, SkImageFilter, and SkBlendMode when restore() is called.
Call restoreToCount() with returned value to restore this and subsequent saves.
@param bounds hint to limit the size of layer; may be nullptr @param paint graphics state for layer; may be nullptr @return depth of saved stack
*/ int saveLayer(const SkRect& bounds, const SkPaint* paint) { return this->saveLayer(&bounds, paint);
}
/** Saves SkMatrix and clip, and allocates SkSurface for subsequent drawing.
Calling restore() discards changes to SkMatrix and clip, and blends layer with alpha opacity onto prior layer.
SkMatrix may be changed by translate(), scale(), rotate(), skew(), concat(), setMatrix(), and resetMatrix(). Clip may be changed by clipRect(), clipRRect(), clipPath(), clipRegion().
SkRect bounds suggests but does not define layer size. To clip drawing to a specific rectangle, use clipRect().
alpha of zero is fully transparent, 1.0f is fully opaque.
Call restoreToCount() with returned value to restore this and subsequent saves.
@param bounds hint to limit the size of layer; may be nullptr @param alpha opacity of layer @return depth of saved stack
example: https://fiddle.skia.org/c/@Canvas_saveLayerAlpha
*/ int saveLayerAlphaf(const SkRect* bounds, float alpha); // Helper that accepts an int between 0 and 255, and divides it by 255.0 int saveLayerAlpha(const SkRect* bounds, U8CPU alpha) { return this->saveLayerAlphaf(bounds, alpha * (1.0f / 255));
}
/** \enum SkCanvas::SaveLayerFlagsSet SaveLayerFlags provides options that may be used in any combination in SaveLayerRec, defining how layer allocated by saveLayer() operates. It may be set to zero, kPreserveLCDText_SaveLayerFlag, kInitWithPrevious_SaveLayerFlag, or both flags.
*/ enum SaveLayerFlagsSet {
kPreserveLCDText_SaveLayerFlag = 1 << 1,
kInitWithPrevious_SaveLayerFlag = 1 << 2, //!< initializes with previous contents // instead of matching previous layer's colortype, use F16
kF16ColorType = 1 << 4,
};
using SaveLayerFlags = uint32_t; using FilterSpan = SkSpan<sk_sp<SkImageFilter>>; static constexpr int kMaxFiltersPerLayer = 16;
/** \struct SkCanvas::SaveLayerRec SaveLayerRec contains the state used to create the layer.
*/ struct SaveLayerRec { /** Sets fBounds, fPaint, and fBackdrop to nullptr. Clears fSaveLayerFlags.
@return empty SaveLayerRec
*/
SaveLayerRec() {}
/** Sets fBounds, fPaint, and fSaveLayerFlags; sets fBackdrop to nullptr.
@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 @return SaveLayerRec with empty fBackdrop
*/
SaveLayerRec(const SkRect* bounds, const SkPaint* paint, SaveLayerFlags saveLayerFlags = 0)
: SaveLayerRec(bounds, paint, nullptr, nullptr, 1.f, SkTileMode::kClamp,
saveLayerFlags, /*filters=*/{}) {}
/** Sets fBounds, fPaint, fBackdrop, and fSaveLayerFlags.
@param bounds layer dimensions; may be nullptr @param paint applied to layer when overlaying prior layer; may be nullptr @param 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). If null, the new layer is initialized with transparent-black. @param saveLayerFlags SaveLayerRec options to modify layer @return SaveLayerRec fully specified
*/
SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop,
SaveLayerFlags saveLayerFlags)
: SaveLayerRec(bounds, paint, backdrop, nullptr, 1.f, SkTileMode::kClamp,
saveLayerFlags, /*filters=*/{}) {}
/** Sets fBounds, fBackdrop, fColorSpace, and fSaveLayerFlags.
@param bounds layer dimensions; may be nullptr @param paint applied to layer when overlaying prior layer; may be nullptr @param 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). If null, the new layer is initialized with transparent-black. @param colorSpace If not null, when the layer is restored, a color space conversion will be applied from this color space to the parent's color space. The restore paint and backdrop filters will be applied in this color space. If null, the new layer will inherit the color space from its parent. @param saveLayerFlags SaveLayerRec options to modify layer @return SaveLayerRec fully specified
*/
SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop, const SkColorSpace* colorSpace, SaveLayerFlags saveLayerFlags)
: SaveLayerRec(bounds, paint, backdrop, colorSpace, 1.f, SkTileMode::kClamp,
saveLayerFlags, /*filters=*/{}) {}
/** Sets fBounds, fBackdrop, fBackdropTileMode, fColorSpace, and fSaveLayerFlags.
@param bounds layer dimensions; may be nullptr @param paint applied to layer when overlaying prior layer; may be nullptr @param 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). If null, the new layer is initialized with transparent-black. @param backdropTileMode If the 'backdrop' is not null, or 'saveLayerFlags' has kInitWithPrevious set, this tile mode is used when the new layer would read outside the backdrop image's available content. @param colorSpace If not null, when the layer is restored, a color space conversion will be applied from this color space to the parent's color space. The restore paint and backdrop filters will be applied in this color space. If null, the new layer will inherit the color space from its parent. @param saveLayerFlags SaveLayerRec options to modify layer @return SaveLayerRec fully specified
*/
SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop,
SkTileMode backdropTileMode, const SkColorSpace* colorSpace,
SaveLayerFlags saveLayerFlags)
: SaveLayerRec(bounds, paint, backdrop, colorSpace, 1.f, backdropTileMode,
saveLayerFlags, /*filters=*/{}) {}
/** * If not null, this triggers the same initialization behavior as setting * kInitWithPrevious_SaveLayerFlag on fSaveLayerFlags: the current layer is copied into * the new layer, rather than initializing the new layer with transparent-black. * This is then filtered by fBackdrop (respecting the current clip).
*/ const SkImageFilter* fBackdrop = nullptr;
/** * If the layer is initialized with prior content (and/or with a backdrop filter) and this * would require sampling outside of the available backdrop, this is the tilemode applied * to the boundary of the prior layer's image.
*/
SkTileMode fBackdropTileMode = SkTileMode::kClamp;
/** * If not null, this triggers a color space conversion when the layer is restored. It * will be as if the layer's contents are drawn in this color space. Filters from * fBackdrop and fPaint will be applied in this color space.
*/ const SkColorSpace* fColorSpace = nullptr;
SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop, const SkColorSpace* colorSpace,
SkScalar backdropScale,
SkTileMode backdropTileMode,
SaveLayerFlags saveLayerFlags,
FilterSpan filters)
: fBounds(bounds)
, fPaint(paint)
, fFilters(filters)
, fBackdrop(backdrop)
, fBackdropTileMode(backdropTileMode)
, fColorSpace(colorSpace)
, fSaveLayerFlags(saveLayerFlags)
, fExperimentalBackdropScale(backdropScale) { // We only allow the paint's image filter or the side-car list of filters -- not both.
SkASSERT(fFilters.empty() || !paint || !paint->getImageFilter()); // To keep things reasonable (during deserialization), we limit filter list size.
SkASSERT(fFilters.size() <= kMaxFiltersPerLayer);
}
// Relative scale factor that the image content used to initialize the layer when the // kInitFromPrevious flag or a backdrop filter is used.
SkScalar fExperimentalBackdropScale = 1.f;
};
/** Saves SkMatrix and clip, and allocates SkSurface for subsequent drawing.
Calling restore() discards changes to SkMatrix and clip, and blends SkSurface with alpha opacity onto the prior layer.
SkMatrix may be changed by translate(), scale(), rotate(), skew(), concat(), setMatrix(), and resetMatrix(). Clip may be changed by clipRect(), clipRRect(), clipPath(), clipRegion().
SaveLayerRec contains the state used to create the layer.
Call restoreToCount() with returned value to restore this and subsequent saves.
@param layerRec layer state @return depth of save state stack before this call was made.
/** Returns the number of saved states, each containing: SkMatrix and clip. Equals the number of save() calls less the number of restore() calls plus one. The save count of a new canvas is one.
/** Rotates SkMatrix by degrees about a point at (px, py). Positive degrees rotates clockwise.
Mathematically, constructs a rotation matrix; premultiplies the rotation matrix by a translation matrix; then replaces SkMatrix with the resulting matrix premultiplied with SkMatrix.
This has the effect of rotating the drawing about a given point before transforming the result with SkMatrix.
@param degrees amount to rotate, in degrees @param px x-axis value of the point to rotate about @param py y-axis value of the point to rotate about
/** Skews SkMatrix by sx on the x-axis and sy on the y-axis. A positive value of sx skews the drawing right as y-axis values increase; a positive value of sy skews the drawing down as x-axis values increase.
Mathematically, replaces SkMatrix with a skew matrix premultiplied with SkMatrix.
This has the effect of skewing the drawing by (sx, sy) before transforming the result with SkMatrix.
@param sx amount to skew on x-axis @param sy amount to skew on y-axis
/** Replaces clip with the intersection or difference of clip and rect, with an aliased or anti-aliased clip edge. rect is transformed by SkMatrix before it is combined with clip.
@param rect SkRect to combine with clip @param op SkClipOp to apply to clip @param doAntiAlias true if clip is to be anti-aliased
/** Replaces clip with the intersection or difference of clip and rect. Resulting clip is aliased; pixels are fully contained by the clip. rect is transformed by SkMatrix before it is combined with clip.
@param rect SkRect to combine with clip @param op SkClipOp to apply to clip
*/ void clipRect(const SkRect& rect, SkClipOp op) {
this->clipRect(rect, op, false);
}
/** Replaces clip with the intersection of clip and rect. Resulting clip is aliased; pixels are fully contained by the clip. rect is transformed by SkMatrix before it is combined with clip.
@param rect SkRect to combine with clip @param doAntiAlias true if clip is to be anti-aliased
*/ void clipRect(const SkRect& rect, bool doAntiAlias = false) {
this->clipRect(rect, SkClipOp::kIntersect, doAntiAlias);
}
/** Sets the maximum clip rectangle, which can be set by clipRect(), clipRRect() and clipPath() and intersect the current clip with the specified rect. The maximum clip affects only future clipping operations; it is not retroactive. The clip restriction is not recorded in pictures.
Pass an empty rect to disable maximum clip. This private API is for use by Android framework only.
DEPRECATED: Replace usage with SkAndroidFrameworkUtils::replaceClip()
@param rect maximum allowed clip in device coordinates
*/ void androidFramework_setDeviceClipRestriction(const SkIRect& rect);
/** Replaces clip with the intersection or difference of clip and rrect, with an aliased or anti-aliased clip edge. rrect is transformed by SkMatrix before it is combined with clip.
@param rrect SkRRect to combine with clip @param op SkClipOp to apply to clip @param doAntiAlias true if clip is to be anti-aliased
/** Replaces clip with the intersection or difference of clip and rrect. Resulting clip is aliased; pixels are fully contained by the clip. rrect is transformed by SkMatrix before it is combined with clip.
@param rrect SkRRect to combine with clip @param op SkClipOp to apply to clip
*/ void clipRRect(const SkRRect& rrect, SkClipOp op) {
this->clipRRect(rrect, op, false);
}
/** Replaces clip with the intersection of clip and rrect, with an aliased or anti-aliased clip edge. rrect is transformed by SkMatrix before it is combined with clip.
@param rrect SkRRect to combine with clip @param doAntiAlias true if clip is to be anti-aliased
*/ void clipRRect(const SkRRect& rrect, bool doAntiAlias = false) {
this->clipRRect(rrect, SkClipOp::kIntersect, doAntiAlias);
}
/** Replaces clip with the intersection or difference of clip and path, with an aliased or anti-aliased clip edge. SkPath::FillType 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 SkMatrix before it is combined with clip.
@param path SkPath to combine with clip @param op SkClipOp to apply to clip @param doAntiAlias true if clip is to be anti-aliased
/** Replaces clip with the intersection or difference of clip and path. Resulting clip is aliased; pixels are fully contained by the clip. SkPath::FillType 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 SkMatrix before it is combined with clip.
@param path SkPath to combine with clip @param op SkClipOp to apply to clip
*/ void clipPath(const SkPath& path, SkClipOp op) {
this->clipPath(path, op, false);
}
/** Replaces clip with the intersection of clip and path. Resulting clip is aliased; pixels are fully contained by the clip. SkPath::FillType 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 SkMatrix before it is combined with clip.
@param path SkPath to combine with clip @param doAntiAlias true if clip is to be anti-aliased
*/ void clipPath(const SkPath& path, bool doAntiAlias = false) {
this->clipPath(path, SkClipOp::kIntersect, doAntiAlias);
}
/** Replaces clip with the intersection or difference of clip and SkRegion deviceRgn. Resulting clip is aliased; pixels are fully contained by the clip. deviceRgn is unaffected by SkMatrix.
@param deviceRgn SkRegion to combine with clip @param op SkClipOp to apply to clip
/** Returns true if SkRect rect, transformed by SkMatrix, 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.
@param rect SkRect to compare with clip @return true if rect, transformed by SkMatrix, does not intersect clip
/** Returns true if path, transformed by SkMatrix, 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.
@param path SkPath to compare with clip @return true if path, transformed by SkMatrix, does not intersect clip
/** Returns bounds of clip, transformed by inverse of SkMatrix. If clip is empty, return false, and set bounds to SkRect::MakeEmpty, where all SkRect sides equal zero.
bounds is outset by one to account for partial pixel coverage if clip is anti-aliased.
@param bounds SkRect of clip in local coordinates @return true if clip bounds is not empty
*/ bool getLocalClipBounds(SkRect* bounds) const {
*bounds = this->getLocalClipBounds(); return !bounds->isEmpty();
}
/** Returns SkIRect bounds of clip, unaffected by SkMatrix. If clip is empty, return SkRect::MakeEmpty, where all SkRect sides equal zero.
Unlike getLocalClipBounds(), returned SkIRect is not outset.
/** Returns SkIRect bounds of clip, unaffected by SkMatrix. If clip is empty, return false, and set bounds to SkRect::MakeEmpty, where all SkRect sides equal zero.
Unlike getLocalClipBounds(), bounds is not outset.
@param bounds SkRect of clip in device coordinates @return true if clip bounds is not empty
*/ bool getDeviceClipBounds(SkIRect* bounds) const {
*bounds = this->getDeviceClipBounds(); return !bounds->isEmpty();
}
/** Fills clip with color color. mode determines how ARGB is combined with destination.
@param color unpremultiplied ARGB @param mode SkBlendMode used to combine source color and destination
/** Fills clip with color color. mode determines how ARGB is combined with destination.
@param color SkColor4f representing unpremultiplied color. @param mode SkBlendMode used to combine source color and destination
*/ void drawColor(const SkColor4f& color, SkBlendMode mode = SkBlendMode::kSrcOver);
/** Fills clip with color color using SkBlendMode::kSrc. This has the effect of replacing all pixels contained by clip with color.
/** Makes SkCanvas contents undefined. Subsequent calls that read SkCanvas pixels, such as drawing with SkBlendMode, return undefined results. discard() does not change clip or SkMatrix.
discard() may do nothing, depending on the implementation of SkSurface or SkDevice that created SkCanvas.
discard() allows optimized performance on subsequent draws by removing cached data associated with SkSurface or SkDevice. It is not necessary to call discard() once done with SkCanvas; any cached data is deleted when owning SkSurface or SkDevice is deleted.
*/ void discard() { this->onDiscard(); }
/** Fills clip with SkPaint paint. SkPaint components, SkShader, SkColorFilter, SkImageFilter, and SkBlendMode affect drawing; SkMaskFilter and SkPathEffect in paint are ignored.
/** \enum SkCanvas::PointMode Selects if an array of points are drawn as discrete points, as lines, or as an open polygon.
*/ enum PointMode {
kPoints_PointMode, //!< draw each point separately
kLines_PointMode, //!< draw each pair of points as a line segment
kPolygon_PointMode, //!< draw the array of points as a open polygon
};
/** Draws pts using clip, SkMatrix and SkPaint paint. count is the number of points; if count is less than one, has no effect. mode may be one of: kPoints_PointMode, kLines_PointMode, or kPolygon_PointMode.
If mode is kPoints_PointMode, the shape of point drawn depends on paint SkPaint::Cap. If paint is set to SkPaint::kRound_Cap, each point draws a circle of diameter SkPaint stroke width. If paint is set to SkPaint::kSquare_Cap or SkPaint::kButt_Cap, each point draws a square of width and height SkPaint stroke width.
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, the final point is ignored.
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 SkPaint::Cap and SkPaint stroke width. SkPaint::Style is ignored, as if were set to SkPaint::kStroke_Style.
Always draws each element one at a time; is not affected by SkPaint::Join, and unlike drawPath(), does not create a mask from all points and lines before drawing.
@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
/** Draws point at (x, y) using clip, SkMatrix and SkPaint paint.
The shape of point drawn depends on paint SkPaint::Cap. If paint is set to SkPaint::kRound_Cap, draw a circle of diameter SkPaint stroke width. If paint is set to SkPaint::kSquare_Cap or SkPaint::kButt_Cap, draw a square of width and height SkPaint stroke width. SkPaint::Style is ignored, as if were set to SkPaint::kStroke_Style.
@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
/** Draws point p using clip, SkMatrix and SkPaint paint.
The shape of point drawn depends on paint SkPaint::Cap. If paint is set to SkPaint::kRound_Cap, draw a circle of diameter SkPaint stroke width. If paint is set to SkPaint::kSquare_Cap or SkPaint::kButt_Cap, draw a square of width and height SkPaint stroke width. SkPaint::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
*/ void drawPoint(SkPoint p, const SkPaint& paint) {
this->drawPoint(p.x(), p.y(), paint);
}
/** Draws line segment from (x0, y0) to (x1, y1) using clip, SkMatrix, and SkPaint paint. In paint: SkPaint stroke width describes the line thickness; SkPaint::Cap draws the end rounded or square; SkPaint::Style is ignored, as if were set to SkPaint::kStroke_Style.
@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
/** Draws line segment from p0 to p1 using clip, SkMatrix, and SkPaint paint. In paint: SkPaint stroke width describes the line thickness; SkPaint::Cap draws the end rounded or square; SkPaint::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
*/ void drawLine(SkPoint p0, SkPoint p1, const SkPaint& paint) {
this->drawLine(p0.x(), p0.y(), p1.x(), p1.y(), paint);
}
/** Draws SkRect rect using clip, SkMatrix, and SkPaint paint. In paint: SkPaint::Style determines if rectangle is stroked or filled; if stroked, SkPaint stroke width describes the line thickness, and SkPaint::Join draws the corners rounded or square.
@param rect rectangle to draw @param paint stroke or fill, blend, color, and so on, used to draw
/** Draws SkIRect rect using clip, SkMatrix, and SkPaint paint. In paint: SkPaint::Style determines if rectangle is stroked or filled; if stroked, SkPaint stroke width describes the line thickness, and SkPaint::Join draws the corners rounded or square.
@param rect rectangle to draw @param paint stroke or fill, blend, color, and so on, used to draw
*/ void drawIRect(const SkIRect& rect, const SkPaint& paint) {
SkRect r;
r.set(rect); // promotes the ints to scalars
this->drawRect(r, paint);
}
/** Draws SkRegion region using clip, SkMatrix, and SkPaint paint. In paint: SkPaint::Style determines if rectangle is stroked or filled; if stroked, SkPaint stroke width describes the line thickness, and SkPaint::Join draws the corners rounded or square.
@param region region to draw @param paint SkPaint stroke or fill, blend, color, and so on, used to draw
/** Draws oval oval using clip, SkMatrix, and SkPaint. In paint: SkPaint::Style determines if oval is stroked or filled; if stroked, SkPaint stroke width describes the line thickness.
@param oval SkRect bounds of oval @param paint SkPaint stroke or fill, blend, color, and so on, used to draw
/** Draws SkRRect rrect using clip, SkMatrix, and SkPaint paint. In paint: SkPaint::Style determines if rrect is stroked or filled; if stroked, SkPaint stroke width describes the line thickness.
rrect may represent a rectangle, circle, oval, uniformly rounded rectangle, or may have any combination of positive non-square radii for the four corners.
@param rrect SkRRect with up to eight corner radii to draw @param paint SkPaint stroke or fill, blend, color, and so on, used to draw
/** Draws SkRRect outer and inner using clip, SkMatrix, and SkPaint paint. outer must contain inner or the drawing is undefined. In paint: SkPaint::Style determines if SkRRect is stroked or filled; if stroked, SkPaint stroke width describes the line thickness. If stroked and SkRRect corner has zero length radii, SkPaint::Join can draw corners rounded or square.
GPU-backed platforms optimize drawing when both outer and inner are concave and outer contains inner. These platforms may not be able to draw SkPath built with identical data as fast.
@param outer SkRRect outer bounds to draw @param inner SkRRect inner bounds to draw @param paint SkPaint stroke or fill, blend, color, and so on, used to draw
/** Draws circle at (cx, cy) with radius using clip, SkMatrix, and SkPaint paint. If radius is zero or less, nothing is drawn. In paint: SkPaint::Style determines if circle is stroked or filled; if stroked, SkPaint stroke width describes the line thickness.
@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 SkPaint stroke or fill, blend, color, and so on, used to draw
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.