Flutter Engine
 
Loading...
Searching...
No Matches
fake_flatland.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "fake_flatland.h"
6
7#include <zircon/types.h>
8
9#include <algorithm> // For std::remove_if
10#include <memory>
11
12#include "flutter/fml/logging.h"
13
15
17 : allocator_binding_(this),
18 flatland_binding_(this),
19 present_handler_([](auto args) {}) {}
20
22
23fuchsia::ui::composition::AllocatorHandle FakeFlatland::ConnectAllocator(
24 async_dispatcher_t* dispatcher) {
25 FML_CHECK(!allocator_binding_.is_bound());
26
27 fuchsia::ui::composition::AllocatorHandle allocator;
28 allocator_binding_.Bind(allocator.NewRequest(), dispatcher);
29
30 return allocator;
31}
32
33fuchsia::ui::composition::FlatlandHandle FakeFlatland::ConnectFlatland(
34 async_dispatcher_t* dispatcher) {
35 FML_CHECK(!flatland_binding_.is_bound());
36
37 fuchsia::ui::composition::FlatlandHandle flatland;
38 flatland_binding_.Bind(flatland.NewRequest(), dispatcher);
39
40 return flatland;
41}
42
43void FakeFlatland::Disconnect(fuchsia::ui::composition::FlatlandError error) {
44 flatland_binding_.events().OnError(error);
45 flatland_binding_.Unbind();
46 allocator_binding_
47 .Unbind(); // TODO(fxb/85619): Does the real Scenic unbind this when
48 // Flatland has an error? Or is it independent?
49}
50
52 present_handler_ =
53 present_handler ? std::move(present_handler) : [](auto args) {};
54}
55
57 fuchsia::ui::composition::OnNextFrameBeginValues
58 on_next_frame_begin_values) {
59 flatland_binding_.events().OnNextFrameBegin(
60 std::move(on_next_frame_begin_values));
61}
62
64 fuchsia::scenic::scheduling::FramePresentedInfo frame_presented_info) {
65 flatland_binding_.events().OnFramePresented(std::move(frame_presented_info));
66}
67
68void FakeFlatland::NotImplemented_(const std::string& name) {
69 FML_LOG(FATAL) << "FakeFlatland does not implement " << name;
70}
71
72void FakeFlatland::RegisterBufferCollection(
73 fuchsia::ui::composition::RegisterBufferCollectionArgs args,
74 RegisterBufferCollectionCallback callback) {
75 auto [export_token_koid, _] = GetKoids(args.export_token());
76
77 // Callers must not set both.
78 ZX_ASSERT(!args.has_buffer_collection_token2() ||
79 !args.has_buffer_collection_token());
80 fuchsia::sysmem2::BufferCollectionTokenHandle sysmem_token;
81 if (args.has_buffer_collection_token2()) {
82 sysmem_token = std::move(*args.mutable_buffer_collection_token2());
83 } else {
84 sysmem_token = fuchsia::sysmem2::BufferCollectionTokenHandle(
85 args.mutable_buffer_collection_token()->TakeChannel());
86 }
87
88 auto [__, emplace_binding_success] =
89 graph_bindings_.buffer_collections.emplace(
90 export_token_koid,
91 BufferCollectionBinding{
92 .export_token = std::move(*args.mutable_export_token()),
93 .sysmem_token = std::move(sysmem_token),
94 .usage = args.usage(),
95 });
96 // TODO(fxb/85619): Disconnect the Allocator here
97 FML_CHECK(emplace_binding_success)
98 << "FakeFlatland::RegisterBufferCollection: BufferCollection already "
99 "exists with koid "
100 << export_token_koid;
101}
102
103void FakeFlatland::Present(fuchsia::ui::composition::PresentArgs args) {
104 // Each FIDL call between this `Present()` and the last one mutated the
105 // `pending_graph_` independently of the `current_graph_`. Only the
106 // `current_graph_` is visible externally in the test.
107 //
108 // `Present()` updates the current graph with a deep clone of the pending one.
109 current_graph_ = pending_graph_.Clone();
110
111 present_handler_(std::move(args));
112}
113
114void FakeFlatland::CreateView(
115 fuchsia::ui::views::ViewCreationToken token,
116 fidl::InterfaceRequest<fuchsia::ui::composition::ParentViewportWatcher>
117 parent_viewport_watcher) {
118 CreateView2(std::move(token), fuchsia::ui::views::ViewIdentityOnCreation{},
119 fuchsia::ui::composition::ViewBoundProtocols{},
120 std::move(parent_viewport_watcher));
121}
122
123void FakeFlatland::CreateView2(
124 fuchsia::ui::views::ViewCreationToken token,
125 fuchsia::ui::views::ViewIdentityOnCreation view_identity,
126 fuchsia::ui::composition::ViewBoundProtocols view_protocols,
127 fidl::InterfaceRequest<fuchsia::ui::composition::ParentViewportWatcher>
128 parent_viewport_watcher) {
129 // TODO(fxb/85619): Handle a 2nd CreateView call
130 FML_CHECK(!pending_graph_.view.has_value());
131 FML_CHECK(!graph_bindings_.viewport_watcher.has_value());
132
133 auto view_token_koids = GetKoids(token);
134 auto view_ref_koids = GetKoids(view_identity.view_ref);
135 auto view_ref_control_koids = GetKoids(view_identity.view_ref_control);
136 FML_CHECK(view_ref_koids.first == view_ref_control_koids.second);
137 FML_CHECK(view_ref_koids.second == view_ref_control_koids.first);
138
139 pending_graph_.view.emplace(FakeView{
140 .view_token = view_token_koids.first,
141 .view_ref = view_ref_koids.first,
142 .view_ref_control = view_ref_control_koids.first,
143 .view_ref_focused =
144 view_protocols.has_view_ref_focused()
145 ? GetKoids(view_protocols.view_ref_focused()).first
146 : zx_koid_t{},
147 .focuser = view_protocols.has_view_focuser()
148 ? GetKoids(view_protocols.view_focuser()).first
149 : zx_koid_t{},
150 .touch_source = view_protocols.has_touch_source()
151 ? GetKoids(view_protocols.touch_source()).first
152 : zx_koid_t{},
153 .mouse_source = view_protocols.has_mouse_source()
154 ? GetKoids(view_protocols.mouse_source()).first
155 : zx_koid_t{},
156 .parent_viewport_watcher = GetKoids(parent_viewport_watcher).first,
157 });
158 graph_bindings_.viewport_watcher.emplace(
159 view_token_koids.first,
160 ParentViewportWatcher(
161 std::move(token), std::move(view_identity), std::move(view_protocols),
162 std::move(parent_viewport_watcher), flatland_binding_.dispatcher()));
163}
164
165void FakeFlatland::CreateTransform(
166 fuchsia::ui::composition::TransformId transform_id) {
167 if (transform_id.value == 0) {
168 // TODO(fxb/85619): Raise a FlatlandError here
169 FML_CHECK(false)
170 << "FakeFlatland::CreateTransform: TransformId 0 is invalid.";
171 return;
172 }
173 if (pending_graph_.transform_map.count(transform_id.value) != 0) {
174 // TODO(fxb/85619): Raise a FlatlandError here
175 FML_CHECK(false) << "FakeFlatland::CreateTransform: TransformId "
176 << transform_id.value << " is already in use.";
177 return;
178 }
179
180 auto [emplaced_transform, emplace_success] =
181 pending_graph_.transform_map.emplace(
182 transform_id.value, std::make_shared<FakeTransform>(FakeTransform{
183 .id = transform_id,
184 }));
185 // TODO(fxb/85619): Raise a FlatlandError here
186 FML_CHECK(emplace_success)
187 << "FakeFlatland::CreateTransform: Internal error (transform_map) adding "
188 "transform with id: "
189 << transform_id.value;
190
191 auto [_, emplace_parent_success] = parents_map_.emplace(
192 transform_id.value,
193 std::make_pair(std::weak_ptr<FakeTransform>(),
194 std::weak_ptr(emplaced_transform->second)));
195 // TODO(fxb/85619): Raise a FlatlandError here
196 FML_CHECK(emplace_parent_success)
197 << "FakeFlatland::CreateTransform: Internal error (parent_map) adding "
198 "transform with id: "
199 << transform_id.value;
200}
201
202void FakeFlatland::SetTranslation(
203 fuchsia::ui::composition::TransformId transform_id,
204 fuchsia::math::Vec translation) {
205 if (transform_id.value == 0) {
206 // TODO(fxb/85619): Raise a FlatlandError here
207 FML_CHECK(false)
208 << "FakeFlatland::SetTranslation: TransformId 0 is invalid.";
209 return;
210 }
211
212 auto found_transform = pending_graph_.transform_map.find(transform_id.value);
213 if (found_transform == pending_graph_.transform_map.end()) {
214 // TODO(fxb/85619): Raise a FlatlandError here
215 FML_CHECK(false) << "FakeFlatland::SetTranslation: TransformId "
216 << transform_id.value << " does not exist.";
217 return;
218 }
219
220 auto& transform = found_transform->second;
222 transform->translation = translation;
223}
224
225void FakeFlatland::SetScale(fuchsia::ui::composition::TransformId transform_id,
226 fuchsia::math::VecF scale) {
227 if (transform_id.value == 0) {
228 // TODO(fxb/85619): Raise a FlatlandError here
229 FML_CHECK(false) << "FakeFlatland::SetScale: TransformId 0 is invalid.";
230 return;
231 }
232
233 auto found_transform = pending_graph_.transform_map.find(transform_id.value);
234 if (found_transform == pending_graph_.transform_map.end()) {
235 // TODO(fxb/85619): Raise a FlatlandError here
236 FML_CHECK(false) << "FakeFlatland::SetScale: TransformId "
237 << transform_id.value << " does not exist.";
238 return;
239 }
240
241 if (scale.x == 0.f || scale.y == 0.f) {
242 FML_CHECK(false) << "SetScale failed, zero values not allowed (" << scale.x
243 << ", " << scale.y << " ).";
244 return;
245 }
246
247 if (isinf(scale.x) || isinf(scale.y) || isnan(scale.x) || isnan(scale.y)) {
248 FML_CHECK(false) << "SetScale failed, invalid scale values (" << scale.x
249 << ", " << scale.y << " ).";
250 return;
251 }
252
253 auto& transform = found_transform->second;
255 transform->scale = scale;
256}
257
258void FakeFlatland::SetOrientation(
259 fuchsia::ui::composition::TransformId transform_id,
260 fuchsia::ui::composition::Orientation orientation) {
261 if (transform_id.value == 0) {
262 // TODO(fxb/85619): Raise a FlatlandError here
263 FML_CHECK(false)
264 << "FakeFlatland::SetOrientation: TransformId 0 is invalid.";
265 return;
266 }
267
268 auto found_transform = pending_graph_.transform_map.find(transform_id.value);
269 if (found_transform == pending_graph_.transform_map.end()) {
270 // TODO(fxb/85619): Raise a FlatlandError here
271 FML_CHECK(false) << "FakeFlatland::SetOrientation: TransformId "
272 << transform_id.value << " does not exist.";
273 return;
274 }
275
276 auto& transform = found_transform->second;
278 transform->orientation = orientation;
279}
280
281void FakeFlatland::SetOpacity(
282 fuchsia::ui::composition::TransformId transform_id,
283 float value) {
284 if (transform_id.value == 0) {
285 // TODO(fxb/85619): Raise a FlatlandError here
286 FML_CHECK(false) << "FakeFlatland::SetOpacity: TransformId 0 is invalid.";
287 return;
288 }
289
290 auto found_transform = pending_graph_.transform_map.find(transform_id.value);
291 if (found_transform == pending_graph_.transform_map.end()) {
292 // TODO(fxb/85619): Raise a FlatlandError here
293 FML_CHECK(false) << "FakeFlatland::SetOpacity: TransformId "
294 << transform_id.value << " does not exist.";
295 return;
296 }
297
298 if (value < 0.f || value > 1.f) {
299 FML_CHECK(false) << "FakeFlatland::SetOpacity: Invalid opacity value.";
300 }
301
302 auto& transform = found_transform->second;
304 transform->opacity = value;
305}
306
307void FakeFlatland::SetClipBoundary(
308 fuchsia::ui::composition::TransformId transform_id,
309 std::unique_ptr<fuchsia::math::Rect> bounds) {
310 if (transform_id.value == 0) {
311 // TODO(fxb/85619): Raise a FlatlandError here
312 FML_CHECK(false)
313 << "FakeFlatland::SetClipBoundary: TransformId 0 is invalid.";
314 return;
315 }
316
317 auto found_transform = pending_graph_.transform_map.find(transform_id.value);
318 if (found_transform == pending_graph_.transform_map.end()) {
319 // TODO(fxb/85619): Raise a FlatlandError here
320 FML_CHECK(false) << "FakeFlatland::SetClipBoundary: TransformId "
321 << transform_id.value << " does not exist.";
322 return;
323 }
324
325 auto& transform = found_transform->second;
327 if (bounds == nullptr) {
328 transform->clip_bounds = std::nullopt;
329 return;
330 }
331
332 transform->clip_bounds = *bounds.get();
333}
334
335// TODO(fxbug.dev/89111): Re-enable once SDK rolls.
336// void FakeFlatland::SetImageOpacity(
337// fuchsia::ui::composition::ContentId content_id,
338// float opacity) {
339// if (content_id.value == 0) {
340// // TODO(fxb/85619): Raise a FlatlandError here
341// FML_CHECK(false)
342// << "FakeFlatland::SetImageOpacity: ContentId 0 is invalid.";
343// return;
344// }
345
346// auto found_content = pending_graph_.content_map.find(image_id.value);
347// if (found_content == pending_graph_.content_map.end()) {
348// // TODO(fxb/85619): Raise a FlatlandError here
349// FML_CHECK(false) << "FakeFlatland::SetImageOpacity: ContentId "
350// << image_id.value << " does not exist.";
351// return;
352// }
353
354// auto& content = found_content->second;
355// FML_CHECK(content);
356// FakeImage* image = std::get_if<FakeImage>(content.get());
357// if (image == nullptr) {
358// // TODO(fxb/85619): Raise a FlatlandError here
359// FML_CHECK(false) << "FakeFlatland::SetImageOpacity: ContentId "
360// << image_id.value << " is not an Image.";
361// return;
362// }
363
364// image->opacity = opacity;
365// }
366
367void FakeFlatland::AddChild(
368 fuchsia::ui::composition::TransformId parent_transform_id,
369 fuchsia::ui::composition::TransformId child_transform_id) {
370 if (parent_transform_id.value == 0) {
371 // TODO(fxb/85619): Raise a FlatlandError here
372 FML_CHECK(false)
373 << "FakeFlatland::AddChild: Parent TransformId 0 is invalid.";
374 return;
375 }
376 if (child_transform_id.value == 0) {
377 // TODO(fxb/85619): Raise a FlatlandError here
378 FML_CHECK(false)
379 << "FakeFlatland::AddChild: Child TransformId 0 is invalid.";
380 return;
381 }
382
383 auto found_parent =
384 pending_graph_.transform_map.find(parent_transform_id.value);
385 if (found_parent == pending_graph_.transform_map.end()) {
386 // TODO(fxb/85619): Raise a FlatlandError here
387 FML_CHECK(false) << "FakeFlatland::AddChild: Parent TransformId "
388 << parent_transform_id.value << " does not exist.";
389 return;
390 }
391 auto found_child =
392 pending_graph_.transform_map.find(child_transform_id.value);
393 if (found_child == pending_graph_.transform_map.end()) {
394 // TODO(fxb/85619): Raise a FlatlandError here
395 FML_CHECK(false) << "FakeFlatland::AddChild: Child TransformId "
396 << child_transform_id.value << " does not exist.";
397 return;
398 }
399 auto found_child_old_parent = parents_map_.find(child_transform_id.value);
400 if (found_child_old_parent == parents_map_.end()) {
401 // TODO(fxb/85619): Raise a FlatlandError here
402 FML_CHECK(false)
403 << "FakeFlatland::AddChild: Internal error - Child TransformId "
404 << child_transform_id.value << " is not in parents_map.";
405 return;
406 }
407 if (found_child_old_parent->second.second.expired()) {
408 // TODO(fxb/85619): Raise a FlatlandError here
409 FML_CHECK(false)
410 << "FakeFlatland::AddChild: Internal error - Child TransformId "
411 << child_transform_id.value << " is expired in parents_map.";
412 return;
413 }
414
415 auto& child = found_child->second;
416 auto& new_parent = found_parent->second;
417 new_parent->children.push_back(child);
418 if (auto old_parent = found_child_old_parent->second.first.lock()) {
419 old_parent->children.erase(std::remove_if(
420 old_parent->children.begin(), old_parent->children.end(),
421 [&child](const auto& transform) { return transform == child; }));
422 }
423 found_child_old_parent->second.first = std::weak_ptr(new_parent);
424}
425
426void FakeFlatland::RemoveChild(
427 fuchsia::ui::composition::TransformId parent_transform_id,
428 fuchsia::ui::composition::TransformId child_transform_id) {
429 if (parent_transform_id.value == 0) {
430 // TODO(fxb/85619): Raise a FlatlandError here
431 FML_CHECK(false)
432 << "FakeFlatland::RemoveChild: Parent TransformId 0 is invalid.";
433 return;
434 }
435 if (child_transform_id.value == 0) {
436 // TODO(fxb/85619): Raise a FlatlandError here
437 FML_CHECK(false)
438 << "FakeFlatland::RemoveChild: Child TransformId 0 is invalid.";
439 return;
440 }
441
442 auto found_child =
443 pending_graph_.transform_map.find(child_transform_id.value);
444 if (found_child == pending_graph_.transform_map.end()) {
445 // TODO(fxb/85619): Raise a FlatlandError here
446 FML_CHECK(false) << "FakeFlatland::RemoveChild: Child TransformId "
447 << child_transform_id.value << " does not exist.";
448 return;
449 }
450
451 auto found_parent =
452 pending_graph_.transform_map.find(parent_transform_id.value);
453 if (found_parent == pending_graph_.transform_map.end()) {
454 // TODO(fxb/85619): Raise a FlatlandError here
455 FML_CHECK(false) << "FakeFlatland::RemoveChild: Parent TransformId "
456 << parent_transform_id.value << " does not exist.";
457 return;
458 }
459
460 auto found_child_parent = parents_map_.find(child_transform_id.value);
461 if (found_child_parent == parents_map_.end()) {
462 // TODO(fxb/85619): Raise a FlatlandError here
463 FML_CHECK(false)
464 << "FakeFlatland::RemoveChild: Internal error - Child TransformId "
465 << child_transform_id.value << " is not in parents_map.";
466 return;
467 }
468 if (found_child_parent->second.second.expired()) {
469 // TODO(fxb/85619): Raise a FlatlandError here
470 FML_CHECK(false)
471 << "FakeFlatland::RemoveChild: Internal error - Child TransformId "
472 << child_transform_id.value << " is expired in parents_map.";
473 return;
474 }
475 if (found_child_parent->second.first.lock() != found_parent->second) {
476 // TODO(fxb/85619): Raise a FlatlandError here
477 FML_CHECK(false)
478 << "FakeFlatland::RemoveChild: Internal error - Child TransformId "
479 << child_transform_id.value << " is not a child of Parent TransformId "
480 << parent_transform_id.value << ".";
481 return;
482 }
483
484 found_child_parent->second.first = std::weak_ptr<FakeTransform>();
485 found_parent->second->children.erase(std::remove_if(
486 found_parent->second->children.begin(),
487 found_parent->second->children.end(),
488 [child_to_remove = found_child->second](const auto& child) {
489 return child == child_to_remove;
490 }));
491}
492
493void FakeFlatland::SetContent(
494 fuchsia::ui::composition::TransformId transform_id,
495 fuchsia::ui::composition::ContentId content_id) {
496 if (transform_id.value == 0) {
497 // TODO(fxb/85619): Raise a FlatlandError here
498 FML_CHECK(false) << "FakeFlatland::SetContent: TransformId 0 is invalid.";
499 return;
500 }
501
502 auto found_transform = pending_graph_.transform_map.find(transform_id.value);
503 if (found_transform == pending_graph_.transform_map.end()) {
504 // TODO(fxb/85619): Raise a FlatlandError here
505 FML_CHECK(false) << "FakeFlatland::SetContent: TransformId "
506 << transform_id.value << " does not exist.";
507 return;
508 }
509
510 auto& transform = found_transform->second;
512 if (content_id.value == 0) {
513 transform->content.reset();
514 return;
515 }
516
517 auto found_content = pending_graph_.content_map.find(content_id.value);
518 if (found_content == pending_graph_.content_map.end()) {
519 // TODO(fxb/85619): Raise a FlatlandError here
520 FML_CHECK(false) << "FakeFlatland::SetContent: ContentId "
521 << content_id.value << " does not exist.";
522 return;
523 }
524
525 auto& content = found_content->second;
527 transform->content = content;
528}
529
530void FakeFlatland::SetRootTransform(
531 fuchsia::ui::composition::TransformId transform_id) {
532 if (transform_id.value == 0) {
533 // TODO(fxb/85619): Raise a FlatlandError here
534 FML_CHECK(false)
535 << "FakeFlatland::SetRootTransform: TransformId 0 is invalid.";
536 return;
537 }
538
539 auto found_new_root = pending_graph_.transform_map.find(transform_id.value);
540 if (found_new_root == pending_graph_.transform_map.end()) {
541 // TODO(fxb/85619): Raise a FlatlandError here
542 FML_CHECK(false) << "FakeFlatland::SetRootTransform: TransformId "
543 << transform_id.value << " does not exist.";
544 return;
545 }
546
547 pending_graph_.root_transform = found_new_root->second;
548}
549
550void FakeFlatland::CreateViewport(
551 fuchsia::ui::composition::ContentId viewport_id,
552 fuchsia::ui::views::ViewportCreationToken token,
553 fuchsia::ui::composition::ViewportProperties properties,
554 fidl::InterfaceRequest<fuchsia::ui::composition::ChildViewWatcher>
555 child_view_watcher) {
556 if (viewport_id.value == 0) {
557 // TODO(fxb/85619): Raise a FlatlandError here
558 FML_CHECK(false) << "FakeFlatland::CreateViewport: ContentId 0 is invalid.";
559 return;
560 }
561 if (pending_graph_.content_map.count(viewport_id.value) != 0) {
562 // TODO(fxb/85619): Raise a FlatlandError here
563 FML_CHECK(false) << "FakeFlatland::CreateViewport: ContentId "
564 << viewport_id.value << " is already in use.";
565 return;
566 }
567
568 auto viewport_token_koids = GetKoids(token.value);
569 auto [emplaced_viewport, emplace_success] =
570 pending_graph_.content_map.emplace(
571 viewport_id.value,
572 std::make_shared<FakeContent>(FakeViewport{
573 .id = viewport_id,
574 .viewport_properties = std::move(properties),
575 .viewport_token = viewport_token_koids.first,
576 .child_view_watcher = GetKoids(child_view_watcher).first,
577 }));
578 // TODO(fxb/85619): Raise a FlatlandError here
579 FML_CHECK(emplace_success)
580 << "FakeFlatland::CreateViewport: Internal error (content_map) adding "
581 "viewport with id: "
582 << viewport_id.value;
583
584 auto [_, emplace_binding_success] = graph_bindings_.view_watchers.emplace(
585 viewport_token_koids.first,
586 ChildViewWatcher(std::move(token), std::move(child_view_watcher),
587 flatland_binding_.dispatcher()));
588 // TODO(fxb/85619): Raise a FlatlandError here
589 FML_CHECK(emplace_binding_success)
590 << "FakeFlatland::CreateViewport: Internal error (view_watcher) adding "
591 "viewport with id: "
592 << viewport_id.value;
593}
594
595void FakeFlatland::CreateImage(
596 fuchsia::ui::composition::ContentId image_id,
597 fuchsia::ui::composition::BufferCollectionImportToken import_token,
598 uint32_t vmo_index,
599 fuchsia::ui::composition::ImageProperties properties) {
600 if (image_id.value == 0) {
601 // TODO(fxb/85619): Raise a FlatlandError here
602 FML_CHECK(false) << "FakeFlatland::CreateImage: ContentId 0 is invalid.";
603 return;
604 }
605 if (pending_graph_.content_map.count(image_id.value) != 0) {
606 // TODO(fxb/85619): Raise a FlatlandError here
607 FML_CHECK(false) << "FakeFlatland::CreateImage: ContentId "
608 << image_id.value << " is already in use.";
609 return;
610 }
611
612 auto import_token_koids = GetKoids(import_token);
613 auto [emplaced_image, emplace_success] = pending_graph_.content_map.emplace(
614 image_id.value, std::make_shared<FakeContent>(FakeImage{
615 .id = image_id,
616 .image_properties = std::move(properties),
617 .import_token = import_token_koids.first,
618 .vmo_index = vmo_index,
619 }));
620 // TODO(fxb/85619): Raise a FlatlandError here
621 FML_CHECK(emplace_success)
622 << "FakeFlatland::CreateImage: Internal error (content_map) adding "
623 "image with id: "
624 << image_id.value;
625
626 auto [_, emplace_binding_success] = graph_bindings_.images.emplace(
627 import_token_koids.first, ImageBinding{
628 .import_token = std::move(import_token),
629 });
630 // TODO(fxb/85619): Raise a FlatlandError here
631 FML_CHECK(emplace_binding_success)
632 << "FakeFlatland::CreateImage: Internal error (images_binding) adding "
633 "viewport with id: "
634 << image_id.value;
635}
636
637void FakeFlatland::SetImageSampleRegion(
638 fuchsia::ui::composition::ContentId image_id,
639 fuchsia::math::RectF rect) {
640 if (image_id.value == 0) {
641 // TODO(fxb/85619): Raise a FlatlandError here
642 FML_CHECK(false)
643 << "FakeFlatland::SetImageSampleRegion: ContentId 0 is invalid.";
644 return;
645 }
646
647 auto found_content = pending_graph_.content_map.find(image_id.value);
648 if (found_content == pending_graph_.content_map.end()) {
649 // TODO(fxb/85619): Raise a FlatlandError here
650 FML_CHECK(false) << "FakeFlatland::SetImageSampleRegion: ContentId "
651 << image_id.value << " does not exist.";
652 return;
653 }
654
655 auto& content = found_content->second;
657 FakeImage* image = std::get_if<FakeImage>(content.get());
658 if (image == nullptr) {
659 // TODO(fxb/85619): Raise a FlatlandError here
660 FML_CHECK(false) << "FakeFlatland::SetImageSampleRegion: ContentId "
661 << image_id.value << " is not an Image.";
662 return;
663 }
664
665 image->sample_region = rect;
666}
667
668void FakeFlatland::SetImageDestinationSize(
669 fuchsia::ui::composition::ContentId image_id,
670 fuchsia::math::SizeU size) {
671 if (image_id.value == 0) {
672 // TODO(fxb/85619): Raise a FlatlandError here
673 FML_CHECK(false)
674 << "FakeFlatland::SetImageDestinationSize: ContentId 0 is invalid.";
675 return;
676 }
677
678 auto found_content = pending_graph_.content_map.find(image_id.value);
679 if (found_content == pending_graph_.content_map.end()) {
680 // TODO(fxb/85619): Raise a FlatlandError here
681 FML_CHECK(false) << "FakeFlatland::SetImageDestinationSize: ContentId "
682 << image_id.value << " does not exist.";
683 return;
684 }
685
686 auto& content = found_content->second;
688 FakeImage* image = std::get_if<FakeImage>(content.get());
689 if (image == nullptr) {
690 // TODO(fxb/85619): Raise a FlatlandError here
691 FML_CHECK(false) << "FakeFlatland::SetImageDestinationSize: ContentId "
692 << image_id.value << " is not an Image.";
693 return;
694 }
695
696 image->destination_size = size;
697}
698
699void FakeFlatland::SetImageBlendingFunction(
700 fuchsia::ui::composition::ContentId image_id,
701 fuchsia::ui::composition::BlendMode blend_mode) {
702 if (image_id.value == 0) {
703 // TODO(fxb/85619): Raise a FlatlandError here
704 FML_CHECK(false)
705 << "FakeFlatland::SetImageDestinationSize: ContentId 0 is invalid.";
706 return;
707 }
708
709 auto found_content = pending_graph_.content_map.find(image_id.value);
710 if (found_content == pending_graph_.content_map.end()) {
711 // TODO(fxb/85619): Raise a FlatlandError here
712 FML_CHECK(false) << "FakeFlatland::SetImageDestinationSize: ContentId "
713 << image_id.value << " does not exist.";
714 return;
715 }
716
717 auto& content = found_content->second;
719 FakeImage* image = std::get_if<FakeImage>(content.get());
720 if (image == nullptr) {
721 // TODO(fxb/85619): Raise a FlatlandError here
722 FML_CHECK(false) << "FakeFlatland::SetImageDestinationSize: ContentId "
723 << image_id.value << " is not an Image.";
724 return;
725 }
726
727 image->blend_mode = blend_mode;
728}
729
730void FakeFlatland::SetViewportProperties(
731 fuchsia::ui::composition::ContentId viewport_id,
732 fuchsia::ui::composition::ViewportProperties properties) {
733 if (viewport_id.value == 0) {
734 // TODO(fxb/85619): Raise a FlatlandError here
735 FML_CHECK(false)
736 << "FakeFlatland::SetViewportProperties: ContentId 0 is invalid.";
737 return;
738 }
739
740 auto found_content = pending_graph_.content_map.find(viewport_id.value);
741 if (found_content == pending_graph_.content_map.end()) {
742 // TODO(fxb/85619): Raise a FlatlandError here
743 FML_CHECK(false) << "FakeFlatland::SetViewportProperties: ContentId "
744 << viewport_id.value << " does not exist.";
745 return;
746 }
747
748 auto& content = found_content->second;
750 FakeViewport* viewport = std::get_if<FakeViewport>(content.get());
751 if (viewport == nullptr) {
752 // TODO(fxb/85619): Raise a FlatlandError here
753 FML_CHECK(false) << "FakeFlatland::SetViewportProperties: ContentId "
754 << viewport_id.value << " is not a Viewport.";
755 return;
756 }
757
758 viewport->viewport_properties = std::move(properties);
759}
760
761void FakeFlatland::ReleaseTransform(
762 fuchsia::ui::composition::TransformId transform_id) {
763 if (transform_id.value == 0) {
764 // TODO(fxb/85619): Raise a FlatlandError here
765 FML_CHECK(false)
766 << "FakeFlatland::ReleaseTransform: TransformId 0 is invalid.";
767 return;
768 }
769
770 size_t erased = pending_graph_.transform_map.erase(transform_id.value);
771 if (erased == 0) {
772 // TODO(fxb/85619): Raise a FlatlandError here
773 FML_CHECK(false) << "FakeFlatland::ReleaseTransform: TransformId "
774 << transform_id.value << " does not exist.";
775 }
776
777 size_t parents_erased = parents_map_.erase(transform_id.value);
778 if (parents_erased == 0) {
779 // TODO(fxb/85619): Raise a FlatlandError here
780 FML_CHECK(false) << "FakeFlatland::ReleaseTransform: TransformId "
781 << transform_id.value << " does not exist in parents_map.";
782 }
783}
784
785void FakeFlatland::ReleaseViewport(
786 fuchsia::ui::composition::ContentId viewport_id,
787 ReleaseViewportCallback callback) {
788 if (viewport_id.value == 0) {
789 // TODO(fxb/85619): Raise a FlatlandError here
790 FML_CHECK(false)
791 << "FakeFlatland::ReleaseViewport: ContentId 0 is invalid.";
792 return;
793 }
794
795 auto found_content = pending_graph_.content_map.find(viewport_id.value);
796 if (found_content == pending_graph_.content_map.end()) {
797 // TODO(fxb/85619): Raise a FlatlandError here
798 FML_CHECK(false) << "FakeFlatland::ReleaseViewport: ContentId "
799 << viewport_id.value << " does not exist.";
800 return;
801 }
802
803 auto& content = found_content->second;
805 FakeViewport* viewport = std::get_if<FakeViewport>(content.get());
806 if (viewport == nullptr) {
807 // TODO(fxb/85619): Raise a FlatlandError here
808 FML_CHECK(false) << "FakeFlatland::ReleaseViewport: ContentId "
809 << viewport_id.value << " is not a Viewport.";
810 return;
811 }
812
813 pending_graph_.content_map.erase(found_content);
814}
815
816void FakeFlatland::ReleaseImage(fuchsia::ui::composition::ContentId image_id) {
817 if (image_id.value == 0) {
818 // TODO(fxb/85619): Raise a FlatlandError here
819 FML_CHECK(false) << "FakeFlatland::ReleaseImage: ContentId 0 is invalid.";
820 return;
821 }
822
823 auto found_content = pending_graph_.content_map.find(image_id.value);
824 if (found_content == pending_graph_.content_map.end()) {
825 // TODO(fxb/85619): Raise a FlatlandError here
826 FML_CHECK(false) << "FakeFlatland::ReleaseImage: ContentId "
827 << image_id.value << " does not exist.";
828 return;
829 }
830
831 auto& content = found_content->second;
833 FakeImage* image = std::get_if<FakeImage>(content.get());
834 if (image == nullptr) {
835 // TODO(fxb/85619): Raise a FlatlandError here
836 FML_CHECK(false) << "FakeFlatland::ReleaseImage: ContentId "
837 << image_id.value << " is not a Viewport.";
838 return;
839 }
840
841 pending_graph_.content_map.erase(found_content);
842}
843
844void FakeFlatland::SetHitRegions(
845 fuchsia::ui::composition::TransformId transform_id,
846 std::vector<fuchsia::ui::composition::HitRegion> regions) {
847 if (transform_id.value == 0) {
848 // TODO(fxb/85619): Raise a FlatlandError here
849 FML_CHECK(false)
850 << "FakeFlatland::SetTranslation: TransformId 0 is invalid.";
851 return;
852 }
853
854 auto found_transform = pending_graph_.transform_map.find(transform_id.value);
855 if (found_transform == pending_graph_.transform_map.end()) {
856 // TODO(fxb/85619): Raise a FlatlandError here
857 FML_CHECK(false) << "FakeFlatland::SetTranslation: TransformId "
858 << transform_id.value << " does not exist.";
859 return;
860 }
861
862 auto& transform = found_transform->second;
864 transform->hit_regions = std::move(regions);
865}
866
867void FakeFlatland::SetInfiniteHitRegion(
868 fuchsia::ui::composition::TransformId transform_id,
869 fuchsia::ui::composition::HitTestInteraction hit_test) {
870 if (transform_id.value == 0) {
871 // TODO(fxb/85619): Raise a FlatlandError here
872 FML_CHECK(false)
873 << "FakeFlatland::SetTranslation: TransformId 0 is invalid.";
874 return;
875 }
876
877 auto found_transform = pending_graph_.transform_map.find(transform_id.value);
878 if (found_transform == pending_graph_.transform_map.end()) {
879 // TODO(fxb/85619): Raise a FlatlandError here
880 FML_CHECK(false) << "FakeFlatland::SetTranslation: TransformId "
881 << transform_id.value << " does not exist.";
882 return;
883 }
884
885 auto& transform = found_transform->second;
886 ZX_ASSERT(transform);
887 transform->hit_regions = {kInfiniteHitRegion};
888}
889
890void FakeFlatland::Clear() {
891 parents_map_.clear();
892 pending_graph_.Clear();
893}
894
895void FakeFlatland::SetDebugName(std::string debug_name) {
896 debug_name_ = std::move(debug_name);
897}
898
899FakeFlatland::ParentViewportWatcher::ParentViewportWatcher(
900 fuchsia::ui::views::ViewCreationToken view_token,
901 fuchsia::ui::views::ViewIdentityOnCreation view_identity,
902 fuchsia::ui::composition::ViewBoundProtocols view_protocols,
903 fidl::InterfaceRequest<fuchsia::ui::composition::ParentViewportWatcher>
904 parent_viewport_watcher,
905 async_dispatcher_t* dispatcher)
906 : view_token(std::move(view_token)),
907 view_identity(std::move(view_identity)),
908 view_protocols(std::move(view_protocols)),
909 parent_viewport_watcher(this,
910 std::move(parent_viewport_watcher),
911 dispatcher) {}
912
913FakeFlatland::ParentViewportWatcher::ParentViewportWatcher(
914 ParentViewportWatcher&& other)
915 : view_token(std::move(other.view_token)),
916 view_identity(std::move(other.view_identity)),
917 view_protocols(std::move(other.view_protocols)),
918 parent_viewport_watcher(this,
919 other.parent_viewport_watcher.Unbind(),
920 other.parent_viewport_watcher.dispatcher()) {}
921
922FakeFlatland::ParentViewportWatcher::~ParentViewportWatcher() = default;
923
924void FakeFlatland::ParentViewportWatcher::NotImplemented_(
925 const std::string& name) {
926 FML_LOG(FATAL) << "FakeFlatland::ParentViewportWatcher does not implement "
927 << name;
928}
929
930void FakeFlatland::ParentViewportWatcher::GetLayout(
931 GetLayoutCallback callback) {
932 NotImplemented_("GetLayout");
933}
934
935void FakeFlatland::ParentViewportWatcher::GetStatus(
936 GetStatusCallback callback) {
937 NotImplemented_("GetStatus");
938}
939
940FakeFlatland::ChildViewWatcher::ChildViewWatcher(
941 fuchsia::ui::views::ViewportCreationToken viewport_token,
942 fidl::InterfaceRequest<fuchsia::ui::composition::ChildViewWatcher>
943 child_view_watcher,
944 async_dispatcher_t* dispatcher)
945 : viewport_token(std::move(viewport_token)),
946 child_view_watcher(this, std::move(child_view_watcher), dispatcher) {}
947
948FakeFlatland::ChildViewWatcher::ChildViewWatcher(ChildViewWatcher&& other)
949 : viewport_token(std::move(other.viewport_token)),
950 child_view_watcher(this,
951 other.child_view_watcher.Unbind(),
952 other.child_view_watcher.dispatcher()) {}
953
954FakeFlatland::ChildViewWatcher::~ChildViewWatcher() = default;
955
956void FakeFlatland::ChildViewWatcher::NotImplemented_(const std::string& name) {
957 FML_LOG(FATAL) << "FakeFlatland::ChildViewWatcher does not implement "
958 << name;
959}
960
961void FakeFlatland::ChildViewWatcher::GetStatus(GetStatusCallback callback) {
962 NotImplemented_("GetStatus");
963}
964
965} // namespace flutter_runner::testing
fuchsia::ui::composition::FlatlandHandle ConnectFlatland(async_dispatcher_t *dispatcher=nullptr)
fuchsia::ui::composition::AllocatorHandle ConnectAllocator(async_dispatcher_t *dispatcher=nullptr)
std::function< void(fuchsia::ui::composition::PresentArgs)> PresentHandler
void SetPresentHandler(PresentHandler present_handler)
void FireOnFramePresentedEvent(fuchsia::scenic::scheduling::FramePresentedInfo frame_presented_info)
const std::string & debug_name() const
void FireOnNextFrameBeginEvent(fuchsia::ui::composition::OnNextFrameBeginValues on_next_frame_begin_values)
void Disconnect(fuchsia::ui::composition::FlatlandError error)
int32_t value
FlutterVulkanImage * image
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
const uint8_t uint32_t uint32_t GError ** error
FlutterDesktopBinaryReply callback
#define FML_LOG(severity)
Definition logging.h:101
#define FML_CHECK(condition)
Definition logging.h:104
const char * name
Definition fuchsia.cc:49
union flutter::testing::@2824::KeyboardChange::@78 content
std::pair< zx_koid_t, zx_koid_t > GetKoids(const ZX &kobj)
static constexpr fuchsia::ui::composition::HitRegion kInfiniteHitRegion
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition ref_ptr.h:261
std::unordered_map< ContentIdKey, std::shared_ptr< FakeContent > > content_map
std::shared_ptr< FakeTransform > root_transform
std::unordered_map< TransformIdKey, std::shared_ptr< FakeTransform > > transform_map