Unverified Commit 670f9d20 authored by Jim Graham's avatar Jim Graham Committed by GitHub

Revert "Introduce the PipelineOwner tree (#122231)" (#122425)

This reverts commit f73c358e.
parent f73c358e
......@@ -30,6 +30,7 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
super.initInstances();
_instance = this;
_pipelineOwner = PipelineOwner(
onNeedVisualUpdate: ensureVisualUpdate,
onSemanticsOwnerCreated: _handleSemanticsOwnerCreated,
onSemanticsUpdate: _handleSemanticsUpdate,
onSemanticsOwnerDisposed: _handleSemanticsOwnerDisposed,
......@@ -44,7 +45,8 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
if (kIsWeb) {
addPostFrameCallback(_handleWebFirstFrame);
}
_pipelineOwner.attach(_manifold);
addSemanticsEnabledListener(_handleSemanticsEnabledChanged);
_handleSemanticsEnabledChanged();
}
/// The current [RendererBinding], if one has been created.
......@@ -199,8 +201,6 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
}
}
late final PipelineManifold _manifold = _BindingPipelineManifold(this);
/// Creates a [RenderView] object to be the root of the
/// [RenderObject] rendering tree, and initializes it so that it
/// will be rendered when the next frame is requested.
......@@ -330,6 +330,17 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
super.dispatchEvent(event, hitTestResult);
}
SemanticsHandle? _semanticsHandle;
void _handleSemanticsEnabledChanged() {
if (semanticsEnabled) {
_semanticsHandle ??= _pipelineOwner.ensureSemantics();
} else {
_semanticsHandle?.dispose();
_semanticsHandle = null;
}
}
@override
void performSemanticsAction(SemanticsActionEvent action) {
_pipelineOwner.semanticsOwner?.performAction(action.nodeId, action.type, action.arguments);
......@@ -610,26 +621,3 @@ class RenderingFlutterBinding extends BindingBase with GestureBinding, Scheduler
return RendererBinding.instance;
}
}
/// A [PipelineManifold] implementation that is backed by the [RendererBinding].
class _BindingPipelineManifold extends ChangeNotifier implements PipelineManifold {
_BindingPipelineManifold(this._binding) {
_binding.addSemanticsEnabledListener(notifyListeners);
}
final RendererBinding _binding;
@override
void requestVisualUpdate() {
_binding.ensureVisualUpdate();
}
@override
bool get semanticsEnabled => _binding.semanticsEnabled;
@override
void dispose() {
_binding.removeSemanticsEnabledListener(notifyListeners);
super.dispose();
}
}
// Copyright 2014 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.
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
test('Initializing the RendererBinding does not crash when semantics is enabled', () {
try {
MyRenderingFlutterBinding();
} catch (e) {
fail('Initializing the RenderingBinding threw an unexpected error:\n$e');
}
expect(RendererBinding.instance, isA<MyRenderingFlutterBinding>());
expect(SemanticsBinding.instance.semanticsEnabled, isTrue);
});
}
// Binding that pretends the platform had semantics enabled before the binding
// is initialized.
class MyRenderingFlutterBinding extends RenderingFlutterBinding {
@override
bool get semanticsEnabled => true;
}
// Copyright 2014 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.
import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import 'rendering_tester.dart';
void main() {
MyTestRenderingFlutterBinding.ensureInitialized();
tearDown(() {
final List<PipelineOwner> children = <PipelineOwner>[];
RendererBinding.instance.pipelineOwner.visitChildren((PipelineOwner child) {
children.add(child);
});
children.forEach(RendererBinding.instance.pipelineOwner.dropChild);
});
test("BindingPipelineManifold notifies binding if render object managed by binding's PipelineOwner tree needs visual update", () {
final PipelineOwner child = PipelineOwner();
RendererBinding.instance.pipelineOwner.adoptChild(child);
final RenderObject renderObject = TestRenderObject();
child.rootNode = renderObject;
renderObject.scheduleInitialLayout();
RendererBinding.instance.pipelineOwner.flushLayout();
MyTestRenderingFlutterBinding.instance.ensureVisualUpdateCount = 0;
renderObject.markNeedsLayout();
expect(MyTestRenderingFlutterBinding.instance.ensureVisualUpdateCount, 1);
});
test('Turning global semantics on/off creates semantics owners in PipelineOwner tree', () {
final PipelineOwner child = PipelineOwner(
onSemanticsUpdate: (_) { },
);
RendererBinding.instance.pipelineOwner.adoptChild(child);
expect(child.semanticsOwner, isNull);
expect(RendererBinding.instance.pipelineOwner.semanticsOwner, isNull);
final SemanticsHandle handle = SemanticsBinding.instance.ensureSemantics();
expect(child.semanticsOwner, isNotNull);
expect(RendererBinding.instance.pipelineOwner.semanticsOwner, isNotNull);
handle.dispose();
expect(child.semanticsOwner, isNull);
expect(RendererBinding.instance.pipelineOwner.semanticsOwner, isNull);
});
}
class MyTestRenderingFlutterBinding extends TestRenderingFlutterBinding {
static MyTestRenderingFlutterBinding get instance => BindingBase.checkInstance(_instance);
static MyTestRenderingFlutterBinding? _instance;
static MyTestRenderingFlutterBinding ensureInitialized() {
if (_instance != null) {
return _instance!;
}
return MyTestRenderingFlutterBinding();
}
@override
void initInstances() {
super.initInstances();
_instance = this;
}
int ensureVisualUpdateCount = 0;
@override
void ensureVisualUpdate() {
super.ensureVisualUpdate();
ensureVisualUpdateCount++;
}
}
class TestRenderObject extends RenderObject {
@override
void debugAssertDoesMeetConstraints() { }
@override
Rect get paintBounds => Rect.zero;
@override
void performLayout() { }
@override
void performResize() { }
@override
Rect get semanticBounds => Rect.zero;
}
......@@ -1045,7 +1045,7 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
void _verifySemanticsHandlesWereDisposed() {
assert(_lastRecordedSemanticsHandles != null);
// TODO(goderbauer): Fix known leak in web engine when running integration tests and remove this "correction", https://github.com/flutter/flutter/issues/121640.
final int knownWebEngineLeakForLiveTestsCorrection = kIsWeb && binding is LiveTestWidgetsFlutterBinding ? 1 : 0;
final int knownWebEngineLeakForLiveTestsCorrection = kIsWeb && binding is LiveTestWidgetsFlutterBinding ? 2 : 0;
if (_currentSemanticsHandles - knownWebEngineLeakForLiveTestsCorrection > _lastRecordedSemanticsHandles!) {
throw FlutterError.fromParts(<DiagnosticsNode>[
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment