Flutter Engine
flutter_runner::VulkanSurface Class Referencefinal

#include <vulkan_surface.h>

Inheritance diagram for flutter_runner::VulkanSurface:
flutter_runner::SurfaceProducerSurface

Public Member Functions

 VulkanSurface (vulkan::VulkanProvider &vulkan_provider, fuchsia::sysmem::AllocatorSyncPtr &sysmem_allocator, fuchsia::ui::composition::AllocatorPtr &flatland_allocator, sk_sp< GrDirectContext > context, scenic::Session *session, const SkISize &size, uint32_t buffer_id)
 
 ~VulkanSurface () override
 
size_t AdvanceAndGetAge () override
 
bool FlushSessionAcquireAndReleaseEvents () override
 
bool IsValid () const override
 
SkISize GetSize () const override
 
void SignalWritesFinished (const std::function< void(void)> &on_writes_committed) override
 
void SetImageId (uint32_t image_id) override
 
uint32_t GetImageId () override
 
sk_sp< SkSurface > GetSkiaSurface () const override
 
fuchsia::ui::composition::BufferCollectionImportToken GetBufferCollectionImportToken () override
 
zx::event GetAcquireFence () override
 
zx::event GetReleaseFence () override
 
void SetReleaseImageCallback (ReleaseImageCallback release_image_callback) override
 
const vulkan::VulkanHandle< VkImage > & GetVkImage ()
 
const vulkan::VulkanHandle< VkSemaphore > & GetAcquireVkSemaphore ()
 
vulkan::VulkanCommandBufferGetCommandBuffer (const vulkan::VulkanHandle< VkCommandPool > &pool)
 
const vulkan::VulkanHandle< VkFence > & GetCommandBufferFence ()
 
size_t GetAllocationSize () const
 
size_t GetImageMemoryRequirementsSize () const
 
bool IsOversized () const
 
bool HasStableSizeHistory () const
 
- Public Member Functions inherited from flutter_runner::SurfaceProducerSurface
virtual ~SurfaceProducerSurface ()=default
 

Detailed Description

Definition at line 41 of file vulkan_surface.h.

Constructor & Destructor Documentation

◆ VulkanSurface()

flutter_runner::VulkanSurface::VulkanSurface ( vulkan::VulkanProvider vulkan_provider,
fuchsia::sysmem::AllocatorSyncPtr &  sysmem_allocator,
fuchsia::ui::composition::AllocatorPtr &  flatland_allocator,
sk_sp< GrDirectContext >  context,
scenic::Session *  session,
const SkISize &  size,
uint32_t  buffer_id 
)

Definition at line 103 of file vulkan_surface.cc.

References FML_CHECK, and FML_LOG.

111  : vulkan_provider_(vulkan_provider), session_(session), wait_(this) {
112  FML_CHECK(session_ || flatland_allocator.is_bound());
113  FML_CHECK(context != nullptr);
114 
115  if (!AllocateDeviceMemory(sysmem_allocator, flatland_allocator,
116  std::move(context), size, buffer_id)) {
117  FML_LOG(ERROR) << "VulkanSurface: Could not allocate device memory.";
118  return;
119  }
120 
121  if (!CreateFences()) {
122  FML_LOG(ERROR) << "VulkanSurface: Could not create signal fences.";
123  return;
124  }
125 
126  PushSessionImageSetupOps(session);
127 
128  std::fill(size_history_.begin(), size_history_.end(), SkISize::MakeEmpty());
129 
130  wait_.set_object(release_event_.get());
131  wait_.set_trigger(ZX_EVENT_SIGNALED);
132  Reset();
133 
134  valid_ = true;
135 }
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
#define FML_LOG(severity)
Definition: logging.h:65
#define FML_CHECK(condition)
Definition: logging.h:68

◆ ~VulkanSurface()

flutter_runner::VulkanSurface::~VulkanSurface ( )
override

Definition at line 137 of file vulkan_surface.cc.

137  {
138  if (session_) {
139  if (image_id_) {
140  session_->Enqueue(scenic::NewReleaseResourceCmd(image_id_));
141  }
142  if (buffer_id_) {
143  session_->DeregisterBufferCollection(buffer_id_);
144  }
145  } else {
146  release_image_callback_();
147  }
148  wait_.Cancel();
149  wait_.set_object(ZX_HANDLE_INVALID);
150 }

Member Function Documentation

◆ AdvanceAndGetAge()

