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 // WindowSurfaceVkSimple.cpp:
7 // Implements the class methods for WindowSurfaceVkSimple.
8 //
9
10 #include "WindowSurfaceVkSimple.h"
11 #include "libANGLE/renderer/vulkan/RendererVk.h"
12
13 namespace rx
14 {
15
WindowSurfaceVkSimple(const egl::SurfaceState & surfaceState,EGLNativeWindowType window)16 WindowSurfaceVkSimple::WindowSurfaceVkSimple(const egl::SurfaceState &surfaceState,
17 EGLNativeWindowType window)
18 : WindowSurfaceVk(surfaceState, window)
19 {}
20
~WindowSurfaceVkSimple()21 WindowSurfaceVkSimple::~WindowSurfaceVkSimple() {}
22
createSurfaceVk(vk::Context * context,gl::Extents * extentsOut)23 angle::Result WindowSurfaceVkSimple::createSurfaceVk(vk::Context *context, gl::Extents *extentsOut)
24 {
25 RendererVk *renderer = context->getRenderer();
26 ASSERT(renderer != nullptr);
27 VkInstance instance = renderer->getInstance();
28 VkPhysicalDevice physicalDevice = renderer->getPhysicalDevice();
29
30 // Query if there is a valid display
31 uint32_t count = 1;
32 ANGLE_VK_TRY(context, vkGetPhysicalDeviceDisplayPropertiesKHR(physicalDevice, &count, nullptr));
33
34 // Get display properties
35 VkDisplayPropertiesKHR prop = {};
36 count = 1;
37 ANGLE_VK_TRY(context, vkGetPhysicalDeviceDisplayPropertiesKHR(physicalDevice, &count, &prop));
38
39 // we should have a valid display now
40 ASSERT(prop.display != VK_NULL_HANDLE);
41 ANGLE_VK_TRY(context,
42 vkGetDisplayModePropertiesKHR(physicalDevice, prop.display, &count, nullptr));
43
44 ASSERT(count != 0);
45 std::vector<VkDisplayModePropertiesKHR> modeProperties(count);
46 ANGLE_VK_TRY(context, vkGetDisplayModePropertiesKHR(physicalDevice, prop.display, &count,
47 modeProperties.data()));
48
49 angle::vk::SimpleDisplayWindow *displayWindow =
50 reinterpret_cast<angle::vk::SimpleDisplayWindow *>(mNativeWindowType);
51 VkDisplaySurfaceCreateInfoKHR info = {};
52 info.sType = VK_STRUCTURE_TYPE_DISPLAY_SURFACE_CREATE_INFO_KHR;
53 info.flags = 0;
54 info.displayMode = modeProperties[0].displayMode;
55 info.planeIndex = 0;
56 info.planeStackIndex = 0;
57 info.transform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
58 info.globalAlpha = 1.0f;
59 info.alphaMode = VK_DISPLAY_PLANE_ALPHA_GLOBAL_BIT_KHR;
60 info.imageExtent.width = displayWindow->width;
61 info.imageExtent.height = displayWindow->height;
62
63 ANGLE_VK_TRY(context, vkCreateDisplayPlaneSurfaceKHR(instance, &info, nullptr, &mSurface));
64
65 return getCurrentWindowSize(context, extentsOut);
66 }
67
getCurrentWindowSize(vk::Context * context,gl::Extents * extentsOut)68 angle::Result WindowSurfaceVkSimple::getCurrentWindowSize(vk::Context *context,
69 gl::Extents *extentsOut)
70 {
71 RendererVk *renderer = context->getRenderer();
72 const VkPhysicalDevice &physicalDevice = renderer->getPhysicalDevice();
73
74 ANGLE_VK_TRY(context, vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, mSurface,
75 &mSurfaceCaps));
76
77 *extentsOut =
78 gl::Extents(mSurfaceCaps.currentExtent.width, mSurfaceCaps.currentExtent.height, 1);
79 return angle::Result::Continue;
80 }
81
82 } // namespace rx
83