blob: 13e788e579d69b3aa5aeddb94024046e65e50491 [file] [log] [blame]
[email protected]5e5648a2013-11-18 00:39:331// Copyright 2012 The Chromium Authors. All rights reserved.
[email protected]94f206c12012-08-25 00:09:142// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]cc3cfaa2013-03-18 09:05:525#include "cc/layers/layer_impl.h"
[email protected]94f206c12012-08-25 00:09:146
[email protected]9f3be432013-12-03 03:53:227#include "base/json/json_reader.h"
[email protected]8e61d4b2013-06-10 22:11:488#include "base/strings/stringprintf.h"
primianoc06e2382015-01-28 04:21:499#include "base/trace_event/trace_event.h"
10#include "base/trace_event/trace_event_argument.h"
[email protected]95e4e1a02013-03-18 07:09:0911#include "cc/animation/animation_registrar.h"
12#include "cc/animation/scrollbar_animation_controller.h"
[email protected]681ccff2013-03-18 06:13:5213#include "cc/base/math_util.h"
[email protected]d5467eb72014-08-22 01:16:4314#include "cc/base/simple_enclosed_region.h"
[email protected]6e84de22013-03-18 06:54:2715#include "cc/debug/debug_colors.h"
16#include "cc/debug/layer_tree_debug_state.h"
[email protected]5e5648a2013-11-18 00:39:3317#include "cc/debug/micro_benchmark_impl.h"
[email protected]f6742f52013-05-08 23:52:2218#include "cc/debug/traced_value.h"
[email protected]3d86dd7a2014-01-24 01:33:1119#include "cc/layers/layer_utils.h"
[email protected]3a83478b2013-08-22 20:55:1720#include "cc/layers/painted_scrollbar_layer_impl.h"
[email protected]0e5f7142013-05-24 06:45:3621#include "cc/output/copy_output_request.h"
[email protected]89e82672013-03-18 07:50:5622#include "cc/quads/debug_border_draw_quad.h"
[email protected]0cd7d6f72014-08-22 14:50:5123#include "cc/quads/render_pass.h"
[email protected]3d86dd7a2014-01-24 01:33:1124#include "cc/trees/layer_tree_host_common.h"
[email protected]556fd292013-03-18 08:03:0425#include "cc/trees/layer_tree_impl.h"
26#include "cc/trees/layer_tree_settings.h"
27#include "cc/trees/proxy.h"
heejin.r.chungd28506ba2014-10-23 16:36:2028#include "ui/gfx/geometry/box_f.h"
29#include "ui/gfx/geometry/point_conversions.h"
30#include "ui/gfx/geometry/quad_f.h"
31#include "ui/gfx/geometry/rect_conversions.h"
32#include "ui/gfx/geometry/size_conversions.h"
[email protected]adeda572014-01-31 00:49:4733#include "ui/gfx/geometry/vector2d_conversions.h"
[email protected]94f206c12012-08-25 00:09:1434
[email protected]9c88e562012-09-14 22:21:3035namespace cc {
aeliasd0070ba2015-01-31 13:44:4936LayerImpl::LayerImpl(LayerTreeImpl* layer_impl, int id)
37 : LayerImpl(layer_impl, id, new LayerImpl::SyncedScrollOffset) {
38}
39
40LayerImpl::LayerImpl(LayerTreeImpl* tree_impl,
41 int id,
42 scoped_refptr<SyncedScrollOffset> scroll_offset)
kulkarni.a4015690f12014-10-10 13:50:0643 : parent_(nullptr),
44 scroll_parent_(nullptr),
45 clip_parent_(nullptr),
[email protected]7aba6662013-03-12 10:17:3446 mask_layer_id_(-1),
47 replica_layer_id_(-1),
48 layer_id_(id),
49 layer_tree_impl_(tree_impl),
aeliasd0070ba2015-01-31 13:44:4950 scroll_offset_(scroll_offset),
kulkarni.a4015690f12014-10-10 13:50:0651 scroll_clip_layer_(nullptr),
[email protected]7aba6662013-03-12 10:17:3452 should_scroll_on_main_thread_(false),
53 have_wheel_event_handlers_(false),
[email protected]f998c532014-03-31 20:02:5154 have_scroll_event_handlers_(false),
ericrk7c030992015-02-20 01:39:3855 scroll_blocks_on_(SCROLL_BLOCKS_ON_NONE),
[email protected]59a7d552013-10-22 03:36:4356 user_scrollable_horizontal_(true),
57 user_scrollable_vertical_(true),
[email protected]7aba6662013-03-12 10:17:3458 stacking_order_changed_(false),
59 double_sided_(true),
[email protected]56fffdd2014-02-11 19:50:5760 should_flatten_transform_(true),
ennee95b1542015-04-20 20:35:5061 should_flatten_transform_from_property_tree_(false),
[email protected]7aba6662013-03-12 10:17:3462 layer_property_changed_(false),
[email protected]7aba6662013-03-12 10:17:3463 masks_to_bounds_(false),
64 contents_opaque_(false),
[email protected]7bbeaf4e2013-11-26 10:27:2265 is_root_for_isolated_group_(false),
[email protected]7aba6662013-03-12 10:17:3466 use_parent_backface_visibility_(false),
67 draw_checkerboard_for_missing_tiles_(false),
68 draws_content_(false),
[email protected]c0ae06c12013-06-24 18:32:1969 hide_layer_and_subtree_(false),
[email protected]08bdf1b2014-04-16 23:23:2970 transform_is_invertible_(true),
[email protected]7aba6662013-03-12 10:17:3471 is_container_for_fixed_position_layers_(false),
[email protected]c55f3fc2013-12-10 05:48:4872 background_color_(0),
73 opacity_(1.0),
74 blend_mode_(SkXfermode::kSrcOver_Mode),
[email protected]ad63b2f2014-08-11 17:39:5475 num_descendants_that_draw_content_(0),
ennee95b1542015-04-20 20:35:5076 transform_tree_index_(-1),
77 opacity_tree_index_(-1),
78 clip_tree_index_(-1),
[email protected]7aba6662013-03-12 10:17:3479 draw_depth_(0.f),
[email protected]ad0250b2014-01-18 03:24:3480 needs_push_properties_(false),
81 num_dependents_need_push_properties_(0),
[email protected]a9d4d4f2014-06-19 06:49:2882 sorting_context_id_(0),
vmpstr3d1d72c2015-01-26 18:27:4083 current_draw_mode_(DRAW_MODE_NONE),
84 frame_timing_requests_dirty_(false) {
[email protected]bf691c22013-03-26 21:15:0685 DCHECK_GT(layer_id_, 0);
[email protected]7aba6662013-03-12 10:17:3486 DCHECK(layer_tree_impl_);
87 layer_tree_impl_->RegisterLayer(this);
sunnypsea328be12015-02-26 06:03:2788 AnimationRegistrar* registrar = layer_tree_impl_->GetAnimationRegistrar();
[email protected]7aba6662013-03-12 10:17:3489 layer_animation_controller_ =
90 registrar->GetAnimationControllerForId(layer_id_);
[email protected]7f5605c2013-04-08 18:08:3591 layer_animation_controller_->AddValueObserver(this);
[email protected]749cbc62014-07-10 01:06:3592 if (IsActive()) {
[email protected]b8384e22013-12-03 02:20:4893 layer_animation_controller_->set_value_provider(this);
[email protected]749cbc62014-07-10 01:06:3594 layer_animation_controller_->set_layer_animation_delegate(this);
95 }
[email protected]ad0250b2014-01-18 03:24:3496 SetNeedsPushProperties();
[email protected]94f206c12012-08-25 00:09:1497}
98
[email protected]7aba6662013-03-12 10:17:3499LayerImpl::~LayerImpl() {
[email protected]ffbb2212013-06-02 23:47:59100 DCHECK_EQ(DRAW_MODE_NONE, current_draw_mode_);
[email protected]18a70192013-04-26 16:18:25101
[email protected]7f5605c2013-04-08 18:08:35102 layer_animation_controller_->RemoveValueObserver(this);
[email protected]b8384e22013-12-03 02:20:48103 layer_animation_controller_->remove_value_provider(this);
[email protected]749cbc62014-07-10 01:06:35104 layer_animation_controller_->remove_layer_animation_delegate(this);
[email protected]b8384e22013-12-03 02:20:48105
[email protected]19334ac2013-12-12 23:59:11106 if (!copy_requests_.empty() && layer_tree_impl_->IsActiveTree())
107 layer_tree_impl()->RemoveLayerWithCopyOutputRequest(this);
[email protected]b8384e22013-12-03 02:20:48108 layer_tree_impl_->UnregisterLayer(this);
[email protected]0e98cdd2013-08-23 00:44:30109
[email protected]f5ad4282014-02-15 14:23:16110 TRACE_EVENT_OBJECT_DELETED_WITH_ID(
[email protected]b4dc36472014-02-26 02:48:25111 TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerImpl", this);
[email protected]94f206c12012-08-25 00:09:14112}
113
[email protected]7aba6662013-03-12 10:17:34114void LayerImpl::AddChild(scoped_ptr<LayerImpl> child) {
[email protected]ad0250b2014-01-18 03:24:34115 child->SetParent(this);
[email protected]7aba6662013-03-12 10:17:34116 DCHECK_EQ(layer_tree_impl(), child->layer_tree_impl());
117 children_.push_back(child.Pass());
118 layer_tree_impl()->set_needs_update_draw_properties();
[email protected]94f206c12012-08-25 00:09:14119}
120
[email protected]7aba6662013-03-12 10:17:34121scoped_ptr<LayerImpl> LayerImpl::RemoveChild(LayerImpl* child) {
[email protected]50761e92013-03-29 20:51:28122 for (OwnedLayerImplList::iterator it = children_.begin();
[email protected]7aba6662013-03-12 10:17:34123 it != children_.end();
124 ++it) {
125 if (*it == child) {
126 scoped_ptr<LayerImpl> ret = children_.take(it);
127 children_.erase(it);
128 layer_tree_impl()->set_needs_update_draw_properties();
129 return ret.Pass();
[email protected]94f206c12012-08-25 00:09:14130 }
[email protected]7aba6662013-03-12 10:17:34131 }
danakjf446a072014-09-27 21:55:48132 return nullptr;
[email protected]94f206c12012-08-25 00:09:14133}
134
[email protected]ad0250b2014-01-18 03:24:34135void LayerImpl::SetParent(LayerImpl* parent) {
136 if (parent_should_know_need_push_properties()) {
137 if (parent_)
138 parent_->RemoveDependentNeedsPushProperties();
139 if (parent)
140 parent->AddDependentNeedsPushProperties();
141 }
142 parent_ = parent;
143}
144
[email protected]7aba6662013-03-12 10:17:34145void LayerImpl::ClearChildList() {
146 if (children_.empty())
147 return;
[email protected]0ede3bb2012-12-09 09:14:39148
[email protected]7aba6662013-03-12 10:17:34149 children_.clear();
150 layer_tree_impl()->set_needs_update_draw_properties();
[email protected]94f206c12012-08-25 00:09:14151}
152
[email protected]0e98cdd2013-08-23 00:44:30153bool LayerImpl::HasAncestor(const LayerImpl* ancestor) const {
154 if (!ancestor)
155 return false;
156
157 for (const LayerImpl* layer = this; layer; layer = layer->parent()) {
158 if (layer == ancestor)
159 return true;
160 }
161
162 return false;
163}
164
165void LayerImpl::SetScrollParent(LayerImpl* parent) {
166 if (scroll_parent_ == parent)
167 return;
168
[email protected]d097e242014-02-28 21:51:11169 if (parent)
170 DCHECK_EQ(layer_tree_impl()->LayerById(parent->id()), parent);
[email protected]0e98cdd2013-08-23 00:44:30171
172 scroll_parent_ = parent;
[email protected]ad0250b2014-01-18 03:24:34173 SetNeedsPushProperties();
[email protected]0e98cdd2013-08-23 00:44:30174}
175
[email protected]9f3be432013-12-03 03:53:22176void LayerImpl::SetDebugInfo(
ssid911e40e2015-02-09 17:55:20177 scoped_refptr<base::trace_event::ConvertableToTraceFormat> other) {
[email protected]9f3be432013-12-03 03:53:22178 debug_info_ = other;
[email protected]ad0250b2014-01-18 03:24:34179 SetNeedsPushProperties();
[email protected]9f3be432013-12-03 03:53:22180}
181
[email protected]0e98cdd2013-08-23 00:44:30182void LayerImpl::SetScrollChildren(std::set<LayerImpl*>* children) {
183 if (scroll_children_.get() == children)
184 return;
185 scroll_children_.reset(children);
[email protected]ad0250b2014-01-18 03:24:34186 SetNeedsPushProperties();
[email protected]0e98cdd2013-08-23 00:44:30187}
188
[email protected]ad63b2f2014-08-11 17:39:54189void LayerImpl::SetNumDescendantsThatDrawContent(int num_descendants) {
190 if (num_descendants_that_draw_content_ == num_descendants)
191 return;
192 num_descendants_that_draw_content_ = num_descendants;
193 SetNeedsPushProperties();
194}
195
[email protected]0e98cdd2013-08-23 00:44:30196void LayerImpl::SetClipParent(LayerImpl* ancestor) {
197 if (clip_parent_ == ancestor)
198 return;
199
[email protected]0e98cdd2013-08-23 00:44:30200 clip_parent_ = ancestor;
[email protected]ad0250b2014-01-18 03:24:34201 SetNeedsPushProperties();
[email protected]0e98cdd2013-08-23 00:44:30202}
203
204void LayerImpl::SetClipChildren(std::set<LayerImpl*>* children) {
205 if (clip_children_.get() == children)
206 return;
207 clip_children_.reset(children);
[email protected]ad0250b2014-01-18 03:24:34208 SetNeedsPushProperties();
[email protected]0e98cdd2013-08-23 00:44:30209}
210
[email protected]0e5f7142013-05-24 06:45:36211void LayerImpl::PassCopyRequests(ScopedPtrVector<CopyOutputRequest>* requests) {
212 if (requests->empty())
[email protected]18a70192013-04-26 16:18:25213 return;
awoloszyne83f28c2014-12-22 15:40:00214 DCHECK(render_surface());
[email protected]f5de9e5b2013-07-30 22:26:57215 bool was_empty = copy_requests_.empty();
weiliangcc1878c62014-09-02 22:43:17216 copy_requests_.insert_and_take(copy_requests_.end(), requests);
[email protected]0e5f7142013-05-24 06:45:36217 requests->clear();
[email protected]18a70192013-04-26 16:18:25218
[email protected]f5de9e5b2013-07-30 22:26:57219 if (was_empty && layer_tree_impl()->IsActiveTree())
[email protected]30fe19ff2013-07-04 00:54:45220 layer_tree_impl()->AddLayerWithCopyOutputRequest(this);
[email protected]18a70192013-04-26 16:18:25221 NoteLayerPropertyChangedForSubtree();
222}
223
[email protected]d4d017e2013-06-20 21:46:11224void LayerImpl::TakeCopyRequestsAndTransformToTarget(
225 ScopedPtrVector<CopyOutputRequest>* requests) {
[email protected]df17af52014-02-06 02:20:40226 DCHECK(!copy_requests_.empty());
227 DCHECK(layer_tree_impl()->IsActiveTree());
awoloszyne83f28c2014-12-22 15:40:00228 DCHECK_EQ(render_target(), this);
[email protected]18a70192013-04-26 16:18:25229
[email protected]30fe19ff2013-07-04 00:54:45230 size_t first_inserted_request = requests->size();
weiliangcc1878c62014-09-02 22:43:17231 requests->insert_and_take(requests->end(), &copy_requests_);
[email protected]0e5f7142013-05-24 06:45:36232 copy_requests_.clear();
[email protected]d4d017e2013-06-20 21:46:11233
[email protected]30fe19ff2013-07-04 00:54:45234 for (size_t i = first_inserted_request; i < requests->size(); ++i) {
[email protected]d4d017e2013-06-20 21:46:11235 CopyOutputRequest* request = requests->at(i);
236 if (!request->has_area())
237 continue;
238
239 gfx::Rect request_in_layer_space = request->area();
240 gfx::Rect request_in_content_space =
241 LayerRectToContentRect(request_in_layer_space);
[email protected]8a822692014-02-12 17:30:55242 request->set_area(MathUtil::MapEnclosingClippedRect(
243 draw_properties_.target_space_transform, request_in_content_space));
[email protected]d4d017e2013-06-20 21:46:11244 }
[email protected]30fe19ff2013-07-04 00:54:45245
[email protected]df17af52014-02-06 02:20:40246 layer_tree_impl()->RemoveLayerWithCopyOutputRequest(this);
danakj0cf95392015-01-29 17:56:54247 layer_tree_impl()->set_needs_update_draw_properties();
[email protected]18a70192013-04-26 16:18:25248}
249
[email protected]7644fa22014-04-28 12:20:33250void LayerImpl::ClearRenderSurfaceLayerList() {
awoloszyne83f28c2014-12-22 15:40:00251 if (render_surface_)
252 render_surface_->ClearLayerLists();
[email protected]7644fa22014-04-28 12:20:33253}
254
[email protected]9be1adc2014-05-07 15:39:41255void LayerImpl::PopulateSharedQuadState(SharedQuadState* state) const {
rosca948d29d2014-11-09 10:25:13256 state->SetAll(
257 draw_properties_.target_space_transform, draw_properties_.content_bounds,
258 draw_properties_.visible_content_rect, draw_properties_.clip_rect,
259 draw_properties_.is_clipped, draw_properties_.opacity,
260 draw_properties_.blend_mode, sorting_context_id_);
[email protected]94f206c12012-08-25 00:09:14261}
262
enne467829b2015-02-13 02:39:34263void LayerImpl::PopulateScaledSharedQuadState(SharedQuadState* state,
264 float scale) const {
265 gfx::Transform scaled_draw_transform =
266 draw_properties_.target_space_transform;
267 scaled_draw_transform.Scale(SK_MScalar1 / scale, SK_MScalar1 / scale);
268 gfx::Size scaled_content_bounds =
269 gfx::ToCeiledSize(gfx::ScaleSize(bounds(), scale));
270 gfx::Rect scaled_visible_content_rect =
271 gfx::ScaleToEnclosingRect(visible_content_rect(), scale);
272 scaled_visible_content_rect.Intersect(gfx::Rect(scaled_content_bounds));
273
274 state->SetAll(scaled_draw_transform, scaled_content_bounds,
275 scaled_visible_content_rect, draw_properties().clip_rect,
276 draw_properties().is_clipped, draw_properties().opacity,
277 draw_properties().blend_mode, sorting_context_id_);
278}
279
[email protected]ffbb2212013-06-02 23:47:59280bool LayerImpl::WillDraw(DrawMode draw_mode,
281 ResourceProvider* resource_provider) {
[email protected]ed511b8d2013-03-25 03:29:29282 // WillDraw/DidDraw must be matched.
[email protected]ffbb2212013-06-02 23:47:59283 DCHECK_NE(DRAW_MODE_NONE, draw_mode);
284 DCHECK_EQ(DRAW_MODE_NONE, current_draw_mode_);
285 current_draw_mode_ = draw_mode;
286 return true;
[email protected]94f206c12012-08-25 00:09:14287}
288
[email protected]7aba6662013-03-12 10:17:34289void LayerImpl::DidDraw(ResourceProvider* resource_provider) {
[email protected]ffbb2212013-06-02 23:47:59290 DCHECK_NE(DRAW_MODE_NONE, current_draw_mode_);
291 current_draw_mode_ = DRAW_MODE_NONE;
[email protected]94f206c12012-08-25 00:09:14292}
293
[email protected]7aba6662013-03-12 10:17:34294bool LayerImpl::ShowDebugBorders() const {
[email protected]846f455b2013-03-18 19:07:41295 return layer_tree_impl()->debug_state().show_debug_borders;
[email protected]3dce37232012-11-15 01:47:44296}
297
[email protected]7aba6662013-03-12 10:17:34298void LayerImpl::GetDebugBorderProperties(SkColor* color, float* width) const {
299 if (draws_content_) {
300 *color = DebugColors::ContentLayerBorderColor();
301 *width = DebugColors::ContentLayerBorderWidth(layer_tree_impl());
302 return;
303 }
304
305 if (masks_to_bounds_) {
306 *color = DebugColors::MaskingLayerBorderColor();
307 *width = DebugColors::MaskingLayerBorderWidth(layer_tree_impl());
308 return;
309 }
310
311 *color = DebugColors::ContainerLayerBorderColor();
312 *width = DebugColors::ContainerLayerBorderWidth(layer_tree_impl());
313}
314
315void LayerImpl::AppendDebugBorderQuad(
[email protected]c6707fd2014-06-23 05:50:36316 RenderPass* render_pass,
[email protected]b48a0b12014-06-20 20:20:32317 const gfx::Size& content_bounds,
[email protected]7aba6662013-03-12 10:17:34318 const SharedQuadState* shared_quad_state,
319 AppendQuadsData* append_quads_data) const {
[email protected]7aba6662013-03-12 10:17:34320 SkColor color;
321 float width;
322 GetDebugBorderProperties(&color, &width);
[email protected]c6707fd2014-06-23 05:50:36323 AppendDebugBorderQuad(render_pass,
[email protected]b48a0b12014-06-20 20:20:32324 content_bounds,
325 shared_quad_state,
326 append_quads_data,
327 color,
328 width);
[email protected]bec084292013-05-21 21:31:44329}
330
[email protected]c6707fd2014-06-23 05:50:36331void LayerImpl::AppendDebugBorderQuad(RenderPass* render_pass,
[email protected]b48a0b12014-06-20 20:20:32332 const gfx::Size& content_bounds,
[email protected]bec084292013-05-21 21:31:44333 const SharedQuadState* shared_quad_state,
334 AppendQuadsData* append_quads_data,
335 SkColor color,
336 float width) const {
337 if (!ShowDebugBorders())
338 return;
[email protected]7aba6662013-03-12 10:17:34339
[email protected]b48a0b12014-06-20 20:20:32340 gfx::Rect quad_rect(content_bounds);
[email protected]9bf06c72014-03-07 18:16:24341 gfx::Rect visible_quad_rect(quad_rect);
[email protected]f7030c32014-07-03 18:54:34342 DebugBorderDrawQuad* debug_border_quad =
343 render_pass->CreateAndAppendDrawQuad<DebugBorderDrawQuad>();
[email protected]9bf06c72014-03-07 18:16:24344 debug_border_quad->SetNew(
345 shared_quad_state, quad_rect, visible_quad_rect, color, width);
danakj069ac122015-02-12 00:59:22346 if (contents_opaque()) {
347 // When opaque, draw a second inner border that is thicker than the outer
348 // border, but more transparent.
349 static const float kFillOpacity = 0.3f;
350 SkColor fill_color = SkColorSetA(
351 color, static_cast<uint8_t>(SkColorGetA(color) * kFillOpacity));
352 float fill_width = width * 3;
353 gfx::Rect fill_rect = quad_rect;
354 fill_rect.Inset(fill_width / 2.f, fill_width / 2.f);
355 gfx::Rect visible_fill_rect =
356 gfx::IntersectRects(visible_quad_rect, fill_rect);
357 DebugBorderDrawQuad* fill_quad =
358 render_pass->CreateAndAppendDrawQuad<DebugBorderDrawQuad>();
359 fill_quad->SetNew(shared_quad_state, fill_rect, visible_fill_rect,
360 fill_color, fill_width);
361 }
[email protected]7aba6662013-03-12 10:17:34362}
363
364bool LayerImpl::HasDelegatedContent() const {
365 return false;
366}
367
368bool LayerImpl::HasContributingDelegatedRenderPasses() const {
369 return false;
370}
371
[email protected]0cd7d6f72014-08-22 14:50:51372RenderPassId LayerImpl::FirstContributingRenderPassId() const {
373 return RenderPassId(0, 0);
[email protected]7aba6662013-03-12 10:17:34374}
375
[email protected]0cd7d6f72014-08-22 14:50:51376RenderPassId LayerImpl::NextContributingRenderPassId(RenderPassId id) const {
377 return RenderPassId(0, 0);
[email protected]7aba6662013-03-12 10:17:34378}
379
ennef6f3fbba42014-10-16 18:16:49380void LayerImpl::GetContentsResourceId(ResourceProvider::ResourceId* resource_id,
381 gfx::Size* resource_size) const {
[email protected]7aba6662013-03-12 10:17:34382 NOTREACHED();
ennef6f3fbba42014-10-16 18:16:49383 *resource_id = 0;
[email protected]7aba6662013-03-12 10:17:34384}
385
[email protected]3244c9132014-01-23 10:39:12386gfx::Vector2dF LayerImpl::ScrollBy(const gfx::Vector2dF& scroll) {
aeliasd0070ba2015-01-31 13:44:49387 gfx::ScrollOffset adjusted_scroll(scroll);
aeliasaf915a882014-10-14 04:12:04388 if (layer_tree_impl()->settings().use_pinch_virtual_viewport) {
389 if (!user_scrollable_horizontal_)
390 adjusted_scroll.set_x(0);
391 if (!user_scrollable_vertical_)
392 adjusted_scroll.set_y(0);
393 }
[email protected]d30700f12013-07-31 08:21:01394 DCHECK(scrollable());
aeliasd0070ba2015-01-31 13:44:49395 gfx::ScrollOffset old_offset = CurrentScrollOffset();
396 gfx::ScrollOffset new_offset =
397 ClampScrollOffsetToLimits(old_offset + adjusted_scroll);
398 SetCurrentScrollOffset(new_offset);
[email protected]adeda572014-01-31 00:49:47399
aeliasd0070ba2015-01-31 13:44:49400 gfx::ScrollOffset unscrolled =
401 old_offset + gfx::ScrollOffset(scroll) - new_offset;
402 return gfx::Vector2dF(unscrolled.x(), unscrolled.y());
[email protected]7aba6662013-03-12 10:17:34403}
404
[email protected]adeda572014-01-31 00:49:47405void LayerImpl::SetScrollClipLayer(int scroll_clip_layer_id) {
406 scroll_clip_layer_ = layer_tree_impl()->LayerById(scroll_clip_layer_id);
407}
408
timav3ca696932014-10-15 02:19:04409bool LayerImpl::user_scrollable(ScrollbarOrientation orientation) const {
410 return (orientation == HORIZONTAL) ? user_scrollable_horizontal_
411 : user_scrollable_vertical_;
412}
413
[email protected]58241dc2013-08-20 01:39:25414void LayerImpl::ApplySentScrollDeltasFromAbortedCommit() {
[email protected]3519b872013-07-30 07:17:50415 DCHECK(layer_tree_impl()->IsActiveTree());
aeliasd0070ba2015-01-31 13:44:49416 scroll_offset_->AbortCommit();
[email protected]58241dc2013-08-20 01:39:25417}
418
[email protected]5ff3c9782013-04-29 17:35:12419InputHandler::ScrollStatus LayerImpl::TryScroll(
[email protected]14bc5d682014-01-17 07:26:47420 const gfx::PointF& screen_space_point,
rbyers18779d822015-02-05 06:22:06421 InputHandler::ScrollInputType type,
422 ScrollBlocksOn effective_block_mode) const {
[email protected]7aba6662013-03-12 10:17:34423 if (should_scroll_on_main_thread()) {
[email protected]ed511b8d2013-03-25 03:29:29424 TRACE_EVENT0("cc", "LayerImpl::TryScroll: Failed ShouldScrollOnMainThread");
ericrk7c030992015-02-20 01:39:38425 return InputHandler::SCROLL_ON_MAIN_THREAD;
[email protected]7aba6662013-03-12 10:17:34426 }
427
428 if (!screen_space_transform().IsInvertible()) {
[email protected]ed511b8d2013-03-25 03:29:29429 TRACE_EVENT0("cc", "LayerImpl::TryScroll: Ignored NonInvertibleTransform");
ericrk7c030992015-02-20 01:39:38430 return InputHandler::SCROLL_IGNORED;
[email protected]7aba6662013-03-12 10:17:34431 }
432
433 if (!non_fast_scrollable_region().IsEmpty()) {
434 bool clipped = false;
435 gfx::Transform inverse_screen_space_transform(
436 gfx::Transform::kSkipInitialization);
437 if (!screen_space_transform().GetInverse(&inverse_screen_space_transform)) {
438 // TODO(shawnsingh): We shouldn't be applying a projection if screen space
439 // transform is uninvertible here. Perhaps we should be returning
ericrk7c030992015-02-20 01:39:38440 // SCROLL_ON_MAIN_THREAD in this case?
[email protected]3dce37232012-11-15 01:47:44441 }
442
[email protected]7aba6662013-03-12 10:17:34443 gfx::PointF hit_test_point_in_content_space =
[email protected]fa816c62013-03-18 04:24:21444 MathUtil::ProjectPoint(inverse_screen_space_transform,
[email protected]7aba6662013-03-12 10:17:34445 screen_space_point,
[email protected]fa816c62013-03-18 04:24:21446 &clipped);
[email protected]7aba6662013-03-12 10:17:34447 gfx::PointF hit_test_point_in_layer_space =
448 gfx::ScalePoint(hit_test_point_in_content_space,
449 1.f / contents_scale_x(),
450 1.f / contents_scale_y());
451 if (!clipped &&
452 non_fast_scrollable_region().Contains(
453 gfx::ToRoundedPoint(hit_test_point_in_layer_space))) {
454 TRACE_EVENT0("cc",
[email protected]ed511b8d2013-03-25 03:29:29455 "LayerImpl::tryScroll: Failed NonFastScrollableRegion");
ericrk7c030992015-02-20 01:39:38456 return InputHandler::SCROLL_ON_MAIN_THREAD;
[email protected]3dce37232012-11-15 01:47:44457 }
[email protected]7aba6662013-03-12 10:17:34458 }
[email protected]3dce37232012-11-15 01:47:44459
rbyers18779d822015-02-05 06:22:06460 if (have_scroll_event_handlers() &&
ericrk7c030992015-02-20 01:39:38461 effective_block_mode & SCROLL_BLOCKS_ON_SCROLL_EVENT) {
rbyers18779d822015-02-05 06:22:06462 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Failed ScrollEventHandlers");
ericrk7c030992015-02-20 01:39:38463 return InputHandler::SCROLL_ON_MAIN_THREAD;
rbyers18779d822015-02-05 06:22:06464 }
465
ericrk7c030992015-02-20 01:39:38466 if (type == InputHandler::WHEEL && have_wheel_event_handlers() &&
467 effective_block_mode & SCROLL_BLOCKS_ON_WHEEL_EVENT) {
[email protected]ed511b8d2013-03-25 03:29:29468 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Failed WheelEventHandlers");
ericrk7c030992015-02-20 01:39:38469 return InputHandler::SCROLL_ON_MAIN_THREAD;
[email protected]7aba6662013-03-12 10:17:34470 }
471
472 if (!scrollable()) {
473 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Ignored not scrollable");
ericrk7c030992015-02-20 01:39:38474 return InputHandler::SCROLL_IGNORED;
[email protected]7aba6662013-03-12 10:17:34475 }
476
miletusf57925d2014-10-01 19:38:13477 gfx::ScrollOffset max_scroll_offset = MaxScrollOffset();
[email protected]adeda572014-01-31 00:49:47478 if (max_scroll_offset.x() <= 0 && max_scroll_offset.y() <= 0) {
[email protected]7aba6662013-03-12 10:17:34479 TRACE_EVENT0("cc",
480 "LayerImpl::tryScroll: Ignored. Technically scrollable,"
481 " but has no affordance in either direction.");
ericrk7c030992015-02-20 01:39:38482 return InputHandler::SCROLL_IGNORED;
[email protected]7aba6662013-03-12 10:17:34483 }
484
ericrk7c030992015-02-20 01:39:38485 return InputHandler::SCROLL_STARTED;
[email protected]3dce37232012-11-15 01:47:44486}
487
[email protected]7aba6662013-03-12 10:17:34488gfx::Rect LayerImpl::LayerRectToContentRect(
489 const gfx::RectF& layer_rect) const {
490 gfx::RectF content_rect =
491 gfx::ScaleRect(layer_rect, contents_scale_x(), contents_scale_y());
492 // Intersect with content rect to avoid the extra pixel because for some
493 // values x and y, ceil((x / y) * y) may be x + 1.
494 content_rect.Intersect(gfx::Rect(content_bounds()));
495 return gfx::ToEnclosingRect(content_rect);
[email protected]b5b1fce2012-12-12 22:49:36496}
497
[email protected]7aba6662013-03-12 10:17:34498skia::RefPtr<SkPicture> LayerImpl::GetPicture() {
499 return skia::RefPtr<SkPicture>();
[email protected]76481592012-09-21 16:47:06500}
501
[email protected]7aba6662013-03-12 10:17:34502scoped_ptr<LayerImpl> LayerImpl::CreateLayerImpl(LayerTreeImpl* tree_impl) {
aeliasd0070ba2015-01-31 13:44:49503 return LayerImpl::Create(tree_impl, layer_id_, scroll_offset_);
[email protected]94f206c12012-08-25 00:09:14504}
505
[email protected]7aba6662013-03-12 10:17:34506void LayerImpl::PushPropertiesTo(LayerImpl* layer) {
[email protected]a2566412014-06-05 03:14:20507 layer->SetTransformOrigin(transform_origin_);
[email protected]7aba6662013-03-12 10:17:34508 layer->SetBackgroundColor(background_color_);
509 layer->SetBounds(bounds_);
510 layer->SetContentBounds(content_bounds());
511 layer->SetContentsScale(contents_scale_x(), contents_scale_y());
[email protected]7aba6662013-03-12 10:17:34512 layer->SetDoubleSided(double_sided_);
513 layer->SetDrawCheckerboardForMissingTiles(
514 draw_checkerboard_for_missing_tiles_);
[email protected]7aba6662013-03-12 10:17:34515 layer->SetDrawsContent(DrawsContent());
[email protected]c0ae06c12013-06-24 18:32:19516 layer->SetHideLayerAndSubtree(hide_layer_and_subtree_);
enneb723b4e22015-02-19 19:47:46517 layer->SetHasRenderSurface(!!render_surface() || layer->HasCopyRequest());
[email protected]7aba6662013-03-12 10:17:34518 layer->SetFilters(filters());
[email protected]7aba6662013-03-12 10:17:34519 layer->SetBackgroundFilters(background_filters());
520 layer->SetMasksToBounds(masks_to_bounds_);
521 layer->SetShouldScrollOnMainThread(should_scroll_on_main_thread_);
522 layer->SetHaveWheelEventHandlers(have_wheel_event_handlers_);
[email protected]f998c532014-03-31 20:02:51523 layer->SetHaveScrollEventHandlers(have_scroll_event_handlers_);
rbyers18779d822015-02-05 06:22:06524 layer->SetScrollBlocksOn(scroll_blocks_on_);
[email protected]7aba6662013-03-12 10:17:34525 layer->SetNonFastScrollableRegion(non_fast_scrollable_region_);
526 layer->SetTouchEventHandlerRegion(touch_event_handler_region_);
527 layer->SetContentsOpaque(contents_opaque_);
[email protected]43615872013-03-13 16:35:17528 layer->SetOpacity(opacity_);
[email protected]7bbeaf4e2013-11-26 10:27:22529 layer->SetBlendMode(blend_mode_);
530 layer->SetIsRootForIsolatedGroup(is_root_for_isolated_group_);
[email protected]7aba6662013-03-12 10:17:34531 layer->SetPosition(position_);
532 layer->SetIsContainerForFixedPositionLayers(
533 is_container_for_fixed_position_layers_);
[email protected]fe956c9c42013-04-09 04:26:33534 layer->SetPositionConstraint(position_constraint_);
[email protected]56fffdd2014-02-11 19:50:57535 layer->SetShouldFlattenTransform(should_flatten_transform_);
ennee95b1542015-04-20 20:35:50536 layer->set_should_flatten_transform_from_property_tree(
537 should_flatten_transform_from_property_tree_);
[email protected]7aba6662013-03-12 10:17:34538 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_);
[email protected]08bdf1b2014-04-16 23:23:29539 layer->SetTransformAndInvertibility(transform_, transform_is_invertible_);
[email protected]9bd1cb52013-01-03 22:26:33540
[email protected]adeda572014-01-31 00:49:47541 layer->SetScrollClipLayer(scroll_clip_layer_ ? scroll_clip_layer_->id()
542 : Layer::INVALID_ID);
[email protected]59a7d552013-10-22 03:36:43543 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_);
544 layer->set_user_scrollable_vertical(user_scrollable_vertical_);
bokanc687507f2014-11-04 23:41:42545
miletusff93ab72015-01-30 04:30:44546 layer->SetScrollCompensationAdjustment(scroll_compensation_adjustment_);
bokanc687507f2014-11-04 23:41:42547
aeliasd0070ba2015-01-31 13:44:49548 layer->PushScrollOffset(nullptr);
549
[email protected]a9d4d4f2014-06-19 06:49:28550 layer->Set3dSortingContextId(sorting_context_id_);
[email protected]ad63b2f2014-08-11 17:39:54551 layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_);
[email protected]b34c97982013-08-24 15:21:38552
ennee95b1542015-04-20 20:35:50553 layer->set_transform_tree_index(transform_tree_index_);
554 layer->set_opacity_tree_index(opacity_tree_index_);
555 layer->set_clip_tree_index(clip_tree_index_);
556 layer->set_offset_to_transform_parent(offset_to_transform_parent_);
557
kulkarni.a4015690f12014-10-10 13:50:06558 LayerImpl* scroll_parent = nullptr;
[email protected]d097e242014-02-28 21:51:11559 if (scroll_parent_) {
[email protected]0e98cdd2013-08-23 00:44:30560 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id());
[email protected]d097e242014-02-28 21:51:11561 DCHECK(scroll_parent);
562 }
[email protected]0e98cdd2013-08-23 00:44:30563
564 layer->SetScrollParent(scroll_parent);
565 if (scroll_children_) {
566 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>;
567 for (std::set<LayerImpl*>::iterator it = scroll_children_->begin();
[email protected]d097e242014-02-28 21:51:11568 it != scroll_children_->end();
569 ++it) {
570 DCHECK_EQ((*it)->scroll_parent(), this);
571 LayerImpl* scroll_child =
572 layer->layer_tree_impl()->LayerById((*it)->id());
573 DCHECK(scroll_child);
574 scroll_children->insert(scroll_child);
575 }
[email protected]0e98cdd2013-08-23 00:44:30576 layer->SetScrollChildren(scroll_children);
[email protected]d097e242014-02-28 21:51:11577 } else {
kulkarni.a4015690f12014-10-10 13:50:06578 layer->SetScrollChildren(nullptr);
[email protected]0e98cdd2013-08-23 00:44:30579 }
580
kulkarni.a4015690f12014-10-10 13:50:06581 LayerImpl* clip_parent = nullptr;
[email protected]0e98cdd2013-08-23 00:44:30582 if (clip_parent_) {
583 clip_parent = layer->layer_tree_impl()->LayerById(
584 clip_parent_->id());
[email protected]d097e242014-02-28 21:51:11585 DCHECK(clip_parent);
[email protected]0e98cdd2013-08-23 00:44:30586 }
587
588 layer->SetClipParent(clip_parent);
589 if (clip_children_) {
590 std::set<LayerImpl*>* clip_children = new std::set<LayerImpl*>;
591 for (std::set<LayerImpl*>::iterator it = clip_children_->begin();
592 it != clip_children_->end(); ++it)
593 clip_children->insert(layer->layer_tree_impl()->LayerById((*it)->id()));
594 layer->SetClipChildren(clip_children);
[email protected]d097e242014-02-28 21:51:11595 } else {
kulkarni.a4015690f12014-10-10 13:50:06596 layer->SetClipChildren(nullptr);
[email protected]0e98cdd2013-08-23 00:44:30597 }
598
[email protected]0e5f7142013-05-24 06:45:36599 layer->PassCopyRequests(&copy_requests_);
[email protected]18a70192013-04-26 16:18:25600
[email protected]7aba6662013-03-12 10:17:34601 // If the main thread commits multiple times before the impl thread actually
602 // draws, then damage tracking will become incorrect if we simply clobber the
[email protected]ed511b8d2013-03-25 03:29:29603 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e.
[email protected]7aba6662013-03-12 10:17:34604 // union) any update changes that have occurred on the main thread.
605 update_rect_.Union(layer->update_rect());
[email protected]ad0250b2014-01-18 03:24:34606 layer->SetUpdateRect(update_rect_);
[email protected]7aba6662013-03-12 10:17:34607
[email protected]7aba6662013-03-12 10:17:34608 layer->SetStackingOrderChanged(stacking_order_changed_);
[email protected]ad0250b2014-01-18 03:24:34609 layer->SetDebugInfo(debug_info_);
[email protected]7aba6662013-03-12 10:17:34610
vmpstr3d1d72c2015-01-26 18:27:40611 if (frame_timing_requests_dirty_) {
612 layer->PassFrameTimingRequests(&frame_timing_requests_);
613 frame_timing_requests_dirty_ = false;
614 }
615
[email protected]7aba6662013-03-12 10:17:34616 // Reset any state that should be cleared for the next update.
617 stacking_order_changed_ = false;
danakj19f0c9e2014-10-11 03:24:42618 update_rect_ = gfx::Rect();
[email protected]ad0250b2014-01-18 03:24:34619 needs_push_properties_ = false;
620 num_dependents_need_push_properties_ = 0;
[email protected]caa567d2012-12-20 07:56:16621}
622
[email protected]fef74fd2014-02-27 06:28:17623gfx::Vector2dF LayerImpl::FixedContainerSizeDelta() const {
624 if (!scroll_clip_layer_)
625 return gfx::Vector2dF();
626
[email protected]587941d2014-08-22 01:40:01627 gfx::Vector2dF delta_from_scroll = scroll_clip_layer_->bounds_delta();
bokan8273d962014-10-22 02:40:27628
629 // In virtual-viewport mode, we don't need to compensate for pinch zoom or
630 // scale since the fixed container is the outer viewport, which sits below
631 // the page scale.
632 if (layer_tree_impl()->settings().use_pinch_virtual_viewport)
633 return delta_from_scroll;
634
aelias58eec0812014-12-04 01:04:40635 float scale_delta = layer_tree_impl()->page_scale_delta();
636 float scale = layer_tree_impl()->current_page_scale_factor() /
637 layer_tree_impl()->page_scale_delta();
638
[email protected]fef74fd2014-02-27 06:28:17639 delta_from_scroll.Scale(1.f / scale);
640
641 // The delta-from-pinch component requires some explanation: A viewport of
642 // size (w,h) will appear to be size (w/s,h/s) under scale s in the content
643 // space. If s -> s' on the impl thread, where s' = s * ds, then the apparent
644 // viewport size change in the content space due to ds is:
645 //
646 // (w/s',h/s') - (w/s,h/s) = (w,h)(1/s' - 1/s) = (w,h)(1 - ds)/(s ds)
647 //
648 gfx::Vector2dF delta_from_pinch =
bokancccfde72014-10-08 15:15:22649 gfx::Rect(scroll_clip_layer_->bounds()).bottom_right() - gfx::PointF();
[email protected]fef74fd2014-02-27 06:28:17650 delta_from_pinch.Scale((1.f - scale_delta) / (scale * scale_delta));
651
652 return delta_from_scroll + delta_from_pinch;
653}
654
[email protected]7aba6662013-03-12 10:17:34655base::DictionaryValue* LayerImpl::LayerTreeAsJson() const {
[email protected]7aba6662013-03-12 10:17:34656 base::DictionaryValue* result = new base::DictionaryValue;
657 result->SetString("LayerType", LayerTypeAsString());
658
[email protected]46c76952013-07-10 00:21:45659 base::ListValue* list = new base::ListValue;
bokancccfde72014-10-08 15:15:22660 list->AppendInteger(bounds().width());
661 list->AppendInteger(bounds().height());
[email protected]7aba6662013-03-12 10:17:34662 result->Set("Bounds", list);
663
664 list = new base::ListValue;
665 list->AppendDouble(position_.x());
666 list->AppendDouble(position_.y());
667 result->Set("Position", list);
668
669 const gfx::Transform& gfx_transform = draw_properties_.target_space_transform;
670 double transform[16];
671 gfx_transform.matrix().asColMajord(transform);
672 list = new base::ListValue;
673 for (int i = 0; i < 16; ++i)
674 list->AppendDouble(transform[i]);
675 result->Set("DrawTransform", list);
676
677 result->SetBoolean("DrawsContent", draws_content_);
[email protected]a9d4d4f2014-06-19 06:49:28678 result->SetBoolean("Is3dSorted", Is3dSorted());
ericrk7c030992015-02-20 01:39:38679 result->SetDouble("OPACITY", opacity());
[email protected]46c76952013-07-10 00:21:45680 result->SetBoolean("ContentsOpaque", contents_opaque_);
[email protected]7aba6662013-03-12 10:17:34681
[email protected]adeda572014-01-31 00:49:47682 if (scrollable())
683 result->SetBoolean("Scrollable", true);
[email protected]d993e032013-06-07 00:16:16684
[email protected]9d161d22013-10-29 20:54:10685 if (have_wheel_event_handlers_)
686 result->SetBoolean("WheelHandler", have_wheel_event_handlers_);
[email protected]f998c532014-03-31 20:02:51687 if (have_scroll_event_handlers_)
688 result->SetBoolean("ScrollHandler", have_scroll_event_handlers_);
[email protected]9d161d22013-10-29 20:54:10689 if (!touch_event_handler_region_.IsEmpty()) {
690 scoped_ptr<base::Value> region = touch_event_handler_region_.AsValue();
691 result->Set("TouchRegion", region.release());
692 }
693
rbyers18779d822015-02-05 06:22:06694 if (scroll_blocks_on_) {
695 list = new base::ListValue;
ericrk7c030992015-02-20 01:39:38696 if (scroll_blocks_on_ & SCROLL_BLOCKS_ON_START_TOUCH)
rbyers18779d822015-02-05 06:22:06697 list->AppendString("StartTouch");
ericrk7c030992015-02-20 01:39:38698 if (scroll_blocks_on_ & SCROLL_BLOCKS_ON_WHEEL_EVENT)
rbyers18779d822015-02-05 06:22:06699 list->AppendString("WheelEvent");
ericrk7c030992015-02-20 01:39:38700 if (scroll_blocks_on_ & SCROLL_BLOCKS_ON_SCROLL_EVENT)
rbyers18779d822015-02-05 06:22:06701 list->AppendString("ScrollEvent");
702 result->Set("ScrollBlocksOn", list);
703 }
704
[email protected]7aba6662013-03-12 10:17:34705 list = new base::ListValue;
706 for (size_t i = 0; i < children_.size(); ++i)
707 list->Append(children_[i]->LayerTreeAsJson());
708 result->Set("Children", list);
709
710 return result;
[email protected]b9dcf43a2013-01-09 00:15:29711}
712
[email protected]7aba6662013-03-12 10:17:34713void LayerImpl::SetStackingOrderChanged(bool stacking_order_changed) {
714 if (stacking_order_changed) {
715 stacking_order_changed_ = true;
716 NoteLayerPropertyChangedForSubtree();
717 }
[email protected]aedf4e52013-01-09 23:24:44718}
719
[email protected]7aba6662013-03-12 10:17:34720void LayerImpl::NoteLayerPropertyChanged() {
721 layer_property_changed_ = true;
722 layer_tree_impl()->set_needs_update_draw_properties();
[email protected]ad0250b2014-01-18 03:24:34723 SetNeedsPushProperties();
[email protected]48871fc2013-01-23 07:36:51724}
725
[email protected]7aba6662013-03-12 10:17:34726void LayerImpl::NoteLayerPropertyChangedForSubtree() {
[email protected]ad0250b2014-01-18 03:24:34727 layer_property_changed_ = true;
728 layer_tree_impl()->set_needs_update_draw_properties();
729 for (size_t i = 0; i < children_.size(); ++i)
730 children_[i]->NoteLayerPropertyChangedForDescendantsInternal();
731 SetNeedsPushProperties();
732}
733
734void LayerImpl::NoteLayerPropertyChangedForDescendantsInternal() {
735 layer_property_changed_ = true;
736 for (size_t i = 0; i < children_.size(); ++i)
737 children_[i]->NoteLayerPropertyChangedForDescendantsInternal();
[email protected]94f206c12012-08-25 00:09:14738}
739
[email protected]7aba6662013-03-12 10:17:34740void LayerImpl::NoteLayerPropertyChangedForDescendants() {
741 layer_tree_impl()->set_needs_update_draw_properties();
742 for (size_t i = 0; i < children_.size(); ++i)
[email protected]ad0250b2014-01-18 03:24:34743 children_[i]->NoteLayerPropertyChangedForDescendantsInternal();
744 SetNeedsPushProperties();
[email protected]7aba6662013-03-12 10:17:34745}
[email protected]94f206c12012-08-25 00:09:14746
[email protected]7aba6662013-03-12 10:17:34747const char* LayerImpl::LayerTypeAsString() const {
[email protected]f256b7fd2013-05-15 01:49:30748 return "cc::LayerImpl";
[email protected]7aba6662013-03-12 10:17:34749}
[email protected]94f206c12012-08-25 00:09:14750
[email protected]7aba6662013-03-12 10:17:34751void LayerImpl::ResetAllChangeTrackingForSubtree() {
752 layer_property_changed_ = false;
[email protected]7aba6662013-03-12 10:17:34753
danakj19f0c9e2014-10-11 03:24:42754 update_rect_ = gfx::Rect();
[email protected]cfa7fd922014-04-29 11:50:03755 damage_rect_ = gfx::RectF();
[email protected]7aba6662013-03-12 10:17:34756
awoloszyne83f28c2014-12-22 15:40:00757 if (render_surface_)
758 render_surface_->ResetPropertyChangedFlag();
[email protected]7aba6662013-03-12 10:17:34759
760 if (mask_layer_)
761 mask_layer_->ResetAllChangeTrackingForSubtree();
762
763 if (replica_layer_) {
764 // This also resets the replica mask, if it exists.
765 replica_layer_->ResetAllChangeTrackingForSubtree();
766 }
767
768 for (size_t i = 0; i < children_.size(); ++i)
769 children_[i]->ResetAllChangeTrackingForSubtree();
[email protected]ad0250b2014-01-18 03:24:34770
771 needs_push_properties_ = false;
772 num_dependents_need_push_properties_ = 0;
[email protected]7aba6662013-03-12 10:17:34773}
774
miletusf57925d2014-10-01 19:38:13775gfx::ScrollOffset LayerImpl::ScrollOffsetForAnimation() const {
aeliasd0070ba2015-01-31 13:44:49776 return CurrentScrollOffset();
[email protected]b8384e22013-12-03 02:20:48777}
778
[email protected]b4c6d812013-10-03 15:48:56779void LayerImpl::OnFilterAnimated(const FilterOperations& filters) {
780 SetFilters(filters);
781}
782
[email protected]7aba6662013-03-12 10:17:34783void LayerImpl::OnOpacityAnimated(float opacity) {
784 SetOpacity(opacity);
785}
786
787void LayerImpl::OnTransformAnimated(const gfx::Transform& transform) {
788 SetTransform(transform);
789}
790
miletusf57925d2014-10-01 19:38:13791void LayerImpl::OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) {
[email protected]b8384e22013-12-03 02:20:48792 // Only layers in the active tree should need to do anything here, since
793 // layers in the pending tree will find out about these changes as a
aeliasd0070ba2015-01-31 13:44:49794 // result of the shared SyncedProperty.
[email protected]b8384e22013-12-03 02:20:48795 if (!IsActive())
796 return;
797
aeliasd0070ba2015-01-31 13:44:49798 SetCurrentScrollOffset(scroll_offset);
[email protected]b8384e22013-12-03 02:20:48799
800 layer_tree_impl_->DidAnimateScrollOffset();
801}
802
[email protected]1c24cf2962013-11-18 23:34:51803void LayerImpl::OnAnimationWaitingForDeletion() {}
804
[email protected]7aba6662013-03-12 10:17:34805bool LayerImpl::IsActive() const {
806 return layer_tree_impl_->IsActiveTree();
807}
808
bokancccfde72014-10-08 15:15:22809gfx::Size LayerImpl::bounds() const {
bokanef971462014-10-13 22:58:32810 gfx::Vector2d delta = gfx::ToCeiledVector2d(bounds_delta_);
811 return gfx::Size(bounds_.width() + delta.x(),
812 bounds_.height() + delta.y());
813}
814
815gfx::SizeF LayerImpl::BoundsForScrolling() const {
816 return gfx::SizeF(bounds_.width() + bounds_delta_.x(),
817 bounds_.height() + bounds_delta_.y());
[email protected]fef74fd2014-02-27 06:28:17818}
819
[email protected]64348ea2014-01-29 22:58:26820void LayerImpl::SetBounds(const gfx::Size& bounds) {
[email protected]7aba6662013-03-12 10:17:34821 if (bounds_ == bounds)
822 return;
823
824 bounds_ = bounds;
[email protected]fef74fd2014-02-27 06:28:17825
sataya.m07f11a82014-10-07 14:29:18826 ScrollbarParametersDidChange(true);
[email protected]fef74fd2014-02-27 06:28:17827 if (masks_to_bounds())
828 NoteLayerPropertyChangedForSubtree();
829 else
830 NoteLayerPropertyChanged();
831}
832
[email protected]587941d2014-08-22 01:40:01833void LayerImpl::SetBoundsDelta(const gfx::Vector2dF& bounds_delta) {
834 if (bounds_delta_ == bounds_delta)
[email protected]fef74fd2014-02-27 06:28:17835 return;
836
[email protected]587941d2014-08-22 01:40:01837 bounds_delta_ = bounds_delta;
[email protected]7aba6662013-03-12 10:17:34838
aelias1505e722014-10-07 22:19:46839 ScrollbarParametersDidChange(true);
[email protected]7aba6662013-03-12 10:17:34840 if (masks_to_bounds())
841 NoteLayerPropertyChangedForSubtree();
842 else
843 NoteLayerPropertyChanged();
844}
845
846void LayerImpl::SetMaskLayer(scoped_ptr<LayerImpl> mask_layer) {
847 int new_layer_id = mask_layer ? mask_layer->id() : -1;
848
849 if (mask_layer) {
850 DCHECK_EQ(layer_tree_impl(), mask_layer->layer_tree_impl());
851 DCHECK_NE(new_layer_id, mask_layer_id_);
852 } else if (new_layer_id == mask_layer_id_) {
853 return;
854 }
855
856 mask_layer_ = mask_layer.Pass();
857 mask_layer_id_ = new_layer_id;
858 if (mask_layer_)
[email protected]ad0250b2014-01-18 03:24:34859 mask_layer_->SetParent(this);
[email protected]7aba6662013-03-12 10:17:34860 NoteLayerPropertyChangedForSubtree();
861}
862
863scoped_ptr<LayerImpl> LayerImpl::TakeMaskLayer() {
864 mask_layer_id_ = -1;
865 return mask_layer_.Pass();
866}
867
868void LayerImpl::SetReplicaLayer(scoped_ptr<LayerImpl> replica_layer) {
869 int new_layer_id = replica_layer ? replica_layer->id() : -1;
870
871 if (replica_layer) {
872 DCHECK_EQ(layer_tree_impl(), replica_layer->layer_tree_impl());
873 DCHECK_NE(new_layer_id, replica_layer_id_);
874 } else if (new_layer_id == replica_layer_id_) {
875 return;
876 }
877
878 replica_layer_ = replica_layer.Pass();
879 replica_layer_id_ = new_layer_id;
880 if (replica_layer_)
[email protected]ad0250b2014-01-18 03:24:34881 replica_layer_->SetParent(this);
[email protected]7aba6662013-03-12 10:17:34882 NoteLayerPropertyChangedForSubtree();
883}
884
885scoped_ptr<LayerImpl> LayerImpl::TakeReplicaLayer() {
886 replica_layer_id_ = -1;
887 return replica_layer_.Pass();
888}
889
[email protected]80413d72013-08-30 20:25:33890ScrollbarLayerImplBase* LayerImpl::ToScrollbarLayer() {
kulkarni.a4015690f12014-10-10 13:50:06891 return nullptr;
[email protected]7aba6662013-03-12 10:17:34892}
893
894void LayerImpl::SetDrawsContent(bool draws_content) {
895 if (draws_content_ == draws_content)
896 return;
897
898 draws_content_ = draws_content;
899 NoteLayerPropertyChanged();
900}
901
[email protected]c0ae06c12013-06-24 18:32:19902void LayerImpl::SetHideLayerAndSubtree(bool hide) {
903 if (hide_layer_and_subtree_ == hide)
904 return;
905
906 hide_layer_and_subtree_ = hide;
907 NoteLayerPropertyChangedForSubtree();
908}
909
[email protected]a2566412014-06-05 03:14:20910void LayerImpl::SetTransformOrigin(const gfx::Point3F& transform_origin) {
911 if (transform_origin_ == transform_origin)
[email protected]7aba6662013-03-12 10:17:34912 return;
[email protected]a2566412014-06-05 03:14:20913 transform_origin_ = transform_origin;
[email protected]7aba6662013-03-12 10:17:34914 NoteLayerPropertyChangedForSubtree();
915}
916
917void LayerImpl::SetBackgroundColor(SkColor background_color) {
918 if (background_color_ == background_color)
919 return;
920
921 background_color_ = background_color;
922 NoteLayerPropertyChanged();
923}
924
[email protected]2c4cbec2013-06-04 21:14:50925SkColor LayerImpl::SafeOpaqueBackgroundColor() const {
926 SkColor color = background_color();
927 if (SkColorGetA(color) == 255 && !contents_opaque()) {
928 color = SK_ColorTRANSPARENT;
929 } else if (SkColorGetA(color) != 255 && contents_opaque()) {
930 for (const LayerImpl* layer = parent(); layer;
931 layer = layer->parent()) {
932 color = layer->background_color();
933 if (SkColorGetA(color) == 255)
934 break;
935 }
936 if (SkColorGetA(color) != 255)
937 color = layer_tree_impl()->background_color();
938 if (SkColorGetA(color) != 255)
939 color = SkColorSetA(color, 255);
940 }
941 return color;
942}
943
[email protected]ae6b1a72013-06-25 18:49:29944void LayerImpl::SetFilters(const FilterOperations& filters) {
[email protected]7aba6662013-03-12 10:17:34945 if (filters_ == filters)
946 return;
947
[email protected]7aba6662013-03-12 10:17:34948 filters_ = filters;
949 NoteLayerPropertyChangedForSubtree();
950}
951
[email protected]b4c6d812013-10-03 15:48:56952bool LayerImpl::FilterIsAnimating() const {
ericrk7c030992015-02-20 01:39:38953 return layer_animation_controller_->IsAnimatingProperty(Animation::FILTER);
[email protected]b4c6d812013-10-03 15:48:56954}
955
956bool LayerImpl::FilterIsAnimatingOnImplOnly() const {
957 Animation* filter_animation =
ericrk7c030992015-02-20 01:39:38958 layer_animation_controller_->GetAnimation(Animation::FILTER);
[email protected]b4c6d812013-10-03 15:48:56959 return filter_animation && filter_animation->is_impl_only();
960}
961
[email protected]7aba6662013-03-12 10:17:34962void LayerImpl::SetBackgroundFilters(
[email protected]ae6b1a72013-06-25 18:49:29963 const FilterOperations& filters) {
[email protected]7aba6662013-03-12 10:17:34964 if (background_filters_ == filters)
965 return;
966
967 background_filters_ = filters;
968 NoteLayerPropertyChanged();
969}
970
[email protected]7aba6662013-03-12 10:17:34971void LayerImpl::SetMasksToBounds(bool masks_to_bounds) {
972 if (masks_to_bounds_ == masks_to_bounds)
973 return;
974
975 masks_to_bounds_ = masks_to_bounds;
976 NoteLayerPropertyChangedForSubtree();
977}
978
979void LayerImpl::SetContentsOpaque(bool opaque) {
980 if (contents_opaque_ == opaque)
981 return;
982
983 contents_opaque_ = opaque;
984 NoteLayerPropertyChangedForSubtree();
985}
986
987void LayerImpl::SetOpacity(float opacity) {
988 if (opacity_ == opacity)
989 return;
990
991 opacity_ = opacity;
[email protected]af37ce802013-10-07 23:53:28992 NoteLayerPropertyChangedForSubtree();
[email protected]7aba6662013-03-12 10:17:34993}
994
995bool LayerImpl::OpacityIsAnimating() const {
ericrk7c030992015-02-20 01:39:38996 return layer_animation_controller_->IsAnimatingProperty(Animation::OPACITY);
[email protected]7aba6662013-03-12 10:17:34997}
998
[email protected]43615872013-03-13 16:35:17999bool LayerImpl::OpacityIsAnimatingOnImplOnly() const {
1000 Animation* opacity_animation =
ericrk7c030992015-02-20 01:39:381001 layer_animation_controller_->GetAnimation(Animation::OPACITY);
[email protected]43615872013-03-13 16:35:171002 return opacity_animation && opacity_animation->is_impl_only();
1003}
1004
[email protected]7bbeaf4e2013-11-26 10:27:221005void LayerImpl::SetBlendMode(SkXfermode::Mode blend_mode) {
1006 if (blend_mode_ == blend_mode)
1007 return;
1008
1009 blend_mode_ = blend_mode;
1010 NoteLayerPropertyChangedForSubtree();
1011}
1012
1013void LayerImpl::SetIsRootForIsolatedGroup(bool root) {
1014 if (is_root_for_isolated_group_ == root)
1015 return;
1016
1017 is_root_for_isolated_group_ = root;
[email protected]ad0250b2014-01-18 03:24:341018 SetNeedsPushProperties();
[email protected]7bbeaf4e2013-11-26 10:27:221019}
1020
[email protected]14bc5d682014-01-17 07:26:471021void LayerImpl::SetPosition(const gfx::PointF& position) {
[email protected]7aba6662013-03-12 10:17:341022 if (position_ == position)
1023 return;
1024
1025 position_ = position;
1026 NoteLayerPropertyChangedForSubtree();
1027}
1028
[email protected]56fffdd2014-02-11 19:50:571029void LayerImpl::SetShouldFlattenTransform(bool flatten) {
1030 if (should_flatten_transform_ == flatten)
[email protected]7aba6662013-03-12 10:17:341031 return;
1032
[email protected]56fffdd2014-02-11 19:50:571033 should_flatten_transform_ = flatten;
1034 NoteLayerPropertyChangedForSubtree();
1035}
1036
[email protected]a9d4d4f2014-06-19 06:49:281037void LayerImpl::Set3dSortingContextId(int id) {
1038 if (id == sorting_context_id_)
[email protected]56fffdd2014-02-11 19:50:571039 return;
[email protected]a9d4d4f2014-06-19 06:49:281040 sorting_context_id_ = id;
[email protected]7aba6662013-03-12 10:17:341041 NoteLayerPropertyChangedForSubtree();
1042}
1043
vmpstr3d1d72c2015-01-26 18:27:401044void LayerImpl::PassFrameTimingRequests(
1045 std::vector<FrameTimingRequest>* requests) {
1046 frame_timing_requests_.swap(*requests);
1047 frame_timing_requests_dirty_ = true;
1048 SetNeedsPushProperties();
1049}
1050
vmpstrd704c872015-04-03 20:29:511051void LayerImpl::GatherFrameTimingRequestIds(std::vector<int64_t>* request_ids) {
1052 for (const auto& request : frame_timing_requests_)
1053 request_ids->push_back(request.id());
1054}
1055
[email protected]7aba6662013-03-12 10:17:341056void LayerImpl::SetTransform(const gfx::Transform& transform) {
1057 if (transform_ == transform)
1058 return;
1059
1060 transform_ = transform;
[email protected]08bdf1b2014-04-16 23:23:291061 transform_is_invertible_ = transform_.IsInvertible();
1062 NoteLayerPropertyChangedForSubtree();
1063}
1064
1065void LayerImpl::SetTransformAndInvertibility(const gfx::Transform& transform,
1066 bool transform_is_invertible) {
1067 if (transform_ == transform) {
1068 DCHECK(transform_is_invertible_ == transform_is_invertible)
1069 << "Can't change invertibility if transform is unchanged";
1070 return;
1071 }
1072 transform_ = transform;
1073 transform_is_invertible_ = transform_is_invertible;
[email protected]af37ce802013-10-07 23:53:281074 NoteLayerPropertyChangedForSubtree();
[email protected]7aba6662013-03-12 10:17:341075}
1076
1077bool LayerImpl::TransformIsAnimating() const {
ericrk7c030992015-02-20 01:39:381078 return layer_animation_controller_->IsAnimatingProperty(Animation::TRANSFORM);
[email protected]7aba6662013-03-12 10:17:341079}
1080
[email protected]43615872013-03-13 16:35:171081bool LayerImpl::TransformIsAnimatingOnImplOnly() const {
1082 Animation* transform_animation =
ericrk7c030992015-02-20 01:39:381083 layer_animation_controller_->GetAnimation(Animation::TRANSFORM);
[email protected]43615872013-03-13 16:35:171084 return transform_animation && transform_animation->is_impl_only();
1085}
1086
danakj19f0c9e2014-10-11 03:24:421087void LayerImpl::SetUpdateRect(const gfx::Rect& update_rect) {
[email protected]ad0250b2014-01-18 03:24:341088 update_rect_ = update_rect;
1089 SetNeedsPushProperties();
1090}
1091
[email protected]cfa7fd922014-04-29 11:50:031092void LayerImpl::AddDamageRect(const gfx::RectF& damage_rect) {
1093 damage_rect_ = gfx::UnionRects(damage_rect_, damage_rect);
1094}
1095
[email protected]64348ea2014-01-29 22:58:261096void LayerImpl::SetContentBounds(const gfx::Size& content_bounds) {
[email protected]7aba6662013-03-12 10:17:341097 if (this->content_bounds() == content_bounds)
1098 return;
1099
1100 draw_properties_.content_bounds = content_bounds;
1101 NoteLayerPropertyChanged();
1102}
1103
1104void LayerImpl::SetContentsScale(float contents_scale_x,
1105 float contents_scale_y) {
1106 if (this->contents_scale_x() == contents_scale_x &&
1107 this->contents_scale_y() == contents_scale_y)
1108 return;
1109
1110 draw_properties_.contents_scale_x = contents_scale_x;
1111 draw_properties_.contents_scale_y = contents_scale_y;
1112 NoteLayerPropertyChanged();
1113}
1114
[email protected]251699b2013-10-09 00:21:261115bool LayerImpl::IsExternalFlingActive() const {
hush33370e12015-04-07 03:49:501116 return layer_tree_impl_->IsExternalFlingActive();
[email protected]251699b2013-10-09 00:21:261117}
1118
aeliasd0070ba2015-01-31 13:44:491119void LayerImpl::SetCurrentScrollOffset(const gfx::ScrollOffset& scroll_offset) {
1120 DCHECK(IsActive());
1121 if (scroll_offset_->SetCurrent(scroll_offset))
hush33370e12015-04-07 03:49:501122 DidUpdateScrollOffset(false);
1123}
1124
1125void LayerImpl::SetCurrentScrollOffsetFromDelegate(
1126 const gfx::ScrollOffset& scroll_offset) {
1127 DCHECK(IsActive());
1128 if (scroll_offset_->SetCurrent(scroll_offset))
1129 DidUpdateScrollOffset(true);
boliu7d5dbab2014-10-10 20:05:471130}
1131
aeliasd0070ba2015-01-31 13:44:491132void LayerImpl::PushScrollOffsetFromMainThread(
1133 const gfx::ScrollOffset& scroll_offset) {
1134 PushScrollOffset(&scroll_offset);
[email protected]b34c97982013-08-24 15:21:381135}
[email protected]7aba6662013-03-12 10:17:341136
danakjb5197d32015-02-03 23:39:491137void LayerImpl::PushScrollOffsetFromMainThreadAndClobberActiveValue(
1138 const gfx::ScrollOffset& scroll_offset) {
1139 scroll_offset_->set_clobber_active_value();
1140 PushScrollOffset(&scroll_offset);
1141}
1142
aeliasd0070ba2015-01-31 13:44:491143gfx::ScrollOffset LayerImpl::PullDeltaForMainThread() {
miletusd799dd22015-03-19 04:23:171144 // TODO(miletus): Remove all this temporary flooring machinery when
1145 // Blink fully supports fractional scrolls.
1146 gfx::ScrollOffset current_offset = CurrentScrollOffset();
1147 gfx::Vector2dF current_delta = ScrollDelta();
1148 gfx::Vector2dF floored_delta(floor(current_delta.x()),
1149 floor(current_delta.y()));
1150 gfx::Vector2dF diff_delta = floored_delta - current_delta;
1151 gfx::ScrollOffset tmp_offset = ScrollOffsetWithDelta(current_offset,
1152 diff_delta);
1153 scroll_offset_->SetCurrent(tmp_offset);
1154 gfx::ScrollOffset delta = scroll_offset_->PullDeltaForMainThread();
1155 scroll_offset_->SetCurrent(current_offset);
1156 return delta;
aeliasd0070ba2015-01-31 13:44:491157}
[email protected]adeda572014-01-31 00:49:471158
aeliasd0070ba2015-01-31 13:44:491159gfx::ScrollOffset LayerImpl::CurrentScrollOffset() const {
1160 return scroll_offset_->Current(IsActive());
[email protected]7aba6662013-03-12 10:17:341161}
1162
[email protected]1960a712013-04-30 17:06:471163gfx::Vector2dF LayerImpl::ScrollDelta() const {
aeliasd0070ba2015-01-31 13:44:491164 if (IsActive())
1165 return gfx::Vector2dF(scroll_offset_->Delta().x(),
1166 scroll_offset_->Delta().y());
1167 else
1168 return gfx::Vector2dF(scroll_offset_->PendingDelta().get().x(),
1169 scroll_offset_->PendingDelta().get().y());
1170}
1171
1172void LayerImpl::SetScrollDelta(const gfx::Vector2dF& delta) {
1173 DCHECK(IsActive());
1174 SetCurrentScrollOffset(scroll_offset_->ActiveBase() +
1175 gfx::ScrollOffset(delta));
1176}
1177
1178gfx::ScrollOffset LayerImpl::BaseScrollOffset() const {
1179 if (IsActive())
1180 return scroll_offset_->ActiveBase();
1181 else
1182 return scroll_offset_->PendingBase();
1183}
1184
1185void LayerImpl::PushScrollOffset(const gfx::ScrollOffset* scroll_offset) {
1186 DCHECK(scroll_offset || IsActive());
1187 bool changed = false;
1188 if (scroll_offset) {
1189 DCHECK(!IsActive() || !layer_tree_impl_->FindPendingTreeLayerById(id()));
1190 changed |= scroll_offset_->PushFromMainThread(*scroll_offset);
miletusf57925d2014-10-01 19:38:131191 }
aeliasd0070ba2015-01-31 13:44:491192 if (IsActive()) {
1193 changed |= scroll_offset_->PushPendingToActive();
aeliasd0070ba2015-01-31 13:44:491194 }
1195
1196 if (changed)
hush33370e12015-04-07 03:49:501197 DidUpdateScrollOffset(false);
[email protected]1960a712013-04-30 17:06:471198}
1199
hush33370e12015-04-07 03:49:501200void LayerImpl::DidUpdateScrollOffset(bool is_from_root_delegate) {
1201 if (!is_from_root_delegate)
1202 layer_tree_impl()->DidUpdateScrollOffset(id());
aeliasd0070ba2015-01-31 13:44:491203 NoteLayerPropertyChangedForSubtree();
1204 ScrollbarParametersDidChange(false);
[email protected]ffb2720f2013-03-15 19:18:371205}
1206
[email protected]7aba6662013-03-12 10:17:341207void LayerImpl::SetDoubleSided(bool double_sided) {
1208 if (double_sided_ == double_sided)
1209 return;
1210
1211 double_sided_ = double_sided;
1212 NoteLayerPropertyChangedForSubtree();
1213}
1214
[email protected]d5467eb72014-08-22 01:16:431215SimpleEnclosedRegion LayerImpl::VisibleContentOpaqueRegion() const {
[email protected]7aba6662013-03-12 10:17:341216 if (contents_opaque())
[email protected]d5467eb72014-08-22 01:16:431217 return SimpleEnclosedRegion(visible_content_rect());
1218 return SimpleEnclosedRegion();
[email protected]7aba6662013-03-12 10:17:341219}
1220
[email protected]37349bc2013-06-04 01:31:521221void LayerImpl::DidBeginTracing() {}
1222
[email protected]9db24462014-01-14 02:25:501223void LayerImpl::ReleaseResources() {}
[email protected]7aba6662013-03-12 10:17:341224
vmpstr9ce5c662015-02-05 23:29:261225void LayerImpl::RecreateResources() {
1226}
1227
miletusf57925d2014-10-01 19:38:131228gfx::ScrollOffset LayerImpl::MaxScrollOffset() const {
[email protected]adeda572014-01-31 00:49:471229 if (!scroll_clip_layer_ || bounds().IsEmpty())
miletusf57925d2014-10-01 19:38:131230 return gfx::ScrollOffset();
[email protected]610834cb2014-01-29 13:54:331231
[email protected]adeda572014-01-31 00:49:471232 LayerImpl const* page_scale_layer = layer_tree_impl()->page_scale_layer();
1233 DCHECK(this != page_scale_layer);
[email protected]adeda572014-01-31 00:49:471234 DCHECK(this != layer_tree_impl()->InnerViewportScrollLayer() ||
1235 IsContainerForFixedPositionLayers());
1236
[email protected]adeda572014-01-31 00:49:471237 float scale_factor = 1.f;
1238 for (LayerImpl const* current_layer = this;
aeliasd0070ba2015-01-31 13:44:491239 current_layer != scroll_clip_layer_->parent();
[email protected]adeda572014-01-31 00:49:471240 current_layer = current_layer->parent()) {
aeliasd0070ba2015-01-31 13:44:491241 if (current_layer == page_scale_layer)
1242 scale_factor = layer_tree_impl()->current_page_scale_factor();
[email protected]adeda572014-01-31 00:49:471243 }
[email protected]adeda572014-01-31 00:49:471244
aeliasd0070ba2015-01-31 13:44:491245 gfx::SizeF scaled_scroll_bounds =
1246 gfx::ToFlooredSize(gfx::ScaleSize(BoundsForScrolling(), scale_factor));
[email protected]0072c112014-04-22 05:53:401247 scaled_scroll_bounds = gfx::ToFlooredSize(scaled_scroll_bounds);
[email protected]adeda572014-01-31 00:49:471248
miletusf57925d2014-10-01 19:38:131249 gfx::ScrollOffset max_offset(
[email protected]adeda572014-01-31 00:49:471250 scaled_scroll_bounds.width() - scroll_clip_layer_->bounds().width(),
1251 scaled_scroll_bounds.height() - scroll_clip_layer_->bounds().height());
1252 // We need the final scroll offset to be in CSS coords.
1253 max_offset.Scale(1 / scale_factor);
miletusf57925d2014-10-01 19:38:131254 max_offset.SetToMax(gfx::ScrollOffset());
1255 return max_offset;
[email protected]adeda572014-01-31 00:49:471256}
1257
aeliasd0070ba2015-01-31 13:44:491258gfx::ScrollOffset LayerImpl::ClampScrollOffsetToLimits(
1259 gfx::ScrollOffset offset) const {
1260 offset.SetToMin(MaxScrollOffset());
1261 offset.SetToMax(gfx::ScrollOffset());
1262 return offset;
1263}
[email protected]adeda572014-01-31 00:49:471264
aeliasd0070ba2015-01-31 13:44:491265gfx::Vector2dF LayerImpl::ClampScrollToMaxScrollOffset() {
1266 gfx::ScrollOffset old_offset = CurrentScrollOffset();
1267 gfx::ScrollOffset clamped_offset = ClampScrollOffsetToLimits(old_offset);
miletusf57925d2014-10-01 19:38:131268 gfx::Vector2dF delta = clamped_offset.DeltaFrom(old_offset);
[email protected]adeda572014-01-31 00:49:471269 if (!delta.IsZero())
1270 ScrollBy(delta);
[email protected]adeda572014-01-31 00:49:471271 return delta;
1272}
1273
1274void LayerImpl::SetScrollbarPosition(ScrollbarLayerImplBase* scrollbar_layer,
sataya.m07f11a82014-10-07 14:29:181275 LayerImpl* scrollbar_clip_layer,
1276 bool on_resize) const {
[email protected]adeda572014-01-31 00:49:471277 DCHECK(scrollbar_layer);
1278 LayerImpl* page_scale_layer = layer_tree_impl()->page_scale_layer();
1279
1280 DCHECK(this != page_scale_layer);
1281 DCHECK(scrollbar_clip_layer);
bokanef971462014-10-13 22:58:321282 gfx::RectF clip_rect(gfx::PointF(),
1283 scrollbar_clip_layer->BoundsForScrolling());
[email protected]adeda572014-01-31 00:49:471284
1285 // See comment in MaxScrollOffset() regarding the use of the content layer
1286 // bounds here.
bokanef971462014-10-13 22:58:321287 gfx::RectF scroll_rect(gfx::PointF(), BoundsForScrolling());
[email protected]adeda572014-01-31 00:49:471288
1289 if (scroll_rect.size().IsEmpty())
1290 return;
1291
miletusf57925d2014-10-01 19:38:131292 gfx::ScrollOffset current_offset;
[email protected]adeda572014-01-31 00:49:471293 for (LayerImpl const* current_layer = this;
aeliasd0070ba2015-01-31 13:44:491294 current_layer != scrollbar_clip_layer->parent();
[email protected]adeda572014-01-31 00:49:471295 current_layer = current_layer->parent()) {
aeliasd0070ba2015-01-31 13:44:491296 current_offset += current_layer->CurrentScrollOffset();
[email protected]adeda572014-01-31 00:49:471297 if (current_layer == page_scale_layer) {
aelias58eec0812014-12-04 01:04:401298 float scale_factor = layer_tree_impl()->current_page_scale_factor();
[email protected]adeda572014-01-31 00:49:471299 current_offset.Scale(scale_factor);
1300 scroll_rect.Scale(scale_factor);
[email protected]adeda572014-01-31 00:49:471301 }
1302 }
[email protected]adeda572014-01-31 00:49:471303
sataya.m68d7d9b42014-09-22 16:01:591304 bool scrollbar_needs_animation = false;
1305 scrollbar_needs_animation |= scrollbar_layer->SetVerticalAdjust(
1306 scrollbar_clip_layer->bounds_delta().y());
[email protected]adeda572014-01-31 00:49:471307 if (scrollbar_layer->orientation() == HORIZONTAL) {
1308 float visible_ratio = clip_rect.width() / scroll_rect.width();
sataya.m68d7d9b42014-09-22 16:01:591309 scrollbar_needs_animation |=
1310 scrollbar_layer->SetCurrentPos(current_offset.x());
1311 scrollbar_needs_animation |=
1312 scrollbar_layer->SetMaximum(scroll_rect.width() - clip_rect.width());
1313 scrollbar_needs_animation |=
1314 scrollbar_layer->SetVisibleToTotalLengthRatio(visible_ratio);
[email protected]adeda572014-01-31 00:49:471315 } else {
1316 float visible_ratio = clip_rect.height() / scroll_rect.height();
wjmaclean56f35ff2015-03-25 23:59:351317 bool y_offset_did_change =
sataya.m68d7d9b42014-09-22 16:01:591318 scrollbar_layer->SetCurrentPos(current_offset.y());
wjmaclean56f35ff2015-03-25 23:59:351319 scrollbar_needs_animation |= y_offset_did_change;
sataya.m68d7d9b42014-09-22 16:01:591320 scrollbar_needs_animation |=
1321 scrollbar_layer->SetMaximum(scroll_rect.height() - clip_rect.height());
1322 scrollbar_needs_animation |=
1323 scrollbar_layer->SetVisibleToTotalLengthRatio(visible_ratio);
wjmaclean56f35ff2015-03-25 23:59:351324 if (y_offset_did_change && layer_tree_impl()->IsActiveTree() &&
1325 this == layer_tree_impl()->InnerViewportScrollLayer()) {
1326 TRACE_COUNTER_ID1("cc", "scroll_offset_y", this->id(),
1327 current_offset.y());
1328 }
[email protected]adeda572014-01-31 00:49:471329 }
sataya.m7acc4b32014-09-23 15:37:211330 if (scrollbar_needs_animation) {
1331 layer_tree_impl()->set_needs_update_draw_properties();
1332 // TODO(wjmaclean) The scrollbar animator for the pinch-zoom scrollbars
1333 // should activate for every scroll on the main frame, not just the
1334 // scrolls that move the pinch virtual viewport (i.e. trigger from
1335 // either inner or outer viewport).
1336 if (scrollbar_animation_controller_) {
bokanc784a6f2015-01-28 04:11:501337 // Non-overlay scrollbars shouldn't trigger animations.
1338 if (scrollbar_layer->is_overlay_scrollbar())
sataya.m07f11a82014-10-07 14:29:181339 scrollbar_animation_controller_->DidScrollUpdate(on_resize);
sataya.m7acc4b32014-09-23 15:37:211340 }
[email protected]adeda572014-01-31 00:49:471341 }
[email protected]7aba6662013-03-12 10:17:341342}
1343
[email protected]7aba6662013-03-12 10:17:341344void LayerImpl::DidBecomeActive() {
[email protected]fea161872013-08-27 22:34:591345 if (layer_tree_impl_->settings().scrollbar_animator ==
ericrk7c030992015-02-20 01:39:381346 LayerTreeSettings::NO_ANIMATOR) {
[email protected]7aba6662013-03-12 10:17:341347 return;
[email protected]fea161872013-08-27 22:34:591348 }
[email protected]7aba6662013-03-12 10:17:341349
[email protected]adeda572014-01-31 00:49:471350 bool need_scrollbar_animation_controller = scrollable() && scrollbars_;
[email protected]fea161872013-08-27 22:34:591351 if (!need_scrollbar_animation_controller) {
danakjf446a072014-09-27 21:55:481352 scrollbar_animation_controller_ = nullptr;
[email protected]fea161872013-08-27 22:34:591353 return;
1354 }
1355
1356 if (scrollbar_animation_controller_)
1357 return;
1358
[email protected]930ff43b2014-05-02 05:24:001359 scrollbar_animation_controller_ =
1360 layer_tree_impl_->CreateScrollbarAnimationController(this);
[email protected]e45638c2013-01-17 22:01:401361}
[email protected]ad0250b2014-01-18 03:24:341362
[email protected]adeda572014-01-31 00:49:471363void LayerImpl::ClearScrollbars() {
1364 if (!scrollbars_)
1365 return;
1366
kulkarni.a4015690f12014-10-10 13:50:061367 scrollbars_.reset(nullptr);
[email protected]94f206c12012-08-25 00:09:141368}
1369
[email protected]adeda572014-01-31 00:49:471370void LayerImpl::AddScrollbar(ScrollbarLayerImplBase* layer) {
1371 DCHECK(layer);
1372 DCHECK(!scrollbars_ || scrollbars_->find(layer) == scrollbars_->end());
1373 if (!scrollbars_)
1374 scrollbars_.reset(new ScrollbarSet());
1375
1376 scrollbars_->insert(layer);
1377}
1378
1379void LayerImpl::RemoveScrollbar(ScrollbarLayerImplBase* layer) {
1380 DCHECK(scrollbars_);
1381 DCHECK(layer);
1382 DCHECK(scrollbars_->find(layer) != scrollbars_->end());
1383
1384 scrollbars_->erase(layer);
1385 if (scrollbars_->empty())
danakjf446a072014-09-27 21:55:481386 scrollbars_ = nullptr;
[email protected]adeda572014-01-31 00:49:471387}
1388
1389bool LayerImpl::HasScrollbar(ScrollbarOrientation orientation) const {
1390 if (!scrollbars_)
1391 return false;
1392
1393 for (ScrollbarSet::iterator it = scrollbars_->begin();
1394 it != scrollbars_->end();
1395 ++it)
1396 if ((*it)->orientation() == orientation)
1397 return true;
1398
1399 return false;
1400}
1401
sataya.m07f11a82014-10-07 14:29:181402void LayerImpl::ScrollbarParametersDidChange(bool on_resize) {
[email protected]adeda572014-01-31 00:49:471403 if (!scrollbars_)
1404 return;
1405
1406 for (ScrollbarSet::iterator it = scrollbars_->begin();
1407 it != scrollbars_->end();
aelias1505e722014-10-07 22:19:461408 ++it) {
1409 bool is_scroll_layer = (*it)->ScrollLayerId() == layer_id_;
1410 bool scroll_layer_resized = is_scroll_layer && on_resize;
1411 (*it)->ScrollbarParametersDidChange(scroll_layer_resized);
1412 }
[email protected]94f206c12012-08-25 00:09:141413}
1414
[email protected]ad0250b2014-01-18 03:24:341415void LayerImpl::SetNeedsPushProperties() {
1416 if (needs_push_properties_)
1417 return;
1418 if (!parent_should_know_need_push_properties() && parent_)
1419 parent_->AddDependentNeedsPushProperties();
1420 needs_push_properties_ = true;
1421}
1422
1423void LayerImpl::AddDependentNeedsPushProperties() {
1424 DCHECK_GE(num_dependents_need_push_properties_, 0);
1425
1426 if (!parent_should_know_need_push_properties() && parent_)
1427 parent_->AddDependentNeedsPushProperties();
1428
1429 num_dependents_need_push_properties_++;
1430}
1431
1432void LayerImpl::RemoveDependentNeedsPushProperties() {
1433 num_dependents_need_push_properties_--;
1434 DCHECK_GE(num_dependents_need_push_properties_, 0);
1435
1436 if (!parent_should_know_need_push_properties() && parent_)
1437 parent_->RemoveDependentNeedsPushProperties();
1438}
1439
vmpstrdcf21da2015-03-23 19:16:321440void LayerImpl::GetAllTilesAndPrioritiesForTracing(
1441 std::map<const Tile*, TilePriority>* tile_map) const {
vmpstrd7de03c2014-08-27 18:11:011442}
1443
ssid911e40e2015-02-09 17:55:201444void LayerImpl::AsValueInto(base::trace_event::TracedValue* state) const {
[email protected]f5ad4282014-02-15 14:23:161445 TracedValue::MakeDictIntoImplicitSnapshotWithCategory(
1446 TRACE_DISABLED_BY_DEFAULT("cc.debug"),
[email protected]b4dc36472014-02-26 02:48:251447 state,
1448 "cc::LayerImpl",
1449 LayerTypeAsString(),
1450 this);
[email protected]f6742f52013-05-08 23:52:221451 state->SetInteger("layer_id", id());
jungjik.lee50f9c8e2015-01-21 14:06:161452 MathUtil::AddToTracedValue("bounds", bounds_, state);
[email protected]d12aa932014-08-01 13:10:381453
danakj38955562014-09-13 02:56:431454 state->SetDouble("opacity", opacity());
1455
jungjik.lee50f9c8e2015-01-21 14:06:161456 MathUtil::AddToTracedValue("position", position_, state);
[email protected]d12aa932014-08-01 13:10:381457
[email protected]f6742f52013-05-08 23:52:221458 state->SetInteger("draws_content", DrawsContent());
[email protected]cdf5b952013-05-15 15:39:291459 state->SetInteger("gpu_memory_usage", GPUMemoryUsageInBytes());
[email protected]d12aa932014-08-01 13:10:381460
aeliasd0070ba2015-01-31 13:44:491461 MathUtil::AddToTracedValue(
1462 "scroll_offset", scroll_offset_ ? scroll_offset_->Current(IsActive())
1463 : gfx::ScrollOffset(),
1464 state);
1465
jungjik.lee50f9c8e2015-01-21 14:06:161466 MathUtil::AddToTracedValue("transform_origin", transform_origin_, state);
[email protected]8c5690222013-02-15 17:36:431467
[email protected]7aba6662013-03-12 10:17:341468 bool clipped;
[email protected]fa816c62013-03-18 04:24:211469 gfx::QuadF layer_quad = MathUtil::MapQuad(
[email protected]7aba6662013-03-12 10:17:341470 screen_space_transform(),
1471 gfx::QuadF(gfx::Rect(content_bounds())),
[email protected]fa816c62013-03-18 04:24:211472 &clipped);
jungjik.lee50f9c8e2015-01-21 14:06:161473 MathUtil::AddToTracedValue("layer_quad", layer_quad, state);
[email protected]78d78612013-09-12 18:04:041474 if (!touch_event_handler_region_.IsEmpty()) {
[email protected]d12aa932014-08-01 13:10:381475 state->BeginArray("touch_event_handler_region");
1476 touch_event_handler_region_.AsValueInto(state);
1477 state->EndArray();
[email protected]78d78612013-09-12 18:04:041478 }
1479 if (have_wheel_event_handlers_) {
1480 gfx::Rect wheel_rect(content_bounds());
1481 Region wheel_region(wheel_rect);
[email protected]d12aa932014-08-01 13:10:381482 state->BeginArray("wheel_event_handler_region");
1483 wheel_region.AsValueInto(state);
1484 state->EndArray();
[email protected]78d78612013-09-12 18:04:041485 }
[email protected]f998c532014-03-31 20:02:511486 if (have_scroll_event_handlers_) {
1487 gfx::Rect scroll_rect(content_bounds());
1488 Region scroll_region(scroll_rect);
[email protected]d12aa932014-08-01 13:10:381489 state->BeginArray("scroll_event_handler_region");
1490 scroll_region.AsValueInto(state);
1491 state->EndArray();
[email protected]f998c532014-03-31 20:02:511492 }
[email protected]78d78612013-09-12 18:04:041493 if (!non_fast_scrollable_region_.IsEmpty()) {
[email protected]d12aa932014-08-01 13:10:381494 state->BeginArray("non_fast_scrollable_region");
1495 non_fast_scrollable_region_.AsValueInto(state);
1496 state->EndArray();
[email protected]78d78612013-09-12 18:04:041497 }
rbyers18779d822015-02-05 06:22:061498 if (scroll_blocks_on_) {
1499 state->SetInteger("scroll_blocks_on", scroll_blocks_on_);
1500 }
[email protected]f6742f52013-05-08 23:52:221501
[email protected]d12aa932014-08-01 13:10:381502 state->BeginArray("children");
1503 for (size_t i = 0; i < children_.size(); ++i) {
1504 state->BeginDictionary();
1505 children_[i]->AsValueInto(state);
1506 state->EndDictionary();
1507 }
1508 state->EndArray();
1509 if (mask_layer_) {
1510 state->BeginDictionary("mask_layer");
1511 mask_layer_->AsValueInto(state);
1512 state->EndDictionary();
1513 }
1514 if (replica_layer_) {
1515 state->BeginDictionary("replica_layer");
1516 replica_layer_->AsValueInto(state);
1517 state->EndDictionary();
1518 }
[email protected]0e98cdd2013-08-23 00:44:301519
1520 if (scroll_parent_)
1521 state->SetInteger("scroll_parent", scroll_parent_->id());
1522
1523 if (clip_parent_)
1524 state->SetInteger("clip_parent", clip_parent_->id());
[email protected]c2a56ff2013-10-14 19:32:511525
1526 state->SetBoolean("can_use_lcd_text", can_use_lcd_text());
1527 state->SetBoolean("contents_opaque", contents_opaque());
[email protected]a1286742013-11-13 17:11:401528
[email protected]3d86dd7a2014-01-24 01:33:111529 state->SetBoolean(
1530 "has_animation_bounds",
1531 layer_animation_controller()->HasAnimationThatInflatesBounds());
1532
1533 gfx::BoxF box;
jungjik.lee50f9c8e2015-01-21 14:06:161534 if (LayerUtils::GetAnimationBounds(*this, &box))
1535 MathUtil::AddToTracedValue("animation_bounds", box, state);
[email protected]9f3be432013-12-03 03:53:221536
1537 if (debug_info_.get()) {
1538 std::string str;
1539 debug_info_->AppendAsTraceFormat(&str);
1540 base::JSONReader json_reader;
[email protected]685de6b12014-01-09 12:25:051541 scoped_ptr<base::Value> debug_info_value(json_reader.ReadToValue(str));
1542
[email protected]478224312014-01-10 17:33:471543 if (debug_info_value->IsType(base::Value::TYPE_DICTIONARY)) {
kulkarni.a4015690f12014-10-10 13:50:061544 base::DictionaryValue* dictionary_value = nullptr;
[email protected]685de6b12014-01-09 12:25:051545 bool converted_to_dictionary =
1546 debug_info_value->GetAsDictionary(&dictionary_value);
1547 DCHECK(converted_to_dictionary);
[email protected]d12aa932014-08-01 13:10:381548 for (base::DictionaryValue::Iterator it(*dictionary_value); !it.IsAtEnd();
1549 it.Advance()) {
1550 state->SetValue(it.key().data(), it.value().DeepCopy());
1551 }
[email protected]685de6b12014-01-09 12:25:051552 } else {
1553 NOTREACHED();
1554 }
[email protected]9f3be432013-12-03 03:53:221555 }
vmpstr3d1d72c2015-01-26 18:27:401556
1557 if (!frame_timing_requests_.empty()) {
1558 state->BeginArray("frame_timing_requests");
1559 for (const auto& request : frame_timing_requests_) {
1560 state->BeginDictionary();
1561 state->SetInteger("request_id", request.id());
1562 MathUtil::AddToTracedValue("request_rect", request.rect(), state);
1563 state->EndDictionary();
1564 }
1565 state->EndArray();
1566 }
[email protected]8c5690222013-02-15 17:36:431567}
1568
[email protected]390bb1ff2014-05-09 17:14:401569bool LayerImpl::IsDrawnRenderSurfaceLayerListMember() const {
1570 return draw_properties_.last_drawn_render_surface_layer_list_id ==
1571 layer_tree_impl_->current_render_surface_list_id();
1572}
1573
[email protected]cdf5b952013-05-15 15:39:291574size_t LayerImpl::GPUMemoryUsageInBytes() const { return 0; }
1575
[email protected]5e5648a2013-11-18 00:39:331576void LayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) {
1577 benchmark->RunOnLayer(this);
1578}
[email protected]749cbc62014-07-10 01:06:351579
[email protected]ad63b2f2014-08-11 17:39:541580int LayerImpl::NumDescendantsThatDrawContent() const {
1581 return num_descendants_that_draw_content_;
1582}
1583
[email protected]749cbc62014-07-10 01:06:351584void LayerImpl::NotifyAnimationFinished(
1585 base::TimeTicks monotonic_time,
dstockwellaf2a117b2014-10-16 21:42:291586 Animation::TargetProperty target_property,
1587 int group) {
ericrk7c030992015-02-20 01:39:381588 if (target_property == Animation::SCROLL_OFFSET)
[email protected]749cbc62014-07-10 01:06:351589 layer_tree_impl_->InputScrollAnimationFinished();
1590}
1591
awoloszyne83f28c2014-12-22 15:40:001592void LayerImpl::SetHasRenderSurface(bool should_have_render_surface) {
1593 if (!!render_surface() == should_have_render_surface)
1594 return;
1595
1596 SetNeedsPushProperties();
1597 layer_tree_impl()->set_needs_update_draw_properties();
1598 if (should_have_render_surface) {
1599 render_surface_ = make_scoped_ptr(new RenderSurfaceImpl(this));
1600 return;
1601 }
1602 render_surface_.reset();
1603}
1604
daplatz350219e2015-03-04 19:04:411605Region LayerImpl::GetInvalidationRegion() {
1606 return Region(update_rect_);
1607}
1608
vmpstrd46a7ac2015-03-18 01:11:121609gfx::Rect LayerImpl::GetEnclosingRectInTargetSpace() const {
1610 return MathUtil::MapEnclosingClippedRect(
1611 draw_properties_.target_space_transform,
1612 gfx::Rect(draw_properties_.content_bounds));
1613}
1614
1615gfx::Rect LayerImpl::GetScaledEnclosingRectInTargetSpace(float scale) const {
1616 gfx::Transform scaled_draw_transform =
1617 draw_properties_.target_space_transform;
1618 scaled_draw_transform.Scale(SK_MScalar1 / scale, SK_MScalar1 / scale);
1619 gfx::Size scaled_content_bounds =
1620 gfx::ToCeiledSize(gfx::ScaleSize(content_bounds(), scale));
1621 return MathUtil::MapEnclosingClippedRect(scaled_draw_transform,
1622 gfx::Rect(scaled_content_bounds));
1623}
1624
[email protected]bc5e77c2012-11-05 20:00:491625} // namespace cc