1 //
2 // Copyright 2019 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 // WindowSurfaceVkGGP.cpp:
7 // Implements the class methods for WindowSurfaceVkGGP.
8 //
9
10 #include "libANGLE/renderer/vulkan/ggp/WindowSurfaceVkGGP.h"
11
12 #include "libANGLE/Context.h"
13 #include "libANGLE/Display.h"
14 #include "libANGLE/Surface.h"
15 #include "libANGLE/renderer/vulkan/DisplayVk.h"
16 #include "libANGLE/renderer/vulkan/vk_renderer.h"
17
18 namespace rx
19 {
20 namespace
21 {
22 constexpr EGLAttrib kDefaultStreamDescriptor = static_cast<EGLAttrib>(kGgpPrimaryStreamDescriptor);
23 } // namespace
24
WindowSurfaceVkGGP(const egl::SurfaceState & surfaceState,EGLNativeWindowType window)25 WindowSurfaceVkGGP::WindowSurfaceVkGGP(const egl::SurfaceState &surfaceState,
26 EGLNativeWindowType window)
27 : WindowSurfaceVk(surfaceState, window)
28 {}
29
createSurfaceVk(vk::Context * context,gl::Extents * extentsOut)30 angle::Result WindowSurfaceVkGGP::createSurfaceVk(vk::Context *context, gl::Extents *extentsOut)
31 {
32 vk::Renderer *renderer = context->getRenderer();
33
34 // Get the stream descriptor if specified. Default is kGgpPrimaryStreamDescriptor.
35 EGLAttrib streamDescriptor =
36 mState.attributes.get(EGL_GGP_STREAM_DESCRIPTOR_ANGLE, kDefaultStreamDescriptor);
37
38 VkStreamDescriptorSurfaceCreateInfoGGP createInfo = {};
39 createInfo.sType = VK_STRUCTURE_TYPE_STREAM_DESCRIPTOR_SURFACE_CREATE_INFO_GGP;
40 createInfo.streamDescriptor = static_cast<GgpStreamDescriptor>(streamDescriptor);
41
42 ANGLE_VK_TRY(context, vkCreateStreamDescriptorSurfaceGGP(renderer->getInstance(), &createInfo,
43 nullptr, &mSurface));
44
45 return getCurrentWindowSize(context, extentsOut);
46 }
47
getCurrentWindowSize(vk::Context * context,gl::Extents * extentsOut)48 angle::Result WindowSurfaceVkGGP::getCurrentWindowSize(vk::Context *context,
49 gl::Extents *extentsOut)
50 {
51 vk::Renderer *renderer = context->getRenderer();
52 const VkPhysicalDevice &physicalDevice = renderer->getPhysicalDevice();
53
54 ANGLE_VK_TRY(context, vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, mSurface,
55 &mSurfaceCaps));
56
57 *extentsOut =
58 gl::Extents(mSurfaceCaps.currentExtent.width, mSurfaceCaps.currentExtent.height, 1);
59 return angle::Result::Continue;
60 }
61
swapWithFrameToken(const gl::Context * context,EGLFrameTokenANGLE frameToken)62 egl::Error WindowSurfaceVkGGP::swapWithFrameToken(const gl::Context *context,
63 EGLFrameTokenANGLE frameToken)
64 {
65 VkPresentFrameTokenGGP frameTokenData = {};
66 frameTokenData.sType = VK_STRUCTURE_TYPE_PRESENT_FRAME_TOKEN_GGP;
67 frameTokenData.frameToken = static_cast<GgpFrameToken>(frameToken);
68
69 angle::Result result = swapImpl(context, nullptr, 0, &frameTokenData);
70 return angle::ToEGL(result, EGL_BAD_SURFACE);
71 }
72 } // namespace rx
73