Do not set layer as opaque

This commit is contained in:
Rohit-Bevinahally
2025-02-23 15:24:03 +05:30
committed by rohitb
parent 776981419e
commit 3020a30fb2
2 changed files with 18 additions and 11 deletions

View File

@ -623,7 +623,7 @@ pub fn init(alloc: Allocator, options: renderer.Options) !Metal {
else => @compileError("unsupported target for Metal"), else => @compileError("unsupported target for Metal"),
}; };
layer.setProperty("device", gpu_state.device.value); layer.setProperty("device", gpu_state.device.value);
layer.setProperty("opaque", options.config.background_opacity >= 1); layer.setProperty("opaque", options.config.background_opacity >= 1 and options.config.background_image.value == null);
layer.setProperty("displaySyncEnabled", options.config.vsync); layer.setProperty("displaySyncEnabled", options.config.vsync);
// Set our layer's pixel format appropriately. // Set our layer's pixel format appropriately.
@ -1272,7 +1272,6 @@ pub fn updateFrame(
// TODO: Is this expensive? Should we be checking if our // TODO: Is this expensive? Should we be checking if our
// bg color has changed first before doing this work? // bg color has changed first before doing this work?
{ {
std.log.info("Updating background color to {}", .{critical.bg});
const color = graphics.c.CGColorCreate( const color = graphics.c.CGColorCreate(
@ptrCast(self.terminal_colorspace), @ptrCast(self.terminal_colorspace),
&[4]f64{ &[4]f64{
@ -1339,7 +1338,11 @@ pub fn updateFrame(
.replace_gray_alpha, .replace_gray_alpha,
.replace_rgb, .replace_rgb,
.replace_rgba, .replace_rgba,
=> try self.current_background_image.?.upload(self.alloc, self.gpu_state.device), => try self.current_background_image.?.upload(
self.alloc,
self.gpu_state.device,
self.gpu_state.default_storage_mode,
),
.unload_pending, .unload_pending,
.unload_replace, .unload_replace,
@ -1720,7 +1723,11 @@ fn drawBackgroundImage(
@as(f32, @floatFromInt(self.size.terminal().height)), @as(f32, @floatFromInt(self.size.terminal().height)),
}, },
.mode = self.background_image_mode, .mode = self.background_image_mode,
}}); }}, .{
// Indicate that the CPU writes to this resource but never reads it.
.cpu_cache_mode = .write_combined,
.storage_mode = self.gpu_state.default_storage_mode,
});
defer buf.deinit(); defer buf.deinit();
// Set our buffer // Set our buffer
@ -2401,7 +2408,7 @@ pub fn changeConfig(self: *Metal, config: *DerivedConfig) !void {
CATransaction.msgSend(void, "begin", .{}); CATransaction.msgSend(void, "begin", .{});
defer CATransaction.msgSend(void, "commit", .{}); defer CATransaction.msgSend(void, "commit", .{});
self.layer.setProperty("opaque", config.background_opacity >= 1); self.layer.setProperty("opaque", config.background_opacity >= 1 and config.background_image.value == null);
self.layer.setProperty("displaySyncEnabled", config.vsync); self.layer.setProperty("displaySyncEnabled", config.vsync);
} }

View File

@ -262,12 +262,12 @@ fragment float4 cell_bg_fragment(
int2 grid_pos = int2(floor((in.position.xy - uniforms.grid_padding.wx) / uniforms.cell_size)); int2 grid_pos = int2(floor((in.position.xy - uniforms.grid_padding.wx) / uniforms.cell_size));
float4 bg = float4(0.0); float4 bg = float4(0.0);
// If we have any background transparency then we render bg-colored cells as // If we have any background transparency or a background image, then we
// fully transparent, since the background is handled by the layer bg color // render bg-colored cells as fully transparent, since the background is
// and we don't want to double up our bg color, but if our bg color is fully // handled by the layer bg color and we don't want to double up our bg color.
// opaque then our layer is opaque and can't handle transparency, so we need // But if our bg color is fully opaque, then our layer is opaque and can't
// to return the bg color directly instead. // handle transparency, so we need to return the bg color directly instead.
if (uniforms.bg_color.a == 255) { if (uniforms.bg_color.a == 255 && !uniforms.has_bg_image) {
bg = in.bg_color; bg = in.bg_color;
} }