size_t flutter_runner::VulkanSurface::AdvanceAndGetAge ( )
overridevirtual

Implements flutter_runner::SurfaceProducerSurface.

Definition at line 459 of file vulkan_surface.cc.

References GetSize().

459  {
460  size_history_[size_history_index_] = GetSize();
461  size_history_index_ = (size_history_index_ + 1) % kSizeHistorySize;
462  age_++;
463  return age_;
464 }
SkISize GetSize() const override

◆ FlushSessionAcquireAndReleaseEvents()

bool flutter_runner::VulkanSurface::FlushSessionAcquireAndReleaseEvents ( )
overridevirtual

Implements flutter_runner::SurfaceProducerSurface.

Definition at line 466 of file vulkan_surface.cc.

References event.

466  {
467  if (session_) {
468  zx::event acquire, release;
469  if (acquire_event_.duplicate(ZX_RIGHT_SAME_RIGHTS, &acquire) != ZX_OK ||
470  release_event_.duplicate(ZX_RIGHT_SAME_RIGHTS, &release) != ZX_OK) {
471  return false;
472  }
473  session_->EnqueueAcquireFence(std::move(acquire));
474  session_->EnqueueReleaseFence(std::move(release));
475  }
476 
477  age_ = 0;
478  return true;
479 }
FlKeyEvent * event

◆ GetAcquireFence()

zx::event flutter_runner::VulkanSurface::GetAcquireFence ( )
overridevirtual

Implements flutter_runner::SurfaceProducerSurface.

Definition at line 440 of file vulkan_surface.cc.

References event, and FML_CHECK.

440  {
441  FML_CHECK(!session_);
442  zx::event fence;
443  acquire_event_.duplicate(ZX_RIGHT_SAME_RIGHTS, &fence);
444  return fence;
445 }
FlKeyEvent * event
#define FML_CHECK(condition)
Definition: logging.h:68

◆ GetAcquireVkSemaphore()

const vulkan::VulkanHandle<VkSemaphore>& flutter_runner::VulkanSurface::GetAcquireVkSemaphore ( )
inline

Definition at line 97 of file vulkan_surface.h.

97  {
98  return acquire_semaphore_;
99  }

◆ GetAllocationSize()

size_t flutter_runner::VulkanSurface::GetAllocationSize ( ) const
inline

Definition at line 113 of file vulkan_surface.h.

113 { return vk_memory_info_.allocationSize; }

◆ GetBufferCollectionImportToken()

fuchsia::ui::composition::BufferCollectionImportToken flutter_runner::VulkanSurface::GetBufferCollectionImportToken ( )
overridevirtual

Implements flutter_runner::SurfaceProducerSurface.

Definition at line 433 of file vulkan_surface.cc.

References FML_CHECK.

433  {
434  FML_CHECK(!session_);
435  fuchsia::ui::composition::BufferCollectionImportToken import_dup;
436  import_token_.value.duplicate(ZX_RIGHT_SAME_RIGHTS, &import_dup.value);
437  return import_dup;
438 }
#define FML_CHECK(condition)
Definition: logging.h:68

◆ GetCommandBuffer()

vulkan::VulkanCommandBuffer* flutter_runner::VulkanSurface::GetCommandBuffer ( const vulkan::VulkanHandle< VkCommandPool > &  pool)
inline

Definition at line 101 of file vulkan_surface.h.

102  {
103  if (!command_buffer_)
104  command_buffer_ = std::make_unique<vulkan::VulkanCommandBuffer>(
105  vulkan_provider_.vk(), vulkan_provider_.vk_device(), pool);
106  return command_buffer_.get();
107  }
virtual const vulkan::VulkanHandle< VkDevice > & vk_device()=0
virtual const vulkan::VulkanProcTable & vk()=0

◆ GetCommandBufferFence()

const vulkan::VulkanHandle<VkFence>& flutter_runner::VulkanSurface::GetCommandBufferFence ( )
inline

Definition at line 109 of file vulkan_surface.h.

109  {
110  return command_buffer_fence_;
111  }

◆ GetImageId()

uint32_t flutter_runner::VulkanSurface::GetImageId ( )
overridevirtual

Implements flutter_runner::SurfaceProducerSurface.

Definition at line 424 of file vulkan_surface.cc.

424  {
425  return image_id_;
426 }

◆ GetImageMemoryRequirementsSize()

size_t flutter_runner::VulkanSurface::GetImageMemoryRequirementsSize ( ) const
inline

