Flutter Engine
flutter_runner::VulkanSurfaceProducer Class Referencefinal

#include <vulkan_surface_producer.h>

Inheritance diagram for flutter_runner::VulkanSurfaceProducer:
flutter_runner::SurfaceProducer vulkan::VulkanProvider

Public Member Functions

 VulkanSurfaceProducer (scenic::Session *scenic_session)
 
 ~VulkanSurfaceProducer () override
 
bool IsValid () const
 
GrDirectContext * gr_context () const
 
std::unique_ptr< SurfaceProducerSurfaceProduceOffscreenSurface (const SkISize &size)
 
std::unique_ptr< SurfaceProducerSurfaceProduceSurface (const SkISize &size) override
 
void SubmitSurfaces (std::vector< std::unique_ptr< SurfaceProducerSurface >> surfaces) override
 
- Public Member Functions inherited from flutter_runner::SurfaceProducer
virtual ~SurfaceProducer ()=default
 
- Public Member Functions inherited from vulkan::VulkanProvider
vulkan::VulkanHandle< VkFence > CreateFence ()
 

Detailed Description

Definition at line 25 of file vulkan_surface_producer.h.

Constructor & Destructor Documentation

◆ VulkanSurfaceProducer()

flutter_runner::VulkanSurfaceProducer::VulkanSurfaceProducer ( scenic::Session *  scenic_session)
explicit

Definition at line 40 of file vulkan_surface_producer.cc.

References FML_LOG.

Referenced by gr_context().

40  {
41  valid_ = Initialize(scenic_session);
42 
43  if (!valid_) {
44  FML_LOG(FATAL) << "VulkanSurfaceProducer: Initialization failed";
45  }
46 }
#define FML_LOG(severity)
Definition: logging.h:65
void Initialize(fidl::InterfaceHandle< fuchsia::sys::Environment > environment, zx::channel directory_request, std::optional< zx::eventpair > view_ref)
Initializes Dart bindings for the Fuchsia application model.
Definition: fuchsia.cc:103

◆ ~VulkanSurfaceProducer()

flutter_runner::VulkanSurfaceProducer::~VulkanSurfaceProducer ( )
override

Definition at line 48 of file vulkan_surface_producer.cc.

References FML_DCHECK, FML_LOG, flutter::kGrCacheMaxByteSize, flutter::kGrCacheMaxCount, and VK_CALL_LOG_ERROR.

48  {
49  // Make sure queue is idle before we start destroying surfaces
50  if (valid_) {
51  VkResult wait_result = VK_CALL_LOG_ERROR(
52  vk_->QueueWaitIdle(logical_device_->GetQueueHandle()));
53  FML_DCHECK(wait_result == VK_SUCCESS);
54  }
55 };
#define FML_DCHECK(condition)
Definition: logging.h:86
#define VK_CALL_LOG_ERROR(expression)

Member Function Documentation

◆ gr_context()

GrDirectContext* flutter_runner::VulkanSurfaceProducer::gr_context ( ) const
inline

◆ IsValid()

bool flutter_runner::VulkanSurfaceProducer::IsValid ( ) const
inline

Definition at line 31 of file vulkan_surface_producer.h.

31 { return valid_; }

◆ ProduceOffscreenSurface()

std::unique_ptr< SurfaceProducerSurface > flutter_runner::VulkanSurfaceProducer::ProduceOffscreenSurface ( const SkISize &  size)

Definition at line 278 of file vulkan_surface_producer.cc.

Referenced by gr_context(), and flutter_runner::Engine::WriteProfileToTrace().

278  {
279  return surface_pool_->CreateSurface(size);
280 }
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13

◆ ProduceSurface()

std::unique_ptr< SurfaceProducerSurface > flutter_runner::VulkanSurfaceProducer::ProduceSurface ( const SkISize &  size)
overridevirtual

Implements flutter_runner::SurfaceProducer.

Definition at line 264 of file vulkan_surface_producer.cc.

References FML_CHECK.

Referenced by gr_context().

265  {
266  FML_CHECK(valid_);
267  last_produce_time_ = async::Now(async_get_default_dispatcher());
268  return surface_pool_->AcquireSurface(size);
269 }
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
#define FML_CHECK(condition)
Definition: logging.h:68

◆ SubmitSurfaces()

void flutter_runner::VulkanSurfaceProducer::SubmitSurfaces ( std::vector< std::unique_ptr< SurfaceProducerSurface >>  surfaces)
overridevirtual

Implements flutter_runner::SurfaceProducer.

Definition at line 160 of file vulkan_surface_producer.cc.

References vulkan::VulkanCommandBuffer::Begin(), vulkan::VulkanCommandBuffer::End(), FML_LOG, vulkan::VulkanCommandBuffer::InsertPipelineBarrier(), and TRACE_EVENT0.

Referenced by gr_context().

161  {
162  TRACE_EVENT0("flutter", "VulkanSurfaceProducer::SubmitSurfaces");
163 
164  // Do a single flush for all canvases derived from the context.
165  {
166  TRACE_EVENT0("flutter", "GrDirectContext::flushAndSignalSemaphores");
167  context_->flushAndSubmit();
168  }
169 
170  if (!TransitionSurfacesToExternal(surfaces))
171  FML_LOG(ERROR) << "TransitionSurfacesToExternal failed";
172 
173  // Submit surface
174  for (auto& surface : surfaces) {
175  SubmitSurface(std::move(surface));
176  }
177 
178  // Buffer management.
179  surface_pool_->AgeAndCollectOldBuffers();
180 
181  // If no further surface production has taken place for 10 frames (TODO:
182  // Don't hardcode refresh rate here), then shrink our surface pool to fit.
183  constexpr auto kShouldShrinkThreshold = zx::msec(10 * 16.67);
184  async::PostDelayedTask(
185  async_get_default_dispatcher(),
186  [self = weak_factory_.GetWeakPtr(), kShouldShrinkThreshold] {
187  if (!self) {
188  return;
189  }
190  auto time_since_last_produce =
191  async::Now(async_get_default_dispatcher()) -
192  self->last_produce_time_;
193  if (time_since_last_produce >= kShouldShrinkThreshold) {
194  self->surface_pool_->ShrinkToFit();
195  }
196  },
197  kShouldShrinkThreshold);
198 }
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:90
#define FML_LOG(severity)
Definition: logging.h:65

The documentation for this class was generated from the following files: