Automatically create the layer when setting hints in PaintingContext (#130364)
Fixes https://github.com/flutter/flutter/issues/92722
This commit is contained in:
parent
123413b052
commit
3a1300e0c4
@ -397,8 +397,16 @@ class PaintingContext extends ClipContext {
|
||||
/// If this hint is not set, the compositor will apply its own heuristics to
|
||||
/// decide whether the current layer is complex enough to benefit from
|
||||
/// caching.
|
||||
///
|
||||
/// Calling this ensures a [Canvas] is available. Only draw calls on the
|
||||
/// current canvas will be hinted; the hint is not propagated to new canvases
|
||||
/// created after a new layer is added to the painting context (e.g. with
|
||||
/// [addLayer] or [pushLayer]).
|
||||
void setIsComplexHint() {
|
||||
_currentLayer?.isComplexHint = true;
|
||||
if (_currentLayer == null) {
|
||||
_startRecording();
|
||||
}
|
||||
_currentLayer!.isComplexHint = true;
|
||||
}
|
||||
|
||||
/// Hints that the painting in the current layer is likely to change next frame.
|
||||
@ -407,8 +415,16 @@ class PaintingContext extends ClipContext {
|
||||
/// cache will not be used in the future. If this hint is not set, the
|
||||
/// compositor will apply its own heuristics to decide whether the current
|
||||
/// layer is likely to be reused in the future.
|
||||
///
|
||||
/// Calling this ensures a [Canvas] is available. Only draw calls on the
|
||||
/// current canvas will be hinted; the hint is not propagated to new canvases
|
||||
/// created after a new layer is added to the painting context (e.g. with
|
||||
/// [addLayer] or [pushLayer]).
|
||||
void setWillChangeHint() {
|
||||
_currentLayer?.willChangeHint = true;
|
||||
if (_currentLayer == null) {
|
||||
_startRecording();
|
||||
}
|
||||
_currentLayer!.willChangeHint = true;
|
||||
}
|
||||
|
||||
/// Adds a composited leaf layer to the recording.
|
||||
|
32
packages/flutter/test/rendering/painting_context_test.dart
Normal file
32
packages/flutter/test/rendering/painting_context_test.dart
Normal file
@ -0,0 +1,32 @@
|
||||
// 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';
|
||||
|
||||
import 'rendering_tester.dart';
|
||||
|
||||
void main() {
|
||||
TestRenderingFlutterBinding.ensureInitialized();
|
||||
|
||||
test('PaintingContext.setIsComplexHint', () {
|
||||
final ContainerLayer layer = ContainerLayer();
|
||||
final PaintingContext context = PaintingContext(layer, Rect.zero);
|
||||
expect(layer.hasChildren, isFalse);
|
||||
context.setIsComplexHint();
|
||||
expect(layer.hasChildren, isTrue);
|
||||
expect(layer.firstChild, isA<PictureLayer>());
|
||||
expect((layer.firstChild! as PictureLayer).isComplexHint, isTrue);
|
||||
});
|
||||
|
||||
test('PaintingContext.setWillChangeHint', () {
|
||||
final ContainerLayer layer = ContainerLayer();
|
||||
final PaintingContext context = PaintingContext(layer, Rect.zero);
|
||||
expect(layer.hasChildren, isFalse);
|
||||
context.setWillChangeHint();
|
||||
expect(layer.hasChildren, isTrue);
|
||||
expect(layer.firstChild, isA<PictureLayer>());
|
||||
expect((layer.firstChild! as PictureLayer).willChangeHint, isTrue);
|
||||
});
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user