aboutsummaryrefslogtreecommitdiff
path: root/cube
diff options
context:
space:
mode:
authorPancakeTAS <pancake@mgnet.work>2025-09-20 15:22:07 +0200
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>2025-09-22 13:35:50 -0600
commite3ecc39da57a5ed15ec8de67f136273ee54b78be (patch)
tree6bb94b8855632656c23dbda6d99b6dde76f147ce /cube
parent22fee0e85d0d31af603bf591f70530c1c83ba186 (diff)
downloadusermoji-e3ecc39da57a5ed15ec8de67f136273ee54b78be.tar.xz
cube: Resize surface after configure
Diffstat (limited to 'cube')
-rw-r--r--cube/cube.c21
-rw-r--r--cube/cube.cpp21
2 files changed, 32 insertions, 10 deletions
diff --git a/cube/cube.c b/cube/cube.c
index 63fc07b2..5797ca51 100644
--- a/cube/cube.c
+++ b/cube/cube.c
@@ -443,6 +443,7 @@ struct demo {
struct wl_seat *seat;
struct wl_pointer *pointer;
struct wl_keyboard *keyboard;
+ int pending_width, pending_height;
#endif
#if defined(VK_USE_PLATFORM_DIRECTFB_EXT)
IDirectFB *dfb;
@@ -1372,6 +1373,12 @@ static void demo_prepare_swapchain(struct demo *demo) {
VkResult U_ASSERT_ONLY err;
VkSwapchainKHR oldSwapchain = demo->swapchain;
+#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
+ if (demo->wsi_platform == WSI_PLATFORM_WAYLAND && !demo->xdg_surface_has_been_configured) {
+ return;
+ }
+#endif
+
// Check the surface capabilities and formats
VkSurfaceCapabilitiesKHR surfCapabilities;
err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(demo->gpu, demo->surface, &surfCapabilities);
@@ -3055,10 +3062,14 @@ static void demo_run(struct demo *demo) {
static void handle_surface_configure(void *data, struct xdg_surface *xdg_surface, uint32_t serial) {
struct demo *demo = (struct demo *)data;
xdg_surface_ack_configure(xdg_surface, serial);
- if (demo->xdg_surface_has_been_configured) {
- demo_resize(demo);
- }
demo->xdg_surface_has_been_configured = 1;
+ if (demo->pending_width > 0) {
+ demo->width = demo->pending_width;
+ }
+ if (demo->pending_height > 0) {
+ demo->height = demo->pending_height;
+ }
+ demo_resize(demo);
}
static const struct xdg_surface_listener xdg_surface_listener = {handle_surface_configure};
@@ -3069,10 +3080,10 @@ static void handle_toplevel_configure(void *data, struct xdg_toplevel *xdg_tople
/* zero values imply the program may choose its own size, so in that case
* stay with the existing value (which on startup is the default) */
if (width > 0) {
- demo->width = width;
+ demo->pending_width = width;
}
if (height > 0) {
- demo->height = height;
+ demo->pending_height = height;
}
/* This should be followed by a surface configure */
}
diff --git a/cube/cube.cpp b/cube/cube.cpp
index 7f4b45d2..04ba3150 100644
--- a/cube/cube.cpp
+++ b/cube/cube.cpp
@@ -442,6 +442,7 @@ struct Demo {
wl_seat *seat = nullptr;
wl_pointer *pointer = nullptr;
wl_keyboard *keyboard = nullptr;
+ int pending_width, pending_height;
#endif
#if defined(VK_USE_PLATFORM_DIRECTFB_EXT)
IDirectFB *dfb = nullptr;
@@ -2197,6 +2198,12 @@ void Demo::prepare() {
void Demo::prepare_swapchain() {
vk::SwapchainKHR oldSwapchain = swapchain;
+#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
+ if (wsi_platform == WsiPlatform::wayland && !xdg_surface_has_been_configured) {
+ return;
+ }
+#endif
+
// Check the surface capabilities and formats
auto surface_capabilities_return = gpu.getSurfaceCapabilitiesKHR(surface);
VERIFY(surface_capabilities_return.result == vk::Result::eSuccess);
@@ -3419,10 +3426,14 @@ void Demo::run<WsiPlatform::wayland>() {
static void handle_surface_configure(void *data, xdg_surface *xdg_surface, uint32_t serial) {
Demo &demo = *static_cast<Demo *>(data);
xdg_surface_ack_configure(xdg_surface, serial);
- if (demo.xdg_surface_has_been_configured) {
- demo.resize();
- }
demo.xdg_surface_has_been_configured = true;
+ if (demo.pending_width > 0) {
+ demo.width = demo.pending_width;
+ }
+ if (demo.pending_height > 0) {
+ demo.height = demo.pending_height;
+ }
+ demo.resize();
}
static const xdg_surface_listener surface_listener = {handle_surface_configure};
@@ -3433,10 +3444,10 @@ static void handle_toplevel_configure(void *data, xdg_toplevel *xdg_toplevel, in
/* zero values imply the program may choose its own size, so in that case
* stay with the existing value (which on startup is the default) */
if (width > 0) {
- demo.width = static_cast<uint32_t>(width);
+ demo.pending_width = static_cast<uint32_t>(width);
}
if (height > 0) {
- demo.height = static_cast<uint32_t>(height);
+ demo.pending_height = static_cast<uint32_t>(height);
}
// This will be followed by a surface configure
}