1 //
2 // Copyright 2024 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 // WindowSurfaceWgpuX11.cpp:
7 // Defines the class interface for WindowSurfaceWgpuX11, implementing WindowSurfaceWgpu.
8 //
9
10 #include "libANGLE/renderer/wgpu/linux/x11/WindowSurfaceWgpuX11.h"
11
12 #include "libANGLE/Display.h"
13 #include "libANGLE/renderer/wgpu/DisplayWgpu.h"
14 #include "libANGLE/renderer/wgpu/wgpu_utils.h"
15
16 #include <X11/Xlib.h>
17 #include <X11/Xresource.h>
18 #include <X11/Xutil.h>
19
20 namespace rx
21 {
22
WindowSurfaceWgpuX11(const egl::SurfaceState & surfaceState,EGLNativeWindowType window)23 WindowSurfaceWgpuX11::WindowSurfaceWgpuX11(const egl::SurfaceState &surfaceState,
24 EGLNativeWindowType window)
25 : WindowSurfaceWgpu(surfaceState, window)
26 {}
27
createWgpuSurface(const egl::Display * display,wgpu::Surface * outSurface)28 angle::Result WindowSurfaceWgpuX11::createWgpuSurface(const egl::Display *display,
29 wgpu::Surface *outSurface)
30 {
31 DisplayWgpu *displayWgpu = webgpu::GetImpl(display);
32
33 EGLNativeWindowType window = getNativeWindow();
34
35 wgpu::Instance instance = displayWgpu->getInstance();
36
37 wgpu::SurfaceDescriptorFromXlibWindow x11Desc;
38 x11Desc.display = reinterpret_cast<Display *>(display->getNativeDisplayId());
39 x11Desc.window = window;
40
41 wgpu::SurfaceDescriptor surfaceDesc;
42 surfaceDesc.nextInChain = &x11Desc;
43
44 wgpu::Surface surface = instance.CreateSurface(&surfaceDesc);
45 *outSurface = surface;
46
47 return angle::Result::Continue;
48 }
49
getCurrentWindowSize(const egl::Display * display,gl::Extents * outSize)50 angle::Result WindowSurfaceWgpuX11::getCurrentWindowSize(const egl::Display *display,
51 gl::Extents *outSize)
52 {
53 Window root;
54 int x, y;
55 unsigned int width, height, border, depth;
56 if (XGetGeometry(reinterpret_cast<Display *>(display->getNativeDisplayId()), getNativeWindow(),
57 &root, &x, &y, &width, &height, &border, &depth) == 0)
58 {
59 ERR() << "Failed to get X11 window geometry.";
60 return angle::Result::Stop;
61 }
62
63 *outSize = gl::Extents(width, height, 1);
64 return angle::Result::Continue;
65 }
66
CreateWgpuWindowSurface(const egl::SurfaceState & surfaceState,EGLNativeWindowType window)67 WindowSurfaceWgpu *CreateWgpuWindowSurface(const egl::SurfaceState &surfaceState,
68 EGLNativeWindowType window)
69 {
70 return new WindowSurfaceWgpuX11(surfaceState, window);
71 }
72 } // namespace rx
73