Surfaces
Methods
- static Surfaces.MakeFromBackendRenderTarget(context: skia.GrRecordingContext, backendRenderTarget: skia.GrBackendRenderTarget, origin: skia.GrSurfaceOrigin, colorType: skia.ColorType, colorSpace: skia.ColorSpace, surfaceProps: skia.SurfaceProps = None) skia.Surface
Wraps a GPU-backed buffer into
Surface.Caller must ensure backendRenderTarget is valid for the lifetime of returned
Surface.Surfaceis returned if all parameters are valid. backendRenderTarget is valid if its pixel configuration agrees with colorSpace and context; for instance, if backendRenderTarget has an sRGB configuration, then context must support sRGB, and colorSpace must be present. Further, backendRenderTarget width and height must not exceed context capabilities, and the context must be able to support back-end render targets.Upon success releaseProc is called when it is safe to delete the render target in the backend API (accounting only for use of the render target by this surface). If
Surfacecreation fails releaseProc is called before this function returns.If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr.
- Parameters:
context – GPU context
backendRenderTarget – GPU intermediate memory buffer
colorSpace – range of colors
surfaceProps – LCD striping orientation and setting for device independent fonts; may be nullptr
- Returns:
Surfaceif all parameters are valid; otherwise, nullptr
- static Surfaces.MakeFromBackendTexture(context: skia.GrRecordingContext, backendTexture: skia.GrBackendTexture, origin: skia.GrSurfaceOrigin, sampleCnt: int, colorType: skia.ColorType, colorSpace: skia.ColorSpace, surfaceProps: skia.SurfaceProps = None) skia.Surface
Wraps a GPU-backed texture into
Surface. Caller must ensure backendRenderTarget is valid for the lifetime of returnedSurface. If sampleCnt greater than zero, creates an intermediate MSAASurfacewhich is used for drawing backendTexture.Surfaceis returned if all parameters are valid. backendTexture is valid if its pixel configuration agrees with colorSpace and context; for instance, if backendTexture has an sRGB configuration, then context must support sRGB, and colorSpace must be present. Further, backendTexture width and height must not exceed context capabilities, and the context must be able to support back-end textures.Upon success textureReleaseProc is called when it is safe to delete the texture in the backend API (accounting only for use of the texture by this surface). If
Surfacecreation fails textureReleaseProc is called before this function returns.If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr.
- Context:
GPU context
- BackendTexture:
texture residing on GPU
- SampleCnt:
samples per pixel, or 0 to disable full scene anti-aliasing
- ColorSpace:
range of colors; may be nullptr
- SurfaceProps:
LCD striping orientation and setting for device independent fonts; may be nullptr
- Returns:
Surfaceif all parameters are valid; otherwise, nullptr
- static Surfaces.MakeNull(width: int, height: int) skia.Surface
Returns
Surfacewithout backing pixels.Drawing to
Canvasreturned fromSurfacehas no effect. Calling makeImageSnapshot() on returnedSurfacereturns nullptr.- Parameters:
width (int) – one or greater
height (int) – one or greater
- Returns:
Surfaceif width and height are positive; otherwise, nullptr
- static Surfaces.MakeRaster(imageInfo: skia.ImageInfo, rowBytes: int = 0, surfaceProps: skia.SurfaceProps = None) skia.Surface
Allocates raster
Surface.Canvasreturned bySurfacedraws directly into pixels. Allocates and zeroes pixel memory. Pixel memory size is imageInfo.height() times rowBytes, or times imageInfo.minRowBytes() if rowBytes is zero. Pixel memory is deleted whenSurfaceis deleted.Surfaceis returned if all parameters are valid. Valid parameters include: info dimensions are greater than zero; info containsColorTypeandAlphaTypesupported by raster surface; rowBytes is large enough to contain info width pixels ofColorType, or is zero.If rowBytes is zero, a suitable value will be chosen internally.
- ImageInfo:
width, height,
ColorType,AlphaType,ColorSpace, of raster surface; width and height must be greater than zero- RowBytes:
interval from one
Surfacerow to the next; may be zero- Skia.SurfaceProps surfaceProps:
LCD striping orientation and setting for device independent fonts; may be nullptr
- Returns:
Surfaceif all parameters are valid; otherwise, nullptr
- static Surfaces.MakeRasterDirect(info: skia.ImageInfo, pixels: Buffer, rowBytes: int = 0, surfaceProps: skia.SurfaceProps = None) skia.Surface
Allocates raster
Surface.Canvasreturned bySurfacedraws directly into pixels.Surfaceis returned if all parameters are valid. Valid parameters include: info dimensions are greater than zero; info containsColorTypeandAlphaTypesupported by raster surface; pixels is not nullptr; rowBytes is large enough to contain info width pixels ofColorType.Pixel buffer size should be info height times computed rowBytes. Pixels are not initialized. To access pixels after drawing, peekPixels() or readPixels().
- Parameters:
imageInfo (skia.ImageInfo) – width, height,
ColorType,AlphaType,ColorSpace, of raster surface; width and height must be greater than zeropixels (Union[bytes,bytearray,memoryview]) – pointer to destination pixels buffer
rowBytes – interval from one
Surfacerow to the nextsurfaceProps – LCD striping orientation and setting for device independent fonts; may be nullptr
- Returns:
Surfaceif all parameters are valid; otherwise, nullptr
- static Surfaces.MakeRasterN32Premul(width: int, height: int, surfaceProps: skia.SurfaceProps = None) skia.Surface
Allocates raster
Surface.Canvasreturned bySurfacedraws directly into pixels. Allocates and zeroes pixel memory. Pixel memory size is height times width times four. Pixel memory is deleted whenSurfaceis deleted.Internally, sets
ImageInfoto width, height, native color type, andAlphaType.kPremul.Note that the
ImageInfonative color type might not be what you desire, if you intent to interact with other software expecting specific color type order. e.g. package wx’s wx.Bitmap.FromBufferRGBA. For that purpose, you need one of the otherSurfaceconstructors which takes an explicit appropriate matchingImageInfoinput, or one that takes an explicitColorTypeinput. You should check the output of surface.imageInfo().colorType() afterwards, in that usage.Surfaceis returned if width and height are greater than zero.Use to create
Surfacethat matchesPMColor, the native pixel arrangement on the platform.Surfacedrawn to output device skips converting its pixel format.- Parameters:
width (int) – pixel column count; must be greater than zero
height (int) – pixel row count; must be greater than zero
surfaceProps (skia.SurfaceProps) – LCD striping orientation and setting for device independent fonts; may be nullptr
- Returns:
Surfaceif all parameters are valid; otherwise, nullptr
- static Surfaces.MakeRenderTarget(*args, **kwargs)
Overloaded function.
MakeRenderTarget(context: skia.GrRecordingContext, budgeted: skia.Budgeted, imageInfo: skia.ImageInfo, sampleCount: int = 0, surfaceOrigin: skia.GrSurfaceOrigin = skia.GrSurfaceOrigin.kBottomLeft_GrSurfaceOrigin, surfaceProps: skia.SurfaceProps = None, shouldCreateWithMips: bool = False, isProtected: bool = False) -> skia.Surface
Returns
Surfaceon GPU indicated by context.Allocates memory for pixels, based on the width, height, and
ColorTypeinImageInfo. budgeted selects whether allocation for pixels is tracked by context. imageInfo describes the pixel format inColorType, and transparency inAlphaType, and color matching inColorSpace.sampleCount requests the number of samples per pixel. Pass zero to disable multi-sample anti-aliasing. The request is rounded up to the next supported count, or rounded down if it is larger than the maximum supported count.
surfaceOrigin pins either the top-left or the bottom-left corner to the origin.
shouldCreateWithMips hints that
Imagereturned by makeImageSnapshot() is mip map.If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr.
- param skia.GrContext context:
GPU context
- param skia.ImageInfo imageInfo:
width, height,
ColorType,AlphaType,ColorSpace; width, or height, or both, may be zero- param int sampleCount:
samples per pixel, or 0 to disable full scene anti-aliasing
- param skia.GrSurfaceOrigin surfaceOrigin:
kTopLeft or kBottomLeft
- param skia.SurfaceProps surfaceProps:
LCD striping orientation and setting for device independent fonts; may be nullptr
- param shouldCreateWithMips:
hint that
Surfacewill host mip map images- param isProtected:
protected-ness
- return:
Surfaceif all parameters are valid; otherwise, nullptr
MakeRenderTarget(context: skia.GrRecordingContext, budgeted: skia.Budgeted, imageInfo: skia.ImageInfo, sampleCount: int, surfaceProps: skia.SurfaceProps = None) -> skia.Surface
Returns
Surfaceon GPU indicated by context.Allocates memory for pixels, based on the width, height, and
ColorTypeinImageInfo. budgeted selects whether allocation for pixels is tracked by context. imageInfo describes the pixel format inColorType, and transparency inAlphaType, and color matching inColorSpace.sampleCount requests the number of samples per pixel. Pass zero to disable multi-sample anti-aliasing. The request is rounded up to the next supported count, or rounded down if it is larger than the maximum supported count.
Surfacebottom-left corner is pinned to the origin.- context:
GPU context
- imageInfo:
width, height,
ColorType,AlphaType,ColorSpace; width, or height, or both, may be zero- sampleCount:
samples per pixel, or 0 to disable full scene anti-aliasing
- surfaceProps:
LCD striping orientation and setting for device independent fonts; may be nullptr
- return:
Surfaceif all parameters are valid; otherwise, nullptr
MakeRenderTarget(context: skia.GrRecordingContext, budgeted: skia.Budgeted, imageInfo: skia.ImageInfo) -> skia.Surface
Returns
Surfaceon GPU indicated by context.Allocates memory for pixels, based on the width, height, and
ColorTypeinImageInfo. budgeted selects whether allocation for pixels is tracked by context. imageInfo describes the pixel format inColorType, and transparency inAlphaType, and color matching inColorSpace.Surfacebottom-left corner is pinned to the origin.- context:
GPU context
- imageInfo:
width, height,
ColorType,AlphaType,ColorSpace; width, or height, or both, may be zero
MakeRenderTarget(context: skia.GrRecordingContext, characterization: skia.SurfaceCharacterization, budgeted: skia.Budgeted) -> skia.Surface
Returns
Surfaceon GPU indicated by context that is compatible with the provided characterization.budgeted selects whether allocation for pixels is tracked by context.
- Surfaces.Raster()
MakeRaster(imageInfo: skia.ImageInfo, rowBytes: int = 0, surfaceProps: skia.SurfaceProps = None) -> skia.Surface
Allocates raster
Surface.Canvasreturned bySurfacedraws directly into pixels. Allocates and zeroes pixel memory. Pixel memory size is imageInfo.height() times rowBytes, or times imageInfo.minRowBytes() if rowBytes is zero. Pixel memory is deleted whenSurfaceis deleted.Surfaceis returned if all parameters are valid. Valid parameters include: info dimensions are greater than zero; info containsColorTypeandAlphaTypesupported by raster surface; rowBytes is large enough to contain info width pixels ofColorType, or is zero.If rowBytes is zero, a suitable value will be chosen internally.
- ImageInfo:
width, height,
ColorType,AlphaType,ColorSpace, of raster surface; width and height must be greater than zero- RowBytes:
interval from one
Surfacerow to the next; may be zero- Skia.SurfaceProps surfaceProps:
LCD striping orientation and setting for device independent fonts; may be nullptr
- Returns:
Surfaceif all parameters are valid; otherwise, nullptr
- static Surfaces.WrapBackendRenderTarget(context: skia.GrRecordingContext, backendRenderTarget: skia.GrBackendRenderTarget, origin: skia.GrSurfaceOrigin, colorType: skia.ColorType, colorSpace: skia.ColorSpace, surfaceProps: skia.SurfaceProps = None, releaseProc: void (void*) = None, releaseContext: capsule = None) skia.Surface
Wraps a GPU-backed buffer into
Surface.Caller must ensure backendRenderTarget is valid for the lifetime of returned
Surface.Surfaceis returned if all parameters are valid. backendRenderTarget is valid if its pixel configuration agrees with colorSpace and context; for instance, if backendRenderTarget has an sRGB configuration, then context must support sRGB, and colorSpace must be present. Further, backendRenderTarget width and height must not exceed context capabilities, and the context must be able to support back-end render targets.Upon success releaseProc is called when it is safe to delete the render target in the backend API (accounting only for use of the render target by this surface). If
Surfacecreation fails releaseProc is called before this function returns.If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr.
- Parameters:
context – GPU context
backendRenderTarget – GPU intermediate memory buffer
colorSpace – range of colors
surfaceProps – LCD striping orientation and setting for device independent fonts; may be nullptr
- Returns:
Surfaceif all parameters are valid; otherwise, nullptr
- Surfaces.__init__(*args, **kwargs)
Overloaded function.
__init__(self: skia.Surface, width: int, height: int, surfaceProps: skia.SurfaceProps = None) -> None
__init__(self: skia.Surface, width: int, height: int, colortype: skia.ColorType, surfaceProps: skia.SurfaceProps = None) -> None
See
MakeRasterN32Premul()plusImageInfo’smakeColorType()__init__(self: skia.Surface, imageInfo: skia.ImageInfo, rowBytes: int = 0, surfaceProps: skia.SurfaceProps = None) -> None
See
MakeRaster()__init__(self: skia.Surface, array: numpy.ndarray, colorType: skia.ColorType = skia.ColorType.kN32_ColorType, alphaType: skia.AlphaType = skia.AlphaType.kUnpremul_AlphaType, colorSpace: skia.ColorSpace = None, surfaceProps: skia.SurfaceProps = None) -> None
Create a raster surface on numpy array.
Input array must have compatible shape with the given color type.
Do not destroy numpy array while using this surface.
- array:
numpy ndarray of shape=(height, width, channels) and appropriate dtype. Must have non-zero width and height, and the valid number of channels for the specified color type.
- colorType:
color type of the array
- alphaType:
alpha type of the array
- colorSpace:
range of colors; may be nullptr
- Surfaces.asyncRescaleAndReadPixels(self: skia.Surface, info: skia.ImageInfo, srcRect: skia.IRect, rescaleGamma: skia.Surface.RescaleGamma, callback: Callable) None
Makes surface pixel data available to caller, possibly asynchronously.
It can also rescale the surface pixels.
Currently asynchronous reads are only supported on the GPU backend and only when the underlying 3D API supports transfer buffers and CPU/GPU synchronization primitives. In all other cases this operates synchronously.
Data is read from the source sub-rectangle, is optionally converted to a linear gamma, is rescaled to the size indicated by ‘info’, is then converted to the color space, color type, and alpha type of ‘info’. A ‘srcRect’ that is not contained by the bounds of the surface causes failure.
When the pixel data is ready the caller’s callback function is called with a AsyncReadResult containing pixel data in the requested color type, alpha type, and color space. The AsyncReadResult will have count() == 1. Upon failure the callback is called with nullptr for AsyncReadResult. For a GPU surface this flushes work but a submit must occur to guarantee a finite time before the callback is called.
The data is valid for the lifetime of AsyncReadResult with the exception that if the
Surfaceis GPU-backed the data is immediately invalidated if the GrContext is abandoned or destroyed.- Parameters:
info – info of the requested pixels
srcRect – subrectangle of surface to read
rescaleGamma – controls whether rescaling is done in the surface’s gamma or whether the source data is transformed to a linear gamma before rescaling.
rescaleQuality – controls the quality (and cost) of the rescaling
callback – function to call with result of the read. The callback takes one argument of
Surface.AsyncReadResult
- Surfaces.characterize(self: skia.Surface, characterization: skia.SurfaceCharacterization) bool
Initializes
SurfaceCharacterizationthat can be used to perform GPU back-end processing in a separate thread.Typically this is used to divide drawing into multiple tiles.
DeferredDisplayListRecorderrecords the drawing commands for each tile.Return true if
Surfacesupports characterization. raster surface returns false.- Parameters:
characterization (skia.SurfaceCharacterization) – properties for parallel drawing
- Returns:
true if supported
- Surfaces.draw(self: skia.Surface, canvas: skia.Canvas, x: float, y: float, paint: skia.Paint = None) None
Draws
Surfacecontents to canvas, with its top-left corner at (x, y).If
Paintpaint is not nullptr, applyColorFilter, alpha,ImageFilter,BlendMode, andDrawLooper.- Canvas:
Canvasdrawn into- X:
horizontal offset in
Canvas- Y:
vertical offset in
Canvas- Paint:
PaintcontainingBlendMode,ColorFilter,ImageFilter, and so on; or nullptr
- Surfaces.flush(*args, **kwargs)
Overloaded function.
flush(self: skia.Surface, access: skia.Surface.BackendSurfaceAccess, info: skia.GrFlushInfo) -> skia.GrSemaphoresSubmitted
Issues pending
Surfacecommands to the GPU-backed API objects and resolves anySurfaceMSAA. A call toGrContext.submit()is always required to ensure work is actually sent to the gpu. Some specific API details:- GL:
Commands are actually sent to the driver, but glFlush is never called. Thus some sync objects from the flush will not be valid until a submission occurs.
- Vulkan/Metal/D3D/Dawn:
Commands are recorded to the backend APIs corresponding command buffer or encoder objects. However, these objects are not sent to the gpu until a submission occurs.
The work that is submitted to the GPU will be dependent on the
BackendSurfaceAccessthat is passed in.If
BackendSurfaceAccess.kNoAccessis passed in all commands will be issued to the GPU.If
BackendSurfaceAccess.kPresentis passed in and the backend API is not Vulkan, it is treated the same as kNoAccess. If the backend API is Vulkan, the VkImage that backs theSurfacewill be transferred back to its original queue. If theSurfacewas created by wrapping a VkImage, the queue will be set to the queue which was originally passed in on the GrVkImageInfo. Additionally, if the original queue was not external or foreign the layout of the VkImage will be set to VK_IMAGE_LAYOUT_PRESENT_SRC_KHR.The
GrFlushInfodescribes additional options to flush. Please see documentation atGrFlushInfofor more info.If the return is
GrSemaphoresSubmitted.kYes, only initializedGrBackendSemaphoreswill be submitted to the gpu during the next submit call (it is possible Skia failed to create a subset of the semaphores). The client should not wait on these semaphores until after submit has been called, but must keep them alive until then. If a submit flag was passed in with the flush these valid semaphores can we waited on immediately. If this call returnsGrSemaphoresSubmitted.kNo, the GPU backend will not submit any semaphores to be signaled on the GPU. Thus the client should not have the GPU wait on any of the semaphores passed in with theGrFlushInfo. Regardless of whether semaphores were submitted to the GPU or not, the client is still responsible for deleting any initialized semaphores. Regardleess of semaphore submission the context will still be flushed. It should be emphasized that a return value ofGrSemaphoresSubmitted.kNodoes not mean the flush did not happen. It simply means there were no semaphores submitted to the GPU. A caller should only take this as a failure if they passed in semaphores to be submitted.Pending surface commands are flushed regardless of the return result.
- param access:
type of access the call will do on the backend object after flush
- param info:
flush options
flush(self: skia.Surface, info: skia.GrFlushInfo, newState: skgpu::MutableTextureState = None) -> skia.GrSemaphoresSubmitted
Issues pending
Surfacecommands to the GPU-backed API objects and resolves anySurfaceMSAA.A call to
GrContext.submit()is always required to ensure work is ctually sent to the gpu. Some specific API details:- GL:
Commands are actually sent to the driver, but glFlush is never called. Thus some sync objects from the flush will not be valid until a submission occurs.
- Vulkan/Metal/D3D/Dawn:
Commands are recorded to the backend APIs corresponding command buffer or encoder objects. However, these objects are not sent to the gpu until a submission occurs.
The GrFlushInfo describes additional options to flush. Please see documentation at GrFlushInfo for more info.
If a GrBackendSurfaceMutableState is passed in, at the end of the flush we will transition the surface to be in the state requested by the GrBackendSurfaceMutableState. If the surface (or
Imageor GrBackendSurface wrapping the same backend object) is used again after this flush the state may be changed and no longer match what is requested here. This is often used if the surface will be used for presenting or external use and the client wants backend object to be prepped for that use. A finishedProc or semaphore on the GrFlushInfo will also include the work for any requested state change.If the return is GrSemaphoresSubmitted::kYes, only initialized GrBackendSemaphores will be submitted to the gpu during the next submit call (it is possible Skia failed to create a subset of the semaphores). The client should not wait on these semaphores until after submit has been called, but must keep them alive until then. If a submit flag was passed in with the flush these valid semaphores can we waited on immediately. If this call returns GrSemaphoresSubmitted::kNo, the GPU backend will not submit any semaphores to be signaled on the GPU. Thus the client should not have the GPU wait on any of the semaphores passed in with the GrFlushInfo. Regardless of whether semaphores were submitted to the GPU or not, the client is still responsible for deleting any initialized semaphores. Regardleess of semaphore submission the context will still be flushed. It should be emphasized that a return value of GrSemaphoresSubmitted::kNo does not mean the flush did not happen. It simply means there were no semaphores submitted to the GPU. A caller should only take this as a failure if they passed in semaphores to be submitted.
Pending surface commands are flushed regardless of the return result.
- param info:
flush options
- param newState:
optional state change request after flush
- Surfaces.flushAndSubmit(self: skia.Surface, sync: skia.GrSyncCpu = skia.GrSyncCpu.kNo) None
Call to ensure all reads/writes of the surface have been issued to the underlying 3D API.
Skia will correctly order its own draws and pixel operations. This must to be used to ensure correct ordering when the surface backing store is accessed outside Skia (e.g. direct use of the 3D API or a windowing system).
GrContexthas additional flush and submit methods that apply to all surfaces and images created from aGrContext. This is equivalent to callingflush()with a defaultGrFlushInfofollowed byGrContext.submit().
- Surfaces.generationID(self: skia.Surface) int
Returns unique value identifying the content of
Surface.Returned value changes each time the content changes. Content is changed by drawing, or by calling
notifyContentWillChange().- Returns:
unique content identifier
- Surfaces.getBackendRenderTarget(self: skia.Surface, backendHandleAccess: skia.Surface.BackendHandleAccess) skia.GrBackendRenderTarget
Retrieves the back-end render target.
If
Surfacehas no back-end render target, an invalid object is returned. CallGrBackendRenderTarget.isValid()to determine if the result is valid.The returned
GrBackendRenderTargetshould be discarded if theSurfaceis drawn to or deleted.- Returns:
GPU render target reference; invalid on failure
- Surfaces.getBackendTexture(self: skia.Surface, backendHandleAccess: skia.Surface.BackendHandleAccess) skia.GrBackendTexture
Retrieves the back-end texture.
If
Surfacehas no back-end texture, an invalid object is returned. CallGrBackendTexture.isValid()to determine if the result is valid.The returned
GrBackendTextureshould be discarded if theSurfaceis drawn to or deleted.- Returns:
GPU texture reference; invalid on failure
- Surfaces.getCanvas(self: skia.Surface) skia.Canvas
Returns
Canvasthat draws intoSurface.Subsequent calls return the same
Canvas.Canvasreturned is managed and owned bySurface, and is deleted whenSurfaceis deleted.
- Surfaces.height(self: skia.Surface) int
Returns pixel row count; may be zero or greater.
- Returns:
number of pixel rows
- Surfaces.imageInfo(self: skia.Surface) skia.ImageInfo
Returns an
ImageInfodescribing the surface.
- Surfaces.isCompatible(self: skia.Surface, characterization: skia.SurfaceCharacterization) bool
Is this surface compatible with the provided characterization?
This method can be used to determine if an existing
Surfaceis a viable destination for anDeferredDisplayList.- Parameters:
characterization (skia.SurfaceCharacterization) – The characterization for which a compatibility check is desired
- Returns:
true if this surface is compatible with the characterization; false otherwise
- Surfaces.makeImageSnapshot(*args, **kwargs)
Overloaded function.
makeImageSnapshot(self: skia.Surface) -> skia.Image
makeImageSnapshot(self: skia.Surface, bounds: skia.IRect) -> skia.Image
Like the no-parameter version, this returns an image of the current surface contents.
This variant takes a rectangle specifying the subset of the surface that is of interest. These bounds will be sanitized before being used.
- If bounds extends beyond the surface, it will be trimmed to just the
intersection of it and the surface.
If bounds does not intersect the surface, then this returns nullptr.
- If bounds == the surface, then this is the same as calling the
no-parameter variant.
- Surfaces.makeSurface(*args, **kwargs)
Overloaded function.
makeSurface(self: skia.Surface, imageInfo: skia.ImageInfo) -> skia.Surface
Returns a compatible
Surface, or nullptr.Returned
Surfacecontains the same raster, GPU, or null properties as the original. ReturnedSurfacedoes not share the same pixels.Returns nullptr if imageInfo width or height are zero, or if imageInfo is incompatible with
Surface.- param skia.ImageInfo imageInfo:
width, height,
ColorType,AlphaType,ColorSpace, ofSurface; width and height must be greater than zero- return:
compatible
Surfaceor nullptr
makeSurface(self: skia.Surface, width: int, height: int) -> skia.Surface
Calls
makeSurface()with the same ImageInfo as this surface, but with the specified width and height.
- Surfaces.notifyContentWillChange(self: skia.Surface, mode: skia.Surface.ContentChangeMode) None
Notifies that
Surfacecontents will be changed by code outside of Skia.Subsequent calls to
generationID()return a different value.
- Surfaces.peekPixels(self: skia.Surface, pixmap: skia.Pixmap) bool
Copies
Surfacepixel address, row bytes, andImageInfotoPixmap, if address is available, and returns true.If pixel address is not available, return false and leave
Pixmapunchanged.pixmap contents become invalid on any future change to
Surface.- Parameters:
pixmap (skia.Pixmap) – storage for pixel state if pixels are readable; otherwise, ignored
- Returns:
true if
Surfacehas direct access to pixels
- Surfaces.props(self: skia.Surface) skia.SurfaceProps
Returns
SurfacePropsfor surface.- Returns:
LCD striping orientation and setting for device independent fonts
- Surfaces.readPixels(*args, **kwargs)
Overloaded function.
readPixels(self: skia.Surface, dst: skia.Pixmap, srcX: int = 0, srcY: int = 0) -> bool
Copies
Rectof pixels to dst.Source
Rectcorners are (srcX, srcY) andSurface(width(), height()). DestinationRectcorners are (0, 0) and (dst.width(), dst.height()). Copies each readable pixel intersecting both rectangles, without scaling, converting to dst.colorType() and dst.alphaType() if required.Pixels are readable when
Surfaceis raster, or backed by a GPU.The destination pixel storage must be allocated by the caller.
Pixel values are converted only if
ColorTypeandAlphaTypedo not match. Only pixels within both source and destination rectangles are copied. dst contents outsideRectintersection 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.
Pixmappixels could not be allocated.dst.rowBytes() is too small to contain one row of pixels.
- dst:
storage for pixels copied from
Surface- srcX:
offset into readable pixels on x-axis; may be negative
- srcY:
offset into readable pixels on y-axis; may be negative
- return:
true if pixels were copied
readPixels(self: skia.Surface, dstInfo: skia.ImageInfo, dstPixels: Buffer, dstRowBytes: int = 0, srcX: int = 0, srcY: int = 0) -> bool
Copies
Rectof pixels fromCanvasinto array.Matrixand clip are ignored.Source
Rectcorners are (srcX, srcY) andSurface(width(), height()). DestinationRectcorners are (0, 0) and (array.shape[1], array.shape[0]). Copies each readable pixel intersecting both rectangles, without scaling, converting toColorType.kN32andAlphaType.kPremulif required.Pixels are readable when
BaseDeviceis raster, or backed by a GPU.The destination pixel storage must be allocated by the caller.
Pixel values are converted only if
ColorTypeandAlphaTypedo not match. Only pixels within both source and destination rectangles are copied. array contents outsideRectintersection 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.
Surfacepixels could not be converted toColorType.kN32orAlphaType.kPremul.
- dstInfo:
- dstPixels:
storage for pixels; dstInfo.height() times dstRowBytes, or larger
- dstRowBytes:
size of one destination row; dstInfo.width() times pixel size, or larger. Ignored when dstPixels has more than one-dimension.
- srcX:
offset into readable pixels on x-axis; may be negative
- srcY:
offset into readable pixels on y-axis; may be negative
- return:
true if pixels were copied
readPixels(self: skia.Surface, dst: skia.Bitmap, srcX: int, srcY: int) -> bool
Copies
Rectof pixels fromSurfaceinto bitmap.Source
Rectcorners are (srcX, srcY) andSurface(width(), height()). DestinationRectcorners 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
Surfaceis raster, or backed by a GPU.The destination pixel storage must be allocated by the caller.
Pixel values are converted only if
ColorTypeandAlphaTypedo not match. Only pixels within both source and destination rectangles are copied. dst contents outsideRectintersection 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.
Surfacepixels could not be converted to dst.colorType()or dst.alphaType().
dst pixels could not be allocated.
dst.rowBytes() is too small to contain one row of pixels.
- dst:
storage for pixels copied from
Surface- srcX:
offset into readable pixels on x-axis; may be negative
- srcY:
offset into readable pixels on y-axis; may be negative
- return:
true if pixels were copied
- Surfaces.recordingContext(self: skia.Surface) skia.GrRecordingContext
Returns the recording context being used by the
Surface.- Returns:
GPU context, if available; nullptr otherwise
- Surfaces.ref(self: skia.RefCntBase) None
Increment the reference count.
Must be balanced by a call to
unref().
- Surfaces.replaceBackendTexture(self: skia.Surface, backendTexture: skia.GrBackendTexture, origin: skia.GrSurfaceOrigin, mode: skia.Surface.ContentChangeMode = skia.Surface.ContentChangeMode.kRetain_ContentChangeMode) bool
If the surface was made via
MakeFromBackendTexture()then it’s backing texture may be substituted with a different texture.The contents of the previous backing texture are copied into the new texture.
Canvasstate is preserved. The original sample count is used. TheGrBackendFormatand dimensions of replacement texture must match that of the original.- Parameters:
backendTexture – the new backing texture for the surface
mode – Retain or discard current Content
- Surfaces.toarray(self: skia.Surface, srcX: int = 0, srcY: int = 0, colorType: skia.ColorType = skia.ColorType.kUnknown_ColorType, alphaType: skia.AlphaType = skia.AlphaType.kUnpremul_AlphaType, colorSpace: skia.ColorSpace = None) numpy.ndarray
Exports a
numpy.ndarray.- Parameters:
srcX – offset into readable pixels on x-axis; may be negative
srcY – offset into readable pixels on y-axis; may be negative
colorType – target
ColorTypealphaType – target
AlphaTypecolorSpace – target
ColorSpace
- Returns:
numpy.ndarray
- Surfaces.unique(self: skia.RefCntBase) bool
May return true if the caller is the only owner.
Ensures that all previous owner’s actions are complete.
- Surfaces.unref(self: skia.RefCntBase) None
Decrement the reference count.
If the reference count is 1 before the decrement, then delete the object. Note that if this is the case, then the object needs to have been allocated via new, and not on the stack.
- Surfaces.width(self: skia.Surface) int
Returns pixel count in each row; may be zero or greater.
- Returns:
number of pixel columns
- Surfaces.writePixels(*args, **kwargs)
Overloaded function.
writePixels(self: skia.Surface, src: skia.Pixmap, dstX: int = 0, dstY: int = 0) -> None
Copies
Rectof pixels from the srcPixmapto theSurface.Source
Rectcorners are (0, 0) and (src.width(), src.height()). DestinationRectcorners are (dstX, dstY) and (dstX + Surface width(), dstY + Surface height()).Copies each readable pixel intersecting both rectangles, without scaling, converting to
SurfacecolorType() andSurfacealphaType() if required.writePixels(self: skia.Surface, src: skia.Bitmap, dstX: int = 0, dstY: int = 0) -> None
Copies
Rectof pixels from the srcBitmapto theSurface.Source
Rectcorners are (0, 0) and (src.width(), src.height()). DestinationRectcorners are (dstX, dstY) and (dstX + Surface width(), dstY + Surface height()).Copies each readable pixel intersecting both rectangles, without scaling, converting to
SurfacecolorType() andSurfacealphaType() if required.
Attributes
- Surfaces.kDiscardWrite_BackendHandleAccess = <BackendHandleAccess.kDiscardWrite_BackendHandleAccess: 2>
- Surfaces.kDiscard_ContentChangeMode = <ContentChangeMode.kDiscard_ContentChangeMode: 0>
- Surfaces.kFlushRead_BackendHandleAccess = <BackendHandleAccess.kFlushRead_BackendHandleAccess: 0>
- Surfaces.kFlushWrite_BackendHandleAccess = <BackendHandleAccess.kFlushWrite_BackendHandleAccess: 1>
- Surfaces.kLinear = <RescaleGamma.kLinear: 1>
- Surfaces.kNoAccess = <BackendSurfaceAccess.kNoAccess: 0>
- Surfaces.kPresent = <BackendSurfaceAccess.kPresent: 1>
- Surfaces.kRetain_ContentChangeMode = <ContentChangeMode.kRetain_ContentChangeMode: 1>
- Surfaces.kSrc = <RescaleGamma.kSrc: 0>