Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 17c7206

Browse files
committed
Assign implicitViewEnabled from C++
1 parent 25fb2aa commit 17c7206

File tree

8 files changed

+44
-34
lines changed

8 files changed

+44
-34
lines changed

common/settings.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ struct Settings {
224224
// must be available to the application.
225225
bool enable_vulkan_validation = false;
226226

227+
// Enable the implicit view, so that the shell should create a view with
228+
// kFlutterImplicitViewId without the platform calling FlutterEngineAddView.
229+
bool enable_implicit_view = true;
230+
227231
// Data set by platform-specific embedders for use in font initialization.
228232
uint32_t font_initialization_data = 0;
229233

lib/ui/dart_ui.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ typedef CanvasPath Path;
9696
V(IsolateNameServerNatives::RemovePortNameMapping, 1) \
9797
V(NativeStringAttribute::initLocaleStringAttribute, 4) \
9898
V(NativeStringAttribute::initSpellOutStringAttribute, 3) \
99-
V(PlatformConfigurationNativeApi::ImplicitViewEnabled, 0) \
10099
V(PlatformConfigurationNativeApi::DefaultRouteName, 0) \
101100
V(PlatformConfigurationNativeApi::ScheduleFrame, 0) \
102101
V(PlatformConfigurationNativeApi::Render, 1) \
@@ -381,6 +380,14 @@ void DartUI::InitForIsolate(const Settings& settings) {
381380
Dart_PropagateError(result);
382381
}
383382
}
383+
384+
if (settings.enable_implicit_view) {
385+
result =
386+
Dart_SetField(dart_ui, ToDart("_implicitViewEnabled"), Dart_True());
387+
if (Dart_IsError(result)) {
388+
Dart_PropagateError(result);
389+
}
390+
}
384391
}
385392

386393
} // namespace flutter

lib/ui/natives.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,7 @@ _ScheduleImmediateClosure _getScheduleMicrotaskClosure() => _scheduleMicrotask;
135135
// rendering.
136136
@pragma('vm:entry-point')
137137
bool _impellerEnabled = false;
138+
139+
// Used internally to indicate whether the platform uses the implicit view.
140+
@pragma('vm:entry-point')
141+
bool _implicitViewEnabled = false;

