forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vulkan_surface.cc
59 lines (45 loc) · 1.52 KB
/
vulkan_surface.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "vulkan_surface.h"
#include "vulkan_application.h"
#include "vulkan_native_surface.h"
namespace vulkan {
VulkanSurface::VulkanSurface(
VulkanProcTable& p_vk, // NOLINT
VulkanApplication& application, // NOLINT
std::unique_ptr<VulkanNativeSurface> native_surface)
: vk(p_vk),
application_(application),
native_surface_(std::move(native_surface)),
valid_(false) {
if (native_surface_ == nullptr || !native_surface_->IsValid()) {
FML_DLOG(INFO) << "Native surface was invalid.";
return;
}
VkSurfaceKHR surface =
native_surface_->CreateSurfaceHandle(vk, application.GetInstance());
if (surface == VK_NULL_HANDLE) {
FML_DLOG(INFO) << "Could not create the surface handle.";
return;
}
surface_ = VulkanHandle<VkSurfaceKHR>{
surface, [this](VkSurfaceKHR surface) {
vk.DestroySurfaceKHR(application_.GetInstance(), surface, nullptr);
}};
valid_ = true;
}
VulkanSurface::~VulkanSurface() = default;
bool VulkanSurface::IsValid() const {
return valid_;
}
const VulkanHandle<VkSurfaceKHR>& VulkanSurface::Handle() const {
return surface_;
}
const VulkanNativeSurface& VulkanSurface::GetNativeSurface() const {
return *native_surface_;
}
SkISize VulkanSurface::GetSize() const {
return valid_ ? native_surface_->GetSize() : SkISize::Make(0, 0);
}
} // namespace vulkan