Skip to content

Commit 7535cb1

Browse files
matanlureyJonah Williams
andauthored
Move AndroidRenderingApi from common to shell/platform/android (#163796)
Towards flutter/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 <jonahwilliams@google.com>
1 parent ebc7d24 commit 7535cb1

14 files changed

+76
-67
lines changed

engine/src/flutter/ci/licenses_golden/licenses_flutter

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42960,6 +42960,7 @@ ORIGIN: ../../../flutter/shell/platform/android/android_environment_gl.h + ../..
4296042960
ORIGIN: ../../../flutter/shell/platform/android/android_exports.lst + ../../../flutter/LICENSE
4296142961
ORIGIN: ../../../flutter/shell/platform/android/android_image_generator.cc + ../../../flutter/LICENSE
4296242962
ORIGIN: ../../../flutter/shell/platform/android/android_image_generator.h + ../../../flutter/LICENSE
42963+
ORIGIN: ../../../flutter/shell/platform/android/android_rendering_selector.h + ../../../flutter/LICENSE
4296342964
ORIGIN: ../../../flutter/shell/platform/android/android_shell_holder.cc + ../../../flutter/LICENSE
4296442965
ORIGIN: ../../../flutter/shell/platform/android/android_shell_holder.h + ../../../flutter/LICENSE
4296542966
ORIGIN: ../../../flutter/shell/platform/android/android_surface_gl_impeller.cc + ../../../flutter/LICENSE
@@ -45876,6 +45877,7 @@ FILE: ../../../flutter/shell/platform/android/android_environment_gl.h
4587645877
FILE: ../../../flutter/shell/platform/android/android_exports.lst
4587745878
FILE: ../../../flutter/shell/platform/android/android_image_generator.cc
4587845879
FILE: ../../../flutter/shell/platform/android/android_image_generator.h
45880+
FILE: ../../../flutter/shell/platform/android/android_rendering_selector.h
4587945881
FILE: ../../../flutter/shell/platform/android/android_shell_holder.cc
4588045882
FILE: ../../../flutter/shell/platform/android/android_shell_holder.h
4588145883
FILE: ../../../flutter/shell/platform/android/android_surface_gl_impeller.cc

engine/src/flutter/common/settings.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
#include <fcntl.h>
99

10-
#include <chrono>
1110
#include <cstdint>
1211
#include <memory>
1312
#include <optional>
@@ -22,14 +21,6 @@
2221

2322
namespace flutter {
2423

25-
// The combination of targeted graphics API and Impeller support.
26-
enum class AndroidRenderingAPI {
27-
kSoftware,
28-
kImpellerOpenGLES,
29-
kImpellerVulkan,
30-
kSkiaOpenGLES
31-
};
32-
3324
class FrameTiming {
3425
public:
3526
enum Phase {
@@ -240,10 +231,6 @@ struct Settings {
240231
// Log a warning during shell initialization if Impeller is not enabled.
241232
bool warn_on_impeller_opt_out = false;
242233

243-
// The selected Android rendering API.
244-
AndroidRenderingAPI android_rendering_api =
245-
AndroidRenderingAPI::kSkiaOpenGLES;
246-
247234
// Requests a specific rendering backend.
248235
std::optional<std::string> requested_rendering_backend;
249236

engine/src/flutter/shell/platform/android/android_context_vk_impeller.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#ifndef FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_CONTEXT_VK_IMPELLER_H_
66
#define FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_CONTEXT_VK_IMPELLER_H_
77

8-
#include "flutter/fml/concurrent_message_loop.h"
98
#include "flutter/fml/macros.h"
109
#include "flutter/fml/native_library.h"
1110
#include "flutter/shell/platform/android/context/android_context.h"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
#ifndef FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_RENDERING_SELECTOR_H_
6+
#define FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_RENDERING_SELECTOR_H_
7+
8+
namespace flutter {
9+
10+
// The combination of targeted graphics API and Impeller support.
11+
enum class AndroidRenderingAPI {
12+
kSoftware,
13+
kImpellerOpenGLES,
14+
kImpellerVulkan,
15+
kSkiaOpenGLES
16+
};
17+
18+
} // namespace flutter
19+
20+
#endif // FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_RENDERING_SELECTOR_H_

engine/src/flutter/shell/platform/android/android_shell_holder.cc

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,27 @@
44

55
#define FML_USED_ON_EMBEDDER
66

7-
#include "flutter/shell/platform/android/android_shell_holder.h"
8-
97
#include <pthread.h>
108
#include <sys/resource.h>
119
#include <sys/time.h>
1210
#include <memory>
1311
#include <optional>
1412

15-
#include <sstream>
1613
#include <string>
1714
#include <utility>
1815

1916
#include "common/settings.h"
2017
#include "flutter/fml/cpu_affinity.h"
2118
#include "flutter/fml/logging.h"
22-
#include "flutter/fml/make_copyable.h"
2319
#include "flutter/fml/message_loop.h"
24-
#include "flutter/fml/native_library.h"
25-
#include "flutter/fml/platform/android/jni_util.h"
2620
#include "flutter/lib/ui/painting/image_generator_registry.h"
2721
#include "flutter/shell/common/rasterizer.h"
2822
#include "flutter/shell/common/run_configuration.h"
2923
#include "flutter/shell/common/thread_host.h"
3024
#include "flutter/shell/platform/android/android_display.h"
3125
#include "flutter/shell/platform/android/android_image_generator.h"
26+
#include "flutter/shell/platform/android/android_rendering_selector.h"
27+
#include "flutter/shell/platform/android/android_shell_holder.h"
3228
#include "flutter/shell/platform/android/context/android_context.h"
3329
#include "flutter/shell/platform/android/platform_view_android.h"
3430

@@ -85,8 +81,11 @@ static PlatformData GetDefaultPlatformData() {
8581

8682
AndroidShellHolder::AndroidShellHolder(
8783
const flutter::Settings& settings,
88-
std::shared_ptr<PlatformViewAndroidJNI> jni_facade)
89-
: settings_(settings), jni_facade_(jni_facade) {
84+
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
85+
AndroidRenderingAPI android_rendering_api)
86+
: settings_(settings),
87+
jni_facade_(jni_facade),
88+
android_rendering_api_(android_rendering_api) {
9089
static size_t thread_host_count = 1;
9190
auto thread_label = std::to_string(thread_host_count++);
9291

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

115114
fml::WeakPtr<PlatformViewAndroid> weak_platform_view;
115+
AndroidRenderingAPI rendering_api = android_rendering_api_;
116116
Shell::CreateCallback<PlatformView> on_create_platform_view =
117-
[&jni_facade, &weak_platform_view](Shell& shell) {
117+
[&jni_facade, &weak_platform_view, rendering_api](Shell& shell) {
118118
std::unique_ptr<PlatformViewAndroid> platform_view_android;
119119
platform_view_android = std::make_unique<PlatformViewAndroid>(
120120
shell, // delegate
121121
shell.GetTaskRunners(), // task runners
122122
jni_facade, // JNI interop
123-
shell.GetSettings()
124-
.enable_software_rendering // use software rendering
123+
rendering_api // rendering API
125124
);
126125
weak_platform_view = platform_view_android->GetWeakPtr();
127126
return platform_view_android;
@@ -188,13 +187,15 @@ AndroidShellHolder::AndroidShellHolder(
188187
const std::shared_ptr<ThreadHost>& thread_host,
189188
std::unique_ptr<Shell> shell,
190189
std::unique_ptr<APKAssetProvider> apk_asset_provider,
191-
const fml::WeakPtr<PlatformViewAndroid>& platform_view)
190+
const fml::WeakPtr<PlatformViewAndroid>& platform_view,
191+
AndroidRenderingAPI rendering_api)
192192
: settings_(settings),
193193
jni_facade_(jni_facade),
194194
platform_view_(platform_view),
195195
thread_host_(thread_host),
196196
shell_(std::move(shell)),
197-
apk_asset_provider_(std::move(apk_asset_provider)) {
197+
apk_asset_provider_(std::move(apk_asset_provider)),
198+
android_rendering_api_(rendering_api) {
198199
FML_DCHECK(jni_facade);
199200
FML_DCHECK(shell_);
200201
FML_DCHECK(shell_->IsSetup());
@@ -275,7 +276,8 @@ std::unique_ptr<AndroidShellHolder> AndroidShellHolder::Spawn(
275276

276277
return std::unique_ptr<AndroidShellHolder>(new AndroidShellHolder(
277278
GetSettings(), jni_facade, thread_host_, std::move(shell),
278-
apk_asset_provider_->Clone(), weak_platform_view));
279+
apk_asset_provider_->Clone(), weak_platform_view,
280+
android_context->RenderingApi()));
279281
}
280282

281283
void AndroidShellHolder::Launch(

engine/src/flutter/shell/platform/android/android_shell_holder.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,13 @@
77

88
#include <memory>
99

10-
#include "flutter/assets/asset_manager.h"
1110
#include "flutter/fml/macros.h"
12-
#include "flutter/fml/unique_fd.h"
13-
#include "flutter/lib/ui/window/viewport_metrics.h"
14-
#include "flutter/runtime/platform_data.h"
1511
#include "flutter/shell/common/run_configuration.h"
1612
#include "flutter/shell/common/shell.h"
1713
#include "flutter/shell/common/thread_host.h"
14+
#include "flutter/shell/platform/android/android_rendering_selector.h"
1815
#include "flutter/shell/platform/android/apk_asset_provider.h"
1916
#include "flutter/shell/platform/android/jni/platform_view_android_jni.h"
20-
#include "flutter/shell/platform/android/platform_message_handler_android.h"
2117
#include "flutter/shell/platform/android/platform_view_android.h"
2218

2319
namespace flutter {
@@ -42,7 +38,8 @@ namespace flutter {
4238
class AndroidShellHolder {
4339
public:
4440
AndroidShellHolder(const flutter::Settings& settings,
45-
std::shared_ptr<PlatformViewAndroidJNI> jni_facade);
41+
std::shared_ptr<PlatformViewAndroidJNI> jni_facade,
42+
AndroidRenderingAPI android_rendering_api);
4643

4744
~AndroidShellHolder();
4845

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

123121
//----------------------------------------------------------------------------
124122
/// @brief Constructor with its components injected.
@@ -136,7 +134,8 @@ class AndroidShellHolder {
136134
const std::shared_ptr<ThreadHost>& thread_host,
137135
std::unique_ptr<Shell> shell,
138136
std::unique_ptr<APKAssetProvider> apk_asset_provider,
139-
const fml::WeakPtr<PlatformViewAndroid>& platform_view);
137+
const fml::WeakPtr<PlatformViewAndroid>& platform_view,
138+
AndroidRenderingAPI rendering_api);
140139
static void ThreadDestructCallback(void* value);
141140
std::optional<RunConfiguration> BuildRunConfiguration(
142141
const std::string& entrypoint,

engine/src/flutter/shell/platform/android/android_shell_holder_unittests.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ TEST(AndroidShellHolder, Create) {
145145
Settings settings;
146146
settings.enable_software_rendering = false;
147147
auto jni = std::make_shared<MockPlatformViewAndroidJNI>();
148-
auto holder = std::make_unique<AndroidShellHolder>(settings, jni);
148+
auto holder = std::make_unique<AndroidShellHolder>(
149+
settings, jni, AndroidRenderingAPI::kImpellerOpenGLES);
149150
EXPECT_NE(holder.get(), nullptr);
150151
EXPECT_TRUE(holder->IsValid());
151152
EXPECT_NE(holder->GetPlatformView().get(), nullptr);
@@ -158,7 +159,8 @@ TEST(AndroidShellHolder, HandlePlatformMessage) {
158159
Settings settings;
159160
settings.enable_software_rendering = false;
160161
auto jni = std::make_shared<MockPlatformViewAndroidJNI>();
161-
auto holder = std::make_unique<AndroidShellHolder>(settings, jni);
162+
auto holder = std::make_unique<AndroidShellHolder>(
163+
settings, jni, AndroidRenderingAPI::kImpellerOpenGLES);
162164
EXPECT_NE(holder.get(), nullptr);
163165
EXPECT_TRUE(holder->IsValid());
164166
EXPECT_NE(holder->GetPlatformView().get(), nullptr);
@@ -186,7 +188,8 @@ TEST(AndroidShellHolder, HandlePlatformMessage) {
186188
TEST(AndroidShellHolder, CreateWithMergedPlatformAndUIThread) {
187189
Settings settings;
188190
auto jni = std::make_shared<MockPlatformViewAndroidJNI>();
189-
auto holder = std::make_unique<AndroidShellHolder>(settings, jni);
191+
auto holder = std::make_unique<AndroidShellHolder>(
192+
settings, jni, AndroidRenderingAPI::kImpellerOpenGLES);
190193
auto window = fml::MakeRefCounted<AndroidNativeWindow>(
191194
nullptr, /*is_fake_window=*/true);
192195
holder->GetPlatformView()->NotifyCreated(window);
@@ -200,7 +203,8 @@ TEST(AndroidShellHolder, CreateWithUnMergedPlatformAndUIThread) {
200203
Settings settings;
201204
settings.merged_platform_ui_thread = false;
202205
auto jni = std::make_shared<MockPlatformViewAndroidJNI>();
203-
auto holder = std::make_unique<AndroidShellHolder>(settings, jni);
206+
auto holder = std::make_unique<AndroidShellHolder>(
207+
settings, jni, AndroidRenderingAPI::kImpellerOpenGLES);
204208
auto window = fml::MakeRefCounted<AndroidNativeWindow>(
205209
nullptr, /*is_fake_window=*/true);
206210
holder->GetPlatformView()->NotifyCreated(window);

engine/src/flutter/shell/platform/android/context/android_context.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
#ifndef FLUTTER_SHELL_PLATFORM_ANDROID_CONTEXT_ANDROID_CONTEXT_H_
66
#define FLUTTER_SHELL_PLATFORM_ANDROID_CONTEXT_ANDROID_CONTEXT_H_
77

8-
#include "common/settings.h"
98
#include "flutter/fml/macros.h"
10-
#include "flutter/fml/task_runner.h"
119
#include "flutter/impeller/renderer/context.h"
10+
#include "flutter/shell/platform/android/android_rendering_selector.h"
1211
#include "third_party/skia/include/gpu/ganesh/GrDirectContext.h"
1312

1413
namespace flutter {

engine/src/flutter/shell/platform/android/flutter_main.cc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,18 @@
1515
#include "flutter/fml/command_line.h"
1616
#include "flutter/fml/file.h"
1717
#include "flutter/fml/logging.h"
18-
#include "flutter/fml/macros.h"
1918
#include "flutter/fml/message_loop.h"
20-
#include "flutter/fml/native_library.h"
21-
#include "flutter/fml/paths.h"
2219
#include "flutter/fml/platform/android/jni_util.h"
2320
#include "flutter/fml/platform/android/paths_android.h"
2421
#include "flutter/lib/ui/plugins/callback_cache.h"
2522
#include "flutter/runtime/dart_vm.h"
26-
#include "flutter/shell/common/shell.h"
2723
#include "flutter/shell/common/switches.h"
2824
#include "flutter/shell/platform/android/android_context_vk_impeller.h"
25+
#include "flutter/shell/platform/android/android_rendering_selector.h"
2926
#include "flutter/shell/platform/android/context/android_context.h"
3027
#include "flutter/shell/platform/android/flutter_main.h"
3128
#include "impeller/base/validation.h"
3229
#include "impeller/toolkit/android/proc_table.h"
33-
#include "third_party/dart/runtime/include/dart_tools_api.h"
3430
#include "txt/platform.h"
3531

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

6965
} // anonymous namespace
7066

71-
FlutterMain::FlutterMain(const flutter::Settings& settings)
72-
: settings_(settings) {}
67+
FlutterMain::FlutterMain(const flutter::Settings& settings,
68+
flutter::AndroidRenderingAPI android_rendering_api)
69+
: settings_(settings), android_rendering_api_(android_rendering_api) {}
7370

7471
FlutterMain::~FlutterMain() = default;
7572

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

85+
flutter::AndroidRenderingAPI FlutterMain::GetAndroidRenderingAPI() {
86+
return android_rendering_api_;
87+
}
88+
8889
void FlutterMain::Init(JNIEnv* env,
8990
jclass clazz,
9091
jobject context,
@@ -116,8 +117,8 @@ void FlutterMain::Init(JNIEnv* env,
116117
}
117118
}
118119

119-
settings.android_rendering_api = SelectedRenderingAPI(settings);
120-
switch (settings.android_rendering_api) {
120+
AndroidRenderingAPI android_rendering_api = SelectedRenderingAPI(settings);
121+
switch (android_rendering_api) {
121122
case AndroidRenderingAPI::kSoftware:
122123
case AndroidRenderingAPI::kSkiaOpenGLES:
123124
settings.enable_impeller = false;
@@ -187,8 +188,7 @@ void FlutterMain::Init(JNIEnv* env,
187188

188189
// Not thread safe. Will be removed when FlutterMain is refactored to no
189190
// longer be a singleton.
190-
g_flutter_main.reset(new FlutterMain(settings));
191-
191+
g_flutter_main.reset(new FlutterMain(settings, android_rendering_api));
192192
g_flutter_main->SetupDartVMServiceUriCallback(env);
193193
}
194194

engine/src/flutter/shell/platform/android/flutter_main.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "flutter/common/settings.h"
1111
#include "flutter/fml/macros.h"
1212
#include "flutter/runtime/dart_service_isolate.h"
13+
#include "flutter/shell/platform/android/android_rendering_selector.h"
1314

1415
namespace flutter {
1516

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

2425
const flutter::Settings& GetSettings() const;
26+
flutter::AndroidRenderingAPI GetAndroidRenderingAPI();
2527

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

3335
private:
3436
const flutter::Settings settings_;
37+
const flutter::AndroidRenderingAPI android_rendering_api_;
3538
DartServiceIsolate::CallbackHandle vm_service_uri_callback_ = 0;
3639

37-
explicit FlutterMain(const flutter::Settings& settings);
40+
explicit FlutterMain(const flutter::Settings& settings,
41+
flutter::AndroidRenderingAPI android_rendering_api);
3842

3943
static void Init(JNIEnv* env,
4044
jclass clazz,

0 commit comments

Comments
 (0)