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
40b4d2ba
Unverified
Commit
40b4d2ba
authored
Nov 07, 2020
by
Ferhat
Committed by
GitHub
Nov 07, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add PageView benchmark (representative of full screen CustomPainter) (#69990)
parent
28d6c5b5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
170 additions
and
0 deletions
+170
-0
bench_pageview_scroll_linethrough.dart
...hmarks/lib/src/web/bench_pageview_scroll_linethrough.dart
+168
-0
web_benchmarks.dart
dev/benchmarks/macrobenchmarks/lib/web_benchmarks.dart
+2
-0
No files found.
dev/benchmarks/macrobenchmarks/lib/src/web/bench_pageview_scroll_linethrough.dart
0 → 100644
View file @
40b4d2ba
// 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:async'
;
import
'package:flutter/material.dart'
;
import
'recorder.dart'
;
/// Creates a [PageView] that uses a font style that can't be rendered
/// using canvas (switching to DOM).
///
/// Since the whole page uses a CustomPainter this is a good representation
/// for apps that have pictures with large number of painting commands.
class
BenchPageViewScrollLineThrough
extends
WidgetRecorder
{
BenchPageViewScrollLineThrough
()
:
super
(
name:
benchmarkName
);
static
const
String
benchmarkName
=
'bench_page_view_scroll_line_through'
;
@override
Widget
createWidget
()
=>
const
MaterialApp
(
title:
'PageView Scroll LineThrough Benchmark'
,
home:
_MyScrollContainer
(),
);
}
class
_MyScrollContainer
extends
StatefulWidget
{
const
_MyScrollContainer
({
Key
key
})
:
super
(
key:
key
);
@override
State
<
_MyScrollContainer
>
createState
()
=>
_MyScrollContainerState
();
}
class
_MyScrollContainerState
extends
State
<
_MyScrollContainer
>
{
static
const
Duration
stepDuration
=
Duration
(
milliseconds:
500
);
PageController
pageController
;
int
pageNumber
=
0
;
@override
void
initState
()
{
super
.
initState
();
pageController
=
PageController
();
// Without the timer the animation doesn't begin.
Timer
.
run
(()
async
{
while
(
pageNumber
<
25
)
{
await
pageController
.
animateToPage
(
pageNumber
%
5
,
duration:
stepDuration
,
curve:
Curves
.
easeInOut
);
pageNumber
++;
}
});
}
@override
void
dispose
()
{
super
.
dispose
();
pageController
.
dispose
();
}
@override
Widget
build
(
BuildContext
context
)
{
return
PageView
.
builder
(
controller:
pageController
,
itemBuilder:
(
BuildContext
context
,
int
position
)
{
return
CustomPaint
(
painter:
_CustomPainter
(
'aa'
),
size:
const
Size
(
300
,
500
),
);
});
}
}
class
_CustomPainter
extends
CustomPainter
{
_CustomPainter
(
this
.
text
);
final
String
text
;
Paint
_linePainter
;
TextPainter
_textPainter
;
static
const
double
lineWidth
=
0.5
;
@override
void
paint
(
Canvas
canvas
,
Size
size
)
{
canvas
.
clipRect
(
Rect
.
fromLTWH
(
0
,
0
,
size
.
width
,
size
.
height
));
double
xPosition
,
yPosition
;
final
double
width
=
size
.
width
/
7
;
final
double
height
=
size
.
height
/
6
;
xPosition
=
0
;
const
double
viewPadding
=
5
;
const
double
circlePadding
=
4
;
yPosition
=
viewPadding
;
_textPainter
=
_textPainter
??
TextPainter
();
_textPainter
.
textDirection
=
TextDirection
.
ltr
;
_textPainter
.
textWidthBasis
=
TextWidthBasis
.
longestLine
;
_textPainter
.
textScaleFactor
=
1
;
const
TextStyle
textStyle
=
TextStyle
(
color:
Colors
.
black87
,
fontSize:
13
,
fontFamily:
'Roboto'
);
_linePainter
=
_linePainter
??
Paint
();
_linePainter
.
isAntiAlias
=
true
;
for
(
int
i
=
0
;
i
<
42
;
i
++)
{
_linePainter
.
color
=
Colors
.
white
;
TextStyle
temp
=
textStyle
;
if
(
i
%
7
==
0
)
{
temp
=
textStyle
.
copyWith
(
decoration:
TextDecoration
.
lineThrough
);
}
final
TextSpan
span
=
TextSpan
(
text:
text
,
style:
temp
,
);
_textPainter
.
text
=
span
;
_textPainter
.
layout
(
minWidth:
0
,
maxWidth:
width
);
_linePainter
.
style
=
PaintingStyle
.
fill
;
canvas
.
drawRect
(
Rect
.
fromLTWH
(
xPosition
,
yPosition
-
viewPadding
,
width
,
height
),
_linePainter
);
_textPainter
.
paint
(
canvas
,
Offset
(
xPosition
+
(
width
/
2
-
_textPainter
.
width
/
2
),
yPosition
+
circlePadding
));
xPosition
+=
width
;
if
(
xPosition
.
round
()
>=
size
.
width
.
round
())
{
xPosition
=
0
;
yPosition
+=
height
;
}
}
_drawVerticalAndHorizontalLines
(
canvas
,
size
,
yPosition
,
xPosition
,
height
,
width
);
}
void
_drawVerticalAndHorizontalLines
(
Canvas
canvas
,
Size
size
,
double
yPosition
,
double
xPosition
,
double
height
,
double
width
)
{
yPosition
=
height
;
_linePainter
.
strokeWidth
=
lineWidth
;
_linePainter
.
color
=
Colors
.
grey
;
canvas
.
drawLine
(
const
Offset
(
0
,
lineWidth
),
Offset
(
size
.
width
,
lineWidth
),
_linePainter
);
for
(
int
i
=
0
;
i
<
6
;
i
++)
{
canvas
.
drawLine
(
Offset
(
0
,
yPosition
),
Offset
(
size
.
width
,
yPosition
),
_linePainter
);
yPosition
+=
height
;
}
canvas
.
drawLine
(
Offset
(
0
,
size
.
height
-
lineWidth
),
Offset
(
size
.
width
,
size
.
height
-
lineWidth
),
_linePainter
);
xPosition
=
width
;
canvas
.
drawLine
(
const
Offset
(
lineWidth
,
0
),
Offset
(
lineWidth
,
size
.
height
),
_linePainter
);
for
(
int
i
=
0
;
i
<
6
;
i
++)
{
canvas
.
drawLine
(
Offset
(
xPosition
,
0
),
Offset
(
xPosition
,
size
.
height
),
_linePainter
);
xPosition
+=
width
;
}
}
@override
bool
shouldRepaint
(
CustomPainter
oldDelegate
)
{
return
true
;
}
}
dev/benchmarks/macrobenchmarks/lib/web_benchmarks.dart
View file @
40b4d2ba
...
...
@@ -20,6 +20,7 @@ import 'src/web/bench_dynamic_clip_on_static_picture.dart';
import
'src/web/bench_mouse_region_grid_hover.dart'
;
import
'src/web/bench_mouse_region_grid_scroll.dart'
;
import
'src/web/bench_mouse_region_mixed_grid_hover.dart'
;
import
'src/web/bench_pageview_scroll_linethrough.dart'
;
import
'src/web/bench_paths.dart'
;
import
'src/web/bench_picture_recording.dart'
;
import
'src/web/bench_simple_lazy_text_scroll.dart'
;
...
...
@@ -46,6 +47,7 @@ final Map<String, RecorderFactory> benchmarks = <String, RecorderFactory>{
BenchSimpleLazyTextScroll
.
benchmarkName
:
()
=>
BenchSimpleLazyTextScroll
(),
BenchBuildMaterialCheckbox
.
benchmarkName
:
()
=>
BenchBuildMaterialCheckbox
(),
BenchDynamicClipOnStaticPicture
.
benchmarkName
:
()
=>
BenchDynamicClipOnStaticPicture
(),
BenchPageViewScrollLineThrough
.
benchmarkName
:
()
=>
BenchPageViewScrollLineThrough
(),
BenchPictureRecording
.
benchmarkName
:
()
=>
BenchPictureRecording
(),
BenchUpdateManyChildLayers
.
benchmarkName
:
()
=>
BenchUpdateManyChildLayers
(),
BenchMouseRegionGridScroll
.
benchmarkName
:
()
=>
BenchMouseRegionGridScroll
(),
...
...
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