Type Definition skia_safe::gpu::DirectContext
source · pub type DirectContext = RCHandle<GrDirectContext>;
Implementations§
source§impl DirectContext
impl DirectContext
pub fn new_gl<'a>( interface: impl Into<Option<Interface>>, options: impl Into<Option<&'a ContextOptions>> ) -> Option<DirectContext>
pub fn reset(&mut self, backend_state: Option<u32>) -> &mut Self
pub fn reset_gl_texture_bindings(&mut self) -> &mut Self
pub fn abandon(&mut self) -> &mut Self
pub fn oomed(&mut self) -> bool
pub fn release_resources_and_abandon(&mut self) -> &mut Self
pub fn resource_cache_limits(&self) -> ResourceCacheLimits
pub fn resource_cache_limit(&self) -> usize
pub fn resource_cache_usage(&self) -> ResourceCacheUsage
pub fn resource_cache_purgeable_bytes(&self) -> usize
pub fn set_resource_cache_limits(&mut self, limits: ResourceCacheLimits)
pub fn set_resource_cache_limit(&mut self, max_resource_bytes: usize)
pub fn free_gpu_resources(&mut self) -> &mut Self
pub fn perform_deferred_cleanup( &mut self, not_used: Duration, scratch_resources_only: impl Into<Option<bool>> ) -> &mut Self
pub fn purge_unlocked_resources( &mut self, bytes_to_purge: Option<usize>, prefer_scratch_resources: bool ) -> &mut Self
pub fn flush_and_submit(&mut self) -> &mut Self
pub fn flush_submit_and_sync_cpu(&mut self) -> &mut Self
pub fn flush_with_info(&mut self, info: &FlushInfo) -> SemaphoresSubmitted
pub fn flush<'a>( &mut self, info: impl Into<Option<&'a FlushInfo>> ) -> SemaphoresSubmitted
pub fn flush_image_with_info( &mut self, image: &Image, info: &FlushInfo ) -> SemaphoresSubmitted
pub fn flush_image(&mut self, image: &Image)
pub fn flush_and_submit_image(&mut self, image: &Image)
pub fn submit(&mut self, sync_cpu: impl Into<Option<bool>>) -> bool
pub fn check_async_work_completion(&mut self)
pub fn supports_distance_field_text(&self) -> bool
pub fn compressed_backend_format( &self, compression: TextureCompressionType ) -> BackendFormat
pub fn set_backend_texture_state( &mut self, backend_texture: &BackendTexture, state: &MutableTextureState ) -> bool
pub fn set_backend_texture_state_and_return_previous( &mut self, backend_texture: &BackendTexture, state: &MutableTextureState ) -> Option<MutableTextureState>
pub fn set_backend_render_target_state( &mut self, target: &BackendRenderTarget, state: &MutableTextureState ) -> bool
pub fn set_backend_render_target_state_and_return_previous( &mut self, target: &BackendRenderTarget, state: &MutableTextureState ) -> Option<MutableTextureState>
pub fn precompile_shader(&mut self, key: &Data, data: &Data) -> bool
pub fn id(&self) -> DirectContextId
Methods from Deref<Target = RecordingContext>§
pub fn to_a_color_mode(&self) -> Option<(Color, BlendMode)>
pub fn to_a_color_matrix(&self) -> Option<[scalar; 20]>
pub fn is_alpha_unchanged(&self) -> bool
pub fn filter_color(&self, color: impl Into<Color>) -> Color
pub fn filter_color4f( &self, color: impl AsRef<Color4f>, src_color_space: &ColorSpace, dst_color_space: Option<&ColorSpace> ) -> Color4f
pub fn composed(&self, inner: impl Into<ColorFilter>) -> Option<Self>
pub fn to_xyzd50_hash(&self) -> XYZD50Hash
pub fn with_linear_gamma(&self) -> Self
pub fn with_srgb_gamma(&self) -> Self
pub fn with_color_spin(&self) -> Self
pub fn is_srgb(&self) -> bool
pub fn serialize(&self) -> Data
pub fn length(&self) -> scalar
pub fn pos_tan(&self, distance: scalar) -> Option<(Point, Vector)>
pub fn get_matrix( &self, distance: scalar, flags: impl Into<Option<MatrixFlags>> ) -> Option<Matrix>
pub fn segment( &self, start_d: scalar, stop_d: scalar, start_with_move_to: bool ) -> Option<Path>
pub fn is_closed(&self) -> bool
pub fn size(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn as_bytes(&self) -> &[u8] ⓘ
pub fn copy_range(&self, offset: usize, buffer: &mut [u8]) -> &Self
pub fn is_empty(&self) -> bool
pub fn count(&self) -> usize
pub fn at_size(&self, index: usize) -> usize
pub fn at(&self, index: usize) -> &[u8] ⓘ
pub unsafe fn at_t<T: Copy>(&self, index: usize) -> &[T]
pub fn at_str(&self, index: usize) -> &CStr
pub fn iter(&self) -> Iter<'_> ⓘ
pub fn draw(&mut self, canvas: &mut Canvas, matrix: Option<&Matrix>)
pub fn draw_at(&mut self, canvas: &mut Canvas, point: impl Into<Point>)
pub fn snap_gpu_draw_handler( &mut self, api: BackendAPI, matrix: &Matrix, clip_bounds: impl Into<IRect>, buffer_info: &ImageInfo ) -> Option<GPUDrawHandler>
pub fn make_picture_snapshot(&mut self) -> Picture
pub fn generation_id(&mut self) -> u32
pub fn bounds(&mut self) -> Rect
pub fn approximate_bytes_used(&mut self) -> usize
pub fn notify_drawing_changed(&mut self)
pub fn count(&mut self) -> usize
pub fn style(&mut self, index: usize) -> (FontStyle, Option<String>)
pub fn new_typeface(&mut self, index: usize) -> Option<Typeface>
pub fn match_style( &mut self, index: usize, pattern: FontStyle ) -> Option<Typeface>
pub fn count_families(&self) -> usize
pub fn family_name(&self, index: usize) -> String
pub fn family_names(&self) -> impl Iterator<Item = String> + '_
pub fn new_styleset(&self, index: usize) -> FontStyleSet
pub fn new_style_set(&self, index: usize) -> FontStyleSet
pub fn match_family(&self, family_name: impl AsRef<str>) -> FontStyleSet
pub fn match_family_style( &self, family_name: impl AsRef<str>, style: FontStyle ) -> Option<Typeface>
pub fn match_family_style_character( &self, family_name: impl AsRef<str>, style: FontStyle, bcp_47: &[&str], character: Unichar ) -> Option<Typeface>
pub fn match_face_style( &self, _typeface: impl AsRef<Typeface>, _style: FontStyle ) -> !
pub fn new_from_data( &self, bytes: &[u8], ttc_index: impl Into<Option<usize>> ) -> Option<Typeface>
sourcepub fn image_info(&self) -> &ImageInfo
pub fn image_info(&self) -> &ImageInfo
sourcepub fn dimensions(&self) -> ISize
pub fn dimensions(&self) -> ISize
Returns ISize
{ width(), height() }
.
Returns: integral size of width()
and height()
sourcepub fn bounds(&self) -> IRect
pub fn bounds(&self) -> IRect
Returns IRect
{ 0, 0, width(), height() }
.
Returns: integral rectangle from origin to width()
and height()
sourcepub fn alpha_type(&self) -> AlphaType
pub fn alpha_type(&self) -> AlphaType
sourcepub fn color_type(&self) -> ColorType
pub fn color_type(&self) -> ColorType
Returns ColorType
if known; otherwise, returns ColorType::Unknown
.
sourcepub fn color_space(&self) -> ColorSpace
pub fn color_space(&self) -> ColorSpace
Returns a smart pointer to ColorSpace
, the range of colors, associated with
Image
. The smart pointer tracks the number of objects sharing this
ColorSpace
reference so the memory is released when the owners destruct.
The returned ColorSpace
is immutable.
ColorSpace
returned was passed to an Image
constructor,
or was parsed from encoded data. ColorSpace
returned may be ignored when Image
is drawn, depending on the capabilities of the crate::Surface
receiving the drawing.
Returns: ColorSpace
in Image
, or None
, wrapped in a smart pointer
sourcepub fn is_alpha_only(&self) -> bool
pub fn is_alpha_only(&self) -> bool
Returns true
if Image
pixels represent transparency only. If true
, each pixel
is packed in 8 bits as defined by ColorType::Alpha8
.
Returns: true
if pixels represent a transparency mask
sourcepub fn is_opaque(&self) -> bool
pub fn is_opaque(&self) -> bool
Returns true
if pixels ignore their alpha value and are treated as fully opaque.
Returns: true
if AlphaType
is AlphaType::Opaque
sourcepub fn to_shader<'a>(
&self,
tile_modes: impl Into<Option<(TileMode, TileMode)>>,
sampling: impl Into<SamplingOptions>,
local_matrix: impl Into<Option<&'a Matrix>>
) -> Option<Shader>
pub fn to_shader<'a>( &self, tile_modes: impl Into<Option<(TileMode, TileMode)>>, sampling: impl Into<SamplingOptions>, local_matrix: impl Into<Option<&'a Matrix>> ) -> Option<Shader>
Make a shader with the specified tiling and mipmap sampling.
sourcepub fn to_raw_shader<'a>(
&self,
tile_modes: impl Into<Option<(TileMode, TileMode)>>,
sampling: impl Into<SamplingOptions>,
local_matrix: impl Into<Option<&'a Matrix>>
) -> Option<Shader>
pub fn to_raw_shader<'a>( &self, tile_modes: impl Into<Option<(TileMode, TileMode)>>, sampling: impl Into<SamplingOptions>, local_matrix: impl Into<Option<&'a Matrix>> ) -> Option<Shader>
to_raw_shader
functions like to_shader
, but for images that contain non-color data.
This includes images encoding things like normals, material properties (eg, roughness),
heightmaps, or any other purely mathematical data that happens to be stored in an image.
These types of images are useful with some programmable shaders (see: crate::RuntimeEffect
).
Raw image shaders work like regular image shaders (including filtering and tiling), with a few major differences:
- No color space transformation is ever applied (the color space of the image is ignored).
- Images with an alpha type of
Unpremul
are not automatically premultiplied. - Bicubic filtering is not supported. If
SamplingOptions::use_cubic
istrue
, these factories will returnNone
.
sourcepub fn peek_pixels(&self) -> Option<Pixmap<'_>>
pub fn peek_pixels(&self) -> Option<Pixmap<'_>>
Copies Image
pixel address, row bytes, and ImageInfo
to pixmap, if address
is available, and returns true
. If pixel address is not available, return
false
and leave pixmap unchanged.
pixmap
storage for pixel state if pixels are readable; otherwise, ignored Returns:true
ifImage
has direct access to pixels
sourcepub fn is_texture_backed(&self) -> bool
pub fn is_texture_backed(&self) -> bool
sourcepub fn texture_size(&self) -> usize
pub fn texture_size(&self) -> usize
Returns an approximation of the amount of texture memory used by the image. Returns zero if the image is not texture backed or if the texture has an external format.
sourcepub fn is_valid(&self, context: &mut RecordingContext) -> bool
pub fn is_valid(&self, context: &mut RecordingContext) -> bool
Returns true
if Image
can be drawn on either raster surface or GPU surface.
If context is None
, tests if Image
draws on raster surface;
otherwise, tests if Image
draws on GPU surface associated with context.
Image
backed by GPU texture may become invalid if associated context is
invalid. lazy image may be invalid and may not draw to raster surface or
GPU surface or both.
context
GPU context Returns:true
ifImage
can be drawn
sourcepub fn flush<'a>(
&self,
context: &mut DirectContext,
flush_info: impl Into<Option<&'a FlushInfo>>
) -> SemaphoresSubmitted
👎Deprecated since 0.63.0: use gpu::DirectContext::flush()
pub fn flush<'a>( &self, context: &mut DirectContext, flush_info: impl Into<Option<&'a FlushInfo>> ) -> SemaphoresSubmitted
sourcepub fn flush_with_info(
&self,
context: &mut DirectContext,
flush_info: &FlushInfo
) -> SemaphoresSubmitted
👎Deprecated since 0.46.0: use gpu::DirectContext::flush()
pub fn flush_with_info( &self, context: &mut DirectContext, flush_info: &FlushInfo ) -> SemaphoresSubmitted
Flushes any pending uses of texture-backed images in the GPU backend. If the image is not
texture-backed (including promise texture images) or if the gpu::DirectContext
does not
have the same context ID as the context backing the image then this is a no-op.
If the image was not used in any non-culled draws in the current queue of work for the
passed gpu::DirectContext
then this is a no-op unless the gpu::FlushInfo
contains semaphores or
a finish proc. Those are respected even when the image has not been used.
context
the context on which to flush pending usages of the image.info
flush options
sourcepub fn flush_and_submit(&self, context: &mut DirectContext)
👎Deprecated since 0.63.0: use gpu::DirectContext::flush_and_submit()
pub fn flush_and_submit(&self, context: &mut DirectContext)
Version of flush()
that uses a default gpu::FlushInfo
. Also submits the flushed work to the
GPU.
sourcepub fn backend_texture(
&self,
flush_pending_gr_context_io: bool
) -> Option<(BackendTexture, SurfaceOrigin)>
👎Deprecated since 0.63.0: use gpu::images::get_backend_texture_from_image()
pub fn backend_texture( &self, flush_pending_gr_context_io: bool ) -> Option<(BackendTexture, SurfaceOrigin)>
Retrieves the back-end texture. If Image
has no back-end texture, None
is returned.
If flush_pending_gr_context_io
is true
, completes deferred I/O operations.
If origin in not None
, copies location of content drawn into Image
.
flush_pending_gr_context_io
flag to flush outstanding requests Returns: back-end API texture handle; invalid on failure
sourcepub fn read_pixels_with_context<'a, P>(
&self,
context: impl Into<Option<&'a mut DirectContext>>,
dst_info: &ImageInfo,
pixels: &mut [P],
dst_row_bytes: usize,
src: impl Into<IPoint>,
caching_hint: CachingHint
) -> bool
pub fn read_pixels_with_context<'a, P>( &self, context: impl Into<Option<&'a mut DirectContext>>, dst_info: &ImageInfo, pixels: &mut [P], dst_row_bytes: usize, src: impl Into<IPoint>, caching_hint: CachingHint ) -> bool
Copies crate::Rect
of pixels from Image
to dst_pixels
. Copy starts at offset (src_x
, src_y
),
and does not exceed Image
(width(), height()).
dst_info
specifies width, height, ColorType
, AlphaType
, and ColorSpace
of
destination. dst_row_bytes
specifies the gap from one destination row to the next.
Returns true
if pixels are copied. Returns false
if:
dst_info
.addr()
equalsNone
dst_row_bytes
is less thandst_info.min_row_bytes()
crate::PixelRef
isNone
Pixels are copied only if pixel conversion is possible. If Image
ColorType
is
ColorType::Gray8
, or ColorType::Alpha8
; dst_info.color_type()
must match.
If Image
ColorType
is ColorType::Gray8
, dst_info
.color_space()
must match.
If Image
AlphaType
is AlphaType::Opaque
, dst_info
.alpha_type()
must
match. If Image
ColorSpace
is None
, dst_info.color_space()
must match. Returns
false
if pixel conversion is not possible.
src_x
and src_y
may be negative to copy only top or left of source. Returns
false
if width()
or height()
is zero or negative.
Returns false
if abs(src_x
) >= Image width(), or if abs(src_y
) >= Image height().
If caching_hint
is CachingHint::Allow
, pixels may be retained locally.
If caching_hint
is CachingHint::Disallow
, pixels are not added to the local cache.
context
thegpu::DirectContext
in play, if it existsdst_info
destination width, height,ColorType
,AlphaType
,ColorSpace
dst_pixels
destination pixel storagedst_row_bytes
destination row lengthsrc_x
column index whose absolute value is less thanwidth()
src_y
row index whose absolute value is less thanheight()
caching_hint
whether the pixels should be cached locally Returns:true
if pixels are copied todst_pixels
sourcepub fn read_pixels_to_pixmap_with_context<'a>(
&self,
context: impl Into<Option<&'a mut DirectContext>>,
dst: &Pixmap<'_>,
src: impl Into<IPoint>,
caching_hint: CachingHint
) -> bool
pub fn read_pixels_to_pixmap_with_context<'a>( &self, context: impl Into<Option<&'a mut DirectContext>>, dst: &Pixmap<'_>, src: impl Into<IPoint>, caching_hint: CachingHint ) -> bool
Copies a crate::Rect
of pixels from Image
to dst. Copy starts at (src_x
, src_y
), and
does not exceed Image
(width(), height()).
dst specifies width, height, ColorType
, AlphaType
, ColorSpace
, pixel storage,
and row bytes of destination. dst.row_bytes()
specifics the gap from one destination
row to the next. Returns true
if pixels are copied. Returns false
if:
- dst pixel storage equals
None
- dst.
row_bytes
is less thanImageInfo::min_row_bytes
crate::PixelRef
isNone
Pixels are copied only if pixel conversion is possible. If Image
ColorType
is
ColorType::Gray8
, or ColorType::Alpha8
; dst.color_type()
must match.
If Image
ColorType
is ColorType::Gray8
, dst.color_space()
must match.
If Image
AlphaType
is AlphaType::Opaque
, dst.alpha_type()
must
match. If Image
ColorSpace
is None
, dst.color_space()
must match. Returns
false
if pixel conversion is not possible.
src_x
and src_y
may be negative to copy only top or left of source. Returns
false
if width()
or height()
is zero or negative.
Returns false
if abs(src_x
) >= Image width(), or if abs(src_y
) >= Image height().
If caching_hint
is CachingHint::Allow
, pixels may be retained locally.
If caching_hint
is CachingHint::Disallow
, pixels are not added to the local cache.
context
thegpu::DirectContext
in play, if it existsdst
destinationPixmap
:ImageInfo
, pixels, row bytessrc_x
column index whose absolute value is less thanwidth()
src_y
row index whose absolute value is less thanheight()
caching_hint
whether the pixels should be cachedlocally_z
Returns:true
if pixels are copied to dst
sourcepub fn read_pixels<P>(
&self,
dst_info: &ImageInfo,
pixels: &mut [P],
dst_row_bytes: usize,
src: impl Into<IPoint>,
caching_hint: CachingHint
) -> bool
pub fn read_pixels<P>( &self, dst_info: &ImageInfo, pixels: &mut [P], dst_row_bytes: usize, src: impl Into<IPoint>, caching_hint: CachingHint ) -> bool
sourcepub unsafe fn read_pixels_to_pixmap(
&self,
dst: &Pixmap<'_>,
src: impl Into<IPoint>,
caching_hint: CachingHint
) -> bool
pub unsafe fn read_pixels_to_pixmap( &self, dst: &Pixmap<'_>, src: impl Into<IPoint>, caching_hint: CachingHint ) -> bool
sourcepub fn scale_pixels(
&self,
dst: &Pixmap<'_>,
sampling: impl Into<SamplingOptions>,
caching_hint: impl Into<Option<CachingHint>>
) -> bool
pub fn scale_pixels( &self, dst: &Pixmap<'_>, sampling: impl Into<SamplingOptions>, caching_hint: impl Into<Option<CachingHint>> ) -> bool
Copies Image
to dst, scaling pixels to fit dst.width()
and dst.height()
, and
converting pixels to match dst.color_type()
and dst.alpha_type()
. Returns true
if
pixels are copied. Returns false
if dst.addr()
is None
, or dst.row_bytes()
is
less than dst ImageInfo::min_row_bytes
.
Pixels are copied only if pixel conversion is possible. If Image
ColorType
is
ColorType::Gray8
, or ColorType::Alpha8
; dst.color_type()
must match.
If Image
ColorType
is ColorType::Gray8
, dst.color_space()
must match.
If Image
AlphaType
is AlphaType::Opaque
, dst.alpha_type()
must
match. If Image
ColorSpace
is None
, dst.color_space()
must match. Returns
false
if pixel conversion is not possible.
If caching_hint
is CachingHint::Allow
, pixels may be retained locally.
If caching_hint
is CachingHint::Disallow
, pixels are not added to the local cache.
sourcepub fn encode_to_data_with_context(
&self,
context: impl Into<Option<DirectContext>>,
image_format: EncodedImageFormat,
quality: impl Into<Option<u32>>
) -> Option<Data>
👎Deprecated since 0.63.0: Use encode
pub fn encode_to_data_with_context( &self, context: impl Into<Option<DirectContext>>, image_format: EncodedImageFormat, quality: impl Into<Option<u32>> ) -> Option<Data>
Encodes Image
pixels, returning result as Data
.
Returns None
if encoding fails, or if encoded_image_format
is not supported.
Image
encoding in a format requires both building with one or more of:
SK_ENCODE_JPEG, SK_ENCODE_PNG, SK_ENCODE_WEBP; and platform support
for the encoded format.
If SK_BUILD_FOR_MAC or SK_BUILD_FOR_IOS is defined, encoded_image_format
can
additionally be one of: EncodedImageFormat::ICO
, EncodedImageFormat::BMP
,
EncodedImageFormat::GIF
.
quality is a platform and format specific metric trading off size and encoding error. When used, quality equaling 100 encodes with the least error. quality may be ignored by the encoder.
context
- thegpu::DirectContext
in play, if it exists; can beNone
encoded_image_format
- one of:EncodedImageFormat::JPEG
,EncodedImageFormat::PNG
,EncodedImageFormat::WEBP
quality
- encoder specific metric with 100 equaling best Returns: encodedImage
, orNone
sourcepub fn encode_to_data(&self, image_format: EncodedImageFormat) -> Option<Data>
👎Deprecated since 0.63.0: Support for encoding GPU backed images without a context was removed, use encode_to_data_with_context
instead
pub fn encode_to_data(&self, image_format: EncodedImageFormat) -> Option<Data>
encode_to_data_with_context
insteadsourcepub fn encode_to_data_with_quality(
&self,
image_format: EncodedImageFormat,
quality: u32
) -> Option<Data>
👎Deprecated since 0.63.0: Support for encoding GPU backed images without a context was removed, use encode_to_data_with_context
instead
pub fn encode_to_data_with_quality( &self, image_format: EncodedImageFormat, quality: u32 ) -> Option<Data>
encode_to_data_with_context
insteadEncodes Image
pixels, returning result as Data
.
Returns None
if encoding fails, or if encoded_image_format
is not supported.
Image
encoding in a format requires both building with one or more of:
SK_ENCODE_JPEG, SK_ENCODE_PNG, SK_ENCODE_WEBP; and platform support
for the encoded format.
If SK_BUILD_FOR_MAC or SK_BUILD_FOR_IOS is defined, encoded_image_format
can
additionally be one of: EncodedImageFormat::ICO
, EncodedImageFormat::BMP
,
EncodedImageFormat::GIF
.
quality is a platform and format specific metric trading off size and encoding error. When used, quality equaling 100 encodes with the least error. quality may be ignored by the encoder.
encoded_image_format
one of:EncodedImageFormat::JPEG
,EncodedImageFormat::PNG
,EncodedImageFormat::WEBP
quality
encoder specific metric with 100 equaling best Returns: encodedImage
, orNone
sourcepub fn encoded_data(&self) -> Option<Data>
pub fn encoded_data(&self) -> Option<Data>
Returns encoded Image
pixels as Data
, if Image
was created from supported
encoded stream format. Platform support for formats vary and may require building
with one or more of: SK_ENCODE_JPEG, SK_ENCODE_PNG, SK_ENCODE_WEBP.
Returns None
if Image
contents are not encoded.
Returns: encoded Image
, or None
sourcepub fn new_subset(&self, rect: impl AsRef<IRect>) -> Option<Image>
👎Deprecated since 0.64.0: use make_subset()
pub fn new_subset(&self, rect: impl AsRef<IRect>) -> Option<Image>
sourcepub fn new_subset_with_context<'a>(
&self,
rect: impl AsRef<IRect>,
direct: impl Into<Option<&'a mut DirectContext>>
) -> Option<Image>
👎Deprecated since 0.64.0: use make_subset()
pub fn new_subset_with_context<'a>( &self, rect: impl AsRef<IRect>, direct: impl Into<Option<&'a mut DirectContext>> ) -> Option<Image>
Returns subset of this image.
Returns None
if any of the following are true:
- Subset is empty
- Subset is not contained inside the image’s bounds
- Pixels in the image could not be read or copied
If this image is texture-backed, the context parameter is required and must match the context of the source image. If the context parameter is provided, and the image is raster-backed, the subset will be converted to texture-backed.
subset
bounds of returnedImage
context
thegpu::DirectContext
in play, if it exists Returns: the subsetted image, orNone
sourcepub fn make_subset<'a>(
&self,
direct: impl Into<Option<&'a mut DirectContext>>,
subset: impl AsRef<IRect>
) -> Option<Image>
pub fn make_subset<'a>( &self, direct: impl Into<Option<&'a mut DirectContext>>, subset: impl AsRef<IRect> ) -> Option<Image>
Returns subset of this image.
Returns None
if any of the following are true:
- Subset is empty - Subset is not contained inside the image’s bounds
- Pixels in the source image could not be read or copied
- This image is texture-backed and the provided context is null or does not match the
source image’s context.
If the source image was texture-backed, the resulting image will be texture-backed also. Otherwise, the returned image will be raster-backed.
direct
- thegpu::DirectContext
of the source image (None
is ok if the source image is not texture-backed).subset
- bounds of returnedImage
Returns: the subsetted image, orNone
sourcepub fn has_mipmaps(&self) -> bool
pub fn has_mipmaps(&self) -> bool
Returns true
if the image has mipmap levels.
sourcepub fn with_default_mipmaps(&self) -> Option<Image>
pub fn with_default_mipmaps(&self) -> Option<Image>
Returns an image with the same “base” pixels as the this image, but with mipmap levels automatically generated and attached.
sourcepub fn new_texture_image(
&self,
context: &mut DirectContext,
mipmapped: Mipmapped
) -> Option<Image>
pub fn new_texture_image( &self, context: &mut DirectContext, mipmapped: Mipmapped ) -> Option<Image>
sourcepub fn new_texture_image_budgeted(
&self,
direct_context: &mut DirectContext,
mipmapped: Mipmapped,
budgeted: Budgeted
) -> Option<Image>
pub fn new_texture_image_budgeted( &self, direct_context: &mut DirectContext, mipmapped: Mipmapped, budgeted: Budgeted ) -> Option<Image>
Returns Image
backed by GPU texture associated with context. Returned Image
is
compatible with crate::Surface
created with dst_color_space
. The returned Image
respects
mipmapped setting; if mipmapped equals gpu::Mipmapped::Yes
, the backing texture
allocates mip map levels.
The mipmapped parameter is effectively treated as No
if MIP maps are not supported by the
GPU.
Returns original Image
if the image is already texture-backed, the context matches, and
mipmapped is compatible with the backing GPU texture. crate::Budgeted
is ignored in this case.
Returns None
if context is None
, or if Image
was created with another
gpu::DirectContext
.
direct_context
thegpu::DirectContext
in play, if it existsmipmapped
whether createdImage
texture must allocate mip map levelsbudgeted
whether to count a newly created texture for the returned image counts against the context’s budget. Returns: createdImage
, orNone
sourcepub fn to_non_texture_image(&self) -> Option<Image>
👎Deprecated since 0.64.0: use make_non_texture_image()
pub fn to_non_texture_image(&self) -> Option<Image>
Returns raster image or lazy image. Copies Image
backed by GPU texture into
CPU memory if needed. Returns original Image
if decoded in raster bitmap,
or if encoded in a stream.
Returns None
if backed by GPU texture and copy fails.
Returns: raster image, lazy image, or None
example: https://fiddle.skia.org/c/@Image_makeNonTextureImage
sourcepub fn make_non_texture_image<'a>(
&self,
context: impl Into<Option<&'a mut DirectContext>>
) -> Option<Image>
pub fn make_non_texture_image<'a>( &self, context: impl Into<Option<&'a mut DirectContext>> ) -> Option<Image>
Returns raster image or lazy image. Copies Image
backed by GPU texture into
CPU memory if needed. Returns original Image
if decoded in raster bitmap,
or if encoded in a stream.
Returns None
if backed by GPU texture and copy fails.
Returns: raster image, lazy image, or None
example: https://fiddle.skia.org/c/@Image_makeNonTextureImage
sourcepub fn to_raster_image(
&self,
caching_hint: impl Into<Option<CachingHint>>
) -> Option<Image>
👎Deprecated since 0.64.0: use make_raster_image()
pub fn to_raster_image( &self, caching_hint: impl Into<Option<CachingHint>> ) -> Option<Image>
Returns raster image. Copies Image
backed by GPU texture into CPU memory,
or decodes Image
from lazy image. Returns original Image
if decoded in
raster bitmap.
Returns None
if copy, decode, or pixel read fails.
If caching_hint
is CachingHint::Allow
, pixels may be retained locally.
If caching_hint
is CachingHint::Disallow
, pixels are not added to the local cache.
Returns: raster image, or None
sourcepub fn make_raster_image<'a>(
&self,
context: impl Into<Option<&'a mut DirectContext>>,
caching_hint: impl Into<Option<CachingHint>>
) -> Option<Image>
pub fn make_raster_image<'a>( &self, context: impl Into<Option<&'a mut DirectContext>>, caching_hint: impl Into<Option<CachingHint>> ) -> Option<Image>
Returns raster image. Copies Image
backed by GPU texture into CPU memory,
or decodes Image
from lazy image. Returns original Image
if decoded in
raster bitmap.
Returns None
if copy, decode, or pixel read fails.
If caching_hint
is CachingHint::Allow
, pixels may be retained locally.
If caching_hint
is CachingHint::Disallow
, pixels are not added to the local cache.
Returns: raster image, or None
sourcepub fn new_with_filter(
&self,
context: Option<&mut RecordingContext>,
filter: &ImageFilter,
clip_bounds: impl Into<IRect>,
subset: impl Into<IRect>
) -> Option<(Image, IRect, IPoint)>
pub fn new_with_filter( &self, context: Option<&mut RecordingContext>, filter: &ImageFilter, clip_bounds: impl Into<IRect>, subset: impl Into<IRect> ) -> Option<(Image, IRect, IPoint)>
Creates filtered Image
. filter processes original Image
, potentially changing
color, position, and size. subset is the bounds of original Image
processed
by filter. clip_bounds
is the expected bounds of the filtered Image
. out_subset
is required storage for the actual bounds of the filtered Image
. offset is
required storage for translation of returned Image
.
Returns None
if Image
could not be created or if the recording context provided doesn’t
match the GPU context in which the image was created. If None
is returned, out_subset
and offset are undefined.
Useful for animation of ImageFilter
that varies size from frame to frame.
Returned Image
is created larger than required by filter so that GPU texture
can be reused with different sized effects. out_subset
describes the valid bounds
of GPU texture returned. offset translates the returned Image
to keep subsequent
animation frames aligned with respect to each other.
context
thegpu::RecordingContext
in play - if it existsfilter
howImage
is sampled when transformedsubset
bounds ofImage
processed by filterclip_bounds
expected bounds of filteredImage
out_subset
storage for returnedImage
boundsoffset
storage for returnedImage
translation Returns: filteredImage
, orNone
sourcepub fn is_lazy_generated(&self) -> bool
pub fn is_lazy_generated(&self) -> bool
Returns true
if Image
is backed by an image-generator or other service that creates
and caches its pixels or texture on-demand.
Returns: true
if Image
is created as needed
example: https://fiddle.skia.org/c/@Image_isLazyGenerated_a example: https://fiddle.skia.org/c/@Image_isLazyGenerated_b
sourcepub fn new_color_space(
&self,
color_space: impl Into<Option<ColorSpace>>
) -> Option<Image>
👎Deprecated since 0.64.0: use make_color_space()
pub fn new_color_space( &self, color_space: impl Into<Option<ColorSpace>> ) -> Option<Image>
sourcepub fn new_color_space_with_context<'a>(
&self,
color_space: impl Into<Option<ColorSpace>>,
direct: impl Into<Option<&'a mut DirectContext>>
) -> Option<Image>
👎Deprecated since 0.64.0: use make_color_space()
pub fn new_color_space_with_context<'a>( &self, color_space: impl Into<Option<ColorSpace>>, direct: impl Into<Option<&'a mut DirectContext>> ) -> Option<Image>
Creates Image
in target ColorSpace
.
Returns None
if Image
could not be created.
Returns original Image
if it is in target ColorSpace
.
Otherwise, converts pixels from Image
ColorSpace
to target ColorSpace
.
If Image
color_space()
returns None
, Image
ColorSpace
is assumed to be s_rgb
.
If this image is texture-backed, the context parameter is required and must match the context of the source image.
target
ColorSpace
describing color range of returnedImage
direct
Thegpu::DirectContext
in play, if it exists Returns: createdImage
in targetColorSpace
sourcepub fn make_color_space<'a>(
&self,
direct: impl Into<Option<&'a mut DirectContext>>,
color_space: impl Into<Option<ColorSpace>>
) -> Option<Image>
pub fn make_color_space<'a>( &self, direct: impl Into<Option<&'a mut DirectContext>>, color_space: impl Into<Option<ColorSpace>> ) -> Option<Image>
Creates Image
in target ColorSpace
.
Returns None
if Image
could not be created.
Returns original Image
if it is in target ColorSpace
.
Otherwise, converts pixels from Image
ColorSpace
to target ColorSpace
.
If Image
color_space()
returns None
, Image
ColorSpace
is assumed to be s_rgb
.
If this image is texture-backed, the context parameter is required and must match the context of the source image.
direct
Thegpu::DirectContext
in play, if it existstarget
ColorSpace
describing color range of returnedImage
Returns: createdImage
in targetColorSpace
sourcepub fn reinterpret_color_space(
&self,
new_color_space: impl Into<ColorSpace>
) -> Option<Image>
pub fn reinterpret_color_space( &self, new_color_space: impl Into<ColorSpace> ) -> Option<Image>
Creates a new Image
identical to this one, but with a different ColorSpace
.
This does not convert the underlying pixel data, so the resulting image will draw
differently.
pub fn filter_bounds<'a>( &self, src: impl AsRef<IRect>, ctm: &Matrix, map_direction: MapDirection, input_rect: impl Into<Option<&'a IRect>> ) -> IRect
pub fn color_filter_node(&self) -> Option<ColorFilter>
pub fn to_a_color_filter(&self) -> Option<ColorFilter>
pub fn count_inputs(&self) -> usize
pub fn input(&self, i: usize) -> Option<ImageFilter>
pub fn get_input(&self, i: usize) -> Option<ImageFilter>
pub fn inputs(&self) -> impl Iterator<Item = Option<ImageFilter>> + '_
pub fn compute_fast_bounds(&self, bounds: impl AsRef<Rect>) -> Rect
pub fn can_compute_fast_bounds(&self) -> bool
pub fn with_local_matrix(&self, matrix: &Matrix) -> Option<ImageFilter>
sourcepub fn approximate_filtered_bounds(&self, src: impl AsRef<Rect>) -> Rect
pub fn approximate_filtered_bounds(&self, src: impl AsRef<Rect>) -> Rect
Returns the approximate bounds that would result from filtering the src
rect. The actual
result may be different, but it should be contained within the returned bounds.
pub fn with_matrix(&self, _matrix: &Matrix) -> !
pub fn as_a_dash(&self) -> Option<DashInfo>
pub fn filter_path( &self, src: &Path, stroke_rec: &StrokeRec, cull_rect: impl AsRef<Rect> ) -> Option<(Path, StrokeRec)>
pub fn filter_path_inplace( &self, dst: &mut Path, src: &Path, stroke_rec: &mut StrokeRec, cull_rect: impl AsRef<Rect> ) -> bool
pub fn filter_path_inplace_with_matrix( &self, dst: &mut Path, src: &Path, stroke_rec: &mut StrokeRec, cull_rect: impl AsRef<Rect>, ctm: &Matrix ) -> bool
pub fn needs_ctm(&self) -> bool
pub fn playback(&self, canvas: &mut Canvas)
pub fn cull_rect(&self) -> Rect
pub fn unique_id(&self) -> u32
pub fn serialize(&self) -> Data
pub fn approximate_op_count(&self) -> usize
pub fn approximate_op_count_nested( &self, nested: impl Into<Option<bool>> ) -> usize
pub fn approximate_bytes_used(&self) -> usize
pub fn to_shader<'a, 'b>( &self, tm: impl Into<Option<(TileMode, TileMode)>>, mode: FilterMode, local_matrix: impl Into<Option<&'a Matrix>>, tile_rect: impl Into<Option<&'b Rect>> ) -> Shader
pub fn dimensions(&self) -> ISize
pub fn width(&self) -> i32
pub fn height(&self) -> i32
pub unsafe fn pixels(&self) -> *mut c_void
pub fn row_bytes(&self) -> usize
pub fn generation_id(&self) -> u32
pub fn notify_pixels_changed(&mut self)
pub fn is_immutable(&self) -> bool
pub fn set_immutable(&mut self)
pub fn notify_added_to_cache(&mut self)
pub fn is_opaque(&self) -> bool
pub fn image(&self) -> Option<(Image, Matrix, (TileMode, TileMode))>
pub fn is_a_image(&self) -> bool
pub fn with_local_matrix(&self, matrix: &Matrix) -> Self
pub fn with_color_filter(&self, color_filter: impl Into<ColorFilter>) -> Self
sourcepub fn is_compatible(&self, characterization: &SurfaceCharacterization) -> bool
pub fn is_compatible(&self, characterization: &SurfaceCharacterization) -> bool
Is this surface compatible with the provided characterization?
This method can be used to determine if an existing Surface
is a viable destination
for an DeferredDisplayList
.
characterization
- The characterization for which a compatibility check is desired Returns:true
if this surface is compatible with the characterization;false
otherwise
sourcepub fn width(&self) -> i32
pub fn width(&self) -> i32
Returns pixel count in each row; may be zero or greater.
Returns: number of pixel columns
sourcepub fn height(&self) -> i32
pub fn height(&self) -> i32
Returns pixel row count; may be zero or greater.
Returns: number of pixel rows
sourcepub fn image_info(&mut self) -> ImageInfo
pub fn image_info(&mut self) -> ImageInfo
Returns an ImageInfo
describing the surface.
sourcepub fn generation_id(&mut self) -> u32
pub fn generation_id(&mut self) -> u32
Returns unique value identifying the content of Surface
. Returned value changes
each time the content changes. Content is changed by drawing, or by calling
Self::notify_content_will_change()
.
Returns: unique content identifier
example: https://fiddle.skia.org/c/@Surface_notifyContentWillChange
sourcepub fn notify_content_will_change(
&mut self,
mode: ContentChangeMode
) -> &mut Self
pub fn notify_content_will_change( &mut self, mode: ContentChangeMode ) -> &mut Self
Notifies that Surface
contents will be changed by code outside of Skia.
Subsequent calls to Self::generation_id()
return a different value.
example: https://fiddle.skia.org/c/@Surface_notifyContentWillChange
sourcepub fn recording_context(&self) -> Option<RecordingContext>
pub fn recording_context(&self) -> Option<RecordingContext>
Returns the recording context being used by the Surface
.
Returns: the recording context, if available; None
otherwise
sourcepub fn direct_context(&self) -> Option<DirectContext>
pub fn direct_context(&self) -> Option<DirectContext>
rust-skia helper, not in Skia
sourcepub fn get_backend_texture(
&mut self,
handle_access: BackendHandleAccess
) -> Option<BackendTexture>
👎Deprecated since 0.64.0: use gpu::surfaces::get_backend_texture()
pub fn get_backend_texture( &mut self, handle_access: BackendHandleAccess ) -> Option<BackendTexture>
Retrieves the back-end texture. If Surface
has no back-end texture, None
is returned.
The returned gpu::BackendTexture
should be discarded if the Surface
is drawn to or deleted.
Returns: GPU texture reference; None
on failure
sourcepub fn get_backend_render_target(
&mut self,
handle_access: BackendHandleAccess
) -> Option<BackendRenderTarget>
👎Deprecated since 0.64.0: use gpu::surfaces::get_backend_render_target()
pub fn get_backend_render_target( &mut self, handle_access: BackendHandleAccess ) -> Option<BackendRenderTarget>
Retrieves the back-end render target. If Surface
has no back-end render target, None
is returned.
The returned gpu::BackendRenderTarget
should be discarded if the Surface
is drawn to
or deleted.
Returns: GPU render target reference; None
on failure
sourcepub fn replace_backend_texture(
&mut self,
backend_texture: &BackendTexture,
origin: SurfaceOrigin
) -> bool
pub fn replace_backend_texture( &mut self, backend_texture: &BackendTexture, origin: SurfaceOrigin ) -> bool
If the surface was made via Self::from_backend_texture
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. Canvas
state is preserved. The original sample count is
used. The gpu::BackendFormat
and dimensions of replacement texture must match that of
the original.
backend_texture
- the new backing texture for the surface
sourcepub fn replace_backend_texture_with_mode(
&mut self,
backend_texture: &BackendTexture,
origin: SurfaceOrigin,
mode: impl Into<Option<ContentChangeMode>>
) -> bool
pub fn replace_backend_texture_with_mode( &mut self, backend_texture: &BackendTexture, origin: SurfaceOrigin, mode: impl Into<Option<ContentChangeMode>> ) -> bool
If the surface was made via Self::from_backend_texture()
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. Canvas
state is preserved. The original sample count is
used. The gpu::BackendFormat
and dimensions of replacement texture must match that of
the original.
backend_texture
- the new backing texture for the surfacemode
- Retain or discard current Content
sourcepub fn new_surface(&mut self, image_info: &ImageInfo) -> Option<Self>
pub fn new_surface(&mut self, image_info: &ImageInfo) -> Option<Self>
Returns a compatible Surface
, or None
. Returned Surface
contains
the same raster, GPU, or null properties as the original. Returned Surface
does not share the same pixels.
Returns None
if image_info
width or height are zero, or if image_info
is incompatible with Surface
.
image_info
- width, height,crate::ColorType
,crate::AlphaType
,crate::ColorSpace
, ofSurface
; width and height must be greater than zero Returns: compatibleSurface
orNone
sourcepub fn new_surface_with_dimensions(
&mut self,
dim: impl Into<ISize>
) -> Option<Self>
pub fn new_surface_with_dimensions( &mut self, dim: impl Into<ISize> ) -> Option<Self>
Calls Self::new_surface()
with the same ImageInfo
as this surface, but with the
specified width and height.
sourcepub fn image_snapshot(&mut self) -> Image
pub fn image_snapshot(&mut self) -> Image
Returns Image
capturing Surface
contents. Subsequent drawing to Surface
contents
are not captured. Image
allocation is accounted for if Surface
was created with
gpu::Budgeted::Yes
.
Returns: Image
initialized with Surface
contents
example: https://fiddle.skia.org/c/@Surface_makeImageSnapshot
sourcepub fn image_snapshot_with_bounds(
&mut self,
bounds: impl AsRef<IRect>
) -> Option<Image>
pub fn image_snapshot_with_bounds( &mut self, bounds: impl AsRef<IRect> ) -> Option<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
None
. - If bounds == the surface, then this is the same as calling the no-parameter variant.
example: https://fiddle.skia.org/c/@Surface_makeImageSnapshot_2
sourcepub fn draw(
&mut self,
canvas: &mut Canvas,
offset: impl Into<Point>,
sampling: impl Into<SamplingOptions>,
paint: Option<&Paint>
)
pub fn draw( &mut self, canvas: &mut Canvas, offset: impl Into<Point>, sampling: impl Into<SamplingOptions>, paint: Option<&Paint> )
Draws Surface
contents to canvas, with its top-left corner at (offset.x, offset.y)
.
If Paint
paint is not None
, apply crate::ColorFilter
, alpha, crate::ImageFilter
, and crate::BlendMode
.
canvas
-Canvas
drawn intooffset.x
- horizontal offset inCanvas
offset.y
- vertical offset inCanvas
sampling
- what technique to use when sampling the surface pixelspaint
-Paint
containingcrate::BlendMode
,crate::ColorFilter
,crate::ImageFilter
, and so on; orNone
pub fn peek_pixels(&mut self) -> Option<Pixmap<'_>>
sourcepub fn read_pixels_to_pixmap(
&mut self,
dst: &Pixmap<'_>,
src: impl Into<IPoint>
) -> bool
pub fn read_pixels_to_pixmap( &mut self, dst: &Pixmap<'_>, src: impl Into<IPoint> ) -> bool
Copies crate::Rect
of pixels to dst.
Source crate::Rect
corners are (src.x
, src.y
) and Surface
(width(), height())
.
Destination crate::Rect
corners are (0, 0)
and (dst.width(), dst.height())
.
Copies each readable pixel intersecting both rectangles, without scaling,
converting to dst_color_type()
and dst_alpha_type()
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 crate::ColorType
and crate::AlphaType
do not match. Only pixels within both source and destination rectangles
are copied. dst contents outside crate::Rect
intersection are unchanged.
Pass negative values for src.x
or src.y
to offset pixels across or down destination.
Does not copy, and returns false
if:
- Source and destination rectangles do not intersect.
Pixmap
pixels could not be allocated.dst.row_bytes()
is too small to contain one row of pixels.
dst
- storage for pixels copied fromSurface
src_x
- offset into readable pixels on x-axis; may be negativesrc_y
- offset into readable pixels on y-axis; may be negative Returns:true
if pixels were copied
sourcepub fn read_pixels(
&mut self,
dst_info: &ImageInfo,
dst_pixels: &mut [u8],
dst_row_bytes: usize,
src: impl Into<IPoint>
) -> bool
pub fn read_pixels( &mut self, dst_info: &ImageInfo, dst_pixels: &mut [u8], dst_row_bytes: usize, src: impl Into<IPoint> ) -> bool
Copies crate::Rect
of pixels from Canvas
into dst_pixels
.
Source crate::Rect
corners are (src.x
, src.y
) and Surface
(width(), height()).
Destination crate::Rect
corners are (0, 0) and (dst_info
.width(), dst_info
.height()).
Copies each readable pixel intersecting both rectangles, without scaling,
converting to dst_info_color_type()
and dst_info_alpha_type()
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 crate::ColorType
and crate::AlphaType
do not match. Only pixels within both source and destination rectangles
are copied. dst_pixels
contents outside crate::Rect
intersection are unchanged.
Pass negative values for src.x
or src.y
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 todst_info.color_type()
ordst_info.alpha_type()
.dst_row_bytes
is too small to contain one row of pixels.
dst_info
- width, height,crate::ColorType
, andcrate::AlphaType
ofdst_pixels
dst_pixels
- storage for pixels;dst_info.height()
timesdst_row_bytes
, or largerdst_row_bytes
- size of one destination row;dst_info.width()
times pixel size, or largersrc.x
- offset into readable pixels on x-axis; may be negativesrc.y
- offset into readable pixels on y-axis; may be negative Returns:true
if pixels were copied
sourcepub fn read_pixels_to_bitmap(
&mut self,
bitmap: &Bitmap,
src: impl Into<IPoint>
) -> bool
pub fn read_pixels_to_bitmap( &mut self, bitmap: &Bitmap, src: impl Into<IPoint> ) -> bool
Copies crate::Rect
of pixels from Surface
into bitmap.
Source crate::Rect
corners are (src.x
, src.y
) and Surface
(width(), height()).
Destination crate::Rect
corners are (0, 0)
and (bitmap.width(), bitmap.height())
.
Copies each readable pixel intersecting both rectangles, without scaling,
converting to bitmap.color_type()
and bitmap.alpha_type()
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 crate::ColorType
and crate::AlphaType
do not match. Only pixels within both source and destination rectangles
are copied. dst contents outside crate::Rect
intersection are unchanged.
Pass negative values for src.x
or src.y
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 todst.color_type()
ordst.alpha_type()
.- dst pixels could not be allocated.
dst.row_bytes()
is too small to contain one row of pixels.
dst
- storage for pixels copied fromSurface
src.x
- offset into readable pixels on x-axis; may be negativesrc.y
- offset into readable pixels on y-axis; may be negative Returns:true
if pixels were copied
sourcepub fn write_pixels_from_pixmap(
&mut self,
src: &Pixmap<'_>,
dst: impl Into<IPoint>
)
pub fn write_pixels_from_pixmap( &mut self, src: &Pixmap<'_>, dst: impl Into<IPoint> )
Copies crate::Rect
of pixels from the src Pixmap
to the Surface
.
Source crate::Rect
corners are (0, 0)
and (src.width(), src.height())
.
Destination crate::Rect
corners are (
dst.x,
dst.y)
and
(dst.x
+ Surface width(), dst.y
+ Surface height()).
Copies each readable pixel intersecting both rectangles, without scaling,
converting to Surface
color_type()
and Surface
alpha_type()
if required.
sourcepub fn write_pixels_from_bitmap(
&mut self,
bitmap: &Bitmap,
dst: impl Into<IPoint>
)
pub fn write_pixels_from_bitmap( &mut self, bitmap: &Bitmap, dst: impl Into<IPoint> )
Copies crate::Rect
of pixels from the src Bitmap
to the Surface
.
Source crate::Rect
corners are (0, 0)
and (src.width(), src.height())
.
Destination crate::Rect
corners are (
dst.x,
dst.y)
and
(
dst.x+ Surface width(),
dst.y + Surface height())
.
Copies each readable pixel intersecting both rectangles, without scaling,
converting to Surface
color_type()
and Surface
alpha_type()
if required.
sourcepub fn props(&self) -> &SurfaceProps
pub fn props(&self) -> &SurfaceProps
Returns SurfaceProps
for surface.
Returns: LCD striping orientation and setting for device independent fonts
sourcepub fn flush_and_submit(&mut self)
pub fn flush_and_submit(&mut self)
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). gpu::DirectContext
has additional flush and submit methods
that apply to all surfaces and images created from a gpu::DirectContext
. This is equivalent
to calling Self::flush()
with a default gpu::FlushInfo
followed by
gpu::DirectContext::submit
.
sourcepub fn flush_submit_and_sync_cpu(&mut self)
pub fn flush_submit_and_sync_cpu(&mut self)
sourcepub fn resolve_msaa(&mut self)
pub fn resolve_msaa(&mut self)
If a surface is GPU texture backed, is being drawn with MSAA, and there is a resolve
texture, this call will insert a resolve command into the stream of gpu commands. In order
for the resolve to actually have an effect, the work still needs to be flushed and submitted
to the GPU after recording the resolve command. If a resolve is not supported or the
Surface
has no dirty work to resolve, then this call is a no-op.
This call is most useful when the Surface
is created by wrapping a single sampled gpu
texture, but asking Skia to render with MSAA. If the client wants to use the wrapped texture
outside of Skia, the only way to trigger a resolve is either to call this command or use
Self::flush()
.
sourcepub fn flush_with_access_info(
&mut self,
access: BackendSurfaceAccess,
info: &FlushInfo
) -> SemaphoresSubmitted
pub fn flush_with_access_info( &mut self, access: BackendSurfaceAccess, info: &FlushInfo ) -> SemaphoresSubmitted
Issues pending Surface
commands to the GPU-backed API objects and resolves any Surface
MSAA. A call to gpu::DirectContext::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 gl_flush
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 BackendSurfaceAccess that is passed in.
If BackendSurfaceAccess::NoAccess
is passed in all commands will be issued to the GPU.
If BackendSurfaceAccess::Present
is passed in and the backend API is not Vulkan, it is
treated the same as k_no_access
. If the backend API is Vulkan, the VkImage that backs the
Surface
will be transferred back to its original queue. If the Surface
was created by
wrapping a VkImage, the queue will be set to the queue which was originally passed in on
the [gpu::vk::ImageInfo
]. 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 gpu::FlushInfo
describes additional options to flush. Please see documentation at
gpu::FlushInfo
for more info.
If the return is gpu::SemaphoresSubmitted::Yes
, only initialized BackendSemaphores
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
gpu::SemaphoresSubmitted::No
, 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 gpu::FlushInfo
. Regardless of whether semaphores were submitted to the GPU or not, the
client is still responsible for deleting any initialized semaphores.
Regardless of semaphore submission the context will still be flushed. It should be
emphasized that a return value of gpu::SemaphoresSubmitted::No
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.
access
- type of access the call will do on the backend object after flushinfo
- flush options
sourcepub fn flush_with_mutable_state<'a>(
&mut self,
info: &FlushInfo,
new_state: impl Into<Option<&'a MutableTextureState>>
) -> SemaphoresSubmitted
pub fn flush_with_mutable_state<'a>( &mut self, info: &FlushInfo, new_state: impl Into<Option<&'a MutableTextureState>> ) -> SemaphoresSubmitted
Issues pending Surface
commands to the GPU-backed API objects and resolves any Surface
MSAA. A call to gpu::DirectContext::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 gl_flush
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 gpu::FlushInfo
describes additional options to flush. Please see documentation at
gpu::FlushInfo
for more info.
If a gpu::MutableTextureState
is passed in, at the end of the flush we will transition
the surface to be in the state requested by the skgpu::MutableTextureState. If the surface
(or Image
or BackendSurface
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 finished_proc
or semaphore on the gpu::FlushInfo
will also
include the work for any requested state change.
If the backend API is Vulkan, the caller can set the skgpu::MutableTextureState’s
VkImageLayout to VK_IMAGE_LAYOUT_UNDEFINED or queue_family_index
to VK_QUEUE_FAMILY_IGNORED to
tell Skia to not change those respective states.
If the return is gpu::SemaphoresSubmitted::Yes
, only initialized BackendSemaphores
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
gpu::SemaphoresSubmitted::No
, 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 gpu::FlushInfo
. Regardless of whether semaphores were submitted to the GPU or not, the
client is still responsible for deleting any initialized semaphores.
Regardless of semaphore submission the context will still be flushed. It should be
emphasized that a return value of gpu::SemaphoresSubmitted::No
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.
info
- flush optionsaccess
- optional state change request after flush
sourcepub fn characterize(&self) -> Option<SurfaceCharacterization>
pub fn characterize(&self) -> Option<SurfaceCharacterization>
Initializes SurfaceCharacterization
that can be used to perform GPU back-end
processing in a separate thread. Typically this is used to divide drawing
into multiple tiles. crate::DeferredDisplayListRecorder
records the drawing commands
for each tile.
Return true
if Surface
supports characterization. raster surface returns false
.
characterization
- properties for parallel drawing Returns:true
if supported
sourcepub fn draw_display_list_with_offset(
&mut self,
deferred_display_list: impl Into<DeferredDisplayList>,
offset: impl Into<IVector>
) -> bool
pub fn draw_display_list_with_offset( &mut self, deferred_display_list: impl Into<DeferredDisplayList>, offset: impl Into<IVector> ) -> bool
Draws the deferred display list created via a crate::DeferredDisplayListRecorder
.
If the deferred display list is not compatible with this Surface
, the draw is skipped
and false
is return.
The offset.x
and offset.y
parameters are experimental and, if not both zero, will cause
the draw to be ignored.
When implemented, if offset.x
or offset.y
are non-zero, the DDL will be drawn offset by that
amount into the surface.
deferred_display_list
- drawing commandsoffset.x
- x-offset at which to draw the DDLoffset.y
- y-offset at which to draw the DDL Returns:false
ifdeferred_display_list
is not compatible