diff --git a/WINGs/wings-rs-tests/Cargo.toml b/WINGs/wings-rs-tests/Cargo.toml index 9258373d..b19144f8 100644 --- a/WINGs/wings-rs-tests/Cargo.toml +++ b/WINGs/wings-rs-tests/Cargo.toml @@ -10,6 +10,7 @@ insta-image = { version = "1.0", features = ["png"] } png = "0.18" tempdir = "0.3.7" wings-rs = { path = "../wings-rs" } +wrlib-rs = { path = "../../wrlib-rs" } wutil-rs = { path = "../../wutil-rs" } x11 = "2.21.0" diff --git a/WINGs/wings-rs-tests/build.rs b/WINGs/wings-rs-tests/build.rs index 10aa504a..59b00430 100644 --- a/WINGs/wings-rs-tests/build.rs +++ b/WINGs/wings-rs-tests/build.rs @@ -2,21 +2,12 @@ fn main() { println!("cargo::rustc-link-search=../.libs"); println!("cargo::rustc-link-search=../../wrlib/.libs"); println!("cargo::rustc-link-arg=-lX11"); - - println!("cargo::rustc-link-arg-tests=-lwraster"); - println!("cargo::rustc-link-arg-tests=-lWUtil"); - println!("cargo::rustc-link-arg-tests=-lWINGs"); - println!("cargo::rustc-link-arg-tests=-lXft"); - println!("cargo::rustc-link-arg-tests=-lpango-1.0"); - println!("cargo::rustc-link-arg-tests=-lpangoxft-1.0"); - println!("cargo::rustc-link-arg-tests=-lpangoft2-1.0"); - - println!("cargo::rustc-link-arg-examples=-lWUtil"); - println!("cargo::rustc-link-arg-examples=-lWINGs"); - println!("cargo::rustc-link-arg-examples=-lwraster"); - println!("cargo::rustc-link-arg-examples=-lX11"); - println!("cargo::rustc-link-arg-examples=-lXft"); - println!("cargo::rustc-link-arg-examples=-lpango-1.0"); - println!("cargo::rustc-link-arg-examples=-lpangoxft-1.0"); - println!("cargo::rustc-link-arg-examples=-lpangoft2-1.0"); + println!("cargo::rustc-link-arg=-lWUtil"); + println!("cargo::rustc-link-arg=-lWINGs"); + println!("cargo::rustc-link-arg=-lwraster"); + println!("cargo::rustc-link-arg=-lX11"); + println!("cargo::rustc-link-arg=-lXft"); + println!("cargo::rustc-link-arg=-lpango-1.0"); + println!("cargo::rustc-link-arg=-lpangoxft-1.0"); + println!("cargo::rustc-link-arg=-lpangoft2-1.0"); } diff --git a/WINGs/wings-rs-tests/tests/image_128x120.png b/WINGs/wings-rs-tests/tests/image_128x120.png new file mode 100644 index 00000000..861e8142 Binary files /dev/null and b/WINGs/wings-rs-tests/tests/image_128x120.png differ diff --git a/WINGs/wings-rs-tests/tests/image_128x120_varying_alpha.png b/WINGs/wings-rs-tests/tests/image_128x120_varying_alpha.png new file mode 100644 index 00000000..b4ed5daf Binary files /dev/null and b/WINGs/wings-rs-tests/tests/image_128x120_varying_alpha.png differ diff --git a/WINGs/wings-rs-tests/tests/image_with_transparent_dot_128x120.png b/WINGs/wings-rs-tests/tests/image_with_transparent_dot_128x120.png new file mode 100644 index 00000000..8ffd980a Binary files /dev/null and b/WINGs/wings-rs-tests/tests/image_with_transparent_dot_128x120.png differ diff --git a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__empty_pixmap_on_window.snap b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__empty_pixmap_on_window.snap new file mode 100644 index 00000000..13c6fb0e --- /dev/null +++ b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__empty_pixmap_on_window.snap @@ -0,0 +1,7 @@ +--- +source: tests/wmpixmap_tests.rs +assertion_line: 63 +expression: app.xvfb.png_screenshot() +extension: png +snapshot_kind: binary +--- diff --git a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__empty_pixmap_on_window.snap.png b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__empty_pixmap_on_window.snap.png new file mode 100644 index 00000000..a6135910 Binary files /dev/null and b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__empty_pixmap_on_window.snap.png differ diff --git a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__empty_window.snap b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__empty_window.snap new file mode 100644 index 00000000..9f1c870f --- /dev/null +++ b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__empty_window.snap @@ -0,0 +1,7 @@ +--- +source: tests/wmpixmap_tests.rs +assertion_line: 41 +expression: app.xvfb.png_screenshot() +extension: png +snapshot_kind: binary +--- diff --git a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__empty_window.snap.png b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__empty_window.snap.png new file mode 100644 index 00000000..a6135910 Binary files /dev/null and b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__empty_window.snap.png differ diff --git a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_blended_base_pixmap.snap b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_blended_base_pixmap.snap new file mode 100644 index 00000000..f5a54e68 --- /dev/null +++ b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_blended_base_pixmap.snap @@ -0,0 +1,7 @@ +--- +source: tests/wmpixmap_tests.rs +assertion_line: 142 +expression: app.xvfb.png_screenshot() +extension: png +snapshot_kind: binary +--- diff --git a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_blended_base_pixmap.snap.png b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_blended_base_pixmap.snap.png new file mode 100644 index 00000000..20cae839 Binary files /dev/null and b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_blended_base_pixmap.snap.png differ diff --git a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_blended_cleared_window.snap b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_blended_cleared_window.snap new file mode 100644 index 00000000..a071f795 --- /dev/null +++ b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_blended_cleared_window.snap @@ -0,0 +1,7 @@ +--- +source: tests/wmpixmap_tests.rs +assertion_line: 160 +expression: app.xvfb.png_screenshot() +extension: png +snapshot_kind: binary +--- diff --git a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_blended_cleared_window.snap.png b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_blended_cleared_window.snap.png new file mode 100644 index 00000000..a6135910 Binary files /dev/null and b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_blended_cleared_window.snap.png differ diff --git a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_blended_with_red.snap b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_blended_with_red.snap new file mode 100644 index 00000000..b1482c84 --- /dev/null +++ b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_blended_with_red.snap @@ -0,0 +1,7 @@ +--- +source: tests/wmpixmap_tests.rs +assertion_line: 175 +expression: app.xvfb.png_screenshot() +extension: png +snapshot_kind: binary +--- diff --git a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_blended_with_red.snap.png b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_blended_with_red.snap.png new file mode 100644 index 00000000..c2917169 Binary files /dev/null and b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_blended_with_red.snap.png differ diff --git a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_pixmap.snap b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_pixmap.snap new file mode 100644 index 00000000..e52d2b8d --- /dev/null +++ b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_pixmap.snap @@ -0,0 +1,7 @@ +--- +source: tests/wmpixmap_tests.rs +assertion_line: 58 +expression: app.xvfb.png_screenshot() +extension: png +snapshot_kind: binary +--- diff --git a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_pixmap.snap.png b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_pixmap.snap.png new file mode 100644 index 00000000..9d9e2b7d Binary files /dev/null and b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_pixmap.snap.png differ diff --git a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_base_pixmap.snap b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_base_pixmap.snap new file mode 100644 index 00000000..d4fba6ed --- /dev/null +++ b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_base_pixmap.snap @@ -0,0 +1,7 @@ +--- +source: tests/wmpixmap_tests.rs +assertion_line: 204 +expression: app.xvfb.png_screenshot() +extension: png +snapshot_kind: binary +--- diff --git a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_base_pixmap.snap.png b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_base_pixmap.snap.png new file mode 100644 index 00000000..20cae839 Binary files /dev/null and b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_base_pixmap.snap.png differ diff --git a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_cleared_window.snap b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_cleared_window.snap new file mode 100644 index 00000000..1a7f0e68 --- /dev/null +++ b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_cleared_window.snap @@ -0,0 +1,7 @@ +--- +source: tests/wmpixmap_tests.rs +assertion_line: 222 +expression: app.xvfb.png_screenshot() +extension: png +snapshot_kind: binary +--- diff --git a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_cleared_window.snap.png b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_cleared_window.snap.png new file mode 100644 index 00000000..a6135910 Binary files /dev/null and b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_cleared_window.snap.png differ diff --git a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_non_integral_base_pixmap.snap b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_non_integral_base_pixmap.snap new file mode 100644 index 00000000..0e4bc210 --- /dev/null +++ b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_non_integral_base_pixmap.snap @@ -0,0 +1,7 @@ +--- +source: tests/wmpixmap_tests.rs +assertion_line: 268 +expression: app.xvfb.png_screenshot() +extension: png +snapshot_kind: binary +--- diff --git a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_non_integral_base_pixmap.snap.png b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_non_integral_base_pixmap.snap.png new file mode 100644 index 00000000..9d9e2b7d Binary files /dev/null and b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_non_integral_base_pixmap.snap.png differ diff --git a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_non_integral_cleared_window.snap b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_non_integral_cleared_window.snap new file mode 100644 index 00000000..ed476720 --- /dev/null +++ b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_non_integral_cleared_window.snap @@ -0,0 +1,7 @@ +--- +source: tests/wmpixmap_tests.rs +assertion_line: 286 +expression: app.xvfb.png_screenshot() +extension: png +snapshot_kind: binary +--- diff --git a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_non_integral_cleared_window.snap.png b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_non_integral_cleared_window.snap.png new file mode 100644 index 00000000..a6135910 Binary files /dev/null and b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_non_integral_cleared_window.snap.png differ diff --git a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_non_integral_scaled.snap b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_non_integral_scaled.snap new file mode 100644 index 00000000..25952ed1 --- /dev/null +++ b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_non_integral_scaled.snap @@ -0,0 +1,7 @@ +--- +source: tests/wmpixmap_tests.rs +assertion_line: 304 +expression: app.xvfb.png_screenshot() +extension: png +snapshot_kind: binary +--- diff --git a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_non_integral_scaled.snap.png b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_non_integral_scaled.snap.png new file mode 100644 index 00000000..7218e317 Binary files /dev/null and b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_non_integral_scaled.snap.png differ diff --git a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_with_red.snap b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_with_red.snap new file mode 100644 index 00000000..b4eb991a --- /dev/null +++ b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_with_red.snap @@ -0,0 +1,7 @@ +--- +source: tests/wmpixmap_tests.rs +assertion_line: 239 +expression: app.xvfb.png_screenshot() +extension: png +snapshot_kind: binary +--- diff --git a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_with_red.snap.png b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_with_red.snap.png new file mode 100644 index 00000000..4b1d8ca9 Binary files /dev/null and b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_file_scaled_blended_with_red.snap.png differ diff --git a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_r_image_no_mask.snap b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_r_image_no_mask.snap new file mode 100644 index 00000000..096becec --- /dev/null +++ b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_r_image_no_mask.snap @@ -0,0 +1,7 @@ +--- +source: tests/wmpixmap_tests.rs +assertion_line: 130 +expression: app.xvfb.png_screenshot() +extension: png +snapshot_kind: binary +--- diff --git a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_r_image_no_mask.snap.png b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_r_image_no_mask.snap.png new file mode 100644 index 00000000..15fefa45 Binary files /dev/null and b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_r_image_no_mask.snap.png differ diff --git a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_r_image_with_mask.snap b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_r_image_with_mask.snap new file mode 100644 index 00000000..44b1a6c4 --- /dev/null +++ b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_r_image_with_mask.snap @@ -0,0 +1,7 @@ +--- +source: tests/wmpixmap_tests.rs +assertion_line: 229 +expression: app.xvfb.png_screenshot() +extension: png +snapshot_kind: binary +--- diff --git a/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_r_image_with_mask.snap.png b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_r_image_with_mask.snap.png new file mode 100644 index 00000000..d065e111 Binary files /dev/null and b/WINGs/wings-rs-tests/tests/snapshots/wmpixmap_tests__from_r_image_with_mask.snap.png differ diff --git a/WINGs/wings-rs-tests/tests/wmpixmap_tests.rs b/WINGs/wings-rs-tests/tests/wmpixmap_tests.rs new file mode 100644 index 00000000..85d8fb65 --- /dev/null +++ b/WINGs/wings-rs-tests/tests/wmpixmap_tests.rs @@ -0,0 +1,450 @@ +use insta_image::assert_png_snapshot; +use std::{ + ptr::{self, NonNull}, + time::Instant, +}; +use wings_rs::WINGsP::{ + WMCreateBlendedPixmapFromFile, WMCreateBlendedPixmapFromRImage, WMCreatePixmap, + WMCreatePixmapFromFile, WMCreatePixmapFromRImage, WMCreateScaledBlendedPixmapFromFile, + WMDrawPixmap, WMReleasePixmap, +}; +use wings_rs_tests::HeadlessApplication; +use wrlib_rs::ffi::{RColor, RLoadImage, RReleaseImage}; + +#[test] +fn draw_blank_pixmap() { + let mut app = HeadlessApplication::new(); + unsafe { + let display = (*app.screen.as_ptr()).display; + let win = x11::xlib::XCreateSimpleWindow( + display, + (*app.screen.as_ptr()).rootWin, + 0, + 0, + 512, + 512, + 1, + 1, + x11::xlib::XWhitePixel(display, 0), + ); + x11::xlib::XMapWindow(display, win); + + let pixmap = NonNull::new(WMCreatePixmap(app.screen.as_ptr(), 128, 196, 24, 1)).unwrap(); + WMDrawPixmap(pixmap.as_ptr(), win, 64, 96); + while app.pump_event_queue(Instant::now()) {} + assert_png_snapshot!("empty_window", app.xvfb.png_screenshot()); + + let gc = x11::xlib::XCreateGC(display, (*pixmap.as_ptr()).pixmap, 0, ptr::null_mut()); + x11::xlib::XSetForeground(display, gc, 0); + x11::xlib::XFillRectangle(display, (*pixmap.as_ptr()).pixmap, gc, 0, 0, 128, 196); + WMDrawPixmap(pixmap.as_ptr(), win, 64, 96); + while app.pump_event_queue(Instant::now()) {} + assert_png_snapshot!("empty_pixmap_on_window", app.xvfb.png_screenshot()); + + x11::xlib::XFreeGC(display, gc); + WMReleasePixmap(pixmap.as_ptr()); + } +} + +// WMCreatePixmapFromXPixmaps is not tested because it simply fills in struct +// fields. Coverage from other tests in this file should be adequate. + +#[test] +fn draw_pixmap_from_file() { + let mut app = HeadlessApplication::new(); + unsafe { + let display = (*app.screen.as_ptr()).display; + let win = x11::xlib::XCreateSimpleWindow( + display, + (*app.screen.as_ptr()).rootWin, + 0, + 0, + 512, + 512, + 1, + 1, + x11::xlib::XWhitePixel(display, 0), + ); + x11::xlib::XMapWindow(display, win); + + let pixmap = NonNull::new(WMCreatePixmapFromFile( + app.screen.as_ptr(), + c"tests/image_128x120.png".as_ptr(), + )) + .unwrap(); + WMDrawPixmap(pixmap.as_ptr(), win, 64, 96); + + while app.pump_event_queue(Instant::now()) {} + assert_png_snapshot!("from_file_pixmap", app.xvfb.png_screenshot()); + WMReleasePixmap(pixmap.as_ptr()); + } +} + +#[test] +fn draw_pixmap_from_r_image_no_mask() { + let mut app = HeadlessApplication::new(); + unsafe { + let display = (*app.screen.as_ptr()).display; + let win = x11::xlib::XCreateSimpleWindow( + display, + (*app.screen.as_ptr()).rootWin, + 0, + 0, + 512, + 512, + 1, + 1, + x11::xlib::XWhitePixel(display, 0), + ); + x11::xlib::XMapWindow(display, win); + + let rimage = RLoadImage( + (*app.screen.as_ptr()).rcontext, + c"tests/image_128x120.png".as_ptr(), + 0, + ); + let pixmap = + NonNull::new(WMCreatePixmapFromRImage(app.screen.as_ptr(), rimage, 255)).unwrap(); + WMDrawPixmap(pixmap.as_ptr(), win, 70, 74); + + while app.pump_event_queue(Instant::now()) {} + assert_png_snapshot!("from_r_image_no_mask", app.xvfb.png_screenshot()); + WMReleasePixmap(pixmap.as_ptr()); + } +} + +#[test] +fn draw_pixmap_from_r_image_with_mask() { + let mut app = HeadlessApplication::new(); + unsafe { + let display = (*app.screen.as_ptr()).display; + let win = x11::xlib::XCreateSimpleWindow( + display, + (*app.screen.as_ptr()).rootWin, + 0, + 0, + 512, + 512, + 1, + 1, + x11::xlib::XBlackPixel(display, 0), + ); + x11::xlib::XMapWindow(display, win); + + let rimage = NonNull::new(RLoadImage( + (*app.screen.as_ptr()).rcontext, + c"tests/image_128x120_varying_alpha.png".as_ptr(), + 255, + )) + .unwrap(); + + // The threshold given to WMCreatePixmapFromRImage is compared against + // the image's alpha channel. Pixels whose transparency are below the + // threshold are masked out. This should draw a quartet of images with + // varying masks. + + // Totally masked. + let pixmap_255 = NonNull::new(WMCreatePixmapFromRImage( + app.screen.as_ptr(), + rimage.as_ptr(), + 255, + )) + .unwrap(); + WMDrawPixmap(pixmap_255.as_ptr(), win, 70, 74); + // Three bubbles masked. + let pixmap_200 = NonNull::new(WMCreatePixmapFromRImage( + app.screen.as_ptr(), + rimage.as_ptr(), + 200, + )) + .unwrap(); + WMDrawPixmap(pixmap_200.as_ptr(), win, 200, 74); + // Two bubbles masked. + let pixmap_128 = NonNull::new(WMCreatePixmapFromRImage( + app.screen.as_ptr(), + rimage.as_ptr(), + 128, + )) + .unwrap(); + WMDrawPixmap(pixmap_128.as_ptr(), win, 70, 200); + // Nothing masked. + let pixmap_0 = NonNull::new(WMCreatePixmapFromRImage( + app.screen.as_ptr(), + rimage.as_ptr(), + 0, + )) + .unwrap(); + WMDrawPixmap(pixmap_0.as_ptr(), win, 200, 200); + + while app.pump_event_queue(Instant::now()) {} + assert_png_snapshot!("from_r_image_with_mask", app.xvfb.png_screenshot()); + WMReleasePixmap(pixmap_255.as_ptr()); + WMReleasePixmap(pixmap_200.as_ptr()); + WMReleasePixmap(pixmap_128.as_ptr()); + WMReleasePixmap(pixmap_0.as_ptr()); + RReleaseImage(rimage.as_ptr()); + } +} + +#[test] +fn draw_blended_pixmap_from_r_image() { + let mut app = HeadlessApplication::new(); + unsafe { + let display = (*app.screen.as_ptr()).display; + let win = x11::xlib::XCreateSimpleWindow( + display, + (*app.screen.as_ptr()).rootWin, + 0, + 0, + 512, + 512, + 1, + 1, + x11::xlib::XWhitePixel(display, 0), + ); + x11::xlib::XMapWindow(display, win); + + let rimage = RLoadImage( + (*app.screen.as_ptr()).rcontext, + c"tests/image_128x120.png".as_ptr(), + 0, + ); + let pixmap = NonNull::new(WMCreateBlendedPixmapFromRImage( + app.screen.as_ptr(), + rimage, + &RColor { + red: 255, + green: 0, + blue: 0, + alpha: 255, + } as *const _, + )) + .unwrap(); + WMDrawPixmap(pixmap.as_ptr(), win, 70, 74); + + while app.pump_event_queue(Instant::now()) {} + assert_png_snapshot!("from_r_image_no_mask", app.xvfb.png_screenshot()); + WMReleasePixmap(pixmap.as_ptr()); + } +} + +#[test] +fn draw_blended_pixmap_from_file() { + let mut app = HeadlessApplication::new(); + unsafe { + let display = (*app.screen.as_ptr()).display; + let win = x11::xlib::XCreateSimpleWindow( + display, + (*app.screen.as_ptr()).rootWin, + 0, + 0, + 512, + 512, + 1, + 1, + x11::xlib::XWhitePixel(display, 0), + ); + x11::xlib::XMapWindow(display, win); + + let pixmap = NonNull::new(WMCreatePixmapFromFile( + app.screen.as_ptr(), + c"tests/image_with_transparent_dot_128x120.png".as_ptr(), + )) + .unwrap(); + WMDrawPixmap(pixmap.as_ptr(), win, 64, 96); + while app.pump_event_queue(Instant::now()) {} + assert_png_snapshot!("from_file_blended_base_pixmap", app.xvfb.png_screenshot()); + + x11::xlib::XUnmapWindow(display, win); + WMReleasePixmap(pixmap.as_ptr()); + + let win = x11::xlib::XCreateSimpleWindow( + display, + (*app.screen.as_ptr()).rootWin, + 0, + 0, + 512, + 512, + 1, + 1, + x11::xlib::XWhitePixel(display, 0), + ); + x11::xlib::XMapWindow(display, win); + while app.pump_event_queue(Instant::now()) {} + assert_png_snapshot!( + "from_file_blended_cleared_window", + app.xvfb.png_screenshot() + ); + + let pixmap = NonNull::new(WMCreateBlendedPixmapFromFile( + app.screen.as_ptr(), + c"tests/image_with_transparent_dot_128x120.png".as_ptr(), + &RColor { + red: 255, + green: 0, + blue: 0, + alpha: 255, + } as *const _, + )) + .unwrap(); + WMDrawPixmap(pixmap.as_ptr(), win, 64, 96); + + while app.pump_event_queue(Instant::now()) {} + assert_png_snapshot!("from_file_blended_with_red", app.xvfb.png_screenshot()); + WMReleasePixmap(pixmap.as_ptr()); + } +} + +#[test] +fn draw_scaled_blended_pixmap_from_file() { + let mut app = HeadlessApplication::new(); + unsafe { + let display = (*app.screen.as_ptr()).display; + let win = x11::xlib::XCreateSimpleWindow( + display, + (*app.screen.as_ptr()).rootWin, + 0, + 0, + 512, + 512, + 1, + 1, + x11::xlib::XWhitePixel(display, 0), + ); + x11::xlib::XMapWindow(display, win); + + let pixmap = NonNull::new(WMCreatePixmapFromFile( + app.screen.as_ptr(), + c"tests/image_with_transparent_dot_128x120.png".as_ptr(), + )) + .unwrap(); + WMDrawPixmap(pixmap.as_ptr(), win, 64, 96); + while app.pump_event_queue(Instant::now()) {} + assert_png_snapshot!( + "from_file_scaled_blended_base_pixmap", + app.xvfb.png_screenshot() + ); + + x11::xlib::XUnmapWindow(display, win); + WMReleasePixmap(pixmap.as_ptr()); + + let win = x11::xlib::XCreateSimpleWindow( + display, + (*app.screen.as_ptr()).rootWin, + 0, + 0, + 512, + 512, + 1, + 1, + x11::xlib::XWhitePixel(display, 0), + ); + x11::xlib::XMapWindow(display, win); + while app.pump_event_queue(Instant::now()) {} + assert_png_snapshot!( + "from_file_scaled_blended_cleared_window", + app.xvfb.png_screenshot() + ); + + let pixmap = NonNull::new(WMCreateScaledBlendedPixmapFromFile( + app.screen.as_ptr(), + c"tests/image_with_transparent_dot_128x120.png".as_ptr(), + &RColor { + red: 255, + green: 0, + blue: 0, + alpha: 255, + } as *const _, + 60, + 64, + )) + .unwrap(); + WMDrawPixmap(pixmap.as_ptr(), win, 64, 96); + + while app.pump_event_queue(Instant::now()) {} + assert_png_snapshot!( + "from_file_scaled_blended_with_red", + app.xvfb.png_screenshot() + ); + WMReleasePixmap(pixmap.as_ptr()); + } +} + +#[test] +fn draw_scaled_blended_pixmap_from_file_non_integral_scaling() { + let mut app = HeadlessApplication::new(); + unsafe { + let display = (*app.screen.as_ptr()).display; + let win = x11::xlib::XCreateSimpleWindow( + display, + (*app.screen.as_ptr()).rootWin, + 0, + 0, + 512, + 512, + 1, + 1, + x11::xlib::XWhitePixel(display, 0), + ); + x11::xlib::XMapWindow(display, win); + + let pixmap = NonNull::new(WMCreatePixmapFromFile( + app.screen.as_ptr(), + c"tests/image_128x120.png".as_ptr(), + )) + .unwrap(); + WMDrawPixmap(pixmap.as_ptr(), win, 64, 96); + while app.pump_event_queue(Instant::now()) {} + assert_png_snapshot!( + "from_file_scaled_blended_non_integral_base_pixmap", + app.xvfb.png_screenshot() + ); + + x11::xlib::XUnmapWindow(display, win); + WMReleasePixmap(pixmap.as_ptr()); + + let win = x11::xlib::XCreateSimpleWindow( + display, + (*app.screen.as_ptr()).rootWin, + 0, + 0, + 512, + 512, + 1, + 1, + x11::xlib::XWhitePixel(display, 0), + ); + x11::xlib::XMapWindow(display, win); + while app.pump_event_queue(Instant::now()) {} + assert_png_snapshot!( + "from_file_scaled_blended_non_integral_cleared_window", + app.xvfb.png_screenshot() + ); + + let pixmap = NonNull::new(WMCreateScaledBlendedPixmapFromFile( + app.screen.as_ptr(), + // No alpha channel on this image, so no color blending happens. + c"tests/image_128x120.png".as_ptr(), + &RColor { + red: 255, + green: 0, + blue: 0, + alpha: 255, + } as *const _, + // Shrink by only a little bit, such that simple integer division + // might be thrown off. This test ensures that rescaling will + // actually happen. + 110, + 114, + )) + .unwrap(); + WMDrawPixmap(pixmap.as_ptr(), win, 64, 96); + + while app.pump_event_queue(Instant::now()) {} + assert_png_snapshot!( + "from_file_scaled_blended_non_integral_scaled", + app.xvfb.png_screenshot() + ); + WMReleasePixmap(pixmap.as_ptr()); + } +} diff --git a/WINGs/wings-rs/Makefile.am b/WINGs/wings-rs/Makefile.am index 9191d38a..14eda0fe 100644 --- a/WINGs/wings-rs/Makefile.am +++ b/WINGs/wings-rs/Makefile.am @@ -51,6 +51,7 @@ src/WINGsP.rs: ../WINGs/WINGsP.h ../../wrlib/wraster.h ../WINGs/WINGs.h ../WINGs --allowlist-type "_WINGsConfiguration" \ --allowlist-item "^WMAlignment" \ --allowlist-item "^WMReliefType" \ + --allowlist-function "^WM(Create|Release|Draw)Pixmap|^WMCreate(|Blended|ScaledBlended)PixmapFromFile|^WMCreate(|Blended)PixmapFromRImage" \ -o src/WINGsP.rs -- \ @PANGO_CFLAGS@ \ -I../../wrlib \ diff --git a/wrlib-rs/Makefile.am b/wrlib-rs/Makefile.am index 4291d9d4..228aaa4f 100644 --- a/wrlib-rs/Makefile.am +++ b/wrlib-rs/Makefile.am @@ -12,6 +12,7 @@ src/ffi.rs: ../wrlib/wraster.h patch_ffi.sed Makefile --allowlist-type "Bool" \ --allowlist-type "R(Context|ContextAttributes|Image|RenderingMode|ScalingFilter|StdColormapMode|ImageFormat|Color)" \ --allowlist-function "RGetClosestXColor" \ + --allowlist-function "RLoadImage|RReleaseImage" \ -o src/ffi.rs \ -- \ -I../../wrlib \