summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/kitty.zig127
-rw-r--r--test/pdf.zig279
-rw-r--r--test/pdf_pointer_bench.zig10
-rw-r--r--test/pdf_scroll_bench.zig70
4 files changed, 278 insertions, 208 deletions
diff --git a/test/kitty.zig b/test/kitty.zig
index daa01060..f222f9cf 100644
--- a/test/kitty.zig
+++ b/test/kitty.zig
@@ -9,7 +9,7 @@
//! and what the emulator stores is drawn where the program put it. Each case
//! feeds a pane's output the way a pty read does and checks all three: the
//! bytes the program would read back, ghostty's image storage, and the
-//! `ImagePlace`s a frame hands the shell (which a tty re-emits to the outer
+//! placements a frame hands the shell (which a tty re-emits to the outer
//! terminal and the GUI draws; test/kitty_harness.zig follows them there).
//!
//! A case pardes does not pass yet is a `knownGap`: its check runs, the test
@@ -125,10 +125,18 @@ const Rig = struct {
return &r.vt(id).screens.active.kitty_images;
}
- fn places(r: *Rig) ![]const pardes.ImagePlace {
+ fn places(r: *Rig) ![]const pardes.Placement {
_ = r.frame.reset(.retain_capacity);
const s = try r.p.render(r.frame.allocator());
- return s.images.items;
+ return s.placements.items;
+ }
+
+ /// The id its program gave the image a place draws.
+ fn idOf(r: *Rig, place: pardes.Placement) ?u32 {
+ const shown = r.p.panes[place.pane] orelse return null;
+ var it = shown.terminal.?.vt.screens.active.kitty_images.images.iterator();
+ while (it.next()) |e| if (pardes.Placement.keyOf(shown.serial, e.key_ptr.*, @truncate(e.value_ptr.generation)) == place.key) return e.key_ptr.*;
+ return null;
}
/// The top-left cell of pane `id`'s body, in screen cells.
@@ -138,9 +146,9 @@ const Rig = struct {
}
/// The places drawn for the image a program called `image_id`.
- fn placesOf(r: *Rig, image_id: u32) ![]const pardes.ImagePlace {
- var out: std.ArrayList(pardes.ImagePlace) = .empty;
- for (try r.places()) |place| if (place.native.page == image_id)
+ fn placesOf(r: *Rig, image_id: u32) ![]const pardes.Placement {
+ var out: std.ArrayList(pardes.Placement) = .empty;
+ for (try r.places()) |place| if (r.idOf(place) == image_id)
try out.append(r.frame.allocator(), place);
return out.items;
}
@@ -155,8 +163,8 @@ const Rig = struct {
};
/// The pixel at `(x, y)` of a drawn place's whole image, as RGBA.
-fn pixel(place: pardes.ImagePlace, x: usize, y: usize) [4]u8 {
- return place.rgba[(y * place.iw + x) * 4 ..][0..4].*;
+fn pixel(place: pardes.Placement, x: usize, y: usize) [4]u8 {
+ return place.raster.bytes()[y * place.raster.stride + x * 4 ..][0..4].*;
}
test "kitty: a support query is answered on the asking pane's pty and stores nothing" {
@@ -221,7 +229,7 @@ test "kitty: RGB, RGBA, PNG and zlib-compressed RGB all draw the same pixels" {
try std.testing.expectEqual(@as(u32, 2), img.height);
const drawn = try r.placesOf(1);
try std.testing.expectEqual(@as(usize, 1), drawn.len);
- try std.testing.expectEqual(@as(usize, 4), drawn[0].iw);
+ try std.testing.expectEqual(@as(usize, 4), drawn[0].raster.w);
for ([_][2]usize{ .{ 0, 0 }, .{ 1, 1 } }) |at| try std.testing.expectEqual(red, pixel(drawn[0], at[0], at[1]));
for ([_][2]usize{ .{ 2, 0 }, .{ 3, 1 } }) |at| try std.testing.expectEqual(blue, pixel(drawn[0], at[0], at[1]));
}
@@ -361,10 +369,10 @@ test "kitty: a=T draws at the cursor and moves the cursor past the image; C=1 le
// A cell row at a time: two rows.
try std.testing.expectEqual(@as(usize, 2), drawn.len);
const o = r.origin(0);
- try std.testing.expectEqual(o.x + 4, drawn[0].x);
- try std.testing.expectEqual(o.y + 2, drawn[0].y);
- try std.testing.expectEqual(o.y + 3, drawn[1].y);
- for (drawn) |place| try std.testing.expectEqual(@as(u16, 2), place.w);
+ try std.testing.expectEqual(o.x + 4, drawn[0].dst.x);
+ try std.testing.expectEqual(o.y + 2, drawn[0].dst.y);
+ try std.testing.expectEqual(o.y + 3, drawn[1].dst.y);
+ for (drawn) |place| try std.testing.expectEqual(@as(u16, 2), place.dst.w);
}
}
@@ -383,14 +391,14 @@ test "kitty: a=p places one image twice by placement id, a source rect crops it,
const o = r.origin(0);
var drawn = try r.placesOf(7);
try std.testing.expectEqual(@as(usize, 2), drawn.len);
- var cropped: ?pardes.ImagePlace = null;
- for (drawn) |place| if (place.y == o.y + 5) {
+ var cropped: ?pardes.Placement = null;
+ for (drawn) |place| if (place.dst.y == o.y + 5) {
cropped = place;
};
const crop = cropped orelse return error.CroppedPlacementMissing;
- try std.testing.expectEqual(o.x + 9, crop.x);
- try std.testing.expectEqual(@as(u16, 1), crop.w);
- const g = crop.native.geometry.?;
+ try std.testing.expectEqual(o.x + 9, crop.dst.x);
+ try std.testing.expectEqual(@as(u16, 1), crop.dst.w);
+ const g: pardes.image.NativeGeometry = .{ .src = crop.src, .dst = crop.at.? };
try std.testing.expectEqual(@as(u32, 2), g.src.x);
try std.testing.expectEqual(@as(u32, 2), g.src.w);
// Put again under the same id, placement 1 moves; it is not doubled.
@@ -400,8 +408,8 @@ test "kitty: a=p places one image twice by placement id, a source rect crops it,
var at_ten = false;
var at_one = false;
for (drawn) |place| {
- if (place.y == o.y + 9) at_ten = true;
- if (place.y == o.y) at_one = true;
+ if (place.dst.y == o.y + 9) at_ten = true;
+ if (place.dst.y == o.y) at_one = true;
}
try std.testing.expect(at_ten and !at_one);
}
@@ -441,7 +449,7 @@ test "kitty: z-index travels with the image, and images are handed on lowest z f
var ids: [4]u32 = undefined;
for (drawn, 0..) |place, i| {
zs[i] = place.z;
- ids[i] = place.native.page;
+ ids[i] = r.idOf(place).?;
}
try std.testing.expectEqualSlices(i32, &.{ -7, 0, 3, 5 }, &zs);
try std.testing.expectEqualSlices(u32, &.{ 9, 10, 11, 8 }, &ids);
@@ -547,13 +555,13 @@ test "kitty: Unicode placeholders draw a virtual placement over two rows, with i
const drawn = try r.placesOf(7);
const o = r.origin(0);
try std.testing.expectEqual(@as(usize, 2), drawn.len);
- try std.testing.expectEqual(o.x + 2, drawn[0].x);
- try std.testing.expectEqual(o.y + 1, drawn[0].y);
- try std.testing.expectEqual(o.y + 2, drawn[1].y);
- for (drawn) |place| try std.testing.expectEqual(@as(u16, 2), place.w);
+ try std.testing.expectEqual(o.x + 2, drawn[0].dst.x);
+ try std.testing.expectEqual(o.y + 1, drawn[0].dst.y);
+ try std.testing.expectEqual(o.y + 2, drawn[1].dst.y);
+ for (drawn) |place| try std.testing.expectEqual(@as(u16, 2), place.dst.w);
// The top row shows the image's top half, the bottom its bottom half.
- try std.testing.expectEqual(@as(u32, 0), drawn[0].native.geometry.?.src.y);
- try std.testing.expectEqual(@as(u32, 1), drawn[1].native.geometry.?.src.y);
+ try std.testing.expectEqual(@as(u32, 0), drawn[0].src.y);
+ try std.testing.expectEqual(@as(u32, 1), drawn[1].src.y);
}
test "kitty: a placeholder naming its placement in the underline colour picks that placement" {
@@ -566,7 +574,7 @@ test "kitty: a placeholder naming its placement in the underline colour picks th
const drawn = try r.placesOf(7);
try std.testing.expectEqual(@as(usize, 1), drawn.len);
// Placement 2 spans two cells, so each cell is half the image.
- try std.testing.expectEqual(@as(u16, 2), drawn[0].w);
+ try std.testing.expectEqual(@as(u16, 2), drawn[0].dst.w);
}
test "kitty: an image follows its text when the shell scrolls, resizes and reflows" {
@@ -574,10 +582,10 @@ test "kitty: an image follows its text when the shell scrolls, resizes and reflo
defer r.deinit();
r.feed(0, "\x1b[5;1Hmarker" ++ apc("a=T,i=10,f=24,s=4,v=2,c=2,r=1,q=2", rgb_b64));
const o = r.origin(0);
- try std.testing.expectEqual(o.y + 4, (try r.placesOf(10))[0].y);
+ try std.testing.expectEqual(o.y + 4, (try r.placesOf(10))[0].dst.y);
// Two lines of output at the bottom scroll it up two rows.
r.feed(0, "\x1b[40;1H\n\n");
- try std.testing.expectEqual(o.y + 2, (try r.placesOf(10))[0].y);
+ try std.testing.expectEqual(o.y + 2, (try r.placesOf(10))[0].dst.y);
// A narrower pane reflows the text; the image stays on its row.
const pane = r.pane(0);
terminal.resizeGrid(pane, 40, pane.rows);
@@ -588,7 +596,7 @@ test "kitty: an image follows its text when the shell scrolls, resizes and reflo
const drawn = try r.placesOf(10);
try std.testing.expectEqual(@as(usize, 1), drawn.len);
const viewport_top: usize = @intCast(terminal.gridOffset(pane));
- try std.testing.expectEqual(o.y + @as(u16, @intCast(row - viewport_top)), drawn[0].y);
+ try std.testing.expectEqual(o.y + @as(u16, @intCast(row - viewport_top)), drawn[0].dst.y);
}
test "kitty: the alternate screen has its own images, and the primary's come back after it" {
@@ -777,7 +785,7 @@ test "kitty: a placement relative to another (P=, Q=) is drawn at its parent's c
try std.testing.expectEqual(@as(usize, 3), drawn.len);
const o = r.origin(0);
var cells: [3][2]u16 = undefined;
- for (drawn, 0..) |place, i| cells[i] = .{ place.x - o.x, place.y - o.y };
+ for (drawn, 0..) |place, i| cells[i] = .{ place.dst.x - o.x, place.dst.y - o.y };
std.mem.sort([2]u16, &cells, {}, struct {
fn lt(_: void, a: [2]u16, b: [2]u16) bool {
return a[0] < b[0];
@@ -1167,8 +1175,8 @@ test "kitty: scrolled back by pardes, an image shows on its row; scrolled forwar
const o = r.origin(0);
const drawn = try r.placesOf(20);
try std.testing.expectEqual(@as(usize, 1), drawn.len);
- try std.testing.expectEqual(o.y, drawn[0].y);
- try std.testing.expectEqual(o.x + 6, drawn[0].x);
+ try std.testing.expectEqual(o.y, drawn[0].dst.y);
+ try std.testing.expectEqual(o.x + 6, drawn[0].dst.x);
terminal.followOutput(pane);
try std.testing.expectEqual(@as(usize, 0), (try r.placesOf(20)).len);
}
@@ -1179,13 +1187,13 @@ test "kitty: an edited copy taller than the rows it covers pushes the images bel
const pane = r.pane(0);
r.feed(0, "\x1b[1;1Hone\r\ntwo\r\n\x1b[6;1H" ++ apc("a=T,i=21,f=24,s=4,v=2,c=2,r=1,q=2", rgb_b64));
const o = r.origin(0);
- try std.testing.expectEqual(o.y + 5, (try r.placesOf(21))[0].y);
+ try std.testing.expectEqual(o.y + 5, (try r.placesOf(21))[0].dst.y);
// Row 1 ("two") edited into three lines.
pane.body.mode = .normal;
pane.ovl = .{ .row = 1, .rows = 1, .text = try gpa.dupe(u8, "two\nthree\nfour") };
const drawn = try r.placesOf(21);
try std.testing.expectEqual(@as(usize, 1), drawn.len);
- try std.testing.expectEqual(o.y + 7, drawn[0].y);
+ try std.testing.expectEqual(o.y + 7, drawn[0].dst.y);
}
test "kitty: an image wider than its pane is cut at the pane's edge, never drawn over the next one" {
@@ -1201,11 +1209,11 @@ test "kitty: an image wider than its pane is cut at the pane's edge, never drawn
r.feed(0, apc("a=T,i=22,f=24,s=4,v=2,c=4,r=1,q=2", rgb_b64));
const drawn = try r.placesOf(22);
try std.testing.expectEqual(@as(usize, 1), drawn.len);
- try std.testing.expect(drawn[0].x + drawn[0].w <= o.x + r.pane(0).cols);
- try std.testing.expect(drawn[0].x + drawn[0].w <= right);
+ try std.testing.expect(drawn[0].dst.x + drawn[0].dst.w <= o.x + r.pane(0).cols);
+ try std.testing.expect(drawn[0].dst.x + drawn[0].dst.w <= right);
// And the pixels it takes are only that cell's.
- const g = drawn[0].native.geometry.?;
- try std.testing.expect(g.dst.w <= @as(u32, drawn[0].w) * 10);
+ const g: pardes.image.NativeGeometry = .{ .src = drawn[0].src, .dst = drawn[0].at.? };
+ try std.testing.expect(g.dst.w <= @as(u32, drawn[0].dst.w) * 10);
}
test "kitty: a collapsed pane draws no image" {
@@ -1224,16 +1232,16 @@ test "kitty: a new cell size (font zoom) redraws an image at the same cells, sca
defer r.deinit();
r.feed(0, "\x1b[2;3H" ++ apc("a=T,i=24,f=24,s=4,v=2,c=2,r=1,q=2", rgb_b64));
var drawn = try r.placesOf(24);
- try std.testing.expectEqual(@as(u32, 20), drawn[0].native.geometry.?.dst.w);
+ try std.testing.expectEqual(@as(u32, 20), drawn[0].at.?.w);
r.p.update(.{ .resize = .{ .cols = 120, .rows = 40, .cell_pixels = .{ .w = 15, .h = 30 } } });
r.drain();
drawn = try r.placesOf(24);
const o = r.origin(0);
try std.testing.expectEqual(@as(usize, 1), drawn.len);
- try std.testing.expectEqual(o.x + 2, drawn[0].x);
- try std.testing.expectEqual(o.y + 1, drawn[0].y);
- try std.testing.expectEqual(@as(u32, 30), drawn[0].native.geometry.?.dst.w);
- try std.testing.expectEqual(@as(u32, 30), drawn[0].native.geometry.?.dst.h);
+ try std.testing.expectEqual(o.x + 2, drawn[0].dst.x);
+ try std.testing.expectEqual(o.y + 1, drawn[0].dst.y);
+ try std.testing.expectEqual(@as(u32, 30), drawn[0].at.?.w);
+ try std.testing.expectEqual(@as(u32, 30), drawn[0].at.?.h);
}
test "kitty: a dumped and restored terminal keeps its images" {
@@ -1292,22 +1300,23 @@ test "kitty: recorded kitten icat and chafa traffic replays: answers whole, imag
continue;
};
const o = r.origin(0);
- var top: ?pardes.ImagePlace = null;
+ var top: ?pardes.Placement = null;
for (drawn) |place| {
- if (top == null or place.y < top.?.y or (place.y == top.?.y and place.x < top.?.x)) top = place;
+ if (top == null or place.dst.y < top.?.dst.y or (place.dst.y == top.?.dst.y and place.dst.x < top.?.dst.x)) top = place;
}
const first = top orelse {
std.debug.print("{s}: nothing drawn\n", .{rec.name});
return error.NothingDrawn;
};
- std.testing.expectEqual([2]u16{ o.x + want[0], o.y + want[1] }, [2]u16{ first.x, first.y }) catch |err| {
- std.debug.print("{s}: drawn at {d},{d}, live at {d},{d}\n", .{ rec.name, first.x - o.x, first.y - o.y, want[0], want[1] });
+ std.testing.expectEqual([2]u16{ o.x + want[0], o.y + want[1] }, [2]u16{ first.dst.x, first.dst.y }) catch |err| {
+ std.debug.print("{s}: drawn at {d},{d}, live at {d},{d}\n", .{ rec.name, first.dst.x - o.x, first.dst.y - o.y, want[0], want[1] });
return err;
};
}
}
-test "kitty: under a shell that draws no pixels, a 64x64 image over 8x4 cells is glyph art in every cell" {
+test "kitty: under a shell that draws no pixels, a 64x64 image over 8x4 cells is still handed on over those cells, its cells left to the shell" {
+ // The glyph art a tty draws there is the tty's test (tui.zig).
var r = try Rig.init(1);
defer r.deinit();
r.p.frontend.native_images = false;
@@ -1337,17 +1346,13 @@ test "kitty: under a shell that draws no pixels, a 64x64 image over 8x4 cells is
}
try cmds.appendSlice(arena, "\r\n");
r.feed(0, cmds.items);
- _ = try r.places();
- const s = &r.p.surface;
+ const drawn = try r.places();
const o = r.origin(0);
- var painted: usize = 0;
- for (0..4) |dy| for (0..8) |dx| {
- const cell = s.at(o.x + 7 + @as(u16, @intCast(dx)), o.y + 1 + @as(u16, @intCast(dy)));
- if (cell.style.bg == .rgb and !cell.default) painted += 1;
- };
- std.testing.expectEqual(@as(usize, 32), painted) catch |err| {
- std.debug.print("helix theme {}: {d} cells painted\n", .{ helix, painted });
- return err;
- };
+ try std.testing.expectEqual(@as(usize, 4), drawn.len);
+ for (drawn, 0..) |place, dy| {
+ try std.testing.expectEqual(pardes.RectCell{ .x = o.x + 7, .y = o.y + 1 + @as(u16, @intCast(dy)), .w = 8, .h = 1 }, place.dst);
+ try std.testing.expect(!place.art.glyph);
+ try std.testing.expectEqualStrings(" ", r.p.surface.at(o.x + 7, place.dst.y).grapheme());
+ }
}
}
diff --git a/test/pdf.zig b/test/pdf.zig
index b66db1df..1b2f2829 100644
--- a/test/pdf.zig
+++ b/test/pdf.zig
@@ -16,7 +16,69 @@ const Key = pardes.Key;
const Event = pardes.Event;
const Mode = panes.Text.Mode;
const Surface = pardes.Surface;
-const ImagePlace = pardes.ImagePlace;
+const Placement = pardes.Placement;
+
+/// A placement as these cases read it: its page and revision (its key
+/// among its pane's pages), where it goes and its pixels.
+const Shown = struct {
+ page: u32,
+ revision: u32,
+ fit: image.NativeFit,
+ geometry: image.NativeGeometry,
+ pixel_offset_y: f32,
+ rgba: []const u8,
+ iw: usize,
+ ih: usize,
+};
+
+/// A frame of `p`, and its placements read so.
+fn renderShown(p: *Pardes, arena: std.mem.Allocator) ![]Shown {
+ _ = try p.render(arena);
+ return shownAll(p, arena);
+}
+
+/// `p`'s frame's placements, read so.
+fn shownAll(p: *Pardes, arena: std.mem.Allocator) ![]Shown {
+ const s = &p.surface;
+ const out = try arena.alloc(Shown, s.placements.items.len);
+ for (s.placements.items, out) |place, *o| {
+ const pane = p.panes[place.pane].?;
+ const pv = pane.pdf.?;
+ var page: u32 = 0;
+ var revision: u32 = 0;
+ found: {
+ for (pv.rasters[0..pv.rasters_len]) |r| if (r.valid and Placement.keyOf(pane.serial, @intCast(r.page), r.revision) == place.key) {
+ page = @intCast(r.page);
+ revision = r.revision;
+ break :found;
+ };
+ for (0..pv.page_count) |pg| if (Placement.keyOf(pane.serial, @intCast(pg), 0) == place.key) {
+ page = @intCast(pg);
+ break :found;
+ };
+ return error.UnknownPlacement;
+ }
+ var scroll: f64 = 0;
+ for (s.regionList()) |r| if (r.kind == .body and r.owner == place.pane) {
+ scroll = r.scroll_px;
+ break;
+ };
+ o.* = .{
+ .page = page,
+ .revision = revision,
+ .fit = switch (pv.fit) {
+ .width => .width,
+ .height => .height,
+ },
+ .geometry = .{ .src = place.src, .dst = place.at orelse return error.MissingPdfGeometry },
+ .pixel_offset_y = -@as(f32, @floatCast(scroll - @floor(scroll))),
+ .rgba = place.raster.bytes(),
+ .iw = place.raster.w,
+ .ih = place.raster.h,
+ };
+ }
+ return out;
+}
const PdfFitMode = panes.Pdf.FitMode;
const PdfTintMode = panes.Pdf.TintMode;
const pdf_enabled = panes.Pdf.enabled;
@@ -159,14 +221,14 @@ const PdfLinkTests = struct {
const pane = p.panes[0].?;
var frame = std.heap.ArenaAllocator.init(p.gpa);
defer frame.deinit();
- const plain = try p.render(frame.allocator());
- const plain_revision = plain.images.items[0].native.revision;
+ _ = try p.render(frame.allocator());
+ const plain_revision = (try shownAll(p, frame.allocator()))[0].revision;
while (p.nextEffect()) |_| {}
const blank = try cellAt(p, 0.3, 0.38);
hover(p, blank);
const hovered = try p.render(frame.allocator());
try std.testing.expectEqual(Surface.PointerShape.link, hovered.pointer_shape);
- try std.testing.expect(hovered.images.items[0].native.revision != plain_revision);
+ try std.testing.expect((try shownAll(p, frame.allocator()))[0].revision != plain_revision);
const highlights = panes.Pdf.highlightInput(p, 0, pane);
try std.testing.expect(!std.meta.eql(highlights.hover_color, highlights.selection_color));
try std.testing.expect(pane.pdf.?.selection == null);
@@ -563,10 +625,10 @@ test "MuPDF pane renders, navigates, searches, and round-trips its page" {
var frame = std.heap.ArenaAllocator.init(gpa);
defer frame.deinit();
const first = try p.render(frame.allocator());
- try std.testing.expectEqual(@as(usize, 1), first.images.items.len);
- const first_place = first.images.items[0];
+ try std.testing.expectEqual(@as(usize, 1), first.placements.items.len);
+ const first_place = (try shownAll(p, frame.allocator()))[0];
try std.testing.expect(first_place.rgba.len == first_place.iw * first_place.ih * 4);
- try std.testing.expectEqual(image.NativeFit.width, first_place.native.fit);
+ try std.testing.expectEqual(image.NativeFit.width, first_place.fit);
const request = panes.Pdf.renderRequest(
panes.Pdf.paneViewport(p, pane) orelse return error.MissingPdfViewport,
pdf_raster_policy,
@@ -597,9 +659,9 @@ test "MuPDF pane renders, navigates, searches, and round-trips its page" {
p.update(.{ .pdf_scroll = .{ .pane = 0, .delta_pixels = 0.25, .glide = false } });
try std.testing.expectEqual(@as(f64, 0.25), pane.pdf.?.document_scroll_y);
_ = frame.reset(.retain_capacity);
- const fractional = try p.render(frame.allocator());
- try std.testing.expectEqual(first_place.native.revision, fractional.images.items[0].native.revision);
- try std.testing.expectEqual(@as(f32, -0.25), fractional.images.items[0].native.pixel_offset_y);
+ _ = try p.render(frame.allocator());
+ try std.testing.expectEqual(first_place.revision, (try shownAll(p, frame.allocator()))[0].revision);
+ try std.testing.expectEqual(@as(f32, -0.25), (try shownAll(p, frame.allocator()))[0].pixel_offset_y);
pane.pdf.?.document_scroll_y = 0;
// The default reading view moves one exact display-cell distance without
@@ -608,13 +670,13 @@ test "MuPDF pane renders, navigates, searches, and round-trips its page" {
try std.testing.expectEqual(@as(usize, 0), pane.pdf.?.page);
try std.testing.expectEqual(@as(f64, p.cell_pixels.h), pane.pdf.?.document_scroll_y);
try std.testing.expectEqual(
- first_place.native.revision,
+ first_place.revision,
panes.Pdf.rasterForPage(pane.pdf.?, pane.pdf.?.page).?.revision,
);
_ = frame.reset(.retain_capacity);
- const panned = try p.render(frame.allocator());
- try std.testing.expectEqual(first_place.native.revision, panned.images.items[0].native.revision);
- try std.testing.expect(panned.images.items[0].native.geometry.?.src.y > first_place.native.geometry.?.src.y);
+ _ = try p.render(frame.allocator());
+ try std.testing.expectEqual(first_place.revision, (try shownAll(p, frame.allocator()))[0].revision);
+ try std.testing.expect((try shownAll(p, frame.allocator()))[0].geometry.src.y > first_place.geometry.src.y);
const row_scroll = pane.pdf.?.document_scroll_y;
pane.pdf.?.document_scroll_y = 0;
@@ -668,7 +730,7 @@ test "MuPDF pane renders, navigates, searches, and round-trips its page" {
p.update(.{ .key = .{ .cp = 'b', .ctrl = true } });
try std.testing.expectEqual(@max(@as(f64, 0), counted_full - @as(f64, @floatFromInt(key_viewport.pixel_h * 2))), pane.pdf.?.document_scroll_y);
try std.testing.expectEqual(
- first_place.native.revision,
+ first_place.revision,
panes.Pdf.rasterForPage(pane.pdf.?, pane.pdf.?.page).?.revision,
);
@@ -687,22 +749,22 @@ test "MuPDF pane renders, navigates, searches, and round-trips its page" {
);
_ = frame.reset(.retain_capacity);
const boundary = try p.render(frame.allocator());
- try std.testing.expectEqual(@as(usize, 2), boundary.images.items.len);
- try std.testing.expectEqual(@as(u32, 0), boundary.images.items[0].native.page);
- try std.testing.expectEqual(@as(u32, 1), boundary.images.items[1].native.page);
+ try std.testing.expectEqual(@as(usize, 2), boundary.placements.items.len);
+ try std.testing.expectEqual(@as(u32, 0), (try shownAll(p, frame.allocator()))[0].page);
+ try std.testing.expectEqual(@as(u32, 1), (try shownAll(p, frame.allocator()))[1].page);
const first_bottom = @as(f32, @floatFromInt(
- boundary.images.items[0].native.geometry.?.dst.y +
- boundary.images.items[0].native.geometry.?.dst.h,
- )) + boundary.images.items[0].native.pixel_offset_y;
+ (try shownAll(p, frame.allocator()))[0].geometry.dst.y +
+ (try shownAll(p, frame.allocator()))[0].geometry.dst.h,
+ )) + (try shownAll(p, frame.allocator()))[0].pixel_offset_y;
const second_top = @as(f32, @floatFromInt(
- boundary.images.items[1].native.geometry.?.dst.y,
- )) + boundary.images.items[1].native.pixel_offset_y;
+ (try shownAll(p, frame.allocator()))[1].geometry.dst.y,
+ )) + (try shownAll(p, frame.allocator()))[1].pixel_offset_y;
const visible_gap = second_top - first_bottom;
try std.testing.expect(visible_gap >= @as(f32, PDF_PAGE_GAP_PX));
try std.testing.expect(visible_gap <= @as(f32, PDF_PAGE_GAP_PX + 1));
const before_boundary_scroll = pane.pdf.?.document_scroll_y;
- const page0_revision = boundary.images.items[0].native.revision;
- const page1_revision = boundary.images.items[1].native.revision;
+ const page0_revision = (try shownAll(p, frame.allocator()))[0].revision;
+ const page1_revision = (try shownAll(p, frame.allocator()))[1].revision;
// A scroll can activate the already-cached neighbor before the shell's
// next draw. Every consumer resolves the active page's resident raster,
@@ -725,9 +787,9 @@ test "MuPDF pane renders, navigates, searches, and round-trips its page" {
try std.testing.expectEqual(before_boundary_scroll + p.cell_pixels.h, pane.pdf.?.document_scroll_y);
_ = frame.reset(.retain_capacity);
const second = try p.render(frame.allocator());
- try std.testing.expectEqual(@as(usize, 2), second.images.items.len);
- try std.testing.expectEqual(page0_revision, second.images.items[0].native.revision);
- try std.testing.expectEqual(page1_revision, second.images.items[1].native.revision);
+ try std.testing.expectEqual(@as(usize, 2), second.placements.items.len);
+ try std.testing.expectEqual(page0_revision, (try shownAll(p, frame.allocator()))[0].revision);
+ try std.testing.expectEqual(page1_revision, (try shownAll(p, frame.allocator()))[1].revision);
p.update(.{ .key = .{ .cp = 'k' } });
try std.testing.expectEqual(before_boundary_scroll, pane.pdf.?.document_scroll_y);
@@ -740,18 +802,18 @@ test "MuPDF pane renders, navigates, searches, and round-trips its page" {
panes.Pdf.activatePage(p, pane, 1, true);
_ = frame.reset(.retain_capacity);
const away = try p.render(frame.allocator());
- try std.testing.expect(away.images.items.len > 0);
- for (away.images.items) |place|
- try std.testing.expect(place.native.page != 0);
+ try std.testing.expect(away.placements.items.len > 0);
+ for (try shownAll(p, frame.allocator())) |place|
+ try std.testing.expect(place.page != 0);
try std.testing.expect(panes.Pdf.rasterForPage(pane.pdf.?, 0) == null);
try std.testing.expectEqual(@as(usize, 1), pane.pdf.?.spare_len);
const retired = pane.pdf.?.spare[0];
panes.Pdf.activatePage(p, pane, 0, true);
_ = frame.reset(.retain_capacity);
- const returned = try p.render(frame.allocator());
- try std.testing.expectEqual(@as(u32, 0), returned.images.items[0].native.page);
- try std.testing.expectEqual(retired.ptr, returned.images.items[0].rgba.ptr);
- try std.testing.expect(returned.images.items[0].native.revision != page0_revision);
+ _ = try p.render(frame.allocator());
+ try std.testing.expectEqual(@as(u32, 0), (try shownAll(p, frame.allocator()))[0].page);
+ try std.testing.expectEqual(retired.ptr, (try shownAll(p, frame.allocator()))[0].rgba.ptr);
+ try std.testing.expect((try shownAll(p, frame.allocator()))[0].revision != page0_revision);
// PdfFit exists as a real builtin in this build. It resets placement but
// preserves the current page pixels; fit-height j/k remains continuous in
@@ -917,16 +979,16 @@ test "a fling's banded pages show the reader exactly what whole pages would" {
try std.testing.expect(panes.Pdf.scrollPane(p, pane, landing, false));
_ = frame.reset(.retain_capacity);
const flung = try p.render(frame.allocator());
- try std.testing.expect(flung.images.items.len >= 2);
+ try std.testing.expect(flung.placements.items.len >= 2);
var banded = false;
- for (flung.images.items) |place| {
- const geometry = place.native.geometry orelse return error.MissingPdfGeometry;
- const raster = panes.Pdf.rasterForPage(pv, place.native.page) orelse
+ for (try shownAll(p, frame.allocator())) |place| {
+ const geometry = place.geometry;
+ const raster = panes.Pdf.rasterForPage(pv, place.page) orelse
return error.MissingPdfRaster;
if (raster.band_h < raster.ih) banded = true;
try std.testing.expectEqual(place.iw * raster.band_h * 4, place.rgba.len);
shots[shots_len] = .{
- .page = place.native.page,
+ .page = place.page,
.dst = geometry.dst,
.pixels = try copySourceRect(gpa, place, geometry.src),
};
@@ -940,13 +1002,13 @@ test "a fling's banded pages show the reader exactly what whole pages would" {
// has to have matched.
_ = frame.reset(.retain_capacity);
const rested = try p.render(frame.allocator());
- try std.testing.expectEqual(shots_len, rested.images.items.len);
- for (rested.images.items, shots[0..shots_len]) |place, shot| {
- const geometry = place.native.geometry orelse return error.MissingPdfGeometry;
- const raster = panes.Pdf.rasterForPage(pv, place.native.page) orelse
+ try std.testing.expectEqual(shots_len, rested.placements.items.len);
+ for (try shownAll(p, frame.allocator()), shots[0..shots_len]) |place, shot| {
+ const geometry = place.geometry;
+ const raster = panes.Pdf.rasterForPage(pv, place.page) orelse
return error.MissingPdfRaster;
try std.testing.expectEqual(raster.ih, raster.band_h); // promoted at rest
- try std.testing.expectEqual(shot.page, place.native.page);
+ try std.testing.expectEqual(shot.page, place.page);
try std.testing.expectEqual(shot.dst.x, geometry.dst.x);
try std.testing.expectEqual(shot.dst.y, geometry.dst.y);
try std.testing.expectEqual(shot.dst.w, geometry.dst.w);
@@ -1035,9 +1097,9 @@ test "a tall page is drawn at the display's resolution, in bands that are the wh
pv.scroll_travel = 0; // read, not flung
_ = frame.reset(.retain_capacity);
const surface = try p.render(frame.allocator());
- try std.testing.expectEqual(@as(usize, 1), surface.images.items.len);
- const place = surface.images.items[0];
- const geometry = place.native.geometry orelse return error.MissingPdfGeometry;
+ try std.testing.expectEqual(@as(usize, 1), surface.placements.items.len);
+ const place = (try shownAll(p, frame.allocator()))[0];
+ const geometry = place.geometry;
const raster = panes.Pdf.rasterForPage(pv, 0) orelse return error.MissingPdfRaster;
// Bounded: a band, never the page, and within one buffer's budget.
try std.testing.expectEqual(shape.width, place.iw);
@@ -1064,7 +1126,7 @@ test "a tall page is drawn at the display's resolution, in bands that are the wh
_ = panes.Pdf.scrollPane(p, pane, @round(max_scroll / 2) - pv.document_scroll_y, false);
pv.scroll_travel = 0;
_ = frame.reset(.retain_capacity);
- const again = (try p.render(frame.allocator())).images.items[0];
+ const again = (try renderShown(p, frame.allocator()))[0];
const again_y = panes.Pdf.rasterForPage(pv, 0).?.band_y;
const stride = shape.stride;
const common_top = @max(middle_y, again_y);
@@ -1078,7 +1140,7 @@ test "a tall page is drawn at the display's resolution, in bands that are the wh
_ = panes.Pdf.scrollPane(p, pane, max_scroll - pv.document_scroll_y, false);
pv.scroll_travel = 0;
_ = frame.reset(.retain_capacity);
- const foot = try gpa.dupe(u8, (try p.render(frame.allocator())).images.items[0].rgba);
+ const foot = try gpa.dupe(u8, (try renderShown(p, frame.allocator()))[0].rgba);
defer gpa.free(foot);
// At the foot of the page, a search hit: its highlight lands on exactly
@@ -1086,8 +1148,8 @@ test "a tall page is drawn at the display's resolution, in bands that are the wh
// word finds the word.
try pv.setSearchQuery(gpa, "bottommost");
_ = frame.reset(.retain_capacity);
- const lit = try p.render(frame.allocator());
- const place = lit.images.items[0];
+ _ = try p.render(frame.allocator());
+ const place = (try shownAll(p, frame.allocator()))[0];
const raster = panes.Pdf.rasterForPage(pv, 0) orelse return error.MissingPdfRaster;
const highlights = try panes.Pdf.buildHighlights(pv, frame.allocator(), panes.Pdf.highlightInput(p, 0, pane));
const marks = highlights.forPage(0);
@@ -1127,7 +1189,7 @@ test "a tall page is drawn at the display's resolution, in bands that are the wh
/// that makes "same picture" mean something when the textures differ in shape.
fn copySourceRect(
gpa: std.mem.Allocator,
- place: ImagePlace,
+ place: Shown,
src: image.PixelRect,
) ![]u8 {
const stride = place.iw * 4;
@@ -1270,11 +1332,11 @@ test "PDF continuous strip renders every intersecting short page" {
var frame = std.heap.ArenaAllocator.init(gpa);
defer frame.deinit();
const surface = try p.render(frame.allocator());
- try std.testing.expectEqual(pv.page_count, surface.images.items.len);
+ try std.testing.expectEqual(pv.page_count, surface.placements.items.len);
try std.testing.expectEqual(pv.page_count, pv.rasters_len);
- for (surface.images.items, 0..) |place, page| {
- try std.testing.expectEqual(@as(u32, @intCast(page)), place.native.page);
- try std.testing.expectEqual(@as(u32, 1), place.native.geometry.?.dst.h);
+ for (try shownAll(p, frame.allocator()), 0..) |place, page| {
+ try std.testing.expectEqual(@as(u32, @intCast(page)), place.page);
+ try std.testing.expectEqual(@as(u32, 1), place.geometry.dst.h);
}
}
@@ -1320,7 +1382,7 @@ test "PDF tint and tinted theme changes rebuild every visible raster only" {
_ = frame.reset(.retain_capacity);
const default_surface = try p.render(frame.allocator());
try std.testing.expectEqual(PdfTintMode.filtered, pv.tint);
- try std.testing.expectEqual(@as(usize, 2), default_surface.images.items.len);
+ try std.testing.expectEqual(@as(usize, 2), default_surface.placements.items.len);
try std.testing.expectEqual(@as(usize, 2), pv.rasters_len);
const Snapshot = struct {
@@ -1333,16 +1395,17 @@ test "PDF tint and tinted theme changes rebuild every visible raster only" {
checksum: u64,
};
const Capture = struct {
- fn get(surface: *const Surface) ![2]Snapshot {
- if (surface.images.items.len != 2) return error.UnexpectedVisiblePdfCount;
+ fn get(core: *Pardes, arena: std.mem.Allocator) ![2]Snapshot {
+ if (core.surface.placements.items.len != 2) return error.UnexpectedVisiblePdfCount;
var out: [2]Snapshot = undefined;
+ const shown = try shownAll(core, arena);
for (&out, 0..) |*snapshot, i| {
- const place = surface.images.items[i];
+ const place = shown[i];
snapshot.* = .{
- .page = place.native.page,
- .revision = place.native.revision,
- .geometry = place.native.geometry orelse return error.MissingPdfGeometry,
- .pixel_offset_y = place.native.pixel_offset_y,
+ .page = place.page,
+ .revision = place.revision,
+ .geometry = place.geometry,
+ .pixel_offset_y = place.pixel_offset_y,
.iw = place.iw,
.ih = place.ih,
.checksum = std.hash.Wyhash.hash(0x5044_4654_494e_5421, place.rgba),
@@ -1361,7 +1424,7 @@ test "PDF tint and tinted theme changes rebuild every visible raster only" {
}
}
};
- const default_filtered = try Capture.get(default_surface);
+ const default_filtered = try Capture.get(p, frame.allocator());
for (pv.rasters[0..pv.rasters_len]) |raster|
try std.testing.expectEqual(PdfTintMode.filtered, raster.tint_key.?.mode);
@@ -1371,8 +1434,8 @@ test "PDF tint and tinted theme changes rebuild every visible raster only" {
pardes.colors.setThemeIndex(p, dark_index);
for (pv.rasters[0..pv.rasters_len]) |raster| try std.testing.expect(!raster.tried);
_ = frame.reset(.retain_capacity);
- const themed_surface = try p.render(frame.allocator());
- const themed = try Capture.get(themed_surface);
+ _ = try p.render(frame.allocator());
+ const themed = try Capture.get(p, frame.allocator());
try Capture.expectGeometry(default_filtered, themed);
for (default_filtered, themed) |old, new| {
try std.testing.expect(new.revision > old.revision);
@@ -1382,8 +1445,8 @@ test "PDF tint and tinted theme changes rebuild every visible raster only" {
panes.Pdf.toggleTint(pane);
try std.testing.expectEqual(PdfTintMode.full, pv.tint);
_ = frame.reset(.retain_capacity);
- const full_surface = try p.render(frame.allocator());
- const full = try Capture.get(full_surface);
+ _ = try p.render(frame.allocator());
+ const full = try Capture.get(p, frame.allocator());
try Capture.expectGeometry(themed, full);
for (themed, full) |old, new| {
try std.testing.expect(new.revision > old.revision);
@@ -1394,8 +1457,8 @@ test "PDF tint and tinted theme changes rebuild every visible raster only" {
panes.Pdf.toggleTint(pane);
try std.testing.expectEqual(PdfTintMode.disabled, pv.tint);
_ = frame.reset(.retain_capacity);
- const disabled_surface = try p.render(frame.allocator());
- const disabled = try Capture.get(disabled_surface);
+ _ = try p.render(frame.allocator());
+ const disabled = try Capture.get(p, frame.allocator());
try Capture.expectGeometry(full, disabled);
for (full, disabled) |old, source| {
try std.testing.expect(source.revision > old.revision);
@@ -1411,8 +1474,8 @@ test "PDF tint and tinted theme changes rebuild every visible raster only" {
// the per-raster key comparison asks MuPDF for replacement pixels.
for (pv.rasters[0..pv.rasters_len]) |raster| try std.testing.expect(raster.tried);
_ = frame.reset(.retain_capacity);
- const unchanged_surface = try p.render(frame.allocator());
- const unchanged = try Capture.get(unchanged_surface);
+ _ = try p.render(frame.allocator());
+ const unchanged = try Capture.get(p, frame.allocator());
try Capture.expectGeometry(disabled, unchanged);
for (disabled, unchanged) |old, new| {
try std.testing.expectEqual(old.revision, new.revision);
@@ -1581,8 +1644,8 @@ test "PDF n/N addresses and reveals distinct MuPDF hits on one page" {
try std.testing.expect(pardes.look.searchStep(p, 0, 1));
try std.testing.expectEqual(@as(usize, 0), pv.search_hit);
try std.testing.expectEqual(@as(usize, 0), pane.search_row.?);
- const first = try p.render(frame.allocator());
- const revision = first.images.items[0].native.revision;
+ _ = try p.render(frame.allocator());
+ const revision = (try shownAll(p, frame.allocator()))[0].revision;
const raster = panes.Pdf.rasterForPage(pv, pv.page).?;
const first_scroll = pv.document_scroll_y;
const first_results = pv.search_results orelse return error.MissingPdfPageSearch;
@@ -1601,15 +1664,15 @@ test "PDF n/N addresses and reveals distinct MuPDF hits on one page" {
try std.testing.expectEqual(@as(usize, 1), pv.search_hit);
try std.testing.expectEqual(@as(usize, 2), pane.search_row.?);
_ = frame.reset(.retain_capacity);
- const second = try p.render(frame.allocator());
- try std.testing.expectEqual(revision, second.images.items[0].native.revision);
+ _ = try p.render(frame.allocator());
+ try std.testing.expectEqual(revision, (try shownAll(p, frame.allocator()))[0].revision);
try std.testing.expect(pardes.look.searchStep(p, 0, 1));
try std.testing.expectEqual(@as(usize, 2), pv.search_hit);
try std.testing.expectEqual(@as(usize, 4), pane.search_row.?);
_ = frame.reset(.retain_capacity);
- const third = try p.render(frame.allocator());
- try std.testing.expectEqual(revision, third.images.items[0].native.revision);
+ _ = try p.render(frame.allocator());
+ try std.testing.expectEqual(revision, (try shownAll(p, frame.allocator()))[0].revision);
try std.testing.expect(pv.document_scroll_y != first_scroll);
const third_results = pv.search_results orelse return error.MissingPdfPageSearch;
const third_quad = for (third_results.quads) |item| {
@@ -1641,7 +1704,7 @@ test "PDF native mouse selection, Look, and highlights share page geometry" {
// A host without Kitty/native pixels keeps the projected-text contract:
// j/k can still change pages and a body drag remains a generic selection.
const fallback = try p.render(frame.allocator());
- try std.testing.expectEqual(@as(usize, 0), fallback.images.items.len);
+ try std.testing.expectEqual(@as(usize, 0), fallback.placements.items.len);
p.update(.{ .key = .{ .cp = 'j' } });
try std.testing.expectEqual(@as(usize, 1), pane.pdf.?.page);
p.update(.{ .key = .{ .cp = 'k' } });
@@ -1658,8 +1721,8 @@ test "PDF native mouse selection, Look, and highlights share page geometry" {
p.frontend.native_images = true;
_ = frame.reset(.retain_capacity);
- const plain = try p.render(frame.allocator());
- const plain_revision = plain.images.items[0].native.revision;
+ _ = try p.render(frame.allocator());
+ const plain_revision = (try shownAll(p, frame.allocator()))[0].revision;
var found = try pane.pdf.?.document.search(gpa, 0, "Pardes");
defer found.deinit(gpa);
@@ -1726,8 +1789,8 @@ test "PDF native mouse selection, Look, and highlights share page geometry" {
) != null);
_ = frame.reset(.retain_capacity);
- const selected_frame = try p.render(frame.allocator());
- const selected_revision = selected_frame.images.items[0].native.revision;
+ _ = try p.render(frame.allocator());
+ const selected_revision = (try shownAll(p, frame.allocator()))[0].revision;
try std.testing.expect(selected_revision != plain_revision);
// Repeating an identical drag endpoint is a no-op: Kitty/SDL keep the
@@ -1735,8 +1798,8 @@ test "PDF native mouse selection, Look, and highlights share page geometry" {
try std.testing.expect(panes.Pdf.beginDrag(p, pane, word_col, selected_row, true));
try std.testing.expect(raster.tried);
_ = frame.reset(.retain_capacity);
- const duplicate = try p.render(frame.allocator());
- try std.testing.expectEqual(selected_revision, duplicate.images.items[0].native.revision);
+ _ = try p.render(frame.allocator());
+ try std.testing.expectEqual(selected_revision, (try shownAll(p, frame.allocator()))[0].revision);
// Delayed native hover retains independent quads/text and changes only
// presentation state. In particular it must not borrow the click path,
@@ -1789,15 +1852,15 @@ test "PDF native mouse selection, Look, and highlights share page geometry" {
try std.testing.expectEqual(pdf_impl.HighlightKind.custom, page_highlights[0].kind);
try std.testing.expectEqual(pdf_impl.HighlightKind.selection, page_highlights[page_highlights.len - 1].kind);
_ = frame.reset(.retain_capacity);
- const hovered_frame = try p.render(frame.allocator());
- const hovered_revision = hovered_frame.images.items[0].native.revision;
+ _ = try p.render(frame.allocator());
+ const hovered_revision = (try shownAll(p, frame.allocator()))[0].revision;
try std.testing.expect(hovered_revision != selected_revision);
p.update(.pointer_leave);
try std.testing.expect(p.pdf_hover_preview == null);
_ = frame.reset(.retain_capacity);
- const unhovered_frame = try p.render(frame.allocator());
- try std.testing.expect(unhovered_frame.images.items[0].native.revision != hovered_revision);
+ _ = try p.render(frame.allocator());
+ try std.testing.expect((try shownAll(p, frame.allocator()))[0].revision != hovered_revision);
try std.testing.expectEqual(active_before, p.active);
try std.testing.expectEqual(page_before, pv.page);
@@ -1850,14 +1913,14 @@ test "PDF native mouse selection, Look, and highlights share page geometry" {
try std.testing.expectEqual(max_document_scroll, pv.document_scroll_y);
pv.document_scroll_y = revealed_scroll;
_ = frame.reset(.retain_capacity);
- const searched = try p.render(frame.allocator());
- try std.testing.expect(searched.images.items[0].native.revision != selected_revision);
+ _ = try p.render(frame.allocator());
+ try std.testing.expect((try shownAll(p, frame.allocator()))[0].revision != selected_revision);
// Fit and viewport changes can crop a hit which was already revealed.
// Fit remains placement-only. SDL's physical-viewport quality request
// changes with a resize and therefore replaces pixels; Kitty's fixed,
// bandwidth-conscious request retains them.
- const revision_before_geometry_change = searched.images.items[0].native.revision;
+ const revision_before_geometry_change = (try shownAll(p, frame.allocator()))[0].revision;
pv.search_reveal_pending = false;
panes.Pdf.toggleFit(pane);
try std.testing.expect(pv.search_reveal_pending);
@@ -1882,14 +1945,14 @@ test "PDF native mouse selection, Look, and highlights share page geometry" {
} });
try std.testing.expect(pv.search_reveal_pending);
_ = frame.reset(.retain_capacity);
- const geometry_changed = try p.render(frame.allocator());
+ _ = try p.render(frame.allocator());
if (pdf_raster_policy.match_viewport)
- try std.testing.expect(geometry_changed.images.items[0].native.revision !=
+ try std.testing.expect((try shownAll(p, frame.allocator()))[0].revision !=
revision_before_geometry_change)
else
try std.testing.expectEqual(
revision_before_geometry_change,
- geometry_changed.images.items[0].native.revision,
+ (try shownAll(p, frame.allocator()))[0].revision,
);
p.update(.{ .resize = .{
.cols = p.screen_w,
@@ -1914,8 +1977,8 @@ test "PDF native mouse selection, Look, and highlights share page geometry" {
// Native drag events update MuPDF quads and copied text immediately, but
// keep the already transmitted page generation stable until release.
_ = frame.reset(.retain_capacity);
- const before_drag = try p.render(frame.allocator());
- const before_drag_revision = before_drag.images.items[0].native.revision;
+ _ = try p.render(frame.allocator());
+ const before_drag_revision = (try shownAll(p, frame.allocator()))[0].revision;
const drag_col = @min(r.x + r.w - 1, word_col +| 12);
const drag_row = @min(r.y + r.h - 1, selected_row +| 4);
p.update(.{ .mouse = .{
@@ -1931,10 +1994,10 @@ test "PDF native mouse selection, Look, and highlights share page geometry" {
.row = @min(drag_row, selected_row +| 2),
} });
_ = frame.reset(.retain_capacity);
- const during_first_drag = try p.render(frame.allocator());
+ _ = try p.render(frame.allocator());
try std.testing.expectEqual(
before_drag_revision,
- during_first_drag.images.items[0].native.revision,
+ (try shownAll(p, frame.allocator()))[0].revision,
);
p.update(.{ .mouse = .{
.button = config.select_button,
@@ -1944,10 +2007,10 @@ test "PDF native mouse selection, Look, and highlights share page geometry" {
} });
try std.testing.expect(p.drag.select.pdf.selection_changed);
_ = frame.reset(.retain_capacity);
- const during_second_drag = try p.render(frame.allocator());
+ _ = try p.render(frame.allocator());
try std.testing.expectEqual(
before_drag_revision,
- during_second_drag.images.items[0].native.revision,
+ (try shownAll(p, frame.allocator()))[0].revision,
);
p.update(.{ .mouse = .{
.button = config.select_button,
@@ -1957,16 +2020,16 @@ test "PDF native mouse selection, Look, and highlights share page geometry" {
} });
try std.testing.expect(!raster.tried);
_ = frame.reset(.retain_capacity);
- const committed_drag = try p.render(frame.allocator());
+ _ = try p.render(frame.allocator());
try std.testing.expectEqual(
before_drag_revision + 1,
- committed_drag.images.items[0].native.revision,
+ (try shownAll(p, frame.allocator()))[0].revision,
);
_ = frame.reset(.retain_capacity);
- const stable_drag = try p.render(frame.allocator());
+ _ = try p.render(frame.allocator());
try std.testing.expectEqual(
- committed_drag.images.items[0].native.revision,
- stable_drag.images.items[0].native.revision,
+ (try shownAll(p, frame.allocator()))[0].revision,
+ (try shownAll(p, frame.allocator()))[0].revision,
);
const saved_query = try gpa.dupe(u8, pv.search_query);
diff --git a/test/pdf_pointer_bench.zig b/test/pdf_pointer_bench.zig
index d6cf0e19..359d2fc1 100644
--- a/test/pdf_pointer_bench.zig
+++ b/test/pdf_pointer_bench.zig
@@ -111,10 +111,12 @@ const Run = struct {
}
fn observe(run: *Run, surface: *const pardes.Surface) void {
- for (surface.images.items) |place| {
- run.visual = mix(run.visual, [_]u64{ place.pane, place.x, place.y, place.w, place.h, place.native.page, place.iw, place.ih });
- if (place.native.geometry) |g| run.visual = mix(run.visual, [_]u64{ g.src.x, g.src.y, g.src.w, g.src.h, g.dst.x, g.dst.y, g.dst.w, g.dst.h });
- run.visual = std.hash.Wyhash.hash(run.visual, place.rgba);
+ for (surface.placements.items) |place| {
+ run.visual = mix(run.visual, [_]u64{ place.pane, place.dst.x, place.dst.y, place.dst.w, place.dst.h, place.raster.w, place.raster.h });
+ const g = place.src;
+ run.visual = mix(run.visual, [_]u64{ g.x, g.y, g.w, g.h });
+ if (place.at) |at| run.visual = mix(run.visual, [_]u64{ at.x, at.y, at.w, at.h });
+ run.visual = std.hash.Wyhash.hash(run.visual, place.raster.bytes());
}
}
};
diff --git a/test/pdf_scroll_bench.zig b/test/pdf_scroll_bench.zig
index 9ef11a1c..837e3acb 100644
--- a/test/pdf_scroll_bench.zig
+++ b/test/pdf_scroll_bench.zig
@@ -381,7 +381,7 @@ fn measure(config: Config, plan: Plan) !Result {
drainEffects(core);
const elapsed = nowNs() -| started;
total += elapsed;
- recorder.observe(frame, surface);
+ recorder.observe(frame, surface, pane);
peak_raster_bytes = @max(peak_raster_bytes, rasterBytes(pv));
// The same frame boundary src/tui/tui.zig marks, so a Tracy capture
// of this benchmark reads like a capture of the real shell.
@@ -458,43 +458,42 @@ const Recorder = struct {
/// and they live in the other checksum on purpose: fast scrolling is
/// ALLOWED to change how pixels are carried and is never allowed to change
/// which pixels arrive.
- fn observe(self: *Recorder, frame: usize, surface: *const pardes.Surface) void {
+ fn observe(self: *Recorder, frame: usize, surface: *const pardes.Surface, pane: *const pardes.Pane) void {
self.frames += 1;
- self.visual = mix(self.visual, surface.images.items.len);
- self.transport = mix(self.transport, surface.images.items.len);
+ self.visual = mix(self.visual, surface.placements.items.len);
+ self.transport = mix(self.transport, surface.placements.items.len);
const full = frame % full_rgba_stride == 0;
- for (surface.images.items) |place| {
+ for (surface.placements.items) |place| {
self.images += 1;
self.visual = mix(self.visual, place.pane);
- self.visual = mix(self.visual, place.x);
- self.visual = mix(self.visual, place.y);
- self.visual = mix(self.visual, place.w);
- self.visual = mix(self.visual, place.h);
- self.visual = mix(self.visual, place.native.page);
- self.visual = mix(self.visual, @backingInt(place.native.fit));
- self.visual = mix(self.visual, place.native.pan_x);
- self.visual = mix(self.visual, place.native.pan_y);
- self.visual = mix(self.visual, @as(u32, @bitCast(place.native.pixel_offset_y)));
- if (place.native.geometry) |geometry| {
- inline for (.{geometry.dst}) |rect| {
- self.visual = mix(self.visual, rect.x);
- self.visual = mix(self.visual, rect.y);
- self.visual = mix(self.visual, rect.w);
- self.visual = mix(self.visual, rect.h);
- }
- self.visual = self.hashSource(self.visual, place, geometry.src, full);
+ self.visual = mix(self.visual, place.dst.x);
+ self.visual = mix(self.visual, place.dst.y);
+ self.visual = mix(self.visual, place.dst.w);
+ self.visual = mix(self.visual, place.dst.h);
+ for (surface.regionList()) |r| if (r.kind == .body and r.owner == place.pane) {
+ self.visual = mix(self.visual, @as(u64, @bitCast(r.scroll_px - @floor(r.scroll_px))));
+ };
+ if (place.at) |rect| {
+ self.visual = mix(self.visual, rect.x);
+ self.visual = mix(self.visual, rect.y);
+ self.visual = mix(self.visual, rect.w);
+ self.visual = mix(self.visual, rect.h);
+ self.visual = self.hashSource(self.visual, place, place.src, full);
} else {
self.visual = mix(self.visual, std.math.maxInt(u64));
self.visual = if (full)
- std.hash.Wyhash.hash(self.visual, place.rgba)
+ std.hash.Wyhash.hash(self.visual, place.raster.bytes())
else
- stridedHash(self.visual, place.rgba);
+ stridedHash(self.visual, place.raster.bytes());
}
- self.transport = mix(self.transport, place.native.page);
- self.transport = mix(self.transport, place.iw);
- self.transport = mix(self.transport, place.ih);
- self.transport = mix(self.transport, place.rgba.len);
- self.transport = mix(self.transport, place.native.revision -% self.base_revision);
+ // The revision the key is of, from the slot holding it (0: a
+ // page's paper before it lands).
+ const revision = for (pane.pdf.?.rasters[0..pane.pdf.?.rasters_len]) |r| {
+ if (r.valid and pardes.Placement.keyOf(pane.serial, @intCast(r.page), r.revision) == place.key) break r.revision;
+ } else 0;
+ self.transport = mix(self.transport, revision -% self.base_revision);
+ self.transport = mix(self.transport, place.raster.w);
+ self.transport = mix(self.transport, place.raster.h);
}
}
@@ -504,21 +503,22 @@ const Recorder = struct {
fn hashSource(
self: *Recorder,
seed: u64,
- place: pardes.ImagePlace,
+ place: pardes.Placement,
src: anytype,
full: bool,
) u64 {
_ = self;
- const stride = place.iw * 4;
- if (stride == 0 or place.rgba.len < stride) return mix(seed, std.math.maxInt(u64));
- const rows = @min(src.h, @as(u32, @intCast(place.rgba.len / stride)) -| src.y);
+ const rgba = place.raster.bytes();
+ const stride: usize = place.raster.stride;
+ if (stride == 0 or rgba.len < stride) return mix(seed, std.math.maxInt(u64));
+ const rows = @min(src.h, @as(u32, @intCast(rgba.len / stride)) -| src.y);
var hash = mix(seed, rows);
var row: u32 = 0;
while (row < rows) : (row += if (full) 1 else 7) {
const start = (@as(usize, src.y) + row) * stride + @as(usize, src.x) * 4;
- const len = @min(@as(usize, src.w) * 4, place.rgba.len -| start);
+ const len = @min(@as(usize, src.w) * 4, rgba.len -| start);
if (len == 0) break;
- hash = std.hash.Wyhash.hash(hash, place.rgba[start..][0..len]);
+ hash = std.hash.Wyhash.hash(hash, rgba[start..][0..len]);
}
return hash;
}