diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-04-05 17:15:33 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-04-11 07:47:18 +0000 |
commit | 7324afb043a0b1e623d8e8eb906cdc53bdeb4685 (patch) | |
tree | a3fe2d74ea9c9e142c390dac4ca0e219382ace46 /chromium/cc/layers | |
parent | 6a4cabb866f66d4128a97cdc6d9d08ce074f1247 (diff) | |
download | qtwebengine-chromium-7324afb043a0b1e623d8e8eb906cdc53bdeb4685.tar.gz |
BASELINE: Update Chromium to 58.0.3029.54
Change-Id: I67f57065a7afdc8e4614adb5c0230281428df4d1
Reviewed-by: Peter Varga <pvarga@inf.u-szeged.hu>
Diffstat (limited to 'chromium/cc/layers')
59 files changed, 1677 insertions, 1497 deletions
diff --git a/chromium/cc/layers/empty_content_layer_client.cc b/chromium/cc/layers/empty_content_layer_client.cc index 982e8f0c6e2..3e1ef402228 100644 --- a/chromium/cc/layers/empty_content_layer_client.cc +++ b/chromium/cc/layers/empty_content_layer_client.cc @@ -5,7 +5,6 @@ #include "cc/layers/empty_content_layer_client.h" #include "cc/playback/display_item_list.h" -#include "cc/playback/display_item_list_settings.h" #include "ui/gfx/geometry/rect.h" namespace cc { @@ -31,7 +30,7 @@ gfx::Rect EmptyContentLayerClient::PaintableRegion() { scoped_refptr<DisplayItemList> EmptyContentLayerClient::PaintContentsToDisplayList( PaintingControlSetting painting_status) { - return DisplayItemList::Create(DisplayItemListSettings()); + return make_scoped_refptr(new DisplayItemList); } bool EmptyContentLayerClient::FillsBoundsCompletely() const { diff --git a/chromium/cc/layers/heads_up_display_layer_impl.cc b/chromium/cc/layers/heads_up_display_layer_impl.cc index 681a58d3ef2..6aae1bd3bdd 100644 --- a/chromium/cc/layers/heads_up_display_layer_impl.cc +++ b/chromium/cc/layers/heads_up_display_layer_impl.cc @@ -93,8 +93,7 @@ void HeadsUpDisplayLayerImpl::AcquireResource( } } - std::unique_ptr<ScopedResource> resource = - ScopedResource::Create(resource_provider); + auto resource = base::MakeUnique<ScopedResource>(resource_provider); resource->Allocate( internal_content_bounds_, ResourceProvider::TEXTURE_HINT_IMMUTABLE, resource_provider->best_texture_format(), gfx::ColorSpace()); diff --git a/chromium/cc/layers/heads_up_display_unittest.cc b/chromium/cc/layers/heads_up_display_unittest.cc index 8babb183e65..18010215855 100644 --- a/chromium/cc/layers/heads_up_display_unittest.cc +++ b/chromium/cc/layers/heads_up_display_unittest.cc @@ -47,40 +47,40 @@ class HudWithRootLayerChange : public HeadsUpDisplayTest { void DidCommit() override { ++num_commits_; - ASSERT_TRUE(layer_tree()->hud_layer()); + ASSERT_TRUE(layer_tree_host()->hud_layer()); switch (num_commits_) { case 1: // Change directly to a new root layer. - layer_tree()->SetRootLayer(root_layer1_); + layer_tree_host()->SetRootLayer(root_layer1_); break; case 2: - EXPECT_EQ(root_layer1_.get(), layer_tree()->hud_layer()->parent()); + EXPECT_EQ(root_layer1_.get(), layer_tree_host()->hud_layer()->parent()); // Unset the root layer. - layer_tree()->SetRootLayer(nullptr); + layer_tree_host()->SetRootLayer(nullptr); break; case 3: - EXPECT_EQ(0, layer_tree()->hud_layer()->parent()); + EXPECT_EQ(0, layer_tree_host()->hud_layer()->parent()); // Change back to the previous root layer. - layer_tree()->SetRootLayer(root_layer1_); + layer_tree_host()->SetRootLayer(root_layer1_); break; case 4: - EXPECT_EQ(root_layer1_.get(), layer_tree()->hud_layer()->parent()); + EXPECT_EQ(root_layer1_.get(), layer_tree_host()->hud_layer()->parent()); // Unset the root layer. - layer_tree()->SetRootLayer(nullptr); + layer_tree_host()->SetRootLayer(nullptr); break; case 5: - EXPECT_EQ(0, layer_tree()->hud_layer()->parent()); + EXPECT_EQ(0, layer_tree_host()->hud_layer()->parent()); // Change to a new root layer from a null root. - layer_tree()->SetRootLayer(root_layer2_); + layer_tree_host()->SetRootLayer(root_layer2_); break; case 6: - EXPECT_EQ(root_layer2_.get(), layer_tree()->hud_layer()->parent()); + EXPECT_EQ(root_layer2_.get(), layer_tree_host()->hud_layer()->parent()); // Change directly back to the last root layer/ - layer_tree()->SetRootLayer(root_layer1_); + layer_tree_host()->SetRootLayer(root_layer1_); break; case 7: - EXPECT_EQ(root_layer1_.get(), layer_tree()->hud_layer()->parent()); + EXPECT_EQ(root_layer1_.get(), layer_tree_host()->hud_layer()->parent()); EndTest(); break; } diff --git a/chromium/cc/layers/layer.cc b/chromium/cc/layers/layer.cc index 18950017962..04fa7f4a423 100644 --- a/chromium/cc/layers/layer.cc +++ b/chromium/cc/layers/layer.cc @@ -23,10 +23,6 @@ #include "cc/layers/scrollbar_layer_interface.h" #include "cc/output/copy_output_request.h" #include "cc/output/copy_output_result.h" -#include "cc/proto/cc_conversions.h" -#include "cc/proto/gfx_conversions.h" -#include "cc/proto/layer.pb.h" -#include "cc/proto/skia_conversions.h" #include "cc/trees/draw_property_utils.h" #include "cc/trees/effect_node.h" #include "cc/trees/layer_tree_host.h" @@ -80,7 +76,6 @@ Layer::Layer() : ignore_set_needs_commit_(false), parent_(nullptr), layer_tree_host_(nullptr), - layer_tree_(nullptr), // Layer IDs start from 1. inputs_(g_next_layer_id.GetNext() + 1), num_descendants_that_draw_content_(0), @@ -124,25 +119,23 @@ void Layer::SetLayerTreeHost(LayerTreeHost* host) { return; if (layer_tree_host_) { - layer_tree_->property_trees()->RemoveIdFromIdToIndexMaps(id()); - layer_tree_->property_trees()->needs_rebuild = true; - layer_tree_->UnregisterLayer(this); + layer_tree_host_->property_trees()->RemoveIdFromIdToIndexMaps(id()); + layer_tree_host_->property_trees()->needs_rebuild = true; + layer_tree_host_->UnregisterLayer(this); if (inputs_.element_id) { - layer_tree_->UnregisterElement(inputs_.element_id, - ElementListType::ACTIVE, this); + layer_tree_host_->UnregisterElement(inputs_.element_id, + ElementListType::ACTIVE, this); } } if (host) { - host->GetLayerTree()->property_trees()->needs_rebuild = true; - host->GetLayerTree()->RegisterLayer(this); + host->property_trees()->needs_rebuild = true; + host->RegisterLayer(this); if (inputs_.element_id) { - host->GetLayerTree()->RegisterElement(inputs_.element_id, - ElementListType::ACTIVE, this); + host->RegisterElement(inputs_.element_id, ElementListType::ACTIVE, this); } } layer_tree_host_ = host; - layer_tree_ = host ? host->GetLayerTree() : nullptr; InvalidatePropertyTreesIndices(); // When changing hosts, the layer needs to commit its properties to the impl @@ -163,17 +156,12 @@ void Layer::SetLayerTreeHost(LayerTreeHost* host) { host->SetNeedsCommit(); } -void Layer::SetNeedsUpdate() { - if (layer_tree_host_ && !ignore_set_needs_commit_) - layer_tree_host_->SetNeedsUpdateLayers(); -} - void Layer::SetNeedsCommit() { if (!layer_tree_host_) return; SetNeedsPushProperties(); - layer_tree_->property_trees()->needs_rebuild = true; + layer_tree_host_->property_trees()->needs_rebuild = true; if (ignore_set_needs_commit_) return; @@ -194,10 +182,10 @@ void Layer::SetNeedsCommitNoRebuild() { } void Layer::SetNeedsFullTreeSync() { - if (!layer_tree_) + if (!layer_tree_host_) return; - layer_tree_->SetNeedsFullTreeSync(); + layer_tree_host_->SetNeedsFullTreeSync(); } void Layer::SetNextCommitWaitsForActivation() { @@ -208,20 +196,20 @@ void Layer::SetNextCommitWaitsForActivation() { } void Layer::SetNeedsPushProperties() { - if (layer_tree_) - layer_tree_->AddLayerShouldPushProperties(this); + if (layer_tree_host_) + layer_tree_host_->AddLayerShouldPushProperties(this); } void Layer::ResetNeedsPushPropertiesForTesting() { - if (layer_tree_) - layer_tree_->RemoveLayerShouldPushProperties(this); + if (layer_tree_host_) + layer_tree_host_->RemoveLayerShouldPushProperties(this); } bool Layer::IsPropertyChangeAllowed() const { - if (!layer_tree_) + if (!layer_tree_host_) return true; - return !layer_tree_->in_paint_layer_contents(); + return !layer_tree_host_->in_paint_layer_contents(); } sk_sp<SkPicture> Layer::GetPicture() const { @@ -237,7 +225,7 @@ void Layer::SetParent(Layer* layer) { if (!layer_tree_host_) return; - layer_tree_->property_trees()->needs_rebuild = true; + layer_tree_host_->property_trees()->needs_rebuild = true; } void Layer::AddChild(scoped_refptr<Layer> child) { @@ -359,11 +347,12 @@ bool Layer::HasAncestor(const Layer* ancestor) const { void Layer::RequestCopyOfOutput(std::unique_ptr<CopyOutputRequest> request) { DCHECK(IsPropertyChangeAllowed()); - if (void* source = request->source()) { + if (request->has_source()) { + const base::UnguessableToken& source = request->source(); auto it = std::find_if(inputs_.copy_requests.begin(), inputs_.copy_requests.end(), - [source](const std::unique_ptr<CopyOutputRequest>& x) { - return x->source() == source; + [&source](const std::unique_ptr<CopyOutputRequest>& x) { + return x->has_source() && x->source() == source; }); if (it != inputs_.copy_requests.end()) inputs_.copy_requests.erase(it); @@ -425,7 +414,15 @@ void Layer::SetMaskLayer(Layer* mask_layer) { inputs_.mask_layer->RemoveFromParent(); DCHECK(!inputs_.mask_layer->parent()); inputs_.mask_layer->SetParent(this); - inputs_.mask_layer->SetIsMask(true); + if (inputs_.filters.IsEmpty() && + (!layer_tree_host_ || + layer_tree_host_->GetSettings().enable_mask_tiling)) { + inputs_.mask_layer->SetLayerMaskType( + Layer::LayerMaskType::MULTI_TEXTURE_MASK); + } else { + inputs_.mask_layer->SetLayerMaskType( + Layer::LayerMaskType::SINGLE_TEXTURE_MASK); + } } SetSubtreePropertyChanged(); SetNeedsFullTreeSync(); @@ -436,6 +433,9 @@ void Layer::SetFilters(const FilterOperations& filters) { if (inputs_.filters == filters) return; inputs_.filters = filters; + if (inputs_.mask_layer) + inputs_.mask_layer->SetLayerMaskType( + Layer::LayerMaskType::SINGLE_TEXTURE_MASK); SetSubtreePropertyChanged(); SetNeedsCommit(); } @@ -471,7 +471,7 @@ void Layer::SetOpacity(float opacity) { inputs_.opacity = opacity; SetSubtreePropertyChanged(); if (layer_tree_host_ && !force_rebuild) { - PropertyTrees* property_trees = layer_tree_->property_trees(); + PropertyTrees* property_trees = layer_tree_host_->property_trees(); auto effect_id_to_index = property_trees->layer_id_to_effect_node_index.find(id()); if (effect_id_to_index != @@ -505,10 +505,12 @@ void Layer::SetBlendMode(SkBlendMode blend_mode) { if (inputs_.blend_mode == blend_mode) return; - // Allowing only blend modes that are defined in the CSS Compositing standard: + // Allowing only blend modes that are defined in the CSS Compositing standard, + // plus destination-in which is used to implement masks. // http://dev.w3.org/fxtf/compositing-1/#blending switch (blend_mode) { case SkBlendMode::kSrcOver: + case SkBlendMode::kDstIn: case SkBlendMode::kScreen: case SkBlendMode::kOverlay: case SkBlendMode::kDarken: @@ -531,7 +533,6 @@ void Layer::SetBlendMode(SkBlendMode blend_mode) { case SkBlendMode::kDst: case SkBlendMode::kDstOver: case SkBlendMode::kSrcIn: - case SkBlendMode::kDstIn: case SkBlendMode::kSrcOut: case SkBlendMode::kDstOut: case SkBlendMode::kSrcATop: @@ -577,7 +578,7 @@ void Layer::SetPosition(const gfx::PointF& position) { return; SetSubtreePropertyChanged(); - PropertyTrees* property_trees = layer_tree_->property_trees(); + PropertyTrees* property_trees = layer_tree_host_->property_trees(); if (property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::TRANSFORM, id())) { DCHECK_EQ(transform_tree_index(), @@ -596,7 +597,7 @@ void Layer::SetPosition(const gfx::PointF& position) { } transform_node->needs_local_transform_update = true; transform_node->transform_changed = true; - layer_tree_->property_trees()->transform_tree.set_needs_update(true); + layer_tree_host_->property_trees()->transform_tree.set_needs_update(true); SetNeedsCommitNoRebuild(); return; } @@ -605,10 +606,6 @@ void Layer::SetPosition(const gfx::PointF& position) { } bool Layer::IsContainerForFixedPositionLayers() const { - if (!inputs_.transform.IsIdentityOrTranslation()) - return true; - if (parent_ && !parent_->inputs_.transform.IsIdentityOrTranslation()) - return true; return inputs_.is_container_for_fixed_position_layers; } @@ -634,7 +631,7 @@ void Layer::SetTransform(const gfx::Transform& transform) { SetSubtreePropertyChanged(); if (layer_tree_host_) { - PropertyTrees* property_trees = layer_tree_->property_trees(); + PropertyTrees* property_trees = layer_tree_host_->property_trees(); if (property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::TRANSFORM, id())) { // We need to trigger a rebuild if we could have affected 2d axis @@ -650,7 +647,7 @@ void Layer::SetTransform(const gfx::Transform& transform) { transform_node->local = transform; transform_node->needs_local_transform_update = true; transform_node->transform_changed = true; - layer_tree_->property_trees()->transform_tree.set_needs_update(true); + layer_tree_host_->property_trees()->transform_tree.set_needs_update(true); if (preserves_2d_axis_alignment) SetNeedsCommitNoRebuild(); else @@ -675,7 +672,7 @@ void Layer::SetTransformOrigin(const gfx::Point3F& transform_origin) { return; SetSubtreePropertyChanged(); - PropertyTrees* property_trees = layer_tree_->property_trees(); + PropertyTrees* property_trees = layer_tree_host_->property_trees(); if (property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::TRANSFORM, id())) { DCHECK_EQ(transform_tree_index(), @@ -686,7 +683,7 @@ void Layer::SetTransformOrigin(const gfx::Point3F& transform_origin) { transform_node->update_post_local_transform(position(), transform_origin); transform_node->needs_local_transform_update = true; transform_node->transform_changed = true; - layer_tree_->property_trees()->transform_tree.set_needs_update(true); + layer_tree_host_->property_trees()->transform_tree.set_needs_update(true); SetNeedsCommitNoRebuild(); return; } @@ -747,8 +744,8 @@ void Layer::SetClipParent(Layer* ancestor) { inputs_.clip_parent->AddClipChild(this); SetNeedsCommit(); - if (layer_tree_) - layer_tree_->SetNeedsMetaInfoRecomputation(true); + if (layer_tree_host_) + layer_tree_host_->SetNeedsMetaInfoRecomputation(true); } void Layer::AddClipChild(Layer* child) { @@ -775,7 +772,7 @@ void Layer::SetScrollOffset(const gfx::ScrollOffset& scroll_offset) { if (!layer_tree_host_) return; - PropertyTrees* property_trees = layer_tree_->property_trees(); + PropertyTrees* property_trees = layer_tree_host_->property_trees(); if (scroll_tree_index() != ScrollTree::kInvalidNodeId && scrollable()) property_trees->scroll_tree.SetScrollOffset(id(), scroll_offset); @@ -808,7 +805,7 @@ void Layer::SetScrollOffsetFromImplSide( bool needs_rebuild = true; - PropertyTrees* property_trees = layer_tree_->property_trees(); + PropertyTrees* property_trees = layer_tree_host_->property_trees(); if (scroll_tree_index() != ScrollTree::kInvalidNodeId && scrollable()) property_trees->scroll_tree.SetScrollOffset(id(), scroll_offset); @@ -828,7 +825,8 @@ void Layer::SetScrollOffsetFromImplSide( property_trees->needs_rebuild = true; if (!inputs_.did_scroll_callback.is_null()) - inputs_.did_scroll_callback.Run(); + inputs_.did_scroll_callback.Run(scroll_offset); + // The callback could potentially change the layer structure: // "this" may have been destroyed during the process. } @@ -842,8 +840,8 @@ void Layer::SetScrollClipLayerId(int clip_layer_id) { } Layer* Layer::scroll_clip_layer() const { - DCHECK(layer_tree_); - return layer_tree_->LayerById(inputs_.scroll_clip_layer_id); + DCHECK(layer_tree_host_); + return layer_tree_host_->LayerById(inputs_.scroll_clip_layer_id); } void Layer::SetUserScrollable(bool horizontal, bool vertical) { @@ -935,7 +933,7 @@ void Layer::SetTransformTreeIndex(int index) { int Layer::transform_tree_index() const { if (!layer_tree_host_ || - layer_tree_->property_trees()->sequence_number != + layer_tree_host_->property_trees()->sequence_number != property_tree_sequence_number_) { return TransformTree::kInvalidNodeId; } @@ -952,7 +950,7 @@ void Layer::SetClipTreeIndex(int index) { int Layer::clip_tree_index() const { if (!layer_tree_host_ || - layer_tree_->property_trees()->sequence_number != + layer_tree_host_->property_trees()->sequence_number != property_tree_sequence_number_) { return ClipTree::kInvalidNodeId; } @@ -969,7 +967,7 @@ void Layer::SetEffectTreeIndex(int index) { int Layer::effect_tree_index() const { if (!layer_tree_host_ || - layer_tree_->property_trees()->sequence_number != + layer_tree_host_->property_trees()->sequence_number != property_tree_sequence_number_) { return EffectTree::kInvalidNodeId; } @@ -986,7 +984,7 @@ void Layer::SetScrollTreeIndex(int index) { int Layer::scroll_tree_index() const { if (!layer_tree_host_ || - layer_tree_->property_trees()->sequence_number != + layer_tree_host_->property_trees()->sequence_number != property_tree_sequence_number_) { return ScrollTree::kInvalidNodeId; } @@ -1058,8 +1056,8 @@ void Layer::SetNeedsDisplayRect(const gfx::Rect& dirty_rect) { SetNeedsPushProperties(); inputs_.update_rect.Union(dirty_rect); - if (DrawsContent()) - SetNeedsUpdate(); + if (DrawsContent() && layer_tree_host_ && !ignore_set_needs_commit_) + layer_tree_host_->SetNeedsUpdateLayers(); } bool Layer::DescendantIsFixedToContainerLayer() const { @@ -1201,7 +1199,7 @@ void Layer::PushPropertiesTo(LayerImpl* layer) { subtree_property_changed_ = false; inputs_.update_rect = gfx::Rect(); - layer_tree_->RemoveLayerShouldPushProperties(this); + layer_tree_host_->RemoveLayerShouldPushProperties(this); } void Layer::TakeCopyRequests( @@ -1226,86 +1224,6 @@ void Layer::TakeCopyRequests( inputs_.copy_requests.clear(); } -void Layer::SetTypeForProtoSerialization(proto::LayerNode* proto) const { - proto->set_type(proto::LayerNode::LAYER); -} - -void Layer::ToLayerNodeProto(proto::LayerNode* proto) const { - proto->set_id(inputs_.layer_id); - SetTypeForProtoSerialization(proto); - - if (parent_) - proto->set_parent_id(parent_->id()); - - DCHECK_EQ(0, proto->children_size()); - for (const auto& child : inputs_.children) { - child->ToLayerNodeProto(proto->add_children()); - } - - if (inputs_.mask_layer) - inputs_.mask_layer->ToLayerNodeProto(proto->mutable_mask_layer()); -} - -void Layer::ToLayerPropertiesProto(proto::LayerProperties* proto) { - proto->set_id(inputs_.layer_id); - - proto::BaseLayerProperties* base = proto->mutable_base(); - RectToProto(inputs_.update_rect, base->mutable_update_rect()); - inputs_.update_rect = gfx::Rect(); - - bool use_paint_properties = layer_tree_host_ && - paint_properties_.source_frame_number == - layer_tree_host_->SourceFrameNumber(); - SizeToProto(use_paint_properties ? paint_properties_.bounds : inputs_.bounds, - base->mutable_bounds()); - - base->set_masks_to_bounds(inputs_.masks_to_bounds); - base->set_opacity(inputs_.opacity); - base->set_blend_mode(SkXfermodeModeToProto(inputs_.blend_mode)); - base->set_is_root_for_isolated_group(inputs_.is_root_for_isolated_group); - base->set_contents_opaque(inputs_.contents_opaque); - PointFToProto(inputs_.position, base->mutable_position()); - TransformToProto(inputs_.transform, base->mutable_transform()); - Point3FToProto(inputs_.transform_origin, base->mutable_transform_origin()); - base->set_is_drawable(inputs_.is_drawable); - base->set_double_sided(inputs_.double_sided); - base->set_should_flatten_transform(inputs_.should_flatten_transform); - base->set_sorting_context_id(inputs_.sorting_context_id); - base->set_use_parent_backface_visibility( - inputs_.use_parent_backface_visibility); - base->set_background_color(inputs_.background_color); - ScrollOffsetToProto(inputs_.scroll_offset, base->mutable_scroll_offset()); - base->set_scroll_clip_layer_id(inputs_.scroll_clip_layer_id); - base->set_user_scrollable_horizontal(inputs_.user_scrollable_horizontal); - base->set_user_scrollable_vertical(inputs_.user_scrollable_vertical); - base->set_main_thread_scrolling_reasons( - inputs_.main_thread_scrolling_reasons); - RegionToProto(inputs_.non_fast_scrollable_region, - base->mutable_non_fast_scrollable_region()); - RegionToProto(inputs_.touch_event_handler_region, - base->mutable_touch_event_handler_region()); - base->set_is_container_for_fixed_position_layers( - inputs_.is_container_for_fixed_position_layers); - inputs_.position_constraint.ToProtobuf(base->mutable_position_constraint()); - inputs_.sticky_position_constraint.ToProtobuf( - base->mutable_sticky_position_constraint()); - - int scroll_parent_id = - inputs_.scroll_parent ? inputs_.scroll_parent->id() : INVALID_ID; - base->set_scroll_parent_id(scroll_parent_id); - - int clip_parent_id = - inputs_.clip_parent ? inputs_.clip_parent->id() : INVALID_ID; - base->set_clip_parent_id(clip_parent_id); - - base->set_has_will_change_transform_hint( - inputs_.has_will_change_transform_hint); - base->set_hide_layer_and_subtree(inputs_.hide_layer_and_subtree); - - // TODO(nyquist): Add support for serializing FilterOperations for - // |filters_| and |background_filters_|. See crbug.com/541321. -} - std::unique_ptr<LayerImpl> Layer::CreateLayerImpl(LayerTreeImpl* tree_impl) { return LayerImpl::Create(tree_impl, inputs_.layer_id); } @@ -1411,49 +1329,11 @@ void Layer::OnFilterAnimated(const FilterOperations& filters) { } void Layer::OnOpacityAnimated(float opacity) { - DCHECK_GE(opacity, 0.f); - DCHECK_LE(opacity, 1.f); - - if (inputs_.opacity == opacity) - return; inputs_.opacity = opacity; - // Changing the opacity may make a previously hidden layer visible, so a new - // recording may be needed. - SetNeedsUpdate(); - if (layer_tree_host_) { - PropertyTrees* property_trees = layer_tree_->property_trees(); - if (property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::EFFECT, - id())) { - DCHECK_EQ(effect_tree_index(), - property_trees->layer_id_to_effect_node_index[id()]); - EffectNode* node = property_trees->effect_tree.Node(effect_tree_index()); - node->opacity = opacity; - property_trees->effect_tree.set_needs_update(true); - } - } } void Layer::OnTransformAnimated(const gfx::Transform& transform) { - if (inputs_.transform == transform) - return; inputs_.transform = transform; - // Changing the transform may change the visible part of this layer, so a new - // recording may be needed. - SetNeedsUpdate(); - if (layer_tree_host_) { - PropertyTrees* property_trees = layer_tree_->property_trees(); - if (property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::TRANSFORM, - id())) { - DCHECK_EQ(transform_tree_index(), - property_trees->layer_id_to_transform_node_index[id()]); - TransformNode* node = - property_trees->transform_tree.Node(transform_tree_index()); - node->local = transform; - node->needs_local_transform_update = true; - node->has_potential_animation = true; - property_trees->transform_tree.set_needs_update(true); - } - } } void Layer::OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) { @@ -1465,7 +1345,7 @@ void Layer::OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) { void Layer::OnIsAnimatingChanged(const PropertyAnimationState& mask, const PropertyAnimationState& state) { DCHECK(layer_tree_host_); - PropertyTrees* property_trees = layer_tree_->property_trees(); + PropertyTrees* property_trees = layer_tree_host_->property_trees(); TransformNode* transform_node = nullptr; if (property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::TRANSFORM, @@ -1565,7 +1445,7 @@ void Layer::ClearPreferredRasterBounds() { } MutatorHost* Layer::GetMutatorHost() const { - return layer_tree_ ? layer_tree_->mutator_host() : nullptr; + return layer_tree_host_ ? layer_tree_host_->mutator_host() : nullptr; } ElementListType Layer::GetElementTypeForAnimation() const { @@ -1620,15 +1500,15 @@ void Layer::SetElementId(ElementId id) { TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), "Layer::SetElementId", "element", id.AsValue().release()); if (inputs_.element_id && layer_tree_host()) { - layer_tree_->UnregisterElement(inputs_.element_id, ElementListType::ACTIVE, - this); + layer_tree_host_->UnregisterElement(inputs_.element_id, + ElementListType::ACTIVE, this); } inputs_.element_id = id; if (inputs_.element_id && layer_tree_host()) { - layer_tree_->RegisterElement(inputs_.element_id, ElementListType::ACTIVE, - this); + layer_tree_host_->RegisterElement(inputs_.element_id, + ElementListType::ACTIVE, this); } SetNeedsCommit(); @@ -1644,16 +1524,8 @@ void Layer::SetMutableProperties(uint32_t properties) { SetNeedsCommit(); } -void Layer::DidBeginTracing() { - // We'll be dumping layer trees as part of trace, so make sure - // PushPropertiesTo() propagates layer debug info to the impl - // side -- otherwise this won't happen for the the layers that - // remain unchanged since tracing started. - SetNeedsPushProperties(); -} - int Layer::num_copy_requests_in_target_subtree() { - return layer_tree_->property_trees() + return layer_tree_host_->property_trees() ->effect_tree.Node(effect_tree_index()) ->num_copy_requests_in_subtree; } @@ -1661,15 +1533,7 @@ int Layer::num_copy_requests_in_target_subtree() { gfx::Transform Layer::screen_space_transform() const { DCHECK_NE(transform_tree_index_, TransformTree::kInvalidNodeId); return draw_property_utils::ScreenSpaceTransform( - this, layer_tree_->property_trees()->transform_tree); -} - -LayerTree* Layer::GetLayerTree() const { - return layer_tree_; -} - -void Layer::SetLayerIdForTesting(int id) { - inputs_.layer_id = id; + this, layer_tree_host_->property_trees()->transform_tree); } } // namespace cc diff --git a/chromium/cc/layers/layer.h b/chromium/cc/layers/layer.h index 530cff780da..c310377ed02 100644 --- a/chromium/cc/layers/layer.h +++ b/chromium/cc/layers/layer.h @@ -25,13 +25,12 @@ #include "cc/layers/layer_position_constraint.h" #include "cc/layers/paint_properties.h" #include "cc/output/filter_operations.h" +#include "cc/paint/paint_record.h" #include "cc/trees/element_id.h" -#include "cc/trees/layer_tree.h" #include "cc/trees/mutator_host_client.h" #include "cc/trees/property_tree.h" #include "cc/trees/target_property.h" #include "third_party/skia/include/core/SkColor.h" -#include "third_party/skia/include/core/SkPicture.h" #include "ui/gfx/geometry/point3_f.h" #include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect_f.h" @@ -55,11 +54,6 @@ class LayerTreeImpl; class MutatorHost; class ScrollbarLayerInterface; -namespace proto { -class LayerNode; -class LayerProperties; -} // namespace proto - // Base class for composited layers. Special layer types are derived from // this class. class CC_EXPORT Layer : public base::RefCounted<Layer> { @@ -71,6 +65,12 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> { INVALID_ID = -1, }; + enum LayerMaskType { + NOT_MASK = 0, + MULTI_TEXTURE_MASK, + SINGLE_TEXTURE_MASK, + }; + static scoped_refptr<Layer> Create(); int id() const { return inputs_.layer_id; } @@ -257,7 +257,8 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> { return inputs_.touch_event_handler_region; } - void set_did_scroll_callback(const base::Closure& callback) { + void set_did_scroll_callback( + const base::Callback<void(const gfx::ScrollOffset&)>& callback) { inputs_.did_scroll_callback = callback; } @@ -317,7 +318,7 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> { virtual void SavePaintProperties(); // Returns true iff anything was updated that needs to be committed. virtual bool Update(); - virtual void SetIsMask(bool is_mask) {} + virtual void SetLayerMaskType(Layer::LayerMaskType type) {} virtual bool IsSuitableForGpuRasterization() const; virtual std::unique_ptr<base::trace_event::ConvertableToTraceFormat> @@ -330,31 +331,7 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> { virtual void PushPropertiesTo(LayerImpl* layer); - // Sets the type proto::LayerType that should be used for serialization - // of the current layer by calling LayerNode::set_type(proto::LayerType). - // TODO(nyquist): Start using a forward declared enum class when - // https://github.com/google/protobuf/issues/67 has been fixed and rolled in. - // This function would preferably instead return a proto::LayerType, but - // since that is an enum (the protobuf library does not generate enum - // classes), it can't be forward declared. We don't want to include - // //cc/proto/layer.pb.h in this header file, as it requires that all - // dependent targets would have to be given the config for how to include it. - virtual void SetTypeForProtoSerialization(proto::LayerNode* proto) const; - - // Recursively iterate over this layer and all children and write the - // hierarchical structure to the given LayerNode proto. In addition to the - // structure itself, the Layer id and type is also written to facilitate - // construction of the correct layer on the client. - virtual void ToLayerNodeProto(proto::LayerNode* proto) const; - - // This method is similar to PushPropertiesTo, but instead of pushing to - // a LayerImpl, it pushes the properties to proto::LayerProperties. It is - // called only on layers that have changed properties. The properties - // themselves are pushed to proto::LayerProperties. - virtual void ToLayerPropertiesProto(proto::LayerProperties* proto); - LayerTreeHost* GetLayerTreeHostForTesting() const { return layer_tree_host_; } - LayerTree* GetLayerTree() const; virtual ScrollbarLayerInterface* ToScrollbarLayer(); @@ -370,6 +347,8 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> { return paint_properties_; } + // Mark the layer as needing to push its properties to the LayerImpl during + // commit. void SetNeedsPushProperties(); void ResetNeedsPushPropertiesForTesting(); @@ -430,8 +409,6 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> { void SetMayContainVideo(bool yes); - void DidBeginTracing(); - int num_copy_requests_in_target_subtree(); void SetElementId(ElementId id); @@ -465,37 +442,30 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> { ElementListType GetElementTypeForAnimation() const; - // Tests in remote mode need to explicitly set the layer id so it matches the - // layer id for the corresponding Layer on the engine. - void SetLayerIdForTesting(int id); - void SetScrollbarsHiddenFromImplSide(bool hidden); const gfx::Rect& update_rect() const { return inputs_.update_rect; } + LayerTreeHost* layer_tree_host() const { return layer_tree_host_; } + protected: friend class LayerImpl; friend class TreeSynchronizer; virtual ~Layer(); Layer(); - LayerTreeHost* layer_tree_host() { return layer_tree_host_; } - // These SetNeeds functions are in order of severity of update: // - // Called when this layer has been modified in some way, but isn't sure - // that it needs a commit yet. It needs CalcDrawProperties and UpdateLayers - // before it knows whether or not a commit is required. - void SetNeedsUpdate(); - // Called when a property has been modified in a way that the layer - // knows immediately that a commit is required. This implies SetNeedsUpdate - // as well as SetNeedsPushProperties to push that property. + // Called when a property has been modified in a way that the layer knows + // immediately that a commit is required. This implies SetNeedsPushProperties + // to push that property. void SetNeedsCommit(); // This is identical to SetNeedsCommit, but the former requests a rebuild of // the property trees. void SetNeedsCommitNoRebuild(); - // Called when there's been a change in layer structure. Implies both - // SetNeedsUpdate and SetNeedsCommit, but not SetNeedsPushProperties. + // Called when there's been a change in layer structure. Implies + // SetNeedsCommit and property tree rebuld, but not SetNeedsPushProperties + // (the full tree is synced over). void SetNeedsFullTreeSync(); // Called when the next commit should wait until the pending tree is activated @@ -520,7 +490,7 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> { private: friend class base::RefCounted<Layer>; friend class LayerTreeHostCommon; - friend class LayerTree; + friend class LayerTreeHost; friend class LayerInternalsForTest; // Interactions with attached animations. @@ -648,7 +618,7 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> { // The following elements can not and are not serialized. LayerClient* client; - base::Closure did_scroll_callback; + base::Callback<void(const gfx::ScrollOffset&)> did_scroll_callback; std::vector<std::unique_ptr<CopyOutputRequest>> copy_requests; gfx::Size preferred_raster_bounds; @@ -660,7 +630,6 @@ class CC_EXPORT Layer : public base::RefCounted<Layer> { // This pointer value is nil when a Layer is not in a tree and is // updated via SetLayerTreeHost() if a layer moves between trees. LayerTreeHost* layer_tree_host_; - LayerTree* layer_tree_; Inputs inputs_; diff --git a/chromium/cc/layers/layer_impl.cc b/chromium/cc/layers/layer_impl.cc index 4074061f723..010df135a98 100644 --- a/chromium/cc/layers/layer_impl.cc +++ b/chromium/cc/layers/layer_impl.cc @@ -133,12 +133,6 @@ void LayerImpl::SetDebugInfo( SetNeedsPushProperties(); } -void LayerImpl::DistributeScroll(ScrollState* scroll_state) { - ScrollTree& scroll_tree = GetScrollTree(); - ScrollNode* scroll_node = scroll_tree.Node(scroll_tree_index()); - scroll_tree.DistributeScroll(scroll_node, scroll_state); -} - void LayerImpl::SetTransformTreeIndex(int index) { transform_tree_index_ = index; } @@ -153,18 +147,16 @@ void LayerImpl::SetEffectTreeIndex(int index) { int LayerImpl::render_target_effect_tree_index() const { EffectNode* effect_node = GetEffectTree().Node(effect_tree_index_); - return effect_node->render_surface ? effect_node->id : effect_node->target_id; + + return GetEffectTree().GetRenderSurface(effect_tree_index_) + ? effect_node->id + : effect_node->target_id; } void LayerImpl::SetScrollTreeIndex(int index) { scroll_tree_index_ = index; } -void LayerImpl::ClearRenderSurfaceLayerList() { - if (render_surface_) - render_surface_->ClearLayerLists(); -} - void LayerImpl::PopulateSharedQuadState(SharedQuadState* state) const { state->SetAll(draw_properties_.target_space_transform, bounds(), draw_properties_.visible_layer_rect, draw_properties_.clip_rect, @@ -360,12 +352,6 @@ void LayerImpl::PushPropertiesTo(LayerImpl* layer) { layer->layer_property_changed_ = true; } - // If whether layer has render surface changes, we need to update draw - // properties. - // TODO(weiliangc): Should be safely removed after impl side is able to - // update render surfaces without rebuilding property trees. - if (layer->has_render_surface() != has_render_surface()) - layer->layer_tree_impl()->set_needs_update_draw_properties(); layer->SetBounds(bounds_); layer->SetScrollClipLayer(scroll_clip_layer_id_); layer->SetElementId(element_id_); @@ -489,9 +475,6 @@ void LayerImpl::ResetChangeTracking() { update_rect_.SetRect(0, 0, 0, 0); damage_rect_.SetRect(0, 0, 0, 0); - - if (render_surface_) - render_surface_->ResetPropertyChangedFlags(); } int LayerImpl::num_copy_requests_in_target_subtree() { @@ -973,17 +956,6 @@ void LayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) { benchmark->RunOnLayer(this); } -void LayerImpl::SetHasRenderSurface(bool should_have_render_surface) { - if (!!render_surface() == should_have_render_surface) - return; - - if (should_have_render_surface) { - render_surface_ = base::MakeUnique<RenderSurfaceImpl>(this); - return; - } - render_surface_.reset(); -} - gfx::Transform LayerImpl::DrawTransform() const { // Only drawn layers have up-to-date draw properties. if (!is_drawn_render_surface_layer_list_member()) { @@ -1052,16 +1024,19 @@ gfx::Rect LayerImpl::GetScaledEnclosingRectInTargetSpace(float scale) const { gfx::Rect(scaled_bounds)); } +RenderSurfaceImpl* LayerImpl::GetRenderSurface() const { + EffectNode* effect_node = GetEffectTree().Node(effect_tree_index_); + if (effect_node->owning_layer_id == id()) + return GetEffectTree().GetRenderSurface(effect_tree_index_); + return nullptr; +} + RenderSurfaceImpl* LayerImpl::render_target() { - return GetEffectTree() - .Node(render_target_effect_tree_index()) - ->render_surface; + return GetEffectTree().GetRenderSurface(render_target_effect_tree_index()); } const RenderSurfaceImpl* LayerImpl::render_target() const { - return GetEffectTree() - .Node(render_target_effect_tree_index()) - ->render_surface; + return GetEffectTree().GetRenderSurface(render_target_effect_tree_index()); } bool LayerImpl::IsHidden() const { diff --git a/chromium/cc/layers/layer_impl.h b/chromium/cc/layers/layer_impl.h index 5fff96cb82c..396cda82c13 100644 --- a/chromium/cc/layers/layer_impl.h +++ b/chromium/cc/layers/layer_impl.h @@ -59,7 +59,6 @@ class RenderPass; class ScrollbarLayerImplBase; class SimpleEnclosedRegion; class Tile; -class ScrollState; struct AppendQuadsData; @@ -90,8 +89,6 @@ class CC_EXPORT LayerImpl { const PropertyAnimationState& state); bool IsActive() const; - void DistributeScroll(ScrollState* scroll_state); - void set_property_tree_sequence_number(int sequence_number) {} void SetTransformTreeIndex(int index); @@ -126,9 +123,6 @@ class CC_EXPORT LayerImpl { void UpdatePropertyTreeTransformIsAnimated(bool is_animated); void UpdatePropertyTreeScrollOffset(); - // For compatibility with Layer. - bool has_render_surface() const { return !!render_surface(); } - LayerTreeImpl* layer_tree_impl() const { return layer_tree_impl_; } void PopulateSharedQuadState(SharedQuadState* state) const; @@ -233,13 +227,7 @@ class CC_EXPORT LayerImpl { bool ShowDebugBorders() const; - // These invalidate the host's render surface layer list. The caller - // is responsible for calling set_needs_update_draw_properties on the tree - // so that its list can be recreated. - void ClearRenderSurfaceLayerList(); - void SetHasRenderSurface(bool has_render_surface); - - RenderSurfaceImpl* render_surface() const { return render_surface_.get(); } + RenderSurfaceImpl* GetRenderSurface() const; // The render surface which this layer draws into. This can be either owned by // the same layer or an ancestor of this layer. @@ -406,6 +394,10 @@ class CC_EXPORT LayerImpl { return is_drawn_render_surface_layer_list_member_; } + bool IsDrawnScrollbar() { + return ToScrollbarLayer() && is_drawn_render_surface_layer_list_member_; + } + void set_may_contain_video(bool yes) { may_contain_video_ = yes; } bool may_contain_video() const { return may_contain_video_; } diff --git a/chromium/cc/layers/layer_impl_unittest.cc b/chromium/cc/layers/layer_impl_unittest.cc index a353a2032da..b51fae0069a 100644 --- a/chromium/cc/layers/layer_impl_unittest.cc +++ b/chromium/cc/layers/layer_impl_unittest.cc @@ -249,7 +249,6 @@ TEST(LayerImplTest, VerifyNeedsUpdateDrawProperties) { host_impl.active_tree()->SetRootLayerForTesting( LayerImpl::Create(host_impl.active_tree(), 1)); LayerImpl* root = host_impl.active_tree()->root_layer_for_testing(); - root->SetHasRenderSurface(true); std::unique_ptr<LayerImpl> layer_ptr = LayerImpl::Create(host_impl.active_tree(), 2); LayerImpl* layer = layer_ptr.get(); @@ -277,13 +276,11 @@ TEST(LayerImplTest, VerifyNeedsUpdateDrawProperties) { // verified. VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetDrawsContent(true)); VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer2->SetDrawsContent(true)); - // Render surface functions should not trigger update draw properties, because - // creating render surface is part of update draw properties. - VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetHasRenderSurface(true)); - VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetHasRenderSurface(false)); + // Create a render surface, because we must have a render surface if we have // filters. - VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetHasRenderSurface(true)); + layer->test_properties()->force_render_surface = true; + host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting(); // Related filter functions. VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES( @@ -307,6 +304,8 @@ TEST(LayerImplTest, VerifyNeedsUpdateDrawProperties) { VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetBounds(large_size)); VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetBounds(large_size)); host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting(); + host_impl.active_tree()->set_needs_update_draw_properties(); + host_impl.active_tree()->UpdateDrawProperties(false /* update_lcd_text */); VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->ScrollBy(arbitrary_vector2d)); VERIFY_NO_NEEDS_UPDATE_DRAW_PROPERTIES(layer->ScrollBy(gfx::Vector2d())); VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES( @@ -322,6 +321,8 @@ TEST(LayerImplTest, VerifyNeedsUpdateDrawProperties) { // Unrelated functions, always set to new values, always set needs update. host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting(); + host_impl.active_tree()->set_needs_update_draw_properties(); + host_impl.active_tree()->UpdateDrawProperties(false /* update_lcd_text */); VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetMasksToBounds(true); layer->NoteLayerPropertyChanged()); VERIFY_NEEDS_UPDATE_DRAW_PROPERTIES(layer->SetContentsOpaque(true); diff --git a/chromium/cc/layers/layer_iterator.h b/chromium/cc/layers/layer_iterator.h index dc89e113ad3..9eb822415fa 100644 --- a/chromium/cc/layers/layer_iterator.h +++ b/chromium/cc/layers/layer_iterator.h @@ -164,7 +164,7 @@ class LayerIterator { : render_surface_layer_list_(render_surface_layer_list), target_render_surface_layer_index_(0) { for (size_t i = 0; i < render_surface_layer_list->size(); ++i) { - if (!render_surface_layer_list->at(i)->render_surface()) { + if (!render_surface_layer_list->at(i)->GetRenderSurface()) { NOTREACHED(); MoveToEnd(); return; @@ -250,8 +250,8 @@ class LayerIterator { } inline bool current_layer_represents_contributing_render_surface() const { - return current_layer()->render_surface() && - current_layer()->render_surface() != target_render_surface(); + RenderSurfaceImpl* render_surface = current_layer()->GetRenderSurface(); + return render_surface && render_surface != target_render_surface(); } inline bool current_layer_represents_target_render_surface() const { return current_layer_index_ == @@ -259,7 +259,7 @@ class LayerIterator { } inline RenderSurfaceImpl* target_render_surface() const { - return target_render_surface_layer()->render_surface(); + return target_render_surface_layer()->GetRenderSurface(); } inline const LayerImplList& target_render_surface_children() const { return target_render_surface()->layer_list(); diff --git a/chromium/cc/layers/layer_iterator_unittest.cc b/chromium/cc/layers/layer_iterator_unittest.cc index ea51d6fd735..4b93ea6e755 100644 --- a/chromium/cc/layers/layer_iterator_unittest.cc +++ b/chromium/cc/layers/layer_iterator_unittest.cc @@ -57,7 +57,8 @@ void ResetCounts(LayerImplList* render_surface_layer_list) { ++surface_index) { TestLayerImpl* render_surface_layer = static_cast<TestLayerImpl*>( render_surface_layer_list->at(surface_index)); - RenderSurfaceImpl* render_surface = render_surface_layer->render_surface(); + RenderSurfaceImpl* render_surface = + render_surface_layer->GetRenderSurface(); render_surface_layer->count_representing_target_surface_ = -1; render_surface_layer->count_representing_contributing_surface_ = -1; diff --git a/chromium/cc/layers/layer_list_iterator_unittest.cc b/chromium/cc/layers/layer_list_iterator_unittest.cc index 38cedf5c7da..54e1006e4f7 100644 --- a/chromium/cc/layers/layer_list_iterator_unittest.cc +++ b/chromium/cc/layers/layer_list_iterator_unittest.cc @@ -68,7 +68,7 @@ TEST(LayerListIteratorTest, VerifyTraversalOrder) { host->SetRootLayer(std::move(layer1)); int i = 1; - for (auto* layer : *host->GetLayerTree()) { + for (auto* layer : *host) { EXPECT_EQ(i++, layer_id_to_order[layer->id()]); } EXPECT_EQ(8, i); @@ -90,7 +90,7 @@ TEST(LayerListIteratorTest, VerifySingleLayer) { host->SetRootLayer(std::move(layer1)); int i = 1; - for (auto* layer : *host->GetLayerTree()) { + for (auto* layer : *host) { EXPECT_EQ(i++, layer_id_to_order[layer->id()]); } EXPECT_EQ(2, i); @@ -156,7 +156,7 @@ TEST(LayerListReverseIteratorTest, VerifyTraversalOrder) { int i = 7; - for (auto* layer : base::Reversed(*host->GetLayerTree())) { + for (auto* layer : base::Reversed(*host)) { EXPECT_EQ(i--, layer_id_to_order[layer->id()]); } @@ -179,7 +179,7 @@ TEST(LayerListReverseIteratorTest, VerifySingleLayer) { host->SetRootLayer(std::move(layer1)); int i = 1; - for (auto* layer : base::Reversed(*host->GetLayerTree())) { + for (auto* layer : base::Reversed(*host)) { EXPECT_EQ(i--, layer_id_to_order[layer->id()]); } EXPECT_EQ(0, i); diff --git a/chromium/cc/layers/layer_position_constraint.cc b/chromium/cc/layers/layer_position_constraint.cc index 5d8824e2421..183b6b5b53e 100644 --- a/chromium/cc/layers/layer_position_constraint.cc +++ b/chromium/cc/layers/layer_position_constraint.cc @@ -3,7 +3,6 @@ // found in the LICENSE file. #include "cc/layers/layer_position_constraint.h" -#include "cc/proto/layer_position_constraint.pb.h" namespace cc { @@ -13,20 +12,6 @@ LayerPositionConstraint::LayerPositionConstraint() is_fixed_to_bottom_edge_(false) { } -void LayerPositionConstraint::ToProtobuf( - proto::LayerPositionConstraint* proto) const { - proto->set_is_fixed_position(is_fixed_position_); - proto->set_is_fixed_to_right_edge(is_fixed_to_right_edge_); - proto->set_is_fixed_to_bottom_edge(is_fixed_to_bottom_edge_); -} - -void LayerPositionConstraint::FromProtobuf( - const proto::LayerPositionConstraint& proto) { - is_fixed_position_ = proto.is_fixed_position(); - is_fixed_to_right_edge_ = proto.is_fixed_to_right_edge(); - is_fixed_to_bottom_edge_ = proto.is_fixed_to_bottom_edge(); -} - bool LayerPositionConstraint::operator==( const LayerPositionConstraint& other) const { if (!is_fixed_position_ && !other.is_fixed_position_) diff --git a/chromium/cc/layers/layer_position_constraint.h b/chromium/cc/layers/layer_position_constraint.h index 1ee4bc72775..9a575137736 100644 --- a/chromium/cc/layers/layer_position_constraint.h +++ b/chromium/cc/layers/layer_position_constraint.h @@ -9,10 +9,6 @@ namespace cc { -namespace proto { -class LayerPositionConstraint; -} - class CC_EXPORT LayerPositionConstraint { public: LayerPositionConstraint(); @@ -28,9 +24,6 @@ class CC_EXPORT LayerPositionConstraint { } bool is_fixed_to_bottom_edge() const { return is_fixed_to_bottom_edge_; } - void ToProtobuf(proto::LayerPositionConstraint* proto) const; - void FromProtobuf(const proto::LayerPositionConstraint& proto); - bool operator==(const LayerPositionConstraint&) const; bool operator!=(const LayerPositionConstraint&) const; diff --git a/chromium/cc/layers/layer_position_constraint_unittest.cc b/chromium/cc/layers/layer_position_constraint_unittest.cc index b4bea8e2c44..ce8e2149816 100644 --- a/chromium/cc/layers/layer_position_constraint_unittest.cc +++ b/chromium/cc/layers/layer_position_constraint_unittest.cc @@ -9,7 +9,6 @@ #include "cc/animation/animation_host.h" #include "cc/layers/layer.h" #include "cc/layers/layer_impl.h" -#include "cc/proto/layer_position_constraint.pb.h" #include "cc/test/fake_layer_tree_host.h" #include "cc/test/fake_proxy.h" #include "cc/test/geometry_test_utils.h" @@ -135,17 +134,17 @@ class LayerPositionConstraintTest : public testing::Test { root_->AddChild(inner_viewport_container_layer_); layer_tree_host_->SetRootLayer(root_); - layer_tree_host_->GetLayerTree()->RegisterViewportLayers( - nullptr, root_, scroll_layer_, child_); + layer_tree_host_->RegisterViewportLayers(nullptr, root_, scroll_layer_, + child_); } void CommitAndUpdateImplPointers() { LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( root_.get(), root_->bounds()); inputs.inner_viewport_scroll_layer = - layer_tree_host_->GetLayerTree()->inner_viewport_scroll_layer(); + layer_tree_host_->inner_viewport_scroll_layer(); inputs.outer_viewport_scroll_layer = - layer_tree_host_->GetLayerTree()->outer_viewport_scroll_layer(); + layer_tree_host_->outer_viewport_scroll_layer(); LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); // Since scroll deltas aren't sent back to the main thread in this test @@ -460,12 +459,12 @@ TEST_F(LayerPositionConstraintTest, gfx::Transform expected_grand_child_transform; gfx::Transform expected_great_grand_child_transform; expected_great_grand_child_transform.PreconcatTransform(rotation_about_z); - EXPECT_TRUE(grand_child_impl_->render_surface()); + EXPECT_TRUE(grand_child_impl_->GetRenderSurface()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ( expected_surface_draw_transform, - grand_child_impl_->render_surface()->draw_transform()); + grand_child_impl_->GetRenderSurface()->draw_transform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, grand_child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, @@ -497,12 +496,12 @@ TEST_F(LayerPositionConstraintTest, expected_great_grand_child_transform.Translate(10.0, 30.0); expected_great_grand_child_transform.PreconcatTransform(rotation_about_z); - EXPECT_TRUE(grand_child_impl_->render_surface()); + EXPECT_TRUE(grand_child_impl_->GetRenderSurface()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ( expected_surface_draw_transform, - grand_child_impl_->render_surface()->draw_transform()); + grand_child_impl_->GetRenderSurface()->draw_transform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, grand_child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, @@ -604,18 +603,18 @@ TEST_F(LayerPositionConstraintTest, gfx::Transform expected_fixed_position_child_transform; expected_fixed_position_child_transform.PreconcatTransform(rotation_about_z); - EXPECT_TRUE(grand_child_impl_->render_surface()); - EXPECT_TRUE(great_grand_child_impl_->render_surface()); + EXPECT_TRUE(grand_child_impl_->GetRenderSurface()); + EXPECT_TRUE(great_grand_child_impl_->GetRenderSurface()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ( expected_grand_child_surface_draw_transform, - grand_child_impl_->render_surface()->draw_transform()); + grand_child_impl_->GetRenderSurface()->draw_transform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, grand_child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ( expected_great_grand_child_surface_draw_transform, - great_grand_child_impl_->render_surface()->draw_transform()); + great_grand_child_impl_->GetRenderSurface()->draw_transform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, great_grand_child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_fixed_position_child_transform, @@ -644,18 +643,18 @@ TEST_F(LayerPositionConstraintTest, expected_fixed_position_child_transform.Translate(10.0, 30.0); expected_fixed_position_child_transform.PreconcatTransform(rotation_about_z); - EXPECT_TRUE(grand_child_impl_->render_surface()); - EXPECT_TRUE(great_grand_child_impl_->render_surface()); + EXPECT_TRUE(grand_child_impl_->GetRenderSurface()); + EXPECT_TRUE(great_grand_child_impl_->GetRenderSurface()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ( expected_grand_child_surface_draw_transform, - grand_child_impl_->render_surface()->draw_transform()); + grand_child_impl_->GetRenderSurface()->draw_transform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, grand_child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ( expected_great_grand_child_surface_draw_transform, - great_grand_child_impl_->render_surface()->draw_transform()); + great_grand_child_impl_->GetRenderSurface()->draw_transform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, great_grand_child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_fixed_position_child_transform, @@ -766,18 +765,18 @@ TEST_F( gfx::Transform expected_fixed_position_child_transform; expected_fixed_position_child_transform.PreconcatTransform(rotation_about_z); - EXPECT_TRUE(grand_child_impl_->render_surface()); - EXPECT_TRUE(great_grand_child_impl_->render_surface()); + EXPECT_TRUE(grand_child_impl_->GetRenderSurface()); + EXPECT_TRUE(great_grand_child_impl_->GetRenderSurface()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ( expected_grand_child_surface_draw_transform, - grand_child_impl_->render_surface()->draw_transform()); + grand_child_impl_->GetRenderSurface()->draw_transform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, grand_child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ( expected_great_grand_child_surface_draw_transform, - great_grand_child_impl_->render_surface()->draw_transform()); + great_grand_child_impl_->GetRenderSurface()->draw_transform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, great_grand_child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_fixed_position_child_transform, @@ -811,18 +810,18 @@ TEST_F( expected_fixed_position_child_transform.Translate(10.0, 30.0); expected_fixed_position_child_transform.PreconcatTransform(rotation_about_z); - EXPECT_TRUE(grand_child_impl_->render_surface()); - EXPECT_TRUE(great_grand_child_impl_->render_surface()); + EXPECT_TRUE(grand_child_impl_->GetRenderSurface()); + EXPECT_TRUE(great_grand_child_impl_->GetRenderSurface()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ( expected_grand_child_surface_draw_transform, - grand_child_impl_->render_surface()->draw_transform()); + grand_child_impl_->GetRenderSurface()->draw_transform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, grand_child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ( expected_great_grand_child_surface_draw_transform, - great_grand_child_impl_->render_surface()->draw_transform()); + great_grand_child_impl_->GetRenderSurface()->draw_transform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, great_grand_child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_fixed_position_child_transform, @@ -849,10 +848,10 @@ TEST_F(LayerPositionConstraintTest, gfx::Transform expected_surface_draw_transform; gfx::Transform expected_child_transform; gfx::Transform expected_grand_child_transform; - EXPECT_TRUE(child_impl_->render_surface()); + EXPECT_TRUE(child_impl_->GetRenderSurface()); EXPECT_TRANSFORMATION_MATRIX_EQ( expected_surface_draw_transform, - child_impl_->render_surface()->draw_transform()); + child_impl_->GetRenderSurface()->draw_transform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, @@ -870,10 +869,10 @@ TEST_F(LayerPositionConstraintTest, expected_grand_child_transform.MakeIdentity(); expected_grand_child_transform.Translate(10.0, 10.0); - EXPECT_TRUE(child_impl_->render_surface()); + EXPECT_TRUE(child_impl_->GetRenderSurface()); EXPECT_TRANSFORMATION_MATRIX_EQ( expected_surface_draw_transform, - child_impl_->render_surface()->draw_transform()); + child_impl_->GetRenderSurface()->draw_transform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, child_impl_->DrawTransform()); EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, @@ -1147,31 +1146,5 @@ TEST_F(LayerPositionConstraintTest, fixed_child_impl->DrawTransform()); } -void VerifySerializeAndDeserializeProto(bool is_fixed_position, - bool is_fixed_to_right_edge, - bool is_fixed_to_bottom_edge) { - LayerPositionConstraint constraint; - constraint.set_is_fixed_position(is_fixed_position); - constraint.set_is_fixed_to_right_edge(is_fixed_to_right_edge); - constraint.set_is_fixed_to_bottom_edge(is_fixed_to_bottom_edge); - proto::LayerPositionConstraint proto; - constraint.ToProtobuf(&proto); - - LayerPositionConstraint constraint2; - constraint2.FromProtobuf(proto); - EXPECT_EQ(constraint, constraint2); -} - -TEST(LayerPositionConstraintSerializationTest, SerializeAndDeserializeProto) { - VerifySerializeAndDeserializeProto(true, true, true); - VerifySerializeAndDeserializeProto(true, true, false); - VerifySerializeAndDeserializeProto(true, false, true); - VerifySerializeAndDeserializeProto(true, false, false); - VerifySerializeAndDeserializeProto(false, true, true); - VerifySerializeAndDeserializeProto(false, true, false); - VerifySerializeAndDeserializeProto(false, false, true); - VerifySerializeAndDeserializeProto(false, false, false); -} - } // namespace } // namespace cc diff --git a/chromium/cc/layers/layer_sticky_position_constraint.cc b/chromium/cc/layers/layer_sticky_position_constraint.cc index 2b6b33295db..79414d6a877 100644 --- a/chromium/cc/layers/layer_sticky_position_constraint.cc +++ b/chromium/cc/layers/layer_sticky_position_constraint.cc @@ -3,8 +3,6 @@ // found in the LICENSE file. #include "cc/layers/layer_sticky_position_constraint.h" -#include "cc/proto/gfx_conversions.h" -#include "cc/proto/layer_sticky_position_constraint.pb.h" namespace cc { @@ -37,44 +35,6 @@ LayerStickyPositionConstraint::LayerStickyPositionConstraint( scroll_container_relative_containing_block_rect( other.scroll_container_relative_containing_block_rect) {} -void LayerStickyPositionConstraint::ToProtobuf( - proto::LayerStickyPositionConstraint* proto) const { - proto->set_is_sticky(is_sticky); - proto->set_is_anchored_left(is_anchored_left); - proto->set_is_anchored_right(is_anchored_right); - proto->set_is_anchored_top(is_anchored_top); - proto->set_is_anchored_bottom(is_anchored_bottom); - proto->set_left_offset(left_offset); - proto->set_right_offset(right_offset); - proto->set_top_offset(top_offset); - proto->set_bottom_offset(bottom_offset); - PointToProto(parent_relative_sticky_box_offset, - proto->mutable_parent_relative_sticky_box_offset()); - RectToProto(scroll_container_relative_sticky_box_rect, - proto->mutable_scroll_container_relative_sticky_box_rect()); - RectToProto(scroll_container_relative_containing_block_rect, - proto->mutable_scroll_container_relative_containing_block_rect()); -} - -void LayerStickyPositionConstraint::FromProtobuf( - const proto::LayerStickyPositionConstraint& proto) { - is_sticky = proto.is_sticky(); - is_anchored_left = proto.is_anchored_left(); - is_anchored_right = proto.is_anchored_right(); - is_anchored_top = proto.is_anchored_top(); - is_anchored_bottom = proto.is_anchored_bottom(); - left_offset = proto.left_offset(); - right_offset = proto.right_offset(); - top_offset = proto.top_offset(); - bottom_offset = proto.bottom_offset(); - parent_relative_sticky_box_offset = - ProtoToPoint(proto.parent_relative_sticky_box_offset()); - scroll_container_relative_sticky_box_rect = - ProtoToRect(proto.scroll_container_relative_sticky_box_rect()); - scroll_container_relative_containing_block_rect = - ProtoToRect(proto.scroll_container_relative_containing_block_rect()); -} - bool LayerStickyPositionConstraint::operator==( const LayerStickyPositionConstraint& other) const { if (!is_sticky && !other.is_sticky) diff --git a/chromium/cc/layers/layer_sticky_position_constraint.h b/chromium/cc/layers/layer_sticky_position_constraint.h index 51a4da0c0b2..3f43bc7751a 100644 --- a/chromium/cc/layers/layer_sticky_position_constraint.h +++ b/chromium/cc/layers/layer_sticky_position_constraint.h @@ -11,10 +11,6 @@ namespace cc { -namespace proto { -class LayerStickyPositionConstraint; -} - struct CC_EXPORT LayerStickyPositionConstraint { LayerStickyPositionConstraint(); LayerStickyPositionConstraint(const LayerStickyPositionConstraint& other); @@ -48,9 +44,6 @@ struct CC_EXPORT LayerStickyPositionConstraint { // block boundary. gfx::Rect scroll_container_relative_containing_block_rect; - void ToProtobuf(proto::LayerStickyPositionConstraint* proto) const; - void FromProtobuf(const proto::LayerStickyPositionConstraint& proto); - bool operator==(const LayerStickyPositionConstraint&) const; bool operator!=(const LayerStickyPositionConstraint&) const; }; diff --git a/chromium/cc/layers/layer_unittest.cc b/chromium/cc/layers/layer_unittest.cc index d47561b0e19..1a227ca01ae 100644 --- a/chromium/cc/layers/layer_unittest.cc +++ b/chromium/cc/layers/layer_unittest.cc @@ -23,7 +23,6 @@ #include "cc/test/fake_layer_tree_host_client.h" #include "cc/test/fake_layer_tree_host_impl.h" #include "cc/test/geometry_test_utils.h" -#include "cc/test/layer_internals_for_test.h" #include "cc/test/layer_test_common.h" #include "cc/test/stub_layer_tree_host_single_thread_client.h" #include "cc/test/test_task_graph_runner.h" @@ -47,67 +46,61 @@ using ::testing::Mock; using ::testing::StrictMock; using ::testing::_; -#define EXPECT_SET_NEEDS_FULL_TREE_SYNC(expect, code_to_test) \ - do { \ - EXPECT_CALL(*layer_tree_, SetNeedsFullTreeSync()).Times((expect)); \ - code_to_test; \ - Mock::VerifyAndClearExpectations(layer_tree_); \ +#define EXPECT_SET_NEEDS_FULL_TREE_SYNC(expect, code_to_test) \ + do { \ + EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times((expect)); \ + code_to_test; \ + Mock::VerifyAndClearExpectations(layer_tree_host_.get()); \ } while (false) -#define EXECUTE_AND_VERIFY_SUBTREE_CHANGED(code_to_test) \ - code_to_test; \ - root->GetLayerTree()->BuildPropertyTreesForTesting(); \ - EXPECT_TRUE(root->subtree_property_changed()); \ - EXPECT_TRUE( \ - root->GetLayerTree()->LayerNeedsPushPropertiesForTesting(root.get())); \ - EXPECT_TRUE(child->subtree_property_changed()); \ - EXPECT_TRUE( \ - child->GetLayerTree()->LayerNeedsPushPropertiesForTesting(child.get())); \ - EXPECT_TRUE(grand_child->subtree_property_changed()); \ - EXPECT_TRUE(grand_child->GetLayerTree()->LayerNeedsPushPropertiesForTesting( \ - grand_child.get())); - -#define EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET(code_to_test) \ - code_to_test; \ - EXPECT_FALSE(root->subtree_property_changed()); \ - EXPECT_FALSE( \ - root->GetLayerTree()->LayerNeedsPushPropertiesForTesting(root.get())); \ - EXPECT_FALSE(child->subtree_property_changed()); \ - EXPECT_FALSE( \ - child->GetLayerTree()->LayerNeedsPushPropertiesForTesting(child.get())); \ - EXPECT_FALSE(grand_child->subtree_property_changed()); \ - EXPECT_FALSE( \ - grand_child->GetLayerTree()->LayerNeedsPushPropertiesForTesting( \ +#define EXECUTE_AND_VERIFY_SUBTREE_CHANGED(code_to_test) \ + code_to_test; \ + root->layer_tree_host()->BuildPropertyTreesForTesting(); \ + EXPECT_TRUE(root->subtree_property_changed()); \ + EXPECT_TRUE(root->layer_tree_host()->LayerNeedsPushPropertiesForTesting( \ + root.get())); \ + EXPECT_TRUE(child->subtree_property_changed()); \ + EXPECT_TRUE(child->layer_tree_host()->LayerNeedsPushPropertiesForTesting( \ + child.get())); \ + EXPECT_TRUE(grand_child->subtree_property_changed()); \ + EXPECT_TRUE( \ + grand_child->layer_tree_host()->LayerNeedsPushPropertiesForTesting( \ + grand_child.get())); + +#define EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET(code_to_test) \ + code_to_test; \ + EXPECT_FALSE(root->subtree_property_changed()); \ + EXPECT_FALSE(root->layer_tree_host()->LayerNeedsPushPropertiesForTesting( \ + root.get())); \ + EXPECT_FALSE(child->subtree_property_changed()); \ + EXPECT_FALSE(child->layer_tree_host()->LayerNeedsPushPropertiesForTesting( \ + child.get())); \ + EXPECT_FALSE(grand_child->subtree_property_changed()); \ + EXPECT_FALSE( \ + grand_child->layer_tree_host()->LayerNeedsPushPropertiesForTesting( \ grand_child.get())); namespace cc { namespace { -class MockLayerTree : public LayerTree { - public: - MockLayerTree(LayerTreeHostInProcess::InitParams* params, - LayerTreeHost* layer_tree_host) - : LayerTree(params->mutator_host, layer_tree_host) {} - ~MockLayerTree() override {} +static auto kArbitrarySourceId1 = + base::UnguessableToken::Deserialize(0xdead, 0xbeef); +static auto kArbitrarySourceId2 = + base::UnguessableToken::Deserialize(0xdead, 0xbee0); - MOCK_METHOD0(SetNeedsFullTreeSync, void()); -}; - -class MockLayerTreeHost : public LayerTreeHostInProcess { +class MockLayerTreeHost : public LayerTreeHost { public: MockLayerTreeHost(LayerTreeHostSingleThreadClient* single_thread_client, - LayerTreeHostInProcess::InitParams* params) - : LayerTreeHostInProcess( - params, - CompositorMode::SINGLE_THREADED, - base::MakeUnique<StrictMock<MockLayerTree>>(params, this)) { + LayerTreeHost::InitParams* params) + : LayerTreeHost(params, CompositorMode::SINGLE_THREADED) { InitializeSingleThreaded(single_thread_client, base::ThreadTaskRunnerHandle::Get()); } MOCK_METHOD0(SetNeedsCommit, void()); MOCK_METHOD0(SetNeedsUpdateLayers, void()); + MOCK_METHOD0(SetNeedsFullTreeSync, void()); }; class LayerTest : public testing::Test { @@ -129,7 +122,7 @@ class LayerTest : public testing::Test { void SetUp() override { animation_host_ = AnimationHost::CreateForTesting(ThreadInstance::MAIN); - LayerTreeHostInProcess::InitParams params; + LayerTreeHost::InitParams params; params.client = &fake_client_; params.settings = &settings_; params.task_graph_runner = &task_graph_runner_; @@ -137,14 +130,11 @@ class LayerTest : public testing::Test { layer_tree_host_.reset( new StrictMock<MockLayerTreeHost>(&single_thread_client_, ¶ms)); - layer_tree_ = static_cast<StrictMock<MockLayerTree>*>( - layer_tree_host_->GetLayerTree()); } void TearDown() override { Mock::VerifyAndClearExpectations(layer_tree_host_.get()); - Mock::VerifyAndClearExpectations(layer_tree_); - EXPECT_CALL(*layer_tree_, SetNeedsFullTreeSync()).Times(AnyNumber()); + EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AnyNumber()); parent_ = nullptr; child1_ = nullptr; child2_ = nullptr; @@ -153,11 +143,10 @@ class LayerTest : public testing::Test { grand_child2_ = nullptr; grand_child3_ = nullptr; - layer_tree_->SetRootLayer(nullptr); + layer_tree_host_->SetRootLayer(nullptr); animation_host_->SetMutatorHostClient(nullptr); layer_tree_host_ = nullptr; animation_host_ = nullptr; - layer_tree_ = nullptr; } void VerifyTestTreeInitialState() const { @@ -191,8 +180,8 @@ class LayerTest : public testing::Test { grand_child2_ = Layer::Create(); grand_child3_ = Layer::Create(); - EXPECT_CALL(*layer_tree_, SetNeedsFullTreeSync()).Times(AnyNumber()); - layer_tree_->SetRootLayer(parent_); + EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AnyNumber()); + layer_tree_host_->SetRootLayer(parent_); parent_->AddChild(child1_); parent_->AddChild(child2_); @@ -201,7 +190,7 @@ class LayerTest : public testing::Test { child1_->AddChild(grand_child2_); child2_->AddChild(grand_child3_); - Mock::VerifyAndClearExpectations(layer_tree_); + Mock::VerifyAndClearExpectations(layer_tree_host_.get()); VerifyTestTreeInitialState(); } @@ -214,7 +203,6 @@ class LayerTest : public testing::Test { FakeLayerTreeHostClient fake_client_; std::unique_ptr<StrictMock<MockLayerTreeHost>> layer_tree_host_; std::unique_ptr<AnimationHost> animation_host_; - StrictMock<MockLayerTree>* layer_tree_; scoped_refptr<Layer> parent_; scoped_refptr<Layer> child1_; scoped_refptr<Layer> child2_; @@ -241,14 +229,14 @@ TEST_F(LayerTest, BasicCreateAndDestroy) { } TEST_F(LayerTest, LayerPropertyChangedForSubtree) { - EXPECT_CALL(*layer_tree_, SetNeedsFullTreeSync()).Times(AtLeast(1)); + EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AtLeast(1)); scoped_refptr<Layer> root = Layer::Create(); scoped_refptr<Layer> child = Layer::Create(); scoped_refptr<Layer> child2 = Layer::Create(); scoped_refptr<Layer> grand_child = Layer::Create(); scoped_refptr<Layer> dummy_layer1 = Layer::Create(); - layer_tree_->SetRootLayer(root); + layer_tree_host_->SetRootLayer(root); root->AddChild(child); root->AddChild(child2); child->AddChild(grand_child); @@ -268,7 +256,7 @@ TEST_F(LayerTest, LayerPropertyChangedForSubtree) { std::unique_ptr<LayerImpl> dummy_layer1_impl = LayerImpl::Create(host_impl_.active_tree(), dummy_layer1->id()); - EXPECT_CALL(*layer_tree_, SetNeedsFullTreeSync()).Times(1); + EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(1); EXECUTE_AND_VERIFY_SUBTREE_CHANGED(root->SetMaskLayer(dummy_layer1.get())); EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET( root->PushPropertiesTo(root_impl.get()); @@ -366,7 +354,7 @@ TEST_F(LayerTest, LayerPropertyChangedForSubtree) { gfx::PointF arbitrary_point_f = gfx::PointF(0.125f, 0.25f); EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); root->SetPosition(arbitrary_point_f); - TransformNode* node = layer_tree_->property_trees()->transform_tree.Node( + TransformNode* node = layer_tree_host_->property_trees()->transform_tree.Node( root->transform_tree_index()); EXPECT_TRUE(node->transform_changed); EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET( @@ -374,33 +362,33 @@ TEST_F(LayerTest, LayerPropertyChangedForSubtree) { child->PushPropertiesTo(child_impl.get()); child2->PushPropertiesTo(child2_impl.get()); grand_child->PushPropertiesTo(grand_child_impl.get()); - layer_tree_->property_trees()->ResetAllChangeTracking()); + layer_tree_host_->property_trees()->ResetAllChangeTracking()); EXPECT_FALSE(node->transform_changed); EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); child->SetPosition(arbitrary_point_f); - node = layer_tree_->property_trees()->transform_tree.Node( + node = layer_tree_host_->property_trees()->transform_tree.Node( child->transform_tree_index()); EXPECT_TRUE(node->transform_changed); // child2 is not in the subtree of child, but its scroll parent is. So, its // to_screen will be effected by change in position of child2. - layer_tree_->property_trees()->transform_tree.UpdateTransforms( + layer_tree_host_->property_trees()->transform_tree.UpdateTransforms( child2->transform_tree_index()); - node = layer_tree_->property_trees()->transform_tree.Node( + node = layer_tree_host_->property_trees()->transform_tree.Node( child2->transform_tree_index()); EXPECT_TRUE(node->transform_changed); EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET( child->PushPropertiesTo(child_impl.get()); grand_child->PushPropertiesTo(grand_child_impl.get()); - layer_tree_->property_trees()->ResetAllChangeTracking()); - node = layer_tree_->property_trees()->transform_tree.Node( + layer_tree_host_->property_trees()->ResetAllChangeTracking()); + node = layer_tree_host_->property_trees()->transform_tree.Node( child->transform_tree_index()); EXPECT_FALSE(node->transform_changed); gfx::Point3F arbitrary_point_3f = gfx::Point3F(0.125f, 0.25f, 0.f); EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); root->SetTransformOrigin(arbitrary_point_3f); - node = layer_tree_->property_trees()->transform_tree.Node( + node = layer_tree_host_->property_trees()->transform_tree.Node( root->transform_tree_index()); EXPECT_TRUE(node->transform_changed); EXECUTE_AND_VERIFY_SUBTREE_CHANGES_RESET( @@ -408,13 +396,13 @@ TEST_F(LayerTest, LayerPropertyChangedForSubtree) { child->PushPropertiesTo(child_impl.get()); child2->PushPropertiesTo(child2_impl.get()); grand_child->PushPropertiesTo(grand_child_impl.get()); - layer_tree_->property_trees()->ResetAllChangeTracking()); + layer_tree_host_->property_trees()->ResetAllChangeTracking()); gfx::Transform arbitrary_transform; arbitrary_transform.Scale3d(0.1f, 0.2f, 0.3f); EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); root->SetTransform(arbitrary_transform); - node = layer_tree_->property_trees()->transform_tree.Node( + node = layer_tree_host_->property_trees()->transform_tree.Node( root->transform_tree_index()); EXPECT_TRUE(node->transform_changed); } @@ -427,7 +415,7 @@ TEST_F(LayerTest, AddAndRemoveChild) { ASSERT_EQ(0U, parent->children().size()); EXPECT_FALSE(child->parent()); - EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_->SetRootLayer(parent)); + EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, parent->AddChild(child)); ASSERT_EQ(1U, parent->children().size()); @@ -439,12 +427,12 @@ TEST_F(LayerTest, AddAndRemoveChild) { } TEST_F(LayerTest, AddSameChildTwice) { - EXPECT_CALL(*layer_tree_, SetNeedsFullTreeSync()).Times(AtLeast(1)); + EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AtLeast(1)); scoped_refptr<Layer> parent = Layer::Create(); scoped_refptr<Layer> child = Layer::Create(); - layer_tree_->SetRootLayer(parent); + layer_tree_host_->SetRootLayer(parent); ASSERT_EQ(0u, parent->children().size()); @@ -464,7 +452,7 @@ TEST_F(LayerTest, InsertChild) { scoped_refptr<Layer> child3 = Layer::Create(); scoped_refptr<Layer> child4 = Layer::Create(); - EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_->SetRootLayer(parent)); + EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); ASSERT_EQ(0U, parent->children().size()); @@ -499,7 +487,7 @@ TEST_F(LayerTest, InsertChild) { EXPECT_EQ(child4, parent->children()[3]); EXPECT_EQ(parent.get(), child4->parent()); - EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_->SetRootLayer(nullptr)); + EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); } TEST_F(LayerTest, InsertChildPastEndOfList) { @@ -528,7 +516,7 @@ TEST_F(LayerTest, InsertSameChildTwice) { scoped_refptr<Layer> child1 = Layer::Create(); scoped_refptr<Layer> child2 = Layer::Create(); - EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_->SetRootLayer(parent)); + EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); ASSERT_EQ(0U, parent->children().size()); @@ -548,7 +536,7 @@ TEST_F(LayerTest, InsertSameChildTwice) { EXPECT_EQ(child2, parent->children()[0]); EXPECT_EQ(child1, parent->children()[1]); - EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_->SetRootLayer(nullptr)); + EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); } TEST_F(LayerTest, ReplaceChildWithNewChild) { @@ -605,7 +593,7 @@ TEST_F(LayerTest, DeleteRemovedScrollParent) { scoped_refptr<Layer> child1 = Layer::Create(); scoped_refptr<Layer> child2 = Layer::Create(); - EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_->SetRootLayer(parent)); + EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); ASSERT_EQ(0U, parent->children().size()); @@ -624,9 +612,10 @@ TEST_F(LayerTest, DeleteRemovedScrollParent) { EXPECT_SET_NEEDS_COMMIT(1, child2 = nullptr); - EXPECT_TRUE(layer_tree_->LayerNeedsPushPropertiesForTesting(child1.get())); + EXPECT_TRUE( + layer_tree_host_->LayerNeedsPushPropertiesForTesting(child1.get())); - EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_->SetRootLayer(nullptr)); + EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); } TEST_F(LayerTest, DeleteRemovedScrollChild) { @@ -634,7 +623,7 @@ TEST_F(LayerTest, DeleteRemovedScrollChild) { scoped_refptr<Layer> child1 = Layer::Create(); scoped_refptr<Layer> child2 = Layer::Create(); - EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_->SetRootLayer(parent)); + EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(parent)); ASSERT_EQ(0U, parent->children().size()); @@ -653,9 +642,10 @@ TEST_F(LayerTest, DeleteRemovedScrollChild) { EXPECT_SET_NEEDS_COMMIT(1, child1 = nullptr); - EXPECT_TRUE(layer_tree_->LayerNeedsPushPropertiesForTesting(child2.get())); + EXPECT_TRUE( + layer_tree_host_->LayerNeedsPushPropertiesForTesting(child2.get())); - EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_->SetRootLayer(nullptr)); + EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); } TEST_F(LayerTest, ReplaceChildWithSameChild) { @@ -664,7 +654,7 @@ TEST_F(LayerTest, ReplaceChildWithSameChild) { // SetNeedsFullTreeSync / SetNeedsCommit should not be called because its the // same child. EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); - EXPECT_CALL(*layer_tree_, SetNeedsFullTreeSync()).Times(0); + EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(0); parent_->ReplaceChild(child2_.get(), child2_); VerifyTestTreeInitialState(); @@ -699,7 +689,8 @@ TEST_F(LayerTest, SetChildren) { EXPECT_EQ(old_parent.get(), child1->parent()); EXPECT_FALSE(child2->parent()); - EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_->SetRootLayer(new_parent)); + EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, + layer_tree_host_->SetRootLayer(new_parent)); EXPECT_SET_NEEDS_FULL_TREE_SYNC( AtLeast(1), new_parent->SetChildren(new_children)); @@ -708,7 +699,7 @@ TEST_F(LayerTest, SetChildren) { EXPECT_EQ(new_parent.get(), child1->parent()); EXPECT_EQ(new_parent.get(), child2->parent()); - EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_->SetRootLayer(nullptr)); + EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(nullptr)); } TEST_F(LayerTest, HasAncestor) { @@ -736,7 +727,7 @@ TEST_F(LayerTest, GetRootLayerAfterTreeManipulations) { CreateSimpleTestTree(); // For this test we don't care about SetNeedsFullTreeSync calls. - EXPECT_CALL(*layer_tree_, SetNeedsFullTreeSync()).Times(AnyNumber()); + EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times(AnyNumber()); scoped_refptr<Layer> child4 = Layer::Create(); @@ -794,7 +785,8 @@ TEST_F(LayerTest, CheckSetNeedsDisplayCausesCorrectBehavior) { // SetNeedsDisplay. scoped_refptr<Layer> test_layer = Layer::Create(); - EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_->SetRootLayer(test_layer)); + EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, + layer_tree_host_->SetRootLayer(test_layer)); EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true)); gfx::Size test_bounds = gfx::Size(501, 508); @@ -845,7 +837,8 @@ TEST_F(LayerTest, CheckSetNeedsDisplayCausesCorrectBehavior) { TEST_F(LayerTest, TestSettingMainThreadScrollingReason) { scoped_refptr<Layer> test_layer = Layer::Create(); - EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_->SetRootLayer(test_layer)); + EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, + layer_tree_host_->SetRootLayer(test_layer)); EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true)); // sanity check of initial test condition @@ -897,7 +890,8 @@ TEST_F(LayerTest, TestSettingMainThreadScrollingReason) { TEST_F(LayerTest, CheckPropertyChangeCausesCorrectBehavior) { scoped_refptr<Layer> test_layer = Layer::Create(); - EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_->SetRootLayer(test_layer)); + EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, + layer_tree_host_->SetRootLayer(test_layer)); EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetIsDrawable(true)); scoped_refptr<Layer> dummy_layer1 = Layer::Create(); @@ -946,7 +940,7 @@ TEST_F(LayerTest, CheckPropertyChangeCausesCorrectBehavior) { EXPECT_FALSE(test_layer->NeedsDisplayForTesting()); // As layers are removed from the tree, they will cause a tree sync. - EXPECT_CALL(*layer_tree_, SetNeedsFullTreeSync()).Times((AnyNumber())); + EXPECT_CALL(*layer_tree_host_, SetNeedsFullTreeSync()).Times((AnyNumber())); } TEST_F(LayerTest, PushPropertiesAccumulatesUpdateRect) { @@ -954,7 +948,8 @@ TEST_F(LayerTest, PushPropertiesAccumulatesUpdateRect) { std::unique_ptr<LayerImpl> impl_layer = LayerImpl::Create(host_impl_.active_tree(), 1); - EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_->SetRootLayer(test_layer)); + EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, + layer_tree_host_->SetRootLayer(test_layer)); host_impl_.active_tree()->SetRootLayerForTesting(std::move(impl_layer)); host_impl_.active_tree()->BuildLayerListForTesting(); @@ -985,7 +980,8 @@ TEST_F(LayerTest, PushPropertiesCausesLayerPropertyChangedForTransform) { std::unique_ptr<LayerImpl> impl_layer = LayerImpl::Create(host_impl_.active_tree(), 1); - EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_->SetRootLayer(test_layer)); + EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, + layer_tree_host_->SetRootLayer(test_layer)); gfx::Transform transform; transform.Rotate(45.0); @@ -1003,7 +999,8 @@ TEST_F(LayerTest, PushPropertiesCausesLayerPropertyChangedForOpacity) { std::unique_ptr<LayerImpl> impl_layer = LayerImpl::Create(host_impl_.active_tree(), 1); - EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_->SetRootLayer(test_layer)); + EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, + layer_tree_host_->SetRootLayer(test_layer)); EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetOpacity(0.5f)); @@ -1039,15 +1036,14 @@ class LayerTreeHostFactory { std::unique_ptr<LayerTreeHost> Create(LayerTreeSettings settings, MutatorHost* mutator_host) { - LayerTreeHostInProcess::InitParams params; + LayerTreeHost::InitParams params; params.client = &client_; params.task_graph_runner = &task_graph_runner_; params.settings = &settings; params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); params.mutator_host = mutator_host; - return LayerTreeHostInProcess::CreateSingleThreaded(&single_thread_client_, - ¶ms); + return LayerTreeHost::CreateSingleThreaded(&single_thread_client_, ¶ms); } private: @@ -1085,16 +1081,15 @@ TEST_F(LayerLayerTreeHostTest, EnteringTree) { auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN); std::unique_ptr<LayerTreeHost> layer_tree_host = factory.Create(animation_host.get()); - LayerTree* layer_tree = layer_tree_host->GetLayerTree(); // Setting the root layer should set the host pointer for all layers in the // tree. - layer_tree->SetRootLayer(parent.get()); + layer_tree_host->SetRootLayer(parent.get()); AssertLayerTreeHostMatchesForSubtree(parent.get(), layer_tree_host.get()); // Clearing the root layer should also clear out the host pointers for all // layers in the tree. - layer_tree->SetRootLayer(nullptr); + layer_tree_host->SetRootLayer(nullptr); AssertLayerTreeHostMatchesForSubtree(parent.get(), nullptr); } @@ -1106,9 +1101,8 @@ TEST_F(LayerLayerTreeHostTest, AddingLayerSubtree) { auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN); std::unique_ptr<LayerTreeHost> layer_tree_host = factory.Create(animation_host.get()); - LayerTree* layer_tree = layer_tree_host->GetLayerTree(); - layer_tree->SetRootLayer(parent.get()); + layer_tree_host->SetRootLayer(parent.get()); EXPECT_EQ(parent->GetLayerTreeHostForTesting(), layer_tree_host.get()); @@ -1125,7 +1119,7 @@ TEST_F(LayerLayerTreeHostTest, AddingLayerSubtree) { parent->AddChild(child); AssertLayerTreeHostMatchesForSubtree(parent.get(), layer_tree_host.get()); - layer_tree->SetRootLayer(nullptr); + layer_tree_host->SetRootLayer(nullptr); } TEST_F(LayerLayerTreeHostTest, ChangeHost) { @@ -1141,7 +1135,7 @@ TEST_F(LayerLayerTreeHostTest, ChangeHost) { auto animation_host1 = AnimationHost::CreateForTesting(ThreadInstance::MAIN); std::unique_ptr<LayerTreeHost> first_layer_tree_host = factory.Create(animation_host1.get()); - first_layer_tree_host->GetLayerTree()->SetRootLayer(parent.get()); + first_layer_tree_host->SetRootLayer(parent.get()); AssertLayerTreeHostMatchesForSubtree(parent.get(), first_layer_tree_host.get()); @@ -1151,12 +1145,12 @@ TEST_F(LayerLayerTreeHostTest, ChangeHost) { auto animation_host2 = AnimationHost::CreateForTesting(ThreadInstance::MAIN); std::unique_ptr<LayerTreeHost> second_layer_tree_host = factory.Create(animation_host2.get()); - second_layer_tree_host->GetLayerTree()->SetRootLayer(parent.get()); + second_layer_tree_host->SetRootLayer(parent.get()); AssertLayerTreeHostMatchesForSubtree(parent.get(), second_layer_tree_host.get()); - second_layer_tree_host->GetLayerTree()->SetRootLayer(nullptr); + second_layer_tree_host->SetRootLayer(nullptr); } TEST_F(LayerLayerTreeHostTest, ChangeHostInSubtree) { @@ -1175,7 +1169,7 @@ TEST_F(LayerLayerTreeHostTest, ChangeHostInSubtree) { auto animation_host1 = AnimationHost::CreateForTesting(ThreadInstance::MAIN); std::unique_ptr<LayerTreeHost> first_layer_tree_host = factory.Create(animation_host1.get()); - first_layer_tree_host->GetLayerTree()->SetRootLayer(first_parent.get()); + first_layer_tree_host->SetRootLayer(first_parent.get()); AssertLayerTreeHostMatchesForSubtree(first_parent.get(), first_layer_tree_host.get()); @@ -1185,7 +1179,7 @@ TEST_F(LayerLayerTreeHostTest, ChangeHostInSubtree) { auto animation_host2 = AnimationHost::CreateForTesting(ThreadInstance::MAIN); std::unique_ptr<LayerTreeHost> second_layer_tree_host = factory.Create(animation_host2.get()); - second_layer_tree_host->GetLayerTree()->SetRootLayer(second_parent.get()); + second_layer_tree_host->SetRootLayer(second_parent.get()); second_parent->AddChild(second_child); @@ -1196,8 +1190,8 @@ TEST_F(LayerLayerTreeHostTest, ChangeHostInSubtree) { second_grand_child->GetLayerTreeHostForTesting()); // Test over, cleanup time. - first_layer_tree_host->GetLayerTree()->SetRootLayer(nullptr); - second_layer_tree_host->GetLayerTree()->SetRootLayer(nullptr); + first_layer_tree_host->SetRootLayer(nullptr); + second_layer_tree_host->SetRootLayer(nullptr); } TEST_F(LayerLayerTreeHostTest, ReplaceMaskLayer) { @@ -1213,7 +1207,7 @@ TEST_F(LayerLayerTreeHostTest, ReplaceMaskLayer) { auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN); std::unique_ptr<LayerTreeHost> layer_tree_host = factory.Create(animation_host.get()); - layer_tree_host->GetLayerTree()->SetRootLayer(parent.get()); + layer_tree_host->SetRootLayer(parent.get()); AssertLayerTreeHostMatchesForSubtree(parent.get(), layer_tree_host.get()); @@ -1223,7 +1217,7 @@ TEST_F(LayerLayerTreeHostTest, ReplaceMaskLayer) { EXPECT_EQ(nullptr, mask_child->GetLayerTreeHostForTesting()); // Test over, cleanup time. - layer_tree_host->GetLayerTree()->SetRootLayer(nullptr); + layer_tree_host->SetRootLayer(nullptr); } TEST_F(LayerLayerTreeHostTest, DestroyHostWithNonNullRootLayer) { @@ -1234,7 +1228,7 @@ TEST_F(LayerLayerTreeHostTest, DestroyHostWithNonNullRootLayer) { auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN); std::unique_ptr<LayerTreeHost> layer_tree_host = factory.Create(animation_host.get()); - layer_tree_host->GetLayerTree()->SetRootLayer(root); + layer_tree_host->SetRootLayer(root); } TEST_F(LayerTest, SafeOpaqueBackgroundColor) { @@ -1242,10 +1236,9 @@ TEST_F(LayerTest, SafeOpaqueBackgroundColor) { auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN); std::unique_ptr<LayerTreeHost> layer_tree_host = factory.Create(animation_host.get()); - LayerTree* layer_tree = layer_tree_host->GetLayerTree(); scoped_refptr<Layer> layer = Layer::Create(); - layer_tree->SetRootLayer(layer); + layer_tree_host->SetRootLayer(layer); for (int contents_opaque = 0; contents_opaque < 2; ++contents_opaque) { for (int layer_opaque = 0; layer_opaque < 2; ++layer_opaque) { @@ -1253,11 +1246,11 @@ TEST_F(LayerTest, SafeOpaqueBackgroundColor) { layer->SetContentsOpaque(!!contents_opaque); layer->SetBackgroundColor(layer_opaque ? SK_ColorRED : SK_ColorTRANSPARENT); - layer_tree->set_background_color(host_opaque ? SK_ColorRED - : SK_ColorTRANSPARENT); + layer_tree_host->set_background_color( + host_opaque ? SK_ColorRED : SK_ColorTRANSPARENT); - layer_tree->property_trees()->needs_rebuild = true; - layer_tree_host->GetLayerTree()->BuildPropertyTreesForTesting(); + layer_tree_host->property_trees()->needs_rebuild = true; + layer_tree_host->BuildPropertyTreesForTesting(); SkColor safe_color = layer->SafeOpaqueBackgroundColor(); if (contents_opaque) { EXPECT_EQ(SkColorGetA(safe_color), 255u) @@ -1346,19 +1339,19 @@ TEST_F(LayerTest, DedupesCopyOutputRequestsBySource) { result_count = 0; // Create identical requests, but this time the source is being set. Expect - // the first request from |this| source aborts immediately when the second - // request from |this| source is made. + // the first request using |kArbitrarySourceId1| aborts immediately when + // the second request using |kArbitrarySourceId1| is made. int did_receive_first_result_from_this_source = 0; request = CopyOutputRequest::CreateRequest(base::Bind( &ReceiveCopyOutputResult, &did_receive_first_result_from_this_source)); - request->set_source(this); + request->set_source(kArbitrarySourceId1); layer->RequestCopyOfOutput(std::move(request)); EXPECT_EQ(0, did_receive_first_result_from_this_source); // Make a request from a different source. int did_receive_result_from_different_source = 0; request = CopyOutputRequest::CreateRequest(base::Bind( &ReceiveCopyOutputResult, &did_receive_result_from_different_source)); - request->set_source(reinterpret_cast<void*>(0xdeadbee0)); + request->set_source(kArbitrarySourceId2); layer->RequestCopyOfOutput(std::move(request)); EXPECT_EQ(0, did_receive_result_from_different_source); // Make a request without specifying the source. @@ -1367,11 +1360,11 @@ TEST_F(LayerTest, DedupesCopyOutputRequestsBySource) { &ReceiveCopyOutputResult, &did_receive_result_from_anonymous_source)); layer->RequestCopyOfOutput(std::move(request)); EXPECT_EQ(0, did_receive_result_from_anonymous_source); - // Make the second request from |this| source. + // Make the second request from |kArbitrarySourceId1|. int did_receive_second_result_from_this_source = 0; request = CopyOutputRequest::CreateRequest(base::Bind( &ReceiveCopyOutputResult, &did_receive_second_result_from_this_source)); - request->set_source(this); + request->set_source(kArbitrarySourceId1); layer->RequestCopyOfOutput( std::move(request)); // First request to be aborted. EXPECT_EQ(1, did_receive_first_result_from_this_source); @@ -1388,25 +1381,31 @@ TEST_F(LayerTest, DedupesCopyOutputRequestsBySource) { } TEST_F(LayerTest, AnimationSchedulesLayerUpdate) { + // TODO(weiliangc): This is really a LayerTreeHost unittest by this point, + // though currently there is no good place for this unittest to go. Move to + // LayerTreeHost unittest when there is a good setup. scoped_refptr<Layer> layer = Layer::Create(); - EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_->SetRootLayer(layer)); - - LayerInternalsForTest layer_internals(layer.get()); + layer->SetElementId(ElementId(2, 0)); + EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_host_->SetRootLayer(layer)); + auto element_id = layer->element_id(); EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(1); - layer_internals.OnOpacityAnimated(0.5f); + layer_tree_host_->SetElementOpacityMutated(element_id, + ElementListType::ACTIVE, 0.5f); Mock::VerifyAndClearExpectations(layer_tree_host_.get()); EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(1); gfx::Transform transform; transform.Rotate(45.0); - layer_internals.OnTransformAnimated(transform); + layer_tree_host_->SetElementTransformMutated( + element_id, ElementListType::ACTIVE, transform); Mock::VerifyAndClearExpectations(layer_tree_host_.get()); // Scroll offset animation should not schedule a layer update since it is // handled similarly to normal compositor scroll updates. EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(0); - layer_internals.OnScrollOffsetAnimated(gfx::ScrollOffset(10, 10)); + layer_tree_host_->SetElementScrollOffsetMutated( + element_id, ElementListType::ACTIVE, gfx::ScrollOffset(10, 10)); Mock::VerifyAndClearExpectations(layer_tree_host_.get()); } @@ -1415,7 +1414,8 @@ TEST_F(LayerTest, ElementIdAndMutablePropertiesArePushed) { std::unique_ptr<LayerImpl> impl_layer = LayerImpl::Create(host_impl_.active_tree(), 1); - EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, layer_tree_->SetRootLayer(test_layer)); + EXPECT_SET_NEEDS_FULL_TREE_SYNC(1, + layer_tree_host_->SetRootLayer(test_layer)); EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(2); diff --git a/chromium/cc/layers/nine_patch_layer.cc b/chromium/cc/layers/nine_patch_layer.cc index 84aaee542c4..03d3c8f3e36 100644 --- a/chromium/cc/layers/nine_patch_layer.cc +++ b/chromium/cc/layers/nine_patch_layer.cc @@ -70,11 +70,8 @@ void NinePatchLayer::PushPropertiesTo(LayerImpl* layer) { TRACE_EVENT0("cc", "NinePatchLayer::PushPropertiesTo"); NinePatchLayerImpl* layer_impl = static_cast<NinePatchLayerImpl*>(layer); - if (!ui_resource_holder_) { - layer_impl->SetUIResourceId(0); - } else { + if (resource_id()) { DCHECK(layer_tree_host()); - layer_impl->SetLayout(image_aperture_, border_, layer_occlusion_, fill_center_, nearest_neighbor_); } diff --git a/chromium/cc/layers/nine_patch_layer_impl.cc b/chromium/cc/layers/nine_patch_layer_impl.cc index 436905a4481..c79a76dfb42 100644 --- a/chromium/cc/layers/nine_patch_layer_impl.cc +++ b/chromium/cc/layers/nine_patch_layer_impl.cc @@ -10,30 +10,13 @@ #include "cc/quads/texture_draw_quad.h" #include "cc/trees/layer_tree_impl.h" #include "cc/trees/occlusion.h" +#include "ui/gfx/geometry/rect_conversions.h" #include "ui/gfx/geometry/rect_f.h" namespace cc { -// Maximum number of patches that can be produced for one NinePatchLayer. -static const int kMaxOcclusionPatches = 12; -static const int kMaxPatches = 9; - -namespace { - -gfx::Rect ToRect(const gfx::RectF& rect) { - return gfx::Rect(rect.x(), rect.y(), rect.width(), rect.height()); -} - -} // namespace - -NinePatchLayerImpl::Patch::Patch(const gfx::RectF& image_rect, - const gfx::RectF& layer_rect) - : image_rect(image_rect), layer_rect(layer_rect) {} - NinePatchLayerImpl::NinePatchLayerImpl(LayerTreeImpl* tree_impl, int id) - : UIResourceLayerImpl(tree_impl, id), - fill_center_(false), - nearest_neighbor_(false) {} + : UIResourceLayerImpl(tree_impl, id) {} NinePatchLayerImpl::~NinePatchLayerImpl() {} @@ -46,19 +29,7 @@ void NinePatchLayerImpl::PushPropertiesTo(LayerImpl* layer) { UIResourceLayerImpl::PushPropertiesTo(layer); NinePatchLayerImpl* layer_impl = static_cast<NinePatchLayerImpl*>(layer); - layer_impl->SetLayout(image_aperture_, border_, layer_occlusion_, - fill_center_, nearest_neighbor_); -} - -static gfx::RectF BoundsToRect(int x1, int y1, int x2, int y2) { - return gfx::RectF(x1, y1, x2 - x1, y2 - y1); -} - -static gfx::RectF NormalizedRect(const gfx::RectF& rect, - float total_width, - float total_height) { - return gfx::RectF(rect.x() / total_width, rect.y() / total_height, - rect.width() / total_width, rect.height() / total_height); + layer_impl->quad_generator_ = this->quad_generator_; } void NinePatchLayerImpl::SetLayout(const gfx::Rect& aperture, @@ -70,240 +41,18 @@ void NinePatchLayerImpl::SetLayout(const gfx::Rect& aperture, // exist before SetLayout can be called. DCHECK(ui_resource_id_); - if (image_aperture_ == aperture && border_ == border && - fill_center_ == fill_center && nearest_neighbor_ == nearest_neighbor && - layer_occlusion_ == layer_occlusion) + if (!quad_generator_.SetLayout(image_bounds_, bounds(), aperture, border, + layer_occlusion, fill_center, + nearest_neighbor)) return; - image_aperture_ = aperture; - border_ = border; - fill_center_ = fill_center; - nearest_neighbor_ = nearest_neighbor; - layer_occlusion_ = layer_occlusion; - NoteLayerPropertyChanged(); } -void NinePatchLayerImpl::CheckGeometryLimitations() { - // |border| is in layer space. It cannot exceed the bounds of the layer. - DCHECK_GE(bounds().width(), border_.width()); - DCHECK_GE(bounds().height(), border_.height()); - - // Sanity Check on |border| - DCHECK_LE(border_.x(), border_.width()); - DCHECK_LE(border_.y(), border_.height()); - DCHECK_GE(border_.x(), 0); - DCHECK_GE(border_.y(), 0); - - // |aperture| is in image space. It cannot exceed the bounds of the bitmap. - DCHECK(!image_aperture_.size().IsEmpty()); - DCHECK(gfx::Rect(image_bounds_).Contains(image_aperture_)) - << "image_bounds_ " << gfx::Rect(image_bounds_).ToString() - << " image_aperture_ " << image_aperture_.ToString(); - - // Sanity check on |layer_occlusion_|. It should always be within the - // border. - gfx::Rect border_rect(border_.x(), border_.y(), - bounds().width() - border_.width(), - bounds().height() - border_.height()); - DCHECK(layer_occlusion_.IsEmpty() || layer_occlusion_.Contains(border_rect)) - << "border_rect " << border_rect.ToString() << " layer_occlusion_ " - << layer_occlusion_.ToString(); -} - -std::vector<NinePatchLayerImpl::Patch> -NinePatchLayerImpl::ComputeQuadsWithoutOcclusion() const { - float image_width = image_bounds_.width(); - float image_height = image_bounds_.height(); - float layer_width = bounds().width(); - float layer_height = bounds().height(); - gfx::RectF layer_aperture(border_.x(), border_.y(), - layer_width - border_.width(), - layer_height - border_.height()); - - std::vector<Patch> patches; - patches.reserve(kMaxPatches); - - // Top-left. - patches.push_back( - Patch(BoundsToRect(0, 0, image_aperture_.x(), image_aperture_.y()), - BoundsToRect(0, 0, layer_aperture.x(), layer_aperture.y()))); - - // Top-right. - patches.push_back(Patch(BoundsToRect(image_aperture_.right(), 0, image_width, - image_aperture_.y()), - BoundsToRect(layer_aperture.right(), 0, layer_width, - layer_aperture.y()))); - - // Bottom-left. - patches.push_back(Patch(BoundsToRect(0, image_aperture_.bottom(), - image_aperture_.x(), image_height), - BoundsToRect(0, layer_aperture.bottom(), - layer_aperture.x(), layer_height))); - - // Bottom-right. - patches.push_back( - Patch(BoundsToRect(image_aperture_.right(), image_aperture_.bottom(), - image_width, image_height), - BoundsToRect(layer_aperture.right(), layer_aperture.bottom(), - layer_width, layer_height))); - - // Top. - patches.push_back( - Patch(BoundsToRect(image_aperture_.x(), 0, image_aperture_.right(), - image_aperture_.y()), - BoundsToRect(layer_aperture.x(), 0, layer_aperture.right(), - layer_aperture.y()))); - - // Left. - patches.push_back( - Patch(BoundsToRect(0, image_aperture_.y(), image_aperture_.x(), - image_aperture_.bottom()), - BoundsToRect(0, layer_aperture.y(), layer_aperture.x(), - layer_aperture.bottom()))); - - // Right. - patches.push_back( - Patch(BoundsToRect(image_aperture_.right(), image_aperture_.y(), - image_width, image_aperture_.bottom()), - BoundsToRect(layer_aperture.right(), layer_aperture.y(), - layer_width, layer_aperture.bottom()))); - - // Bottom. - patches.push_back( - Patch(BoundsToRect(image_aperture_.x(), image_aperture_.bottom(), - image_aperture_.right(), image_height), - BoundsToRect(layer_aperture.x(), layer_aperture.bottom(), - layer_aperture.right(), layer_height))); - - // Center. - if (fill_center_) { - patches.push_back( - Patch(BoundsToRect(image_aperture_.x(), image_aperture_.y(), - image_aperture_.right(), image_aperture_.bottom()), - BoundsToRect(layer_aperture.x(), layer_aperture.y(), - layer_aperture.right(), layer_aperture.bottom()))); - } - - return patches; -} - -std::vector<NinePatchLayerImpl::Patch> -NinePatchLayerImpl::ComputeQuadsWithOcclusion() const { - float image_width = image_bounds_.width(), - image_height = image_bounds_.height(); - float layer_width = bounds().width(), layer_height = bounds().height(); - float layer_border_right = border_.width() - border_.x(), - layer_border_bottom = border_.height() - border_.y(); - float image_aperture_right = image_width - image_aperture_.right(), - image_aperture_bottom = image_height - image_aperture_.bottom(); - float layer_occlusion_right = layer_width - layer_occlusion_.right(), - layer_occlusion_bottom = layer_height - layer_occlusion_.bottom(); - gfx::RectF image_occlusion(BoundsToRect( - border_.x() == 0 ? 0 : (layer_occlusion_.x() * image_aperture_.x() / - border_.x()), - border_.y() == 0 ? 0 : (layer_occlusion_.y() * image_aperture_.y() / - border_.y()), - image_width - (layer_border_right == 0 ? 0 : layer_occlusion_right * - image_aperture_right / - layer_border_right), - image_height - (layer_border_bottom == 0 ? 0 : layer_occlusion_bottom * - image_aperture_bottom / - layer_border_bottom))); - gfx::RectF layer_aperture(border_.x(), border_.y(), - layer_width - border_.width(), - layer_height - border_.height()); - - std::vector<Patch> patches; - patches.reserve(kMaxOcclusionPatches); - - // Top-left-left. - patches.push_back( - Patch(BoundsToRect(0, 0, image_occlusion.x(), image_aperture_.y()), - BoundsToRect(0, 0, layer_occlusion_.x(), layer_aperture.y()))); - - // Top-left-right. - patches.push_back( - Patch(BoundsToRect(image_occlusion.x(), 0, image_aperture_.x(), - image_occlusion.y()), - BoundsToRect(layer_occlusion_.x(), 0, layer_aperture.x(), - layer_occlusion_.y()))); - - // Top-center. - patches.push_back( - Patch(BoundsToRect(image_aperture_.x(), 0, image_aperture_.right(), - image_occlusion.y()), - BoundsToRect(layer_aperture.x(), 0, layer_aperture.right(), - layer_occlusion_.y()))); - - // Top-right-left. - patches.push_back( - Patch(BoundsToRect(image_aperture_.right(), 0, image_occlusion.right(), - image_occlusion.y()), - BoundsToRect(layer_aperture.right(), 0, layer_occlusion_.right(), - layer_occlusion_.y()))); - - // Top-right-right. - patches.push_back(Patch(BoundsToRect(image_occlusion.right(), 0, image_width, - image_aperture_.y()), - BoundsToRect(layer_occlusion_.right(), 0, layer_width, - layer_aperture.y()))); - - // Left-center. - patches.push_back( - Patch(BoundsToRect(0, image_aperture_.y(), image_occlusion.x(), - image_aperture_.bottom()), - BoundsToRect(0, layer_aperture.y(), layer_occlusion_.x(), - layer_aperture.bottom()))); - - // Right-center. - patches.push_back( - Patch(BoundsToRect(image_occlusion.right(), image_aperture_.y(), - image_width, image_aperture_.bottom()), - BoundsToRect(layer_occlusion_.right(), layer_aperture.y(), - layer_width, layer_aperture.bottom()))); - - // Bottom-left-left. - patches.push_back(Patch(BoundsToRect(0, image_aperture_.bottom(), - image_occlusion.x(), image_height), - BoundsToRect(0, layer_aperture.bottom(), - layer_occlusion_.x(), layer_height))); - - // Bottom-left-right. - patches.push_back( - Patch(BoundsToRect(image_occlusion.x(), image_occlusion.bottom(), - image_aperture_.x(), image_height), - BoundsToRect(layer_occlusion_.x(), layer_occlusion_.bottom(), - layer_aperture.x(), layer_height))); - - // Bottom-center. - patches.push_back( - Patch(BoundsToRect(image_aperture_.x(), image_occlusion.bottom(), - image_aperture_.right(), image_height), - BoundsToRect(layer_aperture.x(), layer_occlusion_.bottom(), - layer_aperture.right(), layer_height))); - - // Bottom-right-left. - patches.push_back( - Patch(BoundsToRect(image_aperture_.right(), image_occlusion.bottom(), - image_occlusion.right(), image_height), - BoundsToRect(layer_aperture.right(), layer_occlusion_.bottom(), - layer_occlusion_.right(), layer_height))); - - // Bottom-right-right. - patches.push_back( - Patch(BoundsToRect(image_occlusion.right(), image_aperture_.bottom(), - image_width, image_height), - BoundsToRect(layer_occlusion_.right(), layer_aperture.bottom(), - layer_width, layer_height))); - - return patches; -} - void NinePatchLayerImpl::AppendQuads( RenderPass* render_pass, AppendQuadsData* append_quads_data) { - CheckGeometryLimitations(); + quad_generator_.CheckGeometryLimitations(); SharedQuadState* shared_quad_state = render_pass->CreateAndAppendSharedQuadState(); PopulateSharedQuadState(shared_quad_state); @@ -311,47 +60,17 @@ void NinePatchLayerImpl::AppendQuads( AppendDebugBorderQuad(render_pass, bounds(), shared_quad_state, append_quads_data); - if (!ui_resource_id_) - return; - - ResourceId resource = - layer_tree_impl()->ResourceIdForUIResource(ui_resource_id_); - - if (!resource) - return; - DCHECK(!bounds().IsEmpty()); - std::vector<Patch> patches; + std::vector<NinePatchGenerator::Patch> patches = + quad_generator_.GeneratePatches(); - if (layer_occlusion_.IsEmpty() || fill_center_) - patches = ComputeQuadsWithoutOcclusion(); - else - patches = ComputeQuadsWithOcclusion(); + for (auto& patch : patches) + patch.output_rect = + gfx::RectF(gfx::ToFlooredRectDeprecated(patch.output_rect)); - const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; - const bool opaque = layer_tree_impl()->IsUIResourceOpaque(ui_resource_id_); - static const bool flipped = false; - static const bool premultiplied_alpha = true; - - for (const auto& patch : patches) { - gfx::Rect visible_rect = - draw_properties().occlusion_in_content_space.GetUnoccludedContentRect( - ToRect(patch.layer_rect)); - gfx::Rect opaque_rect = opaque ? visible_rect : gfx::Rect(); - if (!visible_rect.IsEmpty()) { - gfx::RectF image_rect(NormalizedRect( - patch.image_rect, image_bounds_.width(), image_bounds_.height())); - TextureDrawQuad* quad = - render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); - quad->SetNew(shared_quad_state, ToRect(patch.layer_rect), opaque_rect, - visible_rect, resource, premultiplied_alpha, - image_rect.origin(), image_rect.bottom_right(), - SK_ColorTRANSPARENT, vertex_opacity, flipped, - nearest_neighbor_, false); - ValidateQuadResources(quad); - } - } + quad_generator_.AppendQuads(this, ui_resource_id_, render_pass, + shared_quad_state, patches); } const char* NinePatchLayerImpl::LayerTypeAsString() const { @@ -360,30 +79,7 @@ const char* NinePatchLayerImpl::LayerTypeAsString() const { std::unique_ptr<base::DictionaryValue> NinePatchLayerImpl::LayerTreeAsJson() { std::unique_ptr<base::DictionaryValue> result = LayerImpl::LayerTreeAsJson(); - - base::ListValue* list = new base::ListValue; - list->AppendInteger(image_aperture_.origin().x()); - list->AppendInteger(image_aperture_.origin().y()); - list->AppendInteger(image_aperture_.size().width()); - list->AppendInteger(image_aperture_.size().height()); - result->Set("ImageAperture", list); - - list = new base::ListValue; - list->AppendInteger(image_bounds_.width()); - list->AppendInteger(image_bounds_.height()); - result->Set("ImageBounds", list); - - result->Set("Border", MathUtil::AsValue(border_).release()); - - result->SetBoolean("FillCenter", fill_center_); - - list = new base::ListValue; - list->AppendInteger(layer_occlusion_.x()); - list->AppendInteger(layer_occlusion_.y()); - list->AppendInteger(layer_occlusion_.width()); - list->AppendInteger(layer_occlusion_.height()); - result->Set("LayerOcclusion", list); - + quad_generator_.AsJson(result.get()); return result; } diff --git a/chromium/cc/layers/nine_patch_layer_impl.h b/chromium/cc/layers/nine_patch_layer_impl.h index c7a1c2e8b28..69b039a54e7 100644 --- a/chromium/cc/layers/nine_patch_layer_impl.h +++ b/chromium/cc/layers/nine_patch_layer_impl.h @@ -12,6 +12,7 @@ #include "cc/base/cc_export.h" #include "cc/layers/layer_impl.h" #include "cc/layers/ui_resource_layer_impl.h" +#include "cc/quads/nine_patch_generator.h" #include "cc/resources/resource_provider.h" #include "cc/resources/ui_resource_client.h" #include "ui/gfx/geometry/rect.h" @@ -31,52 +32,7 @@ class CC_EXPORT NinePatchLayerImpl : public UIResourceLayerImpl { } ~NinePatchLayerImpl() override; - // The bitmap stretches out the bounds of the layer. The following picture - // illustrates the parameters associated with the dimensions. - // - // Layer space layout - // - // -------------------------------- - // | : : | - // | J C | - // | : : | - // | ------------------ | - // | | : | | - // |~~~I~~| ------------ | | - // | | | | | | - // | | | | | | - // |~~~A~~|~~| |~~|~B~~~~| - // | | | | | | - // | L ------------ | | - // | | : | | - // | ---K-------------- | - // | D | - // | : | - // | : | - // -------------------------------- - // - // Bitmap space layout - // - // ~~~~~~~~~~ W ~~~~~~~~~~ - // : : | - // : Y | - // : : | - // :~~X~~------------ | - // : | : | - // : | : | - // H | Q | - // : | : | - // : ~~~~~P~~~~~ | - // : | - // : | - // : | - // ------------------------ - // - // |image_bounds| = (W, H) - // |image_aperture| = (X, Y, P, Q) - // |border| = (A, C, A + B, C + D) - // |occlusion_rectangle| = (I, J, K, L) - // |fill_center| indicates whether to draw the center quad or not. + // For parameter meanings, see the declaration of NinePatchGenerator. void SetLayout(const gfx::Rect& image_aperture, const gfx::Rect& border, const gfx::Rect& layer_occlusion, @@ -95,33 +51,9 @@ class CC_EXPORT NinePatchLayerImpl : public UIResourceLayerImpl { NinePatchLayerImpl(LayerTreeImpl* tree_impl, int id); private: - class Patch { - public: - Patch(const gfx::RectF& image_rect, const gfx::RectF& layer_rect); - - gfx::RectF image_rect; - gfx::RectF layer_rect; - }; - const char* LayerTypeAsString() const override; - void CheckGeometryLimitations(); - - std::vector<Patch> ComputeQuadsWithOcclusion() const; - std::vector<Patch> ComputeQuadsWithoutOcclusion() const; - - // The transparent center region that shows the parent layer's contents in - // image space. - gfx::Rect image_aperture_; - - // An inset border that the patches will be mapped to. - gfx::Rect border_; - - bool fill_center_; - - bool nearest_neighbor_; - - gfx::Rect layer_occlusion_; + NinePatchGenerator quad_generator_; DISALLOW_COPY_AND_ASSIGN(NinePatchLayerImpl); }; diff --git a/chromium/cc/layers/nine_patch_layer_impl_unittest.cc b/chromium/cc/layers/nine_patch_layer_impl_unittest.cc index 66dc072f8ad..d704a83d539 100644 --- a/chromium/cc/layers/nine_patch_layer_impl_unittest.cc +++ b/chromium/cc/layers/nine_patch_layer_impl_unittest.cc @@ -201,7 +201,7 @@ void NinePatchLayerLayoutTestWithOcclusion(const gfx::Size& bitmap_size, // Verify UV rects gfx::Rect bitmap_rect(bitmap_size); Region tex_remaining(bitmap_rect); - for (const auto& quad : quads) { + for (auto* quad : quads) { const TextureDrawQuad* tex_quad = TextureDrawQuad::MaterialCast(quad); gfx::RectF tex_rect = gfx::BoundingRect(tex_quad->uv_top_left, tex_quad->uv_bottom_right); diff --git a/chromium/cc/layers/painted_overlay_scrollbar_layer.cc b/chromium/cc/layers/painted_overlay_scrollbar_layer.cc new file mode 100644 index 00000000000..ab8643ecac0 --- /dev/null +++ b/chromium/cc/layers/painted_overlay_scrollbar_layer.cc @@ -0,0 +1,173 @@ +// 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/layers/painted_overlay_scrollbar_layer.h" + +#include <algorithm> + +#include "base/auto_reset.h" +#include "cc/base/math_util.h" +#include "cc/layers/painted_overlay_scrollbar_layer_impl.h" +#include "cc/resources/ui_resource_bitmap.h" +#include "cc/resources/ui_resource_manager.h" +#include "cc/trees/layer_tree_host.h" +#include "cc/trees/layer_tree_impl.h" +#include "skia/ext/platform_canvas.h" +#include "third_party/skia/include/core/SkBitmap.h" +#include "third_party/skia/include/core/SkCanvas.h" +#include "third_party/skia/include/core/SkSize.h" +#include "ui/gfx/geometry/size_conversions.h" +#include "ui/gfx/skia_util.h" + +namespace cc { + +std::unique_ptr<LayerImpl> PaintedOverlayScrollbarLayer::CreateLayerImpl( + LayerTreeImpl* tree_impl) { + return PaintedOverlayScrollbarLayerImpl::Create( + tree_impl, id(), scrollbar_->Orientation(), + scrollbar_->IsLeftSideVerticalScrollbar()); +} + +scoped_refptr<PaintedOverlayScrollbarLayer> +PaintedOverlayScrollbarLayer::Create(std::unique_ptr<Scrollbar> scrollbar, + int scroll_layer_id) { + return make_scoped_refptr( + new PaintedOverlayScrollbarLayer(std::move(scrollbar), scroll_layer_id)); +} + +PaintedOverlayScrollbarLayer::PaintedOverlayScrollbarLayer( + std::unique_ptr<Scrollbar> scrollbar, + int scroll_layer_id) + : scrollbar_(std::move(scrollbar)), + scroll_layer_id_(scroll_layer_id), + thumb_thickness_(scrollbar_->ThumbThickness()), + thumb_length_(scrollbar_->ThumbLength()) { + DCHECK(scrollbar_->UsesNinePatchThumbResource()); +} + +PaintedOverlayScrollbarLayer::~PaintedOverlayScrollbarLayer() {} + +int PaintedOverlayScrollbarLayer::ScrollLayerId() const { + return scroll_layer_id_; +} + +void PaintedOverlayScrollbarLayer::SetScrollLayer(int layer_id) { + if (layer_id == scroll_layer_id_) + return; + + scroll_layer_id_ = layer_id; + SetNeedsFullTreeSync(); +} + +bool PaintedOverlayScrollbarLayer::OpacityCanAnimateOnImplThread() const { + return scrollbar_->IsOverlay(); +} + +bool PaintedOverlayScrollbarLayer::AlwaysUseActiveTreeOpacity() const { + return true; +} + +ScrollbarOrientation PaintedOverlayScrollbarLayer::orientation() const { + return scrollbar_->Orientation(); +} + +void PaintedOverlayScrollbarLayer::PushPropertiesTo(LayerImpl* layer) { + Layer::PushPropertiesTo(layer); + + PaintedOverlayScrollbarLayerImpl* scrollbar_layer = + static_cast<PaintedOverlayScrollbarLayerImpl*>(layer); + + scrollbar_layer->SetScrollLayerId(scroll_layer_id_); + + scrollbar_layer->SetThumbThickness(thumb_thickness_); + scrollbar_layer->SetThumbLength(thumb_length_); + if (orientation() == HORIZONTAL) { + scrollbar_layer->SetTrackStart(track_rect_.x() - location_.x()); + scrollbar_layer->SetTrackLength(track_rect_.width()); + } else { + scrollbar_layer->SetTrackStart(track_rect_.y() - location_.y()); + scrollbar_layer->SetTrackLength(track_rect_.height()); + } + + if (thumb_resource_.get()) { + scrollbar_layer->SetImageBounds( + layer_tree_host()->GetUIResourceManager()->GetUIResourceSize( + thumb_resource_->id())); + scrollbar_layer->SetAperture(aperture_); + scrollbar_layer->set_thumb_ui_resource_id(thumb_resource_->id()); + } else { + scrollbar_layer->SetImageBounds(gfx::Size()); + scrollbar_layer->SetAperture(gfx::Rect()); + scrollbar_layer->set_thumb_ui_resource_id(0); + } +} + +ScrollbarLayerInterface* PaintedOverlayScrollbarLayer::ToScrollbarLayer() { + return this; +} + +void PaintedOverlayScrollbarLayer::SetLayerTreeHost(LayerTreeHost* host) { + // When the LTH is set to null or has changed, then this layer should remove + // all of its associated resources. + if (host != layer_tree_host()) + thumb_resource_ = nullptr; + + Layer::SetLayerTreeHost(host); +} + +gfx::Rect PaintedOverlayScrollbarLayer::OriginThumbRectForPainting() const { + return gfx::Rect(gfx::Point(), scrollbar_->NinePatchThumbCanvasSize()); +} + +bool PaintedOverlayScrollbarLayer::Update() { + bool updated = false; + updated |= Layer::Update(); + + DCHECK(scrollbar_->HasThumb()); + DCHECK(scrollbar_->IsOverlay()); + DCHECK(scrollbar_->UsesNinePatchThumbResource()); + updated |= UpdateProperty(scrollbar_->TrackRect(), &track_rect_); + updated |= UpdateProperty(scrollbar_->Location(), &location_); + updated |= UpdateProperty(scrollbar_->ThumbThickness(), &thumb_thickness_); + updated |= UpdateProperty(scrollbar_->ThumbLength(), &thumb_length_); + updated |= PaintThumbIfNeeded(); + + return updated; +} + +bool PaintedOverlayScrollbarLayer::PaintThumbIfNeeded() { + if (!scrollbar_->NeedsPaintPart(THUMB)) + return false; + + gfx::Rect paint_rect = OriginThumbRectForPainting(); + aperture_ = scrollbar_->NinePatchThumbAperture(); + + DCHECK(!paint_rect.size().IsEmpty()); + DCHECK(paint_rect.origin().IsOrigin()); + + SkBitmap skbitmap; + skbitmap.allocN32Pixels(paint_rect.width(), paint_rect.height()); + SkCanvas skcanvas(skbitmap); + + SkRect content_skrect = RectToSkRect(paint_rect); + SkPaint paint; + paint.setAntiAlias(false); + paint.setBlendMode(SkBlendMode::kClear); + skcanvas.drawRect(content_skrect, paint); + skcanvas.clipRect(content_skrect); + + scrollbar_->PaintPart(&skcanvas, THUMB, paint_rect); + // Make sure that the pixels are no longer mutable to unavoid unnecessary + // allocation and copying. + skbitmap.setImmutable(); + + thumb_resource_ = ScopedUIResource::Create( + layer_tree_host()->GetUIResourceManager(), UIResourceBitmap(skbitmap)); + + SetNeedsPushProperties(); + + return true; +} + +} // namespace cc diff --git a/chromium/cc/layers/painted_overlay_scrollbar_layer.h b/chromium/cc/layers/painted_overlay_scrollbar_layer.h new file mode 100644 index 00000000000..6888bec7ce6 --- /dev/null +++ b/chromium/cc/layers/painted_overlay_scrollbar_layer.h @@ -0,0 +1,77 @@ +// 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_LAYERS_PAINTED_OVERLAY_SCROLLBAR_LAYER_H_ +#define CC_LAYERS_PAINTED_OVERLAY_SCROLLBAR_LAYER_H_ + +#include "base/macros.h" +#include "cc/base/cc_export.h" +#include "cc/input/scrollbar.h" +#include "cc/layers/layer.h" +#include "cc/layers/scrollbar_layer_interface.h" +#include "cc/layers/scrollbar_theme_painter.h" +#include "cc/resources/scoped_ui_resource.h" + +namespace cc { + +class CC_EXPORT PaintedOverlayScrollbarLayer : public ScrollbarLayerInterface, + public Layer { + public: + std::unique_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override; + + static scoped_refptr<PaintedOverlayScrollbarLayer> Create( + std::unique_ptr<Scrollbar> scrollbar, + int scroll_layer_id); + + bool OpacityCanAnimateOnImplThread() const override; + bool AlwaysUseActiveTreeOpacity() const override; + ScrollbarLayerInterface* ToScrollbarLayer() override; + + // ScrollbarLayerInterface + int ScrollLayerId() const override; + void SetScrollLayer(int layer_id) override; + ScrollbarOrientation orientation() const override; + + // Layer interface + bool Update() override; + void SetLayerTreeHost(LayerTreeHost* host) override; + void PushPropertiesTo(LayerImpl* layer) override; + + protected: + PaintedOverlayScrollbarLayer(std::unique_ptr<Scrollbar> scrollbar, + int scroll_layer_id); + ~PaintedOverlayScrollbarLayer() override; + + private: + gfx::Rect OriginThumbRectForPainting() const; + + template <typename T> + bool UpdateProperty(T value, T* prop) { + if (*prop == value) + return false; + *prop = value; + SetNeedsPushProperties(); + return true; + } + + bool PaintThumbIfNeeded(); + + std::unique_ptr<Scrollbar> scrollbar_; + int scroll_layer_id_; + + int thumb_thickness_; + int thumb_length_; + gfx::Point location_; + gfx::Rect track_rect_; + + gfx::Rect aperture_; + + std::unique_ptr<ScopedUIResource> thumb_resource_; + + DISALLOW_COPY_AND_ASSIGN(PaintedOverlayScrollbarLayer); +}; + +} // namespace cc + +#endif // CC_LAYERS_PAINTED_OVERLAY_SCROLLBAR_LAYER_H_ diff --git a/chromium/cc/layers/painted_overlay_scrollbar_layer_impl.cc b/chromium/cc/layers/painted_overlay_scrollbar_layer_impl.cc new file mode 100644 index 00000000000..c14b93be585 --- /dev/null +++ b/chromium/cc/layers/painted_overlay_scrollbar_layer_impl.cc @@ -0,0 +1,167 @@ +// 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/layers/painted_overlay_scrollbar_layer_impl.h" + +namespace cc { + +std::unique_ptr<PaintedOverlayScrollbarLayerImpl> +PaintedOverlayScrollbarLayerImpl::Create(LayerTreeImpl* tree_impl, + int id, + ScrollbarOrientation orientation, + bool is_left_side_vertical_scrollbar) { + return base::WrapUnique(new PaintedOverlayScrollbarLayerImpl( + tree_impl, id, orientation, is_left_side_vertical_scrollbar)); +} + +PaintedOverlayScrollbarLayerImpl::PaintedOverlayScrollbarLayerImpl( + LayerTreeImpl* tree_impl, + int id, + ScrollbarOrientation orientation, + bool is_left_side_vertical_scrollbar) + : ScrollbarLayerImplBase(tree_impl, + id, + orientation, + is_left_side_vertical_scrollbar, + true), + thumb_ui_resource_id_(0), + thumb_thickness_(0), + thumb_length_(0), + track_start_(0), + track_length_(0) {} + +PaintedOverlayScrollbarLayerImpl::~PaintedOverlayScrollbarLayerImpl() {} + +std::unique_ptr<LayerImpl> PaintedOverlayScrollbarLayerImpl::CreateLayerImpl( + LayerTreeImpl* tree_impl) { + return PaintedOverlayScrollbarLayerImpl::Create( + tree_impl, id(), orientation(), is_left_side_vertical_scrollbar()); +} + +void PaintedOverlayScrollbarLayerImpl::PushPropertiesTo(LayerImpl* layer) { + ScrollbarLayerImplBase::PushPropertiesTo(layer); + + PaintedOverlayScrollbarLayerImpl* scrollbar_layer = + static_cast<PaintedOverlayScrollbarLayerImpl*>(layer); + + scrollbar_layer->SetThumbThickness(thumb_thickness_); + scrollbar_layer->SetThumbLength(thumb_length_); + scrollbar_layer->SetTrackStart(track_start_); + scrollbar_layer->SetTrackLength(track_length_); + + scrollbar_layer->SetImageBounds(image_bounds_); + scrollbar_layer->SetAperture(aperture_); + + scrollbar_layer->set_thumb_ui_resource_id(thumb_ui_resource_id_); +} + +bool PaintedOverlayScrollbarLayerImpl::WillDraw( + DrawMode draw_mode, + ResourceProvider* resource_provider) { + DCHECK(draw_mode != DRAW_MODE_RESOURCELESS_SOFTWARE); + return LayerImpl::WillDraw(draw_mode, resource_provider); +} + +void PaintedOverlayScrollbarLayerImpl::AppendQuads( + RenderPass* render_pass, + AppendQuadsData* append_quads_data) { + // For overlay scrollbars, the border should match the inset of the aperture + // and be symmetrical. + gfx::Rect border(aperture_.x(), aperture_.y(), aperture_.x() * 2, + aperture_.y() * 2); + gfx::Rect thumb_quad_rect(ComputeThumbQuadRect()); + gfx::Rect layer_occlusion; + bool fill_center = true; + bool nearest_neighbor = false; + + quad_generator_.SetLayout(image_bounds_, thumb_quad_rect.size(), aperture_, + border, layer_occlusion, fill_center, + nearest_neighbor); + quad_generator_.CheckGeometryLimitations(); + + SharedQuadState* shared_quad_state = + render_pass->CreateAndAppendSharedQuadState(); + PopulateSharedQuadState(shared_quad_state); + + AppendDebugBorderQuad(render_pass, bounds(), shared_quad_state, + append_quads_data); + + std::vector<NinePatchGenerator::Patch> patches = + quad_generator_.GeneratePatches(); + + gfx::Vector2dF offset = thumb_quad_rect.OffsetFromOrigin(); + for (auto& patch : patches) + patch.output_rect += offset; + + quad_generator_.AppendQuads(this, thumb_ui_resource_id_, render_pass, + shared_quad_state, patches); +} + +void PaintedOverlayScrollbarLayerImpl::SetThumbThickness(int thumb_thickness) { + if (thumb_thickness_ == thumb_thickness) + return; + thumb_thickness_ = thumb_thickness; + NoteLayerPropertyChanged(); +} + +int PaintedOverlayScrollbarLayerImpl::ThumbThickness() const { + return thumb_thickness_; +} + +void PaintedOverlayScrollbarLayerImpl::SetThumbLength(int thumb_length) { + if (thumb_length_ == thumb_length) + return; + thumb_length_ = thumb_length; + NoteLayerPropertyChanged(); +} + +int PaintedOverlayScrollbarLayerImpl::ThumbLength() const { + return thumb_length_; +} + +void PaintedOverlayScrollbarLayerImpl::SetTrackStart(int track_start) { + if (track_start_ == track_start) + return; + track_start_ = track_start; + NoteLayerPropertyChanged(); +} + +int PaintedOverlayScrollbarLayerImpl::TrackStart() const { + return track_start_; +} + +void PaintedOverlayScrollbarLayerImpl::SetTrackLength(int track_length) { + if (track_length_ == track_length) + return; + track_length_ = track_length; + NoteLayerPropertyChanged(); +} + +void PaintedOverlayScrollbarLayerImpl::SetImageBounds(const gfx::Size& bounds) { + if (image_bounds_ == bounds) + return; + image_bounds_ = bounds; + NoteLayerPropertyChanged(); +} + +void PaintedOverlayScrollbarLayerImpl::SetAperture(const gfx::Rect& aperture) { + if (aperture_ == aperture) + return; + aperture_ = aperture; + NoteLayerPropertyChanged(); +} + +float PaintedOverlayScrollbarLayerImpl::TrackLength() const { + return track_length_ + (orientation() == VERTICAL ? vertical_adjust() : 0); +} + +bool PaintedOverlayScrollbarLayerImpl::IsThumbResizable() const { + return false; +} + +const char* PaintedOverlayScrollbarLayerImpl::LayerTypeAsString() const { + return "cc::PaintedOverlayScrollbarLayerImpl"; +} + +} // namespace cc diff --git a/chromium/cc/layers/painted_overlay_scrollbar_layer_impl.h b/chromium/cc/layers/painted_overlay_scrollbar_layer_impl.h new file mode 100644 index 00000000000..fef31208864 --- /dev/null +++ b/chromium/cc/layers/painted_overlay_scrollbar_layer_impl.h @@ -0,0 +1,82 @@ +// 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_LAYERS_PAINTED_OVERLAY_SCROLLBAR_LAYER_IMPL_H_ +#define CC_LAYERS_PAINTED_OVERLAY_SCROLLBAR_LAYER_IMPL_H_ + +#include "base/macros.h" +#include "cc/base/cc_export.h" +#include "cc/input/scrollbar.h" +#include "cc/layers/scrollbar_layer_impl_base.h" +#include "cc/quads/nine_patch_generator.h" +#include "cc/resources/ui_resource_client.h" + +namespace cc { + +class LayerTreeImpl; + +class CC_EXPORT PaintedOverlayScrollbarLayerImpl + : public ScrollbarLayerImplBase { + public: + static std::unique_ptr<PaintedOverlayScrollbarLayerImpl> Create( + LayerTreeImpl* tree_impl, + int id, + ScrollbarOrientation orientation, + bool is_left_side_vertical_scrollbar); + ~PaintedOverlayScrollbarLayerImpl() override; + + // LayerImpl implementation. + std::unique_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override; + void PushPropertiesTo(LayerImpl* layer) override; + + bool WillDraw(DrawMode draw_mode, + ResourceProvider* resource_provider) override; + void AppendQuads(RenderPass* render_pass, + AppendQuadsData* append_quads_data) override; + + void SetThumbThickness(int thumb_thickness); + void SetThumbLength(int thumb_length); + void SetTrackStart(int track_start); + void SetTrackLength(int track_length); + + void SetImageBounds(const gfx::Size& bounds); + void SetAperture(const gfx::Rect& aperture); + + void set_thumb_ui_resource_id(UIResourceId uid) { + thumb_ui_resource_id_ = uid; + } + + protected: + PaintedOverlayScrollbarLayerImpl(LayerTreeImpl* tree_impl, + int id, + ScrollbarOrientation orientation, + bool is_left_side_vertical_scrollbar); + + // ScrollbarLayerImplBase implementation. + int ThumbThickness() const override; + int ThumbLength() const override; + float TrackLength() const override; + int TrackStart() const override; + bool IsThumbResizable() const override; + + private: + const char* LayerTypeAsString() const override; + + UIResourceId thumb_ui_resource_id_; + + int thumb_thickness_; + int thumb_length_; + int track_start_; + int track_length_; + + gfx::Size image_bounds_; + gfx::Rect aperture_; + + NinePatchGenerator quad_generator_; + + DISALLOW_COPY_AND_ASSIGN(PaintedOverlayScrollbarLayerImpl); +}; + +} // namespace cc +#endif // CC_LAYERS_PAINTED_OVERLAY_SCROLLBAR_LAYER_IMPL_H_ diff --git a/chromium/cc/layers/painted_scrollbar_layer.cc b/chromium/cc/layers/painted_scrollbar_layer.cc index 164a75eef5b..7fc6e9c1ae8 100644 --- a/chromium/cc/layers/painted_scrollbar_layer.cc +++ b/chromium/cc/layers/painted_scrollbar_layer.cc @@ -10,6 +10,8 @@ #include "cc/base/math_util.h" #include "cc/input/main_thread_scrolling_reason.h" #include "cc/layers/painted_scrollbar_layer_impl.h" +#include "cc/paint/paint_canvas.h" +#include "cc/paint/paint_flags.h" #include "cc/resources/ui_resource_bitmap.h" #include "cc/trees/draw_property_utils.h" #include "cc/trees/layer_tree_host.h" @@ -170,13 +172,13 @@ void PaintedScrollbarLayer::UpdateThumbAndTrackGeometry() { } void PaintedScrollbarLayer::UpdateInternalContentScale() { - float scale = GetLayerTree()->device_scale_factor(); + float scale = layer_tree_host()->device_scale_factor(); if (layer_tree_host() ->GetSettings() .layer_transforms_should_scale_layer_contents) { gfx::Transform transform; transform = draw_property_utils::ScreenSpaceTransform( - this, GetLayerTree()->property_trees()->transform_tree); + this, layer_tree_host()->property_trees()->transform_tree); gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents(transform, scale); @@ -263,26 +265,25 @@ UIResourceBitmap PaintedScrollbarLayer::RasterizeScrollbarPart( SkBitmap skbitmap; skbitmap.allocN32Pixels(content_rect.width(), content_rect.height()); - SkCanvas skcanvas(skbitmap); + PaintCanvas canvas(skbitmap); float scale_x = content_rect.width() / static_cast<float>(layer_rect.width()); float scale_y = content_rect.height() / static_cast<float>(layer_rect.height()); - skcanvas.scale(SkFloatToScalar(scale_x), - SkFloatToScalar(scale_y)); - skcanvas.translate(SkFloatToScalar(-layer_rect.x()), - SkFloatToScalar(-layer_rect.y())); + canvas.scale(SkFloatToScalar(scale_x), SkFloatToScalar(scale_y)); + canvas.translate(SkFloatToScalar(-layer_rect.x()), + SkFloatToScalar(-layer_rect.y())); SkRect layer_skrect = RectToSkRect(layer_rect); - SkPaint paint; + PaintFlags paint; paint.setAntiAlias(false); paint.setBlendMode(SkBlendMode::kClear); - skcanvas.drawRect(layer_skrect, paint); - skcanvas.clipRect(layer_skrect); + canvas.drawRect(layer_skrect, paint); + canvas.clipRect(layer_skrect); - scrollbar_->PaintPart(&skcanvas, part, layer_rect); + scrollbar_->PaintPart(&canvas, part, layer_rect); // Make sure that the pixels are no longer mutable to unavoid unnecessary // allocation and copying. skbitmap.setImmutable(); diff --git a/chromium/cc/layers/painted_scrollbar_layer_impl.h b/chromium/cc/layers/painted_scrollbar_layer_impl.h index 19fd8500cc5..4e12371cf34 100644 --- a/chromium/cc/layers/painted_scrollbar_layer_impl.h +++ b/chromium/cc/layers/painted_scrollbar_layer_impl.h @@ -55,6 +55,8 @@ class CC_EXPORT PaintedScrollbarLayerImpl : public ScrollbarLayerImplBase { internal_content_bounds_ = content_bounds; } + int ThumbThickness() const override; + protected: PaintedScrollbarLayerImpl(LayerTreeImpl* tree_impl, int id, @@ -63,7 +65,6 @@ class CC_EXPORT PaintedScrollbarLayerImpl : public ScrollbarLayerImplBase { bool is_overlay); // ScrollbarLayerImplBase implementation. - int ThumbThickness() const override; int ThumbLength() const override; float TrackLength() const override; int TrackStart() const override; diff --git a/chromium/cc/layers/painted_scrollbar_layer_unittest.cc b/chromium/cc/layers/painted_scrollbar_layer_unittest.cc index e249607a9e9..ed58fa0136c 100644 --- a/chromium/cc/layers/painted_scrollbar_layer_unittest.cc +++ b/chromium/cc/layers/painted_scrollbar_layer_unittest.cc @@ -22,7 +22,7 @@ class MockScrollbar : public FakeScrollbar { public: MockScrollbar() : FakeScrollbar(true, true, true) {} MOCK_METHOD3(PaintPart, - void(SkCanvas* canvas, + void(PaintCanvas* canvas, ScrollbarPart part, const gfx::Rect& content_rect)); }; diff --git a/chromium/cc/layers/picture_image_layer.cc b/chromium/cc/layers/picture_image_layer.cc index 81d01f73451..0e909d6b8a6 100644 --- a/chromium/cc/layers/picture_image_layer.cc +++ b/chromium/cc/layers/picture_image_layer.cc @@ -7,14 +7,11 @@ #include <stddef.h> #include "cc/layers/picture_layer_impl.h" -#include "cc/playback/display_item_list_settings.h" +#include "cc/paint/paint_canvas.h" +#include "cc/paint/paint_recorder.h" #include "cc/playback/drawing_display_item.h" #include "cc/trees/layer_tree_host.h" #include "cc/trees/layer_tree_settings.h" -#include "third_party/skia/include/core/SkCanvas.h" -#include "third_party/skia/include/core/SkImage.h" -#include "third_party/skia/include/core/SkPictureRecorder.h" -#include "ui/gfx/skia_util.h" namespace cc { @@ -30,7 +27,7 @@ PictureImageLayer::~PictureImageLayer() { std::unique_ptr<LayerImpl> PictureImageLayer::CreateLayerImpl( LayerTreeImpl* tree_impl) { - auto layer_impl = PictureLayerImpl::Create(tree_impl, id(), is_mask()); + auto layer_impl = PictureLayerImpl::Create(tree_impl, id(), mask_type()); layer_impl->set_is_directly_composited_image(true); return std::move(layer_impl); } @@ -63,14 +60,10 @@ scoped_refptr<DisplayItemList> PictureImageLayer::PaintContentsToDisplayList( DCHECK_GT(image_->height(), 0); DCHECK(layer_tree_host()); - DisplayItemListSettings settings; - settings.use_cached_picture = - layer_tree_host()->GetSettings().use_cached_picture_raster; - scoped_refptr<DisplayItemList> display_list = - DisplayItemList::Create(settings); + auto display_list = make_scoped_refptr(new DisplayItemList); - SkPictureRecorder recorder; - SkCanvas* canvas = + PaintRecorder recorder; + PaintCanvas* canvas = recorder.beginRecording(gfx::RectToSkRect(PaintableRegion())); SkScalar content_to_layer_scale_x = diff --git a/chromium/cc/layers/picture_image_layer_unittest.cc b/chromium/cc/layers/picture_image_layer_unittest.cc index 2280494bd4c..0a9f7a10e49 100644 --- a/chromium/cc/layers/picture_image_layer_unittest.cc +++ b/chromium/cc/layers/picture_image_layer_unittest.cc @@ -37,8 +37,8 @@ TEST(PictureImageLayerTest, PaintContentsToDisplayList) { image_canvas->clear(SK_ColorRED); SkPaint blue_paint; blue_paint.setColor(SK_ColorBLUE); - image_canvas->drawRectCoords(0.f, 0.f, 100.f, 100.f, blue_paint); - image_canvas->drawRectCoords(100.f, 100.f, 200.f, 200.f, blue_paint); + image_canvas->drawRect(SkRect::MakeWH(100, 100), blue_paint); + image_canvas->drawRect(SkRect::MakeLTRB(100, 100, 200, 200), blue_paint); layer->SetImage(image_surface->makeImageSnapshot()); layer->SetBounds(gfx::Size(layer_rect.width(), layer_rect.height())); diff --git a/chromium/cc/layers/picture_layer.cc b/chromium/cc/layers/picture_layer.cc index 8ed4c8b768a..e5bd641e8e7 100644 --- a/chromium/cc/layers/picture_layer.cc +++ b/chromium/cc/layers/picture_layer.cc @@ -6,17 +6,12 @@ #include "base/auto_reset.h" #include "base/trace_event/trace_event.h" -#include "cc/blimp/client_picture_cache.h" -#include "cc/blimp/engine_picture_cache.h" #include "cc/layers/content_layer_client.h" #include "cc/layers/picture_layer_impl.h" +#include "cc/paint/paint_record.h" #include "cc/playback/recording_source.h" -#include "cc/proto/cc_conversions.h" -#include "cc/proto/gfx_conversions.h" -#include "cc/proto/layer.pb.h" #include "cc/trees/layer_tree_host.h" #include "cc/trees/layer_tree_impl.h" -#include "third_party/skia/include/core/SkPictureRecorder.h" #include "ui/gfx/geometry/rect_conversions.h" namespace cc { @@ -32,7 +27,7 @@ scoped_refptr<PictureLayer> PictureLayer::Create(ContentLayerClient* client) { PictureLayer::PictureLayer(ContentLayerClient* client) : instrumentation_object_tracker_(id()), update_source_frame_number_(-1), - is_mask_(false) { + mask_type_(LayerMaskType::NOT_MASK) { picture_layer_inputs_.client = client; } @@ -47,15 +42,15 @@ PictureLayer::~PictureLayer() { std::unique_ptr<LayerImpl> PictureLayer::CreateLayerImpl( LayerTreeImpl* tree_impl) { - return PictureLayerImpl::Create(tree_impl, id(), is_mask_); + return PictureLayerImpl::Create(tree_impl, id(), mask_type_); } void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) { Layer::PushPropertiesTo(base_layer); TRACE_EVENT0("cc", "PictureLayer::PushPropertiesTo"); PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); - // TODO(danakj): Make is_mask_ a constructor parameter for PictureLayer. - DCHECK_EQ(layer_impl->is_mask(), is_mask_); + // TODO(danakj): Make mask_type_ a constructor parameter for PictureLayer. + DCHECK_EQ(layer_impl->mask_type(), mask_type()); DropRecordingSourceContentIfInvalid(); layer_impl->SetNearestNeighbor(picture_layer_inputs_.nearest_neighbor); @@ -65,7 +60,7 @@ void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) { scoped_refptr<RasterSource> raster_source = recording_source_->CreateRasterSource(can_use_lcd_text); layer_impl->set_gpu_raster_max_texture_size( - GetLayerTree()->device_viewport_size()); + layer_tree_host()->device_viewport_size()); layer_impl->UpdateRasterSource(raster_source, &last_updated_invalidation_, nullptr); DCHECK(last_updated_invalidation_.IsEmpty()); @@ -73,9 +68,14 @@ void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) { void PictureLayer::SetLayerTreeHost(LayerTreeHost* host) { Layer::SetLayerTreeHost(host); + if (!host) return; + if (!host->GetSettings().enable_mask_tiling && + mask_type_ == LayerMaskType::MULTI_TEXTURE_MASK) + mask_type_ = LayerMaskType::SINGLE_TEXTURE_MASK; + if (!recording_source_) recording_source_.reset(new RecordingSource); recording_source_->SetSlowdownRasterScaleFactor( @@ -88,7 +88,7 @@ void PictureLayer::SetLayerTreeHost(LayerTreeHost* host) { } void PictureLayer::SetNeedsDisplayRect(const gfx::Rect& layer_rect) { - DCHECK(!layer_tree_host() || !GetLayerTree()->in_paint_layer_contents()); + DCHECK(!layer_tree_host() || !layer_tree_host()->in_paint_layer_contents()); if (recording_source_) recording_source_->SetNeedsDisplayRect(layer_rect); Layer::SetNeedsDisplayRect(layer_rect); @@ -142,14 +142,14 @@ bool PictureLayer::Update() { return updated; } -void PictureLayer::SetIsMask(bool is_mask) { - is_mask_ = is_mask; +void PictureLayer::SetLayerMaskType(LayerMaskType mask_type) { + mask_type_ = mask_type; } sk_sp<SkPicture> PictureLayer::GetPicture() const { - // We could either flatten the RecordingSource into a single - // SkPicture, or paint a fresh one depending on what we intend to do with the - // picture. For now we just paint a fresh one to get consistent results. + // We could either flatten the RecordingSource into a single SkPicture, or + // paint a fresh one depending on what we intend to do with it. For now we + // just paint a fresh one to get consistent results. if (!DrawsContent()) return nullptr; @@ -202,35 +202,6 @@ bool PictureLayer::HasDrawableContent() const { return picture_layer_inputs_.client && Layer::HasDrawableContent(); } -void PictureLayer::SetTypeForProtoSerialization(proto::LayerNode* proto) const { - proto->set_type(proto::LayerNode::PICTURE_LAYER); -} - -void PictureLayer::ToLayerPropertiesProto(proto::LayerProperties* proto) { - DCHECK(GetLayerTree()); - DCHECK(GetLayerTree()->engine_picture_cache()); - - Layer::ToLayerPropertiesProto(proto); - DropRecordingSourceContentIfInvalid(); - proto::PictureLayerProperties* picture = proto->mutable_picture(); - - picture->set_nearest_neighbor(picture_layer_inputs_.nearest_neighbor); - RectToProto(picture_layer_inputs_.recorded_viewport, - picture->mutable_recorded_viewport()); - if (picture_layer_inputs_.display_list) { - picture_layer_inputs_.display_list->ToProtobuf( - picture->mutable_display_list()); - for (const auto& item : *picture_layer_inputs_.display_list) { - sk_sp<const SkPicture> picture = item.GetPicture(); - // Only DrawingDisplayItems have SkPictures. - if (!picture) - continue; - - GetLayerTree()->engine_picture_cache()->MarkUsed(picture.get()); - } - } -} - void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { benchmark->RunOnLayer(this); } diff --git a/chromium/cc/layers/picture_layer.h b/chromium/cc/layers/picture_layer.h index 15d5825508e..71209fb77a1 100644 --- a/chromium/cc/layers/picture_layer.h +++ b/chromium/cc/layers/picture_layer.h @@ -34,12 +34,9 @@ class CC_EXPORT PictureLayer : public Layer { void PushPropertiesTo(LayerImpl* layer) override; void SetNeedsDisplayRect(const gfx::Rect& layer_rect) override; bool Update() override; - void SetIsMask(bool is_mask) override; + void SetLayerMaskType(LayerMaskType mask_type) override; sk_sp<SkPicture> GetPicture() const override; - void SetTypeForProtoSerialization(proto::LayerNode* proto) const override; - void ToLayerPropertiesProto(proto::LayerProperties* proto) override; - bool IsSuitableForGpuRasterization() const override; void RunMicroBenchmark(MicroBenchmark* benchmark) override; @@ -73,7 +70,7 @@ class CC_EXPORT PictureLayer : public Layer { bool HasDrawableContent() const override; - bool is_mask() const { return is_mask_; } + LayerMaskType mask_type() { return mask_type_; } PictureLayerInputs picture_layer_inputs_; @@ -89,7 +86,7 @@ class CC_EXPORT PictureLayer : public Layer { Region last_updated_invalidation_; int update_source_frame_number_; - bool is_mask_; + LayerMaskType mask_type_; DISALLOW_COPY_AND_ASSIGN(PictureLayer); }; diff --git a/chromium/cc/layers/picture_layer_impl.cc b/chromium/cc/layers/picture_layer_impl.cc index 4c82e7310c2..f112497b5d1 100644 --- a/chromium/cc/layers/picture_layer_impl.cc +++ b/chromium/cc/layers/picture_layer_impl.cc @@ -92,7 +92,7 @@ namespace cc { PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* tree_impl, int id, - bool is_mask) + Layer::LayerMaskType mask_type) : LayerImpl(tree_impl, id), twin_layer_(nullptr), tilings_(CreatePictureLayerTilingSet()), @@ -107,7 +107,7 @@ PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* tree_impl, low_res_raster_contents_scale_(0.f), was_screen_space_transform_animating_(false), only_used_low_res_last_append_quads_(false), - is_mask_(is_mask), + mask_type_(mask_type), nearest_neighbor_(false), is_directly_composited_image_(false) { layer_tree_impl()->RegisterPictureLayerImpl(this); @@ -125,12 +125,12 @@ const char* PictureLayerImpl::LayerTypeAsString() const { std::unique_ptr<LayerImpl> PictureLayerImpl::CreateLayerImpl( LayerTreeImpl* tree_impl) { - return PictureLayerImpl::Create(tree_impl, id(), is_mask_); + return PictureLayerImpl::Create(tree_impl, id(), mask_type()); } void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) { PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); - DCHECK_EQ(layer_impl->is_mask_, is_mask_); + DCHECK_EQ(layer_impl->mask_type_, mask_type_); LayerImpl::PushPropertiesTo(base_layer); @@ -354,7 +354,6 @@ void PictureLayerImpl::AppendQuads(RenderPass* render_pass, texture_rect, draw_info.resource_size(), draw_info.contents_swizzled(), nearest_neighbor_); ValidateQuadResources(quad); - iter->draw_info().set_was_ever_used_to_draw(); has_draw_quad = true; break; } @@ -364,7 +363,6 @@ void PictureLayerImpl::AppendQuads(RenderPass* render_pass, quad->SetNew(shared_quad_state, geometry_rect, visible_geometry_rect, draw_info.solid_color(), false); ValidateQuadResources(quad); - iter->draw_info().set_was_ever_used_to_draw(); has_draw_quad = true; break; } @@ -694,9 +692,11 @@ std::unique_ptr<Tile> PictureLayerImpl::CreateTile( const Tile::CreateInfo& info) { int flags = 0; - // We don't handle solid color masks, so we shouldn't bother analyzing those. + // We don't handle solid color masks if mask tiling is disabled, we also don't + // handle solid color single texture masks if the flag is enabled, so we + // shouldn't bother analyzing those. // Otherwise, always analyze to maximize memory savings. - if (!is_mask_) + if (mask_type_ != Layer::LayerMaskType::SINGLE_TEXTURE_MASK) flags = Tile::USE_PICTURE_ANALYSIS; if (contents_opaque()) @@ -738,7 +738,7 @@ gfx::Size PictureLayerImpl::CalculateTileSize( int max_texture_size = layer_tree_impl()->resource_provider()->max_texture_size(); - if (is_mask_) { + if (mask_type_ == Layer::LayerMaskType::SINGLE_TEXTURE_MASK) { // Masks are not tiled, so if we can't cover the whole mask with one tile, // we shouldn't have such a tiling at all. DCHECK_LE(content_bounds.width(), max_texture_size); @@ -1172,25 +1172,24 @@ float PictureLayerImpl::MinimumContentsScale() const { } float PictureLayerImpl::MaximumContentsScale() const { - // Masks can not have tilings that would become larger than the - // max_texture_size since they use a single tile for the entire - // tiling. Other layers can have tilings of any scale. - if (!is_mask_) - return std::numeric_limits<float>::max(); - - int max_texture_size = - layer_tree_impl()->resource_provider()->max_texture_size(); - float max_scale_width = - static_cast<float>(max_texture_size) / bounds().width(); - float max_scale_height = - static_cast<float>(max_texture_size) / bounds().height(); + // When mask tiling is disabled or the mask is single textured, masks can not + // have tilings that would become larger than the max_texture_size since they + // use a single tile for the entire tiling. Other layers can have tilings such + // that dimension * scale does not overflow. + float max_dimension = static_cast<float>( + mask_type_ == Layer::LayerMaskType::SINGLE_TEXTURE_MASK + ? layer_tree_impl()->resource_provider()->max_texture_size() + : std::numeric_limits<int>::max()); + float max_scale_width = max_dimension / bounds().width(); + float max_scale_height = max_dimension / bounds().height(); float max_scale = std::min(max_scale_width, max_scale_height); + // We require that multiplying the layer size by the contents scale and - // ceiling produces a value <= |max_texture_size|. Because for large layer + // ceiling produces a value <= |max_dimension|. Because for large layer // sizes floating point ambiguity may crop up, making the result larger or // smaller than expected, we use a slightly smaller floating point value for // the scale, to help ensure that the resulting content bounds will never end - // up larger than |max_texture_size|. + // up larger than |max_dimension|. return nextafterf(max_scale, 0.f); } @@ -1371,4 +1370,27 @@ bool PictureLayerImpl::HasValidTilePriorities() const { is_drawn_render_surface_layer_list_member(); } +void PictureLayerImpl::InvalidateRegionForImages( + const ImageIdFlatSet& images_to_invalidate) { + TRACE_EVENT_BEGIN0("cc", "PictureLayerImpl::InvalidateRegionForImages"); + + InvalidationRegion image_invalidation; + for (auto image_id : images_to_invalidate) + image_invalidation.Union(raster_source_->GetRectForImage(image_id)); + Region invalidation; + image_invalidation.Swap(&invalidation); + + if (invalidation.IsEmpty()) { + TRACE_EVENT_END1("cc", "PictureLayerImpl::InvalidateRegionForImages", + "Invalidation", invalidation.ToString()); + return; + } + + invalidation_.Union(invalidation); + tilings_->UpdateTilingsForImplSideInvalidation(invalidation); + SetNeedsPushProperties(); + TRACE_EVENT_END1("cc", "PictureLayerImpl::InvalidateRegionForImages", + "Invalidation", invalidation.ToString()); +} + } // namespace cc diff --git a/chromium/cc/layers/picture_layer_impl.h b/chromium/cc/layers/picture_layer_impl.h index 5f1ddf1b291..93a703e036b 100644 --- a/chromium/cc/layers/picture_layer_impl.h +++ b/chromium/cc/layers/picture_layer_impl.h @@ -14,7 +14,9 @@ #include "base/macros.h" #include "base/memory/ptr_util.h" #include "cc/base/cc_export.h" +#include "cc/layers/layer.h" #include "cc/layers/layer_impl.h" +#include "cc/playback/image_id.h" #include "cc/tiles/picture_layer_tiling.h" #include "cc/tiles/picture_layer_tiling_set.h" #include "cc/tiles/tiling_set_eviction_queue.h" @@ -29,14 +31,13 @@ class CC_EXPORT PictureLayerImpl : public LayerImpl, NON_EXPORTED_BASE(public PictureLayerTilingClient) { public: - static std::unique_ptr<PictureLayerImpl> Create(LayerTreeImpl* tree_impl, - int id, - bool is_mask) { - return base::WrapUnique(new PictureLayerImpl(tree_impl, id, is_mask)); + static std::unique_ptr<PictureLayerImpl> + Create(LayerTreeImpl* tree_impl, int id, Layer::LayerMaskType mask_type) { + return base::WrapUnique(new PictureLayerImpl(tree_impl, id, mask_type)); } ~PictureLayerImpl() override; - bool is_mask() const { return is_mask_; } + Layer::LayerMaskType mask_type() const { return mask_type_; } // LayerImpl overrides. const char* LayerTypeAsString() const override; @@ -98,8 +99,12 @@ class CC_EXPORT PictureLayerImpl is_directly_composited_image_ = is_directly_composited_image; } + void InvalidateRegionForImages(const ImageIdFlatSet& images_to_invalidate); + protected: - PictureLayerImpl(LayerTreeImpl* tree_impl, int id, bool is_mask); + PictureLayerImpl(LayerTreeImpl* tree_impl, + int id, + Layer::LayerMaskType mask_type); PictureLayerTiling* AddTiling(float contents_scale); void RemoveAllTilings(); void AddTilingsForRasterScale(); @@ -143,7 +148,7 @@ class CC_EXPORT PictureLayerImpl bool was_screen_space_transform_animating_; bool only_used_low_res_last_append_quads_; - const bool is_mask_; + const Layer::LayerMaskType mask_type_; bool nearest_neighbor_; bool is_directly_composited_image_; diff --git a/chromium/cc/layers/picture_layer_impl_unittest.cc b/chromium/cc/layers/picture_layer_impl_unittest.cc index 4c4f8839128..a9e71b32b1e 100644 --- a/chromium/cc/layers/picture_layer_impl_unittest.cc +++ b/chromium/cc/layers/picture_layer_impl_unittest.cc @@ -32,7 +32,6 @@ #include "cc/test/fake_raster_source.h" #include "cc/test/fake_recording_source.h" #include "cc/test/geometry_test_utils.h" -#include "cc/test/gpu_rasterization_enabled_settings.h" #include "cc/test/layer_test_common.h" #include "cc/test/test_layer_tree_host_base.h" #include "cc/test/test_task_graph_runner.h" @@ -71,18 +70,6 @@ namespace { EXPECT_FALSE(active_layer()->expression); \ } while (false) -class MockCanvas : public SkCanvas { - public: - explicit MockCanvas(int w, int h) : SkCanvas(w, h) {} - - void onDrawRect(const SkRect& rect, const SkPaint& paint) override { - // Capture calls before SkCanvas quickReject() kicks in. - rects_.push_back(rect); - } - - std::vector<SkRect> rects_; -}; - class PictureLayerImplTest : public TestLayerTreeHostBase { public: void SetUp() override { @@ -92,7 +79,6 @@ class PictureLayerImplTest : public TestLayerTreeHostBase { LayerTreeSettings CreateSettings() override { LayerTreeSettings settings; - settings.gpu_rasterization_enabled = true; settings.layer_transforms_should_scale_layer_contents = true; settings.create_low_res_tiling = true; settings.verify_clip_tree_calculations = true; @@ -101,6 +87,10 @@ class PictureLayerImplTest : public TestLayerTreeHostBase { return settings; } + std::unique_ptr<CompositorFrameSink> CreateCompositorFrameSink() override { + return FakeCompositorFrameSink::Create3dForGpuRasterization(); + } + void SetupDefaultTreesWithFixedTileSize(const gfx::Size& layer_bounds, const gfx::Size& tile_size, const Region& invalidation) { @@ -710,6 +700,36 @@ TEST_F(PictureLayerImplTest, ZoomOutCrash) { EXPECT_EQ(active_layer()->tilings()->NumHighResTilings(), 1); } +TEST_F(PictureLayerImplTest, ScaledBoundsOverflowInt) { + // Limit visible size. + gfx::Size viewport_size(1, 1); + host_impl()->SetViewportSize(viewport_size); + + gfx::Size layer_bounds(600000, 60); + + // Set up the high and low res tilings before pinch zoom. + SetupDefaultTrees(layer_bounds); + ResetTilingsAndRasterScales(); + EXPECT_EQ(0u, active_layer()->tilings()->num_tilings()); + float scale = 8000.f; + + // Verify this will overflow an int. + EXPECT_GT(static_cast<float>(layer_bounds.width()) * scale, + static_cast<float>(std::numeric_limits<int>::max())); + + SetContentsScaleOnBothLayers(scale, 1.0f, scale, 1.0f, 0.f, false); + float adjusted_scale = active_layer()->HighResTiling()->contents_scale(); + EXPECT_LT(adjusted_scale, scale); + + // PopulateSharedQuadState CHECKs for overflows. + // See http://crbug.com/679035 + active_layer()->draw_properties().visible_layer_rect = + gfx::Rect(layer_bounds); + SharedQuadState state; + active_layer()->PopulateScaledSharedQuadState(&state, adjusted_scale, + adjusted_scale); +} + TEST_F(PictureLayerImplTest, PinchGestureTilings) { gfx::Size layer_bounds(1300, 1900); @@ -1128,12 +1148,12 @@ TEST_F(PictureLayerImplTest, DontAddLowResForSmallLayers) { // Mask layers dont create low res since they always fit on one tile. std::unique_ptr<FakePictureLayerImpl> mask = - FakePictureLayerImpl::CreateMaskWithRasterSource( + FakePictureLayerImpl::CreateSingleTextureMaskWithRasterSource( host_impl()->pending_tree(), 3, pending_raster_source); mask->SetBounds(layer_bounds); mask->SetDrawsContent(true); pending_layer()->test_properties()->SetMaskLayer(std::move(mask)); - pending_layer()->SetHasRenderSurface(true); + pending_layer()->test_properties()->force_render_surface = true; RebuildPropertyTreesOnPendingTree(); host_impl()->pending_tree()->UpdateDrawProperties(false); @@ -1161,7 +1181,7 @@ TEST_F(PictureLayerImplTest, HugeMasksGetScaledDown) { SetupPendingTree(valid_raster_source); std::unique_ptr<FakePictureLayerImpl> mask_ptr = - FakePictureLayerImpl::CreateMaskWithRasterSource( + FakePictureLayerImpl::CreateSingleTextureMaskWithRasterSource( host_impl()->pending_tree(), 3, valid_raster_source); mask_ptr->SetBounds(layer_bounds); mask_ptr->SetDrawsContent(true); @@ -1290,7 +1310,7 @@ TEST_F(PictureLayerImplTest, ScaledMaskLayer) { SetupPendingTree(valid_raster_source); std::unique_ptr<FakePictureLayerImpl> mask_ptr = - FakePictureLayerImpl::CreateMaskWithRasterSource( + FakePictureLayerImpl::CreateSingleTextureMaskWithRasterSource( host_impl()->pending_tree(), 3, valid_raster_source); mask_ptr->SetBounds(layer_bounds); mask_ptr->SetDrawsContent(true); diff --git a/chromium/cc/layers/picture_layer_unittest.cc b/chromium/cc/layers/picture_layer_unittest.cc index 57e77d55161..c151267bde9 100644 --- a/chromium/cc/layers/picture_layer_unittest.cc +++ b/chromium/cc/layers/picture_layer_unittest.cc @@ -13,12 +13,8 @@ #include "cc/layers/content_layer_client.h" #include "cc/layers/empty_content_layer_client.h" #include "cc/layers/picture_layer_impl.h" -#include "cc/playback/display_item_list_settings.h" -#include "cc/proto/layer.pb.h" -#include "cc/test/fake_client_picture_cache.h" +#include "cc/paint/paint_flags.h" #include "cc/test/fake_compositor_frame_sink.h" -#include "cc/test/fake_engine_picture_cache.h" -#include "cc/test/fake_image_serialization_processor.h" #include "cc/test/fake_layer_tree_host.h" #include "cc/test/fake_picture_layer.h" #include "cc/test/fake_picture_layer_impl.h" @@ -47,7 +43,7 @@ TEST(PictureLayerTest, NoTilesIfEmptyBounds) { auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN); std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create( &host_client, &task_graph_runner, animation_host.get()); - host->GetLayerTree()->SetRootLayer(layer); + host->SetRootLayer(layer); layer->SetIsDrawable(true); layer->SavePaintProperties(); layer->Update(); @@ -91,7 +87,7 @@ TEST(PictureLayerTest, InvalidateRasterAfterUpdate) { auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN); std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create( &host_client, &task_graph_runner, animation_host.get()); - host->GetLayerTree()->SetRootLayer(layer); + host->SetRootLayer(layer); layer->SetIsDrawable(true); layer->SavePaintProperties(); @@ -135,7 +131,7 @@ TEST(PictureLayerTest, InvalidateRasterWithoutUpdate) { auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN); std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create( &host_client, &task_graph_runner, animation_host.get()); - host->GetLayerTree()->SetRootLayer(layer); + host->SetRootLayer(layer); layer->SetIsDrawable(true); layer->SavePaintProperties(); @@ -170,7 +166,7 @@ TEST(PictureLayerTest, ClearVisibleRectWhenNoTiling) { FakeContentLayerClient client; client.set_bounds(layer_size); client.add_draw_image(CreateDiscardableImage(layer_size), gfx::Point(), - SkPaint()); + PaintFlags()); scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client); layer->SetBounds(gfx::Size(10, 10)); @@ -179,7 +175,7 @@ TEST(PictureLayerTest, ClearVisibleRectWhenNoTiling) { auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN); std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create( &host_client, &task_graph_runner, animation_host.get()); - host->GetLayerTree()->SetRootLayer(layer); + host->SetRootLayer(layer); layer->SetIsDrawable(true); layer->SavePaintProperties(); layer->Update(); @@ -261,7 +257,7 @@ TEST(PictureLayerTest, SuitableForGpuRasterization) { auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN); std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create( &host_client, &task_graph_runner, animation_host.get()); - host->GetLayerTree()->SetRootLayer(layer); + host->SetRootLayer(layer); // Update layers to initialize the recording source. gfx::Size layer_bounds(200, 200); @@ -306,22 +302,21 @@ TEST(PictureLayerTest, NonMonotonicSourceFrameNumber) { auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN); - LayerTreeHostInProcess::InitParams params; + LayerTreeHost::InitParams params; params.client = &host_client1; params.settings = &settings; params.task_graph_runner = &task_graph_runner; params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); params.mutator_host = animation_host.get(); std::unique_ptr<LayerTreeHost> host1 = - LayerTreeHostInProcess::CreateSingleThreaded(&single_thread_client, - ¶ms); + LayerTreeHost::CreateSingleThreaded(&single_thread_client, ¶ms); host1->SetVisible(true); host_client1.SetLayerTreeHost(host1.get()); auto animation_host2 = AnimationHost::CreateForTesting(ThreadInstance::MAIN); // TODO(sad): InitParams will be movable. - LayerTreeHostInProcess::InitParams params2; + LayerTreeHost::InitParams params2; params2.client = &host_client1; params2.settings = &settings; params2.task_graph_runner = &task_graph_runner; @@ -329,13 +324,12 @@ TEST(PictureLayerTest, NonMonotonicSourceFrameNumber) { params2.client = &host_client2; params2.mutator_host = animation_host2.get(); std::unique_ptr<LayerTreeHost> host2 = - LayerTreeHostInProcess::CreateSingleThreaded(&single_thread_client, - ¶ms2); + LayerTreeHost::CreateSingleThreaded(&single_thread_client, ¶ms2); host2->SetVisible(true); host_client2.SetLayerTreeHost(host2.get()); // The PictureLayer is put in one LayerTreeHost. - host1->GetLayerTree()->SetRootLayer(layer); + host1->SetRootLayer(layer); // Do a main frame, record the picture layers. EXPECT_EQ(0, layer->update_count()); layer->SetNeedsDisplay(); @@ -350,8 +344,8 @@ TEST(PictureLayerTest, NonMonotonicSourceFrameNumber) { EXPECT_EQ(2, host1->SourceFrameNumber()); // Then moved to another LayerTreeHost. - host1->GetLayerTree()->SetRootLayer(nullptr); - host2->GetLayerTree()->SetRootLayer(layer); + host1->SetRootLayer(nullptr); + host2->SetRootLayer(layer); // Do a main frame, record the picture layers. The frame number has changed // non-monotonically. diff --git a/chromium/cc/layers/render_surface_impl.cc b/chromium/cc/layers/render_surface_impl.cc index 1265e4f0ea0..4b6355631c1 100644 --- a/chromium/cc/layers/render_surface_impl.cc +++ b/chromium/cc/layers/render_surface_impl.cc @@ -31,9 +31,10 @@ namespace cc { -RenderSurfaceImpl::RenderSurfaceImpl(LayerImpl* owning_layer) - : layer_tree_impl_(owning_layer->layer_tree_impl()), - stable_effect_id_(owning_layer->id()), +RenderSurfaceImpl::RenderSurfaceImpl(LayerTreeImpl* layer_tree_impl, + int stable_effect_id) + : layer_tree_impl_(layer_tree_impl), + stable_effect_id_(stable_effect_id), effect_tree_index_(EffectTree::kInvalidNodeId), surface_property_changed_(false), ancestor_property_changed_(false), @@ -49,9 +50,8 @@ RenderSurfaceImpl::~RenderSurfaceImpl() {} RenderSurfaceImpl* RenderSurfaceImpl::render_target() { EffectTree& effect_tree = layer_tree_impl_->property_trees()->effect_tree; EffectNode* node = effect_tree.Node(EffectTreeIndex()); - EffectNode* target_node = effect_tree.Node(node->target_id); - if (target_node->id != EffectTree::kRootNodeId) - return target_node->render_surface; + if (node->target_id != EffectTree::kRootNodeId) + return effect_tree.GetRenderSurface(node->target_id); else return this; } @@ -60,9 +60,8 @@ const RenderSurfaceImpl* RenderSurfaceImpl::render_target() const { const EffectTree& effect_tree = layer_tree_impl_->property_trees()->effect_tree; const EffectNode* node = effect_tree.Node(EffectTreeIndex()); - const EffectNode* target_node = effect_tree.Node(node->target_id); - if (target_node->id != EffectTree::kRootNodeId) - return target_node->render_surface; + if (node->target_id != EffectTree::kRootNodeId) + return effect_tree.GetRenderSurface(node->target_id); else return this; } @@ -403,6 +402,12 @@ void RenderSurfaceImpl::AppendQuads(RenderPass* render_pass, LayerImpl* mask_layer = MaskLayer(); if (mask_layer && mask_layer->DrawsContent() && !mask_layer->bounds().IsEmpty()) { + // The software renderer applies mask layer and blending in the wrong + // order but kDstIn doesn't commute with masking. It is okay to not + // support this configuration because kDstIn was introduced to replace + // mask layers. + DCHECK(BlendMode() != SkBlendMode::kDstIn) + << "kDstIn blend mode with mask layer is unsupported."; mask_layer->GetContentsResourceId(&mask_resource_id, &mask_texture_size); gfx::SizeF unclipped_mask_target_size = gfx::ScaleSize( gfx::SizeF(OwningEffectNode()->unscaled_mask_target_size), @@ -413,9 +418,11 @@ void RenderSurfaceImpl::AppendQuads(RenderPass* render_pass, RenderPassDrawQuad* quad = render_pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>(); - quad->SetNew(shared_quad_state, content_rect(), visible_layer_rect, - GetRenderPassId(), mask_resource_id, mask_uv_scale, - mask_texture_size, surface_contents_scale, FiltersOrigin()); + quad->SetNew( + shared_quad_state, content_rect(), visible_layer_rect, GetRenderPassId(), + mask_resource_id, gfx::ScaleRect(gfx::RectF(content_rect()), + mask_uv_scale.x(), mask_uv_scale.y()), + mask_texture_size, surface_contents_scale, FiltersOrigin(), gfx::RectF()); } } // namespace cc diff --git a/chromium/cc/layers/render_surface_impl.h b/chromium/cc/layers/render_surface_impl.h index 6ca3a29da7a..1b2f0cd2b23 100644 --- a/chromium/cc/layers/render_surface_impl.h +++ b/chromium/cc/layers/render_surface_impl.h @@ -36,7 +36,7 @@ struct AppendQuadsData; class CC_EXPORT RenderSurfaceImpl { public: - explicit RenderSurfaceImpl(LayerImpl* owning_layer); + RenderSurfaceImpl(LayerTreeImpl* layer_tree_impl, int stable_effect_id); virtual ~RenderSurfaceImpl(); // Returns the RenderSurfaceImpl that this render surface contributes to. Root diff --git a/chromium/cc/layers/render_surface_impl_unittest.cc b/chromium/cc/layers/render_surface_impl_unittest.cc index 27b3f67fe48..2095c941eff 100644 --- a/chromium/cc/layers/render_surface_impl_unittest.cc +++ b/chromium/cc/layers/render_surface_impl_unittest.cc @@ -28,7 +28,8 @@ TEST(RenderSurfaceLayerImplTest, Occlusion) { impl.CalcDrawProps(viewport_size); - RenderSurfaceImpl* render_surface_impl = owning_layer_impl->render_surface(); + RenderSurfaceImpl* render_surface_impl = + owning_layer_impl->GetRenderSurface(); ASSERT_TRUE(render_surface_impl); { @@ -71,11 +72,10 @@ TEST(RenderSurfaceLayerImplTest, AppendQuadsWithScaledMask) { LayerTestCommon::LayerImplTest impl; std::unique_ptr<LayerImpl> root = LayerImpl::Create(impl.host_impl()->active_tree(), 2); - root->SetHasRenderSurface(true); std::unique_ptr<LayerImpl> surface = LayerImpl::Create(impl.host_impl()->active_tree(), 3); surface->SetBounds(layer_size); - surface->SetHasRenderSurface(true); + surface->test_properties()->force_render_surface = true; gfx::Transform scale; scale.Scale(2, 2); @@ -104,14 +104,14 @@ TEST(RenderSurfaceLayerImplTest, AppendQuadsWithScaledMask) { ->root_layer_for_testing() ->test_properties() ->children[0]; - RenderSurfaceImpl* render_surface_impl = surface_raw->render_surface(); + RenderSurfaceImpl* render_surface_impl = surface_raw->GetRenderSurface(); std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); AppendQuadsData append_quads_data; render_surface_impl->AppendQuads(render_pass.get(), &append_quads_data); const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(render_pass->quad_list.front()); - EXPECT_EQ(gfx::Vector2dF(0.0005f, 0.0005f), quad->mask_uv_scale); + EXPECT_EQ(gfx::RectF(0, 0, 1.f, 1.f), quad->mask_uv_rect); EXPECT_EQ(gfx::Vector2dF(2.f, 2.f), quad->filters_scale); } diff --git a/chromium/cc/layers/render_surface_unittest.cc b/chromium/cc/layers/render_surface_unittest.cc index 511108dc0f2..85ed8c4294a 100644 --- a/chromium/cc/layers/render_surface_unittest.cc +++ b/chromium/cc/layers/render_surface_unittest.cc @@ -54,7 +54,7 @@ TEST(RenderSurfaceTest, VerifySurfaceChangesAreTrackedProperly) { host_impl.active_tree()->UpdateDrawProperties(false /* update_lcd_text */); RenderSurfaceImpl* render_surface = - host_impl.active_tree()->root_layer_for_testing()->render_surface(); + host_impl.active_tree()->root_layer_for_testing()->GetRenderSurface(); ASSERT_TRUE(render_surface); // Currently, the content_rect, clip_rect, and @@ -101,14 +101,13 @@ TEST(RenderSurfaceTest, SanityCheckSurfaceCreatesCorrectSharedQuadState) { std::unique_ptr<LayerImpl> root_layer = LayerImpl::Create(host_impl.active_tree(), 1); + int owning_layer_id = 2; std::unique_ptr<LayerImpl> owning_layer = - LayerImpl::Create(host_impl.active_tree(), 2); - owning_layer->SetHasRenderSurface(true); - ASSERT_TRUE(owning_layer->render_surface()); + LayerImpl::Create(host_impl.active_tree(), owning_layer_id); + owning_layer->test_properties()->force_render_surface = true; SkBlendMode blend_mode = SkBlendMode::kSoftLight; owning_layer->test_properties()->blend_mode = blend_mode; - RenderSurfaceImpl* render_surface = owning_layer->render_surface(); root_layer->test_properties()->AddChild(std::move(owning_layer)); host_impl.active_tree()->SetRootLayerForTesting(std::move(root_layer)); @@ -117,6 +116,11 @@ TEST(RenderSurfaceTest, SanityCheckSurfaceCreatesCorrectSharedQuadState) { host_impl.active_tree()->BuildLayerListAndPropertyTreesForTesting(); host_impl.active_tree()->UpdateDrawProperties(false /* update_lcd_text */); + ASSERT_TRUE( + host_impl.active_tree()->LayerById(owning_layer_id)->GetRenderSurface()); + RenderSurfaceImpl* render_surface = + host_impl.active_tree()->LayerById(owning_layer_id)->GetRenderSurface(); + gfx::Rect content_rect(0, 0, 50, 50); gfx::Rect clip_rect(5, 5, 40, 40); gfx::Transform origin; @@ -184,9 +188,9 @@ TEST(RenderSurfaceTest, SanityCheckSurfaceCreatesCorrectRenderPass) { host_impl.active_tree()->UpdateDrawProperties(false /* update_lcd_text */); ASSERT_TRUE( - host_impl.active_tree()->LayerById(owning_layer_id)->render_surface()); + host_impl.active_tree()->LayerById(owning_layer_id)->GetRenderSurface()); RenderSurfaceImpl* render_surface = - host_impl.active_tree()->LayerById(owning_layer_id)->render_surface(); + host_impl.active_tree()->LayerById(owning_layer_id)->GetRenderSurface(); gfx::Rect content_rect(0, 0, 50, 50); gfx::Transform origin; diff --git a/chromium/cc/layers/scrollbar_layer_impl_base.h b/chromium/cc/layers/scrollbar_layer_impl_base.h index 5256e631eab..7ec930a24d4 100644 --- a/chromium/cc/layers/scrollbar_layer_impl_base.h +++ b/chromium/cc/layers/scrollbar_layer_impl_base.h @@ -54,6 +54,8 @@ class CC_EXPORT ScrollbarLayerImplBase : public LayerImpl { } bool SetThumbThicknessScaleFactor(float thumb_thickness_scale_factor); + virtual int ThumbThickness() const = 0; + protected: ScrollbarLayerImplBase(LayerTreeImpl* tree_impl, int id, @@ -62,7 +64,6 @@ class CC_EXPORT ScrollbarLayerImplBase : public LayerImpl { bool is_overlay); ~ScrollbarLayerImplBase() override; - virtual int ThumbThickness() const = 0; virtual int ThumbLength() const = 0; virtual float TrackLength() const = 0; virtual int TrackStart() const = 0; diff --git a/chromium/cc/layers/scrollbar_layer_unittest.cc b/chromium/cc/layers/scrollbar_layer_unittest.cc index 13cfbd8f491..5abdca78a25 100644 --- a/chromium/cc/layers/scrollbar_layer_unittest.cc +++ b/chromium/cc/layers/scrollbar_layer_unittest.cc @@ -103,10 +103,13 @@ class ScrollbarLayerTest : public testing::Test { ScrollbarLayerTest() { layer_tree_settings_.single_thread_proxy_scheduler = false; layer_tree_settings_.use_zero_copy = true; - layer_tree_settings_.scrollbar_animator = LayerTreeSettings::LINEAR_FADE; - layer_tree_settings_.scrollbar_fade_delay = + layer_tree_settings_.scrollbar_animator = + LayerTreeSettings::ANDROID_OVERLAY; + layer_tree_settings_.scrollbar_show_delay = base::TimeDelta::FromMilliseconds(20); - layer_tree_settings_.scrollbar_fade_duration = + layer_tree_settings_.scrollbar_fade_out_delay = + base::TimeDelta::FromMilliseconds(20); + layer_tree_settings_.scrollbar_fade_out_duration = base::TimeDelta::FromMilliseconds(20); layer_tree_settings_.verify_clip_tree_calculations = true; @@ -114,7 +117,7 @@ class ScrollbarLayerTest : public testing::Test { animation_host_ = AnimationHost::CreateForTesting(ThreadInstance::MAIN); - LayerTreeHostInProcess::InitParams params; + LayerTreeHost::InitParams params; params.client = &fake_client_; params.settings = &layer_tree_settings_; params.task_graph_runner = &task_graph_runner_; @@ -131,7 +134,6 @@ class ScrollbarLayerTest : public testing::Test { std::move(fake_ui_resource_manager)); layer_tree_host_->InitializeSingleThreaded( &single_thread_client_, base::ThreadTaskRunnerHandle::Get()); - layer_tree_ = layer_tree_host_->GetLayerTree(); layer_tree_host_->SetVisible(true); fake_client_.SetLayerTreeHost(layer_tree_host_.get()); } @@ -171,7 +173,6 @@ class ScrollbarLayerTest : public testing::Test { LayerTreeSettings layer_tree_settings_; std::unique_ptr<AnimationHost> animation_host_; std::unique_ptr<FakeLayerTreeHost> layer_tree_host_; - LayerTree* layer_tree_; int scrollbar_layer_id_; }; @@ -233,7 +234,7 @@ TEST_F(ScrollbarLayerTest, ScrollOffsetSynchronization) { scroll_layer->SetBounds(gfx::Size(100, 200)); content_layer->SetBounds(gfx::Size(100, 200)); - layer_tree_->SetRootLayer(layer_tree_root); + layer_tree_host_->SetRootLayer(layer_tree_root); layer_tree_root->AddChild(scroll_layer); scroll_layer->AddChild(content_layer); layer_tree_root->AddChild(scrollbar_layer); @@ -301,7 +302,7 @@ TEST_F(ScrollbarLayerTest, UpdatePropertiesOfScrollBarWhenThumbRemoved) { root_layer->SetBounds(gfx::Size(100, 50)); content_layer->SetBounds(gfx::Size(100, 50)); - layer_tree_->SetRootLayer(root_clip_layer); + layer_tree_host_->SetRootLayer(root_clip_layer); root_clip_layer->AddChild(root_layer); root_layer->AddChild(content_layer); root_layer->AddChild(scrollbar_layer); @@ -340,7 +341,7 @@ TEST_F(ScrollbarLayerTest, ThumbRect) { root_layer->SetBounds(gfx::Size(100, 50)); content_layer->SetBounds(gfx::Size(100, 50)); - layer_tree_->SetRootLayer(root_clip_layer); + layer_tree_host_->SetRootLayer(root_clip_layer); root_clip_layer->AddChild(root_layer); root_layer->AddChild(content_layer); root_layer->AddChild(scrollbar_layer); @@ -415,7 +416,7 @@ TEST_F(ScrollbarLayerTest, ThumbRectForOverlayLeftSideVerticalScrollbar) { root_clip_layer->SetBounds(gfx::Size(50, 20)); root_layer->SetBounds(gfx::Size(50, 100)); - layer_tree_->SetRootLayer(root_clip_layer); + layer_tree_host_->SetRootLayer(root_clip_layer); root_clip_layer->AddChild(root_layer); root_layer->AddChild(scrollbar_layer); @@ -535,7 +536,7 @@ TEST_F(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { scroll_layer->AddChild(child1); scroll_layer->InsertChild(child2, 1); layer_tree_root->AddChild(scroll_layer); - layer_tree_->SetRootLayer(layer_tree_root); + layer_tree_host_->SetRootLayer(layer_tree_root); // Choose layer bounds to give max_scroll_offset = (8, 8). layer_tree_root->SetBounds(gfx::Size(2, 2)); @@ -588,7 +589,7 @@ TEST_F(ScrollbarLayerTest, ScrollbarLayerOpacity) { scroll_layer->AddChild(child1); scroll_layer->InsertChild(scrollbar_layer, 1); layer_tree_root->AddChild(scroll_layer); - layer_tree_->SetRootLayer(layer_tree_root); + layer_tree_host_->SetRootLayer(layer_tree_root); // Choose layer bounds to give max_scroll_offset = (8, 8). layer_tree_root->SetBounds(gfx::Size(2, 2)); @@ -597,18 +598,18 @@ TEST_F(ScrollbarLayerTest, ScrollbarLayerOpacity) { // Building property trees twice shouldn't change the size of // PropertyTrees::always_use_active_tree_opacity_effect_ids. layer_tree_host_->BuildPropertyTreesForTesting(); - EXPECT_EQ(layer_tree_->property_trees() + EXPECT_EQ(layer_tree_host_->property_trees() ->always_use_active_tree_opacity_effect_ids.size(), 1u); - layer_tree_->property_trees()->needs_rebuild = true; + layer_tree_host_->property_trees()->needs_rebuild = true; layer_tree_host_->BuildPropertyTreesForTesting(); - EXPECT_EQ(layer_tree_->property_trees() + EXPECT_EQ(layer_tree_host_->property_trees() ->always_use_active_tree_opacity_effect_ids.size(), 1u); // A solid color scrollbar layer's opacity is initialized to 0 on main thread layer_tree_host_->UpdateLayers(); - EffectNode* node = layer_tree_->property_trees()->effect_tree.Node( + EffectNode* node = layer_tree_host_->property_trees()->effect_tree.Node( scrollbar_layer->effect_tree_index()); EXPECT_EQ(node->opacity, 0.f); @@ -671,7 +672,7 @@ TEST_F(ScrollbarLayerTest, ScrollbarLayerPushProperties) { scroll_layer->AddChild(child1); scroll_layer->InsertChild(scrollbar_layer, 1); layer_tree_root->AddChild(scroll_layer); - layer_tree_->SetRootLayer(layer_tree_root); + layer_tree_host_->SetRootLayer(layer_tree_root); layer_tree_root->SetBounds(gfx::Size(2, 2)); scroll_layer->SetBounds(gfx::Size(10, 10)); @@ -822,7 +823,7 @@ class ScrollbarLayerTestResourceCreationAndRelease : public ScrollbarLayerTest { layer_tree_root->AddChild(content_layer); layer_tree_root->AddChild(scrollbar_layer); - layer_tree_->SetRootLayer(layer_tree_root); + layer_tree_host_->SetRootLayer(layer_tree_root); scrollbar_layer->SetIsDrawable(true); scrollbar_layer->SetBounds(gfx::Size(100, 100)); @@ -881,7 +882,7 @@ TEST_F(ScrollbarLayerTestResourceCreationAndRelease, TestResourceUpdate) { layer_tree_root->AddChild(content_layer); layer_tree_root->AddChild(scrollbar_layer); - layer_tree_->SetRootLayer(layer_tree_root); + layer_tree_host_->SetRootLayer(layer_tree_root); scrollbar_layer->SetIsDrawable(true); scrollbar_layer->SetBounds(gfx::Size(100, 15)); @@ -1031,7 +1032,7 @@ TEST_F(ScrollbarLayerTestResourceCreationAndRelease, TestResourceUpdate) { class ScaledScrollbarLayerTestResourceCreation : public ScrollbarLayerTest { public: - void TestResourceUpload(const float test_scale) { + void TestResourceUpload(float test_scale) { gfx::Point scrollbar_location(0, 185); scoped_refptr<Layer> layer_tree_root = Layer::Create(); scoped_refptr<Layer> content_layer = Layer::Create(); @@ -1041,7 +1042,7 @@ class ScaledScrollbarLayerTestResourceCreation : public ScrollbarLayerTest { layer_tree_root->AddChild(content_layer); layer_tree_root->AddChild(scrollbar_layer); - layer_tree_->SetRootLayer(layer_tree_root); + layer_tree_host_->SetRootLayer(layer_tree_root); scrollbar_layer->SetIsDrawable(true); scrollbar_layer->SetBounds(gfx::Size(100, 15)); @@ -1054,7 +1055,7 @@ class ScaledScrollbarLayerTestResourceCreation : public ScrollbarLayerTest { EXPECT_EQ(scrollbar_layer->GetLayerTreeHostForTesting(), layer_tree_host_.get()); - layer_tree_->SetDeviceScaleFactor(test_scale); + layer_tree_host_->SetDeviceScaleFactor(test_scale); scrollbar_layer->SavePaintProperties(); scrollbar_layer->Update(); @@ -1100,7 +1101,7 @@ TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) { class ScaledScrollbarLayerTestScaledRasterization : public ScrollbarLayerTest { public: - void TestScale(const gfx::Rect scrollbar_rect, const float test_scale) { + void TestScale(const gfx::Rect& scrollbar_rect, float test_scale) { bool paint_during_update = true; bool has_thumb = false; scoped_refptr<Layer> layer_tree_root = Layer::Create(); @@ -1110,7 +1111,7 @@ class ScaledScrollbarLayerTestScaledRasterization : public ScrollbarLayerTest { layer_tree_root->AddChild(scrollbar_layer); - layer_tree_->SetRootLayer(layer_tree_root); + layer_tree_host_->SetRootLayer(layer_tree_root); scrollbar_layer->SetBounds(scrollbar_rect.size()); scrollbar_layer->SetPosition(gfx::PointF(scrollbar_rect.origin())); @@ -1118,7 +1119,7 @@ class ScaledScrollbarLayerTestScaledRasterization : public ScrollbarLayerTest { scrollbar_layer->fake_scrollbar()->set_track_rect(scrollbar_rect); scrollbar_layer->set_visible_layer_rect(scrollbar_rect); - layer_tree_->SetDeviceScaleFactor(test_scale); + layer_tree_host_->SetDeviceScaleFactor(test_scale); gfx::Rect screen_space_clip_rect; scrollbar_layer->SavePaintProperties(); diff --git a/chromium/cc/layers/solid_color_scrollbar_layer.cc b/chromium/cc/layers/solid_color_scrollbar_layer.cc index 5c276b37ea4..2670fd32165 100644 --- a/chromium/cc/layers/solid_color_scrollbar_layer.cc +++ b/chromium/cc/layers/solid_color_scrollbar_layer.cc @@ -8,8 +8,6 @@ #include "cc/layers/layer_impl.h" #include "cc/layers/solid_color_scrollbar_layer_impl.h" -#include "cc/proto/cc_conversions.h" -#include "cc/proto/layer.pb.h" namespace cc { @@ -70,22 +68,6 @@ ScrollbarLayerInterface* SolidColorScrollbarLayer::ToScrollbarLayer() { return this; } -void SolidColorScrollbarLayer::ToLayerNodeProto(proto::LayerNode* proto) const { - Layer::ToLayerNodeProto(proto); - - proto::SolidColorScrollbarLayerProperties* scrollbar = - proto->mutable_solid_scrollbar(); - scrollbar->set_scroll_layer_id( - solid_color_scrollbar_layer_inputs_.scroll_layer_id); - scrollbar->set_thumb_thickness( - solid_color_scrollbar_layer_inputs_.thumb_thickness); - scrollbar->set_track_start(solid_color_scrollbar_layer_inputs_.track_start); - scrollbar->set_is_left_side_vertical_scrollbar( - solid_color_scrollbar_layer_inputs_.is_left_side_vertical_scrollbar); - scrollbar->set_orientation(ScrollbarOrientationToProto( - solid_color_scrollbar_layer_inputs_.orientation)); -} - void SolidColorScrollbarLayer::SetOpacity(float opacity) { // The opacity of a solid color scrollbar layer is always 0 on main thread. DCHECK_EQ(opacity, 0.f); @@ -129,9 +111,4 @@ ScrollbarOrientation SolidColorScrollbarLayer::orientation() const { return solid_color_scrollbar_layer_inputs_.orientation; } -void SolidColorScrollbarLayer::SetTypeForProtoSerialization( - proto::LayerNode* proto) const { - proto->set_type(proto::LayerNode::SOLID_COLOR_SCROLLBAR_LAYER); -} - } // namespace cc diff --git a/chromium/cc/layers/solid_color_scrollbar_layer.h b/chromium/cc/layers/solid_color_scrollbar_layer.h index 2d90f116fc1..f29117a9059 100644 --- a/chromium/cc/layers/solid_color_scrollbar_layer.h +++ b/chromium/cc/layers/solid_color_scrollbar_layer.h @@ -28,7 +28,6 @@ class CC_EXPORT SolidColorScrollbarLayer : public ScrollbarLayerInterface, bool OpacityCanAnimateOnImplThread() const override; bool AlwaysUseActiveTreeOpacity() const override; ScrollbarLayerInterface* ToScrollbarLayer() override; - void ToLayerNodeProto(proto::LayerNode* proto) const override; void SetOpacity(float opacity) override; void PushPropertiesTo(LayerImpl* layer) override; @@ -61,9 +60,6 @@ class CC_EXPORT SolidColorScrollbarLayer : public ScrollbarLayerInterface, int scroll_layer_id); ~SolidColorScrollbarLayer() override; - // Layer overrides for proto conversions. - void SetTypeForProtoSerialization(proto::LayerNode* proto) const override; - private: friend class LayerSerializationTest; diff --git a/chromium/cc/layers/solid_color_scrollbar_layer_impl.h b/chromium/cc/layers/solid_color_scrollbar_layer_impl.h index 2ecba03fd86..a7b776ef0ae 100644 --- a/chromium/cc/layers/solid_color_scrollbar_layer_impl.h +++ b/chromium/cc/layers/solid_color_scrollbar_layer_impl.h @@ -29,6 +29,8 @@ class CC_EXPORT SolidColorScrollbarLayerImpl : public ScrollbarLayerImplBase { void AppendQuads(RenderPass* render_pass, AppendQuadsData* append_quads_data) override; + int ThumbThickness() const override; + protected: SolidColorScrollbarLayerImpl(LayerTreeImpl* tree_impl, int id, @@ -39,7 +41,6 @@ class CC_EXPORT SolidColorScrollbarLayerImpl : public ScrollbarLayerImplBase { bool is_overlay); // ScrollbarLayerImplBase implementation. - int ThumbThickness() const override; int ThumbLength() const override; float TrackLength() const override; int TrackStart() const override; diff --git a/chromium/cc/layers/surface_layer.cc b/chromium/cc/layers/surface_layer.cc index 818b8f444f6..c208d4778f8 100644 --- a/chromium/cc/layers/surface_layer.cc +++ b/chromium/cc/layers/surface_layer.cc @@ -62,15 +62,25 @@ SurfaceLayer::~SurfaceLayer() { DCHECK(!layer_tree_host()); } -void SurfaceLayer::SetSurfaceInfo(const SurfaceInfo& surface_info) { - RemoveCurrentReference(); - surface_info_ = surface_info; +void SurfaceLayer::SetPrimarySurfaceInfo(const SurfaceInfo& surface_info) { + RemoveReference(std::move(primary_reference_returner_)); + primary_surface_info_ = surface_info; if (layer_tree_host()) { - reference_returner_ = - ref_factory_->CreateReference(layer_tree_host(), surface_info_.id()); + primary_reference_returner_ = ref_factory_->CreateReference( + layer_tree_host(), primary_surface_info_.id()); } UpdateDrawsContent(HasDrawableContent()); - SetNeedsPushProperties(); + SetNeedsCommitNoRebuild(); +} + +void SurfaceLayer::SetFallbackSurfaceInfo(const SurfaceInfo& surface_info) { + RemoveReference(std::move(fallback_reference_returner_)); + fallback_surface_info_ = surface_info; + if (layer_tree_host()) { + fallback_reference_returner_ = ref_factory_->CreateReference( + layer_tree_host(), fallback_surface_info_.id()); + } + SetNeedsCommitNoRebuild(); } void SurfaceLayer::SetStretchContentToFillBounds( @@ -85,7 +95,7 @@ std::unique_ptr<LayerImpl> SurfaceLayer::CreateLayerImpl( } bool SurfaceLayer::HasDrawableContent() const { - return surface_info_.id().is_valid() && Layer::HasDrawableContent(); + return primary_surface_info_.is_valid() && Layer::HasDrawableContent(); } void SurfaceLayer::SetLayerTreeHost(LayerTreeHost* host) { @@ -93,11 +103,18 @@ void SurfaceLayer::SetLayerTreeHost(LayerTreeHost* host) { Layer::SetLayerTreeHost(host); return; } - RemoveCurrentReference(); + RemoveReference(std::move(primary_reference_returner_)); + RemoveReference(std::move(fallback_reference_returner_)); Layer::SetLayerTreeHost(host); if (layer_tree_host()) { - reference_returner_ = - ref_factory_->CreateReference(layer_tree_host(), surface_info_.id()); + if (primary_surface_info_.is_valid()) { + primary_reference_returner_ = ref_factory_->CreateReference( + layer_tree_host(), primary_surface_info_.id()); + } + if (fallback_surface_info_.is_valid()) { + fallback_reference_returner_ = ref_factory_->CreateReference( + layer_tree_host(), fallback_surface_info_.id()); + } } } @@ -105,15 +122,16 @@ void SurfaceLayer::PushPropertiesTo(LayerImpl* layer) { Layer::PushPropertiesTo(layer); TRACE_EVENT0("cc", "SurfaceLayer::PushPropertiesTo"); SurfaceLayerImpl* layer_impl = static_cast<SurfaceLayerImpl*>(layer); - layer_impl->SetSurfaceInfo(surface_info_); + layer_impl->SetPrimarySurfaceInfo(primary_surface_info_); + layer_impl->SetFallbackSurfaceInfo(fallback_surface_info_); layer_impl->SetStretchContentToFillBounds(stretch_content_to_fill_bounds_); } -void SurfaceLayer::RemoveCurrentReference() { - if (!reference_returner_) +void SurfaceLayer::RemoveReference(base::Closure reference_returner) { + if (!reference_returner) return; auto swap_promise = base::MakeUnique<SatisfySwapPromise>( - std::move(reference_returner_), + std::move(reference_returner), layer_tree_host()->GetTaskRunnerProvider()->MainThreadTaskRunner()); layer_tree_host()->GetSwapPromiseManager()->QueueSwapPromise( std::move(swap_promise)); diff --git a/chromium/cc/layers/surface_layer.h b/chromium/cc/layers/surface_layer.h index 6b023641064..ed8289b739f 100644 --- a/chromium/cc/layers/surface_layer.h +++ b/chromium/cc/layers/surface_layer.h @@ -21,7 +21,8 @@ class CC_EXPORT SurfaceLayer : public Layer { static scoped_refptr<SurfaceLayer> Create( scoped_refptr<SurfaceReferenceFactory> ref_factory); - void SetSurfaceInfo(const SurfaceInfo& surface_info); + void SetPrimarySurfaceInfo(const SurfaceInfo& surface_info); + void SetFallbackSurfaceInfo(const SurfaceInfo& surface_info); // When stretch_content_to_fill_bounds is true, the scale of the embedded // surface is ignored and the content will be stretched to fill the bounds. @@ -35,7 +36,14 @@ class CC_EXPORT SurfaceLayer : public Layer { scoped_refptr<SurfaceReferenceFactory> surface_reference_factory() const { return ref_factory_; } - const SurfaceInfo& surface_info() const { return surface_info_; } + + const SurfaceInfo& primary_surface_info() const { + return primary_surface_info_; + } + + const SurfaceInfo& fallback_surface_info() const { + return fallback_surface_info_; + } protected: explicit SurfaceLayer(scoped_refptr<SurfaceReferenceFactory> ref_factory); @@ -43,11 +51,15 @@ class CC_EXPORT SurfaceLayer : public Layer { private: ~SurfaceLayer() override; - void RemoveCurrentReference(); + void RemoveReference(base::Closure reference_returner); + + SurfaceInfo primary_surface_info_; + base::Closure primary_reference_returner_; + + SurfaceInfo fallback_surface_info_; + base::Closure fallback_reference_returner_; - SurfaceInfo surface_info_; scoped_refptr<SurfaceReferenceFactory> ref_factory_; - base::Closure reference_returner_; bool stretch_content_to_fill_bounds_ = false; DISALLOW_COPY_AND_ASSIGN(SurfaceLayer); diff --git a/chromium/cc/layers/surface_layer_impl.cc b/chromium/cc/layers/surface_layer_impl.cc index e23e789c409..1e072569e06 100644 --- a/chromium/cc/layers/surface_layer_impl.cc +++ b/chromium/cc/layers/surface_layer_impl.cc @@ -29,11 +29,19 @@ std::unique_ptr<LayerImpl> SurfaceLayerImpl::CreateLayerImpl( return SurfaceLayerImpl::Create(tree_impl, id()); } -void SurfaceLayerImpl::SetSurfaceInfo(const SurfaceInfo& surface_info) { - if (surface_info_ == surface_info) +void SurfaceLayerImpl::SetPrimarySurfaceInfo(const SurfaceInfo& surface_info) { + if (primary_surface_info_ == surface_info) return; - surface_info_ = surface_info; + primary_surface_info_ = surface_info; + NoteLayerPropertyChanged(); +} + +void SurfaceLayerImpl::SetFallbackSurfaceInfo(const SurfaceInfo& surface_info) { + if (fallback_surface_info_ == surface_info) + return; + + fallback_surface_info_ = surface_info; NoteLayerPropertyChanged(); } @@ -48,46 +56,68 @@ void SurfaceLayerImpl::SetStretchContentToFillBounds(bool stretch_content) { void SurfaceLayerImpl::PushPropertiesTo(LayerImpl* layer) { LayerImpl::PushPropertiesTo(layer); SurfaceLayerImpl* layer_impl = static_cast<SurfaceLayerImpl*>(layer); - layer_impl->SetSurfaceInfo(surface_info_); + layer_impl->SetPrimarySurfaceInfo(primary_surface_info_); + layer_impl->SetFallbackSurfaceInfo(fallback_surface_info_); layer_impl->SetStretchContentToFillBounds(stretch_content_to_fill_bounds_); } void SurfaceLayerImpl::AppendQuads(RenderPass* render_pass, AppendQuadsData* append_quads_data) { AppendRainbowDebugBorder(render_pass); + auto* primary = CreateSurfaceDrawQuad( + render_pass, SurfaceDrawQuadType::PRIMARY, primary_surface_info_); + // Emitting a fallback SurfaceDrawQuad is unnecessary if the primary and + // fallback surface Ids match. + if (primary && fallback_surface_info_.id() != primary_surface_info_.id()) { + primary->fallback_quad = CreateSurfaceDrawQuad( + render_pass, SurfaceDrawQuadType::FALLBACK, fallback_surface_info_); + } +} - SharedQuadState* shared_quad_state = - render_pass->CreateAndAppendSharedQuadState(); +SurfaceDrawQuad* SurfaceLayerImpl::CreateSurfaceDrawQuad( + RenderPass* render_pass, + SurfaceDrawQuadType surface_draw_quad_type, + const SurfaceInfo& surface_info) { + if (!surface_info.is_valid()) + return nullptr; + gfx::Rect quad_rect(surface_info.size_in_pixels()); + gfx::Rect visible_quad_rect = + draw_properties().occlusion_in_content_space.GetUnoccludedContentRect( + gfx::Rect(bounds())); + + float layer_to_content_scale_x, layer_to_content_scale_y; if (stretch_content_to_fill_bounds_) { // Stretches the surface contents to exactly fill the layer bounds, // regardless of scale or aspect ratio differences. - float scale_x = static_cast<float>(surface_info_.size_in_pixels().width()) / - bounds().width(); - float scale_y = - static_cast<float>(surface_info_.size_in_pixels().height()) / + layer_to_content_scale_x = + static_cast<float>(surface_info.size_in_pixels().width()) / + bounds().width(); + layer_to_content_scale_y = + static_cast<float>(surface_info.size_in_pixels().height()) / bounds().height(); - PopulateScaledSharedQuadState(shared_quad_state, scale_x, scale_y); } else { - PopulateScaledSharedQuadState(shared_quad_state, - surface_info_.device_scale_factor(), - surface_info_.device_scale_factor()); + layer_to_content_scale_x = layer_to_content_scale_y = + surface_info.device_scale_factor(); } - if (!surface_info_.id().is_valid()) - return; - - gfx::Rect quad_rect(surface_info_.size_in_pixels()); - gfx::Rect visible_quad_rect = - draw_properties().occlusion_in_content_space.GetUnoccludedContentRect( - quad_rect); + visible_quad_rect = gfx::ScaleToEnclosedRect( + visible_quad_rect, layer_to_content_scale_x, layer_to_content_scale_y); + visible_quad_rect = gfx::IntersectRects(quad_rect, visible_quad_rect); if (visible_quad_rect.IsEmpty()) - return; - SurfaceDrawQuad* quad = + return nullptr; + + SharedQuadState* shared_quad_state = + render_pass->CreateAndAppendSharedQuadState(); + PopulateScaledSharedQuadState(shared_quad_state, layer_to_content_scale_x, + layer_to_content_scale_y); + + SurfaceDrawQuad* surface_draw_quad = render_pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>(); - quad->SetNew(shared_quad_state, quad_rect, visible_quad_rect, - surface_info_.id()); + surface_draw_quad->SetNew(shared_quad_state, quad_rect, visible_quad_rect, + surface_info.id(), surface_draw_quad_type, nullptr); + return surface_draw_quad; } void SurfaceLayerImpl::GetDebugBorderProperties(SkColor* color, @@ -185,7 +215,9 @@ void SurfaceLayerImpl::AppendRainbowDebugBorder(RenderPass* render_pass) { void SurfaceLayerImpl::AsValueInto(base::trace_event::TracedValue* dict) const { LayerImpl::AsValueInto(dict); - dict->SetString("surface_id", surface_info_.id().ToString()); + dict->SetString("surface_id", primary_surface_info_.id().ToString()); + dict->SetString("fallback_surface_id", + fallback_surface_info_.id().ToString()); } const char* SurfaceLayerImpl::LayerTypeAsString() const { diff --git a/chromium/cc/layers/surface_layer_impl.h b/chromium/cc/layers/surface_layer_impl.h index 22798cd7df8..a8523cdcec5 100644 --- a/chromium/cc/layers/surface_layer_impl.h +++ b/chromium/cc/layers/surface_layer_impl.h @@ -11,6 +11,7 @@ #include "base/memory/ptr_util.h" #include "cc/base/cc_export.h" #include "cc/layers/layer_impl.h" +#include "cc/quads/surface_draw_quad.h" #include "cc/surfaces/surface_id.h" #include "cc/surfaces/surface_info.h" @@ -24,8 +25,16 @@ class CC_EXPORT SurfaceLayerImpl : public LayerImpl { } ~SurfaceLayerImpl() override; - void SetSurfaceInfo(const SurfaceInfo& surface_info); - const SurfaceInfo& surface_info() const { return surface_info_; } + void SetPrimarySurfaceInfo(const SurfaceInfo& surface_info); + const SurfaceInfo& primary_surface_info() const { + return primary_surface_info_; + } + + void SetFallbackSurfaceInfo(const SurfaceInfo& surface_info); + const SurfaceInfo& fallback_surface_info() const { + return fallback_surface_info_; + } + void SetStretchContentToFillBounds(bool stretch_content); // LayerImpl overrides. @@ -38,12 +47,19 @@ class CC_EXPORT SurfaceLayerImpl : public LayerImpl { SurfaceLayerImpl(LayerTreeImpl* tree_impl, int id); private: + SurfaceDrawQuad* CreateSurfaceDrawQuad( + RenderPass* render_pass, + SurfaceDrawQuadType surface_draw_quad_type, + const SurfaceInfo& surface_info); + void GetDebugBorderProperties(SkColor* color, float* width) const override; void AppendRainbowDebugBorder(RenderPass* render_pass); void AsValueInto(base::trace_event::TracedValue* dict) const override; const char* LayerTypeAsString() const override; - SurfaceInfo surface_info_; + SurfaceInfo primary_surface_info_; + SurfaceInfo fallback_surface_info_; + bool stretch_content_to_fill_bounds_ = false; DISALLOW_COPY_AND_ASSIGN(SurfaceLayerImpl); diff --git a/chromium/cc/layers/surface_layer_impl_unittest.cc b/chromium/cc/layers/surface_layer_impl_unittest.cc index 051de521cac..1b41a538677 100644 --- a/chromium/cc/layers/surface_layer_impl_unittest.cc +++ b/chromium/cc/layers/surface_layer_impl_unittest.cc @@ -8,6 +8,7 @@ #include "cc/layers/append_quads_data.h" #include "cc/test/layer_test_common.h" +#include "cc/trees/layer_tree_host_common.h" #include "testing/gtest/include/gtest/gtest.h" namespace cc { @@ -15,11 +16,82 @@ namespace { static constexpr FrameSinkId kArbitraryFrameSinkId(1, 1); +TEST(SurfaceLayerImplTest, OcclusionWithDeviceScaleFactor) { + float device_scale_factor = 1.25f; + + gfx::Size layer_size(1000, 1000); + gfx::Size scaled_surface_size( + gfx::ScaleToCeiledSize(layer_size, device_scale_factor)); + gfx::Size viewport_size(1250, 1325); + + const LocalSurfaceId kArbitraryLocalSurfaceId( + 9, base::UnguessableToken::Create()); + + LayerTestCommon::LayerImplTest impl; + + SurfaceLayerImpl* surface_layer_impl = + impl.AddChildToRoot<SurfaceLayerImpl>(); + surface_layer_impl->SetBounds(layer_size); + surface_layer_impl->SetDrawsContent(true); + SurfaceId surface_id(kArbitraryFrameSinkId, kArbitraryLocalSurfaceId); + surface_layer_impl->SetPrimarySurfaceInfo( + SurfaceInfo(surface_id, device_scale_factor, scaled_surface_size)); + + LayerImplList layer_list; + LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( + impl.root_layer_for_testing(), viewport_size, device_scale_factor, + &layer_list); + LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); + + { + SCOPED_TRACE("No occlusion"); + gfx::Rect occluded; + impl.AppendQuadsWithOcclusion(surface_layer_impl, occluded); + + LayerTestCommon::VerifyQuadsExactlyCoverRect( + impl.quad_list(), gfx::Rect(scaled_surface_size)); + EXPECT_EQ(1u, impl.quad_list().size()); + } + + { + SCOPED_TRACE("Full occlusion"); + gfx::Rect occluded(scaled_surface_size); + impl.AppendQuadsWithOcclusion(surface_layer_impl, occluded); + + LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), gfx::Rect()); + EXPECT_EQ(impl.quad_list().size(), 0u); + } + + { + SCOPED_TRACE("Partial occlusion"); + gfx::Rect occluded(gfx::ScaleToEnclosingRect(gfx::Rect(200, 0, 800, 1000), + device_scale_factor)); + impl.AppendQuadsWithOcclusion(surface_layer_impl, occluded); + + size_t partially_occluded_count = 0; + LayerTestCommon::VerifyQuadsAreOccluded(impl.quad_list(), occluded, + &partially_occluded_count); + // The layer outputs one quad, which is partially occluded. + EXPECT_EQ(1u, impl.quad_list().size()); + EXPECT_EQ(1u, partially_occluded_count); + } + { + SCOPED_TRACE("No outside occlusion"); + gfx::Rect occluded(gfx::ScaleToEnclosingRect(gfx::Rect(0, 1000, 1250, 300), + device_scale_factor)); + impl.AppendQuadsWithOcclusion(surface_layer_impl, occluded); + + LayerTestCommon::VerifyQuadsExactlyCoverRect( + impl.quad_list(), gfx::Rect(scaled_surface_size)); + EXPECT_EQ(1u, impl.quad_list().size()); + } +} + TEST(SurfaceLayerImplTest, Occlusion) { gfx::Size layer_size(1000, 1000); gfx::Size viewport_size(1000, 1000); - const LocalFrameId kArbitraryLocalFrameId(9, - base::UnguessableToken::Create()); + const LocalSurfaceId kArbitraryLocalSurfaceId( + 9, base::UnguessableToken::Create()); LayerTestCommon::LayerImplTest impl; @@ -27,8 +99,9 @@ TEST(SurfaceLayerImplTest, Occlusion) { impl.AddChildToRoot<SurfaceLayerImpl>(); surface_layer_impl->SetBounds(layer_size); surface_layer_impl->SetDrawsContent(true); - SurfaceId surface_id(kArbitraryFrameSinkId, kArbitraryLocalFrameId); - surface_layer_impl->SetSurfaceInfo(SurfaceInfo(surface_id, 1.f, layer_size)); + SurfaceId surface_id(kArbitraryFrameSinkId, kArbitraryLocalSurfaceId); + surface_layer_impl->SetPrimarySurfaceInfo( + SurfaceInfo(surface_id, 1.f, layer_size)); impl.CalcDrawProps(viewport_size); @@ -69,8 +142,8 @@ TEST(SurfaceLayerImplTest, SurfaceStretchedToLayerBounds) { LayerTestCommon::LayerImplTest impl; SurfaceLayerImpl* surface_layer_impl = impl.AddChildToRoot<SurfaceLayerImpl>(); - const LocalFrameId kArbitraryLocalFrameId(9, - base::UnguessableToken::Create()); + const LocalSurfaceId kArbitraryLocalSurfaceId( + 9, base::UnguessableToken::Create()); // Given condition: layer and surface have different size and different // aspect ratios. @@ -85,8 +158,8 @@ TEST(SurfaceLayerImplTest, SurfaceStretchedToLayerBounds) { // active tree. surface_layer_impl->SetBounds(layer_size); surface_layer_impl->SetDrawsContent(true); - SurfaceId surface_id(kArbitraryFrameSinkId, kArbitraryLocalFrameId); - surface_layer_impl->SetSurfaceInfo( + SurfaceId surface_id(kArbitraryFrameSinkId, kArbitraryLocalSurfaceId); + surface_layer_impl->SetPrimarySurfaceInfo( SurfaceInfo(surface_id, surface_scale, surface_size)); surface_layer_impl->SetStretchContentToFillBounds(true); @@ -125,5 +198,105 @@ TEST(SurfaceLayerImplTest, SurfaceStretchedToLayerBounds) { EXPECT_EQ(transformed_quad_rect, transformed_layer_rect); } +// This test verifies that two SurfaceDrawQuads are emitted if a +// SurfaceLayerImpl holds both a primary and fallback SurfaceInfo. +TEST(SurfaceLayerImplTest, SurfaceLayerImplEmitsTwoDrawQuadsIfUniqueFallback) { + LayerTestCommon::LayerImplTest impl; + SurfaceLayerImpl* surface_layer_impl = + impl.AddChildToRoot<SurfaceLayerImpl>(); + + // Populate the primary SurfaceInfo. + const LocalSurfaceId kArbitraryLocalSurfaceId1( + 9, base::UnguessableToken::Create()); + SurfaceId surface_id1(kArbitraryFrameSinkId, kArbitraryLocalSurfaceId1); + float surface_scale1 = 1.f; + gfx::Size surface_size1(300, 300); + SurfaceInfo primary_surface_info(surface_id1, surface_scale1, surface_size1); + + // Populate the fallback SurfaceInfo. + const LocalSurfaceId kArbitraryLocalSurfaceId2( + 7, base::UnguessableToken::Create()); + SurfaceId surface_id2(kArbitraryFrameSinkId, kArbitraryLocalSurfaceId2); + float surface_scale2 = 2.f; + gfx::Size surface_size2(400, 400); + SurfaceInfo fallback_surface_info(surface_id2, surface_scale2, surface_size2); + + gfx::Size layer_size(400, 100); + + // Populate the SurfaceLayerImpl ensuring that the primary and fallback + // SurfaceInfos are different. + surface_layer_impl->SetBounds(layer_size); + surface_layer_impl->SetDrawsContent(true); + surface_layer_impl->SetPrimarySurfaceInfo(primary_surface_info); + surface_layer_impl->SetFallbackSurfaceInfo(fallback_surface_info); + + gfx::Size viewport_size(1000, 1000); + impl.CalcDrawProps(viewport_size); + + std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); + AppendQuadsData data; + surface_layer_impl->AppendQuads(render_pass.get(), &data); + + ASSERT_EQ(2u, render_pass->quad_list.size()); + const SurfaceDrawQuad* surface_draw_quad1 = + SurfaceDrawQuad::MaterialCast(render_pass->quad_list.ElementAt(0)); + ASSERT_TRUE(surface_draw_quad1); + const SurfaceDrawQuad* surface_draw_quad2 = + SurfaceDrawQuad::MaterialCast(render_pass->quad_list.ElementAt(1)); + ASSERT_TRUE(surface_draw_quad2); + + EXPECT_EQ(SurfaceDrawQuadType::PRIMARY, + surface_draw_quad1->surface_draw_quad_type); + EXPECT_EQ(surface_id1, surface_draw_quad1->surface_id); + EXPECT_EQ(surface_draw_quad2, surface_draw_quad1->fallback_quad); + EXPECT_EQ(SurfaceDrawQuadType::FALLBACK, + surface_draw_quad2->surface_draw_quad_type); + EXPECT_EQ(surface_id2, surface_draw_quad2->surface_id); +} + +// This test verifies that one SurfaceDrawQuad is emitted if a +// SurfaceLayerImpl holds the same surface ID for both the primary +// and fallback SurfaceInfo. +TEST(SurfaceLayerImplTest, + SurfaceLayerImplEmitsOneDrawQuadsIfPrimaryMatchesFallback) { + LayerTestCommon::LayerImplTest impl; + SurfaceLayerImpl* surface_layer_impl = + impl.AddChildToRoot<SurfaceLayerImpl>(); + + // Populate the primary SurfaceInfo. + const LocalSurfaceId kArbitraryLocalSurfaceId1( + 9, base::UnguessableToken::Create()); + SurfaceId surface_id1(kArbitraryFrameSinkId, kArbitraryLocalSurfaceId1); + float surface_scale1 = 1.f; + gfx::Size surface_size1(300, 300); + SurfaceInfo primary_surface_info(surface_id1, surface_scale1, surface_size1); + + gfx::Size layer_size(400, 100); + + // Populate the SurfaceLayerImpl ensuring that the primary and fallback + // SurfaceInfos are the same. + surface_layer_impl->SetBounds(layer_size); + surface_layer_impl->SetDrawsContent(true); + surface_layer_impl->SetPrimarySurfaceInfo(primary_surface_info); + surface_layer_impl->SetFallbackSurfaceInfo(primary_surface_info); + + gfx::Size viewport_size(1000, 1000); + impl.CalcDrawProps(viewport_size); + + std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); + AppendQuadsData data; + surface_layer_impl->AppendQuads(render_pass.get(), &data); + + ASSERT_EQ(1u, render_pass->quad_list.size()); + const SurfaceDrawQuad* surface_draw_quad1 = + SurfaceDrawQuad::MaterialCast(render_pass->quad_list.ElementAt(0)); + ASSERT_TRUE(surface_draw_quad1); + + EXPECT_EQ(SurfaceDrawQuadType::PRIMARY, + surface_draw_quad1->surface_draw_quad_type); + EXPECT_EQ(surface_id1, surface_draw_quad1->surface_id); + EXPECT_FALSE(surface_draw_quad1->fallback_quad); +} + } // namespace } // namespace cc diff --git a/chromium/cc/layers/surface_layer_unittest.cc b/chromium/cc/layers/surface_layer_unittest.cc index fa6465bd611..ff787087015 100644 --- a/chromium/cc/layers/surface_layer_unittest.cc +++ b/chromium/cc/layers/surface_layer_unittest.cc @@ -14,6 +14,7 @@ #include "cc/animation/animation_host.h" #include "cc/layers/solid_color_layer.h" #include "cc/layers/surface_layer.h" +#include "cc/layers/surface_layer_impl.h" #include "cc/output/compositor_frame.h" #include "cc/surfaces/sequence_surface_reference_factory.h" #include "cc/surfaces/surface_info.h" @@ -34,27 +35,32 @@ namespace { static constexpr FrameSinkId kArbitraryFrameSinkId(1, 1); class SurfaceLayerTest : public testing::Test { + public: + SurfaceLayerTest() + : host_impl_(&task_runner_provider_, &task_graph_runner_) {} + protected: void SetUp() override { animation_host_ = AnimationHost::CreateForTesting(ThreadInstance::MAIN); layer_tree_host_ = FakeLayerTreeHost::Create( &fake_client_, &task_graph_runner_, animation_host_.get()); - layer_tree_ = layer_tree_host_->GetLayerTree(); - layer_tree_->SetViewportSize(gfx::Size(10, 10)); + layer_tree_host_->SetViewportSize(gfx::Size(10, 10)); + host_impl_.CreatePendingTree(); } void TearDown() override { if (layer_tree_host_) { - layer_tree_->SetRootLayer(nullptr); + layer_tree_host_->SetRootLayer(nullptr); layer_tree_host_ = nullptr; } } FakeLayerTreeHostClient fake_client_; + FakeImplTaskRunnerProvider task_runner_provider_; TestTaskGraphRunner task_graph_runner_; std::unique_ptr<AnimationHost> animation_host_; std::unique_ptr<FakeLayerTreeHost> layer_tree_host_; - LayerTree* layer_tree_; + FakeLayerTreeHostImpl host_impl_; }; class TestSurfaceReferenceFactory : public SequenceSurfaceReferenceFactory { @@ -100,19 +106,19 @@ TEST_F(SurfaceLayerTest, MultipleFramesOneSurface) { &required_seq); auto layer = SurfaceLayer::Create(ref_factory); SurfaceInfo info( - SurfaceId(kArbitraryFrameSinkId, LocalFrameId(1, kArbitraryToken)), 1.f, + SurfaceId(kArbitraryFrameSinkId, LocalSurfaceId(1, kArbitraryToken)), 1.f, gfx::Size(1, 1)); - layer->SetSurfaceInfo(info); + layer->SetPrimarySurfaceInfo(info); layer_tree_host_->GetSurfaceSequenceGenerator()->set_frame_sink_id( FrameSinkId(1, 1)); - layer_tree_->SetRootLayer(layer); + layer_tree_host_->SetRootLayer(layer); auto animation_host2 = AnimationHost::CreateForTesting(ThreadInstance::MAIN); std::unique_ptr<FakeLayerTreeHost> layer_tree_host2 = FakeLayerTreeHost::Create(&fake_client_, &task_graph_runner_, animation_host2.get()); auto layer2 = SurfaceLayer::Create(std::move(ref_factory)); - layer2->SetSurfaceInfo(info); + layer2->SetPrimarySurfaceInfo(info); layer_tree_host2->GetSurfaceSequenceGenerator()->set_frame_sink_id( FrameSinkId(2, 2)); layer_tree_host2->SetRootLayer(layer2); @@ -135,12 +141,12 @@ TEST_F(SurfaceLayerTest, MultipleFramesOneSurface) { // Set of sequences that need to be satisfied should include sequences from // both trees. EXPECT_TRUE(required_id == SurfaceId(kArbitraryFrameSinkId, - LocalFrameId(1, kArbitraryToken))); + LocalSurfaceId(1, kArbitraryToken))); EXPECT_EQ(2u, required_seq.size()); EXPECT_TRUE(required_seq.count(expected1)); EXPECT_TRUE(required_seq.count(expected2)); - layer_tree_->SetRootLayer(nullptr); + layer_tree_host_->SetRootLayer(nullptr); layer_tree_host_.reset(); // Layer was removed so sequence from first LayerTreeHost should be @@ -153,6 +159,46 @@ TEST_F(SurfaceLayerTest, MultipleFramesOneSurface) { EXPECT_EQ(2u, required_seq.size()); } +// This test verifies that the primary and fallback SurfaceInfo are pushed +// across from SurfaceLayer to SurfaceLayerImpl. +TEST_F(SurfaceLayerTest, SurfaceInfoPushProperties) { + SurfaceSequence blank_change; + SurfaceId required_id; + std::set<SurfaceSequence> required_sequences; + scoped_refptr<SurfaceReferenceFactory> ref_factory = + new TestSurfaceReferenceFactory(&blank_change, &required_id, + &required_sequences); + + scoped_refptr<SurfaceLayer> layer = SurfaceLayer::Create(ref_factory); + layer_tree_host_->SetRootLayer(layer); + SurfaceInfo primary_info( + SurfaceId(kArbitraryFrameSinkId, + LocalSurfaceId(1, base::UnguessableToken::Create())), + 1.f, gfx::Size(1, 1)); + layer->SetPrimarySurfaceInfo(primary_info); + + std::unique_ptr<SurfaceLayerImpl> layer_impl = + SurfaceLayerImpl::Create(host_impl_.pending_tree(), layer->id()); + layer->PushPropertiesTo(layer_impl.get()); + + // Verify tha the primary SurfaceInfo is pushed through and that there is + // no valid fallback SurfaceInfo. + EXPECT_EQ(primary_info, layer_impl->primary_surface_info()); + EXPECT_EQ(SurfaceInfo(), layer_impl->fallback_surface_info()); + + SurfaceInfo fallback_info( + SurfaceId(kArbitraryFrameSinkId, + LocalSurfaceId(2, base::UnguessableToken::Create())), + 2.f, gfx::Size(10, 10)); + layer->SetFallbackSurfaceInfo(fallback_info); + layer->PushPropertiesTo(layer_impl.get()); + + // Verify that the primary SurfaceInfo stays the same and the new fallback + // SurfaceInfo is pushed through. + EXPECT_EQ(primary_info, layer_impl->primary_surface_info()); + EXPECT_EQ(fallback_info, layer_impl->fallback_surface_info()); +} + // Check that SurfaceSequence is sent through swap promise. class SurfaceLayerSwapPromise : public LayerTreeTest { public: @@ -165,24 +211,24 @@ class SurfaceLayerSwapPromise : public LayerTreeTest { layer_ = SurfaceLayer::Create(new TestSurfaceReferenceFactory( &satisfied_sequence_, &required_id_, &required_set_)); SurfaceInfo info( - SurfaceId(kArbitraryFrameSinkId, LocalFrameId(1, kArbitraryToken)), 1.f, - gfx::Size(1, 1)); - layer_->SetSurfaceInfo(info); + SurfaceId(kArbitraryFrameSinkId, LocalSurfaceId(1, kArbitraryToken)), + 1.f, gfx::Size(1, 1)); + layer_->SetPrimarySurfaceInfo(info); // Layer hasn't been added to tree so no SurfaceSequence generated yet. EXPECT_EQ(0u, required_set_.size()); - layer_tree()->SetRootLayer(layer_); + layer_tree_host()->SetRootLayer(layer_); // Should have SurfaceSequence from first tree. SurfaceSequence expected(kArbitraryFrameSinkId, 1u); EXPECT_TRUE(required_id_ == SurfaceId(kArbitraryFrameSinkId, - LocalFrameId(1, kArbitraryToken))); + LocalSurfaceId(1, kArbitraryToken))); EXPECT_EQ(1u, required_set_.size()); EXPECT_TRUE(required_set_.count(expected)); gfx::Size bounds(100, 100); - layer_tree()->SetViewportSize(bounds); + layer_tree_host()->SetViewportSize(bounds); blank_layer_ = SolidColorLayer::Create(); blank_layer_->SetIsDrawable(true); @@ -220,7 +266,7 @@ class SurfaceLayerSwapPromiseWithDraw : public SurfaceLayerSwapPromise { switch (commit_count_) { case 1: // Remove SurfaceLayer from tree to cause SwapPromise to be created. - layer_tree()->SetRootLayer(blank_layer_); + layer_tree_host()->SetRootLayer(blank_layer_); break; case 2: EndTest(); @@ -233,7 +279,7 @@ class SurfaceLayerSwapPromiseWithDraw : public SurfaceLayerSwapPromise { void AfterTest() override { EXPECT_TRUE(required_id_ == SurfaceId(kArbitraryFrameSinkId, - LocalFrameId(1, kArbitraryToken))); + LocalSurfaceId(1, kArbitraryToken))); EXPECT_EQ(1u, required_set_.size()); EXPECT_TRUE(satisfied_sequence_ == SurfaceSequence(kArbitraryFrameSinkId, 1u)); @@ -259,7 +305,7 @@ class SurfaceLayerSwapPromiseWithoutDraw : public SurfaceLayerSwapPromise { switch (commit_count_) { case 1: // Remove SurfaceLayer from tree to cause SwapPromise to be created. - layer_tree()->SetRootLayer(blank_layer_); + layer_tree_host()->SetRootLayer(blank_layer_); break; case 2: layer_tree_host()->SetNeedsCommit(); @@ -272,7 +318,7 @@ class SurfaceLayerSwapPromiseWithoutDraw : public SurfaceLayerSwapPromise { void AfterTest() override { EXPECT_TRUE(required_id_ == SurfaceId(kArbitraryFrameSinkId, - LocalFrameId(1, kArbitraryToken))); + LocalSurfaceId(1, kArbitraryToken))); EXPECT_EQ(1u, required_set_.size()); EXPECT_TRUE(satisfied_sequence_ == SurfaceSequence(kArbitraryFrameSinkId, 1u)); diff --git a/chromium/cc/layers/texture_layer_impl.cc b/chromium/cc/layers/texture_layer_impl.cc index 98d1ee2f640..a81d66accd1 100644 --- a/chromium/cc/layers/texture_layer_impl.cc +++ b/chromium/cc/layers/texture_layer_impl.cc @@ -106,7 +106,7 @@ bool TextureLayerImpl::WillDraw(DrawMode draw_mode, // Have to upload a copy to a texture for it to be used in a // hardware draw. if (!texture_copy_) - texture_copy_ = ScopedResource::Create(resource_provider); + texture_copy_ = base::MakeUnique<ScopedResource>(resource_provider); if (texture_copy_->size() != texture_mailbox_.size_in_pixels() || resource_provider->InUseByConsumer(texture_copy_->id())) texture_copy_->Free(); diff --git a/chromium/cc/layers/texture_layer_impl_unittest.cc b/chromium/cc/layers/texture_layer_impl_unittest.cc index 870962cfb7c..babb446d456 100644 --- a/chromium/cc/layers/texture_layer_impl_unittest.cc +++ b/chromium/cc/layers/texture_layer_impl_unittest.cc @@ -10,6 +10,7 @@ #include "cc/output/context_provider.h" #include "cc/quads/draw_quad.h" #include "cc/quads/texture_draw_quad.h" +#include "cc/test/fake_compositor_frame_sink.h" #include "cc/test/layer_test_common.h" #include "gpu/command_buffer/client/gles2_interface.h" #include "testing/gtest/include/gtest/gtest.h" @@ -148,10 +149,9 @@ TEST(TextureLayerImplTest, OutputIsSecure) { } TEST(TextureLayerImplTest, ResourceNotFreedOnGpuRasterToggle) { - LayerTreeSettings settings; - settings.gpu_rasterization_enabled = true; bool released = false; - LayerTestCommon::LayerImplTest impl(settings); + LayerTestCommon::LayerImplTest impl( + FakeCompositorFrameSink::Create3dForGpuRasterization()); impl.host_impl()->AdvanceToNextFrame(base::TimeDelta::FromMilliseconds(1)); gfx::Size layer_size(1000, 1000); diff --git a/chromium/cc/layers/texture_layer_unittest.cc b/chromium/cc/layers/texture_layer_unittest.cc index 7d10bf7ee4a..998c6291e3b 100644 --- a/chromium/cc/layers/texture_layer_unittest.cc +++ b/chromium/cc/layers/texture_layer_unittest.cc @@ -38,7 +38,7 @@ #include "cc/test/test_task_graph_runner.h" #include "cc/test/test_web_graphics_context_3d.h" #include "cc/trees/blocking_task_runner.h" -#include "cc/trees/layer_tree_host_in_process.h" +#include "cc/trees/layer_tree_host.h" #include "cc/trees/layer_tree_impl.h" #include "cc/trees/single_thread_proxy.h" #include "gpu/GLES2/gl2extchromium.h" @@ -65,13 +65,13 @@ gpu::SyncToken SyncTokenFromUInt(uint32_t value) { gpu::CommandBufferId::FromUnsafeValue(0x123), value); } -class MockLayerTreeHost : public LayerTreeHostInProcess { +class MockLayerTreeHost : public LayerTreeHost { public: static std::unique_ptr<MockLayerTreeHost> Create( FakeLayerTreeHostClient* client, TaskGraphRunner* task_graph_runner, MutatorHost* mutator_host) { - LayerTreeHostInProcess::InitParams params; + LayerTreeHost::InitParams params; params.client = client; params.task_graph_runner = task_graph_runner; params.mutator_host = mutator_host; @@ -87,8 +87,8 @@ class MockLayerTreeHost : public LayerTreeHostInProcess { MOCK_METHOD0(StopRateLimiter, void()); private: - explicit MockLayerTreeHost(LayerTreeHostInProcess::InitParams* params) - : LayerTreeHostInProcess(params, CompositorMode::SINGLE_THREADED) { + explicit MockLayerTreeHost(LayerTreeHost::InitParams* params) + : LayerTreeHost(params, CompositorMode::SINGLE_THREADED) { InitializeSingleThreaded(&single_thread_client_, base::ThreadTaskRunnerHandle::Get()); } @@ -218,9 +218,8 @@ class TextureLayerTest : public testing::Test { animation_host_ = AnimationHost::CreateForTesting(ThreadInstance::MAIN); layer_tree_host_ = MockLayerTreeHost::Create( &fake_client_, &task_graph_runner_, animation_host_.get()); - layer_tree_ = layer_tree_host_->GetLayerTree(); EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); - layer_tree_->SetViewportSize(gfx::Size(10, 10)); + layer_tree_host_->SetViewportSize(gfx::Size(10, 10)); Mock::VerifyAndClearExpectations(layer_tree_host_.get()); } @@ -229,14 +228,13 @@ class TextureLayerTest : public testing::Test { EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); animation_host_->SetMutatorHostClient(nullptr); - layer_tree_->SetRootLayer(nullptr); + layer_tree_host_->SetRootLayer(nullptr); layer_tree_host_ = nullptr; animation_host_ = nullptr; } std::unique_ptr<MockLayerTreeHost> layer_tree_host_; std::unique_ptr<AnimationHost> animation_host_; - LayerTree* layer_tree_; FakeImplTaskRunnerProvider task_runner_provider_; FakeLayerTreeHostClient fake_client_; TestSharedBitmapManager shared_bitmap_manager_; @@ -249,7 +247,7 @@ class TextureLayerTest : public testing::Test { TEST_F(TextureLayerTest, CheckPropertyChangeCausesCorrectBehavior) { scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(nullptr); - EXPECT_SET_NEEDS_COMMIT(1, layer_tree_->SetRootLayer(test_layer)); + EXPECT_SET_NEEDS_COMMIT(1, layer_tree_host_->SetRootLayer(test_layer)); // Test properties that should call SetNeedsCommit. All properties need to // be set to new values in order for SetNeedsCommit to be called. @@ -289,7 +287,7 @@ TEST_F(TextureLayerWithMailboxTest, ReplaceMailboxOnMainThreadBeforeCommit) { ASSERT_TRUE(test_layer.get()); EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); - layer_tree_->SetRootLayer(test_layer); + layer_tree_host_->SetRootLayer(test_layer); Mock::VerifyAndClearExpectations(layer_tree_host_.get()); EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); @@ -654,6 +652,69 @@ class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest { force_disable_reclaim_resources); } + void AdvanceTestCase() { + ++test_case_; + switch (test_case_) { + case 1: + // Case #1: change mailbox before the commit. The old mailbox should be + // released immediately. + SetMailbox('2'); + EXPECT_EQ(1, callback_count_); + PostSetNeedsCommitToMainThread(); + + // Case 2 does not rely on callbacks to advance. + pending_callback_ = false; + break; + case 2: + // Case #2: change mailbox after the commit (and draw), where the + // layer draws. The old mailbox should be released during the next + // commit. + SetMailbox('3'); + EXPECT_EQ(1, callback_count_); + + // Cases 3-5 rely on a callback to advance. + pending_callback_ = true; + break; + case 3: + EXPECT_EQ(2, callback_count_); + // Case #3: change mailbox when the layer doesn't draw. The old + // mailbox should be released during the next commit. + layer_->SetBounds(gfx::Size()); + SetMailbox('4'); + break; + case 4: + EXPECT_EQ(3, callback_count_); + // Case #4: release mailbox that was committed but never drawn. The + // old mailbox should be released during the next commit. + layer_->SetTextureMailbox(TextureMailbox(), nullptr); + break; + case 5: + EXPECT_EQ(4, callback_count_); + // Restore a mailbox for the next step. + SetMailbox('5'); + + // Cases 6 and 7 do not rely on callbacks to advance. + pending_callback_ = false; + break; + case 6: + // Case #5: remove layer from tree. Callback should *not* be called, the + // mailbox is returned to the main thread. + EXPECT_EQ(4, callback_count_); + layer_->RemoveFromParent(); + break; + case 7: + EXPECT_EQ(4, callback_count_); + // Resetting the mailbox will call the callback now. + layer_->SetTextureMailbox(TextureMailbox(), nullptr); + EXPECT_EQ(5, callback_count_); + EndTest(); + break; + default: + NOTREACHED(); + break; + } + } + // Make sure callback is received on main and doesn't block the impl thread. void ReleaseCallback(char mailbox_char, const gpu::SyncToken& sync_token, @@ -661,6 +722,10 @@ class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest { EXPECT_EQ(true, main_thread_.CalledOnValidThread()); EXPECT_FALSE(lost_resource); ++callback_count_; + + // If we are waiting on a callback, advance now. + if (pending_callback_) + AdvanceTestCase(); } void SetMailbox(char mailbox_char) { @@ -691,63 +756,19 @@ class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest { layer_->SetBounds(bounds); root_->AddChild(layer_); - layer_tree()->SetRootLayer(root_); - layer_tree()->SetViewportSize(bounds); + layer_tree_host()->SetRootLayer(root_); + layer_tree_host()->SetViewportSize(bounds); SetMailbox('1'); EXPECT_EQ(0, callback_count_); - // Case #1: change mailbox before the commit. The old mailbox should be - // released immediately. - SetMailbox('2'); - EXPECT_EQ(1, callback_count_); - PostSetNeedsCommitToMainThread(); + // Setup is complete - advance to test case 1. + AdvanceTestCase(); } void DidCommit() override { - ++commit_count_; - switch (commit_count_) { - case 1: - // Case #2: change mailbox after the commit (and draw), where the - // layer draws. The old mailbox should be released during the next - // commit. - SetMailbox('3'); - EXPECT_EQ(1, callback_count_); - break; - case 2: - EXPECT_EQ(2, callback_count_); - // Case #3: change mailbox when the layer doesn't draw. The old - // mailbox should be released during the next commit. - layer_->SetBounds(gfx::Size()); - SetMailbox('4'); - break; - case 3: - EXPECT_EQ(3, callback_count_); - // Case #4: release mailbox that was committed but never drawn. The - // old mailbox should be released during the next commit. - layer_->SetTextureMailbox(TextureMailbox(), nullptr); - break; - case 4: - EXPECT_EQ(4, callback_count_); - // Restore a mailbox for the next step. - SetMailbox('5'); - break; - case 5: - // Case #5: remove layer from tree. Callback should *not* be called, the - // mailbox is returned to the main thread. - EXPECT_EQ(4, callback_count_); - layer_->RemoveFromParent(); - break; - case 6: - EXPECT_EQ(4, callback_count_); - // Resetting the mailbox will call the callback now. - layer_->SetTextureMailbox(TextureMailbox(), nullptr); - EXPECT_EQ(5, callback_count_); - EndTest(); - break; - default: - NOTREACHED(); - break; - } + // If we are not waiting on a callback, advance now. + if (!pending_callback_) + AdvanceTestCase(); } void AfterTest() override {} @@ -755,7 +776,9 @@ class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest { private: base::ThreadChecker main_thread_; int callback_count_ = 0; - int commit_count_ = 0; + int test_case_ = 0; + // Whether we are waiting on a callback to advance the test case. + bool pending_callback_ = false; scoped_refptr<Layer> root_; scoped_refptr<TextureLayer> layer_; }; @@ -792,8 +815,8 @@ class TextureLayerMailboxIsActivatedDuringCommit : public LayerTreeTest { layer_->SetBounds(bounds); root_->AddChild(layer_); - layer_tree()->SetRootLayer(root_); - layer_tree()->SetViewportSize(bounds); + layer_tree_host()->SetRootLayer(root_); + layer_tree_host()->SetViewportSize(bounds); SetMailbox('1'); PostSetNeedsCommitToMainThread(); @@ -856,7 +879,6 @@ class TextureLayerImplWithMailboxTest : public TextureLayerTest { TextureLayerTest::SetUp(); layer_tree_host_ = MockLayerTreeHost::Create( &fake_client_, &task_graph_runner_, animation_host_.get()); - layer_tree_ = layer_tree_host_->GetLayerTree(); host_impl_.SetVisible(true); EXPECT_TRUE(host_impl_.InitializeRenderer(compositor_frame_sink_.get())); } @@ -1086,7 +1108,7 @@ class TextureLayerNoExtraCommitForMailboxTest texture_layer_->SetIsDrawable(true); root->AddChild(texture_layer_); - layer_tree()->SetRootLayer(root); + layer_tree_host()->SetRootLayer(root); LayerTreeTest::SetupTree(); } @@ -1177,7 +1199,7 @@ class TextureLayerChangeInvisibleMailboxTest texture_layer_->SetIsDrawable(true); parent_layer_->AddChild(texture_layer_); - layer_tree()->SetRootLayer(root); + layer_tree_host()->SetRootLayer(root); LayerTreeTest::SetupTree(); } @@ -1274,7 +1296,7 @@ class TextureLayerReleaseResourcesBase texture_layer->SetBounds(gfx::Size(10, 10)); texture_layer->SetIsDrawable(true); - layer_tree()->root_layer()->AddChild(texture_layer); + layer_tree_host()->root_layer()->AddChild(texture_layer); texture_layer_id_ = texture_layer->id(); } @@ -1348,8 +1370,8 @@ class TextureLayerWithMailboxMainThreadDeleted : public LayerTreeTest { layer_->SetBounds(bounds); root_->AddChild(layer_); - layer_tree()->SetRootLayer(root_); - layer_tree()->SetViewportSize(bounds); + layer_tree_host()->SetRootLayer(root_); + layer_tree_host()->SetViewportSize(bounds); } void BeginTest() override { @@ -1418,8 +1440,8 @@ class TextureLayerWithMailboxImplThreadDeleted : public LayerTreeTest { layer_->SetBounds(bounds); root_->AddChild(layer_); - layer_tree()->SetRootLayer(root_); - layer_tree()->SetViewportSize(bounds); + layer_tree_host()->SetRootLayer(root_); + layer_tree_host()->SetViewportSize(bounds); } void BeginTest() override { diff --git a/chromium/cc/layers/ui_resource_layer.cc b/chromium/cc/layers/ui_resource_layer.cc index b3efe1caeaf..c2ed2147727 100644 --- a/chromium/cc/layers/ui_resource_layer.cc +++ b/chromium/cc/layers/ui_resource_layer.cc @@ -14,47 +14,6 @@ namespace cc { - -namespace { - -class ScopedUIResourceHolder : public UIResourceLayer::UIResourceHolder { - public: - static std::unique_ptr<ScopedUIResourceHolder> Create( - UIResourceManager* ui_resource_manager, - const SkBitmap& skbitmap) { - return base::WrapUnique( - new ScopedUIResourceHolder(ui_resource_manager, skbitmap)); - } - UIResourceId id() override { return resource_->id(); } - - private: - ScopedUIResourceHolder(UIResourceManager* ui_resource_manager, - const SkBitmap& skbitmap) { - resource_ = ScopedUIResource::Create(ui_resource_manager, - UIResourceBitmap(skbitmap)); - } - - std::unique_ptr<ScopedUIResource> resource_; -}; - -class SharedUIResourceHolder : public UIResourceLayer::UIResourceHolder { - public: - static std::unique_ptr<SharedUIResourceHolder> Create(UIResourceId id) { - return base::WrapUnique(new SharedUIResourceHolder(id)); - } - - UIResourceId id() override { return id_; } - - private: - explicit SharedUIResourceHolder(UIResourceId id) : id_(id) {} - - UIResourceId id_; -}; - -} // anonymous namespace - -UIResourceLayer::UIResourceHolder::~UIResourceHolder() {} - scoped_refptr<UIResourceLayer> UIResourceLayer::Create() { return make_scoped_refptr(new UIResourceLayer()); } @@ -110,47 +69,31 @@ void UIResourceLayer::SetLayerTreeHost(LayerTreeHost* host) { Layer::SetLayerTreeHost(host); // Recreate the resource held against the new LTH. - RecreateUIResourceHolder(); + RecreateUIResourceIdFromBitmap(); UpdateDrawsContent(HasDrawableContent()); } -void UIResourceLayer::RecreateUIResourceHolder() { - if (!bitmap_.empty()) - SetBitmap(bitmap_); -} - -void UIResourceLayer::SetBitmap(const SkBitmap& skbitmap) { - bitmap_ = skbitmap; - if (GetLayerTree() && !bitmap_.empty()) { - ui_resource_holder_ = ScopedUIResourceHolder::Create( - layer_tree_host()->GetUIResourceManager(), bitmap_); - } else { - ui_resource_holder_ = nullptr; - } - UpdateDrawsContent(HasDrawableContent()); - SetNeedsCommit(); +void UIResourceLayer::SetBitmap(const SkBitmap& bitmap) { + bitmap_ = bitmap; + if (!layer_tree_host()) + return; + SetUIResourceIdInternal( + layer_tree_host()->GetUIResourceManager()->GetOrCreateUIResource(bitmap)); } void UIResourceLayer::SetUIResourceId(UIResourceId resource_id) { - if (ui_resource_holder_ && ui_resource_holder_->id() == resource_id) + // Even if the ID is not changing we should drop the bitmap. The ID is 0 when + // there's no layer tree. When setting an id (even if to 0), we should no + // longer keep the bitmap. + bitmap_.reset(); + if (resource_id_ == resource_id) return; - - if (!bitmap_.isNull()) - bitmap_.reset(); - - if (resource_id) - ui_resource_holder_ = SharedUIResourceHolder::Create(resource_id); - else - ui_resource_holder_ = nullptr; - - UpdateDrawsContent(HasDrawableContent()); - SetNeedsCommit(); + SetUIResourceIdInternal(resource_id); } bool UIResourceLayer::HasDrawableContent() const { - return ui_resource_holder_ && ui_resource_holder_->id() && - Layer::HasDrawableContent(); + return resource_id_ && Layer::HasDrawableContent(); } void UIResourceLayer::PushPropertiesTo(LayerImpl* layer) { @@ -158,19 +101,28 @@ void UIResourceLayer::PushPropertiesTo(LayerImpl* layer) { TRACE_EVENT0("cc", "UIResourceLayer::PushPropertiesTo"); UIResourceLayerImpl* layer_impl = static_cast<UIResourceLayerImpl*>(layer); - if (!ui_resource_holder_) { - layer_impl->SetUIResourceId(0); - } else { - DCHECK(GetLayerTree()); + layer_impl->SetUIResourceId(resource_id_); + if (resource_id_) { + DCHECK(layer_tree_host()); gfx::Size image_size = layer_tree_host()->GetUIResourceManager()->GetUIResourceSize( - ui_resource_holder_->id()); - layer_impl->SetUIResourceId(ui_resource_holder_->id()); + resource_id_); layer_impl->SetImageBounds(image_size); layer_impl->SetUV(uv_top_left_, uv_bottom_right_); layer_impl->SetVertexOpacity(vertex_opacity_); } } +void UIResourceLayer::RecreateUIResourceIdFromBitmap() { + if (!bitmap_.empty()) + SetBitmap(bitmap_); +} + +void UIResourceLayer::SetUIResourceIdInternal(UIResourceId resource_id) { + resource_id_ = resource_id; + UpdateDrawsContent(HasDrawableContent()); + SetNeedsCommit(); +} + } // namespace cc diff --git a/chromium/cc/layers/ui_resource_layer.h b/chromium/cc/layers/ui_resource_layer.h index c97c60c1737..0dbe6d019e4 100644 --- a/chromium/cc/layers/ui_resource_layer.h +++ b/chromium/cc/layers/ui_resource_layer.h @@ -25,11 +25,14 @@ class CC_EXPORT UIResourceLayer : public Layer { void SetLayerTreeHost(LayerTreeHost* host) override; + // Sets the resource. If they don't exist already, the shared UI resource and + // ID are generated and cached in a map in the associated UIResourceManager. + // Currently, this resource will never be released by the UIResourceManager. void SetBitmap(const SkBitmap& skbitmap); - // An alternative way of setting the resource to allow for sharing. If you use - // this method, you are responsible for updating the ID if the layer moves - // between compositors. + // An alternative way of setting the resource where an ID is used directly. If + // you use this method, you are responsible for updating the ID if the layer + // moves between compositors. void SetUIResourceId(UIResourceId resource_id); // Sets a UV transform to be used at draw time. Defaults to (0, 0) and (1, 1). @@ -42,29 +45,28 @@ class CC_EXPORT UIResourceLayer : public Layer { float top_right, float bottom_right); - class UIResourceHolder { - public: - virtual UIResourceId id() = 0; - virtual ~UIResourceHolder(); - }; - protected: UIResourceLayer(); ~UIResourceLayer() override; bool HasDrawableContent() const override; - std::unique_ptr<UIResourceHolder> ui_resource_holder_; + UIResourceId resource_id() const { return resource_id_; } + + private: + std::unique_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override; + void RecreateUIResourceIdFromBitmap(); + void SetUIResourceIdInternal(UIResourceId resource_id); + + // The resource ID will be zero when it's unset or when there's no associated + // LayerTreeHost. + UIResourceId resource_id_ = 0; SkBitmap bitmap_; gfx::PointF uv_top_left_; gfx::PointF uv_bottom_right_; float vertex_opacity_[4]; - private: - std::unique_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override; - void RecreateUIResourceHolder(); - DISALLOW_COPY_AND_ASSIGN(UIResourceLayer); }; diff --git a/chromium/cc/layers/ui_resource_layer_unittest.cc b/chromium/cc/layers/ui_resource_layer_unittest.cc index a018e71628b..17dc4dadfe7 100644 --- a/chromium/cc/layers/ui_resource_layer_unittest.cc +++ b/chromium/cc/layers/ui_resource_layer_unittest.cc @@ -9,13 +9,9 @@ #include "cc/resources/resource_provider.h" #include "cc/resources/scoped_ui_resource.h" #include "cc/test/fake_layer_tree_host.h" -#include "cc/test/fake_layer_tree_host_client.h" -#include "cc/test/fake_output_surface.h" -#include "cc/test/fake_output_surface_client.h" #include "cc/test/geometry_test_utils.h" +#include "cc/test/layer_test_common.h" #include "cc/test/stub_layer_tree_host_single_thread_client.h" -#include "cc/test/test_task_graph_runner.h" -#include "cc/trees/layer_tree_host.h" #include "cc/trees/single_thread_proxy.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -35,11 +31,8 @@ class TestUIResourceLayer : public UIResourceLayer { return make_scoped_refptr(new TestUIResourceLayer()); } - UIResourceId GetUIResourceId() { - if (ui_resource_holder_) - return ui_resource_holder_->id(); - return 0; - } + using UIResourceLayer::resource_id; + using UIResourceLayer::HasDrawableContent; protected: TestUIResourceLayer() : UIResourceLayer() { SetIsDrawable(true); } @@ -48,23 +41,14 @@ class TestUIResourceLayer : public UIResourceLayer { class UIResourceLayerTest : public testing::Test { protected: - void SetUp() override { - animation_host_ = AnimationHost::CreateForTesting(ThreadInstance::MAIN); - layer_tree_host_ = FakeLayerTreeHost::Create( - &fake_client_, &task_graph_runner_, animation_host_.get()); - layer_tree_host_->InitializeSingleThreaded( - &single_thread_client_, base::ThreadTaskRunnerHandle::Get()); - } - void TearDown() override { - Mock::VerifyAndClearExpectations(layer_tree_host_.get()); + Mock::VerifyAndClearExpectations(layer_tree_host()); } - FakeLayerTreeHostClient fake_client_; - StubLayerTreeHostSingleThreadClient single_thread_client_; - TestTaskGraphRunner task_graph_runner_; - std::unique_ptr<AnimationHost> animation_host_; - std::unique_ptr<FakeLayerTreeHost> layer_tree_host_; + FakeLayerTreeHost* layer_tree_host() { return layer_impl_test_.host(); } + + private: + LayerTestCommon::LayerImplTest layer_impl_test_; }; TEST_F(UIResourceLayerTest, SetBitmap) { @@ -72,9 +56,9 @@ TEST_F(UIResourceLayerTest, SetBitmap) { ASSERT_TRUE(test_layer.get()); test_layer->SetBounds(gfx::Size(100, 100)); - layer_tree_host_->SetRootLayer(test_layer); - Mock::VerifyAndClearExpectations(layer_tree_host_.get()); - EXPECT_EQ(test_layer->GetLayerTreeHostForTesting(), layer_tree_host_.get()); + layer_tree_host()->SetRootLayer(test_layer); + Mock::VerifyAndClearExpectations(layer_tree_host()); + EXPECT_EQ(test_layer->GetLayerTreeHostForTesting(), layer_tree_host()); test_layer->SavePaintProperties(); test_layer->Update(); @@ -96,9 +80,9 @@ TEST_F(UIResourceLayerTest, SetUIResourceId) { ASSERT_TRUE(test_layer.get()); test_layer->SetBounds(gfx::Size(100, 100)); - layer_tree_host_->SetRootLayer(test_layer); - Mock::VerifyAndClearExpectations(layer_tree_host_.get()); - EXPECT_EQ(test_layer->GetLayerTreeHostForTesting(), layer_tree_host_.get()); + layer_tree_host()->SetRootLayer(test_layer); + Mock::VerifyAndClearExpectations(layer_tree_host()); + EXPECT_EQ(test_layer->GetLayerTreeHostForTesting(), layer_tree_host()); test_layer->SavePaintProperties(); test_layer->Update(); @@ -107,7 +91,7 @@ TEST_F(UIResourceLayerTest, SetUIResourceId) { bool is_opaque = false; std::unique_ptr<ScopedUIResource> resource = - ScopedUIResource::Create(layer_tree_host_->GetUIResourceManager(), + ScopedUIResource::Create(layer_tree_host()->GetUIResourceManager(), UIResourceBitmap(gfx::Size(10, 10), is_opaque)); test_layer->SetUIResourceId(resource->id()); test_layer->Update(); @@ -115,20 +99,21 @@ TEST_F(UIResourceLayerTest, SetUIResourceId) { EXPECT_TRUE(test_layer->DrawsContent()); // ID is preserved even when you set ID first and attach it to the tree. - layer_tree_host_->SetRootLayer(nullptr); + layer_tree_host()->SetRootLayer(nullptr); std::unique_ptr<ScopedUIResource> shared_resource = - ScopedUIResource::Create(layer_tree_host_->GetUIResourceManager(), + ScopedUIResource::Create(layer_tree_host()->GetUIResourceManager(), UIResourceBitmap(gfx::Size(5, 5), is_opaque)); test_layer->SetUIResourceId(shared_resource->id()); - layer_tree_host_->SetRootLayer(test_layer); - EXPECT_EQ(shared_resource->id(), test_layer->GetUIResourceId()); + layer_tree_host()->SetRootLayer(test_layer); + EXPECT_EQ(shared_resource->id(), test_layer->resource_id()); EXPECT_TRUE(test_layer->DrawsContent()); } TEST_F(UIResourceLayerTest, BitmapClearedOnSetUIResourceId) { - scoped_refptr<UIResourceLayer> test_layer = TestUIResourceLayer::Create(); + scoped_refptr<TestUIResourceLayer> test_layer = TestUIResourceLayer::Create(); ASSERT_TRUE(test_layer.get()); test_layer->SetBounds(gfx::Size(100, 100)); + EXPECT_FALSE(test_layer->HasDrawableContent()); SkBitmap bitmap; bitmap.allocN32Pixels(10, 10); @@ -136,11 +121,82 @@ TEST_F(UIResourceLayerTest, BitmapClearedOnSetUIResourceId) { ASSERT_FALSE(bitmap.isNull()); ASSERT_TRUE(bitmap.pixelRef()->unique()); + // Without a layer tree, the only additional reference is in UIResourceLayer. test_layer->SetBitmap(bitmap); ASSERT_FALSE(bitmap.pixelRef()->unique()); + // Also, there's no drawable content due to the lack of a LTH. + EXPECT_FALSE(test_layer->HasDrawableContent()); test_layer->SetUIResourceId(0); EXPECT_TRUE(bitmap.pixelRef()->unique()); + EXPECT_FALSE(test_layer->HasDrawableContent()); + + // Add to a layer tree; now the UIResourceManager holds onto a ref + // indefinitely. + { + LayerTestCommon::LayerImplTest impl; + impl.host()->SetRootLayer(test_layer); + + test_layer->SetBitmap(bitmap); + EXPECT_FALSE(bitmap.pixelRef()->unique()); + EXPECT_TRUE(test_layer->HasDrawableContent()); + test_layer->SetUIResourceId(0); + EXPECT_FALSE(bitmap.pixelRef()->unique()); + EXPECT_FALSE(test_layer->HasDrawableContent()); + } + + // After the layer tree/resource manager are destroyed, refs are back to 1. + test_layer->SetUIResourceId(0); + EXPECT_TRUE(bitmap.pixelRef()->unique()); + EXPECT_FALSE(test_layer->HasDrawableContent()); +} + +TEST_F(UIResourceLayerTest, SharedBitmap) { + SkBitmap bitmap; + bitmap.allocN32Pixels(10, 10); + bitmap.setImmutable(); + // The SkPixelRef is what's important, not the SkBitmap itself. + SkBitmap bitmap_copy = bitmap; + + scoped_refptr<TestUIResourceLayer> layer1 = TestUIResourceLayer::Create(); + layer_tree_host()->SetRootLayer(layer1); + layer1->SetBitmap(bitmap); + bitmap.reset(); + layer1->SavePaintProperties(); + layer1->Update(); + EXPECT_TRUE(layer1->DrawsContent()); + const auto resource_id = layer1->resource_id(); + + // Second layer, same LTH. Resource is shared (has same ID). + scoped_refptr<TestUIResourceLayer> layer2 = TestUIResourceLayer::Create(); + layer_tree_host()->SetRootLayer(layer2); + layer2->SetBitmap(bitmap_copy); + layer2->SavePaintProperties(); + layer2->Update(); + EXPECT_TRUE(layer2->DrawsContent()); + EXPECT_EQ(resource_id, layer2->resource_id()); + + // Change bitmap, different resource id. + SkBitmap other_bitmap; + other_bitmap.allocN32Pixels(12, 12); + other_bitmap.setImmutable(); + layer2->SetBitmap(other_bitmap); + EXPECT_NE(resource_id, layer2->resource_id()); + + // Switch layer to different LTH. ID is in a new namespace (LTH), so it may + // still be the same. We can make sure it's using the same shared bitmap by + // verifying that whatever ID it has, it changes away from and back to when we + // change the shared bitmap to something else then back to the original. + LayerTestCommon::LayerImplTest impl; + impl.host()->SetRootLayer(layer1); + layer1->SavePaintProperties(); + layer1->Update(); + EXPECT_TRUE(layer1->DrawsContent()); + const auto other_lth_resource_id = layer1->resource_id(); + layer1->SetBitmap(other_bitmap); + EXPECT_NE(other_lth_resource_id, layer1->resource_id()); + layer1->SetBitmap(bitmap_copy); + EXPECT_EQ(other_lth_resource_id, layer1->resource_id()); } } // namespace diff --git a/chromium/cc/layers/video_frame_provider_client_impl.cc b/chromium/cc/layers/video_frame_provider_client_impl.cc index 751d32f83b2..35822333beb 100644 --- a/chromium/cc/layers/video_frame_provider_client_impl.cc +++ b/chromium/cc/layers/video_frame_provider_client_impl.cc @@ -56,6 +56,7 @@ void VideoFrameProviderClientImpl::SetActiveVideoLayer( void VideoFrameProviderClientImpl::Stop() { DCHECK(thread_checker_.CalledOnValidThread()); + active_video_layer_ = nullptr; // It's called when the main thread is blocked, so lock isn't needed. if (provider_) { provider_->SetVideoFrameProviderClient(nullptr); @@ -63,7 +64,6 @@ void VideoFrameProviderClientImpl::Stop() { } if (rendering_) StopRendering(); - active_video_layer_ = nullptr; stopped_ = true; } @@ -127,6 +127,8 @@ void VideoFrameProviderClientImpl::StopRendering() { DCHECK(!stopped_); client_->RemoveVideoFrameController(this); rendering_ = false; + if (active_video_layer_) + active_video_layer_->SetNeedsRedraw(); } void VideoFrameProviderClientImpl::DidReceiveFrame() { diff --git a/chromium/cc/layers/video_frame_provider_client_impl_unittest.cc b/chromium/cc/layers/video_frame_provider_client_impl_unittest.cc index eaa0e6fe40f..075f4b7674f 100644 --- a/chromium/cc/layers/video_frame_provider_client_impl_unittest.cc +++ b/chromium/cc/layers/video_frame_provider_client_impl_unittest.cc @@ -102,6 +102,14 @@ TEST_F(VideoFrameProviderClientImplTest, StartStopRendering) { StopRendering(); } +TEST_F(VideoFrameProviderClientImplTest, StopRenderingUpdateDamage) { + CreateActiveVideoLayer(); + StartRendering(); + EXPECT_EQ(gfx::Rect(), video_layer_impl_->update_rect()); + StopRendering(); + EXPECT_NE(gfx::Rect(), video_layer_impl_->update_rect()); +} + TEST_F(VideoFrameProviderClientImplTest, StopUsingProvider) { ASSERT_TRUE(client_impl_->get_provider_for_testing()); StartRendering(); @@ -110,6 +118,28 @@ TEST_F(VideoFrameProviderClientImplTest, StopUsingProvider) { ASSERT_FALSE(client_impl_->get_provider_for_testing()); } +TEST_F(VideoFrameProviderClientImplTest, StopUsingProviderUpdateDamage) { + CreateActiveVideoLayer(); + ASSERT_TRUE(client_impl_->get_provider_for_testing()); + StartRendering(); + EXPECT_CALL(*this, RemoveVideoFrameController(_)); + EXPECT_EQ(gfx::Rect(), video_layer_impl_->update_rect()); + client_impl_->StopUsingProvider(); + EXPECT_NE(gfx::Rect(), video_layer_impl_->update_rect()); + ASSERT_FALSE(client_impl_->get_provider_for_testing()); +} + +TEST_F(VideoFrameProviderClientImplTest, StopNotUpdateDamage) { + CreateActiveVideoLayer(); + ASSERT_TRUE(client_impl_->get_provider_for_testing()); + StartRendering(); + EXPECT_CALL(*this, RemoveVideoFrameController(_)); + EXPECT_EQ(gfx::Rect(), video_layer_impl_->update_rect()); + client_impl_->Stop(); + EXPECT_EQ(gfx::Rect(), video_layer_impl_->update_rect()); + ASSERT_FALSE(client_impl_->get_provider_for_testing()); +} + TEST_F(VideoFrameProviderClientImplTest, FrameAcquisition) { CreateActiveVideoLayer(); StartRenderingAndRenderFrame(); |