From 147b7dad17567c5b733511264fba385e733348bc Mon Sep 17 00:00:00 2001 From: Nicolas Capens Date: Fri, 9 Apr 2021 14:53:06 -0400 Subject: Fix setting the dequeueBuffer timeout to -1 ANativeWindow::perform() is a variadic function. When passing -1 as the variadic argument, it gets written as a 32-bit int. But it gets read in Surface::dispatchSetDequeueTimeout() using va_arg(args, int64_t), leaving the upper 32-bit undefined. Typically this is 0, and the value becomes 4294967295. This gets interpreted as a finite timeout of ~4 seconds, instead of the intended infinite timeout represented by negative values such as -1. This change preserves the -1 value by casting it nsecs_t (an alias of int64_t) prior to passing it to the variadic function. This makes android.graphics.cts.BitmapTest#testDrawingHardwareBitmapNotLeaking pass on Cuttlefish with SwANGLE, without the workaround of disabling EGL_EXT_buffer_age support in ANGLE. Note the test typically passes in less than 4 seconds, so it's not entirely clear why we were previously observing timeouts (perhaps it does not represent wall clock time), but the -1 value causes different code paths to be used in various places. Bug: b/182521420 Test: android.view.inputmethod.cts.FocusHandlingTest#testNonFocusablePopupWindowDoesNotAffectImeVisibilityandroid.graphics.cts.BitmapTest#testDrawingHardwareBitmapNotLeaking Change-Id: I94f83bb55e79799306b6e352d60a9ca9314bec20 --- vulkan/libvulkan/swapchain.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vulkan/libvulkan/swapchain.cpp b/vulkan/libvulkan/swapchain.cpp index 4b69bec743..2913850ab3 100644 --- a/vulkan/libvulkan/swapchain.cpp +++ b/vulkan/libvulkan/swapchain.cpp @@ -1088,7 +1088,8 @@ VkResult CreateSwapchainKHR(VkDevice device, ALOGW_IF(err != android::OK, "native_window_api_connect failed: %s (%d)", strerror(-err), err); - err = window->perform(window, NATIVE_WINDOW_SET_DEQUEUE_TIMEOUT, -1); + err = + window->perform(window, NATIVE_WINDOW_SET_DEQUEUE_TIMEOUT, nsecs_t{-1}); if (err != android::OK) { ALOGE("window->perform(SET_DEQUEUE_TIMEOUT) failed: %s (%d)", strerror(-err), err); -- cgit v1.2.3-59-g8ed1b