Flutter Engine
vulkan_native_surface_android.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter 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 
6 
7 #include <android/native_window.h>
8 
9 #include "third_party/skia/include/gpu/vk/GrVkBackendContext.h"
10 
11 namespace vulkan {
12 
14  ANativeWindow* native_window)
15  : native_window_(native_window) {
16  if (native_window_ == nullptr) {
17  return;
18  }
19  ANativeWindow_acquire(native_window_);
20 }
21 
23  if (native_window_ == nullptr) {
24  return;
25  }
26  ANativeWindow_release(native_window_);
27 }
28 
30  return VK_KHR_ANDROID_SURFACE_EXTENSION_NAME;
31 }
32 
34  return kKHR_android_surface_GrVkExtensionFlag;
35 }
36 
38  VulkanProcTable& vk,
39  const VulkanHandle<VkInstance>& instance) const {
40  if (!vk.IsValid() || !instance) {
41  return VK_NULL_HANDLE;
42  }
43 
44  const VkAndroidSurfaceCreateInfoKHR create_info = {
45  .sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR,
46  .pNext = nullptr,
47  .flags = 0,
48  .window = native_window_,
49  };
50 
51  VkSurfaceKHR surface = VK_NULL_HANDLE;
52 
53  if (VK_CALL_LOG_ERROR(vk.CreateAndroidSurfaceKHR(
54  instance, &create_info, nullptr, &surface)) != VK_SUCCESS) {
55  return VK_NULL_HANDLE;
56  }
57 
58  return surface;
59 }
60 
62  return native_window_ != nullptr;
63 }
64 
66  return native_window_ == nullptr
67  ? SkISize::Make(0, 0)
68  : SkISize::Make(ANativeWindow_getWidth(native_window_),
69  ANativeWindow_getHeight(native_window_));
70 }
71 
72 } // namespace vulkan
struct ANativeWindow ANativeWindow
VkSurfaceKHR CreateSurfaceHandle(VulkanProcTable &vk, const VulkanHandle< VkInstance > &instance) const override
VulkanNativeSurfaceAndroid(ANativeWindow *native_window)
const char * GetExtensionName() const override
#define VK_CALL_LOG_ERROR(expression)