Flutter Engine
 
Loading...
Searching...
No Matches
swapchain_vk.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
8
9namespace impeller::interop {
10
11SwapchainVK::SwapchainVK(Context& context, VkSurfaceKHR c_surface)
12 : context_(Ref(&context)) {
13 if (!context.IsVulkan()) {
14 VALIDATION_LOG << "Context is not Vulkan.";
15 return;
16 }
17
18 if (!c_surface) {
19 VALIDATION_LOG << "Invalid surface.";
20 return;
21 }
22
23 // Creating a unique object from a raw handle requires fetching the owner
24 // manually.
25 auto surface = vk::UniqueSurfaceKHR(
26 vk::SurfaceKHR{c_surface},
27 impeller::ContextVK::Cast(*context_->GetContext()).GetInstance());
29 std::move(surface), //
30 ISize::MakeWH(1, 1) //
31 );
32 if (!swapchain) {
33 VALIDATION_LOG << "Could not create Vulkan swapchain.";
34 return;
35 }
36 swapchain_ = std::move(swapchain);
37}
38
40
42 return swapchain_ && swapchain_->IsValid();
43}
44
46 if (!IsValid()) {
47 return nullptr;
48 }
49
50 auto impeller_surface = swapchain_->AcquireNextDrawable();
51 if (!impeller_surface) {
52 VALIDATION_LOG << "Could not acquire next drawable.";
53 return nullptr;
54 }
55
56 auto surface = Create<SurfaceVK>(*context_, std::move(impeller_surface));
57 if (!surface || !surface->IsValid()) {
58 VALIDATION_LOG << "Could not create valid surface.";
59 return nullptr;
60 }
61
62 return surface;
63}
64
65} // namespace impeller::interop
static ContextVK & Cast(Context &base)
vk::Instance GetInstance() const
static std::shared_ptr< SwapchainVK > Create(const std::shared_ptr< Context > &context, vk::UniqueSurfaceKHR surface, const ISize &size, bool enable_msaa=true)
std::shared_ptr< impeller::Context > GetContext() const
Definition context.cc:20
ScopedObject< SurfaceVK > AcquireNextSurface()
VkSwapchainKHR swapchain
Definition main.cc:80
VkSurfaceKHR surface
Definition main.cc:65
ScopedObject< Object > Ref(Object *object)
Definition object.h:146
static constexpr TSize MakeWH(Type width, Type height)
Definition size.h:43
#define VALIDATION_LOG
Definition validation.h:91