Definition at line 115 of file vulkan_surface.h.

115  {
116  return vulkan_image_.vk_memory_requirements.size;
117  }
VkMemoryRequirements vk_memory_requirements

◆ GetReleaseFence()

zx::event flutter_runner::VulkanSurface::GetReleaseFence ( )
overridevirtual

Implements flutter_runner::SurfaceProducerSurface.

Definition at line 447 of file vulkan_surface.cc.

References event, and FML_CHECK.

447  {
448  FML_CHECK(!session_);
449  zx::event fence;
450  release_event_.duplicate(ZX_RIGHT_SAME_RIGHTS, &fence);
451  return fence;
452 }
FlKeyEvent * event
#define FML_CHECK(condition)
Definition: logging.h:68

◆ GetSize()

SkISize flutter_runner::VulkanSurface::GetSize ( ) const
overridevirtual

◆ GetSkiaSurface()

sk_sp< SkSurface > flutter_runner::VulkanSurface::GetSkiaSurface ( ) const
overridevirtual

Implements flutter_runner::SurfaceProducerSurface.

Definition at line 428 of file vulkan_surface.cc.

428  {
429  return valid_ ? sk_surface_ : nullptr;
430 }

◆ GetVkImage()

const vulkan::VulkanHandle<VkImage>& flutter_runner::VulkanSurface::GetVkImage ( )
inline

Definition at line 93 of file vulkan_surface.h.

93  {
94  return vulkan_image_.vk_image;
95  }
vulkan::VulkanHandle< VkImage > vk_image

◆ HasStableSizeHistory()

bool flutter_runner::VulkanSurface::HasStableSizeHistory ( ) const
inline

Definition at line 123 of file vulkan_surface.h.

References color_type, and event.

123  {
124  return std::equal(size_history_.begin() + 1, size_history_.end(),
125  size_history_.begin());
126  }

◆ IsOversized()

bool flutter_runner::VulkanSurface::IsOversized ( ) const
inline

Definition at line 119 of file vulkan_surface.h.

119  {
121  }
size_t GetImageMemoryRequirementsSize() const

◆ IsValid()

bool flutter_runner::VulkanSurface::IsValid ( ) const
overridevirtual

Implements flutter_runner::SurfaceProducerSurface.

Definition at line 152 of file vulkan_surface.cc.

152  {
153  return valid_;
154 }

◆ SetImageId()

void flutter_runner::VulkanSurface::SetImageId ( uint32_t  image_id)
overridevirtual

Implements flutter_runner::SurfaceProducerSurface.

Definition at line 418 of file vulkan_surface.cc.

References FML_CHECK.

418  {
419  FML_CHECK(image_id_ == 0);
420  FML_CHECK(!session_);
421  image_id_ = image_id;
422 }
#define FML_CHECK(condition)
Definition: logging.h:68

◆ SetReleaseImageCallback()

void flutter_runner::VulkanSurface::SetReleaseImageCallback ( ReleaseImageCallback  release_image_callback)
overridevirtual

Implements flutter_runner::SurfaceProducerSurface.

Definition at line 453 of file vulkan_surface.cc.

References FML_CHECK.

454  {
455  FML_CHECK(!session_);
456  release_image_callback_ = release_image_callback;
457 }
#define FML_CHECK(condition)
Definition: logging.h:68

◆ SignalWritesFinished()

void flutter_runner::VulkanSurface::SignalWritesFinished ( const std::function< void(void)> &  on_writes_committed)
overridevirtual

Implements flutter_runner::SurfaceProducerSurface.

Definition at line 481 of file vulkan_surface.cc.

References callback, dart_utils::Check(), FML_CHECK, FML_DCHECK, FML_LOG, vulkan::VulkanHandle< T >::Reset(), vulkan::VulkanProvider::vk(), VK_CALL_LOG_ERROR, and vulkan::VulkanProvider::vk_device().

482  {
483  FML_CHECK(on_writes_committed);
484 
485  if (!valid_) {
486  on_writes_committed();
487  return;
488  }
489 
490  dart_utils::Check(pending_on_writes_committed_ == nullptr,
491  "Attempted to signal a write on the surface when the "
492  "previous write has not yet been acknowledged by the "
493  "compositor.");
494 
495  pending_on_writes_committed_ = on_writes_committed;
496 }
void Check(bool condition, const char *tag, const char *message="")
Definition: inlines.h:12
#define FML_CHECK(condition)
Definition: logging.h:68

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