summaryrefslogtreecommitdiff
path: root/src/Kind.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/Kind.zig')
-rw-r--r--src/Kind.zig27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/Kind.zig b/src/Kind.zig
index 6d4caec6..250e1144 100644
--- a/src/Kind.zig
+++ b/src/Kind.zig
@@ -37,10 +37,10 @@ pub const abi: u32 = c.PA_ABI;
// records the core reads are the ones addons are built to.
comptime {
if (@sizeOf(usize) == 8) for (.{
- .{ c.pa_cell, 20 }, .{ c.pa_window, 24 }, .{ c.pa_rect, 16 }, .{ c.pa_cells, 8 },
- .{ c.pa_placement, 80 }, .{ c.pa_paint, 32 }, .{ c.pa_key, 8 }, .{ c.pa_mouse, 16 },
- .{ c.pa_api, 112 }, .{ c.pa_out, 16 }, .{ c.pa_word, 32 }, .{ c.pa_head, 56 },
- .{ c.pa_ops, 208 }, .{ c.pa_view, 32 }, .{ c.pa_tick, 128 },
+ .{ c.pa_cell, 20 }, .{ c.pa_window, 24 }, .{ c.pa_rect, 16 }, .{ c.pa_cells, 8 },
+ .{ c.pa_placement, 80 }, .{ c.pa_paint, 48 }, .{ c.pa_key, 8 }, .{ c.pa_mouse, 16 },
+ .{ c.pa_api, 112 }, .{ c.pa_out, 16 }, .{ c.pa_word, 32 }, .{ c.pa_head, 56 },
+ .{ c.pa_ops, 208 }, .{ c.pa_view, 32 }, .{ c.pa_tick, 128 },
}) |r| if (@sizeOf(r[0]) != r[1]) @compileError(std.fmt.comptimePrint("{s} is {d} bytes, the header says {d}", .{ @typeName(r[0]), @sizeOf(r[0]), r[1] }));
}
@@ -119,7 +119,6 @@ pub const Registry = struct {
pub const take = Addon.take;
pub const collides = Addon.collides;
pub const drop = Addon.drop;
-
};
// ---- a pane of a kind ----
@@ -389,7 +388,7 @@ pub fn draw(p: *Pardes, s: *surface.Surface, arena: std.mem.Allocator, pane: *Pa
var frame: Frame = .{ .cols = cols, .rows = rows };
if (slot.ops == null and slot.live) {
const sh = slot.shadow orelse return;
- frame = .{ .cells = sh.cells, .cols = sh.cols, .rows = sh.rows, .places = sh.places.items, .n = @intCast(sh.places.items.len) };
+ frame = .{ .cells = sh.cells, .cols = sh.cols, .rows = sh.rows, .places = sh.places.items, .n = @intCast(sh.places.items.len), .gpu = sh.gpu };
} else if (slot.ops == null) {
var line: [160]u8 = undefined;
const why = if (slot.refused.len > 0) slot.refused.slice() else "Addon load <path>";
@@ -398,6 +397,7 @@ pub fn draw(p: *Pardes, s: *surface.Surface, arena: std.mem.Allocator, pane: *Pa
_ = s.print(x, y, cols, text, .{ .fg = fg, .bg = bg });
return;
} else frame.cells = (paint(p, slot, id, arena, cols, rows, &frame) orelse return);
+ if (frame.gpu.len != 0) s.gpu_frames[id] = .{ .bytes = frame.gpu, .serial = pane.serial, .dst = .{ .x = x, .y = y, .w = cols, .h = rows } };
for (0..@min(rows, frame.rows)) |r| for (0..@min(cols, frame.cols)) |col| {
const cell = &frame.cells[r * frame.cols + col];
if (cell.flags & c.PA_PAINTED == 0) continue;
@@ -423,6 +423,7 @@ pub fn draw(p: *Pardes, s: *surface.Surface, arena: std.mem.Allocator, pane: *Pa
/// A frame of a kind's pane: its cells, `cols` a row, and its placements.
pub const Frame = struct {
+ gpu: []const u8 = &.{},
cells: []c.pa_cell = &.{},
cols: u16,
rows: u16,
@@ -438,7 +439,8 @@ pub fn paint(p: *const Pardes, slot: *Slot, id: usize, arena: std.mem.Allocator,
const ops = slot.ops orelse return null;
const cells = arena.alloc(c.pa_cell, @as(usize, cols) * rows) catch return null;
@memset(std.mem.sliceAsBytes(cells), 0);
- var out: c.pa_paint = std.mem.zeroInit(c.pa_paint, .{ .placements = &frame.buf, .cap = frame.buf.len });
+ var gpu: GpuPaint = .{ .arena = arena, .frame = frame };
+ var out: c.pa_paint = std.mem.zeroInit(c.pa_paint, .{ .placements = &frame.buf, .cap = frame.buf.len, .gpu = GpuPaint.emit, .gpu_ctx = &gpu });
const px = p.view().cell_pixels;
const win = std.mem.zeroInit(c.pa_window, .{ .cells = cells.ptr, .stride = cols, .rows = rows, .cols = cols, .cell_w = px.w, .cell_h = px.h, .focused = @intFromBool(focusedAnywhere(p, id)), .view = p.live + 1, .glyphs = @intFromBool(!p.view().frontend.native_images) });
var cl: Call = .{ .p = null, .id = 0, .slot = slot, .quiet = true };
@@ -1206,3 +1208,14 @@ test "a kind's head is checked before a core takes it, and a core's kinds are it
a.drop(a.byName("zzzab").?);
try std.testing.expect(a.byName("zzzab") == null);
}
+
+const GpuPaint = struct {
+ arena: std.mem.Allocator,
+ frame: *Frame,
+ fn emit(ctx: ?*anyopaque, bytes: [*c]const u8, n: u32) callconv(.c) c_int {
+ const self: *GpuPaint = @ptrCast(@alignCast(ctx orelse return 1));
+ if (bytes == null or n > 4 << 20) return 1;
+ self.frame.gpu = self.arena.dupe(u8, bytes[0..n]) catch return 1;
+ return 0;
+ }
+};