1 // Copyright 2020 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "gpu/vulkan/vulkan_image.h"
6
7 #include "base/logging.h"
8 #include "gpu/vulkan/vulkan_device_queue.h"
9 #include "gpu/vulkan/vulkan_function_pointers.h"
10
11 namespace gpu {
12
InitializeFromGpuMemoryBufferHandle(VulkanDeviceQueue * device_queue,gfx::GpuMemoryBufferHandle gmb_handle,const gfx::Size & size,VkFormat format,VkImageUsageFlags usage,VkImageCreateFlags flags,VkImageTiling image_tiling)13 bool VulkanImage::InitializeFromGpuMemoryBufferHandle(
14 VulkanDeviceQueue* device_queue,
15 gfx::GpuMemoryBufferHandle gmb_handle,
16 const gfx::Size& size,
17 VkFormat format,
18 VkImageUsageFlags usage,
19 VkImageCreateFlags flags,
20 VkImageTiling image_tiling) {
21 NOTIMPLEMENTED();
22 return false;
23 }
24
GetMemoryHandle(VkExternalMemoryHandleTypeFlagBits handle_type)25 base::win::ScopedHandle VulkanImage::GetMemoryHandle(
26 VkExternalMemoryHandleTypeFlagBits handle_type) {
27 VkMemoryGetWin32HandleInfoKHR get_handle_info = {
28 .sType = VK_STRUCTURE_TYPE_MEMORY_GET_WIN32_HANDLE_INFO_KHR,
29 .memory = device_memory_,
30 .handleType = handle_type,
31 };
32
33 VkDevice device = device_queue_->GetVulkanDevice();
34
35 HANDLE handle = nullptr;
36 vkGetMemoryWin32HandleKHR(device, &get_handle_info, &handle);
37 if (handle == nullptr) {
38 DLOG(ERROR) << "Unable to extract file handle out of external VkImage";
39 return base::win::ScopedHandle();
40 }
41
42 return base::win::ScopedHandle(handle);
43 }
44
45 } // namespace gpu
46