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
02526228
Commit
02526228
authored
Apr 19, 2017
by
Ian Hickson
Committed by
GitHub
Apr 19, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Promote Layer to full AbstractNode status (#9456)
parent
84a9ff73
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
277 additions
and
100 deletions
+277
-100
layer.dart
packages/flutter/lib/src/rendering/layer.dart
+204
-79
node.dart
packages/flutter/lib/src/rendering/node.dart
+7
-5
object.dart
packages/flutter/lib/src/rendering/object.dart
+6
-3
table.dart
packages/flutter/lib/src/rendering/table.dart
+1
-1
view.dart
packages/flutter/lib/src/rendering/view.dart
+6
-2
layers_test.dart
packages/flutter/test/rendering/layers_test.dart
+43
-0
rendering_tester.dart
packages/flutter/test/rendering/rendering_tester.dart
+10
-9
binding.dart
packages/flutter_test/lib/src/binding.dart
+0
-1
No files found.
packages/flutter/lib/src/rendering/layer.dart
View file @
02526228
...
@@ -10,43 +10,65 @@ import 'package:flutter/painting.dart';
...
@@ -10,43 +10,65 @@ import 'package:flutter/painting.dart';
import
'package:vector_math/vector_math_64.dart'
;
import
'package:vector_math/vector_math_64.dart'
;
import
'debug.dart'
;
import
'debug.dart'
;
import
'node.dart'
;
/// A composited layer.
/// A composited layer.
///
///
/// During painting, the render tree generates a tree of composited layers that
/// During painting, the render tree generates a tree of composited layers that
/// are uploaded into the engine and displayed by the compositor. This class is
/// are uploaded into the engine and displayed by the compositor. This class is
/// the base class for all composited layers.
/// the base class for all composited layers.
abstract
class
Layer
extends
Object
with
TreeDiagnosticsMixin
{
///
/// This layer's parent in the layer tree
/// Most layers can have their properties mutated, and layers can be moved to
ContainerLayer
get
parent
=>
_parent
;
/// different parents. The scene must be explicitly recomposited after such
ContainerLayer
_parent
;
/// changes are made; the layer tree does not maintain its own dirty state.
///
/// To composite the tree, create a [ui.SceneBuilder] object, pass it to the
/// root [Layer] object's [addToScene] method, and then call
/// [ui.SceneBuilder.build] to obtain a [Scene]. A [Scene] can then be painted
/// using [ui.window.render].
///
/// See also:
///
/// * [RenderView.compositeFrame], which implements this recomposition protocol
/// for painting [RenderObject] trees on the the display.
abstract
class
Layer
extends
AbstractNode
with
TreeDiagnosticsMixin
{
/// This layer's parent in the layer tree.
///
/// The [parent] of the root node in the layer tree is null.
///
/// Only subclasses of [ContainerLayer] can have children in the layer tree.
/// All other layer classes are used for leaves in the layer tree.
@override
ContainerLayer
get
parent
=>
super
.
parent
;
/// This layer's next sibling in the parent layer's child list
/// This layer's next sibling in the parent layer's child list
.
Layer
get
nextSibling
=>
_nextSibling
;
Layer
get
nextSibling
=>
_nextSibling
;
Layer
_nextSibling
;
Layer
_nextSibling
;
/// This layer's previous sibling in the parent layer's child list
/// This layer's previous sibling in the parent layer's child list
.
Layer
get
previousSibling
=>
_previousSibling
;
Layer
get
previousSibling
=>
_previousSibling
;
Layer
_previousSibling
;
Layer
_previousSibling
;
/// Removes this layer from its parent layer's child list
/// Removes this layer from its parent layer's child list
.
@mustCallSuper
@mustCallSuper
void
detach
()
{
void
remove
()
{
_parent
?.
_remove
(
this
);
parent
?.
_removeChild
(
this
);
}
}
/// Replaces this layer with the given layer in the parent layer's child list
/// Replaces this layer with the given layer in the parent layer's child list
.
void
replaceWith
(
Layer
newLayer
)
{
void
replaceWith
(
Layer
newLayer
)
{
assert
(
_parent
!=
null
);
assert
(
parent
!=
null
);
assert
(
newLayer
.
_parent
==
null
);
assert
(
attached
==
parent
.
attached
);
assert
(
newLayer
.
parent
==
null
);
assert
(
newLayer
.
_nextSibling
==
null
);
assert
(
newLayer
.
_nextSibling
==
null
);
assert
(
newLayer
.
_previousSibling
==
null
);
assert
(
newLayer
.
_previousSibling
==
null
);
newLayer
.
_nextSibling
=
_nextSibling
;
assert
(!
newLayer
.
attached
);
newLayer
.
_nextSibling
=
nextSibling
;
if
(
_nextSibling
!=
null
)
if
(
_nextSibling
!=
null
)
newLayer
.
_nextSibling
.
_previousSibling
=
newLayer
;
_nextSibling
.
_previousSibling
=
newLayer
;
newLayer
.
_previousSibling
=
_
previousSibling
;
newLayer
.
_previousSibling
=
previousSibling
;
if
(
_previousSibling
!=
null
)
if
(
_previousSibling
!=
null
)
newLayer
.
_previousSibling
.
_nextSibling
=
newLayer
;
_previousSibling
.
_nextSibling
=
newLayer
;
assert
(()
{
assert
(()
{
Layer
node
=
this
;
Layer
node
=
this
;
while
(
node
.
parent
!=
null
)
while
(
node
.
parent
!=
null
)
...
@@ -54,17 +76,19 @@ abstract class Layer extends Object with TreeDiagnosticsMixin {
...
@@ -54,17 +76,19 @@ abstract class Layer extends Object with TreeDiagnosticsMixin {
assert
(
node
!=
newLayer
);
// indicates we are about to create a cycle
assert
(
node
!=
newLayer
);
// indicates we are about to create a cycle
return
true
;
return
true
;
});
});
newLayer
.
_parent
=
_parent
;
parent
.
adoptChild
(
newLayer
);
if
(
_parent
.
_firstChild
==
this
)
assert
(
newLayer
.
attached
==
parent
.
attached
);
_parent
.
_firstChild
=
newLayer
;
if
(
parent
.
firstChild
==
this
)
if
(
_parent
.
_lastChild
==
this
)
parent
.
_firstChild
=
newLayer
;
_parent
.
_lastChild
=
newLayer
;
if
(
parent
.
lastChild
==
this
)
parent
.
_lastChild
=
newLayer
;
_nextSibling
=
null
;
_nextSibling
=
null
;
_previousSibling
=
null
;
_previousSibling
=
null
;
_parent
=
null
;
parent
.
dropChild
(
this
);
assert
(!
attached
);
}
}
/// Override this method to upload this layer to the engine
/// Override this method to upload this layer to the engine
.
///
///
/// The layerOffset is the accumulated offset of this layer's parent from the
/// The layerOffset is the accumulated offset of this layer's parent from the
/// origin of the builder's coordinate system.
/// origin of the builder's coordinate system.
...
@@ -79,16 +103,22 @@ abstract class Layer extends Object with TreeDiagnosticsMixin {
...
@@ -79,16 +103,22 @@ abstract class Layer extends Object with TreeDiagnosticsMixin {
@override
@override
void
debugFillDescription
(
List
<
String
>
description
)
{
void
debugFillDescription
(
List
<
String
>
description
)
{
super
.
debugFillDescription
(
description
);
super
.
debugFillDescription
(
description
);
description
.
add
(
'
${ owner != null ? "owner: $owner" : "DETACHED" }
'
);
if
(
debugCreator
!=
null
)
if
(
debugCreator
!=
null
)
description
.
add
(
'creator:
$debugCreator
'
);
description
.
add
(
'creator:
$debugCreator
'
);
}
}
}
}
/// A composited layer containing a [Picture]
/// A composited layer containing a [Picture].
///
/// Picture layers are always leaves in the layer tree.
class
PictureLayer
extends
Layer
{
class
PictureLayer
extends
Layer
{
/// The picture recorded for this layer
/// The picture recorded for this layer
.
///
///
/// The picture's coodinate system matches this layer's coodinate system
/// The picture's coodinate system matches this layer's coodinate system.
///
/// The scene must be explicitly recomposited after this property is changed
/// (as described at [Layer]).
ui
.
Picture
picture
;
ui
.
Picture
picture
;
/// Hints that the painting in this layer is complex and would benefit from
/// Hints that the painting in this layer is complex and would benefit from
...
@@ -96,6 +126,9 @@ class PictureLayer extends Layer {
...
@@ -96,6 +126,9 @@ class PictureLayer extends Layer {
///
///
/// If this hint is not set, the compositor will apply its own heuristics to
/// If this hint is not set, the compositor will apply its own heuristics to
/// decide whether the this layer is complex enough to benefit from caching.
/// decide whether the this layer is complex enough to benefit from caching.
///
/// The scene must be explicitly recomposited after this property is changed
/// (as described at [Layer]).
bool
isComplexHint
=
false
;
bool
isComplexHint
=
false
;
/// Hints that the painting in this layer is likely to change next frame.
/// Hints that the painting in this layer is likely to change next frame.
...
@@ -104,6 +137,9 @@ class PictureLayer extends Layer {
...
@@ -104,6 +137,9 @@ class PictureLayer extends Layer {
/// will not be used in the future. If this hint is not set, the compositor
/// will not be used in the future. If this hint is not set, the compositor
/// will apply its own heuristics to decide whether this layer is likely to be
/// will apply its own heuristics to decide whether this layer is likely to be
/// reused in the future.
/// reused in the future.
///
/// The scene must be explicitly recomposited after this property is changed
/// (as described at [Layer]).
bool
willChangeHint
=
false
;
bool
willChangeHint
=
false
;
@override
@override
...
@@ -114,6 +150,8 @@ class PictureLayer extends Layer {
...
@@ -114,6 +150,8 @@ class PictureLayer extends Layer {
/// A layer that indicates to the compositor that it should display
/// A layer that indicates to the compositor that it should display
/// certain performance statistics within it.
/// certain performance statistics within it.
///
/// Performance overlay layers are always leaves in the layer tree.
class
PerformanceOverlayLayer
extends
Layer
{
class
PerformanceOverlayLayer
extends
Layer
{
/// Creates a layer that displays a performance overlay.
/// Creates a layer that displays a performance overlay.
PerformanceOverlayLayer
({
PerformanceOverlayLayer
({
...
@@ -124,6 +162,9 @@ class PerformanceOverlayLayer extends Layer {
...
@@ -124,6 +162,9 @@ class PerformanceOverlayLayer extends Layer {
});
});
/// The rectangle in this layer's coordinate system that the overlay should occupy.
/// The rectangle in this layer's coordinate system that the overlay should occupy.
///
/// The scene must be explicitly recomposited after this property is changed
/// (as described at [Layer]).
Rect
overlayRect
;
Rect
overlayRect
;
/// The mask is created by shifting 1 by the index of the specific
/// The mask is created by shifting 1 by the index of the specific
...
@@ -157,40 +198,69 @@ class PerformanceOverlayLayer extends Layer {
...
@@ -157,40 +198,69 @@ class PerformanceOverlayLayer extends Layer {
}
}
}
}
/// A composited layer that has a list of children
/// A composited layer that has a list of children.
///
/// A [ContainerLayer] instance merely takes a list of children and inserts them
/// into the composited rendering in order. There are subclasses of
/// [ContainerLayer] which apply more elaborate effects in the process.
class
ContainerLayer
extends
Layer
{
class
ContainerLayer
extends
Layer
{
/// The first composited layer in this layer's child list
/// The first composited layer in this layer's child list
.
Layer
get
firstChild
=>
_firstChild
;
Layer
get
firstChild
=>
_firstChild
;
Layer
_firstChild
;
Layer
_firstChild
;
/// The last composited layer in this layer's child list
/// The last composited layer in this layer's child list
.
Layer
get
lastChild
=>
_lastChild
;
Layer
get
lastChild
=>
_lastChild
;
Layer
_lastChild
;
Layer
_lastChild
;
bool
_debugUltimatePreviousSiblingOf
(
Layer
child
,
{
Layer
equals
})
{
bool
_debugUltimatePreviousSiblingOf
(
Layer
child
,
{
Layer
equals
})
{
while
(
child
.
_previousSibling
!=
null
)
{
assert
(
child
.
attached
==
attached
);
assert
(
child
.
_previousSibling
!=
child
);
while
(
child
.
previousSibling
!=
null
)
{
child
=
child
.
_previousSibling
;
assert
(
child
.
previousSibling
!=
child
);
child
=
child
.
previousSibling
;
assert
(
child
.
attached
==
attached
);
}
}
return
child
==
equals
;
return
child
==
equals
;
}
}
bool
_debugUltimateNextSiblingOf
(
Layer
child
,
{
Layer
equals
})
{
bool
_debugUltimateNextSiblingOf
(
Layer
child
,
{
Layer
equals
})
{
assert
(
child
.
attached
==
attached
);
while
(
child
.
_nextSibling
!=
null
)
{
while
(
child
.
_nextSibling
!=
null
)
{
assert
(
child
.
_nextSibling
!=
child
);
assert
(
child
.
_nextSibling
!=
child
);
child
=
child
.
_nextSibling
;
child
=
child
.
_nextSibling
;
assert
(
child
.
attached
==
attached
);
}
}
return
child
==
equals
;
return
child
==
equals
;
}
}
/// Adds the given layer to the end of this layer's child list
@override
void
attach
(
Object
owner
)
{
super
.
attach
(
owner
);
Layer
child
=
firstChild
;
while
(
child
!=
null
)
{
child
.
attach
(
owner
);
child
=
child
.
nextSibling
;
}
}
@override
void
detach
()
{
super
.
detach
();
Layer
child
=
firstChild
;
while
(
child
!=
null
)
{
child
.
detach
();
child
=
child
.
nextSibling
;
}
}
/// Adds the given layer to the end of this layer's child list.
void
append
(
Layer
child
)
{
void
append
(
Layer
child
)
{
assert
(
child
!=
this
);
assert
(
child
!=
this
);
assert
(
child
!=
_firstChild
);
assert
(
child
!=
firstChild
);
assert
(
child
!=
_lastChild
);
assert
(
child
!=
lastChild
);
assert
(
child
.
_parent
==
null
);
assert
(
child
.
parent
==
null
);
assert
(
child
.
_nextSibling
==
null
);
assert
(!
child
.
attached
);
assert
(
child
.
_previousSibling
==
null
);
assert
(
child
.
nextSibling
==
null
);
assert
(
child
.
previousSibling
==
null
);
assert
(()
{
assert
(()
{
Layer
node
=
this
;
Layer
node
=
this
;
while
(
node
.
parent
!=
null
)
while
(
node
.
parent
!=
null
)
...
@@ -198,43 +268,53 @@ class ContainerLayer extends Layer {
...
@@ -198,43 +268,53 @@ class ContainerLayer extends Layer {
assert
(
node
!=
child
);
// indicates we are about to create a cycle
assert
(
node
!=
child
);
// indicates we are about to create a cycle
return
true
;
return
true
;
});
});
child
.
_parent
=
this
;
adoptChild
(
child
)
;
child
.
_previousSibling
=
_
lastChild
;
child
.
_previousSibling
=
lastChild
;
if
(
_
lastChild
!=
null
)
if
(
lastChild
!=
null
)
_
lastChild
.
_nextSibling
=
child
;
lastChild
.
_nextSibling
=
child
;
_lastChild
=
child
;
_lastChild
=
child
;
_firstChild
??=
child
;
_firstChild
??=
child
;
assert
(
child
.
attached
==
attached
);
}
}
void
_remove
(
Layer
child
)
{
// Implementation of [Layer.remove].
assert
(
child
.
_parent
==
this
);
void
_removeChild
(
Layer
child
)
{
assert
(
_debugUltimatePreviousSiblingOf
(
child
,
equals:
_firstChild
));
assert
(
child
.
parent
==
this
);
assert
(
_debugUltimateNextSiblingOf
(
child
,
equals:
_lastChild
));
assert
(
child
.
attached
==
attached
);
assert
(
_debugUltimatePreviousSiblingOf
(
child
,
equals:
firstChild
));
assert
(
_debugUltimateNextSiblingOf
(
child
,
equals:
lastChild
));
if
(
child
.
_previousSibling
==
null
)
{
if
(
child
.
_previousSibling
==
null
)
{
assert
(
_firstChild
==
child
);
assert
(
_firstChild
==
child
);
_firstChild
=
child
.
_nextSibling
;
_firstChild
=
child
.
_nextSibling
;
}
else
{
}
else
{
child
.
_previousSibling
.
_nextSibling
=
child
.
_
nextSibling
;
child
.
_previousSibling
.
_nextSibling
=
child
.
nextSibling
;
}
}
if
(
child
.
_nextSibling
==
null
)
{
if
(
child
.
_nextSibling
==
null
)
{
assert
(
_
lastChild
==
child
);
assert
(
lastChild
==
child
);
_lastChild
=
child
.
_
previousSibling
;
_lastChild
=
child
.
previousSibling
;
}
else
{
}
else
{
child
.
_nextSibling
.
_previousSibling
=
child
.
_
previousSibling
;
child
.
nextSibling
.
_previousSibling
=
child
.
previousSibling
;
}
}
assert
((
firstChild
==
null
)
==
(
lastChild
==
null
));
assert
(
firstChild
==
null
||
firstChild
.
attached
==
attached
);
assert
(
lastChild
==
null
||
lastChild
.
attached
==
attached
);
assert
(
firstChild
==
null
||
_debugUltimateNextSiblingOf
(
firstChild
,
equals:
lastChild
));
assert
(
lastChild
==
null
||
_debugUltimatePreviousSiblingOf
(
lastChild
,
equals:
firstChild
));
child
.
_previousSibling
=
null
;
child
.
_previousSibling
=
null
;
child
.
_nextSibling
=
null
;
child
.
_nextSibling
=
null
;
child
.
_parent
=
null
;
dropChild
(
child
);
assert
(!
child
.
attached
);
}
}
/// Removes all of this layer's children from its child list
/// Removes all of this layer's children from its child list
.
void
removeAllChildren
()
{
void
removeAllChildren
()
{
Layer
child
=
_
firstChild
;
Layer
child
=
firstChild
;
while
(
child
!=
null
)
{
while
(
child
!=
null
)
{
final
Layer
next
=
child
.
nextSibling
;
final
Layer
next
=
child
.
nextSibling
;
child
.
_previousSibling
=
null
;
child
.
_previousSibling
=
null
;
child
.
_nextSibling
=
null
;
child
.
_nextSibling
=
null
;
child
.
_parent
=
null
;
assert
(
child
.
attached
==
attached
);
dropChild
(
child
);
child
=
next
;
child
=
next
;
}
}
_firstChild
=
null
;
_firstChild
=
null
;
...
@@ -246,9 +326,15 @@ class ContainerLayer extends Layer {
...
@@ -246,9 +326,15 @@ class ContainerLayer extends Layer {
addChildrenToScene
(
builder
,
layerOffset
);
addChildrenToScene
(
builder
,
layerOffset
);
}
}
/// Uploads all of this layer's children to the engine
/// Uploads all of this layer's children to the engine.
///
/// This method is typically used by [addToScene] to insert the children into
/// the scene. Subclasses of [ContainerLayer] typically override [addToScene]
/// to apply effects to the scene using the [ui.SceneBuilder] API, then insert
/// their children using [addChildrenToScene], then reverse the aforementioned
/// effects before returning from [addToScene].
void
addChildrenToScene
(
ui
.
SceneBuilder
builder
,
Offset
childOffset
)
{
void
addChildrenToScene
(
ui
.
SceneBuilder
builder
,
Offset
childOffset
)
{
Layer
child
=
_
firstChild
;
Layer
child
=
firstChild
;
while
(
child
!=
null
)
{
while
(
child
!=
null
)
{
child
.
addToScene
(
builder
,
childOffset
);
child
.
addToScene
(
builder
,
childOffset
);
child
=
child
.
nextSibling
;
child
=
child
.
nextSibling
;
...
@@ -257,19 +343,19 @@ class ContainerLayer extends Layer {
...
@@ -257,19 +343,19 @@ class ContainerLayer extends Layer {
@override
@override
String
debugDescribeChildren
(
String
prefix
)
{
String
debugDescribeChildren
(
String
prefix
)
{
if
(
firstChild
==
null
)
return
''
;
String
result
=
'
$prefix
\
u2502
\n
'
;
String
result
=
'
$prefix
\
u2502
\n
'
;
if
(
_firstChild
!=
null
)
{
Layer
child
=
firstChild
;
Layer
child
=
_firstChild
;
int
count
=
1
;
int
count
=
1
;
while
(
child
!=
lastChild
)
{
while
(
child
!=
_lastChild
)
{
result
+=
'
${child.toStringDeep("$prefix \u251C\u2500child $count: ", "$prefix \u2502")}
'
;
result
+=
'
${child.toStringDeep("$prefix \u251C\u2500child $count: ", "$prefix \u2502")}
'
;
count
+=
1
;
count
+=
1
;
child
=
child
.
nextSibling
;
child
=
child
.
_nextSibling
;
}
}
if
(
child
!=
null
)
{
if
(
child
!=
null
)
{
assert
(
child
==
lastChild
);
assert
(
child
==
_lastChild
);
result
+=
'
${child.toStringDeep("$prefix \u2514\u2500child $count: ", "$prefix ")}
'
;
result
+=
'
${child.toStringDeep("$prefix \u2514\u2500child $count: ", "$prefix ")}
'
;
}
}
}
return
result
;
return
result
;
}
}
...
@@ -291,6 +377,9 @@ class OffsetLayer extends ContainerLayer {
...
@@ -291,6 +377,9 @@ class OffsetLayer extends ContainerLayer {
OffsetLayer
({
this
.
offset
:
Offset
.
zero
});
OffsetLayer
({
this
.
offset
:
Offset
.
zero
});
/// Offset from parent in the parent's coordinate system.
/// Offset from parent in the parent's coordinate system.
///
/// The scene must be explicitly recomposited after this property is changed
/// (as described at [Layer]).
Offset
offset
;
Offset
offset
;
@override
@override
...
@@ -306,7 +395,7 @@ class OffsetLayer extends ContainerLayer {
...
@@ -306,7 +395,7 @@ class OffsetLayer extends ContainerLayer {
}
}
/// A composite layer that clips its children using a rectangle
/// A composite layer that clips its children using a rectangle
.
class
ClipRectLayer
extends
ContainerLayer
{
class
ClipRectLayer
extends
ContainerLayer
{
/// Creates a layer with a rectangular clip.
/// Creates a layer with a rectangular clip.
///
///
...
@@ -314,7 +403,10 @@ class ClipRectLayer extends ContainerLayer {
...
@@ -314,7 +403,10 @@ class ClipRectLayer extends ContainerLayer {
/// the pipeline.
/// the pipeline.
ClipRectLayer
({
this
.
clipRect
});
ClipRectLayer
({
this
.
clipRect
});
/// The rectangle to clip in the parent's coordinate system
/// The rectangle to clip in the parent's coordinate system.
///
/// The scene must be explicitly recomposited after this property is changed
/// (as described at [Layer]).
Rect
clipRect
;
Rect
clipRect
;
@override
@override
...
@@ -331,7 +423,7 @@ class ClipRectLayer extends ContainerLayer {
...
@@ -331,7 +423,7 @@ class ClipRectLayer extends ContainerLayer {
}
}
}
}
/// A composite layer that clips its children using a rounded rectangle
/// A composite layer that clips its children using a rounded rectangle
.
class
ClipRRectLayer
extends
ContainerLayer
{
class
ClipRRectLayer
extends
ContainerLayer
{
/// Creates a layer with a rounded-rectangular clip.
/// Creates a layer with a rounded-rectangular clip.
///
///
...
@@ -339,7 +431,10 @@ class ClipRRectLayer extends ContainerLayer {
...
@@ -339,7 +431,10 @@ class ClipRRectLayer extends ContainerLayer {
/// the pipeline.
/// the pipeline.
ClipRRectLayer
({
this
.
clipRRect
});
ClipRRectLayer
({
this
.
clipRRect
});
/// The rounded-rect to clip in the parent's coordinate system
/// The rounded-rect to clip in the parent's coordinate system.
///
/// The scene must be explicitly recomposited after this property is changed
/// (as described at [Layer]).
RRect
clipRRect
;
RRect
clipRRect
;
@override
@override
...
@@ -356,7 +451,7 @@ class ClipRRectLayer extends ContainerLayer {
...
@@ -356,7 +451,7 @@ class ClipRRectLayer extends ContainerLayer {
}
}
}
}
/// A composite layer that clips its children using a path
/// A composite layer that clips its children using a path
.
class
ClipPathLayer
extends
ContainerLayer
{
class
ClipPathLayer
extends
ContainerLayer
{
/// Creates a layer with a path-based clip.
/// Creates a layer with a path-based clip.
///
///
...
@@ -364,7 +459,10 @@ class ClipPathLayer extends ContainerLayer {
...
@@ -364,7 +459,10 @@ class ClipPathLayer extends ContainerLayer {
/// the pipeline.
/// the pipeline.
ClipPathLayer
({
this
.
clipPath
});
ClipPathLayer
({
this
.
clipPath
});
/// The path to clip in the parent's coordinate system
/// The path to clip in the parent's coordinate system.
///
/// The scene must be explicitly recomposited after this property is changed
/// (as described at [Layer]).
Path
clipPath
;
Path
clipPath
;
@override
@override
...
@@ -381,7 +479,7 @@ class ClipPathLayer extends ContainerLayer {
...
@@ -381,7 +479,7 @@ class ClipPathLayer extends ContainerLayer {
}
}
}
}
/// A composited layer that applies a transformation matrix to its children
/// A composited layer that applies a transformation matrix to its children
.
class
TransformLayer
extends
OffsetLayer
{
class
TransformLayer
extends
OffsetLayer
{
/// Creates a transform layer.
/// Creates a transform layer.
///
///
...
@@ -391,7 +489,10 @@ class TransformLayer extends OffsetLayer {
...
@@ -391,7 +489,10 @@ class TransformLayer extends OffsetLayer {
this
.
transform
this
.
transform
});
});
/// The matrix to apply
/// The matrix to apply.
///
/// The scene must be explicitly recomposited after this property is changed
/// (as described at [Layer]).
Matrix4
transform
;
Matrix4
transform
;
@override
@override
...
@@ -415,7 +516,7 @@ class TransformLayer extends OffsetLayer {
...
@@ -415,7 +516,7 @@ class TransformLayer extends OffsetLayer {
}
}
}
}
/// A composited layer that makes its children partially transparent
/// A composited layer that makes its children partially transparent
.
class
OpacityLayer
extends
ContainerLayer
{
class
OpacityLayer
extends
ContainerLayer
{
/// Creates an opacity layer.
/// Creates an opacity layer.
///
///
...
@@ -423,10 +524,13 @@ class OpacityLayer extends ContainerLayer {
...
@@ -423,10 +524,13 @@ class OpacityLayer extends ContainerLayer {
/// the pipeline.
/// the pipeline.
OpacityLayer
({
this
.
alpha
});
OpacityLayer
({
this
.
alpha
});
/// The amount to multiply into the alpha channel
/// The amount to multiply into the alpha channel
.
///
///
/// The opacity is expressed as an integer from 0 to 255, where 0 is fully
/// The opacity is expressed as an integer from 0 to 255, where 0 is fully
/// transparent and 255 is fully opaque.
/// transparent and 255 is fully opaque.
///
/// The scene must be explicitly recomposited after this property is changed
/// (as described at [Layer]).
int
alpha
;
int
alpha
;
@override
@override
...
@@ -452,12 +556,21 @@ class ShaderMaskLayer extends ContainerLayer {
...
@@ -452,12 +556,21 @@ class ShaderMaskLayer extends ContainerLayer {
ShaderMaskLayer
({
this
.
shader
,
this
.
maskRect
,
this
.
blendMode
});
ShaderMaskLayer
({
this
.
shader
,
this
.
maskRect
,
this
.
blendMode
});
/// The shader to apply to the children.
/// The shader to apply to the children.
///
/// The scene must be explicitly recomposited after this property is changed
/// (as described at [Layer]).
Shader
shader
;
Shader
shader
;
/// The size of the shader.
/// The size of the shader.
///
/// The scene must be explicitly recomposited after this property is changed
/// (as described at [Layer]).
Rect
maskRect
;
Rect
maskRect
;
/// The blend mode to apply when blending the shader with the children.
/// The blend mode to apply when blending the shader with the children.
///
/// The scene must be explicitly recomposited after this property is changed
/// (as described at [Layer]).
BlendMode
blendMode
;
BlendMode
blendMode
;
@override
@override
...
@@ -485,6 +598,9 @@ class BackdropFilterLayer extends ContainerLayer {
...
@@ -485,6 +598,9 @@ class BackdropFilterLayer extends ContainerLayer {
BackdropFilterLayer
({
this
.
filter
});
BackdropFilterLayer
({
this
.
filter
});
/// The filter to apply to the existing contents of the scene.
/// The filter to apply to the existing contents of the scene.
///
/// The scene must be explicitly recomposited after this property is changed
/// (as described at [Layer]).
ui
.
ImageFilter
filter
;
ui
.
ImageFilter
filter
;
@override
@override
...
@@ -515,13 +631,22 @@ class PhysicalModelLayer extends ContainerLayer {
...
@@ -515,13 +631,22 @@ class PhysicalModelLayer extends ContainerLayer {
assert
(
color
!=
null
);
assert
(
color
!=
null
);
}
}
/// The rounded-rect to clip in the parent's coordinate system
/// The rounded-rect to clip in the parent's coordinate system.
///
/// The scene must be explicitly recomposited after this property is changed
/// (as described at [Layer]).
RRect
clipRRect
;
RRect
clipRRect
;
/// The z-coordinate at which to place this physical object.
/// The z-coordinate at which to place this physical object.
///
/// The scene must be explicitly recomposited after this property is changed
/// (as described at [Layer]).
int
elevation
;
int
elevation
;
/// The background color.
/// The background color.
///
/// The scene must be explicitly recomposited after this property is changed
/// (as described at [Layer]).
Color
color
;
Color
color
;
@override
@override
...
...
packages/flutter/lib/src/rendering/node.dart
View file @
02526228
...
@@ -39,7 +39,7 @@ class AbstractNode {
...
@@ -39,7 +39,7 @@ class AbstractNode {
/// The depth of this node in the tree.
/// The depth of this node in the tree.
///
///
/// The depth of nodes in a tree monotonically increases as you traverse down
/// The depth of nodes in a tree monotonically increases as you traverse down
/// the tree
s
.
/// the tree.
int
get
depth
=>
_depth
;
int
get
depth
=>
_depth
;
int
_depth
=
0
;
int
_depth
=
0
;
...
@@ -80,8 +80,9 @@ class AbstractNode {
...
@@ -80,8 +80,9 @@ class AbstractNode {
/// Typically called only from the [parent]'s [attach] method, and by the
/// Typically called only from the [parent]'s [attach] method, and by the
/// [owner] to mark the root of a tree as attached.
/// [owner] to mark the root of a tree as attached.
///
///
/// Subclasses with children should [attach] all their children to the same
/// Subclasses with children should override this method to first call their
/// [owner] whenever this method is called.
/// inherited [attach] method, and then [attach] all their children to the
/// same [owner].
@mustCallSuper
@mustCallSuper
void
attach
(
covariant
Object
owner
)
{
void
attach
(
covariant
Object
owner
)
{
assert
(
owner
!=
null
);
assert
(
owner
!=
null
);
...
@@ -94,12 +95,13 @@ class AbstractNode {
...
@@ -94,12 +95,13 @@ class AbstractNode {
/// Typically called only from the [parent]'s [detach], and by the [owner] to
/// Typically called only from the [parent]'s [detach], and by the [owner] to
/// mark the root of a tree as detached.
/// mark the root of a tree as detached.
///
///
/// Subclasses with children should
[detach] all their children whenever this
/// Subclasses with children should
override this method to first call their
///
method is called
.
///
inherited [detach] method, and then [detach] all their children
.
@mustCallSuper
@mustCallSuper
void
detach
()
{
void
detach
()
{
assert
(
_owner
!=
null
);
assert
(
_owner
!=
null
);
_owner
=
null
;
_owner
=
null
;
assert
(
parent
==
null
||
attached
==
parent
.
attached
);
}
}
/// The parent of this node in the tree.
/// The parent of this node in the tree.
...
...
packages/flutter/lib/src/rendering/object.dart
View file @
02526228
...
@@ -126,7 +126,7 @@ class PaintingContext {
...
@@ -126,7 +126,7 @@ class PaintingContext {
assert
(
child
.
_layer
!=
null
);
assert
(
child
.
_layer
!=
null
);
assert
(()
{
assert
(()
{
child
.
debugRegisterRepaintBoundaryPaint
(
includedParent:
true
,
includedChild:
false
);
child
.
debugRegisterRepaintBoundaryPaint
(
includedParent:
true
,
includedChild:
false
);
child
.
_layer
.
debugCreator
=
child
.
debugCreator
??
child
.
runtimeType
;
child
.
_layer
.
debugCreator
=
child
.
debugCreator
??
child
;
return
true
;
return
true
;
});
});
}
}
...
@@ -136,7 +136,7 @@ class PaintingContext {
...
@@ -136,7 +136,7 @@ class PaintingContext {
void
_appendLayer
(
Layer
layer
)
{
void
_appendLayer
(
Layer
layer
)
{
assert
(!
_isRecording
);
assert
(!
_isRecording
);
layer
.
detach
();
layer
.
remove
();
_containerLayer
.
append
(
layer
);
_containerLayer
.
append
(
layer
);
}
}
...
@@ -1998,7 +1998,7 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget {
...
@@ -1998,7 +1998,7 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget {
/// To access the layer in debug code, even when it might be inappropriate to
/// To access the layer in debug code, even when it might be inappropriate to
/// access it (e.g. because it is dirty), consider [debugLayer].
/// access it (e.g. because it is dirty), consider [debugLayer].
OffsetLayer
get
layer
{
OffsetLayer
get
layer
{
assert
(
isRepaintBoundary
);
assert
(
isRepaintBoundary
,
'You can only access RenderObject.layer for render objects that are repaint boundaries.'
);
assert
(!
_needsPaint
);
assert
(!
_needsPaint
);
return
_layer
;
return
_layer
;
}
}
...
@@ -2141,6 +2141,7 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget {
...
@@ -2141,6 +2141,7 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget {
///
///
/// See [RenderView] for an example of how this function is used.
/// See [RenderView] for an example of how this function is used.
void
scheduleInitialPaint
(
ContainerLayer
rootLayer
)
{
void
scheduleInitialPaint
(
ContainerLayer
rootLayer
)
{
assert
(
rootLayer
.
attached
);
assert
(
attached
);
assert
(
attached
);
assert
(
parent
is
!
RenderObject
);
assert
(
parent
is
!
RenderObject
);
assert
(!
owner
.
_debugDoingPaint
);
assert
(!
owner
.
_debugDoingPaint
);
...
@@ -2157,11 +2158,13 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget {
...
@@ -2157,11 +2158,13 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget {
///
///
/// This might be called if, e.g., the device pixel ratio changed.
/// This might be called if, e.g., the device pixel ratio changed.
void
replaceRootLayer
(
OffsetLayer
rootLayer
)
{
void
replaceRootLayer
(
OffsetLayer
rootLayer
)
{
assert
(
rootLayer
.
attached
);
assert
(
attached
);
assert
(
attached
);
assert
(
parent
is
!
RenderObject
);
assert
(
parent
is
!
RenderObject
);
assert
(!
owner
.
_debugDoingPaint
);
assert
(!
owner
.
_debugDoingPaint
);
assert
(
isRepaintBoundary
);
assert
(
isRepaintBoundary
);
assert
(
_layer
!=
null
);
// use scheduleInitialPaint the first time
assert
(
_layer
!=
null
);
// use scheduleInitialPaint the first time
_layer
.
detach
();
_layer
=
rootLayer
;
_layer
=
rootLayer
;
markNeedsPaint
();
markNeedsPaint
();
}
}
...
...
packages/flutter/lib/src/rendering/table.dart
View file @
02526228
...
@@ -812,6 +812,7 @@ class RenderTable extends RenderBox {
...
@@ -812,6 +812,7 @@ class RenderTable extends RenderBox {
@override
@override
void
detach
()
{
void
detach
()
{
super
.
detach
();
if
(
_rowDecorationPainters
!=
null
)
{
if
(
_rowDecorationPainters
!=
null
)
{
for
(
BoxPainter
painter
in
_rowDecorationPainters
)
for
(
BoxPainter
painter
in
_rowDecorationPainters
)
painter
?.
dispose
();
painter
?.
dispose
();
...
@@ -819,7 +820,6 @@ class RenderTable extends RenderBox {
...
@@ -819,7 +820,6 @@ class RenderTable extends RenderBox {
}
}
for
(
RenderBox
child
in
_children
)
for
(
RenderBox
child
in
_children
)
child
?.
detach
();
child
?.
detach
();
super
.
detach
();
}
}
@override
@override
...
...
packages/flutter/lib/src/rendering/view.dart
View file @
02526228
...
@@ -80,7 +80,9 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox>
...
@@ -80,7 +80,9 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox>
if
(
configuration
==
value
)
if
(
configuration
==
value
)
return
;
return
;
_configuration
=
value
;
_configuration
=
value
;
replaceRootLayer
(
new
TransformLayer
(
transform:
configuration
.
toMatrix
()));
final
ContainerLayer
rootLayer
=
new
TransformLayer
(
transform:
configuration
.
toMatrix
());
rootLayer
.
attach
(
this
);
replaceRootLayer
(
rootLayer
);
markNeedsLayout
();
markNeedsLayout
();
}
}
...
@@ -88,7 +90,9 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox>
...
@@ -88,7 +90,9 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox>
void
scheduleInitialFrame
()
{
void
scheduleInitialFrame
()
{
assert
(
owner
!=
null
);
assert
(
owner
!=
null
);
scheduleInitialLayout
();
scheduleInitialLayout
();
scheduleInitialPaint
(
new
TransformLayer
(
transform:
configuration
.
toMatrix
()));
final
ContainerLayer
rootLayer
=
new
TransformLayer
(
transform:
configuration
.
toMatrix
());
rootLayer
.
attach
(
this
);
scheduleInitialPaint
(
rootLayer
);
owner
.
requestVisualUpdate
();
owner
.
requestVisualUpdate
();
}
}
...
...
packages/flutter/test/rendering/layers_test.dart
0 → 100644
View file @
02526228
// Copyright 2017 The Chromium 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
'package:flutter/rendering.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'rendering_tester.dart'
;
void
main
(
)
{
test
(
'non-painted layers are detached'
,
()
{
RenderObject
boundary
,
inner
;
final
RenderOpacity
root
=
new
RenderOpacity
(
child:
boundary
=
new
RenderRepaintBoundary
(
child:
inner
=
new
RenderDecoratedBox
(
decoration:
const
BoxDecoration
(),
),
),
);
layout
(
root
,
phase:
EnginePhase
.
paint
);
expect
(
inner
.
isRepaintBoundary
,
isFalse
);
expect
(()
=>
inner
.
layer
,
throwsAssertionError
);
expect
(
boundary
.
isRepaintBoundary
,
isTrue
);
expect
(
boundary
.
layer
,
isNotNull
);
expect
(
boundary
.
layer
.
attached
,
isTrue
);
// this time it painted...
root
.
opacity
=
0.0
;
pumpFrame
(
phase:
EnginePhase
.
paint
);
expect
(
inner
.
isRepaintBoundary
,
isFalse
);
expect
(()
=>
inner
.
layer
,
throwsAssertionError
);
expect
(
boundary
.
isRepaintBoundary
,
isTrue
);
expect
(
boundary
.
layer
,
isNotNull
);
expect
(
boundary
.
layer
.
attached
,
isFalse
);
// this time it did not.
root
.
opacity
=
0.5
;
pumpFrame
(
phase:
EnginePhase
.
paint
);
expect
(
inner
.
isRepaintBoundary
,
isFalse
);
expect
(()
=>
inner
.
layer
,
throwsAssertionError
);
expect
(
boundary
.
isRepaintBoundary
,
isTrue
);
expect
(
boundary
.
layer
,
isNotNull
);
expect
(
boundary
.
layer
.
attached
,
isTrue
);
// this time it did again!
});
}
packages/flutter/test/rendering/rendering_tester.dart
View file @
02526228
...
@@ -8,19 +8,15 @@ import 'package:flutter/rendering.dart';
...
@@ -8,19 +8,15 @@ import 'package:flutter/rendering.dart';
import
'package:flutter/scheduler.dart'
;
import
'package:flutter/scheduler.dart'
;
import
'package:flutter/services.dart'
;
import
'package:flutter/services.dart'
;
enum
EnginePhase
{
import
'package:flutter_test/flutter_test.dart'
show
EnginePhase
;
layout
,
export
'package:flutter_test/flutter_test.dart'
show
EnginePhase
;
compositingBits
,
paint
,
composite
,
flushSemantics
}
class
TestRenderingFlutterBinding
extends
BindingBase
with
SchedulerBinding
,
ServicesBinding
,
RendererBinding
,
GestureBinding
{
class
TestRenderingFlutterBinding
extends
BindingBase
with
SchedulerBinding
,
ServicesBinding
,
RendererBinding
,
GestureBinding
{
EnginePhase
phase
=
EnginePhase
.
composite
;
EnginePhase
phase
=
EnginePhase
.
composite
;
@override
@override
void
beginFrame
()
{
void
beginFrame
()
{
assert
(
phase
!=
EnginePhase
.
build
,
'rendering_tester does not support testing the build phase; use flutter_test instead'
);
pipelineOwner
.
flushLayout
();
pipelineOwner
.
flushLayout
();
if
(
phase
==
EnginePhase
.
layout
)
if
(
phase
==
EnginePhase
.
layout
)
return
;
return
;
...
@@ -34,7 +30,9 @@ class TestRenderingFlutterBinding extends BindingBase with SchedulerBinding, Ser
...
@@ -34,7 +30,9 @@ class TestRenderingFlutterBinding extends BindingBase with SchedulerBinding, Ser
if
(
phase
==
EnginePhase
.
composite
)
if
(
phase
==
EnginePhase
.
composite
)
return
;
return
;
pipelineOwner
.
flushSemantics
();
pipelineOwner
.
flushSemantics
();
assert
(
phase
==
EnginePhase
.
flushSemantics
);
if
(
phase
==
EnginePhase
.
flushSemantics
)
return
;
assert
(
phase
==
EnginePhase
.
flushSemantics
||
phase
==
EnginePhase
.
sendSemanticsTree
);
}
}
}
}
...
@@ -53,10 +51,13 @@ TestRenderingFlutterBinding get renderer {
...
@@ -53,10 +51,13 @@ TestRenderingFlutterBinding get renderer {
/// be put in a different place in the tree or passed to [layout] again, because
/// be put in a different place in the tree or passed to [layout] again, because
/// [layout] places the given object into another [RenderBox] which you would
/// [layout] places the given object into another [RenderBox] which you would
/// need to unparent it from (but that box isn't itself made available).
/// need to unparent it from (but that box isn't itself made available).
///
/// The EnginePhase must not be [EnginePhase.build], since the rendering layer
/// has no build phase.
void
layout
(
RenderBox
box
,
{
void
layout
(
RenderBox
box
,
{
BoxConstraints
constraints
,
BoxConstraints
constraints
,
FractionalOffset
alignment:
FractionalOffset
.
center
,
FractionalOffset
alignment:
FractionalOffset
.
center
,
EnginePhase
phase:
EnginePhase
.
layout
EnginePhase
phase:
EnginePhase
.
layout
,
})
{
})
{
assert
(
box
!=
null
);
// If you want to just repump the last box, call pumpFrame().
assert
(
box
!=
null
);
// If you want to just repump the last box, call pumpFrame().
assert
(
box
.
parent
==
null
);
// We stick the box in another, so you can't reuse it easily, sorry.
assert
(
box
.
parent
==
null
);
// We stick the box in another, so you can't reuse it easily, sorry.
...
...
packages/flutter_test/lib/src/binding.dart
View file @
02526228
...
@@ -30,7 +30,6 @@ import 'test_text_input.dart';
...
@@ -30,7 +30,6 @@ import 'test_text_input.dart';
///
///
/// See [WidgetsBinding.beginFrame] for a more detailed description of some of
/// See [WidgetsBinding.beginFrame] for a more detailed description of some of
/// these phases.
/// these phases.
// TODO(ianh): Merge with near-identical code in the rendering test code.
enum
EnginePhase
{
enum
EnginePhase
{
/// The build phase in the widgets library. See [BuildOwner.buildScope].
/// The build phase in the widgets library. See [BuildOwner.buildScope].
build
,
build
,
...
...
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