Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
11ff938a
Unverified
Commit
11ff938a
authored
Jul 08, 2020
by
zljj0818
Committed by
GitHub
Jul 08, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a filterQuality parameter to texture (#59966)
parent
33aa4576
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
135 additions
and
7 deletions
+135
-7
layer.dart
packages/flutter/lib/src/rendering/layer.dart
+6
-1
texture.dart
packages/flutter/lib/src/rendering/texture.dart
+20
-4
texture.dart
packages/flutter/lib/src/widgets/texture.dart
+15
-2
texture_test.dart
packages/flutter/test/widgets/texture_test.dart
+94
-0
No files found.
packages/flutter/lib/src/rendering/layer.dart
View file @
11ff938a
...
...
@@ -581,11 +581,12 @@ class PictureLayer extends Layer {
class
TextureLayer
extends
Layer
{
/// Creates a texture layer bounded by [rect] and with backend texture
/// identified by [textureId], if [freeze] is true new texture frames will not be
/// populated to the texture.
/// populated to the texture
, and use [filterQuality] to set layer's [FilterQuality]
.
TextureLayer
({
@required
this
.
rect
,
@required
this
.
textureId
,
this
.
freeze
=
false
,
this
.
filterQuality
=
ui
.
FilterQuality
.
low
,
})
:
assert
(
rect
!=
null
),
assert
(
textureId
!=
null
);
...
...
@@ -604,6 +605,9 @@ class TextureLayer extends Layer {
/// un-freezes it when it is certain that a frame with the new size is ready.
final
bool
freeze
;
/// {@macro FilterQuality}
final
ui
.
FilterQuality
filterQuality
;
@override
void
addToScene
(
ui
.
SceneBuilder
builder
,
[
Offset
layerOffset
=
Offset
.
zero
])
{
final
Rect
shiftedRect
=
layerOffset
==
Offset
.
zero
?
rect
:
rect
.
shift
(
layerOffset
);
...
...
@@ -613,6 +617,7 @@ class TextureLayer extends Layer {
width:
shiftedRect
.
width
,
height:
shiftedRect
.
height
,
freeze:
freeze
,
filterQuality:
filterQuality
,
);
}
...
...
packages/flutter/lib/src/rendering/texture.dart
View file @
11ff938a
...
...
@@ -37,10 +37,14 @@ import 'object.dart';
/// * <https://api.flutter.dev/objcdoc/Protocols/FlutterTextureRegistry.html>
/// for how to create and manage backend textures on iOS.
class
TextureBox
extends
RenderBox
{
/// Creates a box backed by the texture identified by [textureId].
TextureBox
({
@required
int
textureId
})
:
assert
(
textureId
!=
null
),
_textureId
=
textureId
;
/// Creates a box backed by the texture identified by [textureId], and use
/// [filterQuality] to set texture's [FilterQuality].
TextureBox
({
@required
int
textureId
,
FilterQuality
filterQuality
=
FilterQuality
.
low
,
})
:
assert
(
textureId
!=
null
),
_textureId
=
textureId
,
_filterQuality
=
filterQuality
;
/// The identity of the backend texture.
int
get
textureId
=>
_textureId
;
...
...
@@ -53,6 +57,17 @@ class TextureBox extends RenderBox {
}
}
/// {@macro FilterQuality}
FilterQuality
get
filterQuality
=>
_filterQuality
;
FilterQuality
_filterQuality
;
set
filterQuality
(
FilterQuality
value
)
{
assert
(
value
!=
null
);
if
(
value
==
_filterQuality
)
return
;
_filterQuality
=
value
;
markNeedsPaint
();
}
@override
bool
get
sizedByParent
=>
true
;
...
...
@@ -77,6 +92,7 @@ class TextureBox extends RenderBox {
context
.
addLayer
(
TextureLayer
(
rect:
Rect
.
fromLTWH
(
offset
.
dx
,
offset
.
dy
,
size
.
width
,
size
.
height
),
textureId:
_textureId
,
filterQuality:
_filterQuality
,
));
}
}
packages/flutter/lib/src/widgets/texture.dart
View file @
11ff938a
...
...
@@ -35,21 +35,34 @@ import 'framework.dart';
/// * <https://api.flutter.dev/objcdoc/Protocols/FlutterTextureRegistry.html>
/// for how to create and manage backend textures on iOS.
class
Texture
extends
LeafRenderObjectWidget
{
/// Creates a widget backed by the texture identified by [textureId].
/// Creates a widget backed by the texture identified by [textureId], and use
/// [filterQuality] to set texture's [FilterQuality].
const
Texture
({
Key
key
,
@required
this
.
textureId
,
this
.
filterQuality
=
FilterQuality
.
low
,
})
:
assert
(
textureId
!=
null
),
super
(
key:
key
);
/// The identity of the backend texture.
final
int
textureId
;
/// {@template FilterQuality}
/// The quality of sampling the texture and rendering it on screen.
///
/// When the texture is scaled, a default [FilterQuality.low] is used for a higher quality but slower
/// interpolation (typically bilinear). It can be changed to [FilterQuality.none] for a lower quality but
/// faster interpolation (typically nearest-neighbor). See also [FilterQuality.medium] and
/// [FilterQuality.high] for more options.
/// {@endtemplate}
final
FilterQuality
filterQuality
;
@override
TextureBox
createRenderObject
(
BuildContext
context
)
=>
TextureBox
(
textureId:
textureId
);
TextureBox
createRenderObject
(
BuildContext
context
)
=>
TextureBox
(
textureId:
textureId
,
filterQuality:
filterQuality
);
@override
void
updateRenderObject
(
BuildContext
context
,
TextureBox
renderObject
)
{
renderObject
.
textureId
=
textureId
;
renderObject
.
filterQuality
=
filterQuality
;
}
}
packages/flutter/test/widgets/texture_test.dart
0 → 100644
View file @
11ff938a
// 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_test/flutter_test.dart'
;
import
'package:flutter/rendering.dart'
;
import
'package:flutter/widgets.dart'
;
void
main
(
)
{
testWidgets
(
'Texture with default FilterQuality'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
const
Center
(
child:
Texture
(
textureId:
1
,))
);
final
Texture
texture
=
tester
.
firstWidget
(
find
.
byType
(
Texture
));
expect
(
texture
,
isNotNull
);
expect
(
texture
.
textureId
,
1
);
expect
(
texture
.
filterQuality
,
FilterQuality
.
low
);
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
.
filterQuality
,
FilterQuality
.
low
);
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
.
filterQuality
,
FilterQuality
.
low
);
});
testWidgets
(
'Texture with FilterQuality.none'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
const
Center
(
child:
Texture
(
textureId:
1
,
filterQuality:
FilterQuality
.
none
))
);
final
Texture
texture
=
tester
.
firstWidget
(
find
.
byType
(
Texture
));
expect
(
texture
,
isNotNull
);
expect
(
texture
.
textureId
,
1
);
expect
(
texture
.
filterQuality
,
FilterQuality
.
none
);
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
.
filterQuality
,
FilterQuality
.
none
);
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
.
filterQuality
,
FilterQuality
.
none
);
});
testWidgets
(
'Texture with FilterQuality.low'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
const
Center
(
child:
Texture
(
textureId:
1
,
filterQuality:
FilterQuality
.
low
))
);
final
Texture
texture
=
tester
.
firstWidget
(
find
.
byType
(
Texture
));
expect
(
texture
,
isNotNull
);
expect
(
texture
.
textureId
,
1
);
expect
(
texture
.
filterQuality
,
FilterQuality
.
low
);
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
.
filterQuality
,
FilterQuality
.
low
);
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
.
filterQuality
,
FilterQuality
.
low
);
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment