Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
vulkan_surface.h
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
5#ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_VULKAN_SURFACE_H_
6#define FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_VULKAN_SURFACE_H_
7
8#include <lib/async/cpp/wait.h>
9#include <lib/zx/event.h>
10#include <lib/zx/vmo.h>
11
12#include <array>
13#include <cstdint>
14#include <memory>
15
16#include "flutter/fml/macros.h"
17#include "flutter/vulkan/procs/vulkan_handle.h"
18#include "flutter/vulkan/procs/vulkan_proc_table.h"
19#include "flutter/vulkan/vulkan_command_buffer.h"
20#include "flutter/vulkan/vulkan_provider.h"
25
26#include "surface_producer.h"
27
28namespace flutter_runner {
29
30// A |VkImage| and its relevant metadata.
43
45 public:
47 fuchsia::sysmem::AllocatorSyncPtr& sysmem_allocator,
48 fuchsia::ui::composition::AllocatorPtr& flatland_allocator,
50 const SkISize& size);
51
52 ~VulkanSurface() override;
53
54 // |SurfaceProducerSurface|
55 size_t AdvanceAndGetAge() override;
56
57 // |SurfaceProducerSurface|
59
60 // |SurfaceProducerSurface|
61 bool IsValid() const override;
62
63 // |SurfaceProducerSurface|
64 SkISize GetSize() const override;
65
66 // Note: It is safe for the caller to collect the surface in the
67 // |on_writes_committed| callback.
69 const std::function<void(void)>& on_writes_committed) override;
70
71 // |SurfaceProducerSurface|
72 void SetImageId(uint32_t image_id) override;
73
74 // |SurfaceProducerSurface|
75 uint32_t GetImageId() override;
76
77 // |SurfaceProducerSurface|
78 sk_sp<SkSurface> GetSkiaSurface() const override;
79
80 // |SurfaceProducerSurface|
81 fuchsia::ui::composition::BufferCollectionImportToken
83
84 // |SurfaceProducerSurface|
85 zx::event GetAcquireFence() override;
86
87 // |SurfaceProducerSurface|
88 zx::event GetReleaseFence() override;
89
90 // |SurfaceProducerSurface|
92 ReleaseImageCallback release_image_callback) override;
93
95 return vulkan_image_.vk_image;
96 }
97
99 return acquire_semaphore_;
100 }
101
104 if (!command_buffer_)
105 command_buffer_ = std::make_unique<vulkan::VulkanCommandBuffer>(
106 vulkan_provider_.vk(), vulkan_provider_.vk_device(), pool);
107 return command_buffer_.get();
108 }
109
111 return command_buffer_fence_;
112 }
113
114 size_t GetAllocationSize() const { return vk_memory_info_.allocationSize; }
115
117 return vulkan_image_.vk_memory_requirements.size;
118 }
119
120 bool IsOversized() const {
122 }
123
124 bool HasStableSizeHistory() const {
125 return std::equal(size_history_.begin() + 1, size_history_.end(),
126 size_history_.begin());
127 }
128
129 private:
130 static constexpr int kSizeHistorySize = 4;
131
132 void OnHandleReady(async_dispatcher_t* dispatcher,
133 async::WaitBase* wait,
134 zx_status_t status,
135 const zx_packet_signal_t* signal);
136
137 bool AllocateDeviceMemory(
138 fuchsia::sysmem::AllocatorSyncPtr& sysmem_allocator,
139 fuchsia::ui::composition::AllocatorPtr& flatland_allocator,
141 const SkISize& size);
142
143 bool CreateVulkanImage(vulkan::VulkanProvider& vulkan_provider,
144 const SkISize& size,
145 VulkanImage* out_vulkan_image);
146
147 bool SetupSkiaSurface(sk_sp<GrDirectContext> context,
148 const SkISize& size,
150 const VkImageCreateInfo& image_create_info,
151 const VkMemoryRequirements& memory_reqs);
152
153 bool CreateFences();
154
155 void Reset();
156
157 vulkan::VulkanHandle<VkSemaphore> SemaphoreFromEvent(
158 const zx::event& event) const;
159
160 vulkan::VulkanProvider& vulkan_provider_;
161 VulkanImage vulkan_image_;
163 VkMemoryAllocateInfo vk_memory_info_;
164 vulkan::VulkanHandle<VkFence> command_buffer_fence_;
165 sk_sp<SkSurface> sk_surface_;
166 fuchsia::ui::composition::BufferCollectionImportToken import_token_;
167 uint32_t image_id_ = 0;
169 zx::event acquire_event_;
170 vulkan::VulkanHandle<VkSemaphore> acquire_semaphore_;
171 std::unique_ptr<vulkan::VulkanCommandBuffer> command_buffer_;
172 zx::event release_event_;
173 async::WaitMethod<VulkanSurface, &VulkanSurface::OnHandleReady> wait_;
174 std::function<void()> pending_on_writes_committed_;
175 std::array<SkISize, kSizeHistorySize> size_history_;
176 int size_history_index_ = 0;
177 size_t age_ = 0;
178 bool valid_ = false;
179 ReleaseImageCallback release_image_callback_;
180
182};
183
184} // namespace flutter_runner
185
186#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_VULKAN_SURFACE_H_
AutoreleasePool pool
SkColorType
Definition SkColorType.h:19
const vulkan::VulkanHandle< VkFence > & GetCommandBufferFence()
const vulkan::VulkanHandle< VkImage > & GetVkImage()
void SetReleaseImageCallback(ReleaseImageCallback release_image_callback) override
fuchsia::ui::composition::BufferCollectionImportToken GetBufferCollectionImportToken() override
bool IsValid() const override
vulkan::VulkanCommandBuffer * GetCommandBuffer(const vulkan::VulkanHandle< VkCommandPool > &pool)
zx::event GetAcquireFence() override
void SignalWritesFinished(const std::function< void(void)> &on_writes_committed) override
SkISize GetSize() const override
bool FlushSessionAcquireAndReleaseEvents() override
void SetImageId(uint32_t image_id) override
const vulkan::VulkanHandle< VkSemaphore > & GetAcquireVkSemaphore()
sk_sp< SkSurface > GetSkiaSurface() const override
zx::event GetReleaseFence() override
size_t GetImageMemoryRequirementsSize() const
virtual const vulkan::VulkanProcTable & vk()=0
virtual const vulkan::VulkanHandle< VkDevice > & vk_device()=0
FlKeyEvent * event
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
std::function< void()> ReleaseImageCallback
uint32_t color_type
VkDeviceSize allocationSize
VkImageCreateInfo vk_image_create_info
VkMemoryRequirements vk_memory_requirements
VkBufferCollectionImageCreateInfoFUCHSIA vk_collection_image_create_info
VulkanImage & operator=(VulkanImage &&)=default
vulkan::VulkanHandle< VkImage > vk_image
VulkanImage(VulkanImage &&)=default
FML_DISALLOW_COPY_AND_ASSIGN(VulkanImage)