Add draw_texture/process_texture and use accelerated fill_rectangle for background draw

This commit is contained in:
Sam Cristall 2025-02-11 16:08:57 -07:00 committed by Simon Hausmann
parent fbee7f9566
commit 3855cf6b9c
3 changed files with 214 additions and 28 deletions

View file

@ -549,6 +549,11 @@ struct TargetPixelBuffer
virtual bool fill_rectangle(int16_t x, int16_t y, int16_t width, int16_t height,
const RgbaColor<uint8_t> &premultiplied_color) = 0;
virtual bool draw_texture(int16_t x, int16_t y, int16_t width, int16_t height,
const uint8_t *src, uint16_t src_stride, int16_t src_width,
int16_t src_height, uint8_t src_pixel_format, uint16_t src_dx,
uint16_t src_dy, uint16_t src_off_x, uint16_t src_off_y,
uint32_t colorize, uint8_t alpha, uint8_t rotation) = 0;
};
# endif
@ -719,6 +724,18 @@ public:
return buffer->fill_rectangle(
x, y, width, height,
Color::from_argb_uint8(alpha, red, green, blue));
},
.draw_texture =
[](void *self, int16_t x, int16_t y, int16_t width, int16_t handle,
const uint8_t *src, uint16_t src_stride, int16_t src_width,
int16_t src_height, uint8_t src_pixel_format, uint16_t src_dx,
uint16_t src_dy, uint16_t src_off_x, uint16_t src_off_y, uint32_t colorize,
uint8_t alpha, uint8_t rotation) {
auto *buffer = reinterpret_cast<TargetPixelBuffer<Rgb8Pixel> *>(self);
return buffer->draw_texture(x, y, width, handle, src, src_stride, src_width,
src_height, src_pixel_format, src_dx, src_dy,
src_off_x, src_off_y, colorize, alpha,
rotation);
}
};
auto r =
@ -749,6 +766,18 @@ public:
return buffer->fill_rectangle(
x, y, width, height,
Color::from_argb_uint8(alpha, red, green, blue));
},
.draw_texture =
[](void *self, int16_t x, int16_t y, int16_t width, int16_t handle,
const uint8_t *src, uint16_t src_stride, int16_t src_width,
int16_t src_height, uint8_t src_pixel_format, uint16_t src_dx,
uint16_t src_dy, uint16_t src_off_x, uint16_t src_off_y, uint32_t colorize,
uint8_t alpha, uint8_t rotation) {
auto *buffer = reinterpret_cast<TargetPixelBuffer<Rgb565Pixel> *>(self);
return buffer->draw_texture(x, y, width, handle, src, src_stride, src_width,
src_height, src_pixel_format, src_dx, src_dy,
src_off_x, src_off_y, colorize, alpha,
rotation);
}
};
auto r = cbindgen_private::slint_software_renderer_render_accel_rgb565(inner,

View file

@ -384,6 +384,25 @@ mod software_renderer {
u8,
u8,
) -> bool,
draw_texture: unsafe extern "C" fn(
CppTargetPixelBufferUserData,
i16,
i16,
i16,
i16,
*const u8,
u16,
i16,
i16,
u8,
u16,
u16,
u16,
u16,
u32,
u8,
u8,
) -> bool,
}
impl TargetPixelBuffer for CppRgb8TargetPixelBuffer {
@ -424,6 +443,48 @@ mod software_renderer {
)
}
}
fn draw_texture(
&mut self,
x: i16,
y: i16,
width: i16,
height: i16,
src: *const u8,
src_stride: u16,
src_width: i16,
src_height: i16,
src_pixel_format: u8,
dx: u16,
dy: u16,
off_x: u16,
off_y: u16,
colorize: u32,
alpha: u8,
rotation: u8,
) -> bool {
unsafe {
(self.draw_texture)(
self.user_data,
x,
y,
width,
height,
src,
src_stride,
src_width,
src_height,
src_pixel_format,
dx,
dy,
off_x,
off_y,
colorize,
alpha,
rotation,
)
}
}
}
#[repr(C)]
@ -447,6 +508,25 @@ mod software_renderer {
u8,
u8,
) -> bool,
draw_texture: unsafe extern "C" fn(
CppTargetPixelBufferUserData,
i16,
i16,
i16,
i16,
*const u8,
u16,
i16,
i16,
u8,
u16,
u16,
u16,
u16,
u32,
u8,
u8,
) -> bool,
}
impl TargetPixelBuffer for CppRgb565TargetPixelBuffer {
@ -487,6 +567,48 @@ mod software_renderer {
)
}
}
fn draw_texture(
&mut self,
x: i16,
y: i16,
width: i16,
height: i16,
src: *const u8,
src_stride: u16,
src_width: i16,
src_height: i16,
src_pixel_format: u8,
dx: u16,
dy: u16,
off_x: u16,
off_y: u16,
colorize: u32,
alpha: u8,
rotation: u8,
) -> bool {
unsafe {
(self.draw_texture)(
self.user_data,
x,
y,
width,
height,
src,
src_stride,
src_width,
src_height,
src_pixel_format,
dx,
dy,
off_x,
off_y,
colorize,
alpha,
rotation,
)
}
}
}
#[no_mangle]