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
e065c7fe
Unverified
Commit
e065c7fe
authored
Dec 02, 2022
by
Jonah Williams
Committed by
GitHub
Dec 02, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[framework] make ImageFiltered a repaint boundary (#116385)
* ++ * ++ * ++
parent
5c975430
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
22 deletions
+75
-22
image_filter.dart
packages/flutter/lib/src/widgets/image_filter.dart
+12
-20
animated_image_filtered_repaint_test.dart
...er/test/widgets/animated_image_filtered_repaint_test.dart
+57
-0
image_filter_test.dart
packages/flutter/test/widgets/image_filter_test.dart
+6
-2
No files found.
packages/flutter/lib/src/widgets/image_filter.dart
View file @
e065c7fe
...
...
@@ -79,7 +79,11 @@ class _ImageFilterRenderObject extends RenderProxyBox {
if
(
enabled
==
value
)
{
return
;
}
final
bool
wasRepaintBoundary
=
isRepaintBoundary
;
_enabled
=
value
;
if
(
isRepaintBoundary
!=
wasRepaintBoundary
)
{
markNeedsCompositingBitsUpdate
();
}
markNeedsPaint
();
}
...
...
@@ -89,32 +93,20 @@ class _ImageFilterRenderObject extends RenderProxyBox {
assert
(
value
!=
null
);
if
(
value
!=
_imageFilter
)
{
_imageFilter
=
value
;
markNeeds
Paint
();
markNeeds
CompositedLayerUpdate
();
}
}
@override
bool
get
alwaysNeedsCompositing
=>
child
!=
null
&&
enabled
;
@override
void
paint
(
PaintingContext
context
,
Offset
offset
)
{
assert
(
imageFilter
!=
null
);
if
(!
enabled
)
{
layer
=
null
;
return
super
.
paint
(
context
,
offset
);
}
@override
bool
get
isRepaintBoundary
=>
alwaysNeedsCompositing
;
if
(
layer
==
null
)
{
layer
=
ImageFilterLayer
(
imageFilter:
imageFilter
,
offset:
offset
);
}
else
{
final
ImageFilterLayer
filterLayer
=
layer
!
as
ImageFilterLayer
;
filterLayer
.
imageFilter
=
imageFilter
;
filterLayer
.
offset
=
offset
;
}
context
.
pushLayer
(
layer
!,
super
.
paint
,
Offset
.
zero
);
assert
(()
{
layer
!.
debugCreator
=
debugCreator
;
return
true
;
}());
@override
OffsetLayer
updateCompositedLayer
({
required
covariant
ImageFilterLayer
?
oldLayer
})
{
final
ImageFilterLayer
layer
=
oldLayer
??
ImageFilterLayer
();
layer
.
imageFilter
=
imageFilter
;
return
layer
;
}
}
packages/flutter/test/widgets/animated_image_filtered_repaint_test.dart
0 → 100644
View file @
e065c7fe
// 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
'dart:ui'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/rendering.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
void
main
(
)
{
testWidgets
(
'ImageFiltered avoids repainting child as it animates'
,
(
WidgetTester
tester
)
async
{
RenderTestObject
.
paintCount
=
0
;
await
tester
.
pumpWidget
(
Container
(
color:
Colors
.
red
,
child:
ImageFiltered
(
imageFilter:
ImageFilter
.
blur
(
sigmaX:
5
,
sigmaY:
5
),
child:
const
TestWidget
(),
),
)
);
expect
(
RenderTestObject
.
paintCount
,
1
);
await
tester
.
pumpWidget
(
Container
(
color:
Colors
.
red
,
child:
ImageFiltered
(
imageFilter:
ImageFilter
.
blur
(
sigmaX:
6
,
sigmaY:
6
),
child:
const
TestWidget
(),
),
)
);
expect
(
RenderTestObject
.
paintCount
,
1
);
});
}
class
TestWidget
extends
SingleChildRenderObjectWidget
{
const
TestWidget
({
super
.
key
,
super
.
child
});
@override
RenderObject
createRenderObject
(
BuildContext
context
)
{
return
RenderTestObject
();
}
}
class
RenderTestObject
extends
RenderProxyBox
{
static
int
paintCount
=
0
;
@override
void
paint
(
PaintingContext
context
,
Offset
offset
)
{
paintCount
+=
1
;
super
.
paint
(
context
,
offset
);
}
}
packages/flutter/test/widgets/image_filter_test.dart
View file @
e065c7fe
...
...
@@ -31,8 +31,10 @@ void main() {
});
testWidgets
(
'Image filter - blur with offset'
,
(
WidgetTester
tester
)
async
{
final
Key
key
=
GlobalKey
();
await
tester
.
pumpWidget
(
RepaintBoundary
(
key:
key
,
child:
Transform
.
translate
(
offset:
const
Offset
(
50
,
50
),
child:
ImageFiltered
(
...
...
@@ -43,7 +45,7 @@ void main() {
),
);
await
expectLater
(
find
.
by
Type
(
ImageFiltered
),
find
.
by
Key
(
key
),
matchesGoldenFile
(
'image_filter_blur_offset.png'
),
);
});
...
...
@@ -119,8 +121,10 @@ void main() {
testWidgets
(
'Image filter - matrix with offset'
,
(
WidgetTester
tester
)
async
{
final
Matrix4
matrix
=
Matrix4
.
rotationZ
(
pi
/
18
);
final
ImageFilter
matrixFilter
=
ImageFilter
.
matrix
(
matrix
.
storage
);
final
Key
key
=
GlobalKey
();
await
tester
.
pumpWidget
(
RepaintBoundary
(
key:
key
,
child:
Transform
.
translate
(
offset:
const
Offset
(
50
,
50
),
child:
ImageFiltered
(
...
...
@@ -147,7 +151,7 @@ void main() {
),
);
await
expectLater
(
find
.
by
Type
(
ImageFiltered
),
find
.
by
Key
(
key
),
matchesGoldenFile
(
'image_filter_matrix_offset.png'
),
);
});
...
...
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