Skip to content

Commit

Permalink
RepaintBoundary added
Browse files Browse the repository at this point in the history
  • Loading branch information
apps-transround committed Apr 12, 2021
1 parent 4bc56a8 commit 47177e2
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ app.*.symbols

# Obfuscation related
app.*.map.json
/lib/build_timestamp.dart
4 changes: 3 additions & 1 deletion lib/expensive_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ class ExpensiveWidget extends StatelessWidget {

@override
Widget build(BuildContext context) {
print('builddy');
return Container(
width: width,
height: height,
decoration: BoxDecoration(color: Colors.orange),
decoration: BoxDecoration(color: Colors.orange.shade100),
child: CustomPaint(
isComplex: true,
painter: ShapesPainter(width, height),
),
);
Expand Down
35 changes: 35 additions & 0 deletions lib/paint_measure.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:scroll_test/render_paint_measure.dart';

class PaintMeasure extends SingleChildRenderObjectWidget {
/// Creates a widget that insets its child.
///
/// The [measurePaint] argument must not be null.
const PaintMeasure({
Key? key,
this.measurePaint = true,
Widget? child,
}) : super(key: key, child: child);

/// The amount of space by which to inset the child.
final bool measurePaint;

@override
RenderPaintMeasure createRenderObject(BuildContext context) {
return RenderPaintMeasure(
measurePaint: measurePaint,
);
}

@override
void updateRenderObject(BuildContext context, RenderPaintMeasure renderObject) {
renderObject..measurePaint = measurePaint;
}

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(DiagnosticsProperty<bool>('measurePaint', measurePaint));
}
}
72 changes: 41 additions & 31 deletions lib/platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2389,24 +2389,24 @@
// double delta = 0;
//
// void debugPaintPaintInfo(PaintingContext context, Offset offset) {
// if ([
// 'RenderSemanticsAnnotations',
// 'RenderSemanticsGestureHandler',
// 'RenderExcludeSemantics',
// 'RenderBlockSemantics',
// '_RenderInkFeatures',
// 'RenderPointerListener',
// 'RenderAbsorbPointer',
// 'RenderIgnorePointer',
// 'RenderMouseRegion',
// '_RenderInputPadding',
// 'RenderPadding',
// // 'RenderPositionedBox',
// // 'RenderConstrainedBox',
// ].contains(this.runtimeType.toString()))
// return;
//
// print(this.runtimeType.toString());
// // if ([
// // 'RenderSemanticsAnnotations',
// // 'RenderSemanticsGestureHandler',
// // 'RenderExcludeSemantics',
// // 'RenderBlockSemantics',
// // '_RenderInkFeatures',
// // 'RenderPointerListener',
// // 'RenderAbsorbPointer',
// // 'RenderIgnorePointer',
// // 'RenderMouseRegion',
// // '_RenderInputPadding',
// // // 'RenderPadding',
// // // 'RenderPositionedBox',
// // // 'RenderConstrainedBox',
// // ].contains(this.runtimeType.toString()))
// // return;
//
// // print(this.runtimeType.toString());
// int i = -1;
// // paintEvents.forEach((element) {
// // final p1 = Offset(i * 5 + delta, 0);
Expand All @@ -2425,14 +2425,24 @@
// int fraction = (asymPC / (asymPC + symPC) * 8).round() + 1;
//
// paintText(context, Offset.zero, ' $asymPC / $symPC', textColor: judgementColorMap[fraction] ?? Color(0xFFFF0000));
// final Paint paint = Paint()
// ..style = PaintingStyle.stroke
// ..strokeWidth = 2.0
// ..color = judgementColorMap[fraction] ?? Color(0xFFa0a0a0);
// context.canvas.drawRect(Rect.fromLTWH(offset.dx, offset.dy,
// paintBounds.width, paintBounds.height)
// , paint);
// } //else {
//
// paintIndicator(context, offset, i, 0, fraction);
// } else {
// int parentMark = 0;
// int meMark = 0;
// if (parent is RenderObject)
// parentMark = (parent as RenderObject).eventssMap[PaintEventType.markPaintUp] ?? 0;
// meMark = eventssMap[PaintEventType.markPaintUp] ?? 0;
//
// print('${this.runtimeType.toString()}: $meMark / $parentMark ${parent.runtimeType}');
//
//
// if (meMark == parentMark && meMark > 10 ) {
// paintIndicator(context, offset, i, 0, 1);
// paintText(context, Offset(offset.dx , offset.dy-10), ' Add RPB', textColor: judgementColorMap[1] ?? Color
// (0xFFFF0000));
// }
// }
// i = 1;
//
// if (debugRepaintLogLevel == LogLevel.full)
Expand All @@ -2459,20 +2469,20 @@
// context.canvas.drawRect(Rect.fromLTWH(offset.dx, offset.dy,
// paintBounds.width, paintBounds.height)
// , paint);
//
// }
//
// void paintData(PaintingContext context, Offset offset, int i) {
// if (this is RenderRepaintBoundary) {
// paintText(context, Offset(offset.dx, offset.dy + i * 20),
// // ' ${key.toString().split('.').last.substring(0, 4)}: '
// ' ${(eventssMap[PaintEventType.paintBoundary]?? 0).toString()} / ${(eventssMap[PaintEventType.markPaintBoundary] ?? 0).toString()} ',
// ' ${(eventssMap[PaintEventType.paintBoundary] ?? 0).toString()} / ${(eventssMap[PaintEventType
// .markPaintBoundary] ?? 0).toString()} ',
// backgroundColor: colorsMap[PaintEventType.paintBoundary] ?? Color(0xFFFF0000));
//
// } else
// paintText(context, Offset(offset.dx, offset.dy + i * 20),
// ' ${(eventssMap[PaintEventType.paintChild] ?? 0).toString()} / ${(eventssMap[PaintEventType.markPaintUp]?? 0).toString() } ',
// ' ${(eventssMap[PaintEventType.paintChild] ?? 0).toString()} / ${(eventssMap[PaintEventType.markPaintUp] ?? 0)
// .toString() } ',
// backgroundColor: colorsMap[PaintEventType.paintChild] ?? Color(0xFFFF0000));
//
// }
//
// void paintText(PaintingContext context, Offset offset, String text, {Color backgroundColor = const Color(
Expand Down
21 changes: 21 additions & 0 deletions lib/render_paint_measure.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:flutter/rendering.dart';

class RenderPaintMeasure extends RenderBox {
RenderPaintMeasure({
this.measurePaint = true,
RenderBox? child,
});

bool measurePaint;

@override
void performLayout() {
return;
}

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(DiagnosticsProperty<bool>('MeasurePaint', measurePaint));
}
}
10 changes: 7 additions & 3 deletions lib/rotate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter/rendering.dart';
import 'package:scroll_test/demo_control.dart';
import 'package:scroll_test/expensive_widget.dart';
import 'package:scroll_test/paintEvent.dart';
import 'package:scroll_test/paint_measure.dart';

void main() => runApp(const MyApp());

Expand Down Expand Up @@ -115,9 +116,12 @@ class _RotateTestState extends State<RotateTest> with TickerProviderStateMixin {
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text('Without RepaintBoundary'),
PaintMeasure(
measurePaint: true,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text('Without RepaintBoundary'),
),
),
Center(
child: SizedBox(
Expand Down

0 comments on commit 47177e2

Please sign in to comment.