Skip to content

Commit

Permalink
Move AndroidRenderingApi from common to shell/platform/android (f…
Browse files Browse the repository at this point in the history
…lutter#163796)

Towards flutter#163792.

Major changes:

- `enum class AndroidRenderingAPI` physically moves to
`shell/platform/android`
- Store in `FlutterMain` (as a result of `::init`), instead of in
`Settings`

---------

Co-authored-by: Jonah Williams <[email protected]>
  • Loading branch information
matanlurey and jonahwilliams authored Feb 25, 2025
1 parent ebc7d24 commit 7535cb1
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 67 deletions.
2 changes: 2 additions & 0 deletions engine/src/flutter/ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -42960,6 +42960,7 @@ ORIGIN: ../../../flutter/shell/platform/android/android_environment_gl.h + ../..
ORIGIN: ../../../flutter/shell/platform/android/android_exports.lst + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/android_image_generator.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/android_image_generator.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/android_rendering_selector.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/android_shell_holder.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/android_shell_holder.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/android/android_surface_gl_impeller.cc + ../../../flutter/LICENSE
Expand Down Expand Up @@ -45876,6 +45877,7 @@ FILE: ../../../flutter/shell/platform/android/android_environment_gl.h
FILE: ../../../flutter/shell/platform/android/android_exports.lst
FILE: ../../../flutter/shell/platform/android/android_image_generator.cc
FILE: ../../../flutter/shell/platform/android/android_image_generator.h
FILE: ../../../flutter/shell/platform/android/android_rendering_selector.h
FILE: ../../../flutter/shell/platform/android/android_shell_holder.cc
FILE: ../../../flutter/shell/platform/android/android_shell_holder.h
FILE: ../../../flutter/shell/platform/android/android_surface_gl_impeller.cc
Expand Down
13 changes: 0 additions & 13 deletions engine/src/flutter/common/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include <fcntl.h>

#include <chrono>
#include <cstdint>
#include <memory>
#include <optional>
Expand All @@ -22,14 +21,6 @@

namespace flutter {

// The combination of targeted graphics API and Impeller support.
enum class AndroidRenderingAPI {
kSoftware,
kImpellerOpenGLES,
kImpellerVulkan,
kSkiaOpenGLES
};

class FrameTiming {
public:
enum Phase {
Expand Down Expand Up @@ -240,10 +231,6 @@ struct Settings {
// Log a warning during shell initialization if Impeller is not enabled.
bool warn_on_impeller_opt_out = false;

// The selected Android rendering API.
AndroidRenderingAPI android_rendering_api =
AndroidRenderingAPI::kSkiaOpenGLES;

// Requests a specific rendering backend.
std::optional<std::string> requested_rendering_backend;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#ifndef FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_CONTEXT_VK_IMPELLER_H_
#define FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_CONTEXT_VK_IMPELLER_H_

#include "flutter/fml/concurrent_message_loop.h"
#include "flutter/fml/macros.h"
#include "flutter/fml/native_library.h"
#include "flutter/shell/platform/android/context/android_context.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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_ANDROID_ANDROID_RENDERING_SELECTOR_H_
#define FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_RENDERING_SELECTOR_H_

namespace flutter {

// The combination of targeted graphics API and Impeller support.
enum class AndroidRenderingAPI {
kSoftware,
kImpellerOpenGLES,
kImpellerVulkan,
kSkiaOpenGLES
};

} // namespace flutter

#endif // FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_RENDERING_SELECTOR_H_
30 changes: 16 additions & 14 deletions engine/src/flutter/shell/platform/android/android_shell_holder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,27 @@

#define FML_USED_ON_EMBEDDER

#include "flutter/shell/platform/android/android_shell_holder.h"

#include <pthread.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <memory>
#include <optional>

#include <sstream>
#include <string>
#include <utility>

#include "common/settings.h"
#include "flutter/fml/cpu_affinity.h"
#include "flutter/fml/logging.h"
#include "flutter/fml/make_copyable.h"
#include "flutter/fml/message_loop.h"
#include "flutter/fml/native_library.h"
#include "flutter/fml/platform/android/jni_util.h"
#include "flutter/lib/ui/painting/image_generator_registry.h"
#include "flutter/shell/common/rasterizer.h"
#include "flutter/shell/common/run_configuration.h"
#include "flutter/shell/common/thread_host.h"
#include "flutter/shell/platform/android/android_display.h"
#include "flutter/shell/platform/android/android_image_generator.h"
#include "flutter/shell/platform/android/android_rendering_selector.h"
#include "flutter/shell/platform/android/android_shell_holder.h"
#include "flutter/shell/platform/android/context/android_context.h"
#include "flutter/shell/platform/android/platform_view_android.h"

Expand Down Expand Up @@ -85,8 +81,11 @@ static PlatformData GetDefaultPlatformData() {

AndroidShellHolder::AndroidShellHolder(
const flutter::Settings& settings,
std::shared_ptr<PlatformViewAndroidJNI> jni_facade)
: settings_(settings), jni_facade_(jni_facade) {
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
AndroidRenderingAPI android_rendering_api)
: settings_(settings),
jni_facade_(jni_facade),
android_rendering_api_(android_rendering_api) {
static size_t thread_host_count = 1;
auto thread_label = std::to_string(thread_host_count++);

Expand All @@ -113,15 +112,15 @@ AndroidShellHolder::AndroidShellHolder(
thread_host_ = std::make_shared<ThreadHost>(host_config);

fml::WeakPtr<PlatformViewAndroid> weak_platform_view;
AndroidRenderingAPI rendering_api = android_rendering_api_;
Shell::CreateCallback<PlatformView> on_create_platform_view =
[&jni_facade, &weak_platform_view](Shell& shell) {
[&jni_facade, &weak_platform_view, rendering_api](Shell& shell) {
std::unique_ptr<PlatformViewAndroid> platform_view_android;
platform_view_android = std::make_unique<PlatformViewAndroid>(
shell, // delegate
shell.GetTaskRunners(), // task runners
jni_facade, // JNI interop
shell.GetSettings()
.enable_software_rendering // use software rendering
rendering_api // rendering API
);
weak_platform_view = platform_view_android->GetWeakPtr();
return platform_view_android;
Expand Down Expand Up @@ -188,13 +187,15 @@ AndroidShellHolder::AndroidShellHolder(
const std::shared_ptr<ThreadHost>& thread_host,
std::unique_ptr<Shell> shell,
std::unique_ptr<APKAssetProvider> apk_asset_provider,
const fml::WeakPtr<PlatformViewAndroid>& platform_view)
const fml::WeakPtr<PlatformViewAndroid>& platform_view,
AndroidRenderingAPI rendering_api)
: settings_(settings),
jni_facade_(jni_facade),
platform_view_(platform_view),
thread_host_(thread_host),
shell_(std::move(shell)),
apk_asset_provider_(std::move(apk_asset_provider)) {
apk_asset_provider_(std::move(apk_asset_provider)),
android_rendering_api_(rendering_api) {
FML_DCHECK(jni_facade);
FML_DCHECK(shell_);
FML_DCHECK(shell_->IsSetup());
Expand Down Expand Up @@ -275,7 +276,8 @@ std::unique_ptr<AndroidShellHolder> AndroidShellHolder::Spawn(

return std::unique_ptr<AndroidShellHolder>(new AndroidShellHolder(
GetSettings(), jni_facade, thread_host_, std::move(shell),
apk_asset_provider_->Clone(), weak_platform_view));
apk_asset_provider_->Clone(), weak_platform_view,
android_context->RenderingApi()));
}

void AndroidShellHolder::Launch(
Expand Down
13 changes: 6 additions & 7 deletions engine/src/flutter/shell/platform/android/android_shell_holder.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@

#include <memory>

#include "flutter/assets/asset_manager.h"
#include "flutter/fml/macros.h"
#include "flutter/fml/unique_fd.h"
#include "flutter/lib/ui/window/viewport_metrics.h"
#include "flutter/runtime/platform_data.h"
#include "flutter/shell/common/run_configuration.h"
#include "flutter/shell/common/shell.h"
#include "flutter/shell/common/thread_host.h"
#include "flutter/shell/platform/android/android_rendering_selector.h"
#include "flutter/shell/platform/android/apk_asset_provider.h"
#include "flutter/shell/platform/android/jni/platform_view_android_jni.h"
#include "flutter/shell/platform/android/platform_message_handler_android.h"
#include "flutter/shell/platform/android/platform_view_android.h"

namespace flutter {
Expand All @@ -42,7 +38,8 @@ namespace flutter {
class AndroidShellHolder {
public:
AndroidShellHolder(const flutter::Settings& settings,
std::shared_ptr<PlatformViewAndroidJNI> jni_facade);
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
AndroidRenderingAPI android_rendering_api);

~AndroidShellHolder();

Expand Down Expand Up @@ -119,6 +116,7 @@ class AndroidShellHolder {
bool is_valid_ = false;
uint64_t next_pointer_flow_id_ = 0;
std::unique_ptr<APKAssetProvider> apk_asset_provider_;
const AndroidRenderingAPI android_rendering_api_;

//----------------------------------------------------------------------------
/// @brief Constructor with its components injected.
Expand All @@ -136,7 +134,8 @@ class AndroidShellHolder {
const std::shared_ptr<ThreadHost>& thread_host,
std::unique_ptr<Shell> shell,
std::unique_ptr<APKAssetProvider> apk_asset_provider,
const fml::WeakPtr<PlatformViewAndroid>& platform_view);
const fml::WeakPtr<PlatformViewAndroid>& platform_view,
AndroidRenderingAPI rendering_api);
static void ThreadDestructCallback(void* value);
std::optional<RunConfiguration> BuildRunConfiguration(
const std::string& entrypoint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ TEST(AndroidShellHolder, Create) {
Settings settings;
settings.enable_software_rendering = false;
auto jni = std::make_shared<MockPlatformViewAndroidJNI>();
auto holder = std::make_unique<AndroidShellHolder>(settings, jni);
auto holder = std::make_unique<AndroidShellHolder>(
settings, jni, AndroidRenderingAPI::kImpellerOpenGLES);
EXPECT_NE(holder.get(), nullptr);
EXPECT_TRUE(holder->IsValid());
EXPECT_NE(holder->GetPlatformView().get(), nullptr);
Expand All @@ -158,7 +159,8 @@ TEST(AndroidShellHolder, HandlePlatformMessage) {
Settings settings;
settings.enable_software_rendering = false;
auto jni = std::make_shared<MockPlatformViewAndroidJNI>();
auto holder = std::make_unique<AndroidShellHolder>(settings, jni);
auto holder = std::make_unique<AndroidShellHolder>(
settings, jni, AndroidRenderingAPI::kImpellerOpenGLES);
EXPECT_NE(holder.get(), nullptr);
EXPECT_TRUE(holder->IsValid());
EXPECT_NE(holder->GetPlatformView().get(), nullptr);
Expand Down Expand Up @@ -186,7 +188,8 @@ TEST(AndroidShellHolder, HandlePlatformMessage) {
TEST(AndroidShellHolder, CreateWithMergedPlatformAndUIThread) {
Settings settings;
auto jni = std::make_shared<MockPlatformViewAndroidJNI>();
auto holder = std::make_unique<AndroidShellHolder>(settings, jni);
auto holder = std::make_unique<AndroidShellHolder>(
settings, jni, AndroidRenderingAPI::kImpellerOpenGLES);
auto window = fml::MakeRefCounted<AndroidNativeWindow>(
nullptr, /*is_fake_window=*/true);
holder->GetPlatformView()->NotifyCreated(window);
Expand All @@ -200,7 +203,8 @@ TEST(AndroidShellHolder, CreateWithUnMergedPlatformAndUIThread) {
Settings settings;
settings.merged_platform_ui_thread = false;
auto jni = std::make_shared<MockPlatformViewAndroidJNI>();
auto holder = std::make_unique<AndroidShellHolder>(settings, jni);
auto holder = std::make_unique<AndroidShellHolder>(
settings, jni, AndroidRenderingAPI::kImpellerOpenGLES);
auto window = fml::MakeRefCounted<AndroidNativeWindow>(
nullptr, /*is_fake_window=*/true);
holder->GetPlatformView()->NotifyCreated(window);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
#ifndef FLUTTER_SHELL_PLATFORM_ANDROID_CONTEXT_ANDROID_CONTEXT_H_
#define FLUTTER_SHELL_PLATFORM_ANDROID_CONTEXT_ANDROID_CONTEXT_H_

#include "common/settings.h"
#include "flutter/fml/macros.h"
#include "flutter/fml/task_runner.h"
#include "flutter/impeller/renderer/context.h"
#include "flutter/shell/platform/android/android_rendering_selector.h"
#include "third_party/skia/include/gpu/ganesh/GrDirectContext.h"

namespace flutter {
Expand Down
22 changes: 11 additions & 11 deletions engine/src/flutter/shell/platform/android/flutter_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,18 @@
#include "flutter/fml/command_line.h"
#include "flutter/fml/file.h"
#include "flutter/fml/logging.h"
#include "flutter/fml/macros.h"
#include "flutter/fml/message_loop.h"
#include "flutter/fml/native_library.h"
#include "flutter/fml/paths.h"
#include "flutter/fml/platform/android/jni_util.h"
#include "flutter/fml/platform/android/paths_android.h"
#include "flutter/lib/ui/plugins/callback_cache.h"
#include "flutter/runtime/dart_vm.h"
#include "flutter/shell/common/shell.h"
#include "flutter/shell/common/switches.h"
#include "flutter/shell/platform/android/android_context_vk_impeller.h"
#include "flutter/shell/platform/android/android_rendering_selector.h"
#include "flutter/shell/platform/android/context/android_context.h"
#include "flutter/shell/platform/android/flutter_main.h"
#include "impeller/base/validation.h"
#include "impeller/toolkit/android/proc_table.h"
#include "third_party/dart/runtime/include/dart_tools_api.h"
#include "txt/platform.h"

namespace flutter {
Expand Down Expand Up @@ -68,8 +64,9 @@ static constexpr const char* kBLC[] = {

} // anonymous namespace

FlutterMain::FlutterMain(const flutter::Settings& settings)
: settings_(settings) {}
FlutterMain::FlutterMain(const flutter::Settings& settings,
flutter::AndroidRenderingAPI android_rendering_api)
: settings_(settings), android_rendering_api_(android_rendering_api) {}

FlutterMain::~FlutterMain() = default;

Expand All @@ -85,6 +82,10 @@ const flutter::Settings& FlutterMain::GetSettings() const {
return settings_;
}

flutter::AndroidRenderingAPI FlutterMain::GetAndroidRenderingAPI() {
return android_rendering_api_;
}

void FlutterMain::Init(JNIEnv* env,
jclass clazz,
jobject context,
Expand Down Expand Up @@ -116,8 +117,8 @@ void FlutterMain::Init(JNIEnv* env,
}
}

settings.android_rendering_api = SelectedRenderingAPI(settings);
switch (settings.android_rendering_api) {
AndroidRenderingAPI android_rendering_api = SelectedRenderingAPI(settings);
switch (android_rendering_api) {
case AndroidRenderingAPI::kSoftware:
case AndroidRenderingAPI::kSkiaOpenGLES:
settings.enable_impeller = false;
Expand Down Expand Up @@ -187,8 +188,7 @@ void FlutterMain::Init(JNIEnv* env,

// Not thread safe. Will be removed when FlutterMain is refactored to no
// longer be a singleton.
g_flutter_main.reset(new FlutterMain(settings));

g_flutter_main.reset(new FlutterMain(settings, android_rendering_api));
g_flutter_main->SetupDartVMServiceUriCallback(env);
}

Expand Down
6 changes: 5 additions & 1 deletion engine/src/flutter/shell/platform/android/flutter_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "flutter/common/settings.h"
#include "flutter/fml/macros.h"
#include "flutter/runtime/dart_service_isolate.h"
#include "flutter/shell/platform/android/android_rendering_selector.h"

namespace flutter {

Expand All @@ -22,6 +23,7 @@ class FlutterMain {
static FlutterMain& Get();

const flutter::Settings& GetSettings() const;
flutter::AndroidRenderingAPI GetAndroidRenderingAPI();

static AndroidRenderingAPI SelectedRenderingAPI(
const flutter::Settings& settings);
Expand All @@ -32,9 +34,11 @@ class FlutterMain {

private:
const flutter::Settings settings_;
const flutter::AndroidRenderingAPI android_rendering_api_;
DartServiceIsolate::CallbackHandle vm_service_uri_callback_ = 0;

explicit FlutterMain(const flutter::Settings& settings);
explicit FlutterMain(const flutter::Settings& settings,
flutter::AndroidRenderingAPI android_rendering_api);

static void Init(JNIEnv* env,
jclass clazz,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@

#include <utility>

#include "flutter/fml/macros.h"
#include "flutter/fml/mapping.h"

#include "flutter/flow/embedded_views.h"
#include "flutter/lib/ui/window/platform_message.h"
#include "flutter/shell/platform/android/surface/android_native_window.h"
#include "third_party/skia/include/core/SkMatrix.h"

#if FML_OS_ANDROID
#include "flutter/fml/platform/android/scoped_java_ref.h"
Expand Down
Loading

0 comments on commit 7535cb1

Please sign in to comment.