1 //
2 // Copyright 2020 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 // WindowSurfaceVkHeadless.cpp:
7 // Implements the class methods for WindowSurfaceVkHeadless.
8 //
9
10 #include "WindowSurfaceVkHeadless.h"
11 #include "libANGLE/renderer/vulkan/vk_renderer.h"
12
13 namespace rx
14 {
15
WindowSurfaceVkHeadless(const egl::SurfaceState & surfaceState,EGLNativeWindowType window)16 WindowSurfaceVkHeadless::WindowSurfaceVkHeadless(const egl::SurfaceState &surfaceState,
17 EGLNativeWindowType window)
18 : WindowSurfaceVk(surfaceState, window)
19 {}
20
~WindowSurfaceVkHeadless()21 WindowSurfaceVkHeadless::~WindowSurfaceVkHeadless() {}
22
createSurfaceVk(vk::ErrorContext * context)23 angle::Result WindowSurfaceVkHeadless::createSurfaceVk(vk::ErrorContext *context)
24 {
25 vk::Renderer *renderer = context->getRenderer();
26 ASSERT(renderer != nullptr);
27 VkInstance instance = renderer->getInstance();
28
29 VkHeadlessSurfaceCreateInfoEXT createInfo = {};
30 createInfo.sType = VK_STRUCTURE_TYPE_HEADLESS_SURFACE_CREATE_INFO_EXT;
31
32 ANGLE_VK_TRY(context, vkCreateHeadlessSurfaceEXT(instance, &createInfo, nullptr, &mSurface));
33
34 return angle::Result::Continue;
35 }
36
getCurrentWindowSize(vk::ErrorContext * context,gl::Extents * extentsOut) const37 angle::Result WindowSurfaceVkHeadless::getCurrentWindowSize(vk::ErrorContext *context,
38 gl::Extents *extentsOut) const
39 {
40 // Spec: "For headless surfaces, currentExtent is the reserved value (0xFFFFFFFF, 0xFFFFFFFF).
41 // Whatever the application sets a swapchain's imageExtent to will be the size of the surface,
42 // after the first image is presented."
43 // For ANGLE, in headless mode, we share the same 'SimpleDisplayWindow' structure with front
44 // EGL window info to define the vulkan backend surface/image extents.
45 angle::vk::SimpleDisplayWindow *simpleWindow =
46 reinterpret_cast<angle::vk::SimpleDisplayWindow *>(mNativeWindowType);
47
48 *extentsOut = gl::Extents(simpleWindow->width, simpleWindow->height, 1);
49
50 return angle::Result::Continue;
51 }
52
53 } // namespace rx
54