Commit 0f3bd3ae authored by Adam Barth's avatar Adam Barth

Speed up compositing by 5x (#3948)

According to the profile for the flow manual test, we're spending the vast
majority of our time recording timeline traces. This patch removes the timeline
traces, which greatly improves performance.

Also, optimize TransformLayer to avoid one matrix memcpy. I filed
https://github.com/google/vector_math.dart/issues/166 about an API that would
make this even faster.
parent e1e773af
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:developer';
import 'dart:ui' as ui show ImageFilter, Picture, SceneBuilder; import 'dart:ui' as ui show ImageFilter, Picture, SceneBuilder;
import 'dart:ui' show Offset; import 'dart:ui' show Offset;
...@@ -106,9 +105,7 @@ class PictureLayer extends Layer { ...@@ -106,9 +105,7 @@ class PictureLayer extends Layer {
@override @override
void addToScene(ui.SceneBuilder builder, Offset layerOffset) { void addToScene(ui.SceneBuilder builder, Offset layerOffset) {
Timeline.startSync('PictureLayer::addToScene');
builder.addPicture(layerOffset, picture); builder.addPicture(layerOffset, picture);
Timeline.finishSync();
} }
} }
...@@ -123,7 +120,6 @@ class ChildSceneLayer extends Layer { ...@@ -123,7 +120,6 @@ class ChildSceneLayer extends Layer {
@override @override
void addToScene(ui.SceneBuilder builder, Offset layerOffset) { void addToScene(ui.SceneBuilder builder, Offset layerOffset) {
Timeline.startSync('ChildSceneLayer::addToScene');
builder.addChildScene( builder.addChildScene(
offset + layerOffset, offset + layerOffset,
devicePixelRatio, devicePixelRatio,
...@@ -131,7 +127,6 @@ class ChildSceneLayer extends Layer { ...@@ -131,7 +127,6 @@ class ChildSceneLayer extends Layer {
physicalHeight, physicalHeight,
sceneToken.value sceneToken.value
); );
Timeline.finishSync();
} }
@override @override
...@@ -164,10 +159,8 @@ class PerformanceOverlayLayer extends Layer { ...@@ -164,10 +159,8 @@ class PerformanceOverlayLayer extends Layer {
@override @override
void addToScene(ui.SceneBuilder builder, Offset layerOffset) { void addToScene(ui.SceneBuilder builder, Offset layerOffset) {
assert(optionsMask != null); assert(optionsMask != null);
Timeline.startSync('PerformanceOverlayLayer::addToScene');
builder.addPerformanceOverlay(optionsMask, overlayRect.shift(layerOffset)); builder.addPerformanceOverlay(optionsMask, overlayRect.shift(layerOffset));
builder.setRasterizerTracingThreshold(rasterizerThreshold); builder.setRasterizerTracingThreshold(rasterizerThreshold);
Timeline.finishSync();
} }
} }
...@@ -259,9 +252,7 @@ class ContainerLayer extends Layer { ...@@ -259,9 +252,7 @@ class ContainerLayer extends Layer {
@override @override
void addToScene(ui.SceneBuilder builder, Offset layerOffset) { void addToScene(ui.SceneBuilder builder, Offset layerOffset) {
Timeline.startSync('ContainerLayer::addToScene');
addChildrenToScene(builder, layerOffset); addChildrenToScene(builder, layerOffset);
Timeline.finishSync();
} }
/// Uploads all of this layer's children to the engine /// Uploads all of this layer's children to the engine
...@@ -301,9 +292,7 @@ class OffsetLayer extends ContainerLayer { ...@@ -301,9 +292,7 @@ class OffsetLayer extends ContainerLayer {
@override @override
void addToScene(ui.SceneBuilder builder, Offset layerOffset) { void addToScene(ui.SceneBuilder builder, Offset layerOffset) {
Timeline.startSync('OffsetLayer::addToScene');
addChildrenToScene(builder, offset + layerOffset); addChildrenToScene(builder, offset + layerOffset);
Timeline.finishSync();
} }
@override @override
...@@ -325,11 +314,9 @@ class ClipRectLayer extends ContainerLayer { ...@@ -325,11 +314,9 @@ class ClipRectLayer extends ContainerLayer {
@override @override
void addToScene(ui.SceneBuilder builder, Offset layerOffset) { void addToScene(ui.SceneBuilder builder, Offset layerOffset) {
Timeline.startSync('ClipRectLayer::addToScene');
builder.pushClipRect(clipRect.shift(layerOffset)); builder.pushClipRect(clipRect.shift(layerOffset));
addChildrenToScene(builder, layerOffset); addChildrenToScene(builder, layerOffset);
builder.pop(); builder.pop();
Timeline.finishSync();
} }
@override @override
...@@ -350,11 +337,9 @@ class ClipRRectLayer extends ContainerLayer { ...@@ -350,11 +337,9 @@ class ClipRRectLayer extends ContainerLayer {
@override @override
void addToScene(ui.SceneBuilder builder, Offset layerOffset) { void addToScene(ui.SceneBuilder builder, Offset layerOffset) {
Timeline.startSync('ClipRRectLayer::addToScene');
builder.pushClipRRect(clipRRect.shift(layerOffset)); builder.pushClipRRect(clipRRect.shift(layerOffset));
addChildrenToScene(builder, layerOffset); addChildrenToScene(builder, layerOffset);
builder.pop(); builder.pop();
Timeline.finishSync();
} }
@override @override
...@@ -375,11 +360,9 @@ class ClipPathLayer extends ContainerLayer { ...@@ -375,11 +360,9 @@ class ClipPathLayer extends ContainerLayer {
@override @override
void addToScene(ui.SceneBuilder builder, Offset layerOffset) { void addToScene(ui.SceneBuilder builder, Offset layerOffset) {
Timeline.startSync('ClipPathLayer::addToScene');
builder.pushClipPath(clipPath.shift(layerOffset)); builder.pushClipPath(clipPath.shift(layerOffset));
addChildrenToScene(builder, layerOffset); addChildrenToScene(builder, layerOffset);
builder.pop(); builder.pop();
Timeline.finishSync();
} }
@override @override
...@@ -398,13 +381,11 @@ class TransformLayer extends OffsetLayer { ...@@ -398,13 +381,11 @@ class TransformLayer extends OffsetLayer {
@override @override
void addToScene(ui.SceneBuilder builder, Offset layerOffset) { void addToScene(ui.SceneBuilder builder, Offset layerOffset) {
Timeline.startSync('TransformLayer::addToScene'); Matrix4 effectiveTransform = new Matrix4.translationValues(offset.dx + layerOffset.dx, offset.dy + layerOffset.dy, 0.0)
Matrix4 offsetTransform = new Matrix4.identity(); ..multiply(transform);
offsetTransform.translate(offset.dx + layerOffset.dx, offset.dy + layerOffset.dy); builder.pushTransform(effectiveTransform.storage);
builder.pushTransform((offsetTransform * transform).storage);
addChildrenToScene(builder, Offset.zero); addChildrenToScene(builder, Offset.zero);
builder.pop(); builder.pop();
Timeline.finishSync();
} }
@override @override
...@@ -427,11 +408,9 @@ class OpacityLayer extends ContainerLayer { ...@@ -427,11 +408,9 @@ class OpacityLayer extends ContainerLayer {
@override @override
void addToScene(ui.SceneBuilder builder, Offset layerOffset) { void addToScene(ui.SceneBuilder builder, Offset layerOffset) {
Timeline.startSync('OpacityLayer::addToScene');
builder.pushOpacity(alpha); builder.pushOpacity(alpha);
addChildrenToScene(builder, layerOffset); addChildrenToScene(builder, layerOffset);
builder.pop(); builder.pop();
Timeline.finishSync();
} }
@override @override
...@@ -456,11 +435,9 @@ class ShaderMaskLayer extends ContainerLayer { ...@@ -456,11 +435,9 @@ class ShaderMaskLayer extends ContainerLayer {
@override @override
void addToScene(ui.SceneBuilder builder, Offset layerOffset) { void addToScene(ui.SceneBuilder builder, Offset layerOffset) {
Timeline.startSync('ShaderMaskLayer::addToScene');
builder.pushShaderMask(shader, maskRect.shift(layerOffset), transferMode); builder.pushShaderMask(shader, maskRect.shift(layerOffset), transferMode);
addChildrenToScene(builder, layerOffset); addChildrenToScene(builder, layerOffset);
builder.pop(); builder.pop();
Timeline.finishSync();
} }
@override @override
...@@ -481,10 +458,8 @@ class BackdropFilterLayer extends ContainerLayer { ...@@ -481,10 +458,8 @@ class BackdropFilterLayer extends ContainerLayer {
@override @override
void addToScene(ui.SceneBuilder builder, Offset layerOffset) { void addToScene(ui.SceneBuilder builder, Offset layerOffset) {
Timeline.startSync('BackdropFilterLayer::addToScene');
builder.pushBackdropFilter(filter); builder.pushBackdropFilter(filter);
addChildrenToScene(builder, layerOffset); addChildrenToScene(builder, layerOffset);
builder.pop(); builder.pop();
Timeline.finishSync();
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment