Skip to content

Commit

Permalink
core: darwin: Only recreate swapchain and send resize event if the wi…
Browse files Browse the repository at this point in the history
…ndow size actually changed
  • Loading branch information
foxnne authored and emidoots committed Dec 24, 2024
1 parent 8520c6d commit cc387dd
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/core/Darwin.zig
Original file line number Diff line number Diff line change
Expand Up @@ -354,29 +354,31 @@ const WindowDelegateCallbacks = struct {
const frame = native_window.frame();
const content_rect = native_window.contentRectForFrameRect(frame);

core_window.width = @intFromFloat(content_rect.size.width);
core_window.height = @intFromFloat(content_rect.size.height);
if (core_window.width != @as(u32, @intFromFloat(content_rect.size.width)) or core_window.height != @as(u32, @intFromFloat(content_rect.size.height))) {
core_window.width = @intFromFloat(content_rect.size.width);
core_window.height = @intFromFloat(content_rect.size.height);

const framebuffer_scale: f32 = @floatCast(native_window.backingScaleFactor());
const window_width: f32 = @floatFromInt(core_window.width);
const window_height: f32 = @floatFromInt(core_window.height);
const framebuffer_scale: f32 = @floatCast(native_window.backingScaleFactor());
const window_width: f32 = @floatFromInt(core_window.width);
const window_height: f32 = @floatFromInt(core_window.height);

core_window.framebuffer_width = @intFromFloat(window_width * framebuffer_scale);
core_window.framebuffer_height = @intFromFloat(window_height * framebuffer_scale);
core_window.framebuffer_width = @intFromFloat(window_width * framebuffer_scale);
core_window.framebuffer_height = @intFromFloat(window_height * framebuffer_scale);

core_window.swap_chain_descriptor.width = core_window.framebuffer_width;
core_window.swap_chain_descriptor.height = core_window.framebuffer_height;
core_window.swap_chain.release();
core_window.swap_chain_descriptor.width = core_window.framebuffer_width;
core_window.swap_chain_descriptor.height = core_window.framebuffer_height;
core_window.swap_chain.release();

core_window.swap_chain = core_window.device.createSwapChain(core_window.surface, &core_window.swap_chain_descriptor);
}
core_window.swap_chain = core_window.device.createSwapChain(core_window.surface, &core_window.swap_chain_descriptor);

core.windows.setValueRaw(block.context.window_id, core_window);
core.windows.setValueRaw(block.context.window_id, core_window);

core.pushEvent(.{ .window_resize = .{
.window_id = block.context.window_id,
.size = .{ .width = core_window.width, .height = core_window.height },
} });
core.pushEvent(.{ .window_resize = .{
.window_id = block.context.window_id,
.size = .{ .width = core_window.width, .height = core_window.height },
} });
}
}
}

pub fn windowShouldClose(block: *objc.foundation.BlockLiteral(*Context)) callconv(.C) bool {
Expand Down

0 comments on commit cc387dd

Please sign in to comment.