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, sk_sp< GrDirectContext > context, scenic::Session *session, const SkISize &size)
 
 ~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
 
scenic::Image * GetImage () override
 
sk_sp< SkSurface > GetSkiaSurface () const 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
 
bool BindToImage (sk_sp< GrDirectContext > context, VulkanImage vulkan_image)
 
- Public Member Functions inherited from flutter_runner::SurfaceProducerSurface
virtual ~SurfaceProducerSurface ()=default
 

Detailed Description

Definition at line 77 of file vulkan_surface.h.

Constructor & Destructor Documentation

◆ VulkanSurface()

flutter_runner::VulkanSurface::VulkanSurface ( vulkan::VulkanProvider vulkan_provider,
sk_sp< GrDirectContext >  context,
scenic::Session *  session,
const SkISize &  size 
)

Definition at line 106 of file vulkan_surface.cc.

References FML_DCHECK, and FML_DLOG.

110  : vulkan_provider_(vulkan_provider), session_(session), wait_(this) {
111  FML_DCHECK(session_);
112 
113  zx::vmo exported_vmo;
114  if (!AllocateDeviceMemory(std::move(context), size, exported_vmo)) {
115  FML_DLOG(INFO) << "Could not allocate device memory.";
116  return;
117  }
118 
119  uint64_t vmo_size;
120  zx_status_t status = exported_vmo.get_size(&vmo_size);
121  FML_DCHECK(status == ZX_OK);
122 
123  if (!CreateFences()) {
124  FML_DLOG(INFO) << "Could not create signal fences.";
125  return;
126  }
127 
128  scenic_memory_ = std::make_unique<scenic::Memory>(
129  session, std::move(exported_vmo), vmo_size,
130  fuchsia::images::MemoryType::VK_DEVICE_MEMORY);
131  if (!PushSessionImageSetupOps(session)) {
132  FML_DLOG(INFO) << "Could not push session image setup ops.";
133  return;
134  }
135 
136  std::fill(size_history_.begin(), size_history_.end(), SkISize::MakeEmpty());
137 
138  wait_.set_object(release_event_.get());
139  wait_.set_trigger(ZX_EVENT_SIGNALED);
140  Reset();
141 
142  valid_ = true;
143 }
#define FML_DCHECK(condition)
Definition: logging.h:86
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
#define FML_DLOG(severity)
Definition: logging.h:85

◆ ~VulkanSurface()

flutter_runner::VulkanSurface::~VulkanSurface ( )
override

Definition at line 145 of file vulkan_surface.cc.

145  {
146  wait_.Cancel();
147  wait_.set_object(ZX_HANDLE_INVALID);
148 }

Member Function Documentation

◆ AdvanceAndGetAge()

size_t flutter_runner::VulkanSurface::AdvanceAndGetAge ( )
overridevirtual

Implements flutter_runner::SurfaceProducerSurface.

Definition at line 456 of file vulkan_surface.cc.

References GetSize().

456  {
457  size_history_[size_history_index_] = GetSize();
458  size_history_index_ = (size_history_index_ + 1) % kSizeHistorySize;
459  age_++;
460  return age_;
461 }
SkISize GetSize() const override

◆ BindToImage()

bool flutter_runner::VulkanSurface::BindToImage ( sk_sp< GrDirectContext >  context,
VulkanImage  vulkan_image 
)

Definition at line 416 of file vulkan_surface.cc.

References FML_DCHECK, FML_DLOG, vulkan::VulkanProvider::vk(), VK_CALL_LOG_ERROR, vulkan::VulkanProvider::vk_device(), flutter_runner::VulkanImage::vk_image, flutter_runner::VulkanImage::vk_image_create_info, and flutter_runner::VulkanImage::vk_memory_requirements.

