blob: 0f92266856ede2ca1f32d04182120ca0fafbe86a [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]89e8267a2013-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]9be1adc82014-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);
enneb79d5f142015-04-23 19:59:55355 if (fill_rect.IsEmpty())
356 return;
danakj069ac122015-02-12 00:59:22357 gfx::Rect visible_fill_rect =
358 gfx::IntersectRects(visible_quad_rect, fill_rect);
359 DebugBorderDrawQuad* fill_quad =
360 render_pass->CreateAndAppendDrawQuad<DebugBorderDrawQuad>();
361 fill_quad->SetNew(shared_quad_state, fill_rect, visible_fill_rect,
362 fill_color, fill_width);
363 }
[email protected]7aba6662013-03-12 10:17:34364}
365
366bool LayerImpl::HasDelegatedContent() const {
367 return false;
368}
369
370bool LayerImpl::HasContributingDelegatedRenderPasses() const {
371 return false;
372}
373
[email protected]0cd7d6f72014-08-22 14:50:51374RenderPassId LayerImpl::FirstContributingRenderPassId() const {
375 return RenderPassId(0, 0);
[email protected]7aba6662013-03-12 10:17:34376}
377
[email protected]0cd7d6f72014-08-22 14:50:51378RenderPassId LayerImpl::NextContributingRenderPassId(RenderPassId id) const {
379 return RenderPassId(0, 0);
[email protected]7aba6662013-03-12 10:17:34380}
381
ennef6f3fbba42014-10-16 18:16:49382void LayerImpl::GetContentsResourceId(ResourceProvider::ResourceId* resource_id,
383 gfx::Size* resource_size) const {
[email protected]7aba6662013-03-12 10:17:34384 NOTREACHED();
ennef6f3fbba42014-10-16 18:16:49385 *resource_id = 0;
[email protected]7aba6662013-03-12 10:17:34386}
387
[email protected]3244c9132014-01-23 10:39:12388gfx::Vector2dF LayerImpl::ScrollBy(const gfx::Vector2dF& scroll) {
aeliasd0070ba2015-01-31 13:44:49389 gfx::ScrollOffset adjusted_scroll(scroll);
aeliasaf915a882014-10-14 04:12:04390 if (layer_tree_impl()->settings().use_pinch_virtual_viewport) {
391 if (!user_scrollable_horizontal_)
392 adjusted_scroll.set_x(0);
393 if (!user_scrollable_vertical_)
394 adjusted_scroll.set_y(0);
395 }
[email protected]d30700f12013-07-31 08:21:01396 DCHECK(scrollable());
aeliasd0070ba2015-01-31 13:44:49397 gfx::ScrollOffset old_offset = CurrentScrollOffset();
398 gfx::ScrollOffset new_offset =
399 ClampScrollOffsetToLimits(old_offset + adjusted_scroll);
400 SetCurrentScrollOffset(new_offset);
[email protected]adeda572014-01-31 00:49:47401
aeliasd0070ba2015-01-31 13:44:49402 gfx::ScrollOffset unscrolled =
403 old_offset + gfx::ScrollOffset(scroll) - new_offset;
404 return gfx::Vector2dF(unscrolled.x(), unscrolled.y());
[email protected]7aba6662013-03-12 10:17:34405}
406
[email protected]adeda572014-01-31 00:49:47407void LayerImpl::SetScrollClipLayer(int scroll_clip_layer_id) {
408 scroll_clip_layer_ = layer_tree_impl()->LayerById(scroll_clip_layer_id);
409}
410
timav3ca696932014-10-15 02:19:04411bool LayerImpl::user_scrollable(ScrollbarOrientation orientation) const {
412 return (orientation == HORIZONTAL) ? user_scrollable_horizontal_
413 : user_scrollable_vertical_;
414}
415
[email protected]58241dc2013-08-20 01:39:25416void LayerImpl::ApplySentScrollDeltasFromAbortedCommit() {
[email protected]3519b872013-07-30 07:17:50417 DCHECK(layer_tree_impl()->IsActiveTree());
aeliasd0070ba2015-01-31 13:44:49418 scroll_offset_->AbortCommit();
[email protected]58241dc2013-08-20 01:39:25419}
420
[email protected]5ff3c9782013-04-29 17:35:12421InputHandler::ScrollStatus LayerImpl::TryScroll(
[email protected]14bc5d682014-01-17 07:26:47422 const gfx::PointF& screen_space_point,
rbyers18779d822015-02-05 06:22:06423 InputHandler::ScrollInputType type,
424 ScrollBlocksOn effective_block_mode) const {
[email protected]7aba6662013-03-12 10:17:34425 if (should_scroll_on_main_thread()) {
[email protected]ed511b8d2013-03-25 03:29:29426 TRACE_EVENT0("cc", "LayerImpl::TryScroll: Failed ShouldScrollOnMainThread");
ericrk7c030992015-02-20 01:39:38427 return InputHandler::SCROLL_ON_MAIN_THREAD;
[email protected]7aba6662013-03-12 10:17:34428 }
429
430 if (!screen_space_transform().IsInvertible()) {
[email protected]ed511b8d2013-03-25 03:29:29431 TRACE_EVENT0("cc", "LayerImpl::TryScroll: Ignored NonInvertibleTransform");
ericrk7c030992015-02-20 01:39:38432 return InputHandler::SCROLL_IGNORED;
[email protected]7aba6662013-03-12 10:17:34433 }
434
435 if (!non_fast_scrollable_region().IsEmpty()) {
436 bool clipped = false;
437 gfx::Transform inverse_screen_space_transform(
438 gfx::Transform::kSkipInitialization);
439 if (!screen_space_transform().GetInverse(&inverse_screen_space_transform)) {
440 // TODO(shawnsingh): We shouldn't be applying a projection if screen space
441 // transform is uninvertible here. Perhaps we should be returning
ericrk7c030992015-02-20 01:39:38442 // SCROLL_ON_MAIN_THREAD in this case?
[email protected]3dce37232012-11-15 01:47:44443 }
444
[email protected]7aba6662013-03-12 10:17:34445 gfx::PointF hit_test_point_in_content_space =
[email protected]fa816c62013-03-18 04:24:21446 MathUtil::ProjectPoint(inverse_screen_space_transform,
[email protected]7aba6662013-03-12 10:17:34447 screen_space_point,
[email protected]fa816c62013-03-18 04:24:21448 &clipped);
[email protected]7aba6662013-03-12 10:17:34449 gfx::PointF hit_test_point_in_layer_space =
450 gfx::ScalePoint(hit_test_point_in_content_space,
451 1.f / contents_scale_x(),
452 1.f / contents_scale_y());
453 if (!clipped &&
454 non_fast_scrollable_region().Contains(
455 gfx::ToRoundedPoint(hit_test_point_in_layer_space))) {
456 TRACE_EVENT0("cc",
[email protected]ed511b8d2013-03-25 03:29:29457 "LayerImpl::tryScroll: Failed NonFastScrollableRegion");
ericrk7c030992015-02-20 01:39:38458 return InputHandler::SCROLL_ON_MAIN_THREAD;
[email protected]3dce37232012-11-15 01:47:44459 }
[email protected]7aba6662013-03-12 10:17:34460 }
[email protected]3dce37232012-11-15 01:47:44461
rbyers18779d822015-02-05 06:22:06462 if (have_scroll_event_handlers() &&
ericrk7c030992015-02-20 01:39:38463 effective_block_mode & SCROLL_BLOCKS_ON_SCROLL_EVENT) {
rbyers18779d822015-02-05 06:22:06464 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Failed ScrollEventHandlers");
ericrk7c030992015-02-20 01:39:38465 return InputHandler::SCROLL_ON_MAIN_THREAD;
rbyers18779d822015-02-05 06:22:06466 }
467
ericrk7c030992015-02-20 01:39:38468 if (type == InputHandler::WHEEL && have_wheel_event_handlers() &&
469 effective_block_mode & SCROLL_BLOCKS_ON_WHEEL_EVENT) {
[email protected]ed511b8d2013-03-25 03:29:29470 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Failed WheelEventHandlers");
ericrk7c030992015-02-20 01:39:38471 return InputHandler::SCROLL_ON_MAIN_THREAD;
[email protected]7aba6662013-03-12 10:17:34472 }
473
474 if (!scrollable()) {
475 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Ignored not scrollable");
ericrk7c030992015-02-20 01:39:38476 return InputHandler::SCROLL_IGNORED;
[email protected]7aba6662013-03-12 10:17:34477 }
478
miletusf57925d2014-10-01 19:38:13479 gfx::ScrollOffset max_scroll_offset = MaxScrollOffset();
[email protected]adeda572014-01-31 00:49:47480 if (max_scroll_offset.x() <= 0 && max_scroll_offset.y() <= 0) {
[email protected]7aba6662013-03-12 10:17:34481 TRACE_EVENT0("cc",
482 "LayerImpl::tryScroll: Ignored. Technically scrollable,"
483 " but has no affordance in either direction.");
ericrk7c030992015-02-20 01:39:38484 return InputHandler::SCROLL_IGNORED;
[email protected]7aba6662013-03-12 10:17:34485 }
486
ericrk7c030992015-02-20 01:39:38487 return InputHandler::SCROLL_STARTED;
[email protected]3dce37232012-11-15 01:47:44488}
489
[email protected]7aba6662013-03-12 10:17:34490gfx::Rect LayerImpl::LayerRectToContentRect(
491 const gfx::RectF& layer_rect) const {
492 gfx::RectF content_rect =
493 gfx::ScaleRect(layer_rect, contents_scale_x(), contents_scale_y());
494 // Intersect with content rect to avoid the extra pixel because for some
495 // values x and y, ceil((x / y) * y) may be x + 1.
496 content_rect.Intersect(gfx::Rect(content_bounds()));
497 return gfx::ToEnclosingRect(content_rect);
[email protected]b5b1fce2012-12-12 22:49:36498}
499
[email protected]7aba6662013-03-12 10:17:34500skia::RefPtr<SkPicture> LayerImpl::GetPicture() {
501 return skia::RefPtr<SkPicture>();
[email protected]76481592012-09-21 16:47:06502}
503
[email protected]7aba6662013-03-12 10:17:34504scoped_ptr<LayerImpl> LayerImpl::CreateLayerImpl(LayerTreeImpl* tree_impl) {
aeliasd0070ba2015-01-31 13:44:49505 return LayerImpl::Create(tree_impl, layer_id_, scroll_offset_);
[email protected]94f206c12012-08-25 00:09:14506}
507
[email protected]7aba6662013-03-12 10:17:34508void LayerImpl::PushPropertiesTo(LayerImpl* layer) {
[email protected]a2566412014-06-05 03:14:20509 layer->SetTransformOrigin(transform_origin_);
[email protected]7aba6662013-03-12 10:17:34510 layer->SetBackgroundColor(background_color_);
511 layer->SetBounds(bounds_);
512 layer->SetContentBounds(content_bounds());
513 layer->SetContentsScale(contents_scale_x(), contents_scale_y());
[email protected]7aba6662013-03-12 10:17:34514 layer->SetDoubleSided(double_sided_);
515 layer->SetDrawCheckerboardForMissingTiles(
516 draw_checkerboard_for_missing_tiles_);
[email protected]7aba6662013-03-12 10:17:34517 layer->SetDrawsContent(DrawsContent());
[email protected]c0ae06c12013-06-24 18:32:19518 layer->SetHideLayerAndSubtree(hide_layer_and_subtree_);
enneb723b4e22015-02-19 19:47:46519 layer->SetHasRenderSurface(!!render_surface() || layer->HasCopyRequest());
[email protected]7aba6662013-03-12 10:17:34520 layer->SetFilters(filters());
[email protected]7aba6662013-03-12 10:17:34521 layer->SetBackgroundFilters(background_filters());
522 layer->SetMasksToBounds(masks_to_bounds_);
523 layer->SetShouldScrollOnMainThread(should_scroll_on_main_thread_);
524 layer->SetHaveWheelEventHandlers(have_wheel_event_handlers_);
[email protected]f998c532014-03-31 20:02:51525 layer->SetHaveScrollEventHandlers(have_scroll_event_handlers_);
rbyers18779d822015-02-05 06:22:06526 layer->SetScrollBlocksOn(scroll_blocks_on_);
[email protected]7aba6662013-03-12 10:17:34527 layer->SetNonFastScrollableRegion(non_fast_scrollable_region_);
528 layer->SetTouchEventHandlerRegion(touch_event_handler_region_);
529 layer->SetContentsOpaque(contents_opaque_);
[email protected]43615872013-03-13 16:35:17530 layer->SetOpacity(opacity_);
[email protected]7bbeaf4e2013-11-26 10:27:22531 layer->SetBlendMode(blend_mode_);
532 layer->SetIsRootForIsolatedGroup(is_root_for_isolated_group_);
[email protected]7aba6662013-03-12 10:17:34533 layer->SetPosition(position_);
534 layer->SetIsContainerForFixedPositionLayers(
535 is_container_for_fixed_position_layers_);
[email protected]fe956c9c42013-04-09 04:26:33536 layer->SetPositionConstraint(position_constraint_);
[email protected]56fffdd2014-02-11 19:50:57537 layer->SetShouldFlattenTransform(should_flatten_transform_);
ennee95b1542015-04-20 20:35:50538 layer->set_should_flatten_transform_from_property_tree(
539 should_flatten_transform_from_property_tree_);
[email protected]7aba6662013-03-12 10:17:34540 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_);
[email protected]08bdf1b2014-04-16 23:23:29541 layer->SetTransformAndInvertibility(transform_, transform_is_invertible_);
[email protected]9bd1cb52013-01-03 22:26:33542
[email protected]adeda572014-01-31 00:49:47543 layer->SetScrollClipLayer(scroll_clip_layer_ ? scroll_clip_layer_->id()
544 : Layer::INVALID_ID);
[email protected]59a7d552013-10-22 03:36:43545 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_);
546 layer->set_user_scrollable_vertical(user_scrollable_vertical_);
bokanc687507f2014-11-04 23:41:42547
miletusff93ab72015-01-30 04:30:44548 layer->SetScrollCompensationAdjustment(scroll_compensation_adjustment_);
bokanc687507f2014-11-04 23:41:42549
aeliasd0070ba2015-01-31 13:44:49550 layer->PushScrollOffset(nullptr);
551
[email protected]a9d4d4f2014-06-19 06:49:28552 layer->Set3dSortingContextId(sorting_context_id_);
[email protected]ad63b2f2014-08-11 17:39:54553 layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_);
[email protected]b34c97982013-08-24 15:21:38554
ennee95b1542015-04-20 20:35:50555 layer->set_transform_tree_index(transform_tree_index_);
556 layer->set_opacity_tree_index(opacity_tree_index_);
557 layer->set_clip_tree_index(clip_tree_index_);
558 layer->set_offset_to_transform_parent(offset_to_transform_parent_);
559
kulkarni.a4015690f12014-10-10 13:50:06560 LayerImpl* scroll_parent = nullptr;
[email protected]d097e242014-02-28 21:51:11561 if (scroll_parent_) {
[email protected]0e98cdd2013-08-23 00:44:30562 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id());
[email protected]d097e242014-02-28 21:51:11563 DCHECK(scroll_parent);
564 }
[email protected]0e98cdd2013-08-23 00:44:30565
566 layer->SetScrollParent(scroll_parent);
567 if (scroll_children_) {
568 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>;
569 for (std::set<LayerImpl*>::iterator it = scroll_children_->begin();
[email protected]d097e242014-02-28 21:51:11570 it != scroll_children_->end();
571 ++it) {
572 DCHECK_EQ((*it)->scroll_parent(), this);
573 LayerImpl* scroll_child =
574 layer->layer_tree_impl()->LayerById((*it)->id());
575 DCHECK(scroll_child);
576 scroll_children->insert(scroll_child);
577 }
[email protected]0e98cdd2013-08-23 00:44:30578 layer->SetScrollChildren(scroll_children);
[email protected]d097e242014-02-28 21:51:11579 } else {
kulkarni.a4015690f12014-10-10 13:50:06580 layer->SetScrollChildren(nullptr);
[email protected]0e98cdd2013-08-23 00:44:30581 }
582
kulkarni.a4015690f12014-10-10 13:50:06583 LayerImpl* clip_parent = nullptr;
[email protected]0e98cdd2013-08-23 00:44:30584 if (clip_parent_) {
585 clip_parent = layer->layer_tree_impl()->LayerById(
586 clip_parent_->id());
[email protected]d097e242014-02-28 21:51:11587 DCHECK(clip_parent);
[email protected]0e98cdd2013-08-23 00:44:30588 }
589
590 layer->SetClipParent(clip_parent);
591 if (clip_children_) {
592 std::set<LayerImpl*>* clip_children = new std::set<LayerImpl*>;
593 for (std::set<LayerImpl*>::iterator it = clip_children_->begin();
594 it != clip_children_->end(); ++it)
595 clip_children->insert(layer->layer_tree_impl()->LayerById((*it)->id()));
596 layer->SetClipChildren(clip_children);
[email protected]d097e242014-02-28 21:51:11597 } else {
kulkarni.a4015690f12014-10-10 13:50:06598 layer->SetClipChildren(nullptr);
[email protected]0e98cdd2013-08-23 00:44:30599 }
600
[email protected]0e5f7142013-05-24 06:45:36601 layer->PassCopyRequests(&copy_requests_);
[email protected]18a70192013-04-26 16:18:25602
[email protected]7aba6662013-03-12 10:17:34603 // If the main thread commits multiple times before the impl thread actually
604 // draws, then damage tracking will become incorrect if we simply clobber the
[email protected]ed511b8d2013-03-25 03:29:29605 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e.
[email protected]7aba6662013-03-12 10:17:34606 // union) any update changes that have occurred on the main thread.
607 update_rect_.Union(layer->update_rect());
[email protected]ad0250b2014-01-18 03:24:34608 layer->SetUpdateRect(update_rect_);
[email protected]7aba6662013-03-12 10:17:34609
[email protected]7aba6662013-03-12 10:17:34610 layer->SetStackingOrderChanged(stacking_order_changed_);
[email protected]ad0250b2014-01-18 03:24:34611 layer->SetDebugInfo(debug_info_);
[email protected]7aba6662013-03-12 10:17:34612
vmpstr3d1d72c2015-01-26 18:27:40613 if (frame_timing_requests_dirty_) {
614 layer->PassFrameTimingRequests(&frame_timing_requests_);
615 frame_timing_requests_dirty_ = false;
616 }
617
[email protected]7aba6662013-03-12 10:17:34618 // Reset any state that should be cleared for the next update.
619 stacking_order_changed_ = false;
danakj19f0c9e2014-10-11 03:24:42620 update_rect_ = gfx::Rect();
[email protected]ad0250b2014-01-18 03:24:34621 needs_push_properties_ = false;
622 num_dependents_need_push_properties_ = 0;
[email protected]caa567d2012-12-20 07:56:16623}
624
[email protected]fef74fd2014-02-27 06:28:17625gfx::Vector2dF LayerImpl::FixedContainerSizeDelta() const {
626 if (!scroll_clip_layer_)
627 return gfx::Vector2dF();
628
[email protected]587941d2014-08-22 01:40:01629 gfx::Vector2dF delta_from_scroll = scroll_clip_layer_->bounds_delta();
bokan8273d962014-10-22 02:40:27630
631 // In virtual-viewport mode, we don't need to compensate for pinch zoom or
632 // scale since the fixed container is the outer viewport, which sits below
633 // the page scale.
634 if (layer_tree_impl()->settings().use_pinch_virtual_viewport)
635 return delta_from_scroll;
636
aelias58eec0812014-12-04 01:04:40637 float scale_delta = layer_tree_impl()->page_scale_delta();
638 float scale = layer_tree_impl()->current_page_scale_factor() /
639 layer_tree_impl()->page_scale_delta();
640
[email protected]fef74fd2014-02-27 06:28:17641 delta_from_scroll.Scale(1.f / scale);
642
643 // The delta-from-pinch component requires some explanation: A viewport of
644 // size (w,h) will appear to be size (w/s,h/s) under scale s in the content
645 // space. If s -> s' on the impl thread, where s' = s * ds, then the apparent
646 // viewport size change in the content space due to ds is:
647 //
648 // (w/s',h/s') - (w/s,h/s) = (w,h)(1/s' - 1/s) = (w,h)(1 - ds)/(s ds)
649 //
650 gfx::Vector2dF delta_from_pinch =
bokancccfde72014-10-08 15:15:22651 gfx::Rect(scroll_clip_layer_->bounds()).bottom_right() - gfx::PointF();
[email protected]fef74fd2014-02-27 06:28:17652 delta_from_pinch.Scale((1.f - scale_delta) / (scale * scale_delta));
653
654 return delta_from_scroll + delta_from_pinch;
655}
656
[email protected]7aba6662013-03-12 10:17:34657base::DictionaryValue* LayerImpl::LayerTreeAsJson() const {
[email protected]7aba6662013-03-12 10:17:34658 base::DictionaryValue* result = new base::DictionaryValue;
659 result->SetString("LayerType", LayerTypeAsString());
660
[email protected]46c76952013-07-10 00:21:45661 base::ListValue* list = new base::ListValue;
bokancccfde72014-10-08 15:15:22662 list->AppendInteger(bounds().width());
663 list->AppendInteger(bounds().height());
[email protected]7aba6662013-03-12 10:17:34664 result->Set("Bounds", list);
665
666 list = new base::ListValue;
667 list->AppendDouble(position_.x());
668 list->AppendDouble(position_.y());
669 result->Set("Position", list);
670
671 const gfx::Transform& gfx_transform = draw_properties_.target_space_transform;
672 double transform[16];
673 gfx_transform.matrix().asColMajord(transform);
674 list = new base::ListValue;
675 for (int i = 0; i < 16; ++i)
676 list->AppendDouble(transform[i]);
677 result->Set("DrawTransform", list);
678
679 result->SetBoolean("DrawsContent", draws_content_);
[email protected]a9d4d4f2014-06-19 06:49:28680 result->SetBoolean("Is3dSorted", Is3dSorted());
ericrk7c030992015-02-20 01:39:38681 result->SetDouble("OPACITY", opacity());
[email protected]46c76952013-07-10 00:21:45682 result->SetBoolean("ContentsOpaque", contents_opaque_);
[email protected]7aba6662013-03-12 10:17:34683
[email protected]adeda572014-01-31 00:49:47684 if (scrollable())
685 result->SetBoolean("Scrollable", true);
[email protected]d993e032013-06-07 00:16:16686
[email protected]9d161d22013-10-29 20:54:10687 if (have_wheel_event_handlers_)
688 result->SetBoolean("WheelHandler", have_wheel_event_handlers_);
[email protected]f998c532014-03-31 20:02:51689 if (have_scroll_event_handlers_)
690 result->SetBoolean("ScrollHandler", have_scroll_event_handlers_);
[email protected]9d161d22013-10-29 20:54:10691 if (!touch_event_handler_region_.IsEmpty()) {
692 scoped_ptr<base::Value> region = touch_event_handler_region_.AsValue();
693 result->Set("TouchRegion", region.release());
694 }
695
rbyers18779d822015-02-05 06:22:06696 if (scroll_blocks_on_) {
697 list = new base::ListValue;
ericrk7c030992015-02-20 01:39:38698 if (scroll_blocks_on_ & SCROLL_BLOCKS_ON_START_TOUCH)
rbyers18779d822015-02-05 06:22:06699 list->AppendString("StartTouch");
ericrk7c030992015-02-20 01:39:38700 if (scroll_blocks_on_ & SCROLL_BLOCKS_ON_WHEEL_EVENT)
rbyers18779d822015-02-05 06:22:06701 list->AppendString("WheelEvent");
ericrk7c030992015-02-20 01:39:38702 if (scroll_blocks_on_ & SCROLL_BLOCKS_ON_SCROLL_EVENT)
rbyers18779d822015-02-05 06:22:06703 list->AppendString("ScrollEvent");
704 result->Set("ScrollBlocksOn", list);
705 }
706
[email protected]7aba6662013-03-12 10:17:34707 list = new base::ListValue;
708 for (size_t i = 0; i < children_.size(); ++i)
709 list->Append(children_[i]->LayerTreeAsJson());
710 result->Set("Children", list);
711
712 return result;
[email protected]b9dcf43a2013-01-09 00:15:29713}
714
[email protected]7aba6662013-03-12 10:17:34715void LayerImpl::SetStackingOrderChanged(bool stacking_order_changed) {
716 if (stacking_order_changed) {
717 stacking_order_changed_ = true;
718 NoteLayerPropertyChangedForSubtree();
719 }
[email protected]aedf4e52013-01-09 23:24:44720}
721
[email protected]7aba6662013-03-12 10:17:34722void LayerImpl::NoteLayerPropertyChanged() {
723 layer_property_changed_ = true;
724 layer_tree_impl()->set_needs_update_draw_properties();
[email protected]ad0250b2014-01-18 03:24:34725 SetNeedsPushProperties();
[email protected]48871fc2013-01-23 07:36:51726}
727
[email protected]7aba6662013-03-12 10:17:34728void LayerImpl::NoteLayerPropertyChangedForSubtree() {
[email protected]ad0250b2014-01-18 03:24:34729 layer_property_changed_ = true;
730 layer_tree_impl()->set_needs_update_draw_properties();
731 for (size_t i = 0; i < children_.size(); ++i)
732 children_[i]->NoteLayerPropertyChangedForDescendantsInternal();
733 SetNeedsPushProperties();
734}
735
736void LayerImpl::NoteLayerPropertyChangedForDescendantsInternal() {
737 layer_property_changed_ = true;
738 for (size_t i = 0; i < children_.size(); ++i)
739 children_[i]->NoteLayerPropertyChangedForDescendantsInternal();
[email protected]94f206c12012-08-25 00:09:14740}
741
[email protected]7aba6662013-03-12 10:17:34742void LayerImpl::NoteLayerPropertyChangedForDescendants() {
743 layer_tree_impl()->set_needs_update_draw_properties();
744 for (size_t i = 0; i < children_.size(); ++i)
[email protected]ad0250b2014-01-18 03:24:34745 children_[i]->NoteLayerPropertyChangedForDescendantsInternal();
746 SetNeedsPushProperties();
[email protected]7aba6662013-03-12 10:17:34747}
[email protected]94f206c12012-08-25 00:09:14748
danakjf9427572015-04-24 22:19:02749#if DCHECK_IS_ON()
750// Verify that the resource id is valid.
751static ResourceProvider::ResourceId ValidateResource(
752 const ResourceProvider* provider,
753 ResourceProvider::ResourceId id) {
754 provider->ValidateResource(id);
755 return id;
756}
757#endif
758
759void LayerImpl::ValidateQuadResourcesInternal(DrawQuad* quad) const {
760#if DCHECK_IS_ON()
761 quad->IterateResources(
762 base::Bind(&ValidateResource, layer_tree_impl_->resource_provider()));
763#endif
764}
765
[email protected]7aba6662013-03-12 10:17:34766const char* LayerImpl::LayerTypeAsString() const {
[email protected]f256b7fd2013-05-15 01:49:30767 return "cc::LayerImpl";
[email protected]7aba6662013-03-12 10:17:34768}
[email protected]94f206c12012-08-25 00:09:14769
[email protected]7aba6662013-03-12 10:17:34770void LayerImpl::ResetAllChangeTrackingForSubtree() {
771 layer_property_changed_ = false;
[email protected]7aba6662013-03-12 10:17:34772
danakj19f0c9e2014-10-11 03:24:42773 update_rect_ = gfx::Rect();
[email protected]cfa7fd922014-04-29 11:50:03774 damage_rect_ = gfx::RectF();
[email protected]7aba6662013-03-12 10:17:34775
awoloszyne83f28c2014-12-22 15:40:00776 if (render_surface_)
777 render_surface_->ResetPropertyChangedFlag();
[email protected]7aba6662013-03-12 10:17:34778
779 if (mask_layer_)
780 mask_layer_->ResetAllChangeTrackingForSubtree();
781
782 if (replica_layer_) {
783 // This also resets the replica mask, if it exists.
784 replica_layer_->ResetAllChangeTrackingForSubtree();
785 }
786
787 for (size_t i = 0; i < children_.size(); ++i)
788 children_[i]->ResetAllChangeTrackingForSubtree();
[email protected]ad0250b2014-01-18 03:24:34789
790 needs_push_properties_ = false;
791 num_dependents_need_push_properties_ = 0;
[email protected]7aba6662013-03-12 10:17:34792}
793
miletusf57925d2014-10-01 19:38:13794gfx::ScrollOffset LayerImpl::ScrollOffsetForAnimation() const {
aeliasd0070ba2015-01-31 13:44:49795 return CurrentScrollOffset();
[email protected]b8384e22013-12-03 02:20:48796}
797
[email protected]b4c6d812013-10-03 15:48:56798void LayerImpl::OnFilterAnimated(const FilterOperations& filters) {
799 SetFilters(filters);
800}
801
[email protected]7aba6662013-03-12 10:17:34802void LayerImpl::OnOpacityAnimated(float opacity) {
803 SetOpacity(opacity);
804}
805
806void LayerImpl::OnTransformAnimated(const gfx::Transform& transform) {
807 SetTransform(transform);
808}
809
miletusf57925d2014-10-01 19:38:13810void LayerImpl::OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) {
[email protected]b8384e22013-12-03 02:20:48811 // Only layers in the active tree should need to do anything here, since
812 // layers in the pending tree will find out about these changes as a
aeliasd0070ba2015-01-31 13:44:49813 // result of the shared SyncedProperty.
[email protected]b8384e22013-12-03 02:20:48814 if (!IsActive())
815 return;
816
aeliasd0070ba2015-01-31 13:44:49817 SetCurrentScrollOffset(scroll_offset);
[email protected]b8384e22013-12-03 02:20:48818
819 layer_tree_impl_->DidAnimateScrollOffset();
820}
821
[email protected]1c24cf2962013-11-18 23:34:51822void LayerImpl::OnAnimationWaitingForDeletion() {}
823
[email protected]7aba6662013-03-12 10:17:34824bool LayerImpl::IsActive() const {
825 return layer_tree_impl_->IsActiveTree();
826}
827
bokancccfde72014-10-08 15:15:22828gfx::Size LayerImpl::bounds() const {
bokanef971462014-10-13 22:58:32829 gfx::Vector2d delta = gfx::ToCeiledVector2d(bounds_delta_);
830 return gfx::Size(bounds_.width() + delta.x(),
831 bounds_.height() + delta.y());
832}
833
834gfx::SizeF LayerImpl::BoundsForScrolling() const {
835 return gfx::SizeF(bounds_.width() + bounds_delta_.x(),
836 bounds_.height() + bounds_delta_.y());
[email protected]fef74fd2014-02-27 06:28:17837}
838
[email protected]64348ea2014-01-29 22:58:26839void LayerImpl::SetBounds(const gfx::Size& bounds) {
[email protected]7aba6662013-03-12 10:17:34840 if (bounds_ == bounds)
841 return;
842
843 bounds_ = bounds;
[email protected]fef74fd2014-02-27 06:28:17844
sataya.m07f11a82014-10-07 14:29:18845 ScrollbarParametersDidChange(true);
[email protected]fef74fd2014-02-27 06:28:17846 if (masks_to_bounds())
847 NoteLayerPropertyChangedForSubtree();
848 else
849 NoteLayerPropertyChanged();
850}
851
[email protected]587941d2014-08-22 01:40:01852void LayerImpl::SetBoundsDelta(const gfx::Vector2dF& bounds_delta) {
853 if (bounds_delta_ == bounds_delta)
[email protected]fef74fd2014-02-27 06:28:17854 return;
855
[email protected]587941d2014-08-22 01:40:01856 bounds_delta_ = bounds_delta;
[email protected]7aba6662013-03-12 10:17:34857
aelias1505e722014-10-07 22:19:46858 ScrollbarParametersDidChange(true);
[email protected]7aba6662013-03-12 10:17:34859 if (masks_to_bounds())
860 NoteLayerPropertyChangedForSubtree();
861 else
862 NoteLayerPropertyChanged();
863}
864
865void LayerImpl::SetMaskLayer(scoped_ptr<LayerImpl> mask_layer) {
866 int new_layer_id = mask_layer ? mask_layer->id() : -1;
867
868 if (mask_layer) {
869 DCHECK_EQ(layer_tree_impl(), mask_layer->layer_tree_impl());
870 DCHECK_NE(new_layer_id, mask_layer_id_);
871 } else if (new_layer_id == mask_layer_id_) {
872 return;
873 }
874
875 mask_layer_ = mask_layer.Pass();
876 mask_layer_id_ = new_layer_id;
877 if (mask_layer_)
[email protected]ad0250b2014-01-18 03:24:34878 mask_layer_->SetParent(this);
[email protected]7aba6662013-03-12 10:17:34879 NoteLayerPropertyChangedForSubtree();
880}
881
882scoped_ptr<LayerImpl> LayerImpl::TakeMaskLayer() {
883 mask_layer_id_ = -1;
884 return mask_layer_.Pass();
885}
886
887void LayerImpl::SetReplicaLayer(scoped_ptr<LayerImpl> replica_layer) {
888 int new_layer_id = replica_layer ? replica_layer->id() : -1;
889
890 if (replica_layer) {
891 DCHECK_EQ(layer_tree_impl(), replica_layer->layer_tree_impl());
892 DCHECK_NE(new_layer_id, replica_layer_id_);
893 } else if (new_layer_id == replica_layer_id_) {
894 return;
895 }
896
897 replica_layer_ = replica_layer.Pass();
898 replica_layer_id_ = new_layer_id;
899 if (replica_layer_)
[email protected]ad0250b2014-01-18 03:24:34900 replica_layer_->SetParent(this);
[email protected]7aba6662013-03-12 10:17:34901 NoteLayerPropertyChangedForSubtree();
902}
903
904scoped_ptr<LayerImpl> LayerImpl::TakeReplicaLayer() {
905 replica_layer_id_ = -1;
906 return replica_layer_.Pass();
907}
908
[email protected]80413d72013-08-30 20:25:33909ScrollbarLayerImplBase* LayerImpl::ToScrollbarLayer() {
kulkarni.a4015690f12014-10-10 13:50:06910 return nullptr;
[email protected]7aba6662013-03-12 10:17:34911}
912
913void LayerImpl::SetDrawsContent(bool draws_content) {
914 if (draws_content_ == draws_content)
915 return;
916
917 draws_content_ = draws_content;
918 NoteLayerPropertyChanged();
919}
920
[email protected]c0ae06c12013-06-24 18:32:19921void LayerImpl::SetHideLayerAndSubtree(bool hide) {
922 if (hide_layer_and_subtree_ == hide)
923 return;
924
925 hide_layer_and_subtree_ = hide;
926 NoteLayerPropertyChangedForSubtree();
927}
928
[email protected]a2566412014-06-05 03:14:20929void LayerImpl::SetTransformOrigin(const gfx::Point3F& transform_origin) {
930 if (transform_origin_ == transform_origin)
[email protected]7aba6662013-03-12 10:17:34931 return;
[email protected]a2566412014-06-05 03:14:20932 transform_origin_ = transform_origin;
[email protected]7aba6662013-03-12 10:17:34933 NoteLayerPropertyChangedForSubtree();
934}
935
936void LayerImpl::SetBackgroundColor(SkColor background_color) {
937 if (background_color_ == background_color)
938 return;
939
940 background_color_ = background_color;
941 NoteLayerPropertyChanged();
942}
943
[email protected]2c4cbec2013-06-04 21:14:50944SkColor LayerImpl::SafeOpaqueBackgroundColor() const {
945 SkColor color = background_color();
946 if (SkColorGetA(color) == 255 && !contents_opaque()) {
947 color = SK_ColorTRANSPARENT;
948 } else if (SkColorGetA(color) != 255 && contents_opaque()) {
949 for (const LayerImpl* layer = parent(); layer;
950 layer = layer->parent()) {
951 color = layer->background_color();
952 if (SkColorGetA(color) == 255)
953 break;
954 }
955 if (SkColorGetA(color) != 255)
956 color = layer_tree_impl()->background_color();
957 if (SkColorGetA(color) != 255)
958 color = SkColorSetA(color, 255);
959 }
960 return color;
961}
962
[email protected]ae6b1a72013-06-25 18:49:29963void LayerImpl::SetFilters(const FilterOperations& filters) {
[email protected]7aba6662013-03-12 10:17:34964 if (filters_ == filters)
965 return;
966
[email protected]7aba6662013-03-12 10:17:34967 filters_ = filters;
968 NoteLayerPropertyChangedForSubtree();
969}
970
[email protected]b4c6d812013-10-03 15:48:56971bool LayerImpl::FilterIsAnimating() const {
ericrk7c030992015-02-20 01:39:38972 return layer_animation_controller_->IsAnimatingProperty(Animation::FILTER);
[email protected]b4c6d812013-10-03 15:48:56973}
974
975bool LayerImpl::FilterIsAnimatingOnImplOnly() const {
976 Animation* filter_animation =
ericrk7c030992015-02-20 01:39:38977 layer_animation_controller_->GetAnimation(Animation::FILTER);
[email protected]b4c6d812013-10-03 15:48:56978 return filter_animation && filter_animation->is_impl_only();
979}
980
[email protected]7aba6662013-03-12 10:17:34981void LayerImpl::SetBackgroundFilters(
[email protected]ae6b1a72013-06-25 18:49:29982 const FilterOperations& filters) {
[email protected]7aba6662013-03-12 10:17:34983 if (background_filters_ == filters)
984 return;
985
986 background_filters_ = filters;
987 NoteLayerPropertyChanged();
988}
989
[email protected]7aba6662013-03-12 10:17:34990void LayerImpl::SetMasksToBounds(bool masks_to_bounds) {
991 if (masks_to_bounds_ == masks_to_bounds)
992 return;
993
994 masks_to_bounds_ = masks_to_bounds;
995 NoteLayerPropertyChangedForSubtree();
996}
997
998void LayerImpl::SetContentsOpaque(bool opaque) {
999 if (contents_opaque_ == opaque)
1000 return;
1001
1002 contents_opaque_ = opaque;
1003 NoteLayerPropertyChangedForSubtree();
1004}
1005
1006void LayerImpl::SetOpacity(float opacity) {
1007 if (opacity_ == opacity)
1008 return;
1009
1010 opacity_ = opacity;
[email protected]af37ce802013-10-07 23:53:281011 NoteLayerPropertyChangedForSubtree();
[email protected]7aba6662013-03-12 10:17:341012}
1013
1014bool LayerImpl::OpacityIsAnimating() const {
ericrk7c030992015-02-20 01:39:381015 return layer_animation_controller_->IsAnimatingProperty(Animation::OPACITY);
[email protected]7aba6662013-03-12 10:17:341016}
1017
[email protected]43615872013-03-13 16:35:171018bool LayerImpl::OpacityIsAnimatingOnImplOnly() const {
1019 Animation* opacity_animation =
ericrk7c030992015-02-20 01:39:381020 layer_animation_controller_->GetAnimation(Animation::OPACITY);
[email protected]43615872013-03-13 16:35:171021 return opacity_animation && opacity_animation->is_impl_only();
1022}
1023
[email protected]7bbeaf4e2013-11-26 10:27:221024void LayerImpl::SetBlendMode(SkXfermode::Mode blend_mode) {
1025 if (blend_mode_ == blend_mode)
1026 return;
1027
1028 blend_mode_ = blend_mode;
1029 NoteLayerPropertyChangedForSubtree();
1030}
1031
1032void LayerImpl::SetIsRootForIsolatedGroup(bool root) {
1033 if (is_root_for_isolated_group_ == root)
1034 return;
1035
1036 is_root_for_isolated_group_ = root;
[email protected]ad0250b2014-01-18 03:24:341037 SetNeedsPushProperties();
[email protected]7bbeaf4e2013-11-26 10:27:221038}
1039
[email protected]14bc5d682014-01-17 07:26:471040void LayerImpl::SetPosition(const gfx::PointF& position) {
[email protected]7aba6662013-03-12 10:17:341041 if (position_ == position)
1042 return;
1043
1044 position_ = position;
1045 NoteLayerPropertyChangedForSubtree();
1046}
1047
[email protected]56fffdd2014-02-11 19:50:571048void LayerImpl::SetShouldFlattenTransform(bool flatten) {
1049 if (should_flatten_transform_ == flatten)
[email protected]7aba6662013-03-12 10:17:341050 return;
1051
[email protected]56fffdd2014-02-11 19:50:571052 should_flatten_transform_ = flatten;
1053 NoteLayerPropertyChangedForSubtree();
1054}
1055
[email protected]a9d4d4f2014-06-19 06:49:281056void LayerImpl::Set3dSortingContextId(int id) {
1057 if (id == sorting_context_id_)
[email protected]56fffdd2014-02-11 19:50:571058 return;
[email protected]a9d4d4f2014-06-19 06:49:281059 sorting_context_id_ = id;
[email protected]7aba6662013-03-12 10:17:341060 NoteLayerPropertyChangedForSubtree();
1061}
1062
vmpstr3d1d72c2015-01-26 18:27:401063void LayerImpl::PassFrameTimingRequests(
1064 std::vector<FrameTimingRequest>* requests) {
1065 frame_timing_requests_.swap(*requests);
1066 frame_timing_requests_dirty_ = true;
1067 SetNeedsPushProperties();
1068}
1069
vmpstrd704c872015-04-03 20:29:511070void LayerImpl::GatherFrameTimingRequestIds(std::vector<int64_t>* request_ids) {
1071 for (const auto& request : frame_timing_requests_)
1072 request_ids->push_back(request.id());
1073}
1074
[email protected]7aba6662013-03-12 10:17:341075void LayerImpl::SetTransform(const gfx::Transform& transform) {
1076 if (transform_ == transform)
1077 return;
1078
1079 transform_ = transform;
[email protected]08bdf1b2014-04-16 23:23:291080 transform_is_invertible_ = transform_.IsInvertible();
1081 NoteLayerPropertyChangedForSubtree();
1082}
1083
1084void LayerImpl::SetTransformAndInvertibility(const gfx::Transform& transform,
1085 bool transform_is_invertible) {
1086 if (transform_ == transform) {
1087 DCHECK(transform_is_invertible_ == transform_is_invertible)
1088 << "Can't change invertibility if transform is unchanged";
1089 return;
1090 }
1091 transform_ = transform;
1092 transform_is_invertible_ = transform_is_invertible;
[email protected]af37ce802013-10-07 23:53:281093 NoteLayerPropertyChangedForSubtree();
[email protected]7aba6662013-03-12 10:17:341094}
1095
1096bool LayerImpl::TransformIsAnimating() const {
ericrk7c030992015-02-20 01:39:381097 return layer_animation_controller_->IsAnimatingProperty(Animation::TRANSFORM);
[email protected]7aba6662013-03-12 10:17:341098}
1099
[email protected]43615872013-03-13 16:35:171100bool LayerImpl::TransformIsAnimatingOnImplOnly() const {
1101 Animation* transform_animation =
ericrk7c030992015-02-20 01:39:381102 layer_animation_controller_->GetAnimation(Animation::TRANSFORM);
[email protected]43615872013-03-13 16:35:171103 return transform_animation && transform_animation->is_impl_only();
1104}
1105
danakj19f0c9e2014-10-11 03:24:421106void LayerImpl::SetUpdateRect(const gfx::Rect& update_rect) {
[email protected]ad0250b2014-01-18 03:24:341107 update_rect_ = update_rect;
1108 SetNeedsPushProperties();
1109}
1110
[email protected]cfa7fd922014-04-29 11:50:031111void LayerImpl::AddDamageRect(const gfx::RectF& damage_rect) {
1112 damage_rect_ = gfx::UnionRects(damage_rect_, damage_rect);
1113}
1114
[email protected]64348ea2014-01-29 22:58:261115void LayerImpl::SetContentBounds(const gfx::Size& content_bounds) {
[email protected]7aba6662013-03-12 10:17:341116 if (this->content_bounds() == content_bounds)
1117 return;
1118
1119 draw_properties_.content_bounds = content_bounds;
1120 NoteLayerPropertyChanged();
1121}
1122
1123void LayerImpl::SetContentsScale(float contents_scale_x,
1124 float contents_scale_y) {
1125 if (this->contents_scale_x() == contents_scale_x &&
1126 this->contents_scale_y() == contents_scale_y)
1127 return;
1128
1129 draw_properties_.contents_scale_x = contents_scale_x;
1130 draw_properties_.contents_scale_y = contents_scale_y;
1131 NoteLayerPropertyChanged();
1132}
1133
[email protected]251699b2013-10-09 00:21:261134bool LayerImpl::IsExternalFlingActive() const {
hush33370e12015-04-07 03:49:501135 return layer_tree_impl_->IsExternalFlingActive();
[email protected]251699b2013-10-09 00:21:261136}
1137
aeliasd0070ba2015-01-31 13:44:491138void LayerImpl::SetCurrentScrollOffset(const gfx::ScrollOffset& scroll_offset) {
1139 DCHECK(IsActive());
1140 if (scroll_offset_->SetCurrent(scroll_offset))
hush33370e12015-04-07 03:49:501141 DidUpdateScrollOffset(false);
1142}
1143
1144void LayerImpl::SetCurrentScrollOffsetFromDelegate(
1145 const gfx::ScrollOffset& scroll_offset) {
1146 DCHECK(IsActive());
1147 if (scroll_offset_->SetCurrent(scroll_offset))
1148 DidUpdateScrollOffset(true);
boliu7d5dbab2014-10-10 20:05:471149}
1150
aeliasd0070ba2015-01-31 13:44:491151void LayerImpl::PushScrollOffsetFromMainThread(
1152 const gfx::ScrollOffset& scroll_offset) {
1153 PushScrollOffset(&scroll_offset);
[email protected]b34c97982013-08-24 15:21:381154}
[email protected]7aba6662013-03-12 10:17:341155
danakjb5197d32015-02-03 23:39:491156void LayerImpl::PushScrollOffsetFromMainThreadAndClobberActiveValue(
1157 const gfx::ScrollOffset& scroll_offset) {
1158 scroll_offset_->set_clobber_active_value();
1159 PushScrollOffset(&scroll_offset);
1160}
1161
aeliasd0070ba2015-01-31 13:44:491162gfx::ScrollOffset LayerImpl::PullDeltaForMainThread() {
miletusd799dd22015-03-19 04:23:171163 // TODO(miletus): Remove all this temporary flooring machinery when
1164 // Blink fully supports fractional scrolls.
1165 gfx::ScrollOffset current_offset = CurrentScrollOffset();
1166 gfx::Vector2dF current_delta = ScrollDelta();
1167 gfx::Vector2dF floored_delta(floor(current_delta.x()),
1168 floor(current_delta.y()));
1169 gfx::Vector2dF diff_delta = floored_delta - current_delta;
1170 gfx::ScrollOffset tmp_offset = ScrollOffsetWithDelta(current_offset,
1171 diff_delta);
1172 scroll_offset_->SetCurrent(tmp_offset);
1173 gfx::ScrollOffset delta = scroll_offset_->PullDeltaForMainThread();
1174 scroll_offset_->SetCurrent(current_offset);
1175 return delta;
aeliasd0070ba2015-01-31 13:44:491176}
[email protected]adeda572014-01-31 00:49:471177
aeliasd0070ba2015-01-31 13:44:491178gfx::ScrollOffset LayerImpl::CurrentScrollOffset() const {
1179 return scroll_offset_->Current(IsActive());
[email protected]7aba6662013-03-12 10:17:341180}
1181
[email protected]1960a712013-04-30 17:06:471182gfx::Vector2dF LayerImpl::ScrollDelta() const {
aeliasd0070ba2015-01-31 13:44:491183 if (IsActive())
1184 return gfx::Vector2dF(scroll_offset_->Delta().x(),
1185 scroll_offset_->Delta().y());
1186 else
1187 return gfx::Vector2dF(scroll_offset_->PendingDelta().get().x(),
1188 scroll_offset_->PendingDelta().get().y());
1189}
1190
1191void LayerImpl::SetScrollDelta(const gfx::Vector2dF& delta) {
1192 DCHECK(IsActive());
1193 SetCurrentScrollOffset(scroll_offset_->ActiveBase() +
1194 gfx::ScrollOffset(delta));
1195}
1196
1197gfx::ScrollOffset LayerImpl::BaseScrollOffset() const {
1198 if (IsActive())
1199 return scroll_offset_->ActiveBase();
1200 else
1201 return scroll_offset_->PendingBase();
1202}
1203
1204void LayerImpl::PushScrollOffset(const gfx::ScrollOffset* scroll_offset) {
1205 DCHECK(scroll_offset || IsActive());
1206 bool changed = false;
1207 if (scroll_offset) {
1208 DCHECK(!IsActive() || !layer_tree_impl_->FindPendingTreeLayerById(id()));
1209 changed |= scroll_offset_->PushFromMainThread(*scroll_offset);
miletusf57925d2014-10-01 19:38:131210 }
aeliasd0070ba2015-01-31 13:44:491211 if (IsActive()) {
1212 changed |= scroll_offset_->PushPendingToActive();
aeliasd0070ba2015-01-31 13:44:491213 }
1214
1215 if (changed)
hush33370e12015-04-07 03:49:501216 DidUpdateScrollOffset(false);
[email protected]1960a712013-04-30 17:06:471217}
1218
hush33370e12015-04-07 03:49:501219void LayerImpl::DidUpdateScrollOffset(bool is_from_root_delegate) {
1220 if (!is_from_root_delegate)
1221 layer_tree_impl()->DidUpdateScrollOffset(id());
aeliasd0070ba2015-01-31 13:44:491222 NoteLayerPropertyChangedForSubtree();
1223 ScrollbarParametersDidChange(false);
vmpstre86240822015-05-11 21:10:111224 // Inform the pending twin that a property changed.
1225 if (layer_tree_impl()->IsActiveTree()) {
1226 LayerImpl* pending_twin = layer_tree_impl()->FindPendingTreeLayerById(id());
1227 if (pending_twin)
1228 pending_twin->NoteLayerPropertyChangedForSubtree();
1229 }
[email protected]ffb2720f2013-03-15 19:18:371230}
1231
[email protected]7aba6662013-03-12 10:17:341232void LayerImpl::SetDoubleSided(bool double_sided) {
1233 if (double_sided_ == double_sided)
1234 return;
1235
1236 double_sided_ = double_sided;
1237 NoteLayerPropertyChangedForSubtree();
1238}
1239
[email protected]d5467eb72014-08-22 01:16:431240SimpleEnclosedRegion LayerImpl::VisibleContentOpaqueRegion() const {
[email protected]7aba6662013-03-12 10:17:341241 if (contents_opaque())
[email protected]d5467eb72014-08-22 01:16:431242 return SimpleEnclosedRegion(visible_content_rect());
1243 return SimpleEnclosedRegion();
[email protected]7aba6662013-03-12 10:17:341244}
1245
[email protected]37349bc2013-06-04 01:31:521246void LayerImpl::DidBeginTracing() {}
1247
[email protected]9db24462014-01-14 02:25:501248void LayerImpl::ReleaseResources() {}
[email protected]7aba6662013-03-12 10:17:341249
vmpstr9ce5c662015-02-05 23:29:261250void LayerImpl::RecreateResources() {
1251}
1252
miletusf57925d2014-10-01 19:38:131253gfx::ScrollOffset LayerImpl::MaxScrollOffset() const {
[email protected]adeda572014-01-31 00:49:471254 if (!scroll_clip_layer_ || bounds().IsEmpty())
miletusf57925d2014-10-01 19:38:131255 return gfx::ScrollOffset();
[email protected]610834cb2014-01-29 13:54:331256
[email protected]adeda572014-01-31 00:49:471257 LayerImpl const* page_scale_layer = layer_tree_impl()->page_scale_layer();
1258 DCHECK(this != page_scale_layer);
[email protected]adeda572014-01-31 00:49:471259 DCHECK(this != layer_tree_impl()->InnerViewportScrollLayer() ||
1260 IsContainerForFixedPositionLayers());
1261
[email protected]adeda572014-01-31 00:49:471262 float scale_factor = 1.f;
1263 for (LayerImpl const* current_layer = this;
aeliasd0070ba2015-01-31 13:44:491264 current_layer != scroll_clip_layer_->parent();
[email protected]adeda572014-01-31 00:49:471265 current_layer = current_layer->parent()) {
aeliasd0070ba2015-01-31 13:44:491266 if (current_layer == page_scale_layer)
1267 scale_factor = layer_tree_impl()->current_page_scale_factor();
[email protected]adeda572014-01-31 00:49:471268 }
[email protected]adeda572014-01-31 00:49:471269
aeliasd0070ba2015-01-31 13:44:491270 gfx::SizeF scaled_scroll_bounds =
1271 gfx::ToFlooredSize(gfx::ScaleSize(BoundsForScrolling(), scale_factor));
[email protected]0072c112014-04-22 05:53:401272 scaled_scroll_bounds = gfx::ToFlooredSize(scaled_scroll_bounds);
[email protected]adeda572014-01-31 00:49:471273
miletusf57925d2014-10-01 19:38:131274 gfx::ScrollOffset max_offset(
[email protected]adeda572014-01-31 00:49:471275 scaled_scroll_bounds.width() - scroll_clip_layer_->bounds().width(),
1276 scaled_scroll_bounds.height() - scroll_clip_layer_->bounds().height());
1277 // We need the final scroll offset to be in CSS coords.
1278 max_offset.Scale(1 / scale_factor);
miletusf57925d2014-10-01 19:38:131279 max_offset.SetToMax(gfx::ScrollOffset());
1280 return max_offset;
[email protected]adeda572014-01-31 00:49:471281}
1282
aeliasd0070ba2015-01-31 13:44:491283gfx::ScrollOffset LayerImpl::ClampScrollOffsetToLimits(
1284 gfx::ScrollOffset offset) const {
1285 offset.SetToMin(MaxScrollOffset());
1286 offset.SetToMax(gfx::ScrollOffset());
1287 return offset;
1288}
[email protected]adeda572014-01-31 00:49:471289
aeliasd0070ba2015-01-31 13:44:491290gfx::Vector2dF LayerImpl::ClampScrollToMaxScrollOffset() {
1291 gfx::ScrollOffset old_offset = CurrentScrollOffset();
1292 gfx::ScrollOffset clamped_offset = ClampScrollOffsetToLimits(old_offset);
miletusf57925d2014-10-01 19:38:131293 gfx::Vector2dF delta = clamped_offset.DeltaFrom(old_offset);
[email protected]adeda572014-01-31 00:49:471294 if (!delta.IsZero())
1295 ScrollBy(delta);
[email protected]adeda572014-01-31 00:49:471296 return delta;
1297}
1298
1299void LayerImpl::SetScrollbarPosition(ScrollbarLayerImplBase* scrollbar_layer,
sataya.m07f11a82014-10-07 14:29:181300 LayerImpl* scrollbar_clip_layer,
1301 bool on_resize) const {
[email protected]adeda572014-01-31 00:49:471302 DCHECK(scrollbar_layer);
1303 LayerImpl* page_scale_layer = layer_tree_impl()->page_scale_layer();
1304
1305 DCHECK(this != page_scale_layer);
1306 DCHECK(scrollbar_clip_layer);
bokanef971462014-10-13 22:58:321307 gfx::RectF clip_rect(gfx::PointF(),
1308 scrollbar_clip_layer->BoundsForScrolling());
[email protected]adeda572014-01-31 00:49:471309
1310 // See comment in MaxScrollOffset() regarding the use of the content layer
1311 // bounds here.
bokanef971462014-10-13 22:58:321312 gfx::RectF scroll_rect(gfx::PointF(), BoundsForScrolling());
[email protected]adeda572014-01-31 00:49:471313
1314 if (scroll_rect.size().IsEmpty())
1315 return;
1316
miletusf57925d2014-10-01 19:38:131317 gfx::ScrollOffset current_offset;
[email protected]adeda572014-01-31 00:49:471318 for (LayerImpl const* current_layer = this;
aeliasd0070ba2015-01-31 13:44:491319 current_layer != scrollbar_clip_layer->parent();
[email protected]adeda572014-01-31 00:49:471320 current_layer = current_layer->parent()) {
aeliasd0070ba2015-01-31 13:44:491321 current_offset += current_layer->CurrentScrollOffset();
[email protected]adeda572014-01-31 00:49:471322 if (current_layer == page_scale_layer) {
aelias58eec0812014-12-04 01:04:401323 float scale_factor = layer_tree_impl()->current_page_scale_factor();
[email protected]adeda572014-01-31 00:49:471324 current_offset.Scale(scale_factor);
1325 scroll_rect.Scale(scale_factor);
[email protected]adeda572014-01-31 00:49:471326 }
1327 }
[email protected]adeda572014-01-31 00:49:471328
sataya.m68d7d9b42014-09-22 16:01:591329 bool scrollbar_needs_animation = false;
1330 scrollbar_needs_animation |= scrollbar_layer->SetVerticalAdjust(
1331 scrollbar_clip_layer->bounds_delta().y());
[email protected]adeda572014-01-31 00:49:471332 if (scrollbar_layer->orientation() == HORIZONTAL) {
1333 float visible_ratio = clip_rect.width() / scroll_rect.width();
sataya.m68d7d9b42014-09-22 16:01:591334 scrollbar_needs_animation |=
1335 scrollbar_layer->SetCurrentPos(current_offset.x());
1336 scrollbar_needs_animation |=
1337 scrollbar_layer->SetMaximum(scroll_rect.width() - clip_rect.width());
1338 scrollbar_needs_animation |=
1339 scrollbar_layer->SetVisibleToTotalLengthRatio(visible_ratio);
[email protected]adeda572014-01-31 00:49:471340 } else {
1341 float visible_ratio = clip_rect.height() / scroll_rect.height();
wjmaclean56f35ff2015-03-25 23:59:351342 bool y_offset_did_change =
sataya.m68d7d9b42014-09-22 16:01:591343 scrollbar_layer->SetCurrentPos(current_offset.y());
wjmaclean56f35ff2015-03-25 23:59:351344 scrollbar_needs_animation |= y_offset_did_change;
sataya.m68d7d9b42014-09-22 16:01:591345 scrollbar_needs_animation |=
1346 scrollbar_layer->SetMaximum(scroll_rect.height() - clip_rect.height());
1347 scrollbar_needs_animation |=
1348 scrollbar_layer->SetVisibleToTotalLengthRatio(visible_ratio);
wjmaclean56f35ff2015-03-25 23:59:351349 if (y_offset_did_change && layer_tree_impl()->IsActiveTree() &&
1350 this == layer_tree_impl()->InnerViewportScrollLayer()) {
1351 TRACE_COUNTER_ID1("cc", "scroll_offset_y", this->id(),
1352 current_offset.y());
1353 }
[email protected]adeda572014-01-31 00:49:471354 }
sataya.m7acc4b32014-09-23 15:37:211355 if (scrollbar_needs_animation) {
1356 layer_tree_impl()->set_needs_update_draw_properties();
1357 // TODO(wjmaclean) The scrollbar animator for the pinch-zoom scrollbars
1358 // should activate for every scroll on the main frame, not just the
1359 // scrolls that move the pinch virtual viewport (i.e. trigger from
1360 // either inner or outer viewport).
1361 if (scrollbar_animation_controller_) {
bokanc784a6f2015-01-28 04:11:501362 // Non-overlay scrollbars shouldn't trigger animations.
1363 if (scrollbar_layer->is_overlay_scrollbar())
sataya.m07f11a82014-10-07 14:29:181364 scrollbar_animation_controller_->DidScrollUpdate(on_resize);
sataya.m7acc4b32014-09-23 15:37:211365 }
[email protected]adeda572014-01-31 00:49:471366 }
[email protected]7aba6662013-03-12 10:17:341367}
1368
[email protected]7aba6662013-03-12 10:17:341369void LayerImpl::DidBecomeActive() {
[email protected]fea161872013-08-27 22:34:591370 if (layer_tree_impl_->settings().scrollbar_animator ==
ericrk7c030992015-02-20 01:39:381371 LayerTreeSettings::NO_ANIMATOR) {
[email protected]7aba6662013-03-12 10:17:341372 return;
[email protected]fea161872013-08-27 22:34:591373 }
[email protected]7aba6662013-03-12 10:17:341374
[email protected]adeda572014-01-31 00:49:471375 bool need_scrollbar_animation_controller = scrollable() && scrollbars_;
[email protected]fea161872013-08-27 22:34:591376 if (!need_scrollbar_animation_controller) {
danakjf446a072014-09-27 21:55:481377 scrollbar_animation_controller_ = nullptr;
[email protected]fea161872013-08-27 22:34:591378 return;
1379 }
1380
1381 if (scrollbar_animation_controller_)
1382 return;
1383
[email protected]930ff43b2014-05-02 05:24:001384 scrollbar_animation_controller_ =
1385 layer_tree_impl_->CreateScrollbarAnimationController(this);
[email protected]e45638c2013-01-17 22:01:401386}
[email protected]ad0250b2014-01-18 03:24:341387
[email protected]adeda572014-01-31 00:49:471388void LayerImpl::ClearScrollbars() {
1389 if (!scrollbars_)
1390 return;
1391
kulkarni.a4015690f12014-10-10 13:50:061392 scrollbars_.reset(nullptr);
[email protected]94f206c12012-08-25 00:09:141393}
1394
[email protected]adeda572014-01-31 00:49:471395void LayerImpl::AddScrollbar(ScrollbarLayerImplBase* layer) {
1396 DCHECK(layer);
1397 DCHECK(!scrollbars_ || scrollbars_->find(layer) == scrollbars_->end());
1398 if (!scrollbars_)
1399 scrollbars_.reset(new ScrollbarSet());
1400
1401 scrollbars_->insert(layer);
1402}
1403
1404void LayerImpl::RemoveScrollbar(ScrollbarLayerImplBase* layer) {
1405 DCHECK(scrollbars_);
1406 DCHECK(layer);
1407 DCHECK(scrollbars_->find(layer) != scrollbars_->end());
1408
1409 scrollbars_->erase(layer);
1410 if (scrollbars_->empty())
danakjf446a072014-09-27 21:55:481411 scrollbars_ = nullptr;
[email protected]adeda572014-01-31 00:49:471412}
1413
1414bool LayerImpl::HasScrollbar(ScrollbarOrientation orientation) const {
1415 if (!scrollbars_)
1416 return false;
1417
1418 for (ScrollbarSet::iterator it = scrollbars_->begin();
1419 it != scrollbars_->end();
1420 ++it)
1421 if ((*it)->orientation() == orientation)
1422 return true;
1423
1424 return false;
1425}
1426
sataya.m07f11a82014-10-07 14:29:181427void LayerImpl::ScrollbarParametersDidChange(bool on_resize) {
[email protected]adeda572014-01-31 00:49:471428 if (!scrollbars_)
1429 return;
1430
1431 for (ScrollbarSet::iterator it = scrollbars_->begin();
1432 it != scrollbars_->end();
aelias1505e722014-10-07 22:19:461433 ++it) {
1434 bool is_scroll_layer = (*it)->ScrollLayerId() == layer_id_;
1435 bool scroll_layer_resized = is_scroll_layer && on_resize;
1436 (*it)->ScrollbarParametersDidChange(scroll_layer_resized);
1437 }
[email protected]94f206c12012-08-25 00:09:141438}
1439
[email protected]ad0250b2014-01-18 03:24:341440void LayerImpl::SetNeedsPushProperties() {
1441 if (needs_push_properties_)
1442 return;
1443 if (!parent_should_know_need_push_properties() && parent_)
1444 parent_->AddDependentNeedsPushProperties();
1445 needs_push_properties_ = true;
1446}
1447
1448void LayerImpl::AddDependentNeedsPushProperties() {
1449 DCHECK_GE(num_dependents_need_push_properties_, 0);
1450
1451 if (!parent_should_know_need_push_properties() && parent_)
1452 parent_->AddDependentNeedsPushProperties();
1453
1454 num_dependents_need_push_properties_++;
1455}
1456
1457void LayerImpl::RemoveDependentNeedsPushProperties() {
1458 num_dependents_need_push_properties_--;
1459 DCHECK_GE(num_dependents_need_push_properties_, 0);
1460
1461 if (!parent_should_know_need_push_properties() && parent_)
1462 parent_->RemoveDependentNeedsPushProperties();
1463}
1464
vmpstrdcf21da2015-03-23 19:16:321465void LayerImpl::GetAllTilesAndPrioritiesForTracing(
1466 std::map<const Tile*, TilePriority>* tile_map) const {
vmpstrd7de03c2014-08-27 18:11:011467}
1468
ssid911e40e2015-02-09 17:55:201469void LayerImpl::AsValueInto(base::trace_event::TracedValue* state) const {
[email protected]f5ad4282014-02-15 14:23:161470 TracedValue::MakeDictIntoImplicitSnapshotWithCategory(
1471 TRACE_DISABLED_BY_DEFAULT("cc.debug"),
[email protected]b4dc36472014-02-26 02:48:251472 state,
1473 "cc::LayerImpl",
1474 LayerTypeAsString(),
1475 this);
[email protected]f6742f52013-05-08 23:52:221476 state->SetInteger("layer_id", id());
jungjik.lee50f9c8e2015-01-21 14:06:161477 MathUtil::AddToTracedValue("bounds", bounds_, state);
[email protected]d12aa932014-08-01 13:10:381478
danakj38955562014-09-13 02:56:431479 state->SetDouble("opacity", opacity());
1480
jungjik.lee50f9c8e2015-01-21 14:06:161481 MathUtil::AddToTracedValue("position", position_, state);
[email protected]d12aa932014-08-01 13:10:381482
[email protected]f6742f52013-05-08 23:52:221483 state->SetInteger("draws_content", DrawsContent());
[email protected]cdf5b952013-05-15 15:39:291484 state->SetInteger("gpu_memory_usage", GPUMemoryUsageInBytes());
[email protected]d12aa932014-08-01 13:10:381485
aeliasd0070ba2015-01-31 13:44:491486 MathUtil::AddToTracedValue(
1487 "scroll_offset", scroll_offset_ ? scroll_offset_->Current(IsActive())
1488 : gfx::ScrollOffset(),
1489 state);
1490
jungjik.lee50f9c8e2015-01-21 14:06:161491 MathUtil::AddToTracedValue("transform_origin", transform_origin_, state);
[email protected]8c5690222013-02-15 17:36:431492
[email protected]7aba6662013-03-12 10:17:341493 bool clipped;
[email protected]fa816c62013-03-18 04:24:211494 gfx::QuadF layer_quad = MathUtil::MapQuad(
[email protected]7aba6662013-03-12 10:17:341495 screen_space_transform(),
1496 gfx::QuadF(gfx::Rect(content_bounds())),
[email protected]fa816c62013-03-18 04:24:211497 &clipped);
jungjik.lee50f9c8e2015-01-21 14:06:161498 MathUtil::AddToTracedValue("layer_quad", layer_quad, state);
[email protected]78d78612013-09-12 18:04:041499 if (!touch_event_handler_region_.IsEmpty()) {
[email protected]d12aa932014-08-01 13:10:381500 state->BeginArray("touch_event_handler_region");
1501 touch_event_handler_region_.AsValueInto(state);
1502 state->EndArray();
[email protected]78d78612013-09-12 18:04:041503 }
1504 if (have_wheel_event_handlers_) {
1505 gfx::Rect wheel_rect(content_bounds());
1506 Region wheel_region(wheel_rect);
[email protected]d12aa932014-08-01 13:10:381507 state->BeginArray("wheel_event_handler_region");
1508 wheel_region.AsValueInto(state);
1509 state->EndArray();
[email protected]78d78612013-09-12 18:04:041510 }
[email protected]f998c532014-03-31 20:02:511511 if (have_scroll_event_handlers_) {
1512 gfx::Rect scroll_rect(content_bounds());
1513 Region scroll_region(scroll_rect);
[email protected]d12aa932014-08-01 13:10:381514 state->BeginArray("scroll_event_handler_region");
1515 scroll_region.AsValueInto(state);
1516 state->EndArray();
[email protected]f998c532014-03-31 20:02:511517 }
[email protected]78d78612013-09-12 18:04:041518 if (!non_fast_scrollable_region_.IsEmpty()) {
[email protected]d12aa932014-08-01 13:10:381519 state->BeginArray("non_fast_scrollable_region");
1520 non_fast_scrollable_region_.AsValueInto(state);
1521 state->EndArray();
[email protected]78d78612013-09-12 18:04:041522 }
rbyers18779d822015-02-05 06:22:061523 if (scroll_blocks_on_) {
1524 state->SetInteger("scroll_blocks_on", scroll_blocks_on_);
1525 }
[email protected]f6742f52013-05-08 23:52:221526
[email protected]d12aa932014-08-01 13:10:381527 state->BeginArray("children");
1528 for (size_t i = 0; i < children_.size(); ++i) {
1529 state->BeginDictionary();
1530 children_[i]->AsValueInto(state);
1531 state->EndDictionary();
1532 }
1533 state->EndArray();
1534 if (mask_layer_) {
1535 state->BeginDictionary("mask_layer");
1536 mask_layer_->AsValueInto(state);
1537 state->EndDictionary();
1538 }
1539 if (replica_layer_) {
1540 state->BeginDictionary("replica_layer");
1541 replica_layer_->AsValueInto(state);
1542 state->EndDictionary();
1543 }
[email protected]0e98cdd2013-08-23 00:44:301544
1545 if (scroll_parent_)
1546 state->SetInteger("scroll_parent", scroll_parent_->id());
1547
1548 if (clip_parent_)
1549 state->SetInteger("clip_parent", clip_parent_->id());
[email protected]c2a56ff2013-10-14 19:32:511550
1551 state->SetBoolean("can_use_lcd_text", can_use_lcd_text());
1552 state->SetBoolean("contents_opaque", contents_opaque());
[email protected]a1286742013-11-13 17:11:401553
[email protected]3d86dd7a2014-01-24 01:33:111554 state->SetBoolean(
1555 "has_animation_bounds",
1556 layer_animation_controller()->HasAnimationThatInflatesBounds());
1557
1558 gfx::BoxF box;
jungjik.lee50f9c8e2015-01-21 14:06:161559 if (LayerUtils::GetAnimationBounds(*this, &box))
1560 MathUtil::AddToTracedValue("animation_bounds", box, state);
[email protected]9f3be432013-12-03 03:53:221561
1562 if (debug_info_.get()) {
1563 std::string str;
1564 debug_info_->AppendAsTraceFormat(&str);
1565 base::JSONReader json_reader;
[email protected]685de6b12014-01-09 12:25:051566 scoped_ptr<base::Value> debug_info_value(json_reader.ReadToValue(str));
1567
[email protected]478224312014-01-10 17:33:471568 if (debug_info_value->IsType(base::Value::TYPE_DICTIONARY)) {
kulkarni.a4015690f12014-10-10 13:50:061569 base::DictionaryValue* dictionary_value = nullptr;
[email protected]685de6b12014-01-09 12:25:051570 bool converted_to_dictionary =
1571 debug_info_value->GetAsDictionary(&dictionary_value);
1572 DCHECK(converted_to_dictionary);
[email protected]d12aa932014-08-01 13:10:381573 for (base::DictionaryValue::Iterator it(*dictionary_value); !it.IsAtEnd();
1574 it.Advance()) {
estade7bc801fb2015-05-07 01:53:081575 state->SetValue(it.key().data(), it.value().CreateDeepCopy());
[email protected]d12aa932014-08-01 13:10:381576 }
[email protected]685de6b12014-01-09 12:25:051577 } else {
1578 NOTREACHED();
1579 }
[email protected]9f3be432013-12-03 03:53:221580 }
vmpstr3d1d72c2015-01-26 18:27:401581
1582 if (!frame_timing_requests_.empty()) {
1583 state->BeginArray("frame_timing_requests");
1584 for (const auto& request : frame_timing_requests_) {
1585 state->BeginDictionary();
1586 state->SetInteger("request_id", request.id());
1587 MathUtil::AddToTracedValue("request_rect", request.rect(), state);
1588 state->EndDictionary();
1589 }
1590 state->EndArray();
1591 }
[email protected]8c5690222013-02-15 17:36:431592}
1593
[email protected]390bb1ff2014-05-09 17:14:401594bool LayerImpl::IsDrawnRenderSurfaceLayerListMember() const {
1595 return draw_properties_.last_drawn_render_surface_layer_list_id ==
1596 layer_tree_impl_->current_render_surface_list_id();
1597}
1598
[email protected]cdf5b952013-05-15 15:39:291599size_t LayerImpl::GPUMemoryUsageInBytes() const { return 0; }
1600
[email protected]5e5648a2013-11-18 00:39:331601void LayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) {
1602 benchmark->RunOnLayer(this);
1603}
[email protected]749cbc62014-07-10 01:06:351604
[email protected]ad63b2f2014-08-11 17:39:541605int LayerImpl::NumDescendantsThatDrawContent() const {
1606 return num_descendants_that_draw_content_;
1607}
1608
[email protected]749cbc62014-07-10 01:06:351609void LayerImpl::NotifyAnimationFinished(
1610 base::TimeTicks monotonic_time,
dstockwellaf2a117b2014-10-16 21:42:291611 Animation::TargetProperty target_property,
1612 int group) {
ericrk7c030992015-02-20 01:39:381613 if (target_property == Animation::SCROLL_OFFSET)
[email protected]749cbc62014-07-10 01:06:351614 layer_tree_impl_->InputScrollAnimationFinished();
1615}
1616
awoloszyne83f28c2014-12-22 15:40:001617void LayerImpl::SetHasRenderSurface(bool should_have_render_surface) {
1618 if (!!render_surface() == should_have_render_surface)
1619 return;
1620
1621 SetNeedsPushProperties();
1622 layer_tree_impl()->set_needs_update_draw_properties();
1623 if (should_have_render_surface) {
1624 render_surface_ = make_scoped_ptr(new RenderSurfaceImpl(this));
1625 return;
1626 }
1627 render_surface_.reset();
1628}
1629
daplatz350219e2015-03-04 19:04:411630Region LayerImpl::GetInvalidationRegion() {
1631 return Region(update_rect_);
1632}
1633
vmpstrd46a7ac2015-03-18 01:11:121634gfx::Rect LayerImpl::GetEnclosingRectInTargetSpace() const {
1635 return MathUtil::MapEnclosingClippedRect(
1636 draw_properties_.target_space_transform,
1637 gfx::Rect(draw_properties_.content_bounds));
1638}
1639
1640gfx::Rect LayerImpl::GetScaledEnclosingRectInTargetSpace(float scale) const {
1641 gfx::Transform scaled_draw_transform =
1642 draw_properties_.target_space_transform;
1643 scaled_draw_transform.Scale(SK_MScalar1 / scale, SK_MScalar1 / scale);
1644 gfx::Size scaled_content_bounds =
1645 gfx::ToCeiledSize(gfx::ScaleSize(content_bounds(), scale));
1646 return MathUtil::MapEnclosingClippedRect(scaled_draw_transform,
1647 gfx::Rect(scaled_content_bounds));
1648}
1649
[email protected]bc5e77c2012-11-05 20:00:491650} // namespace cc