coretext: validate atlas depth matches color depth

This commit is contained in:
Mitchell Hashimoto
2023-06-30 16:59:17 -07:00
parent a74e49833b
commit c52dc229f3

View File

@ -5,6 +5,8 @@ const macos = @import("macos");
const harfbuzz = @import("harfbuzz");
const font = @import("../main.zig");
const log = std.log.scoped(.font_face);
pub const Face = struct {
/// Our font face
font: *macos.text.Font,
@ -172,6 +174,15 @@ pub const Face = struct {
};
defer color.space.release();
// This is just a safety check.
if (atlas.format.depth() != color.depth) {
log.warn("font atlas color depth doesn't equal font color depth atlas={} font={}", .{
atlas.format.depth(),
color.depth,
});
return error.InvalidAtlasFormat;
}
// Our buffer for rendering
// TODO(perf): cache this buffer
var buf = try alloc.alloc(u8, width * height * color.depth);