-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds a number of memory optimizations to the painter: * Downsampling is now done in-place when using AA. Memory is freed after the downsample. This avoids an extra allocation for the downsampled surface. * Additionally in AA, if our pixel source is full opaque alpha, we fast-path to just using the mask as the foreground. This avoids another allocation under this scenario! * Finally, we have moved the edge calculations to a FixedBufferAllocator. The default allocation size (which can be tuned if you're okay calling the painter functions directly from the type function) is 1024 items, or 4096 bytes under our new Polygon.Edge packed struct. This has allowed us to drop the use of external allocators completely from non-AA paint. As part of this, we've dropped the X-coordinate in an edge to an i30 (this might be dropped lower as well, depending on the result of our internal numerics work). * We've also dropped the ArenaAllocator from AA paint as it's not bringing value anymore, and probably just getting in the way of our resize. All of these are in advance of fully addressing #44 - lowering the allocation footprint of the painter will make the path to infallibility much easier.
- Loading branch information
1 parent
3eb8352
commit caaae94
Showing
10 changed files
with
449 additions
and
305 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// SPDX-License-Identifier: 0BSD | ||
// Copyright © 2024 Chris Marchesi | ||
|
||
//! Case: Renders and fills a triangle on a 300x300 surface. | ||
//! | ||
//! This is similar to the 003_fill_triangle.zig, but uses alpha8 as its source | ||
//! versus RGB. | ||
const mem = @import("std").mem; | ||
|
||
const z2d = @import("z2d"); | ||
|
||
pub const filename = "046_fill_triangle_alpha"; | ||
|
||
pub fn render(alloc: mem.Allocator, aa_mode: z2d.options.AntiAliasMode) !z2d.Surface { | ||
const width = 300; | ||
const height = 300; | ||
const sfc = try z2d.Surface.initPixel( | ||
.{ .rgb = .{ .r = 0xFF, .g = 0xFF, .b = 0xFF } }, // White so that srcOver shows up correctly | ||
alloc, | ||
width, | ||
height, | ||
); | ||
|
||
var context: z2d.Context = .{ | ||
.surface = sfc, | ||
.pattern = .{ | ||
.opaque_pattern = .{ | ||
.pixel = .{ .alpha8 = .{ .a = 255 } }, | ||
}, | ||
}, | ||
.anti_aliasing_mode = aa_mode, | ||
}; | ||
|
||
var path = z2d.Path.init(alloc); | ||
defer path.deinit(); | ||
|
||
const margin = 10; | ||
try path.moveTo(0 + margin, 0 + margin); | ||
try path.lineTo(width - margin - 1, 0 + margin); | ||
try path.lineTo(width / 2 - 1, height - margin - 1); | ||
try path.close(); | ||
|
||
try context.fill(alloc, path); | ||
|
||
return sfc; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.