[fuchsia] Use scenic allocator service (flutter/engine#25385)
Switch to scenic allocator and Image3 API. Co-authored-by: David Reveman <reveman@google.com>
This commit is contained in:
@@ -134,6 +134,7 @@ 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",
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
"fuchsia.logger.LogSink",
|
||||
"fuchsia.net.NameLookup",
|
||||
"fuchsia.posix.socket.Provider",
|
||||
"fuchsia.scenic.allocation.Allocator",
|
||||
"fuchsia.sysmem.Allocator",
|
||||
"fuchsia.timezone.Timezone",
|
||||
"fuchsia.tracing.provider.Registry",
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
"fuchsia.logger.LogSink",
|
||||
"fuchsia.net.NameLookup",
|
||||
"fuchsia.posix.socket.Provider",
|
||||
"fuchsia.scenic.allocation.Allocator",
|
||||
"fuchsia.sysmem.Allocator",
|
||||
"fuchsia.timezone.Timezone",
|
||||
"fuchsia.tracing.provider.Registry",
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
"fuchsia.logger.LogSink",
|
||||
"fuchsia.net.NameLookup",
|
||||
"fuchsia.posix.socket.Provider",
|
||||
"fuchsia.scenic.allocation.Allocator",
|
||||
"fuchsia.sysmem.Allocator",
|
||||
"fuchsia.timezone.Timezone",
|
||||
"fuchsia.tracing.provider.Registry",
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
"fuchsia.logger.LogSink",
|
||||
"fuchsia.net.NameLookup",
|
||||
"fuchsia.posix.socket.Provider",
|
||||
"fuchsia.scenic.allocation.Allocator",
|
||||
"fuchsia.sysmem.Allocator",
|
||||
"fuchsia.timezone.Timezone",
|
||||
"fuchsia.tracing.provider.Registry",
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
"services": [
|
||||
"fuchsia.logger.LogSink",
|
||||
"fuchsia.sys.Environment",
|
||||
"fuchsia.scenic.allocation.Allocator",
|
||||
"fuchsia.sysmem.Allocator",
|
||||
"fuchsia.tracing.provider.Registry",
|
||||
"fuchsia.ui.input.ImeService",
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"facets": {
|
||||
"fuchsia.test": {
|
||||
"system-services": [
|
||||
"fuchsia.scenic.allocation.Allocator",
|
||||
"fuchsia.sysmem.Allocator",
|
||||
"fuchsia.ui.scenic.Scenic",
|
||||
"fuchsia.vulkan.loader.Loader"
|
||||
@@ -27,6 +28,7 @@
|
||||
"fuchsia.process.Launcher",
|
||||
"fuchsia.vulkan.loader.Loader",
|
||||
"fuchsia.logger.LogSink",
|
||||
"fuchsia.scenic.allocation.Allocator",
|
||||
"fuchsia.sysmem.Allocator",
|
||||
"fuchsia.ui.scenic.Scenic"
|
||||
]
|
||||
|
||||
@@ -103,15 +103,24 @@ 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,
|
||||
uint32_t buffer_id)
|
||||
const SkISize& size)
|
||||
: vulkan_provider_(vulkan_provider), session_(session), wait_(this) {
|
||||
FML_DCHECK(session_);
|
||||
|
||||
if (!AllocateDeviceMemory(sysmem_allocator, std::move(context), size,
|
||||
buffer_id)) {
|
||||
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)) {
|
||||
FML_DLOG(INFO) << "Could not allocate device memory.";
|
||||
return;
|
||||
}
|
||||
@@ -121,7 +130,7 @@ VulkanSurface::VulkanSurface(
|
||||
return;
|
||||
}
|
||||
|
||||
PushSessionImageSetupOps(session);
|
||||
PushSessionImageSetupOps(session, std::move(import_token));
|
||||
|
||||
std::fill(size_history_.begin(), size_history_.end(), SkISize::MakeEmpty());
|
||||
|
||||
@@ -136,9 +145,6 @@ 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);
|
||||
}
|
||||
@@ -224,9 +230,10 @@ 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,
|
||||
uint32_t buffer_id) {
|
||||
const SkISize& size) {
|
||||
if (size.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
@@ -242,8 +249,14 @@ bool VulkanSurface::AllocateDeviceMemory(
|
||||
status = vulkan_token->Sync();
|
||||
LOG_AND_RETURN(status != ZX_OK, "Failed to sync token");
|
||||
|
||||
session_->RegisterBufferCollection(buffer_id, std::move(scenic_token));
|
||||
buffer_id_ = buffer_id;
|
||||
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";
|
||||
}
|
||||
});
|
||||
|
||||
VkBufferCollectionCreateInfoFUCHSIA import_info;
|
||||
import_info.collectionToken = vulkan_token.Unbind().TakeChannel().release();
|
||||
@@ -370,11 +383,14 @@ bool VulkanSurface::SetupSkiaSurface(sk_sp<GrDirectContext> context,
|
||||
return true;
|
||||
}
|
||||
|
||||
void VulkanSurface::PushSessionImageSetupOps(scenic::Session* session) {
|
||||
void VulkanSurface::PushSessionImageSetupOps(
|
||||
scenic::Session* session,
|
||||
fuchsia::scenic::allocation::BufferCollectionImportToken import_token) {
|
||||
if (image_id_ == 0)
|
||||
image_id_ = session->AllocResourceId();
|
||||
session->Enqueue(scenic::NewCreateImage2Cmd(
|
||||
image_id_, sk_surface_->width(), sk_surface_->height(), buffer_id_, 0));
|
||||
session->Enqueue(scenic::NewCreateImage3Cmd(image_id_, sk_surface_->width(),
|
||||
sk_surface_->height(),
|
||||
std::move(import_token), 0));
|
||||
}
|
||||
|
||||
uint32_t VulkanSurface::GetImageId() {
|
||||
|
||||
@@ -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,
|
||||
uint32_t buffer_id);
|
||||
const SkISize& size);
|
||||
|
||||
~VulkanSurface() override;
|
||||
|
||||
@@ -144,10 +144,12 @@ class VulkanSurface final : public SurfaceProducerSurface {
|
||||
zx_status_t status,
|
||||
const zx_packet_signal_t* signal);
|
||||
|
||||
bool AllocateDeviceMemory(fuchsia::sysmem::AllocatorSyncPtr& sysmem_allocator,
|
||||
sk_sp<GrDirectContext> context,
|
||||
const SkISize& size,
|
||||
uint32_t buffer_id);
|
||||
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 CreateVulkanImage(vulkan::VulkanProvider& vulkan_provider,
|
||||
const SkISize& size,
|
||||
@@ -161,7 +163,9 @@ class VulkanSurface final : public SurfaceProducerSurface {
|
||||
|
||||
bool CreateFences();
|
||||
|
||||
void PushSessionImageSetupOps(scenic::Session* session);
|
||||
void PushSessionImageSetupOps(
|
||||
scenic::Session* session,
|
||||
fuchsia::scenic::allocation::BufferCollectionImportToken import_token);
|
||||
|
||||
void Reset();
|
||||
|
||||
@@ -175,7 +179,6 @@ 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_;
|
||||
|
||||
@@ -41,6 +41,10 @@ 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() {}
|
||||
@@ -114,8 +118,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_, context_, scenic_session_, size,
|
||||
buffer_id_++);
|
||||
vulkan_provider_, sysmem_allocator_, scenic_allocator_, context_,
|
||||
scenic_session_, size);
|
||||
if (!surface->IsValid()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"facets": {
|
||||
"fuchsia.test": {
|
||||
"system-services": [
|
||||
"fuchsia.scenic.allocation.Allocator",
|
||||
"fuchsia.sysmem.Allocator",
|
||||
"fuchsia.vulkan.loader.Loader"
|
||||
]
|
||||
@@ -25,6 +26,7 @@
|
||||
"fuchsia.logger.LogSink",
|
||||
"fuchsia.process.Launcher",
|
||||
"fuchsia.settings.Intl",
|
||||
"fuchsia.scenic.allocation.Allocator",
|
||||
"fuchsia.sysmem.Allocator",
|
||||
"fuchsia.tracing.provider.Registry",
|
||||
"fuchsia.ui.input3.Keyboard",
|
||||
|
||||
Reference in New Issue
Block a user