Commit 38ba5853 authored by Antonio Caggiano's avatar Antonio Caggiano
Browse files

Vulkan: Wayland resize callback

Handle client resize requests and resize the swapchain accordingly after
next buffer swap.

Bug: angleproject:6902
Change-Id: I8bd6b0d4efac041606f15eccb6befa28594905b2
parent 1154cc46
......@@ -126,6 +126,11 @@ bool DisplayImpl::isX11() const
return false;
}
bool DisplayImpl::isWayland() const
{
return false;
}
bool DisplayImpl::supportsDmaBufFormat(EGLint format) const
{
UNREACHABLE();
......
......@@ -123,6 +123,7 @@ class DisplayImpl : public EGLImplFactory, public angle::Subject
virtual egl::Error forceGPUSwitch(EGLint gpuIDHigh, EGLint gpuIDLow);
virtual bool isX11() const;
virtual bool isWayland() const;
virtual bool supportsDmaBufFormat(EGLint format) const;
virtual egl::Error queryDmaBufFormats(EGLint max_formats, EGLint *formats, EGLint *num_formats);
......
......@@ -3350,9 +3350,9 @@ void RendererVk::initFeatures(DisplayVk *displayVk,
ANGLE_FEATURE_CONDITION(&mFeatures, bindEmptyForUnusedDescriptorSets,
IsAndroid() && isQualcommProprietary);
ANGLE_FEATURE_CONDITION(
&mFeatures, perFrameWindowSizeQuery,
IsAndroid() || isIntel || (IsWindows() && isAMD) || IsFuchsia() || isSamsung);
ANGLE_FEATURE_CONDITION(&mFeatures, perFrameWindowSizeQuery,
IsAndroid() || isIntel || (IsWindows() && isAMD) || IsFuchsia() ||
isSamsung || displayVk->isWayland());
ANGLE_FEATURE_CONDITION(&mFeatures, padBuffersToMaxVertexAttribStride, isAMD || isSamsung);
mMaxVertexAttribStride = std::min(static_cast<uint32_t>(gl::limits::kMaxVertexAttribStride),
......
......@@ -306,6 +306,9 @@ class WindowSurfaceVk : public SurfaceVk
const EGLint *rects,
EGLint n_rects,
const void *pNextChain);
// Called when a swapchain image whose acquisition was deferred must be acquired. This method
// will recreate the swapchain (if needed) and call the acquireNextSwapchainImage() method.
angle::Result doDeferredAcquireNextImage(const gl::Context *context, bool presentOutOfDate);
EGLNativeWindowType mNativeWindowType;
VkSurfaceKHR mSurface;
......@@ -334,9 +337,7 @@ class WindowSurfaceVk : public SurfaceVk
// This method is called when a swapchain image is presented. It schedules
// acquireNextSwapchainImage() to be called later.
void deferAcquireNextImage();
// Called when a swapchain image whose acquisition was deferred must be acquired. This method
// will recreate the swapchain (if needed) and call the acquireNextSwapchainImage() method.
angle::Result doDeferredAcquireNextImage(const gl::Context *context, bool presentOutOfDate);
angle::Result computePresentOutOfDate(vk::Context *context,
VkResult result,
bool *presentOutOfDate);
......
......@@ -199,6 +199,11 @@ const char *DisplayVkWayland::getWSIExtension() const
return VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME;
}
bool DisplayVkWayland::isWayland() const
{
return true;
}
bool IsVulkanWaylandDisplayAvailable()
{
wl_display *display = wl_display_connect(nullptr);
......
......@@ -35,6 +35,8 @@ class DisplayVkWayland : public DisplayVkLinux
const char *getWSIExtension() const override;
bool isWayland() const override;
bool supportsDmaBufFormat(EGLint format) const override;
egl::Error queryDmaBufFormats(EGLint maxFormats, EGLint *formats, EGLint *numFormats) override;
egl::Error queryDmaBufModifiers(EGLint format,
......
......@@ -9,6 +9,10 @@
#include "libANGLE/renderer/vulkan/linux/wayland/WindowSurfaceVkWayland.h"
#include "libANGLE/Context.h"
#include "libANGLE/Display.h"
#include "libANGLE/renderer/vulkan/ContextVk.h"
#include "libANGLE/renderer/vulkan/DisplayVk.h"
#include "libANGLE/renderer/vulkan/RendererVk.h"
#include <wayland-egl-backend.h>
......@@ -20,8 +24,15 @@ void WindowSurfaceVkWayland::ResizeCallback(wl_egl_window *eglWindow, void *payl
{
WindowSurfaceVkWayland *windowSurface = reinterpret_cast<WindowSurfaceVkWayland *>(payload);
windowSurface->mExtents.width = eglWindow->width;
windowSurface->mExtents.height = eglWindow->height;
if (windowSurface->mExtents.width != eglWindow->width ||
windowSurface->mExtents.height != eglWindow->height)
{
windowSurface->mExtents.width = eglWindow->width;
windowSurface->mExtents.height = eglWindow->height;
// Trigger swapchain resize
windowSurface->mResized = true;
}
}
WindowSurfaceVkWayland::WindowSurfaceVkWayland(const egl::SurfaceState &surfaceState,
......@@ -76,4 +87,21 @@ egl::Error WindowSurfaceVkWayland::getUserHeight(const egl::Display *display, EG
return egl::NoError();
}
angle::Result WindowSurfaceVkWayland::getAttachmentRenderTarget(
const gl::Context *context,
GLenum binding,
const gl::ImageIndex &imageIndex,
GLsizei samples,
FramebufferAttachmentRenderTarget **rtOut)
{
if (mResized)
{
// A wl_egl_window_resize() should take effect on the next operation which provokes a
// backbuffer to be pulled
ANGLE_TRY(doDeferredAcquireNextImage(context, true));
mResized = false;
}
return WindowSurfaceVk::getAttachmentRenderTarget(context, binding, imageIndex, samples, rtOut);
}
} // namespace rx
......@@ -21,6 +21,8 @@ namespace rx
class WindowSurfaceVkWayland : public WindowSurfaceVk
{
public:
// Requests of new sizes from client go through this callback, but actual resize will happen
// before the next operation which would provoke a backbuffer to be pulled.
static void ResizeCallback(wl_egl_window *window, void *payload);
WindowSurfaceVkWayland(const egl::SurfaceState &surfaceState,
......@@ -33,12 +35,19 @@ class WindowSurfaceVkWayland : public WindowSurfaceVk
egl::Error getUserWidth(const egl::Display *display, EGLint *value) const override;
egl::Error getUserHeight(const egl::Display *display, EGLint *value) const override;
angle::Result getAttachmentRenderTarget(const gl::Context *context,
GLenum binding,
const gl::ImageIndex &imageIndex,
GLsizei samples,
FramebufferAttachmentRenderTarget **rtOut) override;
private:
angle::Result createSurfaceVk(vk::Context *context, gl::Extents *extentsOut) override;
angle::Result getCurrentWindowSize(vk::Context *context, gl::Extents *extentsOut) override;
wl_display *mWaylandDisplay;
gl::Extents mExtents;
bool mResized;
};
} // namespace rx
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment