diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-03-08 10:28:10 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-03-20 13:40:30 +0000 |
commit | e733310db58160074f574c429d48f8308c0afe17 (patch) | |
tree | f8aef4b7e62a69928dbcf880620eece20f98c6df /chromium/cc/trees | |
parent | 2f583e4aec1ae3a86fa047829c96b310dc12ecdf (diff) |
BASELINE: Update Chromium to 56.0.2924.122
Change-Id: I4e04de8f47e47e501c46ed934c76a431c6337ced
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/cc/trees')
80 files changed, 3835 insertions, 6029 deletions
diff --git a/chromium/cc/trees/channel_impl.h b/chromium/cc/trees/channel_impl.h index aec9b4a6d61..6fdd4df9a11 100644 --- a/chromium/cc/trees/channel_impl.h +++ b/chromium/cc/trees/channel_impl.h @@ -10,7 +10,7 @@ namespace cc { -class AnimationEvents; +class MutatorEvents; // Channel used to send commands to and receive commands from ProxyMain. // The ChannelImpl implementation creates and owns ProxyImpl on receiving the @@ -19,10 +19,10 @@ class AnimationEvents; class CC_EXPORT ChannelImpl { public: // Interface for commands sent to ProxyMain - virtual void DidCompleteSwapBuffers() = 0; + virtual void DidReceiveCompositorFrameAck() = 0; virtual void BeginMainFrameNotExpectedSoon() = 0; virtual void DidCommitAndDrawFrame() = 0; - virtual void SetAnimationEvents(std::unique_ptr<AnimationEvents> queue) = 0; + virtual void SetAnimationEvents(std::unique_ptr<MutatorEvents> queue) = 0; virtual void DidLoseCompositorFrameSink() = 0; virtual void RequestNewCompositorFrameSink() = 0; virtual void DidInitializeCompositorFrameSink(bool success) = 0; diff --git a/chromium/cc/trees/channel_main.h b/chromium/cc/trees/channel_main.h index 538d4c8678d..3359d9c2c64 100644 --- a/chromium/cc/trees/channel_main.h +++ b/chromium/cc/trees/channel_main.h @@ -7,7 +7,7 @@ #include "cc/base/cc_export.h" #include "cc/base/completion_event.h" -#include "cc/input/top_controls_state.h" +#include "cc/input/browser_controls_state.h" #include "cc/output/compositor_frame_sink.h" #include "cc/scheduler/begin_frame_source.h" #include "cc/scheduler/commit_earlyout_reason.h" @@ -32,9 +32,10 @@ class CC_EXPORT ChannelMain { virtual ~ChannelMain() {} // Interface for commands sent to ProxyImpl - virtual void UpdateTopControlsStateOnImpl(TopControlsState constraints, - TopControlsState current, - bool animate) = 0; + virtual void UpdateBrowserControlsStateOnImpl( + BrowserControlsState constraints, + BrowserControlsState current, + bool animate) = 0; virtual void InitializeCompositorFrameSinkOnImpl( CompositorFrameSink* compositor_frame_sink) = 0; virtual void InitializeMutatorOnImpl( diff --git a/chromium/cc/trees/clip_node.cc b/chromium/cc/trees/clip_node.cc index b7d8164381c..04011596835 100644 --- a/chromium/cc/trees/clip_node.cc +++ b/chromium/cc/trees/clip_node.cc @@ -4,8 +4,8 @@ #include "base/trace_event/trace_event_argument.h" #include "cc/base/math_util.h" +#include "cc/proto/cc_conversions.h" #include "cc/proto/gfx_conversions.h" -#include "cc/proto/property_tree.pb.h" #include "cc/trees/clip_node.h" namespace cc { @@ -14,10 +14,10 @@ ClipNode::ClipNode() : id(-1), parent_id(-1), owner_id(-1), + clip_type(ClipType::NONE), transform_id(-1), target_transform_id(-1), target_effect_id(-1), - applies_local_clip(true), layer_clipping_uses_only_local_clip(false), target_is_clipped(false), layers_are_clipped(false), @@ -28,13 +28,13 @@ ClipNode::ClipNode(const ClipNode& other) = default; bool ClipNode::operator==(const ClipNode& other) const { return id == other.id && parent_id == other.parent_id && - owner_id == other.owner_id && clip == other.clip && + owner_id == other.owner_id && clip_type == other.clip_type && + clip == other.clip && combined_clip_in_target_space == other.combined_clip_in_target_space && clip_in_target_space == other.clip_in_target_space && transform_id == other.transform_id && target_transform_id == other.target_transform_id && target_effect_id == other.target_effect_id && - applies_local_clip == other.applies_local_clip && layer_clipping_uses_only_local_clip == other.layer_clipping_uses_only_local_clip && target_is_clipped == other.target_is_clipped && @@ -44,67 +44,15 @@ bool ClipNode::operator==(const ClipNode& other) const { resets_clip == other.resets_clip; } -void ClipNode::ToProtobuf(proto::TreeNode* proto) const { - proto->set_id(id); - proto->set_parent_id(parent_id); - proto->set_owner_id(owner_id); - - DCHECK(!proto->has_clip_node_data()); - proto::ClipNodeData* data = proto->mutable_clip_node_data(); - - RectFToProto(clip, data->mutable_clip()); - RectFToProto(combined_clip_in_target_space, - data->mutable_combined_clip_in_target_space()); - RectFToProto(clip_in_target_space, data->mutable_clip_in_target_space()); - - data->set_transform_id(transform_id); - data->set_target_transform_id(target_transform_id); - data->set_target_effect_id(target_effect_id); - data->set_applies_local_clip(applies_local_clip); - data->set_layer_clipping_uses_only_local_clip( - layer_clipping_uses_only_local_clip); - data->set_target_is_clipped(target_is_clipped); - data->set_layers_are_clipped(layers_are_clipped); - data->set_layers_are_clipped_when_surfaces_disabled( - layers_are_clipped_when_surfaces_disabled); - data->set_resets_clip(resets_clip); -} - -void ClipNode::FromProtobuf(const proto::TreeNode& proto) { - id = proto.id(); - parent_id = proto.parent_id(); - owner_id = proto.owner_id(); - - DCHECK(proto.has_clip_node_data()); - const proto::ClipNodeData& data = proto.clip_node_data(); - - clip = ProtoToRectF(data.clip()); - combined_clip_in_target_space = - ProtoToRectF(data.combined_clip_in_target_space()); - clip_in_target_space = ProtoToRectF(data.clip_in_target_space()); - - transform_id = data.transform_id(); - target_transform_id = data.target_transform_id(); - target_effect_id = data.target_effect_id(); - applies_local_clip = data.applies_local_clip(); - layer_clipping_uses_only_local_clip = - data.layer_clipping_uses_only_local_clip(); - target_is_clipped = data.target_is_clipped(); - layers_are_clipped = data.layers_are_clipped(); - layers_are_clipped_when_surfaces_disabled = - data.layers_are_clipped_when_surfaces_disabled(); - resets_clip = data.resets_clip(); -} - void ClipNode::AsValueInto(base::trace_event::TracedValue* value) const { value->SetInteger("id", id); value->SetInteger("parent_id", parent_id); value->SetInteger("owner_id", owner_id); + value->SetInteger("clip_type", static_cast<int>(clip_type)); MathUtil::AddToTracedValue("clip", clip, value); value->SetInteger("transform_id", transform_id); value->SetInteger("target_transform_id", target_transform_id); value->SetInteger("target_effect_id", target_effect_id); - value->SetBoolean("applies_local_clip", applies_local_clip); value->SetBoolean("layer_clipping_uses_only_local_clip", layer_clipping_uses_only_local_clip); value->SetBoolean("target_is_clipped", target_is_clipped); diff --git a/chromium/cc/trees/clip_node.h b/chromium/cc/trees/clip_node.h index e9dfede8342..5ce9f9b645a 100644 --- a/chromium/cc/trees/clip_node.h +++ b/chromium/cc/trees/clip_node.h @@ -16,10 +16,6 @@ class TracedValue; namespace cc { -namespace proto { -class TreeNode; -} // namespace proto - struct CC_EXPORT ClipNode { ClipNode(); ClipNode(const ClipNode& other); @@ -28,11 +24,22 @@ struct CC_EXPORT ClipNode { int parent_id; int owner_id; + enum class ClipType { + // The node doesn't contribute a new clip. It exists only for caching clips + // or for resetting clipping state. + NONE, + + // The node contributes a new clip (that is, |clip| needs to be applied). + APPLIES_LOCAL_CLIP + }; + + ClipType clip_type; + // The clip rect that this node contributes, expressed in the space of its // transform node. gfx::RectF clip; - // Clip nodes are uses for two reasons. First, they are used for determining + // Clip nodes are used for two reasons. First, they are used for determining // which parts of each layer are visible. Second, they are used for // determining whether a clip needs to be applied when drawing a layer, and if // so, the rect that needs to be used. These can be different since not all @@ -54,10 +61,6 @@ struct CC_EXPORT ClipNode { // The id of the effect node that defines the clip node's target space. int target_effect_id; - // Whether this node contributes a new clip (that is, whether |clip| needs to - // be applied), rather than only inheriting ancestor clips. - bool applies_local_clip : 1; - // When true, |clip_in_target_space| does not include clips from ancestor // nodes. bool layer_clipping_uses_only_local_clip : 1; @@ -75,8 +78,6 @@ struct CC_EXPORT ClipNode { bool operator==(const ClipNode& other) const; - void ToProtobuf(proto::TreeNode* proto) const; - void FromProtobuf(const proto::TreeNode& proto); void AsValueInto(base::trace_event::TracedValue* value) const; }; diff --git a/chromium/cc/trees/damage_tracker.h b/chromium/cc/trees/damage_tracker.h index 4111d65dae0..ea5f3167f30 100644 --- a/chromium/cc/trees/damage_tracker.h +++ b/chromium/cc/trees/damage_tracker.h @@ -13,8 +13,6 @@ #include "cc/layers/layer_collections.h" #include "ui/gfx/geometry/rect.h" -class SkImageFilter; - namespace gfx { class Rect; } diff --git a/chromium/cc/trees/damage_tracker_unittest.cc b/chromium/cc/trees/damage_tracker_unittest.cc index 4975bfdccdd..c0429871e7f 100644 --- a/chromium/cc/trees/damage_tracker_unittest.cc +++ b/chromium/cc/trees/damage_tracker_unittest.cc @@ -13,7 +13,6 @@ #include "cc/test/fake_impl_task_runner_provider.h" #include "cc/test/fake_layer_tree_host_impl.h" #include "cc/test/geometry_test_utils.h" -#include "cc/test/test_shared_bitmap_manager.h" #include "cc/test/test_task_graph_runner.h" #include "cc/trees/layer_tree_host_common.h" #include "cc/trees/layer_tree_impl.h" @@ -86,9 +85,7 @@ void EmulateDrawingOneFrame( class DamageTrackerTest : public testing::Test { public: DamageTrackerTest() - : host_impl_(&task_runner_provider_, - &shared_bitmap_manager_, - &task_graph_runner_) {} + : host_impl_(&task_runner_provider_, &task_graph_runner_) {} LayerImpl* CreateTestTreeWithOneSurface() { host_impl_.active_tree()->DetachLayers(); @@ -186,7 +183,6 @@ class DamageTrackerTest : public testing::Test { protected: FakeImplTaskRunnerProvider task_runner_provider_; - TestSharedBitmapManager shared_bitmap_manager_; TestTaskGraphRunner task_graph_runner_; FakeLayerTreeHostImpl host_impl_; }; diff --git a/chromium/cc/trees/draw_property_utils.cc b/chromium/cc/trees/draw_property_utils.cc index 27baf419d83..38b391c96a4 100644 --- a/chromium/cc/trees/draw_property_utils.cc +++ b/chromium/cc/trees/draw_property_utils.cc @@ -53,26 +53,6 @@ static void ValidateRenderSurfaceForLayer(LayerImpl* layer) { DCHECK(effect_node->filters.IsEmpty()); DCHECK(effect_node->background_filters.IsEmpty()); } - -void VerifySurfaceContentsScalesMatch(const int target_effect_id, - const int target_transform_id, - const EffectTree& effect_tree, - const TransformTree& transform_tree) { - if (target_effect_id == EffectTree::kInvalidNodeId) { - // This can happen when PaintArtifactCompositor builds property trees as it - // doesn't set effect ids on clip nodes. - return; - } - const TransformNode* target_transform_node = - transform_tree.Node(target_transform_id); - const EffectNode* target_effect_node = effect_tree.Node(target_effect_id); - DCHECK(target_transform_node->surface_contents_scale == - target_effect_node->surface_contents_scale) - << " surface contents scale from transform tree: " - << target_transform_node->surface_contents_scale.ToString() - << " surface contents scale from effect tree: " - << target_effect_node->surface_contents_scale.ToString(); -} #endif static const EffectNode* ContentsTargetEffectNode( @@ -106,25 +86,11 @@ bool ComputeClipRectInTargetSpace(const LayerImpl* layer, // In this case, layer has a scroll parent. We need to keep the scale // at the layer's target but remove the scale at the scroll parent's // target. - if (property_trees->ComputeTransformToTarget(clip_node->target_transform_id, - target_effect_node->id, - &clip_to_target)) { - PostConcatSurfaceContentsScale(target_effect_node, &clip_to_target); -#if DCHECK_IS_ON() - const TransformTree& transform_tree = property_trees->transform_tree; - VerifySurfaceContentsScalesMatch(layer->effect_tree_index(), - target_node_id, effect_tree, - transform_tree); -#endif - + if (property_trees->GetToTarget(clip_node->target_transform_id, + target_effect_node->id, &clip_to_target)) { const EffectNode* source_node = effect_tree.Node(clip_node->target_effect_id); ConcatInverseSurfaceContentsScale(source_node, &clip_to_target); -#if DCHECK_IS_ON() - VerifySurfaceContentsScalesMatch(clip_node->target_effect_id, - clip_node->target_transform_id, - effect_tree, transform_tree); -#endif *clip_rect_in_target_space = MathUtil::MapClippedRect(clip_to_target, clip_from_clip_node); } else { @@ -178,19 +144,11 @@ static ConditionalClip ComputeLocalRectInTargetSpace( int target_transform_id, int target_effect_id) { gfx::Transform current_to_target; - if (!property_trees->ComputeTransformToTarget( - current_transform_id, target_effect_id, ¤t_to_target)) { + if (!property_trees->GetToTarget(current_transform_id, target_effect_id, + ¤t_to_target)) { // If transform is not invertible, cannot apply clip. return ConditionalClip{false, gfx::RectF()}; } - const EffectTree& effect_tree = property_trees->effect_tree; - const EffectNode* target_effect_node = effect_tree.Node(target_effect_id); - PostConcatSurfaceContentsScale(target_effect_node, ¤t_to_target); -#if DCHECK_IS_ON() - const TransformTree& transform_tree = property_trees->transform_tree; - VerifySurfaceContentsScalesMatch(target_effect_id, target_transform_id, - effect_tree, transform_tree); -#endif if (current_transform_id > target_transform_id) return ConditionalClip{true, // is_clipped. @@ -213,7 +171,7 @@ static ConditionalClip ComputeCurrentClip(const ClipNode* clip_node, gfx::RectF current_clip = clip_node->clip; gfx::Vector2dF surface_contents_scale = effect_tree.Node(target_effect_id)->surface_contents_scale; - // The viewport clip should not be scaled + // The viewport clip should not be scaled. if (surface_contents_scale.x() > 0 && surface_contents_scale.y() > 0 && clip_node->transform_id != TransformTree::kRootNodeId) current_clip.Scale(surface_contents_scale.x(), surface_contents_scale.y()); @@ -222,8 +180,11 @@ static ConditionalClip ComputeCurrentClip(const ClipNode* clip_node, static ConditionalClip ComputeAccumulatedClip( const PropertyTrees* property_trees, + bool include_viewport_clip, int local_clip_id, int target_id) { + DCHECK(!include_viewport_clip || + target_id == EffectTree::kContentsRootNodeId); const ClipTree& clip_tree = property_trees->clip_tree; const EffectTree& effect_tree = property_trees->effect_tree; @@ -237,36 +198,37 @@ static ConditionalClip ComputeAccumulatedClip( // If target is not direct ancestor of clip, this will find least common // ancestor between the target and the clip. - while (target_node->id != EffectTree::kInvalidNodeId && - clip_node->id != ClipTree::kInvalidNodeId) { - while (target_node->clip_id > clip_node->id || - target_node->has_unclipped_descendants) { - target_node = effect_tree.Node(target_node->target_id); - } - if (target_node->clip_id == clip_node->id) - break; - while (target_node->clip_id < clip_node->id) { - parent_chain.push(clip_node); - clip_node = clip_tree.parent(clip_node); - } - if (target_node->clip_id == clip_node->id) { - // Target is responsible for applying this clip_node (id equals to - // target_node's clip id), no need to accumulate this as part of clip - // rect. - clip_node = parent_chain.top(); - parent_chain.pop(); - break; - } + while (target_node->clip_id > clip_node->id || + target_node->has_unclipped_descendants) { + target_node = effect_tree.Node(target_node->target_id); + } + + // Collect clip nodes up to the least common ancestor. + while (target_node->clip_id < clip_node->id) { + parent_chain.push(clip_node); + clip_node = clip_tree.parent(clip_node); + } + DCHECK_EQ(target_node->clip_id, clip_node->id); + + if (!include_viewport_clip && parent_chain.size() == 0) { + // There aren't any clips to apply. + return ConditionalClip{false, gfx::RectF()}; + } + + if (!include_viewport_clip) { + clip_node = parent_chain.top(); + parent_chain.pop(); } // TODO(weiliangc): If we don't create clip for render surface, we don't need // to check applies_local_clip. - while (!clip_node->applies_local_clip && parent_chain.size() > 0) { + while (clip_node->clip_type != ClipNode::ClipType::APPLIES_LOCAL_CLIP && + parent_chain.size() > 0) { clip_node = parent_chain.top(); parent_chain.pop(); } - if (!clip_node->applies_local_clip) + if (clip_node->clip_type != ClipNode::ClipType::APPLIES_LOCAL_CLIP) // No clip node applying clip in between. return ConditionalClip{false, gfx::RectF()}; @@ -278,7 +240,7 @@ static ConditionalClip ComputeAccumulatedClip( while (parent_chain.size() > 0) { clip_node = parent_chain.top(); parent_chain.pop(); - if (!clip_node->applies_local_clip) { + if (clip_node->clip_type != ClipNode::ClipType::APPLIES_LOCAL_CLIP) { continue; } ConditionalClip current_clip = ComputeCurrentClip( @@ -301,73 +263,63 @@ static gfx::RectF ComputeAccumulatedClipInRootSpaceForVisibleRect( const PropertyTrees* property_trees, int local_clip_id) { const int root_effect_id = EffectTree::kContentsRootNodeId; - ConditionalClip accumulated_clip = - ComputeAccumulatedClip(property_trees, local_clip_id, root_effect_id); - - gfx::RectF accumulated_clip_rect = accumulated_clip.clip_rect; - const ClipNode* root_effect_node = - property_trees->clip_tree.Node(root_effect_id); - if (accumulated_clip.is_clipped) { - accumulated_clip_rect.Intersect(root_effect_node->clip_in_target_space); - } else { - // In this case, we need only the viewport clip as the accumulated clip is - // unclipped. - accumulated_clip_rect = root_effect_node->clip_in_target_space; - } - return accumulated_clip_rect; + bool include_viewport_clip = true; + ConditionalClip accumulated_clip = ComputeAccumulatedClip( + property_trees, include_viewport_clip, local_clip_id, root_effect_id); + DCHECK(accumulated_clip.is_clipped); + return accumulated_clip.clip_rect; } -template <typename LayerType> -void CalculateClipRects( - const typename LayerType::LayerListType& visible_layer_list, - const PropertyTrees* property_trees, - bool non_root_surfaces_enabled) { +void CalculateClipRects(const std::vector<LayerImpl*>& visible_layer_list, + const PropertyTrees* property_trees, + bool non_root_surfaces_enabled) { const ClipTree& clip_tree = property_trees->clip_tree; for (auto& layer : visible_layer_list) { const ClipNode* clip_node = clip_tree.Node(layer->clip_tree_index()); + bool layer_needs_clip_rect = + non_root_surfaces_enabled + ? clip_node->layers_are_clipped + : clip_node->layers_are_clipped_when_surfaces_disabled; + if (!layer_needs_clip_rect) { + layer->set_clip_rect(gfx::Rect()); + continue; + } if (!non_root_surfaces_enabled) { layer->set_clip_rect( gfx::ToEnclosingRect(clip_node->clip_in_target_space)); continue; } - // When both the layer and the target are unclipped, the entire layer - // content rect is visible. - const bool fully_visible = - !clip_node->layers_are_clipped && !clip_node->target_is_clipped; + const TransformTree& transform_tree = property_trees->transform_tree; + const TransformNode* transform_node = + transform_tree.Node(layer->transform_tree_index()); + int target_node_id = transform_tree.ContentTargetId(transform_node->id); - if (!fully_visible) { - const TransformTree& transform_tree = property_trees->transform_tree; - const TransformNode* transform_node = - transform_tree.Node(layer->transform_tree_index()); - int target_node_id = transform_tree.ContentTargetId(transform_node->id); - - // The clip node stores clip rect in its target space. - gfx::RectF clip_rect_in_target_space = clip_node->clip_in_target_space; - - // If required, this clip rect should be mapped to the current layer's - // target space. - if (clip_node->target_transform_id != target_node_id) { - // In this case, layer has a clip parent or scroll parent (or shares the - // target with an ancestor layer that has clip parent) and the clip - // parent's target is different from the layer's target. As the layer's - // target has unclippped descendants, it is unclippped. - if (!clip_node->layers_are_clipped) - continue; - - // Compute the clip rect in target space and store it. - bool for_visible_rect_calculation = false; - if (!ComputeClipRectInTargetSpace( - layer, clip_node, property_trees, target_node_id, - for_visible_rect_calculation, &clip_rect_in_target_space)) - continue; - } + // The clip node stores clip rect in its target space. + gfx::RectF clip_rect_in_target_space = clip_node->clip_in_target_space; - if (!clip_rect_in_target_space.IsEmpty()) { - layer->set_clip_rect(gfx::ToEnclosingRect(clip_rect_in_target_space)); - } else { - layer->set_clip_rect(gfx::Rect()); - } + // If required, this clip rect should be mapped to the current layer's + // target space. + if (clip_node->target_transform_id != target_node_id) { + // In this case, layer has a clip parent or scroll parent (or shares the + // target with an ancestor layer that has clip parent) and the clip + // parent's target is different from the layer's target. As the layer's + // target has unclippped descendants, it is unclippped. + if (!clip_node->layers_are_clipped) + continue; + + // Compute the clip rect in target space and store it. + bool for_visible_rect_calculation = false; + if (!ComputeClipRectInTargetSpace( + layer, clip_node, property_trees, target_node_id, + for_visible_rect_calculation, &clip_rect_in_target_space)) + continue; + } + + if (!clip_rect_in_target_space.IsEmpty()) { + layer->set_clip_rect(gfx::ToEnclosingRect(clip_rect_in_target_space)); + } else { + layer->set_clip_rect(gfx::Rect()); } } } @@ -385,9 +337,10 @@ void CalculateVisibleRects(const LayerImplList& visible_layer_list, effect_tree.ClosestAncestorWithCopyRequest(layer->effect_tree_index()); if (effect_ancestor_with_copy_request > 1) { // Non root copy request. - ConditionalClip accumulated_clip_rect = - ComputeAccumulatedClip(property_trees, layer->clip_tree_index(), - effect_ancestor_with_copy_request); + bool include_viewport_clip = false; + ConditionalClip accumulated_clip_rect = ComputeAccumulatedClip( + property_trees, include_viewport_clip, layer->clip_tree_index(), + effect_ancestor_with_copy_request); if (!accumulated_clip_rect.is_clipped) { layer->set_visible_layer_rect(gfx::Rect(layer_bounds)); continue; @@ -497,8 +450,10 @@ void CalculateVisibleRects(const LayerImplList& visible_layer_list, } // The clip rect should be intersected with layer rect in target space. - gfx::Transform content_to_target = transform_tree.ToTarget( - transform_node->id, layer->render_target_effect_tree_index()); + gfx::Transform content_to_target; + property_trees->GetToTarget(transform_node->id, + layer->render_target_effect_tree_index(), + &content_to_target); content_to_target.Translate(layer->offset_to_transform_parent().x(), layer->offset_to_transform_parent().y()); gfx::Rect layer_content_rect = gfx::Rect(layer_bounds); @@ -522,8 +477,9 @@ void CalculateVisibleRects(const LayerImplList& visible_layer_list, gfx::Transform target_to_layer; if (transform_node->ancestors_are_invertible) { - target_to_layer = transform_tree.FromTarget( - transform_node->id, layer->render_target_effect_tree_index()); + property_trees->GetFromTarget(transform_node->id, + layer->render_target_effect_tree_index(), + &target_to_layer); } else { const EffectNode* target_effect_node = ContentsTargetEffectNode(layer->effect_tree_index(), effect_tree); @@ -537,10 +493,6 @@ void CalculateVisibleRects(const LayerImplList& visible_layer_list, continue; } ConcatInverseSurfaceContentsScale(target_effect_node, &target_to_layer); -#if DCHECK_IS_ON() - VerifySurfaceContentsScalesMatch(target_effect_node->id, target_node_id, - effect_tree, transform_tree); -#endif } gfx::Transform target_to_content; target_to_content.Translate(-layer->offset_to_transform_parent().x(), @@ -569,31 +521,36 @@ static int TransformTreeIndexForBackfaceVisibility(LayerType* layer, return layer->id() == node->owner_id ? tree.parent(node)->id : node->id; } -static bool IsTargetSpaceTransformBackFaceVisible(Layer* layer, - int transform_tree_index, - const TransformTree& tree) { +static bool IsTargetSpaceTransformBackFaceVisible( + Layer* layer, + int transform_tree_index, + const PropertyTrees* property_trees) { // We do not skip back face invisible layers on main thread as target space // transform will not be available here. return false; } -static bool IsTargetSpaceTransformBackFaceVisible(LayerImpl* layer, - int transform_tree_index, - const TransformTree& tree) { - return tree - .ToTarget(transform_tree_index, layer->render_target_effect_tree_index()) - .IsBackFaceVisible(); +static bool IsTargetSpaceTransformBackFaceVisible( + LayerImpl* layer, + int transform_tree_index, + const PropertyTrees* property_trees) { + gfx::Transform to_target; + property_trees->GetToTarget(transform_tree_index, + layer->render_target_effect_tree_index(), + &to_target); + return to_target.IsBackFaceVisible(); } template <typename LayerType> static bool IsLayerBackFaceVisible(LayerType* layer, int transform_tree_index, - const TransformTree& tree) { - const TransformNode* node = tree.Node(transform_tree_index); + const PropertyTrees* property_trees) { + const TransformNode* node = + property_trees->transform_tree.Node(transform_tree_index); return layer->use_local_transform_for_backface_visibility() ? node->local.IsBackFaceVisible() : IsTargetSpaceTransformBackFaceVisible( - layer, transform_tree_index, tree); + layer, transform_tree_index, property_trees); } static inline bool TransformToScreenIsKnown(Layer* layer, @@ -612,7 +569,7 @@ static inline bool TransformToScreenIsKnown(LayerImpl* layer, template <typename LayerType> static bool LayerNeedsUpdateInternal(LayerType* layer, bool layer_is_drawn, - const TransformTree& tree) { + const PropertyTrees* property_trees) { // Layers can be skipped if any of these conditions are met. // - is not drawn due to it or one of its ancestors being hidden (or having // no copy requests). @@ -637,6 +594,7 @@ static bool LayerNeedsUpdateInternal(LayerType* layer, // The layer should not be drawn if (1) it is not double-sided and (2) the // back of the layer is known to be facing the screen. + const TransformTree& tree = property_trees->transform_tree; if (layer->should_check_backface_visibility()) { int backface_transform_id = TransformTreeIndexForBackfaceVisibility(layer, tree); @@ -644,7 +602,7 @@ static bool LayerNeedsUpdateInternal(LayerType* layer, // backface is not visible. if (TransformToScreenIsKnown(layer, backface_transform_id, tree) && !HasSingularTransform(backface_transform_id, tree) && - IsLayerBackFaceVisible(layer, backface_transform_id, tree)) + IsLayerBackFaceVisible(layer, backface_transform_id, property_trees)) return false; } @@ -652,19 +610,20 @@ static bool LayerNeedsUpdateInternal(LayerType* layer, } void FindLayersThatNeedUpdates(LayerTreeImpl* layer_tree_impl, - const TransformTree& transform_tree, - const EffectTree& effect_tree, + const PropertyTrees* property_trees, std::vector<LayerImpl*>* visible_layer_list) { - for (auto* layer_impl : *layer_tree_impl) { - bool layer_is_drawn = - effect_tree.Node(layer_impl->effect_tree_index())->is_drawn; + const TransformTree& transform_tree = property_trees->transform_tree; + const EffectTree& effect_tree = property_trees->effect_tree; + for (auto* layer_impl : *layer_tree_impl) { if (!IsRootLayer(layer_impl) && - LayerShouldBeSkipped(layer_impl, layer_is_drawn, transform_tree, - effect_tree)) + LayerShouldBeSkipped(layer_impl, transform_tree, effect_tree)) continue; - if (LayerNeedsUpdate(layer_impl, layer_is_drawn, transform_tree)) + bool layer_is_drawn = + effect_tree.Node(layer_impl->effect_tree_index())->is_drawn; + + if (LayerNeedsUpdate(layer_impl, layer_is_drawn, property_trees)) visible_layer_list->push_back(layer_impl); } } @@ -689,7 +648,6 @@ void UpdateRenderSurfaceForLayer(EffectTree* effect_tree, template <typename LayerType> static inline bool LayerShouldBeSkippedInternal( LayerType* layer, - bool layer_is_drawn, const TransformTree& transform_tree, const EffectTree& effect_tree) { const TransformNode* transform_node = @@ -708,35 +666,31 @@ static inline bool LayerShouldBeSkippedInternal( } bool LayerShouldBeSkipped(LayerImpl* layer, - bool layer_is_drawn, const TransformTree& transform_tree, const EffectTree& effect_tree) { - return LayerShouldBeSkippedInternal(layer, layer_is_drawn, transform_tree, - effect_tree); + return LayerShouldBeSkippedInternal(layer, transform_tree, effect_tree); } bool LayerShouldBeSkipped(Layer* layer, - bool layer_is_drawn, const TransformTree& transform_tree, const EffectTree& effect_tree) { - return LayerShouldBeSkippedInternal(layer, layer_is_drawn, transform_tree, - effect_tree); + return LayerShouldBeSkippedInternal(layer, transform_tree, effect_tree); } void FindLayersThatNeedUpdates(LayerTree* layer_tree, - const TransformTree& transform_tree, - const EffectTree& effect_tree, + const PropertyTrees* property_trees, LayerList* update_layer_list) { + const TransformTree& transform_tree = property_trees->transform_tree; + const EffectTree& effect_tree = property_trees->effect_tree; for (auto* layer : *layer_tree) { - bool layer_is_drawn = - effect_tree.Node(layer->effect_tree_index())->is_drawn; - if (!IsRootLayer(layer) && - LayerShouldBeSkipped(layer, layer_is_drawn, transform_tree, - effect_tree)) + LayerShouldBeSkipped(layer, transform_tree, effect_tree)) continue; - if (LayerNeedsUpdate(layer, layer_is_drawn, transform_tree)) { + bool layer_is_drawn = + effect_tree.Node(layer->effect_tree_index())->is_drawn; + + if (LayerNeedsUpdate(layer, layer_is_drawn, property_trees)) { update_layer_list->push_back(layer); } @@ -822,20 +776,10 @@ void ComputeClips(PropertyTrees* property_trees, const EffectNode* target_effect_node = effect_tree.Node(clip_node->target_effect_id); PostConcatSurfaceContentsScale(target_effect_node, &parent_to_current); -#if DCHECK_IS_ON() - VerifySurfaceContentsScalesMatch(clip_node->target_effect_id, - clip_node->target_transform_id, - effect_tree, transform_tree); -#endif const EffectNode* parent_target_effect_node = effect_tree.Node(parent_clip_node->target_effect_id); ConcatInverseSurfaceContentsScale(parent_target_effect_node, &parent_to_current); -#if DCHECK_IS_ON() - VerifySurfaceContentsScalesMatch(parent_clip_node->target_effect_id, - parent_clip_node->target_transform_id, - effect_tree, transform_tree); -#endif // If we can't compute a transform, it's because we had to use the inverse // of a singular transform. We won't draw in this case, so there's no need // to compute clips. @@ -852,11 +796,12 @@ void ComputeClips(PropertyTrees* property_trees, // need to clip using our parent clip and if we don't propagate it here, // it will be lost. if (clip_node->resets_clip && non_root_surfaces_enabled) { - if (clip_node->applies_local_clip) { - clip_node->clip_in_target_space = MathUtil::MapClippedRect( - transform_tree.ToTarget(clip_node->transform_id, - clip_node->target_effect_id), - clip_node->clip); + if (clip_node->clip_type == ClipNode::ClipType::APPLIES_LOCAL_CLIP) { + gfx::Transform to_target; + property_trees->GetToTarget(clip_node->transform_id, + clip_node->target_effect_id, &to_target); + clip_node->clip_in_target_space = + MathUtil::MapClippedRect(to_target, clip_node->clip); ResetIfHasNanCoordinate(&clip_node->clip_in_target_space); clip_node->combined_clip_in_target_space = gfx::IntersectRects(clip_node->clip_in_target_space, @@ -870,7 +815,8 @@ void ComputeClips(PropertyTrees* property_trees, ResetIfHasNanCoordinate(&clip_node->combined_clip_in_target_space); continue; } - bool use_only_parent_clip = !clip_node->applies_local_clip; + bool use_only_parent_clip = + clip_node->clip_type != ClipNode::ClipType::APPLIES_LOCAL_CLIP; if (use_only_parent_clip) { clip_node->combined_clip_in_target_space = parent_combined_clip_in_target_space; @@ -892,19 +838,12 @@ void ComputeClips(PropertyTrees* property_trees, source_to_target = transform_tree.ToScreen(clip_node->transform_id); } else if (transform_tree.ContentTargetId(transform_node->id) == clip_node->target_transform_id) { - source_to_target = transform_tree.ToTarget(clip_node->transform_id, - clip_node->target_effect_id); + property_trees->GetToTarget(clip_node->transform_id, + clip_node->target_effect_id, + &source_to_target); } else { - success = property_trees->ComputeTransformToTarget( + success = property_trees->GetToTarget( transform_node->id, clip_node->target_effect_id, &source_to_target); - const EffectNode* target_effect_node = - effect_tree.Node(clip_node->target_effect_id); - PostConcatSurfaceContentsScale(target_effect_node, &source_to_target); -#if DCHECK_IS_ON() - VerifySurfaceContentsScalesMatch(clip_node->target_effect_id, - clip_node->target_transform_id, - effect_tree, transform_tree); -#endif // source_to_target computation should be successful as target is an // ancestor of the transform node. DCHECK(success); @@ -949,7 +888,7 @@ void UpdateRenderTarget(EffectTree* effect_tree, for (int i = 1; i < static_cast<int>(effect_tree->size()); ++i) { EffectNode* node = effect_tree->Node(i); if (i == 1) { - // Render target on the node corresponding to root is itself. + // Render target of the node corresponding to root is itself. node->target_id = 1; } else if (!can_render_to_separate_surface) { node->target_id = 1; @@ -985,8 +924,10 @@ static void ComputeClipsWithEffectTree(PropertyTrees* property_trees) { for (int i = 2; i < static_cast<int>(effect_tree->size()); ++i) { EffectNode* effect_node = effect_tree->Node(i); const EffectNode* target_node = effect_tree->Node(effect_node->target_id); - ConditionalClip accumulated_clip_rect = ComputeAccumulatedClip( - property_trees, effect_node->clip_id, target_node->id); + bool include_viewport_clip = false; + ConditionalClip accumulated_clip_rect = + ComputeAccumulatedClip(property_trees, include_viewport_clip, + effect_node->clip_id, target_node->id); gfx::RectF accumulated_clip = accumulated_clip_rect.clip_rect; const RenderSurfaceImpl* render_surface = effect_node->render_surface; if (render_surface && render_surface->is_clipped()) { @@ -1004,6 +945,7 @@ static void ComputeLayerClipRect(const PropertyTrees* property_trees, const LayerImpl* layer) { const EffectTree* effect_tree = &property_trees->effect_tree; const ClipTree* clip_tree = &property_trees->clip_tree; + const ClipNode* clip_node = clip_tree->Node(layer->clip_tree_index()); const EffectNode* effect_node = effect_tree->Node(layer->effect_tree_index()); const EffectNode* target_node = effect_node->has_render_surface @@ -1015,65 +957,25 @@ static void ComputeLayerClipRect(const PropertyTrees* property_trees, target_node = effect_tree->Node(1); } - ConditionalClip accumulated_clip_rect = ComputeAccumulatedClip( - property_trees, layer->clip_tree_index(), target_node->id); + bool include_viewport_clip = false; + ConditionalClip accumulated_clip_rect = + ComputeAccumulatedClip(property_trees, include_viewport_clip, + layer->clip_tree_index(), target_node->id); - gfx::RectF accumulated_clip = accumulated_clip_rect.clip_rect; + bool is_clipped_from_clip_tree = + property_trees->non_root_surfaces_enabled + ? clip_node->layers_are_clipped + : clip_node->layers_are_clipped_when_surfaces_disabled; + DCHECK_EQ(is_clipped_from_clip_tree, accumulated_clip_rect.is_clipped); - if ((!property_trees->non_root_surfaces_enabled && - clip_tree->Node(layer->clip_tree_index()) - ->layers_are_clipped_when_surfaces_disabled) || - clip_tree->Node(layer->clip_tree_index())->layers_are_clipped) { - DCHECK(layer->clip_rect() == gfx::ToEnclosingRect(accumulated_clip)) - << " layer: " << layer->id() << " clip id: " << layer->clip_tree_index() - << " layer clip: " << layer->clip_rect().ToString() << " v.s. " - << gfx::ToEnclosingRect(accumulated_clip).ToString() - << " and clip node clip: " - << gfx::ToEnclosingRect( - clip_tree->Node(layer->clip_tree_index())->clip_in_target_space) - .ToString(); - } -} + gfx::RectF accumulated_clip = accumulated_clip_rect.clip_rect; -static int FindTargetTransformTreeIndexFromEffectTree( - const EffectTree& effect_tree, - const int effect_tree_index) { - const EffectNode* node = effect_tree.Node(effect_tree_index); - if (node->has_render_surface) - return node->transform_id; - node = effect_tree.Node(node->target_id); - return node->transform_id; -} - -static void VerifyDrawTransformsMatch(LayerImpl* layer, - PropertyTrees* property_trees) { - const int source_id = layer->transform_tree_index(); - int destination_id = FindTargetTransformTreeIndexFromEffectTree( - property_trees->effect_tree, layer->effect_tree_index()); - const EffectNode* target_effect_node = ContentsTargetEffectNode( - layer->effect_tree_index(), property_trees->effect_tree); - gfx::Transform draw_transform; - property_trees->ComputeTransformToTarget(source_id, target_effect_node->id, - &draw_transform); - PostConcatSurfaceContentsScale(target_effect_node, &draw_transform); -#if DCHECK_IS_ON() - VerifySurfaceContentsScalesMatch(layer->effect_tree_index(), destination_id, - property_trees->effect_tree, - property_trees->transform_tree); -#endif - if (layer->should_flatten_transform_from_property_tree()) - draw_transform.FlattenTo2d(); - draw_transform.Translate(layer->offset_to_transform_parent().x(), - layer->offset_to_transform_parent().y()); - DCHECK(draw_transform.ApproximatelyEqual(DrawTransform( - layer, property_trees->transform_tree, property_trees->effect_tree))) - << " layer: " << layer->id() << " source transform id: " << source_id - << " destination transform id: " << destination_id - << " draw transform from transform tree: " - << DrawTransform(layer, property_trees->transform_tree, - property_trees->effect_tree) - .ToString() - << " v.s." << draw_transform.ToString(); + DCHECK(layer->clip_rect() == gfx::ToEnclosingRect(accumulated_clip)) + << " layer: " << layer->id() << " clip id: " << layer->clip_tree_index() + << " layer clip: " << layer->clip_rect().ToString() << " v.s. " + << gfx::ToEnclosingRect(accumulated_clip).ToString() + << " and clip node clip: " + << gfx::ToEnclosingRect(clip_node->clip_in_target_space).ToString(); } static void ComputeVisibleRectsInternal( @@ -1098,11 +1000,10 @@ static void ComputeVisibleRectsInternal( ComputeEffects(&property_trees->effect_tree); ComputeClips(property_trees, can_render_to_separate_surface); - FindLayersThatNeedUpdates(root_layer->layer_tree_impl(), - property_trees->transform_tree, - property_trees->effect_tree, visible_layer_list); - CalculateClipRects<LayerImpl>(*visible_layer_list, property_trees, - can_render_to_separate_surface); + FindLayersThatNeedUpdates(root_layer->layer_tree_impl(), property_trees, + visible_layer_list); + CalculateClipRects(*visible_layer_list, property_trees, + can_render_to_separate_surface); CalculateVisibleRects(*visible_layer_list, property_trees, can_render_to_separate_surface); } @@ -1157,12 +1058,6 @@ void VerifyClipTreeCalculations(const LayerImplList& layer_list, ComputeLayerClipRect(property_trees, layer); } -void VerifyTransformTreeCalculations(const LayerImplList& layer_list, - PropertyTrees* property_trees) { - for (auto* layer : layer_list) - VerifyDrawTransformsMatch(layer, property_trees); -} - void ComputeVisibleRects(LayerImpl* root_layer, PropertyTrees* property_trees, bool can_render_to_separate_surface, @@ -1194,9 +1089,10 @@ gfx::Rect ComputeLayerVisibleRectDynamic(const PropertyTrees* property_trees, gfx::Rect layer_content_rect = gfx::Rect(layer->bounds()); gfx::RectF accumulated_clip_in_root_space; if (non_root_copy_request) { - ConditionalClip accumulated_clip = - ComputeAccumulatedClip(property_trees, layer->clip_tree_index(), - effect_ancestor_with_copy_request); + bool include_viewport_clip = false; + ConditionalClip accumulated_clip = ComputeAccumulatedClip( + property_trees, include_viewport_clip, layer->clip_tree_index(), + effect_ancestor_with_copy_request); if (!accumulated_clip.is_clipped) return layer_content_rect; accumulated_clip_in_root_space = accumulated_clip.clip_rect; @@ -1240,46 +1136,33 @@ void VerifyVisibleRectsCalculations(const LayerImplList& layer_list, bool LayerNeedsUpdate(Layer* layer, bool layer_is_drawn, - const TransformTree& tree) { - return LayerNeedsUpdateInternal(layer, layer_is_drawn, tree); + const PropertyTrees* property_trees) { + return LayerNeedsUpdateInternal(layer, layer_is_drawn, property_trees); } bool LayerNeedsUpdate(LayerImpl* layer, bool layer_is_drawn, - const TransformTree& tree) { - return LayerNeedsUpdateInternal(layer, layer_is_drawn, tree); + const PropertyTrees* property_trees) { + return LayerNeedsUpdateInternal(layer, layer_is_drawn, property_trees); } gfx::Transform DrawTransform(const LayerImpl* layer, const TransformTree& transform_tree, const EffectTree& effect_tree) { + // TransformTree::ToTarget computes transform between the layer's transform + // node and surface's transform node and scales it by the surface's content + // scale. gfx::Transform xform; - const bool owns_non_root_surface = - !IsRootLayer(layer) && layer->render_surface(); - if (!owns_non_root_surface) { - // If you're not the root, or you don't own a surface, you need to apply - // your local offset. - xform = - transform_tree.property_trees()->non_root_surfaces_enabled - ? transform_tree.ToTarget(layer->transform_tree_index(), - layer->render_target_effect_tree_index()) - : transform_tree.ToScreen(layer->transform_tree_index()); - if (layer->should_flatten_transform_from_property_tree()) - xform.FlattenTo2d(); - xform.Translate(layer->offset_to_transform_parent().x(), - layer->offset_to_transform_parent().y()); - } else { - // Surfaces need to apply their surface contents scale. - const EffectNode* effect_node = - effect_tree.Node(layer->effect_tree_index()); - xform.Scale(effect_node->surface_contents_scale.x(), - effect_node->surface_contents_scale.y()); -#if DCHECK_IS_ON() - VerifySurfaceContentsScalesMatch(layer->effect_tree_index(), - layer->transform_tree_index(), effect_tree, - transform_tree); -#endif - } + if (transform_tree.property_trees()->non_root_surfaces_enabled) + transform_tree.property_trees()->GetToTarget( + layer->transform_tree_index(), layer->render_target_effect_tree_index(), + &xform); + else + xform = transform_tree.ToScreen(layer->transform_tree_index()); + if (layer->should_flatten_transform_from_property_tree()) + xform.FlattenTo2d(); + xform.Translate(layer->offset_to_transform_parent().x(), + layer->offset_to_transform_parent().y()); return xform; } @@ -1300,22 +1183,10 @@ static void SetSurfaceDrawTransform(const PropertyTrees* property_trees, gfx::Transform render_surface_transform; const EffectNode* target_effect_node = effect_tree.Node(effect_node->target_id); - property_trees->ComputeTransformToTarget( - transform_node->id, target_effect_node->id, &render_surface_transform); - PostConcatSurfaceContentsScale(target_effect_node, &render_surface_transform); -#if DCHECK_IS_ON() - const TransformNode* target_transform_node = - transform_tree.Node(transform_tree.TargetId(transform_node->id)); - VerifySurfaceContentsScalesMatch(effect_node->target_id, - target_transform_node->id, effect_tree, - transform_tree); -#endif + property_trees->GetToTarget(transform_node->id, target_effect_node->id, + &render_surface_transform); ConcatInverseSurfaceContentsScale(effect_node, &render_surface_transform); -#if DCHECK_IS_ON() - VerifySurfaceContentsScalesMatch(effect_node->id, transform_node->id, - effect_tree, transform_tree); -#endif render_surface->SetDrawTransform(render_surface_transform); } @@ -1353,7 +1224,7 @@ static void SetSurfaceClipRect(const ClipNode* parent_clip_node, const EffectNode* effect_node = effect_tree.Node(render_surface->EffectTreeIndex()); int target_effect_id = effect_node->target_id; - const bool success = property_trees->ComputeTransformToTarget( + const bool success = property_trees->GetToTarget( parent_clip_node->target_transform_id, target_effect_id, &clip_parent_target_to_target); @@ -1362,13 +1233,6 @@ static void SetSurfaceClipRect(const ClipNode* parent_clip_node, return; } - PostConcatSurfaceContentsScale(effect_node, &clip_parent_target_to_target); -#if DCHECK_IS_ON() - VerifySurfaceContentsScalesMatch(render_surface->EffectTreeIndex(), - transform_tree.TargetId(transform_node->id), - effect_tree, transform_tree); -#endif - DCHECK_LT(parent_clip_node->target_transform_id, transform_tree.TargetId(transform_node->id)); render_surface->SetClipRect(gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( diff --git a/chromium/cc/trees/draw_property_utils.h b/chromium/cc/trees/draw_property_utils.h index 329d25c690b..4e9e0227336 100644 --- a/chromium/cc/trees/draw_property_utils.h +++ b/chromium/cc/trees/draw_property_utils.h @@ -16,8 +16,6 @@ class Vector2dF; namespace cc { -class ClipTree; -struct DrawProperties; class Layer; class LayerImpl; class LayerTree; @@ -36,8 +34,7 @@ void CC_EXPORT ConcatInverseSurfaceContentsScale(const EffectNode* effect_node, gfx::Transform* transform); // Computes combined clips for every node in |clip_tree|. This function requires // that |transform_tree| has been updated via |ComputeTransforms|. -void CC_EXPORT ComputeClips(ClipTree* clip_tree, - const TransformTree& transform_tree, +void CC_EXPORT ComputeClips(PropertyTrees* property_trees, bool non_root_surfaces_enabled); // Computes combined (screen space) transforms for every node in the transform @@ -66,15 +63,9 @@ void CC_EXPORT UpdatePropertyTrees(PropertyTrees* property_trees, bool can_render_to_separate_surface); void CC_EXPORT FindLayersThatNeedUpdates(LayerTree* layer_tree, - const TransformTree& transform_tree, - const EffectTree& effect_tree, + const PropertyTrees* property_trees, LayerList* update_layer_list); -void CC_EXPORT -ComputeVisibleRectsForTesting(PropertyTrees* property_trees, - bool can_render_to_separate_surface, - LayerList* visible_layer_list); - void CC_EXPORT ComputeVisibleRects(LayerImpl* root_layer, PropertyTrees* property_trees, bool can_render_to_separate_surface, @@ -97,24 +88,20 @@ void CC_EXPORT ComputeSurfaceDrawProperties(const PropertyTrees* property_trees, RenderSurfaceImpl* render_surface); bool CC_EXPORT LayerShouldBeSkipped(LayerImpl* layer, - bool layer_is_drawn, const TransformTree& transform_tree, const EffectTree& effect_tree); bool CC_EXPORT LayerNeedsUpdate(Layer* layer, bool layer_is_drawn, - const TransformTree& tree); + const PropertyTrees* property_trees); bool CC_EXPORT LayerNeedsUpdate(LayerImpl* layer, bool layer_is_drawn, - const TransformTree& tree); + const PropertyTrees* property_trees); void CC_EXPORT VerifyClipTreeCalculations(const LayerImplList& layer_list, PropertyTrees* property_trees); -void CC_EXPORT VerifyTransformTreeCalculations(const LayerImplList& layer_list, - PropertyTrees* property_trees); - gfx::Transform CC_EXPORT DrawTransform(const LayerImpl* layer, const TransformTree& transform_tree, const EffectTree& effect_tree); diff --git a/chromium/cc/trees/effect_node.cc b/chromium/cc/trees/effect_node.cc index 893a033254a..7d987460f48 100644 --- a/chromium/cc/trees/effect_node.cc +++ b/chromium/cc/trees/effect_node.cc @@ -4,7 +4,6 @@ #include "base/trace_event/trace_event_argument.h" #include "cc/proto/gfx_conversions.h" -#include "cc/proto/property_tree.pb.h" #include "cc/proto/skia_conversions.h" #include "cc/trees/effect_node.h" @@ -66,69 +65,6 @@ bool EffectNode::operator==(const EffectNode& other) const { target_id == other.target_id && mask_layer_id == other.mask_layer_id; } -void EffectNode::ToProtobuf(proto::TreeNode* proto) const { - proto->set_id(id); - proto->set_parent_id(parent_id); - proto->set_owner_id(owner_id); - - DCHECK(!proto->has_effect_node_data()); - proto::EffectNodeData* data = proto->mutable_effect_node_data(); - data->set_opacity(opacity); - data->set_screen_space_opacity(screen_space_opacity); - data->set_blend_mode(SkXfermodeModeToProto(blend_mode)); - data->set_has_render_surface(has_render_surface); - data->set_has_copy_request(has_copy_request); - data->set_hidden_by_backface_visibility(hidden_by_backface_visibility); - data->set_double_sided(double_sided); - data->set_is_drawn(is_drawn); - data->set_subtree_hidden(subtree_hidden); - data->set_has_potential_filter_animation(has_potential_filter_animation); - data->set_has_potential_opacity_animation(has_potential_opacity_animation); - data->set_is_currently_animating_filter(is_currently_animating_filter); - data->set_is_currently_animating_opacity(is_currently_animating_opacity); - data->set_effect_changed(effect_changed); - data->set_num_copy_requests_in_subtree(num_copy_requests_in_subtree); - data->set_transform_id(transform_id); - data->set_clip_id(clip_id); - data->set_target_id(target_id); - data->set_mask_layer_id(mask_layer_id); - Vector2dFToProto(surface_contents_scale, - data->mutable_surface_contents_scale()); - SizeToProto(unscaled_mask_target_size, - data->mutable_unscaled_mask_target_size()); -} - -void EffectNode::FromProtobuf(const proto::TreeNode& proto) { - id = proto.id(); - parent_id = proto.parent_id(); - owner_id = proto.owner_id(); - - DCHECK(proto.has_effect_node_data()); - const proto::EffectNodeData& data = proto.effect_node_data(); - - opacity = data.opacity(); - screen_space_opacity = data.screen_space_opacity(); - blend_mode = SkXfermodeModeFromProto(data.blend_mode()); - unscaled_mask_target_size = ProtoToSize(data.unscaled_mask_target_size()); - has_render_surface = data.has_render_surface(); - has_copy_request = data.has_copy_request(); - hidden_by_backface_visibility = data.hidden_by_backface_visibility(); - double_sided = data.double_sided(); - is_drawn = data.is_drawn(); - subtree_hidden = data.subtree_hidden(); - has_potential_filter_animation = data.has_potential_filter_animation(); - has_potential_opacity_animation = data.has_potential_opacity_animation(); - is_currently_animating_filter = data.is_currently_animating_filter(); - is_currently_animating_opacity = data.is_currently_animating_opacity(); - effect_changed = data.effect_changed(); - num_copy_requests_in_subtree = data.num_copy_requests_in_subtree(); - transform_id = data.transform_id(); - clip_id = data.clip_id(); - target_id = data.target_id(); - mask_layer_id = data.mask_layer_id(); - surface_contents_scale = ProtoToVector2dF(data.surface_contents_scale()); -} - void EffectNode::AsValueInto(base::trace_event::TracedValue* value) const { value->SetInteger("id", id); value->SetInteger("parent_id", parent_id); diff --git a/chromium/cc/trees/effect_node.h b/chromium/cc/trees/effect_node.h index a38acdd241f..e1699be82e3 100644 --- a/chromium/cc/trees/effect_node.h +++ b/chromium/cc/trees/effect_node.h @@ -21,10 +21,6 @@ namespace cc { class RenderSurfaceImpl; -namespace proto { -class TreeNode; -} // namespace proto - struct CC_EXPORT EffectNode { EffectNode(); EffectNode(const EffectNode& other); @@ -72,8 +68,6 @@ struct CC_EXPORT EffectNode { bool operator==(const EffectNode& other) const; - void ToProtobuf(proto::TreeNode* proto) const; - void FromProtobuf(const proto::TreeNode& proto); void AsValueInto(base::trace_event::TracedValue* value) const; }; diff --git a/chromium/cc/trees/element_id.cc b/chromium/cc/trees/element_id.cc new file mode 100644 index 00000000000..45913303c10 --- /dev/null +++ b/chromium/cc/trees/element_id.cc @@ -0,0 +1,56 @@ +// Copyright 2016 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. + +#include "cc/trees/element_id.h" + +#include <limits> +#include <ostream> + +#include "base/trace_event/trace_event_argument.h" +#include "base/values.h" + +namespace cc { + +bool ElementId::operator==(const ElementId& o) const { + return primaryId == o.primaryId && secondaryId == o.secondaryId; +} + +bool ElementId::operator!=(const ElementId& o) const { + return !(*this == o); +} + +bool ElementId::operator<(const ElementId& o) const { + return std::tie(primaryId, secondaryId) < + std::tie(o.primaryId, o.secondaryId); +} + +ElementId::operator bool() const { + return !!primaryId; +} + +ElementId LayerIdToElementIdForTesting(int layer_id) { + return ElementId(std::numeric_limits<int>::max() - layer_id, 0); +} + +void ElementId::AddToTracedValue(base::trace_event::TracedValue* res) const { + res->SetInteger("primaryId", primaryId); + res->SetInteger("secondaryId", secondaryId); +} + +std::unique_ptr<base::Value> ElementId::AsValue() const { + std::unique_ptr<base::DictionaryValue> res(new base::DictionaryValue()); + res->SetInteger("primaryId", primaryId); + res->SetInteger("secondaryId", secondaryId); + return std::move(res); +} + +size_t ElementIdHash::operator()(ElementId key) const { + return base::HashInts(key.primaryId, key.secondaryId); +} + +std::ostream& operator<<(std::ostream& out, const ElementId& id) { + return out << "(" << id.primaryId << ", " << id.secondaryId << ")"; +} + +} // namespace cc diff --git a/chromium/cc/trees/element_id.h b/chromium/cc/trees/element_id.h new file mode 100644 index 00000000000..4c0b652cc88 --- /dev/null +++ b/chromium/cc/trees/element_id.h @@ -0,0 +1,70 @@ +// Copyright 2016 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. + +#ifndef CC_TREES_ELEMENT_ID_H_ +#define CC_TREES_ELEMENT_ID_H_ + +#include <stddef.h> + +#include <cstdint> +#include <functional> +#include <iosfwd> +#include <memory> + +#include "base/hash.h" +#include "cc/base/cc_export.h" + +namespace base { +class Value; +namespace trace_event { +class TracedValue; +} // namespace trace_event +} // namespace base + +namespace cc { + +// An "element" is really an animation target. It retains the name element to be +// symmetric with ElementAnimations and blink::ElementAnimations, but is not +// in fact tied to the notion of a blink element. It is also not associated with +// the notion of a Layer. Ultimately, these ids will be used to look up the +// property tree node associated with the given animation. +// +// These ids are chosen by cc's clients to permit the destruction and +// restoration of cc entities (when visuals are hidden and shown) but maintain +// stable identifiers. There will be a single layer for an ElementId, but +// not every layer will have an id. +struct CC_EXPORT ElementId { + ElementId(int primaryId, int secondaryId) + : primaryId(primaryId), secondaryId(secondaryId) {} + ElementId() : ElementId(0, 0) {} + + bool operator==(const ElementId& o) const; + bool operator!=(const ElementId& o) const; + bool operator<(const ElementId& o) const; + + // An ElementId's conversion to a boolean value depends only on its primaryId. + explicit operator bool() const; + + void AddToTracedValue(base::trace_event::TracedValue* res) const; + std::unique_ptr<base::Value> AsValue() const; + + // The compositor treats this as an opaque handle and should not know how to + // interpret these bits. Non-blink cc clients typically operate in terms of + // layers and may set this value to match the client's layer id. + int primaryId; + int secondaryId; +}; + +CC_EXPORT ElementId LayerIdToElementIdForTesting(int layer_id); + +struct CC_EXPORT ElementIdHash { + size_t operator()(ElementId key) const; +}; + +// Stream operator so ElementId can be used in assertion statements. +CC_EXPORT std::ostream& operator<<(std::ostream& out, const ElementId& id); + +} // namespace cc + +#endif // CC_TREES_ELEMENT_ID_H_ diff --git a/chromium/cc/trees/layer_tree.cc b/chromium/cc/trees/layer_tree.cc index 3d46e3fae10..bf07576cc69 100644 --- a/chromium/cc/trees/layer_tree.cc +++ b/chromium/cc/trees/layer_tree.cc @@ -6,46 +6,24 @@ #include "base/auto_reset.h" #include "base/time/time.h" -#include "cc/animation/animation_host.h" #include "cc/input/page_scale_animation.h" #include "cc/layers/heads_up_display_layer.h" #include "cc/layers/heads_up_display_layer_impl.h" #include "cc/layers/layer.h" -#include "cc/layers/layer_proto_converter.h" #include "cc/proto/gfx_conversions.h" #include "cc/proto/layer_tree.pb.h" #include "cc/trees/layer_tree_host.h" #include "cc/trees/layer_tree_host_common.h" #include "cc/trees/layer_tree_impl.h" +#include "cc/trees/mutator_host.h" #include "cc/trees/property_tree_builder.h" namespace cc { -namespace { - -Layer* UpdateAndGetLayer(Layer* current_layer, - int layer_id, - LayerTree* layer_tree) { - if (layer_id == Layer::INVALID_ID) { - if (current_layer) - current_layer->SetLayerTreeHost(nullptr); - - return nullptr; - } - Layer* layer = layer_tree->LayerById(layer_id); - DCHECK(layer); - if (current_layer && current_layer != layer) - current_layer->SetLayerTreeHost(nullptr); - - return layer; -} - -} // namespace - LayerTree::Inputs::Inputs() : top_controls_height(0.f), top_controls_shown_ratio(0.f), - top_controls_shrink_blink_size(false), + browser_controls_shrink_blink_size(false), bottom_controls_height(0.f), device_scale_factor(1.f), painted_device_scale_factor(1.f), @@ -59,20 +37,19 @@ LayerTree::Inputs::Inputs() LayerTree::Inputs::~Inputs() = default; -LayerTree::LayerTree(std::unique_ptr<AnimationHost> animation_host, - LayerTreeHost* layer_tree_host) +LayerTree::LayerTree(MutatorHost* mutator_host, LayerTreeHost* layer_tree_host) : needs_full_tree_sync_(true), needs_meta_info_recomputation_(true), in_paint_layer_contents_(false), - animation_host_(std::move(animation_host)), + mutator_host_(mutator_host), layer_tree_host_(layer_tree_host) { - DCHECK(animation_host_); + DCHECK(mutator_host_); DCHECK(layer_tree_host_); - animation_host_->SetMutatorHostClient(this); + mutator_host_->SetMutatorHostClient(this); } LayerTree::~LayerTree() { - animation_host_->SetMutatorHostClient(nullptr); + mutator_host_->SetMutatorHostClient(nullptr); // We must clear any pointers into the layer tree prior to destroying it. RegisterViewportLayers(nullptr, nullptr, nullptr, nullptr); @@ -158,17 +135,17 @@ void LayerTree::SetViewportSize(const gfx::Size& device_viewport_size) { SetNeedsCommit(); } -void LayerTree::SetTopControlsHeight(float height, bool shrink) { +void LayerTree::SetBrowserControlsHeight(float height, bool shrink) { if (inputs_.top_controls_height == height && - inputs_.top_controls_shrink_blink_size == shrink) + inputs_.browser_controls_shrink_blink_size == shrink) return; inputs_.top_controls_height = height; - inputs_.top_controls_shrink_blink_size = shrink; + inputs_.browser_controls_shrink_blink_size = shrink; SetNeedsCommit(); } -void LayerTree::SetTopControlsShownRatio(float ratio) { +void LayerTree::SetBrowserControlsShownRatio(float ratio) { if (inputs_.top_controls_shown_ratio == ratio) return; @@ -243,8 +220,8 @@ void LayerTree::RegisterLayer(Layer* layer) { DCHECK(!in_paint_layer_contents_); layer_id_map_[layer->id()] = layer; if (layer->element_id()) { - animation_host_->RegisterElement(layer->element_id(), - ElementListType::ACTIVE); + mutator_host_->RegisterElement(layer->element_id(), + ElementListType::ACTIVE); } } @@ -252,8 +229,8 @@ void LayerTree::UnregisterLayer(Layer* layer) { DCHECK(LayerById(layer->id())); DCHECK(!in_paint_layer_contents_); if (layer->element_id()) { - animation_host_->UnregisterElement(layer->element_id(), - ElementListType::ACTIVE); + mutator_host_->UnregisterElement(layer->element_id(), + ElementListType::ACTIVE); } RemoveLayerShouldPushProperties(layer); layer_id_map_.erase(layer->id()); @@ -343,7 +320,8 @@ void LayerTree::SetPropertyTreesNeedRebuild() { layer_tree_host_->SetNeedsUpdateLayers(); } -void LayerTree::PushPropertiesTo(LayerTreeImpl* tree_impl) { +void LayerTree::PushPropertiesTo(LayerTreeImpl* tree_impl, + float unapplied_page_scale_delta) { tree_impl->set_needs_full_tree_sync(needs_full_tree_sync_); needs_full_tree_sync_ = false; @@ -400,15 +378,16 @@ void LayerTree::PushPropertiesTo(LayerTreeImpl* tree_impl) { // Setting property trees must happen before pushing the page scale. tree_impl->SetPropertyTrees(&property_trees_); - tree_impl->PushPageScaleFromMainThread(inputs_.page_scale_factor, - inputs_.min_page_scale_factor, - inputs_.max_page_scale_factor); + tree_impl->PushPageScaleFromMainThread( + inputs_.page_scale_factor * unapplied_page_scale_delta, + inputs_.min_page_scale_factor, inputs_.max_page_scale_factor); - tree_impl->set_top_controls_shrink_blink_size( - inputs_.top_controls_shrink_blink_size); + tree_impl->set_browser_controls_shrink_blink_size( + inputs_.browser_controls_shrink_blink_size); tree_impl->set_top_controls_height(inputs_.top_controls_height); tree_impl->set_bottom_controls_height(inputs_.bottom_controls_height); - tree_impl->PushTopControlsFromMainThread(inputs_.top_controls_shown_ratio); + tree_impl->PushBrowserControlsFromMainThread( + inputs_.top_controls_shown_ratio); tree_impl->elastic_overscroll()->PushFromMainThread(elastic_overscroll_); if (tree_impl->IsActiveTree()) tree_impl->elastic_overscroll()->PushPendingToActive(); @@ -428,11 +407,9 @@ void LayerTree::PushPropertiesTo(LayerTreeImpl* tree_impl) { tree_impl->set_has_ever_been_drawn(false); } -void LayerTree::ToProtobuf(proto::LayerTree* proto, bool inputs_only) { +void LayerTree::ToProtobuf(proto::LayerTree* proto) { TRACE_EVENT0("cc.remote", "LayerProtoConverter::SerializeLayerHierarchy"); - // LayerTree::Inputs Serialization ----------------------------------------- - // TODO(khushalsagar): Why walk the tree twice? Why not serialize properties // for dirty layers as you serialize the hierarchy? if (inputs_.root_layer) @@ -455,8 +432,8 @@ void LayerTree::ToProtobuf(proto::LayerTree* proto, bool inputs_only) { ? inputs_.outer_viewport_scroll_layer->id() : Layer::INVALID_ID); - // Top Controls ignored. They are not supported. - DCHECK(!inputs_.top_controls_shrink_blink_size); + // Browser Controls ignored. They are not supported. + DCHECK(!inputs_.browser_controls_shrink_blink_size); proto->set_device_scale_factor(inputs_.device_scale_factor); proto->set_painted_device_scale_factor(inputs_.painted_device_scale_factor); @@ -480,95 +457,6 @@ void LayerTree::ToProtobuf(proto::LayerTree* proto, bool inputs_only) { proto->set_touch_end_or_cancel_event_listener_properties( static_cast<uint32_t>( event_listener_properties(EventListenerClass::kTouchEndOrCancel))); - - if (inputs_only) - return; - // ---------------------------------------------------------------------- - - for (auto* layer : layers_that_should_push_properties_) { - proto->add_layers_that_should_push_properties(layer->id()); - } - proto->set_in_paint_layer_contents(in_paint_layer_contents()); - - proto->set_needs_full_tree_sync(needs_full_tree_sync_); - proto->set_needs_meta_info_recomputation(needs_meta_info_recomputation_); - proto->set_hud_layer_id(hud_layer_ ? hud_layer_->id() : Layer::INVALID_ID); - - property_trees_.ToProtobuf(proto->mutable_property_trees()); - Vector2dFToProto(elastic_overscroll_, proto->mutable_elastic_overscroll()); -} - -void LayerTree::FromProtobuf(const proto::LayerTree& proto) { - // Layer hierarchy. - scoped_refptr<Layer> new_root_layer; - if (proto.has_root_layer()) - new_root_layer = LayerProtoConverter::DeserializeLayerHierarchy( - inputs_.root_layer, proto.root_layer(), layer_tree_host_); - if (inputs_.root_layer != new_root_layer) { - inputs_.root_layer = new_root_layer; - } - - for (auto layer_id : proto.layers_that_should_push_properties()) { - AddLayerShouldPushProperties(layer_id_map_[layer_id]); - } - in_paint_layer_contents_ = proto.in_paint_layer_contents(); - - needs_full_tree_sync_ = proto.needs_full_tree_sync(); - needs_meta_info_recomputation_ = proto.needs_meta_info_recomputation(); - - inputs_.overscroll_elasticity_layer = - UpdateAndGetLayer(inputs_.overscroll_elasticity_layer.get(), - proto.overscroll_elasticity_layer_id(), this); - inputs_.page_scale_layer = UpdateAndGetLayer( - inputs_.page_scale_layer.get(), proto.page_scale_layer_id(), this); - inputs_.inner_viewport_scroll_layer = - UpdateAndGetLayer(inputs_.inner_viewport_scroll_layer.get(), - proto.inner_viewport_scroll_layer_id(), this); - inputs_.outer_viewport_scroll_layer = - UpdateAndGetLayer(inputs_.outer_viewport_scroll_layer.get(), - proto.outer_viewport_scroll_layer_id(), this); - - inputs_.device_viewport_size = ProtoToSize(proto.device_viewport_size()); - inputs_.device_scale_factor = proto.device_scale_factor(); - inputs_.painted_device_scale_factor = proto.painted_device_scale_factor(); - inputs_.page_scale_factor = proto.page_scale_factor(); - inputs_.min_page_scale_factor = proto.min_page_scale_factor(); - inputs_.max_page_scale_factor = proto.max_page_scale_factor(); - inputs_.background_color = proto.background_color(); - inputs_.has_transparent_background = proto.has_transparent_background(); - inputs_.have_scroll_event_handlers = proto.have_scroll_event_handlers(); - inputs_.event_listener_properties[static_cast<size_t>( - EventListenerClass::kMouseWheel)] = - static_cast<EventListenerProperties>( - proto.wheel_event_listener_properties()); - inputs_.event_listener_properties[static_cast<size_t>( - EventListenerClass::kTouchStartOrMove)] = - static_cast<EventListenerProperties>( - proto.touch_start_or_move_event_listener_properties()); - inputs_.event_listener_properties[static_cast<size_t>( - EventListenerClass::kTouchEndOrCancel)] = - static_cast<EventListenerProperties>( - proto.touch_end_or_cancel_event_listener_properties()); - - hud_layer_ = static_cast<HeadsUpDisplayLayer*>( - UpdateAndGetLayer(hud_layer_.get(), proto.hud_layer_id(), this)); - - LayerSelectionFromProtobuf(&inputs_.selection, proto.selection()); - elastic_overscroll_ = ProtoToVector2dF(proto.elastic_overscroll()); - - // It is required to create new PropertyTrees before deserializing it. - property_trees_ = PropertyTrees(); - property_trees_.FromProtobuf(proto.property_trees()); - - // Forcefully override the sequence number of all layers in the tree to have - // a valid sequence number. Changing the sequence number for a layer does not - // need a commit, so the value will become out of date for layers that are not - // updated for other reasons. All layers that at this point are part of the - // layer tree are valid, so it is OK that they have a valid sequence number. - int seq_num = property_trees_.sequence_number; - LayerTreeHostCommon::CallFunctionForEveryLayer(this, [seq_num](Layer* layer) { - layer->set_property_tree_sequence_number(seq_num); - }); } Layer* LayerTree::LayerByElementId(ElementId element_id) const { @@ -583,13 +471,13 @@ void LayerTree::RegisterElement(ElementId element_id, element_layers_map_[layer->element_id()] = layer; } - animation_host_->RegisterElement(element_id, list_type); + mutator_host_->RegisterElement(element_id, list_type); } void LayerTree::UnregisterElement(ElementId element_id, ElementListType list_type, Layer* layer) { - animation_host_->UnregisterElement(element_id, list_type); + mutator_host_->UnregisterElement(element_id, list_type); if (layer->element_id()) { element_layers_map_.erase(layer->element_id()); diff --git a/chromium/cc/trees/layer_tree.h b/chromium/cc/trees/layer_tree.h index 9f749bfe077..e58e71cb1f4 100644 --- a/chromium/cc/trees/layer_tree.h +++ b/chromium/cc/trees/layer_tree.h @@ -30,10 +30,8 @@ namespace cc { namespace proto { class LayerTree; -class LayerUpdate; } // namespace proto -class AnimationHost; class ClientPictureCache; class EnginePictureCache; class HeadsUpDisplayLayer; @@ -41,18 +39,15 @@ class Layer; class LayerTreeHost; class LayerTreeImpl; class LayerTreeSettings; +class MutatorHost; struct PendingPageScaleAnimation; -class UIResourceManager; -class SwapPromiseManager; -class SurfaceSequenceGenerator; class CC_EXPORT LayerTree : public MutatorHostClient { public: using LayerSet = std::unordered_set<Layer*>; using LayerIdMap = std::unordered_map<int, Layer*>; - LayerTree(std::unique_ptr<AnimationHost> animation_host, - LayerTreeHost* layer_tree_host); + LayerTree(MutatorHost* mutator_host, LayerTreeHost* layer_tree_host); virtual ~LayerTree(); void SetRootLayer(scoped_refptr<Layer> root_layer); @@ -76,6 +71,7 @@ class CC_EXPORT LayerTree : public MutatorHostClient { } void RegisterSelection(const LayerSelection& selection); + const LayerSelection& selection() const { return inputs_.selection; } void SetHaveScrollEventHandlers(bool have_event_handlers); bool have_scroll_event_handlers() const { @@ -94,14 +90,16 @@ class CC_EXPORT LayerTree : public MutatorHostClient { return inputs_.device_viewport_size; } - void SetTopControlsHeight(float height, bool shrink); - void SetTopControlsShownRatio(float ratio); + void SetBrowserControlsHeight(float height, bool shrink); + void SetBrowserControlsShownRatio(float ratio); void SetBottomControlsHeight(float height); void SetPageScaleFactorAndLimits(float page_scale_factor, float min_page_scale_factor, float max_page_scale_factor); float page_scale_factor() const { return inputs_.page_scale_factor; } + float min_page_scale_factor() const { return inputs_.min_page_scale_factor; } + float max_page_scale_factor() const { return inputs_.max_page_scale_factor; } void set_background_color(SkColor color) { inputs_.background_color = color; } SkColor background_color() const { return inputs_.background_color; } @@ -109,6 +107,9 @@ class CC_EXPORT LayerTree : public MutatorHostClient { void set_has_transparent_background(bool transparent) { inputs_.has_transparent_background = transparent; } + bool has_transparent_background() const { + return inputs_.has_transparent_background; + } void StartPageScaleAnimation(const gfx::Vector2d& target_offset, bool use_anchor, @@ -120,6 +121,9 @@ class CC_EXPORT LayerTree : public MutatorHostClient { float device_scale_factor() const { return inputs_.device_scale_factor; } void SetPaintedDeviceScaleFactor(float painted_device_scale_factor); + float painted_device_scale_factor() const { + return inputs_.painted_device_scale_factor; + } void SetDeviceColorSpace(const gfx::ColorSpace& device_color_space); const gfx::ColorSpace& device_color_space() const { @@ -181,12 +185,12 @@ class CC_EXPORT LayerTree : public MutatorHostClient { void SetPropertyTreesNeedRebuild(); - void PushPropertiesTo(LayerTreeImpl* tree_impl); + void PushPropertiesTo(LayerTreeImpl* tree_impl, + float unapplied_page_scale_delta); - void ToProtobuf(proto::LayerTree* proto, bool inputs_only); - void FromProtobuf(const proto::LayerTree& proto); + void ToProtobuf(proto::LayerTree* proto); - AnimationHost* animation_host() const { return animation_host_.get(); } + MutatorHost* mutator_host() const { return mutator_host_; } Layer* LayerByElementId(ElementId element_id) const; void RegisterElement(ElementId element_id, @@ -207,8 +211,6 @@ class CC_EXPORT LayerTree : public MutatorHostClient { // --------------------------------------------------------------------- private: - friend class LayerTreeHostSerializationTest; - // MutatorHostClient implementation. bool IsElementInList(ElementId element_id, ElementListType list_type) const override; @@ -251,7 +253,7 @@ class CC_EXPORT LayerTree : public MutatorHostClient { float top_controls_height; float top_controls_shown_ratio; - bool top_controls_shrink_blink_size; + bool browser_controls_shrink_blink_size; float bottom_controls_height; @@ -298,7 +300,7 @@ class CC_EXPORT LayerTree : public MutatorHostClient { bool in_paint_layer_contents_; - std::unique_ptr<AnimationHost> animation_host_; + MutatorHost* mutator_host_; LayerTreeHost* layer_tree_host_; // TODO(khushalsagar): Make these go away once we transition blimp to an diff --git a/chromium/cc/trees/layer_tree_host.h b/chromium/cc/trees/layer_tree_host.h index 5f02fefd5dd..3b8ff9decca 100644 --- a/chromium/cc/trees/layer_tree_host.h +++ b/chromium/cc/trees/layer_tree_host.h @@ -9,7 +9,7 @@ #include "base/memory/weak_ptr.h" #include "cc/base/cc_export.h" #include "cc/debug/micro_benchmark.h" -#include "cc/input/top_controls_state.h" +#include "cc/input/browser_controls_state.h" namespace base { class TimeTicks; @@ -143,9 +143,6 @@ class CC_EXPORT LayerTreeHost { // scheduling is disabled. virtual void Composite(base::TimeTicks frame_begin_time) = 0; - // Requests a redraw (compositor frame) for the complete viewport. - virtual void SetNeedsRedraw() = 0; - // Requests a redraw (compositor frame) for the given rect. virtual void SetNeedsRedrawRect(const gfx::Rect& damage_rect) = 0; @@ -161,11 +158,11 @@ class CC_EXPORT LayerTreeHost { // tree so a commit can be performed. virtual void NotifyInputThrottledUntilCommit() = 0; - // Sets the state of the top controls. (Used for URL bar animations on + // Sets the state of the browser controls. (Used for URL bar animations on // android). - virtual void UpdateTopControlsState(TopControlsState constraints, - TopControlsState current, - bool animate) = 0; + virtual void UpdateBrowserControlsState(BrowserControlsState constraints, + BrowserControlsState current, + bool animate) = 0; // Returns a reference to the InputHandler used to respond to input events on // the compositor thread. diff --git a/chromium/cc/trees/layer_tree_host_client.h b/chromium/cc/trees/layer_tree_host_client.h index f0a64b8eb16..c0fcb4bef14 100644 --- a/chromium/cc/trees/layer_tree_host_client.h +++ b/chromium/cc/trees/layer_tree_host_client.h @@ -10,13 +10,10 @@ #include "base/memory/ref_counted.h" namespace gfx { -class Vector2d; class Vector2dF; } namespace cc { -class ContextProvider; -class InputHandlerClient; class CompositorFrameSink; struct BeginFrameArgs; @@ -56,7 +53,7 @@ class LayerTreeHostClient { virtual void WillCommit() = 0; virtual void DidCommit() = 0; virtual void DidCommitAndDrawFrame() = 0; - virtual void DidCompleteSwapBuffers() = 0; + virtual void DidReceiveCompositorFrameAck() = 0; virtual void DidCompletePageScaleAnimation() = 0; protected: diff --git a/chromium/cc/trees/layer_tree_host_common.cc b/chromium/cc/trees/layer_tree_host_common.cc index edce74f5928..8fcfccb40fc 100644 --- a/chromium/cc/trees/layer_tree_host_common.cc +++ b/chromium/cc/trees/layer_tree_host_common.cc @@ -15,8 +15,6 @@ #include "cc/layers/layer.h" #include "cc/layers/layer_impl.h" #include "cc/layers/layer_iterator.h" -#include "cc/proto/begin_main_frame_and_commit_state.pb.h" -#include "cc/proto/gfx_conversions.h" #include "cc/trees/draw_property_utils.h" #include "cc/trees/effect_node.h" #include "cc/trees/layer_tree_host.h" @@ -84,7 +82,6 @@ LayerTreeHostCommon::CalcDrawPropsImplInputs::CalcDrawPropsImplInputs( bool can_adjust_raster_scales, bool verify_clip_tree_calculations, bool verify_visible_rect_calculations, - bool verify_transform_tree_calculations, LayerImplList* render_surface_layer_list, PropertyTrees* property_trees) : root_layer(root_layer), @@ -103,7 +100,6 @@ LayerTreeHostCommon::CalcDrawPropsImplInputs::CalcDrawPropsImplInputs( can_adjust_raster_scales(can_adjust_raster_scales), verify_clip_tree_calculations(verify_clip_tree_calculations), verify_visible_rect_calculations(verify_visible_rect_calculations), - verify_transform_tree_calculations(verify_transform_tree_calculations), render_surface_layer_list(render_surface_layer_list), property_trees(property_trees) {} @@ -128,7 +124,6 @@ LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting:: false, true, true, - true, render_surface_layer_list, GetPropertyTrees(root_layer)) { DCHECK(root_layer); @@ -175,50 +170,27 @@ bool LayerTreeHostCommon::ScrollUpdateInfo::operator==( return layer_id == other.layer_id && scroll_delta == other.scroll_delta; } -void LayerTreeHostCommon::ScrollUpdateInfo::ToProtobuf( - proto::ScrollUpdateInfo* proto) const { - proto->set_layer_id(layer_id); - Vector2dToProto(scroll_delta, proto->mutable_scroll_delta()); -} +LayerTreeHostCommon::ScrollbarsUpdateInfo::ScrollbarsUpdateInfo() + : layer_id(Layer::INVALID_ID), hidden(true) {} -void LayerTreeHostCommon::ScrollUpdateInfo::FromProtobuf( - const proto::ScrollUpdateInfo& proto) { - layer_id = proto.layer_id(); - scroll_delta = ProtoToVector2d(proto.scroll_delta()); -} +LayerTreeHostCommon::ScrollbarsUpdateInfo::ScrollbarsUpdateInfo(int layer_id, + bool hidden) + : layer_id(layer_id), hidden(hidden) {} -ScrollAndScaleSet::ScrollAndScaleSet() - : page_scale_delta(1.f), top_controls_delta(0.f) { +bool LayerTreeHostCommon::ScrollbarsUpdateInfo::operator==( + const LayerTreeHostCommon::ScrollbarsUpdateInfo& other) const { + return layer_id == other.layer_id && hidden == other.hidden; } -ScrollAndScaleSet::~ScrollAndScaleSet() {} +ReflectedMainFrameState::ReflectedMainFrameState() : page_scale_delta(1.0f) {} -bool ScrollAndScaleSet::EqualsForTesting(const ScrollAndScaleSet& other) const { - return scrolls == other.scrolls && - page_scale_delta == other.page_scale_delta && - elastic_overscroll_delta == other.elastic_overscroll_delta && - top_controls_delta == other.top_controls_delta; -} +ReflectedMainFrameState::~ReflectedMainFrameState() = default; -void ScrollAndScaleSet::ToProtobuf(proto::ScrollAndScaleSet* proto) const { - for (const auto& scroll : scrolls) - scroll.ToProtobuf(proto->add_scrolls()); - proto->set_page_scale_delta(page_scale_delta); - Vector2dFToProto(elastic_overscroll_delta, - proto->mutable_elastic_overscroll_delta()); - proto->set_top_controls_delta(top_controls_delta); +ScrollAndScaleSet::ScrollAndScaleSet() + : page_scale_delta(1.f), top_controls_delta(0.f) { } -void ScrollAndScaleSet::FromProtobuf(const proto::ScrollAndScaleSet& proto) { - DCHECK_EQ(scrolls.size(), 0u); - for (int i = 0; i < proto.scrolls_size(); ++i) { - scrolls.push_back(LayerTreeHostCommon::ScrollUpdateInfo()); - scrolls[i].FromProtobuf(proto.scrolls(i)); - } - page_scale_delta = proto.page_scale_delta(); - elastic_overscroll_delta = ProtoToVector2dF(proto.elastic_overscroll_delta()); - top_controls_delta = proto.top_controls_delta(); -} +ScrollAndScaleSet::~ScrollAndScaleSet() {} static inline void SetMaskLayersAreDrawnRenderSurfaceLayerListMembers( RenderSurfaceImpl* surface, @@ -240,15 +212,8 @@ static inline void ClearMaskLayersAreDrawnRenderSurfaceLayerListMembers( static inline void ClearIsDrawnRenderSurfaceLayerListMember( LayerImplList* layer_list, ScrollTree* scroll_tree) { - for (LayerImpl* layer : *layer_list) { - if (layer->is_drawn_render_surface_layer_list_member()) { - DCHECK_GT( - scroll_tree->Node(layer->scroll_tree_index())->num_drawn_descendants, - 0); - scroll_tree->Node(layer->scroll_tree_index())->num_drawn_descendants--; - } + for (LayerImpl* layer : *layer_list) layer->set_is_drawn_render_surface_layer_list_member(false); - } } static bool CdpPerfTracingEnabled() { @@ -321,33 +286,11 @@ enum PropertyTreeOption { DONT_BUILD_PROPERTY_TREES }; -static void ComputeLayerScrollsDrawnDescendants(LayerTreeImpl* layer_tree_impl, - ScrollTree* scroll_tree) { - for (int i = static_cast<int>(scroll_tree->size()) - 1; i > 0; --i) { - ScrollNode* node = scroll_tree->Node(i); - scroll_tree->parent(node)->num_drawn_descendants += - node->num_drawn_descendants; - } - for (LayerImpl* layer : *layer_tree_impl) { - bool scrolls_drawn_descendant = false; - if (layer->scrollable()) { - ScrollNode* node = scroll_tree->Node(layer->scroll_tree_index()); - if (node->num_drawn_descendants > 0) - scrolls_drawn_descendant = true; - } - layer->set_scrolls_drawn_descendant(scrolls_drawn_descendant); - } -} - static void ComputeInitialRenderSurfaceLayerList( LayerTreeImpl* layer_tree_impl, PropertyTrees* property_trees, LayerImplList* render_surface_layer_list, bool can_render_to_separate_surface) { - ScrollTree* scroll_tree = &property_trees->scroll_tree; - for (int i = 0; i < static_cast<int>(scroll_tree->size()); ++i) - scroll_tree->Node(i)->num_drawn_descendants = 0; - // Add all non-skipped surfaces to the initial render surface layer list. Add // all non-skipped layers to the layer list of their target surface, and // add their content rect to their target surface's accumulated content rect. @@ -359,13 +302,10 @@ static void ComputeInitialRenderSurfaceLayerList( } layer->set_is_drawn_render_surface_layer_list_member(false); - bool layer_is_drawn = - property_trees->effect_tree.Node(layer->effect_tree_index())->is_drawn; bool is_root = layer_tree_impl->IsRootLayer(layer); - bool skip_layer = - !is_root && draw_property_utils::LayerShouldBeSkipped( - layer, layer_is_drawn, property_trees->transform_tree, - property_trees->effect_tree); + bool skip_layer = !is_root && draw_property_utils::LayerShouldBeSkipped( + layer, property_trees->transform_tree, + property_trees->effect_tree); if (skip_layer) continue; @@ -414,13 +354,14 @@ static void ComputeInitialRenderSurfaceLayerList( surface->render_target()->nearest_occlusion_immune_ancestor()); } } + bool layer_is_drawn = + property_trees->effect_tree.Node(layer->effect_tree_index())->is_drawn; bool layer_should_be_drawn = draw_property_utils::LayerNeedsUpdate( - layer, layer_is_drawn, property_trees->transform_tree); + layer, layer_is_drawn, property_trees); if (!layer_should_be_drawn) continue; layer->set_is_drawn_render_surface_layer_list_member(true); - scroll_tree->Node(layer->scroll_tree_index())->num_drawn_descendants++; layer->render_target()->layer_list().push_back(layer); // The layer contributes its drawable content rect to its render target. @@ -516,9 +457,6 @@ static void CalculateRenderSurfaceLayerList( ComputeListOfNonEmptySurfaces(layer_tree_impl, property_trees, &initial_render_surface_list, render_surface_layer_list); - - ComputeLayerScrollsDrawnDescendants(layer_tree_impl, - &property_trees->scroll_tree); } void CalculateDrawPropertiesInternal( @@ -623,9 +561,6 @@ void CalculateDrawPropertiesInternal( if (inputs->verify_visible_rect_calculations) draw_property_utils::VerifyVisibleRectsCalculations(visible_layer_list, inputs->property_trees); - if (inputs->verify_transform_tree_calculations) - draw_property_utils::VerifyTransformTreeCalculations( - visible_layer_list, inputs->property_trees); if (should_measure_property_tree_performance) { TRACE_EVENT_END0(TRACE_DISABLED_BY_DEFAULT("cc.debug.cdp-perf"), @@ -655,8 +590,7 @@ void LayerTreeHostCommon::CalculateDrawPropertiesForTesting( draw_property_utils::UpdatePropertyTrees(property_trees, can_render_to_separate_surface); draw_property_utils::FindLayersThatNeedUpdates( - inputs->root_layer->GetLayerTree(), property_trees->transform_tree, - property_trees->effect_tree, &update_layer_list); + inputs->root_layer->GetLayerTree(), property_trees, &update_layer_list); } void LayerTreeHostCommon::CalculateDrawProperties( diff --git a/chromium/cc/trees/layer_tree_host_common.h b/chromium/cc/trees/layer_tree_host_common.h index 6945415d429..0b7034c2434 100644 --- a/chromium/cc/trees/layer_tree_host_common.h +++ b/chromium/cc/trees/layer_tree_host_common.h @@ -26,11 +26,6 @@ namespace cc { -namespace proto { -class ScrollUpdateInfo; -class ScrollAndScaleSet; -} - class LayerImpl; class Layer; class SwapPromise; @@ -81,7 +76,6 @@ class CC_EXPORT LayerTreeHostCommon { bool can_adjust_raster_scales, bool verify_clip_tree_calculations, bool verify_visible_rect_calculations, - bool verify_transform_tree_calculations, LayerImplList* render_surface_layer_list, PropertyTrees* property_trees); @@ -100,7 +94,6 @@ class CC_EXPORT LayerTreeHostCommon { bool can_adjust_raster_scales; bool verify_clip_tree_calculations; bool verify_visible_rect_calculations; - bool verify_transform_tree_calculations; LayerImplList* render_surface_layer_list; PropertyTrees* property_trees; }; @@ -144,18 +137,45 @@ class CC_EXPORT LayerTreeHostCommon { struct CC_EXPORT ScrollUpdateInfo { int layer_id; // TODO(miletus): Use ScrollOffset once LayerTreeHost/Blink fully supports - // franctional scroll offset. + // fractional scroll offset. gfx::Vector2d scroll_delta; ScrollUpdateInfo(); bool operator==(const ScrollUpdateInfo& other) const; + }; - void ToProtobuf(proto::ScrollUpdateInfo* proto) const; - void FromProtobuf(const proto::ScrollUpdateInfo& proto); + // Used to communicate scrollbar visibility from Impl thread to Blink. + // Scrollbar input is handled by Blink but the compositor thread animates + // opacity on scrollbars to fade them out when they're overlay. Blink needs + // to be told when they're faded out so it can stop handling input for + // invisible scrollbars. + struct CC_EXPORT ScrollbarsUpdateInfo { + int layer_id; + bool hidden; + + ScrollbarsUpdateInfo(); + ScrollbarsUpdateInfo(int layer_id, bool hidden); + + bool operator==(const ScrollbarsUpdateInfo& other) const; }; }; +// A container for the state that was reported to the main thread during +// BeginMainFrame, but could not be applied/resolved on the main thread. +struct CC_EXPORT ReflectedMainFrameState { + struct ScrollUpdate { + int layer_id = Layer::LayerIdLabels::INVALID_ID; + gfx::Vector2dF scroll_delta; + }; + + ReflectedMainFrameState(); + ~ReflectedMainFrameState(); + + std::vector<ScrollUpdate> scrolls; + float page_scale_delta; +}; + struct CC_EXPORT ScrollAndScaleSet { ScrollAndScaleSet(); ~ScrollAndScaleSet(); @@ -170,12 +190,9 @@ struct CC_EXPORT ScrollAndScaleSet { float page_scale_delta; gfx::Vector2dF elastic_overscroll_delta; float top_controls_delta; + std::vector<LayerTreeHostCommon::ScrollbarsUpdateInfo> scrollbars; std::vector<std::unique_ptr<SwapPromise>> swap_promises; - bool EqualsForTesting(const ScrollAndScaleSet& other) const; - void ToProtobuf(proto::ScrollAndScaleSet* proto) const; - void FromProtobuf(const proto::ScrollAndScaleSet& proto); - private: DISALLOW_COPY_AND_ASSIGN(ScrollAndScaleSet); }; diff --git a/chromium/cc/trees/layer_tree_host_common_perftest.cc b/chromium/cc/trees/layer_tree_host_common_perftest.cc index a6c0d98baf9..23f7c4fbcb2 100644 --- a/chromium/cc/trees/layer_tree_host_common_perftest.cc +++ b/chromium/cc/trees/layer_tree_host_common_perftest.cc @@ -117,7 +117,6 @@ class CalcDrawPropsTest : public LayerTreeHostCommonPerfTest { host_impl->settings().layer_transforms_should_scale_layer_contents, false, // do not verify_clip_tree_calculation for perf tests false, // do not verify_visible_rect_calculation for perf tests - false, // do not verify_transform_tree_calculation for perf tests &update_list, active_tree->property_trees()); LayerTreeHostCommon::CalculateDrawProperties(&inputs); } diff --git a/chromium/cc/trees/layer_tree_host_common_unittest.cc b/chromium/cc/trees/layer_tree_host_common_unittest.cc index b677cd08b14..8b7a4fcc195 100644 --- a/chromium/cc/trees/layer_tree_host_common_unittest.cc +++ b/chromium/cc/trees/layer_tree_host_common_unittest.cc @@ -28,8 +28,6 @@ #include "cc/layers/texture_layer_impl.h" #include "cc/output/copy_output_request.h" #include "cc/output/copy_output_result.h" -#include "cc/proto/begin_main_frame_and_commit_state.pb.h" -#include "cc/proto/gfx_conversions.h" #include "cc/test/animation_test_common.h" #include "cc/test/fake_compositor_frame_sink.h" #include "cc/test/fake_content_layer_client.h" @@ -62,7 +60,6 @@ namespace { class VerifyTreeCalcsLayerTreeSettings : public LayerTreeSettings { public: VerifyTreeCalcsLayerTreeSettings() { - verify_transform_tree_calculations = true; verify_clip_tree_calculations = true; } }; @@ -102,7 +99,9 @@ class LayerTreeHostCommonTestBase : public LayerTestCommon::LayerImplTest { void ExecuteCalculateDrawProperties(Layer* root_layer, float device_scale_factor, float page_scale_factor, - Layer* page_scale_layer) { + Layer* page_scale_layer, + Layer* inner_viewport_scroll_layer, + Layer* outer_viewport_scroll_layer) { PropertyTreeBuilder::PreCalculateMetaInformation(root_layer); EXPECT_TRUE(page_scale_layer || (page_scale_factor == 1.f)); @@ -118,6 +117,8 @@ class LayerTreeHostCommonTestBase : public LayerTestCommon::LayerImplTest { inputs.device_scale_factor = device_scale_factor; inputs.page_scale_factor = page_scale_factor; inputs.page_scale_layer = page_scale_layer; + inputs.inner_viewport_scroll_layer = inner_viewport_scroll_layer; + inputs.outer_viewport_scroll_layer = outer_viewport_scroll_layer; LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); } @@ -126,6 +127,8 @@ class LayerTreeHostCommonTestBase : public LayerTestCommon::LayerImplTest { float device_scale_factor, float page_scale_factor, LayerImpl* page_scale_layer, + LayerImpl* inner_viewport_scroll_layer, + LayerImpl* outer_viewport_scroll_layer, bool skip_verify_visible_rect_calculations = false) { if (device_scale_factor != root_layer->layer_tree_impl()->device_scale_factor()) @@ -150,6 +153,8 @@ class LayerTreeHostCommonTestBase : public LayerTestCommon::LayerImplTest { inputs.device_scale_factor = device_scale_factor; inputs.page_scale_factor = page_scale_factor; inputs.page_scale_layer = page_scale_layer; + inputs.inner_viewport_scroll_layer = inner_viewport_scroll_layer; + inputs.outer_viewport_scroll_layer = outer_viewport_scroll_layer; inputs.can_adjust_raster_scales = true; if (skip_verify_visible_rect_calculations) inputs.verify_visible_rect_calculations = false; @@ -160,16 +165,22 @@ class LayerTreeHostCommonTestBase : public LayerTestCommon::LayerImplTest { template <class LayerType> void ExecuteCalculateDrawProperties(LayerType* root_layer) { LayerType* page_scale_application_layer = nullptr; - ExecuteCalculateDrawProperties(root_layer, 1.f, 1.f, - page_scale_application_layer); + LayerType* inner_viewport_scroll_layer = nullptr; + LayerType* outer_viewport_scroll_layer = nullptr; + ExecuteCalculateDrawProperties( + root_layer, 1.f, 1.f, page_scale_application_layer, + inner_viewport_scroll_layer, outer_viewport_scroll_layer); } template <class LayerType> void ExecuteCalculateDrawProperties(LayerType* root_layer, float device_scale_factor) { LayerType* page_scale_application_layer = nullptr; - ExecuteCalculateDrawProperties(root_layer, device_scale_factor, 1.f, - page_scale_application_layer); + LayerType* inner_viewport_scroll_layer = nullptr; + LayerType* outer_viewport_scroll_layer = nullptr; + ExecuteCalculateDrawProperties( + root_layer, device_scale_factor, 1.f, page_scale_application_layer, + inner_viewport_scroll_layer, outer_viewport_scroll_layer); } const LayerList* GetUpdateLayerList() { return &update_layer_list_; } @@ -206,8 +217,7 @@ class LayerTreeHostCommonTestBase : public LayerTestCommon::LayerImplTest { draw_property_utils::UpdatePropertyTrees(property_trees, can_render_to_separate_surface); draw_property_utils::FindLayersThatNeedUpdates( - root_layer->GetLayerTree(), property_trees->transform_tree, - property_trees->effect_tree, &update_layer_list_); + root_layer->GetLayerTree(), property_trees, &update_layer_list_); } void ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList( @@ -515,10 +525,8 @@ TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) { const float kDeviceScale = 1.666f; FakeImplTaskRunnerProvider task_runner_provider; - TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; - FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, - &task_graph_runner); + FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); std::unique_ptr<LayerImpl> sublayer_scoped_ptr( LayerImpl::Create(host_impl.active_tree(), 1)); @@ -558,7 +566,8 @@ TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) { host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, - scroll_layer->test_properties()->parent); + scroll_layer->test_properties()->parent, + nullptr, nullptr); gfx::Transform expected_transform; gfx::PointF sub_layer_screen_position = kScrollLayerPosition - kScrollDelta; expected_transform.Translate(MathUtil::Round(sub_layer_screen_position.x() * @@ -579,7 +588,8 @@ TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) { scroll_layer->test_properties()->transform = arbitrary_translate; root_layer->layer_tree_impl()->property_trees()->needs_rebuild = true; ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, - scroll_layer->test_properties()->parent); + scroll_layer->test_properties()->parent, + nullptr, nullptr); expected_transform.MakeIdentity(); expected_transform.Translate( MathUtil::Round(kTranslateX * page_scale * kDeviceScale + @@ -601,7 +611,8 @@ TEST_F(LayerTreeHostCommonTest, TransformsAboutScrollOffset) { root_layer->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale); EXPECT_FALSE(root_layer->layer_tree_impl()->property_trees()->needs_rebuild); ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, - scroll_layer->test_properties()->parent); + scroll_layer->test_properties()->parent, + nullptr, nullptr); expected_transform.MakeIdentity(); expected_transform.Translate( @@ -1110,12 +1121,15 @@ TEST_F(LayerTreeHostCommonTest, LayerFullyContainedWithinClipInTargetSpace) { float device_scale_factor = 1.f; float page_scale_factor = 1.f; LayerImpl* page_scale_layer = nullptr; + LayerImpl* inner_viewport_scroll_layer = nullptr; + LayerImpl* outer_viewport_scroll_layer = nullptr; // Visible rects computed by combining clips in target space and root space // don't match because of rotation transforms. So, we skip // verify_visible_rect_calculations. bool skip_verify_visible_rect_calculations = true; ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, - page_scale_layer, + page_scale_layer, inner_viewport_scroll_layer, + outer_viewport_scroll_layer, skip_verify_visible_rect_calculations); // Mapping grand_child's bounds to target space produces a non-empty rect @@ -1193,6 +1207,8 @@ TEST_F(LayerTreeHostCommonTest, RenderSurfaceWithSublayerScale) { } TEST_F(LayerTreeHostCommonTest, TransformAboveRootLayer) { + // Transformations applied at the root of the tree should be forwarded + // to child layers instead of applied to the root RenderSurface. LayerImpl* root = root_layer_for_testing(); LayerImpl* child = AddChild<LayerImpl>(root); @@ -3453,12 +3469,10 @@ TEST_F(LayerTreeHostCommonTest, TEST_F(LayerTreeHostCommonTest, OcclusionBySiblingOfTarget) { FakeImplTaskRunnerProvider task_runner_provider; - TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; std::unique_ptr<CompositorFrameSink> compositor_frame_sink = FakeCompositorFrameSink::Create3d(); - FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, - &task_graph_runner); + FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); std::unique_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); @@ -3528,15 +3542,54 @@ TEST_F(LayerTreeHostCommonTest, OcclusionBySiblingOfTarget) { EXPECT_TRUE(expected_occlusion.IsEqual(actual_occlusion)); } +TEST_F(LayerTreeHostCommonTest, TextureLayerSnapping) { + FakeImplTaskRunnerProvider task_runner_provider; + TestTaskGraphRunner task_graph_runner; + std::unique_ptr<CompositorFrameSink> compositor_frame_sink = + FakeCompositorFrameSink::Create3d(); + FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); + + std::unique_ptr<LayerImpl> root = + LayerImpl::Create(host_impl.active_tree(), 1); + std::unique_ptr<TextureLayerImpl> child = + TextureLayerImpl::Create(host_impl.active_tree(), 2); + + LayerImpl* child_ptr = child.get(); + + root->SetBounds(gfx::Size(100, 100)); + child->SetBounds(gfx::Size(100, 100)); + child->SetDrawsContent(true); + gfx::Transform fractional_translate; + fractional_translate.Translate(10.5f, 20.3f); + child->test_properties()->transform = fractional_translate; + + host_impl.SetViewportSize(root->bounds()); + + root->test_properties()->AddChild(std::move(child)); + host_impl.active_tree()->SetRootLayerForTesting(std::move(root)); + host_impl.SetVisible(true); + host_impl.InitializeRenderer(compositor_frame_sink.get()); + host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting(); + bool update_lcd_text = false; + host_impl.active_tree()->UpdateDrawProperties(update_lcd_text); + + EXPECT_NE(child_ptr->ScreenSpaceTransform(), fractional_translate); + fractional_translate.RoundTranslationComponents(); + EXPECT_TRANSFORMATION_MATRIX_EQ(child_ptr->ScreenSpaceTransform(), + fractional_translate); + gfx::RectF layer_bounds_in_screen_space = + MathUtil::MapClippedRect(child_ptr->ScreenSpaceTransform(), + gfx::RectF(gfx::SizeF(child_ptr->bounds()))); + EXPECT_EQ(layer_bounds_in_screen_space, gfx::RectF(11.f, 20.f, 100.f, 100.f)); +} + TEST_F(LayerTreeHostCommonTest, OcclusionForLayerWithUninvertibleDrawTransform) { FakeImplTaskRunnerProvider task_runner_provider; - TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; std::unique_ptr<CompositorFrameSink> compositor_frame_sink = FakeCompositorFrameSink::Create3d(); - FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, - &task_graph_runner); + FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); std::unique_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); @@ -4158,13 +4211,11 @@ TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithoutPreserves3d) { EXPECT_FALSE(front_facing_child_of_back_facing_surface->has_render_surface()); EXPECT_FALSE(back_facing_child_of_back_facing_surface->has_render_surface()); - EXPECT_EQ(4u, update_layer_list_impl()->size()); + EXPECT_EQ(3u, update_layer_list_impl()->size()); EXPECT_TRUE(UpdateLayerListImplContains(front_facing_child->id())); EXPECT_TRUE(UpdateLayerListImplContains(front_facing_surface->id())); EXPECT_TRUE(UpdateLayerListImplContains( front_facing_child_of_front_facing_surface->id())); - EXPECT_TRUE(UpdateLayerListImplContains( - front_facing_child_of_back_facing_surface->id())); } TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) { @@ -4527,7 +4578,7 @@ TEST_F(LayerTreeHostCommonScalingTest, SurfaceLayerTransformsInHighDPI) { root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting(); root->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale_factor); ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, - root); + root, nullptr, nullptr); EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor, parent->GetIdealContentsScale()); @@ -4613,7 +4664,7 @@ TEST_F(LayerTreeHostCommonScalingTest, SmallIdealScale) { { ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, - root); + root, nullptr, nullptr); // The ideal scale is able to go below 1. float expected_ideal_scale = @@ -4801,10 +4852,9 @@ TEST_F(LayerTreeHostCommonTest, TransparentChildRenderSurfaceCreation) { TEST_F(LayerTreeHostCommonTest, OpacityAnimatingOnPendingTree) { FakeImplTaskRunnerProvider task_runner_provider; - TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; FakeLayerTreeHostImpl host_impl(host()->GetSettings(), &task_runner_provider, - &shared_bitmap_manager, &task_graph_runner); + &task_graph_runner); host_impl.CreatePendingTree(); std::unique_ptr<LayerImpl> root = LayerImpl::Create(host_impl.pending_tree(), 1); @@ -4906,7 +4956,6 @@ class LCDTextTest : public LayerTreeHostCommonTestBase, : LayerTreeHostCommonTestBase(LCDTextTestLayerTreeSettings()), host_impl_(LCDTextTestLayerTreeSettings(), &task_runner_provider_, - &shared_bitmap_manager_, &task_graph_runner_) {} scoped_refptr<AnimationTimeline> timeline() { return timeline_; } @@ -4965,7 +5014,6 @@ class LCDTextTest : public LayerTreeHostCommonTestBase, bool layers_always_allowed_lcd_text_; FakeImplTaskRunnerProvider task_runner_provider_; - TestSharedBitmapManager shared_bitmap_manager_; TestTaskGraphRunner task_graph_runner_; FakeLayerTreeHostImpl host_impl_; scoped_refptr<AnimationTimeline> timeline_; @@ -4980,7 +5028,7 @@ TEST_P(LCDTextTest, CanUseLCDText) { bool expect_not_lcd_text = layers_always_allowed_lcd_text_; // Case 1: Identity transform. - ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); + ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); @@ -4990,7 +5038,7 @@ TEST_P(LCDTextTest, CanUseLCDText) { integral_translation.Translate(1.0, 2.0); child_->test_properties()->transform = integral_translation; child_->layer_tree_impl()->property_trees()->needs_rebuild = true; - ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); + ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); @@ -5000,7 +5048,7 @@ TEST_P(LCDTextTest, CanUseLCDText) { non_integral_translation.Translate(1.5, 2.5); child_->test_properties()->transform = non_integral_translation; child_->layer_tree_impl()->property_trees()->needs_rebuild = true; - ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); + ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); @@ -5010,7 +5058,7 @@ TEST_P(LCDTextTest, CanUseLCDText) { rotation.Rotate(10.0); child_->test_properties()->transform = rotation; child_->layer_tree_impl()->property_trees()->needs_rebuild = true; - ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); + ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); @@ -5020,7 +5068,7 @@ TEST_P(LCDTextTest, CanUseLCDText) { scale.Scale(2.0, 2.0); child_->test_properties()->transform = scale; child_->layer_tree_impl()->property_trees()->needs_rebuild = true; - ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); + ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); @@ -5030,7 +5078,7 @@ TEST_P(LCDTextTest, CanUseLCDText) { skew.Skew(10.0, 0.0); child_->test_properties()->transform = skew; child_->layer_tree_impl()->property_trees()->needs_rebuild = true; - ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); + ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); @@ -5039,7 +5087,7 @@ TEST_P(LCDTextTest, CanUseLCDText) { child_->test_properties()->transform = gfx::Transform(); child_->layer_tree_impl()->property_trees()->needs_rebuild = true; child_->test_properties()->opacity = 0.5f; - ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); + ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); EXPECT_EQ(expect_not_lcd_text, grand_child_->CanUseLCDText()); @@ -5048,21 +5096,21 @@ TEST_P(LCDTextTest, CanUseLCDText) { child_->test_properties()->transform = gfx::Transform(); child_->layer_tree_impl()->property_trees()->needs_rebuild = true; child_->test_properties()->opacity = 1.f; - ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); + ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); // Case 9: Non-opaque content. child_->SetContentsOpaque(false); - ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); + ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); // Case 10: Sanity check: restore content opaqueness. child_->SetContentsOpaque(true); - ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); + ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); @@ -5073,7 +5121,7 @@ TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) { bool expect_not_lcd_text = layers_always_allowed_lcd_text_; // Sanity check: Make sure can_use_lcd_text_ is set on each node. - ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); + ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); @@ -5086,7 +5134,7 @@ TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) { AddOpacityTransitionToElementWithPlayer(child_->element_id(), timeline(), 10.0, 0.9f, 0.1f, false); - ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); + ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); // Text LCD should be adjusted while animation is active. EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); @@ -5098,7 +5146,7 @@ TEST_P(LCDTextTest, CanUseLCDTextWithAnimationContentsOpaque) { bool expect_not_lcd_text = layers_always_allowed_lcd_text_; // Sanity check: Make sure can_use_lcd_text_ is set on each node. - ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); + ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); EXPECT_EQ(expect_lcd_text, child_->CanUseLCDText()); EXPECT_EQ(expect_lcd_text, grand_child_->CanUseLCDText()); @@ -5108,7 +5156,7 @@ TEST_P(LCDTextTest, CanUseLCDTextWithAnimationContentsOpaque) { child_->SetContentsOpaque(false); AddOpacityTransitionToElementWithPlayer(child_->element_id(), timeline(), 10.0, 0.9f, 0.1f, false); - ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr); + ExecuteCalculateDrawProperties(root_, 1.f, 1.f, nullptr, nullptr, nullptr); // LCD text should be disabled for non-opaque layers even during animations. EXPECT_EQ(expect_lcd_text, root_->CanUseLCDText()); EXPECT_EQ(expect_not_lcd_text, child_->CanUseLCDText()); @@ -5123,10 +5171,8 @@ INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) { FakeImplTaskRunnerProvider task_runner_provider; - TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; - FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, - &task_graph_runner); + FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); host_impl.CreatePendingTree(); std::unique_ptr<LayerImpl> root = @@ -5167,10 +5213,8 @@ TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayerImpl) { TEST_F(LayerTreeHostCommonTest, SubtreeHidden_TwoLayersImpl) { FakeImplTaskRunnerProvider task_runner_provider; - TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; - FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, - &task_graph_runner); + FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); host_impl.CreatePendingTree(); std::unique_ptr<LayerImpl> root = @@ -5211,10 +5255,8 @@ void EmptyCopyOutputCallback(std::unique_ptr<CopyOutputResult> result) {} TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) { FakeImplTaskRunnerProvider task_runner_provider; - TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; - FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, - &task_graph_runner); + FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); host_impl.CreatePendingTree(); std::unique_ptr<LayerImpl> root = @@ -5357,10 +5399,8 @@ TEST_F(LayerTreeHostCommonTest, SubtreeHiddenWithCopyRequest) { TEST_F(LayerTreeHostCommonTest, ClippedOutCopyRequest) { FakeImplTaskRunnerProvider task_runner_provider; - TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; - FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, - &task_graph_runner); + FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); host_impl.CreatePendingTree(); std::unique_ptr<LayerImpl> root = @@ -5867,10 +5907,8 @@ TEST_F(LayerTreeHostCommonTest, TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) { FakeImplTaskRunnerProvider task_runner_provider; - TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; - FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, - &task_graph_runner); + FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); std::unique_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 12345); @@ -5972,38 +6010,36 @@ TEST_F(LayerTreeHostCommonTest, CanRenderToSeparateSurface) { TEST_F(LayerTreeHostCommonTest, DoNotIncludeBackfaceInvisibleSurfaces) { LayerImpl* root = root_layer_for_testing(); LayerImpl* back_facing = AddChild<LayerImpl>(root); + LayerImpl* render_surface1 = AddChild<LayerImpl>(back_facing); - LayerImpl* render_surface2 = AddChild<LayerImpl>(back_facing); LayerImpl* child1 = AddChild<LayerImpl>(render_surface1); + + LayerImpl* flattener = AddChild<LayerImpl>(back_facing); + LayerImpl* render_surface2 = AddChild<LayerImpl>(flattener); LayerImpl* child2 = AddChild<LayerImpl>(render_surface2); child1->SetDrawsContent(true); child2->SetDrawsContent(true); root->SetBounds(gfx::Size(50, 50)); - root->Set3dSortingContextId(1); - root->test_properties()->should_flatten_transform = false; back_facing->SetBounds(gfx::Size(50, 50)); - back_facing->Set3dSortingContextId(1); back_facing->test_properties()->should_flatten_transform = false; + render_surface1->SetBounds(gfx::Size(30, 30)); - render_surface1->Set3dSortingContextId(1); render_surface1->test_properties()->should_flatten_transform = false; render_surface1->test_properties()->force_render_surface = true; render_surface1->test_properties()->double_sided = false; + child1->SetBounds(gfx::Size(20, 20)); + + flattener->SetBounds(gfx::Size(30, 30)); render_surface2->SetBounds(gfx::Size(30, 30)); - // Different context from the rest. - render_surface2->Set3dSortingContextId(2); render_surface2->test_properties()->should_flatten_transform = false; render_surface2->test_properties()->force_render_surface = true; render_surface2->test_properties()->double_sided = false; - child1->SetBounds(gfx::Size(20, 20)); child2->SetBounds(gfx::Size(20, 20)); ExecuteCalculateDrawProperties(root); - EXPECT_EQ(render_surface1->sorting_context_id(), root->sorting_context_id()); - EXPECT_NE(render_surface2->sorting_context_id(), root->sorting_context_id()); EXPECT_EQ(3u, render_surface_layer_list_impl()->size()); EXPECT_EQ(2u, render_surface_layer_list_impl() ->at(0) @@ -6567,10 +6603,8 @@ TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) { // + fixed // FakeImplTaskRunnerProvider task_runner_provider; - TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; - FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, - &task_graph_runner); + FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); host_impl.CreatePendingTree(); std::unique_ptr<LayerImpl> root_ptr = LayerImpl::Create(host_impl.active_tree(), 1); @@ -6809,6 +6843,7 @@ TEST_F(LayerTreeHostCommonTest, StickyPositionTop) { sticky_position.is_sticky = true; sticky_position.is_anchored_top = true; sticky_position.top_offset = 10.0f; + sticky_position.parent_relative_sticky_box_offset = gfx::Point(10, 20); sticky_position.scroll_container_relative_sticky_box_rect = gfx::Rect(10, 20, 10, 10); sticky_position.scroll_container_relative_containing_block_rect = @@ -6865,6 +6900,126 @@ TEST_F(LayerTreeHostCommonTest, StickyPositionTop) { sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); } +TEST_F(LayerTreeHostCommonTest, StickyPositionTopScrollParent) { + scoped_refptr<Layer> root = Layer::Create(); + scoped_refptr<Layer> container = Layer::Create(); + scoped_refptr<Layer> scroller = Layer::Create(); + scoped_refptr<Layer> sticky_pos = Layer::Create(); + root->AddChild(container); + container->AddChild(scroller); + root->AddChild(sticky_pos); + sticky_pos->SetScrollParent(scroller.get()); + host()->SetRootLayer(root); + scroller->SetScrollClipLayerId(container->id()); + + LayerStickyPositionConstraint sticky_position; + sticky_position.is_sticky = true; + sticky_position.is_anchored_top = true; + sticky_position.top_offset = 10.0f; + sticky_position.parent_relative_sticky_box_offset = gfx::Point(10, 20); + sticky_position.scroll_container_relative_sticky_box_rect = + gfx::Rect(10, 20, 10, 10); + sticky_position.scroll_container_relative_containing_block_rect = + gfx::Rect(0, 0, 50, 50); + sticky_pos->SetStickyPositionConstraint(sticky_position); + + root->SetBounds(gfx::Size(200, 200)); + container->SetBounds(gfx::Size(100, 100)); + container->SetPosition(gfx::PointF(50, 50)); + scroller->SetBounds(gfx::Size(1000, 1000)); + sticky_pos->SetBounds(gfx::Size(10, 10)); + sticky_pos->SetPosition(gfx::PointF(60, 70)); + + ExecuteCalculateDrawProperties(root.get()); + host()->host_impl()->CreatePendingTree(); + host()->CommitAndCreatePendingTree(); + host()->host_impl()->ActivateSyncTree(); + LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); + + LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); + LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); + LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); + + ExecuteCalculateDrawProperties(root_impl); + EXPECT_VECTOR2DF_EQ( + gfx::Vector2dF(60.f, 70.f), + sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); + + // Scroll less than sticking point, sticky element should move with scroll as + // we haven't gotten to the initial sticky item location yet. + SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(5.f, 5.f)); + ExecuteCalculateDrawProperties(root_impl); + EXPECT_VECTOR2DF_EQ( + gfx::Vector2dF(55.f, 65.f), + sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); + + // Scroll past the sticking point, the Y coordinate should now be clamped. + SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 15.f)); + ExecuteCalculateDrawProperties(root_impl); + EXPECT_VECTOR2DF_EQ( + gfx::Vector2dF(45.f, 60.f), + sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); + SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 25.f)); + ExecuteCalculateDrawProperties(root_impl); + EXPECT_VECTOR2DF_EQ( + gfx::Vector2dF(45.f, 60.f), + sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); + + // Scroll past the end of the sticky container (note: this element does not + // have its own layer as it does not need to be composited). + SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(15.f, 50.f)); + ExecuteCalculateDrawProperties(root_impl); + EXPECT_VECTOR2DF_EQ( + gfx::Vector2dF(45.f, 40.f), + sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); +} + +TEST_F(LayerTreeHostCommonTest, StickyPositionSubpixelScroll) { + scoped_refptr<Layer> root = Layer::Create(); + scoped_refptr<Layer> container = Layer::Create(); + scoped_refptr<Layer> scroller = Layer::Create(); + scoped_refptr<Layer> sticky_pos = Layer::Create(); + root->AddChild(container); + container->AddChild(scroller); + scroller->AddChild(sticky_pos); + host()->SetRootLayer(root); + scroller->SetScrollClipLayerId(container->id()); + + LayerStickyPositionConstraint sticky_position; + sticky_position.is_sticky = true; + sticky_position.is_anchored_bottom = true; + sticky_position.bottom_offset = 10.0f; + sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 200); + sticky_position.scroll_container_relative_sticky_box_rect = + gfx::Rect(0, 200, 10, 10); + sticky_position.scroll_container_relative_containing_block_rect = + gfx::Rect(0, 0, 100, 500); + sticky_pos->SetStickyPositionConstraint(sticky_position); + + root->SetBounds(gfx::Size(100, 100)); + container->SetBounds(gfx::Size(100, 100)); + scroller->SetBounds(gfx::Size(100, 1000)); + sticky_pos->SetBounds(gfx::Size(10, 10)); + sticky_pos->SetPosition(gfx::PointF(0, 200)); + + ExecuteCalculateDrawProperties(root.get()); + host()->host_impl()->CreatePendingTree(); + host()->CommitAndCreatePendingTree(); + host()->host_impl()->ActivateSyncTree(); + LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); + + LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); + LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); + LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); + + ExecuteCalculateDrawProperties(root_impl); + SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 0.8f)); + ExecuteCalculateDrawProperties(root_impl); + EXPECT_VECTOR2DF_EQ( + gfx::Vector2dF(0.f, 80.f), + sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); +} + TEST_F(LayerTreeHostCommonTest, StickyPositionBottom) { scoped_refptr<Layer> root = Layer::Create(); scoped_refptr<Layer> container = Layer::Create(); @@ -6880,6 +7035,7 @@ TEST_F(LayerTreeHostCommonTest, StickyPositionBottom) { sticky_position.is_sticky = true; sticky_position.is_anchored_bottom = true; sticky_position.bottom_offset = 10.0f; + sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 150); sticky_position.scroll_container_relative_sticky_box_rect = gfx::Rect(0, 150, 10, 10); sticky_position.scroll_container_relative_containing_block_rect = @@ -6934,6 +7090,155 @@ TEST_F(LayerTreeHostCommonTest, StickyPositionBottom) { sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); } +TEST_F(LayerTreeHostCommonTest, StickyPositionBottomInnerViewportDelta) { + scoped_refptr<Layer> root = Layer::Create(); + scoped_refptr<Layer> scroller = Layer::Create(); + scoped_refptr<Layer> sticky_pos = Layer::Create(); + root->AddChild(scroller); + scroller->AddChild(sticky_pos); + host()->SetRootLayer(root); + scroller->SetScrollClipLayerId(root->id()); + host()->GetLayerTree()->RegisterViewportLayers(nullptr, root, scroller, + nullptr); + + LayerStickyPositionConstraint sticky_position; + sticky_position.is_sticky = true; + sticky_position.is_anchored_bottom = true; + sticky_position.bottom_offset = 10.0f; + sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 70); + sticky_position.scroll_container_relative_sticky_box_rect = + gfx::Rect(0, 70, 10, 10); + sticky_position.scroll_container_relative_containing_block_rect = + gfx::Rect(0, 60, 100, 100); + sticky_pos->SetStickyPositionConstraint(sticky_position); + + root->SetBounds(gfx::Size(100, 100)); + scroller->SetBounds(gfx::Size(100, 1000)); + sticky_pos->SetBounds(gfx::Size(10, 10)); + sticky_pos->SetPosition(gfx::PointF(0, 70)); + + ExecuteCalculateDrawProperties(root.get(), 1.f, 1.f, root.get(), + scroller.get(), nullptr); + host()->CommitAndCreateLayerImplTree(); + LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); + LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); + ASSERT_EQ(scroller->id(), layer_tree_impl->InnerViewportScrollLayer()->id()); + + LayerImpl* inner_scroll = layer_tree_impl->InnerViewportScrollLayer(); + LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); + + // Initially the sticky element is moved to the bottom of the container. + EXPECT_VECTOR2DF_EQ( + gfx::Vector2dF(0.f, 70.f), + sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); + + // We start to hide the toolbar, but not far enough that the sticky element + // should be moved up yet. + root_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -10.f)); + ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, + nullptr); + EXPECT_VECTOR2DF_EQ( + gfx::Vector2dF(0.f, 70.f), + sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); + + // On hiding more of the toolbar the sticky element starts to stick. + root_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -20.f)); + ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, + nullptr); + EXPECT_VECTOR2DF_EQ( + gfx::Vector2dF(0.f, 60.f), + sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); + + // On hiding more the sticky element stops moving as it has reached its + // limit. + root_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -30.f)); + ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, + nullptr); + EXPECT_VECTOR2DF_EQ( + gfx::Vector2dF(0.f, 60.f), + sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); +} + +TEST_F(LayerTreeHostCommonTest, StickyPositionBottomOuterViewportDelta) { + scoped_refptr<Layer> root = Layer::Create(); + scoped_refptr<Layer> scroller = Layer::Create(); + scoped_refptr<Layer> outer_clip = Layer::Create(); + scoped_refptr<Layer> outer_viewport = Layer::Create(); + scoped_refptr<Layer> sticky_pos = Layer::Create(); + root->AddChild(scroller); + scroller->AddChild(outer_clip); + outer_clip->AddChild(outer_viewport); + outer_viewport->AddChild(sticky_pos); + host()->SetRootLayer(root); + scroller->SetScrollClipLayerId(root->id()); + outer_viewport->SetScrollClipLayerId(outer_clip->id()); + host()->GetLayerTree()->RegisterViewportLayers(nullptr, root, scroller, + outer_viewport); + + LayerStickyPositionConstraint sticky_position; + sticky_position.is_sticky = true; + sticky_position.is_anchored_bottom = true; + sticky_position.bottom_offset = 10.0f; + sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 70); + sticky_position.scroll_container_relative_sticky_box_rect = + gfx::Rect(0, 70, 10, 10); + sticky_position.scroll_container_relative_containing_block_rect = + gfx::Rect(0, 60, 100, 100); + sticky_pos->SetStickyPositionConstraint(sticky_position); + + root->SetBounds(gfx::Size(100, 100)); + scroller->SetBounds(gfx::Size(100, 1000)); + outer_clip->SetBounds(gfx::Size(100, 100)); + sticky_pos->SetBounds(gfx::Size(10, 10)); + sticky_pos->SetPosition(gfx::PointF(0, 70)); + + ExecuteCalculateDrawProperties(root.get(), 1.f, 1.f, root.get(), + scroller.get(), outer_viewport.get()); + host()->CommitAndCreateLayerImplTree(); + LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); + LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); + ASSERT_EQ(outer_viewport->id(), + layer_tree_impl->OuterViewportScrollLayer()->id()); + + LayerImpl* inner_scroll = layer_tree_impl->InnerViewportScrollLayer(); + LayerImpl* outer_scroll = layer_tree_impl->OuterViewportScrollLayer(); + LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); + LayerImpl* outer_clip_impl = layer_tree_impl->LayerById(outer_clip->id()); + + // Initially the sticky element is moved to the bottom of the container. + EXPECT_VECTOR2DF_EQ( + gfx::Vector2dF(0.f, 70.f), + sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); + + // We start to hide the toolbar, but not far enough that the sticky element + // should be moved up yet. + outer_clip_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -10.f)); + ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, + outer_scroll); + EXPECT_VECTOR2DF_EQ( + gfx::Vector2dF(0.f, 70.f), + sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); + + // On hiding more of the toolbar the sticky element starts to stick. + outer_clip_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -20.f)); + ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, + outer_scroll); + + // On hiding more the sticky element stops moving as it has reached its + // limit. + EXPECT_VECTOR2DF_EQ( + gfx::Vector2dF(0.f, 60.f), + sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); + + outer_clip_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -30.f)); + ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, + outer_scroll); + + EXPECT_VECTOR2DF_EQ( + gfx::Vector2dF(0.f, 60.f), + sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); +} + TEST_F(LayerTreeHostCommonTest, StickyPositionLeftRight) { scoped_refptr<Layer> root = Layer::Create(); scoped_refptr<Layer> container = Layer::Create(); @@ -6951,6 +7256,7 @@ TEST_F(LayerTreeHostCommonTest, StickyPositionLeftRight) { sticky_position.is_anchored_right = true; sticky_position.left_offset = 10.f; sticky_position.right_offset = 10.f; + sticky_position.parent_relative_sticky_box_offset = gfx::Point(145, 0); sticky_position.scroll_container_relative_sticky_box_rect = gfx::Rect(145, 0, 10, 10); sticky_position.scroll_container_relative_containing_block_rect = @@ -7053,6 +7359,7 @@ TEST_F(LayerTreeHostCommonTest, StickyPositionMainThreadUpdates) { sticky_position.is_sticky = true; sticky_position.is_anchored_top = true; sticky_position.top_offset = 10.0f; + sticky_position.parent_relative_sticky_box_offset = gfx::Point(10, 20); sticky_position.scroll_container_relative_sticky_box_rect = gfx::Rect(10, 20, 10, 10); sticky_position.scroll_container_relative_containing_block_rect = @@ -7124,6 +7431,110 @@ TEST_F(LayerTreeHostCommonTest, StickyPositionMainThreadUpdates) { sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); } +// This tests the main thread updates with a composited sticky container. In +// this case the position received from main is relative to the container but +// the constraint rects are relative to the ancestor scroller. +TEST_F(LayerTreeHostCommonTest, StickyPositionCompositedContainer) { + scoped_refptr<Layer> root = Layer::Create(); + scoped_refptr<Layer> container = Layer::Create(); + scoped_refptr<Layer> scroller = Layer::Create(); + scoped_refptr<Layer> sticky_container = Layer::Create(); + scoped_refptr<Layer> sticky_pos = Layer::Create(); + root->AddChild(container); + container->AddChild(scroller); + scroller->AddChild(sticky_container); + sticky_container->AddChild(sticky_pos); + host()->SetRootLayer(root); + scroller->SetScrollClipLayerId(container->id()); + + LayerStickyPositionConstraint sticky_position; + sticky_position.is_sticky = true; + sticky_position.is_anchored_top = true; + sticky_position.top_offset = 10.0f; + // The sticky position layer is only offset by (0, 10) from its parent + // layer, this position is used to determine the offset applied by the main + // thread. + sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 10); + sticky_position.scroll_container_relative_sticky_box_rect = + gfx::Rect(20, 30, 10, 10); + sticky_position.scroll_container_relative_containing_block_rect = + gfx::Rect(20, 20, 30, 30); + sticky_pos->SetStickyPositionConstraint(sticky_position); + + root->SetBounds(gfx::Size(100, 100)); + container->SetBounds(gfx::Size(100, 100)); + scroller->SetBounds(gfx::Size(1000, 1000)); + sticky_container->SetPosition(gfx::PointF(20, 20)); + sticky_container->SetBounds(gfx::Size(30, 30)); + sticky_pos->SetBounds(gfx::Size(10, 10)); + sticky_pos->SetPosition(gfx::PointF(0, 10)); + + ExecuteCalculateDrawProperties(root.get()); + host()->host_impl()->CreatePendingTree(); + host()->CommitAndCreatePendingTree(); + host()->host_impl()->ActivateSyncTree(); + LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); + + LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); + LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); + LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); + + ExecuteCalculateDrawProperties(root_impl); + EXPECT_VECTOR2DF_EQ( + gfx::Vector2dF(20.f, 30.f), + sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); + + // Scroll less than sticking point, sticky element should move with scroll as + // we haven't gotten to the initial sticky item location yet. + SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f)); + ExecuteCalculateDrawProperties(root_impl); + EXPECT_VECTOR2DF_EQ( + gfx::Vector2dF(20.f, 25.f), + sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); + + // Scroll past the sticking point, the Y coordinate should now be clamped. + SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 25.f)); + ExecuteCalculateDrawProperties(root_impl); + EXPECT_VECTOR2DF_EQ( + gfx::Vector2dF(20.f, 10.f), + sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); + + // Now the main thread commits the new position of the sticky element. + scroller->SetScrollOffset(gfx::ScrollOffset(0, 25)); + sticky_pos->SetPosition(gfx::PointF(0, 15)); + ExecuteCalculateDrawProperties(root.get()); + host()->host_impl()->CreatePendingTree(); + host()->CommitAndCreatePendingTree(); + host()->host_impl()->ActivateSyncTree(); + layer_tree_impl = host()->host_impl()->active_tree(); + root_impl = layer_tree_impl->LayerById(root->id()); + scroller_impl = layer_tree_impl->LayerById(scroller->id()); + sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); + + // The element should still be where it was before. We reset the delta to + // (0, 0) because we have synced a scroll offset of (0, 25) from the main + // thread. + SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 0.f)); + ExecuteCalculateDrawProperties(root_impl); + EXPECT_VECTOR2DF_EQ( + gfx::Vector2dF(20.f, 10.f), + sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); + + // And if we scroll a little further it remains there. + SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 5.f)); + ExecuteCalculateDrawProperties(root_impl); + EXPECT_VECTOR2DF_EQ( + gfx::Vector2dF(20.f, 10.f), + sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); + + // And hits the bottom of the container. + SetScrollOffsetDelta(scroller_impl, gfx::Vector2dF(0.f, 10.f)); + ExecuteCalculateDrawProperties(root_impl); + EXPECT_VECTOR2DF_EQ( + gfx::Vector2dF(20.f, 5.f), + sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); +} + // A transform on a sticky element should not affect its sticky position. TEST_F(LayerTreeHostCommonTest, StickyPositionScaledStickyBox) { scoped_refptr<Layer> root = Layer::Create(); @@ -7143,6 +7554,7 @@ TEST_F(LayerTreeHostCommonTest, StickyPositionScaledStickyBox) { sticky_position.is_sticky = true; sticky_position.is_anchored_top = true; sticky_position.top_offset = 0.0f; + sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 20); sticky_position.scroll_container_relative_sticky_box_rect = gfx::Rect(0, 20, 10, 10); sticky_position.scroll_container_relative_containing_block_rect = @@ -7221,6 +7633,7 @@ TEST_F(LayerTreeHostCommonTest, StickyPositionScaledContainer) { sticky_position.is_sticky = true; sticky_position.is_anchored_top = true; sticky_position.top_offset = 0.0f; + sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 20); sticky_position.scroll_container_relative_sticky_box_rect = gfx::Rect(0, 20, 10, 10); sticky_position.scroll_container_relative_containing_block_rect = @@ -7390,12 +7803,11 @@ class AnimationScaleFactorTrackingLayerImpl : public LayerImpl { TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) { FakeImplTaskRunnerProvider task_runner_provider; - TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; LayerTreeSettings settings = host()->GetSettings(); settings.layer_transforms_should_scale_layer_contents = true; FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider, - &shared_bitmap_manager, &task_graph_runner); + &task_graph_runner); std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent = AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1); std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> parent = @@ -7648,10 +8060,8 @@ static void GatherDrawnLayers(const LayerImplList* rsll, TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) { FakeImplTaskRunnerProvider task_runner_provider; - TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; - FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, - &task_graph_runner); + FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); std::unique_ptr<LayerImpl> grand_parent = LayerImpl::Create(host_impl.active_tree(), 1); @@ -7874,12 +8284,11 @@ TEST_F(LayerTreeHostCommonTest, RenderSurfaceLayerListMembership) { TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) { FakeImplTaskRunnerProvider task_runner_provider; - TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; LayerTreeSettings settings = host()->GetSettings(); settings.layer_transforms_should_scale_layer_contents = true; FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider, - &shared_bitmap_manager, &task_graph_runner); + &task_graph_runner); std::unique_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); @@ -7989,12 +8398,11 @@ TEST_F(LayerTreeHostCommonTest, DrawPropertyScales) { TEST_F(LayerTreeHostCommonTest, AnimationScales) { FakeImplTaskRunnerProvider task_runner_provider; - TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; LayerTreeSettings settings = host()->GetSettings(); settings.layer_transforms_should_scale_layer_contents = true; FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider, - &shared_bitmap_manager, &task_graph_runner); + &task_graph_runner); std::unique_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); @@ -8068,12 +8476,11 @@ TEST_F(LayerTreeHostCommonTest, // Returns empty scale if layer_transforms_should_scale_layer_contents is // false. FakeImplTaskRunnerProvider task_runner_provider; - TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; LayerTreeSettings settings = host()->GetSettings(); settings.layer_transforms_should_scale_layer_contents = false; FakeLayerTreeHostImpl host_impl(settings, &task_runner_provider, - &shared_bitmap_manager, &task_graph_runner); + &task_graph_runner); std::unique_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); @@ -8148,10 +8555,8 @@ TEST_F(LayerTreeHostCommonTest, VisibleContentRectInChildRenderSurface) { TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) { FakeImplTaskRunnerProvider task_runner_provider; - TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; - FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, - &task_graph_runner); + FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); // Set two layers: the root layer clips it's child, // the child draws its content. @@ -8161,7 +8566,7 @@ TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) { // Sublayer should be bigger than the root enlarged by bounds_delta. gfx::Size sublayer_size = gfx::Size(300, 1000); - // Device viewport accomidated the root and the top controls. + // Device viewport accomidated the root and the browser controls. gfx::Size device_viewport_size = gfx::Size(300, 600); host_impl.SetViewportSize(device_viewport_size); @@ -8779,10 +9184,8 @@ TEST_F(LayerTreeHostCommonTest, SkippingSubtreeMain) { TEST_F(LayerTreeHostCommonTest, SkippingLayerImpl) { FakeImplTaskRunnerProvider task_runner_provider; - TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; - FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, - &task_graph_runner); + FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); std::unique_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); @@ -8906,8 +9309,8 @@ TEST_F(LayerTreeHostCommonTest, SkippingLayerImpl) { std::unique_ptr<Animation> transform_animation( Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM)); scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1)); - host_impl.active_tree()->animation_host()->RegisterPlayerForElement( - root_ptr->element_id(), player.get()); + host_impl.animation_host()->RegisterPlayerForElement(root_ptr->element_id(), + player.get()); player->AddAnimation(std::move(transform_animation)); grandchild_ptr->set_visible_layer_rect(gfx::Rect()); child_ptr->SetScrollClipLayer(root_ptr->id()); @@ -8917,8 +9320,8 @@ TEST_F(LayerTreeHostCommonTest, SkippingLayerImpl) { ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); EXPECT_EQ(gfx::Rect(0, 0), grandchild_ptr->visible_layer_rect()); - host_impl.active_tree()->animation_host()->UnregisterPlayerForElement( - root_ptr->element_id(), player.get()); + host_impl.animation_host()->UnregisterPlayerForElement(root_ptr->element_id(), + player.get()); } TEST_F(LayerTreeHostCommonTest, LayerSkippingInSubtreeOfSingularTransform) { @@ -8954,7 +9357,7 @@ TEST_F(LayerTreeHostCommonTest, LayerSkippingInSubtreeOfSingularTransform) { std::unique_ptr<Animation> transform_animation( Animation::Create(std::move(curve), 3, 3, TargetProperty::TRANSFORM)); scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1)); - host_impl()->active_tree()->animation_host()->RegisterPlayerForElement( + host_impl()->animation_host()->RegisterPlayerForElement( grand_child->element_id(), player.get()); player->AddAnimation(std::move(transform_animation)); @@ -8962,16 +9365,14 @@ TEST_F(LayerTreeHostCommonTest, LayerSkippingInSubtreeOfSingularTransform) { EXPECT_EQ(gfx::Rect(0, 0), grand_child->visible_layer_rect()); EXPECT_EQ(gfx::Rect(0, 0), child->visible_layer_rect()); - host_impl()->active_tree()->animation_host()->UnregisterPlayerForElement( + host_impl()->animation_host()->UnregisterPlayerForElement( grand_child->element_id(), player.get()); } TEST_F(LayerTreeHostCommonTest, SkippingPendingLayerImpl) { FakeImplTaskRunnerProvider task_runner_provider; - TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; - FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, - &task_graph_runner); + FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); host_impl.CreatePendingTree(); std::unique_ptr<LayerImpl> root = @@ -9016,8 +9417,8 @@ TEST_F(LayerTreeHostCommonTest, SkippingPendingLayerImpl) { std::unique_ptr<Animation> animation( Animation::Create(std::move(curve), 3, 3, TargetProperty::OPACITY)); scoped_refptr<AnimationPlayer> player(AnimationPlayer::Create(1)); - host_impl.active_tree()->animation_host()->RegisterPlayerForElement( - root_ptr->element_id(), player.get()); + host_impl.animation_host()->RegisterPlayerForElement(root_ptr->element_id(), + player.get()); player->AddAnimation(std::move(animation)); root_ptr->test_properties()->opacity = 0.f; grandchild_ptr->set_visible_layer_rect(gfx::Rect()); @@ -9025,8 +9426,8 @@ TEST_F(LayerTreeHostCommonTest, SkippingPendingLayerImpl) { ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root_ptr); EXPECT_EQ(gfx::Rect(10, 10), grandchild_ptr->visible_layer_rect()); - host_impl.active_tree()->animation_host()->UnregisterPlayerForElement( - root_ptr->element_id(), player.get()); + host_impl.animation_host()->UnregisterPlayerForElement(root_ptr->element_id(), + player.get()); } TEST_F(LayerTreeHostCommonTest, SkippingLayer) { @@ -9153,12 +9554,15 @@ TEST_F(LayerTreeHostCommonTest, RenderSurfaceClipsSubtree) { float device_scale_factor = 1.f; float page_scale_factor = 1.f; LayerImpl* page_scale_layer = nullptr; + LayerImpl* inner_viewport_scroll_layer = nullptr; + LayerImpl* outer_viewport_scroll_layer = nullptr; // Visible rects computed by combining clips in target space and root space // don't match because of rotation transforms. So, we skip // verify_visible_rect_calculations. bool skip_verify_visible_rect_calculations = true; ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, - page_scale_layer, + page_scale_layer, inner_viewport_scroll_layer, + outer_viewport_scroll_layer, skip_verify_visible_rect_calculations); TransformTree& transform_tree = @@ -9175,7 +9579,7 @@ TEST_F(LayerTreeHostCommonTest, RenderSurfaceClipsSubtree) { ClipTree& clip_tree = root->layer_tree_impl()->property_trees()->clip_tree; ClipNode* clip_node = clip_tree.Node(render_surface->clip_tree_index()); - EXPECT_FALSE(clip_node->applies_local_clip); + EXPECT_EQ(clip_node->clip_type, ClipNode::ClipType::NONE); EXPECT_EQ(gfx::Rect(20, 20), test_layer->visible_layer_rect()); // Also test the visible rects computed by combining clips in root space. @@ -9688,22 +10092,21 @@ TEST_F(LayerTreeHostCommonTest, test_layer->SetBounds(gfx::Size(30, 30)); test_layer->SetDrawsContent(true); - // We want layer between the two targets to create a clip node and transform + // We want layer between the two targets to create a clip node and effect // node but it shouldn't create a render surface. between_targets->SetMasksToBounds(true); - between_targets->Set3dSortingContextId(2); + between_targets->test_properties()->opacity = 0.5f; ExecuteCalculateDrawProperties(root); - TransformTree& tree = - root->layer_tree_impl()->property_trees()->transform_tree; - TransformNode* node = tree.Node(render_surface1->transform_tree_index()); + EffectTree& tree = root->layer_tree_impl()->property_trees()->effect_tree; + EffectNode* node = tree.Node(render_surface1->effect_tree_index()); EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(2.f, 2.f)); - node = tree.Node(between_targets->transform_tree_index()); + node = tree.Node(between_targets->effect_tree_index()); EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(1.f, 1.f)); - node = tree.Node(render_surface2->transform_tree_index()); + node = tree.Node(render_surface2->effect_tree_index()); EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(2.f, 2.f)); EXPECT_EQ(gfx::Rect(15, 15), test_layer->visible_layer_rect()); @@ -9943,43 +10346,6 @@ TEST_F(LayerTreeHostCommonTest, TransformAnimationsTrackingTest) { EXPECT_FALSE(node->has_potential_animation); } -TEST_F(LayerTreeHostCommonTest, SerializeScrollUpdateInfo) { - LayerTreeHostCommon::ScrollUpdateInfo scroll; - scroll.layer_id = 2; - scroll.scroll_delta = gfx::Vector2d(5, 10); - - proto::ScrollUpdateInfo proto; - scroll.ToProtobuf(&proto); - LayerTreeHostCommon::ScrollUpdateInfo new_scroll; - new_scroll.FromProtobuf(proto); - - EXPECT_EQ(scroll, new_scroll); -} - -TEST_F(LayerTreeHostCommonTest, SerializeScrollAndScale) { - ScrollAndScaleSet scroll_and_scale_set; - - LayerTreeHostCommon::ScrollUpdateInfo scroll1; - scroll1.layer_id = 1; - scroll1.scroll_delta = gfx::Vector2d(5, 10); - LayerTreeHostCommon::ScrollUpdateInfo scroll2; - scroll2.layer_id = 2; - scroll2.scroll_delta = gfx::Vector2d(1, 5); - scroll_and_scale_set.scrolls.push_back(scroll1); - scroll_and_scale_set.scrolls.push_back(scroll2); - - scroll_and_scale_set.page_scale_delta = 0.3f; - scroll_and_scale_set.elastic_overscroll_delta = gfx::Vector2dF(0.5f, 0.6f); - scroll_and_scale_set.top_controls_delta = 0.9f; - - proto::ScrollAndScaleSet proto; - scroll_and_scale_set.ToProtobuf(&proto); - ScrollAndScaleSet new_scroll_and_scale_set; - new_scroll_and_scale_set.FromProtobuf(proto); - - EXPECT_TRUE(scroll_and_scale_set.EqualsForTesting(new_scroll_and_scale_set)); -} - TEST_F(LayerTreeHostCommonTest, ScrollTreeBuilderTest) { // Test the behavior of scroll tree builder // Topology: diff --git a/chromium/cc/trees/layer_tree_host_impl.cc b/chromium/cc/trees/layer_tree_host_impl.cc index dbd9e0fb214..c986b160798 100644 --- a/chromium/cc/trees/layer_tree_host_impl.cc +++ b/chromium/cc/trees/layer_tree_host_impl.cc @@ -24,8 +24,6 @@ #include "base/stl_util.h" #include "base/strings/stringprintf.h" #include "base/trace_event/trace_event_argument.h" -#include "cc/animation/animation_events.h" -#include "cc/animation/animation_host.h" #include "cc/base/histograms.h" #include "cc/base/math_util.h" #include "cc/debug/benchmark_instrumentation.h" @@ -35,12 +33,12 @@ #include "cc/debug/frame_viewer_instrumentation.h" #include "cc/debug/rendering_stats_instrumentation.h" #include "cc/debug/traced_value.h" +#include "cc/input/browser_controls_offset_manager.h" #include "cc/input/main_thread_scrolling_reason.h" #include "cc/input/page_scale_animation.h" #include "cc/input/scroll_elasticity_helper.h" #include "cc/input/scroll_state.h" #include "cc/input/scrollbar_animation_controller.h" -#include "cc/input/top_controls_manager.h" #include "cc/layers/append_quads_data.h" #include "cc/layers/heads_up_display_layer_impl.h" #include "cc/layers/layer_impl.h" @@ -73,12 +71,12 @@ #include "cc/tiles/picture_layer_tiling.h" #include "cc/tiles/raster_tile_priority_queue.h" #include "cc/tiles/software_image_decode_controller.h" -#include "cc/tiles/tile_task_manager.h" #include "cc/trees/damage_tracker.h" #include "cc/trees/draw_property_utils.h" #include "cc/trees/latency_info_swap_promise_monitor.h" #include "cc/trees/layer_tree_host_common.h" #include "cc/trees/layer_tree_impl.h" +#include "cc/trees/mutator_host.h" #include "cc/trees/scroll_node.h" #include "cc/trees/single_thread_proxy.h" #include "cc/trees/tree_synchronizer.h" @@ -173,15 +171,12 @@ std::unique_ptr<LayerTreeHostImpl> LayerTreeHostImpl::Create( LayerTreeHostImplClient* client, TaskRunnerProvider* task_runner_provider, RenderingStatsInstrumentation* rendering_stats_instrumentation, - SharedBitmapManager* shared_bitmap_manager, - gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, TaskGraphRunner* task_graph_runner, - std::unique_ptr<AnimationHost> animation_host, + std::unique_ptr<MutatorHost> mutator_host, int id) { return base::WrapUnique(new LayerTreeHostImpl( settings, client, task_runner_provider, rendering_stats_instrumentation, - shared_bitmap_manager, gpu_memory_buffer_manager, task_graph_runner, - std::move(animation_host), id)); + task_graph_runner, std::move(mutator_host), id)); } LayerTreeHostImpl::LayerTreeHostImpl( @@ -189,10 +184,8 @@ LayerTreeHostImpl::LayerTreeHostImpl( LayerTreeHostImplClient* client, TaskRunnerProvider* task_runner_provider, RenderingStatsInstrumentation* rendering_stats_instrumentation, - SharedBitmapManager* shared_bitmap_manager, - gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, TaskGraphRunner* task_graph_runner, - std::unique_ptr<AnimationHost> animation_host, + std::unique_ptr<MutatorHost> mutator_host, int id) : client_(client), task_runner_provider_(task_runner_provider), @@ -208,8 +201,7 @@ LayerTreeHostImpl::LayerTreeHostImpl( did_lock_scrolling_layer_(false), wheel_scrolling_(false), scroll_affects_scroll_handler_(false), - scroll_layer_id_when_mouse_over_scrollbar_(Layer::INVALID_ID), - captured_scrollbar_layer_id_(Layer::INVALID_ID), + scroll_layer_id_mouse_currently_over_(Layer::INVALID_ID), tile_priorities_dirty_(false), settings_(settings), visible_(false), @@ -232,19 +224,17 @@ LayerTreeHostImpl::LayerTreeHostImpl( debug_rect_history_(DebugRectHistory::Create()), max_memory_needed_bytes_(0), resourceless_software_draw_(false), - animation_host_(std::move(animation_host)), + mutator_host_(std::move(mutator_host)), rendering_stats_instrumentation_(rendering_stats_instrumentation), micro_benchmark_controller_(this), - shared_bitmap_manager_(shared_bitmap_manager), - gpu_memory_buffer_manager_(gpu_memory_buffer_manager), task_graph_runner_(task_graph_runner), id_(id), requires_high_res_to_draw_(false), is_likely_to_require_a_draw_(false), has_valid_compositor_frame_sink_(false), mutator_(nullptr) { - DCHECK(animation_host_); - animation_host_->SetMutatorHostClient(this); + DCHECK(mutator_host_); + mutator_host_->SetMutatorHostClient(this); DCHECK(task_runner_provider_->IsImplThread()); DidVisibilityChange(this, visible_); @@ -253,7 +243,7 @@ LayerTreeHostImpl::LayerTreeHostImpl( // LTHI always has an active tree. active_tree_ = base::MakeUnique<LayerTreeImpl>( - this, new SyncedProperty<ScaleGroup>, new SyncedTopControls, + this, new SyncedProperty<ScaleGroup>, new SyncedBrowserControls, new SyncedElasticOverscroll); active_tree_->property_trees()->is_active = true; @@ -262,9 +252,9 @@ LayerTreeHostImpl::LayerTreeHostImpl( TRACE_EVENT_OBJECT_CREATED_WITH_ID(TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerTreeHostImpl", id_); - top_controls_manager_ = - TopControlsManager::Create(this, settings.top_controls_show_threshold, - settings.top_controls_hide_threshold); + browser_controls_offset_manager_ = BrowserControlsOffsetManager::Create( + this, settings.top_controls_show_threshold, + settings.top_controls_hide_threshold); } LayerTreeHostImpl::~LayerTreeHostImpl() { @@ -278,7 +268,6 @@ LayerTreeHostImpl::~LayerTreeHostImpl() { DCHECK(!resource_provider_); DCHECK(!resource_pool_); - DCHECK(!tile_task_manager_); DCHECK(!single_thread_synchronous_task_graph_runner_); DCHECK(!image_decode_controller_); @@ -289,9 +278,7 @@ LayerTreeHostImpl::~LayerTreeHostImpl() { if (scroll_elasticity_helper_) scroll_elasticity_helper_.reset(); - // The layer trees must be destroyed before the layer tree host. We've - // made a contract with our animation controllers that the animation_host - // will outlive them, and we must make good. + // The layer trees must be destroyed before the layer tree host. if (recycle_tree_) recycle_tree_->Shutdown(); if (pending_tree_) @@ -301,8 +288,8 @@ LayerTreeHostImpl::~LayerTreeHostImpl() { pending_tree_ = nullptr; active_tree_ = nullptr; - animation_host_->ClearTimelines(); - animation_host_->SetMutatorHostClient(nullptr); + mutator_host_->ClearMutators(); + mutator_host_->SetMutatorHostClient(nullptr); } void LayerTreeHostImpl::BeginMainFrameAborted( @@ -465,7 +452,7 @@ void LayerTreeHostImpl::AnimateInternal(bool active_tree) { did_animate |= AnimatePageScale(monotonic_time); did_animate |= AnimateLayers(monotonic_time); did_animate |= AnimateScrollbars(monotonic_time); - did_animate |= AnimateTopControls(monotonic_time); + did_animate |= AnimateBrowserControls(monotonic_time); if (active_tree) { did_animate |= Mutate(monotonic_time); @@ -1035,7 +1022,7 @@ DrawResult LayerTreeHostImpl::CalculateRenderPasses(FrameData* frame) { } void LayerTreeHostImpl::MainThreadHasStoppedFlinging() { - top_controls_manager_->MainThreadHasStoppedFlinging(); + browser_controls_offset_manager_->MainThreadHasStoppedFlinging(); if (input_handler_client_) input_handler_client_->MainThreadHasStoppedFlinging(); } @@ -1235,10 +1222,10 @@ void LayerTreeHostImpl::UpdateTileManagerMemoryPolicy( if (global_tile_state_.hard_memory_limit_in_bytes > 0) { // If |global_tile_state_.hard_memory_limit_in_bytes| is greater than 0, we - // are visible. Notify the worker context here. We handle becoming - // invisible in NotifyAllTileTasksComplete to avoid interrupting running - // work. - SetWorkerContextVisibility(true); + // consider our contexts visible. Notify the contexts here. We handle + // becoming invisible in NotifyAllTileTasksComplete to avoid interrupting + // running work. + SetContextVisibility(true); // If |global_tile_state_.hard_memory_limit_in_bytes| is greater than 0, we // allow the image decode controller to retain resources. We handle the @@ -1268,7 +1255,7 @@ void LayerTreeHostImpl::DidModifyTilePriorities() { std::unique_ptr<RasterTilePriorityQueue> LayerTreeHostImpl::BuildRasterQueue( TreePriority tree_priority, RasterTilePriorityQueue::Type type) { - TRACE_EVENT0("disabled-by-default-cc.debug", + TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), "LayerTreeHostImpl::BuildRasterQueue"); return RasterTilePriorityQueue::Create(active_tree_->picture_layers(), @@ -1280,7 +1267,7 @@ std::unique_ptr<RasterTilePriorityQueue> LayerTreeHostImpl::BuildRasterQueue( std::unique_ptr<EvictionTilePriorityQueue> LayerTreeHostImpl::BuildEvictionQueue(TreePriority tree_priority) { - TRACE_EVENT0("disabled-by-default-cc.debug", + TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), "LayerTreeHostImpl::BuildEvictionQueue"); std::unique_ptr<EvictionTilePriorityQueue> queue( @@ -1324,13 +1311,13 @@ void LayerTreeHostImpl::NotifyAllTileTasksCompleted() { // The tile tasks started by the most recent call to PrepareTiles have // completed. Now is a good time to free resources if necessary. if (global_tile_state_.hard_memory_limit_in_bytes == 0) { - // Free image decode controller resources before notifying the worker - // context of visibility change. This ensures that the imaged decode + // Free image decode controller resources before notifying the + // contexts of visibility change. This ensures that the imaged decode // controller has released all Skia refs at the time Skia's cleanup // executes (within worker context's cleanup). if (image_decode_controller_) image_decode_controller_->SetShouldAggressivelyFreeResources(true); - SetWorkerContextVisibility(false); + SetContextVisibility(false); } } @@ -1449,8 +1436,8 @@ void LayerTreeHostImpl::SetExternalTilePriorityConstraints( } } -void LayerTreeHostImpl::DidSwapBuffersComplete() { - client_->DidSwapBuffersCompleteOnImplThread(); +void LayerTreeHostImpl::DidReceiveCompositorFrameAck() { + client_->DidReceiveCompositorFrameAckOnImplThread(); } void LayerTreeHostImpl::ReclaimResources( @@ -1542,13 +1529,14 @@ CompositorFrameMetadata LayerTreeHostImpl::MakeCompositorFrameMetadata() const { metadata.root_layer_size = active_tree_->ScrollableSize(); metadata.min_page_scale_factor = active_tree_->min_page_scale_factor(); metadata.max_page_scale_factor = active_tree_->max_page_scale_factor(); - metadata.top_controls_height = top_controls_manager_->TopControlsHeight(); + metadata.top_controls_height = + browser_controls_offset_manager_->TopControlsHeight(); metadata.top_controls_shown_ratio = - top_controls_manager_->TopControlsShownRatio(); + browser_controls_offset_manager_->TopControlsShownRatio(); metadata.bottom_controls_height = - top_controls_manager_->BottomControlsHeight(); + browser_controls_offset_manager_->BottomControlsHeight(); metadata.bottom_controls_shown_ratio = - top_controls_manager_->BottomControlsShownRatio(); + browser_controls_offset_manager_->BottomControlsShownRatio(); metadata.root_background_color = active_tree_->background_color(); active_tree_->GetViewportSelection(&metadata.selection); @@ -1562,7 +1550,7 @@ CompositorFrameMetadata LayerTreeHostImpl::MakeCompositorFrameMetadata() const { if (GetDrawMode() == DRAW_MODE_RESOURCELESS_SOFTWARE) { metadata.is_resourceless_software_draw_with_scroll_or_animation = - IsActivelyScrolling() || animation_host_->NeedsAnimateLayers(); + IsActivelyScrolling() || mutator_host_->NeedsAnimateLayers(); } for (LayerImpl* surface_layer : active_tree_->SurfaceLayers()) { @@ -1588,7 +1576,7 @@ bool LayerTreeHostImpl::DrawLayers(FrameData* frame) { DCHECK(CanDraw()); DCHECK_EQ(frame->has_no_damage, frame->render_passes.empty()); - TRACE_EVENT0("cc", "LayerTreeHostImpl::DrawLayers"); + TRACE_EVENT0("cc,benchmark", "LayerTreeHostImpl::DrawLayers"); ResetRequiresHighResToDraw(); @@ -1674,7 +1662,7 @@ bool LayerTreeHostImpl::DrawLayers(FrameData* frame) { CompositorFrame compositor_frame; compositor_frame.metadata = std::move(metadata); compositor_frame.delegated_frame_data = std::move(data); - compositor_frame_sink_->SwapBuffers(std::move(compositor_frame)); + compositor_frame_sink_->SubmitCompositorFrame(std::move(compositor_frame)); // The next frame should start by assuming nothing has changed, and changes // are noted as they occur. @@ -1861,20 +1849,22 @@ void LayerTreeHostImpl::UpdateViewportContainerSizes() { ViewportAnchor anchor(InnerViewportScrollLayer(), OuterViewportScrollLayer()); float top_controls_layout_height = - active_tree_->top_controls_shrink_blink_size() + active_tree_->browser_controls_shrink_blink_size() ? active_tree_->top_controls_height() : 0.f; float delta_from_top_controls = - top_controls_layout_height - top_controls_manager_->ContentTopOffset(); + top_controls_layout_height - + browser_controls_offset_manager_->ContentTopOffset(); float bottom_controls_layout_height = - active_tree_->top_controls_shrink_blink_size() + active_tree_->browser_controls_shrink_blink_size() ? active_tree_->bottom_controls_height() : 0.f; - delta_from_top_controls += bottom_controls_layout_height - - top_controls_manager_->ContentBottomOffset(); + delta_from_top_controls += + bottom_controls_layout_height - + browser_controls_offset_manager_->ContentBottomOffset(); // Adjust the viewport layers by shrinking/expanding the container to account - // for changes in the size (e.g. top controls) since the last resize from + // for changes in the size (e.g. browser controls) since the last resize from // Blink. gfx::Vector2dF amount_to_expand(0.f, delta_from_top_controls); inner_container->SetBoundsDelta(amount_to_expand); @@ -2051,9 +2041,6 @@ void LayerTreeHostImpl::SetVisible(bool visible) { // Call PrepareTiles to evict tiles when we become invisible. PrepareTiles(); } - - // Update visibility for the compositor context provider. - SetCompositorContextVisibility(visible); } void LayerTreeHostImpl::SetNeedsOneBeginImplFrame() { @@ -2132,12 +2119,10 @@ void LayerTreeHostImpl::CreateTileManagerResources() { task_graph_runner = single_thread_synchronous_task_graph_runner_.get(); } - tile_task_manager_ = TileTaskManagerImpl::Create(task_graph_runner); - // TODO(vmpstr): Initialize tile task limit at ctor time. tile_manager_.SetResources( - resource_pool_.get(), image_decode_controller_.get(), - tile_task_manager_.get(), raster_buffer_provider_.get(), + resource_pool_.get(), image_decode_controller_.get(), task_graph_runner, + raster_buffer_provider_.get(), is_synchronous_single_threaded_ ? std::numeric_limits<size_t>::max() : settings_.scheduled_raster_task_limit, use_gpu_rasterization_); @@ -2229,11 +2214,18 @@ void LayerTreeHostImpl::SetLayerTreeMutator( mutator_->SetClient(this); } +LayerImpl* LayerTreeHostImpl::ViewportMainScrollLayer() { + return viewport()->MainScrollLayer(); +} + +void LayerTreeHostImpl::DidChangeScrollbarVisibility() { + client_->SetNeedsCommitOnImplThread(); +} + void LayerTreeHostImpl::CleanUpTileManagerAndUIResources() { ClearUIResources(); tile_manager_.FinishTasksAndCleanUp(); resource_pool_ = nullptr; - tile_task_manager_ = nullptr; single_thread_synchronous_task_graph_runner_ = nullptr; image_decode_controller_ = nullptr; @@ -2271,13 +2263,7 @@ void LayerTreeHostImpl::ReleaseCompositorFrameSink() { resource_provider_ = nullptr; // Release any context visibility before we destroy the CompositorFrameSink. - if (visible_) - SetCompositorContextVisibility(false); - // Worker context visibility is based on both LTHI visibility as well as - // memory policy, so we directly check |worker_context_visibility_| here, - // rather than just relying on |visibility_|. - if (worker_context_visibility_) - SetWorkerContextVisibility(false); + SetContextVisibility(false); // Detach from the old CompositorFrameSink and reset |compositor_frame_sink_| // pointer as this surface is going to be destroyed independent of if binding @@ -2312,21 +2298,17 @@ bool LayerTreeHostImpl::InitializeRenderer( compositor_frame_sink_ = compositor_frame_sink; has_valid_compositor_frame_sink_ = true; resource_provider_ = base::MakeUnique<ResourceProvider>( - compositor_frame_sink_->context_provider(), shared_bitmap_manager_, - gpu_memory_buffer_manager_, + compositor_frame_sink_->context_provider(), + compositor_frame_sink_->shared_bitmap_manager(), + compositor_frame_sink_->gpu_memory_buffer_manager(), task_runner_provider_->blocking_main_thread_task_runner(), settings_.renderer_settings.highp_threshold_min, settings_.renderer_settings.texture_id_allocation_chunk_size, compositor_frame_sink_->capabilities().delegated_sync_points_required, - settings_.renderer_settings.use_gpu_memory_buffer_resources, false, + settings_.renderer_settings.use_gpu_memory_buffer_resources, + settings_.enable_color_correct_rendering, settings_.renderer_settings.buffer_to_texture_target_map); - // Make sure the main context visibility is restored. Worker context - // visibility will be set via the memory policy update in - // CreateTileManagerResources below. - if (visible_) - SetCompositorContextVisibility(true); - // Since the new context may be capable of MSAA, update status here. We don't // need to check the return value since we are recreating all resources // already. @@ -2399,7 +2381,7 @@ const gfx::Transform& LayerTreeHostImpl::DrawTransform() const { return external_transform_; } -void LayerTreeHostImpl::DidChangeTopControlsPosition() { +void LayerTreeHostImpl::DidChangeBrowserControlsPosition() { UpdateViewportContainerSizes(); SetNeedsRedraw(); SetNeedsOneBeginImplFrame(); @@ -2415,13 +2397,13 @@ float LayerTreeHostImpl::BottomControlsHeight() const { return active_tree_->bottom_controls_height(); } -void LayerTreeHostImpl::SetCurrentTopControlsShownRatio(float ratio) { - if (active_tree_->SetCurrentTopControlsShownRatio(ratio)) - DidChangeTopControlsPosition(); +void LayerTreeHostImpl::SetCurrentBrowserControlsShownRatio(float ratio) { + if (active_tree_->SetCurrentBrowserControlsShownRatio(ratio)) + DidChangeBrowserControlsPosition(); } -float LayerTreeHostImpl::CurrentTopControlsShownRatio() const { - return active_tree_->CurrentTopControlsShownRatio(); +float LayerTreeHostImpl::CurrentBrowserControlsShownRatio() const { + return active_tree_->CurrentBrowserControlsShownRatio(); } void LayerTreeHostImpl::BindToClient(InputHandlerClient* client) { @@ -2616,7 +2598,7 @@ InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBeginImpl( scroll_status.thread = SCROLL_ON_IMPL_THREAD; ScrollAnimationAbort(scrolling_layer_impl); - top_controls_manager_->ScrollBegin(); + browser_controls_offset_manager_->ScrollBegin(); active_tree_->SetCurrentlyScrollingLayer(scrolling_layer_impl); // TODO(majidvp): get rid of wheel_scrolling_ and set is_direct_manipulation @@ -2782,7 +2764,7 @@ bool LayerTreeHostImpl::ScrollAnimationCreate(ScrollNode* scroll_node, ElementId(active_tree()->LayerById(scroll_node->owner_id)->element_id()), scroll_node->element_id); - animation_host_->ImplOnlyScrollAnimationCreate( + mutator_host_->ImplOnlyScrollAnimationCreate( scroll_node->element_id, target_offset, current_offset, delayed_by); SetNeedsOneBeginImplFrame(); @@ -2833,19 +2815,18 @@ InputHandler::ScrollStatus LayerTreeHostImpl::ScrollAnimated( if (scroll_node) { for (; scroll_tree.parent(scroll_node); scroll_node = scroll_tree.parent(scroll_node)) { - if (!scroll_node->scrollable || - scroll_node->is_outer_viewport_scroll_layer) + if (!scroll_node->scrollable) continue; - if (scroll_node->is_inner_viewport_scroll_layer) { + if (viewport()->MainScrollLayer() && + scroll_node->owner_id == viewport()->MainScrollLayer()->id()) { gfx::Vector2dF scrolled = viewport()->ScrollAnimated(pending_delta, delayed_by); // Viewport::ScrollAnimated returns pending_delta as long as it // starts an animation. if (scrolled == pending_delta) return scroll_status; - pending_delta -= scrolled; - continue; + break; } gfx::Vector2dF scroll_delta = @@ -2979,6 +2960,7 @@ void LayerTreeHostImpl::ApplyScroll(ScrollNode* scroll_node, scroll_state->position_y()); const gfx::Vector2dF delta(scroll_state->delta_x(), scroll_state->delta_y()); gfx::Vector2dF applied_delta; + gfx::Vector2dF delta_applied_to_content; // TODO(tdresser): Use a more rational epsilon. See crbug.com/510550 for // details. const float kEpsilon = 0.1f; @@ -2987,16 +2969,21 @@ void LayerTreeHostImpl::ApplyScroll(ScrollNode* scroll_node, viewport()->MainScrollLayer() && scroll_node->owner_id == viewport()->MainScrollLayer()->id(); - if (is_viewport_scroll_layer) { - bool affect_top_controls = !wheel_scrolling_; + // This is needed if the scroll chains up to the viewport without going + // through the outer viewport scroll layer. This can happen if we scroll an + // element that's not a descendant of the document.rootScroller. In that case + // we want to scroll the inner viewport -- to allow panning while zoomed -- + // but also move browser controls if needed. + bool is_inner_viewport_scroll_layer = + scroll_node->owner_id == InnerViewportScrollLayer()->id(); + + if (is_viewport_scroll_layer || is_inner_viewport_scroll_layer) { Viewport::ScrollResult result = viewport()->ScrollBy( delta, viewport_point, scroll_state->is_direct_manipulation(), - affect_top_controls); + !wheel_scrolling_, is_viewport_scroll_layer); + applied_delta = result.consumed_delta; - scroll_state->set_caused_scroll( - std::abs(result.content_scrolled_delta.x()) > kEpsilon, - std::abs(result.content_scrolled_delta.y()) > kEpsilon); - scroll_state->ConsumeDelta(applied_delta.x(), applied_delta.y()); + delta_applied_to_content = result.content_scrolled_delta; } else { applied_delta = ScrollSingleNode( scroll_node, delta, viewport_point, @@ -3007,8 +2994,16 @@ void LayerTreeHostImpl::ApplyScroll(ScrollNode* scroll_node, // If the layer wasn't able to move, try the next one in the hierarchy. bool scrolled = std::abs(applied_delta.x()) > kEpsilon; scrolled = scrolled || std::abs(applied_delta.y()) > kEpsilon; + if (!scrolled) { + // TODO(bokan): This preserves existing behavior by not allowing tiny + // scrolls to produce overscroll but is inconsistent in how delta gets + // chained up. We need to clean this up. + if (is_viewport_scroll_layer) + scroll_state->ConsumeDelta(applied_delta.x(), applied_delta.y()); + return; + } - if (scrolled && !is_viewport_scroll_layer) { + if (!is_viewport_scroll_layer && !is_inner_viewport_scroll_layer) { // If the applied delta is within 45 degrees of the input // delta, bail out to make it easier to scroll just one layer // in one direction without affecting any of its parents. @@ -3021,13 +3016,13 @@ void LayerTreeHostImpl::ApplyScroll(ScrollNode* scroll_node, // in which the layer moved. applied_delta = MathUtil::ProjectVector(delta, applied_delta); } - scroll_state->set_caused_scroll(std::abs(applied_delta.x()) > kEpsilon, - std::abs(applied_delta.y()) > kEpsilon); - scroll_state->ConsumeDelta(applied_delta.x(), applied_delta.y()); + delta_applied_to_content = applied_delta; } - if (!scrolled) - return; + scroll_state->set_caused_scroll( + std::abs(delta_applied_to_content.x()) > kEpsilon, + std::abs(delta_applied_to_content.y()) > kEpsilon); + scroll_state->ConsumeDelta(applied_delta.x(), applied_delta.y()); scroll_state->set_current_native_scrolling_node(scroll_node); } @@ -3040,18 +3035,19 @@ void LayerTreeHostImpl::DistributeScrollDelta(ScrollState* scroll_state) { std::list<const ScrollNode*> current_scroll_chain; ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree; ScrollNode* scroll_node = scroll_tree.CurrentlyScrollingNode(); + ScrollNode* viewport_scroll_node = + viewport()->MainScrollLayer() + ? scroll_tree.Node(viewport()->MainScrollLayer()->scroll_tree_index()) + : nullptr; if (scroll_node) { + // TODO(bokan): The loop checks for a null parent but don't we still want to + // distribute to the root scroll node? for (; scroll_tree.parent(scroll_node); scroll_node = scroll_tree.parent(scroll_node)) { - if (scroll_node->is_outer_viewport_scroll_layer) { - // TODO(bokan): This should use Viewport::MainScrollLayer once that - // returns the outer viewport scroll layer. + if (scroll_node == viewport_scroll_node) { // Don't chain scrolls past the outer viewport scroll layer. Once we // reach that, we should scroll the viewport which is represented by the // main viewport scroll layer. - DCHECK(viewport()->MainScrollLayer()); - ScrollNode* viewport_scroll_node = scroll_tree.Node( - viewport()->MainScrollLayer()->scroll_tree_index()); DCHECK(viewport_scroll_node); current_scroll_chain.push_front(viewport_scroll_node); break; @@ -3077,7 +3073,7 @@ InputHandlerScrollResult LayerTreeHostImpl::ScrollBy( return InputHandlerScrollResult(); float initial_top_controls_offset = - top_controls_manager_->ControlsTopOffset(); + browser_controls_offset_manager_->ControlsTopOffset(); scroll_state->set_delta_consumed_for_scroll_sequence( did_lock_scrolling_layer_); @@ -3125,7 +3121,8 @@ InputHandlerScrollResult LayerTreeHostImpl::ScrollBy( accumulated_root_overscroll_ += unused_root_delta; bool did_scroll_top_controls = - initial_top_controls_offset != top_controls_manager_->ControlsTopOffset(); + initial_top_controls_offset != + browser_controls_offset_manager_->ControlsTopOffset(); InputHandlerScrollResult scroll_result; scroll_result.did_scroll = did_scroll_content || did_scroll_top_controls; @@ -3175,7 +3172,7 @@ void LayerTreeHostImpl::ScrollEnd(ScrollState* scroll_state) { DCHECK(scroll_state->delta_x() == 0 && scroll_state->delta_y() == 0); DistributeScrollDelta(scroll_state); - top_controls_manager_->ScrollEnd(); + browser_controls_offset_manager_->ScrollEnd(); ClearCurrentlyScrollingLayer(); } @@ -3209,84 +3206,77 @@ float LayerTreeHostImpl::DeviceSpaceDistanceToLayer( } void LayerTreeHostImpl::MouseDown() { - if (scroll_layer_id_when_mouse_over_scrollbar_ == Layer::INVALID_ID) - return; - - captured_scrollbar_layer_id_ = scroll_layer_id_when_mouse_over_scrollbar_; ScrollbarAnimationController* animation_controller = - ScrollbarAnimationControllerForId(captured_scrollbar_layer_id_); + ScrollbarAnimationControllerForId(scroll_layer_id_mouse_currently_over_); if (animation_controller) - animation_controller->DidCaptureScrollbarBegin(); + animation_controller->DidMouseDown(); } void LayerTreeHostImpl::MouseUp() { - if (captured_scrollbar_layer_id_ == Layer::INVALID_ID) - return; - ScrollbarAnimationController* animation_controller = - ScrollbarAnimationControllerForId(captured_scrollbar_layer_id_); + ScrollbarAnimationControllerForId(scroll_layer_id_mouse_currently_over_); if (animation_controller) - animation_controller->DidCaptureScrollbarEnd(); - captured_scrollbar_layer_id_ = Layer::INVALID_ID; + animation_controller->DidMouseUp(); } void LayerTreeHostImpl::MouseMoveAt(const gfx::Point& viewport_point) { + float distance_to_scrollbar = std::numeric_limits<float>::max(); gfx::PointF device_viewport_point = gfx::ScalePoint( gfx::PointF(viewport_point), active_tree_->device_scale_factor()); LayerImpl* layer_impl = active_tree_->FindLayerThatIsHitByPoint(device_viewport_point); - HandleMouseOverScrollbar(layer_impl); - if (scroll_layer_id_when_mouse_over_scrollbar_ != Layer::INVALID_ID) - return; - - bool scroll_on_main_thread = false; - uint32_t main_thread_scrolling_reasons; - LayerImpl* scroll_layer_impl = FindScrollLayerForDeviceViewportPoint( - device_viewport_point, InputHandler::TOUCHSCREEN, layer_impl, - &scroll_on_main_thread, &main_thread_scrolling_reasons); - // Scrollbars for the viewport are registered with the outer viewport layer. - if (scroll_layer_impl == InnerViewportScrollLayer()) - scroll_layer_impl = OuterViewportScrollLayer(); - if (scroll_on_main_thread || !scroll_layer_impl) - return; - - ScrollbarAnimationController* animation_controller = - ScrollbarAnimationControllerForId(scroll_layer_impl->id()); - if (!animation_controller) - return; - - float distance_to_scrollbar = std::numeric_limits<float>::max(); - for (ScrollbarLayerImplBase* scrollbar : - ScrollbarsFor(scroll_layer_impl->id())) - distance_to_scrollbar = - std::min(distance_to_scrollbar, - DeviceSpaceDistanceToLayer(device_viewport_point, scrollbar)); - - animation_controller->DidMouseMoveNear(distance_to_scrollbar / - active_tree_->device_scale_factor()); -} -void LayerTreeHostImpl::HandleMouseOverScrollbar(LayerImpl* layer_impl) { + // Check if mouse is over a scrollbar or not. + // TODO(sahel): get rid of this extera checking when + // FindScrollLayerForDeviceViewportPoint finds the proper layer for + // scrolling on main thread, as well. int new_id = Layer::INVALID_ID; if (layer_impl && layer_impl->ToScrollbarLayer()) new_id = layer_impl->ToScrollbarLayer()->ScrollLayerId(); + if (new_id != Layer::INVALID_ID) { + // Mouse over a scrollbar. + distance_to_scrollbar = 0; + } else { + bool scroll_on_main_thread = false; + uint32_t main_thread_scrolling_reasons; + LayerImpl* scroll_layer_impl = FindScrollLayerForDeviceViewportPoint( + device_viewport_point, InputHandler::TOUCHSCREEN, layer_impl, + &scroll_on_main_thread, &main_thread_scrolling_reasons); - if (new_id == scroll_layer_id_when_mouse_over_scrollbar_) - return; + // Scrollbars for the viewport are registered with the outer viewport layer. + if (scroll_layer_impl == InnerViewportScrollLayer()) + scroll_layer_impl = OuterViewportScrollLayer(); - ScrollbarAnimationController* old_animation_controller = - ScrollbarAnimationControllerForId( - scroll_layer_id_when_mouse_over_scrollbar_); - if (old_animation_controller) - old_animation_controller->DidMouseMoveOffScrollbar(); + new_id = scroll_layer_impl ? scroll_layer_impl->id() : Layer::INVALID_ID; + } - scroll_layer_id_when_mouse_over_scrollbar_ = new_id; + if (new_id != scroll_layer_id_mouse_currently_over_) { + ScrollbarAnimationController* old_animation_controller = + ScrollbarAnimationControllerForId( + scroll_layer_id_mouse_currently_over_); + if (old_animation_controller) { + old_animation_controller->DidMouseLeave(); + } + scroll_layer_id_mouse_currently_over_ = new_id; + } ScrollbarAnimationController* new_animation_controller = - ScrollbarAnimationControllerForId( - scroll_layer_id_when_mouse_over_scrollbar_); - if (new_animation_controller) - new_animation_controller->DidMouseMoveNear(0); + ScrollbarAnimationControllerForId(new_id); + if (!new_animation_controller) + return; + + for (ScrollbarLayerImplBase* scrollbar : ScrollbarsFor(new_id)) + distance_to_scrollbar = + std::min(distance_to_scrollbar, + DeviceSpaceDistanceToLayer(device_viewport_point, scrollbar)); + new_animation_controller->DidMouseMoveNear( + distance_to_scrollbar / active_tree_->device_scale_factor()); +} + +void LayerTreeHostImpl::MouseLeave() { + for (auto& pair : scrollbar_animation_controllers_) + pair.second->DidMouseLeave(); + scroll_layer_id_mouse_currently_over_ = Layer::INVALID_ID; } void LayerTreeHostImpl::PinchGestureBegin() { @@ -3294,7 +3284,7 @@ void LayerTreeHostImpl::PinchGestureBegin() { client_->RenewTreePriority(); pinch_gesture_end_should_clear_scrolling_layer_ = !CurrentlyScrollingLayer(); active_tree_->SetCurrentlyScrollingLayer(viewport()->MainScrollLayer()); - top_controls_manager_->PinchBegin(); + browser_controls_offset_manager_->PinchBegin(); } void LayerTreeHostImpl::PinchGestureUpdate(float magnify_delta, @@ -3318,7 +3308,7 @@ void LayerTreeHostImpl::PinchGestureEnd() { ClearCurrentlyScrollingLayer(); } viewport()->PinchEnd(); - top_controls_manager_->PinchEnd(); + browser_controls_offset_manager_->PinchEnd(); client_->SetNeedsCommitOnImplThread(); // When a pinch ends, we may be displaying content cached at incorrect scales, // so updating draw properties and drawing will ensure we are using the right @@ -3348,14 +3338,26 @@ static void CollectScrollDeltas(ScrollAndScaleSet* scroll_info, ? tree_impl->InnerViewportScrollLayer()->id() : Layer::INVALID_ID; - return tree_impl->property_trees()->scroll_tree.CollectScrollDeltas( + tree_impl->property_trees()->scroll_tree.CollectScrollDeltas( scroll_info, inner_viewport_layer_id); } +static void CollectScrollbarUpdates( + ScrollAndScaleSet* scroll_info, + std::unordered_map<int, std::unique_ptr<ScrollbarAnimationController>>* + controllers) { + scroll_info->scrollbars.reserve(controllers->size()); + for (auto& pair : *controllers) { + scroll_info->scrollbars.push_back(LayerTreeHostCommon::ScrollbarsUpdateInfo( + pair.first, pair.second->ScrollbarsHidden())); + } +} + std::unique_ptr<ScrollAndScaleSet> LayerTreeHostImpl::ProcessScrollDeltas() { std::unique_ptr<ScrollAndScaleSet> scroll_info(new ScrollAndScaleSet()); CollectScrollDeltas(scroll_info.get(), active_tree_.get()); + CollectScrollbarUpdates(scroll_info.get(), &scrollbar_animation_controllers_); scroll_info->page_scale_delta = active_tree_->page_scale_factor()->PullDeltaForMainThread(); scroll_info->top_controls_delta = @@ -3399,13 +3401,13 @@ bool LayerTreeHostImpl::AnimatePageScale(base::TimeTicks monotonic_time) { return true; } -bool LayerTreeHostImpl::AnimateTopControls(base::TimeTicks time) { - if (!top_controls_manager_->has_animation()) +bool LayerTreeHostImpl::AnimateBrowserControls(base::TimeTicks time) { + if (!browser_controls_offset_manager_->has_animation()) return false; - gfx::Vector2dF scroll = top_controls_manager_->Animate(time); + gfx::Vector2dF scroll = browser_controls_offset_manager_->Animate(time); - if (top_controls_manager_->has_animation()) + if (browser_controls_offset_manager_->has_animation()) SetNeedsOneBeginImplFrame(); if (active_tree_->TotalScrollOffset().y() == 0.f) @@ -3415,7 +3417,7 @@ bool LayerTreeHostImpl::AnimateTopControls(base::TimeTicks time) { return false; DCHECK(viewport()); - viewport()->ScrollBy(scroll, gfx::Point(), false, false); + viewport()->ScrollBy(scroll, gfx::Point(), false, false, true); client_->SetNeedsCommitOnImplThread(); client_->RenewTreePriority(); return true; @@ -3429,7 +3431,7 @@ bool LayerTreeHostImpl::AnimateScrollbars(base::TimeTicks monotonic_time) { } bool LayerTreeHostImpl::AnimateLayers(base::TimeTicks monotonic_time) { - const bool animated = animation_host_->AnimateLayers(monotonic_time); + const bool animated = mutator_host_->AnimateLayers(monotonic_time); // TODO(crbug.com/551134): Only do this if the animations are on the active // tree, or if they are on the pending tree waiting for some future time to @@ -3446,12 +3448,12 @@ bool LayerTreeHostImpl::AnimateLayers(base::TimeTicks monotonic_time) { } void LayerTreeHostImpl::UpdateAnimationState(bool start_ready_animations) { - std::unique_ptr<AnimationEvents> events = animation_host_->CreateEvents(); + std::unique_ptr<MutatorEvents> events = mutator_host_->CreateEvents(); - const bool has_active_animations = animation_host_->UpdateAnimationState( - start_ready_animations, events.get()); + const bool has_active_animations = + mutator_host_->UpdateAnimationState(start_ready_animations, events.get()); - if (!events->events_.empty()) + if (!events->IsEmpty()) client_->PostAnimationEventsToMainThreadOnImplThread(std::move(events)); if (has_active_animations) @@ -3459,7 +3461,7 @@ void LayerTreeHostImpl::UpdateAnimationState(bool start_ready_animations) { } void LayerTreeHostImpl::ActivateAnimations() { - const bool activated = animation_host_->ActivateAnimations(); + const bool activated = mutator_host_->ActivateAnimations(); if (activated) { // Activating an animation changes layer draw properties, such as // screen_space_transform_is_animating. So when we see a new animation get @@ -3830,7 +3832,7 @@ void LayerTreeHostImpl::UpdateRootLayerStateForSynchronousInputHandler() { } void LayerTreeHostImpl::ScrollAnimationAbort(LayerImpl* layer_impl) { - return animation_host_->ScrollAnimationAbort(false /* needs_completion */); + return mutator_host_->ScrollAnimationAbort(false /* needs_completion */); } bool LayerTreeHostImpl::ScrollAnimationUpdateTarget( @@ -3841,7 +3843,7 @@ bool LayerTreeHostImpl::ScrollAnimationUpdateTarget( ElementId(active_tree()->LayerById(scroll_node->owner_id)->element_id()), scroll_node->element_id); - return animation_host_->ImplOnlyScrollAnimationUpdateTarget( + return mutator_host_->ImplOnlyScrollAnimationUpdateTarget( scroll_node->element_id, scroll_delta, active_tree_->property_trees()->scroll_tree.MaxScrollOffset( scroll_node->id), @@ -3948,7 +3950,11 @@ void LayerTreeHostImpl::SetTreeLayerScrollOffsetMutated( bool LayerTreeHostImpl::AnimationsPreserveAxisAlignment( const LayerImpl* layer) const { - return animation_host_->AnimationsPreserveAxisAlignment(layer->element_id()); + return mutator_host_->AnimationsPreserveAxisAlignment(layer->element_id()); +} + +void LayerTreeHostImpl::SetNeedUpdateGpuRasterizationStatus() { + need_update_gpu_rasterization_status_ = true; } void LayerTreeHostImpl::SetElementFilterMutated( @@ -4041,46 +4047,37 @@ bool LayerTreeHostImpl::CommitToActiveTree() const { return !task_runner_provider_->HasImplThread(); } -void LayerTreeHostImpl::SetCompositorContextVisibility(bool is_visible) { +void LayerTreeHostImpl::SetContextVisibility(bool is_visible) { if (!compositor_frame_sink_) return; + // Update the compositor context. If we are already in the correct visibility + // state, skip. This can happen if we transition invisible/visible rapidly, + // before we get a chance to go invisible in NotifyAllTileTasksComplete. auto* compositor_context = compositor_frame_sink_->context_provider(); - if (!compositor_context) - return; - - DCHECK_NE(is_visible, !!compositor_context_visibility_); - - if (is_visible) { - compositor_context_visibility_ = - compositor_context->CacheController()->ClientBecameVisible(); - } else { - compositor_context->CacheController()->ClientBecameNotVisible( - std::move(compositor_context_visibility_)); + if (compositor_context && is_visible != !!compositor_context_visibility_) { + if (is_visible) { + compositor_context_visibility_ = + compositor_context->CacheController()->ClientBecameVisible(); + } else { + compositor_context->CacheController()->ClientBecameNotVisible( + std::move(compositor_context_visibility_)); + } } -} - -void LayerTreeHostImpl::SetWorkerContextVisibility(bool is_visible) { - if (!compositor_frame_sink_) - return; + // Update the worker context. If we are already in the correct visibility + // state, skip. This can happen if we transition invisible/visible rapidly, + // before we get a chance to go invisible in NotifyAllTileTasksComplete. auto* worker_context = compositor_frame_sink_->worker_context_provider(); - if (!worker_context) - return; - - // TODO(ericrk): This check is here because worker context visibility is a - // bit less controlled, being settable both by memory policy changes as well - // as direct visibility changes. We should simplify this. crbug.com/642154 - if (is_visible == !!worker_context_visibility_) - return; - - ContextProvider::ScopedContextLock hold(worker_context); - if (is_visible) { - worker_context_visibility_ = - worker_context->CacheController()->ClientBecameVisible(); - } else { - worker_context->CacheController()->ClientBecameNotVisible( - std::move(worker_context_visibility_)); + if (worker_context && is_visible != !!worker_context_visibility_) { + ContextProvider::ScopedContextLock hold(worker_context); + if (is_visible) { + worker_context_visibility_ = + worker_context->CacheController()->ClientBecameVisible(); + } else { + worker_context->CacheController()->ClientBecameNotVisible( + std::move(worker_context_visibility_)); + } } } diff --git a/chromium/cc/trees/layer_tree_host_impl.h b/chromium/cc/trees/layer_tree_host_impl.h index fcf74d005d3..189de43f689 100644 --- a/chromium/cc/trees/layer_tree_host_impl.h +++ b/chromium/cc/trees/layer_tree_host_impl.h @@ -17,13 +17,12 @@ #include "base/callback.h" #include "base/macros.h" #include "base/time/time.h" -#include "cc/animation/layer_tree_mutator.h" #include "cc/base/cc_export.h" #include "cc/base/synced_property.h" #include "cc/debug/micro_benchmark_controller_impl.h" +#include "cc/input/browser_controls_offset_manager_client.h" #include "cc/input/input_handler.h" #include "cc/input/scrollbar_animation_controller.h" -#include "cc/input/top_controls_manager_client.h" #include "cc/layers/layer_collections.h" #include "cc/layers/render_pass_sink.h" #include "cc/output/begin_frame_args.h" @@ -39,6 +38,7 @@ #include "cc/scheduler/video_frame_controller.h" #include "cc/tiles/image_decode_controller.h" #include "cc/tiles/tile_manager.h" +#include "cc/trees/layer_tree_mutator.h" #include "cc/trees/layer_tree_settings.h" #include "cc/trees/mutator_host_client.h" #include "cc/trees/task_runner_provider.h" @@ -50,9 +50,7 @@ class ScrollOffset; namespace cc { -class AnimationEvents; -class AnimationHost; -class CompletionEvent; +class BrowserControlsOffsetManager; class CompositorFrameMetadata; class CompositorFrameSink; class DebugRectHistory; @@ -61,25 +59,20 @@ class FrameRateCounter; class LayerImpl; class LayerTreeImpl; class MemoryHistory; +class MutatorEvents; +class MutatorHost; class PageScaleAnimation; class PendingTreeDurationHistogramTimer; -class PictureLayerImpl; class RasterTilePriorityQueue; -class TileTaskManager; class RasterBufferProvider; -class RenderPassDrawQuad; class RenderingStatsInstrumentation; class ResourcePool; class ScrollElasticityHelper; -class ScrollbarLayerImplBase; class SwapPromise; class SwapPromiseMonitor; class SynchronousTaskGraphRunner; class TaskGraphRunner; -class TextureMailboxDeleter; -class TopControlsManager; class UIResourceBitmap; -class UIResourceRequest; struct ScrollAndScaleSet; class Viewport; @@ -99,7 +92,7 @@ class LayerTreeHostImplClient { public: virtual void DidLoseCompositorFrameSinkOnImplThread() = 0; virtual void SetBeginFrameSource(BeginFrameSource* source) = 0; - virtual void DidSwapBuffersCompleteOnImplThread() = 0; + virtual void DidReceiveCompositorFrameAckOnImplThread() = 0; virtual void OnCanDrawStateChanged(bool can_draw) = 0; virtual void NotifyReadyToActivate() = 0; virtual void NotifyReadyToDraw() = 0; @@ -111,7 +104,7 @@ class LayerTreeHostImplClient { virtual void SetNeedsPrepareTilesOnImplThread() = 0; virtual void SetVideoNeedsBeginFrames(bool needs_begin_frames) = 0; virtual void PostAnimationEventsToMainThreadOnImplThread( - std::unique_ptr<AnimationEvents> events) = 0; + std::unique_ptr<MutatorEvents> events) = 0; virtual bool IsInsideDraw() = 0; virtual void RenewTreePriority() = 0; virtual void PostDelayedAnimationTaskOnImplThread(const base::Closure& task, @@ -137,7 +130,7 @@ class CC_EXPORT LayerTreeHostImpl : public InputHandler, public TileManagerClient, public CompositorFrameSinkClient, - public TopControlsManagerClient, + public BrowserControlsOffsetManagerClient, public ScrollbarAnimationControllerClient, public VideoFrameControllerClient, public LayerTreeMutatorClient, @@ -149,10 +142,8 @@ class CC_EXPORT LayerTreeHostImpl LayerTreeHostImplClient* client, TaskRunnerProvider* task_runner_provider, RenderingStatsInstrumentation* rendering_stats_instrumentation, - SharedBitmapManager* shared_bitmap_manager, - gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, TaskGraphRunner* task_graph_runner, - std::unique_ptr<AnimationHost> animation_host, + std::unique_ptr<MutatorHost> mutator_host, int id); ~LayerTreeHostImpl() override; @@ -180,6 +171,7 @@ class CC_EXPORT LayerTreeHostImpl void MouseDown() override; void MouseUp() override; void MouseMoveAt(const gfx::Point& viewport_point) override; + void MouseLeave() override; void PinchGestureBegin() override; void PinchGestureUpdate(float magnify_delta, @@ -204,12 +196,12 @@ class CC_EXPORT LayerTreeHostImpl gfx::ScrollOffset* offset) override; bool ScrollLayerTo(int layer_id, const gfx::ScrollOffset& offset) override; - // TopControlsManagerClient implementation. + // BrowserControlsOffsetManagerClient implementation. float TopControlsHeight() const override; float BottomControlsHeight() const override; - void SetCurrentTopControlsShownRatio(float offset) override; - float CurrentTopControlsShownRatio() const override; - void DidChangeTopControlsPosition() override; + void SetCurrentBrowserControlsShownRatio(float offset) override; + float CurrentBrowserControlsShownRatio() const override; + void DidChangeBrowserControlsPosition() override; bool HaveRootScrollLayer() const override; void UpdateViewportContainerSizes(); @@ -267,6 +259,7 @@ class CC_EXPORT LayerTreeHostImpl LayerTreeImpl* tree, const gfx::ScrollOffset& scroll_offset); bool AnimationsPreserveAxisAlignment(const LayerImpl* layer) const; + void SetNeedUpdateGpuRasterizationStatus(); // MutatorHostClient implementation. bool IsElementInList(ElementId element_id, @@ -354,6 +347,7 @@ class CC_EXPORT LayerTreeHostImpl void SetNeedsAnimateForScrollbarAnimation() override; void SetNeedsRedrawForScrollbarAnimation() override; ScrollbarSet ScrollbarsFor(int scroll_layer_id) const override; + void DidChangeScrollbarVisibility() override; // VideoBeginFrameSource implementation. void AddVideoFrameController(VideoFrameController* controller) override; @@ -365,7 +359,7 @@ class CC_EXPORT LayerTreeHostImpl const gfx::Rect& viewport_rect, const gfx::Transform& transform) override; void DidLoseCompositorFrameSink() override; - void DidSwapBuffersComplete() override; + void DidReceiveCompositorFrameAck() override; void ReclaimResources(const ReturnedResourceArray& resources) override; void SetMemoryPolicy(const ManagedMemoryPolicy& policy) override; void SetTreeActivationCallback(const base::Closure& callback) override; @@ -437,9 +431,6 @@ class CC_EXPORT LayerTreeHostImpl LayerImpl* OuterViewportScrollLayer() const; LayerImpl* CurrentlyScrollingLayer() const; - int scroll_layer_id_when_mouse_over_scrollbar() const { - return scroll_layer_id_when_mouse_over_scrollbar_; - } bool scroll_affects_scroll_handler() const { return scroll_affects_scroll_handler_; } @@ -474,8 +465,8 @@ class CC_EXPORT LayerTreeHostImpl MemoryHistory* memory_history() { return memory_history_.get(); } DebugRectHistory* debug_rect_history() { return debug_rect_history_.get(); } ResourceProvider* resource_provider() { return resource_provider_.get(); } - TopControlsManager* top_controls_manager() { - return top_controls_manager_.get(); + BrowserControlsOffsetManager* browser_controls_manager() { + return browser_controls_offset_manager_.get(); } const GlobalStateThatImpactsTilePriority& global_tile_state() { return global_tile_state_; @@ -485,7 +476,7 @@ class CC_EXPORT LayerTreeHostImpl return task_runner_provider_; } - AnimationHost* animation_host() const { return animation_host_.get(); } + MutatorHost* mutator_host() const { return mutator_host_.get(); } void SetDebugState(const LayerTreeDebugState& new_debug_state); const LayerTreeDebugState& debug_state() const { return debug_state_; } @@ -594,16 +585,16 @@ class CC_EXPORT LayerTreeHostImpl void SetLayerTreeMutator(std::unique_ptr<LayerTreeMutator> mutator); LayerTreeMutator* mutator() { return mutator_.get(); } + LayerImpl* ViewportMainScrollLayer(); + protected: LayerTreeHostImpl( const LayerTreeSettings& settings, LayerTreeHostImplClient* client, TaskRunnerProvider* task_runner_provider, RenderingStatsInstrumentation* rendering_stats_instrumentation, - SharedBitmapManager* shared_bitmap_manager, - gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, TaskGraphRunner* task_graph_runner, - std::unique_ptr<AnimationHost> animation_host, + std::unique_ptr<MutatorHost> mutator_host, int id); // Virtual for testing. @@ -650,7 +641,7 @@ class CC_EXPORT LayerTreeHostImpl bool AnimatePageScale(base::TimeTicks monotonic_time); bool AnimateScrollbars(base::TimeTicks monotonic_time); - bool AnimateTopControls(base::TimeTicks monotonic_time); + bool AnimateBrowserControls(base::TimeTicks monotonic_time); void TrackDamageForAllSurfaces( const LayerImplList& render_surface_layer_list); @@ -664,8 +655,6 @@ class CC_EXPORT LayerTreeHostImpl void ClearCurrentlyScrollingLayer(); - void HandleMouseOverScrollbar(LayerImpl* layer_impl); - LayerImpl* FindScrollLayerForDeviceViewportPoint( const gfx::PointF& device_viewport_point, InputHandler::ScrollInputType type, @@ -691,8 +680,7 @@ class CC_EXPORT LayerTreeHostImpl const gfx::Vector2dF& scroll_delta, base::TimeDelta delayed_by); - void SetCompositorContextVisibility(bool is_visible); - void SetWorkerContextVisibility(bool is_visible); + void SetContextVisibility(bool is_visible); using UIResourceMap = std::unordered_map<UIResourceId, UIResourceData>; UIResourceMap ui_resource_map_; @@ -721,7 +709,6 @@ class CC_EXPORT LayerTreeHostImpl bool use_msaa_; GpuRasterizationStatus gpu_rasterization_status_; std::unique_ptr<RasterBufferProvider> raster_buffer_provider_; - std::unique_ptr<TileTaskManager> tile_task_manager_; std::unique_ptr<ResourcePool> resource_pool_; std::unique_ptr<ImageDecodeController> image_decode_controller_; @@ -742,8 +729,7 @@ class CC_EXPORT LayerTreeHostImpl bool did_lock_scrolling_layer_; bool wheel_scrolling_; bool scroll_affects_scroll_handler_; - int scroll_layer_id_when_mouse_over_scrollbar_; - int captured_scrollbar_layer_id_; + int scroll_layer_id_mouse_currently_over_; std::vector<std::unique_ptr<SwapPromise>> swap_promises_for_main_thread_scroll_update_; @@ -767,7 +753,8 @@ class CC_EXPORT LayerTreeHostImpl bool pinch_gesture_active_; bool pinch_gesture_end_should_clear_scrolling_layer_; - std::unique_ptr<TopControlsManager> top_controls_manager_; + std::unique_ptr<BrowserControlsOffsetManager> + browser_controls_offset_manager_; std::unique_ptr<PageScaleAnimation> page_scale_animation_; @@ -798,7 +785,7 @@ class CC_EXPORT LayerTreeHostImpl gfx::Rect viewport_damage_rect_; - std::unique_ptr<AnimationHost> animation_host_; + std::unique_ptr<MutatorHost> mutator_host_; std::set<VideoFrameController*> video_frame_controllers_; // Map from scroll layer ID to scrollbar animation controller. @@ -814,8 +801,6 @@ class CC_EXPORT LayerTreeHostImpl // Optional callback to notify of new tree activations. base::Closure tree_activation_callback_; - SharedBitmapManager* shared_bitmap_manager_; - gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager_; TaskGraphRunner* task_graph_runner_; int id_; diff --git a/chromium/cc/trees/layer_tree_host_impl_unittest.cc b/chromium/cc/trees/layer_tree_host_impl_unittest.cc index c9aa95ec5f8..f2702a30d84 100644 --- a/chromium/cc/trees/layer_tree_host_impl_unittest.cc +++ b/chromium/cc/trees/layer_tree_host_impl_unittest.cc @@ -15,15 +15,14 @@ #include "base/location.h" #include "base/memory/ptr_util.h" #include "base/threading/thread_task_runner_handle.h" -#include "cc/animation/animation_events.h" #include "cc/animation/animation_host.h" #include "cc/animation/animation_id_provider.h" #include "cc/animation/transform_operations.h" #include "cc/base/math_util.h" +#include "cc/input/browser_controls_offset_manager.h" #include "cc/input/main_thread_scrolling_reason.h" #include "cc/input/page_scale_animation.h" #include "cc/input/scrollbar_animation_controller_thinning.h" -#include "cc/input/top_controls_manager.h" #include "cc/layers/append_quads_data.h" #include "cc/layers/heads_up_display_layer_impl.h" #include "cc/layers/layer_impl.h" @@ -60,13 +59,12 @@ #include "cc/test/layer_test_common.h" #include "cc/test/layer_tree_test.h" #include "cc/test/test_compositor_frame_sink.h" -#include "cc/test/test_gpu_memory_buffer_manager.h" -#include "cc/test/test_shared_bitmap_manager.h" #include "cc/test/test_task_graph_runner.h" #include "cc/test/test_web_graphics_context_3d.h" #include "cc/trees/effect_node.h" #include "cc/trees/layer_tree_host_common.h" #include "cc/trees/layer_tree_impl.h" +#include "cc/trees/mutator_host.h" #include "cc/trees/single_thread_proxy.h" #include "cc/trees/transform_node.h" #include "media/base/media.h" @@ -116,7 +114,6 @@ class LayerTreeHostImplTest : public testing::Test, settings.renderer_settings.texture_id_allocation_chunk_size = 1; settings.gpu_rasterization_enabled = true; settings.verify_clip_tree_calculations = true; - settings.verify_transform_tree_calculations = true; settings.renderer_settings.buffer_to_texture_target_map = DefaultBufferToTextureTargetMapForTesting(); return settings; @@ -133,7 +130,7 @@ class LayerTreeHostImplTest : public testing::Test, void DidLoseCompositorFrameSinkOnImplThread() override {} void SetBeginFrameSource(BeginFrameSource* source) override {} - void DidSwapBuffersCompleteOnImplThread() override {} + void DidReceiveCompositorFrameAckOnImplThread() override {} void OnCanDrawStateChanged(bool can_draw) override { on_can_draw_state_changed_called_ = true; } @@ -152,7 +149,7 @@ class LayerTreeHostImplTest : public testing::Test, void SetNeedsCommitOnImplThread() override { did_request_commit_ = true; } void SetVideoNeedsBeginFrames(bool needs_begin_frames) override {} void PostAnimationEventsToMainThreadOnImplThread( - std::unique_ptr<AnimationEvents> events) override {} + std::unique_ptr<MutatorEvents> events) override {} bool IsInsideDraw() override { return false; } void RenewTreePriority() override {} void PostDelayedAnimationTaskOnImplThread(const base::Closure& task, @@ -188,6 +185,10 @@ class LayerTreeHostImplTest : public testing::Test, settings, std::move(compositor_frame_sink), &task_runner_provider_); } + AnimationHost* GetImplAnimationHost() const { + return static_cast<AnimationHost*>(host_impl_->mutator_host()); + } + virtual bool CreateHostImplWithTaskRunnerProvider( const LayerTreeSettings& settings, std::unique_ptr<CompositorFrameSink> compositor_frame_sink, @@ -196,7 +197,6 @@ class LayerTreeHostImplTest : public testing::Test, host_impl_->ReleaseCompositorFrameSink(); host_impl_ = LayerTreeHostImpl::Create( settings, this, task_runner_provider, &stats_instrumentation_, - &shared_bitmap_manager_, &gpu_memory_buffer_manager_, &task_graph_runner_, AnimationHost::CreateForTesting(ThreadInstance::IMPL), 0); compositor_frame_sink_ = std::move(compositor_frame_sink); @@ -212,7 +212,7 @@ class LayerTreeHostImplTest : public testing::Test, timeline_ = AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); - host_impl_->animation_host()->AddAnimationTimeline(timeline_); + GetImplAnimationHost()->AddAnimationTimeline(timeline_); return init; } @@ -497,8 +497,6 @@ class LayerTreeHostImplTest : public testing::Test, FakeImplTaskRunnerProvider task_runner_provider_; DebugScopedSetMainThreadBlocked always_main_thread_blocked_; - TestSharedBitmapManager shared_bitmap_manager_; - TestGpuMemoryBufferManager gpu_memory_buffer_manager_; TestTaskGraphRunner task_graph_runner_; std::unique_ptr<CompositorFrameSink> compositor_frame_sink_; std::unique_ptr<LayerTreeHostImpl> host_impl_; @@ -2659,15 +2657,12 @@ class LayerTreeHostImplOverridePhysicalTime : public LayerTreeHostImpl { const LayerTreeSettings& settings, LayerTreeHostImplClient* client, TaskRunnerProvider* task_runner_provider, - SharedBitmapManager* manager, TaskGraphRunner* task_graph_runner, RenderingStatsInstrumentation* rendering_stats_instrumentation) : LayerTreeHostImpl(settings, client, task_runner_provider, rendering_stats_instrumentation, - manager, - nullptr, task_graph_runner, AnimationHost::CreateForTesting(ThreadInstance::IMPL), 0) {} @@ -2695,8 +2690,8 @@ class LayerTreeHostImplTestScrollbarAnimation : public LayerTreeHostImplTest { LayerTreeHostImplOverridePhysicalTime* host_impl_override_time = new LayerTreeHostImplOverridePhysicalTime( - settings, this, &task_runner_provider_, &shared_bitmap_manager_, - &task_graph_runner_, &stats_instrumentation_); + settings, this, &task_runner_provider_, &task_graph_runner_, + &stats_instrumentation_); host_impl_ = base::WrapUnique(host_impl_override_time); compositor_frame_sink_ = CreateCompositorFrameSink(); host_impl_->SetVisible(true); @@ -2725,8 +2720,8 @@ class LayerTreeHostImplTestScrollbarAnimation : public LayerTreeHostImplTest { void RunTest(LayerTreeSettings::ScrollbarAnimator animator) { LayerTreeSettings settings = DefaultSettings(); settings.scrollbar_animator = animator; - settings.scrollbar_fade_delay_ms = 20; - settings.scrollbar_fade_duration_ms = 20; + settings.scrollbar_fade_delay = base::TimeDelta::FromMilliseconds(20); + settings.scrollbar_fade_duration = base::TimeDelta::FromMilliseconds(20); // If no animator is set, scrollbar won't show and no animation is expected. bool expecting_animations = animator != LayerTreeSettings::NO_ANIMATOR; @@ -2916,8 +2911,8 @@ class LayerTreeHostImplTestScrollbarOpacity : public LayerTreeHostImplTest { void RunTest(LayerTreeSettings::ScrollbarAnimator animator) { LayerTreeSettings settings = DefaultSettings(); settings.scrollbar_animator = animator; - settings.scrollbar_fade_delay_ms = 20; - settings.scrollbar_fade_duration_ms = 20; + settings.scrollbar_fade_delay = base::TimeDelta::FromMilliseconds(20); + settings.scrollbar_fade_duration = base::TimeDelta::FromMilliseconds(20); gfx::Size content_size(100, 100); // If no animator is set, scrollbar won't show and no animation is expected. @@ -3047,8 +3042,8 @@ TEST_F(LayerTreeHostImplTest, ScrollbarInnerLargerThanOuter) { TEST_F(LayerTreeHostImplTest, ScrollbarRegistration) { LayerTreeSettings settings = DefaultSettings(); settings.scrollbar_animator = LayerTreeSettings::LINEAR_FADE; - settings.scrollbar_fade_delay_ms = 20; - settings.scrollbar_fade_duration_ms = 20; + settings.scrollbar_fade_delay = base::TimeDelta::FromMilliseconds(20); + settings.scrollbar_fade_duration = base::TimeDelta::FromMilliseconds(20); CreateHostImpl(settings, CreateCompositorFrameSink()); gfx::Size viewport_size(300, 200); @@ -3167,8 +3162,8 @@ TEST_F(LayerTreeHostImplTest, ScrollbarRegistration) { void LayerTreeHostImplTest::SetupMouseMoveAtWithDeviceScale( float device_scale_factor) { LayerTreeSettings settings = DefaultSettings(); - settings.scrollbar_fade_delay_ms = 500; - settings.scrollbar_fade_duration_ms = 300; + settings.scrollbar_fade_delay = base::TimeDelta::FromMilliseconds(500); + settings.scrollbar_fade_duration = base::TimeDelta::FromMilliseconds(300); settings.scrollbar_animator = LayerTreeSettings::THINNING; gfx::Size viewport_size(300, 200); @@ -3223,15 +3218,13 @@ void LayerTreeHostImplTest::SetupMouseMoveAtWithDeviceScale( EXPECT_TRUE(scrollbar_animation_controller->mouse_is_near_scrollbar()); did_request_redraw_ = false; - EXPECT_EQ(Layer::INVALID_ID, - host_impl_->scroll_layer_id_when_mouse_over_scrollbar()); + EXPECT_FALSE(scrollbar_animation_controller->mouse_is_over_scrollbar()); host_impl_->MouseMoveAt(gfx::Point(10, 100)); - EXPECT_EQ(117, host_impl_->scroll_layer_id_when_mouse_over_scrollbar()); + EXPECT_TRUE(scrollbar_animation_controller->mouse_is_over_scrollbar()); host_impl_->MouseMoveAt(gfx::Point(10, 120)); - EXPECT_EQ(117, host_impl_->scroll_layer_id_when_mouse_over_scrollbar()); + EXPECT_TRUE(scrollbar_animation_controller->mouse_is_over_scrollbar()); host_impl_->MouseMoveAt(gfx::Point(150, 120)); - EXPECT_EQ(Layer::INVALID_ID, - host_impl_->scroll_layer_id_when_mouse_over_scrollbar()); + EXPECT_FALSE(scrollbar_animation_controller->mouse_is_over_scrollbar()); } TEST_F(LayerTreeHostImplTest, MouseMoveAtWithDeviceScaleOf1) { @@ -3898,9 +3891,9 @@ TEST_F(LayerTreeHostImplTest, ClampingAfterActivation) { EXPECT_EQ(active_outer_layer->CurrentScrollOffset(), gfx::ScrollOffset(0, 0)); } -class LayerTreeHostImplTopControlsTest : public LayerTreeHostImplTest { +class LayerTreeHostImplBrowserControlsTest : public LayerTreeHostImplTest { public: - LayerTreeHostImplTopControlsTest() + LayerTreeHostImplBrowserControlsTest() // Make the clip size the same as the layer (content) size so the layer is // non-scrollable. : layer_size_(10, 10), @@ -3917,33 +3910,33 @@ class LayerTreeHostImplTopControlsTest : public LayerTreeHostImplTest { settings, std::move(compositor_frame_sink)); if (init) { host_impl_->active_tree()->set_top_controls_height(top_controls_height_); - host_impl_->active_tree()->SetCurrentTopControlsShownRatio(1.f); + host_impl_->active_tree()->SetCurrentBrowserControlsShownRatio(1.f); host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 1.f); } return init; } - void SetupTopControlsAndScrollLayerWithVirtualViewport( + void SetupBrowserControlsAndScrollLayerWithVirtualViewport( const gfx::Size& inner_viewport_size, const gfx::Size& outer_viewport_size, const gfx::Size& scroll_layer_size) { settings_ = DefaultSettings(); CreateHostImpl(settings_, CreateCompositorFrameSink()); - SetupTopControlsAndScrollLayerWithVirtualViewport( + SetupBrowserControlsAndScrollLayerWithVirtualViewport( host_impl_->active_tree(), inner_viewport_size, outer_viewport_size, scroll_layer_size); } - void SetupTopControlsAndScrollLayerWithVirtualViewport( + void SetupBrowserControlsAndScrollLayerWithVirtualViewport( LayerTreeImpl* tree_impl, const gfx::Size& inner_viewport_size, const gfx::Size& outer_viewport_size, const gfx::Size& scroll_layer_size) { - tree_impl->set_top_controls_shrink_blink_size(true); + tree_impl->set_browser_controls_shrink_blink_size(true); tree_impl->set_top_controls_height(top_controls_height_); - tree_impl->SetCurrentTopControlsShownRatio(1.f); + tree_impl->SetCurrentBrowserControlsShownRatio(1.f); tree_impl->PushPageScaleFromMainThread(1.f, 1.f, 1.f); - host_impl_->DidChangeTopControlsPosition(); + host_impl_->DidChangeBrowserControlsPosition(); std::unique_ptr<LayerImpl> root = LayerImpl::Create(tree_impl, 1); std::unique_ptr<LayerImpl> root_clip = LayerImpl::Create(tree_impl, 2); @@ -3994,16 +3987,16 @@ class LayerTreeHostImplTopControlsTest : public LayerTreeHostImplTest { float top_controls_height_; LayerTreeSettings settings_; -}; // class LayerTreeHostImplTopControlsTest +}; // class LayerTreeHostImplBrowserControlsTest // Tests that, on a page with content the same size as the viewport, hiding -// the top controls also increases the ScrollableSize (i.e. the content size). -// Since the viewport got larger, the effective scrollable "content" also did. -// This ensures, for one thing, that the overscroll glow is shown in the right -// place. -TEST_F(LayerTreeHostImplTopControlsTest, - HidingTopControlsExpandsScrollableSize) { - SetupTopControlsAndScrollLayerWithVirtualViewport( +// the browser controls also increases the ScrollableSize (i.e. the content +// size). Since the viewport got larger, the effective scrollable "content" also +// did. This ensures, for one thing, that the overscroll glow is shown in the +// right place. +TEST_F(LayerTreeHostImplBrowserControlsTest, + HidingBrowserControlsExpandsScrollableSize) { + SetupBrowserControlsAndScrollLayerWithVirtualViewport( gfx::Size(50, 50), gfx::Size(50, 50), gfx::Size(50, 50)); LayerTreeImpl* active_tree = host_impl_->active_tree(); @@ -4022,7 +4015,8 @@ TEST_F(LayerTreeHostImplTopControlsTest, LayerImpl* inner_container = active_tree->InnerViewportContainerLayer(); LayerImpl* outer_container = active_tree->OuterViewportContainerLayer(); - // The top controls should start off showing so the viewport should be shrunk. + // The browser controls should start off showing so the viewport should be + // shrunk. ASSERT_EQ(gfx::Size(50, 50), inner_container->bounds()); ASSERT_EQ(gfx::Size(50, 50), outer_container->bounds()); @@ -4034,21 +4028,21 @@ TEST_F(LayerTreeHostImplTopControlsTest, InputHandler::TOUCHSCREEN) .thread); - host_impl_->top_controls_manager()->ScrollBegin(); + host_impl_->browser_controls_manager()->ScrollBegin(); - // Hide the top controls by a bit, the scrollable size should increase but the - // actual content bounds shouldn't. + // Hide the browser controls by a bit, the scrollable size should increase but + // the actual content bounds shouldn't. { - host_impl_->top_controls_manager()->ScrollBy(gfx::Vector2dF(0.f, 25.f)); + host_impl_->browser_controls_manager()->ScrollBy(gfx::Vector2dF(0.f, 25.f)); ASSERT_EQ(gfx::Size(50, 75), inner_container->bounds()); ASSERT_EQ(gfx::Size(50, 75), outer_container->bounds()); EXPECT_EQ(gfx::SizeF(50, 75), active_tree->ScrollableSize()); EXPECT_EQ(gfx::SizeF(50, 50), content->BoundsForScrolling()); } - // Fully hide the top controls. + // Fully hide the browser controls. { - host_impl_->top_controls_manager()->ScrollBy(gfx::Vector2dF(0.f, 25.f)); + host_impl_->browser_controls_manager()->ScrollBy(gfx::Vector2dF(0.f, 25.f)); ASSERT_EQ(gfx::Size(50, 100), inner_container->bounds()); ASSERT_EQ(gfx::Size(50, 100), outer_container->bounds()); EXPECT_EQ(gfx::SizeF(50, 100), active_tree->ScrollableSize()); @@ -4057,19 +4051,20 @@ TEST_F(LayerTreeHostImplTopControlsTest, // Scrolling additionally shouldn't have any effect. { - host_impl_->top_controls_manager()->ScrollBy(gfx::Vector2dF(0.f, 25.f)); + host_impl_->browser_controls_manager()->ScrollBy(gfx::Vector2dF(0.f, 25.f)); ASSERT_EQ(gfx::Size(50, 100), inner_container->bounds()); ASSERT_EQ(gfx::Size(50, 100), outer_container->bounds()); EXPECT_EQ(gfx::SizeF(50, 100), active_tree->ScrollableSize()); EXPECT_EQ(gfx::SizeF(50, 50), content->BoundsForScrolling()); } - host_impl_->top_controls_manager()->ScrollEnd(); + host_impl_->browser_controls_manager()->ScrollEnd(); host_impl_->ScrollEnd(EndState().get()); } -TEST_F(LayerTreeHostImplTopControlsTest, ScrollTopControlsByFractionalAmount) { - SetupTopControlsAndScrollLayerWithVirtualViewport( +TEST_F(LayerTreeHostImplBrowserControlsTest, + ScrollBrowserControlsByFractionalAmount) { + SetupBrowserControlsAndScrollLayerWithVirtualViewport( gfx::Size(10, 10), gfx::Size(10, 10), gfx::Size(10, 10)); DrawFrame(); @@ -4081,11 +4076,11 @@ TEST_F(LayerTreeHostImplTopControlsTest, ScrollTopControlsByFractionalAmount) { // Make the test scroll delta a fractional amount, to verify that the // fixed container size delta is (1) non-zero, and (2) fractional, and - // (3) matches the movement of the top controls. + // (3) matches the movement of the browser controls. gfx::Vector2dF top_controls_scroll_delta(0.f, 5.25f); - host_impl_->top_controls_manager()->ScrollBegin(); - host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); - host_impl_->top_controls_manager()->ScrollEnd(); + host_impl_->browser_controls_manager()->ScrollBegin(); + host_impl_->browser_controls_manager()->ScrollBy(top_controls_scroll_delta); + host_impl_->browser_controls_manager()->ScrollEnd(); LayerImpl* inner_viewport_scroll_layer = host_impl_->active_tree()->InnerViewportScrollLayer(); @@ -4096,11 +4091,12 @@ TEST_F(LayerTreeHostImplTopControlsTest, ScrollTopControlsByFractionalAmount) { } // In this test, the outer viewport is initially unscrollable. We test that a -// scroll initiated on the inner viewport, causing the top controls to show and -// thus making the outer viewport scrollable, still scrolls the outer viewport. -TEST_F(LayerTreeHostImplTopControlsTest, - TopControlsOuterViewportBecomesScrollable) { - SetupTopControlsAndScrollLayerWithVirtualViewport( +// scroll initiated on the inner viewport, causing the browser controls to show +// and thus making the outer viewport scrollable, still scrolls the outer +// viewport. +TEST_F(LayerTreeHostImplBrowserControlsTest, + BrowserControlsOuterViewportBecomesScrollable) { + SetupBrowserControlsAndScrollLayerWithVirtualViewport( gfx::Size(10, 50), gfx::Size(10, 50), gfx::Size(10, 100)); DrawFrame(); @@ -4127,9 +4123,9 @@ TEST_F(LayerTreeHostImplTopControlsTest, host_impl_->ScrollBy( UpdateState(gfx::Point(), gfx::Vector2dF(0.f, 50.f)).get()); - // The entire scroll delta should have been used to hide the top controls. + // The entire scroll delta should have been used to hide the browser controls. // The viewport layers should be resized back to their full sizes. - EXPECT_EQ(0.f, host_impl_->active_tree()->CurrentTopControlsShownRatio()); + EXPECT_EQ(0.f, host_impl_->active_tree()->CurrentBrowserControlsShownRatio()); EXPECT_EQ(0.f, inner_scroll->CurrentScrollOffset().y()); EXPECT_EQ(100.f, inner_container->BoundsForScrolling().height()); EXPECT_EQ(100.f, outer_container->BoundsForScrolling().height()); @@ -4148,15 +4144,15 @@ TEST_F(LayerTreeHostImplTopControlsTest, ->ScrollBegin(BeginState(gfx::Point()).get(), InputHandler::TOUCHSCREEN) .thread); - EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), inner_scroll); + EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), outer_scroll); host_impl_->ScrollBy( UpdateState(gfx::Point(), gfx::Vector2dF(0.f, -50.f)).get()); - // The entire scroll delta should have been used to show the top controls. + // The entire scroll delta should have been used to show the browser controls. // The outer viewport should be resized to accomodate and scrolled to the // bottom of the document to keep the viewport in place. - EXPECT_EQ(1.f, host_impl_->active_tree()->CurrentTopControlsShownRatio()); + EXPECT_EQ(1.f, host_impl_->active_tree()->CurrentBrowserControlsShownRatio()); EXPECT_EQ(50.f, outer_container->BoundsForScrolling().height()); EXPECT_EQ(50.f, inner_container->BoundsForScrolling().height()); EXPECT_EQ(25.f, outer_scroll->CurrentScrollOffset().y()); @@ -4183,9 +4179,9 @@ TEST_F(LayerTreeHostImplTopControlsTest, } // Test that the fixed position container delta is appropriately adjusted -// by the top controls showing/hiding and page scale doesn't affect it. -TEST_F(LayerTreeHostImplTopControlsTest, FixedContainerDelta) { - SetupTopControlsAndScrollLayerWithVirtualViewport( +// by the browser controls showing/hiding and page scale doesn't affect it. +TEST_F(LayerTreeHostImplBrowserControlsTest, FixedContainerDelta) { + SetupBrowserControlsAndScrollLayerWithVirtualViewport( gfx::Size(100, 100), gfx::Size(100, 100), gfx::Size(100, 100)); DrawFrame(); host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 2.f); @@ -4204,43 +4200,43 @@ TEST_F(LayerTreeHostImplTopControlsTest, FixedContainerDelta) { InputHandler::TOUCHSCREEN) .thread); - // Scroll down, the top controls hiding should expand the viewport size so + // Scroll down, the browser controls hiding should expand the viewport size so // the delta should be equal to the scroll distance. gfx::Vector2dF top_controls_scroll_delta(0.f, 20.f); - host_impl_->top_controls_manager()->ScrollBegin(); - host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); + host_impl_->browser_controls_manager()->ScrollBegin(); + host_impl_->browser_controls_manager()->ScrollBy(top_controls_scroll_delta); EXPECT_FLOAT_EQ(top_controls_height_ - top_controls_scroll_delta.y(), - host_impl_->top_controls_manager()->ContentTopOffset()); + host_impl_->browser_controls_manager()->ContentTopOffset()); EXPECT_FLOAT_EQ(top_controls_scroll_delta.y(), outer_viewport_scroll_layer->FixedContainerSizeDelta().y()); host_impl_->ScrollEnd(EndState().get()); // Scroll past the maximum extent. The delta shouldn't be greater than the - // top controls height. - host_impl_->top_controls_manager()->ScrollBegin(); - host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); - host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); - host_impl_->top_controls_manager()->ScrollBy(top_controls_scroll_delta); - EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); + // browser controls height. + host_impl_->browser_controls_manager()->ScrollBegin(); + host_impl_->browser_controls_manager()->ScrollBy(top_controls_scroll_delta); + host_impl_->browser_controls_manager()->ScrollBy(top_controls_scroll_delta); + host_impl_->browser_controls_manager()->ScrollBy(top_controls_scroll_delta); + EXPECT_EQ(0.f, host_impl_->browser_controls_manager()->ContentTopOffset()); EXPECT_VECTOR_EQ(gfx::Vector2dF(0, top_controls_height_), outer_viewport_scroll_layer->FixedContainerSizeDelta()); host_impl_->ScrollEnd(EndState().get()); - // Scroll in the direction to make the top controls show. - host_impl_->top_controls_manager()->ScrollBegin(); - host_impl_->top_controls_manager()->ScrollBy(-top_controls_scroll_delta); + // Scroll in the direction to make the browser controls show. + host_impl_->browser_controls_manager()->ScrollBegin(); + host_impl_->browser_controls_manager()->ScrollBy(-top_controls_scroll_delta); EXPECT_EQ(top_controls_scroll_delta.y(), - host_impl_->top_controls_manager()->ContentTopOffset()); + host_impl_->browser_controls_manager()->ContentTopOffset()); EXPECT_VECTOR_EQ( gfx::Vector2dF(0, top_controls_height_ - top_controls_scroll_delta.y()), outer_viewport_scroll_layer->FixedContainerSizeDelta()); - host_impl_->top_controls_manager()->ScrollEnd(); + host_impl_->browser_controls_manager()->ScrollEnd(); } -// Push a top controls ratio from the main thread that we didn't send as a delta -// and make sure that the ratio is clamped to the [0, 1] range. -TEST_F(LayerTreeHostImplTopControlsTest, TopControlsPushUnsentRatio) { - SetupTopControlsAndScrollLayerWithVirtualViewport( +// Push a browser controls ratio from the main thread that we didn't send as a +// delta and make sure that the ratio is clamped to the [0, 1] range. +TEST_F(LayerTreeHostImplBrowserControlsTest, BrowserControlsPushUnsentRatio) { + SetupBrowserControlsAndScrollLayerWithVirtualViewport( gfx::Size(10, 50), gfx::Size(10, 50), gfx::Size(10, 100)); DrawFrame(); @@ -4252,28 +4248,30 @@ TEST_F(LayerTreeHostImplTopControlsTest, TopControlsPushUnsentRatio) { host_impl_->active_tree()->OuterViewportScrollLayer(); outer_scroll->SetDrawsContent(true); - host_impl_->active_tree()->PushTopControlsFromMainThread(1); - ASSERT_EQ(1.0f, host_impl_->active_tree()->CurrentTopControlsShownRatio()); + host_impl_->active_tree()->PushBrowserControlsFromMainThread(1); + ASSERT_EQ(1.0f, + host_impl_->active_tree()->CurrentBrowserControlsShownRatio()); - host_impl_->active_tree()->SetCurrentTopControlsShownRatio(0.5f); - ASSERT_EQ(0.5f, host_impl_->active_tree()->CurrentTopControlsShownRatio()); + host_impl_->active_tree()->SetCurrentBrowserControlsShownRatio(0.5f); + ASSERT_EQ(0.5f, + host_impl_->active_tree()->CurrentBrowserControlsShownRatio()); - host_impl_->active_tree()->PushTopControlsFromMainThread(0); + host_impl_->active_tree()->PushBrowserControlsFromMainThread(0); - ASSERT_EQ(0, host_impl_->active_tree()->CurrentTopControlsShownRatio()); + ASSERT_EQ(0, host_impl_->active_tree()->CurrentBrowserControlsShownRatio()); } -// Test that if only the top controls are scrolled, we shouldn't request a +// Test that if only the browser controls are scrolled, we shouldn't request a // commit. -TEST_F(LayerTreeHostImplTopControlsTest, TopControlsDontTriggerCommit) { - SetupTopControlsAndScrollLayerWithVirtualViewport( +TEST_F(LayerTreeHostImplBrowserControlsTest, BrowserControlsDontTriggerCommit) { + SetupBrowserControlsAndScrollLayerWithVirtualViewport( gfx::Size(100, 50), gfx::Size(100, 100), gfx::Size(100, 100)); DrawFrame(); - // Show top controls - EXPECT_EQ(1.f, host_impl_->active_tree()->CurrentTopControlsShownRatio()); + // Show browser controls + EXPECT_EQ(1.f, host_impl_->active_tree()->CurrentBrowserControlsShownRatio()); - // Scroll 25px to hide top controls + // Scroll 25px to hide browser controls gfx::Vector2dF scroll_delta(0.f, 25.f); EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, host_impl_ @@ -4285,16 +4283,17 @@ TEST_F(LayerTreeHostImplTopControlsTest, TopControlsDontTriggerCommit) { } // Test that if a scrollable sublayer doesn't consume the scroll, -// top controls should hide when scrolling down. -TEST_F(LayerTreeHostImplTopControlsTest, TopControlsScrollableSublayer) { +// browser controls should hide when scrolling down. +TEST_F(LayerTreeHostImplBrowserControlsTest, + BrowserControlsScrollableSublayer) { gfx::Size sub_content_size(100, 400); gfx::Size sub_content_layer_size(100, 300); - SetupTopControlsAndScrollLayerWithVirtualViewport( + SetupBrowserControlsAndScrollLayerWithVirtualViewport( gfx::Size(100, 50), gfx::Size(100, 100), gfx::Size(100, 100)); DrawFrame(); - // Show top controls - EXPECT_EQ(1.f, host_impl_->active_tree()->CurrentTopControlsShownRatio()); + // Show browser controls + EXPECT_EQ(1.f, host_impl_->active_tree()->CurrentBrowserControlsShownRatio()); LayerImpl* outer_viewport_scroll_layer = host_impl_->active_tree()->OuterViewportScrollLayer(); @@ -4319,7 +4318,7 @@ TEST_F(LayerTreeHostImplTopControlsTest, TopControlsScrollableSublayer) { std::move(child_clip)); host_impl_->active_tree()->BuildPropertyTreesForTesting(); - // Scroll 25px to hide top controls + // Scroll 25px to hide browser controls gfx::Vector2dF scroll_delta(0.f, 25.f); EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, host_impl_ @@ -4329,37 +4328,41 @@ TEST_F(LayerTreeHostImplTopControlsTest, TopControlsScrollableSublayer) { host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); host_impl_->ScrollEnd(EndState().get()); - // Top controls should be hidden + // Browser controls should be hidden EXPECT_EQ(scroll_delta.y(), top_controls_height_ - - host_impl_->top_controls_manager()->ContentTopOffset()); + host_impl_->browser_controls_manager()->ContentTopOffset()); } -// Ensure setting the top controls position explicitly using the setters on the -// TreeImpl correctly affects the top controls manager and viewport bounds. -TEST_F(LayerTreeHostImplTopControlsTest, PositionTopControlsExplicitly) { +// Ensure setting the browser controls position explicitly using the setters on +// the TreeImpl correctly affects the browser controls manager and viewport +// bounds. +TEST_F(LayerTreeHostImplBrowserControlsTest, + PositionBrowserControlsExplicitly) { settings_ = DefaultSettings(); CreateHostImpl(settings_, CreateCompositorFrameSink()); - SetupTopControlsAndScrollLayerWithVirtualViewport( + SetupBrowserControlsAndScrollLayerWithVirtualViewport( layer_size_, layer_size_, layer_size_); DrawFrame(); - host_impl_->active_tree()->SetCurrentTopControlsShownRatio(0.f); + host_impl_->active_tree()->SetCurrentBrowserControlsShownRatio(0.f); host_impl_->active_tree()->top_controls_shown_ratio()->PushFromMainThread( 30.f / top_controls_height_); host_impl_->active_tree()->top_controls_shown_ratio()->PushPendingToActive(); - EXPECT_FLOAT_EQ(30.f, host_impl_->top_controls_manager()->ContentTopOffset()); + EXPECT_FLOAT_EQ(30.f, + host_impl_->browser_controls_manager()->ContentTopOffset()); EXPECT_FLOAT_EQ(-20.f, - host_impl_->top_controls_manager()->ControlsTopOffset()); + host_impl_->browser_controls_manager()->ControlsTopOffset()); - host_impl_->active_tree()->SetCurrentTopControlsShownRatio(0.f); - EXPECT_FLOAT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); + host_impl_->active_tree()->SetCurrentBrowserControlsShownRatio(0.f); + EXPECT_FLOAT_EQ(0.f, + host_impl_->browser_controls_manager()->ContentTopOffset()); EXPECT_FLOAT_EQ(-50.f, - host_impl_->top_controls_manager()->ControlsTopOffset()); + host_impl_->browser_controls_manager()->ControlsTopOffset()); - host_impl_->DidChangeTopControlsPosition(); + host_impl_->DidChangeBrowserControlsPosition(); - // Now that top controls have moved, expect the clip to resize. + // Now that browser controls have moved, expect the clip to resize. LayerImpl* inner_clip_ptr = host_impl_->InnerViewportScrollLayer() ->test_properties() ->parent->test_properties() @@ -4368,34 +4371,34 @@ TEST_F(LayerTreeHostImplTopControlsTest, PositionTopControlsExplicitly) { } // Test that the top_controls delta and sent delta are appropriately -// applied on sync tree activation. The total top controls offset shouldn't +// applied on sync tree activation. The total browser controls offset shouldn't // change after the activation. -TEST_F(LayerTreeHostImplTopControlsTest, ApplyDeltaOnTreeActivation) { +TEST_F(LayerTreeHostImplBrowserControlsTest, ApplyDeltaOnTreeActivation) { settings_ = DefaultSettings(); CreateHostImpl(settings_, CreateCompositorFrameSink()); - SetupTopControlsAndScrollLayerWithVirtualViewport( + SetupBrowserControlsAndScrollLayerWithVirtualViewport( layer_size_, layer_size_, layer_size_); DrawFrame(); host_impl_->active_tree()->top_controls_shown_ratio()->PushFromMainThread( 20.f / top_controls_height_); host_impl_->active_tree()->top_controls_shown_ratio()->PushPendingToActive(); - host_impl_->active_tree()->SetCurrentTopControlsShownRatio( + host_impl_->active_tree()->SetCurrentBrowserControlsShownRatio( 15.f / top_controls_height_); host_impl_->active_tree() ->top_controls_shown_ratio() ->PullDeltaForMainThread(); - host_impl_->active_tree()->SetCurrentTopControlsShownRatio(0.f); - host_impl_->sync_tree()->PushTopControlsFromMainThread(15.f / - top_controls_height_); + host_impl_->active_tree()->SetCurrentBrowserControlsShownRatio(0.f); + host_impl_->sync_tree()->PushBrowserControlsFromMainThread( + 15.f / top_controls_height_); - host_impl_->DidChangeTopControlsPosition(); + host_impl_->DidChangeBrowserControlsPosition(); LayerImpl* inner_clip_ptr = host_impl_->InnerViewportScrollLayer() ->test_properties() ->parent->test_properties() ->parent; EXPECT_EQ(viewport_size_, inner_clip_ptr->bounds()); - EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); + EXPECT_EQ(0.f, host_impl_->browser_controls_manager()->ContentTopOffset()); host_impl_->ActivateSyncTree(); @@ -4403,7 +4406,7 @@ TEST_F(LayerTreeHostImplTopControlsTest, ApplyDeltaOnTreeActivation) { ->test_properties() ->parent->test_properties() ->parent; - EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); + EXPECT_EQ(0.f, host_impl_->browser_controls_manager()->ContentTopOffset()); EXPECT_EQ(viewport_size_, inner_clip_ptr->bounds()); EXPECT_FLOAT_EQ( @@ -4415,32 +4418,33 @@ TEST_F(LayerTreeHostImplTopControlsTest, ApplyDeltaOnTreeActivation) { top_controls_height_); } -// Test that changing the top controls layout height is correctly applied to -// the inner viewport container bounds. That is, the top controls layout +// Test that changing the browser controls layout height is correctly applied to +// the inner viewport container bounds. That is, the browser controls layout // height is the amount that the inner viewport container was shrunk outside -// the compositor to accommodate the top controls. -TEST_F(LayerTreeHostImplTopControlsTest, TopControlsLayoutHeightChanged) { +// the compositor to accommodate the browser controls. +TEST_F(LayerTreeHostImplBrowserControlsTest, + BrowserControlsLayoutHeightChanged) { settings_ = DefaultSettings(); CreateHostImpl(settings_, CreateCompositorFrameSink()); - SetupTopControlsAndScrollLayerWithVirtualViewport( + SetupBrowserControlsAndScrollLayerWithVirtualViewport( layer_size_, layer_size_, layer_size_); DrawFrame(); - host_impl_->sync_tree()->PushTopControlsFromMainThread(1.f); - host_impl_->sync_tree()->set_top_controls_shrink_blink_size(true); + host_impl_->sync_tree()->PushBrowserControlsFromMainThread(1.f); + host_impl_->sync_tree()->set_browser_controls_shrink_blink_size(true); host_impl_->active_tree()->top_controls_shown_ratio()->PushFromMainThread( 1.f); host_impl_->active_tree()->top_controls_shown_ratio()->PushPendingToActive(); - host_impl_->active_tree()->SetCurrentTopControlsShownRatio(0.f); + host_impl_->active_tree()->SetCurrentBrowserControlsShownRatio(0.f); - host_impl_->DidChangeTopControlsPosition(); + host_impl_->DidChangeBrowserControlsPosition(); LayerImpl* inner_clip_ptr = host_impl_->InnerViewportScrollLayer() ->test_properties() ->parent->test_properties() ->parent; EXPECT_EQ(viewport_size_, inner_clip_ptr->bounds()); - EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); + EXPECT_EQ(0.f, host_impl_->browser_controls_manager()->ContentTopOffset()); host_impl_->sync_tree()->root_layer_for_testing()->SetBounds( gfx::Size(inner_clip_ptr->bounds().width(), @@ -4452,34 +4456,36 @@ TEST_F(LayerTreeHostImplTopControlsTest, TopControlsLayoutHeightChanged) { ->test_properties() ->parent->test_properties() ->parent; - EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); + EXPECT_EQ(0.f, host_impl_->browser_controls_manager()->ContentTopOffset()); // The total bounds should remain unchanged since the bounds delta should // account for the difference between the layout height and the current - // top controls offset. + // browser controls offset. EXPECT_EQ(viewport_size_, inner_clip_ptr->bounds()); EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, 50.f), inner_clip_ptr->bounds_delta()); - host_impl_->active_tree()->SetCurrentTopControlsShownRatio(1.f); - host_impl_->DidChangeTopControlsPosition(); + host_impl_->active_tree()->SetCurrentBrowserControlsShownRatio(1.f); + host_impl_->DidChangeBrowserControlsPosition(); - EXPECT_EQ(1.f, host_impl_->top_controls_manager()->TopControlsShownRatio()); - EXPECT_EQ(50.f, host_impl_->top_controls_manager()->TopControlsHeight()); - EXPECT_EQ(50.f, host_impl_->top_controls_manager()->ContentTopOffset()); + EXPECT_EQ(1.f, + host_impl_->browser_controls_manager()->TopControlsShownRatio()); + EXPECT_EQ(50.f, host_impl_->browser_controls_manager()->TopControlsHeight()); + EXPECT_EQ(50.f, host_impl_->browser_controls_manager()->ContentTopOffset()); EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, 0.f), inner_clip_ptr->bounds_delta()); EXPECT_EQ(gfx::Size(viewport_size_.width(), viewport_size_.height() - 50.f), inner_clip_ptr->bounds()); } -// Test that showing/hiding the top controls when the viewport is fully scrolled -// doesn't incorrectly change the viewport offset due to clamping from changing -// viewport bounds. -TEST_F(LayerTreeHostImplTopControlsTest, TopControlsViewportOffsetClamping) { - SetupTopControlsAndScrollLayerWithVirtualViewport( +// Test that showing/hiding the browser controls when the viewport is fully +// scrolled doesn't incorrectly change the viewport offset due to clamping from +// changing viewport bounds. +TEST_F(LayerTreeHostImplBrowserControlsTest, + BrowserControlsViewportOffsetClamping) { + SetupBrowserControlsAndScrollLayerWithVirtualViewport( gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400)); DrawFrame(); - EXPECT_EQ(1.f, host_impl_->active_tree()->CurrentTopControlsShownRatio()); + EXPECT_EQ(1.f, host_impl_->active_tree()->CurrentBrowserControlsShownRatio()); LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer(); LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer(); @@ -4492,7 +4498,7 @@ TEST_F(LayerTreeHostImplTopControlsTest, TopControlsViewportOffsetClamping) { host_impl_->active_tree()->TotalScrollOffset(); EXPECT_EQ(host_impl_->active_tree()->TotalMaxScrollOffset(), viewport_offset); - // Hide the top controls by 25px. + // Hide the browser controls by 25px. gfx::Vector2dF scroll_delta(0.f, 25.f); EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, host_impl_ @@ -4501,16 +4507,17 @@ TEST_F(LayerTreeHostImplTopControlsTest, TopControlsViewportOffsetClamping) { .thread); host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); - // scrolling down at the max extents no longer hides the top controls - EXPECT_EQ(1.f, host_impl_->active_tree()->CurrentTopControlsShownRatio()); + // scrolling down at the max extents no longer hides the browser controls + EXPECT_EQ(1.f, host_impl_->active_tree()->CurrentBrowserControlsShownRatio()); - // forcefully hide the top controls by 25px - host_impl_->top_controls_manager()->ScrollBy(scroll_delta); + // forcefully hide the browser controls by 25px + host_impl_->browser_controls_manager()->ScrollBy(scroll_delta); host_impl_->ScrollEnd(EndState().get()); - EXPECT_FLOAT_EQ(scroll_delta.y(), - top_controls_height_ - - host_impl_->top_controls_manager()->ContentTopOffset()); + EXPECT_FLOAT_EQ( + scroll_delta.y(), + top_controls_height_ - + host_impl_->browser_controls_manager()->ContentTopOffset()); inner_scroll->ClampScrollToMaxScrollOffset(); outer_scroll->ClampScrollToMaxScrollOffset(); @@ -4521,7 +4528,7 @@ TEST_F(LayerTreeHostImplTopControlsTest, TopControlsViewportOffsetClamping) { viewport_offset = host_impl_->active_tree()->TotalScrollOffset(); - // Bring the top controls down by 25px. + // Bring the browser controls down by 25px. scroll_delta = gfx::Vector2dF(0.f, -25.f); EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, host_impl_ @@ -4542,16 +4549,16 @@ TEST_F(LayerTreeHostImplTopControlsTest, TopControlsViewportOffsetClamping) { host_impl_->active_tree()->TotalScrollOffset()); } -// Test that the top controls coming in and out maintains the same aspect ratio -// between the inner and outer viewports. -TEST_F(LayerTreeHostImplTopControlsTest, TopControlsAspectRatio) { - SetupTopControlsAndScrollLayerWithVirtualViewport( +// Test that the browser controls coming in and out maintains the same aspect +// ratio between the inner and outer viewports. +TEST_F(LayerTreeHostImplBrowserControlsTest, BrowserControlsAspectRatio) { + SetupBrowserControlsAndScrollLayerWithVirtualViewport( gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400)); host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 0.5f, 2.f); DrawFrame(); EXPECT_FLOAT_EQ(top_controls_height_, - host_impl_->top_controls_manager()->ContentTopOffset()); + host_impl_->browser_controls_manager()->ContentTopOffset()); gfx::Vector2dF scroll_delta(0.f, 25.f); EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, @@ -4562,12 +4569,13 @@ TEST_F(LayerTreeHostImplTopControlsTest, TopControlsAspectRatio) { host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); host_impl_->ScrollEnd(EndState().get()); - EXPECT_FLOAT_EQ(scroll_delta.y(), - top_controls_height_ - - host_impl_->top_controls_manager()->ContentTopOffset()); + EXPECT_FLOAT_EQ( + scroll_delta.y(), + top_controls_height_ - + host_impl_->browser_controls_manager()->ContentTopOffset()); - // Top controls were hidden by 25px so the inner viewport should have expanded - // by that much. + // Browser controls were hidden by 25px so the inner viewport should have + // expanded by that much. LayerImpl* outer_container = host_impl_->active_tree()->OuterViewportContainerLayer(); LayerImpl* inner_container = @@ -4585,17 +4593,18 @@ TEST_F(LayerTreeHostImplTopControlsTest, TopControlsAspectRatio) { host_impl_->InnerViewportScrollLayer()->BoundsForScrolling()); } -// Test that scrolling the outer viewport affects the top controls. -TEST_F(LayerTreeHostImplTopControlsTest, TopControlsScrollOuterViewport) { - SetupTopControlsAndScrollLayerWithVirtualViewport( +// Test that scrolling the outer viewport affects the browser controls. +TEST_F(LayerTreeHostImplBrowserControlsTest, + BrowserControlsScrollOuterViewport) { + SetupBrowserControlsAndScrollLayerWithVirtualViewport( gfx::Size(100, 100), gfx::Size(200, 200), gfx::Size(200, 400)); DrawFrame(); EXPECT_EQ(top_controls_height_, - host_impl_->top_controls_manager()->ContentTopOffset()); + host_impl_->browser_controls_manager()->ContentTopOffset()); // Send a gesture scroll that will scroll the outer viewport, make sure the - // top controls get scrolled. + // browser controls get scrolled. gfx::Vector2dF scroll_delta(0.f, 15.f); EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, host_impl_ @@ -4604,13 +4613,14 @@ TEST_F(LayerTreeHostImplTopControlsTest, TopControlsScrollOuterViewport) { .thread); host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); - EXPECT_EQ(host_impl_->InnerViewportScrollLayer(), + EXPECT_EQ(host_impl_->OuterViewportScrollLayer(), host_impl_->CurrentlyScrollingLayer()); host_impl_->ScrollEnd(EndState().get()); - EXPECT_FLOAT_EQ(scroll_delta.y(), - top_controls_height_ - - host_impl_->top_controls_manager()->ContentTopOffset()); + EXPECT_FLOAT_EQ( + scroll_delta.y(), + top_controls_height_ - + host_impl_->browser_controls_manager()->ContentTopOffset()); scroll_delta = gfx::Vector2dF(0.f, 50.f); EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, @@ -4620,8 +4630,8 @@ TEST_F(LayerTreeHostImplTopControlsTest, TopControlsScrollOuterViewport) { .thread); host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); - EXPECT_EQ(0, host_impl_->top_controls_manager()->ContentTopOffset()); - EXPECT_EQ(host_impl_->InnerViewportScrollLayer(), + EXPECT_EQ(0, host_impl_->browser_controls_manager()->ContentTopOffset()); + EXPECT_EQ(host_impl_->OuterViewportScrollLayer(), host_impl_->CurrentlyScrollingLayer()); host_impl_->ScrollEnd(EndState().get()); @@ -4642,7 +4652,7 @@ TEST_F(LayerTreeHostImplTopControlsTest, TopControlsScrollOuterViewport) { host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); EXPECT_EQ(top_controls_height_, - host_impl_->top_controls_manager()->ContentTopOffset()); + host_impl_->browser_controls_manager()->ContentTopOffset()); EXPECT_FLOAT_EQ( inner_viewport_offset.y() + (scroll_delta.y() + top_controls_height_), ScrollDelta(host_impl_->InnerViewportScrollLayer()).y()); @@ -4650,11 +4660,11 @@ TEST_F(LayerTreeHostImplTopControlsTest, TopControlsScrollOuterViewport) { host_impl_->ScrollEnd(EndState().get()); } -TEST_F(LayerTreeHostImplTopControlsTest, - ScrollNonScrollableRootWithTopControls) { +TEST_F(LayerTreeHostImplBrowserControlsTest, + ScrollNonScrollableRootWithBrowserControls) { settings_ = DefaultSettings(); CreateHostImpl(settings_, CreateCompositorFrameSink()); - SetupTopControlsAndScrollLayerWithVirtualViewport( + SetupBrowserControlsAndScrollLayerWithVirtualViewport( layer_size_, layer_size_, layer_size_); DrawFrame(); @@ -4664,11 +4674,11 @@ TEST_F(LayerTreeHostImplTopControlsTest, InputHandler::TOUCHSCREEN) .thread); - host_impl_->top_controls_manager()->ScrollBegin(); - host_impl_->top_controls_manager()->ScrollBy(gfx::Vector2dF(0.f, 50.f)); - host_impl_->top_controls_manager()->ScrollEnd(); - EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ContentTopOffset()); - // Now that top controls have moved, expect the clip to resize. + host_impl_->browser_controls_manager()->ScrollBegin(); + host_impl_->browser_controls_manager()->ScrollBy(gfx::Vector2dF(0.f, 50.f)); + host_impl_->browser_controls_manager()->ScrollEnd(); + EXPECT_EQ(0.f, host_impl_->browser_controls_manager()->ContentTopOffset()); + // Now that browser controls have moved, expect the clip to resize. LayerImpl* inner_clip_ptr = host_impl_->InnerViewportScrollLayer() ->test_properties() ->parent->test_properties() @@ -4684,22 +4694,22 @@ TEST_F(LayerTreeHostImplTopControlsTest, .thread); float scroll_increment_y = -25.f; - host_impl_->top_controls_manager()->ScrollBegin(); - host_impl_->top_controls_manager()->ScrollBy( + host_impl_->browser_controls_manager()->ScrollBegin(); + host_impl_->browser_controls_manager()->ScrollBy( gfx::Vector2dF(0.f, scroll_increment_y)); EXPECT_FLOAT_EQ(-scroll_increment_y, - host_impl_->top_controls_manager()->ContentTopOffset()); - // Now that top controls have moved, expect the clip to resize. + host_impl_->browser_controls_manager()->ContentTopOffset()); + // Now that browser controls have moved, expect the clip to resize. EXPECT_EQ(gfx::Size(viewport_size_.width(), viewport_size_.height() + scroll_increment_y), inner_clip_ptr->bounds()); - host_impl_->top_controls_manager()->ScrollBy( + host_impl_->browser_controls_manager()->ScrollBy( gfx::Vector2dF(0.f, scroll_increment_y)); - host_impl_->top_controls_manager()->ScrollEnd(); + host_impl_->browser_controls_manager()->ScrollEnd(); EXPECT_FLOAT_EQ(-2 * scroll_increment_y, - host_impl_->top_controls_manager()->ContentTopOffset()); - // Now that top controls have moved, expect the clip to resize. + host_impl_->browser_controls_manager()->ContentTopOffset()); + // Now that browser controls have moved, expect the clip to resize. EXPECT_EQ(clip_size_, inner_clip_ptr->bounds()); host_impl_->ScrollEnd(EndState().get()); @@ -4717,29 +4727,31 @@ TEST_F(LayerTreeHostImplTopControlsTest, } // Tests that activating a pending tree while there's a bounds_delta on the -// viewport layers from top controls doesn't cause a scroll jump. This bug was -// occurring because the UpdateViewportContainerSizes was being called before -// the property trees were updated with the bounds_delta. crbug.com/597266. -TEST_F(LayerTreeHostImplTopControlsTest, ViewportBoundsDeltaOnTreeActivation) { +// viewport layers from browser controls doesn't cause a scroll jump. This bug +// was occurring because the UpdateViewportContainerSizes was being called +// before the property trees were updated with the bounds_delta. +// crbug.com/597266. +TEST_F(LayerTreeHostImplBrowserControlsTest, + ViewportBoundsDeltaOnTreeActivation) { const gfx::Size inner_viewport_size(1000, 1000); const gfx::Size outer_viewport_size(1000, 1000); const gfx::Size content_size(2000, 2000); // Initialization { - SetupTopControlsAndScrollLayerWithVirtualViewport( + SetupBrowserControlsAndScrollLayerWithVirtualViewport( inner_viewport_size, outer_viewport_size, content_size); host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 1.f); - // Start off with the top controls hidden on both main and impl. - host_impl_->active_tree()->set_top_controls_shrink_blink_size(false); - host_impl_->active_tree()->PushTopControlsFromMainThread(0); + // Start off with the browser controls hidden on both main and impl. + host_impl_->active_tree()->set_browser_controls_shrink_blink_size(false); + host_impl_->active_tree()->PushBrowserControlsFromMainThread(0); host_impl_->CreatePendingTree(); - SetupTopControlsAndScrollLayerWithVirtualViewport( + SetupBrowserControlsAndScrollLayerWithVirtualViewport( host_impl_->pending_tree(), inner_viewport_size, outer_viewport_size, content_size); - host_impl_->pending_tree()->set_top_controls_shrink_blink_size(false); + host_impl_->pending_tree()->set_browser_controls_shrink_blink_size(false); // Fully scroll the viewport. host_impl_->ScrollBegin(BeginState(gfx::Point(75, 75)).get(), @@ -4752,17 +4764,19 @@ TEST_F(LayerTreeHostImplTopControlsTest, ViewportBoundsDeltaOnTreeActivation) { LayerImpl* outer_scroll = host_impl_->active_tree()->OuterViewportScrollLayer(); - ASSERT_FLOAT_EQ(0, host_impl_->top_controls_manager()->ContentTopOffset()); + ASSERT_FLOAT_EQ(0, + host_impl_->browser_controls_manager()->ContentTopOffset()); ASSERT_EQ(1000, outer_scroll->MaxScrollOffset().y()); ASSERT_EQ(1000, outer_scroll->CurrentScrollOffset().y()); - // Kick off an animation to show the top controls. - host_impl_->top_controls_manager()->UpdateTopControlsState(BOTH, SHOWN, true); + // Kick off an animation to show the browser controls. + host_impl_->browser_controls_manager()->UpdateBrowserControlsState( + BOTH, SHOWN, true); base::TimeTicks start_time = base::TimeTicks::Now(); BeginFrameArgs begin_frame_args = CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); - // Pump an animation frame to put some delta in the top controls. + // Pump an animation frame to put some delta in the browser controls. { begin_frame_args.frame_time = start_time + base::TimeDelta::FromMilliseconds(50); @@ -4772,8 +4786,9 @@ TEST_F(LayerTreeHostImplTopControlsTest, ViewportBoundsDeltaOnTreeActivation) { host_impl_->DidFinishImplFrame(); } - // Pull the top controls delta and get it back to the pending tree so that - // when we go to activate the pending tree we cause a change to top controls. + // Pull the browser controls delta and get it back to the pending tree so that + // when we go to activate the pending tree we cause a change to browser + // controls. { float delta = host_impl_->active_tree()->top_controls_shown_ratio()->Delta(); @@ -4786,8 +4801,8 @@ TEST_F(LayerTreeHostImplTopControlsTest, ViewportBoundsDeltaOnTreeActivation) { delta); } - // 200 is the kShowHideMaxDurationMs value from top_controls_manager.cc so the - // top controls should be fully animated in this frame. + // 200 is the kShowHideMaxDurationMs value from browser_controls_manager.cc so + // the browser controls should be fully animated in this frame. { begin_frame_args.frame_time = start_time + base::TimeDelta::FromMilliseconds(200); @@ -4796,7 +4811,7 @@ TEST_F(LayerTreeHostImplTopControlsTest, ViewportBoundsDeltaOnTreeActivation) { host_impl_->UpdateAnimationState(true); host_impl_->DidFinishImplFrame(); - ASSERT_EQ(50, host_impl_->top_controls_manager()->ContentTopOffset()); + ASSERT_EQ(50, host_impl_->browser_controls_manager()->ContentTopOffset()); ASSERT_EQ(1050, outer_scroll->MaxScrollOffset().y()); // NEAR because clip layer bounds are truncated in MaxScrollOffset so we // lose some precision in the intermediate animation steps. @@ -4825,26 +4840,23 @@ TEST_F(LayerTreeHostImplTest, ScrollNonCompositedRoot) { gfx::Size contents_size(20, 20); std::unique_ptr<LayerImpl> content_layer = - LayerImpl::Create(host_impl_->active_tree(), 1); + LayerImpl::Create(host_impl_->active_tree(), 11); content_layer->SetDrawsContent(true); content_layer->SetPosition(gfx::PointF()); content_layer->SetBounds(contents_size); - std::unique_ptr<LayerImpl> scroll_clip_layer = - LayerImpl::Create(host_impl_->active_tree(), 3); - scroll_clip_layer->SetBounds(surface_size); + LayerImpl* scroll_clip_layer = + CreateBasicVirtualViewportLayers(surface_size, surface_size); std::unique_ptr<LayerImpl> scroll_layer = - LayerImpl::Create(host_impl_->active_tree(), 2); - scroll_layer->SetScrollClipLayer(3); + LayerImpl::Create(host_impl_->active_tree(), 12); + scroll_layer->SetScrollClipLayer(scroll_clip_layer->id()); scroll_layer->SetBounds(contents_size); scroll_layer->SetPosition(gfx::PointF()); scroll_layer->test_properties()->AddChild(std::move(content_layer)); scroll_clip_layer->test_properties()->AddChild(std::move(scroll_layer)); scroll_clip_layer->test_properties()->force_render_surface = true; - host_impl_->active_tree()->SetRootLayerForTesting( - std::move(scroll_clip_layer)); host_impl_->active_tree()->BuildPropertyTreesForTesting(); host_impl_->SetViewportSize(surface_size); @@ -4863,13 +4875,13 @@ TEST_F(LayerTreeHostImplTest, ScrollNonCompositedRoot) { TEST_F(LayerTreeHostImplTest, ScrollChildCallsCommitAndRedraw) { gfx::Size surface_size(10, 10); gfx::Size contents_size(20, 20); - std::unique_ptr<LayerImpl> root = - LayerImpl::Create(host_impl_->active_tree(), 1); - root->SetBounds(surface_size); + + LayerImpl* root = + CreateBasicVirtualViewportLayers(surface_size, surface_size); + root->test_properties()->AddChild( - CreateScrollableLayer(2, contents_size, root.get())); + CreateScrollableLayer(12, contents_size, root)); root->test_properties()->force_render_surface = true; - host_impl_->active_tree()->SetRootLayerForTesting(std::move(root)); host_impl_->active_tree()->BuildPropertyTreesForTesting(); host_impl_->SetViewportSize(surface_size); @@ -5184,21 +5196,21 @@ TEST_F(LayerTreeHostImplTest, ScrollChildBeyondLimit) { // parent layer isn't scrolled. gfx::Size surface_size(10, 10); gfx::Size content_size(20, 20); - std::unique_ptr<LayerImpl> root = - LayerImpl::Create(host_impl_->active_tree(), 1); - root->SetBounds(surface_size); + + LayerImpl* root = + CreateBasicVirtualViewportLayers(surface_size, surface_size); + root->test_properties()->force_render_surface = true; std::unique_ptr<LayerImpl> grand_child = - CreateScrollableLayer(3, content_size, root.get()); + CreateScrollableLayer(13, content_size, root); std::unique_ptr<LayerImpl> child = - CreateScrollableLayer(2, content_size, root.get()); + CreateScrollableLayer(12, content_size, root); LayerImpl* grand_child_layer = grand_child.get(); child->test_properties()->AddChild(std::move(grand_child)); LayerImpl* child_layer = child.get(); root->test_properties()->AddChild(std::move(child)); - host_impl_->active_tree()->SetRootLayerForTesting(std::move(root)); host_impl_->active_tree()->BuildPropertyTreesForTesting(); host_impl_->active_tree()->DidBecomeActive(); @@ -5230,8 +5242,7 @@ TEST_F(LayerTreeHostImplTest, ScrollChildBeyondLimit) { ->root_layer_for_testing() ->test_properties() ->children[0]; - LayerImpl* grand_child = child->test_properties()->children[0]; - EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), grand_child->id(), + EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), grand_child_layer->id(), gfx::Vector2d(0, -5))); // The child should not have scrolled. @@ -5430,17 +5441,26 @@ TEST_F(LayerTreeHostImplTest, ScrollBeforeRedraw) { gfx::Size surface_size(10, 10); std::unique_ptr<LayerImpl> root_ptr = LayerImpl::Create(host_impl_->active_tree(), 1); - std::unique_ptr<LayerImpl> root_clip = + std::unique_ptr<LayerImpl> inner_clip = LayerImpl::Create(host_impl_->active_tree(), 2); - std::unique_ptr<LayerImpl> root_scroll = - CreateScrollableLayer(3, surface_size, root_clip.get()); - root_clip->test_properties()->force_render_surface = true; - root_scroll->test_properties()->is_container_for_fixed_position_layers = true; - root_clip->test_properties()->AddChild(std::move(root_scroll)); - root_ptr->test_properties()->AddChild(std::move(root_clip)); + std::unique_ptr<LayerImpl> inner_scroll = + CreateScrollableLayer(3, surface_size, inner_clip.get()); + std::unique_ptr<LayerImpl> outer_clip = + LayerImpl::Create(host_impl_->active_tree(), 7); + std::unique_ptr<LayerImpl> outer_scroll = + CreateScrollableLayer(8, surface_size, outer_clip.get()); + inner_clip->test_properties()->force_render_surface = true; + inner_scroll->test_properties()->is_container_for_fixed_position_layers = + true; + outer_scroll->test_properties()->is_container_for_fixed_position_layers = + true; + outer_clip->test_properties()->AddChild(std::move(outer_scroll)); + inner_scroll->test_properties()->AddChild(std::move(outer_clip)); + inner_clip->test_properties()->AddChild(std::move(inner_scroll)); + root_ptr->test_properties()->AddChild(std::move(inner_clip)); host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_ptr)); host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 1, 3, - Layer::INVALID_ID); + 8); host_impl_->active_tree()->BuildPropertyTreesForTesting(); host_impl_->active_tree()->DidBecomeActive(); @@ -5453,19 +5473,27 @@ TEST_F(LayerTreeHostImplTest, ScrollBeforeRedraw) { host_impl_->active_tree()->DetachLayers(); std::unique_ptr<LayerImpl> root_ptr2 = LayerImpl::Create(host_impl_->active_tree(), 4); - std::unique_ptr<LayerImpl> root_clip2 = + std::unique_ptr<LayerImpl> inner_clip2 = LayerImpl::Create(host_impl_->active_tree(), 5); - std::unique_ptr<LayerImpl> root_scroll2 = - CreateScrollableLayer(6, surface_size, root_clip2.get()); - root_scroll2->test_properties()->is_container_for_fixed_position_layers = + std::unique_ptr<LayerImpl> inner_scroll2 = + CreateScrollableLayer(6, surface_size, inner_clip2.get()); + std::unique_ptr<LayerImpl> outer_clip2 = + LayerImpl::Create(host_impl_->active_tree(), 9); + std::unique_ptr<LayerImpl> outer_scroll2 = + CreateScrollableLayer(10, surface_size, outer_clip2.get()); + inner_scroll2->test_properties()->is_container_for_fixed_position_layers = + true; + outer_scroll2->test_properties()->is_container_for_fixed_position_layers = true; - root_clip2->test_properties()->AddChild(std::move(root_scroll2)); - root_clip2->test_properties()->force_render_surface = true; - root_ptr2->test_properties()->AddChild(std::move(root_clip2)); + outer_clip2->test_properties()->AddChild(std::move(outer_scroll2)); + inner_scroll2->test_properties()->AddChild(std::move(outer_clip2)); + inner_clip2->test_properties()->AddChild(std::move(inner_scroll2)); + inner_clip2->test_properties()->force_render_surface = true; + root_ptr2->test_properties()->AddChild(std::move(inner_clip2)); host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_ptr2)); host_impl_->active_tree()->BuildPropertyTreesForTesting(); host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 4, 6, - Layer::INVALID_ID); + 10); host_impl_->active_tree()->DidBecomeActive(); // Scrolling should still work even though we did not draw yet. @@ -6087,7 +6115,6 @@ TEST_F(LayerTreeHostImplTest, OverscrollRoot) { host_impl_->ScrollEnd(EndState().get()); } - TEST_F(LayerTreeHostImplTest, OverscrollChildWithoutBubbling) { // Scroll child layers beyond their maximum scroll range and make sure root // overscroll does not accumulate. @@ -6108,6 +6135,9 @@ TEST_F(LayerTreeHostImplTest, OverscrollChildWithoutBubbling) { LayerImpl* grand_child_layer = grand_child.get(); child->test_properties()->AddChild(std::move(grand_child)); + host_impl_->active_tree()->SetViewportLayersFromIds( + Layer::INVALID_ID, Layer::INVALID_ID, root->id(), Layer::INVALID_ID); + LayerImpl* child_layer = child.get(); root->test_properties()->AddChild(std::move(child)); root_clip->test_properties()->AddChild(std::move(root)); @@ -6148,11 +6178,17 @@ TEST_F(LayerTreeHostImplTest, OverscrollChildWithoutBubbling) { .thread); EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), grand_child_layer); EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); + host_impl_->ScrollEnd(EndState().get()); + EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, + host_impl_ + ->ScrollBegin(BeginState(gfx::Point(5, 5)).get(), + InputHandler::NON_BUBBLING_GESTURE) + .thread); scroll_result = host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); EXPECT_TRUE(scroll_result.did_scroll); EXPECT_FALSE(scroll_result.did_overscroll_root); - EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), child_layer); + EXPECT_EQ(host_impl_->CurrentlyScrollingLayer()->id(), child_layer->id()); EXPECT_EQ(gfx::Vector2dF(), host_impl_->accumulated_root_overscroll()); host_impl_->ScrollEnd(EndState().get()); @@ -6239,7 +6275,13 @@ TEST_F(LayerTreeHostImplTest, OverscrollAlways) { TEST_F(LayerTreeHostImplTest, NoOverscrollWhenNotAtEdge) { InputHandlerScrollResult scroll_result; - SetupScrollAndContentsLayers(gfx::Size(200, 200)); + gfx::Size viewport_size(100, 100); + gfx::Size content_size(200, 200); + LayerImpl* root_scroll_layer = + CreateBasicVirtualViewportLayers(viewport_size, viewport_size); + host_impl_->active_tree()->OuterViewportScrollLayer()->SetBounds( + content_size); + root_scroll_layer->SetBounds(content_size); host_impl_->active_tree()->BuildPropertyTreesForTesting(); DrawFrame(); @@ -6311,10 +6353,15 @@ TEST_F(LayerTreeHostImplTest, OverscrollOnMainThread) { const gfx::Size viewport_size(50, 50); CreateBasicVirtualViewportLayers(viewport_size, content_size); - LayerImpl* scroll_layer = - host_impl_->active_tree()->InnerViewportScrollLayer(); - scroll_layer->set_main_thread_scrolling_reasons( - MainThreadScrollingReason::kThreadedScrollingDisabled); + host_impl_->active_tree() + ->InnerViewportScrollLayer() + ->set_main_thread_scrolling_reasons( + MainThreadScrollingReason::kThreadedScrollingDisabled); + host_impl_->active_tree() + ->OuterViewportScrollLayer() + ->set_main_thread_scrolling_reasons( + MainThreadScrollingReason::kThreadedScrollingDisabled); + host_impl_->active_tree()->BuildPropertyTreesForTesting(); DrawFrame(); @@ -6338,6 +6385,97 @@ TEST_F(LayerTreeHostImplTest, OverscrollOnMainThread) { .thread); } +// Test that scrolling the inner viewport directly works, as can happen when the +// scroll chains up to it from an sibling of the outer viewport. +TEST_F(LayerTreeHostImplTest, ScrollFromOuterViewportSibling) { + const gfx::Size content_size(200, 200); + const gfx::Size viewport_size(100, 100); + + LayerTreeImpl* layer_tree_impl = host_impl_->active_tree(); + + CreateBasicVirtualViewportLayers(viewport_size, viewport_size); + host_impl_->active_tree()->set_top_controls_height(10); + host_impl_->active_tree()->SetCurrentBrowserControlsShownRatio(1.f); + + LayerImpl* outer_scroll_layer = host_impl_->OuterViewportScrollLayer(); + LayerImpl* inner_scroll_layer = host_impl_->InnerViewportScrollLayer(); + + LayerImpl* scroll_layer = nullptr; + + // Create a scrolling layer that's parented directly to the inner viewport. + // This will test that scrolls that chain up to the inner viewport without + // passing through the outer viewport still scroll correctly and affect + // browser controls. + { + std::unique_ptr<LayerImpl> clip = LayerImpl::Create(layer_tree_impl, 10); + clip->SetBounds(viewport_size); + clip->SetPosition(gfx::PointF()); + + std::unique_ptr<LayerImpl> scroll = LayerImpl::Create(layer_tree_impl, 11); + scroll->SetBounds(gfx::Size(400, 400)); + scroll->SetScrollClipLayer(clip->id()); + scroll->SetDrawsContent(true); + + scroll_layer = scroll.get(); + + clip->test_properties()->AddChild(std::move(scroll)); + inner_scroll_layer->test_properties()->AddChild(std::move(clip)); + + // Move the outer viewport layer away so that scrolls won't target it. + host_impl_->active_tree()->OuterViewportContainerLayer()->SetPosition( + gfx::PointF(400, 400)); + + layer_tree_impl->BuildPropertyTreesForTesting(); + + float min_page_scale = 1.f, max_page_scale = 4.f; + float page_scale_factor = 2.f; + host_impl_->active_tree()->PushPageScaleFromMainThread( + page_scale_factor, min_page_scale, max_page_scale); + host_impl_->active_tree()->SetPageScaleOnActiveTree(page_scale_factor); + } + + // Fully scroll the child. + { + host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), + InputHandler::TOUCHSCREEN); + host_impl_->ScrollBy( + UpdateState(gfx::Point(0, 0), gfx::Vector2dF(1000.f, 1000.f)).get()); + host_impl_->ScrollEnd(EndState().get()); + + EXPECT_EQ(1.f, + host_impl_->active_tree()->CurrentBrowserControlsShownRatio()); + EXPECT_VECTOR_EQ(gfx::Vector2dF(300.f, 300.f), + scroll_layer->CurrentScrollOffset()); + EXPECT_VECTOR_EQ(gfx::Vector2dF(), + inner_scroll_layer->CurrentScrollOffset()); + EXPECT_VECTOR_EQ(gfx::Vector2dF(), + outer_scroll_layer->CurrentScrollOffset()); + } + + // Scrolling on the child now should chain up directly to the inner viewport. + // Scrolling it should cause browser controls to hide. The outer viewport + // should not be affected. + { + host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), + InputHandler::TOUCHSCREEN); + gfx::Vector2d scroll_delta(0, 10); + host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); + EXPECT_EQ(0.f, + host_impl_->active_tree()->CurrentBrowserControlsShownRatio()); + EXPECT_VECTOR_EQ(gfx::Vector2dF(), + inner_scroll_layer->CurrentScrollOffset()); + + host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); + host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); + + EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 10.f), + inner_scroll_layer->CurrentScrollOffset()); + EXPECT_VECTOR_EQ(gfx::Vector2dF(), + outer_scroll_layer->CurrentScrollOffset()); + host_impl_->ScrollEnd(EndState().get()); + } +} + // Test that scrolls chain correctly when a child scroller on the page (e.g. a // scrolling div) is set as the outer viewport. This happens in the // rootScroller proposal. @@ -6469,6 +6607,180 @@ TEST_F(LayerTreeHostImplTest, ScrollChainingWithReplacedOuterViewport) { scroll_layer->CurrentScrollOffset()); } } +// Test that scrolls chain correctly when a child scroller on the page (e.g. a +// scrolling div) is set as the outer viewport but scrolls start from a layer +// that's not a descendant of the outer viewport. This happens in the +// rootScroller proposal. +TEST_F(LayerTreeHostImplTest, RootScrollerScrollNonDescendant) { + const gfx::Size content_size(300, 300); + const gfx::Size viewport_size(300, 300); + + LayerTreeImpl* layer_tree_impl = host_impl_->active_tree(); + + LayerImpl* content_layer = + CreateBasicVirtualViewportLayers(viewport_size, content_size); + LayerImpl* inner_scroll_layer = host_impl_->InnerViewportScrollLayer(); + + LayerImpl* outer_scroll_layer = nullptr; + LayerImpl* sibling_scroll_layer = nullptr; + + // Initialization: Add a scrolling layer, simulating an ordinary DIV, to be + // set as the outer viewport. Add a sibling scrolling layer that isn't a child + // of the outer viewport scroll layer. + { + std::unique_ptr<LayerImpl> clip = LayerImpl::Create(layer_tree_impl, 10); + clip->SetBounds(content_size); + clip->SetPosition(gfx::PointF(100, 100)); + + std::unique_ptr<LayerImpl> scroll = LayerImpl::Create(layer_tree_impl, 11); + scroll->SetBounds(gfx::Size(1200, 1200)); + scroll->SetScrollClipLayer(clip->id()); + scroll->SetDrawsContent(true); + + outer_scroll_layer = scroll.get(); + + clip->test_properties()->AddChild(std::move(scroll)); + content_layer->test_properties()->AddChild(std::move(clip)); + + // Create the non-descendant. + std::unique_ptr<LayerImpl> clip2 = LayerImpl::Create(layer_tree_impl, 14); + clip2->SetBounds(gfx::Size(600, 600)); + clip2->SetPosition(gfx::PointF()); + + std::unique_ptr<LayerImpl> scroll2 = LayerImpl::Create(layer_tree_impl, 15); + scroll2->SetBounds(gfx::Size(1200, 1200)); + scroll2->SetScrollClipLayer(clip2->id()); + scroll2->SetDrawsContent(true); + + sibling_scroll_layer = scroll2.get(); + + clip2->test_properties()->AddChild(std::move(scroll2)); + content_layer->test_properties()->AddChild(std::move(clip2)); + + layer_tree_impl->SetViewportLayersFromIds( + Layer::INVALID_ID, layer_tree_impl->PageScaleLayer()->id(), + inner_scroll_layer->id(), outer_scroll_layer->id()); + layer_tree_impl->BuildPropertyTreesForTesting(); + + ASSERT_EQ(outer_scroll_layer, layer_tree_impl->OuterViewportScrollLayer()); + } + + // Scrolls should target the non-descendant scroller. Chaining should not + // propagate to the outer viewport scroll layer. + { + // This should fully scroll the layer. + host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), + InputHandler::TOUCHSCREEN); + host_impl_->ScrollBy( + UpdateState(gfx::Point(0, 0), gfx::Vector2dF(1000.f, 1000.f)).get()); + host_impl_->ScrollEnd(EndState().get()); + + EXPECT_VECTOR_EQ(gfx::Vector2dF(600.f, 600.f), + sibling_scroll_layer->CurrentScrollOffset()); + EXPECT_VECTOR_EQ(gfx::Vector2dF(), + outer_scroll_layer->CurrentScrollOffset()); + + // Scrolling now should chain up but, since the outer viewport is a sibling + // rather than an ancestor, we shouldn't chain to it. + host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), + InputHandler::TOUCHSCREEN); + host_impl_->ScrollBy( + UpdateState(gfx::Point(0, 0), gfx::Vector2dF(1000.f, 1000.f)).get()); + host_impl_->ScrollEnd(EndState().get()); + + EXPECT_VECTOR_EQ(gfx::Vector2dF(600.f, 600.f), + sibling_scroll_layer->CurrentScrollOffset()); + EXPECT_VECTOR_EQ(gfx::Vector2dF(), + outer_scroll_layer->CurrentScrollOffset()); + } + + float min_page_scale = 1.f, max_page_scale = 4.f; + float page_scale_factor = 1.f; + host_impl_->active_tree()->PushPageScaleFromMainThread( + page_scale_factor, min_page_scale, max_page_scale); + + gfx::Vector2dF viewport_size_vec(viewport_size.width(), + viewport_size.height()); + + // Reset the scroll offset. + sibling_scroll_layer->SetCurrentScrollOffset(gfx::ScrollOffset()); + + // Now pinch-zoom in. Anchoring should cause scrolling only on the inner + // viewport layer. + { + // Pinch in to the middle of the screen. The inner viewport should scroll + // to keep the gesture anchored but not the outer or the sibling scroller. + page_scale_factor = 2.f; + gfx::Point anchor(viewport_size.width() / 2, viewport_size.height() / 2); + host_impl_->ScrollBegin(BeginState(anchor).get(), + InputHandler::TOUCHSCREEN); + host_impl_->PinchGestureBegin(); + host_impl_->PinchGestureUpdate(page_scale_factor, anchor); + host_impl_->PinchGestureEnd(); + + EXPECT_VECTOR_EQ(gfx::Vector2dF(anchor.x() / 2, anchor.y() / 2), + inner_scroll_layer->CurrentScrollOffset()); + + host_impl_->ScrollBy(UpdateState(anchor, viewport_size_vec).get()); + + EXPECT_VECTOR_EQ(ScaleVector2d(viewport_size_vec, 1.f / page_scale_factor), + inner_scroll_layer->CurrentScrollOffset()); + // TODO(bokan): This doesn't yet work but we'll probably want to fix this + // at some point. + // EXPECT_VECTOR_EQ( + // gfx::Vector2dF(), + // outer_scroll_layer->CurrentScrollOffset()); + EXPECT_VECTOR_EQ(gfx::Vector2dF(), + sibling_scroll_layer->CurrentScrollOffset()); + + host_impl_->ScrollEnd(EndState().get()); + } + + // Reset the scroll offsets + sibling_scroll_layer->SetCurrentScrollOffset(gfx::ScrollOffset()); + inner_scroll_layer->SetCurrentScrollOffset(gfx::ScrollOffset()); + outer_scroll_layer->SetCurrentScrollOffset(gfx::ScrollOffset()); + + // Scrolls over the sibling while pinched in should scroll the sibling first, + // but then chain up to the inner viewport so that the user can still pan + // around. The outer viewport should be unaffected. + { + // This should fully scroll the sibling but, because we latch to the + // scroller, it shouldn't chain up to the inner viewport yet. + host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), + InputHandler::TOUCHSCREEN); + host_impl_->ScrollBy( + UpdateState(gfx::Point(0, 0), gfx::Vector2dF(2000.f, 2000.f)).get()); + host_impl_->ScrollEnd(EndState().get()); + + EXPECT_VECTOR_EQ(gfx::Vector2dF(600.f, 600.f), + sibling_scroll_layer->CurrentScrollOffset()); + EXPECT_VECTOR_EQ(gfx::Vector2dF(), + inner_scroll_layer->CurrentScrollOffset()); + + // Scrolling now should chain up to the inner viewport. + host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), + InputHandler::TOUCHSCREEN); + host_impl_->ScrollBy( + UpdateState(gfx::Point(0, 0), gfx::Vector2dF(2000.f, 2000.f)).get()); + host_impl_->ScrollEnd(EndState().get()); + + EXPECT_VECTOR_EQ(ScaleVector2d(viewport_size_vec, 1 / page_scale_factor), + inner_scroll_layer->CurrentScrollOffset()); + EXPECT_VECTOR_EQ(gfx::Vector2dF(), + outer_scroll_layer->CurrentScrollOffset()); + + // No more scrolling should be possible. + host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), + InputHandler::TOUCHSCREEN); + host_impl_->ScrollBy( + UpdateState(gfx::Point(0, 0), gfx::Vector2dF(2000.f, 2000.f)).get()); + host_impl_->ScrollEnd(EndState().get()); + + EXPECT_VECTOR_EQ(gfx::Vector2dF(), + outer_scroll_layer->CurrentScrollOffset()); + } +} TEST_F(LayerTreeHostImplTest, OverscrollOnImplThread) { InputHandlerScrollResult scroll_result; @@ -7213,7 +7525,7 @@ TEST_F(LayerTreeHostImplTest, PartialSwapReceivesDamageRect) { std::unique_ptr<LayerTreeHostImpl> layer_tree_host_impl = LayerTreeHostImpl::Create( settings, this, &task_runner_provider_, &stats_instrumentation_, - &shared_bitmap_manager_, NULL, &task_graph_runner_, + &task_graph_runner_, AnimationHost::CreateForTesting(ThreadInstance::IMPL), 0); layer_tree_host_impl->SetVisible(true); layer_tree_host_impl->InitializeRenderer(compositor_frame_sink.get()); @@ -7336,15 +7648,14 @@ static std::unique_ptr<LayerTreeHostImpl> SetupLayersForOpacity( bool partial_swap, LayerTreeHostImplClient* client, TaskRunnerProvider* task_runner_provider, - SharedBitmapManager* manager, TaskGraphRunner* task_graph_runner, RenderingStatsInstrumentation* stats_instrumentation, CompositorFrameSink* compositor_frame_sink) { settings.renderer_settings.partial_swap_enabled = partial_swap; std::unique_ptr<LayerTreeHostImpl> my_host_impl = LayerTreeHostImpl::Create( - settings, client, task_runner_provider, stats_instrumentation, manager, - nullptr, task_graph_runner, - AnimationHost::CreateForTesting(ThreadInstance::IMPL), 0); + settings, client, task_runner_provider, stats_instrumentation, + task_graph_runner, AnimationHost::CreateForTesting(ThreadInstance::IMPL), + 0); my_host_impl->SetVisible(true); my_host_impl->InitializeRenderer(compositor_frame_sink); my_host_impl->WillBeginImplFrame( @@ -7407,7 +7718,6 @@ static std::unique_ptr<LayerTreeHostImpl> SetupLayersForOpacity( } TEST_F(LayerTreeHostImplTest, ContributingLayerEmptyScissorPartialSwap) { - TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; scoped_refptr<TestContextProvider> provider(TestContextProvider::Create()); provider->BindToCurrentThread(); @@ -7415,9 +7725,8 @@ TEST_F(LayerTreeHostImplTest, ContributingLayerEmptyScissorPartialSwap) { std::unique_ptr<CompositorFrameSink> compositor_frame_sink( FakeCompositorFrameSink::Create3d(provider)); std::unique_ptr<LayerTreeHostImpl> my_host_impl = SetupLayersForOpacity( - DefaultSettings(), true, this, &task_runner_provider_, - &shared_bitmap_manager, &task_graph_runner, &stats_instrumentation_, - compositor_frame_sink.get()); + DefaultSettings(), true, this, &task_runner_provider_, &task_graph_runner, + &stats_instrumentation_, compositor_frame_sink.get()); { LayerTreeHostImpl::FrameData frame; EXPECT_EQ(DRAW_SUCCESS, my_host_impl->PrepareToDraw(&frame)); @@ -7438,7 +7747,6 @@ TEST_F(LayerTreeHostImplTest, ContributingLayerEmptyScissorPartialSwap) { } TEST_F(LayerTreeHostImplTest, ContributingLayerEmptyScissorNoPartialSwap) { - TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; scoped_refptr<TestContextProvider> provider(TestContextProvider::Create()); provider->BindToCurrentThread(); @@ -7447,8 +7755,7 @@ TEST_F(LayerTreeHostImplTest, ContributingLayerEmptyScissorNoPartialSwap) { FakeCompositorFrameSink::Create3d(provider)); std::unique_ptr<LayerTreeHostImpl> my_host_impl = SetupLayersForOpacity( DefaultSettings(), false, this, &task_runner_provider_, - &shared_bitmap_manager, &task_graph_runner, &stats_instrumentation_, - compositor_frame_sink.get()); + &task_graph_runner, &stats_instrumentation_, compositor_frame_sink.get()); { LayerTreeHostImpl::FrameData frame; EXPECT_EQ(DRAW_SUCCESS, my_host_impl->PrepareToDraw(&frame)); @@ -7715,14 +8022,11 @@ TEST_F(LayerTreeHostImplTest, FarAwayQuadsDontNeedAA) { class CompositorFrameMetadataTest : public LayerTreeHostImplTest { public: - CompositorFrameMetadataTest() - : swap_buffers_complete_(0) {} + CompositorFrameMetadataTest() = default; - void DidSwapBuffersCompleteOnImplThread() override { - swap_buffers_complete_++; - } + void DidReceiveCompositorFrameAckOnImplThread() override { acks_received_++; } - int swap_buffers_complete_; + int acks_received_ = 0; }; TEST_F(CompositorFrameMetadataTest, CompositorFrameAckCountsAsSwapComplete) { @@ -7735,8 +8039,8 @@ TEST_F(CompositorFrameMetadataTest, CompositorFrameAckCountsAsSwapComplete) { host_impl_->DidDrawAllLayers(frame); } host_impl_->ReclaimResources(ReturnedResourceArray()); - host_impl_->DidSwapBuffersComplete(); - EXPECT_EQ(swap_buffers_complete_, 1); + host_impl_->DidReceiveCompositorFrameAck(); + EXPECT_EQ(acks_received_, 1); } class CountingSoftwareDevice : public SoftwareOutputDevice { @@ -7821,7 +8125,7 @@ TEST_F(LayerTreeHostImplTest, MemoryLimits) { kSoftwareByteLimit, kSoftwareCutoff, kSoftwareResourceLimit); host_impl_ = LayerTreeHostImpl::Create( settings, this, &task_runner_provider_, &stats_instrumentation_, - &shared_bitmap_manager_, &gpu_memory_buffer_manager_, &task_graph_runner_, + &task_graph_runner_, AnimationHost::CreateForTesting(ThreadInstance::IMPL), 0); // Gpu compositing. @@ -7936,9 +8240,8 @@ TEST_F(LayerTreeHostImplTest, RequireHighResAfterGpuRasterizationToggles) { class LayerTreeHostImplTestPrepareTiles : public LayerTreeHostImplTest { public: void SetUp() override { - fake_host_impl_ = - new FakeLayerTreeHostImpl(LayerTreeSettings(), &task_runner_provider_, - &shared_bitmap_manager_, &task_graph_runner_); + fake_host_impl_ = new FakeLayerTreeHostImpl( + LayerTreeSettings(), &task_runner_provider_, &task_graph_runner_); host_impl_.reset(fake_host_impl_); compositor_frame_sink_ = CreateCompositorFrameSink(); host_impl_->SetVisible(true); @@ -8028,18 +8331,39 @@ TEST_F(LayerTreeHostImplTest, CreateETC1UIResource) { void ShutdownReleasesContext_Callback( std::unique_ptr<CopyOutputResult> result) {} +class FrameSinkClient : public TestCompositorFrameSinkClient { + public: + explicit FrameSinkClient( + scoped_refptr<ContextProvider> display_context_provider) + : display_context_provider_(std::move(display_context_provider)) {} + + std::unique_ptr<OutputSurface> CreateDisplayOutputSurface( + scoped_refptr<ContextProvider> compositor_context_provider) override { + return FakeOutputSurface::Create3d(std::move(display_context_provider_)); + } + + void DisplayReceivedCompositorFrame(const CompositorFrame& frame) override {} + void DisplayWillDrawAndSwap(bool will_draw_and_swap, + const RenderPassList& render_passes) override {} + void DisplayDidDrawAndSwap() override {} + + private: + scoped_refptr<ContextProvider> display_context_provider_; +}; + TEST_F(LayerTreeHostImplTest, ShutdownReleasesContext) { scoped_refptr<TestContextProvider> context_provider = TestContextProvider::Create(); + FrameSinkClient test_client_(context_provider); - CreateHostImpl( - DefaultSettings(), - base::MakeUnique<TestCompositorFrameSink>( - context_provider, TestContextProvider::CreateWorker(), - FakeOutputSurface::Create3d(context_provider), nullptr, nullptr, - RendererSettings(), base::ThreadTaskRunnerHandle::Get().get(), - true /* synchronous_composite */, - false /* force_disable_reclaim_resources */)); + auto compositor_frame_sink = base::MakeUnique<TestCompositorFrameSink>( + context_provider, TestContextProvider::CreateWorker(), nullptr, nullptr, + RendererSettings(), base::ThreadTaskRunnerHandle::Get().get(), + true /* synchronous_composite */, + false /* force_disable_reclaim_resources */); + compositor_frame_sink->SetClient(&test_client_); + + CreateHostImpl(DefaultSettings(), std::move(compositor_frame_sink)); SetupRootLayerImpl(LayerImpl::Create(host_impl_->active_tree(), 1)); @@ -8126,26 +8450,25 @@ TEST_F(LayerTreeHostImplTest, TouchFlingShouldContinueScrollingCurrentLayer) { // Scroll a child layer beyond its maximum scroll range and make sure the // the scroll doesn't bubble up to the parent layer. gfx::Size surface_size(10, 10); - std::unique_ptr<LayerImpl> root = - LayerImpl::Create(host_impl_->active_tree(), 1); + LayerImpl* root = + CreateBasicVirtualViewportLayers(surface_size, surface_size); root->test_properties()->force_render_surface = true; std::unique_ptr<LayerImpl> root_scrolling_owned = - CreateScrollableLayer(2, surface_size, root.get()); + CreateScrollableLayer(12, surface_size, root); auto* root_scrolling = root_scrolling_owned.get(); root->test_properties()->AddChild(std::move(root_scrolling_owned)); std::unique_ptr<LayerImpl> child_owned = - CreateScrollableLayer(3, surface_size, root.get()); + CreateScrollableLayer(13, surface_size, root); auto* child = child_owned.get(); root_scrolling->test_properties()->AddChild(std::move(child_owned)); std::unique_ptr<LayerImpl> grand_child_owned = - CreateScrollableLayer(4, surface_size, root.get()); + CreateScrollableLayer(14, surface_size, root); auto* grand_child = grand_child_owned.get(); child->test_properties()->AddChild(std::move(grand_child_owned)); - host_impl_->active_tree()->SetRootLayerForTesting(std::move(root)); host_impl_->active_tree()->BuildPropertyTreesForTesting(); host_impl_->active_tree()->DidBecomeActive(); @@ -8162,13 +8485,6 @@ TEST_F(LayerTreeHostImplTest, TouchFlingShouldContinueScrollingCurrentLayer) { DrawFrame(); { std::unique_ptr<ScrollAndScaleSet> scroll_info; - LayerImpl* child = host_impl_->active_tree() - ->root_layer_for_testing() - ->test_properties() - ->children[0] - ->test_properties() - ->children[0]; - LayerImpl* grand_child = child->test_properties()->children[0]; gfx::Vector2d scroll_delta(0, -2); EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, @@ -8225,19 +8541,18 @@ TEST_F(LayerTreeHostImplTest, WheelFlingShouldntBubble) { // When flinging via wheel, we shouldn't bubble. gfx::Size surface_size(10, 10); gfx::Size content_size(20, 20); - std::unique_ptr<LayerImpl> root_clip = - LayerImpl::Create(host_impl_->active_tree(), 3); + LayerImpl* root_clip = + CreateBasicVirtualViewportLayers(surface_size, surface_size); root_clip->test_properties()->force_render_surface = true; std::unique_ptr<LayerImpl> root_scroll = - CreateScrollableLayer(1, content_size, root_clip.get()); + CreateScrollableLayer(11, content_size, root_clip); int root_scroll_id = root_scroll->id(); std::unique_ptr<LayerImpl> child = - CreateScrollableLayer(2, content_size, root_clip.get()); + CreateScrollableLayer(12, content_size, root_clip); root_scroll->test_properties()->AddChild(std::move(child)); root_clip->test_properties()->AddChild(std::move(root_scroll)); - host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_clip)); host_impl_->active_tree()->BuildPropertyTreesForTesting(); host_impl_->active_tree()->DidBecomeActive(); @@ -8345,7 +8660,7 @@ TEST_F(LayerTreeHostImplTest, ScrollUnknownScrollAncestorMismatch) { status.main_thread_scrolling_reasons); } -TEST_F(LayerTreeHostImplTest, NotScrollInvisibleScroller) { +TEST_F(LayerTreeHostImplTest, ScrollInvisibleScroller) { gfx::Size content_size(100, 100); SetupScrollAndContentsLayers(content_size); @@ -8365,110 +8680,8 @@ TEST_F(LayerTreeHostImplTest, NotScrollInvisibleScroller) { DrawFrame(); - // We should not have scrolled |child_scroll| even though we technically "hit" - // it. The reason for this is that if the scrolling the scroll would not move - // any layer that is a drawn RSLL member, then we can ignore the hit. - // - // Why SCROLL_STARTED? In this case, it's because we've bubbled out and - // started scrolling the inner viewport. - EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, - host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), - InputHandler::WHEEL) - .thread); - - EXPECT_EQ(2, host_impl_->CurrentlyScrollingLayer()->id()); -} - -TEST_F(LayerTreeHostImplTest, ScrollInvisibleScrollerWithVisibleDescendent) { - gfx::Size content_size(100, 100); - SetupScrollAndContentsLayers(content_size); - - LayerImpl* root = host_impl_->active_tree()->LayerById(1); - LayerImpl* root_scroll_layer = host_impl_->active_tree()->LayerById(2); - - std::unique_ptr<LayerImpl> invisible_scroll_layer = - CreateScrollableLayer(7, content_size, root); - invisible_scroll_layer->SetDrawsContent(false); - - std::unique_ptr<LayerImpl> child_layer = - LayerImpl::Create(host_impl_->active_tree(), 8); - child_layer->SetDrawsContent(false); - - std::unique_ptr<LayerImpl> grand_child_layer = - LayerImpl::Create(host_impl_->active_tree(), 9); - grand_child_layer->SetDrawsContent(true); - grand_child_layer->SetBounds(content_size); - // Move the grand child so it's not hit by our test point. - grand_child_layer->SetPosition(gfx::PointF(10.f, 10.f)); - - child_layer->test_properties()->AddChild(std::move(grand_child_layer)); - invisible_scroll_layer->test_properties()->AddChild(std::move(child_layer)); - root_scroll_layer->test_properties()->AddChild( - std::move(invisible_scroll_layer)); - host_impl_->active_tree()->BuildPropertyTreesForTesting(); - - DrawFrame(); - - // We should have scrolled |invisible_scroll_layer| as it was hit and it has - // a descendant which is a drawn RSLL member. - EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, - host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), - InputHandler::WHEEL) - .thread); - - EXPECT_EQ(7, host_impl_->CurrentlyScrollingLayer()->id()); -} - -TEST_F(LayerTreeHostImplTest, ScrollInvisibleScrollerWithVisibleScrollChild) { - // This test case is very similar to the one above with one key difference: - // the invisible scroller has a scroll child that is indeed draw contents. - // If we attempt to initiate a gesture scroll off of the visible scroll child - // we should still start the scroll child. - gfx::Size content_size(100, 100); - SetupScrollAndContentsLayers(content_size); - - LayerImpl* root = host_impl_->active_tree()->LayerById(1); - - int scroll_layer_id = 2; - LayerImpl* scroll_layer = - host_impl_->active_tree()->LayerById(scroll_layer_id); - - int scroll_child_id = 6; - std::unique_ptr<LayerImpl> scroll_child = - LayerImpl::Create(host_impl_->active_tree(), scroll_child_id); - scroll_child->SetDrawsContent(true); - scroll_child->SetBounds(content_size); - // Move the scroll child so it's not hit by our test point. - scroll_child->SetPosition(gfx::PointF(10.f, 10.f)); - - int invisible_scroll_layer_id = 7; - std::unique_ptr<LayerImpl> invisible_scroll = - CreateScrollableLayer(invisible_scroll_layer_id, content_size, root); - invisible_scroll->SetDrawsContent(false); - - int container_id = 8; - std::unique_ptr<LayerImpl> container = - LayerImpl::Create(host_impl_->active_tree(), container_id); - - std::unique_ptr<std::set<LayerImpl*>> scroll_children( - new std::set<LayerImpl*>); - scroll_children->insert(scroll_child.get()); - invisible_scroll->test_properties()->scroll_children.reset( - scroll_children.release()); - - scroll_child->test_properties()->scroll_parent = invisible_scroll.get(); - - container->test_properties()->AddChild(std::move(invisible_scroll)); - container->test_properties()->AddChild(std::move(scroll_child)); - - scroll_layer->test_properties()->AddChild(std::move(container)); - host_impl_->active_tree()->BuildPropertyTreesForTesting(); - - DrawFrame(); - - // We should have scrolled |child_scroll| even though it is invisible. - // The reason for this is that if the scrolling the scroll would move a layer - // that is a drawn RSLL member, then we should accept this hit. + // We should have scrolled |child_scroll| even though it does not move + // any layer that is a drawn RSLL member. EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), InputHandler::WHEEL) @@ -8688,23 +8901,23 @@ TEST_F(LayerTreeHostImplTest, SimpleSwapPromiseMonitor) { } } -class LayerTreeHostImplWithTopControlsTest : public LayerTreeHostImplTest { +class LayerTreeHostImplWithBrowserControlsTest : public LayerTreeHostImplTest { public: void SetUp() override { LayerTreeSettings settings = DefaultSettings(); CreateHostImpl(settings, CreateCompositorFrameSink()); host_impl_->active_tree()->set_top_controls_height(top_controls_height_); host_impl_->sync_tree()->set_top_controls_height(top_controls_height_); - host_impl_->active_tree()->SetCurrentTopControlsShownRatio(1.f); + host_impl_->active_tree()->SetCurrentBrowserControlsShownRatio(1.f); } protected: static const int top_controls_height_; }; -const int LayerTreeHostImplWithTopControlsTest::top_controls_height_ = 50; +const int LayerTreeHostImplWithBrowserControlsTest::top_controls_height_ = 50; -TEST_F(LayerTreeHostImplWithTopControlsTest, NoIdleAnimations) { +TEST_F(LayerTreeHostImplWithBrowserControlsTest, NoIdleAnimations) { LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); scroll_layer->layer_tree_impl() ->property_trees() @@ -8718,49 +8931,52 @@ TEST_F(LayerTreeHostImplWithTopControlsTest, NoIdleAnimations) { host_impl_->DidFinishImplFrame(); } -TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsHeightIsCommitted) { +TEST_F(LayerTreeHostImplWithBrowserControlsTest, + BrowserControlsHeightIsCommitted) { SetupScrollAndContentsLayers(gfx::Size(100, 100)); EXPECT_FALSE(did_request_redraw_); host_impl_->CreatePendingTree(); host_impl_->sync_tree()->set_top_controls_height(100); host_impl_->ActivateSyncTree(); - EXPECT_EQ(100, host_impl_->top_controls_manager()->TopControlsHeight()); + EXPECT_EQ(100, host_impl_->browser_controls_manager()->TopControlsHeight()); } -TEST_F(LayerTreeHostImplWithTopControlsTest, - TopControlsStayFullyVisibleOnHeightChange) { +TEST_F(LayerTreeHostImplWithBrowserControlsTest, + BrowserControlsStayFullyVisibleOnHeightChange) { SetupScrollAndContentsLayers(gfx::Size(100, 100)); - EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ControlsTopOffset()); + EXPECT_EQ(0.f, host_impl_->browser_controls_manager()->ControlsTopOffset()); host_impl_->CreatePendingTree(); host_impl_->sync_tree()->set_top_controls_height(0); host_impl_->ActivateSyncTree(); - EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ControlsTopOffset()); + EXPECT_EQ(0.f, host_impl_->browser_controls_manager()->ControlsTopOffset()); host_impl_->CreatePendingTree(); host_impl_->sync_tree()->set_top_controls_height(50); host_impl_->ActivateSyncTree(); - EXPECT_EQ(0.f, host_impl_->top_controls_manager()->ControlsTopOffset()); + EXPECT_EQ(0.f, host_impl_->browser_controls_manager()->ControlsTopOffset()); } -TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationScheduling) { +TEST_F(LayerTreeHostImplWithBrowserControlsTest, + BrowserControlsAnimationScheduling) { LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); scroll_layer->layer_tree_impl() ->property_trees() ->scroll_tree.UpdateScrollOffsetBaseForTesting(scroll_layer->id(), gfx::ScrollOffset(0, 10)); - host_impl_->DidChangeTopControlsPosition(); + host_impl_->DidChangeBrowserControlsPosition(); EXPECT_TRUE(did_request_next_frame_); EXPECT_TRUE(did_request_redraw_); } -TEST_F(LayerTreeHostImplWithTopControlsTest, ScrollHandledByTopControls) { +TEST_F(LayerTreeHostImplWithBrowserControlsTest, + ScrollHandledByBrowserControls) { InputHandlerScrollResult result; LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); host_impl_->active_tree()->BuildPropertyTreesForTesting(); host_impl_->SetViewportSize(gfx::Size(100, 100)); - host_impl_->top_controls_manager()->UpdateTopControlsState( + host_impl_->browser_controls_manager()->UpdateBrowserControlsState( BOTH, SHOWN, false); DrawFrame(); @@ -8769,11 +8985,11 @@ TEST_F(LayerTreeHostImplWithTopControlsTest, ScrollHandledByTopControls) { ->ScrollBegin(BeginState(gfx::Point()).get(), InputHandler::TOUCHSCREEN) .thread); - EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); + EXPECT_EQ(0, host_impl_->browser_controls_manager()->ControlsTopOffset()); EXPECT_EQ(gfx::Vector2dF().ToString(), scroll_layer->CurrentScrollOffset().ToString()); - // Scroll just the top controls and verify that the scroll succeeds. + // Scroll just the browser controls and verify that the scroll succeeds. const float residue = 10; float offset = top_controls_height_ - residue; result = host_impl_->ScrollBy( @@ -8781,7 +8997,7 @@ TEST_F(LayerTreeHostImplWithTopControlsTest, ScrollHandledByTopControls) { EXPECT_EQ(result.unused_scroll_delta, gfx::Vector2d(0, 0)); EXPECT_TRUE(result.did_scroll); EXPECT_FLOAT_EQ(-offset, - host_impl_->top_controls_manager()->ControlsTopOffset()); + host_impl_->browser_controls_manager()->ControlsTopOffset()); EXPECT_EQ(gfx::Vector2dF().ToString(), scroll_layer->CurrentScrollOffset().ToString()); @@ -8793,7 +9009,7 @@ TEST_F(LayerTreeHostImplWithTopControlsTest, ScrollHandledByTopControls) { EXPECT_TRUE(result.did_scroll); EXPECT_EQ(result.unused_scroll_delta, gfx::Vector2d(0, 0)); EXPECT_EQ(-top_controls_height_, - host_impl_->top_controls_manager()->ControlsTopOffset()); + host_impl_->browser_controls_manager()->ControlsTopOffset()); EXPECT_EQ(gfx::Vector2dF(0, content_scroll).ToString(), scroll_layer->CurrentScrollOffset().ToString()); @@ -8804,17 +9020,17 @@ TEST_F(LayerTreeHostImplWithTopControlsTest, ScrollHandledByTopControls) { EXPECT_TRUE(result.did_scroll); EXPECT_EQ(result.unused_scroll_delta, gfx::Vector2d(0, 0)); EXPECT_EQ(-top_controls_height_, - host_impl_->top_controls_manager()->ControlsTopOffset()); + host_impl_->browser_controls_manager()->ControlsTopOffset()); EXPECT_EQ(gfx::Vector2dF().ToString(), scroll_layer->CurrentScrollOffset().ToString()); - // And scroll the top controls completely into view + // And scroll the browser controls completely into view offset = -top_controls_height_; result = host_impl_->ScrollBy( UpdateState(gfx::Point(), gfx::Vector2d(0, offset)).get()); EXPECT_TRUE(result.did_scroll); EXPECT_EQ(result.unused_scroll_delta, gfx::Vector2d(0, 0)); - EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); + EXPECT_EQ(0, host_impl_->browser_controls_manager()->ControlsTopOffset()); EXPECT_EQ(gfx::Vector2dF().ToString(), scroll_layer->CurrentScrollOffset().ToString()); @@ -8823,19 +9039,20 @@ TEST_F(LayerTreeHostImplWithTopControlsTest, ScrollHandledByTopControls) { UpdateState(gfx::Point(), gfx::Vector2d(0, offset)).get()); EXPECT_FALSE(result.did_scroll); EXPECT_EQ(result.unused_scroll_delta, gfx::Vector2d(0, -50)); - EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); + EXPECT_EQ(0, host_impl_->browser_controls_manager()->ControlsTopOffset()); EXPECT_EQ(gfx::Vector2dF().ToString(), scroll_layer->CurrentScrollOffset().ToString()); host_impl_->ScrollEnd(EndState().get()); } -TEST_F(LayerTreeHostImplWithTopControlsTest, WheelUnhandledByTopControls) { +TEST_F(LayerTreeHostImplWithBrowserControlsTest, + WheelUnhandledByBrowserControls) { SetupScrollAndContentsLayers(gfx::Size(100, 200)); host_impl_->SetViewportSize(gfx::Size(50, 100)); - host_impl_->active_tree()->set_top_controls_shrink_blink_size(true); - host_impl_->top_controls_manager()->UpdateTopControlsState(BOTH, SHOWN, - false); + host_impl_->active_tree()->set_browser_controls_shrink_blink_size(true); + host_impl_->browser_controls_manager()->UpdateBrowserControlsState( + BOTH, SHOWN, false); DrawFrame(); LayerImpl* viewport_layer = host_impl_->InnerViewportScrollLayer(); @@ -8844,17 +9061,18 @@ TEST_F(LayerTreeHostImplWithTopControlsTest, WheelUnhandledByTopControls) { host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), InputHandler::WHEEL) .thread); - EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); + EXPECT_EQ(0, host_impl_->browser_controls_manager()->ControlsTopOffset()); EXPECT_VECTOR_EQ(gfx::Vector2dF(), viewport_layer->CurrentScrollOffset()); - // Wheel scrolls should not affect the top controls, and should pass + // Wheel scrolls should not affect the browser controls, and should pass // directly through to the viewport. const float delta = top_controls_height_; EXPECT_TRUE( host_impl_->ScrollBy( UpdateState(gfx::Point(), gfx::Vector2d(0, delta)).get()) .did_scroll); - EXPECT_FLOAT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); + EXPECT_FLOAT_EQ(0, + host_impl_->browser_controls_manager()->ControlsTopOffset()); EXPECT_VECTOR_EQ(gfx::Vector2dF(0, delta), viewport_layer->CurrentScrollOffset()); @@ -8862,17 +9080,19 @@ TEST_F(LayerTreeHostImplWithTopControlsTest, WheelUnhandledByTopControls) { host_impl_->ScrollBy( UpdateState(gfx::Point(), gfx::Vector2d(0, delta)).get()) .did_scroll); - EXPECT_FLOAT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); + EXPECT_FLOAT_EQ(0, + host_impl_->browser_controls_manager()->ControlsTopOffset()); EXPECT_VECTOR_EQ(gfx::Vector2dF(0, delta * 2), viewport_layer->CurrentScrollOffset()); } -TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAtOrigin) { +TEST_F(LayerTreeHostImplWithBrowserControlsTest, + BrowserControlsAnimationAtOrigin) { LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); host_impl_->active_tree()->BuildPropertyTreesForTesting(); host_impl_->SetViewportSize(gfx::Size(100, 200)); - host_impl_->top_controls_manager()->UpdateTopControlsState( + host_impl_->browser_controls_manager()->UpdateBrowserControlsState( BOTH, SHOWN, false); DrawFrame(); @@ -8881,11 +9101,11 @@ TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAtOrigin) { ->ScrollBegin(BeginState(gfx::Point()).get(), InputHandler::TOUCHSCREEN) .thread); - EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); + EXPECT_EQ(0, host_impl_->browser_controls_manager()->ControlsTopOffset()); EXPECT_EQ(gfx::Vector2dF().ToString(), scroll_layer->CurrentScrollOffset().ToString()); - // Scroll the top controls partially. + // Scroll the browser controls partially. const float residue = 35; float offset = top_controls_height_ - residue; EXPECT_TRUE( @@ -8893,7 +9113,7 @@ TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAtOrigin) { UpdateState(gfx::Point(), gfx::Vector2d(0, offset)).get()) .did_scroll); EXPECT_FLOAT_EQ(-offset, - host_impl_->top_controls_manager()->ControlsTopOffset()); + host_impl_->browser_controls_manager()->ControlsTopOffset()); EXPECT_EQ(gfx::Vector2dF().ToString(), scroll_layer->CurrentScrollOffset().ToString()); @@ -8903,13 +9123,13 @@ TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAtOrigin) { // End the scroll while the controls are still offset from their limit. host_impl_->ScrollEnd(EndState().get()); - ASSERT_TRUE(host_impl_->top_controls_manager()->has_animation()); + ASSERT_TRUE(host_impl_->browser_controls_manager()->has_animation()); EXPECT_TRUE(did_request_next_frame_); EXPECT_TRUE(did_request_redraw_); EXPECT_FALSE(did_request_commit_); - // The top controls should properly animate until finished, despite the scroll - // offset being at the origin. + // The browser controls should properly animate until finished, despite the + // scroll offset being at the origin. BeginFrameArgs begin_frame_args = CreateBeginFrameArgsForTesting( BEGINFRAME_FROM_HERE, base::TimeTicks::Now()); while (did_request_next_frame_) { @@ -8918,7 +9138,7 @@ TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAtOrigin) { did_request_commit_ = false; float old_offset = - host_impl_->top_controls_manager()->ControlsTopOffset(); + host_impl_->browser_controls_manager()->ControlsTopOffset(); begin_frame_args.frame_time += base::TimeDelta::FromMilliseconds(5); host_impl_->WillBeginImplFrame(begin_frame_args); @@ -8927,7 +9147,7 @@ TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAtOrigin) { scroll_layer->CurrentScrollOffset().ToString()); float new_offset = - host_impl_->top_controls_manager()->ControlsTopOffset(); + host_impl_->browser_controls_manager()->ControlsTopOffset(); // No commit is needed as the controls are animating the content offset, // not the scroll offset. @@ -8937,20 +9157,21 @@ TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAtOrigin) { EXPECT_TRUE(did_request_redraw_); if (new_offset != 0) { - EXPECT_TRUE(host_impl_->top_controls_manager()->has_animation()); + EXPECT_TRUE(host_impl_->browser_controls_manager()->has_animation()); EXPECT_TRUE(did_request_next_frame_); } host_impl_->DidFinishImplFrame(); } - EXPECT_FALSE(host_impl_->top_controls_manager()->has_animation()); + EXPECT_FALSE(host_impl_->browser_controls_manager()->has_animation()); } -TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAfterScroll) { +TEST_F(LayerTreeHostImplWithBrowserControlsTest, + BrowserControlsAnimationAfterScroll) { LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); host_impl_->active_tree()->BuildPropertyTreesForTesting(); host_impl_->SetViewportSize(gfx::Size(100, 100)); - host_impl_->top_controls_manager()->UpdateTopControlsState( + host_impl_->browser_controls_manager()->UpdateBrowserControlsState( BOTH, SHOWN, false); float initial_scroll_offset = 50; scroll_layer->layer_tree_impl() @@ -8964,11 +9185,11 @@ TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAfterScroll) { ->ScrollBegin(BeginState(gfx::Point()).get(), InputHandler::TOUCHSCREEN) .thread); - EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); + EXPECT_EQ(0, host_impl_->browser_controls_manager()->ControlsTopOffset()); EXPECT_EQ(gfx::Vector2dF(0, initial_scroll_offset).ToString(), scroll_layer->CurrentScrollOffset().ToString()); - // Scroll the top controls partially. + // Scroll the browser controls partially. const float residue = 15; float offset = top_controls_height_ - residue; EXPECT_TRUE( @@ -8976,7 +9197,7 @@ TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAfterScroll) { UpdateState(gfx::Point(), gfx::Vector2d(0, offset)).get()) .did_scroll); EXPECT_FLOAT_EQ(-offset, - host_impl_->top_controls_manager()->ControlsTopOffset()); + host_impl_->browser_controls_manager()->ControlsTopOffset()); EXPECT_EQ(gfx::Vector2dF(0, initial_scroll_offset).ToString(), scroll_layer->CurrentScrollOffset().ToString()); @@ -8986,12 +9207,12 @@ TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAfterScroll) { // End the scroll while the controls are still offset from the limit. host_impl_->ScrollEnd(EndState().get()); - ASSERT_TRUE(host_impl_->top_controls_manager()->has_animation()); + ASSERT_TRUE(host_impl_->browser_controls_manager()->has_animation()); EXPECT_TRUE(did_request_next_frame_); EXPECT_TRUE(did_request_redraw_); EXPECT_FALSE(did_request_commit_); - // Animate the top controls to the limit. + // Animate the browser controls to the limit. BeginFrameArgs begin_frame_args = CreateBeginFrameArgsForTesting( BEGINFRAME_FROM_HERE, base::TimeTicks::Now()); while (did_request_next_frame_) { @@ -9000,14 +9221,14 @@ TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAfterScroll) { did_request_commit_ = false; float old_offset = - host_impl_->top_controls_manager()->ControlsTopOffset(); + host_impl_->browser_controls_manager()->ControlsTopOffset(); begin_frame_args.frame_time += base::TimeDelta::FromMilliseconds(5); host_impl_->WillBeginImplFrame(begin_frame_args); host_impl_->Animate(); float new_offset = - host_impl_->top_controls_manager()->ControlsTopOffset(); + host_impl_->browser_controls_manager()->ControlsTopOffset(); if (new_offset != old_offset) { EXPECT_TRUE(did_request_redraw_); @@ -9015,19 +9236,19 @@ TEST_F(LayerTreeHostImplWithTopControlsTest, TopControlsAnimationAfterScroll) { } host_impl_->DidFinishImplFrame(); } - EXPECT_FALSE(host_impl_->top_controls_manager()->has_animation()); + EXPECT_FALSE(host_impl_->browser_controls_manager()->has_animation()); EXPECT_EQ(-top_controls_height_, - host_impl_->top_controls_manager()->ControlsTopOffset()); + host_impl_->browser_controls_manager()->ControlsTopOffset()); } -TEST_F(LayerTreeHostImplWithTopControlsTest, - TopControlsAnimationAfterMainThreadFlingStopped) { +TEST_F(LayerTreeHostImplWithBrowserControlsTest, + BrowserControlsAnimationAfterMainThreadFlingStopped) { LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); host_impl_->active_tree()->BuildPropertyTreesForTesting(); host_impl_->SetViewportSize(gfx::Size(100, 100)); - host_impl_->top_controls_manager()->UpdateTopControlsState(BOTH, SHOWN, - false); + host_impl_->browser_controls_manager()->UpdateBrowserControlsState( + BOTH, SHOWN, false); float initial_scroll_offset = 50; scroll_layer->layer_tree_impl() ->property_trees() @@ -9040,11 +9261,11 @@ TEST_F(LayerTreeHostImplWithTopControlsTest, ->ScrollBegin(BeginState(gfx::Point()).get(), InputHandler::TOUCHSCREEN) .thread); - EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); + EXPECT_EQ(0, host_impl_->browser_controls_manager()->ControlsTopOffset()); EXPECT_EQ(gfx::Vector2dF(0, initial_scroll_offset).ToString(), scroll_layer->CurrentScrollOffset().ToString()); - // Scroll the top controls partially. + // Scroll the browser controls partially. const float residue = 15; float offset = top_controls_height_ - residue; EXPECT_TRUE( @@ -9052,7 +9273,7 @@ TEST_F(LayerTreeHostImplWithTopControlsTest, UpdateState(gfx::Point(), gfx::Vector2d(0, offset)).get()) .did_scroll); EXPECT_FLOAT_EQ(-offset, - host_impl_->top_controls_manager()->ControlsTopOffset()); + host_impl_->browser_controls_manager()->ControlsTopOffset()); EXPECT_EQ(gfx::Vector2dF(0, initial_scroll_offset).ToString(), scroll_layer->CurrentScrollOffset().ToString()); @@ -9062,12 +9283,12 @@ TEST_F(LayerTreeHostImplWithTopControlsTest, // End the fling while the controls are still offset from the limit. host_impl_->MainThreadHasStoppedFlinging(); - ASSERT_TRUE(host_impl_->top_controls_manager()->has_animation()); + ASSERT_TRUE(host_impl_->browser_controls_manager()->has_animation()); EXPECT_TRUE(did_request_next_frame_); EXPECT_TRUE(did_request_redraw_); EXPECT_FALSE(did_request_commit_); - // Animate the top controls to the limit. + // Animate the browser controls to the limit. BeginFrameArgs begin_frame_args = CreateBeginFrameArgsForTesting( BEGINFRAME_FROM_HERE, base::TimeTicks::Now()); while (did_request_next_frame_) { @@ -9075,13 +9296,15 @@ TEST_F(LayerTreeHostImplWithTopControlsTest, did_request_next_frame_ = false; did_request_commit_ = false; - float old_offset = host_impl_->top_controls_manager()->ControlsTopOffset(); + float old_offset = + host_impl_->browser_controls_manager()->ControlsTopOffset(); begin_frame_args.frame_time += base::TimeDelta::FromMilliseconds(5); host_impl_->WillBeginImplFrame(begin_frame_args); host_impl_->Animate(); - float new_offset = host_impl_->top_controls_manager()->ControlsTopOffset(); + float new_offset = + host_impl_->browser_controls_manager()->ControlsTopOffset(); if (new_offset != old_offset) { EXPECT_TRUE(did_request_redraw_); @@ -9089,21 +9312,21 @@ TEST_F(LayerTreeHostImplWithTopControlsTest, } host_impl_->DidFinishImplFrame(); } - EXPECT_FALSE(host_impl_->top_controls_manager()->has_animation()); + EXPECT_FALSE(host_impl_->browser_controls_manager()->has_animation()); EXPECT_EQ(-top_controls_height_, - host_impl_->top_controls_manager()->ControlsTopOffset()); + host_impl_->browser_controls_manager()->ControlsTopOffset()); } -TEST_F(LayerTreeHostImplWithTopControlsTest, - TopControlsScrollDeltaInOverScroll) { +TEST_F(LayerTreeHostImplWithBrowserControlsTest, + BrowserControlsScrollDeltaInOverScroll) { // Verifies that the overscroll delta should not have accumulated in - // the top controls if we do a hide and show without releasing finger. + // the browser controls if we do a hide and show without releasing finger. LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 200)); host_impl_->active_tree()->BuildPropertyTreesForTesting(); host_impl_->SetViewportSize(gfx::Size(100, 100)); - host_impl_->top_controls_manager()->UpdateTopControlsState(BOTH, SHOWN, - false); + host_impl_->browser_controls_manager()->UpdateBrowserControlsState( + BOTH, SHOWN, false); DrawFrame(); EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, @@ -9111,14 +9334,15 @@ TEST_F(LayerTreeHostImplWithTopControlsTest, ->ScrollBegin(BeginState(gfx::Point()).get(), InputHandler::TOUCHSCREEN) .thread); - EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); + EXPECT_EQ(0, host_impl_->browser_controls_manager()->ControlsTopOffset()); float offset = 50; EXPECT_TRUE( host_impl_->ScrollBy( UpdateState(gfx::Point(), gfx::Vector2d(0, offset)).get()) .did_scroll); - EXPECT_EQ(-offset, host_impl_->top_controls_manager()->ControlsTopOffset()); + EXPECT_EQ(-offset, + host_impl_->browser_controls_manager()->ControlsTopOffset()); EXPECT_EQ(gfx::Vector2dF().ToString(), scroll_layer->CurrentScrollOffset().ToString()); @@ -9157,7 +9381,8 @@ TEST_F(LayerTreeHostImplWithTopControlsTest, .did_scroll); EXPECT_EQ(gfx::Vector2dF(0, 0).ToString(), scroll_layer->CurrentScrollOffset().ToString()); - EXPECT_EQ(-offset, host_impl_->top_controls_manager()->ControlsTopOffset()); + EXPECT_EQ(-offset, + host_impl_->browser_controls_manager()->ControlsTopOffset()); EXPECT_TRUE( host_impl_->ScrollBy( @@ -9166,21 +9391,21 @@ TEST_F(LayerTreeHostImplWithTopControlsTest, EXPECT_EQ(gfx::Vector2dF(0, 0).ToString(), scroll_layer->CurrentScrollOffset().ToString()); - // Top controls should be fully visible - EXPECT_EQ(0, host_impl_->top_controls_manager()->ControlsTopOffset()); + // Browser controls should be fully visible + EXPECT_EQ(0, host_impl_->browser_controls_manager()->ControlsTopOffset()); host_impl_->ScrollEnd(EndState().get()); } // Tests that when we set a child scroller (e.g. a scrolling div) as the outer -// viewport, scrolling it controls the top controls. -TEST_F(LayerTreeHostImplTopControlsTest, - ReplacedOuterViewportScrollsTopControls) { +// viewport, scrolling it controls the browser controls. +TEST_F(LayerTreeHostImplBrowserControlsTest, + ReplacedOuterViewportScrollsBrowserControls) { const gfx::Size scroll_content_size(400, 400); const gfx::Size root_layer_size(200, 200); const gfx::Size viewport_size(100, 100); - SetupTopControlsAndScrollLayerWithVirtualViewport( + SetupBrowserControlsAndScrollLayerWithVirtualViewport( viewport_size, viewport_size, root_layer_size); LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer(); @@ -9212,9 +9437,9 @@ TEST_F(LayerTreeHostImplTopControlsTest, DrawFrame(); } - ASSERT_EQ(1.f, host_impl_->active_tree()->CurrentTopControlsShownRatio()); + ASSERT_EQ(1.f, host_impl_->active_tree()->CurrentBrowserControlsShownRatio()); - // Scrolling should scroll the child content and the top controls. The + // Scrolling should scroll the child content and the browser controls. The // original outer viewport should get no scroll. { host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), @@ -9226,7 +9451,8 @@ TEST_F(LayerTreeHostImplTopControlsTest, EXPECT_VECTOR_EQ(gfx::Vector2dF(), outer_scroll->CurrentScrollOffset()); EXPECT_VECTOR_EQ(gfx::Vector2dF(100.f, 50.f), scroll_layer->CurrentScrollOffset()); - EXPECT_EQ(0.f, host_impl_->active_tree()->CurrentTopControlsShownRatio()); + EXPECT_EQ(0.f, + host_impl_->active_tree()->CurrentBrowserControlsShownRatio()); } } @@ -9356,16 +9582,16 @@ TEST_F(LayerTreeHostImplVirtualViewportTest, FlingScrollBubblesToInner) { ->ScrollBegin(BeginState(gfx::Point()).get(), InputHandler::TOUCHSCREEN) .thread); - EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer()); + EXPECT_EQ(outer_scroll, host_impl_->CurrentlyScrollingLayer()); EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, host_impl_->FlingScrollBegin().thread); - EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer()); + EXPECT_EQ(outer_scroll, host_impl_->CurrentlyScrollingLayer()); gfx::Vector2d scroll_delta(inner_viewport.width() / 2.f, inner_viewport.height() / 2.f); host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); inner_expected += gfx::Vector2dF(scroll_delta.x(), scroll_delta.y()); - EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer()); + EXPECT_EQ(outer_scroll, host_impl_->CurrentlyScrollingLayer()); host_impl_->ScrollEnd(EndState().get()); EXPECT_EQ(nullptr, host_impl_->CurrentlyScrollingLayer()); @@ -9379,18 +9605,18 @@ TEST_F(LayerTreeHostImplVirtualViewportTest, FlingScrollBubblesToInner) { ->ScrollBegin(BeginState(gfx::Point()).get(), InputHandler::TOUCHSCREEN) .thread); - EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer()); + EXPECT_EQ(outer_scroll, host_impl_->CurrentlyScrollingLayer()); EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, host_impl_->FlingScrollBegin().thread); - EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer()); + EXPECT_EQ(outer_scroll, host_impl_->CurrentlyScrollingLayer()); host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); inner_expected += gfx::Vector2dF(scroll_delta.x(), scroll_delta.y()); - EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer()); + EXPECT_EQ(outer_scroll, host_impl_->CurrentlyScrollingLayer()); host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); outer_expected += gfx::Vector2dF(scroll_delta.x(), scroll_delta.y()); - EXPECT_EQ(inner_scroll, host_impl_->CurrentlyScrollingLayer()); + EXPECT_EQ(outer_scroll, host_impl_->CurrentlyScrollingLayer()); host_impl_->ScrollEnd(EndState().get()); EXPECT_EQ(nullptr, host_impl_->CurrentlyScrollingLayer()); @@ -9536,7 +9762,6 @@ TEST_F(LayerTreeHostImplVirtualViewportTest, SetupVirtualViewportLayers(content_size, outer_viewport, inner_viewport); LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer(); - LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer(); std::unique_ptr<LayerImpl> child = CreateScrollableLayer(10, outer_viewport, outer_scroll); @@ -9552,7 +9777,8 @@ TEST_F(LayerTreeHostImplVirtualViewportTest, ->RootScrollBegin(BeginState(gfx::Point()).get(), InputHandler::TOUCHSCREEN) .thread); - EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), inner_scroll); + EXPECT_EQ(host_impl_->CurrentlyScrollingLayer(), + host_impl_->ViewportMainScrollLayer()); host_impl_->ScrollEnd(EndState().get()); EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, host_impl_ @@ -9901,9 +10127,9 @@ TEST_F(LayerTreeHostImplTest, ExternalTransformAffectsSublayerScaleFactor) { host_impl_->SetViewportSize(gfx::Size(50, 50)); host_impl_->active_tree()->UpdateDrawProperties(update_lcd_text); - TransformNode* node = - host_impl_->active_tree()->property_trees()->transform_tree.Node( - test_layer->transform_tree_index()); + EffectNode* node = + host_impl_->active_tree()->property_trees()->effect_tree.Node( + test_layer->effect_tree_index()); EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(1.f, 1.f)); gfx::Transform external_transform; @@ -9917,8 +10143,8 @@ TEST_F(LayerTreeHostImplTest, ExternalTransformAffectsSublayerScaleFactor) { // Transform node's sublayer scale should include the device transform scale. host_impl_->OnDraw(external_transform, external_viewport, resourceless_software_draw); - node = host_impl_->active_tree()->property_trees()->transform_tree.Node( - test_layer->transform_tree_index()); + node = host_impl_->active_tree()->property_trees()->effect_tree.Node( + test_layer->effect_tree_index()); EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(2.f, 2.f)); // Clear the external transform. @@ -9928,8 +10154,8 @@ TEST_F(LayerTreeHostImplTest, ExternalTransformAffectsSublayerScaleFactor) { host_impl_->OnDraw(external_transform, external_viewport, resourceless_software_draw); - node = host_impl_->active_tree()->property_trees()->transform_tree.Node( - test_layer->transform_tree_index()); + node = host_impl_->active_tree()->property_trees()->effect_tree.Node( + test_layer->effect_tree_index()); EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(1.f, 1.f)); } @@ -10143,7 +10369,7 @@ TEST_F(LayerTreeHostImplTimelinesTest, ScrollAnimatedAborted) { host_impl_->Animate(); host_impl_->UpdateAnimationState(true); - EXPECT_TRUE(host_impl_->animation_host()->HasAnyAnimationTargetingProperty( + EXPECT_TRUE(GetImplAnimationHost()->HasAnyAnimationTargetingProperty( scrolling_layer->element_id(), TargetProperty::SCROLL_OFFSET)); EXPECT_EQ(gfx::ScrollOffset(), scrolling_layer->CurrentScrollOffset()); @@ -10176,7 +10402,7 @@ TEST_F(LayerTreeHostImplTimelinesTest, ScrollAnimatedAborted) { // The instant scroll should have marked the smooth scroll animation as // aborted. - EXPECT_FALSE(host_impl_->animation_host()->HasActiveAnimationForTesting( + EXPECT_FALSE(GetImplAnimationHost()->HasActiveAnimationForTesting( scrolling_layer->element_id())); EXPECT_VECTOR2DF_EQ(gfx::ScrollOffset(0, y + 50), @@ -10214,7 +10440,7 @@ TEST_F(LayerTreeHostImplTimelinesTest, host_impl_->Animate(); host_impl_->UpdateAnimationState(true); - EXPECT_TRUE(host_impl_->animation_host()->HasAnyAnimationTargetingProperty( + EXPECT_TRUE(GetImplAnimationHost()->HasAnyAnimationTargetingProperty( scrolling_layer->element_id(), TargetProperty::SCROLL_OFFSET)); EXPECT_EQ(gfx::ScrollOffset(), scrolling_layer->CurrentScrollOffset()); @@ -10230,12 +10456,12 @@ TEST_F(LayerTreeHostImplTimelinesTest, EXPECT_TRUE(y > 1 && y < 49); // Abort animation. - host_impl_->animation_host()->ScrollAnimationAbort(true /*needs_completion*/); + GetImplAnimationHost()->ScrollAnimationAbort(true /*needs_completion*/); host_impl_->UpdateAnimationState(true); // Aborting with the needs completion param should have marked the smooth // scroll animation as finished. - EXPECT_FALSE(host_impl_->animation_host()->HasActiveAnimationForTesting( + EXPECT_FALSE(GetImplAnimationHost()->HasActiveAnimationForTesting( scrolling_layer->element_id())); EXPECT_TRUE(y > 1 && y < 49); EXPECT_EQ(NULL, host_impl_->CurrentlyScrollingLayer()); @@ -10906,38 +11132,104 @@ TEST_F(LayerTreeHostImplTest, AddVideoFrameControllerOutsideFrame) { EXPECT_FALSE(controller.did_draw_frame()); } -TEST_F(LayerTreeHostImplTest, GpuRasterizationStatusModes) { +// Tests that SetHasGpuRasterizationTrigger behaves as expected. +TEST_F(LayerTreeHostImplTest, GpuRasterizationStatusTrigger) { + // Set initial state, before varying GPU rasterization trigger. + host_impl_->SetHasGpuRasterizationTrigger(false); + host_impl_->SetContentIsSuitableForGpuRasterization(true); + host_impl_->CommitComplete(); + EXPECT_EQ(GpuRasterizationStatus::OFF_VIEWPORT, + host_impl_->gpu_rasterization_status()); EXPECT_FALSE(host_impl_->use_gpu_rasterization()); + // Toggle the trigger on. host_impl_->SetHasGpuRasterizationTrigger(true); - host_impl_->SetContentIsSuitableForGpuRasterization(true); host_impl_->CommitComplete(); EXPECT_EQ(GpuRasterizationStatus::ON, host_impl_->gpu_rasterization_status()); EXPECT_TRUE(host_impl_->use_gpu_rasterization()); + // And off. host_impl_->SetHasGpuRasterizationTrigger(false); - host_impl_->SetContentIsSuitableForGpuRasterization(true); host_impl_->CommitComplete(); EXPECT_EQ(GpuRasterizationStatus::OFF_VIEWPORT, host_impl_->gpu_rasterization_status()); EXPECT_FALSE(host_impl_->use_gpu_rasterization()); +} +// Tests that SetContentIsSuitableForGpuRasterization behaves as expected. +TEST_F(LayerTreeHostImplTest, GpuRasterizationStatusSuitability) { + // Set initial state, before varying GPU rasterization suitability. host_impl_->SetHasGpuRasterizationTrigger(true); host_impl_->SetContentIsSuitableForGpuRasterization(false); host_impl_->CommitComplete(); EXPECT_EQ(GpuRasterizationStatus::OFF_CONTENT, host_impl_->gpu_rasterization_status()); EXPECT_FALSE(host_impl_->use_gpu_rasterization()); + + // Toggle suitability on. + host_impl_->SetContentIsSuitableForGpuRasterization(true); + host_impl_->CommitComplete(); + EXPECT_EQ(GpuRasterizationStatus::ON, host_impl_->gpu_rasterization_status()); + EXPECT_TRUE(host_impl_->use_gpu_rasterization()); EXPECT_FALSE(host_impl_->use_msaa()); + // And off. + host_impl_->SetContentIsSuitableForGpuRasterization(false); + host_impl_->CommitComplete(); + EXPECT_EQ(GpuRasterizationStatus::OFF_CONTENT, + host_impl_->gpu_rasterization_status()); + EXPECT_FALSE(host_impl_->use_gpu_rasterization()); + EXPECT_FALSE(host_impl_->use_msaa()); +} + +// Tests that SetDeviceScaleFactor correctly impacts GPU rasterization. +TEST_F(LayerTreeHostImplTest, GpuRasterizationStatusDeviceScaleFactor) { + // Create a host impl with MSAA support. std::unique_ptr<TestWebGraphicsContext3D> context_with_msaa = TestWebGraphicsContext3D::Create(); - context_with_msaa->SetMaxSamples(8); + context_with_msaa->SetMaxSamples(4); + LayerTreeSettings msaaSettings = GpuRasterizationEnabledSettings(); + msaaSettings.gpu_rasterization_msaa_sample_count = -1; + EXPECT_TRUE(CreateHostImpl(msaaSettings, FakeCompositorFrameSink::Create3d( + std::move(context_with_msaa)))); + + // Set initial state, before varying scale factor. + host_impl_->SetHasGpuRasterizationTrigger(true); + host_impl_->SetContentIsSuitableForGpuRasterization(false); + host_impl_->CommitComplete(); + EXPECT_EQ(GpuRasterizationStatus::OFF_CONTENT, + host_impl_->gpu_rasterization_status()); + EXPECT_FALSE(host_impl_->use_gpu_rasterization()); + + // Set device scale factor to 2, which lowers the required MSAA samples from + // 8 to 4. + host_impl_->active_tree()->SetDeviceScaleFactor(2.0f); + host_impl_->CommitComplete(); + EXPECT_EQ(GpuRasterizationStatus::MSAA_CONTENT, + host_impl_->gpu_rasterization_status()); + EXPECT_TRUE(host_impl_->use_gpu_rasterization()); + EXPECT_TRUE(host_impl_->use_msaa()); + + // Set device scale factor back to 1. + host_impl_->active_tree()->SetDeviceScaleFactor(1.0f); + host_impl_->CommitComplete(); + EXPECT_EQ(GpuRasterizationStatus::OFF_CONTENT, + host_impl_->gpu_rasterization_status()); + EXPECT_FALSE(host_impl_->use_gpu_rasterization()); + EXPECT_FALSE(host_impl_->use_msaa()); +} +// Tests that explicit MSAA sample count correctly impacts GPU rasterization. +TEST_F(LayerTreeHostImplTest, GpuRasterizationStatusExplicitMSAACount) { + // Create a host impl with MSAA support and a forced sample count of 4. + std::unique_ptr<TestWebGraphicsContext3D> context_with_msaa = + TestWebGraphicsContext3D::Create(); + context_with_msaa->SetMaxSamples(4); LayerTreeSettings msaaSettings = GpuRasterizationEnabledSettings(); msaaSettings.gpu_rasterization_msaa_sample_count = 4; EXPECT_TRUE(CreateHostImpl(msaaSettings, FakeCompositorFrameSink::Create3d( std::move(context_with_msaa)))); + host_impl_->SetHasGpuRasterizationTrigger(true); host_impl_->SetContentIsSuitableForGpuRasterization(false); host_impl_->CommitComplete(); @@ -10945,7 +11237,11 @@ TEST_F(LayerTreeHostImplTest, GpuRasterizationStatusModes) { host_impl_->gpu_rasterization_status()); EXPECT_TRUE(host_impl_->use_gpu_rasterization()); EXPECT_TRUE(host_impl_->use_msaa()); +} +// Tests that GPU rasterization overrides work as expected. +TEST_F(LayerTreeHostImplTest, GpuRasterizationStatusOverrides) { + // GPU rasterization explicitly disabled. LayerTreeSettings settings = DefaultSettings(); settings.gpu_rasterization_enabled = false; EXPECT_TRUE(CreateHostImpl(settings, FakeCompositorFrameSink::Create3d())); @@ -10956,6 +11252,7 @@ TEST_F(LayerTreeHostImplTest, GpuRasterizationStatusModes) { host_impl_->gpu_rasterization_status()); EXPECT_FALSE(host_impl_->use_gpu_rasterization()); + // GPU rasterization explicitly forced. settings.gpu_rasterization_forced = true; EXPECT_TRUE(CreateHostImpl(settings, FakeCompositorFrameSink::Create3d())); @@ -11090,9 +11387,9 @@ TEST_F(LayerTreeHostImplTest, SubLayerScaleForNodeInSubtreeOfPageScaleLayer) { DrawFrame(); - TransformNode* node = - host_impl_->active_tree()->property_trees()->transform_tree.Node( - in_subtree_of_page_scale_layer->transform_tree_index()); + EffectNode* node = + host_impl_->active_tree()->property_trees()->effect_tree.Node( + in_subtree_of_page_scale_layer->effect_tree_index()); EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(1.f, 1.f)); host_impl_->active_tree()->SetPageScaleOnActiveTree(2.f); @@ -11100,8 +11397,8 @@ TEST_F(LayerTreeHostImplTest, SubLayerScaleForNodeInSubtreeOfPageScaleLayer) { DrawFrame(); in_subtree_of_page_scale_layer = host_impl_->active_tree()->LayerById(100); - node = host_impl_->active_tree()->property_trees()->transform_tree.Node( - in_subtree_of_page_scale_layer->transform_tree_index()); + node = host_impl_->active_tree()->property_trees()->effect_tree.Node( + in_subtree_of_page_scale_layer->effect_tree_index()); EXPECT_EQ(node->surface_contents_scale, gfx::Vector2dF(2.f, 2.f)); } @@ -11141,7 +11438,7 @@ TEST_F(LayerTreeHostImplTest, JitterTest) { LayerTreeImpl* pending_tree = host_impl_->pending_tree(); pending_tree->PushPageScaleFromMainThread(1.f, 1.f, 1.f); LayerImpl* last_scrolled_layer = pending_tree->LayerById( - host_impl_->active_tree()->LastScrolledLayerId()); + host_impl_->active_tree()->InnerViewportScrollLayer()->id()); // When building property trees from impl side, the builder uses the scroll // offset of layer_impl to initialize the scroll offset in scroll tree: @@ -11187,7 +11484,7 @@ TEST_F(LayerTreeHostImplTest, RecomputeGpuRasterOnCompositorFrameSinkChange) { host_impl_ = LayerTreeHostImpl::Create( settings, this, &task_runner_provider_, &stats_instrumentation_, - &shared_bitmap_manager_, &gpu_memory_buffer_manager_, &task_graph_runner_, + &task_graph_runner_, AnimationHost::CreateForTesting(ThreadInstance::IMPL), 0); host_impl_->SetVisible(true); @@ -11203,5 +11500,130 @@ TEST_F(LayerTreeHostImplTest, RecomputeGpuRasterOnCompositorFrameSinkChange) { EXPECT_FALSE(host_impl_->use_gpu_rasterization()); } +TEST_F(LayerTreeHostImplTest, LayerTreeHostImplTestScrollbarStates) { + LayerTreeSettings settings = DefaultSettings(); + settings.scrollbar_fade_delay = base::TimeDelta::FromMilliseconds(500); + settings.scrollbar_fade_duration = base::TimeDelta::FromMilliseconds(300); + settings.scrollbar_animator = LayerTreeSettings::THINNING; + + gfx::Size viewport_size(300, 200); + gfx::Size content_size(1000, 1000); + gfx::Size child_layer_size(250, 150); + gfx::Size scrollbar_size_1(gfx::Size(15, viewport_size.height())); + gfx::Size scrollbar_size_2(gfx::Size(15, child_layer_size.height())); + + const int scrollbar_1_id = 10; + const int scrollbar_2_id = 11; + const int child_clip_id = 12; + const int child_scroll_id = 13; + + CreateHostImpl(settings, CreateCompositorFrameSink()); + host_impl_->active_tree()->SetDeviceScaleFactor(1); + host_impl_->SetViewportSize(viewport_size); + CreateScrollAndContentsLayers(host_impl_->active_tree(), content_size); + host_impl_->active_tree()->InnerViewportContainerLayer()->SetBounds( + viewport_size); + LayerImpl* root_scroll = + host_impl_->active_tree()->OuterViewportScrollLayer(); + + // scrollbar_1 on root scroll. + std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar_1 = + SolidColorScrollbarLayerImpl::Create(host_impl_->active_tree(), + scrollbar_1_id, VERTICAL, 5, 5, true, + true); + scrollbar_1->SetScrollLayerId(root_scroll->id()); + scrollbar_1->SetDrawsContent(true); + scrollbar_1->SetBounds(scrollbar_size_1); + scrollbar_1->SetTouchEventHandlerRegion(gfx::Rect(scrollbar_size_1)); + host_impl_->active_tree() + ->InnerViewportContainerLayer() + ->test_properties() + ->AddChild(std::move(scrollbar_1)); + + host_impl_->active_tree()->BuildPropertyTreesForTesting(); + host_impl_->active_tree()->DidBecomeActive(); + + DrawFrame(); + host_impl_->active_tree()->UpdateDrawProperties(false); + + ScrollbarAnimationControllerThinning* scrollbar_1_animation_controller = + static_cast<ScrollbarAnimationControllerThinning*>( + host_impl_->ScrollbarAnimationControllerForId(root_scroll->id())); + EXPECT_TRUE(scrollbar_1_animation_controller); + scrollbar_1_animation_controller->set_mouse_move_distance_for_test(40.f); + + // Mouse moves close to the scrollbar, goes over the scrollbar, and + // moves back to where it was. + host_impl_->MouseMoveAt(gfx::Point(100, 150)); + EXPECT_FALSE(scrollbar_1_animation_controller->mouse_is_near_scrollbar()); + EXPECT_FALSE(scrollbar_1_animation_controller->mouse_is_over_scrollbar()); + host_impl_->MouseMoveAt(gfx::Point(40, 150)); + EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_near_scrollbar()); + EXPECT_FALSE(scrollbar_1_animation_controller->mouse_is_over_scrollbar()); + host_impl_->MouseMoveAt(gfx::Point(10, 150)); + EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_near_scrollbar()); + EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_over_scrollbar()); + host_impl_->MouseMoveAt(gfx::Point(40, 150)); + EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_near_scrollbar()); + EXPECT_FALSE(scrollbar_1_animation_controller->mouse_is_over_scrollbar()); + host_impl_->MouseMoveAt(gfx::Point(100, 150)); + EXPECT_FALSE(scrollbar_1_animation_controller->mouse_is_near_scrollbar()); + EXPECT_FALSE(scrollbar_1_animation_controller->mouse_is_over_scrollbar()); + + // scrollbar_2 on child. + std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar_2 = + SolidColorScrollbarLayerImpl::Create(host_impl_->active_tree(), + scrollbar_2_id, VERTICAL, 5, 5, true, + true); + std::unique_ptr<LayerImpl> child_clip = + LayerImpl::Create(host_impl_->active_tree(), child_clip_id); + std::unique_ptr<LayerImpl> child = + LayerImpl::Create(host_impl_->active_tree(), child_scroll_id); + child->SetPosition(gfx::PointF(50, 50)); + child->SetBounds(child_layer_size); + child->SetDrawsContent(true); + child->SetScrollClipLayer(child_clip_id); + + scrollbar_2->SetScrollLayerId(child_scroll_id); + scrollbar_2->SetDrawsContent(true); + scrollbar_2->SetBounds(scrollbar_size_2); + + child->test_properties()->AddChild(std::move(scrollbar_2)); + child_clip->test_properties()->AddChild(std::move(child)); + root_scroll->test_properties()->AddChild(std::move(child_clip)); + + host_impl_->active_tree()->BuildPropertyTreesForTesting(); + host_impl_->active_tree()->DidBecomeActive(); + + ScrollbarAnimationControllerThinning* scrollbar_2_animation_controller = + static_cast<ScrollbarAnimationControllerThinning*>( + host_impl_->ScrollbarAnimationControllerForId(child_scroll_id)); + EXPECT_TRUE(scrollbar_2_animation_controller); + scrollbar_2_animation_controller->set_mouse_move_distance_for_test(40.f); + + // Mouse goes over scrollbar_2, moves close to scrollbar_2, moves close to + // scrollbar_1, goes over scrollbar_1. + host_impl_->MouseMoveAt(gfx::Point(60, 150)); + EXPECT_FALSE(scrollbar_1_animation_controller->mouse_is_near_scrollbar()); + EXPECT_FALSE(scrollbar_1_animation_controller->mouse_is_over_scrollbar()); + EXPECT_TRUE(scrollbar_2_animation_controller->mouse_is_near_scrollbar()); + EXPECT_TRUE(scrollbar_2_animation_controller->mouse_is_over_scrollbar()); + host_impl_->MouseMoveAt(gfx::Point(100, 150)); + EXPECT_FALSE(scrollbar_1_animation_controller->mouse_is_near_scrollbar()); + EXPECT_FALSE(scrollbar_1_animation_controller->mouse_is_over_scrollbar()); + EXPECT_TRUE(scrollbar_2_animation_controller->mouse_is_near_scrollbar()); + EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_over_scrollbar()); + host_impl_->MouseMoveAt(gfx::Point(40, 150)); + EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_near_scrollbar()); + EXPECT_FALSE(scrollbar_1_animation_controller->mouse_is_over_scrollbar()); + EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_near_scrollbar()); + EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_over_scrollbar()); + host_impl_->MouseMoveAt(gfx::Point(10, 150)); + EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_near_scrollbar()); + EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_over_scrollbar()); + EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_near_scrollbar()); + EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_over_scrollbar()); +} + } // namespace } // namespace cc diff --git a/chromium/cc/trees/layer_tree_host_in_process.cc b/chromium/cc/trees/layer_tree_host_in_process.cc index 57e2ea414e8..6280097b16a 100644 --- a/chromium/cc/trees/layer_tree_host_in_process.cc +++ b/chromium/cc/trees/layer_tree_host_in_process.cc @@ -26,8 +26,6 @@ #include "base/threading/thread_task_runner_handle.h" #include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event_argument.h" -#include "cc/animation/animation_events.h" -#include "cc/animation/animation_host.h" #include "cc/base/math_util.h" #include "cc/blimp/client_picture_cache.h" #include "cc/blimp/engine_picture_cache.h" @@ -43,20 +41,16 @@ #include "cc/layers/heads_up_display_layer_impl.h" #include "cc/layers/layer.h" #include "cc/layers/layer_iterator.h" -#include "cc/layers/layer_proto_converter.h" #include "cc/layers/painted_scrollbar_layer.h" -#include "cc/proto/gfx_conversions.h" -#include "cc/proto/layer_tree.pb.h" -#include "cc/proto/layer_tree_host.pb.h" #include "cc/resources/ui_resource_manager.h" #include "cc/trees/draw_property_utils.h" #include "cc/trees/layer_tree_host_client.h" #include "cc/trees/layer_tree_host_common.h" #include "cc/trees/layer_tree_host_impl.h" #include "cc/trees/layer_tree_impl.h" +#include "cc/trees/mutator_host.h" #include "cc/trees/property_tree_builder.h" #include "cc/trees/proxy_main.h" -#include "cc/trees/remote_channel_impl.h" #include "cc/trees/single_thread_proxy.h" #include "cc/trees/swap_promise_manager.h" #include "cc/trees/tree_synchronizer.h" @@ -68,60 +62,6 @@ static base::StaticAtomicSequenceNumber s_layer_tree_host_sequence_number; } namespace cc { -namespace { - -std::unique_ptr<base::trace_event::TracedValue> -ComputeLayerTreeHostProtoSizeSplitAsValue(proto::LayerTreeHost* proto) { - std::unique_ptr<base::trace_event::TracedValue> value( - new base::trace_event::TracedValue()); - base::CheckedNumeric<int> base_layer_properties_size = 0; - base::CheckedNumeric<int> picture_layer_properties_size = 0; - base::CheckedNumeric<int> display_item_list_size = 0; - base::CheckedNumeric<int> drawing_display_items_size = 0; - - const proto::LayerUpdate& layer_update_proto = proto->layer_updates(); - for (int i = 0; i < layer_update_proto.layers_size(); ++i) { - const proto::LayerProperties layer_properties_proto = - layer_update_proto.layers(i); - base_layer_properties_size += layer_properties_proto.base().ByteSize(); - - if (layer_properties_proto.has_picture()) { - const proto::PictureLayerProperties& picture_proto = - layer_properties_proto.picture(); - picture_layer_properties_size += picture_proto.ByteSize(); - - const proto::DisplayItemList& display_list_proto = - picture_proto.display_list(); - display_item_list_size += display_list_proto.ByteSize(); - - for (int j = 0; j < display_list_proto.items_size(); ++j) { - const proto::DisplayItem& display_item = display_list_proto.items(j); - if (display_item.type() == proto::DisplayItem::Type_Drawing) - drawing_display_items_size += display_item.ByteSize(); - } - } - } - - value->SetInteger("TotalLayerTreeHostProtoSize", proto->ByteSize()); - value->SetInteger("LayerTreeHierarchySize", - proto->layer_tree().root_layer().ByteSize()); - value->SetInteger("LayerUpdatesSize", proto->layer_updates().ByteSize()); - value->SetInteger("PropertyTreesSize", - proto->layer_tree().property_trees().ByteSize()); - - // LayerUpdate size breakdown. - value->SetInteger("TotalBasePropertiesSize", - base_layer_properties_size.ValueOrDefault(-1)); - value->SetInteger("PictureLayerPropertiesSize", - picture_layer_properties_size.ValueOrDefault(-1)); - value->SetInteger("DisplayItemListSize", - display_item_list_size.ValueOrDefault(-1)); - value->SetInteger("DrawingDisplayItemsSize", - drawing_display_items_size.ValueOrDefault(-1)); - return value; -} - -} // namespace LayerTreeHostInProcess::InitParams::InitParams() {} @@ -152,48 +92,12 @@ LayerTreeHostInProcess::CreateSingleThreaded( return layer_tree_host; } -std::unique_ptr<LayerTreeHostInProcess> -LayerTreeHostInProcess::CreateRemoteServer( - RemoteProtoChannel* remote_proto_channel, - InitParams* params) { - DCHECK(params->main_task_runner.get()); - DCHECK(params->settings); - DCHECK(remote_proto_channel); - TRACE_EVENT0("cc.remote", "LayerTreeHostInProcess::CreateRemoteServer"); - - DCHECK(params->image_serialization_processor); - - std::unique_ptr<LayerTreeHostInProcess> layer_tree_host( - new LayerTreeHostInProcess(params, CompositorMode::REMOTE)); - layer_tree_host->InitializeRemoteServer(remote_proto_channel, - params->main_task_runner); - return layer_tree_host; -} - -std::unique_ptr<LayerTreeHostInProcess> -LayerTreeHostInProcess::CreateRemoteClient( - RemoteProtoChannel* remote_proto_channel, - scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, - InitParams* params) { - DCHECK(params->main_task_runner.get()); - DCHECK(params->settings); - DCHECK(remote_proto_channel); - DCHECK(params->image_serialization_processor); - - std::unique_ptr<LayerTreeHostInProcess> layer_tree_host( - new LayerTreeHostInProcess(params, CompositorMode::REMOTE)); - layer_tree_host->InitializeRemoteClient( - remote_proto_channel, params->main_task_runner, impl_task_runner); - return layer_tree_host; -} - LayerTreeHostInProcess::LayerTreeHostInProcess(InitParams* params, CompositorMode mode) : LayerTreeHostInProcess( params, mode, - base::MakeUnique<LayerTree>(std::move(params->animation_host), - this)) {} + base::MakeUnique<LayerTree>(params->mutator_host, this)) {} LayerTreeHostInProcess::LayerTreeHostInProcess( InitParams* params, @@ -214,12 +118,11 @@ LayerTreeHostInProcess::LayerTreeHostInProcess( gpu_rasterization_histogram_recorded_(false), did_complete_scale_animation_(false), id_(s_layer_tree_host_sequence_number.GetNext() + 1), - shared_bitmap_manager_(params->shared_bitmap_manager), - gpu_memory_buffer_manager_(params->gpu_memory_buffer_manager), task_graph_runner_(params->task_graph_runner), image_serialization_processor_(params->image_serialization_processor) { DCHECK(task_graph_runner_); DCHECK(layer_tree_); + DCHECK_NE(compositor_mode_, CompositorMode::REMOTE); rendering_stats_instrumentation_->set_record_rendering_stats( debug_state_.RecordRenderingStats()); @@ -243,43 +146,6 @@ void LayerTreeHostInProcess::InitializeSingleThreaded( task_runner_provider_.get())); } -void LayerTreeHostInProcess::InitializeRemoteServer( - RemoteProtoChannel* remote_proto_channel, - scoped_refptr<base::SingleThreadTaskRunner> main_task_runner) { - task_runner_provider_ = TaskRunnerProvider::Create(main_task_runner, nullptr); - - if (image_serialization_processor_) { - engine_picture_cache_ = - image_serialization_processor_->CreateEnginePictureCache(); - layer_tree_->set_engine_picture_cache(engine_picture_cache_.get()); - } - InitializeProxy(ProxyMain::CreateRemote(remote_proto_channel, this, - task_runner_provider_.get())); -} - -void LayerTreeHostInProcess::InitializeRemoteClient( - RemoteProtoChannel* remote_proto_channel, - scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, - scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { - task_runner_provider_ = - TaskRunnerProvider::Create(main_task_runner, impl_task_runner); - - if (image_serialization_processor_) { - client_picture_cache_ = - image_serialization_processor_->CreateClientPictureCache(); - layer_tree_->set_client_picture_cache(client_picture_cache_.get()); - } - - // For the remote mode, the RemoteChannelImpl implements the Proxy, which is - // owned by the LayerTreeHostInProcess. The RemoteChannelImpl pipes requests - // which need to handled locally, for instance the Output Surface creation to - // the LayerTreeHostInProcess on the client, while the other requests are sent - // to the RemoteChannelMain on the server which directs them to ProxyMain and - // the remote server LayerTreeHostInProcess. - InitializeProxy(base::MakeUnique<RemoteChannelImpl>( - this, remote_proto_channel, task_runner_provider_.get())); -} - void LayerTreeHostInProcess::InitializeForTesting( std::unique_ptr<TaskRunnerProvider> task_runner_provider, std::unique_ptr<Proxy> proxy_for_testing) { @@ -322,7 +188,7 @@ void LayerTreeHostInProcess::InitializeProxy(std::unique_ptr<Proxy> proxy) { proxy_ = std::move(proxy); proxy_->Start(); - layer_tree_->animation_host()->SetSupportsScrollAnimations( + layer_tree_->mutator_host()->SetSupportsScrollAnimations( proxy_->SupportsImplScrolling()); } @@ -421,11 +287,9 @@ void LayerTreeHostInProcess::RequestMainFrameUpdate() { // this function, keep in mind that the function *runs* on the impl thread! Any // code that is logically a main thread operation, e.g. deletion of a Layer, // should be delayed until the LayerTreeHostInProcess::CommitComplete, which -// will run -// after the commit, but on the main thread. +// will run after the commit, but on the main thread. void LayerTreeHostInProcess::FinishCommitOnImplThread( LayerTreeHostImpl* host_impl) { - DCHECK(!IsRemoteServer()); DCHECK(task_runner_provider_->IsImplThread()); bool is_new_trace; @@ -453,7 +317,10 @@ void LayerTreeHostInProcess::FinishCommitOnImplThread( if (layer_tree_->needs_full_tree_sync()) TreeSynchronizer::SynchronizeTrees(layer_tree_->root_layer(), sync_tree); - layer_tree_->PushPropertiesTo(sync_tree); + float page_scale_delta = 1.f; + if (reflected_main_frame_state_) + page_scale_delta = reflected_main_frame_state_->page_scale_delta; + layer_tree_->PushPropertiesTo(sync_tree, page_scale_delta); sync_tree->PassSwapPromises(swap_promise_manager_.TakeSwapPromises()); @@ -463,10 +330,6 @@ void LayerTreeHostInProcess::FinishCommitOnImplThread( RecordGpuRasterizationHistogram(); host_impl->SetViewportSize(layer_tree_->device_viewport_size()); - // TODO(senorblanco): Move this to LayerTree::PushPropertiesTo so that it - // happens before GPU rasterization properties are set, since those trigger an - // update of GPU rasterization status, which depends on the device scale - // factor. (crbug.com/535700) sync_tree->SetDeviceScaleFactor(layer_tree_->device_scale_factor()); host_impl->SetDebugState(debug_state_); @@ -478,6 +341,23 @@ void LayerTreeHostInProcess::FinishCommitOnImplThread( TreeSynchronizer::PushLayerProperties(layer_tree_.get(), sync_tree); + if (reflected_main_frame_state_) { + for (const auto& scroll_update : reflected_main_frame_state_->scrolls) { + int layer_id = scroll_update.layer_id; + gfx::Vector2dF scroll_delta = scroll_update.scroll_delta; + + PropertyTrees* property_trees = layer_tree_->property_trees(); + property_trees->scroll_tree.SetScrollOffset( + layer_id, gfx::ScrollOffsetWithDelta( + layer_tree_->LayerById(layer_id)->scroll_offset(), + scroll_delta)); + } + } + + // This must happen after synchronizing property trees and after pushing + // properties, which updates the clobber_active_value flag. + sync_tree->UpdatePropertyTreeScrollOffset(layer_tree_->property_trees()); + // This must happen after synchronizing property trees and after push // properties, which updates property tree indices, but before animation // host pushes properties as animation host push properties can change @@ -486,17 +366,13 @@ void LayerTreeHostInProcess::FinishCommitOnImplThread( sync_tree->UpdatePropertyTreeScrollingAndAnimationFromMainThread(); TRACE_EVENT0("cc", "LayerTreeHostInProcess::AnimationHost::PushProperties"); - DCHECK(host_impl->animation_host()); - layer_tree_->animation_host()->PushPropertiesTo( - host_impl->animation_host()); + DCHECK(host_impl->mutator_host()); + layer_tree_->mutator_host()->PushPropertiesTo(host_impl->mutator_host()); } - // This must happen after synchronizing property trees and after pushing - // properties, which updates the clobber_active_value flag. - sync_tree->UpdatePropertyTreeScrollOffset(layer_tree_->property_trees()); - micro_benchmark_controller_.ScheduleImplBenchmarks(host_impl); layer_tree_->property_trees()->ResetAllChangeTracking(); + reflected_main_frame_state_ = nullptr; } void LayerTreeHostInProcess::WillCommit() { @@ -557,24 +433,19 @@ void LayerTreeHostInProcess::DidFailToInitializeCompositorFrameSink() { std::unique_ptr<LayerTreeHostImpl> LayerTreeHostInProcess::CreateLayerTreeHostImpl( LayerTreeHostImplClient* client) { - DCHECK(!IsRemoteServer()); DCHECK(task_runner_provider_->IsImplThread()); const bool supports_impl_scrolling = task_runner_provider_->HasImplThread(); - std::unique_ptr<AnimationHost> animation_host_impl = - layer_tree_->animation_host()->CreateImplInstance( - supports_impl_scrolling); + std::unique_ptr<MutatorHost> mutator_host_impl = + layer_tree_->mutator_host()->CreateImplInstance(supports_impl_scrolling); std::unique_ptr<LayerTreeHostImpl> host_impl = LayerTreeHostImpl::Create( settings_, client, task_runner_provider_.get(), - rendering_stats_instrumentation_.get(), shared_bitmap_manager_, - gpu_memory_buffer_manager_, task_graph_runner_, - std::move(animation_host_impl), id_); + rendering_stats_instrumentation_.get(), task_graph_runner_, + std::move(mutator_host_impl), id_); host_impl->SetHasGpuRasterizationTrigger(has_gpu_rasterization_trigger_); host_impl->SetContentIsSuitableForGpuRasterization( content_is_suitable_for_gpu_rasterization_); - shared_bitmap_manager_ = NULL; - gpu_memory_buffer_manager_ = NULL; task_graph_runner_ = NULL; input_handler_weak_ptr_ = host_impl->AsWeakPtr(); return host_impl; @@ -612,10 +483,6 @@ void LayerTreeHostInProcess::SetNeedsRecalculateRasterScales() { proxy_->SetNeedsCommit(); } -void LayerTreeHostInProcess::SetNeedsRedraw() { - SetNeedsRedrawRect(gfx::Rect(layer_tree_->device_viewport_size())); -} - void LayerTreeHostInProcess::SetNeedsRedrawRect(const gfx::Rect& damage_rect) { proxy_->SetNeedsRedraw(damage_rect); } @@ -638,9 +505,9 @@ void LayerTreeHostInProcess::SetNextCommitForcesRedraw() { } void LayerTreeHostInProcess::SetAnimationEvents( - std::unique_ptr<AnimationEvents> events) { + std::unique_ptr<MutatorEvents> events) { DCHECK(task_runner_provider_->IsMainThread()); - layer_tree_->animation_host()->SetAnimationEvents(std::move(events)); + layer_tree_->mutator_host()->SetAnimationEvents(std::move(events)); } void LayerTreeHostInProcess::SetDebugState( @@ -810,8 +677,7 @@ bool LayerTreeHostInProcess::DoUpdateLayers(Layer* root_layer) { draw_property_utils::UpdatePropertyTrees(property_trees, can_render_to_separate_surface); draw_property_utils::FindLayersThatNeedUpdates( - layer_tree_.get(), property_trees->transform_tree, - property_trees->effect_tree, &update_layer_list); + layer_tree_.get(), property_trees, &update_layer_list); } for (const auto& layer : update_layer_list) @@ -883,6 +749,12 @@ void LayerTreeHostInProcess::ApplyScrollAndScale(ScrollAndScaleSet* info) { layer->scroll_offset(), info->scrolls[i].scroll_delta)); SetNeedsUpdateLayers(); } + for (size_t i = 0; i < info->scrollbars.size(); ++i) { + Layer* layer = layer_tree_->LayerById(info->scrollbars[i].layer_id); + if (!layer) + continue; + layer->SetScrollbarsHiddenFromImplSide(info->scrollbars[i].hidden); + } } // This needs to happen after scroll deltas have been sent to prevent top @@ -891,28 +763,36 @@ void LayerTreeHostInProcess::ApplyScrollAndScale(ScrollAndScaleSet* info) { ApplyViewportDeltas(info); } +void LayerTreeHostInProcess::SetReflectedMainFrameState( + std::unique_ptr<ReflectedMainFrameState> reflected_main_frame_state) { + DCHECK(IsThreaded()); + + reflected_main_frame_state_ = std::move(reflected_main_frame_state); + SetNeedsCommit(); +} + const base::WeakPtr<InputHandler>& LayerTreeHostInProcess::GetInputHandler() const { return input_handler_weak_ptr_; } -void LayerTreeHostInProcess::UpdateTopControlsState( - TopControlsState constraints, - TopControlsState current, +void LayerTreeHostInProcess::UpdateBrowserControlsState( + BrowserControlsState constraints, + BrowserControlsState current, bool animate) { - // Top controls are only used in threaded or remote mode. - DCHECK(IsThreaded() || IsRemoteServer()); - proxy_->UpdateTopControlsState(constraints, current, animate); + // Browser controls are only used in threaded mode. + DCHECK(IsThreaded()); + proxy_->UpdateBrowserControlsState(constraints, current, animate); } void LayerTreeHostInProcess::AnimateLayers(base::TimeTicks monotonic_time) { - AnimationHost* animation_host = layer_tree_->animation_host(); - std::unique_ptr<AnimationEvents> events = animation_host->CreateEvents(); + MutatorHost* mutator_host = layer_tree_->mutator_host(); + std::unique_ptr<MutatorEvents> events = mutator_host->CreateEvents(); - if (animation_host->AnimateLayers(monotonic_time)) - animation_host->UpdateAnimationState(true, events.get()); + if (mutator_host->AnimateLayers(monotonic_time)) + mutator_host->UpdateAnimationState(true, events.get()); - if (!events->events_.empty()) + if (!events->IsEmpty()) layer_tree_->property_trees()->needs_rebuild = true; } @@ -947,101 +827,4 @@ bool LayerTreeHostInProcess::IsThreaded() const { return compositor_mode_ == CompositorMode::THREADED; } -bool LayerTreeHostInProcess::IsRemoteServer() const { - // The LayerTreeHostInProcess on the server does not have an impl task runner. - return compositor_mode_ == CompositorMode::REMOTE && - !task_runner_provider_->HasImplThread(); -} - -bool LayerTreeHostInProcess::IsRemoteClient() const { - return compositor_mode_ == CompositorMode::REMOTE && - task_runner_provider_->HasImplThread(); -} - -void LayerTreeHostInProcess::ToProtobufForCommit( - proto::LayerTreeHost* proto, - std::vector<std::unique_ptr<SwapPromise>>* swap_promises) { - DCHECK(engine_picture_cache_); - // Not all fields are serialized, as they are either not needed for a commit, - // or implementation isn't ready yet. - // Unsupported items: - // - animations - // - UI resources - // - instrumentation of stats - // - histograms - // Skipped items: - // - SwapPromise as they are mostly used for perf measurements. - // - The bitmap and GPU memory related items. - // Other notes: - // - The output surfaces are only valid on the client-side so they are - // therefore not serialized. - // - LayerTreeSettings are needed only during construction of the - // LayerTreeHostInProcess, so they are serialized outside of the - // LayerTreeHostInProcess - // serialization. - // - The |visible_| flag will be controlled from the client separately and - // will need special handling outside of the serialization of the - // LayerTreeHostInProcess. - // TODO(nyquist): Figure out how to support animations. See crbug.com/570376. - TRACE_EVENT0("cc.remote", "LayerTreeHostInProcess::ToProtobufForCommit"); - *swap_promises = swap_promise_manager_.TakeSwapPromises(); - - proto->set_source_frame_number(source_frame_number_); - - // Serialize the LayerTree before serializing the properties. During layer - // property serialization, we clear the list |layer_that_should_properties_| - // from the LayerTree. - // The serialization code here need to serialize the complete state, including - // the result of the main frame update. - const bool inputs_only = false; - layer_tree_->ToProtobuf(proto->mutable_layer_tree(), inputs_only); - - LayerProtoConverter::SerializeLayerProperties(this, - proto->mutable_layer_updates()); - - std::vector<PictureData> pictures = - engine_picture_cache_->CalculateCacheUpdateAndFlush(); - proto::PictureDataVectorToSkPicturesProto(pictures, - proto->mutable_pictures()); - - debug_state_.ToProtobuf(proto->mutable_debug_state()); - proto->set_has_gpu_rasterization_trigger(has_gpu_rasterization_trigger_); - proto->set_content_is_suitable_for_gpu_rasterization( - content_is_suitable_for_gpu_rasterization_); - proto->set_id(id_); - proto->set_next_commit_forces_redraw(next_commit_forces_redraw_); - - TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( - "cc.remote", "LayerTreeHostProto", source_frame_number_, - ComputeLayerTreeHostProtoSizeSplitAsValue(proto)); -} - -void LayerTreeHostInProcess::FromProtobufForCommit( - const proto::LayerTreeHost& proto) { - DCHECK(client_picture_cache_); - source_frame_number_ = proto.source_frame_number(); - - layer_tree_->FromProtobuf(proto.layer_tree()); - - // Ensure ClientPictureCache contains all the necessary SkPictures before - // deserializing the properties. - proto::SkPictures proto_pictures = proto.pictures(); - std::vector<PictureData> pictures = - SkPicturesProtoToPictureDataVector(proto_pictures); - client_picture_cache_->ApplyCacheUpdate(pictures); - - LayerProtoConverter::DeserializeLayerProperties(layer_tree_->root_layer(), - proto.layer_updates()); - - // The deserialization is finished, so now clear the cache. - client_picture_cache_->Flush(); - - debug_state_.FromProtobuf(proto.debug_state()); - has_gpu_rasterization_trigger_ = proto.has_gpu_rasterization_trigger(); - content_is_suitable_for_gpu_rasterization_ = - proto.content_is_suitable_for_gpu_rasterization(); - id_ = proto.id(); - next_commit_forces_redraw_ = proto.next_commit_forces_redraw(); -} - } // namespace cc diff --git a/chromium/cc/trees/layer_tree_host_in_process.h b/chromium/cc/trees/layer_tree_host_in_process.h index 17983f40b6d..eec439482d6 100644 --- a/chromium/cc/trees/layer_tree_host_in_process.h +++ b/chromium/cc/trees/layer_tree_host_in_process.h @@ -20,15 +20,14 @@ #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" #include "base/time/time.h" -#include "cc/animation/target_property.h" #include "cc/base/cc_export.h" #include "cc/debug/micro_benchmark.h" #include "cc/debug/micro_benchmark_controller.h" +#include "cc/input/browser_controls_state.h" #include "cc/input/event_listener_properties.h" #include "cc/input/input_handler.h" #include "cc/input/layer_selection_bound.h" #include "cc/input/scrollbar.h" -#include "cc/input/top_controls_state.h" #include "cc/layers/layer_collections.h" #include "cc/layers/layer_list_iterator.h" #include "cc/output/compositor_frame_sink.h" @@ -42,20 +41,14 @@ #include "cc/trees/layer_tree_settings.h" #include "cc/trees/proxy.h" #include "cc/trees/swap_promise_manager.h" +#include "cc/trees/target_property.h" #include "third_party/skia/include/core/SkColor.h" #include "ui/gfx/geometry/rect.h" -namespace gpu { -class GpuMemoryBufferManager; -} // namespace gpu - namespace cc { -class AnimationHost; -class AnimationEvents; -class BeginFrameSource; +class MutatorEvents; class ClientPictureCache; class EnginePictureCache; -class HeadsUpDisplayLayer; class ImageSerializationProcessor; class Layer; class LayerTreeHostClient; @@ -63,42 +56,30 @@ class LayerTreeHostImpl; class LayerTreeHostImplClient; class LayerTreeHostSingleThreadClient; class LayerTreeMutator; +class MutatorHost; class PropertyTrees; -class Region; -class RemoteProtoChannel; class RenderingStatsInstrumentation; -class ResourceProvider; -class ResourceUpdateQueue; -class SharedBitmapManager; class TaskGraphRunner; -class TopControlsManager; -struct PendingPageScaleAnimation; +struct ReflectedMainFrameState; struct RenderingStats; struct ScrollAndScaleSet; -namespace proto { -class LayerTreeHost; -} - class CC_EXPORT LayerTreeHostInProcess : public LayerTreeHost { public: // TODO(sad): InitParams should be a movable type so that it can be // std::move()d to the Create* functions. struct CC_EXPORT InitParams { LayerTreeHostClient* client = nullptr; - SharedBitmapManager* shared_bitmap_manager = nullptr; - gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager = nullptr; TaskGraphRunner* task_graph_runner = nullptr; LayerTreeSettings const* settings = nullptr; scoped_refptr<base::SingleThreadTaskRunner> main_task_runner; ImageSerializationProcessor* image_serialization_processor = nullptr; - std::unique_ptr<AnimationHost> animation_host; + MutatorHost* mutator_host; InitParams(); ~InitParams(); }; - // The SharedBitmapManager will be used on the compositor thread. static std::unique_ptr<LayerTreeHostInProcess> CreateThreaded( scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, InitParams* params); @@ -107,21 +88,6 @@ class CC_EXPORT LayerTreeHostInProcess : public LayerTreeHost { LayerTreeHostSingleThreadClient* single_thread_client, InitParams* params); - static std::unique_ptr<LayerTreeHostInProcess> CreateRemoteServer( - RemoteProtoChannel* remote_proto_channel, - InitParams* params); - - // The lifetime of this LayerTreeHostInProcess is tied to the lifetime of the - // remote server LayerTreeHostInProcess. It should be created on receiving - // CompositorMessageToImpl::InitializeImpl message and destroyed on receiving - // a CompositorMessageToImpl::CloseImpl message from the server. This ensures - // that the client will not send any compositor messages once the - // LayerTreeHostInProcess on the server is destroyed. - static std::unique_ptr<LayerTreeHostInProcess> CreateRemoteClient( - RemoteProtoChannel* remote_proto_channel, - scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, - InitParams* params); - ~LayerTreeHostInProcess() override; // LayerTreeHost implementation. @@ -151,13 +117,12 @@ class CC_EXPORT LayerTreeHostInProcess : public LayerTreeHost { void SetDeferCommits(bool defer_commits) override; void LayoutAndUpdateLayers() override; void Composite(base::TimeTicks frame_begin_time) override; - void SetNeedsRedraw() override; void SetNeedsRedrawRect(const gfx::Rect& damage_rect) override; void SetNextCommitForcesRedraw() override; void NotifyInputThrottledUntilCommit() override; - void UpdateTopControlsState(TopControlsState constraints, - TopControlsState current, - bool animate) override; + void UpdateBrowserControlsState(BrowserControlsState constraints, + BrowserControlsState current, + bool animate) override; const base::WeakPtr<InputHandler>& GetInputHandler() const override; void DidStopFlinging() override; void SetDebugState(const LayerTreeDebugState& debug_state) override; @@ -189,12 +154,21 @@ class CC_EXPORT LayerTreeHostInProcess : public LayerTreeHost { LayerTreeHostImplClient* client); void DidLoseCompositorFrameSink(); void DidCommitAndDrawFrame() { client_->DidCommitAndDrawFrame(); } - void DidCompleteSwapBuffers() { client_->DidCompleteSwapBuffers(); } + void DidReceiveCompositorFrameAck() { + client_->DidReceiveCompositorFrameAck(); + } bool UpdateLayers(); // Called when the compositor completed page scale animation. void DidCompletePageScaleAnimation(); void ApplyScrollAndScale(ScrollAndScaleSet* info); + void SetReflectedMainFrameState( + std::unique_ptr<ReflectedMainFrameState> reflected_main_frame_state); + const ReflectedMainFrameState* reflected_main_frame_state_for_testing() + const { + return reflected_main_frame_state_.get(); + } + LayerTreeHostClient* client() { return client_; } bool gpu_rasterization_histogram_recorded() const { @@ -207,7 +181,7 @@ class CC_EXPORT LayerTreeHostInProcess : public LayerTreeHost { return rendering_stats_instrumentation_.get(); } - void SetAnimationEvents(std::unique_ptr<AnimationEvents> events); + void SetAnimationEvents(std::unique_ptr<MutatorEvents> events); bool has_gpu_rasterization_trigger() const { return has_gpu_rasterization_trigger_; @@ -215,24 +189,8 @@ class CC_EXPORT LayerTreeHostInProcess : public LayerTreeHost { Proxy* proxy() const { return proxy_.get(); } - // Serializes the parts of this LayerTreeHostInProcess that is needed for a - // commit to a protobuf message. Not all members are serialized as they are - // not helpful for remote usage. - // The |swap_promise_list_| is transferred to the serializer in - // |swap_promises|. - void ToProtobufForCommit( - proto::LayerTreeHost* proto, - std::vector<std::unique_ptr<SwapPromise>>* swap_promises); - - // Deserializes the protobuf into this LayerTreeHostInProcess before a commit. - // The expected input is a serialized remote LayerTreeHost. After - // deserializing the protobuf, the normal commit-flow should continue. - void FromProtobufForCommit(const proto::LayerTreeHost& proto); - bool IsSingleThreaded() const; bool IsThreaded() const; - bool IsRemoteServer() const; - bool IsRemoteClient() const; ImageSerializationProcessor* image_serialization_processor() const { return image_serialization_processor_; @@ -259,13 +217,6 @@ class CC_EXPORT LayerTreeHostInProcess : public LayerTreeHost { void InitializeSingleThreaded( LayerTreeHostSingleThreadClient* single_thread_client, scoped_refptr<base::SingleThreadTaskRunner> main_task_runner); - void InitializeRemoteServer( - RemoteProtoChannel* remote_proto_channel, - scoped_refptr<base::SingleThreadTaskRunner> main_task_runner); - void InitializeRemoteClient( - RemoteProtoChannel* remote_proto_channel, - scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, - scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner); void InitializeForTesting( std::unique_ptr<TaskRunnerProvider> task_runner_provider, std::unique_ptr<Proxy> proxy_for_testing); @@ -275,15 +226,8 @@ class CC_EXPORT LayerTreeHostInProcess : public LayerTreeHost { void SetUIResourceManagerForTesting( std::unique_ptr<UIResourceManager> ui_resource_manager); - // shared_bitmap_manager(), gpu_memory_buffer_manager(), and - // task_graph_runner() return valid values only until the LayerTreeHostImpl is - // created in CreateLayerTreeHostImpl(). - SharedBitmapManager* shared_bitmap_manager() const { - return shared_bitmap_manager_; - } - gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager() const { - return gpu_memory_buffer_manager_; - } + // task_graph_runner() returns a valid value only until the LayerTreeHostImpl + // is created in CreateLayerTreeHostImpl(). TaskGraphRunner* task_graph_runner() const { return task_graph_runner_; } void OnCommitForSwapPromises(); @@ -355,8 +299,6 @@ class CC_EXPORT LayerTreeHostInProcess : public LayerTreeHost { bool next_commit_forces_redraw_ = false; bool next_commit_forces_recalculate_raster_scales_ = false; - SharedBitmapManager* shared_bitmap_manager_; - gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager_; TaskGraphRunner* task_graph_runner_; ImageSerializationProcessor* image_serialization_processor_; @@ -366,6 +308,15 @@ class CC_EXPORT LayerTreeHostInProcess : public LayerTreeHost { SurfaceSequenceGenerator surface_sequence_generator_; uint32_t num_consecutive_frames_suitable_for_gpu_ = 0; + // The state that was expected to be reflected from the main thread during + // BeginMainFrame, but could not be done. The client provides these deltas + // to use during the commit instead of applying them at that point because + // its necessary for these deltas to be applied *after* PropertyTrees are + // built/updated on the main thread. + // TODO(khushalsagar): Investigate removing this after SPV2, since then we + // should get these PropertyTrees directly from blink? + std::unique_ptr<ReflectedMainFrameState> reflected_main_frame_state_; + DISALLOW_COPY_AND_ASSIGN(LayerTreeHostInProcess); }; diff --git a/chromium/cc/trees/layer_tree_host_pixeltest_filters.cc b/chromium/cc/trees/layer_tree_host_pixeltest_filters.cc index 723c6d95724..a4386cbd58d 100644 --- a/chromium/cc/trees/layer_tree_host_pixeltest_filters.cc +++ b/chromium/cc/trees/layer_tree_host_pixeltest_filters.cc @@ -7,6 +7,7 @@ #include "build/build_config.h" #include "cc/layers/picture_layer.h" #include "cc/layers/solid_color_layer.h" +#include "cc/test/fake_content_layer_client.h" #include "cc/test/layer_tree_pixel_test.h" #include "cc/test/pixel_comparator.h" #include "cc/test/solid_color_content_layer_client.h" @@ -754,6 +755,58 @@ TEST_F(RotatedDropShadowFilterTest, RotatedDropShadowFilterTest_Software) { base::FilePath(FILE_PATH_LITERAL("rotated_drop_shadow_filter_sw.png"))); } +class TranslatedFilterTest : public LayerTreeHostFiltersPixelTest { + protected: + void RunPixelTestType(PixelTestType test_type, base::FilePath image_name) { + scoped_refptr<Layer> clip = Layer::Create(); + clip->SetBounds(gfx::Size(300, 300)); + clip->SetMasksToBounds(true); + + scoped_refptr<Layer> parent = Layer::Create(); + parent->SetPosition(gfx::PointF(30.f, 30.f)); + + gfx::Rect child_rect(100, 100); + // Use two colors to bypass solid color detection, so we get a tile quad. + // This is intended to test render pass removal optimizations. + FakeContentLayerClient client; + client.set_bounds(child_rect.size()); + SkPaint paint; + paint.setColor(SK_ColorGREEN); + client.add_draw_rect(child_rect, paint); + paint.setColor(SK_ColorBLUE); + client.add_draw_rect(gfx::Rect(100, 50), paint); + scoped_refptr<PictureLayer> child = PictureLayer::Create(&client); + child->SetBounds(child_rect.size()); + child->SetIsDrawable(true); + FilterOperations filters; + filters.Append(FilterOperation::CreateOpacityFilter(0.5f)); + child->SetFilters(filters); + + // This layer will be clipped by |clip|, so the RenderPass created for + // |child| will only have one visible quad. + scoped_refptr<SolidColorLayer> grand_child = + CreateSolidColorLayer(gfx::Rect(-300, -300, 100, 100), SK_ColorRED); + + child->AddChild(grand_child); + parent->AddChild(child); + clip->AddChild(parent); + + RunPixelTest(test_type, clip, image_name); + } +}; + +TEST_F(TranslatedFilterTest, GL) { + RunPixelTestType( + PIXEL_TEST_GL, + base::FilePath(FILE_PATH_LITERAL("translated_blue_green_alpha_gl.png"))); +} + +TEST_F(TranslatedFilterTest, Software) { + RunPixelTestType( + PIXEL_TEST_SOFTWARE, + base::FilePath(FILE_PATH_LITERAL("translated_blue_green_alpha_sw.png"))); +} + class EnlargedTextureWithAlphaThresholdFilter : public LayerTreeHostFiltersPixelTest { protected: diff --git a/chromium/cc/trees/layer_tree_host_pixeltest_tiles.cc b/chromium/cc/trees/layer_tree_host_pixeltest_tiles.cc index 67342e21151..9a649dcece9 100644 --- a/chromium/cc/trees/layer_tree_host_pixeltest_tiles.cc +++ b/chromium/cc/trees/layer_tree_host_pixeltest_tiles.cc @@ -11,7 +11,6 @@ #include "cc/playback/display_item_list_settings.h" #include "cc/playback/drawing_display_item.h" #include "cc/test/layer_tree_pixel_test.h" -#include "cc/test/test_gpu_memory_buffer_manager.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkPictureRecorder.h" diff --git a/chromium/cc/trees/layer_tree_host_single_thread_client.h b/chromium/cc/trees/layer_tree_host_single_thread_client.h index 3d078920735..00cc3dbaec8 100644 --- a/chromium/cc/trees/layer_tree_host_single_thread_client.h +++ b/chromium/cc/trees/layer_tree_host_single_thread_client.h @@ -15,14 +15,17 @@ class LayerTreeHostSingleThreadClient { // delay for potential future frame. virtual void RequestScheduleAnimation() {} - // Called whenever the compositor posts a SwapBuffers (either full or - // partial). After DidPostSwapBuffers(), exactly one of - // DidCompleteSwapBuffers() or DidAbortSwapBuffers() will be called, thus - // these functions can be used to keep track of pending swap buffers calls for - // rate limiting. - virtual void DidPostSwapBuffers() = 0; - virtual void DidCompleteSwapBuffers() = 0; - virtual void DidAbortSwapBuffers() = 0; + // Called whenever the compositor submits a CompositorFrame. Afterward, + // LayerTreeHostClient::DidReceiveCompositorFrameAck() will be called once the + // display compositor/ finishes processing the frame. So these functions can + // be used to keep track of pending submitted CompositorFrames for rate + // limiting. + virtual void DidSubmitCompositorFrame() = 0; + + // Called when the active CompositorFrameSink is lost and needs to be + // replaced. This allows the embedder to schedule a composite which will + // run the machinery to acquire a new CompositorFrameSink. + virtual void DidLoseCompositorFrameSink() = 0; protected: virtual ~LayerTreeHostSingleThreadClient() {} diff --git a/chromium/cc/trees/layer_tree_host_unittest.cc b/chromium/cc/trees/layer_tree_host_unittest.cc index 5f168bc16df..ae40cad1835 100644 --- a/chromium/cc/trees/layer_tree_host_unittest.cc +++ b/chromium/cc/trees/layer_tree_host_unittest.cc @@ -47,10 +47,11 @@ #include "cc/test/geometry_test_utils.h" #include "cc/test/layer_internals_for_test.h" #include "cc/test/layer_tree_test.h" +#include "cc/test/push_properties_counting_layer.h" +#include "cc/test/push_properties_counting_layer_impl.h" #include "cc/test/render_pass_test_utils.h" #include "cc/test/skia_common.h" #include "cc/test/test_compositor_frame_sink.h" -#include "cc/test/test_shared_bitmap_manager.h" #include "cc/test/test_web_graphics_context_3d.h" #include "cc/trees/effect_node.h" #include "cc/trees/layer_tree_host_common.h" @@ -81,25 +82,25 @@ class LayerTreeHostTest : public LayerTreeTest {}; class LayerTreeHostTestHasImplThreadTest : public LayerTreeHostTest { public: - LayerTreeHostTestHasImplThreadTest() : threaded_(false) {} + LayerTreeHostTestHasImplThreadTest() : single_threaded_(false) {} void RunTest(CompositorMode mode) override { - threaded_ = mode == CompositorMode::THREADED; + single_threaded_ = mode == CompositorMode::SINGLE_THREADED; LayerTreeHostTest::RunTest(mode); } void BeginTest() override { - EXPECT_EQ(threaded_, HasImplThread()); + EXPECT_EQ(single_threaded_, !HasImplThread()); EndTest(); } - void AfterTest() override { EXPECT_EQ(threaded_, HasImplThread()); } + void AfterTest() override { EXPECT_EQ(single_threaded_, !HasImplThread()); } private: - bool threaded_; + bool single_threaded_; }; -SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestHasImplThreadTest); +SINGLE_MULTI_AND_REMOTE_TEST_F(LayerTreeHostTestHasImplThreadTest); class LayerTreeHostTestSetNeedsCommitInsideLayout : public LayerTreeHostTest { protected: @@ -118,7 +119,7 @@ class LayerTreeHostTestSetNeedsCommitInsideLayout : public LayerTreeHostTest { void AfterTest() override {} }; -SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsCommitInsideLayout); +SINGLE_MULTI_AND_REMOTE_TEST_F(LayerTreeHostTestSetNeedsCommitInsideLayout); class LayerTreeHostTestFrameOrdering : public LayerTreeHostTest { protected: @@ -193,7 +194,7 @@ class LayerTreeHostTestFrameOrdering : public LayerTreeHostTest { ImplOrder impl_ = IMPL_START; }; -SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestFrameOrdering); +SINGLE_MULTI_AND_REMOTE_TEST_F(LayerTreeHostTestFrameOrdering); class LayerTreeHostTestSetNeedsUpdateInsideLayout : public LayerTreeHostTest { protected: @@ -212,7 +213,7 @@ class LayerTreeHostTestSetNeedsUpdateInsideLayout : public LayerTreeHostTest { void AfterTest() override {} }; -SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsUpdateInsideLayout); +SINGLE_MULTI_AND_REMOTE_TEST_F(LayerTreeHostTestSetNeedsUpdateInsideLayout); // Test if the LTHI receives ReadyToActivate notifications from the TileManager // when no raster tasks get scheduled. @@ -256,7 +257,7 @@ class LayerTreeHostTestReadyToActivateEmpty : public LayerTreeHostTest { size_t required_for_activation_count_; }; -SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestReadyToActivateEmpty); +SINGLE_MULTI_AND_REMOTE_TEST_F(LayerTreeHostTestReadyToActivateEmpty); // Test if the LTHI receives ReadyToActivate notifications from the TileManager // when some raster tasks flagged as REQUIRED_FOR_ACTIVATION got scheduled. @@ -285,9 +286,9 @@ class LayerTreeHostTestReadyToActivateNonEmpty FakeContentLayerClient client_; }; -// Multi-thread only because in single thread the commit goes directly to the -// active tree, so notify ready to activate is skipped. -MULTI_THREAD_TEST_F(LayerTreeHostTestReadyToActivateNonEmpty); +// No single thread test because the commit goes directly to the active tree in +// single thread mode, so notify ready to activate is skipped. +REMOTE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestReadyToActivateNonEmpty); // Test if the LTHI receives ReadyToDraw notifications from the TileManager when // no raster tasks get scheduled. @@ -327,7 +328,7 @@ class LayerTreeHostTestReadyToDrawEmpty : public LayerTreeHostTest { size_t required_for_draw_count_; }; -SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestReadyToDrawEmpty); +SINGLE_MULTI_AND_REMOTE_TEST_F(LayerTreeHostTestReadyToDrawEmpty); // Test if the LTHI receives ReadyToDraw notifications from the TileManager when // some raster tasks flagged as REQUIRED_FOR_DRAW got scheduled. @@ -434,6 +435,8 @@ class LayerTreeHostTestReadyToDrawVisibility : public LayerTreeHostTest { // single threaded mode. SINGLE_THREAD_TEST_F(LayerTreeHostTestReadyToDrawVisibility); +// Since the LayerTreeHostContextCacheTests exclusively tests the behavior of +// LayerTreeHostImpl, they don't need to run for the remote mode. class LayerTreeHostContextCacheTest : public LayerTreeHostTest { public: std::unique_ptr<TestCompositorFrameSink> CreateCompositorFrameSink( @@ -573,35 +576,36 @@ class LayerTreeHostFreeContextResourcesOnDestroy SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostFreeContextResourcesOnDestroy); // Test if the LTH successfully frees and stops freeing context resources -// when the OutputSurface is lost and recreated. -class LayerTreeHostCacheBehaviorOnOutputSurfaceRecreated +// when the CompositorFrameSink is lost and recreated. +class LayerTreeHostCacheBehaviorOnCompositorFrameSinkRecreated : public LayerTreeHostContextCacheTest { public: void WillBeginImplFrameOnThread(LayerTreeHostImpl* host_impl, const BeginFrameArgs& args) override { - // This code is run once, to trigger recreation of our OutputSurface. - if (has_recreated_) + // This code is run once, to trigger recreation of our CompositorFrameSink. + if (test_state_ != TestState::INIT) return; // Ensure that our initialization expectations have completed. Mock::VerifyAndClearExpectations(mock_main_context_support_); Mock::VerifyAndClearExpectations(mock_worker_context_support_); - // Output surface lost expectations. + // CompositorFrameSink lost expectations. EXPECT_CALL(*mock_worker_context_support_, SetAggressivelyFreeResources(true)); EXPECT_CALL(*mock_main_context_support_, SetAggressivelyFreeResources(true)); host_impl->DidLoseCompositorFrameSink(); - has_recreated_ = true; + test_state_ = TestState::RECREATED; } - void DidInitializeCompositorFrameSink() override { - // This is run after we have recreated our OutputSurface. - if (!has_recreated_) + void InitializedRendererOnThread(LayerTreeHostImpl* host_impl, + bool success) override { + // This is run after we have recreated our CompositorFrameSink. + if (test_state_ != TestState::RECREATED) return; - // Ensure that our initialization expectations have completed. + // Ensure that our expectations have completed. Mock::VerifyAndClearExpectations(mock_main_context_support_); Mock::VerifyAndClearExpectations(mock_worker_context_support_); @@ -611,14 +615,16 @@ class LayerTreeHostCacheBehaviorOnOutputSurfaceRecreated EXPECT_CALL(*mock_main_context_support_, SetAggressivelyFreeResources(true)); EndTest(); + test_state_ = TestState::DONE; } private: - bool has_recreated_ = false; + enum class TestState { INIT, RECREATED, DONE }; + TestState test_state_ = TestState::INIT; }; SINGLE_AND_MULTI_THREAD_TEST_F( - LayerTreeHostCacheBehaviorOnOutputSurfaceRecreated); + LayerTreeHostCacheBehaviorOnCompositorFrameSinkRecreated); // Two setNeedsCommits in a row should lead to at least 1 commit and at least 1 // draw with frame 0. @@ -651,7 +657,7 @@ class LayerTreeHostTestSetNeedsCommit1 : public LayerTreeHostTest { int num_draws_; }; -SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsCommit1); +SINGLE_MULTI_AND_REMOTE_TEST_F(LayerTreeHostTestSetNeedsCommit1); // A SetNeedsCommit should lead to 1 commit. Issuing a second commit after that // first committed frame draws should lead to another commit. @@ -687,7 +693,7 @@ class LayerTreeHostTestSetNeedsCommit2 : public LayerTreeHostTest { int num_draws_; }; -MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsCommit2); +REMOTE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsCommit2); // Verify that we pass property values in PushPropertiesTo. class LayerTreeHostTestPushPropertiesTo : public LayerTreeHostTest { @@ -782,7 +788,7 @@ class LayerTreeHostTestPushPropertiesTo : public LayerTreeHostTest { int index_; }; -SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestPushPropertiesTo); +SINGLE_MULTI_AND_REMOTE_TEST_F(LayerTreeHostTestPushPropertiesTo); class LayerTreeHostTestPushNodeOwnerToNodeIdMap : public LayerTreeHostTest { protected: @@ -904,6 +910,11 @@ class LayerTreeHostTestPushNodeOwnerToNodeIdMap : public LayerTreeHostTest { scoped_refptr<Layer> child_; }; +// This test compares the value of tree indexes from Layers on the engine to the +// resulting PropertyTrees copied to the pending tree after the commit on the +// client. This will result in a failure for LTH remote test since while the +// client side Layers would have the correct values for these indexes, but the +// engine will never build PropertyTrees in LTH remote. See crbug.com/655795. SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestPushNodeOwnerToNodeIdMap); class LayerTreeHostTestSurfaceDamage : public LayerTreeHostTest { @@ -985,6 +996,12 @@ class LayerTreeHostTestSurfaceDamage : public LayerTreeHostTest { scoped_refptr<Layer> grand_child_; }; +// This test changes properties on the Layer and ensures that the subtree damage +// is tracked correctly on the resulting RenderSurfaceImpl for the corresponding +// LayerImpl. Since the remote code path currently synchronizes the hierarchy +// between the engine and client for every frame, all Layers on the client end +// up being marked as damaged. +// Enable this when crbug.com/605170 is fixed. SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSurfaceDamage); // Verify damage status of property trees is preserved after commit. @@ -1196,6 +1213,9 @@ class LayerTreeHostTestEffectTreeSync : public LayerTreeHostTest { FilterOperations sepia_filter_; }; +// This test verifies that correct values are retained on the impl thread in +// cases where they are animated on that thread. Since remote mode doesn't +// support threaded animations, we don't need to run this in remote mode. SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestEffectTreeSync); class LayerTreeHostTestTransformTreeSync : public LayerTreeHostTest { @@ -1273,6 +1293,9 @@ class LayerTreeHostTestTransformTreeSync : public LayerTreeHostTest { scoped_refptr<Layer> root_; }; +// This test verifies that correct values are retained on the impl thread in +// cases where they are animated on that thread. Since remote mode doesn't +// support threaded animations, we don't need to run this in remote mode. SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestTransformTreeSync); // Verify damage status is updated even when the transform tree doesn't need @@ -1347,6 +1370,9 @@ class LayerTreeHostTestTransformTreeDamageIsUpdated : public LayerTreeHostTest { scoped_refptr<Layer> grand_child_; }; +// This test verifies that correct values are retained on the impl thread in +// cases where they are animated on that thread. Since remote mode doesn't +// support threaded animations, we don't need to run this in remote mode. SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestTransformTreeDamageIsUpdated); // Test that when mask layers switches layers, this gets pushed onto impl. @@ -1417,6 +1443,12 @@ class LayerTreeHostTestSwitchMaskLayer : public LayerTreeHostTest { int index_; }; +// This test also verifies that the Layers updated in a main frame correspond +// only to the Layers that need updates computed using +// draw_property_utils::FindLayersThatNeedUpdates. Since LayerTreeHostRemote +// currently updates all Layers during the main frame, the test fails for remote +// mode. +// TODO(xingliu): Revisit enabling this when crbug.com/650885 is resolved. SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSwitchMaskLayer); // 1 setNeedsRedraw after the first commit has completed should lead to 1 @@ -1453,7 +1485,7 @@ class LayerTreeHostTestSetNeedsRedraw : public LayerTreeHostTest { int num_draws_; }; -MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsRedraw); +REMOTE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsRedraw); // After setNeedsRedrawRect(invalid_rect) the final damage_rect // must contain invalid_rect. @@ -1511,7 +1543,7 @@ class LayerTreeHostTestSetNeedsRedrawRect : public LayerTreeHostTest { scoped_refptr<FakePictureLayer> root_layer_; }; -SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsRedrawRect); +SINGLE_MULTI_AND_REMOTE_TEST_F(LayerTreeHostTestSetNeedsRedrawRect); // Ensure the texture size of the pending and active trees are identical when a // layer is not in the viewport and a resize happens on the viewport @@ -1590,7 +1622,7 @@ class LayerTreeHostTestGpuRasterDeviceSizeChanged : public LayerTreeHostTest { // As there's no pending tree in single-threaded case, this test should run // only for multi-threaded case. -MULTI_THREAD_TEST_F(LayerTreeHostTestGpuRasterDeviceSizeChanged); +REMOTE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestGpuRasterDeviceSizeChanged); class LayerTreeHostTestNoExtraCommitFromInvalidate : public LayerTreeHostTest { public: @@ -1640,7 +1672,7 @@ class LayerTreeHostTestNoExtraCommitFromInvalidate : public LayerTreeHostTest { scoped_refptr<Layer> scaled_layer_; }; -SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoExtraCommitFromInvalidate); +SINGLE_MULTI_AND_REMOTE_TEST_F(LayerTreeHostTestNoExtraCommitFromInvalidate); class LayerTreeHostTestNoExtraCommitFromScrollbarInvalidate : public LayerTreeHostTest { @@ -1697,6 +1729,8 @@ class LayerTreeHostTestNoExtraCommitFromScrollbarInvalidate scoped_refptr<FakePaintedScrollbarLayer> scrollbar_; }; +// No remote test here because PaintedScrollbarLayer is not supported by LTH +// remote. SINGLE_AND_MULTI_THREAD_TEST_F( LayerTreeHostTestNoExtraCommitFromScrollbarInvalidate); @@ -1764,7 +1798,7 @@ class LayerTreeHostTestDeviceScaleFactorChange : public LayerTreeHostTest { scoped_refptr<Layer> child_layer_; }; -SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDeviceScaleFactorChange); +SINGLE_MULTI_AND_REMOTE_TEST_F(LayerTreeHostTestDeviceScaleFactorChange); class LayerTreeHostTestDeviceColorSpaceChange : public LayerTreeHostTest { public: @@ -1887,6 +1921,9 @@ class LayerTreeHostTestDeviceColorSpaceChange : public LayerTreeHostTest { scoped_refptr<Layer> child_layer_; }; +// No remote test because LTH remote doesn't serialize device_color_space, so +// LTH in process will always use the default color space here. +// see crbug/658786. SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDeviceColorSpaceChange); class LayerTreeHostTestSetNextCommitForcesRedraw : public LayerTreeHostTest { @@ -1977,6 +2014,7 @@ class LayerTreeHostTestSetNextCommitForcesRedraw : public LayerTreeHostTest { // This test blocks activation which is not supported for single thread mode. MULTI_THREAD_BLOCKNOTIFY_TEST_F(LayerTreeHostTestSetNextCommitForcesRedraw); +REMOTE_TEST_F(LayerTreeHostTestSetNextCommitForcesRedraw); // Tests that if a layer is not drawn because of some reason in the parent then // its damage is preserved until the next time it is drawn. @@ -2073,7 +2111,7 @@ class LayerTreeHostTestUndrawnLayersDamageLater : public LayerTreeHostTest { scoped_refptr<FakePictureLayer> child_layer_; }; -SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestUndrawnLayersDamageLater); +SINGLE_MULTI_AND_REMOTE_TEST_F(LayerTreeHostTestUndrawnLayersDamageLater); // Tests that if a layer is not drawn because of some reason in the parent then // its damage is preserved until the next time it is drawn. @@ -2178,7 +2216,7 @@ class LayerTreeHostTestDamageWithScale : public LayerTreeHostTest { scoped_refptr<Layer> child_layer_; }; -SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDamageWithScale); +SINGLE_MULTI_AND_REMOTE_TEST_F(LayerTreeHostTestDamageWithScale); // This test verifies that properties on the layer tree host are commited // to the impl side. @@ -2222,7 +2260,7 @@ class LayerTreeHostTestCommit : public LayerTreeHostTest { void AfterTest() override {} }; -MULTI_THREAD_TEST_F(LayerTreeHostTestCommit); +REMOTE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestCommit); // This test verifies that LayerTreeHostImpl's current frame time gets // updated in consecutive frames when it doesn't draw due to tree @@ -2280,6 +2318,7 @@ class LayerTreeHostTestFrameTimeUpdatesAfterActivationFails // This test blocks activation which is not supported for single thread mode. MULTI_THREAD_BLOCKNOTIFY_TEST_F( LayerTreeHostTestFrameTimeUpdatesAfterActivationFails); +REMOTE_TEST_F(LayerTreeHostTestFrameTimeUpdatesAfterActivationFails); // This test verifies that LayerTreeHostImpl's current frame time gets // updated in consecutive frames when it draws in each frame. @@ -2328,7 +2367,7 @@ class LayerTreeHostTestFrameTimeUpdatesAfterDraw : public LayerTreeHostTest { base::TimeTicks first_frame_time_; }; -SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestFrameTimeUpdatesAfterDraw); +SINGLE_MULTI_AND_REMOTE_TEST_F(LayerTreeHostTestFrameTimeUpdatesAfterDraw); // Verifies that StartPageScaleAnimation events propagate correctly // from LayerTreeHost to LayerTreeHostImpl in the MT compositor. @@ -2406,6 +2445,7 @@ class LayerTreeHostTestStartPageScaleAnimation : public LayerTreeHostTest { }; // Single thread proxy does not support impl-side page scale changes. +// Remote test does not support page scale animation. MULTI_THREAD_TEST_F(LayerTreeHostTestStartPageScaleAnimation); class LayerTreeHostTestSetVisible : public LayerTreeHostTest { @@ -2436,7 +2476,7 @@ class LayerTreeHostTestSetVisible : public LayerTreeHostTest { int num_draws_; }; -MULTI_THREAD_TEST_F(LayerTreeHostTestSetVisible); +REMOTE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetVisible); class LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers : public LayerTreeHostTest { @@ -2538,7 +2578,8 @@ class LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers scoped_refptr<FakePictureLayer> child_layer_; }; -MULTI_THREAD_TEST_F(LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers); +REMOTE_AND_MULTI_THREAD_TEST_F( + LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers); class LayerTreeHostTestContinuousInvalidate : public LayerTreeHostTest { public: @@ -2588,7 +2629,7 @@ class LayerTreeHostTestContinuousInvalidate : public LayerTreeHostTest { int num_draw_layers_; }; -SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousInvalidate); +SINGLE_MULTI_AND_REMOTE_TEST_F(LayerTreeHostTestContinuousInvalidate); class LayerTreeHostTestDeferCommits : public LayerTreeHostTest { public: @@ -2646,7 +2687,7 @@ class LayerTreeHostTestDeferCommits : public LayerTreeHostTest { int num_send_begin_main_frame_; }; -SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDeferCommits); +SINGLE_MULTI_AND_REMOTE_TEST_F(LayerTreeHostTestDeferCommits); class LayerTreeHostTestCompositeImmediatelyStateTransitions : public LayerTreeHostTest { @@ -2805,7 +2846,7 @@ class LayerTreeHostTestLCDChange : public LayerTreeHostTest { int num_tiles_rastered_; }; -SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestLCDChange); +SINGLE_MULTI_AND_REMOTE_TEST_F(LayerTreeHostTestLCDChange); class LayerTreeHostTestBeginFrameNotificationShutdownWhileEnabled : public LayerTreeHostTest { @@ -2827,6 +2868,8 @@ class LayerTreeHostTestBeginFrameNotificationShutdownWhileEnabled void AfterTest() override {} }; +// No remote test since synchronous renderer compositor is not supported for LTH +// remote. MULTI_THREAD_TEST_F( LayerTreeHostTestBeginFrameNotificationShutdownWhileEnabled); @@ -2880,7 +2923,6 @@ class OnDrawCompositorFrameSink : public TestCompositorFrameSink { explicit OnDrawCompositorFrameSink( scoped_refptr<ContextProvider> compositor_context_provider, scoped_refptr<ContextProvider> worker_context_provider, - std::unique_ptr<OutputSurface> display_output_surface, SharedBitmapManager* shared_bitmap_manager, gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, const RendererSettings& renderer_settings, @@ -2890,7 +2932,6 @@ class OnDrawCompositorFrameSink : public TestCompositorFrameSink { base::Closure invalidate_callback) : TestCompositorFrameSink(std::move(compositor_context_provider), std::move(worker_context_provider), - std::move(display_output_surface), shared_bitmap_manager, gpu_memory_buffer_manager, renderer_settings, @@ -2927,16 +2968,15 @@ class LayerTreeHostTestAbortedCommitDoesntStallSynchronousCompositor &LayerTreeHostTestAbortedCommitDoesntStallSynchronousCompositor:: CallOnDraw, base::Unretained(this)); - auto output_surface = base::MakeUnique<OnDrawCompositorFrameSink>( + auto frame_sink = base::MakeUnique<OnDrawCompositorFrameSink>( compositor_context_provider, std::move(worker_context_provider), - CreateDisplayOutputSurface(compositor_context_provider), shared_bitmap_manager(), gpu_memory_buffer_manager(), layer_tree_host()->GetSettings().renderer_settings, ImplThreadTaskRunner(), false /* synchronous_composite */, false /* force_disable_reclaim_resources */, std::move(on_draw_callback)); - output_surface_ = output_surface.get(); - return std::move(output_surface); + compositor_frame_sink_ = frame_sink.get(); + return std::move(frame_sink); } void CallOnDraw() { @@ -2946,14 +2986,16 @@ class LayerTreeHostTestAbortedCommitDoesntStallSynchronousCompositor bool resourceless_software_draw = false; ImplThreadTaskRunner()->PostTask( FROM_HERE, base::Bind(&OnDrawCompositorFrameSink::OnDraw, - base::Unretained(output_surface_), + base::Unretained(compositor_frame_sink_), resourceless_software_draw)); } } - OnDrawCompositorFrameSink* output_surface_ = nullptr; + OnDrawCompositorFrameSink* compositor_frame_sink_ = nullptr; }; +// No remote test since synchronous renderer compositor is not supported for LTH +// remote. MULTI_THREAD_TEST_F( LayerTreeHostTestAbortedCommitDoesntStallSynchronousCompositor); @@ -2981,7 +3023,7 @@ class LayerTreeHostTestUninvertibleTransformDoesNotBlockActivation FakeContentLayerClient client_; }; -SINGLE_AND_MULTI_THREAD_TEST_F( +SINGLE_MULTI_AND_REMOTE_TEST_F( LayerTreeHostTestUninvertibleTransformDoesNotBlockActivation); class LayerTreeHostTestNumFramesPending : public LayerTreeHostTest { @@ -3001,12 +3043,13 @@ class LayerTreeHostTestNumFramesPending : public LayerTreeHostTest { case 2: // Round 2 done. EXPECT_EQ(1, frame_); - layer_tree_host()->SetNeedsRedraw(); + layer_tree_host()->SetNeedsRedrawRect( + gfx::Rect(layer_tree()->device_viewport_size())); break; } } - void DidCompleteSwapBuffers() override { + void DidReceiveCompositorFrameAck() override { int commit = layer_tree_host()->SourceFrameNumber(); ++frame_; switch (frame_) { @@ -3029,7 +3072,7 @@ class LayerTreeHostTestNumFramesPending : public LayerTreeHostTest { int frame_; }; -SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNumFramesPending); +SINGLE_MULTI_AND_REMOTE_TEST_F(LayerTreeHostTestNumFramesPending); class LayerTreeHostTestResourcelessSoftwareDraw : public LayerTreeHostTest { protected: @@ -3065,16 +3108,15 @@ class LayerTreeHostTestResourcelessSoftwareDraw : public LayerTreeHostTest { auto on_draw_callback = base::Bind(&LayerTreeHostTestResourcelessSoftwareDraw::CallOnDraw, base::Unretained(this)); - auto output_surface = base::MakeUnique<OnDrawCompositorFrameSink>( + auto frame_sink = base::MakeUnique<OnDrawCompositorFrameSink>( compositor_context_provider, std::move(worker_context_provider), - CreateDisplayOutputSurface(compositor_context_provider), shared_bitmap_manager(), gpu_memory_buffer_manager(), layer_tree_host()->GetSettings().renderer_settings, ImplThreadTaskRunner(), false /* synchronous_composite */, false /* force_disable_reclaim_resources */, std::move(on_draw_callback)); - output_surface_ = output_surface.get(); - return std::move(output_surface); + compositor_frame_sink_ = frame_sink.get(); + return std::move(frame_sink); } void BeginTest() override { PostSetNeedsCommitToMainThread(); } @@ -3086,7 +3128,7 @@ class LayerTreeHostTestResourcelessSoftwareDraw : public LayerTreeHostTest { bool resourceless_software_draw = true; ImplThreadTaskRunner()->PostTask( FROM_HERE, base::Bind(&OnDrawCompositorFrameSink::OnDraw, - base::Unretained(output_surface_), + base::Unretained(compositor_frame_sink_), resourceless_software_draw)); } } @@ -3127,7 +3169,7 @@ class LayerTreeHostTestResourcelessSoftwareDraw : public LayerTreeHostTest { void AfterTest() override {} private: - OnDrawCompositorFrameSink* output_surface_ = nullptr; + OnDrawCompositorFrameSink* compositor_frame_sink_ = nullptr; FakeContentLayerClient client_; scoped_refptr<Layer> root_layer_; scoped_refptr<Layer> parent_layer_; @@ -3136,6 +3178,8 @@ class LayerTreeHostTestResourcelessSoftwareDraw : public LayerTreeHostTest { }; // Resourceless is not used for SingleThreadProxy, so it is unimplemented. +// No remote test since synchronous renderer compositor is not supported for LTH +// remote. MULTI_THREAD_TEST_F(LayerTreeHostTestResourcelessSoftwareDraw); // Test for UI Resource management. @@ -3232,85 +3276,10 @@ class LayerTreeHostTestUIResource : public LayerTreeHostTest { int num_ui_resources_; }; +// No remote test since LTH remote does not support UIResourceLayers and +// PaintedScrollbarLayers, which uses UIResourceManager. MULTI_THREAD_TEST_F(LayerTreeHostTestUIResource); -class PushPropertiesCountingLayerImpl : public LayerImpl { - public: - static std::unique_ptr<PushPropertiesCountingLayerImpl> Create( - LayerTreeImpl* tree_impl, - int id) { - return base::WrapUnique(new PushPropertiesCountingLayerImpl(tree_impl, id)); - } - - ~PushPropertiesCountingLayerImpl() override {} - - void PushPropertiesTo(LayerImpl* layer) override { - LayerImpl::PushPropertiesTo(layer); - push_properties_count_++; - // Push state to the active tree because we can only access it from there. - static_cast<PushPropertiesCountingLayerImpl*>(layer) - ->push_properties_count_ = push_properties_count_; - } - - std::unique_ptr<LayerImpl> CreateLayerImpl( - LayerTreeImpl* tree_impl) override { - return PushPropertiesCountingLayerImpl::Create(tree_impl, id()); - } - - size_t push_properties_count() const { return push_properties_count_; } - void reset_push_properties_count() { push_properties_count_ = 0; } - - private: - size_t push_properties_count_; - - PushPropertiesCountingLayerImpl(LayerTreeImpl* tree_impl, int id) - : LayerImpl(tree_impl, id), push_properties_count_(0) { - SetBounds(gfx::Size(1, 1)); - } -}; - -class PushPropertiesCountingLayer : public Layer { - public: - static scoped_refptr<PushPropertiesCountingLayer> Create() { - return new PushPropertiesCountingLayer(); - } - - void PushPropertiesTo(LayerImpl* layer) override { - Layer::PushPropertiesTo(layer); - push_properties_count_++; - if (persist_needs_push_properties_) { - GetLayerTree()->AddLayerShouldPushProperties(this); - } - } - - // Something to make this layer push properties, but no other layer. - void MakePushProperties() { SetContentsOpaque(!contents_opaque()); } - - std::unique_ptr<LayerImpl> CreateLayerImpl( - LayerTreeImpl* tree_impl) override { - return PushPropertiesCountingLayerImpl::Create(tree_impl, id()); - } - - void SetDrawsContent(bool draws_content) { SetIsDrawable(draws_content); } - - size_t push_properties_count() const { return push_properties_count_; } - void reset_push_properties_count() { push_properties_count_ = 0; } - - void set_persist_needs_push_properties(bool persist) { - persist_needs_push_properties_ = persist; - } - - private: - PushPropertiesCountingLayer() - : push_properties_count_(0), persist_needs_push_properties_(false) { - SetBounds(gfx::Size(1, 1)); - } - ~PushPropertiesCountingLayer() override {} - - size_t push_properties_count_; - bool persist_needs_push_properties_; -}; - class LayerTreeHostTestLayersPushProperties : public LayerTreeHostTest { protected: void BeginTest() override { @@ -3511,6 +3480,9 @@ class LayerTreeHostTestLayersPushProperties : public LayerTreeHostTest { size_t expected_push_properties_leaf_layer_; }; +// No remote test because LTH remote does not build property trees, so layers +// to push properties are different between engine and client. +// See crbug/655795. MULTI_THREAD_TEST_F(LayerTreeHostTestLayersPushProperties); class LayerTreeHostTestImplLayersPushProperties @@ -3707,7 +3679,9 @@ class LayerTreeHostTestImplLayersPushProperties size_t expected_push_properties_grandchild2_impl_; }; -// In single thread there's no pending tree to push properties from. +// No remote test because LTH remote does not build property trees, so layers +// to push properties are different between engine and client. +// See crbug/655795. MULTI_THREAD_TEST_F(LayerTreeHostTestImplLayersPushProperties); class LayerTreeHostTestPropertyChangesDuringUpdateArePushed @@ -3765,6 +3739,7 @@ class LayerTreeHostTestPropertyChangesDuringUpdateArePushed scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer_; }; +// No remote test since remote LTH does not support PaintedScrollbarLayer. MULTI_THREAD_TEST_F(LayerTreeHostTestPropertyChangesDuringUpdateArePushed); class LayerTreeHostTestSetDrawableCausesCommit : public LayerTreeHostTest { @@ -3796,7 +3771,7 @@ class LayerTreeHostTestSetDrawableCausesCommit : public LayerTreeHostTest { EXPECT_EQ(0, root_->NumDescendantsThatDrawContent()); root_->reset_push_properties_count(); child_->reset_push_properties_count(); - child_->SetDrawsContent(true); + child_->SetIsDrawable(true); EXPECT_EQ(1, root_->NumDescendantsThatDrawContent()); EXPECT_EQ(0u, root_->push_properties_count()); EXPECT_EQ(0u, child_->push_properties_count()); @@ -3825,7 +3800,7 @@ class LayerTreeHostTestSetDrawableCausesCommit : public LayerTreeHostTest { scoped_refptr<PushPropertiesCountingLayer> child_; }; -MULTI_THREAD_TEST_F(LayerTreeHostTestSetDrawableCausesCommit); +REMOTE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetDrawableCausesCommit); class LayerTreeHostTestCasePushPropertiesThreeGrandChildren : public LayerTreeHostTest { @@ -3898,7 +3873,8 @@ class LayerTreeHostTestPushPropertiesAddingToTreeRequiresPush } }; -MULTI_THREAD_TEST_F(LayerTreeHostTestPushPropertiesAddingToTreeRequiresPush); +REMOTE_AND_MULTI_THREAD_TEST_F( + LayerTreeHostTestPushPropertiesAddingToTreeRequiresPush); class LayerTreeHostTestPushPropertiesRemovingChildStopsRecursion : public LayerTreeHostTestCasePushPropertiesThreeGrandChildren { @@ -3981,7 +3957,8 @@ class LayerTreeHostTestPushPropertiesRemovingChildStopsRecursion } }; -MULTI_THREAD_TEST_F(LayerTreeHostTestPushPropertiesRemovingChildStopsRecursion); +REMOTE_AND_MULTI_THREAD_TEST_F( + LayerTreeHostTestPushPropertiesRemovingChildStopsRecursion); class LayerTreeHostTestPushPropertiesRemovingChildStopsRecursionWithPersistence : public LayerTreeHostTestCasePushPropertiesThreeGrandChildren { @@ -4029,7 +4006,7 @@ class LayerTreeHostTestPushPropertiesRemovingChildStopsRecursionWithPersistence } }; -MULTI_THREAD_TEST_F( +REMOTE_AND_MULTI_THREAD_TEST_F( LayerTreeHostTestPushPropertiesRemovingChildStopsRecursionWithPersistence); class LayerTreeHostTestPushPropertiesSetPropertiesWhileOutsideTree @@ -4098,7 +4075,7 @@ class LayerTreeHostTestPushPropertiesSetPropertiesWhileOutsideTree } }; -MULTI_THREAD_TEST_F( +REMOTE_AND_MULTI_THREAD_TEST_F( LayerTreeHostTestPushPropertiesSetPropertiesWhileOutsideTree); class LayerTreeHostTestPushPropertiesSetPropertyInParentThenChild @@ -4163,7 +4140,7 @@ class LayerTreeHostTestPushPropertiesSetPropertyInParentThenChild } }; -MULTI_THREAD_TEST_F( +REMOTE_AND_MULTI_THREAD_TEST_F( LayerTreeHostTestPushPropertiesSetPropertyInParentThenChild); class LayerTreeHostTestPushPropertiesSetPropertyInChildThenParent @@ -4228,7 +4205,7 @@ class LayerTreeHostTestPushPropertiesSetPropertyInChildThenParent } }; -MULTI_THREAD_TEST_F( +REMOTE_AND_MULTI_THREAD_TEST_F( LayerTreeHostTestPushPropertiesSetPropertyInChildThenParent); // This test verifies that the tree activation callback is invoked correctly. @@ -4287,7 +4264,7 @@ class LayerTreeHostTestTreeActivationCallback : public LayerTreeHostTest { int callback_count_; }; -SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestTreeActivationCallback); +SINGLE_MULTI_AND_REMOTE_TEST_F(LayerTreeHostTestTreeActivationCallback); class LayerInvalidateCausesDraw : public LayerTreeHostTest { public: @@ -4350,6 +4327,7 @@ class LayerTreeHostTestVideoLayerInvalidate : public LayerInvalidateCausesDraw { FakeVideoFrameProvider provider_; }; +// LTH remote does not support VideoLayer. SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestVideoLayerInvalidate); class LayerTreeHostTestPushHiddenLayer : public LayerTreeHostTest { @@ -4417,7 +4395,7 @@ class LayerTreeHostTestPushHiddenLayer : public LayerTreeHostTest { scoped_refptr<SolidColorLayer> child_layer_; }; -SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestPushHiddenLayer); +SINGLE_MULTI_AND_REMOTE_TEST_F(LayerTreeHostTestPushHiddenLayer); class LayerTreeHostTestUpdateLayerInEmptyViewport : public LayerTreeHostTest { protected: @@ -4450,7 +4428,7 @@ class LayerTreeHostTestUpdateLayerInEmptyViewport : public LayerTreeHostTest { scoped_refptr<FakePictureLayer> root_layer_; }; -MULTI_THREAD_TEST_F(LayerTreeHostTestUpdateLayerInEmptyViewport); +REMOTE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestUpdateLayerInEmptyViewport); class LayerTreeHostTestElasticOverscroll : public LayerTreeHostTest { public: @@ -4545,6 +4523,7 @@ class LayerTreeHostTestElasticOverscroll : public LayerTreeHostTest { int num_draws_; }; +// Remote test does not support enable_elastic_overscroll. MULTI_THREAD_TEST_F(LayerTreeHostTestElasticOverscroll); struct TestSwapPromiseResult { @@ -4649,6 +4628,9 @@ class PinnedLayerTreeSwapPromise : public LayerTreeHostTest { TestSwapPromiseResult pinned_active_swap_promise_result_; }; +// No remote test because this test compares the swap promises result between +// LTH in process and LTH impl. LTH remote runs its own swap promise, and we +// don't send swap promises to the client. MULTI_THREAD_TEST_F(PinnedLayerTreeSwapPromise); class LayerTreeHostTestBreakSwapPromise : public LayerTreeHostTest { @@ -4746,6 +4728,8 @@ class LayerTreeHostTestBreakSwapPromise : public LayerTreeHostTest { TestSwapPromiseResult swap_promise_result_[3]; }; +// No remote test because LTH remote runs its own swap promises, and we +// don't send swap promises to the LTH in process on the client side. MULTI_THREAD_TEST_F(LayerTreeHostTestBreakSwapPromise); class LayerTreeHostTestKeepSwapPromise : public LayerTreeHostTest { @@ -4837,6 +4821,8 @@ class LayerTreeHostTestKeepSwapPromise : public LayerTreeHostTest { TestSwapPromiseResult swap_promise_result_; }; +// No remote test because LTH remote runs its own swap promises, and we +// don't send swap promises to the LTH in process on the client side. SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestKeepSwapPromise); class LayerTreeHostTestKeepSwapPromiseMFBA : public LayerTreeHostTest { @@ -4951,6 +4937,8 @@ class LayerTreeHostTestKeepSwapPromiseMFBA : public LayerTreeHostTest { TestSwapPromiseResult swap_promise_result_; }; +// No remote test because LTH remote runs its own swap promises, and we +// don't send swap promises to the LTH in process on the client side. MULTI_THREAD_TEST_F(LayerTreeHostTestKeepSwapPromiseMFBA); class LayerTreeHostTestBreakSwapPromiseForVisibility @@ -4993,6 +4981,8 @@ class LayerTreeHostTestBreakSwapPromiseForVisibility TestSwapPromiseResult swap_promise_result_; }; +// No remote test because LTH remote runs its own swap promises, and we +// don't send swap promises to the LTH in process on the client side. SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestBreakSwapPromiseForVisibility); class SimpleSwapPromiseMonitor : public SwapPromiseMonitor { @@ -5076,6 +5066,8 @@ class LayerTreeHostTestSimpleSwapPromiseMonitor : public LayerTreeHostTest { void AfterTest() override {} }; +// No remote test because LTH remote runs its own swap promises, and we +// don't send swap promises to the LTH in process on the client side. SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSimpleSwapPromiseMonitor); class LayerTreeHostTestHighResRequiredAfterEvictingUIResources @@ -5297,6 +5289,8 @@ class LayerTreeHostTestGpuRasterizationEnabled : public LayerTreeHostTest { FakeRecordingSource* recording_source_; }; +// No remote test since we does not send gpu rasterization flag to the client. +// See crbug/650431. MULTI_THREAD_TEST_F(LayerTreeHostTestGpuRasterizationEnabled); class LayerTreeHostTestGpuRasterizationReenabled : public LayerTreeHostTest { @@ -5640,7 +5634,6 @@ class LayerTreeHostTestSynchronousCompositeSwapPromise bool force_disable_reclaim_resources = !reclaim_resources_; return base::MakeUnique<TestCompositorFrameSink>( compositor_context_provider, std::move(worker_context_provider), - CreateDisplayOutputSurface(compositor_context_provider), shared_bitmap_manager(), gpu_memory_buffer_manager(), layer_tree_host()->GetSettings().renderer_settings, ImplThreadTaskRunner(), synchronous_composite, @@ -5942,14 +5935,14 @@ class LayerTreeHostTestCrispUpAfterPinchEnds : public LayerTreeHostTest { // On frame 3, we will have a lower res tile complete for the pinch-out // gesture even though it's not displayed. We wait for it here to prevent // flakiness. - EXPECT_EQ(0.75f, tile->contents_scale()); + EXPECT_EQ(0.75f, tile->contents_scale_key()); PostNextAfterDraw(host_impl); } // On frame_ == 4, we are preventing texture uploads from completing, // so this verifies they are not completing before frame_ == 5. // Flaky failures here indicate we're failing to prevent uploads from // completing. - EXPECT_NE(4, frame_) << tile->contents_scale(); + EXPECT_NE(4, frame_) << tile->contents_scale_key(); } void AfterTest() override {} @@ -5967,7 +5960,7 @@ MULTI_THREAD_TEST_F(LayerTreeHostTestCrispUpAfterPinchEnds); class LayerTreeHostTestCrispUpAfterPinchEndsWithOneCopy : public LayerTreeHostTestCrispUpAfterPinchEnds { protected: - std::unique_ptr<OutputSurface> CreateDisplayOutputSurface( + std::unique_ptr<OutputSurface> CreateDisplayOutputSurfaceOnThread( scoped_refptr<ContextProvider> compositor_context_provider) override { scoped_refptr<TestContextProvider> display_context_provider = TestContextProvider::Create(); @@ -5977,7 +5970,8 @@ class LayerTreeHostTestCrispUpAfterPinchEndsWithOneCopy #if defined(OS_MACOSX) context3d->set_support_texture_rectangle(true); #endif - return LayerTreeTest::CreateDisplayOutputSurface( + display_context_provider->BindToCurrentThread(); + return LayerTreeTest::CreateDisplayOutputSurfaceOnThread( std::move(display_context_provider)); } }; @@ -6730,7 +6724,7 @@ class LayerTreeTestMaskLayerWithDifferentBounds : public LayerTreeTest { FakeContentLayerClient client_; }; -SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeTestMaskLayerWithDifferentBounds); +SINGLE_MULTI_AND_REMOTE_TEST_F(LayerTreeTestMaskLayerWithDifferentBounds); class LayerTreeTestPageScaleFlags : public LayerTreeTest { protected: @@ -6801,7 +6795,7 @@ class LayerTreeTestPageScaleFlags : public LayerTreeTest { std::vector<int> not_affected_by_page_scale_; }; -SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeTestPageScaleFlags); +SINGLE_MULTI_AND_REMOTE_TEST_F(LayerTreeTestPageScaleFlags); class LayerTreeHostTestDestroyWhileInitializingOutputSurface : public LayerTreeHostTest { diff --git a/chromium/cc/trees/layer_tree_host_unittest_animation.cc b/chromium/cc/trees/layer_tree_host_unittest_animation.cc index 44f7d83f7b6..b6c4053e7b9 100644 --- a/chromium/cc/trees/layer_tree_host_unittest_animation.cc +++ b/chromium/cc/trees/layer_tree_host_unittest_animation.cc @@ -44,14 +44,14 @@ class LayerTreeHostAnimationTest : public LayerTreeTest { } void AttachPlayersToTimeline() { - layer_tree()->animation_host()->AddAnimationTimeline(timeline_.get()); + animation_host()->AddAnimationTimeline(timeline_.get()); layer_tree()->SetElementIdsForTesting(); timeline_->AttachPlayer(player_.get()); timeline_->AttachPlayer(player_child_.get()); } void GetImplTimelineAndPlayerByID(const LayerTreeHostImpl& host_impl) { - AnimationHost* animation_host_impl = host_impl.animation_host(); + AnimationHost* animation_host_impl = GetImplAnimationHost(&host_impl); timeline_impl_ = animation_host_impl->GetTimelineById(timeline_id_); EXPECT_TRUE(timeline_impl_); player_impl_ = timeline_impl_->GetPlayerById(player_id_); @@ -60,6 +60,11 @@ class LayerTreeHostAnimationTest : public LayerTreeTest { EXPECT_TRUE(player_child_impl_); } + AnimationHost* GetImplAnimationHost( + const LayerTreeHostImpl* host_impl) const { + return static_cast<AnimationHost*>(host_impl->mutator_host()); + } + protected: scoped_refptr<AnimationTimeline> timeline_; scoped_refptr<AnimationPlayer> player_; @@ -245,7 +250,7 @@ class LayerTreeHostAnimationTestAnimationsGetDeleted void AnimateLayers(LayerTreeHostImpl* host_impl, base::TimeTicks monotonic_time) override { - bool have_animations = !host_impl->animation_host() + bool have_animations = !GetImplAnimationHost(host_impl) ->active_element_animations_for_testing() .empty(); if (!started_animating_ && have_animations) { @@ -304,7 +309,7 @@ class LayerTreeHostAnimationTestAddAnimationWithTimingFunction return; scoped_refptr<AnimationTimeline> timeline_impl = - host_impl->animation_host()->GetTimelineById(timeline_id_); + GetImplAnimationHost(host_impl)->GetTimelineById(timeline_id_); scoped_refptr<AnimationPlayer> player_child_impl = timeline_impl->GetPlayerById(player_child_id_); @@ -369,7 +374,7 @@ class LayerTreeHostAnimationTestSynchronizeAnimationStartTimes void UpdateAnimationState(LayerTreeHostImpl* impl_host, bool has_unfinished_animation) override { scoped_refptr<AnimationTimeline> timeline_impl = - impl_host->animation_host()->GetTimelineById(timeline_id_); + GetImplAnimationHost(impl_host)->GetTimelineById(timeline_id_); scoped_refptr<AnimationPlayer> player_child_impl = timeline_impl->GetPlayerById(player_child_id_); @@ -446,7 +451,7 @@ class LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { scoped_refptr<AnimationTimeline> timeline_impl = - host_impl->animation_host()->GetTimelineById(timeline_id_); + GetImplAnimationHost(host_impl)->GetTimelineById(timeline_id_); scoped_refptr<AnimationPlayer> player_impl = timeline_impl->GetPlayerById(player_id_); @@ -795,20 +800,16 @@ class LayerTreeHostAnimationTestScrollOffsetAnimationTakeover if (layer_tree_host()->SourceFrameNumber() == 1) { // Add an update after the first commit to trigger the animation takeover // path. - layer_tree() - ->animation_host() - ->scroll_offset_animations() - .AddTakeoverUpdate(scroll_layer_->element_id()); - EXPECT_TRUE(layer_tree() - ->animation_host() - ->scroll_offset_animations() - .HasUpdatesForTesting()); + animation_host()->scroll_offset_animations().AddTakeoverUpdate( + scroll_layer_->element_id()); + EXPECT_TRUE( + animation_host()->scroll_offset_animations().HasUpdatesForTesting()); } } void WillCommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { if (host_impl->sync_tree()->source_frame_number() == 0) { - host_impl->animation_host()->ImplOnlyScrollAnimationCreate( + GetImplAnimationHost(host_impl)->ImplOnlyScrollAnimationCreate( scroll_layer_->element_id(), gfx::ScrollOffset(650.f, 750.f), gfx::ScrollOffset(10, 20), base::TimeDelta()); } @@ -854,14 +855,11 @@ class LayerTreeHostAnimationTestScrollOffsetAnimationAdjusted const LayerTreeHostImpl& host_impl, scoped_refptr<FakePictureLayer> layer) const { scoped_refptr<ElementAnimations> element_animations = - host_impl.animation_host()->GetElementAnimationsForElementId( - layer->element_id()); + GetImplAnimationHost(&host_impl) + ->GetElementAnimationsForElementId(layer->element_id()); DCHECK(element_animations); DCHECK(element_animations->players_list().might_have_observers()); - - ElementAnimations::PlayersList::Iterator it( - &element_animations->players_list()); - AnimationPlayer* player = it.GetNext(); + AnimationPlayer* player = &*element_animations->players_list().begin(); DCHECK(player); return *player; } @@ -872,21 +870,14 @@ class LayerTreeHostAnimationTestScrollOffsetAnimationAdjusted if (layer_tree_host()->SourceFrameNumber() == 1) { // Add an update after the first commit to trigger the animation update // path. - layer_tree() - ->animation_host() - ->scroll_offset_animations() - .AddAdjustmentUpdate(scroll_layer_->element_id(), - gfx::Vector2dF(100.f, 100.f)); - EXPECT_TRUE(layer_tree() - ->animation_host() - ->scroll_offset_animations() - .HasUpdatesForTesting()); + animation_host()->scroll_offset_animations().AddAdjustmentUpdate( + scroll_layer_->element_id(), gfx::Vector2dF(100.f, 100.f)); + EXPECT_TRUE( + animation_host()->scroll_offset_animations().HasUpdatesForTesting()); } else if (layer_tree_host()->SourceFrameNumber() == 2) { // Verify that the update queue is cleared after the update is applied. - EXPECT_FALSE(layer_tree() - ->animation_host() - ->scroll_offset_animations() - .HasUpdatesForTesting()); + EXPECT_FALSE( + animation_host()->scroll_offset_animations().HasUpdatesForTesting()); } } @@ -914,7 +905,7 @@ class LayerTreeHostAnimationTestScrollOffsetAnimationAdjusted void WillCommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { if (host_impl->sync_tree()->source_frame_number() == 0) { - host_impl->animation_host()->ImplOnlyScrollAnimationCreate( + GetImplAnimationHost(host_impl)->ImplOnlyScrollAnimationCreate( scroll_layer_->element_id(), gfx::ScrollOffset(650.f, 750.f), gfx::ScrollOffset(10, 20), base::TimeDelta()); } @@ -1040,7 +1031,7 @@ class LayerTreeHostAnimationTestScrollOffsetAnimationRemoval return false; scoped_refptr<AnimationTimeline> timeline_impl = - host_impl->animation_host()->GetTimelineById(timeline_id_); + GetImplAnimationHost(host_impl)->GetTimelineById(timeline_id_); scoped_refptr<AnimationPlayer> player_impl = timeline_impl->GetPlayerById(player_child_id_); @@ -1130,7 +1121,7 @@ class LayerTreeHostAnimationTestAnimationsAddedToNewAndExistingLayers void UpdateAnimationState(LayerTreeHostImpl* host_impl, bool has_unfinished_animation) override { scoped_refptr<AnimationTimeline> timeline_impl = - host_impl->animation_host()->GetTimelineById(timeline_id_); + GetImplAnimationHost(host_impl)->GetTimelineById(timeline_id_); scoped_refptr<AnimationPlayer> player_impl = timeline_impl->GetPlayerById(player_id_); scoped_refptr<AnimationPlayer> player_child_impl = @@ -1208,7 +1199,7 @@ class LayerTreeHostAnimationTestPendingTreeAnimatesFirstCommit return; scoped_refptr<AnimationTimeline> timeline_impl = - host_impl->animation_host()->GetTimelineById(timeline_id_); + GetImplAnimationHost(host_impl)->GetTimelineById(timeline_id_); scoped_refptr<AnimationPlayer> player_impl = timeline_impl->GetPlayerById(player_id_); @@ -1252,7 +1243,7 @@ class LayerTreeHostAnimationTestAnimatedLayerRemovedAndAdded layer_tree()->SetElementIdsForTesting(); - layer_tree()->animation_host()->AddAnimationTimeline(timeline_.get()); + animation_host()->AddAnimationTimeline(timeline_.get()); timeline_->AttachPlayer(player_.get()); player_->AttachElement(layer_->element_id()); DCHECK(player_->element_animations()); @@ -1269,7 +1260,7 @@ class LayerTreeHostAnimationTestAnimatedLayerRemovedAndAdded player_->element_animations()->has_element_in_active_list()); EXPECT_FALSE( player_->element_animations()->has_element_in_pending_list()); - EXPECT_TRUE(layer_tree()->animation_host()->NeedsAnimateLayers()); + EXPECT_TRUE(animation_host()->NeedsAnimateLayers()); break; case 1: layer_->RemoveFromParent(); @@ -1277,7 +1268,7 @@ class LayerTreeHostAnimationTestAnimatedLayerRemovedAndAdded player_->element_animations()->has_element_in_active_list()); EXPECT_FALSE( player_->element_animations()->has_element_in_pending_list()); - EXPECT_FALSE(layer_tree()->animation_host()->NeedsAnimateLayers()); + EXPECT_FALSE(animation_host()->NeedsAnimateLayers()); break; case 2: layer_tree()->root_layer()->AddChild(layer_); @@ -1285,14 +1276,14 @@ class LayerTreeHostAnimationTestAnimatedLayerRemovedAndAdded player_->element_animations()->has_element_in_active_list()); EXPECT_FALSE( player_->element_animations()->has_element_in_pending_list()); - EXPECT_TRUE(layer_tree()->animation_host()->NeedsAnimateLayers()); + EXPECT_TRUE(animation_host()->NeedsAnimateLayers()); break; } } void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { scoped_refptr<AnimationTimeline> timeline_impl = - host_impl->animation_host()->GetTimelineById(timeline_id_); + GetImplAnimationHost(host_impl)->GetTimelineById(timeline_id_); scoped_refptr<AnimationPlayer> player_impl = timeline_impl->GetPlayerById(player_id_); @@ -1300,17 +1291,17 @@ class LayerTreeHostAnimationTestAnimatedLayerRemovedAndAdded case 0: EXPECT_TRUE( player_impl->element_animations()->has_element_in_active_list()); - EXPECT_TRUE(host_impl->animation_host()->NeedsAnimateLayers()); + EXPECT_TRUE(GetImplAnimationHost(host_impl)->NeedsAnimateLayers()); break; case 1: EXPECT_FALSE( player_impl->element_animations()->has_element_in_active_list()); - EXPECT_FALSE(host_impl->animation_host()->NeedsAnimateLayers()); + EXPECT_FALSE(GetImplAnimationHost(host_impl)->NeedsAnimateLayers()); break; case 2: EXPECT_TRUE( player_impl->element_animations()->has_element_in_active_list()); - EXPECT_TRUE(host_impl->animation_host()->NeedsAnimateLayers()); + EXPECT_TRUE(GetImplAnimationHost(host_impl)->NeedsAnimateLayers()); EndTest(); break; } @@ -1375,7 +1366,7 @@ class LayerTreeHostAnimationTestAddAnimationAfterAnimating void CheckAnimations(LayerTreeHostImpl* host_impl) { GetImplTimelineAndPlayerByID(*host_impl); - EXPECT_EQ(2u, host_impl->animation_host() + EXPECT_EQ(2u, GetImplAnimationHost(host_impl) ->active_element_animations_for_testing() .size()); diff --git a/chromium/cc/trees/layer_tree_host_unittest_copyrequest.cc b/chromium/cc/trees/layer_tree_host_unittest_copyrequest.cc index ef0c1fbbc5a..25fe1ec2f2b 100644 --- a/chromium/cc/trees/layer_tree_host_unittest_copyrequest.cc +++ b/chromium/cc/trees/layer_tree_host_unittest_copyrequest.cc @@ -129,7 +129,7 @@ class LayerTreeHostCopyRequestTestMultipleRequests void AfterTest() override { EXPECT_EQ(4u, callbacks_.size()); } - std::unique_ptr<OutputSurface> CreateDisplayOutputSurface( + std::unique_ptr<OutputSurface> CreateDisplayOutputSurfaceOnThread( scoped_refptr<ContextProvider> compositor_context_provider) override { if (!use_gl_renderer_) { return FakeOutputSurface::CreateSoftware( @@ -140,6 +140,7 @@ class LayerTreeHostCopyRequestTestMultipleRequests TestContextProvider::Create(); TestContextSupport* context_support = display_context_provider->support(); context_support->set_out_of_order_callbacks(out_of_order_callbacks_); + display_context_provider->BindToCurrentThread(); return FakeOutputSurface::Create3d(std::move(display_context_provider)); } @@ -466,11 +467,11 @@ class LayerTreeHostTestHiddenSurfaceNotAllocatedForSubtreeCopyRequest std::unique_ptr<TestCompositorFrameSink> CreateCompositorFrameSink( scoped_refptr<ContextProvider> compositor_context_provider, scoped_refptr<ContextProvider> worker_context_provider) override { - auto surface = LayerTreeHostCopyRequestTest::CreateCompositorFrameSink( + auto frame_sink = LayerTreeHostCopyRequestTest::CreateCompositorFrameSink( std::move(compositor_context_provider), std::move(worker_context_provider)); - display_ = surface->display(); - return surface; + frame_sink_ = frame_sink.get(); + return frame_sink; } void BeginTest() override { @@ -507,7 +508,7 @@ class LayerTreeHostTestHiddenSurfaceNotAllocatedForSubtreeCopyRequest } void DisplayDidDrawAndSwapOnThread() override { - DirectRenderer* renderer = display_->renderer_for_testing(); + DirectRenderer* renderer = frame_sink_->display()->renderer_for_testing(); // |parent| owns a surface, but it was hidden and not part of the copy // request so it should not allocate any resource. @@ -533,7 +534,7 @@ class LayerTreeHostTestHiddenSurfaceNotAllocatedForSubtreeCopyRequest RenderPassId parent_render_pass_id; RenderPassId copy_layer_render_pass_id; - Display* display_ = nullptr; + TestCompositorFrameSink* frame_sink_ = nullptr; bool did_swap_ = false; FakeContentLayerClient client_; scoped_refptr<FakePictureLayer> root_; @@ -731,9 +732,10 @@ SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestAsyncTwoReadbacksWithoutDraw); class LayerTreeHostCopyRequestTestDeleteTexture : public LayerTreeHostCopyRequestTest { protected: - std::unique_ptr<OutputSurface> CreateDisplayOutputSurface( + std::unique_ptr<OutputSurface> CreateDisplayOutputSurfaceOnThread( scoped_refptr<ContextProvider> compositor_context_provider) override { display_context_provider_ = TestContextProvider::Create(); + display_context_provider_->BindToCurrentThread(); return FakeOutputSurface::Create3d(display_context_provider_); } @@ -789,6 +791,9 @@ class LayerTreeHostCopyRequestTestDeleteTexture // to be destroyed by the compositor, so we should have 1 less by now. EXPECT_EQ(num_textures_after_readback_ - 1, display_context_provider_->TestContext3d()->NumTextures()); + + // Drop the reference to the context provider on the compositor thread. + display_context_provider_ = nullptr; EndTest(); } @@ -847,7 +852,7 @@ class LayerTreeHostCopyRequestTestCountTextures settings->renderer_settings.texture_id_allocation_chunk_size = 1; } - std::unique_ptr<OutputSurface> CreateDisplayOutputSurface( + std::unique_ptr<OutputSurface> CreateDisplayOutputSurfaceOnThread( scoped_refptr<ContextProvider> compositor_context_provider) override { // These tests expect the LayerTreeHostImpl to share a context with // the Display so that sync points are not needed and the texture counts diff --git a/chromium/cc/trees/layer_tree_host_unittest_damage.cc b/chromium/cc/trees/layer_tree_host_unittest_damage.cc index 561a92a0896..33ff66f3e7a 100644 --- a/chromium/cc/trees/layer_tree_host_unittest_damage.cc +++ b/chromium/cc/trees/layer_tree_host_unittest_damage.cc @@ -43,7 +43,8 @@ class LayerTreeHostDamageTestSetNeedsRedraw void DidCommitAndDrawFrame() override { switch (layer_tree_host()->SourceFrameNumber()) { case 1: - layer_tree_host()->SetNeedsRedraw(); + layer_tree_host()->SetNeedsRedrawRect( + gfx::Rect(layer_tree()->device_viewport_size())); break; } } diff --git a/chromium/cc/trees/layer_tree_host_unittest_picture.cc b/chromium/cc/trees/layer_tree_host_unittest_picture.cc index bb13a32b06e..f7d4fadceeb 100644 --- a/chromium/cc/trees/layer_tree_host_unittest_picture.cc +++ b/chromium/cc/trees/layer_tree_host_unittest_picture.cc @@ -458,19 +458,19 @@ class LayerTreeHostPictureTestRSLLMembershipWithScale case 0: // On 1st commit the pending layer has tilings. ASSERT_EQ(1u, picture->tilings()->num_tilings()); - EXPECT_EQ(1.f, picture->tilings()->tiling_at(0)->contents_scale()); + EXPECT_EQ(1.f, picture->tilings()->tiling_at(0)->contents_scale_key()); break; case 1: // On 2nd commit, the pending layer is transparent, so has a stale // value. ASSERT_EQ(1u, picture->tilings()->num_tilings()); - EXPECT_EQ(1.f, picture->tilings()->tiling_at(0)->contents_scale()); + EXPECT_EQ(1.f, picture->tilings()->tiling_at(0)->contents_scale_key()); break; case 2: // On 3rd commit, the pending layer is visible again, so has tilings and // is updated for the pinch. ASSERT_EQ(1u, picture->tilings()->num_tilings()); - EXPECT_EQ(2.f, picture->tilings()->tiling_at(0)->contents_scale()); + EXPECT_EQ(2.f, picture->tilings()->tiling_at(0)->contents_scale_key()); } } @@ -488,7 +488,7 @@ class LayerTreeHostPictureTestRSLLMembershipWithScale if (draws_in_frame_ == 1) { // On 1st commit the layer has tilings. EXPECT_GT(picture->tilings()->num_tilings(), 0u); - EXPECT_EQ(1.f, picture->HighResTiling()->contents_scale()); + EXPECT_EQ(1.f, picture->HighResTiling()->contents_scale_key()); // Pinch zoom in to change the scale on the active tree. impl->PinchGestureBegin(); @@ -498,7 +498,7 @@ class LayerTreeHostPictureTestRSLLMembershipWithScale // If the pinch gesture caused a commit we could get here with a // pending tree. EXPECT_FALSE(impl->pending_tree()); - EXPECT_EQ(2.f, picture->HighResTiling()->contents_scale()); + EXPECT_EQ(2.f, picture->HighResTiling()->contents_scale_key()); // Need to wait for ready to draw here so that the pinch is // entirely complete, otherwise another draw might come in before @@ -616,10 +616,12 @@ class LayerTreeHostPictureTestForceRecalculateScales case 0: // On first commit, both layers are at the default scale. ASSERT_EQ(1u, will_change_layer->tilings()->num_tilings()); - EXPECT_EQ(1.f, - will_change_layer->tilings()->tiling_at(0)->contents_scale()); + EXPECT_EQ( + 1.f, + will_change_layer->tilings()->tiling_at(0)->contents_scale_key()); ASSERT_EQ(1u, normal_layer->tilings()->num_tilings()); - EXPECT_EQ(1.f, normal_layer->tilings()->tiling_at(0)->contents_scale()); + EXPECT_EQ(1.f, + normal_layer->tilings()->tiling_at(0)->contents_scale_key()); MainThreadTaskRunner()->PostTask( FROM_HERE, @@ -631,10 +633,12 @@ class LayerTreeHostPictureTestForceRecalculateScales // On 2nd commit after scaling up to 2, the normal layer will adjust its // scale and the will change layer should not (as it is will change. ASSERT_EQ(1u, will_change_layer->tilings()->num_tilings()); - EXPECT_EQ(1.f, - will_change_layer->tilings()->tiling_at(0)->contents_scale()); + EXPECT_EQ( + 1.f, + will_change_layer->tilings()->tiling_at(0)->contents_scale_key()); ASSERT_EQ(1u, normal_layer->tilings()->num_tilings()); - EXPECT_EQ(2.f, normal_layer->tilings()->tiling_at(0)->contents_scale()); + EXPECT_EQ(2.f, + normal_layer->tilings()->tiling_at(0)->contents_scale_key()); MainThreadTaskRunner()->PostTask( FROM_HERE, @@ -646,10 +650,12 @@ class LayerTreeHostPictureTestForceRecalculateScales // On 3rd commit, both layers should adjust scales due to forced // recalculating. ASSERT_EQ(1u, will_change_layer->tilings()->num_tilings()); - EXPECT_EQ(4.f, - will_change_layer->tilings()->tiling_at(0)->contents_scale()); + EXPECT_EQ( + 4.f, + will_change_layer->tilings()->tiling_at(0)->contents_scale_key()); ASSERT_EQ(1u, normal_layer->tilings()->num_tilings()); - EXPECT_EQ(4.f, normal_layer->tilings()->tiling_at(0)->contents_scale()); + EXPECT_EQ(4.f, + normal_layer->tilings()->tiling_at(0)->contents_scale_key()); EndTest(); break; } diff --git a/chromium/cc/trees/layer_tree_host_unittest_proxy.cc b/chromium/cc/trees/layer_tree_host_unittest_proxy.cc index e82cd26d5ff..94ca4cb55c0 100644 --- a/chromium/cc/trees/layer_tree_host_unittest_proxy.cc +++ b/chromium/cc/trees/layer_tree_host_unittest_proxy.cc @@ -25,7 +25,7 @@ class LayerTreeHostProxyTest : public LayerTreeTest { return update_check_layer_.get(); } - ProxyMain* GetProxyMain() const { + ProxyMain* GetProxyMain() { DCHECK(HasImplThread()); return static_cast<ProxyMain*>(proxy()); } diff --git a/chromium/cc/trees/layer_tree_host_unittest_record_gpu_histogram.cc b/chromium/cc/trees/layer_tree_host_unittest_record_gpu_histogram.cc index a9b1993bd2e..bb64f2ac81e 100644 --- a/chromium/cc/trees/layer_tree_host_unittest_record_gpu_histogram.cc +++ b/chromium/cc/trees/layer_tree_host_unittest_record_gpu_histogram.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "cc/animation/animation_host.h" #include "cc/test/fake_layer_tree_host.h" #include "cc/test/fake_layer_tree_host_client.h" #include "cc/test/test_task_graph_runner.h" @@ -15,9 +16,10 @@ TEST(LayerTreeHostRecordGpuHistogramTest, SingleThreaded) { FakeLayerTreeHostClient host_client; TestTaskGraphRunner task_graph_runner; LayerTreeSettings settings; - std::unique_ptr<FakeLayerTreeHost> host = - FakeLayerTreeHost::Create(&host_client, &task_graph_runner, settings, - CompositorMode::SINGLE_THREADED); + auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN); + std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create( + &host_client, &task_graph_runner, animation_host.get(), settings, + CompositorMode::SINGLE_THREADED); host->RecordGpuRasterizationHistogram(); EXPECT_FALSE(host->gpu_rasterization_histogram_recorded()); } @@ -26,8 +28,10 @@ TEST(LayerTreeHostRecordGpuHistogramTest, Threaded) { FakeLayerTreeHostClient host_client; TestTaskGraphRunner task_graph_runner; LayerTreeSettings settings; + auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN); std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create( - &host_client, &task_graph_runner, settings, CompositorMode::THREADED); + &host_client, &task_graph_runner, animation_host.get(), settings, + CompositorMode::THREADED); host->RecordGpuRasterizationHistogram(); EXPECT_TRUE(host->gpu_rasterization_histogram_recorded()); } diff --git a/chromium/cc/trees/layer_tree_host_unittest_remote_server.cc b/chromium/cc/trees/layer_tree_host_unittest_remote_server.cc deleted file mode 100644 index 8a41fb9c2db..00000000000 --- a/chromium/cc/trees/layer_tree_host_unittest_remote_server.cc +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright 2016 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. - -#include <memory> - -#include "base/memory/ptr_util.h" -#include "base/threading/thread_task_runner_handle.h" -#include "cc/animation/animation_host.h" -#include "cc/test/fake_image_serialization_processor.h" -#include "cc/test/test_task_graph_runner.h" -#include "cc/trees/layer_tree_host_client.h" -#include "cc/trees/layer_tree_host_in_process.h" -#include "cc/trees/proxy_common.h" -#include "cc/trees/proxy_main.h" -#include "cc/trees/remote_proto_channel.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace cc { -namespace { - -class LayerTreeHostTestRemoteServer : public testing::Test, - public RemoteProtoChannel, - public LayerTreeHostClient { - public: - LayerTreeHostTestRemoteServer() - : calls_received_(0), - image_serialization_processor_( - base::WrapUnique(new FakeImageSerializationProcessor)) { - LayerTreeHostInProcess::InitParams params; - params.client = this; - params.task_graph_runner = &task_graph_runner_; - params.settings = &settings_; - params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); - params.image_serialization_processor = image_serialization_processor_.get(); - params.animation_host = - AnimationHost::CreateForTesting(ThreadInstance::MAIN); - layer_tree_host_ = - LayerTreeHostInProcess::CreateRemoteServer(this, ¶ms); - } - - ~LayerTreeHostTestRemoteServer() override {} - - // LayerTreeHostClient implementation - void WillBeginMainFrame() override {} - void BeginMainFrame(const BeginFrameArgs& args) override {} - void BeginMainFrameNotExpectedSoon() override {} - void DidBeginMainFrame() override {} - void UpdateLayerTreeHost() override {} - void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta, - const gfx::Vector2dF& outer_delta, - const gfx::Vector2dF& elastic_overscroll_delta, - float page_scale, - float top_controls_delta) override {} - void RequestNewCompositorFrameSink() override { NOTREACHED(); } - void DidInitializeCompositorFrameSink() override { NOTREACHED(); } - void DidFailToInitializeCompositorFrameSink() override { NOTREACHED(); } - void WillCommit() override {} - void DidCommit() override {} - void DidCommitAndDrawFrame() override {} - void DidCompleteSwapBuffers() override {} - void DidCompletePageScaleAnimation() override {} - - // RemoteProtoChannel implementation - void SetProtoReceiver(RemoteProtoChannel::ProtoReceiver* receiver) override { - receiver_ = receiver; - } - void SendCompositorProto(const proto::CompositorMessage& proto) override {} - - int calls_received_; - TestTaskGraphRunner task_graph_runner_; - LayerTreeSettings settings_; - std::unique_ptr<LayerTreeHostInProcess> layer_tree_host_; - RemoteProtoChannel::ProtoReceiver* receiver_; - std::unique_ptr<FakeImageSerializationProcessor> - image_serialization_processor_; - - private: - DISALLOW_COPY_AND_ASSIGN(LayerTreeHostTestRemoteServer); -}; - -class LayerTreeHostTestRemoteServerBeginMainFrame - : public LayerTreeHostTestRemoteServer { - protected: - void BeginMainFrame(const BeginFrameArgs& args) override { - calls_received_++; - } -}; - -// Makes sure that the BeginMainFrame call is not aborted on the server. -// See crbug.com/577301. -TEST_F(LayerTreeHostTestRemoteServerBeginMainFrame, BeginMainFrameNotAborted) { - layer_tree_host_->SetVisible(true); - - std::unique_ptr<BeginMainFrameAndCommitState> begin_frame_state; - begin_frame_state.reset(new BeginMainFrameAndCommitState()); - begin_frame_state->scroll_info.reset(new ScrollAndScaleSet()); - - static_cast<ProxyMain*>(layer_tree_host_->proxy()) - ->BeginMainFrame(std::move(begin_frame_state)); - EXPECT_EQ(calls_received_, 1); -} - -} // namespace -} // namespace cc diff --git a/chromium/cc/trees/layer_tree_host_unittest_scroll.cc b/chromium/cc/trees/layer_tree_host_unittest_scroll.cc index 7af261ed77f..473d5285e43 100644 --- a/chromium/cc/trees/layer_tree_host_unittest_scroll.cc +++ b/chromium/cc/trees/layer_tree_host_unittest_scroll.cc @@ -21,10 +21,11 @@ #include "cc/test/fake_picture_layer_impl.h" #include "cc/test/geometry_test_utils.h" #include "cc/test/layer_tree_test.h" -#include "cc/test/test_shared_bitmap_manager.h" #include "cc/test/test_task_graph_runner.h" +#include "cc/trees/layer_tree_host_common.h" #include "cc/trees/layer_tree_impl.h" #include "cc/trees/scroll_node.h" +#include "cc/trees/transform_node.h" #include "testing/gmock/include/gmock/gmock.h" #include "ui/gfx/geometry/point_conversions.h" #include "ui/gfx/geometry/size_conversions.h" @@ -155,7 +156,7 @@ class LayerTreeHostScrollTestScrollSimple : public LayerTreeHostScrollTest { int outer_viewport_container_layer_id_; }; -MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollSimple); +REMOTE_AND_MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollSimple); class LayerTreeHostScrollTestScrollMultipleRedraw : public LayerTreeHostScrollTest { @@ -1306,16 +1307,16 @@ TEST(LayerTreeHostFlingTest, DidStopFlingingThread) { LayerTreeSettings settings; StubLayerTreeHostClient layer_tree_host_client; - TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; + auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN); + LayerTreeHostInProcess::InitParams params; params.client = &layer_tree_host_client; - params.shared_bitmap_manager = &shared_bitmap_manager; params.task_graph_runner = &task_graph_runner; params.settings = &settings; params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); - params.animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN); + params.mutator_host = animation_host.get(); std::unique_ptr<LayerTreeHostInProcess> layer_tree_host = LayerTreeHostInProcess::CreateThreaded(impl_thread.task_runner(), ¶ms); @@ -1328,7 +1329,11 @@ TEST(LayerTreeHostFlingTest, DidStopFlingingThread) { base::Unretained(&input_handler_client))); layer_tree_host->DidStopFlinging(); + + animation_host->SetMutatorHostClient(nullptr); layer_tree_host = nullptr; + animation_host = nullptr; + impl_thread.Stop(); EXPECT_TRUE(received_stop_flinging); } @@ -1977,5 +1982,258 @@ class LayerTreeHostScrollTestElasticOverscroll MULTI_THREAD_TEST_F(LayerTreeHostScrollTestElasticOverscroll); +class LayerTreeHostScrollTestPropertyTreeUpdate + : public LayerTreeHostScrollTest { + public: + LayerTreeHostScrollTestPropertyTreeUpdate() + : initial_scroll_(10, 20), second_scroll_(0, 0) {} + + void BeginTest() override { + layer_tree()->inner_viewport_scroll_layer()->SetScrollOffset( + initial_scroll_); + layer_tree()->inner_viewport_scroll_layer()->SetBounds(gfx::Size(100, 100)); + PostSetNeedsCommitToMainThread(); + } + + void UpdateLayerTreeHost() override { + Layer* scroll_layer = layer_tree()->inner_viewport_scroll_layer(); + if (layer_tree_host()->SourceFrameNumber() == 0) { + EXPECT_VECTOR_EQ(initial_scroll_, scroll_layer->scroll_offset()); + } else { + EXPECT_VECTOR_EQ( + gfx::ScrollOffsetWithDelta(initial_scroll_, scroll_amount_), + scroll_layer->scroll_offset()); + scroll_layer->SetScrollOffset(second_scroll_); + scroll_layer->SetOpacity(0.5f); + } + } + + void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { + LayerImpl* scroll_layer = impl->InnerViewportScrollLayer(); + + switch (impl->active_tree()->source_frame_number()) { + case 0: + EXPECT_VECTOR_EQ(initial_scroll_, ScrollTreeForLayer(scroll_layer) + ->GetScrollOffsetBaseForTesting( + scroll_layer->id())); + EXPECT_VECTOR_EQ( + initial_scroll_, + scroll_layer->layer_tree_impl() + ->property_trees() + ->transform_tree.Node(scroll_layer->transform_tree_index()) + ->scroll_offset); + PostSetNeedsCommitToMainThread(); + break; + case 1: + EXPECT_VECTOR_EQ(second_scroll_, ScrollTreeForLayer(scroll_layer) + ->GetScrollOffsetBaseForTesting( + scroll_layer->id())); + EXPECT_VECTOR_EQ( + second_scroll_, + scroll_layer->layer_tree_impl() + ->property_trees() + ->transform_tree.Node(scroll_layer->transform_tree_index()) + ->scroll_offset); + EndTest(); + break; + } + } + + void AfterTest() override {} + + private: + gfx::ScrollOffset initial_scroll_; + gfx::ScrollOffset second_scroll_; + gfx::Vector2dF scroll_amount_; +}; + +SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostScrollTestPropertyTreeUpdate); + +class LayerTreeHostScrollTestAppliesReflectedDeltas + : public LayerTreeHostScrollTest { + public: + void BeginTest() override { PostSetNeedsCommitToMainThread(); } + + void SetupTree() override { + LayerTreeHostScrollTest::SetupTree(); + + gfx::Size scroll_layer_bounds(200, 200); + layer_tree()->outer_viewport_scroll_layer()->SetBounds(scroll_layer_bounds); + layer_tree()->outer_viewport_scroll_layer()->SetScrollOffset( + initial_offset_); + layer_tree()->outer_viewport_scroll_layer()->set_did_scroll_callback( + base::Bind(&LayerTreeHostScrollTestAppliesReflectedDeltas:: + DidScrollOuterViewport, + base::Unretained(this))); + + layer_tree()->SetPageScaleFactorAndLimits(initial_page_scale_, 0.f, 1.f); + } + + void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { + LayerImpl* outer_viewport_layer = host_impl->OuterViewportScrollLayer(); + + switch (host_impl->active_tree()->source_frame_number()) { + case 0: { + // We have the first tree, so let's scroll the outer viewport layer and + // change the page scale. + outer_viewport_layer->ScrollBy(outer_viewport_offset_deltas_[0]); + last_active_offset_ = outer_viewport_layer->CurrentScrollOffset(); + + host_impl->active_tree()->page_scale_factor()->SetCurrent( + initial_page_scale_ * page_scale_update_); + last_page_scale_ = + host_impl->active_tree()->current_page_scale_factor(); + + PostSetNeedsCommitToMainThread(); + } break; + case 1: + // The scroll offset on the active tree should remain unchanged. + EXPECT_EQ(last_active_offset_, + outer_viewport_layer->CurrentScrollOffset()); + EXPECT_EQ(last_page_scale_, + host_impl->active_tree()->current_page_scale_factor()); + + // Scroll again to make sure that only the delta applied in this frame + // is reported to the main thread. + outer_viewport_layer->ScrollBy(outer_viewport_offset_deltas_[1]); + last_active_offset_ = outer_viewport_layer->CurrentScrollOffset(); + + PostSetNeedsCommitToMainThread(); + break; + case 2: + // The scroll offset on the active tree should remain unchanged. + EXPECT_EQ(last_active_offset_, + outer_viewport_layer->CurrentScrollOffset()); + EXPECT_EQ(last_page_scale_, + host_impl->active_tree()->current_page_scale_factor()); + + // One last frame to make sure we reach consistent state. + PostSetNeedsCommitToMainThread(); + break; + case 3: + // The scroll offset on the active tree should remain unchanged. + EXPECT_EQ(last_active_offset_, + outer_viewport_layer->CurrentScrollOffset()); + EXPECT_EQ(last_page_scale_, + host_impl->active_tree()->current_page_scale_factor()); + + EndTest(); + break; + } + } + + void WillCommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { + LayerTreeImpl* sync_tree = host_impl->sync_tree(); + LayerImpl* outer_viewport_layer = sync_tree->OuterViewportScrollLayer(); + TransformNode* node = sync_tree->property_trees()->transform_tree.Node( + outer_viewport_layer->transform_tree_index()); + + switch (host_impl->sync_tree()->source_frame_number()) { + case 1: + case 2: + // Pushing page scale/scroll offset from the main thread should have + // resulted in a request to update draw properties. This is necessary + // to ensure that the draw properties are recomputed on the pending + // tree post-commit, since the property trees update on the main thread + // did not include the additionally reflected delta. + EXPECT_TRUE(host_impl->sync_tree()->needs_update_draw_properties()); + EXPECT_TRUE(node->needs_local_transform_update); + break; + } + } + + void BeginMainFrame(const BeginFrameArgs& args) override { + switch (layer_tree_host()->SourceFrameNumber()) { + case 1: + // Pretend that we could not apply the deltas this frame and send them + // back to the impl thread. + layer_tree()->outer_viewport_scroll_layer()->SetScrollOffset( + initial_offset_); + layer_tree()->SetPageScaleFactorAndLimits(initial_page_scale_, 0.f, + 1.f); + + SendReflectedMainFrameState(0); + break; + case 2: + // Pretend that the previous delta was handled and now reflect back the + // new delta. + layer_tree()->outer_viewport_scroll_layer()->SetScrollOffset( + gfx::ScrollOffsetWithDelta(initial_offset_, + outer_viewport_offset_deltas_[0])); + layer_tree()->SetPageScaleFactorAndLimits( + initial_page_scale_ * page_scale_update_, 0.f, 1.f); + + SendReflectedMainFrameState(1); + break; + case 3: + // Reflect all the deltas on the tree during the main frame itself. + gfx::ScrollOffset scroll_offset = + layer_tree()->outer_viewport_scroll_layer()->scroll_offset(); + layer_tree()->outer_viewport_scroll_layer()->SetScrollOffset( + gfx::ScrollOffsetWithDelta(scroll_offset, + outer_viewport_offset_deltas_[1])); + break; + } + } + + void DidScrollOuterViewport() { + Layer* outer_viewport_layer = layer_tree()->outer_viewport_scroll_layer(); + gfx::ScrollOffset expected_offset; + switch (layer_tree_host()->SourceFrameNumber()) { + case 0: + NOTREACHED(); + case 1: + expected_offset = gfx::ScrollOffsetWithDelta( + initial_offset_, outer_viewport_offset_deltas_[0]); + EXPECT_EQ(outer_viewport_layer->scroll_offset(), expected_offset); + break; + case 2: + // Since the first delta was reflected back and not applied on the main + // thread, the value here should only include the delta from the second + // update. + expected_offset = gfx::ScrollOffsetWithDelta( + initial_offset_, outer_viewport_offset_deltas_[1]); + EXPECT_EQ(outer_viewport_layer->scroll_offset(), expected_offset); + break; + default: + NOTREACHED(); + } + } + + void AfterTest() override {} + + private: + void SendReflectedMainFrameState(int delta_to_reflect) { + std::unique_ptr<ReflectedMainFrameState> reflected_main_frame_state = + base::MakeUnique<ReflectedMainFrameState>(); + + ReflectedMainFrameState::ScrollUpdate scroll_update; + scroll_update.layer_id = layer_tree()->outer_viewport_scroll_layer()->id(); + scroll_update.scroll_delta = + outer_viewport_offset_deltas_[delta_to_reflect]; + reflected_main_frame_state->scrolls.push_back(scroll_update); + + if (delta_to_reflect == 0) + reflected_main_frame_state->page_scale_delta = page_scale_update_; + + layer_tree_host_in_process()->SetReflectedMainFrameState( + std::move(reflected_main_frame_state)); + } + + // Accessed on the impl thread. + gfx::ScrollOffset last_active_offset_; + float last_page_scale_ = 0.f; + + const gfx::ScrollOffset initial_offset_ = gfx::ScrollOffset(2, 3); + const gfx::Vector2dF outer_viewport_offset_deltas_[2] = { + gfx::Vector2dF(10, 3), gfx::Vector2dF(5, 3)}; + + const float initial_page_scale_ = 0.5f; + const float page_scale_update_ = 0.2f; +}; + +// The reflected deltas are supported in threaded mode only. +MULTI_THREAD_TEST_F(LayerTreeHostScrollTestAppliesReflectedDeltas); + } // namespace } // namespace cc diff --git a/chromium/cc/trees/layer_tree_host_unittest_serialization.cc b/chromium/cc/trees/layer_tree_host_unittest_serialization.cc deleted file mode 100644 index 7cab9ba0ca4..00000000000 --- a/chromium/cc/trees/layer_tree_host_unittest_serialization.cc +++ /dev/null @@ -1,446 +0,0 @@ -// Copyright 2015 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. - -#include "cc/trees/layer_tree_host.h" - -#include <memory> - -#include "base/memory/ptr_util.h" -#include "cc/layers/empty_content_layer_client.h" -#include "cc/layers/heads_up_display_layer.h" -#include "cc/layers/layer.h" -#include "cc/proto/layer.pb.h" -#include "cc/proto/layer_tree_host.pb.h" -#include "cc/test/fake_image_serialization_processor.h" -#include "cc/test/fake_layer_tree_host.h" -#include "cc/test/fake_layer_tree_host_client.h" -#include "cc/test/fake_picture_layer.h" -#include "cc/test/fake_recording_source.h" -#include "cc/test/layer_tree_test.h" -#include "cc/test/skia_common.h" -#include "cc/test/test_task_graph_runner.h" -#include "cc/trees/layer_tree.h" -#include "cc/trees/layer_tree_host_common.h" -#include "cc/trees/layer_tree_settings.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "third_party/skia/include/core/SkColor.h" -#include "ui/gfx/geometry/point.h" -#include "ui/gfx/geometry/size.h" -#include "ui/gfx/geometry/vector2d_f.h" - -namespace cc { - -namespace { -std::unique_ptr<FakeRecordingSource> CreateRecordingSource( - const gfx::Rect& viewport) { - gfx::Rect layer_rect(viewport.right(), viewport.bottom()); - std::unique_ptr<FakeRecordingSource> recording_source = - FakeRecordingSource::CreateRecordingSource(viewport, layer_rect.size()); - return recording_source; -} - -scoped_refptr<FakePictureLayer> CreatePictureLayer() { - gfx::Rect recorded_viewport(0, 0, 256, 256); - - std::unique_ptr<FakeRecordingSource> recording_source = - CreateRecordingSource(recorded_viewport); - recording_source->SetDisplayListUsesCachedPicture(false); - - SkPaint simple_paint; - simple_paint.setColor(SkColorSetARGB(255, 12, 23, 34)); - recording_source->add_draw_rect_with_paint(gfx::Rect(0, 0, 256, 256), - simple_paint); - recording_source->SetGenerateDiscardableImagesMetadata(true); - recording_source->Rerecord(); - - ContentLayerClient* client = EmptyContentLayerClient::GetInstance(); - return FakePictureLayer::CreateWithRecordingSource( - client, std::move(recording_source)); -} -} // namespace - -class LayerTreeHostSerializationTest : public testing::Test { - public: - LayerTreeHostSerializationTest() - : image_serialization_processor_( - base::MakeUnique<FakeImageSerializationProcessor>()) {} - - protected: - void SetUp() override { - LayerTreeSettings settings; - layer_tree_host_src_ = FakeLayerTreeHost::Create( - &client_src_, &task_graph_runner_src_, settings, - CompositorMode::SINGLE_THREADED, image_serialization_processor_.get()); - layer_tree_host_dst_ = FakeLayerTreeHost::Create( - &client_dst_, &task_graph_runner_dst_, settings, - CompositorMode::SINGLE_THREADED, image_serialization_processor_.get()); - layer_tree_host_src_->InitializePictureCacheForTesting(); - layer_tree_host_dst_->InitializePictureCacheForTesting(); - } - - void TearDown() override { - // Need to reset |in_paint_layer_contents_| to tear down. - - layer_tree_host_src_->GetLayerTree()->in_paint_layer_contents_ = false; - layer_tree_host_dst_->GetLayerTree()->in_paint_layer_contents_ = false; - - // Need to reset LayerTreeHost pointers before tear down. - layer_tree_host_src_ = nullptr; - layer_tree_host_dst_ = nullptr; - } - - void VerifyHostHasAllExpectedLayersInTree(Layer* root_layer) { - LayerTreeHostCommon::CallFunctionForEveryLayer( - root_layer->GetLayerTree(), [root_layer](Layer* layer) { - DCHECK(layer->GetLayerTreeHostForTesting()); - EXPECT_EQ(layer, layer->GetLayerTree()->LayerById(layer->id())); - }); - } - - void VerifySerializationAndDeserialization() { - proto::LayerTreeHost proto; - LayerTree* layer_tree_src = layer_tree_host_src_->GetLayerTree(); - LayerTree* layer_tree_dst = layer_tree_host_dst_->GetLayerTree(); - - std::unordered_set<Layer*> layers_that_should_push_properties_src = - layer_tree_src->LayersThatShouldPushProperties(); - std::vector<std::unique_ptr<SwapPromise>> swap_promises; - layer_tree_host_src_->ToProtobufForCommit(&proto, &swap_promises); - layer_tree_host_dst_->FromProtobufForCommit(proto); - - EXPECT_EQ(layer_tree_src->needs_full_tree_sync_, - layer_tree_dst->needs_full_tree_sync_); - EXPECT_EQ(layer_tree_src->needs_meta_info_recomputation_, - layer_tree_dst->needs_meta_info_recomputation_); - EXPECT_EQ(layer_tree_host_src_->source_frame_number_, - layer_tree_host_dst_->source_frame_number_); - EXPECT_EQ(layer_tree_host_src_->root_layer()->id(), - layer_tree_host_dst_->root_layer()->id()); - EXPECT_EQ(layer_tree_host_dst_.get(), - layer_tree_dst->inputs_.root_layer->GetLayerTreeHostForTesting()); - EXPECT_EQ(layer_tree_src->inputs_.root_layer->double_sided(), - layer_tree_dst->inputs_.root_layer->double_sided()); - EXPECT_EQ(layer_tree_src->inputs_.device_viewport_size, - layer_tree_dst->inputs_.device_viewport_size); - EXPECT_EQ(layer_tree_src->inputs_.device_scale_factor, - layer_tree_dst->inputs_.device_scale_factor); - EXPECT_EQ(layer_tree_src->inputs_.painted_device_scale_factor, - layer_tree_dst->inputs_.painted_device_scale_factor); - EXPECT_EQ(layer_tree_src->inputs_.page_scale_factor, - layer_tree_dst->inputs_.page_scale_factor); - EXPECT_EQ(layer_tree_src->inputs_.min_page_scale_factor, - layer_tree_dst->inputs_.min_page_scale_factor); - EXPECT_EQ(layer_tree_src->inputs_.max_page_scale_factor, - layer_tree_dst->inputs_.max_page_scale_factor); - EXPECT_EQ(layer_tree_src->elastic_overscroll_, - layer_tree_dst->elastic_overscroll_); - EXPECT_EQ(layer_tree_host_src_->has_gpu_rasterization_trigger_, - layer_tree_host_dst_->has_gpu_rasterization_trigger_); - EXPECT_EQ(layer_tree_host_src_->content_is_suitable_for_gpu_rasterization_, - layer_tree_host_dst_->content_is_suitable_for_gpu_rasterization_); - EXPECT_EQ(layer_tree_src->inputs_.background_color, - layer_tree_dst->inputs_.background_color); - EXPECT_EQ(layer_tree_src->inputs_.has_transparent_background, - layer_tree_dst->inputs_.has_transparent_background); - EXPECT_EQ(layer_tree_src->in_paint_layer_contents(), - layer_tree_dst->in_paint_layer_contents()); - EXPECT_EQ(layer_tree_host_src_->id_, layer_tree_host_dst_->id_); - EXPECT_EQ(layer_tree_host_src_->next_commit_forces_redraw_, - layer_tree_host_dst_->next_commit_forces_redraw_); - for (auto* layer : layers_that_should_push_properties_src) { - EXPECT_TRUE(layer_tree_dst->LayerNeedsPushPropertiesForTesting( - layer_tree_dst->LayerById(layer->id()))); - } - - if (layer_tree_src->hud_layer_) { - EXPECT_EQ(layer_tree_src->hud_layer_->id(), - layer_tree_dst->hud_layer_->id()); - // The HUD layer member is a HeadsUpDisplayLayer instead of Layer, so - // inspect the proto to see if it contains the the right layer type. - bool found_hud_layer_type = false; - for (int i = 0; i < proto.layer_tree().root_layer().children_size(); - ++i) { - if (proto.layer_tree().root_layer().children(i).id() == - layer_tree_src->hud_layer_->id()) { - EXPECT_EQ(proto::LayerNode::HEADS_UP_DISPLAY_LAYER, - proto.layer_tree().root_layer().children(i).type()); - found_hud_layer_type = true; - break; - } - } - EXPECT_TRUE(found_hud_layer_type); - } else { - EXPECT_FALSE(layer_tree_dst->hud_layer_); - } - if (layer_tree_src->overscroll_elasticity_layer()) { - EXPECT_EQ(layer_tree_src->overscroll_elasticity_layer()->id(), - layer_tree_dst->overscroll_elasticity_layer()->id()); - } else { - EXPECT_FALSE(layer_tree_dst->overscroll_elasticity_layer()); - } - if (layer_tree_src->page_scale_layer()) { - EXPECT_EQ(layer_tree_src->page_scale_layer()->id(), - layer_tree_dst->page_scale_layer()->id()); - } else { - EXPECT_FALSE(layer_tree_dst->page_scale_layer()); - } - if (layer_tree_src->inner_viewport_scroll_layer()) { - EXPECT_EQ(layer_tree_src->inner_viewport_scroll_layer()->id(), - layer_tree_dst->inner_viewport_scroll_layer()->id()); - } else { - EXPECT_FALSE(layer_tree_dst->inner_viewport_scroll_layer()); - } - if (layer_tree_src->outer_viewport_scroll_layer()) { - EXPECT_EQ(layer_tree_src->outer_viewport_scroll_layer()->id(), - layer_tree_dst->outer_viewport_scroll_layer()->id()); - } else { - EXPECT_FALSE(layer_tree_dst->outer_viewport_scroll_layer()); - } - EXPECT_EQ(layer_tree_src->inputs_.selection, - layer_tree_dst->inputs_.selection); - EXPECT_EQ(layer_tree_src->property_trees_, layer_tree_dst->property_trees_); - - // All layers must have a property tree index that matches PropertyTrees. - if (layer_tree_dst->property_trees_.sequence_number) { - int seq_num = layer_tree_dst->property_trees_.sequence_number; - LayerTreeHostCommon::CallFunctionForEveryLayer( - layer_tree_host_dst_->GetLayerTree(), [seq_num](Layer* layer) { - EXPECT_EQ(seq_num, layer->property_tree_sequence_number()); - }); - } - } - - void RunAllMembersChangedTest() { - LayerTree* layer_tree_src = layer_tree_host_src_->GetLayerTree(); - - layer_tree_src->needs_full_tree_sync_ = - !layer_tree_src->needs_full_tree_sync_; - layer_tree_src->needs_meta_info_recomputation_ = - !layer_tree_src->needs_meta_info_recomputation_; - layer_tree_host_src_->source_frame_number_ *= 3; - - // Just fake setup a layer for both source and dest. - scoped_refptr<Layer> root_layer_src = Layer::Create(); - layer_tree_host_src_->SetRootLayer(root_layer_src); - layer_tree_host_dst_->SetRootLayer(Layer::Create()); - root_layer_src->SetDoubleSided(!root_layer_src->double_sided()); - - layer_tree_src->inputs_.device_viewport_size = gfx::Size(3, 14); - layer_tree_src->inputs_.device_scale_factor = - layer_tree_src->inputs_.device_scale_factor * 3 + 1; - layer_tree_src->inputs_.painted_device_scale_factor = - layer_tree_src->inputs_.painted_device_scale_factor * 3 + 1; - layer_tree_src->inputs_.page_scale_factor = - layer_tree_src->inputs_.page_scale_factor * 3 + 1; - layer_tree_src->inputs_.min_page_scale_factor = - layer_tree_src->inputs_.min_page_scale_factor * 3 + 1; - layer_tree_src->inputs_.max_page_scale_factor = - layer_tree_src->inputs_.max_page_scale_factor * 3 + 1; - layer_tree_src->elastic_overscroll_ = gfx::Vector2dF(3, 14); - layer_tree_host_src_->has_gpu_rasterization_trigger_ = - !layer_tree_host_src_->has_gpu_rasterization_trigger_; - layer_tree_host_src_->content_is_suitable_for_gpu_rasterization_ = - !layer_tree_host_src_->content_is_suitable_for_gpu_rasterization_; - layer_tree_src->inputs_.background_color = SK_ColorMAGENTA; - layer_tree_src->inputs_.has_transparent_background = - !layer_tree_src->inputs_.has_transparent_background; - layer_tree_host_src_->id_ = layer_tree_host_src_->id_ * 3 + 1; - layer_tree_host_src_->next_commit_forces_redraw_ = - !layer_tree_host_src_->next_commit_forces_redraw_; - - layer_tree_src->hud_layer_ = HeadsUpDisplayLayer::Create(); - root_layer_src->AddChild(layer_tree_src->hud_layer_); - - scoped_refptr<Layer> overscroll_elasticity_layer = Layer::Create(); - scoped_refptr<Layer> page_scale_layer = Layer::Create(); - scoped_refptr<Layer> inner_viewport_scroll_layer = Layer::Create(); - scoped_refptr<Layer> outer_viewport_scroll_layer = Layer::Create(); - - root_layer_src->AddChild(overscroll_elasticity_layer); - root_layer_src->AddChild(page_scale_layer); - root_layer_src->AddChild(inner_viewport_scroll_layer); - root_layer_src->AddChild(outer_viewport_scroll_layer); - - layer_tree_src->RegisterViewportLayers( - overscroll_elasticity_layer, page_scale_layer, - inner_viewport_scroll_layer, outer_viewport_scroll_layer); - - // Set in_paint_layer_contents_ only after all calls to AddChild() have - // finished to ensure it's allowed to do so at that time. - layer_tree_src->in_paint_layer_contents_ = - !layer_tree_src->in_paint_layer_contents(); - - LayerSelectionBound sel_bound; - sel_bound.edge_top = gfx::Point(14, 3); - LayerSelection selection; - selection.start = sel_bound; - layer_tree_src->inputs_.selection = selection; - - layer_tree_src->property_trees_.sequence_number = - layer_tree_src->property_trees_.sequence_number * 3 + 1; - - VerifySerializationAndDeserialization(); - } - - void RunLayersChangedTest() { - // Just fake setup a layer for both source and dest. - scoped_refptr<Layer> root_layer_src = Layer::Create(); - layer_tree_host_src_->SetRootLayer(root_layer_src); - layer_tree_host_dst_->SetRootLayer(Layer::Create()); - root_layer_src->SetDoubleSided(!root_layer_src->double_sided()); - - // No HUD layer or |overscroll_elasticity_layer_|, or the inner/outer - // viewport scroll layers. - scoped_refptr<Layer> overscroll_elasticity_layer = Layer::Create(); - layer_tree_host_src_->GetLayerTree()->inputs_.overscroll_elasticity_layer = - overscroll_elasticity_layer; - root_layer_src->AddChild(overscroll_elasticity_layer); - - VerifySerializationAndDeserialization(); - } - - void RunLayersChangedMultipleSerializations() { - // Just fake setup a layer for both source and dest. - scoped_refptr<Layer> root_layer_src = Layer::Create(); - layer_tree_host_src_->SetRootLayer(root_layer_src); - layer_tree_host_dst_->SetRootLayer(Layer::Create()); - root_layer_src->SetDoubleSided(!root_layer_src->double_sided()); - - LayerTree* layer_tree_src = layer_tree_host_src_->GetLayerTree(); - - // Ensure that all the layers work correctly for multiple rounds of - // serialization and deserialization. - layer_tree_src->hud_layer_ = HeadsUpDisplayLayer::Create(); - root_layer_src->AddChild(layer_tree_src->hud_layer_); - - scoped_refptr<Layer> overscroll_elasticity_layer = Layer::Create(); - scoped_refptr<Layer> page_scale_layer = Layer::Create(); - scoped_refptr<Layer> inner_viewport_scroll_layer = Layer::Create(); - scoped_refptr<Layer> outer_viewport_scroll_layer = Layer::Create(); - - root_layer_src->AddChild(overscroll_elasticity_layer); - root_layer_src->AddChild(page_scale_layer); - root_layer_src->AddChild(inner_viewport_scroll_layer); - root_layer_src->AddChild(outer_viewport_scroll_layer); - layer_tree_host_src_->GetLayerTree()->RegisterViewportLayers( - overscroll_elasticity_layer, page_scale_layer, - inner_viewport_scroll_layer, outer_viewport_scroll_layer); - - VerifySerializationAndDeserialization(); - VerifySerializationAndDeserialization(); - - layer_tree_src->hud_layer_ = nullptr; - VerifySerializationAndDeserialization(); - layer_tree_host_src_->GetLayerTree()->inputs_.overscroll_elasticity_layer = - nullptr; - VerifySerializationAndDeserialization(); - layer_tree_host_src_->GetLayerTree()->inputs_.page_scale_layer = nullptr; - VerifySerializationAndDeserialization(); - layer_tree_host_src_->GetLayerTree()->inputs_.inner_viewport_scroll_layer = - nullptr; - VerifySerializationAndDeserialization(); - layer_tree_host_src_->GetLayerTree()->inputs_.outer_viewport_scroll_layer = - nullptr; - VerifySerializationAndDeserialization(); - } - - void RunPictureLayerMultipleSerializationsTest() { - // Just fake setup a layer for both source and dest. - scoped_refptr<Layer> root_layer_src = Layer::Create(); - layer_tree_host_src_->SetRootLayer(root_layer_src); - layer_tree_host_dst_->SetRootLayer(Layer::Create()); - - // Ensure that a PictureLayer work correctly for multiple rounds of - // serialization and deserialization. - scoped_refptr<FakePictureLayer> picture_layer_src = CreatePictureLayer(); - root_layer_src->AddChild(picture_layer_src); - picture_layer_src->SetBounds(gfx::Size(10, 10)); - picture_layer_src->SetIsDrawable(true); - picture_layer_src->SavePaintProperties(); - picture_layer_src->Update(); - picture_layer_src->SavePaintProperties(); - VerifySerializationAndDeserialization(); - ASSERT_EQ(1U, layer_tree_host_dst_->root_layer()->children().size()); - PictureLayer* picture_layer_dst = reinterpret_cast<PictureLayer*>( - layer_tree_host_dst_->root_layer()->child_at(0)); - - RecordingSource* recording_source_src = - picture_layer_src->GetRecordingSourceForTesting(); - RecordingSource* recording_source_dst = - picture_layer_dst->GetRecordingSourceForTesting(); - EXPECT_EQ(recording_source_src->GetSize(), recording_source_dst->GetSize()); - EXPECT_TRUE(AreDisplayListDrawingResultsSame( - gfx::Rect(recording_source_src->GetSize()), - picture_layer_src->GetDisplayItemList(), - picture_layer_dst->GetDisplayItemList())); - - VerifySerializationAndDeserialization(); - } - - void RunAddAndRemoveNodeFromLayerTree() { - /* Testing serialization when the tree hierarchy changes like this: - root root - / \ / \ - a b => a c - \ \ - c d - */ - scoped_refptr<Layer> layer_src_root = Layer::Create(); - layer_tree_host_src_->SetRootLayer(layer_src_root); - - scoped_refptr<Layer> layer_src_a = Layer::Create(); - scoped_refptr<Layer> layer_src_b = Layer::Create(); - scoped_refptr<Layer> layer_src_c = Layer::Create(); - scoped_refptr<Layer> layer_src_d = Layer::Create(); - - layer_src_root->AddChild(layer_src_a); - layer_src_root->AddChild(layer_src_b); - layer_src_b->AddChild(layer_src_c); - - VerifySerializationAndDeserialization(); - VerifyHostHasAllExpectedLayersInTree(layer_tree_host_dst_->root_layer()); - - // Now change the Layer Hierarchy - layer_src_c->RemoveFromParent(); - layer_src_b->RemoveFromParent(); - layer_src_root->AddChild(layer_src_c); - layer_src_c->AddChild(layer_src_d); - - VerifySerializationAndDeserialization(); - VerifyHostHasAllExpectedLayersInTree(layer_tree_host_dst_->root_layer()); - } - - private: - std::unique_ptr<ImageSerializationProcessor> image_serialization_processor_; - - TestTaskGraphRunner task_graph_runner_src_; - FakeLayerTreeHostClient client_src_; - std::unique_ptr<FakeLayerTreeHost> layer_tree_host_src_; - - TestTaskGraphRunner task_graph_runner_dst_; - FakeLayerTreeHostClient client_dst_; - std::unique_ptr<FakeLayerTreeHost> layer_tree_host_dst_; -}; - -TEST_F(LayerTreeHostSerializationTest, AllMembersChanged) { - RunAllMembersChangedTest(); -} - -TEST_F(LayerTreeHostSerializationTest, LayersChanged) { - RunLayersChangedTest(); -} - -TEST_F(LayerTreeHostSerializationTest, LayersChangedMultipleSerializations) { - RunLayersChangedMultipleSerializations(); -} - -TEST_F(LayerTreeHostSerializationTest, AddAndRemoveNodeFromLayerTree) { - RunAddAndRemoveNodeFromLayerTree(); -} - -TEST_F(LayerTreeHostSerializationTest, PictureLayerMultipleSerializations) { - RunPictureLayerMultipleSerializationsTest(); -} - -} // namespace cc diff --git a/chromium/cc/trees/layer_tree_impl.cc b/chromium/cc/trees/layer_tree_impl.cc index 2909ece1ab0..edfd5b0aeee 100644 --- a/chromium/cc/trees/layer_tree_impl.cc +++ b/chromium/cc/trees/layer_tree_impl.cc @@ -17,7 +17,6 @@ #include "base/timer/elapsed_timer.h" #include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event_argument.h" -#include "cc/animation/animation_host.h" #include "cc/base/histograms.h" #include "cc/base/math_util.h" #include "cc/base/synced_property.h" @@ -40,6 +39,7 @@ #include "cc/trees/effect_node.h" #include "cc/trees/layer_tree_host_common.h" #include "cc/trees/layer_tree_host_impl.h" +#include "cc/trees/mutator_host.h" #include "cc/trees/occlusion_tracker.h" #include "cc/trees/property_tree.h" #include "cc/trees/property_tree_builder.h" @@ -56,7 +56,7 @@ namespace cc { LayerTreeImpl::LayerTreeImpl( LayerTreeHostImpl* layer_tree_host_impl, scoped_refptr<SyncedProperty<ScaleGroup>> page_scale_factor, - scoped_refptr<SyncedTopControls> top_controls_shown_ratio, + scoped_refptr<SyncedBrowserControls> top_controls_shown_ratio, scoped_refptr<SyncedElasticOverscroll> elastic_overscroll) : layer_tree_host_impl_(layer_tree_host_impl), source_frame_number_(-1), @@ -84,7 +84,7 @@ LayerTreeImpl::LayerTreeImpl( has_ever_been_drawn_(false), have_scroll_event_handlers_(false), event_listener_properties_(), - top_controls_shrink_blink_size_(false), + browser_controls_shrink_blink_size_(false), top_controls_height_(0), bottom_controls_height_(0), top_controls_shown_ratio_(top_controls_shown_ratio) { @@ -426,7 +426,7 @@ void LayerTreeImpl::PushPropertiesTo(LayerTreeImpl* target_tree) { // This needs to be called early so that we don't clamp with incorrect max // offsets when UpdateViewportContainerSizes is called from e.g. - // PushTopControls + // PushBrowserControls target_tree->UpdatePropertyTreesForBoundsDelta(); if (next_activation_forces_redraw_) { @@ -437,11 +437,11 @@ void LayerTreeImpl::PushPropertiesTo(LayerTreeImpl* target_tree) { target_tree->PassSwapPromises(std::move(swap_promise_list_)); swap_promise_list_.clear(); - target_tree->set_top_controls_shrink_blink_size( - top_controls_shrink_blink_size_); + target_tree->set_browser_controls_shrink_blink_size( + browser_controls_shrink_blink_size_); target_tree->set_top_controls_height(top_controls_height_); target_tree->set_bottom_controls_height(bottom_controls_height_); - target_tree->PushTopControls(nullptr); + target_tree->PushBrowserControls(nullptr); // Active tree already shares the page_scale_factor object with pending // tree so only the limits need to be provided. @@ -548,7 +548,7 @@ void LayerTreeImpl::AddToElementMap(LayerImpl* layer) { element_layers_map_[layer->element_id()] = layer->id(); - layer_tree_host_impl_->animation_host()->RegisterElement( + layer_tree_host_impl_->mutator_host()->RegisterElement( layer->element_id(), IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING); } @@ -562,7 +562,7 @@ void LayerTreeImpl::RemoveFromElementMap(LayerImpl* layer) { layer->element_id().AsValue().release(), "layer_id", layer->id()); - layer_tree_host_impl_->animation_host()->UnregisterElement( + layer_tree_host_impl_->mutator_host()->UnregisterElement( layer->element_id(), IsActiveTree() ? ElementListType::ACTIVE : ElementListType::PENDING); @@ -776,11 +776,11 @@ void LayerTreeImpl::PushPageScaleFactorAndLimits(const float* page_scale_factor, } } -void LayerTreeImpl::set_top_controls_shrink_blink_size(bool shrink) { - if (top_controls_shrink_blink_size_ == shrink) +void LayerTreeImpl::set_browser_controls_shrink_blink_size(bool shrink) { + if (browser_controls_shrink_blink_size_ == shrink) return; - top_controls_shrink_blink_size_ = shrink; + browser_controls_shrink_blink_size_ = shrink; if (IsActiveTree()) layer_tree_host_impl_->UpdateViewportContainerSizes(); } @@ -803,25 +803,25 @@ void LayerTreeImpl::set_bottom_controls_height(float bottom_controls_height) { layer_tree_host_impl_->UpdateViewportContainerSizes(); } -bool LayerTreeImpl::ClampTopControlsShownRatio() { +bool LayerTreeImpl::ClampBrowserControlsShownRatio() { float ratio = top_controls_shown_ratio_->Current(true); ratio = std::max(ratio, 0.f); ratio = std::min(ratio, 1.f); return top_controls_shown_ratio_->SetCurrent(ratio); } -bool LayerTreeImpl::SetCurrentTopControlsShownRatio(float ratio) { +bool LayerTreeImpl::SetCurrentBrowserControlsShownRatio(float ratio) { bool changed = top_controls_shown_ratio_->SetCurrent(ratio); - changed |= ClampTopControlsShownRatio(); + changed |= ClampBrowserControlsShownRatio(); return changed; } -void LayerTreeImpl::PushTopControlsFromMainThread( +void LayerTreeImpl::PushBrowserControlsFromMainThread( float top_controls_shown_ratio) { - PushTopControls(&top_controls_shown_ratio); + PushBrowserControls(&top_controls_shown_ratio); } -void LayerTreeImpl::PushTopControls(const float* top_controls_shown_ratio) { +void LayerTreeImpl::PushBrowserControls(const float* top_controls_shown_ratio) { DCHECK(top_controls_shown_ratio || IsActiveTree()); if (top_controls_shown_ratio) { @@ -830,9 +830,9 @@ void LayerTreeImpl::PushTopControls(const float* top_controls_shown_ratio) { } if (IsActiveTree()) { bool changed_active = top_controls_shown_ratio_->PushPendingToActive(); - changed_active |= ClampTopControlsShownRatio(); + changed_active |= ClampBrowserControlsShownRatio(); if (changed_active) - layer_tree_host_impl_->DidChangeTopControlsPosition(); + layer_tree_host_impl_->DidChangeBrowserControlsPosition(); } } @@ -865,6 +865,7 @@ void LayerTreeImpl::SetDeviceScaleFactor(float device_scale_factor) { set_needs_update_draw_properties(); if (IsActiveTree()) layer_tree_host_impl_->SetFullViewportDamage(); + layer_tree_host_impl_->SetNeedUpdateGpuRasterizationStatus(); } void LayerTreeImpl::SetDeviceColorSpace( @@ -992,7 +993,6 @@ bool LayerTreeImpl::UpdateDrawProperties( settings().layer_transforms_should_scale_layer_contents, settings().verify_clip_tree_calculations, verify_visible_rect_calculations, - settings().verify_transform_tree_calculations, &render_surface_layer_list_, &property_trees_); LayerTreeHostCommon::CalculateDrawProperties(&inputs); if (const char* client_name = GetClientNameForMetrics()) { @@ -1037,14 +1037,9 @@ bool LayerTreeImpl::UpdateDrawProperties( // We are calculating transform between two render surfaces. So, we // need to apply the surface contents scale at target and remove the // surface contents scale at source. - property_trees()->ComputeTransformToTarget( + property_trees()->GetToTarget( it->render_surface()->TransformTreeIndex(), occlusion_surface->EffectTreeIndex(), &draw_transform); - const EffectNode* occlusion_effect_node = - property_trees()->effect_tree.Node( - occlusion_surface->EffectTreeIndex()); - draw_property_utils::PostConcatSurfaceContentsScale( - occlusion_effect_node, &draw_transform); const EffectNode* effect_node = property_trees()->effect_tree.Node( it->render_surface()->EffectTreeIndex()); draw_property_utils::ConcatInverseSurfaceContentsScale( @@ -1362,24 +1357,23 @@ const gfx::Rect LayerTreeImpl::ViewportRectForTilePriority() const { std::unique_ptr<ScrollbarAnimationController> LayerTreeImpl::CreateScrollbarAnimationController(int scroll_layer_id) { - DCHECK(settings().scrollbar_fade_delay_ms); - DCHECK(settings().scrollbar_fade_duration_ms); - base::TimeDelta delay = - base::TimeDelta::FromMilliseconds(settings().scrollbar_fade_delay_ms); - base::TimeDelta resize_delay = base::TimeDelta::FromMilliseconds( - settings().scrollbar_fade_resize_delay_ms); - base::TimeDelta duration = - base::TimeDelta::FromMilliseconds(settings().scrollbar_fade_duration_ms); + DCHECK(!settings().scrollbar_fade_delay.is_zero()); + DCHECK(!settings().scrollbar_fade_duration.is_zero()); + base::TimeDelta delay = settings().scrollbar_fade_delay; + base::TimeDelta resize_delay = settings().scrollbar_fade_resize_delay; + base::TimeDelta fade_duration = settings().scrollbar_fade_duration; switch (settings().scrollbar_animator) { case LayerTreeSettings::LINEAR_FADE: { return ScrollbarAnimationControllerLinearFade::Create( scroll_layer_id, layer_tree_host_impl_, delay, resize_delay, - duration); + fade_duration); } case LayerTreeSettings::THINNING: { + base::TimeDelta thinning_duration = + settings().scrollbar_thinning_duration; return ScrollbarAnimationControllerThinning::Create( scroll_layer_id, layer_tree_host_impl_, delay, resize_delay, - duration); + fade_duration, thinning_duration); } case LayerTreeSettings::NO_ANIMATOR: NOTREACHED(); @@ -1785,7 +1779,7 @@ static bool PointIsClippedByAncestorClipNode( for (const ClipNode* clip_node = clip_tree.Node(layer->clip_tree_index()); clip_node->id > 1; clip_node = clip_tree.parent(clip_node)) { - if (clip_node->applies_local_clip) { + if (clip_node->clip_type == ClipNode::ClipType::APPLIES_LOCAL_CLIP) { const TransformNode* transform_node = transform_tree.Node(clip_node->target_transform_id); gfx::Rect combined_clip_in_target_space = @@ -1893,16 +1887,15 @@ static void FindClosestMatchingLayer(const gfx::PointF& screen_space_point, } } -static bool ScrollsOrScrollbarAnyDrawnRenderSurfaceLayerListMember( - LayerImpl* layer) { - return layer->scrolls_drawn_descendant() || +static bool IsScrollableOrDrawnScrollbarLayer(LayerImpl* layer) { + return layer->scrollable() || (layer->ToScrollbarLayer() && layer->is_drawn_render_surface_layer_list_member()); } struct FindScrollingLayerOrScrollbarLayerFunctor { bool operator()(LayerImpl* layer) const { - return ScrollsOrScrollbarAnyDrawnRenderSurfaceLayerListMember(layer); + return IsScrollableOrDrawnScrollbarLayer(layer); } }; @@ -1919,7 +1912,7 @@ LayerTreeImpl::FindFirstScrollingLayerOrScrollbarLayerThatIsHitByPoint( struct HitTestVisibleScrollableOrTouchableFunctor { bool operator()(LayerImpl* layer) const { return layer->is_drawn_render_surface_layer_list_member() || - ScrollsOrScrollbarAnyDrawnRenderSurfaceLayerListMember(layer) || + IsScrollableOrDrawnScrollbarLayer(layer) || !layer->touch_event_handler_region().IsEmpty(); } }; @@ -2074,8 +2067,7 @@ LayerTreeImpl::TakePendingPageScaleAnimation() { } void LayerTreeImpl::ScrollAnimationAbort(bool needs_completion) { - layer_tree_host_impl_->animation_host()->ScrollAnimationAbort( - needs_completion); + layer_tree_host_impl_->mutator_host()->ScrollAnimationAbort(needs_completion); } void LayerTreeImpl::ResetAllChangeTracking() { diff --git a/chromium/cc/trees/layer_tree_impl.h b/chromium/cc/trees/layer_tree_impl.h index 85473a43251..ad4edc336f2 100644 --- a/chromium/cc/trees/layer_tree_impl.h +++ b/chromium/cc/trees/layer_tree_impl.h @@ -38,12 +38,10 @@ class DebugRectHistory; class FrameRateCounter; class HeadsUpDisplayLayerImpl; class ImageDecodeController; -class LayerExternalScrollOffsetListener; class LayerTreeDebugState; class LayerTreeImpl; class LayerTreeSettings; class MemoryHistory; -class PageScaleAnimation; class PictureLayerImpl; class TaskRunnerProvider; class ResourceProvider; @@ -53,7 +51,7 @@ class VideoFrameControllerClient; struct PendingPageScaleAnimation; typedef std::vector<UIResourceRequest> UIResourceRequestQueue; -typedef SyncedProperty<AdditionGroup<float>> SyncedTopControls; +typedef SyncedProperty<AdditionGroup<float>> SyncedBrowserControls; typedef SyncedProperty<AdditionGroup<gfx::Vector2dF>> SyncedElasticOverscroll; class CC_EXPORT LayerTreeImpl { @@ -63,7 +61,7 @@ class CC_EXPORT LayerTreeImpl { enum : int { kFixedPointHitsThreshold = 3 }; LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl, scoped_refptr<SyncedProperty<ScaleGroup>> page_scale_factor, - scoped_refptr<SyncedTopControls> top_controls_shown_ratio, + scoped_refptr<SyncedBrowserControls> top_controls_shown_ratio, scoped_refptr<SyncedElasticOverscroll> elastic_overscroll); virtual ~LayerTreeImpl(); @@ -105,8 +103,8 @@ class CC_EXPORT LayerTreeImpl { bool RequiresHighResToDraw() const; bool SmoothnessTakesPriority() const; VideoFrameControllerClient* GetVideoFrameControllerClient() const; - AnimationHost* animation_host() const { - return layer_tree_host_impl_->animation_host(); + MutatorHost* mutator_host() const { + return layer_tree_host_impl_->mutator_host(); } // Tree specific methods exposed to layer-impl tree. @@ -246,10 +244,10 @@ class CC_EXPORT LayerTreeImpl { return elastic_overscroll_.get(); } - SyncedTopControls* top_controls_shown_ratio() { + SyncedBrowserControls* top_controls_shown_ratio() { return top_controls_shown_ratio_.get(); } - const SyncedTopControls* top_controls_shown_ratio() const { + const SyncedBrowserControls* top_controls_shown_ratio() const { return top_controls_shown_ratio_.get(); } @@ -411,17 +409,17 @@ class CC_EXPORT LayerTreeImpl { // the viewport. void GetViewportSelection(Selection<gfx::SelectionBound>* selection); - void set_top_controls_shrink_blink_size(bool shrink); - bool top_controls_shrink_blink_size() const { - return top_controls_shrink_blink_size_; + void set_browser_controls_shrink_blink_size(bool shrink); + bool browser_controls_shrink_blink_size() const { + return browser_controls_shrink_blink_size_; } - bool SetCurrentTopControlsShownRatio(float ratio); - float CurrentTopControlsShownRatio() const { + bool SetCurrentBrowserControlsShownRatio(float ratio); + float CurrentBrowserControlsShownRatio() const { return top_controls_shown_ratio_->Current(IsActiveTree()); } void set_top_controls_height(float top_controls_height); float top_controls_height() const { return top_controls_height_; } - void PushTopControlsFromMainThread(float top_controls_shown_ratio); + void PushBrowserControlsFromMainThread(float top_controls_shown_ratio); void set_bottom_controls_height(float bottom_controls_height); float bottom_controls_height() const { return bottom_controls_height_; } @@ -469,8 +467,8 @@ class CC_EXPORT LayerTreeImpl { bool IsViewportLayerId(int id) const; void UpdateScrollbars(int scroll_layer_id, int clip_layer_id); void DidUpdatePageScale(); - void PushTopControls(const float* top_controls_shown_ratio); - bool ClampTopControlsShownRatio(); + void PushBrowserControls(const float* top_controls_shown_ratio); + bool ClampBrowserControlsShownRatio(); LayerTreeHostImpl* layer_tree_host_impl_; int source_frame_number_; @@ -553,13 +551,13 @@ class CC_EXPORT LayerTreeImpl { // Whether or not Blink's viewport size was shrunk by the height of the top // controls at the time of the last layout. - bool top_controls_shrink_blink_size_; + bool browser_controls_shrink_blink_size_; float top_controls_height_; float bottom_controls_height_; - // The amount that the top controls are shown from 0 (hidden) to 1 (fully + // The amount that the browser controls are shown from 0 (hidden) to 1 (fully // shown). - scoped_refptr<SyncedTopControls> top_controls_shown_ratio_; + scoped_refptr<SyncedBrowserControls> top_controls_shown_ratio_; std::unique_ptr<PendingPageScaleAnimation> pending_page_scale_animation_; diff --git a/chromium/cc/trees/layer_tree_impl_unittest.cc b/chromium/cc/trees/layer_tree_impl_unittest.cc index 47d4435117e..213d9d2106f 100644 --- a/chromium/cc/trees/layer_tree_impl_unittest.cc +++ b/chromium/cc/trees/layer_tree_impl_unittest.cc @@ -5,7 +5,6 @@ #include "cc/trees/layer_tree_impl.h" #include "base/macros.h" -#include "cc/animation/mutable_properties.h" #include "cc/layers/heads_up_display_layer_impl.h" #include "cc/test/fake_layer_tree_host_impl.h" #include "cc/test/geometry_test_utils.h" @@ -15,6 +14,7 @@ #include "cc/trees/draw_property_utils.h" #include "cc/trees/layer_tree_host_common.h" #include "cc/trees/layer_tree_host_impl.h" +#include "cc/trees/mutable_properties.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/chromium/cc/trees/layer_tree_mutator.h b/chromium/cc/trees/layer_tree_mutator.h new file mode 100644 index 00000000000..9233ca2eec9 --- /dev/null +++ b/chromium/cc/trees/layer_tree_mutator.h @@ -0,0 +1,40 @@ +// Copyright 2016 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. + +#ifndef CC_TREES_LAYER_TREE_MUTATOR_H_ +#define CC_TREES_LAYER_TREE_MUTATOR_H_ + +#include "base/callback_forward.h" +#include "base/time/time.h" +#include "cc/base/cc_export.h" + +namespace cc { + +class LayerTreeImpl; + +class LayerTreeMutatorClient { + public: + // This is necessary because it forces an impl frame. We couldn't, for + // example, just assume that we will "always mutate" and early-out in the + // mutator if there was nothing to do because we won't always be producing + // impl frames. + virtual void SetNeedsMutate() = 0; +}; + +class CC_EXPORT LayerTreeMutator { + public: + virtual ~LayerTreeMutator() {} + + // Returns true if the mutator should be rescheduled. + virtual bool Mutate(base::TimeTicks now, LayerTreeImpl* tree_impl) = 0; + virtual void SetClient(LayerTreeMutatorClient* client) = 0; + + // Returns a callback which is responsible for applying layer tree mutations + // to DOM elements. + virtual base::Closure TakeMutations() = 0; +}; + +} // namespace cc + +#endif // CC_TREES_LAYER_TREE_MUTATOR_H_ diff --git a/chromium/cc/trees/layer_tree_settings.cc b/chromium/cc/trees/layer_tree_settings.cc index 7a2d0a93f38..faebb4209da 100644 --- a/chromium/cc/trees/layer_tree_settings.cc +++ b/chromium/cc/trees/layer_tree_settings.cc @@ -40,10 +40,9 @@ bool LayerTreeSettings::operator==(const LayerTreeSettings& other) const { other.gpu_rasterization_msaa_sample_count && create_low_res_tiling == other.create_low_res_tiling && scrollbar_animator == other.scrollbar_animator && - scrollbar_fade_delay_ms == other.scrollbar_fade_delay_ms && - scrollbar_fade_resize_delay_ms == - other.scrollbar_fade_resize_delay_ms && - scrollbar_fade_duration_ms == other.scrollbar_fade_duration_ms && + scrollbar_fade_delay == other.scrollbar_fade_delay && + scrollbar_fade_resize_delay == other.scrollbar_fade_resize_delay && + scrollbar_fade_duration == other.scrollbar_fade_duration && solid_color_scrollbar_color == other.solid_color_scrollbar_color && timeout_and_draw_when_animation_checkerboards == other.timeout_and_draw_when_animation_checkerboards && @@ -75,8 +74,6 @@ bool LayerTreeSettings::operator==(const LayerTreeSettings& other) const { use_occlusion_for_tile_prioritization == other.use_occlusion_for_tile_prioritization && verify_clip_tree_calculations == other.verify_clip_tree_calculations && - verify_transform_tree_calculations == - other.verify_transform_tree_calculations && image_decode_tasks_enabled == other.image_decode_tasks_enabled && max_staging_buffer_usage_in_bytes == other.max_staging_buffer_usage_in_bytes && diff --git a/chromium/cc/trees/layer_tree_settings.h b/chromium/cc/trees/layer_tree_settings.h index 22275d88e4e..28f129a01ae 100644 --- a/chromium/cc/trees/layer_tree_settings.h +++ b/chromium/cc/trees/layer_tree_settings.h @@ -9,6 +9,7 @@ #include <vector> +#include "base/time/time.h" #include "cc/base/cc_export.h" #include "cc/debug/layer_tree_debug_state.h" #include "cc/output/managed_memory_policy.h" @@ -56,9 +57,10 @@ class CC_EXPORT LayerTreeSettings { THINNING, }; ScrollbarAnimator scrollbar_animator = NO_ANIMATOR; - int scrollbar_fade_delay_ms = 0; - int scrollbar_fade_resize_delay_ms = 0; - int scrollbar_fade_duration_ms = 0; + base::TimeDelta scrollbar_fade_delay; + base::TimeDelta scrollbar_fade_resize_delay; + base::TimeDelta scrollbar_fade_duration; + base::TimeDelta scrollbar_thinning_duration; SkColor solid_color_scrollbar_color = SK_ColorWHITE; bool timeout_and_draw_when_animation_checkerboards = true; bool layer_transforms_should_scale_layer_contents = false; @@ -86,7 +88,6 @@ class CC_EXPORT LayerTreeSettings { size_t scheduled_raster_task_limit = 32; bool use_occlusion_for_tile_prioritization = false; bool verify_clip_tree_calculations = false; - bool verify_transform_tree_calculations = false; bool image_decode_tasks_enabled = false; bool abort_commit_before_compositor_frame_sink_creation = true; bool use_layer_lists = false; diff --git a/chromium/cc/trees/mutable_properties.h b/chromium/cc/trees/mutable_properties.h new file mode 100644 index 00000000000..ef68c5ad274 --- /dev/null +++ b/chromium/cc/trees/mutable_properties.h @@ -0,0 +1,25 @@ +// Copyright 2015 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. + +#ifndef CC_TREES_MUTABLE_PROPERTIES_H_ +#define CC_TREES_MUTABLE_PROPERTIES_H_ + +#include <stdint.h> + +namespace cc { + +struct MutableProperty { + enum : uint32_t { kNone = 0 }; + enum : uint32_t { kOpacity = 1 << 0 }; + enum : uint32_t { kScrollLeft = 1 << 1 }; + enum : uint32_t { kScrollTop = 1 << 2 }; + enum : uint32_t { kTransform = 1 << 3 }; + enum : uint32_t { kTransformRelated = kTransform | kScrollLeft | kScrollTop }; + + enum : int { kNumProperties = 4 }; +}; + +} // namespace cc + +#endif // CC_TREES_MUTABLE_PROPERTIES_H_ diff --git a/chromium/cc/trees/mutator_host.h b/chromium/cc/trees/mutator_host.h new file mode 100644 index 00000000000..bd3ed1d88a4 --- /dev/null +++ b/chromium/cc/trees/mutator_host.h @@ -0,0 +1,138 @@ +// Copyright 2016 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. + +#ifndef CC_TREES_MUTATOR_HOST_H_ +#define CC_TREES_MUTATOR_HOST_H_ + +#include <memory> + +#include "base/memory/ptr_util.h" +#include "base/time/time.h" +#include "cc/trees/element_id.h" +#include "cc/trees/mutator_host_client.h" +#include "ui/gfx/geometry/box_f.h" +#include "ui/gfx/geometry/vector2d_f.h" + +namespace gfx { +class ScrollOffset; +} + +namespace cc { + +class MutatorEvents; +class MutatorHostClient; + +// A MutatorHost owns all the animation and mutation effects. +// There is just one MutatorHost for LayerTreeHost on main renderer thread +// and just one MutatorHost for LayerTreeHostImpl on the impl thread. +// We synchronize them during the commit in a one-way data-flow process +// (PushPropertiesTo). +// A MutatorHost talks to its correspondent LayerTreeHost via +// MutatorHostClient interface. +class MutatorHost { + public: + virtual ~MutatorHost() {} + + virtual std::unique_ptr<MutatorHost> CreateImplInstance( + bool supports_impl_scrolling) const = 0; + + virtual void ClearMutators() = 0; + + virtual void RegisterElement(ElementId element_id, + ElementListType list_type) = 0; + virtual void UnregisterElement(ElementId element_id, + ElementListType list_type) = 0; + + virtual void SetMutatorHostClient(MutatorHostClient* client) = 0; + + virtual void PushPropertiesTo(MutatorHost* host_impl) = 0; + + virtual void SetSupportsScrollAnimations(bool supports_scroll_animations) = 0; + virtual bool NeedsAnimateLayers() const = 0; + + virtual bool ActivateAnimations() = 0; + virtual bool AnimateLayers(base::TimeTicks monotonic_time) = 0; + virtual bool UpdateAnimationState(bool start_ready_animations, + MutatorEvents* events) = 0; + + virtual std::unique_ptr<MutatorEvents> CreateEvents() = 0; + virtual void SetAnimationEvents(std::unique_ptr<MutatorEvents> events) = 0; + + virtual bool ScrollOffsetAnimationWasInterrupted( + ElementId element_id) const = 0; + + virtual bool IsAnimatingFilterProperty(ElementId element_id, + ElementListType list_type) const = 0; + virtual bool IsAnimatingOpacityProperty(ElementId element_id, + ElementListType list_type) const = 0; + virtual bool IsAnimatingTransformProperty( + ElementId element_id, + ElementListType list_type) const = 0; + + virtual bool HasPotentiallyRunningFilterAnimation( + ElementId element_id, + ElementListType list_type) const = 0; + virtual bool HasPotentiallyRunningOpacityAnimation( + ElementId element_id, + ElementListType list_type) const = 0; + virtual bool HasPotentiallyRunningTransformAnimation( + ElementId element_id, + ElementListType list_type) const = 0; + + virtual bool HasAnyAnimationTargetingProperty( + ElementId element_id, + TargetProperty::Type property) const = 0; + + virtual bool HasFilterAnimationThatInflatesBounds( + ElementId element_id) const = 0; + virtual bool HasTransformAnimationThatInflatesBounds( + ElementId element_id) const = 0; + virtual bool HasAnimationThatInflatesBounds(ElementId element_id) const = 0; + + virtual bool FilterAnimationBoundsForBox(ElementId element_id, + const gfx::BoxF& box, + gfx::BoxF* bounds) const = 0; + virtual bool TransformAnimationBoundsForBox(ElementId element_id, + const gfx::BoxF& box, + gfx::BoxF* bounds) const = 0; + + virtual bool HasOnlyTranslationTransforms( + ElementId element_id, + ElementListType list_type) const = 0; + virtual bool AnimationsPreserveAxisAlignment(ElementId element_id) const = 0; + + virtual bool MaximumTargetScale(ElementId element_id, + ElementListType list_type, + float* max_scale) const = 0; + virtual bool AnimationStartScale(ElementId element_id, + ElementListType list_type, + float* start_scale) const = 0; + + virtual bool HasAnyAnimation(ElementId element_id) const = 0; + virtual bool HasActiveAnimationForTesting(ElementId element_id) const = 0; + + virtual void ImplOnlyScrollAnimationCreate( + ElementId element_id, + const gfx::ScrollOffset& target_offset, + const gfx::ScrollOffset& current_offset, + base::TimeDelta delayed_by) = 0; + virtual bool ImplOnlyScrollAnimationUpdateTarget( + ElementId element_id, + const gfx::Vector2dF& scroll_delta, + const gfx::ScrollOffset& max_scroll_offset, + base::TimeTicks frame_monotonic_time, + base::TimeDelta delayed_by) = 0; + + virtual void ScrollAnimationAbort(bool needs_completion) = 0; +}; + +class MutatorEvents { + public: + virtual ~MutatorEvents() {} + virtual bool IsEmpty() const = 0; +}; + +} // namespace cc + +#endif // CC_TREES_MUTATOR_HOST_H_ diff --git a/chromium/cc/trees/mutator_host_client.h b/chromium/cc/trees/mutator_host_client.h index 0dca15b7fbc..d3a3e0e7683 100644 --- a/chromium/cc/trees/mutator_host_client.h +++ b/chromium/cc/trees/mutator_host_client.h @@ -5,10 +5,9 @@ #ifndef CC_TREES_MUTATOR_HOST_CLIENT_H_ #define CC_TREES_MUTATOR_HOST_CLIENT_H_ -// TODO(loyso) Move these headers out of cc/animation. -#include "cc/animation/element_id.h" -#include "cc/animation/property_animation_state.h" -#include "cc/animation/target_property.h" +#include "cc/trees/element_id.h" +#include "cc/trees/property_animation_state.h" +#include "cc/trees/target_property.h" namespace gfx { class Transform; diff --git a/chromium/cc/trees/occlusion_tracker_unittest.cc b/chromium/cc/trees/occlusion_tracker_unittest.cc index 7f8ee8460b1..d99d41eb419 100644 --- a/chromium/cc/trees/occlusion_tracker_unittest.cc +++ b/chromium/cc/trees/occlusion_tracker_unittest.cc @@ -6,6 +6,7 @@ #include <stddef.h> +#include "cc/animation/animation_host.h" #include "cc/base/math_util.h" #include "cc/layers/layer.h" #include "cc/layers/layer_impl.h" @@ -87,7 +88,10 @@ class OcclusionTrackerTest : public testing::Test { protected: explicit OcclusionTrackerTest(bool opaque_layers) : opaque_layers_(opaque_layers), - host_(FakeLayerTreeHost::Create(&client_, &task_graph_runner_)), + animation_host_(AnimationHost::CreateForTesting(ThreadInstance::MAIN)), + host_(FakeLayerTreeHost::Create(&client_, + &task_graph_runner_, + animation_host_.get())), next_layer_impl_id_(1) {} virtual void RunMyTest() = 0; @@ -290,6 +294,7 @@ class OcclusionTrackerTest : public testing::Test { bool opaque_layers_; FakeLayerTreeHostClient client_; TestTaskGraphRunner task_graph_runner_; + std::unique_ptr<AnimationHost> animation_host_; std::unique_ptr<FakeLayerTreeHost> host_; // These hold ownership of the layers for the duration of the test. LayerImplList render_surface_layer_list_impl_; diff --git a/chromium/cc/trees/property_animation_state.cc b/chromium/cc/trees/property_animation_state.cc new file mode 100644 index 00000000000..92f4b99d851 --- /dev/null +++ b/chromium/cc/trees/property_animation_state.cc @@ -0,0 +1,74 @@ +// Copyright 2016 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. + +#include "cc/trees/property_animation_state.h" + +#include "base/logging.h" + +namespace cc { + +PropertyAnimationState::PropertyAnimationState() {} + +PropertyAnimationState::PropertyAnimationState( + const PropertyAnimationState& rhs) + : currently_running(rhs.currently_running), + potentially_animating(rhs.potentially_animating) {} + +PropertyAnimationState::~PropertyAnimationState() {} + +bool PropertyAnimationState::operator==( + const PropertyAnimationState& other) const { + return currently_running == other.currently_running && + potentially_animating == other.potentially_animating; +} + +bool PropertyAnimationState::operator!=( + const PropertyAnimationState& other) const { + return !operator==(other); +} + +PropertyAnimationState& PropertyAnimationState::operator|=( + const PropertyAnimationState& other) { + currently_running |= other.currently_running; + potentially_animating |= other.potentially_animating; + + return *this; +} + +PropertyAnimationState& PropertyAnimationState::operator^=( + const PropertyAnimationState& other) { + currently_running ^= other.currently_running; + potentially_animating ^= other.potentially_animating; + + return *this; +} + +PropertyAnimationState& PropertyAnimationState::operator&=( + const PropertyAnimationState& other) { + currently_running &= other.currently_running; + potentially_animating &= other.potentially_animating; + + return *this; +} + +PropertyAnimationState operator^(const PropertyAnimationState& lhs, + const PropertyAnimationState& rhs) { + PropertyAnimationState result = lhs; + result ^= rhs; + return result; +} + +bool PropertyAnimationState::IsValid() const { + // currently_running must be a subset for potentially_animating. + // currently <= potentially i.e. potentially || !currently. + TargetProperties result = potentially_animating | ~currently_running; + return result.all(); +} + +void PropertyAnimationState::Clear() { + currently_running.reset(); + potentially_animating.reset(); +} + +} // namespace cc diff --git a/chromium/cc/trees/property_animation_state.h b/chromium/cc/trees/property_animation_state.h new file mode 100644 index 00000000000..173ea921da2 --- /dev/null +++ b/chromium/cc/trees/property_animation_state.h @@ -0,0 +1,38 @@ +// Copyright 2016 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. + +#ifndef CC_TREES_PROPERTY_ANIMATION_STATE_H_ +#define CC_TREES_PROPERTY_ANIMATION_STATE_H_ + +#include "cc/base/cc_export.h" +#include "cc/trees/target_property.h" + +namespace cc { + +struct CC_EXPORT PropertyAnimationState { + PropertyAnimationState(); + PropertyAnimationState(const PropertyAnimationState& rhs); + ~PropertyAnimationState(); + + TargetProperties currently_running; + TargetProperties potentially_animating; + + bool operator==(const PropertyAnimationState& other) const; + bool operator!=(const PropertyAnimationState& other) const; + + PropertyAnimationState& operator|=(const PropertyAnimationState& other); + PropertyAnimationState& operator^=(const PropertyAnimationState& other); + PropertyAnimationState& operator&=(const PropertyAnimationState& other); + + bool IsValid() const; + + void Clear(); +}; + +PropertyAnimationState operator^(const PropertyAnimationState& lhs, + const PropertyAnimationState& rhs); + +} // namespace cc + +#endif // CC_TREES_PROPERTY_ANIMATION_STATE_H_ diff --git a/chromium/cc/trees/property_tree.cc b/chromium/cc/trees/property_tree.cc index dc1a210c0c1..3e67f101ae2 100644 --- a/chromium/cc/trees/property_tree.cc +++ b/chromium/cc/trees/property_tree.cc @@ -10,20 +10,19 @@ #include "base/logging.h" #include "base/memory/ptr_util.h" #include "base/trace_event/trace_event_argument.h" -#include "cc/animation/animation_host.h" #include "cc/layers/layer_impl.h" #include "cc/output/copy_output_request.h" #include "cc/proto/gfx_conversions.h" -#include "cc/proto/property_tree.pb.h" -#include "cc/proto/synced_property_conversions.h" #include "cc/trees/clip_node.h" #include "cc/trees/effect_node.h" #include "cc/trees/layer_tree_host_common.h" #include "cc/trees/layer_tree_impl.h" +#include "cc/trees/mutator_host.h" #include "cc/trees/property_tree.h" #include "cc/trees/scroll_node.h" #include "cc/trees/transform_node.h" #include "ui/gfx/geometry/vector2d_conversions.h" + namespace cc { template <typename T> @@ -85,37 +84,6 @@ bool PropertyTree<T>::operator==(const PropertyTree<T>& other) const { } template <typename T> -void PropertyTree<T>::ToProtobuf(proto::PropertyTree* proto) const { - DCHECK_EQ(0, proto->nodes_size()); - for (const auto& node : nodes_) - node.ToProtobuf(proto->add_nodes()); - proto->set_needs_update(needs_update_); -} - -template <typename T> -void PropertyTree<T>::FromProtobuf( - const proto::PropertyTree& proto, - std::unordered_map<int, int>* node_id_to_index_map) { - // Verify that the property tree is empty. - DCHECK_EQ(static_cast<int>(nodes_.size()), 1); - DCHECK_EQ(back()->id, kRootNodeId); - DCHECK_EQ(back()->parent_id, kInvalidNodeId); - - // Add the first node. - DCHECK_GT(proto.nodes_size(), 0); - nodes_.back().FromProtobuf(proto.nodes(0)); - - DCHECK(!node_id_to_index_map || (*node_id_to_index_map).empty()); - for (int i = 1; i < proto.nodes_size(); ++i) { - nodes_.push_back(T()); - nodes_.back().FromProtobuf(proto.nodes(i)); - (*node_id_to_index_map)[nodes_.back().owner_id] = nodes_.back().id; - } - - needs_update_ = proto.needs_update(); -} - -template <typename T> void PropertyTree<T>::AsValueInto(base::trace_event::TracedValue* value) const { value->BeginArray("nodes"); for (const auto& node : nodes_) { @@ -131,20 +99,6 @@ template class PropertyTree<ClipNode>; template class PropertyTree<EffectNode>; template class PropertyTree<ScrollNode>; -void StickyPositionNodeData::ToProtobuf( - proto::StickyPositionNodeData* proto) const { - proto->set_scroll_ancestor(scroll_ancestor); - constraints.ToProtobuf(proto->mutable_constraints()); - Vector2dFToProto(main_thread_offset, proto->mutable_main_thread_offset()); -} - -void StickyPositionNodeData::FromProtobuf( - const proto::StickyPositionNodeData& proto) { - scroll_ancestor = proto.scroll_ancestor(); - constraints.FromProtobuf(proto.constraints()); - main_thread_offset = ProtoToVector2dF(proto.main_thread_offset()); -} - int TransformTree::Insert(const TransformNode& tree_node, int parent_id) { int node_id = PropertyTree<TransformNode>::Insert(tree_node, parent_id); DCHECK_EQ(node_id, static_cast<int>(cached_data_.size())); @@ -174,20 +128,10 @@ void TransformTree::clear() { #endif } -bool TransformTree::ComputeTransform(int source_id, - int dest_id, - gfx::Transform* transform) const { - transform->MakeIdentity(); - - if (source_id == dest_id) - return true; - - if (source_id > dest_id) { - CombineTransformsBetween(source_id, dest_id, transform); - return true; - } - - return CombineInversesBetween(source_id, dest_id, transform); +void TransformTree::set_needs_update(bool needs_update) { + if (needs_update && !needs_update_) + property_trees()->UpdateCachedNumber(); + needs_update_ = needs_update; } bool TransformTree::ComputeTranslation(int source_id, @@ -262,9 +206,9 @@ void TransformTree::ResetChangeTracking() { void TransformTree::UpdateTransforms(int id) { TransformNode* node = Node(id); TransformNode* parent_node = parent(node); + DCHECK(parent_node); TransformNode* target_node = Node(TargetId(id)); TransformNode* source_node = Node(node->source_node_id); - property_trees()->UpdateCachedNumber(); // TODO(flackr): Only dirty when scroll offset changes. if (node->sticky_position_constraint_id >= 0 || node->needs_local_transform_update || NeedsSourceToParentUpdate(node)) { @@ -273,10 +217,8 @@ void TransformTree::UpdateTransforms(int id) { UndoSnapping(node); } UpdateScreenSpaceTransform(node, parent_node, target_node); - UpdateSurfaceContentsScale(node); UpdateAnimationProperties(node, parent_node); UpdateSnapping(node); - UpdateTargetSpaceTransform(node, target_node); UpdateNodeAndAncestorsHaveIntegerTranslations(node, parent_node); UpdateTransformChanged(node, parent_node, source_node); UpdateNodeAndAncestorsAreAnimatedOrInvertible(node, parent_node); @@ -328,30 +270,11 @@ void TransformTree::CombineTransformsBetween(int source_id, std::vector<int> source_to_destination; source_to_destination.push_back(current->id); current = parent(current); - bool destination_has_non_zero_surface_contents_scale = - dest->surface_contents_scale.x() != 0.f && - dest->surface_contents_scale.y() != 0.f; - DCHECK(destination_has_non_zero_surface_contents_scale || - !dest->ancestors_are_invertible); - for (; current && current->id > dest_id; current = parent(current)) { - if (destination_has_non_zero_surface_contents_scale && - TargetId(current->id) == dest_id && - ContentTargetId(current->id) == dest_id) - break; + for (; current && current->id > dest_id; current = parent(current)) source_to_destination.push_back(current->id); - } gfx::Transform combined_transform; - if (current->id > dest_id) { - // TODO(sunxd): Instead of using target space transform, only use to_parent - // here when we fully implement computing draw transforms on demand. - combined_transform = ToTarget(current->id, kInvalidNodeId); - // The stored target space transform has surface contents scale baked in, - // but we need the unscaled transform. - combined_transform.matrix().postScale( - 1.0f / dest->surface_contents_scale.x(), - 1.0f / dest->surface_contents_scale.y(), 1.0f); - } else if (current->id < dest_id) { + if (current->id < dest_id) { // We have reached the lowest common ancestor of the source and destination // nodes. This case can occur when we are transforming between a node // corresponding to a fixed-position layer (or its descendant) and the node @@ -428,9 +351,20 @@ gfx::Vector2dF StickyPositionOffset(TransformTree* tree, TransformNode* node) { gfx::ScrollOffset scroll_offset = tree->property_trees()->scroll_tree.current_scroll_offset( scroll_node->owner_id); - - gfx::RectF clip(gfx::PointF(scroll_offset.x(), scroll_offset.y()), - gfx::SizeF(scroll_node->scroll_clip_layer_bounds)); + gfx::PointF scroll_position(scroll_offset.x(), scroll_offset.y()); + TransformNode* scroll_ancestor_transform_node = + tree->Node(scroll_node->transform_id); + if (scroll_ancestor_transform_node->scrolls) { + // The scroll position does not include snapping which shifts the scroll + // offset to align to a pixel boundary, we need to manually include it here. + // In this case, snapping is caused by a scroll. + scroll_position -= scroll_ancestor_transform_node->snap_amount; + } + + gfx::RectF clip( + scroll_position, + gfx::SizeF(tree->property_trees()->scroll_tree.scroll_clip_layer_bounds( + scroll_node->id))); gfx::Vector2dF sticky_offset( constraint.scroll_container_relative_sticky_box_rect.OffsetFromOrigin()); gfx::Vector2dF layer_offset(sticky_data->main_thread_offset); @@ -492,7 +426,7 @@ gfx::Vector2dF StickyPositionOffset(TransformTree* tree, TransformNode* node) { top_delta = available_space; sticky_offset.set_y(sticky_offset.y() + top_delta); } - return sticky_offset - layer_offset - + return sticky_offset - layer_offset - node->source_to_parent - constraint.scroll_container_relative_sticky_box_rect .OffsetFromOrigin(); } @@ -505,14 +439,20 @@ void TransformTree::UpdateLocalTransform(TransformNode* node) { gfx::Vector2dF unsnapping; TransformNode* current; TransformNode* parent_node; + // Since we are calculating the adjustment for fixed position node or a + // scroll child, we need to unsnap only if the snap was caused by a scroll. for (current = Node(node->source_node_id); current->id > node->parent_id; current = parent(current)) { - unsnapping.Subtract(current->scroll_snap); + DCHECK(current->scrolls || current->snap_amount.IsZero()); + if (current->scrolls) + unsnapping.Subtract(current->snap_amount); } for (parent_node = Node(node->parent_id); parent_node->id > node->source_node_id; parent_node = parent(parent_node)) { - unsnapping.Add(parent_node->scroll_snap); + DCHECK(parent_node->scrolls || parent_node->snap_amount.IsZero()); + if (parent_node->scrolls) + unsnapping.Add(parent_node->snap_amount); } // If a node NeedsSourceToParentUpdate, the node is either a fixed position // node or a scroll child. @@ -532,14 +472,14 @@ void TransformTree::UpdateLocalTransform(TransformNode* node) { property_trees()->inner_viewport_container_bounds_delta(); gfx::Vector2dF outer_viewport_bounds_delta = property_trees()->outer_viewport_container_bounds_delta(); - if (node->affected_by_inner_viewport_bounds_delta_x) + if (node->moved_by_inner_viewport_bounds_delta_x) fixed_position_adjustment.set_x(inner_viewport_bounds_delta.x()); - else if (node->affected_by_outer_viewport_bounds_delta_x) + else if (node->moved_by_outer_viewport_bounds_delta_x) fixed_position_adjustment.set_x(outer_viewport_bounds_delta.x()); - if (node->affected_by_inner_viewport_bounds_delta_y) + if (node->moved_by_inner_viewport_bounds_delta_y) fixed_position_adjustment.set_y(inner_viewport_bounds_delta.y()); - else if (node->affected_by_outer_viewport_bounds_delta_y) + else if (node->moved_by_outer_viewport_bounds_delta_y) fixed_position_adjustment.set_y(outer_viewport_bounds_delta.y()); transform.Translate(node->source_to_parent.x() - node->scroll_offset.x() + @@ -557,21 +497,15 @@ void TransformTree::UpdateLocalTransform(TransformNode* node) { void TransformTree::UpdateScreenSpaceTransform(TransformNode* node, TransformNode* parent_node, TransformNode* target_node) { - if (!parent_node) { - SetToScreen(node->id, node->to_parent); - node->ancestors_are_invertible = true; - node->to_screen_is_potentially_animated = false; - node->node_and_ancestors_are_flat = node->to_parent.IsFlat(); - } else { - gfx::Transform to_screen_space_transform = ToScreen(parent_node->id); - if (node->flattens_inherited_transform) - to_screen_space_transform.FlattenTo2d(); - to_screen_space_transform.PreconcatTransform(node->to_parent); - node->ancestors_are_invertible = parent_node->ancestors_are_invertible; - node->node_and_ancestors_are_flat = - parent_node->node_and_ancestors_are_flat && node->to_parent.IsFlat(); - SetToScreen(node->id, to_screen_space_transform); - } + DCHECK(parent_node); + gfx::Transform to_screen_space_transform = ToScreen(parent_node->id); + if (node->flattens_inherited_transform) + to_screen_space_transform.FlattenTo2d(); + to_screen_space_transform.PreconcatTransform(node->to_parent); + node->ancestors_are_invertible = parent_node->ancestors_are_invertible; + node->node_and_ancestors_are_flat = + parent_node->node_and_ancestors_are_flat && node->to_parent.IsFlat(); + SetToScreen(node->id, to_screen_space_transform); gfx::Transform from_screen; if (!ToScreen(node->id).GetInverse(&from_screen)) @@ -579,75 +513,37 @@ void TransformTree::UpdateScreenSpaceTransform(TransformNode* node, SetFromScreen(node->id, from_screen); } -void TransformTree::UpdateSurfaceContentsScale(TransformNode* node) { - // The surface contents scale depends on the screen space transform, so update - // it too. - if (!node->needs_surface_contents_scale) { - node->surface_contents_scale = gfx::Vector2dF(1.0f, 1.0f); - return; - } - - float layer_scale_factor = - device_scale_factor_ * device_transform_scale_factor_; - if (node->in_subtree_of_page_scale_layer) - layer_scale_factor *= page_scale_factor_; - node->surface_contents_scale = MathUtil::ComputeTransform2dScaleComponents( - ToScreen(node->id), layer_scale_factor); -} - -void TransformTree::UpdateTargetSpaceTransform(TransformNode* node, - TransformNode* target_node) { - gfx::Transform target_space_transform; - if (node->needs_surface_contents_scale) { - target_space_transform.MakeIdentity(); - target_space_transform.Scale(node->surface_contents_scale.x(), - node->surface_contents_scale.y()); - } else { - // In order to include the root transform for the root surface, we walk up - // to the root of the transform tree in ComputeTransform. - int target_id = target_node->id; - ComputeTransform(node->id, target_id, &target_space_transform); - target_space_transform.matrix().postScale( - target_node->surface_contents_scale.x(), - target_node->surface_contents_scale.y(), 1.f); - } - - gfx::Transform from_target; - if (!target_space_transform.GetInverse(&from_target)) - node->ancestors_are_invertible = false; - SetToTarget(node->id, target_space_transform); - SetFromTarget(node->id, from_target); -} - void TransformTree::UpdateAnimationProperties(TransformNode* node, TransformNode* parent_node) { + DCHECK(parent_node); bool ancestor_is_animating = false; - if (parent_node) - ancestor_is_animating = parent_node->to_screen_is_potentially_animated; + ancestor_is_animating = parent_node->to_screen_is_potentially_animated; node->to_screen_is_potentially_animated = node->has_potential_animation || ancestor_is_animating; } void TransformTree::UndoSnapping(TransformNode* node) { - // to_parent transform has the scroll snap from previous frame baked in. + // to_parent transform has snapping from previous frame baked in. // We need to undo it and use the un-snapped transform to compute current // target and screen space transforms. - node->to_parent.Translate(-node->scroll_snap.x(), -node->scroll_snap.y()); + node->to_parent.Translate(-node->snap_amount.x(), -node->snap_amount.y()); } void TransformTree::UpdateSnapping(TransformNode* node) { - if (!node->scrolls || node->to_screen_is_potentially_animated || + if (!node->should_be_snapped || node->to_screen_is_potentially_animated || !ToScreen(node->id).IsScaleOrTranslation() || !node->ancestors_are_invertible) { return; } - // Scroll snapping must be done in screen space (the pixels we care about). - // This means we effectively snap the screen space transform. If ST is the + // Snapping must be done in target space (the pixels we care about) and then + // the render pass should also be snapped if necessary. But, we do it in + // screen space because it is easier and works most of the time if there is + // no intermediate render pass with a snap-destrying transform. If ST is the // screen space transform and ST' is ST with its translation components // rounded, then what we're after is the scroll delta X, where ST * X = ST'. - // I.e., we want a transform that will realize our scroll snap. It follows - // that X = ST^-1 * ST'. We cache ST and ST^-1 to make this more efficient. + // I.e., we want a transform that will realize our snap. It follows that + // X = ST^-1 * ST'. We cache ST and ST^-1 to make this more efficient. gfx::Transform rounded = ToScreen(node->id); rounded.RoundTranslationComponents(); gfx::Transform delta = FromScreen(node->id); @@ -658,20 +554,21 @@ void TransformTree::UpdateSnapping(TransformNode* node) { gfx::Vector2dF translation = delta.To2dTranslation(); - // Now that we have our scroll delta, we must apply it to each of our - // combined, to/from matrices. + // Now that we have our delta, we must apply it to each of our combined, + // to/from matrices. SetToScreen(node->id, rounded); node->to_parent.Translate(translation.x(), translation.y()); gfx::Transform from_screen = FromScreen(node->id); from_screen.matrix().postTranslate(-translation.x(), -translation.y(), 0); SetFromScreen(node->id, from_screen); - node->scroll_snap = translation; + node->snap_amount = translation; } void TransformTree::UpdateTransformChanged(TransformNode* node, TransformNode* parent_node, TransformNode* source_node) { - if (parent_node && parent_node->transform_changed) { + DCHECK(parent_node); + if (parent_node->transform_changed) { node->transform_changed = true; return; } @@ -684,11 +581,7 @@ void TransformTree::UpdateTransformChanged(TransformNode* node, void TransformTree::UpdateNodeAndAncestorsAreAnimatedOrInvertible( TransformNode* node, TransformNode* parent_node) { - if (!parent_node) { - node->node_and_ancestors_are_animated_or_invertible = - node->has_potential_animation || node->is_invertible; - return; - } + DCHECK(parent_node); if (!parent_node->node_and_ancestors_are_animated_or_invertible) { node->node_and_ancestors_are_animated_or_invertible = false; return; @@ -738,10 +631,7 @@ void TransformTree::SetRootTransformsAndScales( gfx::Transform root_from_screen; bool invertible = root_to_screen.GetInverse(&root_from_screen); DCHECK(invertible); - TransformNode* root_node = Node(kRootNodeId); - if (root_node->surface_contents_scale != screen_space_scale) { - root_node->needs_surface_contents_scale = true; - root_node->surface_contents_scale = screen_space_scale; + if (root_to_screen != ToScreen(kRootNodeId)) { SetToScreen(kRootNodeId, root_to_screen); SetFromScreen(kRootNodeId, root_from_screen); set_needs_update(true); @@ -790,44 +680,6 @@ bool TransformTree::HasNodesAffectedByOuterViewportBoundsDelta() const { return !nodes_affected_by_outer_viewport_bounds_delta_.empty(); } -const gfx::Transform& TransformTree::FromTarget(int node_id, - int effect_id) const { - DCHECK(static_cast<int>(cached_data_.size()) > node_id); - if (effect_id != kInvalidNodeId && - property_trees()->verify_transform_tree_calculations) { - const gfx::Transform& transform = - property_trees()->GetDrawTransforms(node_id, effect_id).from_target; - CHECK(transform.ApproximatelyEqual(cached_data_[node_id].from_target)); - } - return cached_data_[node_id].from_target; -} - -void TransformTree::SetFromTarget(int node_id, - const gfx::Transform& transform) { - DCHECK(static_cast<int>(cached_data_.size()) > node_id); - cached_data_[node_id].from_target = transform; -} - -const gfx::Transform& TransformTree::ToTarget(int node_id, - int effect_id) const { - DCHECK(static_cast<int>(cached_data_.size()) > node_id); - if (effect_id != kInvalidNodeId && - property_trees()->verify_transform_tree_calculations) { - const gfx::Transform& transform = - property_trees()->GetDrawTransforms(node_id, effect_id).to_target; - if (property_trees()->non_root_surfaces_enabled) - CHECK(transform.ApproximatelyEqual(cached_data_[node_id].to_target)); - else - CHECK(transform.ApproximatelyEqual(cached_data_[node_id].to_screen)); - } - return cached_data_[node_id].to_target; -} - -void TransformTree::SetToTarget(int node_id, const gfx::Transform& transform) { - DCHECK(static_cast<int>(cached_data_.size()) > node_id); - cached_data_[node_id].to_target = transform; -} - const gfx::Transform& TransformTree::FromScreen(int node_id) const { DCHECK(static_cast<int>(cached_data_.size()) > node_id); return cached_data_[node_id].from_screen; @@ -847,6 +699,7 @@ const gfx::Transform& TransformTree::ToScreen(int node_id) const { void TransformTree::SetToScreen(int node_id, const gfx::Transform& transform) { DCHECK(static_cast<int>(cached_data_.size()) > node_id); cached_data_[node_id].to_screen = transform; + cached_data_[node_id].is_showing_backface = transform.IsBackFaceVisible(); } int TransformTree::TargetId(int node_id) const { @@ -893,73 +746,6 @@ StickyPositionNodeData* TransformTree::StickyPositionData(int node_id) { return &sticky_position_data_[node->sticky_position_constraint_id]; } -void TransformTree::ToProtobuf(proto::PropertyTree* proto) const { - DCHECK(!proto->has_property_type()); - proto->set_property_type(proto::PropertyTree::Transform); - - PropertyTree::ToProtobuf(proto); - proto::TransformTreeData* data = proto->mutable_transform_tree_data(); - - data->set_source_to_parent_updates_allowed(source_to_parent_updates_allowed_); - data->set_page_scale_factor(page_scale_factor_); - data->set_device_scale_factor(device_scale_factor_); - data->set_device_transform_scale_factor(device_transform_scale_factor_); - - for (auto i : nodes_affected_by_inner_viewport_bounds_delta_) - data->add_nodes_affected_by_inner_viewport_bounds_delta(i); - - for (auto i : nodes_affected_by_outer_viewport_bounds_delta_) - data->add_nodes_affected_by_outer_viewport_bounds_delta(i); - - for (int i = 0; i < static_cast<int>(cached_data_.size()); ++i) - cached_data_[i].ToProtobuf(data->add_cached_data()); - - for (int i = 0; i < static_cast<int>(sticky_position_data_.size()); ++i) - sticky_position_data_[i].ToProtobuf(data->add_sticky_position_data()); -} - -void TransformTree::FromProtobuf( - const proto::PropertyTree& proto, - std::unordered_map<int, int>* node_id_to_index_map) { - DCHECK(proto.has_property_type()); - DCHECK_EQ(proto.property_type(), proto::PropertyTree::Transform); - - PropertyTree::FromProtobuf(proto, node_id_to_index_map); - const proto::TransformTreeData& data = proto.transform_tree_data(); - - source_to_parent_updates_allowed_ = data.source_to_parent_updates_allowed(); - page_scale_factor_ = data.page_scale_factor(); - device_scale_factor_ = data.device_scale_factor(); - device_transform_scale_factor_ = data.device_transform_scale_factor(); - - DCHECK(nodes_affected_by_inner_viewport_bounds_delta_.empty()); - for (int i = 0; i < data.nodes_affected_by_inner_viewport_bounds_delta_size(); - ++i) { - nodes_affected_by_inner_viewport_bounds_delta_.push_back( - data.nodes_affected_by_inner_viewport_bounds_delta(i)); - } - - DCHECK(nodes_affected_by_outer_viewport_bounds_delta_.empty()); - for (int i = 0; i < data.nodes_affected_by_outer_viewport_bounds_delta_size(); - ++i) { - nodes_affected_by_outer_viewport_bounds_delta_.push_back( - data.nodes_affected_by_outer_viewport_bounds_delta(i)); - } - - DCHECK_EQ(static_cast<int>(cached_data_.size()), 1); - cached_data_.back().FromProtobuf(data.cached_data(0)); - for (int i = 1; i < data.cached_data_size(); ++i) { - cached_data_.push_back(TransformCachedNodeData()); - cached_data_.back().FromProtobuf(data.cached_data(i)); - } - - DCHECK(static_cast<int>(sticky_position_data_.empty())); - for (int i = 0; i < data.sticky_position_data_size(); ++i) { - sticky_position_data_.push_back(StickyPositionNodeData()); - sticky_position_data_.back().FromProtobuf(data.sticky_position_data(i)); - } -} - EffectTree::EffectTree() {} EffectTree::~EffectTree() {} @@ -1015,40 +801,17 @@ void EffectTree::UpdateEffectChanged(EffectNode* node, void EffectTree::UpdateBackfaceVisibility(EffectNode* node, EffectNode* parent_node) { - if (!parent_node) { - node->hidden_by_backface_visibility = false; - return; - } - if (parent_node->hidden_by_backface_visibility) { + if (parent_node && parent_node->hidden_by_backface_visibility) { node->hidden_by_backface_visibility = true; return; + } else if (node->double_sided) { + node->hidden_by_backface_visibility = false; + return; } - - TransformTree& transform_tree = property_trees()->transform_tree; - if (node->has_render_surface && !node->double_sided) { - TransformNode* transform_node = transform_tree.Node(node->transform_id); - if (transform_node->is_invertible && - transform_node->ancestors_are_invertible) { - if (transform_node->sorting_context_id) { - const TransformNode* parent_transform_node = - transform_tree.parent(transform_node); - if (parent_transform_node && - parent_transform_node->sorting_context_id == - transform_node->sorting_context_id) { - gfx::Transform surface_draw_transform; - property_trees()->ComputeTransformToTarget( - transform_node->id, node->target_id, &surface_draw_transform); - node->hidden_by_backface_visibility = - surface_draw_transform.IsBackFaceVisible(); - } else { - node->hidden_by_backface_visibility = - transform_node->local.IsBackFaceVisible(); - } - return; - } - } - } - node->hidden_by_backface_visibility = false; + node->hidden_by_backface_visibility = + property_trees() + ->transform_tree.cached_data()[node->transform_id] + .is_showing_backface; } void EffectTree::UpdateSurfaceContentsScale(EffectNode* effect_node) { @@ -1170,10 +933,7 @@ void EffectTree::TakeCopyRequestsAndTransformToSurface( source_id = TransformTree::kContentsRootNodeId; } gfx::Transform transform; - property_trees()->transform_tree.ComputeTransform(source_id, destination_id, - &transform); - transform.matrix().postScale(effect_node->surface_contents_scale.x(), - effect_node->surface_contents_scale.y(), 1.f); + property_trees()->GetToTarget(source_id, node_id, &transform); it->set_area(MathUtil::MapEnclosingClippedRect(transform, it->area())); } } @@ -1233,12 +993,10 @@ void EffectTree::ResetChangeTracking() { void TransformTree::UpdateNodeAndAncestorsHaveIntegerTranslations( TransformNode* node, TransformNode* parent_node) { + DCHECK(parent_node); node->node_and_ancestors_have_only_integer_translation = - node->to_parent.IsIdentityOrIntegerTranslation(); - if (parent_node) - node->node_and_ancestors_have_only_integer_translation = - node->node_and_ancestors_have_only_integer_translation && - parent_node->node_and_ancestors_have_only_integer_translation; + node->to_parent.IsIdentityOrIntegerTranslation() && + parent_node->node_and_ancestors_have_only_integer_translation; } void ClipTree::SetViewportClip(gfx::RectF viewport_rect) { @@ -1261,22 +1019,6 @@ bool ClipTree::operator==(const ClipTree& other) const { return PropertyTree::operator==(other); } -void ClipTree::ToProtobuf(proto::PropertyTree* proto) const { - DCHECK(!proto->has_property_type()); - proto->set_property_type(proto::PropertyTree::Clip); - - PropertyTree::ToProtobuf(proto); -} - -void ClipTree::FromProtobuf( - const proto::PropertyTree& proto, - std::unordered_map<int, int>* node_id_to_index_map) { - DCHECK(proto.has_property_type()); - DCHECK_EQ(proto.property_type(), proto::PropertyTree::Clip); - - PropertyTree::FromProtobuf(proto, node_id_to_index_map); -} - EffectTree& EffectTree::operator=(const EffectTree& from) { PropertyTree::operator=(from); mask_layer_ids_ = from.mask_layer_ids_; @@ -1290,32 +1032,6 @@ bool EffectTree::operator==(const EffectTree& other) const { mask_layer_ids_ == other.mask_layer_ids_; } -void EffectTree::ToProtobuf(proto::PropertyTree* proto) const { - DCHECK(!proto->has_property_type()); - proto->set_property_type(proto::PropertyTree::Effect); - - PropertyTree::ToProtobuf(proto); - proto::EffectTreeData* data = proto->mutable_effect_tree_data(); - - for (auto i : mask_layer_ids_) - data->add_mask_layer_ids(i); -} - -void EffectTree::FromProtobuf( - const proto::PropertyTree& proto, - std::unordered_map<int, int>* node_id_to_index_map) { - DCHECK(proto.has_property_type()); - DCHECK_EQ(proto.property_type(), proto::PropertyTree::Effect); - - PropertyTree::FromProtobuf(proto, node_id_to_index_map); - const proto::EffectTreeData& data = proto.effect_tree_data(); - - DCHECK(mask_layer_ids_.empty()); - for (int i = 0; i < data.mask_layer_ids_size(); ++i) { - mask_layer_ids_.push_back(data.mask_layer_ids(i)); - } -} - ScrollTree::ScrollTree() : currently_scrolling_node_id_(kInvalidNodeId), layer_id_to_scroll_offset_map_(ScrollTree::ScrollOffsetMap()) {} @@ -1354,48 +1070,6 @@ bool ScrollTree::operator==(const ScrollTree& other) const { return PropertyTree::operator==(other) && is_currently_scrolling_node_equal; } -void ScrollTree::ToProtobuf(proto::PropertyTree* proto) const { - DCHECK(!proto->has_property_type()); - proto->set_property_type(proto::PropertyTree::Scroll); - - PropertyTree::ToProtobuf(proto); - proto::ScrollTreeData* data = proto->mutable_scroll_tree_data(); - - data->set_currently_scrolling_node_id(currently_scrolling_node_id_); - for (auto i : layer_id_to_scroll_offset_map_) { - data->add_layer_id_to_scroll_offset_map(); - proto::ScrollOffsetMapEntry* entry = - data->mutable_layer_id_to_scroll_offset_map( - data->layer_id_to_scroll_offset_map_size() - 1); - entry->set_layer_id(i.first); - SyncedScrollOffsetToProto(*i.second.get(), entry->mutable_scroll_offset()); - } -} - -void ScrollTree::FromProtobuf( - const proto::PropertyTree& proto, - std::unordered_map<int, int>* node_id_to_index_map) { - DCHECK(proto.has_property_type()); - DCHECK_EQ(proto.property_type(), proto::PropertyTree::Scroll); - - PropertyTree::FromProtobuf(proto, node_id_to_index_map); - const proto::ScrollTreeData& data = proto.scroll_tree_data(); - - currently_scrolling_node_id_ = data.currently_scrolling_node_id(); - - // TODO(khushalsagar): This should probably be removed if the copy constructor - // for ScrollTree copies the |layer_id_to_scroll_offset_map_| as well. - layer_id_to_scroll_offset_map_.clear(); - for (int i = 0; i < data.layer_id_to_scroll_offset_map_size(); ++i) { - const proto::ScrollOffsetMapEntry entry = - data.layer_id_to_scroll_offset_map(i); - layer_id_to_scroll_offset_map_[entry.layer_id()] = new SyncedScrollOffset(); - ProtoToSyncedScrollOffset( - entry.scroll_offset(), - layer_id_to_scroll_offset_map_[entry.layer_id()].get()); - } -} - void ScrollTree::clear() { PropertyTree<ScrollNode>::clear(); @@ -1772,8 +1446,7 @@ PropertyTrees::PropertyTrees() full_tree_damaged(false), sequence_number(0), is_main_thread(true), - is_active(false), - verify_transform_tree_calculations(false) { + is_active(false) { transform_tree.SetPropertyTrees(this); effect_tree.SetPropertyTrees(this); clip_tree.SetPropertyTrees(this); @@ -1818,7 +1491,6 @@ PropertyTrees& PropertyTrees::operator=(const PropertyTrees& from) { sequence_number = from.sequence_number; is_main_thread = from.is_main_thread; is_active = from.is_active; - verify_transform_tree_calculations = from.verify_transform_tree_calculations; inner_viewport_container_bounds_delta_ = from.inner_viewport_container_bounds_delta(); outer_viewport_container_bounds_delta_ = @@ -1833,56 +1505,6 @@ PropertyTrees& PropertyTrees::operator=(const PropertyTrees& from) { return *this; } -void PropertyTrees::ToProtobuf(proto::PropertyTrees* proto) const { - // TODO(khushalsagar): Add support for sending diffs when serializaing - // property trees. See crbug/555370. - transform_tree.ToProtobuf(proto->mutable_transform_tree()); - effect_tree.ToProtobuf(proto->mutable_effect_tree()); - clip_tree.ToProtobuf(proto->mutable_clip_tree()); - scroll_tree.ToProtobuf(proto->mutable_scroll_tree()); - proto->set_needs_rebuild(needs_rebuild); - proto->set_changed(changed); - proto->set_full_tree_damaged(full_tree_damaged); - proto->set_non_root_surfaces_enabled(non_root_surfaces_enabled); - proto->set_is_main_thread(is_main_thread); - proto->set_is_active(is_active); - proto->set_verify_transform_tree_calculations( - verify_transform_tree_calculations); - - // TODO(khushalsagar): Consider using the sequence number to decide if - // property trees need to be serialized again for a commit. See crbug/555370. - proto->set_sequence_number(sequence_number); - - for (auto i : always_use_active_tree_opacity_effect_ids) - proto->add_always_use_active_tree_opacity_effect_ids(i); -} - -// static -void PropertyTrees::FromProtobuf(const proto::PropertyTrees& proto) { - transform_tree.FromProtobuf(proto.transform_tree(), - &transform_id_to_index_map); - effect_tree.FromProtobuf(proto.effect_tree(), &effect_id_to_index_map); - clip_tree.FromProtobuf(proto.clip_tree(), &clip_id_to_index_map); - scroll_tree.FromProtobuf(proto.scroll_tree(), &scroll_id_to_index_map); - - needs_rebuild = proto.needs_rebuild(); - changed = proto.changed(); - full_tree_damaged = proto.full_tree_damaged(); - non_root_surfaces_enabled = proto.non_root_surfaces_enabled(); - sequence_number = proto.sequence_number(); - is_main_thread = proto.is_main_thread(); - is_active = proto.is_active(); - verify_transform_tree_calculations = - proto.verify_transform_tree_calculations(); - - transform_tree.SetPropertyTrees(this); - effect_tree.SetPropertyTrees(this); - clip_tree.SetPropertyTrees(this); - scroll_tree.SetPropertyTrees(this); - for (auto i : proto.always_use_active_tree_opacity_effect_ids()) - always_use_active_tree_opacity_effect_ids.push_back(i); -} - void PropertyTrees::clear() { transform_tree.clear(); clip_tree.clear(); @@ -2101,8 +1723,7 @@ CombinedAnimationScale PropertyTrees::GetAnimationScales( // Computing maximum animated scale in the presence of non-scale/translation // transforms isn't supported. bool failed_for_non_scale_or_translation = - !transform_tree.Node(transform_node_id) - ->to_parent.IsScaleOrTranslation(); + !node->to_parent.IsScaleOrTranslation(); // We don't attempt to accumulate animation scale from multiple nodes with // scale animations, because of the risk of significant overestimation. For @@ -2144,11 +1765,11 @@ CombinedAnimationScale PropertyTrees::GetAnimationScales( // TODO(sunxd): make LayerTreeImpl::MaximumTargetScale take layer id as // parameter. LayerImpl* layer_impl = layer_tree_impl->LayerById(node->owner_id); - layer_impl->GetAnimationHost()->MaximumTargetScale( + layer_impl->GetMutatorHost()->MaximumTargetScale( layer_impl->element_id(), layer_impl->GetElementTypeForAnimation(), &cached_data_.animation_scales[transform_node_id] .local_maximum_animation_target_scale); - layer_impl->GetAnimationHost()->AnimationStartScale( + layer_impl->GetMutatorHost()->AnimationStartScale( layer_impl->element_id(), layer_impl->GetElementTypeForAnimation(), &cached_data_.animation_scales[transform_node_id] .local_starting_animation_scale); @@ -2207,95 +1828,123 @@ void PropertyTrees::SetAnimationScalesForTesting( cached_data_.property_tree_update_number; } -const DrawTransforms& PropertyTrees::GetDrawTransforms(int transform_id, - int effect_id) const { - if (cached_data_.draw_transforms[effect_id][transform_id].update_number != - cached_data_.property_tree_update_number) { - gfx::Transform target_space_transform; - gfx::Transform from_target; - const TransformNode* transform_node = transform_tree.Node(transform_id); - const EffectNode* effect_node = effect_tree.Node(effect_id); - const TransformNode* dest_node = - transform_tree.Node(effect_node->transform_id); - DCHECK(effect_id == effect_tree.kRootNodeId || - effect_node->has_render_surface); - bool already_computed_inverse = false; - if (transform_id == effect_node->transform_id) { - target_space_transform.Scale(effect_node->surface_contents_scale.x(), - effect_node->surface_contents_scale.y()); - } else if (!dest_node || (dest_node->ancestors_are_invertible && - dest_node->node_and_ancestors_are_flat)) { - // Compute transform from transform_id to effect_node->transform using - // screen space transforms. - target_space_transform.ConcatTransform( - transform_tree.ToScreen(transform_id)); - if (dest_node) - target_space_transform.ConcatTransform( - transform_tree.FromScreen(dest_node->id)); - if (dest_node->needs_surface_contents_scale) - target_space_transform.matrix().postScale( - dest_node->surface_contents_scale.x(), - dest_node->surface_contents_scale.y(), 1.f); - } else if (transform_node->id > dest_node->id) { - target_space_transform = - GetDrawTransforms(transform_node->parent_id, effect_id).to_target; - if (transform_node->flattens_inherited_transform) - target_space_transform.FlattenTo2d(); - target_space_transform.PreconcatTransform(transform_node->to_parent); - } else { - const TransformNode* current = dest_node; - std::vector<int> source_to_destination; - source_to_destination.push_back(current->id); - current = transform_tree.parent(current); - for (; current && current->id > transform_node->id; - current = transform_tree.parent(current)) { - source_to_destination.push_back(current->id); - } - DCHECK_EQ(current, transform_node); - gfx::Transform combined_transform; - size_t source_to_destination_size = source_to_destination.size(); - for (size_t i = 0; i < source_to_destination_size; ++i) { - size_t index = source_to_destination_size - 1 - i; - const TransformNode* node = - transform_tree.Node(source_to_destination[index]); - if (node->flattens_inherited_transform) - combined_transform.FlattenTo2d(); - combined_transform.PreconcatTransform(node->to_parent); - } - if (effect_node->surface_contents_scale.x() != 0.f && - effect_node->surface_contents_scale.y() != 0.f) - combined_transform.Scale( - 1.0f / effect_node->surface_contents_scale.x(), - 1.0f / effect_node->surface_contents_scale.y()); - cached_data_.draw_transforms[effect_id][transform_id] - .transforms.invertible = - combined_transform.GetInverse(&target_space_transform); - from_target = combined_transform; - already_computed_inverse = true; - } - if (!already_computed_inverse) { - cached_data_.draw_transforms[effect_id][transform_id] - .transforms.invertible = - target_space_transform.GetInverse(&from_target); +bool PropertyTrees::GetToTarget(int transform_id, + int effect_id, + gfx::Transform* to_target) const { + DrawTransforms& transforms = GetDrawTransforms(transform_id, effect_id); + if (transforms.to_valid) { + *to_target = transforms.to_target; + return true; + } else if (!transforms.might_be_invertible) { + return false; + } else { + transforms.might_be_invertible = + transforms.from_target.GetInverse(to_target); + transforms.to_valid = transforms.might_be_invertible; + transforms.to_target = *to_target; + return transforms.to_valid; + } +} + +bool PropertyTrees::GetFromTarget(int transform_id, + int effect_id, + gfx::Transform* from_target) const { + DrawTransforms& transforms = GetDrawTransforms(transform_id, effect_id); + if (transforms.from_valid) { + *from_target = transforms.from_target; + return true; + } else if (!transforms.might_be_invertible) { + return false; + } else { + transforms.might_be_invertible = + transforms.to_target.GetInverse(from_target); + transforms.from_valid = transforms.might_be_invertible; + transforms.from_target = *from_target; + return transforms.from_valid; + } +} + +DrawTransformData& PropertyTrees::FetchDrawTransformsDataFromCache( + int transform_id, + int dest_id) const { + for (auto& transform_data : cached_data_.draw_transforms[transform_id]) { + // We initialize draw_transforms with 1 element vectors when + // ResetCachedData, so if we hit a -1 target id, it means it's the first + // time we compute draw transforms after reset. + if (transform_data.target_id == dest_id || transform_data.target_id == -1) { + return transform_data; } - cached_data_.draw_transforms[effect_id][transform_id].update_number = - cached_data_.property_tree_update_number; - cached_data_.draw_transforms[effect_id][transform_id] - .transforms.from_target = from_target; - cached_data_.draw_transforms[effect_id][transform_id].transforms.to_target = - target_space_transform; } - return cached_data_.draw_transforms[effect_id][transform_id].transforms; + // Add an entry to the cache. + cached_data_.draw_transforms[transform_id].push_back(DrawTransformData()); + DrawTransformData& data = cached_data_.draw_transforms[transform_id].back(); + data.update_number = -1; + data.target_id = dest_id; + return data; +} + +DrawTransforms& PropertyTrees::GetDrawTransforms(int transform_id, + int effect_id) const { + const EffectNode* effect_node = effect_tree.Node(effect_id); + int dest_id = effect_node->transform_id; + + DrawTransformData& data = + FetchDrawTransformsDataFromCache(transform_id, dest_id); + + DCHECK(data.update_number != cached_data_.property_tree_update_number || + data.target_id != -1); + if (data.update_number == cached_data_.property_tree_update_number) + return data.transforms; + + // Cache miss. + gfx::Transform target_space_transform; + gfx::Transform from_target; + bool already_computed_inverse = false; + if (transform_id == dest_id) { + target_space_transform.Scale(effect_node->surface_contents_scale.x(), + effect_node->surface_contents_scale.y()); + data.transforms.to_valid = true; + data.transforms.from_valid = false; + } else if (transform_id > dest_id) { + transform_tree.CombineTransformsBetween(transform_id, dest_id, + &target_space_transform); + target_space_transform.matrix().postScale( + effect_node->surface_contents_scale.x(), + effect_node->surface_contents_scale.y(), 1.f); + data.transforms.to_valid = true; + data.transforms.from_valid = false; + data.transforms.might_be_invertible = true; + } else { + gfx::Transform combined_transform; + transform_tree.CombineTransformsBetween(dest_id, transform_id, + &combined_transform); + if (effect_node->surface_contents_scale.x() != 0.f && + effect_node->surface_contents_scale.y() != 0.f) + combined_transform.Scale(1.0f / effect_node->surface_contents_scale.x(), + 1.0f / effect_node->surface_contents_scale.y()); + bool invertible = combined_transform.GetInverse(&target_space_transform); + data.transforms.might_be_invertible = invertible; + data.transforms.to_valid = invertible; + data.transforms.from_valid = true; + from_target = combined_transform; + already_computed_inverse = true; + } + + if (!already_computed_inverse) + data.transforms.to_valid = true; + data.update_number = cached_data_.property_tree_update_number; + data.target_id = dest_id; + data.transforms.from_target = from_target; + data.transforms.to_target = target_space_transform; + return data.transforms; } void PropertyTrees::ResetCachedData() { cached_data_.property_tree_update_number = 0; cached_data_.animation_scales = std::vector<AnimationScaleData>( transform_tree.nodes().size(), AnimationScaleData()); - cached_data_.draw_transforms = - std::vector<std::unordered_map<int, DrawTransformData>>( - effect_tree.nodes().size(), - std::unordered_map<int, DrawTransformData>()); + cached_data_.draw_transforms = std::vector<std::vector<DrawTransformData>>( + transform_tree.nodes().size(), std::vector<DrawTransformData>(1)); } void PropertyTrees::UpdateCachedNumber() { @@ -2319,76 +1968,19 @@ gfx::Transform PropertyTrees::ToScreenSpaceTransformWithoutSurfaceContentsScale( return screen_space_transform; } -bool PropertyTrees::ComputeTransformToTarget(int transform_id, - int effect_id, - gfx::Transform* transform) const { - transform->MakeIdentity(); - - if (transform_id == TransformTree::kInvalidNodeId) - return true; - - int target_transform_id; - const EffectNode* effect_node = effect_tree.Node(effect_id); - if (effect_id == EffectTree::kInvalidNodeId) { - // This can happen when PaintArtifactCompositor builds property trees as - // it doesn't set effect ids on clip nodes. We want to compute transform - // to the root in this case. - target_transform_id = TransformTree::kRootNodeId; - } else { - DCHECK(effect_node->has_render_surface || - effect_node->id == EffectTree::kRootNodeId); - target_transform_id = effect_node->transform_id; - } - - bool success = transform_tree.ComputeTransform( - transform_id, target_transform_id, transform); - if (verify_transform_tree_calculations) { - gfx::Transform to_target; - to_target.ConcatTransform( - GetDrawTransforms(transform_id, effect_id).to_target); - if (effect_node->surface_contents_scale.x() != 0.f && - effect_node->surface_contents_scale.y() != 0.f) - to_target.matrix().postScale( - 1.0f / effect_node->surface_contents_scale.x(), - 1.0f / effect_node->surface_contents_scale.y(), 1.0f); - DCHECK(to_target.ApproximatelyEqual(*transform)); - } - return success; -} - bool PropertyTrees::ComputeTransformFromTarget( int transform_id, int effect_id, gfx::Transform* transform) const { transform->MakeIdentity(); - if (transform_id == TransformTree::kInvalidNodeId) return true; - int target_transform_id; const EffectNode* effect_node = effect_tree.Node(effect_id); - if (effect_id == EffectTree::kInvalidNodeId) { - // This can happen when PaintArtifactCompositor builds property trees as - // it doesn't set effect ids on clip nodes. We want to compute transform - // to the root in this case. - target_transform_id = TransformTree::kRootNodeId; - } else { - DCHECK(effect_node->has_render_surface || - effect_node->id == EffectTree::kRootNodeId); - target_transform_id = effect_node->transform_id; - } - bool success = transform_tree.ComputeTransform(target_transform_id, - transform_id, transform); - if (verify_transform_tree_calculations) { - auto draw_transforms = GetDrawTransforms(transform_id, effect_id); - gfx::Transform from_target; - from_target.ConcatTransform(draw_transforms.from_target); - from_target.Scale(effect_node->surface_contents_scale.x(), - effect_node->surface_contents_scale.y()); - DCHECK(from_target.ApproximatelyEqual(*transform) || - !draw_transforms.invertible); - } + bool success = GetFromTarget(transform_id, effect_id, transform); + transform->Scale(effect_node->surface_contents_scale.x(), + effect_node->surface_contents_scale.y()); return success; } diff --git a/chromium/cc/trees/property_tree.h b/chromium/cc/trees/property_tree.h index 28dfee36bab..85a8d47a825 100644 --- a/chromium/cc/trees/property_tree.h +++ b/chromium/cc/trees/property_tree.h @@ -11,11 +11,11 @@ #include <unordered_map> #include <vector> -#include "cc/animation/element_id.h" #include "cc/base/cc_export.h" #include "cc/base/synced_property.h" #include "cc/layers/layer_sticky_position_constraint.h" #include "cc/output/filter_operations.h" +#include "cc/trees/element_id.h" #include "ui/gfx/geometry/rect_f.h" #include "ui/gfx/geometry/scroll_offset.h" #include "ui/gfx/transform.h" @@ -28,14 +28,6 @@ class TracedValue; namespace cc { -namespace proto { -class PropertyTree; -class PropertyTrees; -class ScrollNodeData; -class StickyPositionNodeData; -class TreeNode; -} // namespace proto - class CopyOutputRequest; class LayerTreeImpl; class ScrollState; @@ -46,13 +38,6 @@ struct ScrollNode; struct TransformNode; struct TransformCachedNodeData; -// ------------------------------*IMPORTANT*--------------------------------- -// Each class declared here has a corresponding proto defined in -// cc/proto/property_tree.proto. When making any changes to a class structure -// including addition/deletion/updation of a field, please also make the -// change to its proto and the ToProtobuf and FromProtobuf methods for that -// class. - typedef SyncedProperty<AdditionGroup<gfx::ScrollOffset>> SyncedScrollOffset; class PropertyTrees; @@ -106,10 +91,6 @@ class CC_EXPORT PropertyTree { int next_available_id() const { return static_cast<int>(size()); } - void ToProtobuf(proto::PropertyTree* proto) const; - void FromProtobuf(const proto::PropertyTree& proto, - std::unordered_map<int, int>* node_id_to_index_map); - void SetPropertyTrees(PropertyTrees* property_trees) { property_trees_ = property_trees; } @@ -120,6 +101,7 @@ class CC_EXPORT PropertyTree { private: std::vector<T> nodes_; + friend class TransformTree; bool needs_update_; PropertyTrees* property_trees_; }; @@ -134,8 +116,6 @@ struct StickyPositionNodeData { gfx::Vector2dF main_thread_offset; StickyPositionNodeData() : scroll_ancestor(-1) {} - void ToProtobuf(proto::StickyPositionNodeData* proto) const; - void FromProtobuf(const proto::StickyPositionNodeData& proto); }; class CC_EXPORT TransformTree final : public PropertyTree<TransformNode> { @@ -158,19 +138,6 @@ class CC_EXPORT TransformTree final : public PropertyTree<TransformNode> { void clear(); - // Computes the change of basis transform from node |source_id| to |dest_id|. - // The function returns false iff the inverse of a singular transform was - // used (and the result should, therefore, not be trusted). Transforms may - // be computed between any pair of nodes that have an ancestor/descendant - // relationship. Transforms between other pairs of nodes may only be computed - // if the following condition holds: let id1 the larger id and let id2 be the - // other id; then the nearest ancestor of node id1 whose id is smaller than - // id2 is the lowest common ancestor of the pair of nodes, and the transform - // from this lowest common ancestor to node id2 is only a 2d translation. - bool ComputeTransform(int source_id, - int dest_id, - gfx::Transform* transform) const; - void OnTransformAnimated(const gfx::Transform& transform, int id, LayerTreeImpl* layer_tree_impl); @@ -194,6 +161,8 @@ class CC_EXPORT TransformTree final : public PropertyTree<TransformNode> { TransformNode* node, TransformNode* parent_node); + void set_needs_update(bool needs_update); + // A TransformNode's source_to_parent value is used to account for the fact // that fixed-position layers are positioned by Blink wrt to their layer tree // parent (their "source"), but are parented in the transform tree by their @@ -225,7 +194,6 @@ class CC_EXPORT TransformTree final : public PropertyTree<TransformNode> { float page_scale_factor_for_root, const gfx::Transform& device_transform, gfx::PointF root_position); - float device_transform_scale_factor() const { return device_transform_scale_factor_; } @@ -249,14 +217,6 @@ class CC_EXPORT TransformTree final : public PropertyTree<TransformNode> { return nodes_affected_by_outer_viewport_bounds_delta_; } - const gfx::Transform& FromTarget(int node_id, int effect) const; - void SetFromTarget(int node_id, const gfx::Transform& transform); - - // TODO(sunxd): Remove target space transforms in cached data when we - // completely implement computing draw transforms on demand. - const gfx::Transform& ToTarget(int node_id, int effect_id) const; - void SetToTarget(int node_id, const gfx::Transform& transform); - const gfx::Transform& FromScreen(int node_id) const; void SetFromScreen(int node_id, const gfx::Transform& transform); @@ -275,10 +235,6 @@ class CC_EXPORT TransformTree final : public PropertyTree<TransformNode> { StickyPositionNodeData* StickyPositionData(int node_id); - void ToProtobuf(proto::PropertyTree* proto) const; - void FromProtobuf(const proto::PropertyTree& proto, - std::unordered_map<int, int>* node_id_to_index_map); - // Computes the combined transform between |source_id| and |dest_id|. These // two nodes must be on the same ancestor chain. void CombineTransformsBetween(int source_id, @@ -301,9 +257,6 @@ class CC_EXPORT TransformTree final : public PropertyTree<TransformNode> { void UpdateScreenSpaceTransform(TransformNode* node, TransformNode* parent_node, TransformNode* target_node); - void UpdateSurfaceContentsScale(TransformNode* node); - void UpdateTargetSpaceTransform(TransformNode* node, - TransformNode* target_node); void UpdateAnimationProperties(TransformNode* node, TransformNode* parent_node); void UndoSnapping(TransformNode* node); @@ -334,10 +287,6 @@ class CC_EXPORT ClipTree final : public PropertyTree<ClipNode> { void SetViewportClip(gfx::RectF viewport_rect); gfx::RectF ViewportClip() const; - - void ToProtobuf(proto::PropertyTree* proto) const; - void FromProtobuf(const proto::PropertyTree& proto, - std::unordered_map<int, int>* node_id_to_index_map); }; class CC_EXPORT EffectTree final : public PropertyTree<EffectNode> { @@ -382,10 +331,6 @@ class CC_EXPORT EffectTree final : public PropertyTree<EffectNode> { void ResetChangeTracking(); - void ToProtobuf(proto::PropertyTree* proto) const; - void FromProtobuf(const proto::PropertyTree& proto, - std::unordered_map<int, int>* node_id_to_index_map); - private: void UpdateOpacities(EffectNode* node, EffectNode* parent_node); void UpdateIsDrawn(EffectNode* node, EffectNode* parent_node); @@ -407,14 +352,11 @@ class CC_EXPORT ScrollTree final : public PropertyTree<ScrollNode> { ScrollTree& operator=(const ScrollTree& from); bool operator==(const ScrollTree& other) const; - void ToProtobuf(proto::PropertyTree* proto) const; - void FromProtobuf(const proto::PropertyTree& proto, - std::unordered_map<int, int>* node_id_to_index_map); - void clear(); typedef std::unordered_map<int, scoped_refptr<SyncedScrollOffset>> ScrollOffsetMap; + typedef std::unordered_map<int, bool> ScrollbarsEnabledMap; gfx::ScrollOffset MaxScrollOffset(int scroll_node_id) const; void OnScrollOffsetAnimated(int layer_id, @@ -463,6 +405,7 @@ class CC_EXPORT ScrollTree final : public PropertyTree<ScrollNode> { private: int currently_scrolling_node_id_; ScrollOffsetMap layer_id_to_scroll_offset_map_; + ScrollbarsEnabledMap layer_id_to_scrollbars_enabled_map_; SyncedScrollOffset* synced_scroll_offset(int layer_id); const SyncedScrollOffset* synced_scroll_offset(int layer_id) const; @@ -519,33 +462,48 @@ struct CombinedAnimationScale { }; struct DrawTransforms { - bool invertible; + // We compute invertibility of a draw transforms lazily. + // Might_be_invertible is true if we have not computed the inverse of either + // to_target or from_target, or to_target / from_target is invertible. + bool might_be_invertible; + // From_valid is true if the from_target is already computed directly or + // computed by inverting an invertible to_target. + bool from_valid; + // To_valid is true if to_target stores a valid result, similar to from_valid. + bool to_valid; gfx::Transform from_target; gfx::Transform to_target; DrawTransforms(gfx::Transform from, gfx::Transform to) - : invertible(true), from_target(from), to_target(to) {} + : might_be_invertible(true), + from_valid(false), + to_valid(false), + from_target(from), + to_target(to) {} bool operator==(const DrawTransforms& other) const { - return invertible == other.invertible && from_target == other.from_target && - to_target == other.to_target; + return from_valid == other.from_valid && to_valid == other.to_valid && + from_target == other.from_target && to_target == other.to_target; } }; struct DrawTransformData { int update_number; + int target_id; + DrawTransforms transforms; // TODO(sunxd): Move screen space transforms here if it can improve // performance. DrawTransformData() - : update_number(-1), transforms(gfx::Transform(), gfx::Transform()) {} + : update_number(-1), + target_id(-1), + transforms(gfx::Transform(), gfx::Transform()) {} }; struct PropertyTreesCachedData { int property_tree_update_number; std::vector<AnimationScaleData> animation_scales; - mutable std::vector<std::unordered_map<int, DrawTransformData>> - draw_transforms; + mutable std::vector<std::vector<DrawTransformData>> draw_transforms; PropertyTreesCachedData(); ~PropertyTreesCachedData(); @@ -560,9 +518,6 @@ class CC_EXPORT PropertyTrees final { bool operator==(const PropertyTrees& other) const; PropertyTrees& operator=(const PropertyTrees& from); - void ToProtobuf(proto::PropertyTrees* proto) const; - void FromProtobuf(const proto::PropertyTrees& proto); - std::unordered_map<int, int> transform_id_to_index_map; std::unordered_map<int, int> effect_id_to_index_map; std::unordered_map<int, int> clip_id_to_index_map; @@ -590,7 +545,6 @@ class CC_EXPORT PropertyTrees final { int sequence_number; bool is_main_thread; bool is_active; - bool verify_transform_tree_calculations; void clear(); @@ -624,18 +578,18 @@ class CC_EXPORT PropertyTrees final { float maximum_animation_scale, float starting_animation_scale); - // GetDrawTransforms may change the value of cached_data_. - const DrawTransforms& GetDrawTransforms(int transform_id, - int effect_id) const; + bool GetToTarget(int transform_id, + int effect_id, + gfx::Transform* to_target) const; + bool GetFromTarget(int transform_id, + int effect_id, + gfx::Transform* from_target) const; void ResetCachedData(); void UpdateCachedNumber(); gfx::Transform ToScreenSpaceTransformWithoutSurfaceContentsScale( int transform_id, int effect_id) const; - bool ComputeTransformToTarget(int transform_id, - int effect_id, - gfx::Transform* transform) const; bool ComputeTransformFromTarget(int transform_id, int effect_id, @@ -646,6 +600,11 @@ class CC_EXPORT PropertyTrees final { gfx::Vector2dF outer_viewport_container_bounds_delta_; gfx::Vector2dF inner_viewport_scroll_bounds_delta_; + // GetDrawTransforms may change the value of cached_data_. + DrawTransforms& GetDrawTransforms(int transform_id, int effect_id) const; + DrawTransformData& FetchDrawTransformsDataFromCache(int transform_id, + int effect_id) const; + PropertyTreesCachedData cached_data_; }; diff --git a/chromium/cc/trees/property_tree_builder.cc b/chromium/cc/trees/property_tree_builder.cc index 5bab434b848..6a0a0899f98 100644 --- a/chromium/cc/trees/property_tree_builder.cc +++ b/chromium/cc/trees/property_tree_builder.cc @@ -9,8 +9,6 @@ #include <map> #include <set> -#include "cc/animation/animation_host.h" -#include "cc/animation/mutable_properties.h" #include "cc/base/math_util.h" #include "cc/layers/layer.h" #include "cc/layers/layer_impl.h" @@ -20,6 +18,8 @@ #include "cc/trees/effect_node.h" #include "cc/trees/layer_tree_impl.h" #include "cc/trees/layer_tree_settings.h" +#include "cc/trees/mutable_properties.h" +#include "cc/trees/mutator_host.h" #include "cc/trees/scroll_node.h" #include "cc/trees/transform_node.h" #include "ui/gfx/geometry/point_f.h" @@ -244,56 +244,56 @@ static const gfx::Transform& Transform(LayerImpl* layer) { // Methods to query state from the AnimationHost ---------------------- template <typename LayerType> bool OpacityIsAnimating(LayerType* layer) { - return layer->GetAnimationHost()->IsAnimatingOpacityProperty( + return layer->GetMutatorHost()->IsAnimatingOpacityProperty( layer->element_id(), layer->GetElementTypeForAnimation()); } template <typename LayerType> bool HasPotentiallyRunningOpacityAnimation(LayerType* layer) { - return layer->GetAnimationHost()->HasPotentiallyRunningOpacityAnimation( + return layer->GetMutatorHost()->HasPotentiallyRunningOpacityAnimation( layer->element_id(), layer->GetElementTypeForAnimation()); } template <typename LayerType> bool FilterIsAnimating(LayerType* layer) { - return layer->GetAnimationHost()->IsAnimatingFilterProperty( + return layer->GetMutatorHost()->IsAnimatingFilterProperty( layer->element_id(), layer->GetElementTypeForAnimation()); } template <typename LayerType> bool HasPotentiallyRunningFilterAnimation(LayerType* layer) { - return layer->GetAnimationHost()->HasPotentiallyRunningFilterAnimation( + return layer->GetMutatorHost()->HasPotentiallyRunningFilterAnimation( layer->element_id(), layer->GetElementTypeForAnimation()); } template <typename LayerType> bool TransformIsAnimating(LayerType* layer) { - return layer->GetAnimationHost()->IsAnimatingTransformProperty( + return layer->GetMutatorHost()->IsAnimatingTransformProperty( layer->element_id(), layer->GetElementTypeForAnimation()); } template <typename LayerType> bool HasPotentiallyRunningTransformAnimation(LayerType* layer) { - return layer->GetAnimationHost()->HasPotentiallyRunningTransformAnimation( + return layer->GetMutatorHost()->HasPotentiallyRunningTransformAnimation( layer->element_id(), layer->GetElementTypeForAnimation()); } template <typename LayerType> bool HasOnlyTranslationTransforms(LayerType* layer) { - return layer->GetAnimationHost()->HasOnlyTranslationTransforms( + return layer->GetMutatorHost()->HasOnlyTranslationTransforms( layer->element_id(), layer->GetElementTypeForAnimation()); } template <typename LayerType> bool AnimationsPreserveAxisAlignment(LayerType* layer) { - return layer->GetAnimationHost()->AnimationsPreserveAxisAlignment( + return layer->GetMutatorHost()->AnimationsPreserveAxisAlignment( layer->element_id()); } template <typename LayerType> bool HasAnyAnimationTargetingProperty(LayerType* layer, TargetProperty::Type property) { - return layer->GetAnimationHost()->HasAnyAnimationTargetingProperty( + return layer->GetMutatorHost()->HasAnyAnimationTargetingProperty( layer->element_id(), property); } @@ -369,7 +369,7 @@ void AddClipNodeIfNeeded(const DataForRecursion<LayerType>& data_from_ancestor, // of its own, but clips from ancestor nodes don't need to be considered // when computing clip rects or visibility. has_unclipped_surface = true; - DCHECK(!parent->applies_local_clip); + DCHECK_NE(parent->clip_type, ClipNode::ClipType::APPLIES_LOCAL_CLIP); } // A surface with unclipped descendants cannot be clipped by its ancestor // clip at draw time since the unclipped descendants aren't affected by the @@ -429,7 +429,10 @@ void AddClipNodeIfNeeded(const DataForRecursion<LayerType>& data_from_ancestor, node.layer_clipping_uses_only_local_clip = false; } - node.applies_local_clip = layer_clips_subtree; + if (layer_clips_subtree) + node.clip_type = ClipNode::ClipType::APPLIES_LOCAL_CLIP; + else + node.clip_type = ClipNode::ClipType::NONE; node.resets_clip = has_unclipped_surface; node.target_is_clipped = data_for_children->target_is_clipped; node.layers_are_clipped = layers_are_clipped; @@ -490,6 +493,7 @@ bool AddTransformNodeIfNeeded( const bool is_scrollable = layer->scrollable(); const bool is_fixed = PositionConstraint(layer).is_fixed_position(); const bool is_sticky = StickyPositionConstraint(layer).is_sticky; + const bool is_snapped = layer->IsSnapped(); const bool has_significant_transform = !Transform(layer).IsIdentityOr2DTranslation(); @@ -520,7 +524,8 @@ bool AddTransformNodeIfNeeded( const bool is_at_boundary_of_3d_rendering_context = IsAtBoundaryOf3dRenderingContext(layer); - bool requires_node = is_root || is_scrollable || has_significant_transform || + DCHECK(!is_scrollable || is_snapped); + bool requires_node = is_root || is_snapped || has_significant_transform || has_any_transform_animation || has_surface || is_fixed || is_page_scale_layer || is_overscroll_elasticity_layer || has_proxied_transform_related_property || @@ -596,6 +601,7 @@ bool AddTransformNodeIfNeeded( node->id; node->scrolls = is_scrollable; + node->should_be_snapped = is_snapped; node->flattens_inherited_transform = data_for_children->should_flatten; node->sorting_context_id = layer->sorting_context_id(); @@ -638,9 +644,6 @@ bool AddTransformNodeIfNeeded( data_from_ancestor.page_scale_factor); } - if (has_surface && !is_root) - node->needs_surface_contents_scale = true; - node->source_node_id = source_index; node->post_local_scale_factor = post_local_scale_factor; if (is_root) { @@ -668,22 +671,22 @@ bool AddTransformNodeIfNeeded( if (is_fixed) { if (data_from_ancestor.affected_by_inner_viewport_bounds_delta) { - node->affected_by_inner_viewport_bounds_delta_x = + node->moved_by_inner_viewport_bounds_delta_x = PositionConstraint(layer).is_fixed_to_right_edge(); - node->affected_by_inner_viewport_bounds_delta_y = + node->moved_by_inner_viewport_bounds_delta_y = PositionConstraint(layer).is_fixed_to_bottom_edge(); - if (node->affected_by_inner_viewport_bounds_delta_x || - node->affected_by_inner_viewport_bounds_delta_y) { + if (node->moved_by_inner_viewport_bounds_delta_x || + node->moved_by_inner_viewport_bounds_delta_y) { data_for_children->property_trees->transform_tree .AddNodeAffectedByInnerViewportBoundsDelta(node->id); } } else if (data_from_ancestor.affected_by_outer_viewport_bounds_delta) { - node->affected_by_outer_viewport_bounds_delta_x = + node->moved_by_outer_viewport_bounds_delta_x = PositionConstraint(layer).is_fixed_to_right_edge(); - node->affected_by_outer_viewport_bounds_delta_y = + node->moved_by_outer_viewport_bounds_delta_y = PositionConstraint(layer).is_fixed_to_bottom_edge(); - if (node->affected_by_outer_viewport_bounds_delta_x || - node->affected_by_outer_viewport_bounds_delta_y) { + if (node->moved_by_outer_viewport_bounds_delta_x || + node->moved_by_outer_viewport_bounds_delta_y) { data_for_children->property_trees->transform_tree .AddNodeAffectedByOuterViewportBoundsDelta(node->id); } @@ -699,9 +702,26 @@ bool AddTransformNodeIfNeeded( node->id); sticky_data->constraints = StickyPositionConstraint(layer); sticky_data->scroll_ancestor = GetScrollParentId(data_from_ancestor, layer); + ScrollNode* scroll_ancestor = + data_for_children->property_trees->scroll_tree.Node( + sticky_data->scroll_ancestor); + if (sticky_data->constraints.is_anchored_right || + sticky_data->constraints.is_anchored_bottom) { + // Sticky nodes whose ancestor scroller is the inner / outer viewport + // need to have their local transform updated when the inner / outer + // viewport bounds change, but do not unconditionally move by that delta + // like fixed position nodes. + if (scroll_ancestor->is_inner_viewport_scroll_layer) { + data_for_children->property_trees->transform_tree + .AddNodeAffectedByInnerViewportBoundsDelta(node->id); + } else if (scroll_ancestor->is_outer_viewport_scroll_layer) { + data_for_children->property_trees->transform_tree + .AddNodeAffectedByOuterViewportBoundsDelta(node->id); + } + } sticky_data->main_thread_offset = layer->position().OffsetFromOrigin() - - sticky_data->constraints.scroll_container_relative_sticky_box_rect + sticky_data->constraints.parent_relative_sticky_box_offset .OffsetFromOrigin(); } @@ -1386,7 +1406,7 @@ void BuildPropertyTreesTopLevelInternal( ClipNode root_clip; root_clip.resets_clip = true; - root_clip.applies_local_clip = true; + root_clip.clip_type = ClipNode::ClipType::APPLIES_LOCAL_CLIP; root_clip.clip = gfx::RectF(viewport); root_clip.transform_id = kRootPropertyTreeNodeId; root_clip.target_transform_id = kRootPropertyTreeNodeId; @@ -1442,10 +1462,6 @@ void PropertyTreeBuilder::BuildPropertyTrees( PropertyTrees* property_trees) { property_trees->is_main_thread = true; property_trees->is_active = false; - property_trees->verify_transform_tree_calculations = - root_layer->GetLayerTree() - ->GetSettings() - .verify_transform_tree_calculations; SkColor color = root_layer->GetLayerTree()->background_color(); if (SkColorGetA(color) != 255) color = SkColorSetA(color, 255); @@ -1475,10 +1491,6 @@ void PropertyTreeBuilder::BuildPropertyTrees( PropertyTrees* property_trees) { property_trees->is_main_thread = false; property_trees->is_active = root_layer->IsActive(); - property_trees->verify_transform_tree_calculations = - root_layer->layer_tree_impl() - ->settings() - .verify_transform_tree_calculations; SkColor color = root_layer->layer_tree_impl()->background_color(); if (SkColorGetA(color) != 255) color = SkColorSetA(color, 255); diff --git a/chromium/cc/trees/property_tree_unittest.cc b/chromium/cc/trees/property_tree_unittest.cc index b2f5a78d414..66840c4ad1c 100644 --- a/chromium/cc/trees/property_tree_unittest.cc +++ b/chromium/cc/trees/property_tree_unittest.cc @@ -5,7 +5,6 @@ #include "cc/trees/property_tree.h" #include "cc/input/main_thread_scrolling_reason.h" -#include "cc/proto/property_tree.pb.h" #include "cc/test/geometry_test_utils.h" #include "cc/trees/clip_node.h" #include "cc/trees/draw_property_utils.h" @@ -17,420 +16,37 @@ namespace cc { namespace { -TEST(PropertyTreeSerializationTest, TransformNodeSerialization) { - TransformNode original; - original.id = 3; - original.parent_id = 2; - original.owner_id = 4; - original.pre_local.Translate3d(1.f, 2.f, 3.f); - original.local.Translate3d(3.f, 1.f, 5.f); - original.post_local.Translate3d(1.f, 8.f, 3.f); - original.to_parent.Translate3d(3.2f, 2.f, 3.f); - original.source_node_id = 5; - original.needs_local_transform_update = false; - original.is_invertible = false; - original.ancestors_are_invertible = false; - original.has_potential_animation = false; - original.to_screen_is_potentially_animated = false; - original.has_only_translation_animations = false; - original.flattens_inherited_transform = false; - original.node_and_ancestors_are_flat = false; - original.node_and_ancestors_have_only_integer_translation = false; - original.scrolls = false; - original.needs_surface_contents_scale = false; - original.affected_by_inner_viewport_bounds_delta_x = false; - original.affected_by_inner_viewport_bounds_delta_y = false; - original.affected_by_outer_viewport_bounds_delta_x = false; - original.affected_by_outer_viewport_bounds_delta_y = false; - original.in_subtree_of_page_scale_layer = false; - original.post_local_scale_factor = 0.5f; - original.surface_contents_scale = gfx::Vector2dF(0.5f, 0.5f); - original.scroll_offset = gfx::ScrollOffset(1.5f, 1.5f); - original.scroll_snap = gfx::Vector2dF(0.4f, 0.4f); - original.source_offset = gfx::Vector2dF(2.5f, 2.4f); - original.source_to_parent = gfx::Vector2dF(3.2f, 3.2f); - - proto::TreeNode proto; - original.ToProtobuf(&proto); - TransformNode result; - result.FromProtobuf(proto); - - EXPECT_EQ(original, result); -} - -TEST(PropertyTreeSerializationTest, TransformTreeSerialization) { +TEST(PropertyTreeTest, ComputeTransformRoot) { PropertyTrees property_trees; - TransformTree& original = property_trees.transform_tree; - TransformNode& root = *original.Node(0); - root.id = 0; - root.owner_id = 1; - original.SetTargetId(root.id, 3); - original.SetContentTargetId(root.id, 4); - TransformNode second; - second.owner_id = 2; - second.local.Translate3d(2.f, 2.f, 0.f); - second.source_node_id = 0; - second.id = original.Insert(second, 0); - original.SetTargetId(second.id, 0); - TransformNode third; - third.owner_id = 3; - third.scrolls = true; - third.source_node_id = 1; - third.id = original.Insert(third, 1); - original.SetTargetId(third.id, 0); - - original.set_needs_update(true); - - original.set_page_scale_factor(0.5f); - original.set_device_scale_factor(0.6f); - gfx::Transform transform = - gfx::Transform(1.05f, 2.15f, 3.14f, 4.13f, 5.12f, 6.11f, 7.1f, 8.9f, 9.8f, - 10.7f, 11.6f, 12.5f, 13.4f, 14.3f, 15.2f, 16.1f); - original.SetRootTransformsAndScales(0.6f, 1.f, transform, gfx::PointF()); - original.AddNodeAffectedByInnerViewportBoundsDelta(0); - original.AddNodeAffectedByOuterViewportBoundsDelta(1); - - proto::PropertyTree proto; - original.ToProtobuf(&proto); - TransformTree result; - std::unordered_map<int, int> transform_id_to_index_map; - result.FromProtobuf(proto, &transform_id_to_index_map); - - EXPECT_EQ(transform_id_to_index_map[1], 0); - EXPECT_EQ(transform_id_to_index_map[2], 1); - EXPECT_EQ(transform_id_to_index_map[3], 2); - EXPECT_EQ(original, result); -} - -TEST(PropertyTreeSerializationTest, ClipNodeSerialization) { - ClipNode original; - original.id = 3; - original.parent_id = 2; - original.owner_id = 4; - original.clip = gfx::RectF(0.5f, 0.5f); - original.combined_clip_in_target_space = gfx::RectF(0.6f, 0.6f); - original.clip_in_target_space = gfx::RectF(0.7f, 0.7f); - original.transform_id = 2; - original.target_transform_id = 3; - original.target_effect_id = 4; - original.applies_local_clip = false; - original.layer_clipping_uses_only_local_clip = false; - original.target_is_clipped = false; - original.layers_are_clipped = false; - original.layers_are_clipped_when_surfaces_disabled = false; - original.resets_clip = false; - - proto::TreeNode proto; - original.ToProtobuf(&proto); - ClipNode result; - result.FromProtobuf(proto); - - EXPECT_EQ(original, result); -} - -TEST(PropertyTreeSerializationTest, ClipTreeSerialization) { - ClipTree original; - ClipNode& root = *original.Node(0); - root.owner_id = 1; - root.transform_id = 2; - root.target_transform_id = 1; - root.target_effect_id = 1; - ClipNode second; - second.owner_id = 2; - second.transform_id = 4; - second.applies_local_clip = true; - ClipNode third; - third.owner_id = 3; - third.target_transform_id = 3; - third.target_effect_id = 2; - third.target_is_clipped = false; - - original.Insert(second, 0); - original.Insert(third, 1); - original.set_needs_update(true); - - proto::PropertyTree proto; - original.ToProtobuf(&proto); - ClipTree result; - std::unordered_map<int, int> clip_id_to_index_map; - result.FromProtobuf(proto, &clip_id_to_index_map); - - EXPECT_EQ(clip_id_to_index_map[1], 0); - EXPECT_EQ(clip_id_to_index_map[2], 1); - EXPECT_EQ(clip_id_to_index_map[3], 2); - EXPECT_EQ(original, result); -} - -TEST(PropertyTreeSerializationTest, EffectNodeSerialization) { - EffectNode original; - original.id = 3; - original.parent_id = 2; - original.owner_id = 4; - original.opacity = 0.5f; - original.screen_space_opacity = 0.6f; - original.has_render_surface = false; - original.transform_id = 2; - original.clip_id = 3; - original.mask_layer_id = 6; - original.surface_contents_scale = gfx::Vector2dF(0.5f, 0.5f); - - proto::TreeNode proto; - original.ToProtobuf(&proto); - EffectNode result; - result.FromProtobuf(proto); - - EXPECT_EQ(original, result); -} - -TEST(PropertyTreeSerializationTest, EffectTreeSerialization) { - EffectTree original; - EffectNode& root = *original.Node(0); - root.owner_id = 5; - root.transform_id = 2; - root.clip_id = 1; - EffectNode second; - second.owner_id = 6; - second.transform_id = 4; - second.opacity = true; - second.mask_layer_id = 32; - EffectNode third; - third.owner_id = 7; - third.clip_id = 3; - third.has_render_surface = false; - - original.Insert(second, 0); - original.Insert(third, 1); - original.AddMaskLayerId(32); - original.set_needs_update(true); - - proto::PropertyTree proto; - original.ToProtobuf(&proto); - EffectTree result; - std::unordered_map<int, int> effect_id_to_index_map; - result.FromProtobuf(proto, &effect_id_to_index_map); - - EXPECT_EQ(effect_id_to_index_map[5], 0); - EXPECT_EQ(effect_id_to_index_map[6], 1); - EXPECT_EQ(effect_id_to_index_map[7], 2); - EXPECT_EQ(original, result); -} - -TEST(PropertyTreeSerializationTest, ScrollNodeSerialization) { - ScrollNode original; - original.id = 3; - original.parent_id = 2; - original.owner_id = 4; - original.scrollable = true; - original.main_thread_scrolling_reasons = - MainThreadScrollingReason::kScrollbarScrolling; - original.contains_non_fast_scrollable_region = false; - original.scroll_clip_layer_bounds = gfx::Size(10, 10); - original.bounds = gfx::Size(15, 15); - original.max_scroll_offset_affected_by_page_scale = true; - original.is_inner_viewport_scroll_layer = true; - original.is_outer_viewport_scroll_layer = false; - - proto::TreeNode proto; - original.ToProtobuf(&proto); - ScrollNode result; - result.FromProtobuf(proto); - - EXPECT_EQ(original, result); -} - -TEST(PropertyTreeSerializationTest, ScrollTreeSerialization) { - PropertyTrees property_trees; - property_trees.is_main_thread = true; - ScrollTree& original = property_trees.scroll_tree; - ScrollNode second; - second.owner_id = 10; - second.scrollable = true; - second.bounds = gfx::Size(15, 15); - ScrollNode third; - third.owner_id = 20; - third.contains_non_fast_scrollable_region = true; - - original.Insert(second, 0); - original.Insert(third, 1); - - original.set_currently_scrolling_node(1); - original.SetScrollOffset(1, gfx::ScrollOffset(1, 2)); - - proto::PropertyTree proto; - original.ToProtobuf(&proto); - ScrollTree result; - std::unordered_map<int, int> scroll_id_to_index_map; - result.FromProtobuf(proto, &scroll_id_to_index_map); - - EXPECT_EQ(original, result); - EXPECT_EQ(scroll_id_to_index_map[10], 1); - EXPECT_EQ(scroll_id_to_index_map[20], 2); - - original.clear(); - original.set_currently_scrolling_node(0); - original.SetScrollOffset(2, gfx::ScrollOffset(1, 2)); - - proto::PropertyTree proto2; - original.ToProtobuf(&proto2); - result = ScrollTree(); - scroll_id_to_index_map.clear(); - result.FromProtobuf(proto2, &scroll_id_to_index_map); - - EXPECT_EQ(original, result); -} - -TEST(PropertyTreeSerializationTest, PropertyTrees) { - PropertyTrees original; - TransformNode transform_node1 = TransformNode(); - transform_node1.owner_id = 10; - transform_node1.id = original.transform_tree.Insert(transform_node1, 0); - TransformNode transform_node2 = TransformNode(); - transform_node2.owner_id = 20; - transform_node2.id = original.transform_tree.Insert(transform_node2, 1); - original.transform_id_to_index_map[10] = 1; - original.transform_id_to_index_map[20] = 2; - - ClipNode clip_node1 = ClipNode(); - clip_node1.owner_id = 10; - clip_node1.id = original.clip_tree.Insert(clip_node1, 0); - ClipNode clip_node2 = ClipNode(); - clip_node2.owner_id = 22; - clip_node2.id = original.clip_tree.Insert(clip_node2, 1); - original.clip_id_to_index_map[10] = 1; - original.clip_id_to_index_map[22] = 2; - - EffectNode effect_node1 = EffectNode(); - effect_node1.owner_id = 11; - effect_node1.id = original.effect_tree.Insert(effect_node1, 0); - EffectNode effect_node2 = EffectNode(); - effect_node2.owner_id = 23; - effect_node2.id = original.effect_tree.Insert(effect_node2, 1); - original.effect_id_to_index_map[11] = 1; - original.effect_id_to_index_map[23] = 2; - - ScrollNode scroll_node1 = ScrollNode(); - scroll_node1.owner_id = 10; - scroll_node1.id = original.scroll_tree.Insert(scroll_node1, 0); - ScrollNode scroll_node2 = ScrollNode(); - scroll_node2.owner_id = 20; - scroll_node2.id = original.scroll_tree.Insert(scroll_node2, 1); - original.scroll_id_to_index_map[10] = 1; - original.scroll_id_to_index_map[20] = 2; - - original.needs_rebuild = false; - original.non_root_surfaces_enabled = false; - original.sequence_number = 3; - - proto::PropertyTrees proto; - original.ToProtobuf(&proto); - PropertyTrees result; - result.FromProtobuf(proto); - - EXPECT_EQ(original, result); -} - -class PropertyTreeTest : public testing::Test { - public: - PropertyTreeTest() : test_serialization_(false) {} - - protected: - void RunTest(bool test_serialization) { - test_serialization_ = test_serialization; - StartTest(); - } - - virtual void StartTest() = 0; - - void SetupTransformTreeForTest(TransformTree* transform_tree) { - if (!test_serialization_) - return; - - TransformTree new_tree; - proto::PropertyTree proto; - transform_tree->ToProtobuf(&proto); - std::unordered_map<int, int> transform_id_to_index_map; - new_tree.FromProtobuf(proto, &transform_id_to_index_map); - EXPECT_EQ(*transform_tree, new_tree); - - PropertyTrees* property_trees = transform_tree->property_trees(); - *transform_tree = new_tree; - transform_tree->SetPropertyTrees(property_trees); - } - - void SetupEffectTreeForTest(EffectTree* effect_tree) { - if (!test_serialization_) - return; - - EffectTree new_tree; - proto::PropertyTree proto; - effect_tree->ToProtobuf(&proto); - std::unordered_map<int, int> effect_id_to_index_map; - new_tree.FromProtobuf(proto, &effect_id_to_index_map); - - EXPECT_EQ(*effect_tree, new_tree); - *effect_tree = new_tree; - } - - private: - bool test_serialization_; -}; - -#define DIRECT_PROPERTY_TREE_TEST_F(TEST_FIXTURE_NAME) \ - TEST_F(TEST_FIXTURE_NAME, RunDirect) { RunTest(false); } - -#define SERIALIZED_PROPERTY_TREE_TEST_F(TEST_FIXTURE_NAME) \ - TEST_F(TEST_FIXTURE_NAME, RunSerialized) { RunTest(true); } - -#define DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F(TEST_FIXTURE_NAME) \ - DIRECT_PROPERTY_TREE_TEST_F(TEST_FIXTURE_NAME); \ - SERIALIZED_PROPERTY_TREE_TEST_F(TEST_FIXTURE_NAME) - -class PropertyTreeTestComputeTransformRoot : public PropertyTreeTest { - protected: - void StartTest() override { - PropertyTrees property_trees; - TransformTree& tree = property_trees.transform_tree; - TransformNode& root = *tree.Node(0); - root.id = 0; - root.local.Translate(2, 2); - tree.SetTargetId(root.id, 0); - SetupTransformTreeForTest(&tree); - tree.UpdateTransforms(0); - - gfx::Transform expected; - gfx::Transform transform; - bool success = tree.ComputeTransform(0, 0, &transform); - EXPECT_TRUE(success); - EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); - - transform.MakeIdentity(); - expected.Translate(2, 2); - success = tree.ComputeTransform(0, -1, &transform); - EXPECT_TRUE(success); - EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); - - transform.MakeIdentity(); - expected.MakeIdentity(); - expected.Translate(-2, -2); - success = tree.ComputeTransform(-1, 0, &transform); - EXPECT_TRUE(success); - EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); + TransformTree& tree = property_trees.transform_tree; + TransformNode contents_root; + contents_root.local.Translate(2, 2); + contents_root.source_node_id = 0; + contents_root.id = tree.Insert(contents_root, 0); + tree.SetTargetId(contents_root.id, 0); + tree.UpdateTransforms(1); + + gfx::Transform expected; + gfx::Transform transform; + expected.Translate(2, 2); + tree.CombineTransformsBetween(1, 0, &transform); + EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); + + transform.MakeIdentity(); + expected.MakeIdentity(); + expected.Translate(-2, -2); + bool success = tree.CombineInversesBetween(0, 1, &transform); + EXPECT_TRUE(success); + EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); } -}; - -DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( - PropertyTreeTestComputeTransformRoot); -class PropertyTreeTestSetNeedsUpdate : public PropertyTreeTest { - protected: - void StartTest() override { + TEST(PropertyTreeTest, SetNeedsUpdate) { PropertyTrees property_trees; TransformTree& tree = property_trees.transform_tree; TransformNode contents_root; contents_root.source_node_id = 0; contents_root.id = tree.Insert(contents_root, 0); tree.SetTargetId(contents_root.id, 0); - SetupTransformTreeForTest(&tree); EXPECT_FALSE(tree.needs_update()); tree.SetRootTransformsAndScales(0.6f, 1.f, gfx::Transform(), gfx::PointF()); @@ -439,114 +55,94 @@ class PropertyTreeTestSetNeedsUpdate : public PropertyTreeTest { tree.SetRootTransformsAndScales(0.6f, 1.f, gfx::Transform(), gfx::PointF()); EXPECT_FALSE(tree.needs_update()); } -}; -DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F(PropertyTreeTestSetNeedsUpdate); - -class PropertyTreeTestComputeTransformChild : public PropertyTreeTest { - protected: - void StartTest() override { + TEST(PropertyTreeTest, ComputeTransformChild) { PropertyTrees property_trees; TransformTree& tree = property_trees.transform_tree; - TransformNode& root = *tree.Node(0); - root.local.Translate(2, 2); - tree.SetTargetId(root.id, 0); - tree.UpdateTransforms(0); + TransformNode contents_root; + contents_root.local.Translate(2, 2); + contents_root.source_node_id = 0; + contents_root.id = tree.Insert(contents_root, 0); + tree.SetTargetId(contents_root.id, 0); + tree.UpdateTransforms(contents_root.id); TransformNode child; child.local.Translate(3, 3); - child.source_node_id = 0; - child.id = tree.Insert(child, 0); + child.source_node_id = 1; + child.id = tree.Insert(child, contents_root.id); tree.SetTargetId(child.id, 0); - SetupTransformTreeForTest(&tree); - tree.UpdateTransforms(1); + tree.UpdateTransforms(child.id); gfx::Transform expected; gfx::Transform transform; expected.Translate(3, 3); - bool success = tree.ComputeTransform(1, 0, &transform); - EXPECT_TRUE(success); + tree.CombineTransformsBetween(2, 1, &transform); EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); transform.MakeIdentity(); expected.MakeIdentity(); expected.Translate(-3, -3); - success = tree.ComputeTransform(0, 1, &transform); + bool success = tree.CombineInversesBetween(1, 2, &transform); EXPECT_TRUE(success); EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); transform.MakeIdentity(); expected.MakeIdentity(); expected.Translate(5, 5); - success = tree.ComputeTransform(1, -1, &transform); - EXPECT_TRUE(success); + tree.CombineTransformsBetween(2, 0, &transform); EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); transform.MakeIdentity(); expected.MakeIdentity(); expected.Translate(-5, -5); - success = tree.ComputeTransform(-1, 1, &transform); + success = tree.CombineInversesBetween(0, 2, &transform); EXPECT_TRUE(success); EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); } -}; -DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( - PropertyTreeTestComputeTransformChild); - -class PropertyTreeTestComputeTransformSibling : public PropertyTreeTest { - protected: - void StartTest() override { + TEST(PropertyTreeTest, ComputeTransformSibling) { PropertyTrees property_trees; TransformTree& tree = property_trees.transform_tree; - TransformNode& root = *tree.Node(0); - root.local.Translate(2, 2); - tree.SetTargetId(root.id, 0); - tree.UpdateTransforms(0); + TransformNode contents_root; + contents_root.source_node_id = 0; + contents_root.local.Translate(2, 2); + contents_root.id = tree.Insert(contents_root, 0); + tree.SetTargetId(contents_root.id, 0); + tree.UpdateTransforms(1); TransformNode child; child.local.Translate(3, 3); - child.source_node_id = 0; - child.id = tree.Insert(child, 0); + child.source_node_id = 1; + child.id = tree.Insert(child, 1); tree.SetTargetId(child.id, 0); TransformNode sibling; sibling.local.Translate(7, 7); - sibling.source_node_id = 0; - sibling.id = tree.Insert(sibling, 0); + sibling.source_node_id = 1; + sibling.id = tree.Insert(sibling, 1); tree.SetTargetId(sibling.id, 0); - SetupTransformTreeForTest(&tree); - - tree.UpdateTransforms(1); tree.UpdateTransforms(2); + tree.UpdateTransforms(3); gfx::Transform expected; gfx::Transform transform; expected.Translate(4, 4); - bool success = tree.ComputeTransform(2, 1, &transform); - EXPECT_TRUE(success); + tree.CombineTransformsBetween(3, 2, &transform); EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); transform.MakeIdentity(); expected.MakeIdentity(); expected.Translate(-4, -4); - success = tree.ComputeTransform(1, 2, &transform); + bool success = tree.CombineInversesBetween(2, 3, &transform); EXPECT_TRUE(success); EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); } -}; -DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( - PropertyTreeTestComputeTransformSibling); - -class PropertyTreeTestComputeTransformSiblingSingularAncestor - : public PropertyTreeTest { - protected: - void StartTest() override { + TEST(PropertyTreeTest, ComputeTransformSiblingSingularAncestor) { // In this test, we have the following tree: // root // + singular @@ -558,60 +154,52 @@ class PropertyTreeTestComputeTransformSiblingSingularAncestor // transforms between these nodes. PropertyTrees property_trees; TransformTree& tree = property_trees.transform_tree; - TransformNode& root = *tree.Node(0); - root.local.Translate(2, 2); - tree.SetTargetId(root.id, 0); - tree.UpdateTransforms(0); + TransformNode contents_root; + contents_root.local.Translate(2, 2); + contents_root.source_node_id = 0; + contents_root.id = tree.Insert(contents_root, 0); + tree.SetTargetId(contents_root.id, 0); + tree.UpdateTransforms(1); TransformNode singular; singular.local.matrix().set(2, 2, 0.0); - singular.source_node_id = 0; - singular.id = tree.Insert(singular, 0); + singular.source_node_id = 1; + singular.id = tree.Insert(singular, 1); tree.SetTargetId(singular.id, 0); TransformNode child; child.local.Translate(3, 3); - child.source_node_id = 1; - child.id = tree.Insert(child, 1); + child.source_node_id = 2; + child.id = tree.Insert(child, 2); tree.SetTargetId(child.id, 0); TransformNode sibling; sibling.local.Translate(7, 7); - sibling.source_node_id = 1; - sibling.id = tree.Insert(sibling, 1); + sibling.source_node_id = 2; + sibling.id = tree.Insert(sibling, 2); tree.SetTargetId(sibling.id, 0); - SetupTransformTreeForTest(&tree); - - tree.UpdateTransforms(1); tree.UpdateTransforms(2); tree.UpdateTransforms(3); + tree.UpdateTransforms(4); gfx::Transform expected; gfx::Transform transform; expected.Translate(4, 4); - bool success = tree.ComputeTransform(3, 2, &transform); - EXPECT_TRUE(success); + tree.CombineTransformsBetween(4, 3, &transform); EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); transform.MakeIdentity(); expected.MakeIdentity(); expected.Translate(-4, -4); - success = tree.ComputeTransform(2, 3, &transform); + bool success = tree.CombineInversesBetween(3, 4, &transform); EXPECT_TRUE(success); EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); } -}; -DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( - PropertyTreeTestComputeTransformSiblingSingularAncestor); - -class PropertyTreeTestTransformsWithFlattening : public PropertyTreeTest { - protected: - void StartTest() override { + TEST(PropertyTreeTest, TransformsWithFlattening) { PropertyTrees property_trees; - property_trees.verify_transform_tree_calculations = true; TransformTree& tree = property_trees.transform_tree; EffectTree& effect_tree = property_trees.effect_tree; @@ -634,7 +222,6 @@ class PropertyTreeTestTransformsWithFlattening : public PropertyTreeTest { effect_tree.Node(effect_parent)->has_render_surface = true; effect_tree.Node(effect_parent)->surface_contents_scale = gfx::Vector2dF(1.f, 1.f); - tree.Node(parent)->needs_surface_contents_scale = true; tree.SetTargetId(parent, grand_parent); tree.SetContentTargetId(parent, parent); tree.Node(parent)->source_node_id = grand_parent; @@ -655,22 +242,22 @@ class PropertyTreeTestTransformsWithFlattening : public PropertyTreeTest { tree.Node(grand_child)->local = rotation_about_x; tree.set_needs_update(true); - SetupTransformTreeForTest(&tree); draw_property_utils::ComputeTransforms(&tree); property_trees.ResetCachedData(); gfx::Transform flattened_rotation_about_x = rotation_about_x; flattened_rotation_about_x.FlattenTo2d(); - EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x, - tree.ToTarget(child, effect_parent)); + gfx::Transform to_target; + property_trees.GetToTarget(child, effect_parent, &to_target); + EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x, to_target); EXPECT_TRANSFORMATION_MATRIX_EQ( flattened_rotation_about_x * rotation_about_x, tree.ToScreen(child)); + property_trees.GetToTarget(grand_child, effect_parent, &to_target); EXPECT_TRANSFORMATION_MATRIX_EQ( - flattened_rotation_about_x * rotation_about_x, - tree.ToTarget(grand_child, effect_parent)); + flattened_rotation_about_x * rotation_about_x, to_target); EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_x * flattened_rotation_about_x * @@ -678,51 +265,44 @@ class PropertyTreeTestTransformsWithFlattening : public PropertyTreeTest { tree.ToScreen(grand_child)); gfx::Transform grand_child_to_child; - bool success = - tree.ComputeTransform(grand_child, child, &grand_child_to_child); - EXPECT_TRUE(success); + tree.CombineTransformsBetween(grand_child, child, &grand_child_to_child); EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x, grand_child_to_child); // Remove flattening at grand_child, and recompute transforms. tree.Node(grand_child)->flattens_inherited_transform = false; tree.set_needs_update(true); - SetupTransformTreeForTest(&tree); draw_property_utils::ComputeTransforms(&tree); + property_trees.GetToTarget(grand_child, effect_parent, &to_target); EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x * rotation_about_x, - tree.ToTarget(grand_child, effect_parent)); + to_target); EXPECT_TRANSFORMATION_MATRIX_EQ( flattened_rotation_about_x * rotation_about_x * rotation_about_x, tree.ToScreen(grand_child)); - success = tree.ComputeTransform(grand_child, child, &grand_child_to_child); - EXPECT_TRUE(success); + grand_child_to_child.MakeIdentity(); + tree.CombineTransformsBetween(grand_child, child, &grand_child_to_child); EXPECT_TRANSFORMATION_MATRIX_EQ(rotation_about_x, grand_child_to_child); } -}; - -DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( - PropertyTreeTestTransformsWithFlattening); -class PropertyTreeTestMultiplicationOrder : public PropertyTreeTest { - protected: - void StartTest() override { + TEST(PropertyTreeTest, MultiplicationOrder) { PropertyTrees property_trees; TransformTree& tree = property_trees.transform_tree; - TransformNode& root = *tree.Node(0); - root.local.Translate(2, 2); - tree.SetTargetId(root.id, 0); - tree.UpdateTransforms(0); + TransformNode contents_root; + contents_root.local.Translate(2, 2); + contents_root.source_node_id = 0; + contents_root.id = tree.Insert(contents_root, 0); + tree.SetTargetId(contents_root.id, 0); + tree.UpdateTransforms(1); TransformNode child; child.local.Scale(2, 2); - child.source_node_id = 0; - child.id = tree.Insert(child, 0); + child.source_node_id = 1; + child.id = tree.Insert(child, 1); tree.SetTargetId(child.id, 0); - SetupTransformTreeForTest(&tree); - tree.UpdateTransforms(1); + tree.UpdateTransforms(2); gfx::Transform expected; expected.Translate(2, 2); @@ -731,39 +311,33 @@ class PropertyTreeTestMultiplicationOrder : public PropertyTreeTest { gfx::Transform transform; gfx::Transform inverse; - bool success = tree.ComputeTransform(1, -1, &transform); - EXPECT_TRUE(success); + tree.CombineTransformsBetween(2, 0, &transform); EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); - success = tree.ComputeTransform(-1, 1, &inverse); + bool success = tree.CombineInversesBetween(0, 2, &inverse); EXPECT_TRUE(success); transform = transform * inverse; expected.MakeIdentity(); EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); } -}; -DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F(PropertyTreeTestMultiplicationOrder); - -class PropertyTreeTestComputeTransformWithUninvertibleTransform - : public PropertyTreeTest { - protected: - void StartTest() override { + TEST(PropertyTreeTest, ComputeTransformWithUninvertibleTransform) { PropertyTrees property_trees; TransformTree& tree = property_trees.transform_tree; - TransformNode& root = *tree.Node(0); - tree.SetTargetId(root.id, 0); - tree.UpdateTransforms(0); + TransformNode contents_root; + contents_root.source_node_id = 0; + contents_root.id = tree.Insert(contents_root, 0); + tree.SetTargetId(contents_root.id, 0); + tree.UpdateTransforms(1); TransformNode child; child.local.Scale(0, 0); - child.source_node_id = 0; - child.id = tree.Insert(child, 0); + child.source_node_id = 1; + child.id = tree.Insert(child, 1); tree.SetTargetId(child.id, 0); - SetupTransformTreeForTest(&tree); - tree.UpdateTransforms(1); + tree.UpdateTransforms(2); gfx::Transform expected; expected.Scale(0, 0); @@ -771,175 +345,28 @@ class PropertyTreeTestComputeTransformWithUninvertibleTransform gfx::Transform transform; gfx::Transform inverse; - bool success = tree.ComputeTransform(1, 0, &transform); - EXPECT_TRUE(success); + tree.CombineTransformsBetween(2, 1, &transform); EXPECT_TRANSFORMATION_MATRIX_EQ(expected, transform); // To compute this would require inverting the 0 matrix, so we cannot // succeed. - success = tree.ComputeTransform(0, 1, &inverse); + bool success = tree.CombineInversesBetween(1, 2, &inverse); EXPECT_FALSE(success); } -}; - -DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( - PropertyTreeTestComputeTransformWithUninvertibleTransform); - -class PropertyTreeTestComputeTransformWithSurfaceContentsScale - : public PropertyTreeTest { - protected: - void StartTest() override { - PropertyTrees property_trees; - TransformTree& tree = property_trees.transform_tree; - TransformNode& root = *tree.Node(0); - root.id = 0; - tree.SetTargetId(root.id, 0); - tree.UpdateTransforms(0); - - TransformNode grand_parent; - grand_parent.local.Scale(2.f, 2.f); - grand_parent.source_node_id = 0; - grand_parent.needs_surface_contents_scale = true; - int grand_parent_id = tree.Insert(grand_parent, 0); - tree.SetTargetId(grand_parent_id, 0); - tree.UpdateTransforms(grand_parent_id); - - TransformNode parent; - parent.local.Translate(15.f, 15.f); - parent.source_node_id = grand_parent_id; - int parent_id = tree.Insert(parent, grand_parent_id); - tree.SetTargetId(parent_id, grand_parent_id); - tree.UpdateTransforms(parent_id); - - TransformNode child; - child.local.Scale(3.f, 3.f); - child.source_node_id = parent_id; - int child_id = tree.Insert(child, parent_id); - tree.SetTargetId(child_id, grand_parent_id); - tree.UpdateTransforms(child_id); - - TransformNode grand_child; - grand_child.local.Scale(5.f, 5.f); - grand_child.source_node_id = child_id; - grand_child.needs_surface_contents_scale = true; - int grand_child_id = tree.Insert(grand_child, child_id); - tree.SetTargetId(grand_child_id, grand_parent_id); - SetupTransformTreeForTest(&tree); - tree.UpdateTransforms(grand_child_id); - - EXPECT_EQ(gfx::Vector2dF(2.f, 2.f), - tree.Node(grand_parent_id)->surface_contents_scale); - EXPECT_EQ(gfx::Vector2dF(30.f, 30.f), - tree.Node(grand_child_id)->surface_contents_scale); - - // Compute transform from grand_parent to grand_child. - gfx::Transform expected_transform_without_surface_contents_scale; - expected_transform_without_surface_contents_scale.Scale(1.f / 15.f, - 1.f / 15.f); - expected_transform_without_surface_contents_scale.Translate(-15.f, -15.f); - - gfx::Transform expected_transform_with_dest_surface_contents_scale; - expected_transform_with_dest_surface_contents_scale.Scale(30.f, 30.f); - expected_transform_with_dest_surface_contents_scale.Scale(1.f / 15.f, - 1.f / 15.f); - expected_transform_with_dest_surface_contents_scale.Translate(-15.f, -15.f); - - gfx::Transform expected_transform_with_source_surface_contents_scale; - expected_transform_with_source_surface_contents_scale.Scale(1.f / 15.f, - 1.f / 15.f); - expected_transform_with_source_surface_contents_scale.Translate(-15.f, - -15.f); - expected_transform_with_source_surface_contents_scale.Scale(0.5f, 0.5f); - - gfx::Transform transform; - bool success = - tree.ComputeTransform(grand_parent_id, grand_child_id, &transform); - EXPECT_TRUE(success); - EXPECT_TRANSFORMATION_MATRIX_EQ( - expected_transform_without_surface_contents_scale, transform); - - success = - tree.ComputeTransform(grand_parent_id, grand_child_id, &transform); - const TransformNode* grand_child_node = tree.Node(grand_child_id); - transform.matrix().postScale(grand_child_node->surface_contents_scale.x(), - grand_child_node->surface_contents_scale.y(), - 1.f); - EXPECT_TRUE(success); - EXPECT_TRANSFORMATION_MATRIX_EQ( - expected_transform_with_dest_surface_contents_scale, transform); - - success = - tree.ComputeTransform(grand_parent_id, grand_child_id, &transform); - const TransformNode* grand_parent_node = tree.Node(grand_parent_id); - EXPECT_NE(grand_parent_node->surface_contents_scale.x(), 0.f); - EXPECT_NE(grand_parent_node->surface_contents_scale.y(), 0.f); - transform.Scale(1.0 / grand_parent_node->surface_contents_scale.x(), - 1.0 / grand_parent_node->surface_contents_scale.y()); - EXPECT_TRUE(success); - EXPECT_TRANSFORMATION_MATRIX_EQ( - expected_transform_with_source_surface_contents_scale, transform); - - // Now compute transform from grand_child to grand_parent. - expected_transform_without_surface_contents_scale.MakeIdentity(); - expected_transform_without_surface_contents_scale.Translate(15.f, 15.f); - expected_transform_without_surface_contents_scale.Scale(15.f, 15.f); - - expected_transform_with_dest_surface_contents_scale.MakeIdentity(); - expected_transform_with_dest_surface_contents_scale.Scale(2.f, 2.f); - expected_transform_with_dest_surface_contents_scale.Translate(15.f, 15.f); - expected_transform_with_dest_surface_contents_scale.Scale(15.f, 15.f); - - expected_transform_with_source_surface_contents_scale.MakeIdentity(); - expected_transform_with_source_surface_contents_scale.Translate(15.f, 15.f); - expected_transform_with_source_surface_contents_scale.Scale(15.f, 15.f); - expected_transform_with_source_surface_contents_scale.Scale(1.f / 30.f, - 1.f / 30.f); - - success = - tree.ComputeTransform(grand_child_id, grand_parent_id, &transform); - EXPECT_TRUE(success); - EXPECT_TRANSFORMATION_MATRIX_EQ( - expected_transform_without_surface_contents_scale, transform); - - success = - tree.ComputeTransform(grand_child_id, grand_parent_id, &transform); - transform.matrix().postScale(grand_parent_node->surface_contents_scale.x(), - grand_parent_node->surface_contents_scale.y(), - 1.f); - EXPECT_TRUE(success); - EXPECT_TRANSFORMATION_MATRIX_EQ( - expected_transform_with_dest_surface_contents_scale, transform); - - success = - tree.ComputeTransform(grand_child_id, grand_parent_id, &transform); - EXPECT_NE(grand_child_node->surface_contents_scale.x(), 0.f); - EXPECT_NE(grand_child_node->surface_contents_scale.y(), 0.f); - transform.Scale(1.0 / grand_child_node->surface_contents_scale.x(), - 1.0 / grand_child_node->surface_contents_scale.y()); - EXPECT_TRUE(success); - EXPECT_TRANSFORMATION_MATRIX_EQ( - expected_transform_with_source_surface_contents_scale, transform); - } -}; - -DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( - PropertyTreeTestComputeTransformWithSurfaceContentsScale); -class PropertyTreeTestComputeTransformToTargetWithZeroSurfaceContentsScale - : public PropertyTreeTest { - protected: - void StartTest() override { + TEST(PropertyTreeTest, ComputeTransformToTargetWithZeroSurfaceContentsScale) { PropertyTrees property_trees; TransformTree& tree = property_trees.transform_tree; - TransformNode& root = *tree.Node(0); - tree.SetTargetId(root.id, 0); - tree.UpdateTransforms(0); + TransformNode contents_root; + contents_root.source_node_id = 0; + contents_root.id = tree.Insert(contents_root, 0); + tree.SetTargetId(contents_root.id, 0); + tree.UpdateTransforms(1); TransformNode grand_parent; grand_parent.local.Scale(2.f, 0.f); - grand_parent.source_node_id = 0; - grand_parent.needs_surface_contents_scale = true; - int grand_parent_id = tree.Insert(grand_parent, 0); + grand_parent.source_node_id = 1; + int grand_parent_id = tree.Insert(grand_parent, 1); tree.SetTargetId(grand_parent_id, 0); tree.SetContentTargetId(grand_parent_id, grand_parent_id); tree.UpdateTransforms(grand_parent_id); @@ -958,50 +385,39 @@ class PropertyTreeTestComputeTransformToTargetWithZeroSurfaceContentsScale int child_id = tree.Insert(child, parent_id); tree.SetTargetId(child_id, grand_parent_id); tree.SetContentTargetId(child_id, grand_parent_id); - SetupTransformTreeForTest(&tree); tree.UpdateTransforms(child_id); gfx::Transform expected_transform; expected_transform.Translate(4.f, 5.f); gfx::Transform transform; - bool success = tree.ComputeTransform(child_id, grand_parent_id, &transform); - EXPECT_TRUE(success); + tree.CombineTransformsBetween(child_id, grand_parent_id, &transform); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, transform); tree.Node(grand_parent_id)->local.MakeIdentity(); tree.Node(grand_parent_id)->local.Scale(0.f, 2.f); tree.Node(grand_parent_id)->needs_local_transform_update = true; tree.set_needs_update(true); - SetupTransformTreeForTest(&tree); draw_property_utils::ComputeTransforms(&tree); - success = tree.ComputeTransform(child_id, grand_parent_id, &transform); - EXPECT_TRUE(success); + transform.MakeIdentity(); + tree.CombineTransformsBetween(child_id, grand_parent_id, &transform); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, transform); tree.Node(grand_parent_id)->local.MakeIdentity(); tree.Node(grand_parent_id)->local.Scale(0.f, 0.f); tree.Node(grand_parent_id)->needs_local_transform_update = true; tree.set_needs_update(true); - SetupTransformTreeForTest(&tree); draw_property_utils::ComputeTransforms(&tree); - success = tree.ComputeTransform(child_id, grand_parent_id, &transform); - EXPECT_TRUE(success); + transform.MakeIdentity(); + tree.CombineTransformsBetween(child_id, grand_parent_id, &transform); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, transform); } -}; -DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( - PropertyTreeTestComputeTransformToTargetWithZeroSurfaceContentsScale); - -class PropertyTreeTestFlatteningWhenDestinationHasOnlyFlatAncestors - : public PropertyTreeTest { - protected: - void StartTest() override { + TEST(PropertyTreeTest, FlatteningWhenDestinationHasOnlyFlatAncestors) { // This tests that flattening is performed correctly when // destination and its ancestors are flat, but there are 3d transforms // and flattening between the source and destination. @@ -1030,56 +446,39 @@ class PropertyTreeTestFlatteningWhenDestinationHasOnlyFlatAncestors tree.Node(grand_child)->flattens_inherited_transform = true; tree.set_needs_update(true); - SetupTransformTreeForTest(&tree); draw_property_utils::ComputeTransforms(&tree); gfx::Transform flattened_rotation_about_x = rotation_about_x; flattened_rotation_about_x.FlattenTo2d(); gfx::Transform grand_child_to_parent; - bool success = - tree.ComputeTransform(grand_child, parent, &grand_child_to_parent); - EXPECT_TRUE(success); + tree.CombineTransformsBetween(grand_child, parent, &grand_child_to_parent); EXPECT_TRANSFORMATION_MATRIX_EQ(flattened_rotation_about_x, grand_child_to_parent); } -}; - -DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( - PropertyTreeTestFlatteningWhenDestinationHasOnlyFlatAncestors); -class PropertyTreeTestScreenSpaceOpacityUpdateTest : public PropertyTreeTest { - protected: - void StartTest() override { + TEST(PropertyTreeTest, ScreenSpaceOpacityUpdateTest) { // This tests that screen space opacity is updated for the subtree when // opacity of a node changes. - EffectTree tree; + PropertyTrees property_trees; + EffectTree& tree = property_trees.effect_tree; int parent = tree.Insert(EffectNode(), 0); int child = tree.Insert(EffectNode(), parent); - SetupEffectTreeForTest(&tree); EXPECT_EQ(tree.Node(child)->screen_space_opacity, 1.f); tree.Node(parent)->opacity = 0.5f; tree.set_needs_update(true); - SetupEffectTreeForTest(&tree); draw_property_utils::ComputeEffects(&tree); EXPECT_EQ(tree.Node(child)->screen_space_opacity, 0.5f); tree.Node(child)->opacity = 0.5f; tree.set_needs_update(true); - SetupEffectTreeForTest(&tree); draw_property_utils::ComputeEffects(&tree); EXPECT_EQ(tree.Node(child)->screen_space_opacity, 0.25f); } -}; - -DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( - PropertyTreeTestScreenSpaceOpacityUpdateTest); -class PropertyTreeTestNonIntegerTranslationTest : public PropertyTreeTest { - protected: - void StartTest() override { + TEST(PropertyTreeTest, NonIntegerTranslationTest) { // This tests that when a node has non-integer translation, the information // is propagated to the subtree. PropertyTrees property_trees; @@ -1095,7 +494,6 @@ class PropertyTreeTestNonIntegerTranslationTest : public PropertyTreeTest { tree.Node(child)->local.Translate(1, 1); tree.Node(child)->source_node_id = parent; tree.set_needs_update(true); - SetupTransformTreeForTest(&tree); draw_property_utils::ComputeTransforms(&tree); EXPECT_FALSE( tree.Node(parent)->node_and_ancestors_have_only_integer_translation); @@ -1107,7 +505,6 @@ class PropertyTreeTestNonIntegerTranslationTest : public PropertyTreeTest { tree.Node(parent)->needs_local_transform_update = true; tree.Node(child)->needs_local_transform_update = true; tree.set_needs_update(true); - SetupTransformTreeForTest(&tree); draw_property_utils::ComputeTransforms(&tree); EXPECT_TRUE( tree.Node(parent)->node_and_ancestors_have_only_integer_translation); @@ -1118,25 +515,17 @@ class PropertyTreeTestNonIntegerTranslationTest : public PropertyTreeTest { tree.Node(child)->needs_local_transform_update = true; tree.SetTargetId(child, child); tree.set_needs_update(true); - SetupTransformTreeForTest(&tree); draw_property_utils::ComputeTransforms(&tree); EXPECT_TRUE( tree.Node(parent)->node_and_ancestors_have_only_integer_translation); EXPECT_TRUE( tree.Node(child)->node_and_ancestors_have_only_integer_translation); } -}; -DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( - PropertyTreeTestNonIntegerTranslationTest); - -class PropertyTreeTestSingularTransformSnapTest : public PropertyTreeTest { - protected: - void StartTest() override { + TEST(PropertyTreeTest, SingularTransformSnapTest) { // This tests that to_target transform is not snapped when it has a singular // transform. PropertyTrees property_trees; - property_trees.verify_transform_tree_calculations = true; TransformTree& tree = property_trees.transform_tree; EffectTree& effect_tree = property_trees.effect_tree; @@ -1145,7 +534,6 @@ class PropertyTreeTestSingularTransformSnapTest : public PropertyTreeTest { effect_tree.Node(effect_parent)->has_render_surface = true; effect_tree.Node(effect_parent)->surface_contents_scale = gfx::Vector2dF(1.f, 1.f); - tree.SetTargetId(parent, parent); tree.Node(parent)->scrolls = true; tree.Node(parent)->source_node_id = 0; @@ -1159,32 +547,28 @@ class PropertyTreeTestSingularTransformSnapTest : public PropertyTreeTest { child_node->source_node_id = parent; tree.set_needs_update(true); - SetupTransformTreeForTest(&tree); draw_property_utils::ComputeTransforms(&tree); property_trees.ResetCachedData(); gfx::Transform from_target; - EXPECT_FALSE(tree.ToTarget(child, effect_parent).GetInverse(&from_target)); + gfx::Transform to_target; + property_trees.GetToTarget(child, effect_parent, &to_target); + EXPECT_FALSE(to_target.GetInverse(&from_target)); // The following checks are to ensure that snapping is skipped because of // singular transform (and not because of other reasons which also cause // snapping to be skipped). EXPECT_TRUE(child_node->scrolls); - EXPECT_TRUE(tree.ToTarget(child, effect_parent).IsScaleOrTranslation()); + property_trees.GetToTarget(child, effect_parent, &to_target); + EXPECT_TRUE(to_target.IsScaleOrTranslation()); EXPECT_FALSE(child_node->to_screen_is_potentially_animated); EXPECT_FALSE(child_node->ancestors_are_invertible); - gfx::Transform rounded = tree.ToTarget(child, effect_parent); + gfx::Transform rounded; + property_trees.GetToTarget(child, effect_parent, &rounded); rounded.RoundTranslationComponents(); - EXPECT_NE(tree.ToTarget(child, effect_parent), rounded); + property_trees.GetToTarget(child, effect_parent, &to_target); + EXPECT_NE(to_target, rounded); } -}; - -DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F( - PropertyTreeTestSingularTransformSnapTest); - -#undef DIRECT_AND_SERIALIZED_PROPERTY_TREE_TEST_F -#undef SERIALIZED_PROPERTY_TREE_TEST_F -#undef DIRECT_PROPERTY_TREE_TEST_F } // namespace } // namespace cc diff --git a/chromium/cc/trees/proxy.h b/chromium/cc/trees/proxy.h index 53381d9dfe7..e49dc774b77 100644 --- a/chromium/cc/trees/proxy.h +++ b/chromium/cc/trees/proxy.h @@ -14,18 +14,15 @@ #include "base/time/time.h" #include "base/values.h" #include "cc/base/cc_export.h" -#include "cc/input/top_controls_state.h" +#include "cc/input/browser_controls_state.h" #include "cc/scheduler/begin_frame_source.h" #include "cc/trees/task_runner_provider.h" namespace gfx { class Rect; -class Vector2d; } namespace cc { -class BeginFrameSource; -class LayerTreeDebugState; class LayerTreeMutator; class CompositorFrameSink; @@ -73,9 +70,9 @@ class CC_EXPORT Proxy { virtual bool SupportsImplScrolling() const = 0; - virtual void UpdateTopControlsState(TopControlsState constraints, - TopControlsState current, - bool animate) = 0; + virtual void UpdateBrowserControlsState(BrowserControlsState constraints, + BrowserControlsState current, + bool animate) = 0; // Testing hooks virtual bool MainFrameWillHappenForTesting() = 0; diff --git a/chromium/cc/trees/proxy_common.cc b/chromium/cc/trees/proxy_common.cc index be80dd52733..ab9c87be5b6 100644 --- a/chromium/cc/trees/proxy_common.cc +++ b/chromium/cc/trees/proxy_common.cc @@ -4,7 +4,6 @@ #include "cc/trees/proxy_common.h" -#include "cc/proto/begin_main_frame_and_commit_state.pb.h" #include "cc/trees/layer_tree_host.h" namespace cc { @@ -13,23 +12,4 @@ BeginMainFrameAndCommitState::BeginMainFrameAndCommitState() {} BeginMainFrameAndCommitState::~BeginMainFrameAndCommitState() {} -void BeginMainFrameAndCommitState::ToProtobuf( - proto::BeginMainFrameAndCommitState* proto) const { - proto->set_begin_frame_id(begin_frame_id); - begin_frame_args.ToProtobuf(proto->mutable_begin_frame_args()); - scroll_info->ToProtobuf(proto->mutable_scroll_info()); - proto->set_memory_allocation_limit_bytes(memory_allocation_limit_bytes); - proto->set_evicted_ui_resources(evicted_ui_resources); -} - -void BeginMainFrameAndCommitState::FromProtobuf( - const proto::BeginMainFrameAndCommitState& proto) { - begin_frame_id = proto.begin_frame_id(); - begin_frame_args.FromProtobuf(proto.begin_frame_args()); - scroll_info.reset(new ScrollAndScaleSet()); - scroll_info->FromProtobuf(proto.scroll_info()); - memory_allocation_limit_bytes = proto.memory_allocation_limit_bytes(); - evicted_ui_resources = proto.evicted_ui_resources(); -} - } // namespace cc diff --git a/chromium/cc/trees/proxy_common.h b/chromium/cc/trees/proxy_common.h index 42156f7ec05..69ffcfda262 100644 --- a/chromium/cc/trees/proxy_common.h +++ b/chromium/cc/trees/proxy_common.h @@ -14,12 +14,6 @@ namespace cc { -namespace proto { -class BeginMainFrameAndCommitState; -} - -class LayerTreeHost; - using BeginFrameCallbackList = std::vector<base::Closure>; struct CC_EXPORT BeginMainFrameAndCommitState { @@ -32,9 +26,6 @@ struct CC_EXPORT BeginMainFrameAndCommitState { std::unique_ptr<ScrollAndScaleSet> scroll_info; size_t memory_allocation_limit_bytes = 0; bool evicted_ui_resources = false; - - void ToProtobuf(proto::BeginMainFrameAndCommitState* proto) const; - void FromProtobuf(const proto::BeginMainFrameAndCommitState& proto); }; } // namespace cc diff --git a/chromium/cc/trees/proxy_common_unittest.cc b/chromium/cc/trees/proxy_common_unittest.cc deleted file mode 100644 index 3b47eb87a7c..00000000000 --- a/chromium/cc/trees/proxy_common_unittest.cc +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2016 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. - -#include "cc/trees/proxy_common.h" - -#include "cc/proto/begin_main_frame_and_commit_state.pb.h" -#include "cc/test/begin_frame_args_test.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace cc { -namespace { - -TEST(ProxyCommonUnittest, SerializeBeginMainFrameAndCommitState) { - BeginMainFrameAndCommitState begin_main_frame_state; - begin_main_frame_state.begin_frame_id = 5; - - begin_main_frame_state.begin_frame_args = BeginFrameArgs::Create( - BEGINFRAME_FROM_HERE, base::TimeTicks::FromInternalValue(4), - base::TimeTicks::FromInternalValue(7), - base::TimeDelta::FromInternalValue(9), BeginFrameArgs::NORMAL); - begin_main_frame_state.begin_frame_args.on_critical_path = false; - - LayerTreeHostCommon::ScrollUpdateInfo scroll1; - scroll1.layer_id = 1; - scroll1.scroll_delta = gfx::Vector2d(5, 10); - LayerTreeHostCommon::ScrollUpdateInfo scroll2; - scroll2.layer_id = 2; - scroll2.scroll_delta = gfx::Vector2d(1, 5); - begin_main_frame_state.scroll_info.reset(new ScrollAndScaleSet()); - begin_main_frame_state.scroll_info->scrolls.push_back(scroll1); - begin_main_frame_state.scroll_info->scrolls.push_back(scroll2); - - begin_main_frame_state.scroll_info->page_scale_delta = 0.3f; - begin_main_frame_state.scroll_info->elastic_overscroll_delta = - gfx::Vector2dF(0.5f, 0.6f); - begin_main_frame_state.scroll_info->top_controls_delta = 0.9f; - - begin_main_frame_state.evicted_ui_resources = false; - - proto::BeginMainFrameAndCommitState proto; - begin_main_frame_state.ToProtobuf(&proto); - - BeginMainFrameAndCommitState new_begin_main_frame_state; - new_begin_main_frame_state.FromProtobuf(proto); - - EXPECT_EQ(new_begin_main_frame_state.begin_frame_id, - begin_main_frame_state.begin_frame_id); - EXPECT_EQ(new_begin_main_frame_state.begin_frame_args, - begin_main_frame_state.begin_frame_args); - EXPECT_TRUE(begin_main_frame_state.scroll_info->EqualsForTesting( - *new_begin_main_frame_state.scroll_info.get())); - EXPECT_EQ(new_begin_main_frame_state.evicted_ui_resources, - begin_main_frame_state.evicted_ui_resources); -} - -} // namespace -} // namespace cc diff --git a/chromium/cc/trees/proxy_impl.cc b/chromium/cc/trees/proxy_impl.cc index fcefcec6594..710a80b1dd7 100644 --- a/chromium/cc/trees/proxy_impl.cc +++ b/chromium/cc/trees/proxy_impl.cc @@ -12,16 +12,16 @@ #include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event_argument.h" #include "base/trace_event/trace_event_synthetic_delay.h" -#include "cc/animation/animation_events.h" #include "cc/debug/benchmark_instrumentation.h" #include "cc/debug/devtools_instrumentation.h" -#include "cc/input/top_controls_manager.h" +#include "cc/input/browser_controls_offset_manager.h" #include "cc/output/compositor_frame_sink.h" #include "cc/output/context_provider.h" #include "cc/scheduler/compositor_timing_history.h" #include "cc/scheduler/delay_based_time_source.h" #include "cc/trees/layer_tree_host_in_process.h" #include "cc/trees/layer_tree_impl.h" +#include "cc/trees/mutator_host.h" #include "cc/trees/task_runner_provider.h" #include "gpu/command_buffer/client/gles2_interface.h" @@ -90,11 +90,12 @@ ProxyImpl::~ProxyImpl() { DCHECK(IsImplThread()); DCHECK(IsMainThreadBlocked()); + // Prevent the scheduler from performing actions while we're in an + // inconsistent state. + scheduler_->Stop(); // Take away the CompositorFrameSink before destroying things so it doesn't // try to call into its client mid-shutdown. - scheduler_->DidLoseCompositorFrameSink(); layer_tree_host_impl_->ReleaseCompositorFrameSink(); - scheduler_ = nullptr; layer_tree_host_impl_ = nullptr; // We need to explicitly shutdown the notifier to destroy any weakptrs it is @@ -110,11 +111,12 @@ void ProxyImpl::InitializeMutatorOnImpl( layer_tree_host_impl_->SetLayerTreeMutator(std::move(mutator)); } -void ProxyImpl::UpdateTopControlsStateOnImpl(TopControlsState constraints, - TopControlsState current, - bool animate) { +void ProxyImpl::UpdateBrowserControlsStateOnImpl( + BrowserControlsState constraints, + BrowserControlsState current, + bool animate) { DCHECK(IsImplThread()); - layer_tree_host_impl_->top_controls_manager()->UpdateTopControlsState( + layer_tree_host_impl_->browser_controls_manager()->UpdateBrowserControlsState( constraints, current, animate); } @@ -267,11 +269,12 @@ void ProxyImpl::SetBeginFrameSource(BeginFrameSource* source) { } } -void ProxyImpl::DidSwapBuffersCompleteOnImplThread() { - TRACE_EVENT0("cc,benchmark", "ProxyImpl::DidSwapBuffersCompleteOnImplThread"); +void ProxyImpl::DidReceiveCompositorFrameAckOnImplThread() { + TRACE_EVENT0("cc,benchmark", + "ProxyImpl::DidReceiveCompositorFrameAckOnImplThread"); DCHECK(IsImplThread()); - scheduler_->DidSwapBuffersComplete(); - channel_impl_->DidCompleteSwapBuffers(); + scheduler_->DidReceiveCompositorFrameAck(); + channel_impl_->DidReceiveCompositorFrameAck(); } void ProxyImpl::OnCanDrawStateChanged(bool can_draw) { @@ -325,7 +328,7 @@ void ProxyImpl::SetVideoNeedsBeginFrames(bool needs_begin_frames) { } void ProxyImpl::PostAnimationEventsToMainThreadOnImplThread( - std::unique_ptr<AnimationEvents> events) { + std::unique_ptr<MutatorEvents> events) { TRACE_EVENT0("cc", "ProxyImpl::PostAnimationEventsToMainThreadOnImplThread"); DCHECK(IsImplThread()); channel_impl_->SetAnimationEvents(std::move(events)); @@ -447,24 +450,22 @@ void ProxyImpl::ScheduledActionSendBeginMainFrame(const BeginFrameArgs& args) { devtools_instrumentation::DidRequestMainThreadFrame(layer_tree_host_id_); } -DrawResult ProxyImpl::ScheduledActionDrawAndSwapIfPossible() { - TRACE_EVENT0("cc", "ProxyImpl::ScheduledActionDrawAndSwap"); +DrawResult ProxyImpl::ScheduledActionDrawIfPossible() { + TRACE_EVENT0("cc", "ProxyImpl::ScheduledActionDraw"); DCHECK(IsImplThread()); - // SchedulerStateMachine::DidDrawIfPossibleCompleted isn't set up to - // handle DRAW_ABORTED_CANT_DRAW. Moreover, the scheduler should - // never generate this call when it can't draw. + // The scheduler should never generate this call when it can't draw. DCHECK(layer_tree_host_impl_->CanDraw()); bool forced_draw = false; - return DrawAndSwapInternal(forced_draw); + return DrawInternal(forced_draw); } -DrawResult ProxyImpl::ScheduledActionDrawAndSwapForced() { - TRACE_EVENT0("cc", "ProxyImpl::ScheduledActionDrawAndSwapForced"); +DrawResult ProxyImpl::ScheduledActionDrawForced() { + TRACE_EVENT0("cc", "ProxyImpl::ScheduledActionDrawForced"); DCHECK(IsImplThread()); bool forced_draw = true; - return DrawAndSwapInternal(forced_draw); + return DrawInternal(forced_draw); } void ProxyImpl::ScheduledActionCommit() { @@ -537,8 +538,8 @@ void ProxyImpl::SendBeginMainFrameNotExpectedSoon() { channel_impl_->BeginMainFrameNotExpectedSoon(); } -DrawResult ProxyImpl::DrawAndSwapInternal(bool forced_draw) { - TRACE_EVENT_SYNTHETIC_DELAY("cc.DrawAndSwap"); +DrawResult ProxyImpl::DrawInternal(bool forced_draw) { + TRACE_EVENT_SYNTHETIC_DELAY("cc.Draw"); DCHECK(IsImplThread()); DCHECK(layer_tree_host_impl_.get()); @@ -575,7 +576,8 @@ DrawResult ProxyImpl::DrawAndSwapInternal(bool forced_draw) { if (draw_frame) { if (layer_tree_host_impl_->DrawLayers(&frame)) - scheduler_->DidSwapBuffers(); + // Drawing implies we submitted a frame to the CompositorFrameSink. + scheduler_->DidSubmitCompositorFrame(); result = DRAW_SUCCESS; } else { DCHECK_NE(DRAW_SUCCESS, result); diff --git a/chromium/cc/trees/proxy_impl.h b/chromium/cc/trees/proxy_impl.h index ed1e10edf0b..d6c20c10db8 100644 --- a/chromium/cc/trees/proxy_impl.h +++ b/chromium/cc/trees/proxy_impl.h @@ -10,7 +10,7 @@ #include "base/macros.h" #include "cc/base/completion_event.h" #include "cc/base/delayed_unique_notifier.h" -#include "cc/input/top_controls_state.h" +#include "cc/input/browser_controls_state.h" #include "cc/scheduler/scheduler.h" #include "cc/trees/channel_impl.h" #include "cc/trees/layer_tree_host_impl.h" @@ -30,9 +30,9 @@ class CC_EXPORT ProxyImpl : public NON_EXPORTED_BASE(LayerTreeHostImplClient), ~ProxyImpl() override; // Virtual for testing. - void UpdateTopControlsStateOnImpl(TopControlsState constraints, - TopControlsState current, - bool animate); + void UpdateBrowserControlsStateOnImpl(BrowserControlsState constraints, + BrowserControlsState current, + bool animate); void InitializeCompositorFrameSinkOnImpl( CompositorFrameSink* compositor_frame_sink); void InitializeMutatorOnImpl(std::unique_ptr<LayerTreeMutator> mutator); @@ -68,7 +68,7 @@ class CC_EXPORT ProxyImpl : public NON_EXPORTED_BASE(LayerTreeHostImplClient), // LayerTreeHostImplClient implementation void DidLoseCompositorFrameSinkOnImplThread() override; void SetBeginFrameSource(BeginFrameSource* source) override; - void DidSwapBuffersCompleteOnImplThread() override; + void DidReceiveCompositorFrameAckOnImplThread() override; void OnCanDrawStateChanged(bool can_draw) override; void NotifyReadyToActivate() override; void NotifyReadyToDraw() override; @@ -80,7 +80,7 @@ class CC_EXPORT ProxyImpl : public NON_EXPORTED_BASE(LayerTreeHostImplClient), void SetNeedsCommitOnImplThread() override; void SetVideoNeedsBeginFrames(bool needs_begin_frames) override; void PostAnimationEventsToMainThreadOnImplThread( - std::unique_ptr<AnimationEvents> events) override; + std::unique_ptr<MutatorEvents> events) override; bool IsInsideDraw() override; void RenewTreePriority() override; void PostDelayedAnimationTaskOnImplThread(const base::Closure& task, @@ -95,8 +95,8 @@ class CC_EXPORT ProxyImpl : public NON_EXPORTED_BASE(LayerTreeHostImplClient), void WillBeginImplFrame(const BeginFrameArgs& args) override; void DidFinishImplFrame() override; void ScheduledActionSendBeginMainFrame(const BeginFrameArgs& args) override; - DrawResult ScheduledActionDrawAndSwapIfPossible() override; - DrawResult ScheduledActionDrawAndSwapForced() override; + DrawResult ScheduledActionDrawIfPossible() override; + DrawResult ScheduledActionDrawForced() override; void ScheduledActionCommit() override; void ScheduledActionActivateSyncTree() override; void ScheduledActionBeginCompositorFrameSinkCreation() override; @@ -104,7 +104,7 @@ class CC_EXPORT ProxyImpl : public NON_EXPORTED_BASE(LayerTreeHostImplClient), void ScheduledActionInvalidateCompositorFrameSink() override; void SendBeginMainFrameNotExpectedSoon() override; - DrawResult DrawAndSwapInternal(bool forced_draw); + DrawResult DrawInternal(bool forced_draw); bool IsImplThread() const; bool IsMainThreadBlocked() const; diff --git a/chromium/cc/trees/proxy_main.cc b/chromium/cc/trees/proxy_main.cc index e02a86b8776..513f84dc9ff 100644 --- a/chromium/cc/trees/proxy_main.cc +++ b/chromium/cc/trees/proxy_main.cc @@ -10,7 +10,6 @@ #include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event_argument.h" #include "base/trace_event/trace_event_synthetic_delay.h" -#include "cc/animation/animation_events.h" #include "cc/debug/benchmark_instrumentation.h" #include "cc/debug/devtools_instrumentation.h" #include "cc/output/compositor_frame_sink.h" @@ -18,7 +17,7 @@ #include "cc/resources/ui_resource_manager.h" #include "cc/trees/blocking_task_runner.h" #include "cc/trees/layer_tree_host_in_process.h" -#include "cc/trees/remote_channel_main.h" +#include "cc/trees/mutator_host.h" #include "cc/trees/scoped_abort_remaining_swap_promises.h" #include "cc/trees/threaded_channel.h" @@ -34,17 +33,6 @@ std::unique_ptr<ProxyMain> ProxyMain::CreateThreaded( return proxy_main; } -std::unique_ptr<ProxyMain> ProxyMain::CreateRemote( - RemoteProtoChannel* remote_proto_channel, - LayerTreeHostInProcess* layer_tree_host, - TaskRunnerProvider* task_runner_provider) { - std::unique_ptr<ProxyMain> proxy_main( - new ProxyMain(layer_tree_host, task_runner_provider)); - proxy_main->SetChannel(RemoteChannelMain::Create( - remote_proto_channel, proxy_main.get(), task_runner_provider)); - return proxy_main; -} - ProxyMain::ProxyMain(LayerTreeHostInProcess* layer_tree_host, TaskRunnerProvider* task_runner_provider) : layer_tree_host_(layer_tree_host), @@ -72,9 +60,9 @@ void ProxyMain::SetChannel(std::unique_ptr<ChannelMain> channel_main) { channel_main_ = std::move(channel_main); } -void ProxyMain::DidCompleteSwapBuffers() { +void ProxyMain::DidReceiveCompositorFrameAck() { DCHECK(IsMainThread()); - layer_tree_host_->DidCompleteSwapBuffers(); + layer_tree_host_->DidReceiveCompositorFrameAck(); } void ProxyMain::BeginMainFrameNotExpectedSoon() { @@ -88,7 +76,7 @@ void ProxyMain::DidCommitAndDrawFrame() { layer_tree_host_->DidCommitAndDrawFrame(); } -void ProxyMain::SetAnimationEvents(std::unique_ptr<AnimationEvents> events) { +void ProxyMain::SetAnimationEvents(std::unique_ptr<MutatorEvents> events) { TRACE_EVENT0("cc", "ProxyMain::SetAnimationEvents"); DCHECK(IsMainThread()); layer_tree_host_->SetAnimationEvents(std::move(events)); @@ -351,7 +339,7 @@ void ProxyMain::MainThreadHasStoppedFlinging() { void ProxyMain::Start() { DCHECK(IsMainThread()); - DCHECK(layer_tree_host_->IsThreaded() || layer_tree_host_->IsRemoteServer()); + DCHECK(layer_tree_host_->IsThreaded()); DCHECK(channel_main_); // Create LayerTreeHostImpl. @@ -401,11 +389,12 @@ void ProxyMain::ReleaseCompositorFrameSink() { completion.Wait(); } -void ProxyMain::UpdateTopControlsState(TopControlsState constraints, - TopControlsState current, - bool animate) { +void ProxyMain::UpdateBrowserControlsState(BrowserControlsState constraints, + BrowserControlsState current, + bool animate) { DCHECK(IsMainThread()); - channel_main_->UpdateTopControlsStateOnImpl(constraints, current, animate); + channel_main_->UpdateBrowserControlsStateOnImpl(constraints, current, + animate); } bool ProxyMain::SendCommitRequestToImplThreadIfNeeded( diff --git a/chromium/cc/trees/proxy_main.h b/chromium/cc/trees/proxy_main.h index 6bd6d7870f7..d455af6be19 100644 --- a/chromium/cc/trees/proxy_main.h +++ b/chromium/cc/trees/proxy_main.h @@ -7,16 +7,14 @@ #include "base/macros.h" #include "cc/base/cc_export.h" -#include "cc/input/top_controls_state.h" +#include "cc/input/browser_controls_state.h" #include "cc/trees/channel_main.h" #include "cc/trees/proxy.h" #include "cc/trees/proxy_common.h" -#include "cc/trees/remote_proto_channel.h" namespace cc { -class AnimationEvents; -class BeginFrameSource; +class MutatorEvents; class ChannelMain; class CompositorFrameSink; class LayerTreeHostInProcess; @@ -31,11 +29,6 @@ class CC_EXPORT ProxyMain : public Proxy { LayerTreeHostInProcess* layer_tree_host, TaskRunnerProvider* task_runner_provider); - static std::unique_ptr<ProxyMain> CreateRemote( - RemoteProtoChannel* remote_proto_channel, - LayerTreeHostInProcess* layer_tree_host, - TaskRunnerProvider* task_runner_provider); - ~ProxyMain() override; // Commits between the main and impl threads are processed through a pipeline @@ -48,10 +41,10 @@ class CC_EXPORT ProxyMain : public Proxy { COMMIT_PIPELINE_STAGE, }; - void DidCompleteSwapBuffers(); + void DidReceiveCompositorFrameAck(); void BeginMainFrameNotExpectedSoon(); void DidCommitAndDrawFrame(); - void SetAnimationEvents(std::unique_ptr<AnimationEvents> events); + void SetAnimationEvents(std::unique_ptr<MutatorEvents> events); void DidLoseCompositorFrameSink(); void RequestNewCompositorFrameSink(); void DidInitializeCompositorFrameSink(bool success); @@ -99,9 +92,9 @@ class CC_EXPORT ProxyMain : public Proxy { void SetMutator(std::unique_ptr<LayerTreeMutator> mutator) override; bool MainFrameWillHappenForTesting() override; void ReleaseCompositorFrameSink() override; - void UpdateTopControlsState(TopControlsState constraints, - TopControlsState current, - bool animate) override; + void UpdateBrowserControlsState(BrowserControlsState constraints, + BrowserControlsState current, + bool animate) override; // This sets the channel used by ProxyMain to communicate with ProxyImpl. void SetChannel(std::unique_ptr<ChannelMain> channel_main); diff --git a/chromium/cc/trees/remote_channel_impl.cc b/chromium/cc/trees/remote_channel_impl.cc deleted file mode 100644 index 32d2bdb02af..00000000000 --- a/chromium/cc/trees/remote_channel_impl.cc +++ /dev/null @@ -1,518 +0,0 @@ -// Copyright 2016 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. - -#include "cc/trees/remote_channel_impl.h" - -#include "base/bind_helpers.h" -#include "base/memory/ptr_util.h" -#include "base/single_thread_task_runner.h" -#include "cc/animation/animation_events.h" -#include "cc/proto/compositor_message.pb.h" -#include "cc/proto/compositor_message_to_impl.pb.h" -#include "cc/proto/compositor_message_to_main.pb.h" -#include "cc/proto/gfx_conversions.h" -#include "cc/trees/layer_tree_host_in_process.h" -#include "cc/trees/layer_tree_settings.h" - -namespace cc { - -RemoteChannelImpl::RemoteChannelImpl(LayerTreeHostInProcess* layer_tree_host, - RemoteProtoChannel* remote_proto_channel, - TaskRunnerProvider* task_runner_provider) - : task_runner_provider_(task_runner_provider), - main_thread_vars_unsafe_(this, layer_tree_host, remote_proto_channel), - compositor_thread_vars_unsafe_( - main().remote_channel_weak_factory.GetWeakPtr()) { - DCHECK(task_runner_provider_->IsMainThread()); - - main().remote_proto_channel->SetProtoReceiver(this); -} - -RemoteChannelImpl::~RemoteChannelImpl() { - DCHECK(task_runner_provider_->IsMainThread()); - DCHECK(!main().started); - - main().remote_proto_channel->SetProtoReceiver(nullptr); -} - -std::unique_ptr<ProxyImpl> RemoteChannelImpl::CreateProxyImpl( - ChannelImpl* channel_impl, - LayerTreeHostInProcess* layer_tree_host, - TaskRunnerProvider* task_runner_provider) { - DCHECK(task_runner_provider_->IsImplThread()); - return base::MakeUnique<ProxyImpl>(channel_impl, layer_tree_host, - task_runner_provider); -} - -void RemoteChannelImpl::OnProtoReceived( - std::unique_ptr<proto::CompositorMessage> proto) { - DCHECK(task_runner_provider_->IsMainThread()); - DCHECK(main().started); - DCHECK(proto->has_to_impl()); - - // If we don't have an CompositorFrameSink, queue the message and defer - // processing it till we initialize a new CompositorFrameSink. - if (main().waiting_for_compositor_frame_sink_initialization) { - VLOG(1) << "Queueing message proto since CompositorFrameSink was released."; - main().pending_messages.push(proto->to_impl()); - } else { - HandleProto(proto->to_impl()); - } -} - -void RemoteChannelImpl::HandleProto( - const proto::CompositorMessageToImpl& proto) { - DCHECK(task_runner_provider_->IsMainThread()); - DCHECK(proto.has_message_type()); - DCHECK(!main().waiting_for_compositor_frame_sink_initialization); - - switch (proto.message_type()) { - case proto::CompositorMessageToImpl::UNKNOWN: - NOTIMPLEMENTED() << "Ignoring message of UNKNOWN type"; - break; - case proto::CompositorMessageToImpl::SET_NEEDS_COMMIT: - VLOG(1) << "Received commit request from the engine."; - ImplThreadTaskRunner()->PostTask( - FROM_HERE, - base::Bind(&ProxyImpl::SetNeedsCommitOnImpl, proxy_impl_weak_ptr_)); - break; - case proto::CompositorMessageToImpl::SET_DEFER_COMMITS: { - const proto::SetDeferCommits& defer_commits_message = - proto.defer_commits_message(); - bool defer_commits = defer_commits_message.defer_commits(); - VLOG(1) << "Received set defer commits to: " << defer_commits - << " from the engine."; - ImplThreadTaskRunner()->PostTask( - FROM_HERE, base::Bind(&ProxyImpl::SetDeferCommitsOnImpl, - proxy_impl_weak_ptr_, defer_commits)); - } break; - case proto::CompositorMessageToImpl::START_COMMIT: { - VLOG(1) << "Received commit proto from the engine."; - base::TimeTicks main_thread_start_time = base::TimeTicks::Now(); - const proto::StartCommit& start_commit_message = - proto.start_commit_message(); - - main().layer_tree_host->FromProtobufForCommit( - start_commit_message.layer_tree_host()); - - { - DebugScopedSetMainThreadBlocked main_thread_blocked( - task_runner_provider_); - CompletionEvent completion; - VLOG(1) << "Starting commit."; - ImplThreadTaskRunner()->PostTask( - FROM_HERE, - base::Bind(&ProxyImpl::NotifyReadyToCommitOnImpl, - proxy_impl_weak_ptr_, &completion, - main().layer_tree_host, main_thread_start_time, false)); - completion.Wait(); - } - } break; - case proto::CompositorMessageToImpl::BEGIN_MAIN_FRAME_ABORTED: { - base::TimeTicks main_thread_start_time = base::TimeTicks::Now(); - const proto::BeginMainFrameAborted& begin_main_frame_aborted_message = - proto.begin_main_frame_aborted_message(); - CommitEarlyOutReason reason = CommitEarlyOutReasonFromProtobuf( - begin_main_frame_aborted_message.reason()); - std::vector<std::unique_ptr<SwapPromise>> empty_swap_promises; - VLOG(1) << "Received BeginMainFrameAborted from the engine with reason: " - << CommitEarlyOutReasonToString(reason); - ImplThreadTaskRunner()->PostTask( - FROM_HERE, - base::Bind(&ProxyImpl::BeginMainFrameAbortedOnImpl, - proxy_impl_weak_ptr_, reason, main_thread_start_time, - base::Passed(&empty_swap_promises))); - } break; - case proto::CompositorMessageToImpl::SET_NEEDS_REDRAW: { - VLOG(1) << "Received redraw request from the engine."; - const proto::SetNeedsRedraw& set_needs_redraw_message = - proto.set_needs_redraw_message(); - gfx::Rect damaged_rect = - ProtoToRect(set_needs_redraw_message.damaged_rect()); - PostSetNeedsRedrawToImpl(damaged_rect); - } break; - } -} - -bool RemoteChannelImpl::IsStarted() const { - DCHECK(task_runner_provider_->IsMainThread()); - return main().started; -} - -bool RemoteChannelImpl::CommitToActiveTree() const { - return false; -} - -void RemoteChannelImpl::SetCompositorFrameSink( - CompositorFrameSink* compositor_frame_sink) { - DCHECK(task_runner_provider_->IsMainThread()); - - ImplThreadTaskRunner()->PostTask( - FROM_HERE, base::Bind(&ProxyImpl::InitializeCompositorFrameSinkOnImpl, - proxy_impl_weak_ptr_, compositor_frame_sink)); -} - -void RemoteChannelImpl::ReleaseCompositorFrameSink() { - DCHECK(task_runner_provider_->IsMainThread()); - DCHECK(!main().waiting_for_compositor_frame_sink_initialization); - VLOG(1) << "Releasing CompositorFrameSink"; - - { - CompletionEvent completion; - DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); - ImplThreadTaskRunner()->PostTask( - FROM_HERE, base::Bind(&ProxyImpl::ReleaseCompositorFrameSinkOnImpl, - proxy_impl_weak_ptr_, &completion)); - completion.Wait(); - } - - main().waiting_for_compositor_frame_sink_initialization = true; -} - -void RemoteChannelImpl::SetVisible(bool visible) { - DCHECK(task_runner_provider_->IsMainThread()); - VLOG(1) << "Setting visibility to: " << visible; - - ImplThreadTaskRunner()->PostTask( - FROM_HERE, - base::Bind(&ProxyImpl::SetVisibleOnImpl, proxy_impl_weak_ptr_, visible)); -} - -void RemoteChannelImpl::SetNeedsAnimate() { - NOTREACHED() << "Should not be called on the remote client LayerTreeHost"; -} - -void RemoteChannelImpl::SetNeedsUpdateLayers() { - NOTREACHED() << "Should not be called on the remote client LayerTreeHost"; -} - -void RemoteChannelImpl::SetNeedsCommit() { - // Ideally commits should be requested only on the server. But we have to - // allow this call since the LayerTreeHostInProcesswill currently ask for a - // commit in 2 cases: - // 1) When it is being initialized from a protobuf for a commit. - // 2) When it loses the CompositorFrameSink. - NOTIMPLEMENTED() << "Commits should not be requested on the client"; -} - -void RemoteChannelImpl::SetNeedsRedraw(const gfx::Rect& damage_rect) { - NOTREACHED() << "Should not be called on the remote client LayerTreeHost"; -} - -void RemoteChannelImpl::SetNextCommitWaitsForActivation() { - NOTREACHED() << "Should not be called on the remote client LayerTreeHost"; -} - -void RemoteChannelImpl::NotifyInputThrottledUntilCommit() { - NOTREACHED() << "Should not be called on the remote client LayerTreeHost"; -} - -void RemoteChannelImpl::SetDeferCommits(bool defer_commits) { - NOTREACHED() << "Should not be called on the remote client LayerTreeHost"; -} - -void RemoteChannelImpl::MainThreadHasStoppedFlinging() { - NOTREACHED() << "Should not be called on the remote client LayerTreeHost"; -} - -bool RemoteChannelImpl::CommitRequested() const { - NOTREACHED() << "Should not be called on the remote client LayerTreeHost"; - return false; -} - -bool RemoteChannelImpl::BeginMainFrameRequested() const { - NOTREACHED() << "Should not be called on the remote client LayerTreeHost"; - return false; -} - -void RemoteChannelImpl::Start() { - DCHECK(task_runner_provider_->IsMainThread()); - DCHECK(!main().started); - - CompletionEvent completion; - { - DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); - ImplThreadTaskRunner()->PostTask( - FROM_HERE, base::Bind(&RemoteChannelImpl::InitializeImplOnImpl, - base::Unretained(this), &completion, - main().layer_tree_host)); - completion.Wait(); - } - main().started = true; -} - -void RemoteChannelImpl::Stop() { - DCHECK(task_runner_provider_->IsMainThread()); - DCHECK(main().started); - - { - CompletionEvent completion; - DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); - ImplThreadTaskRunner()->PostTask( - FROM_HERE, base::Bind(&ProxyImpl::FinishGLOnImpl, proxy_impl_weak_ptr_, - &completion)); - completion.Wait(); - } - { - CompletionEvent completion; - DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); - ImplThreadTaskRunner()->PostTask( - FROM_HERE, base::Bind(&RemoteChannelImpl::ShutdownImplOnImpl, - base::Unretained(this), &completion)); - completion.Wait(); - } - - main().started = false; - main().remote_channel_weak_factory.InvalidateWeakPtrs(); -} - -void RemoteChannelImpl::SetMutator(std::unique_ptr<LayerTreeMutator> mutator) { - // TODO(vollick): add support for compositor worker. -} - -bool RemoteChannelImpl::SupportsImplScrolling() const { - return true; -} - -void RemoteChannelImpl::UpdateTopControlsState(TopControlsState constraints, - TopControlsState current, - bool animate) { - NOTREACHED() << "Should not be called on the remote client LayerTreeHost"; -} - -bool RemoteChannelImpl::MainFrameWillHappenForTesting() { - DCHECK(task_runner_provider_->IsMainThread()); - bool main_frame_will_happen; - { - CompletionEvent completion; - DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); - ImplThreadTaskRunner()->PostTask( - FROM_HERE, - base::Bind(&ProxyImpl::MainFrameWillHappenOnImplForTesting, - proxy_impl_weak_ptr_, &completion, &main_frame_will_happen)); - completion.Wait(); - } - return main_frame_will_happen; -} - -void RemoteChannelImpl::DidCompleteSwapBuffers() { - DCHECK(task_runner_provider_->IsImplThread()); - MainThreadTaskRunner()->PostTask( - FROM_HERE, base::Bind(&RemoteChannelImpl::DidCompleteSwapBuffersOnMain, - impl().remote_channel_weak_ptr)); -} - -void RemoteChannelImpl::BeginMainFrameNotExpectedSoon() {} - -void RemoteChannelImpl::DidCommitAndDrawFrame() { - DCHECK(task_runner_provider_->IsImplThread()); - MainThreadTaskRunner()->PostTask( - FROM_HERE, base::Bind(&RemoteChannelImpl::DidCommitAndDrawFrameOnMain, - impl().remote_channel_weak_ptr)); -} - -void RemoteChannelImpl::SetAnimationEvents( - std::unique_ptr<AnimationEvents> queue) {} - -void RemoteChannelImpl::DidLoseCompositorFrameSink() { - DCHECK(task_runner_provider_->IsImplThread()); - - MainThreadTaskRunner()->PostTask( - FROM_HERE, - base::Bind(&RemoteChannelImpl::DidLoseCompositorFrameSinkOnMain, - impl().remote_channel_weak_ptr)); -} - -void RemoteChannelImpl::RequestNewCompositorFrameSink() { - DCHECK(task_runner_provider_->IsImplThread()); - - MainThreadTaskRunner()->PostTask( - FROM_HERE, - base::Bind(&RemoteChannelImpl::RequestNewCompositorFrameSinkOnMain, - impl().remote_channel_weak_ptr)); -} - -void RemoteChannelImpl::DidInitializeCompositorFrameSink(bool success) { - DCHECK(task_runner_provider_->IsImplThread()); - - MainThreadTaskRunner()->PostTask( - FROM_HERE, - base::Bind(&RemoteChannelImpl::DidInitializeCompositorFrameSinkOnMain, - impl().remote_channel_weak_ptr, success)); -} - -void RemoteChannelImpl::DidCompletePageScaleAnimation() {} - -void RemoteChannelImpl::BeginMainFrame( - std::unique_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) { - std::unique_ptr<proto::CompositorMessage> proto; - proto.reset(new proto::CompositorMessage); - proto::CompositorMessageToMain* to_main_proto = proto->mutable_to_main(); - - to_main_proto->set_message_type( - proto::CompositorMessageToMain::BEGIN_MAIN_FRAME); - proto::BeginMainFrame* begin_main_frame_message = - to_main_proto->mutable_begin_main_frame_message(); - begin_main_frame_state->ToProtobuf( - begin_main_frame_message->mutable_begin_main_frame_state()); - - SendMessageProto(std::move(proto)); -} - -void RemoteChannelImpl::SendMessageProto( - std::unique_ptr<proto::CompositorMessage> proto) { - DCHECK(task_runner_provider_->IsImplThread()); - - MainThreadTaskRunner()->PostTask( - FROM_HERE, - base::Bind(&RemoteChannelImpl::SendMessageProtoOnMain, - impl().remote_channel_weak_ptr, base::Passed(&proto))); -} - -void RemoteChannelImpl::DidCompleteSwapBuffersOnMain() { - DCHECK(task_runner_provider_->IsMainThread()); - main().layer_tree_host->DidCompleteSwapBuffers(); -} - -void RemoteChannelImpl::DidCommitAndDrawFrameOnMain() { - DCHECK(task_runner_provider_->IsMainThread()); - main().layer_tree_host->DidCommitAndDrawFrame(); -} - -void RemoteChannelImpl::DidLoseCompositorFrameSinkOnMain() { - DCHECK(task_runner_provider_->IsMainThread()); - - main().layer_tree_host->DidLoseCompositorFrameSink(); -} - -void RemoteChannelImpl::RequestNewCompositorFrameSinkOnMain() { - DCHECK(task_runner_provider_->IsMainThread()); - - main().layer_tree_host->RequestNewCompositorFrameSink(); -} - -void RemoteChannelImpl::DidInitializeCompositorFrameSinkOnMain(bool success) { - DCHECK(task_runner_provider_->IsMainThread()); - - if (!success) { - main().layer_tree_host->DidFailToInitializeCompositorFrameSink(); - return; - } - - VLOG(1) << "CompositorFrameSink initialized successfully"; - main().layer_tree_host->DidInitializeCompositorFrameSink(); - - // If we were waiting for CompositorFrameSink initialization, we might have - // queued some messages. Relay them now that a new CompositorFrameSink has - // been initialized. - main().waiting_for_compositor_frame_sink_initialization = false; - while (!main().pending_messages.empty()) { - VLOG(1) << "Handling queued message"; - HandleProto(main().pending_messages.front()); - main().pending_messages.pop(); - } - - // The commit after a new CompositorFrameSink can early out, in which case we - // will never redraw. Schedule one just to be safe. - PostSetNeedsRedrawToImpl(gfx::Rect( - main().layer_tree_host->GetLayerTree()->device_viewport_size())); -} - -void RemoteChannelImpl::SendMessageProtoOnMain( - std::unique_ptr<proto::CompositorMessage> proto) { - DCHECK(task_runner_provider_->IsMainThread()); - VLOG(1) << "Sending BeginMainFrame request to the engine."; - - main().remote_proto_channel->SendCompositorProto(*proto); -} - -void RemoteChannelImpl::PostSetNeedsRedrawToImpl( - const gfx::Rect& damaged_rect) { - DCHECK(task_runner_provider_->IsMainThread()); - - ImplThreadTaskRunner()->PostTask( - FROM_HERE, base::Bind(&ProxyImpl::SetNeedsRedrawOnImpl, - proxy_impl_weak_ptr_, damaged_rect)); -} - -void RemoteChannelImpl::InitializeImplOnImpl( - CompletionEvent* completion, - LayerTreeHostInProcess* layer_tree_host) { - DCHECK(task_runner_provider_->IsMainThreadBlocked()); - DCHECK(task_runner_provider_->IsImplThread()); - - impl().proxy_impl = - CreateProxyImpl(this, layer_tree_host, task_runner_provider_); - impl().proxy_impl_weak_factory = - base::MakeUnique<base::WeakPtrFactory<ProxyImpl>>( - impl().proxy_impl.get()); - proxy_impl_weak_ptr_ = impl().proxy_impl_weak_factory->GetWeakPtr(); - completion->Signal(); -} - -void RemoteChannelImpl::ShutdownImplOnImpl(CompletionEvent* completion) { - DCHECK(task_runner_provider_->IsMainThreadBlocked()); - DCHECK(task_runner_provider_->IsImplThread()); - - // We must invalidate the proxy_impl weak ptrs and destroy the weak ptr - // factory before destroying proxy_impl. - impl().proxy_impl_weak_factory->InvalidateWeakPtrs(); - impl().proxy_impl_weak_factory.reset(); - - impl().proxy_impl.reset(); - completion->Signal(); -} - -RemoteChannelImpl::MainThreadOnly& RemoteChannelImpl::main() { - DCHECK(task_runner_provider_->IsMainThread()); - return main_thread_vars_unsafe_; -} - -const RemoteChannelImpl::MainThreadOnly& RemoteChannelImpl::main() const { - DCHECK(task_runner_provider_->IsMainThread()); - return main_thread_vars_unsafe_; -} - -RemoteChannelImpl::CompositorThreadOnly& RemoteChannelImpl::impl() { - DCHECK(task_runner_provider_->IsImplThread()); - return compositor_thread_vars_unsafe_; -} - -const RemoteChannelImpl::CompositorThreadOnly& RemoteChannelImpl::impl() const { - DCHECK(task_runner_provider_->IsImplThread()); - return compositor_thread_vars_unsafe_; -} - -base::SingleThreadTaskRunner* RemoteChannelImpl::MainThreadTaskRunner() const { - return task_runner_provider_->MainThreadTaskRunner(); -} - -base::SingleThreadTaskRunner* RemoteChannelImpl::ImplThreadTaskRunner() const { - return task_runner_provider_->ImplThreadTaskRunner(); -} - -RemoteChannelImpl::MainThreadOnly::MainThreadOnly( - RemoteChannelImpl* remote_channel_impl, - LayerTreeHostInProcess* layer_tree_host, - RemoteProtoChannel* remote_proto_channel) - : layer_tree_host(layer_tree_host), - remote_proto_channel(remote_proto_channel), - started(false), - waiting_for_compositor_frame_sink_initialization(false), - remote_channel_weak_factory(remote_channel_impl) { - DCHECK(layer_tree_host); - DCHECK(remote_proto_channel); -} - -RemoteChannelImpl::MainThreadOnly::~MainThreadOnly() {} - -RemoteChannelImpl::CompositorThreadOnly::CompositorThreadOnly( - base::WeakPtr<RemoteChannelImpl> remote_channel_weak_ptr) - : proxy_impl(nullptr), - proxy_impl_weak_factory(nullptr), - remote_channel_weak_ptr(remote_channel_weak_ptr) {} - -RemoteChannelImpl::CompositorThreadOnly::~CompositorThreadOnly() {} - -} // namespace cc diff --git a/chromium/cc/trees/remote_channel_impl.h b/chromium/cc/trees/remote_channel_impl.h deleted file mode 100644 index f77a53efd3d..00000000000 --- a/chromium/cc/trees/remote_channel_impl.h +++ /dev/null @@ -1,208 +0,0 @@ -// Copyright 2016 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. - -#ifndef CC_TREES_REMOTE_CHANNEL_IMPL_H_ -#define CC_TREES_REMOTE_CHANNEL_IMPL_H_ - -#include <queue> - -#include "base/macros.h" -#include "base/memory/weak_ptr.h" -#include "cc/base/cc_export.h" -#include "cc/base/completion_event.h" -#include "cc/proto/compositor_message_to_impl.pb.h" -#include "cc/trees/channel_impl.h" -#include "cc/trees/proxy.h" -#include "cc/trees/proxy_impl.h" -#include "cc/trees/remote_proto_channel.h" - -namespace cc { -class LayerTreeHostInProcess; - -namespace proto { -class CompositorMessage; -class CompositorMessageToImpl; -class CompositorMessageToMain; -} - -// The Proxy and ChannelImpl implementation for the remote compositor. -// The object life cycle and communication across threads is as follows: -// -// The RemoteChannelImpl is created by the remote client LayerTreeHost, which -// initializes the impl side of the compositor. -// -// Main Thread | Impl Thread -// | -// Proxy::Start | -// | | -// | RemoteChannelImpl -// --------------------------------------------------------------------------- -// RemoteChannelImpl::Start()---PostTask---> RemoteChannelImpl:: -// InitializeImplOnImpl -// | -// ProxyImpl::Create -// | -// . -// . -// ProxyImpl::ScheduledActionBegin -// CompositorFrameSinkCreation -// | -// ChannelImpl::RequestNewCompositorFrameSink -// | -// RemoteChannelImpl:: | -// RequestNewCompositorFrameSink()<----PostTask-------------- -// . -// . -// | -// RemoteChannelImpl:: -// ~RemoteChannelImpl() ---PostTask---> RemoteChannelImpl:: -// ShutdownImplOnImpl -// ---------------------------------------------------------------------------- -// -// The class is created and destroyed on the main thread but can be safely -// called from the main or impl thread. It is safe to call RemoteChannelImpl on -// the impl thread since: -// 1) The only impl threaded callers of RemoteChannelImpl is the -// RemoteChannelImpl itself and ProxyImpl which is created and owned by the -// RemoteChannelImpl. -// 2) The RemoteChannelImpl blocks the main thread in its dtor to wait for the -// impl-thread teardown to complete, which ensures that any tasks queued to call -// it on the impl thread are run before it is destroyed on the main thread. -// -// The RemoteChannelImpl receives and processes messages from the remote server -// compositor on the main thread. The requests from ProxyImpl are received on -// the impl thread which may be directed to the LayerTreeHostInProcesson the -// client (for instance output surface requests) or sent to the -// LayerTreeHostInProcess on the server. The messages to the server are created -// on the impl thread and sent using the RemoteProtoChannel on the main thread. -class CC_EXPORT RemoteChannelImpl : public ChannelImpl, - public RemoteProtoChannel::ProtoReceiver, - public Proxy { - public: - RemoteChannelImpl(LayerTreeHostInProcess* layer_tree_host, - RemoteProtoChannel* remote_proto_channel, - TaskRunnerProvider* task_runner_provider); - ~RemoteChannelImpl() override; - - // virtual for testing. - virtual std::unique_ptr<ProxyImpl> CreateProxyImpl( - ChannelImpl* channel_impl, - LayerTreeHostInProcess* layer_tree_host, - TaskRunnerProvider* task_runner_provider); - - private: - struct MainThreadOnly { - LayerTreeHostInProcess* layer_tree_host; - RemoteProtoChannel* remote_proto_channel; - - bool started; - - // This is set to true if we lost the output surface and can not push any - // commits to the impl thread. - bool waiting_for_compositor_frame_sink_initialization; - - // The queue of messages received from the server. The messages are added to - // this queue if we are waiting for a new output surface to be initialized. - std::queue<proto::CompositorMessageToImpl> pending_messages; - - base::WeakPtrFactory<RemoteChannelImpl> remote_channel_weak_factory; - - MainThreadOnly(RemoteChannelImpl*, - LayerTreeHostInProcess* layer_tree_host, - RemoteProtoChannel* remote_proto_channel); - ~MainThreadOnly(); - }; - - struct CompositorThreadOnly { - std::unique_ptr<ProxyImpl> proxy_impl; - std::unique_ptr<base::WeakPtrFactory<ProxyImpl>> proxy_impl_weak_factory; - base::WeakPtr<RemoteChannelImpl> remote_channel_weak_ptr; - - CompositorThreadOnly( - base::WeakPtr<RemoteChannelImpl> remote_channel_weak_ptr); - ~CompositorThreadOnly(); - }; - - // called on main thread. - // RemoteProtoChannel::ProtoReceiver implementation. - void OnProtoReceived( - std::unique_ptr<proto::CompositorMessage> proto) override; - - // Proxy implementation - bool IsStarted() const override; - bool CommitToActiveTree() const override; - void SetCompositorFrameSink( - CompositorFrameSink* compositor_frame_sink) override; - void ReleaseCompositorFrameSink() override; - void SetVisible(bool visible) override; - void SetNeedsAnimate() override; - void SetNeedsUpdateLayers() override; - void SetNeedsCommit() override; - void SetNeedsRedraw(const gfx::Rect& damage_rect) override; - void SetNextCommitWaitsForActivation() override; - void NotifyInputThrottledUntilCommit() override; - void SetDeferCommits(bool defer_commits) override; - void MainThreadHasStoppedFlinging() override; - bool CommitRequested() const override; - bool BeginMainFrameRequested() const override; - void Start() override; - void Stop() override; - void SetMutator(std::unique_ptr<LayerTreeMutator> mutator) override; - bool SupportsImplScrolling() const override; - void UpdateTopControlsState(TopControlsState constraints, - TopControlsState current, - bool animate) override; - bool MainFrameWillHappenForTesting() override; - - // Called on impl thread. - // ChannelImpl implementation - void DidCompleteSwapBuffers() override; - void BeginMainFrameNotExpectedSoon() override; - void DidCommitAndDrawFrame() override; - void SetAnimationEvents(std::unique_ptr<AnimationEvents> queue) override; - void DidLoseCompositorFrameSink() override; - void RequestNewCompositorFrameSink() override; - void DidInitializeCompositorFrameSink(bool success) override; - void DidCompletePageScaleAnimation() override; - void BeginMainFrame(std::unique_ptr<BeginMainFrameAndCommitState> - begin_main_frame_state) override; - - void SendMessageProto(std::unique_ptr<proto::CompositorMessage> proto); - - // called on main thread. - void HandleProto(const proto::CompositorMessageToImpl& proto); - void DidCompleteSwapBuffersOnMain(); - void DidCommitAndDrawFrameOnMain(); - void DidLoseCompositorFrameSinkOnMain(); - void RequestNewCompositorFrameSinkOnMain(); - void DidInitializeCompositorFrameSinkOnMain(bool success); - void SendMessageProtoOnMain(std::unique_ptr<proto::CompositorMessage> proto); - void PostSetNeedsRedrawToImpl(const gfx::Rect& damaged_rect); - - void InitializeImplOnImpl(CompletionEvent* completion, - LayerTreeHostInProcess* layer_tree_host); - void ShutdownImplOnImpl(CompletionEvent* completion); - - MainThreadOnly& main(); - const MainThreadOnly& main() const; - CompositorThreadOnly& impl(); - const CompositorThreadOnly& impl() const; - - base::SingleThreadTaskRunner* MainThreadTaskRunner() const; - base::SingleThreadTaskRunner* ImplThreadTaskRunner() const; - - TaskRunnerProvider* task_runner_provider_; - - // use accessors instead of these variables directly - MainThreadOnly main_thread_vars_unsafe_; - CompositorThreadOnly compositor_thread_vars_unsafe_; - - base::WeakPtr<ProxyImpl> proxy_impl_weak_ptr_; - - DISALLOW_COPY_AND_ASSIGN(RemoteChannelImpl); -}; - -} // namespace cc - -#endif // CC_TREES_REMOTE_CHANNEL_IMPL_H_ diff --git a/chromium/cc/trees/remote_channel_main.cc b/chromium/cc/trees/remote_channel_main.cc deleted file mode 100644 index 6b490697a04..00000000000 --- a/chromium/cc/trees/remote_channel_main.cc +++ /dev/null @@ -1,278 +0,0 @@ -// Copyright 2016 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. - -#include "cc/trees/remote_channel_main.h" - -#include <memory> - -#include "base/memory/ptr_util.h" -#include "cc/proto/base_conversions.h" -#include "cc/proto/compositor_message.pb.h" -#include "cc/proto/compositor_message_to_impl.pb.h" -#include "cc/proto/compositor_message_to_main.pb.h" -#include "cc/proto/gfx_conversions.h" -#include "cc/trees/layer_tree_host_in_process.h" -#include "cc/trees/proxy_main.h" - -namespace cc { - -std::unique_ptr<RemoteChannelMain> RemoteChannelMain::Create( - RemoteProtoChannel* remote_proto_channel, - ProxyMain* proxy_main, - TaskRunnerProvider* task_runner_provider) { - return base::WrapUnique(new RemoteChannelMain( - remote_proto_channel, proxy_main, task_runner_provider)); -} - -RemoteChannelMain::RemoteChannelMain(RemoteProtoChannel* remote_proto_channel, - ProxyMain* proxy_main, - TaskRunnerProvider* task_runner_provider) - : remote_proto_channel_(remote_proto_channel), - proxy_main_(proxy_main), - task_runner_provider_(task_runner_provider), - initialized_(false), - weak_factory_(this) { - TRACE_EVENT0("cc.remote", "RemoteChannelMain::RemoteChannelMain"); - DCHECK(remote_proto_channel_); - DCHECK(proxy_main_); - DCHECK(task_runner_provider_); - DCHECK(task_runner_provider_->IsMainThread()); - remote_proto_channel_->SetProtoReceiver(this); -} - -RemoteChannelMain::~RemoteChannelMain() { - TRACE_EVENT0("cc.remote", "~RemoteChannelMain::RemoteChannelMain"); - DCHECK(task_runner_provider_->IsMainThread()); - DCHECK(!initialized_); - - remote_proto_channel_->SetProtoReceiver(nullptr); -} - -void RemoteChannelMain::OnProtoReceived( - std::unique_ptr<proto::CompositorMessage> proto) { - TRACE_EVENT0("cc.remote", "RemoteChannelMain::OnProtoReceived"); - DCHECK(task_runner_provider_->IsMainThread()); - DCHECK(proto->has_to_main()); - - HandleProto(proto->to_main()); -} - -void RemoteChannelMain::UpdateTopControlsStateOnImpl( - TopControlsState constraints, - TopControlsState current, - bool animate) {} - -void RemoteChannelMain::InitializeCompositorFrameSinkOnImpl( - CompositorFrameSink*) { - NOTREACHED() << "Should not be called on the server LayerTreeHost"; -} - -void RemoteChannelMain::InitializeMutatorOnImpl( - std::unique_ptr<LayerTreeMutator> mutator) { - // TODO(vollick): add support for CompositorWorker. - NOTIMPLEMENTED(); -} - -void RemoteChannelMain::MainThreadHasStoppedFlingingOnImpl() { - NOTIMPLEMENTED(); -} - -void RemoteChannelMain::SetInputThrottledUntilCommitOnImpl(bool is_throttled) {} - -void RemoteChannelMain::SetDeferCommitsOnImpl(bool defer_commits) { - TRACE_EVENT1("cc.remote", "RemoteChannelMain::SetDeferCommitsOnImpl", - "defer_commits", defer_commits); - proto::CompositorMessage proto; - proto::CompositorMessageToImpl* to_impl_proto = proto.mutable_to_impl(); - to_impl_proto->set_message_type( - proto::CompositorMessageToImpl::SET_DEFER_COMMITS); - proto::SetDeferCommits* defer_commits_message = - to_impl_proto->mutable_defer_commits_message(); - defer_commits_message->set_defer_commits(defer_commits); - - VLOG(1) << "Sending defer commits: " << defer_commits << " to client."; - SendMessageProto(proto); -} - -void RemoteChannelMain::SetVisibleOnImpl(bool visible) { - NOTIMPLEMENTED() << "Visibility is not controlled by the server"; -} - -void RemoteChannelMain::ReleaseCompositorFrameSinkOnImpl( - CompletionEvent* completion) { - NOTREACHED() << "Should not be called on the server LayerTreeHost"; - completion->Signal(); -} - -void RemoteChannelMain::MainFrameWillHappenOnImplForTesting( - CompletionEvent* completion, - bool* main_frame_will_happen) { - // For the LayerTreeTests in remote mode, LayerTreeTest directly calls - // RemoteChannelImpl::MainFrameWillHappenForTesting and avoids adding a - // message type for tests to the compositor protocol. - NOTREACHED(); -} - -void RemoteChannelMain::SetNeedsRedrawOnImpl(const gfx::Rect& damage_rect) { - TRACE_EVENT0("cc.remote", "RemoteChannelMain::SetNeedsRedrawOnImpl"); - proto::CompositorMessage proto; - proto::CompositorMessageToImpl* to_impl_proto = proto.mutable_to_impl(); - to_impl_proto->set_message_type( - proto::CompositorMessageToImpl::SET_NEEDS_REDRAW); - proto::SetNeedsRedraw* set_needs_redraw_message = - to_impl_proto->mutable_set_needs_redraw_message(); - RectToProto(damage_rect, set_needs_redraw_message->mutable_damaged_rect()); - - VLOG(1) << "Sending redraw request to client."; - SendMessageProto(proto); - - // The client will not inform us when the frame buffers are swapped. - MainThreadTaskRunner()->PostTask( - FROM_HERE, base::Bind(&RemoteChannelMain::DidCompleteSwapBuffers, - weak_factory_.GetWeakPtr())); -} - -void RemoteChannelMain::SetNeedsCommitOnImpl() { - TRACE_EVENT0("cc.remote", "RemoteChannelMain::SetNeedsCommitOnImpl"); - proto::CompositorMessage proto; - proto::CompositorMessageToImpl* to_impl_proto = proto.mutable_to_impl(); - to_impl_proto->set_message_type( - proto::CompositorMessageToImpl::SET_NEEDS_COMMIT); - - VLOG(1) << "Sending commit request to client."; - SendMessageProto(proto); -} - -void RemoteChannelMain::BeginMainFrameAbortedOnImpl( - CommitEarlyOutReason reason, - base::TimeTicks main_thread_start_time, - std::vector<std::unique_ptr<SwapPromise>> swap_promises) { - TRACE_EVENT1("cc.remote", "RemoteChannelMain::BeginMainFrameAbortedOnImpl", - "reason", CommitEarlyOutReasonToString(reason)); - proto::CompositorMessage proto; - proto::CompositorMessageToImpl* to_impl_proto = proto.mutable_to_impl(); - to_impl_proto->set_message_type( - proto::CompositorMessageToImpl::BEGIN_MAIN_FRAME_ABORTED); - proto::BeginMainFrameAborted* begin_main_frame_aborted_message = - to_impl_proto->mutable_begin_main_frame_aborted_message(); - CommitEarlyOutReasonToProtobuf( - reason, begin_main_frame_aborted_message->mutable_reason()); - - VLOG(1) << "Sending BeginMainFrameAborted message to client with reason: " - << CommitEarlyOutReasonToString(reason); - SendMessageProto(proto); - - // Notify swap promises that commit had no updates. In the local compositor - // case this goes to the impl thread to be queued up in case we have an - // activation pending but that never happens for remote compositor. - for (const auto& swap_promise : swap_promises) - swap_promise->DidNotSwap(SwapPromise::COMMIT_NO_UPDATE); -} - -void RemoteChannelMain::NotifyReadyToCommitOnImpl( - CompletionEvent* completion, - LayerTreeHostInProcess* layer_tree_host, - base::TimeTicks main_thread_start_time, - bool hold_commit_for_activation) { - TRACE_EVENT0("cc.remote", "RemoteChannelMain::NotifyReadyToCommitOnImpl"); - proto::CompositorMessage proto; - proto::CompositorMessageToImpl* to_impl_proto = proto.mutable_to_impl(); - to_impl_proto->set_message_type(proto::CompositorMessageToImpl::START_COMMIT); - proto::StartCommit* start_commit_message = - to_impl_proto->mutable_start_commit_message(); - std::vector<std::unique_ptr<SwapPromise>> swap_promises; - layer_tree_host->ToProtobufForCommit( - start_commit_message->mutable_layer_tree_host(), &swap_promises); - - VLOG(1) << "Sending commit message to client. Commit bytes size: " - << proto.ByteSize(); - SendMessageProto(proto); - - // Activate the swap promises after the commit is queued. - // In the threaded compositor, activation implies that the pending tree on the - // impl thread has been activated. While the impl thread for the remote - // compositor is on the client, the embedder still expects to receive these - // events in order to drive decisions that depend on impl frame production. - // So we dispatch these events after a commit message is sent to the client. - // Sending the commit message implies that a visual update has been queued for - // the client, which is the closest we can come to offering an indicator akin - // to an impl frame queued for display. - for (const auto& swap_promise : swap_promises) - swap_promise->DidActivate(); - - // In order to avoid incurring the overhead for the client to send us a - // message for when a frame to be committed is drawn we inform the embedder - // that the draw was successful immediately after sending the commit message. - // Since the compositing state may be used by the embedder to throttle - // commit/draw requests, it is better to allow them to propagate rather than - // incurring a round-trip to get Acks for draw from the client for each frame. - - // This is done as a separate PostTask to ensure that these calls run after - // LayerTreeHostClient::DidCommit and stay consistent with the - // behaviour in the threaded compositor. - MainThreadTaskRunner()->PostTask( - FROM_HERE, base::Bind(&RemoteChannelMain::DidCommitAndDrawFrame, - weak_factory_.GetWeakPtr())); - - completion->Signal(); -} - -void RemoteChannelMain::SynchronouslyInitializeImpl( - LayerTreeHostInProcess* layer_tree_host) { - TRACE_EVENT0("cc.remote", "RemoteChannelMain::SynchronouslyInitializeImpl"); - DCHECK(!initialized_); - - initialized_ = true; -} - -void RemoteChannelMain::SynchronouslyCloseImpl() { - TRACE_EVENT0("cc.remote", "RemoteChannelMain::SynchronouslyCloseImpl"); - DCHECK(initialized_); - - initialized_ = false; -} - -void RemoteChannelMain::SendMessageProto( - const proto::CompositorMessage& proto) { - TRACE_EVENT0("cc.remote", "RemoteChannelMain::SendMessageProto"); - remote_proto_channel_->SendCompositorProto(proto); -} - -void RemoteChannelMain::HandleProto( - const proto::CompositorMessageToMain& proto) { - TRACE_EVENT0("cc.remote", "RemoteChannelMain::HandleProto"); - DCHECK(proto.has_message_type()); - - switch (proto.message_type()) { - case proto::CompositorMessageToMain::UNKNOWN: - NOTIMPLEMENTED() << "Ignoring message proto of unknown type"; - break; - case proto::CompositorMessageToMain::BEGIN_MAIN_FRAME: { - TRACE_EVENT0("cc.remote", "RemoteChannelMain::BeginMainFrame"); - VLOG(1) << "Received BeginMainFrame request from client."; - const proto::BeginMainFrame& begin_main_frame_message = - proto.begin_main_frame_message(); - std::unique_ptr<BeginMainFrameAndCommitState> begin_main_frame_state; - begin_main_frame_state.reset(new BeginMainFrameAndCommitState); - begin_main_frame_state->FromProtobuf( - begin_main_frame_message.begin_main_frame_state()); - proxy_main_->BeginMainFrame(std::move(begin_main_frame_state)); - } break; - } -} - -void RemoteChannelMain::DidCommitAndDrawFrame() { - proxy_main_->DidCommitAndDrawFrame(); - DidCompleteSwapBuffers(); -} - -void RemoteChannelMain::DidCompleteSwapBuffers() { - proxy_main_->DidCompleteSwapBuffers(); -} - -base::SingleThreadTaskRunner* RemoteChannelMain::MainThreadTaskRunner() const { - return task_runner_provider_->MainThreadTaskRunner(); -} - -} // namespace cc diff --git a/chromium/cc/trees/remote_channel_main.h b/chromium/cc/trees/remote_channel_main.h deleted file mode 100644 index 43e49c6225a..00000000000 --- a/chromium/cc/trees/remote_channel_main.h +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright 2016 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. - -#ifndef CC_TREES_REMOTE_CHANNEL_MAIN_H_ -#define CC_TREES_REMOTE_CHANNEL_MAIN_H_ - -#include "base/macros.h" -#include "cc/base/cc_export.h" -#include "cc/trees/channel_main.h" -#include "cc/trees/remote_proto_channel.h" -#include "cc/trees/task_runner_provider.h" - -namespace cc { -class ProxyMain; - -namespace proto { -class CompositorMessage; -class CompositorMessageToMain; -} - -class CC_EXPORT RemoteChannelMain : public ChannelMain, - public RemoteProtoChannel::ProtoReceiver { - public: - static std::unique_ptr<RemoteChannelMain> Create( - RemoteProtoChannel* remote_proto_channel, - ProxyMain* proxy_main, - TaskRunnerProvider* task_runner_provider); - - ~RemoteChannelMain() override; - - // ChannelMain implementation - void UpdateTopControlsStateOnImpl(TopControlsState constraints, - TopControlsState current, - bool animate) override; - void InitializeCompositorFrameSinkOnImpl(CompositorFrameSink*) override; - void InitializeMutatorOnImpl( - std::unique_ptr<LayerTreeMutator> mutator) override; - void MainThreadHasStoppedFlingingOnImpl() override; - void SetInputThrottledUntilCommitOnImpl(bool is_throttled) override; - void SetDeferCommitsOnImpl(bool defer_commits) override; - void SetVisibleOnImpl(bool visible) override; - void ReleaseCompositorFrameSinkOnImpl(CompletionEvent* completion) override; - void MainFrameWillHappenOnImplForTesting( - CompletionEvent* completion, - bool* main_frame_will_happen) override; - void SetNeedsRedrawOnImpl(const gfx::Rect& damage_rect) override; - void SetNeedsCommitOnImpl() override; - void BeginMainFrameAbortedOnImpl( - CommitEarlyOutReason reason, - base::TimeTicks main_thread_start_time, - std::vector<std::unique_ptr<SwapPromise>> swap_promises) override; - void NotifyReadyToCommitOnImpl(CompletionEvent* completion, - LayerTreeHostInProcess* layer_tree_host, - base::TimeTicks main_thread_start_time, - bool hold_commit_for_activation) override; - void SynchronouslyInitializeImpl( - LayerTreeHostInProcess* layer_tree_host) override; - void SynchronouslyCloseImpl() override; - - // RemoteProtoChannel::ProtoReceiver implementation - void OnProtoReceived( - std::unique_ptr<proto::CompositorMessage> proto) override; - - protected: - RemoteChannelMain(RemoteProtoChannel* remote_proto_channel, - ProxyMain* proxy_main, - TaskRunnerProvider* task_runner_provider); - - private: - void SendMessageProto(const proto::CompositorMessage& proto); - void HandleProto(const proto::CompositorMessageToMain& proto); - void DidCommitAndDrawFrame(); - void DidCompleteSwapBuffers(); - - base::SingleThreadTaskRunner* MainThreadTaskRunner() const; - - RemoteProtoChannel* remote_proto_channel_; - ProxyMain* proxy_main_; - TaskRunnerProvider* task_runner_provider_; - - bool initialized_; - - base::WeakPtrFactory<RemoteChannelMain> weak_factory_; - - DISALLOW_COPY_AND_ASSIGN(RemoteChannelMain); -}; - -} // namespace cc - -#endif // CC_TREES_REMOTE_CHANNEL_MAIN_H_ diff --git a/chromium/cc/trees/remote_proto_channel.h b/chromium/cc/trees/remote_proto_channel.h deleted file mode 100644 index 8f7ad099a13..00000000000 --- a/chromium/cc/trees/remote_proto_channel.h +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2015 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. - -#ifndef CC_TREES_REMOTE_PROTO_CHANNEL_H_ -#define CC_TREES_REMOTE_PROTO_CHANNEL_H_ - -#include <memory> - -#include "cc/base/cc_export.h" - -namespace cc { - -namespace proto { -class CompositorMessage; -} - -// Provides a bridge for getting compositor protobuf messages to/from the -// outside world. -class CC_EXPORT RemoteProtoChannel { - public: - // Meant to be implemented by a RemoteChannel that needs to receive and parse - // incoming protobufs. - class CC_EXPORT ProtoReceiver { - public: - // TODO(khushalsagar): This should probably include a closure that returns - // the status of processing this proto. See crbug/576974 - virtual void OnProtoReceived( - std::unique_ptr<proto::CompositorMessage> proto) = 0; - - protected: - virtual ~ProtoReceiver() {} - }; - - // Called by the ProtoReceiver. The RemoteProtoChannel must outlive its - // receiver. - virtual void SetProtoReceiver(ProtoReceiver* receiver) = 0; - - virtual void SendCompositorProto(const proto::CompositorMessage& proto) = 0; - - protected: - virtual ~RemoteProtoChannel() {} -}; - -} // namespace cc - -#endif // CC_TREES_REMOTE_PROTO_CHANNEL_H_ diff --git a/chromium/cc/trees/scroll_node.cc b/chromium/cc/trees/scroll_node.cc index a20fe2f84f6..5da6957545a 100644 --- a/chromium/cc/trees/scroll_node.cc +++ b/chromium/cc/trees/scroll_node.cc @@ -3,11 +3,10 @@ // found in the LICENSE file. #include "base/trace_event/trace_event_argument.h" -#include "cc/animation/element_id.h" #include "cc/base/math_util.h" #include "cc/input/main_thread_scrolling_reason.h" #include "cc/proto/gfx_conversions.h" -#include "cc/proto/property_tree.pb.h" +#include "cc/trees/element_id.h" #include "cc/trees/scroll_node.h" namespace cc { @@ -26,8 +25,7 @@ ScrollNode::ScrollNode() should_flatten(false), user_scrollable_horizontal(false), user_scrollable_vertical(false), - transform_id(0), - num_drawn_descendants(0) {} + transform_id(0) {} ScrollNode::ScrollNode(const ScrollNode& other) = default; @@ -52,60 +50,6 @@ bool ScrollNode::operator==(const ScrollNode& other) const { element_id == other.element_id && transform_id == other.transform_id; } -void ScrollNode::ToProtobuf(proto::TreeNode* proto) const { - proto->set_id(id); - proto->set_parent_id(parent_id); - proto->set_owner_id(owner_id); - - DCHECK(!proto->has_scroll_node_data()); - proto::ScrollNodeData* data = proto->mutable_scroll_node_data(); - data->set_scrollable(scrollable); - data->set_main_thread_scrolling_reasons(main_thread_scrolling_reasons); - data->set_contains_non_fast_scrollable_region( - contains_non_fast_scrollable_region); - SizeToProto(scroll_clip_layer_bounds, - data->mutable_scroll_clip_layer_bounds()); - SizeToProto(bounds, data->mutable_bounds()); - data->set_max_scroll_offset_affected_by_page_scale( - max_scroll_offset_affected_by_page_scale); - data->set_is_inner_viewport_scroll_layer(is_inner_viewport_scroll_layer); - data->set_is_outer_viewport_scroll_layer(is_outer_viewport_scroll_layer); - Vector2dFToProto(offset_to_transform_parent, - data->mutable_offset_to_transform_parent()); - data->set_should_flatten(should_flatten); - data->set_user_scrollable_horizontal(user_scrollable_horizontal); - data->set_user_scrollable_vertical(user_scrollable_vertical); - element_id.ToProtobuf(data->mutable_element_id()); - data->set_transform_id(transform_id); -} - -void ScrollNode::FromProtobuf(const proto::TreeNode& proto) { - id = proto.id(); - parent_id = proto.parent_id(); - owner_id = proto.owner_id(); - - DCHECK(proto.has_scroll_node_data()); - const proto::ScrollNodeData& data = proto.scroll_node_data(); - - scrollable = data.scrollable(); - main_thread_scrolling_reasons = data.main_thread_scrolling_reasons(); - contains_non_fast_scrollable_region = - data.contains_non_fast_scrollable_region(); - scroll_clip_layer_bounds = ProtoToSize(data.scroll_clip_layer_bounds()); - bounds = ProtoToSize(data.bounds()); - max_scroll_offset_affected_by_page_scale = - data.max_scroll_offset_affected_by_page_scale(); - is_inner_viewport_scroll_layer = data.is_inner_viewport_scroll_layer(); - is_outer_viewport_scroll_layer = data.is_outer_viewport_scroll_layer(); - offset_to_transform_parent = - ProtoToVector2dF(data.offset_to_transform_parent()); - should_flatten = data.should_flatten(); - user_scrollable_horizontal = data.user_scrollable_horizontal(); - user_scrollable_vertical = data.user_scrollable_vertical(); - element_id.FromProtobuf(data.element_id()); - transform_id = data.transform_id(); -} - void ScrollNode::AsValueInto(base::trace_event::TracedValue* value) const { value->SetInteger("id", id); value->SetInteger("parent_id", parent_id); diff --git a/chromium/cc/trees/scroll_node.h b/chromium/cc/trees/scroll_node.h index 05154e43ea6..f68fd59e1e1 100644 --- a/chromium/cc/trees/scroll_node.h +++ b/chromium/cc/trees/scroll_node.h @@ -17,10 +17,6 @@ class TracedValue; namespace cc { -namespace proto { -class TreeNode; -} // namespace proto - struct CC_EXPORT ScrollNode { ScrollNode(); ScrollNode(const ScrollNode& other); @@ -61,13 +57,8 @@ struct CC_EXPORT ScrollNode { bool user_scrollable_vertical; ElementId element_id; int transform_id; - // Number of drawn layers pointing to this node or any of its descendants. - int num_drawn_descendants; bool operator==(const ScrollNode& other) const; - - void ToProtobuf(proto::TreeNode* proto) const; - void FromProtobuf(const proto::TreeNode& proto); void AsValueInto(base::trace_event::TracedValue* value) const; }; diff --git a/chromium/cc/trees/single_thread_proxy.cc b/chromium/cc/trees/single_thread_proxy.cc index 901f3960729..593a7dc0629 100644 --- a/chromium/cc/trees/single_thread_proxy.cc +++ b/chromium/cc/trees/single_thread_proxy.cc @@ -8,7 +8,6 @@ #include "base/memory/ptr_util.h" #include "base/profiler/scoped_tracker.h" #include "base/trace_event/trace_event.h" -#include "cc/animation/animation_events.h" #include "cc/debug/benchmark_instrumentation.h" #include "cc/debug/devtools_instrumentation.h" #include "cc/output/compositor_frame_sink.h" @@ -23,6 +22,7 @@ #include "cc/trees/layer_tree_host_in_process.h" #include "cc/trees/layer_tree_host_single_thread_client.h" #include "cc/trees/layer_tree_impl.h" +#include "cc/trees/mutator_host.h" #include "cc/trees/scoped_abort_remaining_swap_promises.h" namespace cc { @@ -39,7 +39,7 @@ SingleThreadProxy::SingleThreadProxy(LayerTreeHostInProcess* layer_tree_host, LayerTreeHostSingleThreadClient* client, TaskRunnerProvider* task_runner_provider) : layer_tree_host_(layer_tree_host), - client_(client), + single_thread_client_(client), task_runner_provider_(task_runner_provider), next_frame_is_newly_committed_frame_(false), #if DCHECK_IS_ON() @@ -156,7 +156,7 @@ void SingleThreadProxy::SetCompositorFrameSink( void SingleThreadProxy::SetNeedsAnimate() { TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsAnimate"); DCHECK(task_runner_provider_->IsMainThread()); - client_->RequestScheduleAnimation(); + single_thread_client_->RequestScheduleAnimation(); if (animate_requested_) return; animate_requested_ = true; @@ -229,7 +229,7 @@ void SingleThreadProxy::CommitComplete() { void SingleThreadProxy::SetNeedsCommit() { DCHECK(task_runner_provider_->IsMainThread()); - client_->RequestScheduleComposite(); + single_thread_client_->RequestScheduleComposite(); if (commit_requested_) return; commit_requested_ = true; @@ -289,16 +289,17 @@ void SingleThreadProxy::Stop() { DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); DebugScopedSetImplThread impl(task_runner_provider_); + // Prevent the scheduler from performing actions while we're in an + // inconsistent state. + if (scheduler_on_impl_thread_) + scheduler_on_impl_thread_->Stop(); // Take away the CompositorFrameSink before destroying things so it doesn't // try to call into its client mid-shutdown. layer_tree_host_impl_->ReleaseCompositorFrameSink(); - - BlockingTaskRunner::CapturePostTasks blocked( - task_runner_provider_->blocking_main_thread_task_runner()); scheduler_on_impl_thread_ = nullptr; layer_tree_host_impl_ = nullptr; } - layer_tree_host_ = NULL; + layer_tree_host_ = nullptr; } void SingleThreadProxy::SetMutator(std::unique_ptr<LayerTreeMutator> mutator) { @@ -330,7 +331,7 @@ void SingleThreadProxy::NotifyReadyToDraw() { } void SingleThreadProxy::SetNeedsRedrawOnImplThread() { - client_->RequestScheduleComposite(); + single_thread_client_->RequestScheduleComposite(); if (scheduler_on_impl_thread_) scheduler_on_impl_thread_->SetNeedsRedraw(); } @@ -338,7 +339,7 @@ void SingleThreadProxy::SetNeedsRedrawOnImplThread() { void SingleThreadProxy::SetNeedsOneBeginImplFrameOnImplThread() { TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsOneBeginImplFrameOnImplThread"); - client_->RequestScheduleComposite(); + single_thread_client_->RequestScheduleComposite(); if (scheduler_on_impl_thread_) scheduler_on_impl_thread_->SetNeedsOneBeginImplFrame(); } @@ -350,7 +351,7 @@ void SingleThreadProxy::SetNeedsPrepareTilesOnImplThread() { } void SingleThreadProxy::SetNeedsCommitOnImplThread() { - client_->RequestScheduleComposite(); + single_thread_client_->RequestScheduleComposite(); if (scheduler_on_impl_thread_) scheduler_on_impl_thread_->SetNeedsBeginMainFrame(); } @@ -364,7 +365,7 @@ void SingleThreadProxy::SetVideoNeedsBeginFrames(bool needs_begin_frames) { } void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread( - std::unique_ptr<AnimationEvents> events) { + std::unique_ptr<MutatorEvents> events) { TRACE_EVENT0( "cc", "SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread"); DCHECK(task_runner_provider_->IsImplThread()); @@ -408,7 +409,7 @@ void SingleThreadProxy::DidLoseCompositorFrameSinkOnImplThread() { // the output surface if already in BEGIN_IMPL_FRAME_STATE_IDLE. layer_tree_host_->DidLoseCompositorFrameSink(); } - client_->DidAbortSwapBuffers(); + single_thread_client_->DidLoseCompositorFrameSink(); if (scheduler_on_impl_thread_) scheduler_on_impl_thread_->DidLoseCompositorFrameSink(); compositor_frame_sink_lost_ = true; @@ -419,12 +420,12 @@ void SingleThreadProxy::SetBeginFrameSource(BeginFrameSource* source) { scheduler_on_impl_thread_->SetBeginFrameSource(source); } -void SingleThreadProxy::DidSwapBuffersCompleteOnImplThread() { +void SingleThreadProxy::DidReceiveCompositorFrameAckOnImplThread() { TRACE_EVENT0("cc,benchmark", - "SingleThreadProxy::DidSwapBuffersCompleteOnImplThread"); + "SingleThreadProxy::DidReceiveCompositorFrameAckOnImplThread"); if (scheduler_on_impl_thread_) - scheduler_on_impl_thread_->DidSwapBuffersComplete(); - layer_tree_host_->DidCompleteSwapBuffers(); + scheduler_on_impl_thread_->DidReceiveCompositorFrameAck(); + layer_tree_host_->DidReceiveCompositorFrameAck(); } void SingleThreadProxy::OnDrawForCompositorFrameSink( @@ -549,8 +550,9 @@ DrawResult SingleThreadProxy::DoComposite(LayerTreeHostImpl::FrameData* frame) { if (draw_frame) { if (layer_tree_host_impl_->DrawLayers(frame)) { if (scheduler_on_impl_thread_) - scheduler_on_impl_thread_->DidSwapBuffers(); - client_->DidPostSwapBuffers(); + // Drawing implies we submitted a frame to the CompositorFrameSink. + scheduler_on_impl_thread_->DidSubmitCompositorFrame(); + single_thread_client_->DidSubmitCompositorFrame(); } } layer_tree_host_impl_->DidDrawAllLayers(*frame); @@ -687,13 +689,13 @@ void SingleThreadProxy::BeginMainFrameAbortedOnImplThread( scheduler_on_impl_thread_->BeginMainFrameAborted(reason); } -DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapIfPossible() { +DrawResult SingleThreadProxy::ScheduledActionDrawIfPossible() { DebugScopedSetImplThread impl(task_runner_provider_); LayerTreeHostImpl::FrameData frame; return DoComposite(&frame); } -DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapForced() { +DrawResult SingleThreadProxy::ScheduledActionDrawForced() { NOTREACHED(); return INVALID_RESULT; } @@ -732,10 +734,11 @@ void SingleThreadProxy::ScheduledActionInvalidateCompositorFrameSink() { NOTREACHED(); } -void SingleThreadProxy::UpdateTopControlsState(TopControlsState constraints, - TopControlsState current, - bool animate) { - NOTREACHED() << "Top Controls are used only in threaded mode"; +void SingleThreadProxy::UpdateBrowserControlsState( + BrowserControlsState constraints, + BrowserControlsState current, + bool animate) { + NOTREACHED() << "Browser Controls are used only in threaded mode"; } void SingleThreadProxy::DidFinishImplFrame() { diff --git a/chromium/cc/trees/single_thread_proxy.h b/chromium/cc/trees/single_thread_proxy.h index 05aea535125..2fdcfd60798 100644 --- a/chromium/cc/trees/single_thread_proxy.h +++ b/chromium/cc/trees/single_thread_proxy.h @@ -19,9 +19,8 @@ namespace cc { -class AnimationEvents; +class MutatorEvents; class BeginFrameSource; -class ContextProvider; class LayerTreeHostInProcess; class LayerTreeHostSingleThreadClient; @@ -57,16 +56,16 @@ class CC_EXPORT SingleThreadProxy : public Proxy, void SetMutator(std::unique_ptr<LayerTreeMutator> mutator) override; bool SupportsImplScrolling() const override; bool MainFrameWillHappenForTesting() override; - void UpdateTopControlsState(TopControlsState constraints, - TopControlsState current, - bool animate) override; + void UpdateBrowserControlsState(BrowserControlsState constraints, + BrowserControlsState current, + bool animate) override; // SchedulerClient implementation void WillBeginImplFrame(const BeginFrameArgs& args) override; void DidFinishImplFrame() override; void ScheduledActionSendBeginMainFrame(const BeginFrameArgs& args) override; - DrawResult ScheduledActionDrawAndSwapIfPossible() override; - DrawResult ScheduledActionDrawAndSwapForced() override; + DrawResult ScheduledActionDrawIfPossible() override; + DrawResult ScheduledActionDrawForced() override; void ScheduledActionCommit() override; void ScheduledActionActivateSyncTree() override; void ScheduledActionBeginCompositorFrameSinkCreation() override; @@ -77,7 +76,7 @@ class CC_EXPORT SingleThreadProxy : public Proxy, // LayerTreeHostImplClient implementation void DidLoseCompositorFrameSinkOnImplThread() override; void SetBeginFrameSource(BeginFrameSource* source) override; - void DidSwapBuffersCompleteOnImplThread() override; + void DidReceiveCompositorFrameAckOnImplThread() override; void OnCanDrawStateChanged(bool can_draw) override; void NotifyReadyToActivate() override; void NotifyReadyToDraw() override; @@ -87,7 +86,7 @@ class CC_EXPORT SingleThreadProxy : public Proxy, void SetNeedsCommitOnImplThread() override; void SetVideoNeedsBeginFrames(bool needs_begin_frames) override; void PostAnimationEventsToMainThreadOnImplThread( - std::unique_ptr<AnimationEvents> events) override; + std::unique_ptr<MutatorEvents> events) override; bool IsInsideDraw() override; void RenewTreePriority() override {} void PostDelayedAnimationTaskOnImplThread(const base::Closure& task, @@ -123,7 +122,7 @@ class CC_EXPORT SingleThreadProxy : public Proxy, // Accessed on main thread only. LayerTreeHostInProcess* layer_tree_host_; - LayerTreeHostSingleThreadClient* client_; + LayerTreeHostSingleThreadClient* single_thread_client_; TaskRunnerProvider* task_runner_provider_; diff --git a/chromium/cc/trees/target_property.cc b/chromium/cc/trees/target_property.cc new file mode 100644 index 00000000000..cabff92b5a5 --- /dev/null +++ b/chromium/cc/trees/target_property.cc @@ -0,0 +1,31 @@ +// Copyright (c) 2016 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. + +#include "cc/trees/target_property.h" + +#include "base/macros.h" + +namespace cc { + +namespace { + +static_assert(TargetProperty::FIRST_TARGET_PROPERTY == 0, + "TargetProperty must be 0-based enum"); + +// This should match the TargetProperty enum. +static const char* const s_targetPropertyNames[] = { + "TRANSFORM", "OPACITY", "FILTER", "SCROLL_OFFSET", "BACKGROUND_COLOR"}; + +static_assert(static_cast<int>(TargetProperty::LAST_TARGET_PROPERTY) + 1 == + arraysize(s_targetPropertyNames), + "TargetPropertyEnumSize should equal the number of elements in " + "s_targetPropertyNames"); + +} // namespace + +const char* TargetProperty::GetName(TargetProperty::Type property) { + return s_targetPropertyNames[property]; +} + +} // namespace cc diff --git a/chromium/cc/trees/target_property.h b/chromium/cc/trees/target_property.h new file mode 100644 index 00000000000..34ddf3fd7cc --- /dev/null +++ b/chromium/cc/trees/target_property.h @@ -0,0 +1,34 @@ +// Copyright (c) 2016 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. + +#ifndef CC_TREES_TARGET_PROPERTY_H_ +#define CC_TREES_TARGET_PROPERTY_H_ + +#include <bitset> + +namespace cc { + +namespace TargetProperty { + +enum Type { + TRANSFORM = 0, + OPACITY, + FILTER, + SCROLL_OFFSET, + BACKGROUND_COLOR, + // These sentinels must be last + FIRST_TARGET_PROPERTY = TRANSFORM, + LAST_TARGET_PROPERTY = BACKGROUND_COLOR +}; + +const char* GetName(TargetProperty::Type property); + +} // namespace TargetProperty + +// A set of target properties. TargetProperty must be 0-based enum. +using TargetProperties = std::bitset<TargetProperty::LAST_TARGET_PROPERTY + 1>; + +} // namespace cc + +#endif // CC_TREES_TARGET_PROPERTY_H_ diff --git a/chromium/cc/trees/task_runner_provider.h b/chromium/cc/trees/task_runner_provider.h index 5092e533475..e4c7b195cc4 100644 --- a/chromium/cc/trees/task_runner_provider.h +++ b/chromium/cc/trees/task_runner_provider.h @@ -19,9 +19,6 @@ #include "cc/base/cc_export.h" namespace base { -namespace trace_event { -class TracedValue; -} class SingleThreadTaskRunner; } diff --git a/chromium/cc/trees/threaded_channel.cc b/chromium/cc/trees/threaded_channel.cc index 7ff17e1cccb..05bf230942a 100644 --- a/chromium/cc/trees/threaded_channel.cc +++ b/chromium/cc/trees/threaded_channel.cc @@ -9,9 +9,9 @@ #include "base/memory/ptr_util.h" #include "base/single_thread_task_runner.h" #include "base/trace_event/trace_event.h" -#include "cc/animation/animation_events.h" -#include "cc/animation/layer_tree_mutator.h" #include "cc/trees/layer_tree_host.h" +#include "cc/trees/layer_tree_mutator.h" +#include "cc/trees/mutator_host.h" namespace cc { @@ -37,14 +37,15 @@ ThreadedChannel::~ThreadedChannel() { DCHECK(!IsInitialized()); } -void ThreadedChannel::UpdateTopControlsStateOnImpl(TopControlsState constraints, - TopControlsState current, - bool animate) { +void ThreadedChannel::UpdateBrowserControlsStateOnImpl( + BrowserControlsState constraints, + BrowserControlsState current, + bool animate) { DCHECK(IsMainThread()); ImplThreadTaskRunner()->PostTask( FROM_HERE, - base::Bind(&ProxyImpl::UpdateTopControlsStateOnImpl, proxy_impl_weak_ptr_, - constraints, current, animate)); + base::Bind(&ProxyImpl::UpdateBrowserControlsStateOnImpl, + proxy_impl_weak_ptr_, constraints, current, animate)); } void ThreadedChannel::InitializeCompositorFrameSinkOnImpl( @@ -191,10 +192,10 @@ void ThreadedChannel::SynchronouslyCloseImpl() { main().initialized = false; } -void ThreadedChannel::DidCompleteSwapBuffers() { +void ThreadedChannel::DidReceiveCompositorFrameAck() { DCHECK(IsImplThread()); MainThreadTaskRunner()->PostTask( - FROM_HERE, base::Bind(&ProxyMain::DidCompleteSwapBuffers, + FROM_HERE, base::Bind(&ProxyMain::DidReceiveCompositorFrameAck, impl().proxy_main_weak_ptr)); } @@ -213,7 +214,7 @@ void ThreadedChannel::DidCommitAndDrawFrame() { } void ThreadedChannel::SetAnimationEvents( - std::unique_ptr<AnimationEvents> events) { + std::unique_ptr<MutatorEvents> events) { DCHECK(IsImplThread()); MainThreadTaskRunner()->PostTask( FROM_HERE, base::Bind(&ProxyMain::SetAnimationEvents, diff --git a/chromium/cc/trees/threaded_channel.h b/chromium/cc/trees/threaded_channel.h index be0954d6120..b94f15e2629 100644 --- a/chromium/cc/trees/threaded_channel.h +++ b/chromium/cc/trees/threaded_channel.h @@ -84,9 +84,9 @@ class CC_EXPORT ThreadedChannel : public ChannelMain, public ChannelImpl { ~ThreadedChannel() override; // ChannelMain Implementation - void UpdateTopControlsStateOnImpl(TopControlsState constraints, - TopControlsState current, - bool animate) override; + void UpdateBrowserControlsStateOnImpl(BrowserControlsState constraints, + BrowserControlsState current, + bool animate) override; void InitializeCompositorFrameSinkOnImpl( CompositorFrameSink* output_surface) override; void InitializeMutatorOnImpl( @@ -116,10 +116,10 @@ class CC_EXPORT ThreadedChannel : public ChannelMain, public ChannelImpl { void SynchronouslyCloseImpl() override; // ChannelImpl Implementation - void DidCompleteSwapBuffers() override; + void DidReceiveCompositorFrameAck() override; void BeginMainFrameNotExpectedSoon() override; void DidCommitAndDrawFrame() override; - void SetAnimationEvents(std::unique_ptr<AnimationEvents> events) override; + void SetAnimationEvents(std::unique_ptr<MutatorEvents> events) override; void DidLoseCompositorFrameSink() override; void RequestNewCompositorFrameSink() override; void DidInitializeCompositorFrameSink(bool success) override; diff --git a/chromium/cc/trees/transform_node.cc b/chromium/cc/trees/transform_node.cc index 0060c3a06e0..b0655785c10 100644 --- a/chromium/cc/trees/transform_node.cc +++ b/chromium/cc/trees/transform_node.cc @@ -5,7 +5,6 @@ #include "base/trace_event/trace_event_argument.h" #include "cc/base/math_util.h" #include "cc/proto/gfx_conversions.h" -#include "cc/proto/property_tree.pb.h" #include "cc/trees/transform_node.h" #include "ui/gfx/geometry/point3_f.h" @@ -30,11 +29,11 @@ TransformNode::TransformNode() node_and_ancestors_are_flat(true), node_and_ancestors_have_only_integer_translation(true), scrolls(false), - needs_surface_contents_scale(false), - affected_by_inner_viewport_bounds_delta_x(false), - affected_by_inner_viewport_bounds_delta_y(false), - affected_by_outer_viewport_bounds_delta_x(false), - affected_by_outer_viewport_bounds_delta_y(false), + should_be_snapped(false), + moved_by_inner_viewport_bounds_delta_x(false), + moved_by_inner_viewport_bounds_delta_y(false), + moved_by_outer_viewport_bounds_delta_x(false), + moved_by_outer_viewport_bounds_delta_y(false), in_subtree_of_page_scale_layer(false), transform_changed(false), post_local_scale_factor(1.0f) {} @@ -64,22 +63,21 @@ bool TransformNode::operator==(const TransformNode& other) const { node_and_ancestors_have_only_integer_translation == other.node_and_ancestors_have_only_integer_translation && scrolls == other.scrolls && - needs_surface_contents_scale == other.needs_surface_contents_scale && - affected_by_inner_viewport_bounds_delta_x == - other.affected_by_inner_viewport_bounds_delta_x && - affected_by_inner_viewport_bounds_delta_y == - other.affected_by_inner_viewport_bounds_delta_y && - affected_by_outer_viewport_bounds_delta_x == - other.affected_by_outer_viewport_bounds_delta_x && - affected_by_outer_viewport_bounds_delta_y == - other.affected_by_outer_viewport_bounds_delta_y && + should_be_snapped == other.should_be_snapped && + moved_by_inner_viewport_bounds_delta_x == + other.moved_by_inner_viewport_bounds_delta_x && + moved_by_inner_viewport_bounds_delta_y == + other.moved_by_inner_viewport_bounds_delta_y && + moved_by_outer_viewport_bounds_delta_x == + other.moved_by_outer_viewport_bounds_delta_x && + moved_by_outer_viewport_bounds_delta_y == + other.moved_by_outer_viewport_bounds_delta_y && in_subtree_of_page_scale_layer == other.in_subtree_of_page_scale_layer && transform_changed == other.transform_changed && post_local_scale_factor == other.post_local_scale_factor && - surface_contents_scale == other.surface_contents_scale && scroll_offset == other.scroll_offset && - scroll_snap == other.scroll_snap && + snap_amount == other.snap_amount && source_offset == other.source_offset && source_to_parent == other.source_to_parent; } @@ -102,124 +100,6 @@ void TransformNode::update_post_local_transform( transform_origin.z()); } -void TransformNode::ToProtobuf(proto::TreeNode* proto) const { - proto->set_id(id); - proto->set_parent_id(parent_id); - proto->set_owner_id(owner_id); - - DCHECK(!proto->has_transform_node_data()); - proto::TranformNodeData* data = proto->mutable_transform_node_data(); - - TransformToProto(pre_local, data->mutable_pre_local()); - TransformToProto(local, data->mutable_local()); - TransformToProto(post_local, data->mutable_post_local()); - - TransformToProto(to_parent, data->mutable_to_parent()); - - data->set_source_node_id(source_node_id); - data->set_sorting_context_id(sorting_context_id); - - data->set_needs_local_transform_update(needs_local_transform_update); - - data->set_node_and_ancestors_are_animated_or_invertible( - node_and_ancestors_are_animated_or_invertible); - - data->set_is_invertible(is_invertible); - data->set_ancestors_are_invertible(ancestors_are_invertible); - - data->set_has_potential_animation(has_potential_animation); - data->set_is_currently_animating(is_currently_animating); - data->set_to_screen_is_potentially_animated( - to_screen_is_potentially_animated); - data->set_has_only_translation_animations(has_only_translation_animations); - - data->set_flattens_inherited_transform(flattens_inherited_transform); - data->set_node_and_ancestors_are_flat(node_and_ancestors_are_flat); - - data->set_node_and_ancestors_have_only_integer_translation( - node_and_ancestors_have_only_integer_translation); - data->set_scrolls(scrolls); - data->set_needs_surface_contents_scale(needs_surface_contents_scale); - - data->set_affected_by_inner_viewport_bounds_delta_x( - affected_by_inner_viewport_bounds_delta_x); - data->set_affected_by_inner_viewport_bounds_delta_y( - affected_by_inner_viewport_bounds_delta_y); - data->set_affected_by_outer_viewport_bounds_delta_x( - affected_by_outer_viewport_bounds_delta_x); - data->set_affected_by_outer_viewport_bounds_delta_y( - affected_by_outer_viewport_bounds_delta_y); - - data->set_in_subtree_of_page_scale_layer(in_subtree_of_page_scale_layer); - data->set_transform_changed(transform_changed); - data->set_post_local_scale_factor(post_local_scale_factor); - - Vector2dFToProto(surface_contents_scale, - data->mutable_surface_contents_scale()); - ScrollOffsetToProto(scroll_offset, data->mutable_scroll_offset()); - Vector2dFToProto(scroll_snap, data->mutable_scroll_snap()); - Vector2dFToProto(source_offset, data->mutable_source_offset()); - Vector2dFToProto(source_to_parent, data->mutable_source_to_parent()); -} - -void TransformNode::FromProtobuf(const proto::TreeNode& proto) { - id = proto.id(); - parent_id = proto.parent_id(); - owner_id = proto.owner_id(); - - DCHECK(proto.has_transform_node_data()); - const proto::TranformNodeData& data = proto.transform_node_data(); - - pre_local = ProtoToTransform(data.pre_local()); - local = ProtoToTransform(data.local()); - post_local = ProtoToTransform(data.post_local()); - - to_parent = ProtoToTransform(data.to_parent()); - - source_node_id = data.source_node_id(); - sorting_context_id = data.sorting_context_id(); - - needs_local_transform_update = data.needs_local_transform_update(); - - node_and_ancestors_are_animated_or_invertible = - data.node_and_ancestors_are_animated_or_invertible(); - - is_invertible = data.is_invertible(); - ancestors_are_invertible = data.ancestors_are_invertible(); - - has_potential_animation = data.has_potential_animation(); - is_currently_animating = data.is_currently_animating(); - to_screen_is_potentially_animated = data.to_screen_is_potentially_animated(); - has_only_translation_animations = data.has_only_translation_animations(); - - flattens_inherited_transform = data.flattens_inherited_transform(); - node_and_ancestors_are_flat = data.node_and_ancestors_are_flat(); - - node_and_ancestors_have_only_integer_translation = - data.node_and_ancestors_have_only_integer_translation(); - scrolls = data.scrolls(); - needs_surface_contents_scale = data.needs_surface_contents_scale(); - - affected_by_inner_viewport_bounds_delta_x = - data.affected_by_inner_viewport_bounds_delta_x(); - affected_by_inner_viewport_bounds_delta_y = - data.affected_by_inner_viewport_bounds_delta_y(); - affected_by_outer_viewport_bounds_delta_x = - data.affected_by_outer_viewport_bounds_delta_x(); - affected_by_outer_viewport_bounds_delta_y = - data.affected_by_outer_viewport_bounds_delta_y(); - - in_subtree_of_page_scale_layer = data.in_subtree_of_page_scale_layer(); - transform_changed = data.transform_changed(); - post_local_scale_factor = data.post_local_scale_factor(); - - surface_contents_scale = ProtoToVector2dF(data.surface_contents_scale()); - scroll_offset = ProtoToScrollOffset(data.scroll_offset()); - scroll_snap = ProtoToVector2dF(data.scroll_snap()); - source_offset = ProtoToVector2dF(data.source_offset()); - source_to_parent = ProtoToVector2dF(data.source_to_parent()); -} - void TransformNode::AsValueInto(base::trace_event::TracedValue* value) const { value->SetInteger("id", id); value->SetInteger("parent_id", parent_id); @@ -233,11 +113,11 @@ void TransformNode::AsValueInto(base::trace_event::TracedValue* value) const { value->SetInteger("source_node_id", source_node_id); value->SetInteger("sorting_context_id", sorting_context_id); MathUtil::AddToTracedValue("scroll_offset", scroll_offset, value); - MathUtil::AddToTracedValue("scroll_snap", scroll_snap, value); + MathUtil::AddToTracedValue("snap_amount", snap_amount, value); } TransformCachedNodeData::TransformCachedNodeData() - : target_id(-1), content_target_id(-1) {} + : target_id(-1), content_target_id(-1), is_showing_backface(false) {} TransformCachedNodeData::TransformCachedNodeData( const TransformCachedNodeData& other) = default; @@ -246,30 +126,10 @@ TransformCachedNodeData::~TransformCachedNodeData() {} bool TransformCachedNodeData::operator==( const TransformCachedNodeData& other) const { - return from_target == other.from_target && to_target == other.to_target && - from_screen == other.from_screen && to_screen == other.to_screen && + return from_screen == other.from_screen && to_screen == other.to_screen && target_id == other.target_id && - content_target_id == other.content_target_id; -} - -void TransformCachedNodeData::ToProtobuf( - proto::TransformCachedNodeData* proto) const { - TransformToProto(from_target, proto->mutable_from_target()); - TransformToProto(to_target, proto->mutable_to_target()); - TransformToProto(from_screen, proto->mutable_from_screen()); - TransformToProto(to_screen, proto->mutable_to_screen()); - proto->set_target_id(target_id); - proto->set_content_target_id(content_target_id); -} - -void TransformCachedNodeData::FromProtobuf( - const proto::TransformCachedNodeData& proto) { - from_target = ProtoToTransform(proto.from_target()); - to_target = ProtoToTransform(proto.to_target()); - from_screen = ProtoToTransform(proto.from_screen()); - to_screen = ProtoToTransform(proto.to_screen()); - target_id = proto.target_id(); - content_target_id = proto.content_target_id(); + content_target_id == other.content_target_id && + is_showing_backface == other.is_showing_backface; } } // namespace cc diff --git a/chromium/cc/trees/transform_node.h b/chromium/cc/trees/transform_node.h index 1e8c3910aaa..b94bf9ee2eb 100644 --- a/chromium/cc/trees/transform_node.h +++ b/chromium/cc/trees/transform_node.h @@ -18,11 +18,6 @@ class TracedValue; namespace cc { -namespace proto { -class TransformCachedNodeData; -class TreeNode; -} // namespace proto - struct CC_EXPORT TransformNode { TransformNode(); TransformNode(const TransformNode&); @@ -94,14 +89,14 @@ struct CC_EXPORT TransformNode { bool scrolls : 1; - bool needs_surface_contents_scale : 1; + bool should_be_snapped : 1; // These are used to position nodes wrt the right or bottom of the inner or // outer viewport. - bool affected_by_inner_viewport_bounds_delta_x : 1; - bool affected_by_inner_viewport_bounds_delta_y : 1; - bool affected_by_outer_viewport_bounds_delta_x : 1; - bool affected_by_outer_viewport_bounds_delta_y : 1; + bool moved_by_inner_viewport_bounds_delta_x : 1; + bool moved_by_inner_viewport_bounds_delta_y : 1; + bool moved_by_outer_viewport_bounds_delta_x : 1; + bool moved_by_outer_viewport_bounds_delta_y : 1; // Layer scale factor is used as a fallback when we either cannot adjust // raster scale or if the raster scale cannot be extracted from the screen @@ -115,14 +110,13 @@ struct CC_EXPORT TransformNode { // TODO(vollick): will be moved when accelerated effects are implemented. float post_local_scale_factor; - gfx::Vector2dF surface_contents_scale; - // TODO(vollick): will be moved when accelerated effects are implemented. gfx::ScrollOffset scroll_offset; - // We scroll snap where possible, but this means fixed-pos elements must be - // adjusted. This value stores the snapped amount for this purpose. - gfx::Vector2dF scroll_snap; + // This value stores the snapped amount whenever we snap. If the snap is due + // to a scroll, we need it to calculate fixed-pos elements adjustment, even + // otherwise we may need it to undo the snapping next frame. + gfx::Vector2dF snap_amount; // TODO(vollick): will be moved when accelerated effects are implemented. gfx::Vector2dF source_offset; @@ -140,9 +134,6 @@ struct CC_EXPORT TransformNode { void update_post_local_transform(const gfx::PointF& position, const gfx::Point3F& transform_origin); - void ToProtobuf(proto::TreeNode* proto) const; - void FromProtobuf(const proto::TreeNode& proto); - void AsValueInto(base::trace_event::TracedValue* value) const; }; @@ -152,8 +143,6 @@ struct CC_EXPORT TransformCachedNodeData { TransformCachedNodeData(const TransformCachedNodeData& other); ~TransformCachedNodeData(); - gfx::Transform from_target; - gfx::Transform to_target; gfx::Transform from_screen; gfx::Transform to_screen; int target_id; @@ -161,10 +150,9 @@ struct CC_EXPORT TransformCachedNodeData { // with this transform node. int content_target_id; - bool operator==(const TransformCachedNodeData& other) const; + bool is_showing_backface : 1; - void ToProtobuf(proto::TransformCachedNodeData* proto) const; - void FromProtobuf(const proto::TransformCachedNodeData& proto); + bool operator==(const TransformCachedNodeData& other) const; }; } // namespace cc diff --git a/chromium/cc/trees/tree_synchronizer.h b/chromium/cc/trees/tree_synchronizer.h index 58688b76706..b088eaf0284 100644 --- a/chromium/cc/trees/tree_synchronizer.h +++ b/chromium/cc/trees/tree_synchronizer.h @@ -14,7 +14,6 @@ namespace cc { class LayerImpl; class LayerTree; -class LayerTreeHost; class LayerTreeImpl; class Layer; diff --git a/chromium/cc/trees/tree_synchronizer_unittest.cc b/chromium/cc/trees/tree_synchronizer_unittest.cc index f656634636a..682ce60d673 100644 --- a/chromium/cc/trees/tree_synchronizer_unittest.cc +++ b/chromium/cc/trees/tree_synchronizer_unittest.cc @@ -13,6 +13,7 @@ #include "base/format_macros.h" #include "base/memory/ptr_util.h" #include "base/strings/stringprintf.h" +#include "cc/animation/animation_host.h" #include "cc/layers/layer.h" #include "cc/layers/layer_impl.h" #include "cc/test/animation_test_common.h" @@ -20,7 +21,6 @@ #include "cc/test/fake_layer_tree_host.h" #include "cc/test/fake_rendering_stats_instrumentation.h" #include "cc/test/stub_layer_tree_host_single_thread_client.h" -#include "cc/test/test_shared_bitmap_manager.h" #include "cc/test/test_task_graph_runner.h" #include "cc/trees/effect_node.h" #include "cc/trees/layer_tree_host_common.h" @@ -128,7 +128,10 @@ void ExpectTreesAreIdentical(Layer* root_layer, class TreeSynchronizerTest : public testing::Test { protected: TreeSynchronizerTest() - : host_(FakeLayerTreeHost::Create(&client_, &task_graph_runner_)) {} + : animation_host_(AnimationHost::CreateForTesting(ThreadInstance::MAIN)), + host_(FakeLayerTreeHost::Create(&client_, + &task_graph_runner_, + animation_host_.get())) {} bool is_equal(ScrollTree::ScrollOffsetMap map, ScrollTree::ScrollOffsetMap other) { @@ -151,6 +154,7 @@ class TreeSynchronizerTest : public testing::Test { FakeLayerTreeHostClient client_; StubLayerTreeHostSingleThreadClient single_thread_client_; TestTaskGraphRunner task_graph_runner_; + std::unique_ptr<AnimationHost> animation_host_; std::unique_ptr<FakeLayerTreeHost> host_; }; @@ -483,7 +487,6 @@ TEST_F(TreeSynchronizerTest, SynchronizeCurrentlyScrollingNode) { FakeLayerTreeHostImplClient client; FakeImplTaskRunnerProvider task_runner_provider; FakeRenderingStatsInstrumentation stats_instrumentation; - TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; FakeLayerTreeHostImpl* host_impl = host_->host_impl(); host_impl->CreatePendingTree(); @@ -531,7 +534,6 @@ TEST_F(TreeSynchronizerTest, SynchronizeScrollTreeScrollOffsetMap) { FakeLayerTreeHostImplClient client; FakeImplTaskRunnerProvider task_runner_provider; FakeRenderingStatsInstrumentation stats_instrumentation; - TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; FakeLayerTreeHostImpl* host_impl = host_->host_impl(); host_impl->CreatePendingTree(); @@ -627,7 +629,6 @@ TEST_F(TreeSynchronizerTest, RefreshPropertyTreesCachedData) { FakeLayerTreeHostImplClient client; FakeImplTaskRunnerProvider task_runner_provider; FakeRenderingStatsInstrumentation stats_instrumentation; - TestSharedBitmapManager shared_bitmap_manager; TestTaskGraphRunner task_graph_runner; FakeLayerTreeHostImpl* host_impl = host_->host_impl(); host_impl->CreatePendingTree(); |