Unverified Commit 3a1300e0 authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Automatically create the layer when setting hints in PaintingContext (#130364)

Fixes https://github.com/flutter/flutter/issues/92722
parent 123413b0
...@@ -397,8 +397,16 @@ class PaintingContext extends ClipContext { ...@@ -397,8 +397,16 @@ class PaintingContext extends ClipContext {
/// If this hint is not set, the compositor will apply its own heuristics to /// 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 /// decide whether the current layer is complex enough to benefit from
/// caching. /// 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() { 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. /// Hints that the painting in the current layer is likely to change next frame.
...@@ -407,8 +415,16 @@ class PaintingContext extends ClipContext { ...@@ -407,8 +415,16 @@ class PaintingContext extends ClipContext {
/// cache will not be used in the future. If this hint is not set, the /// 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 /// compositor will apply its own heuristics to decide whether the current
/// layer is likely to be reused in the future. /// 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() { void setWillChangeHint() {
_currentLayer?.willChangeHint = true; if (_currentLayer == null) {
_startRecording();
}
_currentLayer!.willChangeHint = true;
} }
/// Adds a composited leaf layer to the recording. /// Adds a composited leaf layer to the recording.
......
// 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);
});
}
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