• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
5 #include "flutter/vulkan/vulkan_surface.h"
6 
7 #include "flutter/vulkan/vulkan_application.h"
8 #ifdef RS_ENABLE_VK
9 #include "flutter/vulkan/vulkan_hilog.h"
10 #endif
11 #include "flutter/vulkan/vulkan_native_surface.h"
12 
13 namespace vulkan {
14 
VulkanSurface(VulkanProcTable & p_vk,VulkanApplication & application,std::unique_ptr<VulkanNativeSurface> native_surface)15 VulkanSurface::VulkanSurface(
16     VulkanProcTable& p_vk,
17     VulkanApplication& application,
18     std::unique_ptr<VulkanNativeSurface> native_surface)
19     : vk(p_vk),
20       application_(application),
21       native_surface_(std::move(native_surface)),
22       valid_(false) {
23   if (native_surface_ == nullptr || !native_surface_->IsValid()) {
24 #ifdef RS_ENABLE_VK
25     LOGE("Native surface was invalid.");
26 #else
27     FML_DLOG(INFO) << "Native surface was invalid.";
28 #endif
29     return;
30   }
31 
32   VkSurfaceKHR surface =
33       native_surface_->CreateSurfaceHandle(vk, application.GetInstance());
34 
35   if (surface == VK_NULL_HANDLE) {
36 #ifdef RS_ENABLE_VK
37     LOGE("Could not create the surface handle.");
38 #else
39     FML_DLOG(INFO) << "Could not create the surface handle.";
40 #endif
41     return;
42   }
43 
44   surface_ = {surface, [this](VkSurfaceKHR surface) {
45                 vk.DestroySurfaceKHR(application_.GetInstance(), surface,
46                                      nullptr);
47               }};
48 
49   valid_ = true;
50 }
51 
52 VulkanSurface::~VulkanSurface() = default;
53 
IsValid() const54 bool VulkanSurface::IsValid() const {
55   return valid_;
56 }
57 
Handle() const58 const VulkanHandle<VkSurfaceKHR>& VulkanSurface::Handle() const {
59   return surface_;
60 }
61 
GetNativeSurface() const62 const VulkanNativeSurface& VulkanSurface::GetNativeSurface() const {
63   return *native_surface_;
64 }
65 
GetSize() const66 SkISize VulkanSurface::GetSize() const {
67   return valid_ ? native_surface_->GetSize() : SkISize::Make(0, 0);
68 }
69 
70 }  // namespace vulkan
71