mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-17 21:27:00 +00:00
Merge pull request #8166 from dotCooCoo/fix/blur-drag-test-clock
Tests: canvas tests keep their color settings when a parallel test changes them
This commit is contained in:
@@ -66,8 +66,8 @@ use overlays::selected_anchor;
|
||||
use overlays::{HandleLook, blend_widgets_overlay, draw_inside_overlay, draw_overlays, hover_highlight, ime_geometry, selection_overlay};
|
||||
pub use panes::Panes;
|
||||
pub(crate) use panes::{consolidate, note_drop, noted_cursor, pane, release_on_noted, tile, tiled_area};
|
||||
pub(crate) use raster::{KeptFrame, color_image, color_image_owned, render_job};
|
||||
use raster::{changed_pixels, frame_ppp, pixel_region, upload};
|
||||
pub(crate) use raster::{color_image, color_image_owned, render_job};
|
||||
pub use selection_marks::SelectionMarks;
|
||||
#[cfg(test)]
|
||||
pub(crate) use task_bar::chip_paints;
|
||||
|
||||
@@ -2821,10 +2821,20 @@ fn the_art_renders_within_the_largest_texture_side() {
|
||||
assert_eq!(pixel_region(&xf, 1024), None, "more than the display's largest texture");
|
||||
}
|
||||
|
||||
/// Run a test that compares two renders with the color settings that are active when it starts.
|
||||
/// A test on another thread can change the process's active settings; this thread keeps its own.
|
||||
fn keeping_color_settings(test: fn()) {
|
||||
vectorcraft_color::cms::with_active(vectorcraft_color::cms::active(), test);
|
||||
}
|
||||
|
||||
/// A placed document's bitmap made in the background renders the canvas again only where the
|
||||
/// objects showing its file are: both copies of the file are in the part rendered again.
|
||||
#[test]
|
||||
fn a_ready_placed_document_bitmap_renders_only_its_part_of_the_canvas() {
|
||||
keeping_color_settings(a_ready_placed_bitmap);
|
||||
}
|
||||
|
||||
fn a_ready_placed_bitmap() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width":400,"height":300})).unwrap();
|
||||
app.ui.task_bar = false;
|
||||
@@ -2859,9 +2869,8 @@ fn a_ready_placed_document_bitmap_renders_only_its_part_of_the_canvas() {
|
||||
};
|
||||
let (_, delta) = frame_output(&mut app, &ctx);
|
||||
assert!(canvas(&app, delta).is_some_and(|(pos, _)| pos.is_none()), "the first frame renders all of it");
|
||||
let t = std::time::Instant::now();
|
||||
while vectorcraft_render::placed_document::busy() && t.elapsed().as_secs() < 20 {
|
||||
std::thread::sleep(std::time::Duration::from_millis(5));
|
||||
while vectorcraft_render::placed_document::busy() {
|
||||
std::thread::yield_now();
|
||||
}
|
||||
let (_, delta) = frame_output(&mut app, &ctx);
|
||||
let (pos, size) = canvas(&app, delta).expect("the bitmap shows");
|
||||
@@ -3137,6 +3146,10 @@ fn the_canvas_is_drawn_through_the_display_profile_while_the_preference_is_on()
|
||||
/// transparency grid renders the art again, and Outline converts the art alone.
|
||||
#[test]
|
||||
fn translucent_art_over_the_paper_is_blended_before_the_display_profile() {
|
||||
keeping_color_settings(translucent_art_over_the_paper);
|
||||
}
|
||||
|
||||
fn translucent_art_over_the_paper() {
|
||||
use crate::display_profile::{Found, Reading};
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
|
||||
@@ -3490,12 +3503,42 @@ fn the_first_view_reports_the_plug_in_effects_it_deferred() {
|
||||
}
|
||||
}
|
||||
|
||||
/// The render worker's side of a controlled worker: the test thread renders the jobs the canvas
|
||||
/// queues, with [`crate::render_worker::render`] and the worker's own renderer and last frame.
|
||||
struct WorkerSide {
|
||||
jobs: std::sync::mpsc::Receiver<crate::render_worker::Job>,
|
||||
done: std::sync::mpsc::Sender<crate::render_worker::Done>,
|
||||
renderer: vectorcraft_render::Renderer,
|
||||
kept: Option<crate::canvas::KeptFrame>,
|
||||
}
|
||||
|
||||
impl WorkerSide {
|
||||
/// A controlled worker for the canvas, and its side.
|
||||
fn start() -> (crate::render_worker::Worker, Self) {
|
||||
let (worker, jobs, done) = crate::render_worker::Worker::test_channel();
|
||||
(worker, Self { jobs, done, renderer: vectorcraft_render::Renderer::new(), kept: None })
|
||||
}
|
||||
|
||||
/// Render the newest job queued, as the worker thread does, and send its frame with a time of
|
||||
/// 50 ms: the canvas then keeps sending the document's frames to the worker. False when no job
|
||||
/// is queued.
|
||||
fn render(&mut self) -> bool {
|
||||
let Some(job) = self.jobs.try_iter().last() else { return false };
|
||||
let done = crate::render_worker::render(&mut self.renderer, &mut self.kept, job);
|
||||
self.done.send(crate::render_worker::Done { ms: 50.0, ..done }).is_ok()
|
||||
}
|
||||
}
|
||||
|
||||
/// A drag of an object with raster effects (#1257): the drag's frames render while
|
||||
/// interacting and draw the object's drop shadow and filtered content from the rasters of the
|
||||
/// frame before; the frame after the drag renders without `interacting`, on the render worker,
|
||||
/// and draws what a fresh renderer draws.
|
||||
/// and draws what a fresh renderer draws. The worker is a controlled one ([`WorkerSide`]).
|
||||
#[test]
|
||||
fn dragging_an_object_with_raster_effects_draws_its_rasters_moved() {
|
||||
keeping_color_settings(dragging_with_raster_effects);
|
||||
}
|
||||
|
||||
fn dragging_with_raster_effects() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
|
||||
app.canvas.worker_started = true; // render on this thread
|
||||
@@ -3528,17 +3571,13 @@ fn dragging_an_object_with_raster_effects_draws_its_rasters_moved() {
|
||||
}
|
||||
// The frame after the drag runs the effects again: on the worker, while the canvas shows
|
||||
// the drag's last frame.
|
||||
app.canvas.worker = crate::render_worker::Worker::spawn(ctx.clone());
|
||||
let (worker, mut side) = WorkerSide::start();
|
||||
app.canvas.worker = Some(worker);
|
||||
app.session.pointer(&PointerEvent::new(PointerKind::Up, 181.9, 131.3), view).unwrap();
|
||||
assert!(upload(&mut app).is_none(), "not rendered on this thread");
|
||||
assert!(app.canvas.worker.as_ref().and_then(|w| w.pending.as_ref()).is_some_and(|k| !k.interacting), "sent to the worker");
|
||||
let until = std::time::Instant::now() + std::time::Duration::from_secs(60);
|
||||
let mut after = None;
|
||||
while after.is_none() && std::time::Instant::now() < until {
|
||||
std::thread::sleep(std::time::Duration::from_millis(5));
|
||||
after = upload(&mut app);
|
||||
}
|
||||
let after = after.expect("the worker's frame arrives");
|
||||
assert!(side.render(), "the worker renders the frame");
|
||||
let after = upload(&mut app).expect("the worker's frame arrives");
|
||||
assert!(app.canvas.key.as_ref().is_some_and(|k| !k.interacting));
|
||||
assert!(!app.canvas.moved);
|
||||
app.canvas.worker = None;
|
||||
@@ -3554,6 +3593,10 @@ fn dragging_an_object_with_raster_effects_draws_its_rasters_moved() {
|
||||
/// without a drag, renders without `dragging` and draws the same.
|
||||
#[test]
|
||||
fn a_drag_on_the_canvas_draws_raster_effects_at_a_lower_resolution() {
|
||||
keeping_color_settings(a_drag_at_a_lower_resolution);
|
||||
}
|
||||
|
||||
fn a_drag_at_a_lower_resolution() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
|
||||
app.canvas.worker_started = true; // render on this thread
|
||||
@@ -3609,9 +3652,13 @@ fn a_drag_on_the_canvas_draws_raster_effects_at_a_lower_resolution() {
|
||||
/// the blur reaches far past the raster budget, so the still frame keeps the backdrop's raster
|
||||
/// cropped to the view, and each frame of a Selection tool drag draws it from there instead of
|
||||
/// previewing it at the drag's lower resolution: on this thread, and on the worker, where the
|
||||
/// frames of a heavy document render.
|
||||
/// frames of a heavy document render. The worker is a controlled one ([`WorkerSide`]).
|
||||
#[test]
|
||||
fn a_drag_over_a_wide_blur_draws_the_blur_from_the_still_frame() {
|
||||
keeping_color_settings(a_drag_over_a_wide_blur);
|
||||
}
|
||||
|
||||
fn a_drag_over_a_wide_blur() {
|
||||
for on_worker in [false, true] {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 595, "height": 842})).unwrap();
|
||||
@@ -3623,9 +3670,9 @@ fn a_drag_over_a_wide_blur_draws_the_blur_from_the_still_frame() {
|
||||
app.run("select.set", json!({"ids": [square]})).unwrap();
|
||||
app.select_tool("selection");
|
||||
let ctx = egui::Context::default();
|
||||
// One headless frame with `events`, then, on the worker, frames until the frame it renders
|
||||
// for them is shown.
|
||||
let run = |app: &mut VectorcraftApp, events: Vec<egui::Event>| {
|
||||
// One headless frame with `events`, then, with a worker, its frames rendered and shown
|
||||
// until none is pending.
|
||||
let run = |app: &mut VectorcraftApp, side: &mut Option<WorkerSide>, events: Vec<egui::Event>| {
|
||||
let frame = |app: &mut VectorcraftApp, events| {
|
||||
let raw =
|
||||
egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(Pos2::ZERO, vec2(1440.0, 870.0))), events, ..Default::default() };
|
||||
@@ -3633,39 +3680,40 @@ fn a_drag_over_a_wide_blur_draws_the_blur_from_the_still_frame() {
|
||||
out.textures_delta.clear();
|
||||
};
|
||||
frame(app, events);
|
||||
let until = std::time::Instant::now() + std::time::Duration::from_secs(60);
|
||||
while app.canvas.worker.as_ref().is_some_and(|w| w.pending.is_some()) && std::time::Instant::now() < until {
|
||||
std::thread::sleep(std::time::Duration::from_millis(5));
|
||||
for _ in 0..8 {
|
||||
if !side.as_mut().is_some_and(WorkerSide::render) {
|
||||
break;
|
||||
}
|
||||
frame(app, vec![]);
|
||||
}
|
||||
assert!(app.canvas.worker.as_ref().is_none_or(|w| w.pending.is_none()), "the worker's frame is shown");
|
||||
};
|
||||
let moved = |app: &VectorcraftApp| if on_worker { app.canvas.moved } else { app.canvas.renderer.stats.moved > 0 };
|
||||
run(&mut app, vec![]);
|
||||
let mut side = None;
|
||||
run(&mut app, &mut side, vec![]);
|
||||
if let Some(vm) = app.view_mut() {
|
||||
(vm.zoom, vm.center) = (2.0, Point::new(290.0, 410.0));
|
||||
}
|
||||
if on_worker {
|
||||
app.canvas.worker = crate::render_worker::Worker::spawn(ctx.clone());
|
||||
let (worker, worker_side) = WorkerSide::start();
|
||||
app.canvas.worker = Some(worker);
|
||||
app.canvas.last_ms = 50.0;
|
||||
side = Some(worker_side);
|
||||
}
|
||||
run(&mut app, vec![]);
|
||||
run(&mut app, &mut side, vec![]);
|
||||
assert_eq!(app.canvas.from_worker, on_worker);
|
||||
assert!(!moved(&app), "a still frame, on the worker: {on_worker}");
|
||||
let at = app.canvas_rect.unwrap().center();
|
||||
let button = |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };
|
||||
run(&mut app, vec![egui::Event::PointerMoved(at)]);
|
||||
run(&mut app, vec![button(at, true)]);
|
||||
run(&mut app, &mut side, vec![egui::Event::PointerMoved(at)]);
|
||||
run(&mut app, &mut side, vec![button(at, true)]);
|
||||
for step in [1.0, 2.0, 3.0] {
|
||||
run(&mut app, vec![egui::Event::PointerMoved(at + vec2(13.0, 7.0) * step)]);
|
||||
run(&mut app, &mut side, vec![egui::Event::PointerMoved(at + vec2(13.0, 7.0) * step)]);
|
||||
assert!(app.canvas.key.as_ref().is_some_and(|k| k.interacting && k.dragging), "step {step}, on the worker: {on_worker}");
|
||||
assert_eq!(app.canvas.from_worker, on_worker, "step {step}");
|
||||
assert!(
|
||||
!moved(&app),
|
||||
"the blur drawn from the still frame's raster, step {step}, on the worker: {on_worker} ({} ms)",
|
||||
app.perf.render_ms
|
||||
);
|
||||
assert!(!moved(&app), "the blur drawn from the still frame's raster, step {step}, on the worker: {on_worker}");
|
||||
}
|
||||
run(&mut app, vec![button(at + vec2(39.0, 21.0), false)]);
|
||||
run(&mut app, &mut side, vec![button(at + vec2(39.0, 21.0), false)]);
|
||||
let info = app.run("document.inspect", json!({})).unwrap();
|
||||
let children = info["layers"][0]["children"].as_array().unwrap().clone();
|
||||
let x0 = |id: &serde_json::Value| children.iter().find(|c| c["id"] == *id).unwrap()["bounds"]["x"].as_f64().unwrap();
|
||||
@@ -3706,6 +3754,10 @@ fn an_interaction_stays_on_the_worker_that_drew_the_frame_shown() {
|
||||
/// leaves the document as it was (#1257): here a drag back to where it started.
|
||||
#[test]
|
||||
fn a_drag_back_to_its_start_renders_again_after_it() {
|
||||
keeping_color_settings(a_drag_back_to_its_start);
|
||||
}
|
||||
|
||||
fn a_drag_back_to_its_start() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
|
||||
app.canvas.worker_started = true; // render on this thread
|
||||
@@ -3772,6 +3824,10 @@ fn canvas_render_jobs_use_renderer_limited_dimensions() {
|
||||
/// controlled worker cannot finish early, even if egui repeats a layout pass.
|
||||
#[test]
|
||||
fn cached_frames_keep_their_scale_during_resize_rotation_and_dpi_changes() {
|
||||
keeping_color_settings(cached_frames_keep_their_scale);
|
||||
}
|
||||
|
||||
fn cached_frames_keep_their_scale() {
|
||||
for (old_rot, new_rot, old_ppp, new_ppp, pixel, resize_only) in [
|
||||
// Isolate the original panel/window resize: zoom, pan, rotation and DPI stay fixed.
|
||||
(0.0, 0.0, 1.0, 1.0, false, true),
|
||||
@@ -3867,9 +3923,13 @@ fn cached_frames_keep_their_scale_during_resize_rotation_and_dpi_changes() {
|
||||
/// a heavy document), the canvas draws the last frame turned until that frame arrives: each
|
||||
/// corner goes where the new view puts the document point that the corner showed. The new frame
|
||||
/// is then drawn unturned. In Pixel Preview the last frame's pixels stay over the document rect
|
||||
/// they cover.
|
||||
/// they cover. The worker is a controlled one ([`WorkerSide`]).
|
||||
#[test]
|
||||
fn a_turned_view_draws_the_last_frame_turned_until_its_own_arrives() {
|
||||
keeping_color_settings(a_turned_view);
|
||||
}
|
||||
|
||||
fn a_turned_view() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
|
||||
app.session.execute("shape.rectangle", &json!({"x": 100, "y": 50, "width": 200, "height": 200})).unwrap();
|
||||
@@ -3890,7 +3950,8 @@ fn a_turned_view_draws_the_last_frame_turned_until_its_own_arrives() {
|
||||
})
|
||||
};
|
||||
// With a worker and a last frame that took 50 ms, the next frame renders on the worker.
|
||||
app.canvas.worker = crate::render_worker::Worker::spawn(ctx.clone());
|
||||
let (worker, mut side) = WorkerSide::start();
|
||||
app.canvas.worker = Some(worker);
|
||||
app.canvas.last_ms = 50.0;
|
||||
app.run("view.rotateReset", json!({})).unwrap();
|
||||
let mesh = art(&mut app).expect("the last frame, turned");
|
||||
@@ -3908,11 +3969,8 @@ fn a_turned_view_draws_the_last_frame_turned_until_its_own_arrives() {
|
||||
let [a, b, _, d] = [0, 1, 2, 3].map(|i| mesh.vertices[i].pos);
|
||||
assert!((a + (b - a) * uv.x + (d - a) * uv.y - new.to_screen(p)).length() < 0.01, "the rectangle's corner");
|
||||
// The worker's frame at 0° then covers the canvas unturned.
|
||||
let until = std::time::Instant::now() + std::time::Duration::from_secs(60);
|
||||
while app.canvas.key.as_ref().is_some_and(|k| k.rot != 0.0) && std::time::Instant::now() < until {
|
||||
std::thread::sleep(std::time::Duration::from_millis(5));
|
||||
shapes(&mut app, &ctx);
|
||||
}
|
||||
assert!(side.render(), "the worker renders the frame at 0°");
|
||||
shapes(&mut app, &ctx);
|
||||
assert!(app.canvas.key.as_ref().is_some_and(|k| k.rot == 0.0), "the worker's frame arrives");
|
||||
let b = art(&mut app).expect("the worker's frame").calc_bounds();
|
||||
assert!((b.min - rect.min).length() < 0.01 && (b.max - rect.max).length() < 0.01, "{b:?} over {rect:?}");
|
||||
@@ -3922,7 +3980,8 @@ fn a_turned_view_draws_the_last_frame_turned_until_its_own_arrives() {
|
||||
app.view_mut().unwrap().zoom = 8.0;
|
||||
shapes(&mut app, &ctx);
|
||||
let [x0, y0, ..] = app.canvas.key.as_ref().and_then(|k| k.pixel).expect("the pixels rendered");
|
||||
app.canvas.worker = crate::render_worker::Worker::spawn(ctx.clone());
|
||||
let (worker, _side) = WorkerSide::start();
|
||||
app.canvas.worker = Some(worker);
|
||||
app.canvas.last_ms = 50.0;
|
||||
app.view_mut().unwrap().rotation = 30.0;
|
||||
let mesh = art(&mut app).expect("the last frame's pixels");
|
||||
@@ -3937,6 +3996,10 @@ fn a_turned_view_draws_the_last_frame_turned_until_its_own_arrives() {
|
||||
/// fill is dropped.
|
||||
#[test]
|
||||
fn a_pan_fills_the_area_the_last_frame_leaves_until_the_worker_frame_arrives() {
|
||||
keeping_color_settings(a_pan_fills_the_area);
|
||||
}
|
||||
|
||||
fn a_pan_fills_the_area() {
|
||||
let ctx = egui::Context::default();
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
|
||||
@@ -4062,6 +4125,10 @@ fn a_pan_fills_the_area_the_last_frame_leaves_until_the_worker_frame_arrives() {
|
||||
/// before.
|
||||
#[test]
|
||||
fn without_a_worker_a_heavy_canvas_is_reprojected_until_the_view_is_still() {
|
||||
keeping_color_settings(without_a_worker_a_heavy_canvas);
|
||||
}
|
||||
|
||||
fn without_a_worker_a_heavy_canvas() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
|
||||
app.session.execute("shape.rectangle", &json!({"x": 100, "y": 50, "width": 200, "height": 200})).unwrap();
|
||||
@@ -4172,6 +4239,10 @@ fn the_canvas_waits_only_while_the_view_of_a_slow_frame_changes() {
|
||||
/// worker's pixel copy ask for that.
|
||||
#[test]
|
||||
fn a_bitmap_made_for_another_documents_file_leaves_a_pan_waiting() {
|
||||
keeping_color_settings(a_bitmap_for_another_documents_file);
|
||||
}
|
||||
|
||||
fn a_bitmap_for_another_documents_file() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
|
||||
app.session.execute("shape.rectangle", &json!({"x": 100, "y": 50, "width": 200, "height": 200})).unwrap();
|
||||
@@ -13156,6 +13227,10 @@ fn pan_doc() -> (std::sync::Arc<vectorcraft_doc::Document>, CacheKey) {
|
||||
/// put in that frame moves with the pan, and the frame matches a whole render where the mark is not.
|
||||
#[test]
|
||||
fn a_whole_pixel_pan_copies_the_pixels_that_stay_on_screen() {
|
||||
keeping_color_settings(a_whole_pixel_pan);
|
||||
}
|
||||
|
||||
fn a_whole_pixel_pan() {
|
||||
let (doc, key) = pan_doc();
|
||||
for pan in [(10.0, 0.0), (-10.0, 0.0), (0.0, 7.0), (0.0, -7.0), (-13.0, 5.0)] {
|
||||
let mut r = vectorcraft_render::Renderer::new();
|
||||
@@ -13183,6 +13258,10 @@ fn a_whole_pixel_pan_copies_the_pixels_that_stay_on_screen() {
|
||||
/// plug-in registry, and the plug-in is removed after.
|
||||
#[test]
|
||||
fn a_plug_in_change_draws_the_document_s_plug_in_effects_again() {
|
||||
keeping_color_settings(a_plug_in_change);
|
||||
}
|
||||
|
||||
fn a_plug_in_change() {
|
||||
use vectorcraft_plugins::wat as tpl;
|
||||
let id = "test.canvas.redraw";
|
||||
let module = vectorcraft_format::base64_encode(&wat::parse_str(tpl::module(&tpl::manifest(id, "effect", "{}"), tpl::ECHO, "", 1)).unwrap());
|
||||
@@ -13225,6 +13304,10 @@ fn a_plug_in_change_draws_the_document_s_plug_in_effects_again() {
|
||||
/// compares such frames with a fresh render pixel by pixel.
|
||||
#[test]
|
||||
fn a_frame_renders_whole_when_anything_but_a_whole_pixel_pan_changed() {
|
||||
keeping_color_settings(a_frame_renders_whole);
|
||||
}
|
||||
|
||||
fn a_frame_renders_whole() {
|
||||
let (doc, key) = pan_doc();
|
||||
let other_opts = |f: &dyn Fn(&mut vectorcraft_render::RenderOptions)| {
|
||||
let mut job = pan_job(&doc, &key, (10.0, 0.0));
|
||||
@@ -13302,6 +13385,10 @@ fn a_frame_renders_whole_when_anything_but_a_whole_pixel_pan_changed() {
|
||||
/// not kept. A frame that may not copy can still be kept.
|
||||
#[test]
|
||||
fn the_render_worker_keeps_one_frame_up_to_its_limit() {
|
||||
keeping_color_settings(the_render_worker_keeps_one_frame);
|
||||
}
|
||||
|
||||
fn the_render_worker_keeps_one_frame() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 256, "height": 128})).unwrap();
|
||||
let id = app.run("shape.rectangle", json!({"x": 16, "y": 16, "width": 64, "height": 64})).unwrap()["id"].clone();
|
||||
@@ -13348,6 +13435,10 @@ fn the_render_worker_keeps_one_frame_up_to_its_limit() {
|
||||
/// worker renders whole matches a fresh render, and each copied frame is within one level of it.
|
||||
#[test]
|
||||
fn worker_frames_match_a_fresh_render_through_a_session() {
|
||||
keeping_color_settings(worker_frames_match_a_fresh_render);
|
||||
}
|
||||
|
||||
fn worker_frames_match_a_fresh_render() {
|
||||
let (doc, key) = pan_doc();
|
||||
let mut edited = (*doc).clone();
|
||||
edited.layers.reverse();
|
||||
@@ -13433,6 +13524,10 @@ fn worker_frames_match_a_fresh_render_through_a_session() {
|
||||
/// not keep such a frame for the pan to copy from.
|
||||
#[test]
|
||||
fn a_pan_over_art_the_frame_size_decides_renders_whole() {
|
||||
keeping_color_settings(a_pan_over_art);
|
||||
}
|
||||
|
||||
fn a_pan_over_art() {
|
||||
let (_, key) = pan_doc();
|
||||
let effect = |effect: &str, params: serde_json::Value| {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
@@ -13488,6 +13583,10 @@ fn a_pan_over_art_the_frame_size_decides_renders_whole() {
|
||||
/// before and only once.
|
||||
#[test]
|
||||
fn a_frame_with_copied_pixels_renders_whole_once_the_view_stops() {
|
||||
keeping_color_settings(a_frame_with_copied_pixels);
|
||||
}
|
||||
|
||||
fn a_frame_with_copied_pixels() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
|
||||
app.canvas.worker_started = true;
|
||||
@@ -13534,6 +13633,10 @@ fn a_frame_with_copied_pixels_renders_whole_once_the_view_stops() {
|
||||
/// first step of the next pan copies from it. The jobs are the ones the canvas asks for.
|
||||
#[test]
|
||||
fn a_pan_after_the_settling_frame_copies() {
|
||||
keeping_color_settings(a_pan_after_the_settling_frame);
|
||||
}
|
||||
|
||||
fn a_pan_after_the_settling_frame() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
|
||||
app.canvas.worker_started = true;
|
||||
@@ -13632,6 +13735,10 @@ fn the_render_worker_thread_copies_a_pan() {
|
||||
/// meanwhile, does not queue the frame again while it renders, and shows it once it lands.
|
||||
#[test]
|
||||
fn a_documents_first_frame_renders_on_the_worker() {
|
||||
keeping_color_settings(a_documents_first_frame);
|
||||
}
|
||||
|
||||
fn a_documents_first_frame() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
|
||||
app.canvas.worker_started = true;
|
||||
|
||||
@@ -52,6 +52,15 @@ pub struct Done {
|
||||
pub reused: bool,
|
||||
}
|
||||
|
||||
/// Render `job` as the worker thread does: inside the job's automation roots and deferred
|
||||
/// effects, with the worker's renderer `r` and its last frame `kept`.
|
||||
pub(crate) fn render(r: &mut Renderer, kept: &mut Option<crate::canvas::KeptFrame>, job: Job) -> Done {
|
||||
let t0 = crate::now_ms();
|
||||
let frame = job.scope.clone().run(|| job.effects.view(|| crate::canvas::render_job(r, kept, &job)));
|
||||
let ms = crate::now_ms() - t0;
|
||||
Done { key: job.key, doc: job.doc, opts: job.opts, img: frame.img, ms, moved: frame.moved, reused: frame.reused }
|
||||
}
|
||||
|
||||
pub struct Worker {
|
||||
tx: Sender<Job>,
|
||||
rx: Receiver<Done>,
|
||||
@@ -76,11 +85,7 @@ impl Worker {
|
||||
while let Ok(newer) = jobs.try_recv() {
|
||||
job = newer;
|
||||
}
|
||||
let t0 = crate::now_ms();
|
||||
let frame = job.scope.clone().run(|| job.effects.view(|| crate::canvas::render_job(&mut r, &mut kept, &job)));
|
||||
let ms = crate::now_ms() - t0;
|
||||
let done = Done { key: job.key, doc: job.doc, opts: job.opts, img: frame.img, ms, moved: frame.moved, reused: frame.reused };
|
||||
if done_tx.send(done).is_err() {
|
||||
if done_tx.send(render(&mut r, &mut kept, job)).is_err() {
|
||||
break;
|
||||
}
|
||||
ctx.request_repaint();
|
||||
|
||||
Reference in New Issue
Block a user