kitty graphics: address review comments

- move wuffs code from src/ to pkg/
- eliminate stray debug logs
- make logs a warning instead of an error
- remove initialization of some structs to zero
This commit is contained in:
Jeffrey C. Ollie
2024-09-02 00:37:10 -05:00
committed by Mitchell Hashimoto
parent e6c3ba2cf9
commit 6edeb45e7e
12 changed files with 70 additions and 37 deletions

View File

@ -1038,7 +1038,10 @@ fn addDeps(
.images = false,
.text_input = false,
});
const wuffs_dep = b.dependency("wuffs", .{});
const wuffs_dep = b.dependency("wuffs", .{
.target = target,
.optimize = optimize,
});
// Wasm we do manually since it is such a different build.
if (step.rootModuleTarget().cpu.arch == .wasm32) {
@ -1063,21 +1066,6 @@ fn addDeps(
step.addIncludePath(b.path("src/apprt/gtk"));
}
step.addIncludePath(wuffs_dep.path("release/c"));
step.addCSourceFile(
.{
.file = wuffs_dep.path("release/c/wuffs-v0.4.c"),
.flags = f: {
const flags = @import("src/wuffs/defs.zig").build;
var a: [flags.len][]const u8 = undefined;
inline for (flags, 0..) |flag, i| {
a[i] = "-D" ++ flag ++ "=1";
}
break :f &a;
},
},
);
// C++ files
step.linkLibCpp();
step.addIncludePath(b.path("src"));
@ -1139,6 +1127,7 @@ fn addDeps(
step.root_module.addImport("sentry", sentry_dep.module("sentry"));
step.root_module.addImport("ziglyph", ziglyph_dep.module("ziglyph"));
step.root_module.addImport("vaxis", vaxis_dep.module("vaxis"));
step.root_module.addImport("wuffs", wuffs_dep.module("wuffs"));
// Mac Stuff
if (step.rootModuleTarget().isDarwin()) {

View File

@ -40,11 +40,8 @@
.sentry = .{ .path = "./pkg/sentry" },
.simdutf = .{ .path = "./pkg/simdutf" },
.utfcpp = .{ .path = "./pkg/utfcpp" },
.wuffs = .{ .path = "./pkg/wuffs" },
.zlib = .{ .path = "./pkg/zlib" },
.wuffs = .{
.url = "https://github.com/google/wuffs/archive/refs/tags/v0.4.0-alpha.8.tar.gz",
.hash = "12200984439edc817fbcbbaff564020e5104a0d04a2d0f53080700827052de700462",
},
// Shader translation
.glslang = .{ .path = "./pkg/glslang" },

30
pkg/wuffs/build.zig Normal file
View File

@ -0,0 +1,30 @@
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const wuffs = b.dependency("wuffs", .{});
const module = b.addModule("wuffs", .{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
module.addIncludePath(wuffs.path("release/c"));
module.addCSourceFile(
.{
.file = wuffs.path("release/c/wuffs-v0.4.c"),
.flags = f: {
const flags = @import("src/defs.zig").build;
var a: [flags.len][]const u8 = undefined;
inline for (flags, 0..) |flag, i| {
a[i] = "-D" ++ flag ++ "=1";
}
break :f &a;
},
},
);
}

17
pkg/wuffs/build.zig.zon Normal file
View File

@ -0,0 +1,17 @@
.{
.name = "wuffs",
.version = "0.0.0",
.dependencies = .{
.wuffs = .{
.url = "https://github.com/google/wuffs/archive/refs/tags/v0.4.0-alpha.8.tar.gz",
.hash = "12200984439edc817fbcbbaff564020e5104a0d04a2d0f53080700827052de700462",
},
},
.paths = .{
"build.zig",
"build.zig.zon",
"src",
},
}

View File

@ -10,8 +10,6 @@ pub fn decode(alloc: std.mem.Allocator, data: []const u8) Error!struct {
height: u32,
data: []const u8,
} {
log.info("data is {d} bytes", .{data.len});
// Work around some weirdness in WUFFS/Zig, there are some structs that
// are defined as "extern" by the Zig compiler which means that Zig won't
// allocate them on the stack at compile time. WUFFS has functions for
@ -32,12 +30,12 @@ pub fn decode(alloc: std.mem.Allocator, data: []const u8) Error!struct {
);
if (!c.wuffs_base__status__is_ok(&status)) {
const e = c.wuffs_base__status__message(&status);
log.err("{s}", .{e});
log.warn("{s}", .{e});
return error.WuffsError;
}
}
var source_buffer = std.mem.zeroes(c.wuffs_base__io_buffer);
var source_buffer: c.wuffs_base__io_buffer = undefined;
source_buffer.data.ptr = @constCast(@ptrCast(data.ptr));
source_buffer.data.len = data.len;
source_buffer.meta.wi = data.len;
@ -45,7 +43,7 @@ pub fn decode(alloc: std.mem.Allocator, data: []const u8) Error!struct {
source_buffer.meta.pos = 0;
source_buffer.meta.closed = true;
var image_config = std.mem.zeroes(c.wuffs_base__image_config);
var image_config: c.wuffs_base__image_config = undefined;
{
const status = c.wuffs_png__decoder__decode_image_config(
decoder,
@ -54,7 +52,7 @@ pub fn decode(alloc: std.mem.Allocator, data: []const u8) Error!struct {
);
if (!c.wuffs_base__status__is_ok(&status)) {
const e = c.wuffs_base__status__message(&status);
log.err("{s}", .{e});
log.warn("{s}", .{e});
return error.WuffsError;
}
}
@ -70,9 +68,10 @@ pub fn decode(alloc: std.mem.Allocator, data: []const u8) Error!struct {
height,
);
const color = c.wuffs_base__color_u32_argb_premul;
const destination = try alloc.alloc(u8, width * height * @sizeOf(color));
const destination = try alloc.alloc(
u8,
width * height * @sizeOf(c.wuffs_base__color_u32_argb_premul),
);
errdefer alloc.free(destination);
// temporary buffer for intermediate processing of image
@ -87,7 +86,7 @@ pub fn decode(alloc: std.mem.Allocator, data: []const u8) Error!struct {
work_buffer.len,
);
var pixel_buffer = std.mem.zeroes(c.wuffs_base__pixel_buffer);
var pixel_buffer: c.wuffs_base__pixel_buffer = undefined;
{
const status = c.wuffs_base__pixel_buffer__set_from_slice(
&pixel_buffer,
@ -96,12 +95,12 @@ pub fn decode(alloc: std.mem.Allocator, data: []const u8) Error!struct {
);
if (!c.wuffs_base__status__is_ok(&status)) {
const e = c.wuffs_base__status__message(&status);
log.err("{s}", .{e});
log.warn("{s}", .{e});
return error.WuffsError;
}
}
var frame_config = std.mem.zeroes(c.wuffs_base__frame_config);
var frame_config: c.wuffs_base__frame_config = undefined;
{
const status = c.wuffs_png__decoder__decode_frame_config(
decoder,
@ -110,7 +109,7 @@ pub fn decode(alloc: std.mem.Allocator, data: []const u8) Error!struct {
);
if (!c.wuffs_base__status__is_ok(&status)) {
const e = c.wuffs_base__status__message(&status);
log.err("{s}", .{e});
log.warn("{s}", .{e});
return error.WuffsError;
}
}
@ -126,7 +125,7 @@ pub fn decode(alloc: std.mem.Allocator, data: []const u8) Error!struct {
);
if (!c.wuffs_base__status__is_ok(&status)) {
const e = c.wuffs_base__status__message(&status);
log.err("{s}", .{e});
log.warn("{s}", .{e});
return error.WuffsError;
}
}

View File

@ -62,6 +62,7 @@ fn swizzle(
std.debug.assert(c.wuffs_base__pixel_format__bits_per_pixel(&src_fmt) % 8 == 0);
const src_size = c.wuffs_base__pixel_format__bits_per_pixel(&src_fmt) / 8;
std.debug.assert(src.len % src_size == 0);
const dst = try alloc.alloc(u8, src.len * dst_size / src_size);
@ -85,7 +86,7 @@ fn swizzle(
);
if (!c.wuffs_base__status__is_ok(&status)) {
const e = c.wuffs_base__status__message(&status);
log.err("{s}", .{e});
log.warn("{s}", .{e});
return error.WuffsError;
}
}

View File

@ -2,7 +2,7 @@ const std = @import("std");
const Allocator = std.mem.Allocator;
const assert = std.debug.assert;
const gl = @import("opengl");
const wuffs = @import("../../wuffs/main.zig");
const wuffs = @import("wuffs");
/// Represents a single image placement on the grid. A placement is a
/// request to render an instance of an image.

View File

@ -10,7 +10,7 @@ const command = @import("graphics_command.zig");
const point = @import("../point.zig");
const PageList = @import("../PageList.zig");
const internal_os = @import("../../os/main.zig");
const wuffs = @import("../../wuffs/main.zig");
const wuffs = @import("wuffs");
const log = std.log.scoped(.kitty_gfx);