Skip to content

Commit 984c5ec

Browse files
committed
cube: Resize surface after configure
1 parent 83cded8 commit 984c5ec

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

cube/cube.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ struct demo {
443443
struct wl_seat *seat;
444444
struct wl_pointer *pointer;
445445
struct wl_keyboard *keyboard;
446+
int pending_width, pending_height;
446447
#endif
447448
#if defined(VK_USE_PLATFORM_DIRECTFB_EXT)
448449
IDirectFB *dfb;
@@ -1372,6 +1373,12 @@ static void demo_prepare_swapchain(struct demo *demo) {
13721373
VkResult U_ASSERT_ONLY err;
13731374
VkSwapchainKHR oldSwapchain = demo->swapchain;
13741375

1376+
#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1377+
if (demo->wsi_platform == WSI_PLATFORM_WAYLAND && !demo->xdg_surface_has_been_configured) {
1378+
return;
1379+
}
1380+
#endif
1381+
13751382
// Check the surface capabilities and formats
13761383
VkSurfaceCapabilitiesKHR surfCapabilities;
13771384
err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(demo->gpu, demo->surface, &surfCapabilities);
@@ -3054,10 +3061,14 @@ static void demo_run(struct demo *demo) {
30543061
static void handle_surface_configure(void *data, struct xdg_surface *xdg_surface, uint32_t serial) {
30553062
struct demo *demo = (struct demo *)data;
30563063
xdg_surface_ack_configure(xdg_surface, serial);
3057-
if (demo->xdg_surface_has_been_configured) {
3058-
demo_resize(demo);
3059-
}
30603064
demo->xdg_surface_has_been_configured = 1;
3065+
if (demo->pending_width > 0) {
3066+
demo->width = demo->pending_width;
3067+
}
3068+
if (demo->pending_height > 0) {
3069+
demo->height = demo->pending_height;
3070+
}
3071+
demo_resize(demo);
30613072
}
30623073

30633074
static const struct xdg_surface_listener xdg_surface_listener = {handle_surface_configure};
@@ -3068,10 +3079,10 @@ static void handle_toplevel_configure(void *data, struct xdg_toplevel *xdg_tople
30683079
/* zero values imply the program may choose its own size, so in that case
30693080
* stay with the existing value (which on startup is the default) */
30703081
if (width > 0) {
3071-
demo->width = width;
3082+
demo->pending_width = width;
30723083
}
30733084
if (height > 0) {
3074-
demo->height = height;
3085+
demo->pending_height = height;
30753086
}
30763087
/* This should be followed by a surface configure */
30773088
}

cube/cube.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ struct Demo {
442442
wl_seat *seat = nullptr;
443443
wl_pointer *pointer = nullptr;
444444
wl_keyboard *keyboard = nullptr;
445+
int pending_width, pending_height;
445446
#endif
446447
#if defined(VK_USE_PLATFORM_DIRECTFB_EXT)
447448
IDirectFB *dfb = nullptr;
@@ -2197,6 +2198,12 @@ void Demo::prepare() {
21972198
void Demo::prepare_swapchain() {
21982199
vk::SwapchainKHR oldSwapchain = swapchain;
21992200

2201+
#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
2202+
if (wsi_platform == WsiPlatform::wayland && !xdg_surface_has_been_configured) {
2203+
return;
2204+
}
2205+
#endif
2206+
22002207
// Check the surface capabilities and formats
22012208
auto surface_capabilities_return = gpu.getSurfaceCapabilitiesKHR(surface);
22022209
VERIFY(surface_capabilities_return.result == vk::Result::eSuccess);
@@ -3418,10 +3425,14 @@ void Demo::run<WsiPlatform::wayland>() {
34183425
static void handle_surface_configure(void *data, xdg_surface *xdg_surface, uint32_t serial) {
34193426
Demo &demo = *static_cast<Demo *>(data);
34203427
xdg_surface_ack_configure(xdg_surface, serial);
3421-
if (demo.xdg_surface_has_been_configured) {
3422-
demo.resize();
3423-
}
34243428
demo.xdg_surface_has_been_configured = true;
3429+
if (demo.pending_width > 0) {
3430+
demo.width = demo.pending_width;
3431+
}
3432+
if (demo.pending_height > 0) {
3433+
demo.height = demo.pending_height;
3434+
}
3435+
demo.resize();
34253436
}
34263437

34273438
static const xdg_surface_listener surface_listener = {handle_surface_configure};
@@ -3432,10 +3443,10 @@ static void handle_toplevel_configure(void *data, xdg_toplevel *xdg_toplevel, in
34323443
/* zero values imply the program may choose its own size, so in that case
34333444
* stay with the existing value (which on startup is the default) */
34343445
if (width > 0) {
3435-
demo.width = static_cast<uint32_t>(width);
3446+
demo.pending_width = static_cast<uint32_t>(width);
34363447
}
34373448
if (height > 0) {
3438-
demo.height = static_cast<uint32_t>(height);
3449+
demo.pending_height = static_cast<uint32_t>(height);
34393450
}
34403451
// This will be followed by a surface configure
34413452
}

0 commit comments

Comments
 (0)