417  {
418  FML_DCHECK(vulkan_image.vk_memory_requirements.size <=
419  vk_memory_info_.allocationSize);
420 
421  vulkan_image_ = std::move(vulkan_image);
422 
423  // Bind image memory.
424  if (VK_CALL_LOG_ERROR(vulkan_provider_.vk().BindImageMemory(
425  vulkan_provider_.vk_device(), vulkan_image_.vk_image, vk_memory_,
426  0)) != VK_SUCCESS) {
427  valid_ = false;
428  return false;
429  }
430 
431  const auto& extent = vulkan_image.vk_image_create_info.extent;
432  auto size = SkISize::Make(extent.width, extent.height);
433 
434  if (!SetupSkiaSurface(std::move(context), size, kSkiaColorType,
435  vulkan_image.vk_image_create_info,
436  vulkan_image.vk_memory_requirements)) {
437  FML_DLOG(ERROR) << "Failed to setup skia surface";
438  valid_ = false;
439  return false;
440  }
441 
442  if (sk_surface_ == nullptr) {
443  valid_ = false;
444  return false;
445  }
446 
447  if (!PushSessionImageSetupOps(session_)) {
448  FML_DLOG(ERROR) << "Could not push session image setup ops.";
449  valid_ = false;
450  return false;
451  }
452 
453  return true;
454 }
#define FML_DCHECK(condition)
Definition: logging.h:86
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
virtual const vulkan::VulkanHandle< VkDevice > & vk_device()=0
#define VK_CALL_LOG_ERROR(expression)
virtual const vulkan::VulkanProcTable & vk()=0
#define FML_DLOG(severity)
Definition: logging.h:85
vulkan::VulkanHandle< VkImage > vk_image

◆ FlushSessionAcquireAndReleaseEvents()

bool flutter_runner::VulkanSurface::FlushSessionAcquireAndReleaseEvents ( )
overridevirtual

Implements flutter_runner::SurfaceProducerSurface.

Definition at line 463 of file vulkan_surface.cc.

References event.

463  {
464  zx::event acquire, release;
465 
466  if (acquire_event_.duplicate(ZX_RIGHT_SAME_RIGHTS, &acquire) != ZX_OK ||
467  release_event_.duplicate(ZX_RIGHT_SAME_RIGHTS, &release) != ZX_OK) {
468  return false;
469  }
470 
471  session_->EnqueueAcquireFence(std::move(acquire));
472  session_->EnqueueReleaseFence(std::move(release));
473  age_ = 0;
474  return true;
475 }
GdkEventButton * event
Definition: fl_view.cc:62

◆ GetAcquireVkSemaphore()

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

Definition at line 113 of file vulkan_surface.h.

113  {
114  return acquire_semaphore_;
115  }

◆ GetAllocationSize()

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

Definition at line 129 of file vulkan_surface.h.

129 { return vk_memory_info_.allocationSize; }

◆ GetCommandBuffer()

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

Definition at line 117 of file vulkan_surface.h.

118  {
119  if (!command_buffer_)
120  command_buffer_ = std::make_unique<vulkan::VulkanCommandBuffer>(
121  vulkan_provider_.vk(), vulkan_provider_.vk_device(), pool);
122  return command_buffer_.get();
123  }
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 125 of file vulkan_surface.h.

125  {
126  return command_buffer_fence_;
127  }

◆ GetImage()

scenic::Image * flutter_runner::VulkanSurface::GetImage ( )
overridevirtual

Implements flutter_runner::SurfaceProducerSurface.

Definition at line 405 of file vulkan_surface.cc.

405  {
406  if (!valid_) {
407  return 0;
408  }
409  return session_image_.get();
410 }

◆ GetImageMemoryRequirementsSize()

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

Definition at line 131 of file vulkan_surface.h.

131  {
132  return vulkan_image_.vk_memory_requirements.size;
133  }
VkMemoryRequirements vk_memory_requirements

◆ 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 412 of file vulkan_surface.cc.

412  {
413  return valid_ ? sk_surface_ : nullptr;
414 }

◆ GetVkImage()

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

Definition at line 109 of file vulkan_surface.h.

109  {
110  return vulkan_image_.vk_image;
111  }
vulkan::VulkanHandle< VkImage > vk_image

◆ HasStableSizeHistory()

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

Definition at line 139 of file vulkan_surface.h.

References color_type, event, and FML_DISALLOW_COPY_AND_ASSIGN.

139  {
140  return std::equal(size_history_.begin() + 1, size_history_.end(),
141  size_history_.begin());
142  }

◆ IsOversized()

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

Definition at line 135 of file vulkan_surface.h.

135  {
137  }
size_t GetImageMemoryRequirementsSize() const

◆ IsValid()

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

Implements flutter_runner::SurfaceProducerSurface.

Definition at line 150 of file vulkan_surface.cc.

150  {
151  return valid_;
152 }

◆ SignalWritesFinished()

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

Implements flutter_runner::SurfaceProducerSurface.

Definition at line 477 of file vulkan_surface.cc.

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

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

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