Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
surface_context_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
7#include "flutter/fml/trace_event.h"
12
13namespace impeller {
14
15SurfaceContextVK::SurfaceContextVK(const std::shared_ptr<ContextVK>& parent)
16 : parent_(parent) {}
17
19
21 return parent_->GetBackendType();
22}
23
25 return parent_->DescribeGpuModel();
26}
27
29 return parent_->IsValid();
30}
31
32std::shared_ptr<Allocator> SurfaceContextVK::GetResourceAllocator() const {
33 return parent_->GetResourceAllocator();
34}
35
36std::shared_ptr<ShaderLibrary> SurfaceContextVK::GetShaderLibrary() const {
37 return parent_->GetShaderLibrary();
38}
39
40std::shared_ptr<SamplerLibrary> SurfaceContextVK::GetSamplerLibrary() const {
41 return parent_->GetSamplerLibrary();
42}
43
44std::shared_ptr<PipelineLibrary> SurfaceContextVK::GetPipelineLibrary() const {
45 return parent_->GetPipelineLibrary();
46}
47
48std::shared_ptr<CommandBuffer> SurfaceContextVK::CreateCommandBuffer() const {
49 return parent_->CreateCommandBuffer();
50}
51
52std::shared_ptr<CommandQueue> SurfaceContextVK::GetCommandQueue() const {
53 return parent_->GetCommandQueue();
54}
55
56const std::shared_ptr<const Capabilities>& SurfaceContextVK::GetCapabilities()
57 const {
58 return parent_->GetCapabilities();
59}
60
62 parent_->Shutdown();
63}
64
66 const ISize& size) {
67 auto swapchain = SwapchainVK::Create(parent_, std::move(surface), size);
68 if (!swapchain) {
69 VALIDATION_LOG << "Could not create swapchain.";
70 return false;
71 }
72 if (!swapchain->IsValid()) {
73 VALIDATION_LOG << "Could not create valid swapchain.";
74 return false;
75 }
76 swapchain_ = std::move(swapchain);
77 return true;
78}
79
80std::unique_ptr<Surface> SurfaceContextVK::AcquireNextSurface() {
81 TRACE_EVENT0("impeller", __FUNCTION__);
82 auto surface = swapchain_ ? swapchain_->AcquireNextDrawable() : nullptr;
83 if (!surface) {
84 return nullptr;
85 }
86 if (auto pipeline_library = parent_->GetPipelineLibrary()) {
87 impeller::PipelineLibraryVK::Cast(*pipeline_library)
89 }
90 parent_->GetCommandPoolRecycler()->Dispose();
91 parent_->GetResourceAllocator()->DebugTraceMemoryStatistics();
92 return surface;
93}
94
96 swapchain_->UpdateSurfaceSize(size);
97}
98
99#ifdef FML_OS_ANDROID
100
101vk::UniqueSurfaceKHR SurfaceContextVK::CreateAndroidSurface(
102 ANativeWindow* window) const {
103 if (!parent_->GetInstance()) {
104 return vk::UniqueSurfaceKHR{VK_NULL_HANDLE};
105 }
106
107 auto create_info = vk::AndroidSurfaceCreateInfoKHR().setWindow(window);
108 auto surface_res =
109 parent_->GetInstance().createAndroidSurfaceKHRUnique(create_info);
110
111 if (surface_res.result != vk::Result::eSuccess) {
112 VALIDATION_LOG << "Could not create Android surface, error: "
113 << vk::to_string(surface_res.result);
114 return vk::UniqueSurfaceKHR{VK_NULL_HANDLE};
115 }
116
117 return std::move(surface_res.value);
118}
119
120#endif // FML_OS_ANDROID
121
122const vk::Device& SurfaceContextVK::GetDevice() const {
123 return parent_->GetDevice();
124}
125
127 parent_->InitializeCommonlyUsedShadersIfNeeded();
128}
129
131 return *parent_;
132}
133
134} // namespace impeller
static PipelineLibraryVK & Cast(PipelineLibrary &base)
bool SetWindowSurface(vk::UniqueSurfaceKHR surface, const ISize &size)
SurfaceContextVK(const std::shared_ptr< ContextVK > &parent)
std::shared_ptr< PipelineLibrary > GetPipelineLibrary() const override
Returns the library of pipelines used by render or compute commands.
const std::shared_ptr< const Capabilities > & GetCapabilities() const override
Get the capabilities of Impeller context. All optionally supported feature of the platform,...
BackendType GetBackendType() const override
Get the graphics backend of an Impeller context.
std::string DescribeGpuModel() const override
bool IsValid() const override
Determines if a context is valid. If the caller ever receives an invalid context, they must discard i...
void UpdateSurfaceSize(const ISize &size) const
Mark the current swapchain configuration as dirty, forcing it to be recreated on the next frame.
std::unique_ptr< Surface > AcquireNextSurface()
const vk::Device & GetDevice() const
std::shared_ptr< SamplerLibrary > GetSamplerLibrary() const override
Returns the library of combined image samplers used in shaders.
std::shared_ptr< CommandQueue > GetCommandQueue() const override
Return the graphics queue for submitting command buffers.
void Shutdown() override
Force all pending asynchronous work to finish. This is achieved by deleting all owned concurrent mess...
std::shared_ptr< CommandBuffer > CreateCommandBuffer() const override
Create a new command buffer. Command buffers can be used to encode graphics, blit,...
const ContextVK & GetParent() const
std::shared_ptr< ShaderLibrary > GetShaderLibrary() const override
Returns the library of shaders used to specify the programmable stages of a pipeline.
void InitializeCommonlyUsedShadersIfNeeded() const override
std::shared_ptr< Allocator > GetResourceAllocator() const override
Returns the allocator used to create textures and buffers on the device.
static std::shared_ptr< SwapchainVK > Create(const std::shared_ptr< Context > &context, vk::UniqueSurfaceKHR surface, const ISize &size, bool enable_msaa=true)
VkSwapchainKHR swapchain
Definition main.cc:64
GLFWwindow * window
Definition main.cc:45
VkSurfaceKHR surface
Definition main.cc:49
#define TRACE_EVENT0(category_group, name)
#define VALIDATION_LOG
Definition validation.h:73
#define VK_NULL_HANDLE
Definition vulkan_core.h:46
struct ANativeWindow ANativeWindow