blob: c4b4c2bd8d321c5bb7c2a4e2c0d50be2fddac009 [file]
// 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/engine/embedder.h"
#include "src/embedder/flatland_connection.h"
#include "src/embedder/software_surface.h"
#include "src/embedder/software_surface_producer.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 ====
/// Produces software surfaces for Flutter to render onto.
std::unique_ptr<SoftwareSurfaceProducer> software_surface_producer;
/// 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 = nullptr;
};
} // namespace embedder
#endif // SRC_EMBEDDER_EMBEDDER_STATE_H_