Handle ANativeWindow resize with Vulkan swapchain
Recreate VulkanSurface, if ANativeWindow has been resized. This
new code is hit when wallpaper is resized from 64x64 to real size.
Bug: 119111018
Test: Wallpaper is shawn correctly with Vulkan rendering
Change-Id: I5e43310e5ee8597a7f326d51b1773e2cf68b603a
diff --git a/libs/hwui/pipeline/skia/SkiaVulkanPipeline.cpp b/libs/hwui/pipeline/skia/SkiaVulkanPipeline.cpp
index 7fc41ac..a494e49 100644
--- a/libs/hwui/pipeline/skia/SkiaVulkanPipeline.cpp
+++ b/libs/hwui/pipeline/skia/SkiaVulkanPipeline.cpp
@@ -51,7 +51,7 @@
LOG_ALWAYS_FATAL_IF(mVkSurface == nullptr,
"drawRenderNode called on a context with no surface!");
- SkSurface* backBuffer = mVkManager.getBackbufferSurface(mVkSurface);
+ SkSurface* backBuffer = mVkManager.getBackbufferSurface(&mVkSurface);
if (backBuffer == nullptr) {
SkDebugf("failed to get backbuffer");
return Frame(-1, -1, 0);
diff --git a/libs/hwui/renderthread/VulkanManager.cpp b/libs/hwui/renderthread/VulkanManager.cpp
index f96b1f8..d84ec85 100644
--- a/libs/hwui/renderthread/VulkanManager.cpp
+++ b/libs/hwui/renderthread/VulkanManager.cpp
@@ -16,6 +16,8 @@
#include "VulkanManager.h"
+#include <gui/Surface.h>
+
#include "Properties.h"
#include "RenderThread.h"
#include "renderstate/RenderState.h"
@@ -452,7 +454,20 @@
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);
@@ -717,6 +732,8 @@
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) {
@@ -814,7 +831,7 @@
return nullptr;
}
- VulkanSurface* surface = new VulkanSurface(colorMode);
+ VulkanSurface* surface = new VulkanSurface(colorMode, window);
VkAndroidSurfaceCreateInfoKHR surfaceCreateInfo;
memset(&surfaceCreateInfo, 0, sizeof(VkAndroidSurfaceCreateInfoKHR));
diff --git a/libs/hwui/renderthread/VulkanManager.h b/libs/hwui/renderthread/VulkanManager.h
index 6702649..8594a1b 100644
--- a/libs/hwui/renderthread/VulkanManager.h
+++ b/libs/hwui/renderthread/VulkanManager.h
@@ -38,7 +38,8 @@
class VulkanSurface {
public:
- VulkanSurface(ColorMode colorMode) : mColorMode(colorMode) {}
+ VulkanSurface(ColorMode colorMode, ANativeWindow* window)
+ : mColorMode(colorMode), mNativeWindow(window) {}
sk_sp<SkSurface> getBackBufferSurface() { return mBackbuffer; }
@@ -75,6 +76,9 @@
ImageInfo* mImageInfos;
uint16_t mCurrentTime = 0;
ColorMode mColorMode;
+ ANativeWindow* mNativeWindow;
+ int mWindowWidth = 0;
+ int mWindowHeight = 0;
};
// This class contains the shared global Vulkan objects, such as VkInstance, VkDevice and VkQueue,
@@ -109,7 +113,7 @@
// Returns an SkSurface which wraps the next image returned from vkAcquireNextImageKHR. It also
// will transition the VkImage from a present layout to color attachment so that it can be used
// by the client for drawing.
- SkSurface* getBackbufferSurface(VulkanSurface* surface);
+ SkSurface* getBackbufferSurface(VulkanSurface** surface);
// Presents the current VkImage.
void swapBuffers(VulkanSurface* surface);