• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // DisplayVkWayland.cpp:
7 //    Implements the class methods for DisplayVkWayland.
8 //
9 
10 #include "libANGLE/renderer/vulkan/linux/wayland/DisplayVkWayland.h"
11 
12 #include <wayland-client.h>
13 
14 #include "common/system_utils.h"
15 #include "libANGLE/Display.h"
16 #include "libANGLE/renderer/vulkan/linux/wayland/WindowSurfaceVkWayland.h"
17 #include "libANGLE/renderer/vulkan/vk_caps_utils.h"
18 
19 namespace rx
20 {
21 
DisplayVkWayland(const egl::DisplayState & state)22 DisplayVkWayland::DisplayVkWayland(const egl::DisplayState &state)
23     : DisplayVkLinux(state), mWaylandDisplay(nullptr)
24 {}
25 
initialize(egl::Display * display)26 egl::Error DisplayVkWayland::initialize(egl::Display *display)
27 {
28     mWaylandDisplay = reinterpret_cast<wl_display *>(display->getNativeDisplayId());
29     if (!mWaylandDisplay)
30     {
31         ERR() << "Failed to retrieve wayland display";
32         return egl::EglNotInitialized();
33     }
34 
35     return DisplayVk::initialize(display);
36 }
37 
terminate()38 void DisplayVkWayland::terminate()
39 {
40     mWaylandDisplay = nullptr;
41     DisplayVk::terminate();
42 }
43 
isValidNativeWindow(EGLNativeWindowType window) const44 bool DisplayVkWayland::isValidNativeWindow(EGLNativeWindowType window) const
45 {
46     // Wayland display Errors are fatal.
47     // If this function returns non-zero, the display is not valid anymore.
48     int error = wl_display_get_error(mWaylandDisplay);
49     if (error)
50     {
51         WARN() << "Wayland window is not valid: " << error << " " << strerror(error);
52     }
53     return error == 0;
54 }
55 
createWindowSurfaceVk(const egl::SurfaceState & state,EGLNativeWindowType window)56 SurfaceImpl *DisplayVkWayland::createWindowSurfaceVk(const egl::SurfaceState &state,
57                                                      EGLNativeWindowType window)
58 {
59     return new WindowSurfaceVkWayland(state, window, mWaylandDisplay);
60 }
61 
generateConfigs()62 egl::ConfigSet DisplayVkWayland::generateConfigs()
63 {
64     const std::array<GLenum, 1> kColorFormats = {GL_BGRA8_EXT};
65 
66     std::vector<GLenum> depthStencilFormats(
67         egl_vk::kConfigDepthStencilFormats,
68         egl_vk::kConfigDepthStencilFormats + ArraySize(egl_vk::kConfigDepthStencilFormats));
69 
70     if (getCaps().stencil8)
71     {
72         depthStencilFormats.push_back(GL_STENCIL_INDEX8);
73     }
74     return egl_vk::GenerateConfigs(kColorFormats.data(), kColorFormats.size(),
75                                    depthStencilFormats.data(), depthStencilFormats.size(), this);
76 }
77 
checkConfigSupport(egl::Config * config)78 void DisplayVkWayland::checkConfigSupport(egl::Config *config)
79 {
80     // In wayland there is no native visual ID or type
81 }
82 
getWSIExtension() const83 const char *DisplayVkWayland::getWSIExtension() const
84 {
85     return VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME;
86 }
87 
IsVulkanWaylandDisplayAvailable()88 bool IsVulkanWaylandDisplayAvailable()
89 {
90     wl_display *display = wl_display_connect(nullptr);
91     if (!display)
92     {
93         return false;
94     }
95     wl_display_disconnect(display);
96     return true;
97 }
98 
CreateVulkanWaylandDisplay(const egl::DisplayState & state)99 DisplayImpl *CreateVulkanWaylandDisplay(const egl::DisplayState &state)
100 {
101     return new DisplayVkWayland(state);
102 }
103 }  // namespace rx
104