Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit c6e55c1

Browse files
author
David Reveman
committed
[fuchsia] Use scenic allocator service
Switch to scenic allocator and Image3 API.
1 parent 93744d9 commit c6e55c1

12 files changed

+59
-26
lines changed

shell/platform/fuchsia/flutter/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ template("runner_sources") {
133133
"$fuchsia_sdk_root/fidl:fuchsia.images",
134134
"$fuchsia_sdk_root/fidl:fuchsia.intl",
135135
"$fuchsia_sdk_root/fidl:fuchsia.io",
136+
"$fuchsia_sdk_root/fidl:fuchsia.scenic.allocation",
136137
"$fuchsia_sdk_root/fidl:fuchsia.sys",
137138
"$fuchsia_sdk_root/fidl:fuchsia.ui.app",
138139
"$fuchsia_sdk_root/fidl:fuchsia.ui.scenic",

shell/platform/fuchsia/flutter/meta/flutter_aot_product_runner.cmx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"fuchsia.logger.LogSink",
2121
"fuchsia.net.NameLookup",
2222
"fuchsia.posix.socket.Provider",
23+
"fuchsia.scenic.allocation.Allocator",
2324
"fuchsia.sysmem.Allocator",
2425
"fuchsia.timezone.Timezone",
2526
"fuchsia.tracing.provider.Registry",

shell/platform/fuchsia/flutter/meta/flutter_aot_runner.cmx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"fuchsia.logger.LogSink",
2121
"fuchsia.net.NameLookup",
2222
"fuchsia.posix.socket.Provider",
23+
"fuchsia.scenic.allocation.Allocator",
2324
"fuchsia.sysmem.Allocator",
2425
"fuchsia.timezone.Timezone",
2526
"fuchsia.tracing.provider.Registry",

shell/platform/fuchsia/flutter/meta/flutter_jit_product_runner.cmx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"fuchsia.logger.LogSink",
2222
"fuchsia.net.NameLookup",
2323
"fuchsia.posix.socket.Provider",
24+
"fuchsia.scenic.allocation.Allocator",
2425
"fuchsia.sysmem.Allocator",
2526
"fuchsia.timezone.Timezone",
2627
"fuchsia.tracing.provider.Registry",

shell/platform/fuchsia/flutter/meta/flutter_jit_runner.cmx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"fuchsia.logger.LogSink",
2222
"fuchsia.net.NameLookup",
2323
"fuchsia.posix.socket.Provider",
24+
"fuchsia.scenic.allocation.Allocator",
2425
"fuchsia.sysmem.Allocator",
2526
"fuchsia.timezone.Timezone",
2627
"fuchsia.tracing.provider.Registry",

shell/platform/fuchsia/flutter/meta/flutter_runner_scenic_tests.cmx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"services": [
1313
"fuchsia.logger.LogSink",
1414
"fuchsia.sys.Environment",
15+
"fuchsia.scenic.allocation.Allocator",
1516
"fuchsia.sysmem.Allocator",
1617
"fuchsia.tracing.provider.Registry",
1718
"fuchsia.ui.input.ImeService",

shell/platform/fuchsia/flutter/meta/flutter_runner_tests.cmx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"facets": {
99
"fuchsia.test": {
1010
"system-services": [
11+
"fuchsia.scenic.allocation.Allocator",
1112
"fuchsia.sysmem.Allocator",
1213
"fuchsia.ui.scenic.Scenic",
1314
"fuchsia.vulkan.loader.Loader"
@@ -27,6 +28,7 @@
2728
"fuchsia.process.Launcher",
2829
"fuchsia.vulkan.loader.Loader",
2930
"fuchsia.logger.LogSink",
31+
"fuchsia.scenic.allocation.Allocator",
3032
"fuchsia.sysmem.Allocator",
3133
"fuchsia.ui.scenic.Scenic"
3234
]

shell/platform/fuchsia/flutter/vulkan_surface.cc

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,24 @@ bool VulkanSurface::CreateVulkanImage(vulkan::VulkanProvider& vulkan_provider,
103103
VulkanSurface::VulkanSurface(
104104
vulkan::VulkanProvider& vulkan_provider,
105105
fuchsia::sysmem::AllocatorSyncPtr& sysmem_allocator,
106+
fuchsia::scenic::allocation::AllocatorPtr& scenic_allocator,
106107
sk_sp<GrDirectContext> context,
107108
scenic::Session* session,
108-
const SkISize& size,
109-
uint32_t buffer_id)
109+
const SkISize& size)
110110
: vulkan_provider_(vulkan_provider), session_(session), wait_(this) {
111111
FML_DCHECK(session_);
112112

113-
if (!AllocateDeviceMemory(sysmem_allocator, std::move(context), size,
114-
buffer_id)) {
113+
fuchsia::scenic::allocation::BufferCollectionExportToken export_token;
114+
fuchsia::scenic::allocation::BufferCollectionImportToken import_token;
115+
if (zx::eventpair::create(0, &export_token.value, &import_token.value) !=
116+
ZX_OK) {
117+
FML_DLOG(INFO) << "Failed to create event pair";
118+
return;
119+
}
120+
121+
if (!AllocateDeviceMemory(sysmem_allocator, scenic_allocator,
122+
std::move(export_token), std::move(context),
123+
size)) {
115124
FML_DLOG(INFO) << "Could not allocate device memory.";
116125
return;
117126
}
@@ -121,7 +130,7 @@ VulkanSurface::VulkanSurface(
121130
return;
122131
}
123132

124-
PushSessionImageSetupOps(session);
133+
PushSessionImageSetupOps(session, std::move(import_token));
125134

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

@@ -136,9 +145,6 @@ VulkanSurface::~VulkanSurface() {
136145
if (image_id_) {
137146
session_->Enqueue(scenic::NewReleaseResourceCmd(image_id_));
138147
}
139-
if (buffer_id_) {
140-
session_->DeregisterBufferCollection(buffer_id_);
141-
}
142148
wait_.Cancel();
143149
wait_.set_object(ZX_HANDLE_INVALID);
144150
}
@@ -224,9 +230,10 @@ bool VulkanSurface::CreateFences() {
224230

225231
bool VulkanSurface::AllocateDeviceMemory(
226232
fuchsia::sysmem::AllocatorSyncPtr& sysmem_allocator,
233+
fuchsia::scenic::allocation::AllocatorPtr& scenic_allocator,
234+
fuchsia::scenic::allocation::BufferCollectionExportToken export_token,
227235
sk_sp<GrDirectContext> context,
228-
const SkISize& size,
229-
uint32_t buffer_id) {
236+
const SkISize& size) {
230237
if (size.isEmpty()) {
231238
return false;
232239
}
@@ -242,8 +249,14 @@ bool VulkanSurface::AllocateDeviceMemory(
242249
status = vulkan_token->Sync();
243250
LOG_AND_RETURN(status != ZX_OK, "Failed to sync token");
244251

245-
session_->RegisterBufferCollection(buffer_id, std::move(scenic_token));
246-
buffer_id_ = buffer_id;
252+
scenic_allocator->RegisterBufferCollection(
253+
std::move(export_token), std::move(scenic_token),
254+
[](fuchsia::scenic::allocation::Allocator_RegisterBufferCollection_Result
255+
result) {
256+
if (result.is_err()) {
257+
FML_DLOG(ERROR) << "RegisterBufferCollection failed";
258+
}
259+
});
247260

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

373-
void VulkanSurface::PushSessionImageSetupOps(scenic::Session* session) {
386+
void VulkanSurface::PushSessionImageSetupOps(
387+
scenic::Session* session,
388+
fuchsia::scenic::allocation::BufferCollectionImportToken import_token) {
374389
if (image_id_ == 0)
375390
image_id_ = session->AllocResourceId();
376-
session->Enqueue(scenic::NewCreateImage2Cmd(
377-
image_id_, sk_surface_->width(), sk_surface_->height(), buffer_id_, 0));
391+
session->Enqueue(scenic::NewCreateImage3Cmd(image_id_, sk_surface_->width(),
392+
sk_surface_->height(),
393+
std::move(import_token), 0));
378394
}
379395

380396
uint32_t VulkanSurface::GetImageId() {

shell/platform/fuchsia/flutter/vulkan_surface.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ class VulkanSurface final : public SurfaceProducerSurface {
7171
public:
7272
VulkanSurface(vulkan::VulkanProvider& vulkan_provider,
7373
fuchsia::sysmem::AllocatorSyncPtr& sysmem_allocator,
74+
fuchsia::scenic::allocation::AllocatorPtr& scenic_allocator,
7475
sk_sp<GrDirectContext> context,
7576
scenic::Session* session,
76-
const SkISize& size,
77-
uint32_t buffer_id);
77+
const SkISize& size);
7878

7979
~VulkanSurface() override;
8080

@@ -144,10 +144,12 @@ class VulkanSurface final : public SurfaceProducerSurface {
144144
zx_status_t status,
145145
const zx_packet_signal_t* signal);
146146

147-
bool AllocateDeviceMemory(fuchsia::sysmem::AllocatorSyncPtr& sysmem_allocator,
148-
sk_sp<GrDirectContext> context,
149-
const SkISize& size,
150-
uint32_t buffer_id);
147+
bool AllocateDeviceMemory(
148+
fuchsia::sysmem::AllocatorSyncPtr& sysmem_allocator,
149+
fuchsia::scenic::allocation::AllocatorPtr& scenic_allocator,
150+
fuchsia::scenic::allocation::BufferCollectionExportToken export_token,
151+
sk_sp<GrDirectContext> context,
152+
const SkISize& size);
151153

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

162164
bool CreateFences();
163165

164-
void PushSessionImageSetupOps(scenic::Session* session);
166+
void PushSessionImageSetupOps(
167+
scenic::Session* session,
168+
fuchsia::scenic::allocation::BufferCollectionImportToken import_token);
165169

166170
void Reset();
167171

@@ -175,7 +179,6 @@ class VulkanSurface final : public SurfaceProducerSurface {
175179
VkMemoryAllocateInfo vk_memory_info_;
176180
vulkan::VulkanHandle<VkFence> command_buffer_fence_;
177181
sk_sp<SkSurface> sk_surface_;
178-
uint32_t buffer_id_ = 0;
179182
uint32_t image_id_ = 0;
180183
vulkan::VulkanHandle<VkBufferCollectionFUCHSIA> collection_;
181184
zx::event acquire_event_;

shell/platform/fuchsia/flutter/vulkan_surface_pool.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ VulkanSurfacePool::VulkanSurfacePool(vulkan::VulkanProvider& vulkan_provider,
4141
sysmem_allocator_->SetDebugClientInfo(GetCurrentProcessName(),
4242
GetCurrentProcessId());
4343
FML_DCHECK(status != ZX_OK);
44+
status = fdio_service_connect(
45+
"/svc/fuchsia.scenic.allocation.Allocator",
46+
scenic_allocator_.NewRequest().TakeChannel().release());
47+
FML_DCHECK(status != ZX_OK);
4448
}
4549

4650
VulkanSurfacePool::~VulkanSurfacePool() {}
@@ -114,8 +118,8 @@ std::unique_ptr<VulkanSurface> VulkanSurfacePool::CreateSurface(
114118
TRACE_EVENT2("flutter", "VulkanSurfacePool::CreateSurface", "width",
115119
size.width(), "height", size.height());
116120
auto surface = std::make_unique<VulkanSurface>(
117-
vulkan_provider_, sysmem_allocator_, context_, scenic_session_, size,
118-
buffer_id_++);
121+
vulkan_provider_, sysmem_allocator_, scenic_allocator_, context_,
122+
scenic_session_, size);
119123
if (!surface->IsValid()) {
120124
return nullptr;
121125
}

0 commit comments

Comments
 (0)