diff options
Diffstat (limited to 'addons/pdf/pdf.zig')
| -rw-r--r-- | addons/pdf/pdf.zig | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/addons/pdf/pdf.zig b/addons/pdf/pdf.zig index 45f1e22a..d7125de5 100644 --- a/addons/pdf/pdf.zig +++ b/addons/pdf/pdf.zig @@ -709,7 +709,9 @@ pub const Pdf = struct { const In = extern struct { op: Op, cookie: u32 = 0, doc: u64 = 0, page: u32 = 0, tint: Tint = .disabled, req: Request = std.mem.zeroes(Request), band_y: u32 = 0, band_h: u32 = 0, ink: u32 = 0, paper: u32 = 0, keep_clean: u32 = 0, n: u32 = 0 }; /// A job's answer, and after it the sizes (sizes), the text (text), the /// quads (hits), or each page's count of hits and the rows (search). - const Out = extern struct { ok: u32 = 0, busy: u32 = 0, w: u32 = 0, h: u32 = 0, band_y: u32 = 0, band_h: u32 = 0, n: u32 = 0, hits: u32 = 0, rgba: ?[*]u8 = null, clean: ?[*]u8 = null }; + /// (`doc`: the document a render's pixels are of: one closed since, + /// a file changed on disk, freed them with it.) + const Out = extern struct { ok: u32 = 0, busy: u32 = 0, w: u32 = 0, h: u32 = 0, band_y: u32 = 0, band_h: u32 = 0, n: u32 = 0, hits: u32 = 0, doc: u64 = 0, rgba: ?[*]u8 = null, clean: ?[*]u8 = null }; /// On a worker: the job on a free lane of its document. pub fn jobRun(bytes: []const u8, gpa: std.mem.Allocator) ?[]u8 { @@ -780,7 +782,8 @@ pub const Pdf = struct { const res = if (bytes.len >= @sizeOf(Out)) std.mem.bytesToValue(Out, bytes[0..@sizeOf(Out)]) else Out{}; const extra = bytes[@min(bytes.len, @sizeOf(Out))..]; const len = @as(usize, res.w) * 4 * res.band_h; - const px: [2][]u8 = .{ if (res.rgba) |p| p[0..len] else &.{}, if (res.clean) |p| p[0..len] else &.{} }; + const ours = res.doc == d.id; + const px: [2][]u8 = .{ if (res.rgba) |p| (if (ours) p[0..len] else &.{}) else &.{}, if (res.clean) |p| (if (ours) p[0..len] else &.{}) else &.{} }; for (px) |p| claim(d, p); var kept = false; // (the pixels, a page's slot's) defer if (!kept) for (px) |p| heap.free(p); @@ -835,7 +838,7 @@ pub const Pdf = struct { if (s.job.token == token and s.view != 0) break s; } else return; s.job.token, s.job.failed = .{ 0, res.ok == 0 and res.busy == 0 }; - if (res.ok == 0) return; + if (res.ok == 0 or !ours) return; for ([_][]const u8{ s.rgba, s.clean, std.mem.sliceAsBytes(s.shown) }) |p| heap.free(p); const v = st.views[s.view - 1].v; st.revs += 1; @@ -888,7 +891,7 @@ fn render(d: *Doc, ld: ?*m.pardes_pdf_document, in: *const Pdf.In, marks: []cons }; docs_lock.unlock(); if (kept) { - res.* = .{ .ok = 1, .w = @intCast(L.width), .h = full, .band_y = by, .band_h = bh, .rgba = px.ptr, .clean = if (clean.len > 0) clean.ptr else null }; + res.* = .{ .ok = 1, .w = @intCast(L.width), .h = full, .band_y = by, .band_h = bh, .doc = d.id, .rgba = px.ptr, .clean = if (clean.len > 0) clean.ptr else null }; return; } for ([_][]u8{ px, clean }) |p| { |
