From 39e759212fadfa8b8e3758c35c3338f90a96fd74 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Fri, 22 Jul 2016 14:09:48 -0700 Subject: [PATCH] Improve compositing strategy for Shrine (#5014) This patch includes a number of improvements: * Material page routes now put a repaint boundary inside their transition so they don't repaint during the transition. * Heroes that are on a quest now get a repaint boundary so we repaint them individually. * I've hoisted the transparent material for the product items up in the widget tree, which doesn't affect performance but makes the ink splashes reach the edge of the product cards. * I've changed the repaint rainbow visualization to make it easier to see what's going on. --- .../lib/demo/shrine/shrine_home.dart | 54 +++++++++---------- .../flutter/lib/src/rendering/object.dart | 9 +++- packages/flutter/lib/src/widgets/heroes.dart | 2 +- packages/flutter/lib/src/widgets/routes.dart | 7 ++- 4 files changed, 38 insertions(+), 34 deletions(-) diff --git a/examples/flutter_gallery/lib/demo/shrine/shrine_home.dart b/examples/flutter_gallery/lib/demo/shrine/shrine_home.dart index 901a29a40fd..13158b3a5c7 100644 --- a/examples/flutter_gallery/lib/demo/shrine/shrine_home.dart +++ b/examples/flutter_gallery/lib/demo/shrine/shrine_home.dart @@ -258,37 +258,37 @@ class ProductItem extends StatelessWidget { @override Widget build(BuildContext context) { return new Card( - child: new Column( + child: new Stack( children: [ - new Align( - alignment: FractionalOffset.centerRight, - child: new ProductPriceItem(product: product) - ), - new Container( - width: 144.0, - height: 144.0, - padding: const EdgeInsets.symmetric(horizontal: 8.0), - child: new Stack( - children: [ - new Hero( - tag: productHeroTag, - key: new ObjectKey(product), - child: new Image( - image: new AssetImage(product.imageAsset), - fit: ImageFit.contain + new Column( + children: [ + new Align( + alignment: FractionalOffset.centerRight, + child: new ProductPriceItem(product: product) + ), + new Container( + width: 144.0, + height: 144.0, + padding: const EdgeInsets.symmetric(horizontal: 8.0), + child: new Hero( + tag: productHeroTag, + key: new ObjectKey(product), + child: new Image( + image: new AssetImage(product.imageAsset), + fit: ImageFit.contain + ) ) ), - new Material( - color: Theme.of(context).canvasColor.withAlpha(0x00), - child: new InkWell(onTap: onPressed) - ), - ] - ) + new Padding( + padding: const EdgeInsets.symmetric(horizontal: 8.0), + child: new VendorItem(vendor: product.vendor) + ) + ] + ), + new Material( + type: MaterialType.transparency, + child: new InkWell(onTap: onPressed) ), - new Padding( - padding: const EdgeInsets.symmetric(horizontal: 8.0), - child: new VendorItem(vendor: product.vendor) - ) ] ) ); diff --git a/packages/flutter/lib/src/rendering/object.dart b/packages/flutter/lib/src/rendering/object.dart index 5dcd98541d4..7b2a45d33ba 100644 --- a/packages/flutter/lib/src/rendering/object.dart +++ b/packages/flutter/lib/src/rendering/object.dart @@ -173,8 +173,13 @@ class PaintingContext { if (!_isRecording) return; assert(() { - if (debugRepaintRainbowEnabled) - canvas.drawRect(_paintBounds, new Paint()..color = debugCurrentRepaintColor.toColor()); + if (debugRepaintRainbowEnabled) { + Paint paint = new Paint() + ..style = PaintingStyle.stroke + ..strokeWidth = 6.0 + ..color = debugCurrentRepaintColor.toColor(); + canvas.drawRect(_paintBounds.deflate(3.0), paint); + } if (debugPaintLayerBordersEnabled) { Paint paint = new Paint() ..style = PaintingStyle.stroke diff --git a/packages/flutter/lib/src/widgets/heroes.dart b/packages/flutter/lib/src/widgets/heroes.dart index a64c7f835d7..4a86eed9c65 100644 --- a/packages/flutter/lib/src/widgets/heroes.dart +++ b/packages/flutter/lib/src/widgets/heroes.dart @@ -272,7 +272,7 @@ class _HeroQuestState implements HeroHandle { size: animationArea.size, child: new RotationTransition( turns: currentTurns.animate(animation), - child: new KeyedSubtree( + child: new RepaintBoundary( key: key, child: child ) diff --git a/packages/flutter/lib/src/widgets/routes.dart b/packages/flutter/lib/src/widgets/routes.dart index d73f4da491e..c5bb5c2babf 100644 --- a/packages/flutter/lib/src/widgets/routes.dart +++ b/packages/flutter/lib/src/widgets/routes.dart @@ -426,15 +426,14 @@ class _ModalScopeState extends State<_ModalScope> { context, config.route.animation, config.route.forwardAnimation, - contents + new RepaintBoundary(child: contents) ) ); } - contents = new Focus( + return new Focus( key: config.route.focusKey, - child: new RepaintBoundary(child: contents) + child: contents ); - return contents; } }