Skip to content

Commit e3ecc39

Browse files
PancakeTAScharles-lunarg
authored andcommitted
cube: Resize surface after configure
1 parent 22fee0e commit e3ecc39

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);
@@ -3055,10 +3062,14 @@ static void demo_run(struct demo *demo) {
30553062
static void handle_surface_configure(void *data, struct xdg_surface *xdg_surface, uint32_t serial) {
30563063
struct demo *demo = (struct demo *)data;
30573064
xdg_surface_ack_configure(xdg_surface, serial);
3058-
if (demo->xdg_surface_has_been_configured) {
3059-
demo_resize(demo);
3060-
}
30613065
demo->xdg_surface_has_been_configured = 1;
3066+
if (demo->pending_width > 0) {
3067+
demo->width = demo->pending_width;
3068+
}
3069+
if (demo->pending_height > 0) {
3070+
demo->height = demo->pending_height;
3071+
}
3072+
demo_resize(demo);
30623073
}
30633074

30643075
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
30693080
/* zero values imply the program may choose its own size, so in that case
30703081
* stay with the existing value (which on startup is the default) */
30713082
if (width > 0) {
3072-
demo->width = width;
3083+
demo->pending_width = width;
30733084
}
30743085
if (height > 0) {
3075-
demo->height = height;
3086+
demo->pending_height = height;
30763087
}
30773088
/* This should be followed by a surface configure */
30783089
}

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);
@@ -3419,10 +3426,14 @@ void Demo::run<WsiPlatform::wayland>() {
34193426
static void handle_surface_configure(void *data, xdg_surface *xdg_surface, uint32_t serial) {
34203427
Demo &demo = *static_cast<Demo *>(data);
34213428
xdg_surface_ack_configure(xdg_surface, serial);
3422-
if (demo.xdg_surface_has_been_configured) {
3423-
demo.resize();
3424-
}
34253429
demo.xdg_surface_has_been_configured = true;
3430+
if (demo.pending_width > 0) {
3431+
demo.width = demo.pending_width;
3432+
}
3433+
if (demo.pending_height > 0) {
3434+
demo.height = demo.pending_height;
3435+
}
3436+
demo.resize();
34263437
}
34273438

34283439
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
34333444
/* zero values imply the program may choose its own size, so in that case
34343445
* stay with the existing value (which on startup is the default) */
34353446
if (width > 0) {
3436-
demo.width = static_cast<uint32_t>(width);
3447+
demo.pending_width = static_cast<uint32_t>(width);
34373448
}
34383449
if (height > 0) {
3439-
demo.height = static_cast<uint32_t>(height);
3450+
demo.pending_height = static_cast<uint32_t>(height);
34403451
}
34413452
// This will be followed by a surface configure
34423453
}

0 commit comments

Comments
 (0)