Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: cc/layers/layer_impl.cc

Issue 1866203004: Convert //cc from scoped_ptr to std::unique_ptr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: scopedptrcc: rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/layers/layer_impl.h ('k') | cc/layers/layer_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/layers/layer_impl.h" 5 #include "cc/layers/layer_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/json/json_reader.h" 13 #include "base/json/json_reader.h"
14 #include "base/memory/ptr_util.h"
14 #include "base/numerics/safe_conversions.h" 15 #include "base/numerics/safe_conversions.h"
15 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
16 #include "base/trace_event/trace_event.h" 17 #include "base/trace_event/trace_event.h"
17 #include "base/trace_event/trace_event_argument.h" 18 #include "base/trace_event/trace_event_argument.h"
18 #include "cc/animation/mutable_properties.h" 19 #include "cc/animation/mutable_properties.h"
19 #include "cc/base/math_util.h" 20 #include "cc/base/math_util.h"
20 #include "cc/base/simple_enclosed_region.h" 21 #include "cc/base/simple_enclosed_region.h"
21 #include "cc/debug/debug_colors.h" 22 #include "cc/debug/debug_colors.h"
22 #include "cc/debug/layer_tree_debug_state.h" 23 #include "cc/debug/layer_tree_debug_state.h"
23 #include "cc/debug/micro_benchmark_impl.h" 24 #include "cc/debug/micro_benchmark_impl.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 TRACE_EVENT_OBJECT_DELETED_WITH_ID( 117 TRACE_EVENT_OBJECT_DELETED_WITH_ID(
117 TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerImpl", this); 118 TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerImpl", this);
118 119
119 if (mask_layer_) 120 if (mask_layer_)
120 layer_tree_impl_->RemoveLayer(mask_layer_id_); 121 layer_tree_impl_->RemoveLayer(mask_layer_id_);
121 if (replica_layer_) 122 if (replica_layer_)
122 layer_tree_impl_->RemoveLayer(replica_layer_id_); 123 layer_tree_impl_->RemoveLayer(replica_layer_id_);
123 ClearChildList(); 124 ClearChildList();
124 } 125 }
125 126
126 void LayerImpl::AddChild(scoped_ptr<LayerImpl> child) { 127 void LayerImpl::AddChild(std::unique_ptr<LayerImpl> child) {
127 child->SetParent(this); 128 child->SetParent(this);
128 DCHECK_EQ(layer_tree_impl(), child->layer_tree_impl()); 129 DCHECK_EQ(layer_tree_impl(), child->layer_tree_impl());
129 children_.push_back(child.get()); 130 children_.push_back(child.get());
130 layer_tree_impl_->AddLayer(std::move(child)); 131 layer_tree_impl_->AddLayer(std::move(child));
131 } 132 }
132 133
133 scoped_ptr<LayerImpl> LayerImpl::RemoveChildForTesting(LayerImpl* child) { 134 std::unique_ptr<LayerImpl> LayerImpl::RemoveChildForTesting(LayerImpl* child) {
134 auto it = std::find(children_.begin(), children_.end(), child); 135 auto it = std::find(children_.begin(), children_.end(), child);
135 if (it != children_.end()) 136 if (it != children_.end())
136 children_.erase(it); 137 children_.erase(it);
137 return layer_tree_impl_->RemoveLayer(child->id()); 138 return layer_tree_impl_->RemoveLayer(child->id());
138 } 139 }
139 140
140 void LayerImpl::SetParent(LayerImpl* parent) { 141 void LayerImpl::SetParent(LayerImpl* parent) {
141 parent_ = parent; 142 parent_ = parent;
142 } 143 }
143 144
(...skipping 16 matching lines...) Expand all
160 return; 161 return;
161 162
162 if (parent) 163 if (parent)
163 DCHECK_EQ(layer_tree_impl()->LayerById(parent->id()), parent); 164 DCHECK_EQ(layer_tree_impl()->LayerById(parent->id()), parent);
164 165
165 scroll_parent_ = parent; 166 scroll_parent_ = parent;
166 SetNeedsPushProperties(); 167 SetNeedsPushProperties();
167 } 168 }
168 169
169 void LayerImpl::SetDebugInfo( 170 void LayerImpl::SetDebugInfo(
170 scoped_ptr<base::trace_event::ConvertableToTraceFormat> debug_info) { 171 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> debug_info) {
171 owned_debug_info_ = std::move(debug_info); 172 owned_debug_info_ = std::move(debug_info);
172 debug_info_ = owned_debug_info_.get(); 173 debug_info_ = owned_debug_info_.get();
173 SetNeedsPushProperties(); 174 SetNeedsPushProperties();
174 } 175 }
175 176
176 void LayerImpl::SetScrollChildren(std::set<LayerImpl*>* children) { 177 void LayerImpl::SetScrollChildren(std::set<LayerImpl*>* children) {
177 if (scroll_children_.get() == children) 178 if (scroll_children_.get() == children)
178 return; 179 return;
179 scroll_children_.reset(children); 180 scroll_children_.reset(children);
180 SetNeedsPushProperties(); 181 SetNeedsPushProperties();
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 effect_tree_index_ = index; 243 effect_tree_index_ = index;
243 SetNeedsPushProperties(); 244 SetNeedsPushProperties();
244 } 245 }
245 246
246 void LayerImpl::SetScrollTreeIndex(int index) { 247 void LayerImpl::SetScrollTreeIndex(int index) {
247 scroll_tree_index_ = index; 248 scroll_tree_index_ = index;
248 SetNeedsPushProperties(); 249 SetNeedsPushProperties();
249 } 250 }
250 251
251 void LayerImpl::PassCopyRequests( 252 void LayerImpl::PassCopyRequests(
252 std::vector<scoped_ptr<CopyOutputRequest>>* requests) { 253 std::vector<std::unique_ptr<CopyOutputRequest>>* requests) {
253 // In the case that a layer still has a copy request, this means that there's 254 // In the case that a layer still has a copy request, this means that there's
254 // a commit to the active tree without a draw. This only happens in some 255 // a commit to the active tree without a draw. This only happens in some
255 // edge cases during lost context or visibility changes, so don't try to 256 // edge cases during lost context or visibility changes, so don't try to
256 // handle preserving these output requests (and their surface). 257 // handle preserving these output requests (and their surface).
257 if (!copy_requests_.empty()) { 258 if (!copy_requests_.empty()) {
258 layer_tree_impl()->RemoveLayerWithCopyOutputRequest(this); 259 layer_tree_impl()->RemoveLayerWithCopyOutputRequest(this);
259 // Destroying these will abort them. 260 // Destroying these will abort them.
260 copy_requests_.clear(); 261 copy_requests_.clear();
261 } 262 }
262 263
263 if (requests->empty()) 264 if (requests->empty())
264 return; 265 return;
265 266
266 bool was_empty = copy_requests_.empty(); 267 bool was_empty = copy_requests_.empty();
267 for (auto& request : *requests) 268 for (auto& request : *requests)
268 copy_requests_.push_back(std::move(request)); 269 copy_requests_.push_back(std::move(request));
269 requests->clear(); 270 requests->clear();
270 271
271 if (was_empty && layer_tree_impl()->IsActiveTree()) 272 if (was_empty && layer_tree_impl()->IsActiveTree())
272 layer_tree_impl()->AddLayerWithCopyOutputRequest(this); 273 layer_tree_impl()->AddLayerWithCopyOutputRequest(this);
273 } 274 }
274 275
275 void LayerImpl::TakeCopyRequestsAndTransformToTarget( 276 void LayerImpl::TakeCopyRequestsAndTransformToTarget(
276 std::vector<scoped_ptr<CopyOutputRequest>>* requests) { 277 std::vector<std::unique_ptr<CopyOutputRequest>>* requests) {
277 DCHECK(!copy_requests_.empty()); 278 DCHECK(!copy_requests_.empty());
278 DCHECK(layer_tree_impl()->IsActiveTree()); 279 DCHECK(layer_tree_impl()->IsActiveTree());
279 DCHECK_EQ(render_target(), this); 280 DCHECK_EQ(render_target(), this);
280 281
281 size_t first_inserted_request = requests->size(); 282 size_t first_inserted_request = requests->size();
282 for (auto& request : copy_requests_) 283 for (auto& request : copy_requests_)
283 requests->push_back(std::move(request)); 284 requests->push_back(std::move(request));
284 copy_requests_.clear(); 285 copy_requests_.clear();
285 286
286 for (size_t i = first_inserted_request; i < requests->size(); ++i) { 287 for (size_t i = first_inserted_request; i < requests->size(); ++i) {
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 455
455 void LayerImpl::set_user_scrollable_vertical(bool scrollable) { 456 void LayerImpl::set_user_scrollable_vertical(bool scrollable) {
456 user_scrollable_vertical_ = scrollable; 457 user_scrollable_vertical_ = scrollable;
457 } 458 }
458 459
459 bool LayerImpl::user_scrollable(ScrollbarOrientation orientation) const { 460 bool LayerImpl::user_scrollable(ScrollbarOrientation orientation) const {
460 return (orientation == HORIZONTAL) ? user_scrollable_horizontal_ 461 return (orientation == HORIZONTAL) ? user_scrollable_horizontal_
461 : user_scrollable_vertical_; 462 : user_scrollable_vertical_;
462 } 463 }
463 464
464 scoped_ptr<LayerImpl> LayerImpl::CreateLayerImpl(LayerTreeImpl* tree_impl) { 465 std::unique_ptr<LayerImpl> LayerImpl::CreateLayerImpl(
466 LayerTreeImpl* tree_impl) {
465 return LayerImpl::Create(tree_impl, layer_id_); 467 return LayerImpl::Create(tree_impl, layer_id_);
466 } 468 }
467 469
468 void LayerImpl::set_main_thread_scrolling_reasons( 470 void LayerImpl::set_main_thread_scrolling_reasons(
469 uint32_t main_thread_scrolling_reasons) { 471 uint32_t main_thread_scrolling_reasons) {
470 if (main_thread_scrolling_reasons_ == main_thread_scrolling_reasons) 472 if (main_thread_scrolling_reasons_ == main_thread_scrolling_reasons)
471 return; 473 return;
472 474
473 if (main_thread_scrolling_reasons & 475 if (main_thread_scrolling_reasons &
474 MainThreadScrollingReason::kHasNonLayerViewportConstrainedObjects && 476 MainThreadScrollingReason::kHasNonLayerViewportConstrainedObjects &&
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 646
645 result->SetBoolean("DrawsContent", draws_content_); 647 result->SetBoolean("DrawsContent", draws_content_);
646 result->SetBoolean("Is3dSorted", Is3dSorted()); 648 result->SetBoolean("Is3dSorted", Is3dSorted());
647 result->SetDouble("OPACITY", opacity()); 649 result->SetDouble("OPACITY", opacity());
648 result->SetBoolean("ContentsOpaque", contents_opaque_); 650 result->SetBoolean("ContentsOpaque", contents_opaque_);
649 651
650 if (scrollable()) 652 if (scrollable())
651 result->SetBoolean("Scrollable", true); 653 result->SetBoolean("Scrollable", true);
652 654
653 if (!touch_event_handler_region_.IsEmpty()) { 655 if (!touch_event_handler_region_.IsEmpty()) {
654 scoped_ptr<base::Value> region = touch_event_handler_region_.AsValue(); 656 std::unique_ptr<base::Value> region = touch_event_handler_region_.AsValue();
655 result->Set("TouchRegion", region.release()); 657 result->Set("TouchRegion", region.release());
656 } 658 }
657 659
658 list = new base::ListValue; 660 list = new base::ListValue;
659 for (size_t i = 0; i < children_.size(); ++i) 661 for (size_t i = 0; i < children_.size(); ++i)
660 list->Append(children_[i]->LayerTreeAsJson()); 662 list->Append(children_[i]->LayerTreeAsJson());
661 result->Set("Children", list); 663 result->Set("Children", list);
662 664
663 return result; 665 return result;
664 } 666 }
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 gfx::PointF() + offset_to_transform_parent(), gfx::SizeF(bounds())); 974 gfx::PointF() + offset_to_transform_parent(), gfx::SizeF(bounds()));
973 property_trees->clip_tree.set_needs_update(true); 975 property_trees->clip_tree.set_needs_update(true);
974 } 976 }
975 property_trees->full_tree_damaged = true; 977 property_trees->full_tree_damaged = true;
976 layer_tree_impl()->set_needs_update_draw_properties(); 978 layer_tree_impl()->set_needs_update_draw_properties();
977 } else { 979 } else {
978 NoteLayerPropertyChanged(); 980 NoteLayerPropertyChanged();
979 } 981 }
980 } 982 }
981 983
982 void LayerImpl::SetMaskLayer(scoped_ptr<LayerImpl> mask_layer) { 984 void LayerImpl::SetMaskLayer(std::unique_ptr<LayerImpl> mask_layer) {
983 int new_layer_id = mask_layer ? mask_layer->id() : -1; 985 int new_layer_id = mask_layer ? mask_layer->id() : -1;
984 986
985 if (mask_layer) { 987 if (mask_layer) {
986 DCHECK_EQ(layer_tree_impl(), mask_layer->layer_tree_impl()); 988 DCHECK_EQ(layer_tree_impl(), mask_layer->layer_tree_impl());
987 DCHECK_NE(new_layer_id, mask_layer_id_); 989 DCHECK_NE(new_layer_id, mask_layer_id_);
988 } else if (new_layer_id == mask_layer_id_) { 990 } else if (new_layer_id == mask_layer_id_) {
989 return; 991 return;
990 } 992 }
991 993
992 if (mask_layer_) 994 if (mask_layer_)
993 layer_tree_impl_->RemoveLayer(mask_layer_->id()); 995 layer_tree_impl_->RemoveLayer(mask_layer_->id());
994 mask_layer_ = mask_layer.get(); 996 mask_layer_ = mask_layer.get();
995 if (mask_layer_) 997 if (mask_layer_)
996 layer_tree_impl_->AddLayer(std::move(mask_layer)); 998 layer_tree_impl_->AddLayer(std::move(mask_layer));
997 999
998 mask_layer_id_ = new_layer_id; 1000 mask_layer_id_ = new_layer_id;
999 } 1001 }
1000 1002
1001 scoped_ptr<LayerImpl> LayerImpl::TakeMaskLayer() { 1003 std::unique_ptr<LayerImpl> LayerImpl::TakeMaskLayer() {
1002 mask_layer_id_ = -1; 1004 mask_layer_id_ = -1;
1003 scoped_ptr<LayerImpl> ret; 1005 std::unique_ptr<LayerImpl> ret;
1004 if (mask_layer_) 1006 if (mask_layer_)
1005 ret = layer_tree_impl_->RemoveLayer(mask_layer_->id()); 1007 ret = layer_tree_impl_->RemoveLayer(mask_layer_->id());
1006 mask_layer_ = nullptr; 1008 mask_layer_ = nullptr;
1007 return ret; 1009 return ret;
1008 } 1010 }
1009 1011
1010 void LayerImpl::SetReplicaLayer(scoped_ptr<LayerImpl> replica_layer) { 1012 void LayerImpl::SetReplicaLayer(std::unique_ptr<LayerImpl> replica_layer) {
1011 int new_layer_id = replica_layer ? replica_layer->id() : -1; 1013 int new_layer_id = replica_layer ? replica_layer->id() : -1;
1012 1014
1013 if (replica_layer) { 1015 if (replica_layer) {
1014 DCHECK_EQ(layer_tree_impl(), replica_layer->layer_tree_impl()); 1016 DCHECK_EQ(layer_tree_impl(), replica_layer->layer_tree_impl());
1015 DCHECK_NE(new_layer_id, replica_layer_id_); 1017 DCHECK_NE(new_layer_id, replica_layer_id_);
1016 } else if (new_layer_id == replica_layer_id_) { 1018 } else if (new_layer_id == replica_layer_id_) {
1017 return; 1019 return;
1018 } 1020 }
1019 1021
1020 if (replica_layer_) 1022 if (replica_layer_)
1021 layer_tree_impl_->RemoveLayer(replica_layer_->id()); 1023 layer_tree_impl_->RemoveLayer(replica_layer_->id());
1022 replica_layer_ = replica_layer.get(); 1024 replica_layer_ = replica_layer.get();
1023 if (replica_layer_) 1025 if (replica_layer_)
1024 layer_tree_impl_->AddLayer(std::move(replica_layer)); 1026 layer_tree_impl_->AddLayer(std::move(replica_layer));
1025 1027
1026 replica_layer_id_ = new_layer_id; 1028 replica_layer_id_ = new_layer_id;
1027 } 1029 }
1028 1030
1029 scoped_ptr<LayerImpl> LayerImpl::TakeReplicaLayer() { 1031 std::unique_ptr<LayerImpl> LayerImpl::TakeReplicaLayer() {
1030 replica_layer_id_ = -1; 1032 replica_layer_id_ = -1;
1031 scoped_ptr<LayerImpl> ret; 1033 std::unique_ptr<LayerImpl> ret;
1032 if (replica_layer_) 1034 if (replica_layer_)
1033 ret = layer_tree_impl_->RemoveLayer(replica_layer_->id()); 1035 ret = layer_tree_impl_->RemoveLayer(replica_layer_->id());
1034 replica_layer_ = nullptr; 1036 replica_layer_ = nullptr;
1035 return ret; 1037 return ret;
1036 } 1038 }
1037 1039
1038 ScrollbarLayerImplBase* LayerImpl::ToScrollbarLayer() { 1040 ScrollbarLayerImplBase* LayerImpl::ToScrollbarLayer() {
1039 return nullptr; 1041 return nullptr;
1040 } 1042 }
1041 1043
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
1462 layer_tree_impl_->HasAnimationThatInflatesBounds(this)); 1464 layer_tree_impl_->HasAnimationThatInflatesBounds(this));
1463 1465
1464 gfx::BoxF box; 1466 gfx::BoxF box;
1465 if (LayerUtils::GetAnimationBounds(*this, &box)) 1467 if (LayerUtils::GetAnimationBounds(*this, &box))
1466 MathUtil::AddToTracedValue("animation_bounds", box, state); 1468 MathUtil::AddToTracedValue("animation_bounds", box, state);
1467 1469
1468 if (debug_info_) { 1470 if (debug_info_) {
1469 std::string str; 1471 std::string str;
1470 debug_info_->AppendAsTraceFormat(&str); 1472 debug_info_->AppendAsTraceFormat(&str);
1471 base::JSONReader json_reader; 1473 base::JSONReader json_reader;
1472 scoped_ptr<base::Value> debug_info_value(json_reader.ReadToValue(str)); 1474 std::unique_ptr<base::Value> debug_info_value(json_reader.ReadToValue(str));
1473 1475
1474 if (debug_info_value->IsType(base::Value::TYPE_DICTIONARY)) { 1476 if (debug_info_value->IsType(base::Value::TYPE_DICTIONARY)) {
1475 base::DictionaryValue* dictionary_value = nullptr; 1477 base::DictionaryValue* dictionary_value = nullptr;
1476 bool converted_to_dictionary = 1478 bool converted_to_dictionary =
1477 debug_info_value->GetAsDictionary(&dictionary_value); 1479 debug_info_value->GetAsDictionary(&dictionary_value);
1478 DCHECK(converted_to_dictionary); 1480 DCHECK(converted_to_dictionary);
1479 for (base::DictionaryValue::Iterator it(*dictionary_value); !it.IsAtEnd(); 1481 for (base::DictionaryValue::Iterator it(*dictionary_value); !it.IsAtEnd();
1480 it.Advance()) { 1482 it.Advance()) {
1481 state->SetValue(it.key().data(), it.value().CreateDeepCopy()); 1483 state->SetValue(it.key().data(), it.value().CreateDeepCopy());
1482 } 1484 }
(...skipping 28 matching lines...) Expand all
1511 int LayerImpl::NumDescendantsThatDrawContent() const { 1513 int LayerImpl::NumDescendantsThatDrawContent() const {
1512 return num_descendants_that_draw_content_; 1514 return num_descendants_that_draw_content_;
1513 } 1515 }
1514 1516
1515 void LayerImpl::SetHasRenderSurface(bool should_have_render_surface) { 1517 void LayerImpl::SetHasRenderSurface(bool should_have_render_surface) {
1516 if (!!render_surface() == should_have_render_surface) 1518 if (!!render_surface() == should_have_render_surface)
1517 return; 1519 return;
1518 1520
1519 SetNeedsPushProperties(); 1521 SetNeedsPushProperties();
1520 if (should_have_render_surface) { 1522 if (should_have_render_surface) {
1521 render_surface_ = make_scoped_ptr(new RenderSurfaceImpl(this)); 1523 render_surface_ = base::WrapUnique(new RenderSurfaceImpl(this));
1522 return; 1524 return;
1523 } 1525 }
1524 render_surface_.reset(); 1526 render_surface_.reset();
1525 } 1527 }
1526 1528
1527 gfx::Transform LayerImpl::DrawTransform() const { 1529 gfx::Transform LayerImpl::DrawTransform() const {
1528 // Only drawn layers have up-to-date draw properties. 1530 // Only drawn layers have up-to-date draw properties.
1529 if (!IsDrawnRenderSurfaceLayerListMember()) { 1531 if (!IsDrawnRenderSurfaceLayerListMember()) {
1530 if (layer_tree_impl()->property_trees()->non_root_surfaces_enabled) { 1532 if (layer_tree_impl()->property_trees()->non_root_surfaces_enabled) {
1531 return draw_property_utils::DrawTransform( 1533 return draw_property_utils::DrawTransform(
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1611 .layer_transforms_should_scale_layer_contents) { 1613 .layer_transforms_should_scale_layer_contents) {
1612 return default_scale; 1614 return default_scale;
1613 } 1615 }
1614 1616
1615 gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents( 1617 gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents(
1616 DrawTransform(), default_scale); 1618 DrawTransform(), default_scale);
1617 return std::max(transform_scales.x(), transform_scales.y()); 1619 return std::max(transform_scales.x(), transform_scales.y());
1618 } 1620 }
1619 1621
1620 } // namespace cc 1622 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/layer_impl.h ('k') | cc/layers/layer_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698