Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 305e13a2 authored by Stan Iliev's avatar Stan Iliev
Browse files

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
parent 743ad8a7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ Frame SkiaVulkanPipeline::getFrame() {
    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);
+19 −2
Original line number Diff line number Diff line
@@ -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 @@ 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);

@@ -717,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) {
@@ -814,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));
+6 −2
Original line number Diff line number Diff line
@@ -38,7 +38,8 @@ class RenderThread;

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 @@ private:
    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 @@ public:
    // 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);