• 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 #include "flutter/vulkan/vulkan_native_surface.h"
9 
10 namespace vulkan {
11 
VulkanSurface(VulkanProcTable & p_vk,VulkanApplication & application,std::unique_ptr<VulkanNativeSurface> native_surface)12 VulkanSurface::VulkanSurface(
13     VulkanProcTable& p_vk,
14     VulkanApplication& application,
15     std::unique_ptr<VulkanNativeSurface> native_surface)
16     : vk(p_vk),
17       application_(application),
18       native_surface_(std::move(native_surface)),
19       valid_(false) {
20   if (native_surface_ == nullptr || !native_surface_->IsValid()) {
21     FML_DLOG(INFO) << "Native surface was invalid.";
22     return;
23   }
24 
25   VkSurfaceKHR surface =
26       native_surface_->CreateSurfaceHandle(vk, application.GetInstance());
27 
28   if (surface == VK_NULL_HANDLE) {
29     FML_DLOG(INFO) << "Could not create the surface handle.";
30     return;
31   }
32 
33   surface_ = {surface, [this](VkSurfaceKHR surface) {
34                 vk.DestroySurfaceKHR(application_.GetInstance(), surface,
35                                      nullptr);
36               }};
37 
38   valid_ = true;
39 }
40 
41 VulkanSurface::~VulkanSurface() = default;
42 
IsValid() const43 bool VulkanSurface::IsValid() const {
44   return valid_;
45 }
46 
Handle() const47 const VulkanHandle<VkSurfaceKHR>& VulkanSurface::Handle() const {
48   return surface_;
49 }
50 
GetNativeSurface() const51 const VulkanNativeSurface& VulkanSurface::GetNativeSurface() const {
52   return *native_surface_;
53 }
54 
GetSize() const55 SkISize VulkanSurface::GetSize() const {
56   return valid_ ? native_surface_->GetSize() : SkISize::Make(0, 0);
57 }
58 
59 }  // namespace vulkan
60