blob: 4228b3eb83ea8cb0bc1ef7634369600851614287 [file] [log] [blame]
Jason Macnak32281f72022-10-12 13:00:36 -07001// 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
Jason Macnaked0c9e62023-03-30 15:58:24 -070021namespace gfxstream {
22namespace vk {
23
Jason Macnak32281f72022-10-12 13:00:36 -070024using emugl::ABORT_REASON_OTHER;
25using emugl::FatalError;
26
Jason Macnaked0c9e62023-03-30 15:58:24 -070027std::unique_ptr<DisplaySurfaceVk> DisplaySurfaceVk::create(const VulkanDispatch& vk,
28 VkInstance instance,
29 FBNativeWindowType window) {
Jason Macnak32281f72022-10-12 13:00:36 -070030 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
Jason Macnaked0c9e62023-03-30 15:58:24 -070052DisplaySurfaceVk::DisplaySurfaceVk(const VulkanDispatch& vk, VkInstance instance,
Jason Macnak32281f72022-10-12 13:00:36 -070053 VkSurfaceKHR surface)
Jason Macnaked0c9e62023-03-30 15:58:24 -070054 : mVk(vk), mInstance(instance), mSurface(surface) {}
Jason Macnak32281f72022-10-12 13:00:36 -070055
56DisplaySurfaceVk::~DisplaySurfaceVk() {
57 if (mSurface != VK_NULL_HANDLE) {
58 mVk.vkDestroySurfaceKHR(mInstance, mSurface, nullptr);
59 }
60}
Jason Macnaked0c9e62023-03-30 15:58:24 -070061
62} // namespace vk
63} // namespace gfxstream