1 //
2 // Copyright 2018 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 // WindowSurfaceVkAndroid.cpp:
7 // Implements the class methods for WindowSurfaceVkAndroid.
8 //
9
10 #include "libANGLE/renderer/vulkan/android/WindowSurfaceVkAndroid.h"
11
12 #include <android/native_window.h>
13
14 #include "libANGLE/renderer/vulkan/RendererVk.h"
15
16 namespace rx
17 {
18
WindowSurfaceVkAndroid(const egl::SurfaceState & surfaceState,EGLNativeWindowType window)19 WindowSurfaceVkAndroid::WindowSurfaceVkAndroid(const egl::SurfaceState &surfaceState,
20 EGLNativeWindowType window)
21 : WindowSurfaceVk(surfaceState, window)
22 {}
23
createSurfaceVk(vk::Context * context,gl::Extents * extentsOut)24 angle::Result WindowSurfaceVkAndroid::createSurfaceVk(vk::Context *context, gl::Extents *extentsOut)
25 {
26 VkAndroidSurfaceCreateInfoKHR createInfo = {};
27
28 createInfo.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR;
29 createInfo.flags = 0;
30 createInfo.window = mNativeWindowType;
31 ANGLE_VK_TRY(context, vkCreateAndroidSurfaceKHR(context->getRenderer()->getInstance(),
32 &createInfo, nullptr, &mSurface));
33
34 return getCurrentWindowSize(context, extentsOut);
35 }
36
getCurrentWindowSize(vk::Context * context,gl::Extents * extentsOut)37 angle::Result WindowSurfaceVkAndroid::getCurrentWindowSize(vk::Context *context,
38 gl::Extents *extentsOut)
39 {
40 RendererVk *renderer = context->getRenderer();
41 const VkPhysicalDevice &physicalDevice = renderer->getPhysicalDevice();
42 VkSurfaceCapabilitiesKHR surfaceCaps;
43 ANGLE_VK_TRY(context,
44 vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, mSurface, &surfaceCaps));
45 *extentsOut = gl::Extents(surfaceCaps.currentExtent.width, surfaceCaps.currentExtent.height, 1);
46 return angle::Result::Continue;
47 }
48
49 } // namespace rx
50