adding freeze parameter to Texture and TextureBox (#75738)
This commit is contained in:
@@ -559,9 +559,9 @@ class TextureLayer extends Layer {
|
||||
/// The identity of the backend texture.
|
||||
final int textureId;
|
||||
|
||||
/// When true the texture that will not be updated with new frames.
|
||||
/// When true the texture will not be updated with new frames.
|
||||
///
|
||||
/// This is used when resizing an embedded Android views: When resizing there
|
||||
/// This is used for resizing embedded Android views: when resizing there
|
||||
/// is a short period during which the framework cannot tell if the newest
|
||||
/// texture frame has the previous or new size, to workaround this the
|
||||
/// framework "freezes" the texture just before resizing the Android view and
|
||||
|
||||
@@ -38,9 +38,11 @@ class TextureBox extends RenderBox {
|
||||
/// [filterQuality] to set texture's [FilterQuality].
|
||||
TextureBox({
|
||||
required int textureId,
|
||||
bool freeze = false,
|
||||
FilterQuality filterQuality = FilterQuality.low,
|
||||
}) : assert(textureId != null),
|
||||
_textureId = textureId,
|
||||
_freeze = freeze,
|
||||
_filterQuality = filterQuality;
|
||||
|
||||
/// The identity of the backend texture.
|
||||
@@ -54,15 +56,26 @@ class TextureBox extends RenderBox {
|
||||
}
|
||||
}
|
||||
|
||||
/// When true the texture will not be updated with new frames.
|
||||
bool get freeze => _freeze;
|
||||
bool _freeze;
|
||||
set freeze(bool value) {
|
||||
assert(value != null);
|
||||
if (value != _freeze) {
|
||||
_freeze = value;
|
||||
markNeedsPaint();
|
||||
}
|
||||
}
|
||||
|
||||
/// {@macro flutter.widgets.Texture.filterQuality}
|
||||
FilterQuality get filterQuality => _filterQuality;
|
||||
FilterQuality _filterQuality;
|
||||
set filterQuality(FilterQuality value) {
|
||||
assert(value != null);
|
||||
if (value == _filterQuality)
|
||||
return;
|
||||
_filterQuality = value;
|
||||
markNeedsPaint();
|
||||
if (value != _filterQuality) {
|
||||
_filterQuality = value;
|
||||
markNeedsPaint();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -87,6 +100,7 @@ class TextureBox extends RenderBox {
|
||||
context.addLayer(TextureLayer(
|
||||
rect: Rect.fromLTWH(offset.dx, offset.dy, size.width, size.height),
|
||||
textureId: _textureId,
|
||||
freeze: freeze,
|
||||
filterQuality: _filterQuality,
|
||||
));
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ class Texture extends LeafRenderObjectWidget {
|
||||
const Texture({
|
||||
Key? key,
|
||||
required this.textureId,
|
||||
this.freeze = false,
|
||||
this.filterQuality = FilterQuality.low,
|
||||
}) : assert(textureId != null),
|
||||
super(key: key);
|
||||
@@ -45,6 +46,9 @@ class Texture extends LeafRenderObjectWidget {
|
||||
/// The identity of the backend texture.
|
||||
final int textureId;
|
||||
|
||||
/// When true the texture will not be updated with new frames.
|
||||
final bool freeze;
|
||||
|
||||
/// {@template flutter.widgets.Texture.filterQuality}
|
||||
/// The quality of sampling the texture and rendering it on screen.
|
||||
///
|
||||
@@ -56,11 +60,12 @@ class Texture extends LeafRenderObjectWidget {
|
||||
final FilterQuality filterQuality;
|
||||
|
||||
@override
|
||||
TextureBox createRenderObject(BuildContext context) => TextureBox(textureId: textureId, filterQuality: filterQuality);
|
||||
TextureBox createRenderObject(BuildContext context) => TextureBox(textureId: textureId, freeze: freeze, filterQuality: filterQuality);
|
||||
|
||||
@override
|
||||
void updateRenderObject(BuildContext context, TextureBox renderObject) {
|
||||
renderObject.textureId = textureId;
|
||||
renderObject.freeze = freeze;
|
||||
renderObject.filterQuality = filterQuality;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,37 @@ import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Texture with freeze set to true', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const Center(child: Texture(textureId: 1, freeze: true))
|
||||
);
|
||||
|
||||
final Texture texture = tester.firstWidget(find.byType(Texture));
|
||||
expect(texture, isNotNull);
|
||||
expect(texture.textureId, 1);
|
||||
expect(texture.freeze, true);
|
||||
|
||||
final RenderObject renderObject = tester.firstRenderObject(find.byType(Texture));
|
||||
expect(renderObject, isNotNull);
|
||||
final TextureBox textureBox = renderObject as TextureBox;
|
||||
expect(textureBox, isNotNull);
|
||||
expect(textureBox.textureId, 1);
|
||||
expect(textureBox.freeze, true);
|
||||
|
||||
final ContainerLayer containerLayer = ContainerLayer();
|
||||
final PaintingContext paintingContext = PaintingContext(containerLayer, Rect.zero);
|
||||
textureBox.paint(paintingContext, Offset.zero);
|
||||
final Layer layer = containerLayer.lastChild!;
|
||||
expect(layer, isNotNull);
|
||||
final TextureLayer textureLayer = layer as TextureLayer;
|
||||
expect(textureLayer, isNotNull);
|
||||
expect(textureLayer.textureId, 1);
|
||||
expect(textureLayer.freeze, true);
|
||||
});
|
||||
|
||||
testWidgets('Texture with default FilterQuality', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const Center(child: Texture(textureId: 1,))
|
||||
const Center(child: Texture(textureId: 1))
|
||||
);
|
||||
|
||||
final Texture texture = tester.firstWidget(find.byType(Texture));
|
||||
|
||||
Reference in New Issue
Block a user