• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2022 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "DisplaySurfaceVk.h"
16 
17 #include "host-common/GfxstreamFatalError.h"
18 #include "host-common/logging.h"
19 #include "vk_util.h"
20 
21 namespace gfxstream {
22 namespace vk {
23 
24 using emugl::ABORT_REASON_OTHER;
25 using emugl::FatalError;
26 
create(const VulkanDispatch & vk,VkInstance instance,FBNativeWindowType window)27 std::unique_ptr<DisplaySurfaceVk> DisplaySurfaceVk::create(const VulkanDispatch& vk,
28                                                            VkInstance instance,
29                                                            FBNativeWindowType window) {
30     VkSurfaceKHR surface = VK_NULL_HANDLE;
31 #ifdef _WIN32
32     const VkWin32SurfaceCreateInfoKHR surfaceCi = {
33         .sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR,
34         .pNext = nullptr,
35         .flags = 0,
36         .hinstance = GetModuleHandle(nullptr),
37         .hwnd = window,
38     };
39     VK_CHECK(vk.vkCreateWin32SurfaceKHR(instance, &surfaceCi, nullptr, &surface));
40 #else
41     GFXSTREAM_ABORT(FatalError(ABORT_REASON_OTHER))
42         << "Unimplemented.";
43 #endif
44     if (surface == VK_NULL_HANDLE) {
45         GFXSTREAM_ABORT(FatalError(ABORT_REASON_OTHER))
46             << "No VkSurfaceKHR created?";
47     }
48 
49     return std::unique_ptr<DisplaySurfaceVk>(new DisplaySurfaceVk(vk, instance, surface));
50 }
51 
DisplaySurfaceVk(const VulkanDispatch & vk,VkInstance instance,VkSurfaceKHR surface)52 DisplaySurfaceVk::DisplaySurfaceVk(const VulkanDispatch& vk, VkInstance instance,
53                                    VkSurfaceKHR surface)
54     : mVk(vk), mInstance(instance), mSurface(surface) {}
55 
~DisplaySurfaceVk()56 DisplaySurfaceVk::~DisplaySurfaceVk() {
57     if (mSurface != VK_NULL_HANDLE) {
58         mVk.vkDestroySurfaceKHR(mInstance, mSurface, nullptr);
59     }
60 }
61 
62 }  // namespace vk
63 }  // namespace gfxstream
64