1 //
2 // Copyright 2021-2022 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // WindowSurfaceVkWayland.cpp:
7 // Implements the class methods for WindowSurfaceVkWayland.
8 //
9
10 #include "libANGLE/renderer/vulkan/linux/wayland/WindowSurfaceVkWayland.h"
11
12 #include "libANGLE/renderer/vulkan/vk_renderer.h"
13
14 #include <wayland-egl-backend.h>
15
16 namespace rx
17 {
18
ResizeCallback(wl_egl_window * eglWindow,void * payload)19 void WindowSurfaceVkWayland::ResizeCallback(wl_egl_window *eglWindow, void *payload)
20 {
21 WindowSurfaceVkWayland *windowSurface = reinterpret_cast<WindowSurfaceVkWayland *>(payload);
22
23 windowSurface->mExtents.width = eglWindow->width;
24 windowSurface->mExtents.height = eglWindow->height;
25 }
26
WindowSurfaceVkWayland(const egl::SurfaceState & surfaceState,EGLNativeWindowType window,wl_display * display)27 WindowSurfaceVkWayland::WindowSurfaceVkWayland(const egl::SurfaceState &surfaceState,
28 EGLNativeWindowType window,
29 wl_display *display)
30 : WindowSurfaceVk(surfaceState, window), mWaylandDisplay(display)
31 {
32 wl_egl_window *eglWindow = reinterpret_cast<wl_egl_window *>(window);
33 eglWindow->resize_callback = WindowSurfaceVkWayland::ResizeCallback;
34 eglWindow->driver_private = this;
35
36 mExtents = gl::Extents(eglWindow->width, eglWindow->height, 1);
37 }
38
createSurfaceVk(vk::ErrorContext * context)39 angle::Result WindowSurfaceVkWayland::createSurfaceVk(vk::ErrorContext *context)
40 {
41 ANGLE_VK_CHECK(context,
42 vkGetPhysicalDeviceWaylandPresentationSupportKHR(
43 context->getRenderer()->getPhysicalDevice(),
44 context->getRenderer()->getQueueFamilyIndex(), mWaylandDisplay),
45 VK_ERROR_INITIALIZATION_FAILED);
46
47 wl_egl_window *eglWindow = reinterpret_cast<wl_egl_window *>(mNativeWindowType);
48
49 VkWaylandSurfaceCreateInfoKHR createInfo = {};
50
51 createInfo.sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR;
52 createInfo.flags = 0;
53 createInfo.display = mWaylandDisplay;
54 createInfo.surface = eglWindow->surface;
55 ANGLE_VK_TRY(context, vkCreateWaylandSurfaceKHR(context->getRenderer()->getInstance(),
56 &createInfo, nullptr, &mSurface));
57
58 return angle::Result::Continue;
59 }
60
getCurrentWindowSize(vk::ErrorContext * context,gl::Extents * extentsOut) const61 angle::Result WindowSurfaceVkWayland::getCurrentWindowSize(vk::ErrorContext *context,
62 gl::Extents *extentsOut) const
63 {
64 *extentsOut = mExtents;
65 return angle::Result::Continue;
66 }
67
68 } // namespace rx
69