@@ -28,13 +28,13 @@ namespace {
2828
2929constexpr SkColorType kSkiaColorType = kRGBA_8888_SkColorType ;
3030
31- uint32_t BytesPerRow (const fuchsia::sysmem ::SingleBufferSettings& settings,
31+ uint32_t BytesPerRow (const fuchsia::sysmem2 ::SingleBufferSettings& settings,
3232 uint32_t bytes_per_pixel,
3333 uint32_t image_width) {
3434 const uint32_t bytes_per_row_divisor =
35- settings.image_format_constraints .bytes_per_row_divisor ;
35+ settings.image_format_constraints () .bytes_per_row_divisor () ;
3636 const uint32_t min_bytes_per_row =
37- settings.image_format_constraints .min_bytes_per_row ;
37+ settings.image_format_constraints () .min_bytes_per_row () ;
3838 const uint32_t unrounded_bytes_per_row =
3939 std::max (image_width * bytes_per_pixel, min_bytes_per_row);
4040 const uint32_t roundup_bytes =
@@ -46,7 +46,7 @@ uint32_t BytesPerRow(const fuchsia::sysmem::SingleBufferSettings& settings,
4646} // namespace
4747
4848SoftwareSurface::SoftwareSurface (
49- fuchsia::sysmem ::AllocatorSyncPtr& sysmem_allocator,
49+ fuchsia::sysmem2 ::AllocatorSyncPtr& sysmem_allocator,
5050 fuchsia::ui::composition::AllocatorPtr& flatland_allocator,
5151 const SkISize& size)
5252 : wait_for_surface_read_finished_(this ) {
@@ -102,7 +102,7 @@ bool SoftwareSurface::CreateFences() {
102102}
103103
104104bool SoftwareSurface::SetupSkiaSurface (
105- fuchsia::sysmem ::AllocatorSyncPtr& sysmem_allocator,
105+ fuchsia::sysmem2 ::AllocatorSyncPtr& sysmem_allocator,
106106 fuchsia::ui::composition::AllocatorPtr& flatland_allocator,
107107 const SkISize& size) {
108108 if (size.isEmpty ()) {
@@ -112,9 +112,10 @@ bool SoftwareSurface::SetupSkiaSurface(
112112
113113 // Allocate a "local" sysmem token to represent flutter's handle to the
114114 // sysmem buffer.
115- fuchsia::sysmem::BufferCollectionTokenSyncPtr local_token;
116- zx_status_t allocate_status =
117- sysmem_allocator->AllocateSharedCollection (local_token.NewRequest ());
115+ fuchsia::sysmem2::BufferCollectionTokenSyncPtr local_token;
116+ zx_status_t allocate_status = sysmem_allocator->AllocateSharedCollection (
117+ std::move (fuchsia::sysmem2::AllocatorAllocateSharedCollectionRequest{}
118+ .set_token_request (local_token.NewRequest ())));
118119 if (allocate_status != ZX_OK) {
119120 FML_LOG (ERROR) << " Failed to allocate collection: "
120121 << zx_status_get_string (allocate_status);
@@ -123,14 +124,19 @@ bool SoftwareSurface::SetupSkiaSurface(
123124
124125 // Create a single Duplicate of the token and Sync it; the single duplicate
125126 // token represents scenic's handle to the sysmem buffer.
126- std::vector< fuchsia::sysmem::BufferCollectionTokenHandle> duplicate_tokens ;
127+ fuchsia::sysmem2::BufferCollectionToken_DuplicateSync_Result duplicate_result ;
127128 zx_status_t duplicate_status = local_token->DuplicateSync (
128- std::vector<zx_rights_t >{ZX_RIGHT_SAME_RIGHTS}, &duplicate_tokens);
129+ std::move (fuchsia::sysmem2::BufferCollectionTokenDuplicateSyncRequest{}
130+ .set_rights_attenuation_masks (
131+ std::vector<zx_rights_t >{ZX_RIGHT_SAME_RIGHTS})),
132+ &duplicate_result);
129133 if (duplicate_status != ZX_OK) {
130134 FML_LOG (ERROR) << " Failed to duplicate collection token: "
131135 << zx_status_get_string (duplicate_status);
132136 return false ;
133137 }
138+ auto duplicate_tokens =
139+ std::move (*duplicate_result.response ().mutable_tokens ());
134140 if (duplicate_tokens.size () != 1u ) {
135141 FML_LOG (ERROR) << " Failed to duplicate collection token: Incorrect number "
136142 " of tokens returned." ;
@@ -153,7 +159,8 @@ bool SoftwareSurface::SetupSkiaSurface(
153159
154160 fuchsia::ui::composition::RegisterBufferCollectionArgs args;
155161 args.set_export_token (std::move (export_token));
156- args.set_buffer_collection_token (std::move (scenic_token));
162+ args.set_buffer_collection_token (
163+ fuchsia::sysmem::BufferCollectionTokenHandle (scenic_token.TakeChannel ()));
157164 args.set_usage (
158165 fuchsia::ui::composition::RegisterBufferCollectionUsage::DEFAULT);
159166 flatland_allocator->RegisterBufferCollection (
@@ -167,9 +174,11 @@ bool SoftwareSurface::SetupSkiaSurface(
167174 });
168175
169176 // Acquire flutter's local handle to the sysmem buffer.
170- fuchsia::sysmem::BufferCollectionSyncPtr buffer_collection;
171- zx_status_t bind_status = sysmem_allocator->BindSharedCollection (
172- std::move (local_token), buffer_collection.NewRequest ());
177+ fuchsia::sysmem2::BufferCollectionSyncPtr buffer_collection;
178+ zx_status_t bind_status = sysmem_allocator->BindSharedCollection (std::move (
179+ fuchsia::sysmem2::AllocatorBindSharedCollectionRequest{}
180+ .set_token (std::move (local_token))
181+ .set_buffer_collection_request (buffer_collection.NewRequest ())));
173182 if (bind_status != ZX_OK) {
174183 FML_LOG (ERROR) << " Failed to bind collection token: "
175184 << zx_status_get_string (bind_status);
@@ -178,63 +187,66 @@ bool SoftwareSurface::SetupSkiaSurface(
178187
179188 // Set flutter's constraints on the sysmem buffer. Software rendering only
180189 // requires CPU access to the surface and a basic R8G8B8A8 pixel format.
181- fuchsia::sysmem::BufferCollectionConstraints constraints;
182- constraints.min_buffer_count = 1 ;
183- constraints.usage .cpu =
184- fuchsia::sysmem::cpuUsageWrite | fuchsia::sysmem::cpuUsageWriteOften;
185- constraints.has_buffer_memory_constraints = true ;
186- constraints.buffer_memory_constraints .physically_contiguous_required = false ;
187- constraints.buffer_memory_constraints .secure_required = false ;
188- constraints.buffer_memory_constraints .ram_domain_supported = true ;
189- constraints.buffer_memory_constraints .cpu_domain_supported = true ;
190- constraints.buffer_memory_constraints .inaccessible_domain_supported = false ;
191- constraints.image_format_constraints_count = 1 ;
192- fuchsia::sysmem::ImageFormatConstraints& image_constraints =
193- constraints.image_format_constraints [0 ];
194- image_constraints = fuchsia::sysmem::ImageFormatConstraints ();
195- image_constraints.min_coded_width = static_cast <uint32_t >(size.fWidth );
196- image_constraints.min_coded_height = static_cast <uint32_t >(size.fHeight );
197- image_constraints.min_bytes_per_row = static_cast <uint32_t >(size.fWidth ) * 4 ;
198- image_constraints.pixel_format .type =
199- fuchsia::sysmem::PixelFormatType::R8G8B8A8;
200- image_constraints.color_spaces_count = 1 ;
201- image_constraints.color_space [0 ].type = fuchsia::sysmem::ColorSpaceType::SRGB;
202- image_constraints.pixel_format .has_format_modifier = true ;
203- image_constraints.pixel_format .format_modifier .value =
204- fuchsia::sysmem::FORMAT_MODIFIER_LINEAR;
205- zx_status_t set_constraints_status =
206- buffer_collection->SetConstraints (true , constraints);
190+ fuchsia::sysmem2::BufferCollectionConstraints constraints;
191+ constraints.set_min_buffer_count (1 );
192+ constraints.mutable_usage ()->set_cpu (fuchsia::sysmem2::CPU_USAGE_WRITE |
193+ fuchsia::sysmem2::CPU_USAGE_WRITE_OFTEN);
194+ auto & bmc = *constraints.mutable_buffer_memory_constraints ();
195+ bmc.set_physically_contiguous_required (false );
196+ bmc.set_secure_required (false );
197+ bmc.set_ram_domain_supported (true );
198+ bmc.set_cpu_domain_supported (true );
199+ bmc.set_inaccessible_domain_supported (false );
200+ auto & ifc = constraints.mutable_image_format_constraints ()->emplace_back ();
201+ ifc.set_min_size (fuchsia::math::SizeU{static_cast <uint32_t >(size.fWidth ),
202+ static_cast <uint32_t >(size.fHeight )});
203+ ifc.set_min_bytes_per_row (static_cast <uint32_t >(size.fWidth ) * 4 );
204+ ifc.set_pixel_format (fuchsia::images2::PixelFormat::R8G8B8A8);
205+ ifc.mutable_color_spaces ()->emplace_back (fuchsia::images2::ColorSpace::SRGB);
206+ ifc.set_pixel_format_modifier (fuchsia::images2::PixelFormatModifier::LINEAR);
207+ zx_status_t set_constraints_status = buffer_collection->SetConstraints (
208+ std::move (fuchsia::sysmem2::BufferCollectionSetConstraintsRequest{}
209+ .set_constraints (std::move (constraints))));
207210 if (set_constraints_status != ZX_OK) {
208211 FML_LOG (ERROR) << " Failed to set constraints: "
209212 << zx_status_get_string (set_constraints_status);
210213 return false ;
211214 }
212215
213216 // Wait for sysmem to allocate, now that constraints are set.
214- fuchsia::sysmem::BufferCollectionInfo_2 buffer_collection_info;
215- zx_status_t allocation_status = ZX_OK ;
217+ fuchsia::sysmem2::BufferCollection_WaitForAllBuffersAllocated_Result
218+ wait_result ;
216219 zx_status_t wait_for_allocated_status =
217- buffer_collection->WaitForBuffersAllocated (&allocation_status,
218- &buffer_collection_info);
219- if (allocation_status != ZX_OK) {
220- FML_LOG (ERROR) << " Failed to allocate: "
221- << zx_status_get_string (allocation_status);
222- return false ;
223- }
220+ buffer_collection->WaitForAllBuffersAllocated (&wait_result);
224221 if (wait_for_allocated_status != ZX_OK) {
225222 FML_LOG (ERROR) << " Failed to wait for allocate: "
226223 << zx_status_get_string (wait_for_allocated_status);
227224 return false ;
228225 }
226+ if (!wait_result.is_response ()) {
227+ if (wait_result.is_framework_err ()) {
228+ FML_LOG (ERROR) << " Failed to allocate (framework_err): "
229+ << fidl::ToUnderlying (wait_result.framework_err ());
230+ } else {
231+ FML_DCHECK (wait_result.is_err ());
232+ FML_LOG (ERROR) << " Failed to allocate (err): "
233+ << static_cast <uint32_t >(wait_result.err ());
234+ }
235+ return false ;
236+ }
237+ auto buffer_collection_info =
238+ std::move (*wait_result.response ().mutable_buffer_collection_info ());
229239
230240 // Cache the allocated surface VMO and metadata.
231- FML_CHECK (buffer_collection_info.settings .buffer_settings .size_bytes != 0 );
232- FML_CHECK (buffer_collection_info.buffers [0 ].vmo != ZX_HANDLE_INVALID);
233- surface_vmo_ = std::move (buffer_collection_info.buffers [0 ].vmo );
241+ FML_CHECK (buffer_collection_info.settings ().buffer_settings ().size_bytes () !=
242+ 0 );
243+ FML_CHECK (buffer_collection_info.buffers ()[0 ].vmo ().is_valid ());
244+ surface_vmo_ =
245+ std::move (*buffer_collection_info.mutable_buffers ()->at (0 ).mutable_vmo ());
234246 surface_size_bytes_ =
235- buffer_collection_info.settings .buffer_settings .size_bytes ;
236- if (buffer_collection_info.settings .buffer_settings .coherency_domain ==
237- fuchsia::sysmem ::CoherencyDomain::RAM) {
247+ buffer_collection_info.settings () .buffer_settings () .size_bytes () ;
248+ if (buffer_collection_info.settings () .buffer_settings () .coherency_domain () ==
249+ fuchsia::sysmem2 ::CoherencyDomain::RAM) {
238250 // RAM coherency domain requires a cache clean when writes are finished.
239251 needs_cache_clean_ = true ;
240252 }
@@ -252,7 +264,7 @@ bool SoftwareSurface::SetupSkiaSurface(
252264
253265 // Now that the buffer is CPU-readable, it's safe to discard flutter's
254266 // connection to sysmem.
255- zx_status_t close_status = buffer_collection->Close ();
267+ zx_status_t close_status = buffer_collection->Release ();
256268 if (close_status != ZX_OK) {
257269 FML_LOG (ERROR) << " Failed to close buffer: "
258270 << zx_status_get_string (close_status);
@@ -261,9 +273,9 @@ bool SoftwareSurface::SetupSkiaSurface(
261273
262274 // Wrap the buffer in a software-rendered Skia surface.
263275 const uint64_t vmo_offset =
264- buffer_collection_info.buffers [0 ].vmo_usable_start ;
276+ buffer_collection_info.buffers () [0 ].vmo_usable_start () ;
265277 const size_t vmo_stride =
266- BytesPerRow (buffer_collection_info.settings , 4u , size.width ());
278+ BytesPerRow (buffer_collection_info.settings () , 4u , size.width ());
267279 SkSurfaceProps sk_surface_props (0 , kUnknown_SkPixelGeometry );
268280 sk_surface_ = SkSurfaces::WrapPixels (
269281 SkImageInfo::Make (size, kSkiaColorType , kPremul_SkAlphaType ,
0 commit comments