pub fn render(
        &mut self,
        state: &LayoutState,
        image: &mut [u8],
        [width, height]: [u32; 2],
        stride: u32,
        force_redraw: bool,
    ) -> Option<(f32, f32)> {
        let mut frame_buffer = PixmapMut::from_bytes(image, stride, height).unwrap();

        if stride != self.background.width() || height != self.background.height() {
            self.background = Pixmap::new(stride, height).unwrap();
        }

        let new_resolution =
            self.scene_manager
                .update_scene(SkiaAllocator, (width as _, height as _), &state);

        let scene = self.scene_manager.scene();
        let rectangle = scene.rectangle();
        let rectangle = rectangle.as_deref().unwrap();

        let bottom_layer_changed = scene.bottom_layer_changed();

        let mut background = self.background.as_mut();

        if bottom_layer_changed {
            fill_background(scene, &mut background, width, height);
            render_layer(&mut background, scene.bottom_layer(), rectangle);
        }

        let top_layer = scene.top_layer();

        let (min_y, max_y) = calculate_bounds(top_layer);
        let min_y = mem::replace(&mut self.min_y, min_y).min(min_y);
        let max_y = mem::replace(&mut self.max_y, max_y).max(max_y);

        if force_redraw || bottom_layer_changed {
            frame_buffer
                .data_mut()
                .copy_from_slice(background.data_mut());
        } else if min_y <= max_y {
            let stride = 4 * stride as usize;
            let min_y = stride * (min_y - 1.0) as usize;
            let max_y = stride * ((max_y + 2.0) as usize).min(height as usize);

            frame_buffer.data_mut()[min_y..max_y]
                .copy_from_slice(&background.data_mut()[min_y..max_y]);
        }

        render_layer(&mut frame_buffer, top_layer, rectangle);

        new_resolution
    }
/// Renders the layout state provided into the image buffer provided. The
/// image has to be an array of `RGBA8` encoded pixels (red, green, blue,
/// alpha with each channel being an u8). Some frameworks may over allocate
/// an image's dimensions. So an image with dimensions `100x50` may be over
/// allocated as `128x64`. In that case you provide the real dimensions of
/// `100x50` as the width and height, but a stride of `128` pixels as that
/// correlates with the real width of the underlying buffer. It may detect
/// that the layout got resized. In that case it returns the new ideal size.
/// This is just a hint and can be ignored entirely. The image is always
/// rendered with the resolution provided. By default the renderer will try
/// not to redraw parts of the image that haven't changed. You can force a
/// redraw in case the image provided or its contents have changed.
Renders the layout state provided into the image buffer provided. The
image has to be an array of `RGBA8` encoded pixels (red, green, blue,
alpha with each channel being an u8). Some frameworks may over allocate
an image's dimensions. So an image with dimensions `100x50` may be over
allocated as `128x64`. In that case you provide the real dimensions of
`100x50` as the width and height, but a stride of `128` pixels as that
correlates with the real width of the underlying buffer. It may detect
that the layout got resized. In that case it returns the new ideal size.
This is just a hint and can be ignored entirely. The image is always
rendered with the resolution provided. By default the renderer will try
not to redraw parts of the image that haven't changed. You can force a
redraw in case the image provided or its contents have changed.
Renders the layout state provided into the image buffer provided . The image has to be an array of ` RGBA8 ` encoded pixels ( red green blue alpha with each channel being an u8 ) . Some frameworks may over allocate an image ' s dimensions . So an image with dimensions ` 100x50 ` may be over allocated as ` 128x64 ` . In that case you provide the real dimensions of ` 100x50 ` as the width and height but a stride of ` 128 ` pixels as that correlates with the real width of the underlying buffer . It may detect that the layout got resized . In that case it returns the new ideal size . This is just a hint and can be ignored entirely . The image is always rendered with the resolution provided . By default the renderer will try not to redraw parts of the image that haven ' t changed . You can force a redraw in case the image provided or its contents have changed .
pub fn render(
        &mut self,
        state: &LayoutState,
        image: &mut [u8],
        [width, height]: [u32; 2],
        stride: u32,
        force_redraw: bool,
    ) -> Option<(f32, f32)> {
        let mut frame_buffer = PixmapMut::from_bytes(image, stride, height).unwrap();
        if stride != self.background.width() || height != self.background.height() {
            self.background = Pixmap::new(stride, height).unwrap();
        }
        let new_resolution =
            self.scene_manager
                .update_scene(SkiaAllocator, (width as _, height as _), &state);
        let scene = self.scene_manager.scene();
        let rectangle = scene.rectangle();
        let rectangle = rectangle.as_deref().unwrap();
        let bottom_layer_changed = scene.bottom_layer_changed();
        let mut background = self.background.as_mut();
        if bottom_layer_changed {
            fill_background(scene, &mut background, width, height);
            render_layer(&mut background, scene.bottom_layer(), rectangle);
        }
        let top_layer = scene.top_layer();
        let (min_y, max_y) = calculate_bounds(top_layer);
        let min_y = mem::replace(&mut self.min_y, min_y).min(min_y);
        let max_y = mem::replace(&mut self.max_y, max_y).max(max_y);
        if force_redraw || bottom_layer_changed {
            frame_buffer
                .data_mut()
                .copy_from_slice(background.data_mut());
        } else if min_y <= max_y {
            let stride = 4 * stride as usize;
            let min_y = stride * (min_y - 1.0) as usize;
            let max_y = stride * ((max_y + 2.0) as usize).min(height as usize);
            frame_buffer.data_mut()[min_y..max_y]
                .copy_from_slice(&background.data_mut()[min_y..max_y]);
        }
        render_layer(&mut frame_buffer, top_layer, rectangle);
        new_resolution
    }
