Class Surface
- java.lang.Object
-
- io.github.humbleui.skija.impl.Native
-
- io.github.humbleui.skija.impl.Managed
-
- io.github.humbleui.skija.impl.RefCnt
-
- io.github.humbleui.skija.Surface
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class Surface extends RefCnt
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class io.github.humbleui.skija.impl.RefCnt
RefCnt._FinalizerHolder
-
Nested classes/interfaces inherited from class io.github.humbleui.skija.impl.Managed
Managed.CleanerThunk
-
-
Field Summary
Fields Modifier and Type Field Description DirectContext_contextBackendRenderTarget_renderTarget-
Fields inherited from class io.github.humbleui.skija.impl.Managed
_cleanable
-
-
Constructor Summary
Constructors Constructor Description Surface(long ptr)Surface(long ptr, DirectContext context)Surface(long ptr, DirectContext context, BackendRenderTarget renderTarget)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void_nDraw(long ptr, long canvasPtr, float x, float y, long paintPtr)static void_nFlush(long ptr)static void_nFlushAndSubmit(long ptr, boolean syncCpu)static int_nGenerationId(long ptr)static long_nGetCanvas(long ptr)static int_nGetHeight(long ptr)static ImageInfo_nGetImageInfo(long ptr)static long_nGetRecordingContext(long ptr)static int_nGetWidth(long ptr)static long_nMakeImageSnapshot(long ptr)static long_nMakeImageSnapshotR(long ptr, int left, int top, int right, int bottom)static long_nMakeNull(int width, int height)static long_nMakeRaster(int width, int height, int colorType, int alphaType, long colorSpacePtr, long rowBytes, SurfaceProps surfaceProps)static long_nMakeRenderTarget(long contextPtr, boolean budgeted, int width, int height, int colorType, int alphaType, long colorSpacePtr, int sampleCount, int surfaceOrigin, SurfaceProps surfaceProps, boolean shouldCreateWithMips)static long_nMakeSurface(long ptr, int width, int height)static long_nMakeSurfaceI(long ptr, int width, int height, int colorType, int alphaType, long colorSpacePtr)static void_nNotifyContentWillChange(long ptr, int mode)static boolean_nPeekPixels(long ptr, long pixmapPtr)static boolean_nReadPixels(long ptr, long bitmapPtr, int srcX, int srcY)static boolean_nReadPixelsToPixmap(long ptr, long pixmapPtr, int srcX, int srcY)static boolean_nUnique(long ptr)static long_nWrapBackendRenderTarget(long pContext, long pBackendRenderTarget, int surfaceOrigin, int colorType, long colorSpacePtr, SurfaceProps surfaceProps)static long_nWrapMTKView(long contextPtr, long mtkViewPtr, int surfaceOrigin, int sampleCount, int colorType, long colorSpacePtr, SurfaceProps surfaceProps)static long_nWrapPixels(int width, int height, int colorType, int alphaType, long colorSpacePtr, long pixelsPtr, long rowBytes, SurfaceProps surfaceProps)static long_nWrapPixelsPixmap(long pixmapPtr, SurfaceProps surfaceProps)static void_nWritePixels(long ptr, long bitmapPtr, int x, int y)static void_nWritePixelsFromPixmap(long ptr, long pixmapPtr, int x, int y)voiddraw(Canvas canvas, int x, int y, Paint paint)Draws Surface contents to canvas, with its top-left corner at (x, y).voidflush()voidflushAndSubmit()Call to ensure all reads/writes of the surface have been issued to the underlying 3D API.voidflushAndSubmit(boolean syncCpu)Call to ensure all reads/writes of the surface have been issued to the underlying 3D API.@NotNull CanvasgetCanvas()Returns Canvas that draws into Surface.intgetGenerationId()Returns unique value identifying the content of Surface.intgetHeight()Returns pixel row count; may be zero or greater.@NotNull ImageInfogetImageInfo()Returns an ImageInfo describing the surface.@Nullable DirectContextgetRecordingContext()Returns the recording context being used by the Surface.intgetWidth()Returns pixel count in each row; may be zero or greater.booleanisUnique()May return true if the caller is the only owner.static SurfacemakeFromBackendRenderTarget(DirectContext context, BackendRenderTarget rt, SurfaceOrigin origin, SurfaceColorFormat colorFormat, ColorSpace colorSpace)static SurfacemakeFromBackendRenderTarget(DirectContext context, BackendRenderTarget rt, SurfaceOrigin origin, SurfaceColorFormat colorFormat, ColorSpace colorSpace, SurfaceProps surfaceProps)static SurfacemakeFromMTKView(@NotNull DirectContext context, long mtkViewPtr, @NotNull SurfaceOrigin origin, int sampleCount, @NotNull SurfaceColorFormat colorFormat, @Nullable ColorSpace colorSpace, @Nullable SurfaceProps surfaceProps)@NotNull ImagemakeImageSnapshot()Returns Image capturing Surface contents.@Nullable ImagemakeImageSnapshot(@NotNull io.github.humbleui.types.IRect area)Like the no-parameter version, this returns an image of the current surface contents.static @NotNull SurfacemakeNull(int width, int height)Returns Surface without backing pixels.static @NotNull SurfacemakeRaster(@NotNull ImageInfo imageInfo)Allocates raster Surface.static @NotNull SurfacemakeRaster(@NotNull ImageInfo imageInfo, long rowBytes)Allocates raster Surface.static @NotNull SurfacemakeRaster(@NotNull ImageInfo imageInfo, long rowBytes, @Nullable SurfaceProps surfaceProps)Allocates raster Surface.static SurfacemakeRasterDirect(@NotNull ImageInfo imageInfo, long pixelsPtr, long rowBytes)Deprecated.static SurfacemakeRasterDirect(@NotNull ImageInfo imageInfo, long pixelsPtr, long rowBytes, @Nullable SurfaceProps surfaceProps)Deprecated.static SurfacemakeRasterDirect(@NotNull Pixmap pixmap)Deprecated.- usewrapPixels(Pixmap)static SurfacemakeRasterDirect(@NotNull Pixmap pixmap, @Nullable SurfaceProps surfaceProps)Deprecated.static @NotNull SurfacemakeRasterN32Premul(int width, int height)Deprecated.- use makeRaster(ImageInfo.makeN32Premul(width, height))static @NotNull SurfacemakeRenderTarget(@NotNull DirectContext context, boolean budgeted, @NotNull ImageInfo imageInfo)Returns Surface on GPU indicated by context.static @NotNull SurfacemakeRenderTarget(@NotNull DirectContext context, boolean budgeted, @NotNull ImageInfo imageInfo, int sampleCount, @NotNull SurfaceOrigin origin, @Nullable SurfaceProps surfaceProps)Returns Surface on GPU indicated by context.static @NotNull SurfacemakeRenderTarget(@NotNull DirectContext context, boolean budgeted, @NotNull ImageInfo imageInfo, int sampleCount, @NotNull SurfaceOrigin origin, @Nullable SurfaceProps surfaceProps, boolean shouldCreateWithMips)Returns Surface on GPU indicated by context.static @NotNull SurfacemakeRenderTarget(@NotNull DirectContext context, boolean budgeted, @NotNull ImageInfo imageInfo, int sampleCount, @Nullable SurfaceProps surfaceProps)Returns Surface on GPU indicated by context.@Nullable SurfacemakeSurface(int width, int height)Calls makeSurface(ImageInfo) with the same ImageInfo as this surface, but with the specified width and height.@Nullable SurfacemakeSurface(ImageInfo imageInfo)Returns a compatible Surface, or null.voidnotifyContentWillChange(ContentChangeMode mode)Notifies that Surface contents will be changed by code outside of Skia.booleanpeekPixels(@NotNull Pixmap pixmap)booleanreadPixels(Bitmap bitmap, int srcX, int srcY)Copies Rect of pixels from Surface into bitmap.booleanreadPixels(Pixmap pixmap, int srcX, int srcY)static @NotNull SurfacewrapBackendRenderTarget(@NotNull DirectContext context, @NotNull BackendRenderTarget rt, @NotNull SurfaceOrigin origin, @NotNull SurfaceColorFormat colorFormat, @Nullable ColorSpace colorSpace)Wraps a GPU-backed buffer intoSurface.static @NotNull SurfacewrapBackendRenderTarget(@NotNull DirectContext context, @NotNull BackendRenderTarget rt, @NotNull SurfaceOrigin origin, @NotNull SurfaceColorFormat colorFormat, @Nullable ColorSpace colorSpace, @Nullable SurfaceProps surfaceProps)Wraps a GPU-backed buffer intoSurface.static @NotNull SurfacewrapMTKView(@NotNull DirectContext context, long mtkViewPtr, @NotNull SurfaceOrigin origin, int sampleCount, @NotNull SurfaceColorFormat colorFormat, @Nullable ColorSpace colorSpace, @Nullable SurfaceProps surfaceProps)static @NotNull SurfacewrapPixels(@NotNull ImageInfo imageInfo, long pixelsPtr, long rowBytes)Allocates raster Surface.static @NotNull SurfacewrapPixels(@NotNull ImageInfo imageInfo, long pixelsPtr, long rowBytes, @Nullable SurfaceProps surfaceProps)Allocates raster Surface.static @NotNull SurfacewrapPixels(@NotNull Pixmap pixmap)static @NotNull SurfacewrapPixels(@NotNull Pixmap pixmap, @Nullable SurfaceProps surfaceProps)voidwritePixels(Bitmap bitmap, int x, int y)Copies Rect of pixels from the src Bitmap to the Surface.voidwritePixels(Pixmap pixmap, int x, int y)-
Methods inherited from class io.github.humbleui.skija.impl.RefCnt
_nGetFinalizer, _nGetRefCount, getRefCount, toString
-
Methods inherited from class io.github.humbleui.skija.impl.Managed
_nInvokeFinalizer, close, isClosed
-
Methods inherited from class io.github.humbleui.skija.impl.Native
_nativeEquals, equals, getPtr, hashCode
-
-
-
-
Field Detail
-
_context
@Internal public final DirectContext _context
-
_renderTarget
@Internal public final BackendRenderTarget _renderTarget
-
-
Constructor Detail
-
Surface
@Internal public Surface(long ptr)
-
Surface
@Internal public Surface(long ptr, DirectContext context)
-
Surface
@Internal public Surface(long ptr, DirectContext context, BackendRenderTarget renderTarget)
-
-
Method Detail
-
makeRasterDirect
@Deprecated public static Surface makeRasterDirect(@NotNull @NotNull ImageInfo imageInfo, long pixelsPtr, long rowBytes)
Deprecated.
-
wrapPixels
@NotNull @Contract("_, _, _ -> new") public static @NotNull Surface wrapPixels(@NotNull @NotNull ImageInfo imageInfo, long pixelsPtr, long rowBytes)Allocates raster Surface. Canvas returned by Surface draws directly into pixels.
Surface is returned if all parameters are valid. Valid parameters include:
- info dimensions are greater than zero;
- info contains ColorType and AlphaType supported by raster surface;
- pixelsPtr is not 0;
- rowBytes is large enough to contain info width pixels of ColorType.
Pixel buffer size should be info height times computed rowBytes.
Pixels are not initialized.
To access pixels after drawing, peekPixels() or readPixels().
- Parameters:
imageInfo- width, height, ColorType, AlphaType, ColorSpace, of raster surface; width and height must be greater than zeropixelsPtr- pointer to destination pixels bufferrowBytes- memory address of destination native pixels buffer- Returns:
- created Surface
-
makeRasterDirect
@Deprecated public static Surface makeRasterDirect(@NotNull @NotNull ImageInfo imageInfo, long pixelsPtr, long rowBytes, @Nullable @Nullable SurfaceProps surfaceProps)
Deprecated.
-
wrapPixels
@NotNull @Contract("_, _, _, _ -> new") public static @NotNull Surface wrapPixels(@NotNull @NotNull ImageInfo imageInfo, long pixelsPtr, long rowBytes, @Nullable @Nullable SurfaceProps surfaceProps)Allocates raster Surface. Canvas returned by Surface draws directly into pixels.
Surface is returned if all parameters are valid. Valid parameters include:
- info dimensions are greater than zero;
- info contains ColorType and AlphaType supported by raster surface;
- pixelsPtr is not 0;
- rowBytes is large enough to contain info width pixels of ColorType.
Pixel buffer size should be info height times computed rowBytes.
Pixels are not initialized.
To access pixels after drawing, peekPixels() or readPixels().
- Parameters:
imageInfo- width, height, ColorType, AlphaType, ColorSpace, of raster surface; width and height must be greater than zeropixelsPtr- pointer to destination pixels bufferrowBytes- memory address of destination native pixels buffersurfaceProps- LCD striping orientation and setting for device independent fonts; may be null- Returns:
- created Surface
-
makeRasterDirect
@Deprecated public static Surface makeRasterDirect(@NotNull @NotNull Pixmap pixmap)
Deprecated.- usewrapPixels(Pixmap)
-
wrapPixels
@NotNull @Contract("_ -> new") public static @NotNull Surface wrapPixels(@NotNull @NotNull Pixmap pixmap)
-
makeRasterDirect
@Deprecated public static Surface makeRasterDirect(@NotNull @NotNull Pixmap pixmap, @Nullable @Nullable SurfaceProps surfaceProps)
Deprecated.
-
wrapPixels
@NotNull @Contract("_, _ -> new") public static @NotNull Surface wrapPixels(@NotNull @NotNull Pixmap pixmap, @Nullable @Nullable SurfaceProps surfaceProps)
-
makeRaster
@NotNull @Contract("_, _, _ -> new") public static @NotNull Surface makeRaster(@NotNull @NotNull ImageInfo imageInfo)Allocates raster Surface. Canvas returned by Surface draws directly into pixels. Allocates and zeroes pixel memory. Pixel memory size is imageInfo.height() times imageInfo.minRowBytes(). Pixel memory is deleted when Surface is deleted.
Surface is returned if all parameters are valid. Valid parameters include:
- info dimensions are greater than zero;
- info contains ColorType and AlphaType supported by raster surface;
- Parameters:
imageInfo- width, height, ColorType, AlphaType, ColorSpace, of raster surface; width and height must be greater than zero- Returns:
- new Surface
-
makeRaster
@NotNull @Contract("_, _, _ -> new") public static @NotNull Surface makeRaster(@NotNull @NotNull ImageInfo imageInfo, long rowBytes)Allocates raster Surface. Canvas returned by Surface draws 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 when Surface is deleted.
Surface is returned if all parameters are valid. Valid parameters include:
- info dimensions are greater than zero;
- info contains ColorType and AlphaType supported by raster surface;
- rowBytes is large enough to contain info width pixels of ColorType, or is zero.
If rowBytes is zero, a suitable value will be chosen internally.
- Parameters:
imageInfo- width, height, ColorType, AlphaType, ColorSpace, of raster surface; width and height must be greater than zerorowBytes- interval from one Surface row to the next; may be zero- Returns:
- new Surface
-
makeRaster
@NotNull @Contract("_, _, _ -> new") public static @NotNull Surface makeRaster(@NotNull @NotNull ImageInfo imageInfo, long rowBytes, @Nullable @Nullable SurfaceProps surfaceProps)Allocates raster Surface. Canvas returned by Surface draws 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 when Surface is deleted.
Surface is returned if all parameters are valid. Valid parameters include:
- info dimensions are greater than zero;
- info contains ColorType and AlphaType supported by raster surface;
- rowBytes is large enough to contain info width pixels of ColorType, or is zero.
If rowBytes is zero, a suitable value will be chosen internally.
- Parameters:
imageInfo- width, height, ColorType, AlphaType, ColorSpace, of raster surface; width and height must be greater than zerorowBytes- interval from one Surface row to the next; may be zerosurfaceProps- LCD striping orientation and setting for device independent fonts; may be null- Returns:
- new Surface
-
makeFromBackendRenderTarget
@Deprecated public static Surface makeFromBackendRenderTarget(DirectContext context, BackendRenderTarget rt, SurfaceOrigin origin, SurfaceColorFormat colorFormat, ColorSpace colorSpace)
-
wrapBackendRenderTarget
@NotNull public static @NotNull Surface wrapBackendRenderTarget(@NotNull @NotNull DirectContext context, @NotNull @NotNull BackendRenderTarget rt, @NotNull @NotNull SurfaceOrigin origin, @NotNull @NotNull SurfaceColorFormat colorFormat, @Nullable @Nullable ColorSpace colorSpace)
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.- Parameters:
context- GPU contextrt- texture residing on GPUorigin- surfaceOrigin pins either the top-left or the bottom-left corner to the origin.colorFormat- color formatcolorSpace- range of colors; may be null- Returns:
- Surface if all parameters are valid; otherwise, null
- See Also:
- https://fiddle.skia.org/c/@Surface_MakeFromBackendTexture
-
makeFromBackendRenderTarget
@Deprecated public static Surface makeFromBackendRenderTarget(DirectContext context, BackendRenderTarget rt, SurfaceOrigin origin, SurfaceColorFormat colorFormat, ColorSpace colorSpace, SurfaceProps surfaceProps)
-
wrapBackendRenderTarget
@NotNull public static @NotNull Surface wrapBackendRenderTarget(@NotNull @NotNull DirectContext context, @NotNull @NotNull BackendRenderTarget rt, @NotNull @NotNull SurfaceOrigin origin, @NotNull @NotNull SurfaceColorFormat colorFormat, @Nullable @Nullable ColorSpace colorSpace, @Nullable @Nullable SurfaceProps surfaceProps)
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.- Parameters:
context- GPU contextrt- texture residing on GPUorigin- surfaceOrigin pins either the top-left or the bottom-left corner to the origin.colorFormat- color formatcolorSpace- range of colors; may be nullsurfaceProps- LCD striping orientation and setting for device independent fonts; may be null- Returns:
- Surface if all parameters are valid; otherwise, null
- See Also:
- https://fiddle.skia.org/c/@Surface_MakeFromBackendTexture
-
makeFromMTKView
@Deprecated public static Surface makeFromMTKView(@NotNull @NotNull DirectContext context, long mtkViewPtr, @NotNull @NotNull SurfaceOrigin origin, int sampleCount, @NotNull @NotNull SurfaceColorFormat colorFormat, @Nullable @Nullable ColorSpace colorSpace, @Nullable @Nullable SurfaceProps surfaceProps)
-
wrapMTKView
@NotNull public static @NotNull Surface wrapMTKView(@NotNull @NotNull DirectContext context, long mtkViewPtr, @NotNull @NotNull SurfaceOrigin origin, int sampleCount, @NotNull @NotNull SurfaceColorFormat colorFormat, @Nullable @Nullable ColorSpace colorSpace, @Nullable @Nullable SurfaceProps surfaceProps)
-
makeRasterN32Premul
@NotNull @Deprecated public static @NotNull Surface makeRasterN32Premul(int width, int height)
Deprecated.- use makeRaster(ImageInfo.makeN32Premul(width, height))Allocates raster
Surface.Canvas returned by Surface draws directly into pixels. Allocates and zeroes pixel memory. Pixel memory size is height times width times four. Pixel memory is deleted when Surface is deleted.
Internally, sets ImageInfo to width, height, native color type, and ColorAlphaType.PREMUL.
Surface is returned if width and height are greater than zero.
Use to create Surface that matches PMColor, the native pixel arrangement on the platform. Surface drawn to output device skips converting its pixel format.
- Parameters:
width- pixel column count; must be greater than zeroheight- pixel row count; must be greater than zero- Returns:
- Surface if all parameters are valid; otherwise, null
- See Also:
- https://fiddle.skia.org/c/@Surface_MakeRasterN32Premul
-
makeRenderTarget
@NotNull @Contract("_, _, _ -> new") public static @NotNull Surface makeRenderTarget(@NotNull @NotNull DirectContext context, boolean budgeted, @NotNull @NotNull ImageInfo imageInfo)Returns Surface on GPU indicated by context. Allocates memory for pixels, based on the width, height, and ColorType in ImageInfo. describes the pixel format in ColorType, and transparency in AlphaType, and color matching in ColorSpace.
- Parameters:
context- GPU contextbudgeted- selects whether allocation for pixels is tracked by contextimageInfo- width, height, ColorType, AlphaType, ColorSpace; width, or height, or both, may be zero- Returns:
- new SkSurface
-
makeRenderTarget
@NotNull @Contract("_, _, _, _, _ -> new") public static @NotNull Surface makeRenderTarget(@NotNull @NotNull DirectContext context, boolean budgeted, @NotNull @NotNull ImageInfo imageInfo, int sampleCount, @Nullable @Nullable SurfaceProps surfaceProps)Returns Surface on GPU indicated by context. Allocates memory for pixels, based on the width, height, and ColorType in ImageInfo. describes the pixel format in ColorType, and transparency in AlphaType, and color matching in ColorSpace.
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.
- Parameters:
context- GPU contextbudgeted- selects whether allocation for pixels is tracked by contextimageInfo- width, height, ColorType, AlphaType, ColorSpace; width, or height, or both, may be zerosampleCount- samples per pixel, or 0 to disable full scene anti-aliasingsurfaceProps- LCD striping orientation and setting for device independent fonts; may be null- Returns:
- new SkSurface
-
makeRenderTarget
@NotNull @Contract("_, _, _, _, _, _ -> new") public static @NotNull Surface makeRenderTarget(@NotNull @NotNull DirectContext context, boolean budgeted, @NotNull @NotNull ImageInfo imageInfo, int sampleCount, @NotNull @NotNull SurfaceOrigin origin, @Nullable @Nullable SurfaceProps surfaceProps)Returns Surface on GPU indicated by context. Allocates memory for pixels, based on the width, height, and ColorType in ImageInfo. describes the pixel format in ColorType, and transparency in AlphaType, and color matching in ColorSpace.
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.
- Parameters:
context- GPU contextbudgeted- selects whether allocation for pixels is tracked by contextimageInfo- width, height, ColorType, AlphaType, ColorSpace; width, or height, or both, may be zerosampleCount- samples per pixel, or 0 to disable full scene anti-aliasingorigin- pins either the top-left or the bottom-left corner to the origin.surfaceProps- LCD striping orientation and setting for device independent fonts; may be null- Returns:
- new SkSurface
-
makeRenderTarget
@NotNull @Contract("_, _, _, _, _, _, _ -> new") public static @NotNull Surface makeRenderTarget(@NotNull @NotNull DirectContext context, boolean budgeted, @NotNull @NotNull ImageInfo imageInfo, int sampleCount, @NotNull @NotNull SurfaceOrigin origin, @Nullable @Nullable SurfaceProps surfaceProps, boolean shouldCreateWithMips)Returns Surface on GPU indicated by context. Allocates memory for pixels, based on the width, height, and ColorType in ImageInfo. describes the pixel format in ColorType, and transparency in AlphaType, and color matching in ColorSpace.
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.
shouldCreateWithMips hints that Image returned by
makeImageSnapshot()is mip map.- Parameters:
context- GPU contextbudgeted- selects whether allocation for pixels is tracked by contextimageInfo- width, height, ColorType, AlphaType, ColorSpace; width, or height, or both, may be zerosampleCount- samples per pixel, or 0 to disable full scene anti-aliasingorigin- pins either the top-left or the bottom-left corner to the origin.surfaceProps- LCD striping orientation and setting for device independent fonts; may be nullshouldCreateWithMips- hint that SkSurface will host mip map images- Returns:
- new SkSurface
-
makeNull
@NotNull @Contract("_, _ -> new") public static @NotNull Surface makeNull(int width, int height)Returns Surface without backing pixels. Drawing to Canvas returned from Surface has no effect. Calling makeImageSnapshot() on returned Surface returns null.- Parameters:
width- one or greaterheight- one or greater- Returns:
- Surface if width and height are positive
- See Also:
- https://fiddle.skia.org/c/@Surface_MakeNull
-
getWidth
public int getWidth()
Returns pixel count in each row; may be zero or greater.
- Returns:
- number of pixel columns
- See Also:
- https://fiddle.skia.org/c/@Surface_width
-
getHeight
public int getHeight()
Returns pixel row count; may be zero or greater.
- Returns:
- number of pixel rows
- See Also:
- https://fiddle.skia.org/c/@Surface_height
-
getImageInfo
@NotNull public @NotNull ImageInfo getImageInfo()
Returns an ImageInfo describing the surface.
- Returns:
- ImageInfo describing the surface.
-
getGenerationId
public int getGenerationId()
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
-
notifyContentWillChange
public void notifyContentWillChange(ContentChangeMode mode)
Notifies that Surface contents will be changed by code outside of Skia.
Subsequent calls to generationID() return a different value.
-
getRecordingContext
@Nullable public @Nullable DirectContext getRecordingContext()
Returns the recording context being used by the Surface.
- Returns:
- the recording context, if available; null otherwise
-
getCanvas
@NotNull public @NotNull Canvas getCanvas()
Returns Canvas that draws into Surface.
Subsequent calls return the same Canvas. Canvas returned is managed and owned by Surface, and is deleted when Surface is deleted.
- Returns:
- Canvas for Surface
-
makeSurface
@Nullable public @Nullable Surface makeSurface(ImageInfo imageInfo)
Returns a compatible Surface, or null.
Returned Surface contains the same raster, GPU, or null properties as the original. Returned Surface does not share the same pixels.
Returns null if imageInfo width or height are zero, or if imageInfo is incompatible with Surface.
- Parameters:
imageInfo- contains width, height, AlphaType, ColorType, ColorSpace- Returns:
- compatible SkSurface or null
- See Also:
- https://fiddle.skia.org/c/@Surface_makeSurface
-
makeSurface
@Nullable public @Nullable Surface makeSurface(int width, int height)
Calls makeSurface(ImageInfo) with the same ImageInfo as this surface, but with the specified width and height.
Returned Surface contains the same raster, GPU, or null properties as the original. Returned Surface does not share the same pixels.
Returns null if imageInfo width or height are zero, or if imageInfo is incompatible with Surface.
- Parameters:
width- pixel column count; must be greater than zeroheight- pixel row count; must be greater than zero- Returns:
- compatible SkSurface or null
-
makeImageSnapshot
@NotNull public @NotNull Image makeImageSnapshot()
Returns Image capturing Surface contents.
Subsequent drawing to Surface contents are not captured. Image allocation is accounted for if Surface was created with SkBudgeted::kYes.
- Returns:
- Image initialized with Surface contents
- See Also:
- https://fiddle.skia.org/c/@Surface_makeImageSnapshot
-
makeImageSnapshot
@Nullable public @Nullable Image makeImageSnapshot(@NotNull @NotNull io.github.humbleui.types.IRect area)
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 null.
- If bounds == the surface, then this is the same as calling the no-parameter variant.
- Returns:
- Image initialized with Surface contents or null
- See Also:
- https://fiddle.skia.org/c/@Surface_makeImageSnapshot_2
-
draw
public void draw(Canvas canvas, int x, int y, Paint paint)
Draws Surface contents to canvas, with its top-left corner at (x, y).
If Paint paint is not null, apply ColorFilter, alpha, ImageFilter, and BlendMode.
- Parameters:
canvas- Canvas drawn intox- horizontal offset in Canvasy- vertical offset in Canvaspaint- Paint containing BlendMode, ColorFilter, ImageFilter, and so on; or null- See Also:
- https://fiddle.skia.org/c/@Surface_draw
-
peekPixels
public boolean peekPixels(@NotNull @NotNull Pixmap pixmap)
-
readPixels
public boolean readPixels(Pixmap pixmap, int srcX, int srcY)
-
readPixels
public boolean readPixels(Bitmap bitmap, int srcX, int srcY)
Copies Rect of pixels from Surface into bitmap.
Source Rect corners are (srcX, srcY) and Surface (width(), height()). Destination Rect 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 Surface is raster, or backed by a GPU.
The destination pixel storage must be allocated by the caller.
Pixel values are converted only if ColorType and AlphaType do not match. Only pixels within both source and destination rectangles are copied. dst contents outside Rect 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.
- Surface pixels 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.
- Parameters:
bitmap- storage for pixels copied from SkSurfacesrcX- offset into readable pixels on x-axis; may be negativesrcY- offset into readable pixels on y-axis; may be negative- Returns:
- true if pixels were copied
- See Also:
- https://fiddle.skia.org/c/@Surface_readPixels_3
-
writePixels
public void writePixels(Pixmap pixmap, int x, int y)
-
writePixels
public void writePixels(Bitmap bitmap, int x, int y)
Copies Rect of pixels from the src Bitmap to the Surface.
Source Rect corners are (0, 0) and (src.width(), src.height()). Destination Rect corners are (dstX, dstY) and (dstX + Surface width(), dstY + Surface height()).
Copies each readable pixel intersecting both rectangles, without scaling, converting to Surface colorType() and Surface alphaType() if required.
- Parameters:
bitmap- storage for pixels to copy to Surfacex- x-axis position relative to Surface to begin copy; may be negativey- y-axis position relative to Surface to begin copy; may be negative- See Also:
- https://fiddle.skia.org/c/@Surface_writePixels_2
-
flushAndSubmit
public void flushAndSubmit()
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). DirectContext has additional flush and submit methods that apply to all surfaces and images created from a DirectContext.
-
flushAndSubmit
public void flushAndSubmit(boolean syncCpu)
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). DirectContext has additional flush and submit methods that apply to all surfaces and images created from a DirectContext.
- Parameters:
syncCpu- a flag determining if cpu should be synced
-
flush
public void flush()
-
isUnique
public boolean isUnique()
May return true if the caller is the only owner.
Ensures that all previous owner's actions are complete.
-
_nWrapPixels
public static long _nWrapPixels(int width, int height, int colorType, int alphaType, long colorSpacePtr, long pixelsPtr, long rowBytes, SurfaceProps surfaceProps)
-
_nWrapPixelsPixmap
public static long _nWrapPixelsPixmap(long pixmapPtr, SurfaceProps surfaceProps)
-
_nMakeRaster
public static long _nMakeRaster(int width, int height, int colorType, int alphaType, long colorSpacePtr, long rowBytes, SurfaceProps surfaceProps)
-
_nWrapBackendRenderTarget
public static long _nWrapBackendRenderTarget(long pContext, long pBackendRenderTarget, int surfaceOrigin, int colorType, long colorSpacePtr, SurfaceProps surfaceProps)
-
_nWrapMTKView
public static long _nWrapMTKView(long contextPtr, long mtkViewPtr, int surfaceOrigin, int sampleCount, int colorType, long colorSpacePtr, SurfaceProps surfaceProps)
-
_nMakeRenderTarget
public static long _nMakeRenderTarget(long contextPtr, boolean budgeted, int width, int height, int colorType, int alphaType, long colorSpacePtr, int sampleCount, int surfaceOrigin, SurfaceProps surfaceProps, boolean shouldCreateWithMips)
-
_nMakeNull
public static long _nMakeNull(int width, int height)
-
_nGetWidth
public static int _nGetWidth(long ptr)
-
_nGetHeight
public static int _nGetHeight(long ptr)
-
_nGetImageInfo
public static ImageInfo _nGetImageInfo(long ptr)
-
_nGenerationId
public static int _nGenerationId(long ptr)
-
_nNotifyContentWillChange
public static void _nNotifyContentWillChange(long ptr, int mode)
-
_nGetRecordingContext
public static long _nGetRecordingContext(long ptr)
-
_nGetCanvas
public static long _nGetCanvas(long ptr)
-
_nMakeSurfaceI
public static long _nMakeSurfaceI(long ptr, int width, int height, int colorType, int alphaType, long colorSpacePtr)
-
_nMakeSurface
public static long _nMakeSurface(long ptr, int width, int height)
-
_nMakeImageSnapshot
public static long _nMakeImageSnapshot(long ptr)
-
_nMakeImageSnapshotR
public static long _nMakeImageSnapshotR(long ptr, int left, int top, int right, int bottom)
-
_nDraw
public static void _nDraw(long ptr, long canvasPtr, float x, float y, long paintPtr)
-
_nPeekPixels
public static boolean _nPeekPixels(long ptr, long pixmapPtr)
-
_nReadPixelsToPixmap
public static boolean _nReadPixelsToPixmap(long ptr, long pixmapPtr, int srcX, int srcY)
-
_nReadPixels
public static boolean _nReadPixels(long ptr, long bitmapPtr, int srcX, int srcY)
-
_nWritePixelsFromPixmap
public static void _nWritePixelsFromPixmap(long ptr, long pixmapPtr, int x, int y)
-
_nWritePixels
public static void _nWritePixels(long ptr, long bitmapPtr, int x, int y)
-
_nFlushAndSubmit
public static void _nFlushAndSubmit(long ptr, boolean syncCpu)
-
_nFlush
public static void _nFlush(long ptr)
-
_nUnique
public static boolean _nUnique(long ptr)
-
-