1 //
2 // Copyright 2016 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 // WindowSurfaceVkXcb.cpp:
7 //    Implements the class methods for WindowSurfaceVkXcb.
8 //
9 
10 #include "libANGLE/renderer/vulkan/xcb/WindowSurfaceVkXcb.h"
11 
12 #include "libANGLE/renderer/vulkan/RendererVk.h"
13 
14 namespace rx
15 {
16 
WindowSurfaceVkXcb(const egl::SurfaceState & surfaceState,EGLNativeWindowType window,xcb_connection_t * conn)17 WindowSurfaceVkXcb::WindowSurfaceVkXcb(const egl::SurfaceState &surfaceState,
18                                        EGLNativeWindowType window,
19                                        xcb_connection_t *conn)
20     : WindowSurfaceVk(surfaceState, window), mXcbConnection(conn)
21 {}
22 
createSurfaceVk(vk::Context * context,gl::Extents * extentsOut)23 angle::Result WindowSurfaceVkXcb::createSurfaceVk(vk::Context *context, gl::Extents *extentsOut)
24 {
25     VkXcbSurfaceCreateInfoKHR createInfo = {};
26 
27     createInfo.sType      = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
28     createInfo.flags      = 0;
29     createInfo.connection = mXcbConnection;
30     createInfo.window     = static_cast<xcb_window_t>(mNativeWindowType);
31     ANGLE_VK_TRY(context, vkCreateXcbSurfaceKHR(context->getRenderer()->getInstance(), &createInfo,
32                                                 nullptr, &mSurface));
33 
34     return getCurrentWindowSize(context, extentsOut);
35 }
36 
getCurrentWindowSize(vk::Context * context,gl::Extents * extentsOut)37 angle::Result WindowSurfaceVkXcb::getCurrentWindowSize(vk::Context *context,
38                                                        gl::Extents *extentsOut)
39 {
40     xcb_get_geometry_cookie_t cookie =
41         xcb_get_geometry(mXcbConnection, static_cast<xcb_drawable_t>(mNativeWindowType));
42     xcb_generic_error_t *error      = nullptr;
43     xcb_get_geometry_reply_t *reply = xcb_get_geometry_reply(mXcbConnection, cookie, &error);
44     if (error)
45     {
46         free(error);
47         ANGLE_VK_CHECK(context, false, VK_ERROR_INITIALIZATION_FAILED);
48     }
49     ASSERT(reply);
50     *extentsOut = gl::Extents(reply->width, reply->height, 1);
51     free(reply);
52     return angle::Result::Continue;
53 }
54 
55 }  // namespace rx
56