pub fn render ( & mut self , state : & LayoutState , image : & mut [ u8 ] , [ width , height ] : [ u32 ; 2 ] , stride : u32 , force_redraw : bool , ) -> Option < ( f32 , f32 ) > { let mut frame_buffer = PixmapMut :: from_bytes ( image , stride , height ) . unwrap ( ) ; if stride != self . background . width ( ) || height != self . background . height ( ) { self . background = Pixmap :: new ( stride , height ) . unwrap ( ) ; } let new_resolution = self . scene_manager . update_scene ( SkiaAllocator , ( width as _ , height as _ ) , & state ) ; let scene = self . scene_manager . scene ( ) ; let rectangle = scene . rectangle ( ) ; let rectangle = rectangle . as_deref ( ) . unwrap ( ) ; let bottom_layer_changed = scene . bottom_layer_changed ( ) ; let mut background = self . background . as_mut ( ) ; if bottom_layer_changed { fill_background ( scene , & mut background , width , height ) ; render_layer ( & mut background , scene . bottom_layer ( ) , rectangle ) ; } let top_layer = scene . top_layer ( ) ; let ( min_y , max_y ) = calculate_bounds ( top_layer ) ; let min_y = mem :: replace ( & mut self . min_y , min_y ) . min ( min_y ) ; let max_y = mem :: replace ( & mut self . max_y , max_y ) . max ( max_y ) ; if force_redraw || bottom_layer_changed { frame_buffer . data_mut ( ) . copy_from_slice ( background . data_mut ( ) ) ; } else if min_y <= max_y { let stride = 4 * stride as usize ; let min_y = stride * ( min_y - 1.0 ) as usize ; let max_y = stride * ( ( max_y + 2.0 ) as usize ) . min ( height as usize ) ; frame_buffer . data_mut ( ) [ min_y .. max_y ] . copy_from_slice ( & background . data_mut ( ) [ min_y .. max_y ] ) ; } render_layer ( & mut frame_buffer , top_layer , rectangle ) ; new_resolution }
Renders the layout state provided into the image buffer provided.
Renders the layout state provided into the image buffer provided .
&mut self
state
&LayoutState
image
[u32; 2]
stride
u32
force_redraw
bool
&mut self
state
&LayoutState
image
[u32; 2]
stride
u32
force_redraw
bool