lib/ui/platform_dispatcher.dart

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ class PlatformDispatcher {
118118
/// these. Use [instance] to access the singleton.
119119
PlatformDispatcher._() {
120120
_setNeedsReportTimings = _nativeSetNeedsReportTimings;
121+
if (_implicitViewEnabled) {
122+
_doAddView(_kImplicitViewId);
123+
}
121124
}
122125

123126
/// The [PlatformDispatcher] singleton.
@@ -225,18 +228,8 @@ class PlatformDispatcher {
225228
/// * [PlatformDispatcher.views] for a list of all [FlutterView]s provided
226229
/// by the platform.
227230
FlutterView? get implicitView {
228-
if (_implicitViewEnabled()) {
229-
if (_implicitView == null) {
230-
_addView(_kImplicitViewId);
231-
}
232-
return _implicitView!;
233-
}
234-
return null;
231+
return _views[_kImplicitViewId];
235232
}
236-
FlutterView? _implicitView;
237-
238-
@Native<Handle Function()>(symbol: 'PlatformConfigurationNativeApi::ImplicitViewEnabled')
239-
external static bool _implicitViewEnabled();
240233

241234
/// A callback that is invoked whenever the [ViewConfiguration] of any of the
242235
/// [views] changes.
@@ -265,22 +258,23 @@ class PlatformDispatcher {
265258
}
266259

267260
FlutterView _createView(int id) {
268-
if (id == _kImplicitViewId) {
269-
assert(_implicitViewEnabled());
270-
return _implicitView ??= FlutterView._(id, this);
271-
}
272261
return FlutterView._(id, this);
273262
}
274263

275264
void _addView(int id) {
276-
assert(!_views.containsKey(id));
265+
assert(id != _kImplicitViewId, 'The implicit view #$id can not be added.');
266+
_doAddView(id);
267+
}
268+
269+
void _doAddView(int id) {
270+
assert(!_views.containsKey(id), 'View ID $id already exists.');
277271
_views[id] = _createView(id);
278272
_viewConfigurations[id] = const _ViewConfiguration();
279273
}
280274

281275
void _removeView(int id) {
282-
assert(!_views.containsKey(id));
283-
// TODO(dkwingsmt): Reset _implicitView?
276+
assert(id != _kImplicitViewId, 'The implicit view #$id can not be removed.');
277+
assert(_views.containsKey(id), 'View ID $id does not exist.');
284278
_views.remove(id);
285279
_viewConfigurations.remove(id);
286280
}

lib/ui/window/platform_configuration.cc

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ PlatformConfiguration::PlatformConfiguration(
3636
PlatformConfigurationClient* client)
3737
: client_(client) {
3838
if (client_->ImplicitViewEnabled()) {
39-
AddView(kFlutterDefaultViewId);
39+
DoAddView(kFlutterDefaultViewId);
4040
}
4141
}
4242

@@ -89,11 +89,17 @@ void PlatformConfiguration::DidCreateIsolate() {
8989
}
9090

9191
void PlatformConfiguration::AddView(int64_t view_id) {
92-
// TODO(dkwingsmt): How do I access the current dart state after
93-
// DidCreateIsolate?
92+
FML_DCHECK(view_id != kFlutterDefaultViewId);
93+
DoAddView(view_id);
94+
}
95+
96+
void PlatformConfiguration::DoAddView(int64_t view_id) {
9497
windows_.emplace(
9598
view_id, std::make_unique<Window>(library_, view_id,
9699
ViewportMetrics{1.0, 0.0, 0.0, -1, 0}));
100+
if (view_id == kFlutterDefaultViewId) {
101+
return;
102+
}
97103
std::shared_ptr<tonic::DartState> dart_state = add_view_.dart_state().lock();
98104
if (!dart_state) {
99105
return;
@@ -106,6 +112,7 @@ void PlatformConfiguration::AddView(int64_t view_id) {
106112
}
107113

108114
void PlatformConfiguration::RemoveView(int64_t view_id) {
115+
FML_DCHECK(view_id != kFlutterDefaultViewId);
109116
windows_.erase(view_id);
110117
std::shared_ptr<tonic::DartState> dart_state =
111118
remove_view_.dart_state().lock();
@@ -527,16 +534,6 @@ Dart_Handle PlatformConfigurationNativeApi::ComputePlatformResolvedLocale(
527534
return tonic::DartConverter<std::vector<std::string>>::ToDart(results);
528535
}
529536

530-
Dart_Handle PlatformConfigurationNativeApi::ImplicitViewEnabled() {
531-
UIDartState::ThrowIfUIOperationsProhibited();
532-
bool enabled = UIDartState::Current()
533-
->platform_configuration()
534-
->client()
535-
->ImplicitViewEnabled();
536-
537-
return Dart_NewBoolean(enabled);
538-
}
539-
540537
std::string PlatformConfigurationNativeApi::DefaultRouteName() {
541538
UIDartState::ThrowIfUIOperationsProhibited();
542539
return UIDartState::Current()

lib/ui/window/platform_configuration.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,8 @@ class PlatformConfiguration final {
480480
int next_response_id_ = 1;
481481
std::unordered_map<int, fml::RefPtr<PlatformMessageResponse>>
482482
pending_responses_;
483+
484+
void DoAddView(int64_t view_id);
483485
};
484486

485487
//----------------------------------------------------------------------------
@@ -508,8 +510,6 @@ class PlatformMessageHandlerStorage {
508510
//----------------------------------------------------------------------------
509511
class PlatformConfigurationNativeApi {
510512
public:
511-
static Dart_Handle ImplicitViewEnabled();
512-
513513
static std::string DefaultRouteName();
514514

515515
static void ScheduleFrame();

shell/platform/embedder/embedder.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,6 +1813,8 @@ FlutterEngineResult FlutterEngineInitialize(size_t version,
18131813
settings.assets_path = args->assets_path;
18141814
settings.leak_vm = !SAFE_ACCESS(args, shutdown_dart_vm_when_done, false);
18151815
settings.old_gen_heap_size = SAFE_ACCESS(args, dart_old_gen_heap_size, -1);
1816+
settings.enable_implicit_view =
1817+
!SAFE_ACCESS(args, implicit_view_disabled, false);
18161818

18171819
if (!flutter::DartVM::IsRunningPrecompiledCode()) {
18181820
// Verify the assets path contains Dart 2 kernel assets.

shell/platform/embedder/embedder.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2113,6 +2113,8 @@ typedef struct {
21132113
/// and `update_semantics_callback2` may be provided; the others must be set
21142114
/// to null.
21152115
FlutterUpdateSemanticsCallback2 update_semantics_callback2;
2116+
2117+
bool implicit_view_disabled;
21162118
} FlutterProjectArgs;
21172119

21182120
#ifndef FLUTTER_ENGINE_NO_PROTOTYPES

0 commit comments

Comments
 (0)