mirror of
https://github.com/encounter/engine.git
synced 2026-03-30 11:09:55 -07:00
400e3b00fb
The FIDL service `fuchsia.intl.PropertyProvider` is a service that
the flutter runner can use to obtain information on system preferred
locales.
This change sends a platform message "setLocale" on the channel
"flutter/localization", based on the values provided by the above
mentioned FIDL service.
Credit: most of this was initially written by @kpozin; I ported it
to out-of-tree flutter engine.
Tested:
1. Compile and publish the unit tests package as shown in
the script below.
2. In a Fuchsia repository (pointed to by `$FUCHSIA_DIR`), run
`fx serve`
3. `fx shell run fuchsia-pkg://fuchsia.com/flutter_runner_tests#meta/flutter_runner_tests.cmx`
The script used to update the unit tests.
```bash
set -x
FLUTTER_ENGINE_DIR="${FLUTTER_ENGINE_DIR:-$HOME/fx/flutter/engine/src}"
readonly OUT_DIR="${FLUTTER_ENGINE_DIR}/out"
(
cd ${FLUTTER_ENGINE_DIR}
./flutter/tools/gn --fuchsia --fuchsia-cpu x64 --unoptimized
ninja -j 100 -C "${OUT_DIR}/fuchsia_debug_unopt_x64"
cp "${OUT_DIR}/compile_commands.json" "${FLUTTER_ENGINE_DIR}"
echo "Publishing the tests package"
"${FLUTTER_ENGINE_DIR}/fuchsia/sdk/linux/tools/pm" publish \
-a -r $FUCHSIA_DIR/out/release/amber-files \
-f "${FLUTTER_ENGINE_DIR}/out/fuchsia_debug_unopt_x64/flutter_runner_tests-0.far"
)
```
83 lines
2.6 KiB
C++
83 lines
2.6 KiB
C++
// Copyright 2013 The Flutter 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 FLUTTER_SHELL_PLATFORM_FUCHSIA_ENGINE_H_
|
|
#define FLUTTER_SHELL_PLATFORM_FUCHSIA_ENGINE_H_
|
|
|
|
#include <fuchsia/intl/cpp/fidl.h>
|
|
#include <fuchsia/io/cpp/fidl.h>
|
|
#include <fuchsia/ui/gfx/cpp/fidl.h>
|
|
#include <fuchsia/ui/views/cpp/fidl.h>
|
|
#include <lib/async-loop/cpp/loop.h>
|
|
#include <lib/sys/cpp/service_directory.h>
|
|
#include <lib/zx/event.h>
|
|
|
|
#include "flutter/fml/macros.h"
|
|
#include "flutter/shell/common/shell.h"
|
|
#include "isolate_configurator.h"
|
|
#include "thread.h"
|
|
|
|
namespace flutter_runner {
|
|
|
|
// Represents an instance of running Flutter engine along with the threads
|
|
// that host the same.
|
|
class Engine final {
|
|
public:
|
|
class Delegate {
|
|
public:
|
|
virtual void OnEngineTerminate(const Engine* holder) = 0;
|
|
};
|
|
|
|
Engine(Delegate& delegate,
|
|
std::string thread_label,
|
|
std::shared_ptr<sys::ServiceDirectory> svc,
|
|
std::shared_ptr<sys::ServiceDirectory> runner_services,
|
|
flutter::Settings settings,
|
|
fml::RefPtr<const flutter::DartSnapshot> isolate_snapshot,
|
|
fuchsia::ui::views::ViewToken view_token,
|
|
fuchsia::ui::views::ViewRefControl view_ref_control,
|
|
fuchsia::ui::views::ViewRef view_ref,
|
|
UniqueFDIONS fdio_ns,
|
|
fidl::InterfaceRequest<fuchsia::io::Directory> directory_request);
|
|
~Engine();
|
|
|
|
// Returns the Dart return code for the root isolate if one is present. This
|
|
// call is thread safe and synchronous. This call must be made infrequently.
|
|
std::pair<bool, uint32_t> GetEngineReturnCode() const;
|
|
|
|
#if !defined(DART_PRODUCT)
|
|
void WriteProfileToTrace() const;
|
|
#endif // !defined(DART_PRODUCT)
|
|
|
|
private:
|
|
Delegate& delegate_;
|
|
const std::string thread_label_;
|
|
flutter::Settings settings_;
|
|
std::array<std::unique_ptr<Thread>, 3> threads_;
|
|
std::unique_ptr<IsolateConfigurator> isolate_configurator_;
|
|
std::unique_ptr<flutter::Shell> shell_;
|
|
zx::event vsync_event_;
|
|
fml::WeakPtrFactory<Engine> weak_factory_;
|
|
// A stub for the FIDL protocol fuchsia.intl.PropertyProvider.
|
|
fuchsia::intl::PropertyProviderPtr intl_property_provider_;
|
|
|
|
void OnMainIsolateStart();
|
|
|
|
void OnMainIsolateShutdown();
|
|
|
|
void Terminate();
|
|
|
|
void OnSessionMetricsDidChange(const fuchsia::ui::gfx::Metrics& metrics);
|
|
void OnSessionSizeChangeHint(float width_change_factor,
|
|
float height_change_factor);
|
|
|
|
void OnDebugWireframeSettingsChanged(bool enabled);
|
|
|
|
FML_DISALLOW_COPY_AND_ASSIGN(Engine);
|
|
};
|
|
|
|
} // namespace flutter_runner
|
|
|
|
#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_ENGINE_H_
|