Skip to content

Commit

Permalink
Software renderer: fix drawing background of rotated screen
Browse files Browse the repository at this point in the history
We need to draw the background over the rotated rectangle otherwise we
don't fill the whole background.

Regression from #7685

(also cleanup a useless blend that was leftover from the same change)

Adapt the screenshot test to have at least one non-square "window" so
that we catch the problem in the future
  • Loading branch information
ogoffart committed Mar 5, 2025
1 parent be59032 commit 36a89ae
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
8 changes: 3 additions & 5 deletions internal/core/software_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,13 +588,11 @@ impl SoftwareRenderer {
};
drop(i);

let mut bg = PremultipliedRgbaColor::background();
// TODO: gradient background
PremultipliedRgbaColor::blend(&mut bg, background.color().into());
renderer.actual_renderer.processor.dirty_region = dirty_region.clone();
renderer.actual_renderer.processor.process_rectangle_impl(
PhysicalRect::from_size(euclid::Size2D::new(size.width, size.height)),
bg,
screen_rect.transformed(rotation),
// TODO: gradient background
background.color().into(),
CompositionMode::Source,
);

Expand Down
13 changes: 12 additions & 1 deletion tests/screenshots/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@ fn main() -> std::io::Result<()> {
});
let skip_clipping = source.contains("SKIP_CLIPPING");

let needle = "SIZE=";
let (size_w, size_h) = source.find(needle).map_or((64, 64), |p| {
source[p + needle.len()..]
.find(char::is_whitespace)
.and_then(|end| source[p + needle.len()..][..end].split_once('x'))
.and_then(|(w, h)| Some((w.parse().ok()?, h.parse().ok()?)))
.unwrap_or_else(|| {
panic!("Cannot parse {needle} for {}", testcase.relative_path.display())
})
});

let mut output = BufWriter::new(std::fs::File::create(
Path::new(&std::env::var_os("OUT_DIR").unwrap()).join(format!("{module_name}.rs")),
)?);
Expand All @@ -122,7 +133,7 @@ fn main() -> std::io::Result<()> {
use crate::testing;
let window = testing::init_swr();
window.set_size(slint::PhysicalSize::new(64, 64));
window.set_size(slint::PhysicalSize::new({size_w}, {size_h}));
let screenshot = {reference_path};
let options = testing::TestCaseOptions {{ rotation_threshold: {rotation_threshold}f32, skip_clipping: {skip_clipping} }};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0

// SIZE=60x64

export component TestCase inherits Window {
width: 64px;
width: 60px;
height: 64px;

background: #2360e62b;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 7 additions & 2 deletions tests/screenshots/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ pub fn screenshot(
LogicalRect::from_size(euclid::size2(width as f32, height as f32)).into(),
);
renderer.set_rendering_rotation(rotated);
renderer.render(buffer.make_mut_slice(), width as usize);
let stride = buffer.width() as usize;
renderer.render(buffer.make_mut_slice(), stride);
renderer.set_rendering_rotation(RenderingRotation::NoRotation);
});

Expand Down Expand Up @@ -133,7 +134,11 @@ fn compare_images(
let reference = image_buffer(reference_path)
.map_err(|image_err| format!("error loading reference image: {image_err:#}"))?;

if reference.size() != screenshot.size() {
let mut ref_size = reference.size();
if matches!(rotated, RenderingRotation::Rotate90 | RenderingRotation::Rotate270) {
std::mem::swap(&mut ref_size.width, &mut ref_size.height);
}
if ref_size != screenshot.size() {
return Err(format!(
"image sizes don't match. reference size {:#?} rendered size {:#?}",
reference.size(),
Expand Down

0 comments on commit 36a89ae

Please sign in to comment.