Skip to content

Commit

Permalink
internal/Painter: remove configurable edge FBA, use fallback alloc
Browse files Browse the repository at this point in the history
This removes the configurable FBA for the edge cache, moving it to a
fallback allocator instead, with the FBA being a much smaller size, so
that we respect the stack a lot more.

The FBA should be enough for 64 edges worst-case scenario each edge is 4
bytes and may be duplicated in the final edge set, so 64*4*2 =
512 bytes. Note that not all edges make it into the final edge set
(e.g., during non-zero fill), hence why we say worst-case. This can and
will be optimized eventually to allow for more.
  • Loading branch information
vancluever committed Nov 1, 2024
1 parent 5848bc0 commit 3ae47bf
Show file tree
Hide file tree
Showing 3 changed files with 257 additions and 259 deletions.
15 changes: 3 additions & 12 deletions src/Context.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,14 @@ const Context = @This();
const mem = @import("std").mem;

const options = @import("options.zig");
const paintpkg = @import("internal/Painter.zig");

const Painter = @import("internal/Painter.zig");
const Path = @import("Path.zig");
const Pattern = @import("pattern.zig").Pattern;
const Surface = @import("surface.zig").Surface;
const Transformation = @import("Transformation.zig");
const PathError = @import("errors.zig").PathError;

/// The default value to use for the edge cache during rasterization, in number
/// of edges that can be stored per scanline.
///
/// Note that this cannot be modified in the context. If you require a
/// different value, either due to OOM issues due to a large number of edges,
/// or if you want a smaller buffer, see internal/Painter.zig. Note that this
/// API is currently unstable.
comptime default_edge_cache_size: usize = 1024,

/// The underlying surface.
surface: Surface,

Expand Down Expand Up @@ -100,7 +91,7 @@ transformation: Transformation = Transformation.identity,
///
/// This is a no-op if there are no nodes.
pub fn fill(self: *Context, alloc: mem.Allocator, path: Path) !void {
try (paintpkg.Painter(self.default_edge_cache_size){ .context = self }).fill(alloc, path.nodes);
try (Painter{ .context = self }).fill(alloc, path.nodes);
}

/// Strokes a line for the path(s) in the supplied set.
Expand All @@ -115,5 +106,5 @@ pub fn fill(self: *Context, alloc: mem.Allocator, path: Path) !void {
///
/// This is a no-op if there are no nodes.
pub fn stroke(self: *Context, alloc: mem.Allocator, path: Path) !void {
try (paintpkg.Painter(self.default_edge_cache_size){ .context = self }).stroke(alloc, path.nodes);
try (Painter{ .context = self }).stroke(alloc, path.nodes);
}
Loading

0 comments on commit 3ae47bf

Please sign in to comment.