| // Copyright 2022 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #ifndef SRC_EMBEDDER_EMBEDDER_STATE_H_ |
| #define SRC_EMBEDDER_EMBEDDER_STATE_H_ |
| |
| #include <fuchsia/sysmem/cpp/fidl.h> |
| #include <fuchsia/ui/composition/cpp/fidl.h> |
| #include <lib/sys/cpp/component_context.h> |
| #include <lib/zx/vmo.h> |
| |
| #include <optional> |
| |
| #include "src/embedder/accessibility_bridge.h" |
| #include "src/embedder/engine/embedder.h" |
| #include "src/embedder/flatland_connection.h" |
| #include "src/embedder/software_surface.h" |
| |
| namespace embedder { |
| |
| /// Mutable state for the embedder. |
| /// |
| /// This is provided to all Engine callbacks through the |
| /// embedder's `user_data` argument. See `FlutterEngineRun` in |
| /// engine/embedder.h for more details on `user_data`. |
| struct EmbedderState { |
| /// Capabilities are served from the embedder component |
| /// parent components using this component context. |
| // |
| // WARNING: `component_context` MUST BE THE FIRST FIELD OF THIS DATA. |
| // We shouldn't rely on the Dart SDK from our embedder, so instead we |
| // do a terrible hack in https://github.com/flutter/engine/pull/33472 that |
| // requires reading this field to work around http://fxbug.dev/75282 to set |
| // the inspect node inside the embedder on the Fuchsia platform. |
| // |
| // TODO(fxb/75282): Properly fix this and remove the terrible hack. |
| std::unique_ptr<sys::ComponentContext> component_context; |
| |
| // ===== FLUTTER ENGINE STATE ===== |
| |
| /// The instance of the Flutter Engine that is running the |
| /// Flutter app. |
| FlutterEngine engine; |
| |
| // ===== RENDERING ===== |
| |
| /// Maintains our Flatland server connection and associated state. |
| /// |
| /// Flatland is Fuchsia's 2D composition API, which lets us construct |
| /// a scene graph and submit that graph to be rendered. |
| /// |
| /// See https://fuchsia.dev/fuchsia-src/concepts/ui/scenic/flatland?hl=en. |
| std::unique_ptr<FlatlandConnection> flatland_connection; |
| |
| // ===== SOFTWARE RENDERING ==== |
| |
| /// The allocator for memory in Flatland. |
| /// |
| /// Required to allocate a surface for Flatland. See |
| /// notes in |
| /// https://fuchsia.dev/fuchsia-src/concepts/ui/scenic/flatland?hl=en#design. |
| fuchsia::ui::composition::AllocatorPtr flatland_allocator; |
| |
| /// Allocator for memory from sysmem. |
| /// |
| /// Memory for graphics surfaces on Fuchsia must come from sysmem. |
| /// |
| /// For more details on how sysmem works and how to interact with |
| /// sysmem, see |
| /// https://fuchsia.dev/fuchsia-src/development/graphics/sysmem/concepts/sysmem. |
| fuchsia::sysmem::AllocatorSyncPtr sysmem_allocator; |
| |
| /// The last acquired surface for rendering. |
| /// |
| /// TODO(akbiggs): Replace with composition logic |
| /// that supports multiple surfaces. See |
| /// https://github.com/flutter/engine/blob/main/shell/platform/fuchsia/flutter/flatland_external_view_embedder.cc#L108. |
| std::unique_ptr<SoftwareSurface> software_surface; |
| |
| /// The accessibility bridge responsible for intermediating |
| /// accessibility-related calls between Fuchsia and Flutter |
| std::unique_ptr<AccessibilityBridge> accessibility_bridge_; |
| }; |
| |
| } // namespace embedder |
| |
| #endif // SRC_EMBEDDER_EMBEDDER_STATE_H_ |