pub(crate) fn fill(image: &Image, color: &[u8]) -> Result<()> {
    let format_width: usize = pixel_width(&image.format_constraints.pixel_format).try_into()?;
    if format_width != color.len() {
        return Err(format_err!(
            "provided color width ({}) does not match expected pixel format width ({})",
            color.len(),
            format_width
        ));
    }

    let mapping_size: usize = image.buffer_settings.size_bytes.try_into()?;
    let mapping = Mapping::create_from_vmo(
        &image.vmo,
        mapping_size,
        zx::VmarFlags::PERM_READ | zx::VmarFlags::PERM_WRITE,
    )
    .context("failed to map VMO")?;

    for i in 0..(mapping_size / format_width) {
        mapping.write_at(i * format_width, color);
    }
    image.vmo.op_range(zx::VmoOp::CACHE_CLEAN_INVALIDATE, 0, image.vmo.get_size()?)?;

    Ok(())
}
/// Fill the given image with the specified color. The size and interpretation of the given color
/// must match the provided image format.
Fill the given image with the specified color. The size and interpretation of the given color
must match the provided image format.
Fill the given image with the specified color . The size and interpretation of the given color must match the provided image format .
pub(crate) fn fill(image: &Image, color: &[u8]) -> Result<()> {
    let format_width: usize = pixel_width(&image.format_constraints.pixel_format).try_into()?;
    if format_width != color.len() {
        return Err(format_err!(
            "provided color width ({}) does not match expected pixel format width ({})",
            color.len(),
            format_width
        ));
    }
    let mapping_size: usize = image.buffer_settings.size_bytes.try_into()?;
    let mapping = Mapping::create_from_vmo(
        &image.vmo,
        mapping_size,
        zx::VmarFlags::PERM_READ | zx::VmarFlags::PERM_WRITE,
    )
    .context("failed to map VMO")?;
    for i in 0..(mapping_size / format_width) {
        mapping.write_at(i * format_width, color);
    }
    image.vmo.op_range(zx::VmoOp::CACHE_CLEAN_INVALIDATE, 0, image.vmo.get_size()?)?;
    Ok(())
}
pub ( crate ) fn fill ( image : & Image , color : & [ u8 ] ) -> Result < ( ) > { let format_width : usize = pixel_width ( & image . format_constraints . pixel_format ) . try_into ( ) ? ; if format_width != color . len ( ) { return Err ( format_err ! ( " " color len ( ) format_width ) ) ; } let mapping_size : usize = image . buffer_settings . size_bytes . try_into ( ) ? ; let mapping = Mapping :: create_from_vmo ( & image . vmo , mapping_size , zx :: VmarFlags :: PERM_READ | zx :: VmarFlags :: PERM_WRITE , ) . context ( " " ) ? ; for i in 0 .. ( mapping_size / format_width ) { mapping . write_at ( i * format_width , color ) ; } image . vmo . op_range ( zx :: VmoOp :: CACHE_CLEAN_INVALIDATE , 0 , image . vmo . get_size ( ) ? ) ? ; Ok ( ( ) ) }
Fill the given image with the specified color.
Fill the given image with the specified color .
image
&Image
color
&[u8]
image
&Image
color
&[u8]