diff options
Diffstat (limited to 'core/term')
| -rw-r--r-- | core/term/TerminalImages.zig | 13 | ||||
| -rw-r--r-- | core/term/terminal.zig | 11 |
2 files changed, 14 insertions, 10 deletions
diff --git a/core/term/TerminalImages.zig b/core/term/TerminalImages.zig index 1420d9e3..feba5ddc 100644 --- a/core/term/TerminalImages.zig +++ b/core/term/TerminalImages.zig @@ -29,6 +29,8 @@ pub const storage_limit = 64 * 1024 * 1024; petscii: bool = false, /// Pixels in RGBA for images ghostty-vt holds in another format (RGB, /// grey): only for images on screen, dropped the frame they are not. +/// The emulator's own allocator's, as the emulator is (`draw`'s `own`): +/// never a client core's, whose rollback would free it under the emulator. converted: std.AutoHashMapUnmanaged(u32, Converted) = .empty, /// When the next frame of a playing animation (a=a) is due, in ms on the /// core's clock (`Pardes.stepped_ns`): the core wakes for it (nextWake). @@ -160,9 +162,11 @@ fn decodePng(gpa: std.mem.Allocator, bytes: []const u8) ghostty_vt.sys.DecodeErr /// Draw the active screen's images. `rows_of[v]` is the body row the /// viewport's row `v` is shown on, if it is shown; `cols` how many of its -/// columns the body shows, from `tx`. +/// columns the body shows, from `tx`. The caches are `own`'s (the +/// emulator's), `out` is `gpa`'s. pub fn draw( ti: *TerminalImages, + own: std.mem.Allocator, gpa: std.mem.Allocator, vt: *ghostty_vt.Terminal, where: plain.term.ImagesAt, @@ -173,7 +177,7 @@ pub fn draw( ) void { var conv = ti.converted.valueIterator(); while (conv.next()) |c| c.used = false; - defer ti.prune(gpa); + defer ti.prune(own); const screen = vt.screens.active; const storage = &screen.kitty_images; @@ -187,7 +191,7 @@ pub fn draw( const bottom = pages.getBottomRight(.viewport) orelse return; 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 }; + const ctx: Ctx = .{ .ti = ti, .own = own, .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 = out.items.len; @@ -268,6 +272,7 @@ pub fn draw( const Ctx = struct { ti: *TerminalImages, + own: std.mem.Allocator, gpa: std.mem.Allocator, out: *std.ArrayList(plain.Placement), pane: u8, @@ -287,7 +292,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.gpa, img) orelse return; + const rgba = ctx.ti.pixelsOf(ctx.own, 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; diff --git a/core/term/terminal.zig b/core/term/terminal.zig index d328748e..d99cfb79 100644 --- a/core/term/terminal.zig +++ b/core/term/terminal.zig @@ -721,12 +721,11 @@ pub fn scrollbackLen(state: ?*State) usize { return @intCast(counting.fullCount()); } -/// Its emulator and what it holds, freed; its kitty images' caches were -/// `gpa`'s. -pub fn close(state: *State, gpa: std.mem.Allocator) void { - if (comptime images_enabled) state.images.deinit(gpa); - state.stream.deinit(); +/// Its emulator and what it holds, freed. +pub fn close(state: *State) void { const own = state.gpa; + if (comptime images_enabled) state.images.deinit(own); + state.stream.deinit(); state.vt.deinit(own); own.destroy(state); } @@ -1502,7 +1501,7 @@ pub fn images(state: *State, gpa: std.mem.Allocator, at: ImagesAt, out: *std.Arr // Nothing to draw, no placeholder to blank and nothing cached to let // go: the common case costs the rows' flags. if (!any_placeholder and screen.kitty_images.placements.count() == 0 and state.images.converted.count() == 0) return; - state.images.draw(gpa, &state.vt, at, rows_of[0..vp_rows], out, frame, frame_cols); + state.images.draw(state.gpa, gpa, &state.vt, at, rows_of[0..vp_rows], out, frame, frame_cols); } test "the luminance table answers exactly what ghostty computes" { |
