Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
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
1 change: 0 additions & 1 deletion shell/platform/fuchsia/flutter/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ template("runner_sources") {
"$fuchsia_sdk_root/fidl:fuchsia.images",
"$fuchsia_sdk_root/fidl:fuchsia.intl",
"$fuchsia_sdk_root/fidl:fuchsia.io",
"$fuchsia_sdk_root/fidl:fuchsia.scenic.allocation",
"$fuchsia_sdk_root/fidl:fuchsia.sys",
"$fuchsia_sdk_root/fidl:fuchsia.ui.app",
"$fuchsia_sdk_root/fidl:fuchsia.ui.scenic",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"fuchsia.logger.LogSink",
"fuchsia.net.NameLookup",
"fuchsia.posix.socket.Provider",
"fuchsia.scenic.allocation.Allocator",
"fuchsia.sysmem.Allocator",
"fuchsia.timezone.Timezone",
"fuchsia.tracing.provider.Registry",
Expand Down
1 change: 0 additions & 1 deletion shell/platform/fuchsia/flutter/meta/flutter_aot_runner.cmx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"fuchsia.logger.LogSink",
"fuchsia.net.NameLookup",
"fuchsia.posix.socket.Provider",
"fuchsia.scenic.allocation.Allocator",
"fuchsia.sysmem.Allocator",
"fuchsia.timezone.Timezone",
"fuchsia.tracing.provider.Registry",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"fuchsia.logger.LogSink",
"fuchsia.net.NameLookup",
"fuchsia.posix.socket.Provider",
"fuchsia.scenic.allocation.Allocator",
"fuchsia.sysmem.Allocator",
"fuchsia.timezone.Timezone",
"fuchsia.tracing.provider.Registry",
Expand Down
1 change: 0 additions & 1 deletion shell/platform/fuchsia/flutter/meta/flutter_jit_runner.cmx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"fuchsia.logger.LogSink",
"fuchsia.net.NameLookup",
"fuchsia.posix.socket.Provider",
"fuchsia.scenic.allocation.Allocator",
"fuchsia.sysmem.Allocator",
"fuchsia.timezone.Timezone",
"fuchsia.tracing.provider.Registry",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"services": [
"fuchsia.logger.LogSink",
"fuchsia.sys.Environment",
"fuchsia.scenic.allocation.Allocator",
"fuchsia.sysmem.Allocator",
"fuchsia.tracing.provider.Registry",
"fuchsia.ui.input.ImeService",
Expand Down
2 changes: 0 additions & 2 deletions shell/platform/fuchsia/flutter/meta/flutter_runner_tests.cmx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"facets": {
"fuchsia.test": {
"system-services": [
"fuchsia.scenic.allocation.Allocator",
"fuchsia.sysmem.Allocator",
"fuchsia.ui.scenic.Scenic",
"fuchsia.vulkan.loader.Loader"
Expand All @@ -28,7 +27,6 @@
"fuchsia.process.Launcher",
"fuchsia.vulkan.loader.Loader",
"fuchsia.logger.LogSink",
"fuchsia.scenic.allocation.Allocator",
"fuchsia.sysmem.Allocator",
"fuchsia.ui.scenic.Scenic"
]
Expand Down
46 changes: 15 additions & 31 deletions shell/platform/fuchsia/flutter/vulkan_surface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,24 +103,15 @@ bool VulkanSurface::CreateVulkanImage(vulkan::VulkanProvider& vulkan_provider,
VulkanSurface::VulkanSurface(
vulkan::VulkanProvider& vulkan_provider,
fuchsia::sysmem::AllocatorSyncPtr& sysmem_allocator,
fuchsia::scenic::allocation::AllocatorPtr& scenic_allocator,
sk_sp<GrDirectContext> context,
scenic::Session* session,
const SkISize& size)
const SkISize& size,
uint32_t buffer_id)
: vulkan_provider_(vulkan_provider), session_(session), wait_(this) {
FML_DCHECK(session_);

fuchsia::scenic::allocation::BufferCollectionExportToken export_token;
fuchsia::scenic::allocation::BufferCollectionImportToken import_token;
if (zx::eventpair::create(0, &export_token.value, &import_token.value) !=
ZX_OK) {
FML_DLOG(INFO) << "Failed to create event pair";
return;
}

if (!AllocateDeviceMemory(sysmem_allocator, scenic_allocator,
std::move(export_token), std::move(context),
size)) {
if (!AllocateDeviceMemory(sysmem_allocator, std::move(context), size,
buffer_id)) {
FML_DLOG(INFO) << "Could not allocate device memory.";
return;
}
Expand All @@ -130,7 +121,7 @@ VulkanSurface::VulkanSurface(
return;
}

PushSessionImageSetupOps(session, std::move(import_token));
PushSessionImageSetupOps(session);

std::fill(size_history_.begin(), size_history_.end(), SkISize::MakeEmpty());

Expand All @@ -145,6 +136,9 @@ VulkanSurface::~VulkanSurface() {
if (image_id_) {
session_->Enqueue(scenic::NewReleaseResourceCmd(image_id_));
}
if (buffer_id_) {
session_->DeregisterBufferCollection(buffer_id_);
}
wait_.Cancel();
wait_.set_object(ZX_HANDLE_INVALID);
}
Expand Down Expand Up @@ -230,10 +224,9 @@ bool VulkanSurface::CreateFences() {

bool VulkanSurface::AllocateDeviceMemory(
fuchsia::sysmem::AllocatorSyncPtr& sysmem_allocator,
fuchsia::scenic::allocation::AllocatorPtr& scenic_allocator,
fuchsia::scenic::allocation::BufferCollectionExportToken export_token,
sk_sp<GrDirectContext> context,
const SkISize& size) {
const SkISize& size,
uint32_t buffer_id) {
if (size.isEmpty()) {
return false;
}
Expand All @@ -249,14 +242,8 @@ bool VulkanSurface::AllocateDeviceMemory(
status = vulkan_token->Sync();
LOG_AND_RETURN(status != ZX_OK, "Failed to sync token");

scenic_allocator->RegisterBufferCollection(
std::move(export_token), std::move(scenic_token),
[](fuchsia::scenic::allocation::Allocator_RegisterBufferCollection_Result
result) {
if (result.is_err()) {
FML_DLOG(ERROR) << "RegisterBufferCollection failed";
}
});
session_->RegisterBufferCollection(buffer_id, std::move(scenic_token));
buffer_id_ = buffer_id;

VkBufferCollectionCreateInfoFUCHSIA import_info;
import_info.collectionToken = vulkan_token.Unbind().TakeChannel().release();
Expand Down Expand Up @@ -383,14 +370,11 @@ bool VulkanSurface::SetupSkiaSurface(sk_sp<GrDirectContext> context,
return true;
}

void VulkanSurface::PushSessionImageSetupOps(
scenic::Session* session,
fuchsia::scenic::allocation::BufferCollectionImportToken import_token) {
void VulkanSurface::PushSessionImageSetupOps(scenic::Session* session) {
if (image_id_ == 0)
image_id_ = session->AllocResourceId();
session->Enqueue(scenic::NewCreateImage3Cmd(image_id_, sk_surface_->width(),
sk_surface_->height(),
std::move(import_token), 0));
session->Enqueue(scenic::NewCreateImage2Cmd(
image_id_, sk_surface_->width(), sk_surface_->height(), buffer_id_, 0));
}

uint32_t VulkanSurface::GetImageId() {
Expand Down
19 changes: 8 additions & 11 deletions shell/platform/fuchsia/flutter/vulkan_surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ class VulkanSurface final : public SurfaceProducerSurface {
public:
VulkanSurface(vulkan::VulkanProvider& vulkan_provider,
fuchsia::sysmem::AllocatorSyncPtr& sysmem_allocator,
fuchsia::scenic::allocation::AllocatorPtr& scenic_allocator,
sk_sp<GrDirectContext> context,
scenic::Session* session,
const SkISize& size);
const SkISize& size,
uint32_t buffer_id);

~VulkanSurface() override;

Expand Down Expand Up @@ -144,12 +144,10 @@ class VulkanSurface final : public SurfaceProducerSurface {
zx_status_t status,
const zx_packet_signal_t* signal);

bool AllocateDeviceMemory(
fuchsia::sysmem::AllocatorSyncPtr& sysmem_allocator,
fuchsia::scenic::allocation::AllocatorPtr& scenic_allocator,
fuchsia::scenic::allocation::BufferCollectionExportToken export_token,
sk_sp<GrDirectContext> context,
const SkISize& size);
bool AllocateDeviceMemory(fuchsia::sysmem::AllocatorSyncPtr& sysmem_allocator,
sk_sp<GrDirectContext> context,
const SkISize& size,
uint32_t buffer_id);

bool CreateVulkanImage(vulkan::VulkanProvider& vulkan_provider,
const SkISize& size,
Expand All @@ -163,9 +161,7 @@ class VulkanSurface final : public SurfaceProducerSurface {

bool CreateFences();

void PushSessionImageSetupOps(
scenic::Session* session,
fuchsia::scenic::allocation::BufferCollectionImportToken import_token);
void PushSessionImageSetupOps(scenic::Session* session);

void Reset();

Expand All @@ -179,6 +175,7 @@ class VulkanSurface final : public SurfaceProducerSurface {
VkMemoryAllocateInfo vk_memory_info_;
vulkan::VulkanHandle<VkFence> command_buffer_fence_;
sk_sp<SkSurface> sk_surface_;
uint32_t buffer_id_ = 0;
uint32_t image_id_ = 0;
vulkan::VulkanHandle<VkBufferCollectionFUCHSIA> collection_;
zx::event acquire_event_;
Expand Down
8 changes: 2 additions & 6 deletions shell/platform/fuchsia/flutter/vulkan_surface_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ VulkanSurfacePool::VulkanSurfacePool(vulkan::VulkanProvider& vulkan_provider,
sysmem_allocator_->SetDebugClientInfo(GetCurrentProcessName(),
GetCurrentProcessId());
FML_DCHECK(status != ZX_OK);
status = fdio_service_connect(
"/svc/fuchsia.scenic.allocation.Allocator",
scenic_allocator_.NewRequest().TakeChannel().release());
FML_DCHECK(status != ZX_OK);
}

VulkanSurfacePool::~VulkanSurfacePool() {}
Expand Down Expand Up @@ -118,8 +114,8 @@ std::unique_ptr<VulkanSurface> VulkanSurfacePool::CreateSurface(
TRACE_EVENT2("flutter", "VulkanSurfacePool::CreateSurface", "width",
size.width(), "height", size.height());
auto surface = std::make_unique<VulkanSurface>(
vulkan_provider_, sysmem_allocator_, scenic_allocator_, context_,
scenic_session_, size);
vulkan_provider_, sysmem_allocator_, context_, scenic_session_, size,
buffer_id_++);
if (!surface->IsValid()) {
return nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion shell/platform/fuchsia/flutter/vulkan_surface_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ class VulkanSurfacePool final {
sk_sp<GrDirectContext> context_;
scenic::Session* scenic_session_;
fuchsia::sysmem::AllocatorSyncPtr sysmem_allocator_;
fuchsia::scenic::allocation::AllocatorPtr scenic_allocator_;
std::vector<std::unique_ptr<VulkanSurface>> available_surfaces_;
std::unordered_map<uintptr_t, std::unique_ptr<VulkanSurface>>
pending_surfaces_;
uint32_t buffer_id_ = 1;

size_t trace_surfaces_created_ = 0;
size_t trace_surfaces_reused_ = 0;
Expand Down
2 changes: 0 additions & 2 deletions testing/fuchsia/meta/fuchsia_test.cmx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"facets": {
"fuchsia.test": {
"system-services": [
"fuchsia.scenic.allocation.Allocator",
"fuchsia.sysmem.Allocator",
"fuchsia.vulkan.loader.Loader"
]
Expand All @@ -26,7 +25,6 @@
"fuchsia.logger.LogSink",
"fuchsia.process.Launcher",
"fuchsia.settings.Intl",
"fuchsia.scenic.allocation.Allocator",
"fuchsia.sysmem.Allocator",
"fuchsia.tracing.provider.Registry",
"fuchsia.ui.input3.Keyboard",
Expand Down