pub struct WgpuRenderer { /* private fields */ }Expand description
WGPU-based renderer for GPU-accelerated 2D rendering.
This renderer supports:
- GPU-accelerated shape rendering (rectangles, rounded rectangles)
- Gradients (solid, linear, radial)
- GPU text rendering via retained raster image batches
- Cross-platform support (Desktop, Web, Android)
Implementations§
Source§impl WgpuRenderer
impl WgpuRenderer
Sourcepub fn new(fonts: &[&[u8]]) -> Self
pub fn new(fonts: &[&[u8]]) -> Self
Create a new WGPU renderer.
fonts– font bytes to load, ordered by priority (first = highest priority). Pass&[]to load no fonts; text will not render until fonts are provided.
Call init_gpu before rendering.
Sourcepub fn with_font_set(fonts: SoftwareTextFontSet) -> Self
pub fn with_font_set(fonts: SoftwareTextFontSet) -> Self
Create a renderer over an already-parsed font set.
Measurement and rasterization both take clones of this one set, so an app-supplied family resolves identically on both sides.
pub fn with_text_system(text_system: WgpuTextSystem) -> Self
Sourcepub fn init_gpu(
&mut self,
device: Arc<Device>,
queue: Arc<Queue>,
surface_format: TextureFormat,
adapter_backend: Backend,
)
pub fn init_gpu( &mut self, device: Arc<Device>, queue: Arc<Queue>, surface_format: TextureFormat, adapter_backend: Backend, )
Initialize GPU resources with a WGPU device and queue.
Replacing a live renderer (Android surface recreation, device loss)
drops every retained replay slot with the old GpuRenderer, so the
bypass contract fails closed BEFORE the new renderer exists: every
slot confirmation is revoked and the feed generation bumped — no
scene build may omit primitives against buffers that died, and
already-built frames rematerialize their bypassed spans instead of
referencing the dead renderer’s slot ids.
Sourcepub fn note_surface_reconfigured(&mut self)
pub fn note_surface_reconfigured(&mut self)
Record that the surface was reconfigured (resize, format change, swapchain recreation): bumps the surface epoch stamped into every subsequent packet, so a packet built against the previous configuration is cancelled by the present stage instead of drawn.
Sourcepub fn set_root_scale(&mut self, scale: f32)
pub fn set_root_scale(&mut self, scale: f32)
Set root scale factor for text rendering (e.g., density scaling on Android)
pub fn root_scale(&self) -> f32
Sourcepub fn render(
&mut self,
view: &TextureView,
width: u32,
height: u32,
) -> Result<(), WgpuRendererError>
pub fn render( &mut self, view: &TextureView, width: u32, height: u32, ) -> Result<(), WgpuRendererError>
Render the scene to a texture view.
Producer first, present second: the frontend lowers the frame into a
[frame_packet::FramePacket] (direct root, root surface, and dev
overlay alike), the GPU renderer consumes it, and the present
stage’s returns — the recycled scene and the replay ack — fold back
into the frontend afterwards.
Sourcepub fn capture_frame(
&mut self,
width: u32,
height: u32,
) -> Result<CapturedFrame, WgpuRendererError>
pub fn capture_frame( &mut self, width: u32, height: u32, ) -> Result<CapturedFrame, WgpuRendererError>
Render the current scene into an RGBA pixel buffer for robot tests.
Uses the renderer’s configured root scale.
Sourcepub fn capture_frame_with_scale(
&mut self,
width: u32,
height: u32,
root_scale: f32,
) -> Result<CapturedFrame, WgpuRendererError>
pub fn capture_frame_with_scale( &mut self, width: u32, height: u32, root_scale: f32, ) -> Result<CapturedFrame, WgpuRendererError>
Render the current scene into an RGBA pixel buffer with an explicit scale.
pub fn last_frame_stats(&self) -> Option<RenderStatsSnapshot>
pub fn debug_cpu_allocation_stats(&self) -> DebugCpuAllocationStats
Sourcepub fn try_device(&self) -> Option<&Device>
pub fn try_device(&self) -> Option<&Device>
Return the WGPU device when GPU resources are initialized.
Trait Implementations§
Source§impl Default for WgpuRenderer
impl Default for WgpuRenderer
Source§impl Renderer for WgpuRenderer
impl Renderer for WgpuRenderer
type Scene = Scene
type Error = WgpuRendererError
Source§fn attach_app_context_services(&mut self, app_context: &AppContext)
fn attach_app_context_services(&mut self, app_context: &AppContext)
fn scene(&self) -> &Self::Scene
fn scene_mut(&mut self) -> &mut Self::Scene
fn rebuild_scene( &mut self, layout_tree: &LayoutTree, _viewport: Size, ) -> Result<(), Self::Error>
Source§fn rebuild_scene_from_applier(
&mut self,
applier: &mut MemoryApplier,
root: NodeId,
_viewport: Size,
) -> Result<(), Self::Error>
fn rebuild_scene_from_applier( &mut self, applier: &mut MemoryApplier, root: NodeId, _viewport: Size, ) -> Result<(), Self::Error>
fn update_scene_from_applier( &mut self, applier: &mut MemoryApplier, root: NodeId, viewport: Size, dirty_nodes: &[NodeId], ) -> Result<(), Self::Error>
fn update_visual_scene_from_applier( &mut self, applier: &mut MemoryApplier, root: NodeId, viewport: Size, dirty_nodes: &[NodeId], ) -> Result<(), Self::Error>
Source§fn draw_dev_overlay(&mut self, text: &str, viewport: Size)
fn draw_dev_overlay(&mut self, text: &str, viewport: Size)
Source§fn needs_frame_warmup(&self) -> bool
fn needs_frame_warmup(&self) -> bool
Auto Trait Implementations§
impl !Freeze for WgpuRenderer
impl !RefUnwindSafe for WgpuRenderer
impl !Send for WgpuRenderer
impl !Sync for WgpuRenderer
impl !UnwindSafe for WgpuRenderer
impl Unpin for WgpuRenderer
impl UnsafeUnpin for WgpuRenderer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more