Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 33 additions & 28 deletions flutter/shell/platform/tizen/external_texture_pixel_vulkan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,26 @@ bool ExternalTexturePixelVulkan::PopulateVulkanTexture(
return false;
}

if (!pixel_buffer->buffer) {
FT_LOG(Error) << "pixel_buffer->buffer is nullptr";
return false;
}
Comment thread
xiaowei-guan marked this conversation as resolved.

if (pixel_buffer->width == 0 || pixel_buffer->height == 0) {
FT_LOG(Error) << "Invalid pixel buffer dimensions: " << pixel_buffer->width
<< "x" << pixel_buffer->height;
return false;
}

if (!CreateOrUpdateImage(pixel_buffer->width, pixel_buffer->height)) {
FT_LOG(Error) << "Fail to create image";
ReleaseImage();
return false;
}

VkDeviceSize required_staging_size =
pixel_buffer->width * pixel_buffer->height * 4;
static_cast<VkDeviceSize>(pixel_buffer->width) *
static_cast<VkDeviceSize>(pixel_buffer->height) * 4;
if (!CreateOrUpdateBuffer(required_staging_size)) {
FT_LOG(Error) << "Fail to create buffer";
ReleaseBuffer();
Expand All @@ -54,7 +66,10 @@ bool ExternalTexturePixelVulkan::PopulateVulkanTexture(
width_ = pixel_buffer->width;
height_ = pixel_buffer->height;

CopyBufferToImage(pixel_buffer->buffer, required_staging_size);
if (!CopyBufferToImage(pixel_buffer->buffer, required_staging_size)) {
FT_LOG(Error) << "Failed to copy buffer to image";
return false;
}

FlutterVulkanTexture* vulkan_texture =
static_cast<FlutterVulkanTexture*>(flutter_texture);
Expand Down Expand Up @@ -127,27 +142,6 @@ bool ExternalTexturePixelVulkan::CreateImage(size_t width, size_t height) {
return true;
}

bool ExternalTexturePixelVulkan::FindMemoryType(
uint32_t type_filter,
VkMemoryPropertyFlags properties,
uint32_t& index_out) {
VkPhysicalDeviceMemoryProperties memory_properties;
vkGetPhysicalDeviceMemoryProperties(
static_cast<VkPhysicalDevice>(
vulkan_renderer_->GetPhysicalDeviceHandle()),
&memory_properties);

for (uint32_t i = 0; i < memory_properties.memoryTypeCount; i++) {
if ((type_filter & (1 << i)) &&
(memory_properties.memoryTypes[i].propertyFlags & properties) ==
properties) {
index_out = i;
return true;
}
}
return false;
}

bool ExternalTexturePixelVulkan::CreateBuffer(VkDeviceSize required_size) {
VkBufferCreateInfo buffer_info{};
buffer_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Expand Down Expand Up @@ -194,13 +188,23 @@ void ExternalTexturePixelVulkan::ReleaseBuffer() {
staging_buffer_size_ = 0;
}

void ExternalTexturePixelVulkan::CopyBufferToImage(const uint8_t* src_buffer,
bool ExternalTexturePixelVulkan::CopyBufferToImage(const uint8_t* src_buffer,
VkDeviceSize size) {
void* data;
vkMapMemory(GetDevice(), staging_buffer_memory_, 0, size, 0, &data);
VkResult result =
vkMapMemory(GetDevice(), staging_buffer_memory_, 0, size, 0, &data);
if (result != VK_SUCCESS) {
FT_LOG(Error) << "Failed to map staging buffer memory";
return false;
}
Comment thread
xiaowei-guan marked this conversation as resolved.
memcpy(data, src_buffer, static_cast<size_t>(size));
vkUnmapMemory(GetDevice(), staging_buffer_memory_);

VkCommandBuffer command_buffer = vulkan_renderer_->BeginSingleTimeCommands();
if (command_buffer == VK_NULL_HANDLE) {
FT_LOG(Error) << "Failed to begin single time commands";
return false;
}

VkBufferImageCopy region{};
region.bufferOffset = 0;
Expand All @@ -218,6 +222,7 @@ void ExternalTexturePixelVulkan::CopyBufferToImage(const uint8_t* src_buffer,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);

vulkan_renderer_->EndSingleTimeCommands(command_buffer);
return true;
}

void ExternalTexturePixelVulkan::ReleaseImage() {
Expand All @@ -237,8 +242,8 @@ bool ExternalTexturePixelVulkan::AllocateMemory(
VkDeviceMemory& memory,
VkMemoryPropertyFlags properties) {
uint32_t memory_type_index;
if (!FindMemoryType(memory_requirements.memoryTypeBits, properties,
memory_type_index)) {
if (!vulkan_renderer_->FindMemoryType(memory_requirements.memoryTypeBits,
properties, &memory_type_index)) {
FT_LOG(Error) << "Fail to find memory type";
return false;
}
Expand All @@ -255,7 +260,7 @@ bool ExternalTexturePixelVulkan::AllocateMemory(
return true;
}

VkDevice ExternalTexturePixelVulkan::GetDevice() {
VkDevice ExternalTexturePixelVulkan::GetDevice() const {
return static_cast<VkDevice>(vulkan_renderer_->GetDeviceHandle());
}

Expand Down
7 changes: 2 additions & 5 deletions flutter/shell/platform/tizen/external_texture_pixel_vulkan.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,10 @@ class ExternalTexturePixelVulkan : public ExternalVulkanTexture {
bool CreateImage(size_t width, size_t height);
bool CreateOrUpdateBuffer(VkDeviceSize required_size);
bool CreateOrUpdateImage(size_t width, size_t height);
void CopyBufferToImage(const uint8_t* src_buffer, VkDeviceSize size);
VkDevice GetDevice();
bool CopyBufferToImage(const uint8_t* src_buffer, VkDeviceSize size);
VkDevice GetDevice() const;
void ReleaseBuffer();
void ReleaseImage();
bool FindMemoryType(uint32_t typeFilter,
VkMemoryPropertyFlags properties,
uint32_t& index_out);
FlutterDesktopPixelBufferTextureCallback texture_callback_ = nullptr;
size_t width_ = 0;
size_t height_ = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ bool ExternalTextureSurfaceVulkan::CreateBuffer(
}
if (!vulkan_buffer_->AllocateAndBindMemory(tbm_surface)) {
FT_LOG(Error) << "Fail to allocate memory";
vulkan_buffer_->ReleaseImage();
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,7 @@ VkFormat ExternalTextureSurfaceVulkanBuffer::ConvertFormat(tbm_format& format) {
}
}

bool ExternalTextureSurfaceVulkanBuffer::FindMemoryType(
uint32_t type_filter,
VkMemoryPropertyFlags properties,
uint32_t& index_out) {
VkPhysicalDeviceMemoryProperties memory_properties;
vkGetPhysicalDeviceMemoryProperties(
static_cast<VkPhysicalDevice>(
vulkan_renderer_->GetPhysicalDeviceHandle()),
&memory_properties);

for (uint32_t i = 0; i < memory_properties.memoryTypeCount; i++) {
if ((type_filter & (1 << i)) &&
(memory_properties.memoryTypes[i].propertyFlags & properties) ==
properties) {
index_out = i;
return true;
}
}
return false;
}

VkDevice ExternalTextureSurfaceVulkanBuffer::GetDevice() {
VkDevice ExternalTextureSurfaceVulkanBuffer::GetDevice() const {
return static_cast<VkDevice>(vulkan_renderer_->GetDeviceHandle());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ class ExternalTextureSurfaceVulkanBuffer {

protected:
VkFormat ConvertFormat(tbm_format& format);
VkDevice GetDevice();
bool FindMemoryType(uint32_t memory_type_bits_requirement,
VkMemoryPropertyFlags required_properties,
uint32_t& index_out);
VkDevice GetDevice() const;
Comment thread
xiaowei-guan marked this conversation as resolved.

private:
TizenRendererVulkan* vulkan_renderer_ = nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

#include "flutter/shell/platform/tizen/external_texture_surface_vulkan_buffer_dma.h"
#include <unistd.h>
#include "flutter/shell/platform/tizen/logger.h"

namespace flutter {
Expand Down Expand Up @@ -31,7 +32,11 @@ VkDeviceMemory ExternalTextureSurfaceVulkanBufferDma::GetMemory() {
bool ExternalTextureSurfaceVulkanBufferDma::CreateImage(
tbm_surface_h tbm_surface) {
tbm_surface_info_s tbm_surface_info;
tbm_surface_get_info(tbm_surface, &tbm_surface_info);
if (tbm_surface_get_info(tbm_surface, &tbm_surface_info) !=
TBM_SURFACE_ERROR_NONE) {
FT_LOG(Error) << "Fail to get tbm_surface info";
return false;
}
texture_format_ = ConvertFormat(tbm_surface_info.format);

VkExternalMemoryImageCreateInfoKHR external_image_create_info = {};
Expand Down Expand Up @@ -108,9 +113,10 @@ bool ExternalTextureSurfaceVulkanBufferDma::AllocateAndBindMemory(
int bo_fd = tbm_bo_export_fd(bo);
int bo_size = tbm_bo_size(bo);

uint32_t memory_type_index = -1;
uint32_t memory_type_index = 0;
if (!GetFdMemoryTypeIndex(bo_fd, memory_type_index)) {
FT_LOG(Error) << "Fail to get memory type index";
close(bo_fd);
return false;
Comment thread
xiaowei-guan marked this conversation as resolved.
}

Expand All @@ -129,15 +135,16 @@ bool ExternalTextureSurfaceVulkanBufferDma::AllocateAndBindMemory(
if (vkAllocateMemory(GetDevice(), &alloc_info, nullptr,
&texture_device_memory_) != VK_SUCCESS) {
FT_LOG(Error) << "Fail to allocate memory";
close(bo_fd);
return false;
}

if (vkBindImageMemory(GetDevice(), texture_image_, texture_device_memory_,
0u) != VK_SUCCESS) {
FT_LOG(Error) << "Fail to bind image memory";
close(bo_fd);
return false;
Comment thread
xiaowei-guan marked this conversation as resolved.
}
close(bo_fd);
return true;
}

Expand Down
23 changes: 21 additions & 2 deletions flutter/shell/platform/tizen/tizen_renderer_vulkan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ bool TizenRendererVulkan::InitVulkan(TizenViewBase* view) {
}

void TizenRendererVulkan::Cleanup() {
if (logical_device_) {
if (logical_device_ != VK_NULL_HANDLE) {
// Ensure all GPU work is complete before destroying anything.
vkDeviceWaitIdle(logical_device_);

Expand Down Expand Up @@ -749,7 +749,6 @@ bool TizenRendererVulkan::InitializeSwapchain() {
FT_LOG(Error) << "Could not get swap chain images count";
return false;
}
// swapchain_images_.reserve(image_count);
swapchain_images_.resize(image_count);
if (vkGetSwapchainImagesKHR(logical_device_, swapchain_, &image_count,
swapchain_images_.data()) != VK_SUCCESS) {
Expand Down Expand Up @@ -1022,4 +1021,24 @@ void TizenRendererVulkan::EndSingleTimeCommands(VkCommandBuffer commandBuffer) {
&commandBuffer);
}

bool TizenRendererVulkan::FindMemoryType(uint32_t type_filter,
VkMemoryPropertyFlags properties,
uint32_t* index_out) {
if (!index_out) {
return false;
}
VkPhysicalDeviceMemoryProperties memory_properties;
vkGetPhysicalDeviceMemoryProperties(physical_device_, &memory_properties);
Comment thread
xiaowei-guan marked this conversation as resolved.

for (uint32_t i = 0; i < memory_properties.memoryTypeCount; i++) {
if ((type_filter & (1 << i)) &&
(memory_properties.memoryTypes[i].propertyFlags & properties) ==
properties) {
*index_out = i;
return true;
}
}
return false;
}
Comment thread
xiaowei-guan marked this conversation as resolved.

} // namespace flutter
3 changes: 3 additions & 0 deletions flutter/shell/platform/tizen/tizen_renderer_vulkan.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class TizenRendererVulkan : public TizenRenderer {
bool Present(const FlutterVulkanImage* image);
VkCommandBuffer BeginSingleTimeCommands();
void EndSingleTimeCommands(VkCommandBuffer commandBuffer);
bool FindMemoryType(uint32_t type_filter,
VkMemoryPropertyFlags properties,
uint32_t* index_out);

private:
bool CreateCommandPool();
Expand Down
Loading