| 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 "vulkan_surface.h" |
| 6 | |
| 7 | #include "vulkan_application.h" |
| 8 | #include "vulkan_native_surface.h" |
| 9 | |
| 10 | namespace vulkan { |
| 11 | |
| 12 | VulkanSurface::VulkanSurface( |
| 13 | VulkanProcTable& p_vk, // NOLINT |
| 14 | VulkanApplication& application, // NOLINT |
| 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, instance: 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_ = VulkanHandle<VkSurfaceKHR>{ |
| 34 | surface, [this](VkSurfaceKHR surface) { |
| 35 | vk.DestroySurfaceKHR(application_.GetInstance(), surface, nullptr); |
| 36 | }}; |
| 37 | |
| 38 | valid_ = true; |
| 39 | } |
| 40 | |
| 41 | VulkanSurface::~VulkanSurface() = default; |
| 42 | |
| 43 | bool VulkanSurface::IsValid() const { |
| 44 | return valid_; |
| 45 | } |
| 46 | |
| 47 | const VulkanHandle<VkSurfaceKHR>& VulkanSurface::Handle() const { |
| 48 | return surface_; |
| 49 | } |
| 50 | |
| 51 | const VulkanNativeSurface& VulkanSurface::GetNativeSurface() const { |
| 52 | return *native_surface_; |
| 53 | } |
| 54 | |
| 55 | SkISize VulkanSurface::GetSize() const { |
| 56 | return valid_ ? native_surface_->GetSize() : SkISize::Make(w: 0, h: 0); |
| 57 | } |
| 58 | |
| 59 | } // namespace vulkan |
| 60 | |