summaryrefslogtreecommitdiff
path: root/src/term/TerminalImages.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/term/TerminalImages.zig')
-rw-r--r--src/term/TerminalImages.zig39
1 files changed, 19 insertions, 20 deletions
diff --git a/src/term/TerminalImages.zig b/src/term/TerminalImages.zig
index ab7aca25..3847be4c 100644
--- a/src/term/TerminalImages.zig
+++ b/src/term/TerminalImages.zig
@@ -161,37 +161,35 @@ fn decodePng(gpa: std.mem.Allocator, bytes: []const u8) ghostty_vt.sys.DecodeErr
/// columns the body shows, from `tx`.
pub fn draw(
ti: *TerminalImages,
- p: *pardes.Pardes,
- s: *pardes.Surface,
+ gpa: std.mem.Allocator,
vt: *ghostty_vt.Terminal,
- pane_id: u8,
- serial: u32,
- tx: u16,
- body_y: u16,
- cols: u16,
+ where: plain.term.ImagesAt,
rows_of: []const ?u16,
+ out: *std.ArrayList(plain.Placement),
+ frame: []plain.Cell,
+ frame_cols: u16,
) void {
var conv = ti.converted.valueIterator();
while (conv.next()) |c| c.used = false;
- defer ti.prune(p.gpa);
+ defer ti.prune(gpa);
const screen = vt.screens.active;
const storage = &screen.kitty_images;
// Animations step on the core's clock, as this frame shows them; the
// shown frame is `renderData()` (a new `generation` each step, which
// the caches key on).
- const now_ms = p.clock.stepped_ns / std.time.ns_per_ms;
+ const now_ms = where.now_ms;
ti.animation_due_ms = if (storage.animationTick(vt.io(), now_ms)) |delay| now_ms +| delay else null;
const pages = &screen.pages;
const top = pages.getTopLeft(.viewport);
const bottom = pages.getBottomRight(.viewport) orelse return;
- const cw: u32 = @max(1, p.view().cell_pixels.w);
- const ch: u32 = @max(1, p.view().cell_pixels.h);
- const ctx: Ctx = .{ .ti = ti, .p = p, .pane = pane_id, .serial = serial, .tx = tx, .body_y = body_y, .cols = cols, .rows_of = rows_of, .cw = cw, .ch = ch };
+ const cw: u32 = @max(1, where.cell_w);
+ const ch: u32 = @max(1, where.cell_h);
+ const ctx: Ctx = .{ .ti = ti, .gpa = gpa, .out = out, .pane = where.pane, .serial = where.serial, .tx = where.tx, .body_y = where.body_y, .cols = where.cols, .rows_of = rows_of, .cw = cw, .ch = ch };
// Handed on lowest z first (the storage's order is a hash map's), the
// order a shell draws them in; equal z keeps the order they came in.
- const first = s.placements.items.len;
- defer std.sort.insertion(plain.Placement, s.placements.items[first..], {}, struct {
+ const first = out.items.len;
+ defer std.sort.insertion(plain.Placement, out.items[first..], {}, struct {
fn lessThan(_: void, a: plain.Placement, b: plain.Placement) bool {
return a.z < b.z;
}
@@ -206,8 +204,8 @@ pub fn draw(
if (v >= rows_of.len) continue;
const row = rows_of[v] orelse continue;
for (@as(usize, at.viewport.x)..@as(usize, at.viewport.x) + run.width) |x| {
- if (x >= cols) break;
- const cell = s.at(tx + @as(u16, @intCast(x)), body_y + row);
+ if (x >= where.cols) break;
+ const cell = &frame[@as(usize, where.body_y + row) * frame_cols + where.tx + x];
cell.text[0] = ' ';
cell.len = 1;
}
@@ -268,7 +266,8 @@ pub fn draw(
const Ctx = struct {
ti: *TerminalImages,
- p: *pardes.Pardes,
+ gpa: std.mem.Allocator,
+ out: *std.ArrayList(plain.Placement),
pane: u8,
serial: u32,
tx: u16,
@@ -286,7 +285,7 @@ const Ctx = struct {
const x0 = @max(dst.x, 0);
const x1 = @min(dst.x + dst.w, @as(i64, ctx.cols) * cw);
if (x1 <= x0) return;
- const rgba = ctx.ti.pixelsOf(ctx.p.gpa, img) orelse return;
+ const rgba = ctx.ti.pixelsOf(ctx.gpa, img) orelse return;
const first_row = @divFloor(@max(dst.y, 0), ch);
const last_row = @min(@divFloor(dst.y + dst.h - 1, ch), @as(i64, @intCast(ctx.rows_of.len)) - 1);
var v = first_row;
@@ -304,7 +303,7 @@ const Ctx = struct {
};
const c0: u16 = @intCast(@divFloor(x0, cw));
const c1: u16 = @intCast(@divFloor(x1 + cw - 1, cw));
- _ = ctx.p.appendPlacement(.{
+ ctx.out.append(ctx.gpa, .{
.pane = ctx.pane,
.raster = .of(rgba, img.width, img.height),
.src = piece,
@@ -318,7 +317,7 @@ const Ctx = struct {
.key = plain.Placement.keyOf(ctx.serial, img.id, @truncate(img.generation)),
.z = z,
.art = .{ .glyph = ctx.ti.petscii },
- });
+ }) catch {};
}
}
};