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 ()
 
bool IsValid () const
 
std::unique_ptr< SurfaceProducerSurfaceProduceSurface (const SkISize &size) override
 
void SubmitSurface (std::unique_ptr< SurfaceProducerSurface > surface) override
 
void OnSurfacesPresented (std::vector< std::unique_ptr< SurfaceProducerSurface >> surfaces)
 
GrDirectContext * gr_context ()
 
- 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)

Definition at line 40 of file vulkan_surface_producer.cc.

References FML_DLOG, and FML_LOG.

Referenced by gr_context().

40  {
41  valid_ = Initialize(scenic_session);
42 
43  if (valid_) {
44  FML_DLOG(INFO)
45  << "Flutter engine: Vulkan surface producer initialization: Successful";
46  } else {
47  FML_LOG(ERROR)
48  << "Flutter engine: Vulkan surface producer initialization: Failed";
49  }
50 }
#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)
Definition: fuchsia.cc:103
#define FML_DLOG(severity)
Definition: logging.h:85

◆ ~VulkanSurfaceProducer()

flutter_runner::VulkanSurfaceProducer::~VulkanSurfaceProducer ( )

Definition at line 52 of file vulkan_surface_producer.cc.

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

52  {
53  // Make sure queue is idle before we start destroying surfaces
54  if (valid_) {
55  VkResult wait_result = VK_CALL_LOG_ERROR(
56  vk_->QueueWaitIdle(logical_device_->GetQueueHandle()));
57  FML_DCHECK(wait_result == VK_SUCCESS);
58  }
59 };
#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 ( )
inline

Definition at line 44 of file vulkan_surface_producer.h.

References fml::RefPtr< T >::get(), and VulkanSurfaceProducer().

44 { return context_.get(); }

◆ IsValid()

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

Definition at line 32 of file vulkan_surface_producer.h.

References OnSurfacesPresented(), ProduceSurface(), fml::size(), and SubmitSurface().

32 { return valid_; }

◆ OnSurfacesPresented()

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

Definition at line 157 of file vulkan_surface_producer.cc.

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

Referenced by IsValid(), flutter_runner::ScopedFrame::ScopedFrame(), and flutter_runner::FuchsiaExternalViewEmbedder::SubmitFrame().

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

◆ ProduceSurface()

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

Implements flutter_runner::SurfaceProducer.

Definition at line 261 of file vulkan_surface_producer.cc.

References FML_DCHECK.

Referenced by IsValid(), flutter_runner::ScopedFrame::ScopedFrame(), and flutter_runner::FuchsiaExternalViewEmbedder::SubmitFrame().

262  {
263  FML_DCHECK(valid_);
264  last_produce_time_ = async::Now(async_get_default_dispatcher());
265  return surface_pool_->AcquireSurface(size);
266 }
#define FML_DCHECK(condition)
Definition: logging.h:86
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13

◆ SubmitSurface()

void flutter_runner::VulkanSurfaceProducer::SubmitSurface ( std::unique_ptr< SurfaceProducerSurface surface)
overridevirtual

Implements flutter_runner::SurfaceProducer.

Definition at line 268 of file vulkan_surface_producer.cc.

References FML_DCHECK.

Referenced by IsValid(), and OnSurfacesPresented().

269  {
270  FML_DCHECK(valid_ && surface != nullptr);
271  surface_pool_->SubmitSurface(std::move(surface));
272 }
#define FML_DCHECK(condition)
Definition: logging.h:86

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