blob: af3f24a1dfdb789cfe44da1d674981c3e435169e [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"
vmpstr91e23092015-06-08 22:24:168#include "base/numerics/safe_conversions.h"
[email protected]8e61d4b2013-06-10 22:11:489#include "base/strings/stringprintf.h"
primianoc06e2382015-01-28 04:21:4910#include "base/trace_event/trace_event.h"
11#include "base/trace_event/trace_event_argument.h"
[email protected]95e4e1a02013-03-18 07:09:0912#include "cc/animation/animation_registrar.h"
13#include "cc/animation/scrollbar_animation_controller.h"
[email protected]681ccff2013-03-18 06:13:5214#include "cc/base/math_util.h"
[email protected]d5467eb72014-08-22 01:16:4315#include "cc/base/simple_enclosed_region.h"
[email protected]6e84de22013-03-18 06:54:2716#include "cc/debug/debug_colors.h"
17#include "cc/debug/layer_tree_debug_state.h"
[email protected]5e5648a2013-11-18 00:39:3318#include "cc/debug/micro_benchmark_impl.h"
[email protected]f6742f52013-05-08 23:52:2219#include "cc/debug/traced_value.h"
[email protected]3d86dd7a2014-01-24 01:33:1120#include "cc/layers/layer_utils.h"
[email protected]3a83478b2013-08-22 20:55:1721#include "cc/layers/painted_scrollbar_layer_impl.h"
[email protected]0e5f7142013-05-24 06:45:3622#include "cc/output/copy_output_request.h"
[email protected]89e8267a2013-03-18 07:50:5623#include "cc/quads/debug_border_draw_quad.h"
[email protected]0cd7d6f72014-08-22 14:50:5124#include "cc/quads/render_pass.h"
[email protected]3d86dd7a2014-01-24 01:33:1125#include "cc/trees/layer_tree_host_common.h"
[email protected]556fd292013-03-18 08:03:0426#include "cc/trees/layer_tree_impl.h"
27#include "cc/trees/layer_tree_settings.h"
28#include "cc/trees/proxy.h"
heejin.r.chungd28506ba2014-10-23 16:36:2029#include "ui/gfx/geometry/box_f.h"
30#include "ui/gfx/geometry/point_conversions.h"
31#include "ui/gfx/geometry/quad_f.h"
32#include "ui/gfx/geometry/rect_conversions.h"
33#include "ui/gfx/geometry/size_conversions.h"
[email protected]adeda572014-01-31 00:49:4734#include "ui/gfx/geometry/vector2d_conversions.h"
[email protected]94f206c12012-08-25 00:09:1435
[email protected]9c88e562012-09-14 22:21:3036namespace cc {
aeliasd0070ba2015-01-31 13:44:4937LayerImpl::LayerImpl(LayerTreeImpl* layer_impl, int id)
38 : LayerImpl(layer_impl, id, new LayerImpl::SyncedScrollOffset) {
39}
40
41LayerImpl::LayerImpl(LayerTreeImpl* tree_impl,
42 int id,
43 scoped_refptr<SyncedScrollOffset> scroll_offset)
kulkarni.a4015690f12014-10-10 13:50:0644 : parent_(nullptr),
45 scroll_parent_(nullptr),
46 clip_parent_(nullptr),
[email protected]7aba6662013-03-12 10:17:3447 mask_layer_id_(-1),
48 replica_layer_id_(-1),
49 layer_id_(id),
50 layer_tree_impl_(tree_impl),
aeliasd0070ba2015-01-31 13:44:4951 scroll_offset_(scroll_offset),
kulkarni.a4015690f12014-10-10 13:50:0652 scroll_clip_layer_(nullptr),
[email protected]7aba6662013-03-12 10:17:3453 should_scroll_on_main_thread_(false),
54 have_wheel_event_handlers_(false),
[email protected]f998c532014-03-31 20:02:5155 have_scroll_event_handlers_(false),
ericrk7c030992015-02-20 01:39:3856 scroll_blocks_on_(SCROLL_BLOCKS_ON_NONE),
[email protected]59a7d552013-10-22 03:36:4357 user_scrollable_horizontal_(true),
58 user_scrollable_vertical_(true),
[email protected]7aba6662013-03-12 10:17:3459 stacking_order_changed_(false),
60 double_sided_(true),
[email protected]56fffdd2014-02-11 19:50:5761 should_flatten_transform_(true),
ennee95b1542015-04-20 20:35:5062 should_flatten_transform_from_property_tree_(false),
jaydasikad36e7fa2015-07-14 15:15:0463 is_clipped_(false),
[email protected]7aba6662013-03-12 10:17:3464 layer_property_changed_(false),
[email protected]7aba6662013-03-12 10:17:3465 masks_to_bounds_(false),
66 contents_opaque_(false),
[email protected]7bbeaf4e2013-11-26 10:27:2267 is_root_for_isolated_group_(false),
[email protected]7aba6662013-03-12 10:17:3468 use_parent_backface_visibility_(false),
69 draw_checkerboard_for_missing_tiles_(false),
70 draws_content_(false),
[email protected]c0ae06c12013-06-24 18:32:1971 hide_layer_and_subtree_(false),
[email protected]08bdf1b2014-04-16 23:23:2972 transform_is_invertible_(true),
[email protected]7aba6662013-03-12 10:17:3473 is_container_for_fixed_position_layers_(false),
enne9c48d4f12015-06-30 00:31:1574 is_affected_by_page_scale_(true),
[email protected]c55f3fc2013-12-10 05:48:4875 background_color_(0),
76 opacity_(1.0),
77 blend_mode_(SkXfermode::kSrcOver_Mode),
[email protected]ad63b2f2014-08-11 17:39:5478 num_descendants_that_draw_content_(0),
ennee95b1542015-04-20 20:35:5079 transform_tree_index_(-1),
80 opacity_tree_index_(-1),
81 clip_tree_index_(-1),
[email protected]7aba6662013-03-12 10:17:3482 draw_depth_(0.f),
[email protected]ad0250b2014-01-18 03:24:3483 needs_push_properties_(false),
84 num_dependents_need_push_properties_(0),
[email protected]a9d4d4f2014-06-19 06:49:2885 sorting_context_id_(0),
vmpstr3d1d72c2015-01-26 18:27:4086 current_draw_mode_(DRAW_MODE_NONE),
jaydasika976cd10b2015-05-26 15:45:2487 frame_timing_requests_dirty_(false),
88 visited_(false),
89 layer_or_descendant_is_drawn_(false),
90 sorted_for_recursion_(false) {
[email protected]bf691c22013-03-26 21:15:0691 DCHECK_GT(layer_id_, 0);
[email protected]7aba6662013-03-12 10:17:3492 DCHECK(layer_tree_impl_);
93 layer_tree_impl_->RegisterLayer(this);
loysod71ece82015-07-03 13:48:5094
95 if (!layer_tree_impl_->settings().use_compositor_animation_timelines) {
96 AnimationRegistrar* registrar = layer_tree_impl_->GetAnimationRegistrar();
97 layer_animation_controller_ =
98 registrar->GetAnimationControllerForId(layer_id_);
99 layer_animation_controller_->AddValueObserver(this);
100 if (IsActive()) {
101 layer_animation_controller_->set_value_provider(this);
102 layer_animation_controller_->set_layer_animation_delegate(this);
103 }
[email protected]749cbc62014-07-10 01:06:35104 }
[email protected]ad0250b2014-01-18 03:24:34105 SetNeedsPushProperties();
[email protected]94f206c12012-08-25 00:09:14106}
107
[email protected]7aba6662013-03-12 10:17:34108LayerImpl::~LayerImpl() {
[email protected]ffbb2212013-06-02 23:47:59109 DCHECK_EQ(DRAW_MODE_NONE, current_draw_mode_);
[email protected]18a70192013-04-26 16:18:25110
loysod71ece82015-07-03 13:48:50111 if (layer_animation_controller_) {
112 layer_animation_controller_->RemoveValueObserver(this);
113 layer_animation_controller_->remove_value_provider(this);
114 layer_animation_controller_->remove_layer_animation_delegate(this);
115 }
[email protected]b8384e22013-12-03 02:20:48116
[email protected]19334ac2013-12-12 23:59:11117 if (!copy_requests_.empty() && layer_tree_impl_->IsActiveTree())
118 layer_tree_impl()->RemoveLayerWithCopyOutputRequest(this);
[email protected]b8384e22013-12-03 02:20:48119 layer_tree_impl_->UnregisterLayer(this);
[email protected]0e98cdd2013-08-23 00:44:30120
[email protected]f5ad4282014-02-15 14:23:16121 TRACE_EVENT_OBJECT_DELETED_WITH_ID(
[email protected]b4dc36472014-02-26 02:48:25122 TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerImpl", this);
[email protected]94f206c12012-08-25 00:09:14123}
124
[email protected]7aba6662013-03-12 10:17:34125void LayerImpl::AddChild(scoped_ptr<LayerImpl> child) {
[email protected]ad0250b2014-01-18 03:24:34126 child->SetParent(this);
[email protected]7aba6662013-03-12 10:17:34127 DCHECK_EQ(layer_tree_impl(), child->layer_tree_impl());
128 children_.push_back(child.Pass());
129 layer_tree_impl()->set_needs_update_draw_properties();
[email protected]94f206c12012-08-25 00:09:14130}
131
[email protected]7aba6662013-03-12 10:17:34132scoped_ptr<LayerImpl> LayerImpl::RemoveChild(LayerImpl* child) {
[email protected]50761e92013-03-29 20:51:28133 for (OwnedLayerImplList::iterator it = children_.begin();
[email protected]7aba6662013-03-12 10:17:34134 it != children_.end();
135 ++it) {
136 if (*it == child) {
137 scoped_ptr<LayerImpl> ret = children_.take(it);
138 children_.erase(it);
139 layer_tree_impl()->set_needs_update_draw_properties();
140 return ret.Pass();
[email protected]94f206c12012-08-25 00:09:14141 }
[email protected]7aba6662013-03-12 10:17:34142 }
danakjf446a072014-09-27 21:55:48143 return nullptr;
[email protected]94f206c12012-08-25 00:09:14144}
145
[email protected]ad0250b2014-01-18 03:24:34146void LayerImpl::SetParent(LayerImpl* parent) {
147 if (parent_should_know_need_push_properties()) {
148 if (parent_)
149 parent_->RemoveDependentNeedsPushProperties();
150 if (parent)
151 parent->AddDependentNeedsPushProperties();
152 }
153 parent_ = parent;
154}
155
[email protected]7aba6662013-03-12 10:17:34156void LayerImpl::ClearChildList() {
157 if (children_.empty())
158 return;
[email protected]0ede3bb2012-12-09 09:14:39159
[email protected]7aba6662013-03-12 10:17:34160 children_.clear();
161 layer_tree_impl()->set_needs_update_draw_properties();
[email protected]94f206c12012-08-25 00:09:14162}
163
[email protected]0e98cdd2013-08-23 00:44:30164bool LayerImpl::HasAncestor(const LayerImpl* ancestor) const {
165 if (!ancestor)
166 return false;
167
168 for (const LayerImpl* layer = this; layer; layer = layer->parent()) {
169 if (layer == ancestor)
170 return true;
171 }
172
173 return false;
174}
175
176void LayerImpl::SetScrollParent(LayerImpl* parent) {
177 if (scroll_parent_ == parent)
178 return;
179
[email protected]d097e242014-02-28 21:51:11180 if (parent)
181 DCHECK_EQ(layer_tree_impl()->LayerById(parent->id()), parent);
[email protected]0e98cdd2013-08-23 00:44:30182
183 scroll_parent_ = parent;
[email protected]ad0250b2014-01-18 03:24:34184 SetNeedsPushProperties();
[email protected]0e98cdd2013-08-23 00:44:30185}
186
[email protected]9f3be432013-12-03 03:53:22187void LayerImpl::SetDebugInfo(
ssid911e40e2015-02-09 17:55:20188 scoped_refptr<base::trace_event::ConvertableToTraceFormat> other) {
[email protected]9f3be432013-12-03 03:53:22189 debug_info_ = other;
[email protected]ad0250b2014-01-18 03:24:34190 SetNeedsPushProperties();
[email protected]9f3be432013-12-03 03:53:22191}
192
[email protected]0e98cdd2013-08-23 00:44:30193void LayerImpl::SetScrollChildren(std::set<LayerImpl*>* children) {
194 if (scroll_children_.get() == children)
195 return;
196 scroll_children_.reset(children);
[email protected]ad0250b2014-01-18 03:24:34197 SetNeedsPushProperties();
[email protected]0e98cdd2013-08-23 00:44:30198}
199
[email protected]ad63b2f2014-08-11 17:39:54200void LayerImpl::SetNumDescendantsThatDrawContent(int num_descendants) {
201 if (num_descendants_that_draw_content_ == num_descendants)
202 return;
203 num_descendants_that_draw_content_ = num_descendants;
204 SetNeedsPushProperties();
205}
206
[email protected]0e98cdd2013-08-23 00:44:30207void LayerImpl::SetClipParent(LayerImpl* ancestor) {
208 if (clip_parent_ == ancestor)
209 return;
210
[email protected]0e98cdd2013-08-23 00:44:30211 clip_parent_ = ancestor;
[email protected]ad0250b2014-01-18 03:24:34212 SetNeedsPushProperties();
[email protected]0e98cdd2013-08-23 00:44:30213}
214
215void LayerImpl::SetClipChildren(std::set<LayerImpl*>* children) {
216 if (clip_children_.get() == children)
217 return;
218 clip_children_.reset(children);
[email protected]ad0250b2014-01-18 03:24:34219 SetNeedsPushProperties();
[email protected]0e98cdd2013-08-23 00:44:30220}
221
vollick692444f2015-05-20 15:39:14222void LayerImpl::SetTransformTreeIndex(int index) {
223 transform_tree_index_ = index;
224 SetNeedsPushProperties();
225}
226
227void LayerImpl::SetClipTreeIndex(int index) {
228 clip_tree_index_ = index;
229 SetNeedsPushProperties();
230}
231
232void LayerImpl::SetOpacityTreeIndex(int index) {
233 opacity_tree_index_ = index;
234 SetNeedsPushProperties();
235}
236
[email protected]0e5f7142013-05-24 06:45:36237void LayerImpl::PassCopyRequests(ScopedPtrVector<CopyOutputRequest>* requests) {
ennef44fcf92015-06-12 23:56:32238 // In the case that a layer still has a copy request, this means that there's
239 // a commit to the active tree without a draw. This only happens in some
240 // edge cases during lost context or visibility changes, so don't try to
241 // handle preserving these output requests (and their surface).
242 if (!copy_requests_.empty()) {
243 layer_tree_impl()->RemoveLayerWithCopyOutputRequest(this);
244 // Destroying these will abort them.
245 copy_requests_.clear();
246 }
247
[email protected]0e5f7142013-05-24 06:45:36248 if (requests->empty())
[email protected]18a70192013-04-26 16:18:25249 return;
ennef44fcf92015-06-12 23:56:32250
awoloszyne83f28c2014-12-22 15:40:00251 DCHECK(render_surface());
[email protected]f5de9e5b2013-07-30 22:26:57252 bool was_empty = copy_requests_.empty();
weiliangcc1878c62014-09-02 22:43:17253 copy_requests_.insert_and_take(copy_requests_.end(), requests);
[email protected]0e5f7142013-05-24 06:45:36254 requests->clear();
[email protected]18a70192013-04-26 16:18:25255
[email protected]f5de9e5b2013-07-30 22:26:57256 if (was_empty && layer_tree_impl()->IsActiveTree())
[email protected]30fe19ff2013-07-04 00:54:45257 layer_tree_impl()->AddLayerWithCopyOutputRequest(this);
[email protected]18a70192013-04-26 16:18:25258 NoteLayerPropertyChangedForSubtree();
259}
260
[email protected]d4d017e2013-06-20 21:46:11261void LayerImpl::TakeCopyRequestsAndTransformToTarget(
262 ScopedPtrVector<CopyOutputRequest>* requests) {
[email protected]df17af52014-02-06 02:20:40263 DCHECK(!copy_requests_.empty());
264 DCHECK(layer_tree_impl()->IsActiveTree());
awoloszyne83f28c2014-12-22 15:40:00265 DCHECK_EQ(render_target(), this);
[email protected]18a70192013-04-26 16:18:25266
[email protected]30fe19ff2013-07-04 00:54:45267 size_t first_inserted_request = requests->size();
weiliangcc1878c62014-09-02 22:43:17268 requests->insert_and_take(requests->end(), &copy_requests_);
[email protected]0e5f7142013-05-24 06:45:36269 copy_requests_.clear();
[email protected]d4d017e2013-06-20 21:46:11270
[email protected]30fe19ff2013-07-04 00:54:45271 for (size_t i = first_inserted_request; i < requests->size(); ++i) {
[email protected]d4d017e2013-06-20 21:46:11272 CopyOutputRequest* request = requests->at(i);
273 if (!request->has_area())
274 continue;
275
276 gfx::Rect request_in_layer_space = request->area();
danakje0f14a882015-06-18 05:05:07277 request_in_layer_space.Intersect(gfx::Rect(bounds()));
[email protected]8a822692014-02-12 17:30:55278 request->set_area(MathUtil::MapEnclosingClippedRect(
danakje0f14a882015-06-18 05:05:07279 draw_properties_.target_space_transform, request_in_layer_space));
[email protected]d4d017e2013-06-20 21:46:11280 }
[email protected]30fe19ff2013-07-04 00:54:45281
[email protected]df17af52014-02-06 02:20:40282 layer_tree_impl()->RemoveLayerWithCopyOutputRequest(this);
danakj0cf95392015-01-29 17:56:54283 layer_tree_impl()->set_needs_update_draw_properties();
[email protected]18a70192013-04-26 16:18:25284}
285
[email protected]7644fa22014-04-28 12:20:33286void LayerImpl::ClearRenderSurfaceLayerList() {
awoloszyne83f28c2014-12-22 15:40:00287 if (render_surface_)
288 render_surface_->ClearLayerLists();
[email protected]7644fa22014-04-28 12:20:33289}
290
[email protected]9be1adc82014-05-07 15:39:41291void LayerImpl::PopulateSharedQuadState(SharedQuadState* state) const {
Dana Jansensc46d3742015-06-18 01:33:14292 state->SetAll(draw_properties_.target_space_transform, bounds(),
danakj64767d902015-06-19 00:10:43293 draw_properties_.visible_layer_rect, draw_properties_.clip_rect,
jaydasikad36e7fa2015-07-14 15:15:04294 is_clipped_, draw_properties_.opacity,
danakj64767d902015-06-19 00:10:43295 draw_properties_.blend_mode, sorting_context_id_);
[email protected]94f206c12012-08-25 00:09:14296}
297
enne467829b2015-02-13 02:39:34298void LayerImpl::PopulateScaledSharedQuadState(SharedQuadState* state,
299 float scale) const {
300 gfx::Transform scaled_draw_transform =
301 draw_properties_.target_space_transform;
302 scaled_draw_transform.Scale(SK_MScalar1 / scale, SK_MScalar1 / scale);
Dana Jansensc46d3742015-06-18 01:33:14303 gfx::Size scaled_bounds = gfx::ToCeiledSize(gfx::ScaleSize(bounds(), scale));
danakj64767d902015-06-19 00:10:43304 gfx::Rect scaled_visible_layer_rect =
305 gfx::ScaleToEnclosingRect(visible_layer_rect(), scale);
306 scaled_visible_layer_rect.Intersect(gfx::Rect(scaled_bounds));
enne467829b2015-02-13 02:39:34307
danakj64767d902015-06-19 00:10:43308 state->SetAll(scaled_draw_transform, scaled_bounds, scaled_visible_layer_rect,
jaydasikad36e7fa2015-07-14 15:15:04309 draw_properties().clip_rect, is_clipped_,
danakj64767d902015-06-19 00:10:43310 draw_properties().opacity, draw_properties().blend_mode,
311 sorting_context_id_);
enne467829b2015-02-13 02:39:34312}
313
[email protected]ffbb2212013-06-02 23:47:59314bool LayerImpl::WillDraw(DrawMode draw_mode,
315 ResourceProvider* resource_provider) {
[email protected]ed511b8d2013-03-25 03:29:29316 // WillDraw/DidDraw must be matched.
[email protected]ffbb2212013-06-02 23:47:59317 DCHECK_NE(DRAW_MODE_NONE, draw_mode);
318 DCHECK_EQ(DRAW_MODE_NONE, current_draw_mode_);
319 current_draw_mode_ = draw_mode;
320 return true;
[email protected]94f206c12012-08-25 00:09:14321}
322
[email protected]7aba6662013-03-12 10:17:34323void LayerImpl::DidDraw(ResourceProvider* resource_provider) {
[email protected]ffbb2212013-06-02 23:47:59324 DCHECK_NE(DRAW_MODE_NONE, current_draw_mode_);
325 current_draw_mode_ = DRAW_MODE_NONE;
[email protected]94f206c12012-08-25 00:09:14326}
327
[email protected]7aba6662013-03-12 10:17:34328bool LayerImpl::ShowDebugBorders() const {
[email protected]846f455b2013-03-18 19:07:41329 return layer_tree_impl()->debug_state().show_debug_borders;
[email protected]3dce37232012-11-15 01:47:44330}
331
[email protected]7aba6662013-03-12 10:17:34332void LayerImpl::GetDebugBorderProperties(SkColor* color, float* width) const {
333 if (draws_content_) {
334 *color = DebugColors::ContentLayerBorderColor();
335 *width = DebugColors::ContentLayerBorderWidth(layer_tree_impl());
336 return;
337 }
338
339 if (masks_to_bounds_) {
340 *color = DebugColors::MaskingLayerBorderColor();
341 *width = DebugColors::MaskingLayerBorderWidth(layer_tree_impl());
342 return;
343 }
344
345 *color = DebugColors::ContainerLayerBorderColor();
346 *width = DebugColors::ContainerLayerBorderWidth(layer_tree_impl());
347}
348
349void LayerImpl::AppendDebugBorderQuad(
[email protected]c6707fd2014-06-23 05:50:36350 RenderPass* render_pass,
Dana Jansensc46d3742015-06-18 01:33:14351 const gfx::Size& bounds,
[email protected]7aba6662013-03-12 10:17:34352 const SharedQuadState* shared_quad_state,
353 AppendQuadsData* append_quads_data) const {
[email protected]7aba6662013-03-12 10:17:34354 SkColor color;
355 float width;
356 GetDebugBorderProperties(&color, &width);
Dana Jansensc46d3742015-06-18 01:33:14357 AppendDebugBorderQuad(render_pass, bounds, shared_quad_state,
358 append_quads_data, color, width);
[email protected]bec084292013-05-21 21:31:44359}
360
[email protected]c6707fd2014-06-23 05:50:36361void LayerImpl::AppendDebugBorderQuad(RenderPass* render_pass,
Dana Jansensc46d3742015-06-18 01:33:14362 const gfx::Size& bounds,
[email protected]bec084292013-05-21 21:31:44363 const SharedQuadState* shared_quad_state,
364 AppendQuadsData* append_quads_data,
365 SkColor color,
366 float width) const {
367 if (!ShowDebugBorders())
368 return;
[email protected]7aba6662013-03-12 10:17:34369
Dana Jansensc46d3742015-06-18 01:33:14370 gfx::Rect quad_rect(bounds);
[email protected]9bf06c72014-03-07 18:16:24371 gfx::Rect visible_quad_rect(quad_rect);
[email protected]f7030c32014-07-03 18:54:34372 DebugBorderDrawQuad* debug_border_quad =
373 render_pass->CreateAndAppendDrawQuad<DebugBorderDrawQuad>();
[email protected]9bf06c72014-03-07 18:16:24374 debug_border_quad->SetNew(
375 shared_quad_state, quad_rect, visible_quad_rect, color, width);
danakj069ac122015-02-12 00:59:22376 if (contents_opaque()) {
377 // When opaque, draw a second inner border that is thicker than the outer
378 // border, but more transparent.
379 static const float kFillOpacity = 0.3f;
380 SkColor fill_color = SkColorSetA(
381 color, static_cast<uint8_t>(SkColorGetA(color) * kFillOpacity));
382 float fill_width = width * 3;
383 gfx::Rect fill_rect = quad_rect;
384 fill_rect.Inset(fill_width / 2.f, fill_width / 2.f);
enneb79d5f142015-04-23 19:59:55385 if (fill_rect.IsEmpty())
386 return;
danakj069ac122015-02-12 00:59:22387 gfx::Rect visible_fill_rect =
388 gfx::IntersectRects(visible_quad_rect, fill_rect);
389 DebugBorderDrawQuad* fill_quad =
390 render_pass->CreateAndAppendDrawQuad<DebugBorderDrawQuad>();
391 fill_quad->SetNew(shared_quad_state, fill_rect, visible_fill_rect,
392 fill_color, fill_width);
393 }
[email protected]7aba6662013-03-12 10:17:34394}
395
396bool LayerImpl::HasDelegatedContent() const {
397 return false;
398}
399
400bool LayerImpl::HasContributingDelegatedRenderPasses() const {
401 return false;
402}
403
[email protected]0cd7d6f72014-08-22 14:50:51404RenderPassId LayerImpl::FirstContributingRenderPassId() const {
405 return RenderPassId(0, 0);
[email protected]7aba6662013-03-12 10:17:34406}
407
[email protected]0cd7d6f72014-08-22 14:50:51408RenderPassId LayerImpl::NextContributingRenderPassId(RenderPassId id) const {
409 return RenderPassId(0, 0);
[email protected]7aba6662013-03-12 10:17:34410}
411
jbaumanbbd425e2015-05-19 00:33:35412void LayerImpl::GetContentsResourceId(ResourceId* resource_id,
ennef6f3fbba42014-10-16 18:16:49413 gfx::Size* resource_size) const {
[email protected]7aba6662013-03-12 10:17:34414 NOTREACHED();
ennef6f3fbba42014-10-16 18:16:49415 *resource_id = 0;
[email protected]7aba6662013-03-12 10:17:34416}
417
[email protected]3244c9132014-01-23 10:39:12418gfx::Vector2dF LayerImpl::ScrollBy(const gfx::Vector2dF& scroll) {
aeliasd0070ba2015-01-31 13:44:49419 gfx::ScrollOffset adjusted_scroll(scroll);
bokan57ebc052015-05-29 13:14:21420 if (!user_scrollable_horizontal_)
421 adjusted_scroll.set_x(0);
422 if (!user_scrollable_vertical_)
423 adjusted_scroll.set_y(0);
[email protected]d30700f12013-07-31 08:21:01424 DCHECK(scrollable());
aeliasd0070ba2015-01-31 13:44:49425 gfx::ScrollOffset old_offset = CurrentScrollOffset();
426 gfx::ScrollOffset new_offset =
427 ClampScrollOffsetToLimits(old_offset + adjusted_scroll);
428 SetCurrentScrollOffset(new_offset);
[email protected]adeda572014-01-31 00:49:47429
aeliasd0070ba2015-01-31 13:44:49430 gfx::ScrollOffset unscrolled =
431 old_offset + gfx::ScrollOffset(scroll) - new_offset;
432 return gfx::Vector2dF(unscrolled.x(), unscrolled.y());
[email protected]7aba6662013-03-12 10:17:34433}
434
[email protected]adeda572014-01-31 00:49:47435void LayerImpl::SetScrollClipLayer(int scroll_clip_layer_id) {
436 scroll_clip_layer_ = layer_tree_impl()->LayerById(scroll_clip_layer_id);
437}
438
timav3ca696932014-10-15 02:19:04439bool LayerImpl::user_scrollable(ScrollbarOrientation orientation) const {
440 return (orientation == HORIZONTAL) ? user_scrollable_horizontal_
441 : user_scrollable_vertical_;
442}
443
[email protected]58241dc2013-08-20 01:39:25444void LayerImpl::ApplySentScrollDeltasFromAbortedCommit() {
[email protected]3519b872013-07-30 07:17:50445 DCHECK(layer_tree_impl()->IsActiveTree());
aeliasd0070ba2015-01-31 13:44:49446 scroll_offset_->AbortCommit();
[email protected]58241dc2013-08-20 01:39:25447}
448
[email protected]5ff3c9782013-04-29 17:35:12449InputHandler::ScrollStatus LayerImpl::TryScroll(
[email protected]14bc5d682014-01-17 07:26:47450 const gfx::PointF& screen_space_point,
rbyers18779d822015-02-05 06:22:06451 InputHandler::ScrollInputType type,
452 ScrollBlocksOn effective_block_mode) const {
[email protected]7aba6662013-03-12 10:17:34453 if (should_scroll_on_main_thread()) {
[email protected]ed511b8d2013-03-25 03:29:29454 TRACE_EVENT0("cc", "LayerImpl::TryScroll: Failed ShouldScrollOnMainThread");
ericrk7c030992015-02-20 01:39:38455 return InputHandler::SCROLL_ON_MAIN_THREAD;
[email protected]7aba6662013-03-12 10:17:34456 }
457
458 if (!screen_space_transform().IsInvertible()) {
[email protected]ed511b8d2013-03-25 03:29:29459 TRACE_EVENT0("cc", "LayerImpl::TryScroll: Ignored NonInvertibleTransform");
ericrk7c030992015-02-20 01:39:38460 return InputHandler::SCROLL_IGNORED;
[email protected]7aba6662013-03-12 10:17:34461 }
462
463 if (!non_fast_scrollable_region().IsEmpty()) {
464 bool clipped = false;
465 gfx::Transform inverse_screen_space_transform(
466 gfx::Transform::kSkipInitialization);
467 if (!screen_space_transform().GetInverse(&inverse_screen_space_transform)) {
468 // TODO(shawnsingh): We shouldn't be applying a projection if screen space
469 // transform is uninvertible here. Perhaps we should be returning
ericrk7c030992015-02-20 01:39:38470 // SCROLL_ON_MAIN_THREAD in this case?
[email protected]3dce37232012-11-15 01:47:44471 }
472
danakj2c8d12c2015-06-18 06:15:33473 gfx::PointF hit_test_point_in_layer_space = MathUtil::ProjectPoint(
474 inverse_screen_space_transform, screen_space_point, &clipped);
[email protected]7aba6662013-03-12 10:17:34475 if (!clipped &&
476 non_fast_scrollable_region().Contains(
477 gfx::ToRoundedPoint(hit_test_point_in_layer_space))) {
478 TRACE_EVENT0("cc",
[email protected]ed511b8d2013-03-25 03:29:29479 "LayerImpl::tryScroll: Failed NonFastScrollableRegion");
ericrk7c030992015-02-20 01:39:38480 return InputHandler::SCROLL_ON_MAIN_THREAD;
[email protected]3dce37232012-11-15 01:47:44481 }
[email protected]7aba6662013-03-12 10:17:34482 }
[email protected]3dce37232012-11-15 01:47:44483
rbyers18779d822015-02-05 06:22:06484 if (have_scroll_event_handlers() &&
ericrk7c030992015-02-20 01:39:38485 effective_block_mode & SCROLL_BLOCKS_ON_SCROLL_EVENT) {
rbyers18779d822015-02-05 06:22:06486 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Failed ScrollEventHandlers");
ericrk7c030992015-02-20 01:39:38487 return InputHandler::SCROLL_ON_MAIN_THREAD;
rbyers18779d822015-02-05 06:22:06488 }
489
ericrk7c030992015-02-20 01:39:38490 if (type == InputHandler::WHEEL && have_wheel_event_handlers() &&
491 effective_block_mode & SCROLL_BLOCKS_ON_WHEEL_EVENT) {
[email protected]ed511b8d2013-03-25 03:29:29492 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Failed WheelEventHandlers");
ericrk7c030992015-02-20 01:39:38493 return InputHandler::SCROLL_ON_MAIN_THREAD;
[email protected]7aba6662013-03-12 10:17:34494 }
495
496 if (!scrollable()) {
497 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Ignored not scrollable");
ericrk7c030992015-02-20 01:39:38498 return InputHandler::SCROLL_IGNORED;
[email protected]7aba6662013-03-12 10:17:34499 }
500
miletusf57925d2014-10-01 19:38:13501 gfx::ScrollOffset max_scroll_offset = MaxScrollOffset();
[email protected]adeda572014-01-31 00:49:47502 if (max_scroll_offset.x() <= 0 && max_scroll_offset.y() <= 0) {
[email protected]7aba6662013-03-12 10:17:34503 TRACE_EVENT0("cc",
504 "LayerImpl::tryScroll: Ignored. Technically scrollable,"
505 " but has no affordance in either direction.");
ericrk7c030992015-02-20 01:39:38506 return InputHandler::SCROLL_IGNORED;
[email protected]7aba6662013-03-12 10:17:34507 }
508
ericrk7c030992015-02-20 01:39:38509 return InputHandler::SCROLL_STARTED;
[email protected]3dce37232012-11-15 01:47:44510}
511
[email protected]7aba6662013-03-12 10:17:34512skia::RefPtr<SkPicture> LayerImpl::GetPicture() {
513 return skia::RefPtr<SkPicture>();
[email protected]76481592012-09-21 16:47:06514}
515
[email protected]7aba6662013-03-12 10:17:34516scoped_ptr<LayerImpl> LayerImpl::CreateLayerImpl(LayerTreeImpl* tree_impl) {
aeliasd0070ba2015-01-31 13:44:49517 return LayerImpl::Create(tree_impl, layer_id_, scroll_offset_);
[email protected]94f206c12012-08-25 00:09:14518}
519
[email protected]7aba6662013-03-12 10:17:34520void LayerImpl::PushPropertiesTo(LayerImpl* layer) {
[email protected]a2566412014-06-05 03:14:20521 layer->SetTransformOrigin(transform_origin_);
[email protected]7aba6662013-03-12 10:17:34522 layer->SetBackgroundColor(background_color_);
523 layer->SetBounds(bounds_);
[email protected]7aba6662013-03-12 10:17:34524 layer->SetDoubleSided(double_sided_);
525 layer->SetDrawCheckerboardForMissingTiles(
526 draw_checkerboard_for_missing_tiles_);
[email protected]7aba6662013-03-12 10:17:34527 layer->SetDrawsContent(DrawsContent());
[email protected]c0ae06c12013-06-24 18:32:19528 layer->SetHideLayerAndSubtree(hide_layer_and_subtree_);
ennef44fcf92015-06-12 23:56:32529 layer->SetHasRenderSurface(!!render_surface());
[email protected]7aba6662013-03-12 10:17:34530 layer->SetFilters(filters());
[email protected]7aba6662013-03-12 10:17:34531 layer->SetBackgroundFilters(background_filters());
532 layer->SetMasksToBounds(masks_to_bounds_);
533 layer->SetShouldScrollOnMainThread(should_scroll_on_main_thread_);
534 layer->SetHaveWheelEventHandlers(have_wheel_event_handlers_);
[email protected]f998c532014-03-31 20:02:51535 layer->SetHaveScrollEventHandlers(have_scroll_event_handlers_);
rbyers18779d822015-02-05 06:22:06536 layer->SetScrollBlocksOn(scroll_blocks_on_);
[email protected]7aba6662013-03-12 10:17:34537 layer->SetNonFastScrollableRegion(non_fast_scrollable_region_);
538 layer->SetTouchEventHandlerRegion(touch_event_handler_region_);
539 layer->SetContentsOpaque(contents_opaque_);
[email protected]43615872013-03-13 16:35:17540 layer->SetOpacity(opacity_);
[email protected]7bbeaf4e2013-11-26 10:27:22541 layer->SetBlendMode(blend_mode_);
542 layer->SetIsRootForIsolatedGroup(is_root_for_isolated_group_);
[email protected]7aba6662013-03-12 10:17:34543 layer->SetPosition(position_);
544 layer->SetIsContainerForFixedPositionLayers(
545 is_container_for_fixed_position_layers_);
[email protected]fe956c9c42013-04-09 04:26:33546 layer->SetPositionConstraint(position_constraint_);
[email protected]56fffdd2014-02-11 19:50:57547 layer->SetShouldFlattenTransform(should_flatten_transform_);
ennee95b1542015-04-20 20:35:50548 layer->set_should_flatten_transform_from_property_tree(
549 should_flatten_transform_from_property_tree_);
jaydasikad36e7fa2015-07-14 15:15:04550 layer->set_is_clipped(is_clipped_);
[email protected]7aba6662013-03-12 10:17:34551 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_);
[email protected]08bdf1b2014-04-16 23:23:29552 layer->SetTransformAndInvertibility(transform_, transform_is_invertible_);
[email protected]9bd1cb52013-01-03 22:26:33553
[email protected]adeda572014-01-31 00:49:47554 layer->SetScrollClipLayer(scroll_clip_layer_ ? scroll_clip_layer_->id()
555 : Layer::INVALID_ID);
[email protected]59a7d552013-10-22 03:36:43556 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_);
557 layer->set_user_scrollable_vertical(user_scrollable_vertical_);
bokanc687507f2014-11-04 23:41:42558
miletusff93ab72015-01-30 04:30:44559 layer->SetScrollCompensationAdjustment(scroll_compensation_adjustment_);
bokanc687507f2014-11-04 23:41:42560
aeliasd0070ba2015-01-31 13:44:49561 layer->PushScrollOffset(nullptr);
562
[email protected]a9d4d4f2014-06-19 06:49:28563 layer->Set3dSortingContextId(sorting_context_id_);
[email protected]ad63b2f2014-08-11 17:39:54564 layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_);
[email protected]b34c97982013-08-24 15:21:38565
vollick692444f2015-05-20 15:39:14566 layer->SetTransformTreeIndex(transform_tree_index_);
567 layer->SetClipTreeIndex(clip_tree_index_);
568 layer->SetOpacityTreeIndex(opacity_tree_index_);
ennee95b1542015-04-20 20:35:50569 layer->set_offset_to_transform_parent(offset_to_transform_parent_);
570
kulkarni.a4015690f12014-10-10 13:50:06571 LayerImpl* scroll_parent = nullptr;
[email protected]d097e242014-02-28 21:51:11572 if (scroll_parent_) {
[email protected]0e98cdd2013-08-23 00:44:30573 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id());
[email protected]d097e242014-02-28 21:51:11574 DCHECK(scroll_parent);
575 }
[email protected]0e98cdd2013-08-23 00:44:30576
577 layer->SetScrollParent(scroll_parent);
578 if (scroll_children_) {
579 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>;
580 for (std::set<LayerImpl*>::iterator it = scroll_children_->begin();
[email protected]d097e242014-02-28 21:51:11581 it != scroll_children_->end();
582 ++it) {
583 DCHECK_EQ((*it)->scroll_parent(), this);
584 LayerImpl* scroll_child =
585 layer->layer_tree_impl()->LayerById((*it)->id());
586 DCHECK(scroll_child);
587 scroll_children->insert(scroll_child);
588 }
[email protected]0e98cdd2013-08-23 00:44:30589 layer->SetScrollChildren(scroll_children);
[email protected]d097e242014-02-28 21:51:11590 } else {
kulkarni.a4015690f12014-10-10 13:50:06591 layer->SetScrollChildren(nullptr);
[email protected]0e98cdd2013-08-23 00:44:30592 }
593
kulkarni.a4015690f12014-10-10 13:50:06594 LayerImpl* clip_parent = nullptr;
[email protected]0e98cdd2013-08-23 00:44:30595 if (clip_parent_) {
596 clip_parent = layer->layer_tree_impl()->LayerById(
597 clip_parent_->id());
[email protected]d097e242014-02-28 21:51:11598 DCHECK(clip_parent);
[email protected]0e98cdd2013-08-23 00:44:30599 }
600
601 layer->SetClipParent(clip_parent);
602 if (clip_children_) {
603 std::set<LayerImpl*>* clip_children = new std::set<LayerImpl*>;
604 for (std::set<LayerImpl*>::iterator it = clip_children_->begin();
605 it != clip_children_->end(); ++it)
606 clip_children->insert(layer->layer_tree_impl()->LayerById((*it)->id()));
607 layer->SetClipChildren(clip_children);
[email protected]d097e242014-02-28 21:51:11608 } else {
kulkarni.a4015690f12014-10-10 13:50:06609 layer->SetClipChildren(nullptr);
[email protected]0e98cdd2013-08-23 00:44:30610 }
611
[email protected]0e5f7142013-05-24 06:45:36612 layer->PassCopyRequests(&copy_requests_);
[email protected]18a70192013-04-26 16:18:25613
[email protected]7aba6662013-03-12 10:17:34614 // If the main thread commits multiple times before the impl thread actually
615 // draws, then damage tracking will become incorrect if we simply clobber the
[email protected]ed511b8d2013-03-25 03:29:29616 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e.
[email protected]7aba6662013-03-12 10:17:34617 // union) any update changes that have occurred on the main thread.
618 update_rect_.Union(layer->update_rect());
[email protected]ad0250b2014-01-18 03:24:34619 layer->SetUpdateRect(update_rect_);
[email protected]7aba6662013-03-12 10:17:34620
[email protected]7aba6662013-03-12 10:17:34621 layer->SetStackingOrderChanged(stacking_order_changed_);
[email protected]ad0250b2014-01-18 03:24:34622 layer->SetDebugInfo(debug_info_);
[email protected]7aba6662013-03-12 10:17:34623
vmpstr3d1d72c2015-01-26 18:27:40624 if (frame_timing_requests_dirty_) {
vmpstr3a24da5042015-05-27 03:33:31625 layer->SetFrameTimingRequests(frame_timing_requests_);
vmpstr3d1d72c2015-01-26 18:27:40626 frame_timing_requests_dirty_ = false;
627 }
628
[email protected]7aba6662013-03-12 10:17:34629 // Reset any state that should be cleared for the next update.
630 stacking_order_changed_ = false;
danakj19f0c9e2014-10-11 03:24:42631 update_rect_ = gfx::Rect();
[email protected]ad0250b2014-01-18 03:24:34632 needs_push_properties_ = false;
633 num_dependents_need_push_properties_ = 0;
[email protected]caa567d2012-12-20 07:56:16634}
635
[email protected]fef74fd2014-02-27 06:28:17636gfx::Vector2dF LayerImpl::FixedContainerSizeDelta() const {
637 if (!scroll_clip_layer_)
638 return gfx::Vector2dF();
639
[email protected]587941d2014-08-22 01:40:01640 gfx::Vector2dF delta_from_scroll = scroll_clip_layer_->bounds_delta();
bokan8273d962014-10-22 02:40:27641
642 // In virtual-viewport mode, we don't need to compensate for pinch zoom or
643 // scale since the fixed container is the outer viewport, which sits below
644 // the page scale.
bokan57ebc052015-05-29 13:14:21645 return delta_from_scroll;
[email protected]fef74fd2014-02-27 06:28:17646}
647
[email protected]7aba6662013-03-12 10:17:34648base::DictionaryValue* LayerImpl::LayerTreeAsJson() const {
[email protected]7aba6662013-03-12 10:17:34649 base::DictionaryValue* result = new base::DictionaryValue;
r.kasibhatlafd17d0e2015-05-17 11:12:07650 result->SetInteger("LayerId", id());
[email protected]7aba6662013-03-12 10:17:34651 result->SetString("LayerType", LayerTypeAsString());
652
[email protected]46c76952013-07-10 00:21:45653 base::ListValue* list = new base::ListValue;
bokancccfde72014-10-08 15:15:22654 list->AppendInteger(bounds().width());
655 list->AppendInteger(bounds().height());
[email protected]7aba6662013-03-12 10:17:34656 result->Set("Bounds", list);
657
658 list = new base::ListValue;
659 list->AppendDouble(position_.x());
660 list->AppendDouble(position_.y());
661 result->Set("Position", list);
662
663 const gfx::Transform& gfx_transform = draw_properties_.target_space_transform;
664 double transform[16];
665 gfx_transform.matrix().asColMajord(transform);
666 list = new base::ListValue;
667 for (int i = 0; i < 16; ++i)
668 list->AppendDouble(transform[i]);
669 result->Set("DrawTransform", list);
670
671 result->SetBoolean("DrawsContent", draws_content_);
[email protected]a9d4d4f2014-06-19 06:49:28672 result->SetBoolean("Is3dSorted", Is3dSorted());
ericrk7c030992015-02-20 01:39:38673 result->SetDouble("OPACITY", opacity());
[email protected]46c76952013-07-10 00:21:45674 result->SetBoolean("ContentsOpaque", contents_opaque_);
[email protected]7aba6662013-03-12 10:17:34675
[email protected]adeda572014-01-31 00:49:47676 if (scrollable())
677 result->SetBoolean("Scrollable", true);
[email protected]d993e032013-06-07 00:16:16678
[email protected]9d161d22013-10-29 20:54:10679 if (have_wheel_event_handlers_)
680 result->SetBoolean("WheelHandler", have_wheel_event_handlers_);
[email protected]f998c532014-03-31 20:02:51681 if (have_scroll_event_handlers_)
682 result->SetBoolean("ScrollHandler", have_scroll_event_handlers_);
[email protected]9d161d22013-10-29 20:54:10683 if (!touch_event_handler_region_.IsEmpty()) {
684 scoped_ptr<base::Value> region = touch_event_handler_region_.AsValue();
685 result->Set("TouchRegion", region.release());
686 }
687
rbyers18779d822015-02-05 06:22:06688 if (scroll_blocks_on_) {
689 list = new base::ListValue;
ericrk7c030992015-02-20 01:39:38690 if (scroll_blocks_on_ & SCROLL_BLOCKS_ON_START_TOUCH)
rbyers18779d822015-02-05 06:22:06691 list->AppendString("StartTouch");
ericrk7c030992015-02-20 01:39:38692 if (scroll_blocks_on_ & SCROLL_BLOCKS_ON_WHEEL_EVENT)
rbyers18779d822015-02-05 06:22:06693 list->AppendString("WheelEvent");
ericrk7c030992015-02-20 01:39:38694 if (scroll_blocks_on_ & SCROLL_BLOCKS_ON_SCROLL_EVENT)
rbyers18779d822015-02-05 06:22:06695 list->AppendString("ScrollEvent");
696 result->Set("ScrollBlocksOn", list);
697 }
698
[email protected]7aba6662013-03-12 10:17:34699 list = new base::ListValue;
700 for (size_t i = 0; i < children_.size(); ++i)
701 list->Append(children_[i]->LayerTreeAsJson());
702 result->Set("Children", list);
703
704 return result;
[email protected]b9dcf43a2013-01-09 00:15:29705}
706
[email protected]7aba6662013-03-12 10:17:34707void LayerImpl::SetStackingOrderChanged(bool stacking_order_changed) {
708 if (stacking_order_changed) {
709 stacking_order_changed_ = true;
710 NoteLayerPropertyChangedForSubtree();
711 }
[email protected]aedf4e52013-01-09 23:24:44712}
713
[email protected]7aba6662013-03-12 10:17:34714void LayerImpl::NoteLayerPropertyChanged() {
715 layer_property_changed_ = true;
716 layer_tree_impl()->set_needs_update_draw_properties();
[email protected]ad0250b2014-01-18 03:24:34717 SetNeedsPushProperties();
[email protected]48871fc2013-01-23 07:36:51718}
719
[email protected]7aba6662013-03-12 10:17:34720void LayerImpl::NoteLayerPropertyChangedForSubtree() {
[email protected]ad0250b2014-01-18 03:24:34721 layer_property_changed_ = true;
722 layer_tree_impl()->set_needs_update_draw_properties();
723 for (size_t i = 0; i < children_.size(); ++i)
724 children_[i]->NoteLayerPropertyChangedForDescendantsInternal();
725 SetNeedsPushProperties();
726}
727
728void LayerImpl::NoteLayerPropertyChangedForDescendantsInternal() {
729 layer_property_changed_ = true;
730 for (size_t i = 0; i < children_.size(); ++i)
731 children_[i]->NoteLayerPropertyChangedForDescendantsInternal();
[email protected]94f206c12012-08-25 00:09:14732}
733
[email protected]7aba6662013-03-12 10:17:34734void LayerImpl::NoteLayerPropertyChangedForDescendants() {
735 layer_tree_impl()->set_needs_update_draw_properties();
736 for (size_t i = 0; i < children_.size(); ++i)
[email protected]ad0250b2014-01-18 03:24:34737 children_[i]->NoteLayerPropertyChangedForDescendantsInternal();
738 SetNeedsPushProperties();
[email protected]7aba6662013-03-12 10:17:34739}
[email protected]94f206c12012-08-25 00:09:14740
danakjf9427572015-04-24 22:19:02741void LayerImpl::ValidateQuadResourcesInternal(DrawQuad* quad) const {
742#if DCHECK_IS_ON()
vmpstr0eca2e82015-06-02 22:14:46743 const ResourceProvider* resource_provider =
744 layer_tree_impl_->resource_provider();
745 for (ResourceId resource_id : quad->resources)
746 resource_provider->ValidateResource(resource_id);
danakjf9427572015-04-24 22:19:02747#endif
748}
749
[email protected]7aba6662013-03-12 10:17:34750const char* LayerImpl::LayerTypeAsString() const {
[email protected]f256b7fd2013-05-15 01:49:30751 return "cc::LayerImpl";
[email protected]7aba6662013-03-12 10:17:34752}
[email protected]94f206c12012-08-25 00:09:14753
[email protected]7aba6662013-03-12 10:17:34754void LayerImpl::ResetAllChangeTrackingForSubtree() {
755 layer_property_changed_ = false;
[email protected]7aba6662013-03-12 10:17:34756
danakj19f0c9e2014-10-11 03:24:42757 update_rect_ = gfx::Rect();
[email protected]cfa7fd922014-04-29 11:50:03758 damage_rect_ = gfx::RectF();
[email protected]7aba6662013-03-12 10:17:34759
awoloszyne83f28c2014-12-22 15:40:00760 if (render_surface_)
761 render_surface_->ResetPropertyChangedFlag();
[email protected]7aba6662013-03-12 10:17:34762
763 if (mask_layer_)
764 mask_layer_->ResetAllChangeTrackingForSubtree();
765
766 if (replica_layer_) {
767 // This also resets the replica mask, if it exists.
768 replica_layer_->ResetAllChangeTrackingForSubtree();
769 }
770
771 for (size_t i = 0; i < children_.size(); ++i)
772 children_[i]->ResetAllChangeTrackingForSubtree();
[email protected]ad0250b2014-01-18 03:24:34773
774 needs_push_properties_ = false;
775 num_dependents_need_push_properties_ = 0;
[email protected]7aba6662013-03-12 10:17:34776}
777
ajuma59c23b42015-05-25 20:18:37778void LayerImpl::UpdatePropertyTreeTransform() {
779 if (transform_tree_index_ != -1) {
780 TransformTree& transform_tree =
781 layer_tree_impl()->property_trees()->transform_tree;
782 TransformNode* node = transform_tree.Node(transform_tree_index_);
ajumae7425272015-07-13 18:37:34783 // A LayerImpl's own current state is insufficient for determining whether
784 // it owns a TransformNode, since this depends on the state of the
785 // corresponding Layer at the time of the last commit. For example, a
786 // transform animation might have been in progress at the time the last
787 // commit started, but might have finished since then on the compositor
788 // thread.
789 if (node->owner_id != id())
790 return;
ajuma59c23b42015-05-25 20:18:37791 if (node->data.local != transform_) {
792 node->data.local = transform_;
793 node->data.needs_local_transform_update = true;
794 transform_tree.set_needs_update(true);
795 // TODO(ajuma): The current criteria for creating clip nodes means that
796 // property trees may need to be rebuilt when the new transform isn't
797 // axis-aligned wrt the old transform (see Layer::SetTransform). Since
798 // rebuilding property trees every frame of a transform animation is
799 // something we should try to avoid, change property tree-building so that
800 // it doesn't depend on axis aliginment.
801 }
802 }
803}
804
805void LayerImpl::UpdatePropertyTreeOpacity() {
806 if (opacity_tree_index_ != -1) {
807 OpacityTree& opacity_tree =
808 layer_tree_impl()->property_trees()->opacity_tree;
809 OpacityNode* node = opacity_tree.Node(opacity_tree_index_);
ajumae7425272015-07-13 18:37:34810 // A LayerImpl's own current state is insufficient for determining whether
811 // it owns an OpacityNode, since this depends on the state of the
812 // corresponding Layer at the time of the last commit. For example, an
813 // opacity animation might have been in progress at the time the last commit
814 // started, but might have finished since then on the compositor thread.
815 if (node->owner_id != id())
816 return;
jaydasika9fc1aef2015-06-26 23:35:57817 node->data.opacity = opacity_;
818 opacity_tree.set_needs_update(true);
ajuma59c23b42015-05-25 20:18:37819 }
820}
821
ajuma9db24fb2015-06-29 20:15:07822void LayerImpl::UpdatePropertyTreeForScrollingAndAnimationIfNeeded() {
823 if (scrollable())
824 UpdatePropertyTreeScrollOffset();
825
ajumae7425272015-07-13 18:37:34826 if (HasAnyAnimationTargetingProperty(Animation::OPACITY))
ajuma9db24fb2015-06-29 20:15:07827 UpdatePropertyTreeOpacity();
828
ajumae7425272015-07-13 18:37:34829 if (HasAnyAnimationTargetingProperty(Animation::TRANSFORM))
ajuma9db24fb2015-06-29 20:15:07830 UpdatePropertyTreeTransform();
831}
832
miletusf57925d2014-10-01 19:38:13833gfx::ScrollOffset LayerImpl::ScrollOffsetForAnimation() const {
aeliasd0070ba2015-01-31 13:44:49834 return CurrentScrollOffset();
[email protected]b8384e22013-12-03 02:20:48835}
836
[email protected]b4c6d812013-10-03 15:48:56837void LayerImpl::OnFilterAnimated(const FilterOperations& filters) {
838 SetFilters(filters);
839}
840
[email protected]7aba6662013-03-12 10:17:34841void LayerImpl::OnOpacityAnimated(float opacity) {
842 SetOpacity(opacity);
ajuma59c23b42015-05-25 20:18:37843 UpdatePropertyTreeOpacity();
[email protected]7aba6662013-03-12 10:17:34844}
845
846void LayerImpl::OnTransformAnimated(const gfx::Transform& transform) {
847 SetTransform(transform);
ajuma59c23b42015-05-25 20:18:37848 UpdatePropertyTreeTransform();
[email protected]7aba6662013-03-12 10:17:34849}
850
miletusf57925d2014-10-01 19:38:13851void LayerImpl::OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) {
[email protected]b8384e22013-12-03 02:20:48852 // Only layers in the active tree should need to do anything here, since
853 // layers in the pending tree will find out about these changes as a
aeliasd0070ba2015-01-31 13:44:49854 // result of the shared SyncedProperty.
[email protected]b8384e22013-12-03 02:20:48855 if (!IsActive())
856 return;
857
aeliasd0070ba2015-01-31 13:44:49858 SetCurrentScrollOffset(scroll_offset);
[email protected]b8384e22013-12-03 02:20:48859
860 layer_tree_impl_->DidAnimateScrollOffset();
861}
862
[email protected]1c24cf2962013-11-18 23:34:51863void LayerImpl::OnAnimationWaitingForDeletion() {}
864
[email protected]7aba6662013-03-12 10:17:34865bool LayerImpl::IsActive() const {
866 return layer_tree_impl_->IsActiveTree();
867}
868
bokancccfde72014-10-08 15:15:22869gfx::Size LayerImpl::bounds() const {
bokanef971462014-10-13 22:58:32870 gfx::Vector2d delta = gfx::ToCeiledVector2d(bounds_delta_);
871 return gfx::Size(bounds_.width() + delta.x(),
872 bounds_.height() + delta.y());
873}
874
875gfx::SizeF LayerImpl::BoundsForScrolling() const {
876 return gfx::SizeF(bounds_.width() + bounds_delta_.x(),
877 bounds_.height() + bounds_delta_.y());
[email protected]fef74fd2014-02-27 06:28:17878}
879
[email protected]64348ea2014-01-29 22:58:26880void LayerImpl::SetBounds(const gfx::Size& bounds) {
[email protected]7aba6662013-03-12 10:17:34881 if (bounds_ == bounds)
882 return;
883
884 bounds_ = bounds;
[email protected]fef74fd2014-02-27 06:28:17885
sataya.m07f11a82014-10-07 14:29:18886 ScrollbarParametersDidChange(true);
[email protected]fef74fd2014-02-27 06:28:17887 if (masks_to_bounds())
888 NoteLayerPropertyChangedForSubtree();
889 else
890 NoteLayerPropertyChanged();
891}
892
[email protected]587941d2014-08-22 01:40:01893void LayerImpl::SetBoundsDelta(const gfx::Vector2dF& bounds_delta) {
ajuma6b46da22015-06-25 21:53:02894 DCHECK(IsActive());
[email protected]587941d2014-08-22 01:40:01895 if (bounds_delta_ == bounds_delta)
[email protected]fef74fd2014-02-27 06:28:17896 return;
897
[email protected]587941d2014-08-22 01:40:01898 bounds_delta_ = bounds_delta;
[email protected]7aba6662013-03-12 10:17:34899
ajuma6b46da22015-06-25 21:53:02900 TransformTree& transform_tree =
901 layer_tree_impl()->property_trees()->transform_tree;
ajumadd2802e72015-06-30 20:28:29902 if (this == layer_tree_impl()->InnerViewportContainerLayer())
903 transform_tree.SetInnerViewportBoundsDelta(bounds_delta);
904 else if (this == layer_tree_impl()->OuterViewportContainerLayer())
905 transform_tree.SetOuterViewportBoundsDelta(bounds_delta);
ajuma6b46da22015-06-25 21:53:02906
aelias1505e722014-10-07 22:19:46907 ScrollbarParametersDidChange(true);
miletus8bd08a622015-06-16 18:44:52908
909 if (masks_to_bounds()) {
910 // If layer is clipping, then update the clip node using the new bounds.
911 ClipNode* clip_node =
912 layer_tree_impl()->property_trees()->clip_tree.Node(clip_tree_index());
913 if (clip_node) {
914 DCHECK(id() == clip_node->owner_id);
915 clip_node->data.clip =
916 gfx::RectF(gfx::PointF() + offset_to_transform_parent(), bounds());
917 layer_tree_impl()->property_trees()->clip_tree.set_needs_update(true);
918 }
919
[email protected]7aba6662013-03-12 10:17:34920 NoteLayerPropertyChangedForSubtree();
miletus8bd08a622015-06-16 18:44:52921 } else {
[email protected]7aba6662013-03-12 10:17:34922 NoteLayerPropertyChanged();
miletus8bd08a622015-06-16 18:44:52923 }
[email protected]7aba6662013-03-12 10:17:34924}
925
926void LayerImpl::SetMaskLayer(scoped_ptr<LayerImpl> mask_layer) {
927 int new_layer_id = mask_layer ? mask_layer->id() : -1;
928
929 if (mask_layer) {
930 DCHECK_EQ(layer_tree_impl(), mask_layer->layer_tree_impl());
931 DCHECK_NE(new_layer_id, mask_layer_id_);
932 } else if (new_layer_id == mask_layer_id_) {
933 return;
934 }
935
936 mask_layer_ = mask_layer.Pass();
937 mask_layer_id_ = new_layer_id;
938 if (mask_layer_)
[email protected]ad0250b2014-01-18 03:24:34939 mask_layer_->SetParent(this);
[email protected]7aba6662013-03-12 10:17:34940 NoteLayerPropertyChangedForSubtree();
941}
942
943scoped_ptr<LayerImpl> LayerImpl::TakeMaskLayer() {
944 mask_layer_id_ = -1;
945 return mask_layer_.Pass();
946}
947
948void LayerImpl::SetReplicaLayer(scoped_ptr<LayerImpl> replica_layer) {
949 int new_layer_id = replica_layer ? replica_layer->id() : -1;
950
951 if (replica_layer) {
952 DCHECK_EQ(layer_tree_impl(), replica_layer->layer_tree_impl());
953 DCHECK_NE(new_layer_id, replica_layer_id_);
954 } else if (new_layer_id == replica_layer_id_) {
955 return;
956 }
957
958 replica_layer_ = replica_layer.Pass();
959 replica_layer_id_ = new_layer_id;
960 if (replica_layer_)
[email protected]ad0250b2014-01-18 03:24:34961 replica_layer_->SetParent(this);
[email protected]7aba6662013-03-12 10:17:34962 NoteLayerPropertyChangedForSubtree();
963}
964
965scoped_ptr<LayerImpl> LayerImpl::TakeReplicaLayer() {
966 replica_layer_id_ = -1;
967 return replica_layer_.Pass();
968}
969
[email protected]80413d72013-08-30 20:25:33970ScrollbarLayerImplBase* LayerImpl::ToScrollbarLayer() {
kulkarni.a4015690f12014-10-10 13:50:06971 return nullptr;
[email protected]7aba6662013-03-12 10:17:34972}
973
974void LayerImpl::SetDrawsContent(bool draws_content) {
975 if (draws_content_ == draws_content)
976 return;
977
978 draws_content_ = draws_content;
979 NoteLayerPropertyChanged();
980}
981
[email protected]c0ae06c12013-06-24 18:32:19982void LayerImpl::SetHideLayerAndSubtree(bool hide) {
983 if (hide_layer_and_subtree_ == hide)
984 return;
985
986 hide_layer_and_subtree_ = hide;
987 NoteLayerPropertyChangedForSubtree();
988}
989
[email protected]a2566412014-06-05 03:14:20990void LayerImpl::SetTransformOrigin(const gfx::Point3F& transform_origin) {
991 if (transform_origin_ == transform_origin)
[email protected]7aba6662013-03-12 10:17:34992 return;
[email protected]a2566412014-06-05 03:14:20993 transform_origin_ = transform_origin;
[email protected]7aba6662013-03-12 10:17:34994 NoteLayerPropertyChangedForSubtree();
995}
996
997void LayerImpl::SetBackgroundColor(SkColor background_color) {
998 if (background_color_ == background_color)
999 return;
1000
1001 background_color_ = background_color;
1002 NoteLayerPropertyChanged();
1003}
1004
[email protected]2c4cbec2013-06-04 21:14:501005SkColor LayerImpl::SafeOpaqueBackgroundColor() const {
1006 SkColor color = background_color();
1007 if (SkColorGetA(color) == 255 && !contents_opaque()) {
1008 color = SK_ColorTRANSPARENT;
1009 } else if (SkColorGetA(color) != 255 && contents_opaque()) {
1010 for (const LayerImpl* layer = parent(); layer;
1011 layer = layer->parent()) {
1012 color = layer->background_color();
1013 if (SkColorGetA(color) == 255)
1014 break;
1015 }
1016 if (SkColorGetA(color) != 255)
1017 color = layer_tree_impl()->background_color();
1018 if (SkColorGetA(color) != 255)
1019 color = SkColorSetA(color, 255);
1020 }
1021 return color;
1022}
1023
[email protected]ae6b1a72013-06-25 18:49:291024void LayerImpl::SetFilters(const FilterOperations& filters) {
[email protected]7aba6662013-03-12 10:17:341025 if (filters_ == filters)
1026 return;
1027
[email protected]7aba6662013-03-12 10:17:341028 filters_ = filters;
1029 NoteLayerPropertyChangedForSubtree();
1030}
1031
[email protected]b4c6d812013-10-03 15:48:561032bool LayerImpl::FilterIsAnimating() const {
loysod71ece82015-07-03 13:48:501033 return layer_animation_controller_
1034 ? layer_animation_controller_->IsAnimatingProperty(
1035 Animation::FILTER)
1036 : layer_tree_impl_->IsAnimatingFilterProperty(this);
[email protected]b4c6d812013-10-03 15:48:561037}
1038
1039bool LayerImpl::FilterIsAnimatingOnImplOnly() const {
loysod71ece82015-07-03 13:48:501040 if (!layer_animation_controller_)
1041 return layer_tree_impl_->FilterIsAnimatingOnImplOnly(this);
1042
[email protected]b4c6d812013-10-03 15:48:561043 Animation* filter_animation =
ericrk7c030992015-02-20 01:39:381044 layer_animation_controller_->GetAnimation(Animation::FILTER);
[email protected]b4c6d812013-10-03 15:48:561045 return filter_animation && filter_animation->is_impl_only();
1046}
1047
[email protected]7aba6662013-03-12 10:17:341048void LayerImpl::SetBackgroundFilters(
[email protected]ae6b1a72013-06-25 18:49:291049 const FilterOperations& filters) {
[email protected]7aba6662013-03-12 10:17:341050 if (background_filters_ == filters)
1051 return;
1052
1053 background_filters_ = filters;
1054 NoteLayerPropertyChanged();
1055}
1056
[email protected]7aba6662013-03-12 10:17:341057void LayerImpl::SetMasksToBounds(bool masks_to_bounds) {
1058 if (masks_to_bounds_ == masks_to_bounds)
1059 return;
1060
1061 masks_to_bounds_ = masks_to_bounds;
1062 NoteLayerPropertyChangedForSubtree();
1063}
1064
1065void LayerImpl::SetContentsOpaque(bool opaque) {
1066 if (contents_opaque_ == opaque)
1067 return;
1068
1069 contents_opaque_ = opaque;
1070 NoteLayerPropertyChangedForSubtree();
1071}
1072
1073void LayerImpl::SetOpacity(float opacity) {
1074 if (opacity_ == opacity)
1075 return;
1076
1077 opacity_ = opacity;
[email protected]af37ce802013-10-07 23:53:281078 NoteLayerPropertyChangedForSubtree();
[email protected]7aba6662013-03-12 10:17:341079}
1080
1081bool LayerImpl::OpacityIsAnimating() const {
loysod71ece82015-07-03 13:48:501082 return layer_animation_controller_
1083 ? layer_animation_controller_->IsAnimatingProperty(
1084 Animation::OPACITY)
1085 : layer_tree_impl_->IsAnimatingOpacityProperty(this);
1086}
1087
1088bool LayerImpl::HasPotentiallyRunningOpacityAnimation() const {
1089 if (layer_animation_controller_) {
1090 if (Animation* animation =
1091 layer_animation_controller()->GetAnimation(Animation::OPACITY)) {
1092 return !animation->is_finished();
1093 }
1094 return false;
1095 } else {
1096 return layer_tree_impl_->HasPotentiallyRunningOpacityAnimation(this);
1097 }
[email protected]7aba6662013-03-12 10:17:341098}
1099
[email protected]43615872013-03-13 16:35:171100bool LayerImpl::OpacityIsAnimatingOnImplOnly() const {
loysod71ece82015-07-03 13:48:501101 if (!layer_animation_controller_)
1102 return layer_tree_impl_->OpacityIsAnimatingOnImplOnly(this);
1103
[email protected]43615872013-03-13 16:35:171104 Animation* opacity_animation =
ericrk7c030992015-02-20 01:39:381105 layer_animation_controller_->GetAnimation(Animation::OPACITY);
[email protected]43615872013-03-13 16:35:171106 return opacity_animation && opacity_animation->is_impl_only();
1107}
1108
[email protected]7bbeaf4e2013-11-26 10:27:221109void LayerImpl::SetBlendMode(SkXfermode::Mode blend_mode) {
1110 if (blend_mode_ == blend_mode)
1111 return;
1112
1113 blend_mode_ = blend_mode;
1114 NoteLayerPropertyChangedForSubtree();
1115}
1116
1117void LayerImpl::SetIsRootForIsolatedGroup(bool root) {
1118 if (is_root_for_isolated_group_ == root)
1119 return;
1120
1121 is_root_for_isolated_group_ = root;
[email protected]ad0250b2014-01-18 03:24:341122 SetNeedsPushProperties();
[email protected]7bbeaf4e2013-11-26 10:27:221123}
1124
[email protected]14bc5d682014-01-17 07:26:471125void LayerImpl::SetPosition(const gfx::PointF& position) {
[email protected]7aba6662013-03-12 10:17:341126 if (position_ == position)
1127 return;
1128
1129 position_ = position;
1130 NoteLayerPropertyChangedForSubtree();
1131}
1132
[email protected]56fffdd2014-02-11 19:50:571133void LayerImpl::SetShouldFlattenTransform(bool flatten) {
1134 if (should_flatten_transform_ == flatten)
[email protected]7aba6662013-03-12 10:17:341135 return;
1136
[email protected]56fffdd2014-02-11 19:50:571137 should_flatten_transform_ = flatten;
1138 NoteLayerPropertyChangedForSubtree();
1139}
1140
[email protected]a9d4d4f2014-06-19 06:49:281141void LayerImpl::Set3dSortingContextId(int id) {
1142 if (id == sorting_context_id_)
[email protected]56fffdd2014-02-11 19:50:571143 return;
[email protected]a9d4d4f2014-06-19 06:49:281144 sorting_context_id_ = id;
[email protected]7aba6662013-03-12 10:17:341145 NoteLayerPropertyChangedForSubtree();
1146}
1147
vmpstr3a24da5042015-05-27 03:33:311148void LayerImpl::SetFrameTimingRequests(
1149 const std::vector<FrameTimingRequest>& requests) {
1150 frame_timing_requests_ = requests;
vmpstr3d1d72c2015-01-26 18:27:401151 frame_timing_requests_dirty_ = true;
1152 SetNeedsPushProperties();
1153}
1154
vmpstrd704c872015-04-03 20:29:511155void LayerImpl::GatherFrameTimingRequestIds(std::vector<int64_t>* request_ids) {
1156 for (const auto& request : frame_timing_requests_)
1157 request_ids->push_back(request.id());
1158}
1159
[email protected]7aba6662013-03-12 10:17:341160void LayerImpl::SetTransform(const gfx::Transform& transform) {
1161 if (transform_ == transform)
1162 return;
1163
1164 transform_ = transform;
[email protected]08bdf1b2014-04-16 23:23:291165 transform_is_invertible_ = transform_.IsInvertible();
1166 NoteLayerPropertyChangedForSubtree();
1167}
1168
1169void LayerImpl::SetTransformAndInvertibility(const gfx::Transform& transform,
1170 bool transform_is_invertible) {
1171 if (transform_ == transform) {
1172 DCHECK(transform_is_invertible_ == transform_is_invertible)
1173 << "Can't change invertibility if transform is unchanged";
1174 return;
1175 }
1176 transform_ = transform;
1177 transform_is_invertible_ = transform_is_invertible;
[email protected]af37ce802013-10-07 23:53:281178 NoteLayerPropertyChangedForSubtree();
[email protected]7aba6662013-03-12 10:17:341179}
1180
1181bool LayerImpl::TransformIsAnimating() const {
loysod71ece82015-07-03 13:48:501182 return layer_animation_controller_
1183 ? layer_animation_controller_->IsAnimatingProperty(
1184 Animation::TRANSFORM)
1185 : layer_tree_impl_->IsAnimatingTransformProperty(this);
1186}
1187
1188bool LayerImpl::HasPotentiallyRunningTransformAnimation() const {
1189 if (layer_animation_controller_) {
1190 if (Animation* animation =
1191 layer_animation_controller()->GetAnimation(Animation::TRANSFORM)) {
1192 return !animation->is_finished();
1193 }
1194 return false;
1195 } else {
1196 return layer_tree_impl_->HasPotentiallyRunningTransformAnimation(this);
1197 }
[email protected]7aba6662013-03-12 10:17:341198}
1199
[email protected]43615872013-03-13 16:35:171200bool LayerImpl::TransformIsAnimatingOnImplOnly() const {
loysod71ece82015-07-03 13:48:501201 if (!layer_animation_controller_)
1202 return layer_tree_impl_->TransformIsAnimatingOnImplOnly(this);
1203
[email protected]43615872013-03-13 16:35:171204 Animation* transform_animation =
ericrk7c030992015-02-20 01:39:381205 layer_animation_controller_->GetAnimation(Animation::TRANSFORM);
[email protected]43615872013-03-13 16:35:171206 return transform_animation && transform_animation->is_impl_only();
1207}
1208
loysod71ece82015-07-03 13:48:501209bool LayerImpl::HasOnlyTranslationTransforms() const {
1210 if (!layer_animation_controller_)
1211 return layer_tree_impl_->HasOnlyTranslationTransforms(this);
1212
1213 return layer_animation_controller_->HasOnlyTranslationTransforms();
1214}
1215
1216bool LayerImpl::MaximumTargetScale(float* max_scale) const {
1217 if (!layer_animation_controller_)
1218 return layer_tree_impl_->MaximumTargetScale(this, max_scale);
1219
1220 return layer_animation_controller_->MaximumTargetScale(max_scale);
1221}
1222
1223bool LayerImpl::AnimationStartScale(float* start_scale) const {
1224 if (!layer_animation_controller_)
1225 return layer_tree_impl_->AnimationStartScale(this, start_scale);
1226
1227 return layer_animation_controller_->AnimationStartScale(start_scale);
1228}
1229
ajumae7425272015-07-13 18:37:341230bool LayerImpl::HasAnyAnimationTargetingProperty(
1231 Animation::TargetProperty property) const {
1232 if (!layer_animation_controller_)
1233 return layer_tree_impl_->HasAnyAnimationTargetingProperty(this, property);
1234
1235 return !!layer_animation_controller_->GetAnimation(property);
1236}
1237
loysod71ece82015-07-03 13:48:501238bool LayerImpl::HasFilterAnimationThatInflatesBounds() const {
1239 if (!layer_animation_controller_)
1240 return layer_tree_impl_->HasFilterAnimationThatInflatesBounds(this);
1241
1242 return layer_animation_controller_->HasFilterAnimationThatInflatesBounds();
1243}
1244
1245bool LayerImpl::HasTransformAnimationThatInflatesBounds() const {
1246 if (!layer_animation_controller_)
1247 return layer_tree_impl_->HasTransformAnimationThatInflatesBounds(this);
1248
1249 return layer_animation_controller_->HasTransformAnimationThatInflatesBounds();
1250}
1251
1252bool LayerImpl::HasAnimationThatInflatesBounds() const {
1253 if (!layer_animation_controller_)
1254 return layer_tree_impl_->HasAnimationThatInflatesBounds(this);
1255
1256 return layer_animation_controller_->HasAnimationThatInflatesBounds();
1257}
1258
1259bool LayerImpl::FilterAnimationBoundsForBox(const gfx::BoxF& box,
1260 gfx::BoxF* bounds) const {
1261 if (!layer_animation_controller_)
1262 return layer_tree_impl_->FilterAnimationBoundsForBox(this, box, bounds);
1263
1264 return layer_animation_controller_->FilterAnimationBoundsForBox(box, bounds);
1265}
1266
1267bool LayerImpl::TransformAnimationBoundsForBox(const gfx::BoxF& box,
1268 gfx::BoxF* bounds) const {
1269 if (!layer_animation_controller_)
1270 return layer_tree_impl_->TransformAnimationBoundsForBox(this, box, bounds);
1271
1272 return layer_animation_controller_->TransformAnimationBoundsForBox(box,
1273 bounds);
1274}
1275
danakj19f0c9e2014-10-11 03:24:421276void LayerImpl::SetUpdateRect(const gfx::Rect& update_rect) {
[email protected]ad0250b2014-01-18 03:24:341277 update_rect_ = update_rect;
1278 SetNeedsPushProperties();
1279}
1280
[email protected]cfa7fd922014-04-29 11:50:031281void LayerImpl::AddDamageRect(const gfx::RectF& damage_rect) {
1282 damage_rect_ = gfx::UnionRects(damage_rect_, damage_rect);
1283}
1284
hushb0ee8dc2015-06-10 00:48:571285bool LayerImpl::IsExternalScrollActive() const {
1286 return layer_tree_impl_->IsExternalScrollActive();
[email protected]251699b2013-10-09 00:21:261287}
1288
aeliasd0070ba2015-01-31 13:44:491289void LayerImpl::SetCurrentScrollOffset(const gfx::ScrollOffset& scroll_offset) {
1290 DCHECK(IsActive());
1291 if (scroll_offset_->SetCurrent(scroll_offset))
hush33370e12015-04-07 03:49:501292 DidUpdateScrollOffset(false);
1293}
1294
1295void LayerImpl::SetCurrentScrollOffsetFromDelegate(
1296 const gfx::ScrollOffset& scroll_offset) {
1297 DCHECK(IsActive());
1298 if (scroll_offset_->SetCurrent(scroll_offset))
1299 DidUpdateScrollOffset(true);
boliu7d5dbab2014-10-10 20:05:471300}
1301
aeliasd0070ba2015-01-31 13:44:491302void LayerImpl::PushScrollOffsetFromMainThread(
1303 const gfx::ScrollOffset& scroll_offset) {
1304 PushScrollOffset(&scroll_offset);
[email protected]b34c97982013-08-24 15:21:381305}
[email protected]7aba6662013-03-12 10:17:341306
danakjb5197d32015-02-03 23:39:491307void LayerImpl::PushScrollOffsetFromMainThreadAndClobberActiveValue(
1308 const gfx::ScrollOffset& scroll_offset) {
1309 scroll_offset_->set_clobber_active_value();
1310 PushScrollOffset(&scroll_offset);
1311}
1312
aeliasd0070ba2015-01-31 13:44:491313gfx::ScrollOffset LayerImpl::PullDeltaForMainThread() {
miletusd799dd22015-03-19 04:23:171314 // TODO(miletus): Remove all this temporary flooring machinery when
1315 // Blink fully supports fractional scrolls.
1316 gfx::ScrollOffset current_offset = CurrentScrollOffset();
bokan5a025bd62015-07-20 11:08:201317 gfx::ScrollOffset current_delta = IsActive()
1318 ? scroll_offset_->Delta()
1319 : scroll_offset_->PendingDelta().get();
1320 gfx::ScrollOffset floored_delta(floor(current_delta.x()),
1321 floor(current_delta.y()));
1322 gfx::ScrollOffset diff_delta = floored_delta - current_delta;
1323 gfx::ScrollOffset tmp_offset = current_offset + diff_delta;
miletusd799dd22015-03-19 04:23:171324 scroll_offset_->SetCurrent(tmp_offset);
1325 gfx::ScrollOffset delta = scroll_offset_->PullDeltaForMainThread();
1326 scroll_offset_->SetCurrent(current_offset);
1327 return delta;
aeliasd0070ba2015-01-31 13:44:491328}
[email protected]adeda572014-01-31 00:49:471329
aeliasd0070ba2015-01-31 13:44:491330gfx::ScrollOffset LayerImpl::CurrentScrollOffset() const {
1331 return scroll_offset_->Current(IsActive());
[email protected]7aba6662013-03-12 10:17:341332}
1333
[email protected]1960a712013-04-30 17:06:471334gfx::Vector2dF LayerImpl::ScrollDelta() const {
aeliasd0070ba2015-01-31 13:44:491335 if (IsActive())
1336 return gfx::Vector2dF(scroll_offset_->Delta().x(),
1337 scroll_offset_->Delta().y());
1338 else
1339 return gfx::Vector2dF(scroll_offset_->PendingDelta().get().x(),
1340 scroll_offset_->PendingDelta().get().y());
1341}
1342
1343void LayerImpl::SetScrollDelta(const gfx::Vector2dF& delta) {
1344 DCHECK(IsActive());
ajuma5e47dec2015-05-29 22:10:231345 DCHECK(scrollable() || delta.IsZero());
aeliasd0070ba2015-01-31 13:44:491346 SetCurrentScrollOffset(scroll_offset_->ActiveBase() +
1347 gfx::ScrollOffset(delta));
1348}
1349
1350gfx::ScrollOffset LayerImpl::BaseScrollOffset() const {
1351 if (IsActive())
1352 return scroll_offset_->ActiveBase();
1353 else
1354 return scroll_offset_->PendingBase();
1355}
1356
1357void LayerImpl::PushScrollOffset(const gfx::ScrollOffset* scroll_offset) {
1358 DCHECK(scroll_offset || IsActive());
1359 bool changed = false;
1360 if (scroll_offset) {
1361 DCHECK(!IsActive() || !layer_tree_impl_->FindPendingTreeLayerById(id()));
1362 changed |= scroll_offset_->PushFromMainThread(*scroll_offset);
miletusf57925d2014-10-01 19:38:131363 }
aeliasd0070ba2015-01-31 13:44:491364 if (IsActive()) {
1365 changed |= scroll_offset_->PushPendingToActive();
aeliasd0070ba2015-01-31 13:44:491366 }
1367
1368 if (changed)
hush33370e12015-04-07 03:49:501369 DidUpdateScrollOffset(false);
[email protected]1960a712013-04-30 17:06:471370}
1371
ajuma9db24fb2015-06-29 20:15:071372void LayerImpl::UpdatePropertyTreeScrollOffset() {
enne1eb3a922015-06-17 17:37:501373 // TODO(enne): in the future, scrolling should update the scroll tree
1374 // directly instead of going through layers.
1375 if (transform_tree_index_ != -1) {
1376 TransformTree& transform_tree =
1377 layer_tree_impl()->property_trees()->transform_tree;
1378 TransformNode* node = transform_tree.Node(transform_tree_index_);
1379 gfx::ScrollOffset current_offset = scroll_offset_->Current(IsActive());
1380 if (node->data.scroll_offset != current_offset) {
1381 node->data.scroll_offset = current_offset;
1382 node->data.needs_local_transform_update = true;
1383 transform_tree.set_needs_update(true);
1384 }
1385 }
1386}
1387
hush33370e12015-04-07 03:49:501388void LayerImpl::DidUpdateScrollOffset(bool is_from_root_delegate) {
enne04192cf92015-05-20 00:32:221389 DCHECK(scroll_offset_);
1390
hush33370e12015-04-07 03:49:501391 if (!is_from_root_delegate)
1392 layer_tree_impl()->DidUpdateScrollOffset(id());
aeliasd0070ba2015-01-31 13:44:491393 NoteLayerPropertyChangedForSubtree();
1394 ScrollbarParametersDidChange(false);
enne04192cf92015-05-20 00:32:221395
ajuma9db24fb2015-06-29 20:15:071396 UpdatePropertyTreeScrollOffset();
enne04192cf92015-05-20 00:32:221397
vmpstre86240822015-05-11 21:10:111398 // Inform the pending twin that a property changed.
1399 if (layer_tree_impl()->IsActiveTree()) {
1400 LayerImpl* pending_twin = layer_tree_impl()->FindPendingTreeLayerById(id());
1401 if (pending_twin)
enne04192cf92015-05-20 00:32:221402 pending_twin->DidUpdateScrollOffset(is_from_root_delegate);
vmpstre86240822015-05-11 21:10:111403 }
[email protected]ffb2720f2013-03-15 19:18:371404}
1405
[email protected]7aba6662013-03-12 10:17:341406void LayerImpl::SetDoubleSided(bool double_sided) {
1407 if (double_sided_ == double_sided)
1408 return;
1409
1410 double_sided_ = double_sided;
1411 NoteLayerPropertyChangedForSubtree();
1412}
1413
danakj64767d902015-06-19 00:10:431414SimpleEnclosedRegion LayerImpl::VisibleOpaqueRegion() const {
[email protected]7aba6662013-03-12 10:17:341415 if (contents_opaque())
danakj64767d902015-06-19 00:10:431416 return SimpleEnclosedRegion(visible_layer_rect());
[email protected]d5467eb72014-08-22 01:16:431417 return SimpleEnclosedRegion();
[email protected]7aba6662013-03-12 10:17:341418}
1419
[email protected]37349bc2013-06-04 01:31:521420void LayerImpl::DidBeginTracing() {}
1421
[email protected]9db24462014-01-14 02:25:501422void LayerImpl::ReleaseResources() {}
[email protected]7aba6662013-03-12 10:17:341423
vmpstr9ce5c662015-02-05 23:29:261424void LayerImpl::RecreateResources() {
1425}
1426
miletusf57925d2014-10-01 19:38:131427gfx::ScrollOffset LayerImpl::MaxScrollOffset() const {
[email protected]adeda572014-01-31 00:49:471428 if (!scroll_clip_layer_ || bounds().IsEmpty())
miletusf57925d2014-10-01 19:38:131429 return gfx::ScrollOffset();
[email protected]610834cb2014-01-29 13:54:331430
aeliasc26b50b72015-07-14 20:18:251431 LayerImpl const* page_scale_layer = layer_tree_impl()->PageScaleLayer();
[email protected]adeda572014-01-31 00:49:471432 DCHECK(this != page_scale_layer);
[email protected]adeda572014-01-31 00:49:471433 DCHECK(this != layer_tree_impl()->InnerViewportScrollLayer() ||
1434 IsContainerForFixedPositionLayers());
1435
[email protected]adeda572014-01-31 00:49:471436 float scale_factor = 1.f;
1437 for (LayerImpl const* current_layer = this;
aeliasd0070ba2015-01-31 13:44:491438 current_layer != scroll_clip_layer_->parent();
[email protected]adeda572014-01-31 00:49:471439 current_layer = current_layer->parent()) {
aeliasd0070ba2015-01-31 13:44:491440 if (current_layer == page_scale_layer)
1441 scale_factor = layer_tree_impl()->current_page_scale_factor();
[email protected]adeda572014-01-31 00:49:471442 }
[email protected]adeda572014-01-31 00:49:471443
aeliasd0070ba2015-01-31 13:44:491444 gfx::SizeF scaled_scroll_bounds =
1445 gfx::ToFlooredSize(gfx::ScaleSize(BoundsForScrolling(), scale_factor));
[email protected]0072c112014-04-22 05:53:401446 scaled_scroll_bounds = gfx::ToFlooredSize(scaled_scroll_bounds);
[email protected]adeda572014-01-31 00:49:471447
miletusf57925d2014-10-01 19:38:131448 gfx::ScrollOffset max_offset(
[email protected]adeda572014-01-31 00:49:471449 scaled_scroll_bounds.width() - scroll_clip_layer_->bounds().width(),
1450 scaled_scroll_bounds.height() - scroll_clip_layer_->bounds().height());
1451 // We need the final scroll offset to be in CSS coords.
1452 max_offset.Scale(1 / scale_factor);
miletusf57925d2014-10-01 19:38:131453 max_offset.SetToMax(gfx::ScrollOffset());
1454 return max_offset;
[email protected]adeda572014-01-31 00:49:471455}
1456
aeliasd0070ba2015-01-31 13:44:491457gfx::ScrollOffset LayerImpl::ClampScrollOffsetToLimits(
1458 gfx::ScrollOffset offset) const {
1459 offset.SetToMin(MaxScrollOffset());
1460 offset.SetToMax(gfx::ScrollOffset());
1461 return offset;
1462}
[email protected]adeda572014-01-31 00:49:471463
aeliasd0070ba2015-01-31 13:44:491464gfx::Vector2dF LayerImpl::ClampScrollToMaxScrollOffset() {
1465 gfx::ScrollOffset old_offset = CurrentScrollOffset();
1466 gfx::ScrollOffset clamped_offset = ClampScrollOffsetToLimits(old_offset);
miletusf57925d2014-10-01 19:38:131467 gfx::Vector2dF delta = clamped_offset.DeltaFrom(old_offset);
[email protected]adeda572014-01-31 00:49:471468 if (!delta.IsZero())
1469 ScrollBy(delta);
[email protected]adeda572014-01-31 00:49:471470 return delta;
1471}
1472
1473void LayerImpl::SetScrollbarPosition(ScrollbarLayerImplBase* scrollbar_layer,
sataya.m07f11a82014-10-07 14:29:181474 LayerImpl* scrollbar_clip_layer,
1475 bool on_resize) const {
[email protected]adeda572014-01-31 00:49:471476 DCHECK(scrollbar_layer);
aeliasc26b50b72015-07-14 20:18:251477 LayerImpl* page_scale_layer = layer_tree_impl()->PageScaleLayer();
[email protected]adeda572014-01-31 00:49:471478
1479 DCHECK(this != page_scale_layer);
1480 DCHECK(scrollbar_clip_layer);
bokanef971462014-10-13 22:58:321481 gfx::RectF clip_rect(gfx::PointF(),
1482 scrollbar_clip_layer->BoundsForScrolling());
[email protected]adeda572014-01-31 00:49:471483
1484 // See comment in MaxScrollOffset() regarding the use of the content layer
1485 // bounds here.
bokanef971462014-10-13 22:58:321486 gfx::RectF scroll_rect(gfx::PointF(), BoundsForScrolling());
[email protected]adeda572014-01-31 00:49:471487
1488 if (scroll_rect.size().IsEmpty())
1489 return;
1490
miletusf57925d2014-10-01 19:38:131491 gfx::ScrollOffset current_offset;
[email protected]adeda572014-01-31 00:49:471492 for (LayerImpl const* current_layer = this;
aeliasd0070ba2015-01-31 13:44:491493 current_layer != scrollbar_clip_layer->parent();
[email protected]adeda572014-01-31 00:49:471494 current_layer = current_layer->parent()) {
aeliasd0070ba2015-01-31 13:44:491495 current_offset += current_layer->CurrentScrollOffset();
[email protected]adeda572014-01-31 00:49:471496 if (current_layer == page_scale_layer) {
aelias58eec0812014-12-04 01:04:401497 float scale_factor = layer_tree_impl()->current_page_scale_factor();
[email protected]adeda572014-01-31 00:49:471498 current_offset.Scale(scale_factor);
1499 scroll_rect.Scale(scale_factor);
[email protected]adeda572014-01-31 00:49:471500 }
1501 }
[email protected]adeda572014-01-31 00:49:471502
sataya.m68d7d9b42014-09-22 16:01:591503 bool scrollbar_needs_animation = false;
1504 scrollbar_needs_animation |= scrollbar_layer->SetVerticalAdjust(
1505 scrollbar_clip_layer->bounds_delta().y());
[email protected]adeda572014-01-31 00:49:471506 if (scrollbar_layer->orientation() == HORIZONTAL) {
1507 float visible_ratio = clip_rect.width() / scroll_rect.width();
sataya.m68d7d9b42014-09-22 16:01:591508 scrollbar_needs_animation |=
1509 scrollbar_layer->SetCurrentPos(current_offset.x());
1510 scrollbar_needs_animation |=
1511 scrollbar_layer->SetMaximum(scroll_rect.width() - clip_rect.width());
1512 scrollbar_needs_animation |=
1513 scrollbar_layer->SetVisibleToTotalLengthRatio(visible_ratio);
[email protected]adeda572014-01-31 00:49:471514 } else {
1515 float visible_ratio = clip_rect.height() / scroll_rect.height();
wjmaclean56f35ff2015-03-25 23:59:351516 bool y_offset_did_change =
sataya.m68d7d9b42014-09-22 16:01:591517 scrollbar_layer->SetCurrentPos(current_offset.y());
wjmaclean56f35ff2015-03-25 23:59:351518 scrollbar_needs_animation |= y_offset_did_change;
sataya.m68d7d9b42014-09-22 16:01:591519 scrollbar_needs_animation |=
1520 scrollbar_layer->SetMaximum(scroll_rect.height() - clip_rect.height());
1521 scrollbar_needs_animation |=
1522 scrollbar_layer->SetVisibleToTotalLengthRatio(visible_ratio);
wjmaclean56f35ff2015-03-25 23:59:351523 if (y_offset_did_change && layer_tree_impl()->IsActiveTree() &&
1524 this == layer_tree_impl()->InnerViewportScrollLayer()) {
1525 TRACE_COUNTER_ID1("cc", "scroll_offset_y", this->id(),
1526 current_offset.y());
1527 }
[email protected]adeda572014-01-31 00:49:471528 }
sataya.m7acc4b32014-09-23 15:37:211529 if (scrollbar_needs_animation) {
1530 layer_tree_impl()->set_needs_update_draw_properties();
1531 // TODO(wjmaclean) The scrollbar animator for the pinch-zoom scrollbars
1532 // should activate for every scroll on the main frame, not just the
1533 // scrolls that move the pinch virtual viewport (i.e. trigger from
1534 // either inner or outer viewport).
1535 if (scrollbar_animation_controller_) {
bokanc784a6f2015-01-28 04:11:501536 // Non-overlay scrollbars shouldn't trigger animations.
1537 if (scrollbar_layer->is_overlay_scrollbar())
sataya.m07f11a82014-10-07 14:29:181538 scrollbar_animation_controller_->DidScrollUpdate(on_resize);
sataya.m7acc4b32014-09-23 15:37:211539 }
[email protected]adeda572014-01-31 00:49:471540 }
[email protected]7aba6662013-03-12 10:17:341541}
1542
[email protected]7aba6662013-03-12 10:17:341543void LayerImpl::DidBecomeActive() {
[email protected]fea161872013-08-27 22:34:591544 if (layer_tree_impl_->settings().scrollbar_animator ==
ericrk7c030992015-02-20 01:39:381545 LayerTreeSettings::NO_ANIMATOR) {
[email protected]7aba6662013-03-12 10:17:341546 return;
[email protected]fea161872013-08-27 22:34:591547 }
[email protected]7aba6662013-03-12 10:17:341548
[email protected]adeda572014-01-31 00:49:471549 bool need_scrollbar_animation_controller = scrollable() && scrollbars_;
[email protected]fea161872013-08-27 22:34:591550 if (!need_scrollbar_animation_controller) {
danakjf446a072014-09-27 21:55:481551 scrollbar_animation_controller_ = nullptr;
[email protected]fea161872013-08-27 22:34:591552 return;
1553 }
1554
1555 if (scrollbar_animation_controller_)
1556 return;
1557
[email protected]930ff43b2014-05-02 05:24:001558 scrollbar_animation_controller_ =
1559 layer_tree_impl_->CreateScrollbarAnimationController(this);
[email protected]e45638c2013-01-17 22:01:401560}
[email protected]ad0250b2014-01-18 03:24:341561
[email protected]adeda572014-01-31 00:49:471562void LayerImpl::ClearScrollbars() {
1563 if (!scrollbars_)
1564 return;
1565
kulkarni.a4015690f12014-10-10 13:50:061566 scrollbars_.reset(nullptr);
[email protected]94f206c12012-08-25 00:09:141567}
1568
[email protected]adeda572014-01-31 00:49:471569void LayerImpl::AddScrollbar(ScrollbarLayerImplBase* layer) {
1570 DCHECK(layer);
1571 DCHECK(!scrollbars_ || scrollbars_->find(layer) == scrollbars_->end());
1572 if (!scrollbars_)
1573 scrollbars_.reset(new ScrollbarSet());
1574
1575 scrollbars_->insert(layer);
1576}
1577
1578void LayerImpl::RemoveScrollbar(ScrollbarLayerImplBase* layer) {
1579 DCHECK(scrollbars_);
1580 DCHECK(layer);
1581 DCHECK(scrollbars_->find(layer) != scrollbars_->end());
1582
1583 scrollbars_->erase(layer);
1584 if (scrollbars_->empty())
danakjf446a072014-09-27 21:55:481585 scrollbars_ = nullptr;
[email protected]adeda572014-01-31 00:49:471586}
1587
1588bool LayerImpl::HasScrollbar(ScrollbarOrientation orientation) const {
1589 if (!scrollbars_)
1590 return false;
1591
1592 for (ScrollbarSet::iterator it = scrollbars_->begin();
1593 it != scrollbars_->end();
1594 ++it)
1595 if ((*it)->orientation() == orientation)
1596 return true;
1597
1598 return false;
1599}
1600
sataya.m07f11a82014-10-07 14:29:181601void LayerImpl::ScrollbarParametersDidChange(bool on_resize) {
[email protected]adeda572014-01-31 00:49:471602 if (!scrollbars_)
1603 return;
1604
1605 for (ScrollbarSet::iterator it = scrollbars_->begin();
1606 it != scrollbars_->end();
aelias1505e722014-10-07 22:19:461607 ++it) {
1608 bool is_scroll_layer = (*it)->ScrollLayerId() == layer_id_;
1609 bool scroll_layer_resized = is_scroll_layer && on_resize;
1610 (*it)->ScrollbarParametersDidChange(scroll_layer_resized);
1611 }
[email protected]94f206c12012-08-25 00:09:141612}
1613
[email protected]ad0250b2014-01-18 03:24:341614void LayerImpl::SetNeedsPushProperties() {
1615 if (needs_push_properties_)
1616 return;
1617 if (!parent_should_know_need_push_properties() && parent_)
1618 parent_->AddDependentNeedsPushProperties();
1619 needs_push_properties_ = true;
1620}
1621
1622void LayerImpl::AddDependentNeedsPushProperties() {
1623 DCHECK_GE(num_dependents_need_push_properties_, 0);
1624
1625 if (!parent_should_know_need_push_properties() && parent_)
1626 parent_->AddDependentNeedsPushProperties();
1627
1628 num_dependents_need_push_properties_++;
1629}
1630
1631void LayerImpl::RemoveDependentNeedsPushProperties() {
1632 num_dependents_need_push_properties_--;
1633 DCHECK_GE(num_dependents_need_push_properties_, 0);
1634
1635 if (!parent_should_know_need_push_properties() && parent_)
1636 parent_->RemoveDependentNeedsPushProperties();
1637}
1638
hendrikwc5e915852015-05-13 01:29:031639void LayerImpl::GetAllPrioritizedTilesForTracing(
1640 std::vector<PrioritizedTile>* prioritized_tiles) const {
vmpstrd7de03c2014-08-27 18:11:011641}
1642
ssid911e40e2015-02-09 17:55:201643void LayerImpl::AsValueInto(base::trace_event::TracedValue* state) const {
[email protected]f5ad4282014-02-15 14:23:161644 TracedValue::MakeDictIntoImplicitSnapshotWithCategory(
1645 TRACE_DISABLED_BY_DEFAULT("cc.debug"),
[email protected]b4dc36472014-02-26 02:48:251646 state,
1647 "cc::LayerImpl",
1648 LayerTypeAsString(),
1649 this);
[email protected]f6742f52013-05-08 23:52:221650 state->SetInteger("layer_id", id());
jungjik.lee50f9c8e2015-01-21 14:06:161651 MathUtil::AddToTracedValue("bounds", bounds_, state);
[email protected]d12aa932014-08-01 13:10:381652
danakj38955562014-09-13 02:56:431653 state->SetDouble("opacity", opacity());
1654
jungjik.lee50f9c8e2015-01-21 14:06:161655 MathUtil::AddToTracedValue("position", position_, state);
[email protected]d12aa932014-08-01 13:10:381656
[email protected]f6742f52013-05-08 23:52:221657 state->SetInteger("draws_content", DrawsContent());
vmpstr91e23092015-06-08 22:24:161658 state->SetInteger("gpu_memory_usage",
1659 base::saturated_cast<int>(GPUMemoryUsageInBytes()));
[email protected]d12aa932014-08-01 13:10:381660
aeliasd0070ba2015-01-31 13:44:491661 MathUtil::AddToTracedValue(
1662 "scroll_offset", scroll_offset_ ? scroll_offset_->Current(IsActive())
1663 : gfx::ScrollOffset(),
1664 state);
1665
jungjik.lee50f9c8e2015-01-21 14:06:161666 MathUtil::AddToTracedValue("transform_origin", transform_origin_, state);
[email protected]8c5690222013-02-15 17:36:431667
[email protected]7aba6662013-03-12 10:17:341668 bool clipped;
[email protected]fa816c62013-03-18 04:24:211669 gfx::QuadF layer_quad = MathUtil::MapQuad(
Dana Jansensc46d3742015-06-18 01:33:141670 screen_space_transform(), gfx::QuadF(gfx::Rect(bounds())), &clipped);
jungjik.lee50f9c8e2015-01-21 14:06:161671 MathUtil::AddToTracedValue("layer_quad", layer_quad, state);
[email protected]78d78612013-09-12 18:04:041672 if (!touch_event_handler_region_.IsEmpty()) {
[email protected]d12aa932014-08-01 13:10:381673 state->BeginArray("touch_event_handler_region");
1674 touch_event_handler_region_.AsValueInto(state);
1675 state->EndArray();
[email protected]78d78612013-09-12 18:04:041676 }
1677 if (have_wheel_event_handlers_) {
Dana Jansensc46d3742015-06-18 01:33:141678 gfx::Rect wheel_rect(bounds());
[email protected]78d78612013-09-12 18:04:041679 Region wheel_region(wheel_rect);
[email protected]d12aa932014-08-01 13:10:381680 state->BeginArray("wheel_event_handler_region");
1681 wheel_region.AsValueInto(state);
1682 state->EndArray();
[email protected]78d78612013-09-12 18:04:041683 }
[email protected]f998c532014-03-31 20:02:511684 if (have_scroll_event_handlers_) {
Dana Jansensc46d3742015-06-18 01:33:141685 gfx::Rect scroll_rect(bounds());
[email protected]f998c532014-03-31 20:02:511686 Region scroll_region(scroll_rect);
[email protected]d12aa932014-08-01 13:10:381687 state->BeginArray("scroll_event_handler_region");
1688 scroll_region.AsValueInto(state);
1689 state->EndArray();
[email protected]f998c532014-03-31 20:02:511690 }
[email protected]78d78612013-09-12 18:04:041691 if (!non_fast_scrollable_region_.IsEmpty()) {
[email protected]d12aa932014-08-01 13:10:381692 state->BeginArray("non_fast_scrollable_region");
1693 non_fast_scrollable_region_.AsValueInto(state);
1694 state->EndArray();
[email protected]78d78612013-09-12 18:04:041695 }
rbyers18779d822015-02-05 06:22:061696 if (scroll_blocks_on_) {
1697 state->SetInteger("scroll_blocks_on", scroll_blocks_on_);
1698 }
[email protected]f6742f52013-05-08 23:52:221699
[email protected]d12aa932014-08-01 13:10:381700 state->BeginArray("children");
1701 for (size_t i = 0; i < children_.size(); ++i) {
1702 state->BeginDictionary();
1703 children_[i]->AsValueInto(state);
1704 state->EndDictionary();
1705 }
1706 state->EndArray();
1707 if (mask_layer_) {
1708 state->BeginDictionary("mask_layer");
1709 mask_layer_->AsValueInto(state);
1710 state->EndDictionary();
1711 }
1712 if (replica_layer_) {
1713 state->BeginDictionary("replica_layer");
1714 replica_layer_->AsValueInto(state);
1715 state->EndDictionary();
1716 }
[email protected]0e98cdd2013-08-23 00:44:301717
1718 if (scroll_parent_)
1719 state->SetInteger("scroll_parent", scroll_parent_->id());
1720
1721 if (clip_parent_)
1722 state->SetInteger("clip_parent", clip_parent_->id());
[email protected]c2a56ff2013-10-14 19:32:511723
1724 state->SetBoolean("can_use_lcd_text", can_use_lcd_text());
1725 state->SetBoolean("contents_opaque", contents_opaque());
[email protected]a1286742013-11-13 17:11:401726
[email protected]3d86dd7a2014-01-24 01:33:111727 state->SetBoolean(
1728 "has_animation_bounds",
loysod71ece82015-07-03 13:48:501729 layer_animation_controller_
1730 ? layer_animation_controller_->HasAnimationThatInflatesBounds()
1731 : layer_tree_impl_->HasAnimationThatInflatesBounds(this));
[email protected]3d86dd7a2014-01-24 01:33:111732
1733 gfx::BoxF box;
jungjik.lee50f9c8e2015-01-21 14:06:161734 if (LayerUtils::GetAnimationBounds(*this, &box))
1735 MathUtil::AddToTracedValue("animation_bounds", box, state);
[email protected]9f3be432013-12-03 03:53:221736
1737 if (debug_info_.get()) {
1738 std::string str;
1739 debug_info_->AppendAsTraceFormat(&str);
1740 base::JSONReader json_reader;
[email protected]685de6b12014-01-09 12:25:051741 scoped_ptr<base::Value> debug_info_value(json_reader.ReadToValue(str));
1742
[email protected]478224312014-01-10 17:33:471743 if (debug_info_value->IsType(base::Value::TYPE_DICTIONARY)) {
kulkarni.a4015690f12014-10-10 13:50:061744 base::DictionaryValue* dictionary_value = nullptr;
[email protected]685de6b12014-01-09 12:25:051745 bool converted_to_dictionary =
1746 debug_info_value->GetAsDictionary(&dictionary_value);
1747 DCHECK(converted_to_dictionary);
[email protected]d12aa932014-08-01 13:10:381748 for (base::DictionaryValue::Iterator it(*dictionary_value); !it.IsAtEnd();
1749 it.Advance()) {
estade7bc801fb2015-05-07 01:53:081750 state->SetValue(it.key().data(), it.value().CreateDeepCopy());
[email protected]d12aa932014-08-01 13:10:381751 }
[email protected]685de6b12014-01-09 12:25:051752 } else {
1753 NOTREACHED();
1754 }
[email protected]9f3be432013-12-03 03:53:221755 }
vmpstr3d1d72c2015-01-26 18:27:401756
1757 if (!frame_timing_requests_.empty()) {
1758 state->BeginArray("frame_timing_requests");
1759 for (const auto& request : frame_timing_requests_) {
1760 state->BeginDictionary();
1761 state->SetInteger("request_id", request.id());
1762 MathUtil::AddToTracedValue("request_rect", request.rect(), state);
1763 state->EndDictionary();
1764 }
1765 state->EndArray();
1766 }
[email protected]8c5690222013-02-15 17:36:431767}
1768
[email protected]390bb1ff2014-05-09 17:14:401769bool LayerImpl::IsDrawnRenderSurfaceLayerListMember() const {
1770 return draw_properties_.last_drawn_render_surface_layer_list_id ==
1771 layer_tree_impl_->current_render_surface_list_id();
1772}
1773
[email protected]cdf5b952013-05-15 15:39:291774size_t LayerImpl::GPUMemoryUsageInBytes() const { return 0; }
1775
[email protected]5e5648a2013-11-18 00:39:331776void LayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) {
1777 benchmark->RunOnLayer(this);
1778}
[email protected]749cbc62014-07-10 01:06:351779
[email protected]ad63b2f2014-08-11 17:39:541780int LayerImpl::NumDescendantsThatDrawContent() const {
1781 return num_descendants_that_draw_content_;
1782}
1783
[email protected]749cbc62014-07-10 01:06:351784void LayerImpl::NotifyAnimationFinished(
1785 base::TimeTicks monotonic_time,
dstockwellaf2a117b2014-10-16 21:42:291786 Animation::TargetProperty target_property,
1787 int group) {
ericrk7c030992015-02-20 01:39:381788 if (target_property == Animation::SCROLL_OFFSET)
[email protected]749cbc62014-07-10 01:06:351789 layer_tree_impl_->InputScrollAnimationFinished();
1790}
1791
awoloszyne83f28c2014-12-22 15:40:001792void LayerImpl::SetHasRenderSurface(bool should_have_render_surface) {
1793 if (!!render_surface() == should_have_render_surface)
1794 return;
1795
1796 SetNeedsPushProperties();
1797 layer_tree_impl()->set_needs_update_draw_properties();
1798 if (should_have_render_surface) {
1799 render_surface_ = make_scoped_ptr(new RenderSurfaceImpl(this));
1800 return;
1801 }
1802 render_surface_.reset();
1803}
1804
daplatz350219e2015-03-04 19:04:411805Region LayerImpl::GetInvalidationRegion() {
1806 return Region(update_rect_);
1807}
1808
vmpstrd46a7ac2015-03-18 01:11:121809gfx::Rect LayerImpl::GetEnclosingRectInTargetSpace() const {
1810 return MathUtil::MapEnclosingClippedRect(
Dana Jansensc46d3742015-06-18 01:33:141811 draw_properties_.target_space_transform, gfx::Rect(bounds()));
vmpstrd46a7ac2015-03-18 01:11:121812}
1813
1814gfx::Rect LayerImpl::GetScaledEnclosingRectInTargetSpace(float scale) const {
1815 gfx::Transform scaled_draw_transform =
1816 draw_properties_.target_space_transform;
1817 scaled_draw_transform.Scale(SK_MScalar1 / scale, SK_MScalar1 / scale);
Dana Jansensc46d3742015-06-18 01:33:141818 gfx::Size scaled_bounds = gfx::ToCeiledSize(gfx::ScaleSize(bounds(), scale));
vmpstrd46a7ac2015-03-18 01:11:121819 return MathUtil::MapEnclosingClippedRect(scaled_draw_transform,
Dana Jansensc46d3742015-06-18 01:33:141820 gfx::Rect(scaled_bounds));
vmpstrd46a7ac2015-03-18 01:11:121821}
1822
enne637715732015-07-07 02:05:261823float LayerImpl::GetIdealContentsScale() const {
1824 float page_scale = IsAffectedByPageScale()
1825 ? layer_tree_impl()->current_page_scale_factor()
1826 : 1.f;
1827 float device_scale = layer_tree_impl()->device_scale_factor();
1828
1829 float default_scale = page_scale * device_scale;
1830 if (!layer_tree_impl()
1831 ->settings()
1832 .layer_transforms_should_scale_layer_contents) {
1833 return default_scale;
1834 }
1835
1836 // TODO(enne): the transform needs to come from property trees instead of
1837 // draw properties.
1838 gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents(
1839 draw_properties().target_space_transform, default_scale);
1840 return std::max(transform_scales.x(), transform_scales.y());
1841}
1842
[email protected]bc5e77c2012-11-05 20:00:491843} // namespace cc