core: Optimize BMD.fillRect()

This commit is contained in:
Adrian Wielgosik 2024-09-16 13:02:21 +02:00 committed by Adrian Wielgosik
parent a3d58f0815
commit 4ab0910bff
2 changed files with 21 additions and 4 deletions

View File

@ -710,6 +710,19 @@ impl<'gc> BitmapData<'gc> {
self.pixels[(x + y * self.width) as usize] = color;
}
#[inline]
pub fn set_pixel32_row_raw(&mut self, x1: u32, x2: u32, y: u32, color: Color) {
let p1 = (x1 + y * self.width) as usize;
let p2 = (x2 + y * self.width) as usize;
let slice = &mut self.pixels[p1..p2];
slice.fill(color);
}
#[inline]
pub fn fill(&mut self, color: Color) {
self.pixels.fill(color);
}
#[inline]
pub fn get_pixel32_raw(&self, x: u32, y: u32) -> Color {
self.pixels[(x + y * self.width()) as usize]

View File

@ -45,7 +45,9 @@ pub fn fill_rect<'gc>(
return;
}
let target = if rect.width() == target.width() && rect.height() == target.height() {
let is_full = rect.width() == target.width() && rect.height() == target.height();
let target = if is_full {
// If we're filling the whole region, we can discard the gpu data
target.overwrite_cpu_pixels_from_gpu(mc).0
} else {
@ -55,9 +57,11 @@ pub fn fill_rect<'gc>(
let mut write = target.write(mc);
let color = Color::from(color).to_premultiplied_alpha(write.transparency());
for y in rect.y_min..rect.y_max {
for x in rect.x_min..rect.x_max {
write.set_pixel32_raw(x, y, color);
if is_full {
write.fill(color);
} else {
for y in rect.y_min..rect.y_max {
write.set_pixel32_row_raw(rect.x_min, rect.x_max, y, color);
}
}
write.set_cpu_dirty(mc, rect);