Skip to content

Commit

Permalink
fix(gpu): 🐛 expand alpha mask texture slice to avoid cut edge, E.g. g…
Browse files Browse the repository at this point in the history
…lyph in text "🟡🟡🟡🟡"
  • Loading branch information
wjian23 committed Sep 27, 2023
1 parent 979ea2a commit 0179b74
Show file tree
Hide file tree
Showing 15 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dev-helper/src/painter_backend_eq_image_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub fn assert_texture_eq_png(img: PixelImage, file_path: &std::path::Path) {
)
.unwrap();

const TOLERANCE: f64 = 0.0000025;
const TOLERANCE: f64 = 0.000008;
let (v, _) = dssim.compare(&expected, dissim_mig);
let v: f64 = v.into();

Expand Down
23 changes: 17 additions & 6 deletions gpu/src/gpu_backend/textures_mgr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,14 @@ where
.filter(|h| h.attr >= prefer_scale)
.copied()
{
let slice = alpha_tex_slice(&self.alpha_atlas, &h).cut_blank_edge();
let matrix = cache_to_view_matrix(key.path(), transform, slice.rect.origin, h.attr);
(slice, matrix)
let mask_slice = alpha_tex_slice(&self.alpha_atlas, &h).cut_blank_edge();
let matrix = cache_to_view_matrix(key.path(), transform, mask_slice.rect.origin, h.attr);
(mask_slice.expand_for_paste(), matrix)
} else {
let path = key.path().clone();
let scale_bounds = path.bounds().scale(prefer_scale, prefer_scale);
let prefer_cache_size = path_add_edges(scale_bounds.round_out().size.to_i32().cast_unit());

let h = self
.alpha_atlas
.allocate(key, prefer_scale, prefer_cache_size, gpu_impl);
Expand All @@ -146,7 +147,7 @@ where
.fill_task
.push(FillTask { slice, path, ts, clip_rect: None });

(mask_slice, matrix)
(mask_slice.expand_for_paste(), matrix)
}
}

Expand Down Expand Up @@ -179,7 +180,10 @@ where
};

let offset = (clip_view.origin - slice.rect.origin).to_f32();
(slice, Transform::translation(offset.x, offset.y))
(
slice.expand_for_paste(),
Transform::translation(offset.x, offset.y),
)
}

pub(super) fn store_image(
Expand Down Expand Up @@ -395,6 +399,13 @@ impl TextureSlice {
self.rect = self.rect.inner_rect(blank_side);
self
}

pub fn expand_for_paste(mut self) -> TextureSlice {
const EXPANDED_EDGE: i32 = 1;
let blank_side = SideOffsets2D::new_all_same(EXPANDED_EDGE);
self.rect = self.rect.outer_rect(blank_side);
self
}
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -638,7 +649,7 @@ pub mod tests {
let (slice2, ts2) = mgr.store_clipped_path(clip_view, path, &mut wgpu);
assert_eq!(slice1, slice2);
assert_eq!(ts1, ts2);
assert_eq!(slice1.rect, ribir_geom::rect(2, 2, 100, 100));
assert_eq!(slice1.rect, ribir_geom::rect(1, 1, 102, 102));
assert_eq!(ts1, Transform::new(1., 0., 0., 1., 8., 8.));
}

Expand Down
Binary file modified test_cases/counter/counter_with_default_by_wgpu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test_cases/counter/counter_with_material_by_wgpu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test_cases/messages/messages_with_default_by_wgpu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test_cases/messages/messages_with_material_by_wgpu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test_cases/ribir_gpu/gpu_backend/tests/draw_svg_gradient_wgpu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test_cases/storybook/storybook_with_default_by_wgpu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test_cases/storybook/storybook_with_material_by_wgpu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test_cases/todos/todos_with_default_by_wgpu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test_cases/todos/todos_with_material_by_wgpu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0179b74

Please sign in to comment.