diff options
Diffstat (limited to 'libs/hwui/renderthread/VulkanManager.cpp')
-rw-r--r-- | libs/hwui/renderthread/VulkanManager.cpp | 134 |
1 files changed, 65 insertions, 69 deletions
diff --git a/libs/hwui/renderthread/VulkanManager.cpp b/libs/hwui/renderthread/VulkanManager.cpp index 9e435a5dbf75..d84ec8508ee4 100644 --- a/libs/hwui/renderthread/VulkanManager.cpp +++ b/libs/hwui/renderthread/VulkanManager.cpp @@ -16,7 +16,7 @@ #include "VulkanManager.h" -#include <private/gui/SyncFeatures.h> +#include <gui/Surface.h> #include "Properties.h" #include "RenderThread.h" @@ -454,7 +454,20 @@ VulkanSurface::BackbufferInfo* VulkanManager::getAvailableBackbuffer(VulkanSurfa return backbuffer; } -SkSurface* VulkanManager::getBackbufferSurface(VulkanSurface* surface) { +SkSurface* VulkanManager::getBackbufferSurface(VulkanSurface** surfaceOut) { + // Recreate VulkanSurface, if ANativeWindow has been resized. + VulkanSurface* surface = *surfaceOut; + int windowWidth = 0, windowHeight = 0; + ANativeWindow* window = surface->mNativeWindow; + window->query(window, NATIVE_WINDOW_WIDTH, &windowWidth); + window->query(window, NATIVE_WINDOW_HEIGHT, &windowHeight); + if (windowWidth != surface->mWindowWidth || windowHeight != surface->mWindowHeight) { + ColorMode colorMode = surface->mColorMode; + destroySurface(surface); + *surfaceOut = createSurface(window, colorMode); + surface = *surfaceOut; + } + VulkanSurface::BackbufferInfo* backbuffer = getAvailableBackbuffer(surface); SkASSERT(backbuffer); @@ -719,6 +732,8 @@ bool VulkanManager::createSwapchain(VulkanSurface* surface) { extent.height = caps.minImageExtent.height; } SkASSERT(extent.height <= caps.maxImageExtent.height); + surface->mWindowWidth = extent.width; + surface->mWindowHeight = extent.height; uint32_t imageCount = caps.minImageCount + 2; if (caps.maxImageCount > 0 && imageCount > caps.maxImageCount) { @@ -816,7 +831,7 @@ VulkanSurface* VulkanManager::createSurface(ANativeWindow* window, ColorMode col return nullptr; } - VulkanSurface* surface = new VulkanSurface(colorMode); + VulkanSurface* surface = new VulkanSurface(colorMode, window); VkAndroidSurfaceCreateInfoKHR surfaceCreateInfo; memset(&surfaceCreateInfo, 0, sizeof(VkAndroidSurfaceCreateInfoKHR)); @@ -1033,69 +1048,59 @@ status_t VulkanManager::fenceWait(sp<Fence>& fence) { return INVALID_OPERATION; } - if (SyncFeatures::getInstance().useWaitSync() && - SyncFeatures::getInstance().useNativeFenceSync()) { - // Block GPU on the fence. - int fenceFd = fence->dup(); - if (fenceFd == -1) { - ALOGE("VulkanManager::fenceWait: error dup'ing fence fd: %d", errno); - return -errno; - } + // Block GPU on the fence. + int fenceFd = fence->dup(); + if (fenceFd == -1) { + ALOGE("VulkanManager::fenceWait: error dup'ing fence fd: %d", errno); + return -errno; + } - VkSemaphoreCreateInfo semaphoreInfo; - semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; - semaphoreInfo.pNext = nullptr; - semaphoreInfo.flags = 0; - VkSemaphore semaphore; - VkResult err = mCreateSemaphore(mDevice, &semaphoreInfo, nullptr, &semaphore); - if (VK_SUCCESS != err) { - ALOGE("Failed to create import semaphore, err: %d", err); - return UNKNOWN_ERROR; - } - VkImportSemaphoreFdInfoKHR importInfo; - importInfo.sType = VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_FD_INFO_KHR; - importInfo.pNext = nullptr; - importInfo.semaphore = semaphore; - importInfo.flags = VK_SEMAPHORE_IMPORT_TEMPORARY_BIT; - importInfo.handleType = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT; - importInfo.fd = fenceFd; - - err = mImportSemaphoreFdKHR(mDevice, &importInfo); - if (VK_SUCCESS != err) { - ALOGE("Failed to import semaphore, err: %d", err); - return UNKNOWN_ERROR; - } + VkSemaphoreCreateInfo semaphoreInfo; + semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; + semaphoreInfo.pNext = nullptr; + semaphoreInfo.flags = 0; + VkSemaphore semaphore; + VkResult err = mCreateSemaphore(mDevice, &semaphoreInfo, nullptr, &semaphore); + if (VK_SUCCESS != err) { + ALOGE("Failed to create import semaphore, err: %d", err); + return UNKNOWN_ERROR; + } + VkImportSemaphoreFdInfoKHR importInfo; + importInfo.sType = VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_FD_INFO_KHR; + importInfo.pNext = nullptr; + importInfo.semaphore = semaphore; + importInfo.flags = VK_SEMAPHORE_IMPORT_TEMPORARY_BIT; + importInfo.handleType = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT; + importInfo.fd = fenceFd; + + err = mImportSemaphoreFdKHR(mDevice, &importInfo); + if (VK_SUCCESS != err) { + ALOGE("Failed to import semaphore, err: %d", err); + return UNKNOWN_ERROR; + } - LOG_ALWAYS_FATAL_IF(mDummyCB == VK_NULL_HANDLE); + LOG_ALWAYS_FATAL_IF(mDummyCB == VK_NULL_HANDLE); - VkPipelineStageFlags waitDstStageFlags = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; + VkPipelineStageFlags waitDstStageFlags = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; - VkSubmitInfo submitInfo; - memset(&submitInfo, 0, sizeof(VkSubmitInfo)); - submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; - submitInfo.waitSemaphoreCount = 1; - // Wait to make sure aquire semaphore set above has signaled. - submitInfo.pWaitSemaphores = &semaphore; - submitInfo.pWaitDstStageMask = &waitDstStageFlags; - submitInfo.commandBufferCount = 1; - submitInfo.pCommandBuffers = &mDummyCB; - submitInfo.signalSemaphoreCount = 0; + VkSubmitInfo submitInfo; + memset(&submitInfo, 0, sizeof(VkSubmitInfo)); + submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + submitInfo.waitSemaphoreCount = 1; + // Wait to make sure aquire semaphore set above has signaled. + submitInfo.pWaitSemaphores = &semaphore; + submitInfo.pWaitDstStageMask = &waitDstStageFlags; + submitInfo.commandBufferCount = 1; + submitInfo.pCommandBuffers = &mDummyCB; + submitInfo.signalSemaphoreCount = 0; - mQueueSubmit(mGraphicsQueue, 1, &submitInfo, VK_NULL_HANDLE); + mQueueSubmit(mGraphicsQueue, 1, &submitInfo, VK_NULL_HANDLE); - // On Android when we import a semaphore, it is imported using temporary permanence. That - // means as soon as we queue the semaphore for a wait it reverts to its previous permanent - // state before importing. This means it will now be in an idle state with no pending - // signal or wait operations, so it is safe to immediately delete it. - mDestroySemaphore(mDevice, semaphore, nullptr); - } else { - // Block CPU on the fence. - status_t err = fence->waitForever("VulkanManager::fenceWait"); - if (err != NO_ERROR) { - ALOGE("VulkanManager::fenceWait: error waiting for fence: %d", err); - return err; - } - } + // On Android when we import a semaphore, it is imported using temporary permanence. That + // means as soon as we queue the semaphore for a wait it reverts to its previous permanent + // state before importing. This means it will now be in an idle state with no pending + // signal or wait operations, so it is safe to immediately delete it. + mDestroySemaphore(mDevice, semaphore, nullptr); return OK; } @@ -1105,15 +1110,6 @@ status_t VulkanManager::createReleaseFence(sp<Fence>& nativeFence) { return INVALID_OPERATION; } - if (SyncFeatures::getInstance().useFenceSync()) { - ALOGE("VulkanManager::createReleaseFence: Vk backend doesn't support non-native fences"); - return INVALID_OPERATION; - } - - if (!SyncFeatures::getInstance().useNativeFenceSync()) { - return OK; - } - VkExportSemaphoreCreateInfo exportInfo; exportInfo.sType = VK_STRUCTURE_TYPE_EXPORT_SEMAPHORE_CREATE_INFO; exportInfo.pNext = nullptr; |