OLD | NEW |
---|---|
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "cc/animation/animation_registrar.h" | 9 #include "cc/animation/animation_registrar.h" |
10 #include "cc/animation/scrollbar_animation_controller.h" | 10 #include "cc/animation/scrollbar_animation_controller.h" |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 return 0; | 247 return 0; |
248 } | 248 } |
249 | 249 |
250 void LayerImpl::SetSentScrollDelta(gfx::Vector2d sent_scroll_delta) { | 250 void LayerImpl::SetSentScrollDelta(gfx::Vector2d sent_scroll_delta) { |
251 // Pending tree never has sent scroll deltas | 251 // Pending tree never has sent scroll deltas |
252 DCHECK(layer_tree_impl()->IsActiveTree()); | 252 DCHECK(layer_tree_impl()->IsActiveTree()); |
253 | 253 |
254 if (sent_scroll_delta_ == sent_scroll_delta) | 254 if (sent_scroll_delta_ == sent_scroll_delta) |
255 return; | 255 return; |
256 | 256 |
257 TRACE_EVENT2("impl-scroll", | |
258 "LayerImpl::SetSentScrollDelta", | |
259 "scrollX", sent_scroll_delta.x(), | |
danakj
2013/07/29 17:16:08
scroll_x?
| |
260 "scrollY", sent_scroll_delta.y()); | |
danakj
2013/07/29 17:16:08
scroll_y?
| |
261 | |
257 sent_scroll_delta_ = sent_scroll_delta; | 262 sent_scroll_delta_ = sent_scroll_delta; |
258 } | 263 } |
259 | 264 |
260 gfx::Vector2dF LayerImpl::ScrollBy(gfx::Vector2dF scroll) { | 265 gfx::Vector2dF LayerImpl::ScrollBy(gfx::Vector2dF scroll) { |
266 TRACE_EVENT2("impl-scroll", | |
267 "LayerImpl::ScrollBy", | |
268 "scrollX", scroll.x(), | |
danakj
2013/07/29 17:16:08
same.
consider making a base::Value containing th
enne (OOO)
2013/07/29 17:46:31
Even better, add a MathUtil::AsValue for gfx::Vect
| |
269 "scrollY", scroll.y()); | |
261 gfx::Vector2dF min_delta = -scroll_offset_; | 270 gfx::Vector2dF min_delta = -scroll_offset_; |
262 gfx::Vector2dF max_delta = max_scroll_offset_ - scroll_offset_; | 271 gfx::Vector2dF max_delta = max_scroll_offset_ - scroll_offset_; |
263 // Clamp new_delta so that position + delta stays within scroll bounds. | 272 // Clamp new_delta so that position + delta stays within scroll bounds. |
264 gfx::Vector2dF new_delta = (ScrollDelta() + scroll); | 273 gfx::Vector2dF new_delta = (ScrollDelta() + scroll); |
265 new_delta.SetToMax(min_delta); | 274 new_delta.SetToMax(min_delta); |
266 new_delta.SetToMin(max_delta); | 275 new_delta.SetToMin(max_delta); |
267 gfx::Vector2dF unscrolled = ScrollDelta() + scroll - new_delta; | 276 gfx::Vector2dF unscrolled = ScrollDelta() + scroll - new_delta; |
268 | 277 |
269 SetScrollDelta(new_delta); | 278 SetScrollDelta(new_delta); |
270 return unscrolled; | 279 return unscrolled; |
271 } | 280 } |
272 | 281 |
273 InputHandler::ScrollStatus LayerImpl::TryScroll( | 282 InputHandler::ScrollStatus LayerImpl::TryScroll( |
274 gfx::PointF screen_space_point, | 283 gfx::PointF screen_space_point, |
275 InputHandler::ScrollInputType type) const { | 284 InputHandler::ScrollInputType type) const { |
276 if (should_scroll_on_main_thread()) { | 285 if (should_scroll_on_main_thread()) { |
277 TRACE_EVENT0("cc", "LayerImpl::TryScroll: Failed ShouldScrollOnMainThread"); | 286 TRACE_EVENT_INSTANT0("cc,impl-scroll", |
danakj
2013/07/29 17:16:08
Should we drop these from the "cc" category then?
| |
287 "LayerImpl::TryScroll: Failed ShouldScrollOnMainThread", | |
288 TRACE_EVENT_SCOPE_THREAD); | |
278 return InputHandler::ScrollOnMainThread; | 289 return InputHandler::ScrollOnMainThread; |
279 } | 290 } |
280 | 291 |
281 if (!screen_space_transform().IsInvertible()) { | 292 if (!screen_space_transform().IsInvertible()) { |
282 TRACE_EVENT0("cc", "LayerImpl::TryScroll: Ignored NonInvertibleTransform"); | 293 TRACE_EVENT_INSTANT0("cc,impl-scroll", |
danakj
2013/07/29 17:16:08
i think "impl" as a name is something to avoid and
enne (OOO)
2013/07/29 17:46:31
Do you think there'll ever be a blink scrolling tr
| |
294 "LayerImpl::TryScroll: Ignored NonInvertibleTransform", | |
295 TRACE_EVENT_SCOPE_THREAD); | |
283 return InputHandler::ScrollIgnored; | 296 return InputHandler::ScrollIgnored; |
284 } | 297 } |
285 | 298 |
286 if (!non_fast_scrollable_region().IsEmpty()) { | 299 if (!non_fast_scrollable_region().IsEmpty()) { |
287 bool clipped = false; | 300 bool clipped = false; |
288 gfx::Transform inverse_screen_space_transform( | 301 gfx::Transform inverse_screen_space_transform( |
289 gfx::Transform::kSkipInitialization); | 302 gfx::Transform::kSkipInitialization); |
290 if (!screen_space_transform().GetInverse(&inverse_screen_space_transform)) { | 303 if (!screen_space_transform().GetInverse(&inverse_screen_space_transform)) { |
291 // TODO(shawnsingh): We shouldn't be applying a projection if screen space | 304 // TODO(shawnsingh): We shouldn't be applying a projection if screen space |
292 // transform is uninvertible here. Perhaps we should be returning | 305 // transform is uninvertible here. Perhaps we should be returning |
293 // ScrollOnMainThread in this case? | 306 // ScrollOnMainThread in this case? |
294 } | 307 } |
295 | 308 |
296 gfx::PointF hit_test_point_in_content_space = | 309 gfx::PointF hit_test_point_in_content_space = |
297 MathUtil::ProjectPoint(inverse_screen_space_transform, | 310 MathUtil::ProjectPoint(inverse_screen_space_transform, |
298 screen_space_point, | 311 screen_space_point, |
299 &clipped); | 312 &clipped); |
300 gfx::PointF hit_test_point_in_layer_space = | 313 gfx::PointF hit_test_point_in_layer_space = |
301 gfx::ScalePoint(hit_test_point_in_content_space, | 314 gfx::ScalePoint(hit_test_point_in_content_space, |
302 1.f / contents_scale_x(), | 315 1.f / contents_scale_x(), |
303 1.f / contents_scale_y()); | 316 1.f / contents_scale_y()); |
304 if (!clipped && | 317 if (!clipped && |
305 non_fast_scrollable_region().Contains( | 318 non_fast_scrollable_region().Contains( |
306 gfx::ToRoundedPoint(hit_test_point_in_layer_space))) { | 319 gfx::ToRoundedPoint(hit_test_point_in_layer_space))) { |
307 TRACE_EVENT0("cc", | 320 TRACE_EVENT_INSTANT0("cc,impl-scroll", |
308 "LayerImpl::tryScroll: Failed NonFastScrollableRegion"); | 321 "LayerImpl::TryScroll: Failed NonFastScrollableRegion", |
322 TRACE_EVENT_SCOPE_THREAD); | |
309 return InputHandler::ScrollOnMainThread; | 323 return InputHandler::ScrollOnMainThread; |
310 } | 324 } |
311 } | 325 } |
312 | 326 |
313 if (type == InputHandler::Wheel && have_wheel_event_handlers()) { | 327 if (type == InputHandler::Wheel && have_wheel_event_handlers()) { |
314 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Failed WheelEventHandlers"); | 328 TRACE_EVENT_INSTANT0("cc,impl-scroll", |
329 "LayerImpl::TryScroll: Failed WheelEventHandlers", | |
330 TRACE_EVENT_SCOPE_THREAD); | |
315 return InputHandler::ScrollOnMainThread; | 331 return InputHandler::ScrollOnMainThread; |
316 } | 332 } |
317 | 333 |
318 if (!scrollable()) { | 334 if (!scrollable()) { |
319 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Ignored not scrollable"); | 335 TRACE_EVENT_INSTANT0("cc,impl-scroll", |
336 "LayerImpl::TryScroll: Ignored not scrollable", | |
337 TRACE_EVENT_SCOPE_THREAD); | |
320 return InputHandler::ScrollIgnored; | 338 return InputHandler::ScrollIgnored; |
321 } | 339 } |
322 | 340 |
323 if (max_scroll_offset_.x() <= 0 && max_scroll_offset_.y() <= 0) { | 341 if (max_scroll_offset_.x() <= 0 && max_scroll_offset_.y() <= 0) { |
324 TRACE_EVENT0("cc", | 342 TRACE_EVENT_INSTANT0("cc,impl-scroll", |
325 "LayerImpl::tryScroll: Ignored. Technically scrollable," | 343 "LayerImpl::TryScroll: Ignored. Technically scrollable," |
326 " but has no affordance in either direction."); | 344 " but has no affordance in either direction.", |
345 TRACE_EVENT_SCOPE_THREAD); | |
327 return InputHandler::ScrollIgnored; | 346 return InputHandler::ScrollIgnored; |
328 } | 347 } |
329 | 348 |
349 TRACE_EVENT_INSTANT1("cc,impl-scroll", | |
350 "LayerImpl::TryScroll: Started", | |
351 TRACE_EVENT_SCOPE_THREAD, | |
352 "layerId", id()); | |
danakj
2013/07/29 17:16:08
layer_id?
| |
353 | |
330 return InputHandler::ScrollStarted; | 354 return InputHandler::ScrollStarted; |
331 } | 355 } |
332 | 356 |
333 bool LayerImpl::DrawCheckerboardForMissingTiles() const { | 357 bool LayerImpl::DrawCheckerboardForMissingTiles() const { |
334 return draw_checkerboard_for_missing_tiles_ && | 358 return draw_checkerboard_for_missing_tiles_ && |
335 !layer_tree_impl()->settings().background_color_instead_of_checkerboard; | 359 !layer_tree_impl()->settings().background_color_instead_of_checkerboard; |
336 } | 360 } |
337 | 361 |
338 gfx::Rect LayerImpl::LayerRectToContentRect( | 362 gfx::Rect LayerImpl::LayerRectToContentRect( |
339 const gfx::RectF& layer_rect) const { | 363 const gfx::RectF& layer_rect) const { |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
867 gfx::Vector2dF LayerImpl::ScrollDelta() const { | 891 gfx::Vector2dF LayerImpl::ScrollDelta() const { |
868 if (scroll_offset_delegate_) | 892 if (scroll_offset_delegate_) |
869 return scroll_offset_delegate_->GetTotalScrollOffset() - scroll_offset_; | 893 return scroll_offset_delegate_->GetTotalScrollOffset() - scroll_offset_; |
870 return scroll_delta_; | 894 return scroll_delta_; |
871 } | 895 } |
872 | 896 |
873 void LayerImpl::SetScrollDelta(gfx::Vector2dF scroll_delta) { | 897 void LayerImpl::SetScrollDelta(gfx::Vector2dF scroll_delta) { |
874 if (ScrollDelta() == scroll_delta) | 898 if (ScrollDelta() == scroll_delta) |
875 return; | 899 return; |
876 | 900 |
901 TRACE_EVENT2("impl-scroll", | |
902 "LayerImpl::SetScrollDelta", | |
903 "scroll_delta.x", scroll_delta.x(), | |
904 "scroll_delta.y", scroll_delta.y()); | |
905 | |
877 if (layer_tree_impl()->IsActiveTree()) { | 906 if (layer_tree_impl()->IsActiveTree()) { |
878 LayerImpl* pending_twin = layer_tree_impl()->FindPendingTreeLayerById(id()); | 907 LayerImpl* pending_twin = layer_tree_impl()->FindPendingTreeLayerById(id()); |
879 if (pending_twin) { | 908 if (pending_twin) { |
880 // The pending twin can't mirror the scroll delta of the active | 909 // The pending twin can't mirror the scroll delta of the active |
881 // layer. Although the delta - sent scroll delta difference is | 910 // layer. Although the delta - sent scroll delta difference is |
882 // identical for both twins, the sent scroll delta for the pending | 911 // identical for both twins, the sent scroll delta for the pending |
883 // layer is zero, as anything that has been sent has been baked | 912 // layer is zero, as anything that has been sent has been baked |
884 // into the layer's position/scroll offset as a part of commit. | 913 // into the layer's position/scroll offset as a part of commit. |
885 DCHECK(pending_twin->sent_scroll_delta().IsZero()); | 914 DCHECK(pending_twin->sent_scroll_delta().IsZero()); |
886 pending_twin->SetScrollDelta(scroll_delta - sent_scroll_delta()); | 915 pending_twin->SetScrollDelta(scroll_delta - sent_scroll_delta()); |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1099 state->Set("compositing_reasons", | 1128 state->Set("compositing_reasons", |
1100 CompositingReasonsAsValue(compositing_reasons_).release()); | 1129 CompositingReasonsAsValue(compositing_reasons_).release()); |
1101 | 1130 |
1102 bool clipped; | 1131 bool clipped; |
1103 gfx::QuadF layer_quad = MathUtil::MapQuad( | 1132 gfx::QuadF layer_quad = MathUtil::MapQuad( |
1104 screen_space_transform(), | 1133 screen_space_transform(), |
1105 gfx::QuadF(gfx::Rect(content_bounds())), | 1134 gfx::QuadF(gfx::Rect(content_bounds())), |
1106 &clipped); | 1135 &clipped); |
1107 state->Set("layer_quad", MathUtil::AsValue(layer_quad).release()); | 1136 state->Set("layer_quad", MathUtil::AsValue(layer_quad).release()); |
1108 | 1137 |
1138 #ifndef NDEBUG | |
danakj
2013/07/29 17:16:08
Why only in not NDEBUG?
enne (OOO)
2013/07/29 17:46:31
Layers only get their names set in debug builds.
| |
1139 state->SetString("debug_name", debug_name_); | |
1140 #endif | |
1109 | 1141 |
1110 scoped_ptr<base::ListValue> children_list(new base::ListValue()); | 1142 scoped_ptr<base::ListValue> children_list(new base::ListValue()); |
1111 for (size_t i = 0; i < children_.size(); ++i) | 1143 for (size_t i = 0; i < children_.size(); ++i) |
1112 children_list->Append(children_[i]->AsValue().release()); | 1144 children_list->Append(children_[i]->AsValue().release()); |
1113 state->Set("children", children_list.release()); | 1145 state->Set("children", children_list.release()); |
1114 if (mask_layer_) | 1146 if (mask_layer_) |
1115 state->Set("mask_layer", mask_layer_->AsValue().release()); | 1147 state->Set("mask_layer", mask_layer_->AsValue().release()); |
1116 if (replica_layer_) | 1148 if (replica_layer_) |
1117 state->Set("replica_layer", replica_layer_->AsValue().release()); | 1149 state->Set("replica_layer", replica_layer_->AsValue().release()); |
1118 } | 1150 } |
1119 | 1151 |
1120 size_t LayerImpl::GPUMemoryUsageInBytes() const { return 0; } | 1152 size_t LayerImpl::GPUMemoryUsageInBytes() const { return 0; } |
1121 | 1153 |
1122 scoped_ptr<base::Value> LayerImpl::AsValue() const { | 1154 scoped_ptr<base::Value> LayerImpl::AsValue() const { |
1123 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | 1155 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
1124 AsValueInto(state.get()); | 1156 AsValueInto(state.get()); |
1125 return state.PassAs<base::Value>(); | 1157 return state.PassAs<base::Value>(); |
1126 } | 1158 } |
1127 | 1159 |
1128 } // namespace cc | 1160 } // namespace cc |
OLD | NEW |