blob: 57b62f880ed30c978e7f608cab61187810e7be72 [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
avi02a4d172015-12-21 06:14:367#include <stddef.h>
8#include <stdint.h>
9
dchengf9c838e2015-12-18 08:10:1210#include <utility>
11
[email protected]9f3be432013-12-03 03:53:2212#include "base/json/json_reader.h"
vmpstr91e23092015-06-08 22:24:1613#include "base/numerics/safe_conversions.h"
[email protected]8e61d4b2013-06-10 22:11:4814#include "base/strings/stringprintf.h"
primianoc06e2382015-01-28 04:21:4915#include "base/trace_event/trace_event.h"
16#include "base/trace_event/trace_event_argument.h"
[email protected]95e4e1a02013-03-18 07:09:0917#include "cc/animation/animation_registrar.h"
vollick933f496e2015-12-08 04:22:0518#include "cc/animation/mutable_properties.h"
[email protected]681ccff2013-03-18 06:13:5219#include "cc/base/math_util.h"
[email protected]d5467eb72014-08-22 01:16:4320#include "cc/base/simple_enclosed_region.h"
[email protected]6e84de22013-03-18 06:54:2721#include "cc/debug/debug_colors.h"
22#include "cc/debug/layer_tree_debug_state.h"
[email protected]5e5648a2013-11-18 00:39:3323#include "cc/debug/micro_benchmark_impl.h"
[email protected]f6742f52013-05-08 23:52:2224#include "cc/debug/traced_value.h"
danakj35904762016-01-21 20:49:4025#include "cc/input/main_thread_scrolling_reason.h"
tdresserd9e201472015-07-31 13:15:0726#include "cc/input/scroll_state.h"
aeliasa57c40d122015-10-08 00:20:0927#include "cc/layers/layer.h"
[email protected]3d86dd7a2014-01-24 01:33:1128#include "cc/layers/layer_utils.h"
[email protected]0e5f7142013-05-24 06:45:3629#include "cc/output/copy_output_request.h"
[email protected]89e8267a2013-03-18 07:50:5630#include "cc/quads/debug_border_draw_quad.h"
[email protected]0cd7d6f72014-08-22 14:50:5131#include "cc/quads/render_pass.h"
ajumad9432e32015-11-30 19:43:4432#include "cc/trees/draw_property_utils.h"
[email protected]3d86dd7a2014-01-24 01:33:1133#include "cc/trees/layer_tree_host_common.h"
[email protected]556fd292013-03-18 08:03:0434#include "cc/trees/layer_tree_impl.h"
35#include "cc/trees/layer_tree_settings.h"
36#include "cc/trees/proxy.h"
heejin.r.chungd28506ba2014-10-23 16:36:2037#include "ui/gfx/geometry/box_f.h"
38#include "ui/gfx/geometry/point_conversions.h"
39#include "ui/gfx/geometry/quad_f.h"
40#include "ui/gfx/geometry/rect_conversions.h"
41#include "ui/gfx/geometry/size_conversions.h"
[email protected]adeda572014-01-31 00:49:4742#include "ui/gfx/geometry/vector2d_conversions.h"
[email protected]94f206c12012-08-25 00:09:1443
[email protected]9c88e562012-09-14 22:21:3044namespace cc {
aeliasd0070ba2015-01-31 13:44:4945LayerImpl::LayerImpl(LayerTreeImpl* layer_impl, int id)
46 : LayerImpl(layer_impl, id, new LayerImpl::SyncedScrollOffset) {
47}
48
49LayerImpl::LayerImpl(LayerTreeImpl* tree_impl,
50 int id,
51 scoped_refptr<SyncedScrollOffset> scroll_offset)
kulkarni.a4015690f12014-10-10 13:50:0652 : parent_(nullptr),
53 scroll_parent_(nullptr),
54 clip_parent_(nullptr),
[email protected]7aba6662013-03-12 10:17:3455 mask_layer_id_(-1),
56 replica_layer_id_(-1),
57 layer_id_(id),
58 layer_tree_impl_(tree_impl),
aeliasd0070ba2015-01-31 13:44:4959 scroll_offset_(scroll_offset),
aeliasa57c40d122015-10-08 00:20:0960 scroll_clip_layer_id_(Layer::INVALID_ID),
danakj35904762016-01-21 20:49:4061 main_thread_scrolling_reasons_(
62 MainThreadScrollingReason::kNotScrollingOnMain),
[email protected]7aba6662013-03-12 10:17:3463 have_wheel_event_handlers_(false),
[email protected]f998c532014-03-31 20:02:5164 have_scroll_event_handlers_(false),
ericrk7c030992015-02-20 01:39:3865 scroll_blocks_on_(SCROLL_BLOCKS_ON_NONE),
[email protected]59a7d552013-10-22 03:36:4366 user_scrollable_horizontal_(true),
67 user_scrollable_vertical_(true),
[email protected]7aba6662013-03-12 10:17:3468 stacking_order_changed_(false),
69 double_sided_(true),
[email protected]56fffdd2014-02-11 19:50:5770 should_flatten_transform_(true),
ennee95b1542015-04-20 20:35:5071 should_flatten_transform_from_property_tree_(false),
[email protected]7aba6662013-03-12 10:17:3472 layer_property_changed_(false),
[email protected]7aba6662013-03-12 10:17:3473 masks_to_bounds_(false),
74 contents_opaque_(false),
[email protected]7bbeaf4e2013-11-26 10:27:2275 is_root_for_isolated_group_(false),
[email protected]7aba6662013-03-12 10:17:3476 use_parent_backface_visibility_(false),
[email protected]7aba6662013-03-12 10:17:3477 draws_content_(false),
[email protected]c0ae06c12013-06-24 18:32:1978 hide_layer_and_subtree_(false),
[email protected]08bdf1b2014-04-16 23:23:2979 transform_is_invertible_(true),
[email protected]7aba6662013-03-12 10:17:3480 is_container_for_fixed_position_layers_(false),
enne9c48d4f12015-06-30 00:31:1581 is_affected_by_page_scale_(true),
vmpstre1564a52015-11-24 19:43:1582 was_ever_ready_since_last_transform_animation_(true),
[email protected]c55f3fc2013-12-10 05:48:4883 background_color_(0),
84 opacity_(1.0),
85 blend_mode_(SkXfermode::kSrcOver_Mode),
jaydasika92239dc2015-08-15 02:59:2686 draw_blend_mode_(SkXfermode::kSrcOver_Mode),
[email protected]ad63b2f2014-08-11 17:39:5487 num_descendants_that_draw_content_(0),
ennee95b1542015-04-20 20:35:5088 transform_tree_index_(-1),
weiliangc6a52f302015-08-18 16:29:3589 effect_tree_index_(-1),
ennee95b1542015-04-20 20:35:5090 clip_tree_index_(-1),
[email protected]7aba6662013-03-12 10:17:3491 draw_depth_(0.f),
[email protected]ad0250b2014-01-18 03:24:3492 needs_push_properties_(false),
93 num_dependents_need_push_properties_(0),
[email protected]a9d4d4f2014-06-19 06:49:2894 sorting_context_id_(0),
vmpstr3d1d72c2015-01-26 18:27:4095 current_draw_mode_(DRAW_MODE_NONE),
vollick933f496e2015-12-08 04:22:0596 element_id_(0),
vollickfd6e4f4a2016-01-22 19:13:2997 mutable_properties_(MutableProperty::kNone),
weiliangcc154ce22015-12-09 03:39:2698 force_render_surface_(false),
jaydasika976cd10b2015-05-26 15:45:2499 frame_timing_requests_dirty_(false),
100 visited_(false),
101 layer_or_descendant_is_drawn_(false),
jaydasika60f85862015-10-01 20:36:14102 layer_or_descendant_has_input_handler_(false),
jaydasikab5504ca2015-12-18 23:41:55103 sorted_for_recursion_(false),
104 is_hidden_from_property_trees_(false) {
[email protected]bf691c22013-03-26 21:15:06105 DCHECK_GT(layer_id_, 0);
[email protected]7aba6662013-03-12 10:17:34106 DCHECK(layer_tree_impl_);
107 layer_tree_impl_->RegisterLayer(this);
loysod71ece82015-07-03 13:48:50108
109 if (!layer_tree_impl_->settings().use_compositor_animation_timelines) {
110 AnimationRegistrar* registrar = layer_tree_impl_->GetAnimationRegistrar();
111 layer_animation_controller_ =
112 registrar->GetAnimationControllerForId(layer_id_);
113 layer_animation_controller_->AddValueObserver(this);
114 if (IsActive()) {
115 layer_animation_controller_->set_value_provider(this);
116 layer_animation_controller_->set_layer_animation_delegate(this);
117 }
[email protected]749cbc62014-07-10 01:06:35118 }
vollick9c7f6d02016-01-08 04:36:38119
120 layer_tree_impl_->AddToElementMap(this);
121
[email protected]ad0250b2014-01-18 03:24:34122 SetNeedsPushProperties();
[email protected]94f206c12012-08-25 00:09:14123}
124
[email protected]7aba6662013-03-12 10:17:34125LayerImpl::~LayerImpl() {
[email protected]ffbb2212013-06-02 23:47:59126 DCHECK_EQ(DRAW_MODE_NONE, current_draw_mode_);
[email protected]18a70192013-04-26 16:18:25127
loysod71ece82015-07-03 13:48:50128 if (layer_animation_controller_) {
129 layer_animation_controller_->RemoveValueObserver(this);
130 layer_animation_controller_->remove_value_provider(this);
131 layer_animation_controller_->remove_layer_animation_delegate(this);
132 }
[email protected]b8384e22013-12-03 02:20:48133
[email protected]19334ac2013-12-12 23:59:11134 if (!copy_requests_.empty() && layer_tree_impl_->IsActiveTree())
135 layer_tree_impl()->RemoveLayerWithCopyOutputRequest(this);
aeliasa57c40d122015-10-08 00:20:09136 layer_tree_impl_->UnregisterScrollLayer(this);
[email protected]b8384e22013-12-03 02:20:48137 layer_tree_impl_->UnregisterLayer(this);
[email protected]0e98cdd2013-08-23 00:44:30138
vollick9c7f6d02016-01-08 04:36:38139 layer_tree_impl_->RemoveFromElementMap(this);
140
[email protected]f5ad4282014-02-15 14:23:16141 TRACE_EVENT_OBJECT_DELETED_WITH_ID(
[email protected]b4dc36472014-02-26 02:48:25142 TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerImpl", this);
[email protected]94f206c12012-08-25 00:09:14143}
144
[email protected]7aba6662013-03-12 10:17:34145void LayerImpl::AddChild(scoped_ptr<LayerImpl> child) {
[email protected]ad0250b2014-01-18 03:24:34146 child->SetParent(this);
[email protected]7aba6662013-03-12 10:17:34147 DCHECK_EQ(layer_tree_impl(), child->layer_tree_impl());
danakja04855a2015-11-18 20:39:10148 children_.push_back(std::move(child));
[email protected]7aba6662013-03-12 10:17:34149 layer_tree_impl()->set_needs_update_draw_properties();
[email protected]94f206c12012-08-25 00:09:14150}
151
[email protected]7aba6662013-03-12 10:17:34152scoped_ptr<LayerImpl> LayerImpl::RemoveChild(LayerImpl* child) {
[email protected]50761e92013-03-29 20:51:28153 for (OwnedLayerImplList::iterator it = children_.begin();
[email protected]7aba6662013-03-12 10:17:34154 it != children_.end();
155 ++it) {
vmpstra370ef52015-11-18 10:41:28156 if (it->get() == child) {
dchengf9c838e2015-12-18 08:10:12157 scoped_ptr<LayerImpl> ret = std::move(*it);
[email protected]7aba6662013-03-12 10:17:34158 children_.erase(it);
159 layer_tree_impl()->set_needs_update_draw_properties();
vmpstra370ef52015-11-18 10:41:28160 return ret;
[email protected]94f206c12012-08-25 00:09:14161 }
[email protected]7aba6662013-03-12 10:17:34162 }
danakjf446a072014-09-27 21:55:48163 return nullptr;
[email protected]94f206c12012-08-25 00:09:14164}
165
[email protected]ad0250b2014-01-18 03:24:34166void LayerImpl::SetParent(LayerImpl* parent) {
167 if (parent_should_know_need_push_properties()) {
168 if (parent_)
169 parent_->RemoveDependentNeedsPushProperties();
170 if (parent)
171 parent->AddDependentNeedsPushProperties();
172 }
173 parent_ = parent;
174}
175
[email protected]7aba6662013-03-12 10:17:34176void LayerImpl::ClearChildList() {
177 if (children_.empty())
178 return;
[email protected]0ede3bb2012-12-09 09:14:39179
[email protected]7aba6662013-03-12 10:17:34180 children_.clear();
181 layer_tree_impl()->set_needs_update_draw_properties();
[email protected]94f206c12012-08-25 00:09:14182}
183
[email protected]0e98cdd2013-08-23 00:44:30184bool LayerImpl::HasAncestor(const LayerImpl* ancestor) const {
185 if (!ancestor)
186 return false;
187
188 for (const LayerImpl* layer = this; layer; layer = layer->parent()) {
189 if (layer == ancestor)
190 return true;
191 }
192
193 return false;
194}
195
196void LayerImpl::SetScrollParent(LayerImpl* parent) {
197 if (scroll_parent_ == parent)
198 return;
199
[email protected]d097e242014-02-28 21:51:11200 if (parent)
201 DCHECK_EQ(layer_tree_impl()->LayerById(parent->id()), parent);
[email protected]0e98cdd2013-08-23 00:44:30202
203 scroll_parent_ = parent;
[email protected]ad0250b2014-01-18 03:24:34204 SetNeedsPushProperties();
[email protected]0e98cdd2013-08-23 00:44:30205}
206
[email protected]9f3be432013-12-03 03:53:22207void LayerImpl::SetDebugInfo(
ssid911e40e2015-02-09 17:55:20208 scoped_refptr<base::trace_event::ConvertableToTraceFormat> other) {
[email protected]9f3be432013-12-03 03:53:22209 debug_info_ = other;
[email protected]ad0250b2014-01-18 03:24:34210 SetNeedsPushProperties();
[email protected]9f3be432013-12-03 03:53:22211}
212
[email protected]0e98cdd2013-08-23 00:44:30213void LayerImpl::SetScrollChildren(std::set<LayerImpl*>* children) {
214 if (scroll_children_.get() == children)
215 return;
216 scroll_children_.reset(children);
[email protected]ad0250b2014-01-18 03:24:34217 SetNeedsPushProperties();
[email protected]0e98cdd2013-08-23 00:44:30218}
219
tdresserd9e201472015-07-31 13:15:07220void LayerImpl::DistributeScroll(ScrollState* scroll_state) {
221 DCHECK(scroll_state);
222 if (scroll_state->FullyConsumed())
223 return;
224
225 scroll_state->DistributeToScrollChainDescendant();
226
227 // If the scroll doesn't propagate, and we're currently scrolling
228 // a layer other than this one, prevent the scroll from
229 // propagating to this layer.
230 if (!scroll_state->should_propagate() &&
231 scroll_state->delta_consumed_for_scroll_sequence() &&
232 scroll_state->current_native_scrolling_layer() != this) {
233 return;
234 }
235
236 ApplyScroll(scroll_state);
237}
238
239void LayerImpl::ApplyScroll(ScrollState* scroll_state) {
240 DCHECK(scroll_state);
241 layer_tree_impl()->ApplyScroll(this, scroll_state);
242}
243
[email protected]ad63b2f2014-08-11 17:39:54244void LayerImpl::SetNumDescendantsThatDrawContent(int num_descendants) {
245 if (num_descendants_that_draw_content_ == num_descendants)
246 return;
247 num_descendants_that_draw_content_ = num_descendants;
248 SetNeedsPushProperties();
249}
250
[email protected]0e98cdd2013-08-23 00:44:30251void LayerImpl::SetClipParent(LayerImpl* ancestor) {
252 if (clip_parent_ == ancestor)
253 return;
254
[email protected]0e98cdd2013-08-23 00:44:30255 clip_parent_ = ancestor;
[email protected]ad0250b2014-01-18 03:24:34256 SetNeedsPushProperties();
[email protected]0e98cdd2013-08-23 00:44:30257}
258
259void LayerImpl::SetClipChildren(std::set<LayerImpl*>* children) {
260 if (clip_children_.get() == children)
261 return;
262 clip_children_.reset(children);
[email protected]ad0250b2014-01-18 03:24:34263 SetNeedsPushProperties();
[email protected]0e98cdd2013-08-23 00:44:30264}
265
vollick692444f2015-05-20 15:39:14266void LayerImpl::SetTransformTreeIndex(int index) {
267 transform_tree_index_ = index;
268 SetNeedsPushProperties();
269}
270
271void LayerImpl::SetClipTreeIndex(int index) {
272 clip_tree_index_ = index;
273 SetNeedsPushProperties();
274}
275
weiliangc6a52f302015-08-18 16:29:35276void LayerImpl::SetEffectTreeIndex(int index) {
277 effect_tree_index_ = index;
vollick692444f2015-05-20 15:39:14278 SetNeedsPushProperties();
279}
280
vmpstra370ef52015-11-18 10:41:28281void LayerImpl::PassCopyRequests(
282 std::vector<scoped_ptr<CopyOutputRequest>>* requests) {
ennef44fcf92015-06-12 23:56:32283 // In the case that a layer still has a copy request, this means that there's
284 // a commit to the active tree without a draw. This only happens in some
285 // edge cases during lost context or visibility changes, so don't try to
286 // handle preserving these output requests (and their surface).
287 if (!copy_requests_.empty()) {
288 layer_tree_impl()->RemoveLayerWithCopyOutputRequest(this);
289 // Destroying these will abort them.
290 copy_requests_.clear();
291 }
292
[email protected]0e5f7142013-05-24 06:45:36293 if (requests->empty())
[email protected]18a70192013-04-26 16:18:25294 return;
ennef44fcf92015-06-12 23:56:32295
[email protected]f5de9e5b2013-07-30 22:26:57296 bool was_empty = copy_requests_.empty();
vmpstra370ef52015-11-18 10:41:28297 for (auto& request : *requests)
298 copy_requests_.push_back(std::move(request));
[email protected]0e5f7142013-05-24 06:45:36299 requests->clear();
[email protected]18a70192013-04-26 16:18:25300
[email protected]f5de9e5b2013-07-30 22:26:57301 if (was_empty && layer_tree_impl()->IsActiveTree())
[email protected]30fe19ff2013-07-04 00:54:45302 layer_tree_impl()->AddLayerWithCopyOutputRequest(this);
[email protected]18a70192013-04-26 16:18:25303 NoteLayerPropertyChangedForSubtree();
304}
305
[email protected]d4d017e2013-06-20 21:46:11306void LayerImpl::TakeCopyRequestsAndTransformToTarget(
vmpstra370ef52015-11-18 10:41:28307 std::vector<scoped_ptr<CopyOutputRequest>>* requests) {
[email protected]df17af52014-02-06 02:20:40308 DCHECK(!copy_requests_.empty());
309 DCHECK(layer_tree_impl()->IsActiveTree());
awoloszyne83f28c2014-12-22 15:40:00310 DCHECK_EQ(render_target(), this);
[email protected]18a70192013-04-26 16:18:25311
[email protected]30fe19ff2013-07-04 00:54:45312 size_t first_inserted_request = requests->size();
vmpstra370ef52015-11-18 10:41:28313 for (auto& request : copy_requests_)
314 requests->push_back(std::move(request));
[email protected]0e5f7142013-05-24 06:45:36315 copy_requests_.clear();
[email protected]d4d017e2013-06-20 21:46:11316
[email protected]30fe19ff2013-07-04 00:54:45317 for (size_t i = first_inserted_request; i < requests->size(); ++i) {
vmpstra370ef52015-11-18 10:41:28318 CopyOutputRequest* request = (*requests)[i].get();
[email protected]d4d017e2013-06-20 21:46:11319 if (!request->has_area())
320 continue;
321
322 gfx::Rect request_in_layer_space = request->area();
danakje0f14a882015-06-18 05:05:07323 request_in_layer_space.Intersect(gfx::Rect(bounds()));
[email protected]8a822692014-02-12 17:30:55324 request->set_area(MathUtil::MapEnclosingClippedRect(
ajumad9432e32015-11-30 19:43:44325 DrawTransform(), request_in_layer_space));
[email protected]d4d017e2013-06-20 21:46:11326 }
[email protected]30fe19ff2013-07-04 00:54:45327
[email protected]df17af52014-02-06 02:20:40328 layer_tree_impl()->RemoveLayerWithCopyOutputRequest(this);
danakj0cf95392015-01-29 17:56:54329 layer_tree_impl()->set_needs_update_draw_properties();
[email protected]18a70192013-04-26 16:18:25330}
331
[email protected]7644fa22014-04-28 12:20:33332void LayerImpl::ClearRenderSurfaceLayerList() {
awoloszyne83f28c2014-12-22 15:40:00333 if (render_surface_)
334 render_surface_->ClearLayerLists();
[email protected]7644fa22014-04-28 12:20:33335}
336
[email protected]9be1adc82014-05-07 15:39:41337void LayerImpl::PopulateSharedQuadState(SharedQuadState* state) const {
Dana Jansensc46d3742015-06-18 01:33:14338 state->SetAll(draw_properties_.target_space_transform, bounds(),
danakj64767d902015-06-19 00:10:43339 draw_properties_.visible_layer_rect, draw_properties_.clip_rect,
ajumae2b7a5c2015-09-30 21:41:42340 draw_properties_.is_clipped, draw_properties_.opacity,
341 draw_blend_mode_, sorting_context_id_);
[email protected]94f206c12012-08-25 00:09:14342}
343
enne467829b2015-02-13 02:39:34344void LayerImpl::PopulateScaledSharedQuadState(SharedQuadState* state,
345 float scale) const {
346 gfx::Transform scaled_draw_transform =
347 draw_properties_.target_space_transform;
348 scaled_draw_transform.Scale(SK_MScalar1 / scale, SK_MScalar1 / scale);
danakjddaec912015-09-25 19:38:40349 gfx::Size scaled_bounds = gfx::ScaleToCeiledSize(bounds(), scale);
danakj64767d902015-06-19 00:10:43350 gfx::Rect scaled_visible_layer_rect =
351 gfx::ScaleToEnclosingRect(visible_layer_rect(), scale);
352 scaled_visible_layer_rect.Intersect(gfx::Rect(scaled_bounds));
enne467829b2015-02-13 02:39:34353
danakj64767d902015-06-19 00:10:43354 state->SetAll(scaled_draw_transform, scaled_bounds, scaled_visible_layer_rect,
ajumae2b7a5c2015-09-30 21:41:42355 draw_properties().clip_rect, draw_properties().is_clipped,
jaydasika92239dc2015-08-15 02:59:26356 draw_properties().opacity, draw_blend_mode_,
danakj64767d902015-06-19 00:10:43357 sorting_context_id_);
enne467829b2015-02-13 02:39:34358}
359
[email protected]ffbb2212013-06-02 23:47:59360bool LayerImpl::WillDraw(DrawMode draw_mode,
361 ResourceProvider* resource_provider) {
[email protected]ed511b8d2013-03-25 03:29:29362 // WillDraw/DidDraw must be matched.
[email protected]ffbb2212013-06-02 23:47:59363 DCHECK_NE(DRAW_MODE_NONE, draw_mode);
364 DCHECK_EQ(DRAW_MODE_NONE, current_draw_mode_);
365 current_draw_mode_ = draw_mode;
366 return true;
[email protected]94f206c12012-08-25 00:09:14367}
368
[email protected]7aba6662013-03-12 10:17:34369void LayerImpl::DidDraw(ResourceProvider* resource_provider) {
[email protected]ffbb2212013-06-02 23:47:59370 DCHECK_NE(DRAW_MODE_NONE, current_draw_mode_);
371 current_draw_mode_ = DRAW_MODE_NONE;
[email protected]94f206c12012-08-25 00:09:14372}
373
[email protected]7aba6662013-03-12 10:17:34374bool LayerImpl::ShowDebugBorders() const {
[email protected]846f455b2013-03-18 19:07:41375 return layer_tree_impl()->debug_state().show_debug_borders;
[email protected]3dce37232012-11-15 01:47:44376}
377
[email protected]7aba6662013-03-12 10:17:34378void LayerImpl::GetDebugBorderProperties(SkColor* color, float* width) const {
379 if (draws_content_) {
380 *color = DebugColors::ContentLayerBorderColor();
381 *width = DebugColors::ContentLayerBorderWidth(layer_tree_impl());
382 return;
383 }
384
385 if (masks_to_bounds_) {
386 *color = DebugColors::MaskingLayerBorderColor();
387 *width = DebugColors::MaskingLayerBorderWidth(layer_tree_impl());
388 return;
389 }
390
391 *color = DebugColors::ContainerLayerBorderColor();
392 *width = DebugColors::ContainerLayerBorderWidth(layer_tree_impl());
393}
394
395void LayerImpl::AppendDebugBorderQuad(
[email protected]c6707fd2014-06-23 05:50:36396 RenderPass* render_pass,
Dana Jansensc46d3742015-06-18 01:33:14397 const gfx::Size& bounds,
[email protected]7aba6662013-03-12 10:17:34398 const SharedQuadState* shared_quad_state,
399 AppendQuadsData* append_quads_data) const {
[email protected]7aba6662013-03-12 10:17:34400 SkColor color;
401 float width;
402 GetDebugBorderProperties(&color, &width);
Dana Jansensc46d3742015-06-18 01:33:14403 AppendDebugBorderQuad(render_pass, bounds, shared_quad_state,
404 append_quads_data, color, width);
[email protected]bec084292013-05-21 21:31:44405}
406
[email protected]c6707fd2014-06-23 05:50:36407void LayerImpl::AppendDebugBorderQuad(RenderPass* render_pass,
Dana Jansensc46d3742015-06-18 01:33:14408 const gfx::Size& bounds,
[email protected]bec084292013-05-21 21:31:44409 const SharedQuadState* shared_quad_state,
410 AppendQuadsData* append_quads_data,
411 SkColor color,
412 float width) const {
413 if (!ShowDebugBorders())
414 return;
[email protected]7aba6662013-03-12 10:17:34415
Dana Jansensc46d3742015-06-18 01:33:14416 gfx::Rect quad_rect(bounds);
[email protected]9bf06c72014-03-07 18:16:24417 gfx::Rect visible_quad_rect(quad_rect);
[email protected]f7030c32014-07-03 18:54:34418 DebugBorderDrawQuad* debug_border_quad =
419 render_pass->CreateAndAppendDrawQuad<DebugBorderDrawQuad>();
[email protected]9bf06c72014-03-07 18:16:24420 debug_border_quad->SetNew(
421 shared_quad_state, quad_rect, visible_quad_rect, color, width);
danakj069ac122015-02-12 00:59:22422 if (contents_opaque()) {
423 // When opaque, draw a second inner border that is thicker than the outer
424 // border, but more transparent.
425 static const float kFillOpacity = 0.3f;
426 SkColor fill_color = SkColorSetA(
427 color, static_cast<uint8_t>(SkColorGetA(color) * kFillOpacity));
428 float fill_width = width * 3;
429 gfx::Rect fill_rect = quad_rect;
430 fill_rect.Inset(fill_width / 2.f, fill_width / 2.f);
enneb79d5f142015-04-23 19:59:55431 if (fill_rect.IsEmpty())
432 return;
danakj069ac122015-02-12 00:59:22433 gfx::Rect visible_fill_rect =
434 gfx::IntersectRects(visible_quad_rect, fill_rect);
435 DebugBorderDrawQuad* fill_quad =
436 render_pass->CreateAndAppendDrawQuad<DebugBorderDrawQuad>();
437 fill_quad->SetNew(shared_quad_state, fill_rect, visible_fill_rect,
438 fill_color, fill_width);
439 }
[email protected]7aba6662013-03-12 10:17:34440}
441
442bool LayerImpl::HasDelegatedContent() const {
443 return false;
444}
445
446bool LayerImpl::HasContributingDelegatedRenderPasses() const {
447 return false;
448}
449
[email protected]0cd7d6f72014-08-22 14:50:51450RenderPassId LayerImpl::FirstContributingRenderPassId() const {
451 return RenderPassId(0, 0);
[email protected]7aba6662013-03-12 10:17:34452}
453
[email protected]0cd7d6f72014-08-22 14:50:51454RenderPassId LayerImpl::NextContributingRenderPassId(RenderPassId id) const {
455 return RenderPassId(0, 0);
[email protected]7aba6662013-03-12 10:17:34456}
457
jbaumanbbd425e2015-05-19 00:33:35458void LayerImpl::GetContentsResourceId(ResourceId* resource_id,
ennef6f3fbba42014-10-16 18:16:49459 gfx::Size* resource_size) const {
[email protected]7aba6662013-03-12 10:17:34460 NOTREACHED();
ennef6f3fbba42014-10-16 18:16:49461 *resource_id = 0;
[email protected]7aba6662013-03-12 10:17:34462}
463
[email protected]3244c9132014-01-23 10:39:12464gfx::Vector2dF LayerImpl::ScrollBy(const gfx::Vector2dF& scroll) {
aeliasd0070ba2015-01-31 13:44:49465 gfx::ScrollOffset adjusted_scroll(scroll);
bokan57ebc052015-05-29 13:14:21466 if (!user_scrollable_horizontal_)
467 adjusted_scroll.set_x(0);
468 if (!user_scrollable_vertical_)
469 adjusted_scroll.set_y(0);
[email protected]d30700f12013-07-31 08:21:01470 DCHECK(scrollable());
aeliasd0070ba2015-01-31 13:44:49471 gfx::ScrollOffset old_offset = CurrentScrollOffset();
472 gfx::ScrollOffset new_offset =
473 ClampScrollOffsetToLimits(old_offset + adjusted_scroll);
474 SetCurrentScrollOffset(new_offset);
[email protected]adeda572014-01-31 00:49:47475
aeliasd0070ba2015-01-31 13:44:49476 gfx::ScrollOffset unscrolled =
477 old_offset + gfx::ScrollOffset(scroll) - new_offset;
478 return gfx::Vector2dF(unscrolled.x(), unscrolled.y());
[email protected]7aba6662013-03-12 10:17:34479}
480
[email protected]adeda572014-01-31 00:49:47481void LayerImpl::SetScrollClipLayer(int scroll_clip_layer_id) {
aeliasa57c40d122015-10-08 00:20:09482 if (scroll_clip_layer_id_ == scroll_clip_layer_id)
483 return;
484
485 layer_tree_impl()->UnregisterScrollLayer(this);
486 scroll_clip_layer_id_ = scroll_clip_layer_id;
487 layer_tree_impl()->RegisterScrollLayer(this);
488}
489
490LayerImpl* LayerImpl::scroll_clip_layer() const {
491 return layer_tree_impl()->LayerById(scroll_clip_layer_id_);
492}
493
494bool LayerImpl::scrollable() const {
495 return scroll_clip_layer_id_ != Layer::INVALID_ID;
[email protected]adeda572014-01-31 00:49:47496}
497
timav3ca696932014-10-15 02:19:04498bool LayerImpl::user_scrollable(ScrollbarOrientation orientation) const {
499 return (orientation == HORIZONTAL) ? user_scrollable_horizontal_
500 : user_scrollable_vertical_;
501}
502
[email protected]58241dc2013-08-20 01:39:25503void LayerImpl::ApplySentScrollDeltasFromAbortedCommit() {
[email protected]3519b872013-07-30 07:17:50504 DCHECK(layer_tree_impl()->IsActiveTree());
aeliasd0070ba2015-01-31 13:44:49505 scroll_offset_->AbortCommit();
[email protected]58241dc2013-08-20 01:39:25506}
507
[email protected]5ff3c9782013-04-29 17:35:12508InputHandler::ScrollStatus LayerImpl::TryScroll(
[email protected]14bc5d682014-01-17 07:26:47509 const gfx::PointF& screen_space_point,
rbyers18779d822015-02-05 06:22:06510 InputHandler::ScrollInputType type,
511 ScrollBlocksOn effective_block_mode) const {
tdresser81e84c672016-01-18 23:21:22512 InputHandler::ScrollStatus scroll_status;
513 scroll_status.main_thread_scrolling_reasons =
danakj35904762016-01-21 20:49:40514 MainThreadScrollingReason::kNotScrollingOnMain;
[email protected]7aba6662013-03-12 10:17:34515 if (should_scroll_on_main_thread()) {
[email protected]ed511b8d2013-03-25 03:29:29516 TRACE_EVENT0("cc", "LayerImpl::TryScroll: Failed ShouldScrollOnMainThread");
tdresser81e84c672016-01-18 23:21:22517 scroll_status.thread = InputHandler::SCROLL_ON_MAIN_THREAD;
518 scroll_status.main_thread_scrolling_reasons =
519 main_thread_scrolling_reasons_;
520 return scroll_status;
[email protected]7aba6662013-03-12 10:17:34521 }
522
ajumab6aa1c62015-12-01 21:01:10523 gfx::Transform screen_space_transform = ScreenSpaceTransform();
524 if (!screen_space_transform.IsInvertible()) {
[email protected]ed511b8d2013-03-25 03:29:29525 TRACE_EVENT0("cc", "LayerImpl::TryScroll: Ignored NonInvertibleTransform");
tdresser81e84c672016-01-18 23:21:22526 scroll_status.thread = InputHandler::SCROLL_IGNORED;
527 scroll_status.main_thread_scrolling_reasons =
danakj35904762016-01-21 20:49:40528 MainThreadScrollingReason::kNonInvertibleTransform;
tdresser81e84c672016-01-18 23:21:22529 return scroll_status;
[email protected]7aba6662013-03-12 10:17:34530 }
531
532 if (!non_fast_scrollable_region().IsEmpty()) {
533 bool clipped = false;
534 gfx::Transform inverse_screen_space_transform(
535 gfx::Transform::kSkipInitialization);
ajumab6aa1c62015-12-01 21:01:10536 if (!screen_space_transform.GetInverse(&inverse_screen_space_transform)) {
[email protected]7aba6662013-03-12 10:17:34537 // TODO(shawnsingh): We shouldn't be applying a projection if screen space
538 // transform is uninvertible here. Perhaps we should be returning
ericrk7c030992015-02-20 01:39:38539 // SCROLL_ON_MAIN_THREAD in this case?
[email protected]3dce37232012-11-15 01:47:44540 }
541
danakj2c8d12c2015-06-18 06:15:33542 gfx::PointF hit_test_point_in_layer_space = MathUtil::ProjectPoint(
543 inverse_screen_space_transform, screen_space_point, &clipped);
[email protected]7aba6662013-03-12 10:17:34544 if (!clipped &&
545 non_fast_scrollable_region().Contains(
546 gfx::ToRoundedPoint(hit_test_point_in_layer_space))) {
547 TRACE_EVENT0("cc",
[email protected]ed511b8d2013-03-25 03:29:29548 "LayerImpl::tryScroll: Failed NonFastScrollableRegion");
tdresser81e84c672016-01-18 23:21:22549 scroll_status.thread = InputHandler::SCROLL_ON_MAIN_THREAD;
550 scroll_status.main_thread_scrolling_reasons =
danakj35904762016-01-21 20:49:40551 MainThreadScrollingReason::kNonFastScrollableRegion;
tdresser81e84c672016-01-18 23:21:22552 return scroll_status;
[email protected]3dce37232012-11-15 01:47:44553 }
[email protected]7aba6662013-03-12 10:17:34554 }
[email protected]3dce37232012-11-15 01:47:44555
rbyers18779d822015-02-05 06:22:06556 if (have_scroll_event_handlers() &&
ericrk7c030992015-02-20 01:39:38557 effective_block_mode & SCROLL_BLOCKS_ON_SCROLL_EVENT) {
rbyers18779d822015-02-05 06:22:06558 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Failed ScrollEventHandlers");
tdresser81e84c672016-01-18 23:21:22559 scroll_status.thread = InputHandler::SCROLL_ON_MAIN_THREAD;
danakj35904762016-01-21 20:49:40560 scroll_status.main_thread_scrolling_reasons =
561 MainThreadScrollingReason::kEventHandlers;
tdresser81e84c672016-01-18 23:21:22562 return scroll_status;
rbyers18779d822015-02-05 06:22:06563 }
564
skobesde5abdb82015-10-20 19:16:34565 if ((type == InputHandler::WHEEL || type == InputHandler::ANIMATED_WHEEL) &&
566 have_wheel_event_handlers() &&
ericrk7c030992015-02-20 01:39:38567 effective_block_mode & SCROLL_BLOCKS_ON_WHEEL_EVENT) {
[email protected]ed511b8d2013-03-25 03:29:29568 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Failed WheelEventHandlers");
tdresser81e84c672016-01-18 23:21:22569 scroll_status.thread = InputHandler::SCROLL_ON_MAIN_THREAD;
danakj35904762016-01-21 20:49:40570 scroll_status.main_thread_scrolling_reasons =
571 MainThreadScrollingReason::kEventHandlers;
tdresser81e84c672016-01-18 23:21:22572 return scroll_status;
[email protected]7aba6662013-03-12 10:17:34573 }
574
575 if (!scrollable()) {
576 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Ignored not scrollable");
tdresser81e84c672016-01-18 23:21:22577 scroll_status.thread = InputHandler::SCROLL_IGNORED;
danakj35904762016-01-21 20:49:40578 scroll_status.main_thread_scrolling_reasons =
579 MainThreadScrollingReason::kNotScrollable;
tdresser81e84c672016-01-18 23:21:22580 return scroll_status;
[email protected]7aba6662013-03-12 10:17:34581 }
582
miletusf57925d2014-10-01 19:38:13583 gfx::ScrollOffset max_scroll_offset = MaxScrollOffset();
[email protected]adeda572014-01-31 00:49:47584 if (max_scroll_offset.x() <= 0 && max_scroll_offset.y() <= 0) {
[email protected]7aba6662013-03-12 10:17:34585 TRACE_EVENT0("cc",
586 "LayerImpl::tryScroll: Ignored. Technically scrollable,"
587 " but has no affordance in either direction.");
tdresser81e84c672016-01-18 23:21:22588 scroll_status.thread = InputHandler::SCROLL_IGNORED;
danakj35904762016-01-21 20:49:40589 scroll_status.main_thread_scrolling_reasons =
590 MainThreadScrollingReason::kNotScrollable;
tdresser81e84c672016-01-18 23:21:22591 return scroll_status;
[email protected]7aba6662013-03-12 10:17:34592 }
593
tdresser81e84c672016-01-18 23:21:22594 scroll_status.thread = InputHandler::SCROLL_ON_IMPL_THREAD;
595 return scroll_status;
[email protected]3dce37232012-11-15 01:47:44596}
597
[email protected]7aba6662013-03-12 10:17:34598skia::RefPtr<SkPicture> LayerImpl::GetPicture() {
599 return skia::RefPtr<SkPicture>();
[email protected]76481592012-09-21 16:47:06600}
601
[email protected]7aba6662013-03-12 10:17:34602scoped_ptr<LayerImpl> LayerImpl::CreateLayerImpl(LayerTreeImpl* tree_impl) {
aeliasd0070ba2015-01-31 13:44:49603 return LayerImpl::Create(tree_impl, layer_id_, scroll_offset_);
[email protected]94f206c12012-08-25 00:09:14604}
605
[email protected]7aba6662013-03-12 10:17:34606void LayerImpl::PushPropertiesTo(LayerImpl* layer) {
[email protected]a2566412014-06-05 03:14:20607 layer->SetTransformOrigin(transform_origin_);
[email protected]7aba6662013-03-12 10:17:34608 layer->SetBackgroundColor(background_color_);
609 layer->SetBounds(bounds_);
[email protected]7aba6662013-03-12 10:17:34610 layer->SetDoubleSided(double_sided_);
[email protected]7aba6662013-03-12 10:17:34611 layer->SetDrawsContent(DrawsContent());
[email protected]c0ae06c12013-06-24 18:32:19612 layer->SetHideLayerAndSubtree(hide_layer_and_subtree_);
weiliangcc154ce22015-12-09 03:39:26613 // If whether layer has render surface changes, we need to update draw
614 // properties.
615 // TODO(weiliangc): Should be safely removed after impl side is able to
616 // update render surfaces without rebuilding property trees.
617 if (layer->has_render_surface() != has_render_surface())
618 layer->layer_tree_impl()->set_needs_update_draw_properties();
ennef44fcf92015-06-12 23:56:32619 layer->SetHasRenderSurface(!!render_surface());
weiliangcc154ce22015-12-09 03:39:26620 layer->SetForceRenderSurface(force_render_surface_);
[email protected]7aba6662013-03-12 10:17:34621 layer->SetFilters(filters());
[email protected]7aba6662013-03-12 10:17:34622 layer->SetBackgroundFilters(background_filters());
623 layer->SetMasksToBounds(masks_to_bounds_);
tdresser81e84c672016-01-18 23:21:22624 layer->set_main_thread_scrolling_reasons(main_thread_scrolling_reasons_);
[email protected]7aba6662013-03-12 10:17:34625 layer->SetHaveWheelEventHandlers(have_wheel_event_handlers_);
[email protected]f998c532014-03-31 20:02:51626 layer->SetHaveScrollEventHandlers(have_scroll_event_handlers_);
rbyers18779d822015-02-05 06:22:06627 layer->SetScrollBlocksOn(scroll_blocks_on_);
[email protected]7aba6662013-03-12 10:17:34628 layer->SetNonFastScrollableRegion(non_fast_scrollable_region_);
629 layer->SetTouchEventHandlerRegion(touch_event_handler_region_);
630 layer->SetContentsOpaque(contents_opaque_);
[email protected]43615872013-03-13 16:35:17631 layer->SetOpacity(opacity_);
[email protected]7bbeaf4e2013-11-26 10:27:22632 layer->SetBlendMode(blend_mode_);
633 layer->SetIsRootForIsolatedGroup(is_root_for_isolated_group_);
[email protected]7aba6662013-03-12 10:17:34634 layer->SetPosition(position_);
635 layer->SetIsContainerForFixedPositionLayers(
636 is_container_for_fixed_position_layers_);
[email protected]fe956c9c42013-04-09 04:26:33637 layer->SetPositionConstraint(position_constraint_);
[email protected]56fffdd2014-02-11 19:50:57638 layer->SetShouldFlattenTransform(should_flatten_transform_);
ennee95b1542015-04-20 20:35:50639 layer->set_should_flatten_transform_from_property_tree(
640 should_flatten_transform_from_property_tree_);
jaydasika92239dc2015-08-15 02:59:26641 layer->set_draw_blend_mode(draw_blend_mode_);
[email protected]7aba6662013-03-12 10:17:34642 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_);
[email protected]08bdf1b2014-04-16 23:23:29643 layer->SetTransformAndInvertibility(transform_, transform_is_invertible_);
[email protected]9bd1cb52013-01-03 22:26:33644
aeliasa57c40d122015-10-08 00:20:09645 layer->SetScrollClipLayer(scroll_clip_layer_id_);
vollick933f496e2015-12-08 04:22:05646 layer->SetElementId(element_id_);
647 layer->SetMutableProperties(mutable_properties_);
[email protected]59a7d552013-10-22 03:36:43648 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_);
649 layer->set_user_scrollable_vertical(user_scrollable_vertical_);
bokanc687507f2014-11-04 23:41:42650
miletusff93ab72015-01-30 04:30:44651 layer->SetScrollCompensationAdjustment(scroll_compensation_adjustment_);
bokanc687507f2014-11-04 23:41:42652
aeliasd0070ba2015-01-31 13:44:49653 layer->PushScrollOffset(nullptr);
654
[email protected]a9d4d4f2014-06-19 06:49:28655 layer->Set3dSortingContextId(sorting_context_id_);
[email protected]ad63b2f2014-08-11 17:39:54656 layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_);
[email protected]b34c97982013-08-24 15:21:38657
vollick692444f2015-05-20 15:39:14658 layer->SetTransformTreeIndex(transform_tree_index_);
659 layer->SetClipTreeIndex(clip_tree_index_);
weiliangc6a52f302015-08-18 16:29:35660 layer->SetEffectTreeIndex(effect_tree_index_);
ennee95b1542015-04-20 20:35:50661 layer->set_offset_to_transform_parent(offset_to_transform_parent_);
jaydasikab5504ca2015-12-18 23:41:55662 layer->set_is_hidden_from_property_trees(is_hidden_from_property_trees_);
ennee95b1542015-04-20 20:35:50663
kulkarni.a4015690f12014-10-10 13:50:06664 LayerImpl* scroll_parent = nullptr;
[email protected]d097e242014-02-28 21:51:11665 if (scroll_parent_) {
[email protected]0e98cdd2013-08-23 00:44:30666 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id());
[email protected]d097e242014-02-28 21:51:11667 DCHECK(scroll_parent);
668 }
[email protected]0e98cdd2013-08-23 00:44:30669
670 layer->SetScrollParent(scroll_parent);
671 if (scroll_children_) {
672 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>;
673 for (std::set<LayerImpl*>::iterator it = scroll_children_->begin();
[email protected]d097e242014-02-28 21:51:11674 it != scroll_children_->end();
675 ++it) {
676 DCHECK_EQ((*it)->scroll_parent(), this);
677 LayerImpl* scroll_child =
678 layer->layer_tree_impl()->LayerById((*it)->id());
679 DCHECK(scroll_child);
680 scroll_children->insert(scroll_child);
681 }
[email protected]0e98cdd2013-08-23 00:44:30682 layer->SetScrollChildren(scroll_children);
[email protected]d097e242014-02-28 21:51:11683 } else {
kulkarni.a4015690f12014-10-10 13:50:06684 layer->SetScrollChildren(nullptr);
[email protected]0e98cdd2013-08-23 00:44:30685 }
686
kulkarni.a4015690f12014-10-10 13:50:06687 LayerImpl* clip_parent = nullptr;
[email protected]0e98cdd2013-08-23 00:44:30688 if (clip_parent_) {
689 clip_parent = layer->layer_tree_impl()->LayerById(
690 clip_parent_->id());
[email protected]d097e242014-02-28 21:51:11691 DCHECK(clip_parent);
[email protected]0e98cdd2013-08-23 00:44:30692 }
693
694 layer->SetClipParent(clip_parent);
695 if (clip_children_) {
696 std::set<LayerImpl*>* clip_children = new std::set<LayerImpl*>;
697 for (std::set<LayerImpl*>::iterator it = clip_children_->begin();
698 it != clip_children_->end(); ++it)
699 clip_children->insert(layer->layer_tree_impl()->LayerById((*it)->id()));
700 layer->SetClipChildren(clip_children);
[email protected]d097e242014-02-28 21:51:11701 } else {
kulkarni.a4015690f12014-10-10 13:50:06702 layer->SetClipChildren(nullptr);
[email protected]0e98cdd2013-08-23 00:44:30703 }
704
[email protected]0e5f7142013-05-24 06:45:36705 layer->PassCopyRequests(&copy_requests_);
[email protected]18a70192013-04-26 16:18:25706
[email protected]7aba6662013-03-12 10:17:34707 // If the main thread commits multiple times before the impl thread actually
708 // draws, then damage tracking will become incorrect if we simply clobber the
[email protected]ed511b8d2013-03-25 03:29:29709 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e.
[email protected]7aba6662013-03-12 10:17:34710 // union) any update changes that have occurred on the main thread.
711 update_rect_.Union(layer->update_rect());
[email protected]ad0250b2014-01-18 03:24:34712 layer->SetUpdateRect(update_rect_);
[email protected]7aba6662013-03-12 10:17:34713
[email protected]7aba6662013-03-12 10:17:34714 layer->SetStackingOrderChanged(stacking_order_changed_);
[email protected]ad0250b2014-01-18 03:24:34715 layer->SetDebugInfo(debug_info_);
[email protected]7aba6662013-03-12 10:17:34716
vmpstr3d1d72c2015-01-26 18:27:40717 if (frame_timing_requests_dirty_) {
vmpstr3a24da5042015-05-27 03:33:31718 layer->SetFrameTimingRequests(frame_timing_requests_);
vmpstr3d1d72c2015-01-26 18:27:40719 frame_timing_requests_dirty_ = false;
720 }
721
[email protected]7aba6662013-03-12 10:17:34722 // Reset any state that should be cleared for the next update.
723 stacking_order_changed_ = false;
danakj19f0c9e2014-10-11 03:24:42724 update_rect_ = gfx::Rect();
[email protected]ad0250b2014-01-18 03:24:34725 needs_push_properties_ = false;
726 num_dependents_need_push_properties_ = 0;
[email protected]caa567d2012-12-20 07:56:16727}
728
sunxdf66237552016-01-06 21:36:37729bool LayerImpl::IsAffectedByPageScale() const {
730 TransformTree& transform_tree =
731 layer_tree_impl()->property_trees()->transform_tree;
732 return transform_tree.Node(transform_tree_index())
733 ->data.in_subtree_of_page_scale_layer;
734}
735
[email protected]fef74fd2014-02-27 06:28:17736gfx::Vector2dF LayerImpl::FixedContainerSizeDelta() const {
aeliasa57c40d122015-10-08 00:20:09737 LayerImpl* scroll_clip_layer =
738 layer_tree_impl()->LayerById(scroll_clip_layer_id_);
739 if (!scroll_clip_layer)
[email protected]fef74fd2014-02-27 06:28:17740 return gfx::Vector2dF();
741
aeliasa57c40d122015-10-08 00:20:09742 return scroll_clip_layer->bounds_delta();
[email protected]fef74fd2014-02-27 06:28:17743}
744
[email protected]7aba6662013-03-12 10:17:34745base::DictionaryValue* LayerImpl::LayerTreeAsJson() const {
[email protected]7aba6662013-03-12 10:17:34746 base::DictionaryValue* result = new base::DictionaryValue;
r.kasibhatlafd17d0e2015-05-17 11:12:07747 result->SetInteger("LayerId", id());
[email protected]7aba6662013-03-12 10:17:34748 result->SetString("LayerType", LayerTypeAsString());
749
[email protected]46c76952013-07-10 00:21:45750 base::ListValue* list = new base::ListValue;
bokancccfde72014-10-08 15:15:22751 list->AppendInteger(bounds().width());
752 list->AppendInteger(bounds().height());
[email protected]7aba6662013-03-12 10:17:34753 result->Set("Bounds", list);
754
755 list = new base::ListValue;
756 list->AppendDouble(position_.x());
757 list->AppendDouble(position_.y());
758 result->Set("Position", list);
759
ajumad9432e32015-11-30 19:43:44760 const gfx::Transform& gfx_transform = DrawTransform();
[email protected]7aba6662013-03-12 10:17:34761 double transform[16];
762 gfx_transform.matrix().asColMajord(transform);
763 list = new base::ListValue;
764 for (int i = 0; i < 16; ++i)
765 list->AppendDouble(transform[i]);
766 result->Set("DrawTransform", list);
767
768 result->SetBoolean("DrawsContent", draws_content_);
[email protected]a9d4d4f2014-06-19 06:49:28769 result->SetBoolean("Is3dSorted", Is3dSorted());
ericrk7c030992015-02-20 01:39:38770 result->SetDouble("OPACITY", opacity());
[email protected]46c76952013-07-10 00:21:45771 result->SetBoolean("ContentsOpaque", contents_opaque_);
[email protected]7aba6662013-03-12 10:17:34772
[email protected]adeda572014-01-31 00:49:47773 if (scrollable())
774 result->SetBoolean("Scrollable", true);
[email protected]d993e032013-06-07 00:16:16775
[email protected]9d161d22013-10-29 20:54:10776 if (have_wheel_event_handlers_)
777 result->SetBoolean("WheelHandler", have_wheel_event_handlers_);
[email protected]f998c532014-03-31 20:02:51778 if (have_scroll_event_handlers_)
779 result->SetBoolean("ScrollHandler", have_scroll_event_handlers_);
[email protected]9d161d22013-10-29 20:54:10780 if (!touch_event_handler_region_.IsEmpty()) {
781 scoped_ptr<base::Value> region = touch_event_handler_region_.AsValue();
782 result->Set("TouchRegion", region.release());
783 }
784
rbyers18779d822015-02-05 06:22:06785 if (scroll_blocks_on_) {
786 list = new base::ListValue;
ericrk7c030992015-02-20 01:39:38787 if (scroll_blocks_on_ & SCROLL_BLOCKS_ON_START_TOUCH)
rbyers18779d822015-02-05 06:22:06788 list->AppendString("StartTouch");
ericrk7c030992015-02-20 01:39:38789 if (scroll_blocks_on_ & SCROLL_BLOCKS_ON_WHEEL_EVENT)
rbyers18779d822015-02-05 06:22:06790 list->AppendString("WheelEvent");
ericrk7c030992015-02-20 01:39:38791 if (scroll_blocks_on_ & SCROLL_BLOCKS_ON_SCROLL_EVENT)
rbyers18779d822015-02-05 06:22:06792 list->AppendString("ScrollEvent");
793 result->Set("ScrollBlocksOn", list);
794 }
795
[email protected]7aba6662013-03-12 10:17:34796 list = new base::ListValue;
797 for (size_t i = 0; i < children_.size(); ++i)
798 list->Append(children_[i]->LayerTreeAsJson());
799 result->Set("Children", list);
800
801 return result;
[email protected]b9dcf43a2013-01-09 00:15:29802}
803
[email protected]7aba6662013-03-12 10:17:34804void LayerImpl::SetStackingOrderChanged(bool stacking_order_changed) {
805 if (stacking_order_changed) {
806 stacking_order_changed_ = true;
807 NoteLayerPropertyChangedForSubtree();
808 }
[email protected]aedf4e52013-01-09 23:24:44809}
810
[email protected]7aba6662013-03-12 10:17:34811void LayerImpl::NoteLayerPropertyChanged() {
812 layer_property_changed_ = true;
813 layer_tree_impl()->set_needs_update_draw_properties();
[email protected]ad0250b2014-01-18 03:24:34814 SetNeedsPushProperties();
[email protected]48871fc2013-01-23 07:36:51815}
816
[email protected]7aba6662013-03-12 10:17:34817void LayerImpl::NoteLayerPropertyChangedForSubtree() {
[email protected]ad0250b2014-01-18 03:24:34818 layer_property_changed_ = true;
819 layer_tree_impl()->set_needs_update_draw_properties();
820 for (size_t i = 0; i < children_.size(); ++i)
821 children_[i]->NoteLayerPropertyChangedForDescendantsInternal();
822 SetNeedsPushProperties();
823}
824
825void LayerImpl::NoteLayerPropertyChangedForDescendantsInternal() {
826 layer_property_changed_ = true;
827 for (size_t i = 0; i < children_.size(); ++i)
828 children_[i]->NoteLayerPropertyChangedForDescendantsInternal();
[email protected]94f206c12012-08-25 00:09:14829}
830
[email protected]7aba6662013-03-12 10:17:34831void LayerImpl::NoteLayerPropertyChangedForDescendants() {
832 layer_tree_impl()->set_needs_update_draw_properties();
833 for (size_t i = 0; i < children_.size(); ++i)
[email protected]ad0250b2014-01-18 03:24:34834 children_[i]->NoteLayerPropertyChangedForDescendantsInternal();
835 SetNeedsPushProperties();
[email protected]7aba6662013-03-12 10:17:34836}
[email protected]94f206c12012-08-25 00:09:14837
danakjf9427572015-04-24 22:19:02838void LayerImpl::ValidateQuadResourcesInternal(DrawQuad* quad) const {
839#if DCHECK_IS_ON()
vmpstr0eca2e82015-06-02 22:14:46840 const ResourceProvider* resource_provider =
841 layer_tree_impl_->resource_provider();
842 for (ResourceId resource_id : quad->resources)
843 resource_provider->ValidateResource(resource_id);
danakjf9427572015-04-24 22:19:02844#endif
845}
846
[email protected]7aba6662013-03-12 10:17:34847const char* LayerImpl::LayerTypeAsString() const {
[email protected]f256b7fd2013-05-15 01:49:30848 return "cc::LayerImpl";
[email protected]7aba6662013-03-12 10:17:34849}
[email protected]94f206c12012-08-25 00:09:14850
[email protected]7aba6662013-03-12 10:17:34851void LayerImpl::ResetAllChangeTrackingForSubtree() {
852 layer_property_changed_ = false;
[email protected]7aba6662013-03-12 10:17:34853
danakjd344ab92015-08-28 19:25:51854 update_rect_.SetRect(0, 0, 0, 0);
855 damage_rect_.SetRect(0, 0, 0, 0);
[email protected]7aba6662013-03-12 10:17:34856
awoloszyne83f28c2014-12-22 15:40:00857 if (render_surface_)
858 render_surface_->ResetPropertyChangedFlag();
[email protected]7aba6662013-03-12 10:17:34859
860 if (mask_layer_)
861 mask_layer_->ResetAllChangeTrackingForSubtree();
862
863 if (replica_layer_) {
864 // This also resets the replica mask, if it exists.
865 replica_layer_->ResetAllChangeTrackingForSubtree();
866 }
867
868 for (size_t i = 0; i < children_.size(); ++i)
869 children_[i]->ResetAllChangeTrackingForSubtree();
[email protected]ad0250b2014-01-18 03:24:34870
871 needs_push_properties_ = false;
872 num_dependents_need_push_properties_ = 0;
[email protected]7aba6662013-03-12 10:17:34873}
874
sunxded58688e2016-01-11 21:01:02875int LayerImpl::num_copy_requests_in_target_subtree() {
876 return layer_tree_impl()
877 ->property_trees()
878 ->effect_tree.Node(effect_tree_index())
879 ->data.num_copy_requests_in_subtree;
880}
881
ajuma59c23b42015-05-25 20:18:37882void LayerImpl::UpdatePropertyTreeTransform() {
883 if (transform_tree_index_ != -1) {
884 TransformTree& transform_tree =
885 layer_tree_impl()->property_trees()->transform_tree;
886 TransformNode* node = transform_tree.Node(transform_tree_index_);
ajumae7425272015-07-13 18:37:34887 // A LayerImpl's own current state is insufficient for determining whether
888 // it owns a TransformNode, since this depends on the state of the
889 // corresponding Layer at the time of the last commit. For example, a
890 // transform animation might have been in progress at the time the last
891 // commit started, but might have finished since then on the compositor
892 // thread.
893 if (node->owner_id != id())
894 return;
ajuma59c23b42015-05-25 20:18:37895 if (node->data.local != transform_) {
896 node->data.local = transform_;
897 node->data.needs_local_transform_update = true;
898 transform_tree.set_needs_update(true);
899 // TODO(ajuma): The current criteria for creating clip nodes means that
900 // property trees may need to be rebuilt when the new transform isn't
901 // axis-aligned wrt the old transform (see Layer::SetTransform). Since
902 // rebuilding property trees every frame of a transform animation is
903 // something we should try to avoid, change property tree-building so that
904 // it doesn't depend on axis aliginment.
905 }
906 }
907}
908
ajumacaaa9b32015-08-04 15:55:29909void LayerImpl::UpdatePropertyTreeTransformIsAnimated(bool is_animated) {
910 if (transform_tree_index_ != -1) {
911 TransformTree& transform_tree =
912 layer_tree_impl()->property_trees()->transform_tree;
913 TransformNode* node = transform_tree.Node(transform_tree_index_);
914 // A LayerImpl's own current state is insufficient for determining whether
915 // it owns a TransformNode, since this depends on the state of the
916 // corresponding Layer at the time of the last commit. For example, if
917 // |is_animated| is false, this might mean a transform animation just ticked
918 // past its finish point (so the LayerImpl still owns a TransformNode) or it
919 // might mean that a transform animation was removed during commit or
920 // activation (and, in that case, the LayerImpl will no longer own a
921 // TransformNode, unless it has non-animation-related reasons for owning a
922 // node).
923 if (node->owner_id != id())
924 return;
925 if (node->data.is_animated != is_animated) {
926 node->data.is_animated = is_animated;
ajumab4a846f22015-08-24 19:13:44927 if (is_animated) {
928 float maximum_target_scale = 0.f;
929 node->data.local_maximum_animation_target_scale =
930 MaximumTargetScale(&maximum_target_scale) ? maximum_target_scale
931 : 0.f;
932
933 float animation_start_scale = 0.f;
934 node->data.local_starting_animation_scale =
935 AnimationStartScale(&animation_start_scale) ? animation_start_scale
936 : 0.f;
937
938 node->data.has_only_translation_animations =
939 HasOnlyTranslationTransforms();
940 } else {
941 node->data.local_maximum_animation_target_scale = 0.f;
942 node->data.local_starting_animation_scale = 0.f;
943 node->data.has_only_translation_animations = true;
944 }
945
ajumacaaa9b32015-08-04 15:55:29946 transform_tree.set_needs_update(true);
loyso62daf92e2015-11-20 04:47:35947 layer_tree_impl()->set_needs_update_draw_properties();
ajumacaaa9b32015-08-04 15:55:29948 }
949 }
950}
951
ajuma59c23b42015-05-25 20:18:37952void LayerImpl::UpdatePropertyTreeOpacity() {
weiliangc6a52f302015-08-18 16:29:35953 if (effect_tree_index_ != -1) {
954 EffectTree& effect_tree = layer_tree_impl()->property_trees()->effect_tree;
aeliasa57c40d122015-10-08 00:20:09955 if (effect_tree_index_ >= static_cast<int>(effect_tree.size()))
956 return;
weiliangc6a52f302015-08-18 16:29:35957 EffectNode* node = effect_tree.Node(effect_tree_index_);
ajumae7425272015-07-13 18:37:34958 // A LayerImpl's own current state is insufficient for determining whether
959 // it owns an OpacityNode, since this depends on the state of the
960 // corresponding Layer at the time of the last commit. For example, an
961 // opacity animation might have been in progress at the time the last commit
962 // started, but might have finished since then on the compositor thread.
963 if (node->owner_id != id())
964 return;
jaydasika9fc1aef2015-06-26 23:35:57965 node->data.opacity = opacity_;
weiliangc6a52f302015-08-18 16:29:35966 effect_tree.set_needs_update(true);
ajuma59c23b42015-05-25 20:18:37967 }
968}
969
ajuma9db24fb2015-06-29 20:15:07970void LayerImpl::UpdatePropertyTreeForScrollingAndAnimationIfNeeded() {
971 if (scrollable())
972 UpdatePropertyTreeScrollOffset();
973
ajumae7425272015-07-13 18:37:34974 if (HasAnyAnimationTargetingProperty(Animation::OPACITY))
ajuma9db24fb2015-06-29 20:15:07975 UpdatePropertyTreeOpacity();
976
ajumacaaa9b32015-08-04 15:55:29977 if (HasAnyAnimationTargetingProperty(Animation::TRANSFORM)) {
ajuma9db24fb2015-06-29 20:15:07978 UpdatePropertyTreeTransform();
ajumacaaa9b32015-08-04 15:55:29979 UpdatePropertyTreeTransformIsAnimated(
980 HasPotentiallyRunningTransformAnimation());
981 }
ajuma9db24fb2015-06-29 20:15:07982}
983
miletusf57925d2014-10-01 19:38:13984gfx::ScrollOffset LayerImpl::ScrollOffsetForAnimation() const {
aeliasd0070ba2015-01-31 13:44:49985 return CurrentScrollOffset();
[email protected]b8384e22013-12-03 02:20:48986}
987
[email protected]b4c6d812013-10-03 15:48:56988void LayerImpl::OnFilterAnimated(const FilterOperations& filters) {
989 SetFilters(filters);
990}
991
[email protected]7aba6662013-03-12 10:17:34992void LayerImpl::OnOpacityAnimated(float opacity) {
993 SetOpacity(opacity);
ajuma59c23b42015-05-25 20:18:37994 UpdatePropertyTreeOpacity();
[email protected]7aba6662013-03-12 10:17:34995}
996
997void LayerImpl::OnTransformAnimated(const gfx::Transform& transform) {
998 SetTransform(transform);
ajuma59c23b42015-05-25 20:18:37999 UpdatePropertyTreeTransform();
vmpstre1564a52015-11-24 19:43:151000 was_ever_ready_since_last_transform_animation_ = false;
[email protected]7aba6662013-03-12 10:17:341001}
1002
miletusf57925d2014-10-01 19:38:131003void LayerImpl::OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) {
[email protected]b8384e22013-12-03 02:20:481004 // Only layers in the active tree should need to do anything here, since
1005 // layers in the pending tree will find out about these changes as a
aeliasd0070ba2015-01-31 13:44:491006 // result of the shared SyncedProperty.
[email protected]b8384e22013-12-03 02:20:481007 if (!IsActive())
1008 return;
1009
aeliasd0070ba2015-01-31 13:44:491010 SetCurrentScrollOffset(scroll_offset);
[email protected]b8384e22013-12-03 02:20:481011
1012 layer_tree_impl_->DidAnimateScrollOffset();
1013}
1014
[email protected]1c24cf2962013-11-18 23:34:511015void LayerImpl::OnAnimationWaitingForDeletion() {}
1016
ajumacaaa9b32015-08-04 15:55:291017void LayerImpl::OnTransformIsPotentiallyAnimatingChanged(bool is_animating) {
1018 UpdatePropertyTreeTransformIsAnimated(is_animating);
vmpstre1564a52015-11-24 19:43:151019 was_ever_ready_since_last_transform_animation_ = false;
ajumacaaa9b32015-08-04 15:55:291020}
1021
[email protected]7aba6662013-03-12 10:17:341022bool LayerImpl::IsActive() const {
1023 return layer_tree_impl_->IsActiveTree();
1024}
1025
bokancccfde72014-10-08 15:15:221026gfx::Size LayerImpl::bounds() const {
bokanef971462014-10-13 22:58:321027 gfx::Vector2d delta = gfx::ToCeiledVector2d(bounds_delta_);
1028 return gfx::Size(bounds_.width() + delta.x(),
1029 bounds_.height() + delta.y());
1030}
1031
1032gfx::SizeF LayerImpl::BoundsForScrolling() const {
1033 return gfx::SizeF(bounds_.width() + bounds_delta_.x(),
1034 bounds_.height() + bounds_delta_.y());
[email protected]fef74fd2014-02-27 06:28:171035}
1036
[email protected]64348ea2014-01-29 22:58:261037void LayerImpl::SetBounds(const gfx::Size& bounds) {
[email protected]7aba6662013-03-12 10:17:341038 if (bounds_ == bounds)
1039 return;
1040
1041 bounds_ = bounds;
[email protected]fef74fd2014-02-27 06:28:171042
aeliasa57c40d122015-10-08 00:20:091043 layer_tree_impl()->DidUpdateScrollState(id());
[email protected]fef74fd2014-02-27 06:28:171044 if (masks_to_bounds())
1045 NoteLayerPropertyChangedForSubtree();
1046 else
1047 NoteLayerPropertyChanged();
1048}
1049
[email protected]587941d2014-08-22 01:40:011050void LayerImpl::SetBoundsDelta(const gfx::Vector2dF& bounds_delta) {
ajuma6b46da22015-06-25 21:53:021051 DCHECK(IsActive());
[email protected]587941d2014-08-22 01:40:011052 if (bounds_delta_ == bounds_delta)
[email protected]fef74fd2014-02-27 06:28:171053 return;
1054
[email protected]587941d2014-08-22 01:40:011055 bounds_delta_ = bounds_delta;
[email protected]7aba6662013-03-12 10:17:341056
ajuma6b46da22015-06-25 21:53:021057 TransformTree& transform_tree =
1058 layer_tree_impl()->property_trees()->transform_tree;
ajumadd2802e72015-06-30 20:28:291059 if (this == layer_tree_impl()->InnerViewportContainerLayer())
1060 transform_tree.SetInnerViewportBoundsDelta(bounds_delta);
1061 else if (this == layer_tree_impl()->OuterViewportContainerLayer())
1062 transform_tree.SetOuterViewportBoundsDelta(bounds_delta);
ajuma6b46da22015-06-25 21:53:021063
aeliasa57c40d122015-10-08 00:20:091064 layer_tree_impl()->DidUpdateScrollState(id());
miletus8bd08a622015-06-16 18:44:521065
1066 if (masks_to_bounds()) {
1067 // If layer is clipping, then update the clip node using the new bounds.
1068 ClipNode* clip_node =
1069 layer_tree_impl()->property_trees()->clip_tree.Node(clip_tree_index());
1070 if (clip_node) {
1071 DCHECK(id() == clip_node->owner_id);
danakjddaec912015-09-25 19:38:401072 clip_node->data.clip = gfx::RectF(
1073 gfx::PointF() + offset_to_transform_parent(), gfx::SizeF(bounds()));
miletus8bd08a622015-06-16 18:44:521074 layer_tree_impl()->property_trees()->clip_tree.set_needs_update(true);
1075 }
1076
[email protected]7aba6662013-03-12 10:17:341077 NoteLayerPropertyChangedForSubtree();
miletus8bd08a622015-06-16 18:44:521078 } else {
[email protected]7aba6662013-03-12 10:17:341079 NoteLayerPropertyChanged();
miletus8bd08a622015-06-16 18:44:521080 }
[email protected]7aba6662013-03-12 10:17:341081}
1082
1083void LayerImpl::SetMaskLayer(scoped_ptr<LayerImpl> mask_layer) {
1084 int new_layer_id = mask_layer ? mask_layer->id() : -1;
1085
1086 if (mask_layer) {
1087 DCHECK_EQ(layer_tree_impl(), mask_layer->layer_tree_impl());
1088 DCHECK_NE(new_layer_id, mask_layer_id_);
1089 } else if (new_layer_id == mask_layer_id_) {
1090 return;
1091 }
1092
danakja04855a2015-11-18 20:39:101093 mask_layer_ = std::move(mask_layer);
[email protected]7aba6662013-03-12 10:17:341094 mask_layer_id_ = new_layer_id;
1095 if (mask_layer_)
[email protected]ad0250b2014-01-18 03:24:341096 mask_layer_->SetParent(this);
[email protected]7aba6662013-03-12 10:17:341097 NoteLayerPropertyChangedForSubtree();
1098}
1099
1100scoped_ptr<LayerImpl> LayerImpl::TakeMaskLayer() {
1101 mask_layer_id_ = -1;
danakja04855a2015-11-18 20:39:101102 return std::move(mask_layer_);
[email protected]7aba6662013-03-12 10:17:341103}
1104
1105void LayerImpl::SetReplicaLayer(scoped_ptr<LayerImpl> replica_layer) {
1106 int new_layer_id = replica_layer ? replica_layer->id() : -1;
1107
1108 if (replica_layer) {
1109 DCHECK_EQ(layer_tree_impl(), replica_layer->layer_tree_impl());
1110 DCHECK_NE(new_layer_id, replica_layer_id_);
1111 } else if (new_layer_id == replica_layer_id_) {
1112 return;
1113 }
1114
danakja04855a2015-11-18 20:39:101115 replica_layer_ = std::move(replica_layer);
[email protected]7aba6662013-03-12 10:17:341116 replica_layer_id_ = new_layer_id;
1117 if (replica_layer_)
[email protected]ad0250b2014-01-18 03:24:341118 replica_layer_->SetParent(this);
[email protected]7aba6662013-03-12 10:17:341119 NoteLayerPropertyChangedForSubtree();
1120}
1121
1122scoped_ptr<LayerImpl> LayerImpl::TakeReplicaLayer() {
1123 replica_layer_id_ = -1;
danakja04855a2015-11-18 20:39:101124 return std::move(replica_layer_);
[email protected]7aba6662013-03-12 10:17:341125}
1126
[email protected]80413d72013-08-30 20:25:331127ScrollbarLayerImplBase* LayerImpl::ToScrollbarLayer() {
kulkarni.a4015690f12014-10-10 13:50:061128 return nullptr;
[email protected]7aba6662013-03-12 10:17:341129}
1130
1131void LayerImpl::SetDrawsContent(bool draws_content) {
1132 if (draws_content_ == draws_content)
1133 return;
1134
1135 draws_content_ = draws_content;
1136 NoteLayerPropertyChanged();
1137}
1138
[email protected]c0ae06c12013-06-24 18:32:191139void LayerImpl::SetHideLayerAndSubtree(bool hide) {
1140 if (hide_layer_and_subtree_ == hide)
1141 return;
1142
1143 hide_layer_and_subtree_ = hide;
1144 NoteLayerPropertyChangedForSubtree();
1145}
1146
[email protected]a2566412014-06-05 03:14:201147void LayerImpl::SetTransformOrigin(const gfx::Point3F& transform_origin) {
1148 if (transform_origin_ == transform_origin)
[email protected]7aba6662013-03-12 10:17:341149 return;
[email protected]a2566412014-06-05 03:14:201150 transform_origin_ = transform_origin;
[email protected]7aba6662013-03-12 10:17:341151 NoteLayerPropertyChangedForSubtree();
1152}
1153
1154void LayerImpl::SetBackgroundColor(SkColor background_color) {
1155 if (background_color_ == background_color)
1156 return;
1157
1158 background_color_ = background_color;
1159 NoteLayerPropertyChanged();
1160}
1161
[email protected]2c4cbec2013-06-04 21:14:501162SkColor LayerImpl::SafeOpaqueBackgroundColor() const {
1163 SkColor color = background_color();
1164 if (SkColorGetA(color) == 255 && !contents_opaque()) {
1165 color = SK_ColorTRANSPARENT;
1166 } else if (SkColorGetA(color) != 255 && contents_opaque()) {
1167 for (const LayerImpl* layer = parent(); layer;
1168 layer = layer->parent()) {
1169 color = layer->background_color();
1170 if (SkColorGetA(color) == 255)
1171 break;
1172 }
1173 if (SkColorGetA(color) != 255)
1174 color = layer_tree_impl()->background_color();
1175 if (SkColorGetA(color) != 255)
1176 color = SkColorSetA(color, 255);
1177 }
1178 return color;
1179}
1180
[email protected]ae6b1a72013-06-25 18:49:291181void LayerImpl::SetFilters(const FilterOperations& filters) {
[email protected]7aba6662013-03-12 10:17:341182 if (filters_ == filters)
1183 return;
1184
[email protected]7aba6662013-03-12 10:17:341185 filters_ = filters;
1186 NoteLayerPropertyChangedForSubtree();
1187}
1188
[email protected]b4c6d812013-10-03 15:48:561189bool LayerImpl::FilterIsAnimating() const {
ajuma315a4782015-07-24 21:16:341190 LayerAnimationController::ObserverType observer_type =
1191 IsActive() ? LayerAnimationController::ObserverType::ACTIVE
1192 : LayerAnimationController::ObserverType::PENDING;
loysod71ece82015-07-03 13:48:501193 return layer_animation_controller_
ajuma315a4782015-07-24 21:16:341194 ? layer_animation_controller_->IsCurrentlyAnimatingProperty(
1195 Animation::FILTER, observer_type)
loysod71ece82015-07-03 13:48:501196 : layer_tree_impl_->IsAnimatingFilterProperty(this);
[email protected]b4c6d812013-10-03 15:48:561197}
1198
ajuma315a4782015-07-24 21:16:341199bool LayerImpl::HasPotentiallyRunningFilterAnimation() const {
1200 LayerAnimationController::ObserverType observer_type =
1201 IsActive() ? LayerAnimationController::ObserverType::ACTIVE
1202 : LayerAnimationController::ObserverType::PENDING;
1203 return layer_animation_controller_
1204 ? layer_animation_controller_->IsPotentiallyAnimatingProperty(
1205 Animation::FILTER, observer_type)
1206 : layer_tree_impl_->HasPotentiallyRunningFilterAnimation(this);
1207}
1208
[email protected]b4c6d812013-10-03 15:48:561209bool LayerImpl::FilterIsAnimatingOnImplOnly() const {
loysod71ece82015-07-03 13:48:501210 if (!layer_animation_controller_)
1211 return layer_tree_impl_->FilterIsAnimatingOnImplOnly(this);
1212
[email protected]b4c6d812013-10-03 15:48:561213 Animation* filter_animation =
ericrk7c030992015-02-20 01:39:381214 layer_animation_controller_->GetAnimation(Animation::FILTER);
[email protected]b4c6d812013-10-03 15:48:561215 return filter_animation && filter_animation->is_impl_only();
1216}
1217
[email protected]7aba6662013-03-12 10:17:341218void LayerImpl::SetBackgroundFilters(
[email protected]ae6b1a72013-06-25 18:49:291219 const FilterOperations& filters) {
[email protected]7aba6662013-03-12 10:17:341220 if (background_filters_ == filters)
1221 return;
1222
1223 background_filters_ = filters;
1224 NoteLayerPropertyChanged();
1225}
1226
[email protected]7aba6662013-03-12 10:17:341227void LayerImpl::SetMasksToBounds(bool masks_to_bounds) {
1228 if (masks_to_bounds_ == masks_to_bounds)
1229 return;
1230
1231 masks_to_bounds_ = masks_to_bounds;
1232 NoteLayerPropertyChangedForSubtree();
1233}
1234
1235void LayerImpl::SetContentsOpaque(bool opaque) {
1236 if (contents_opaque_ == opaque)
1237 return;
1238
1239 contents_opaque_ = opaque;
1240 NoteLayerPropertyChangedForSubtree();
1241}
1242
1243void LayerImpl::SetOpacity(float opacity) {
1244 if (opacity_ == opacity)
1245 return;
1246
1247 opacity_ = opacity;
[email protected]af37ce802013-10-07 23:53:281248 NoteLayerPropertyChangedForSubtree();
[email protected]7aba6662013-03-12 10:17:341249}
1250
1251bool LayerImpl::OpacityIsAnimating() const {
ajuma315a4782015-07-24 21:16:341252 LayerAnimationController::ObserverType observer_type =
1253 IsActive() ? LayerAnimationController::ObserverType::ACTIVE
1254 : LayerAnimationController::ObserverType::PENDING;
loysod71ece82015-07-03 13:48:501255 return layer_animation_controller_
ajuma315a4782015-07-24 21:16:341256 ? layer_animation_controller_->IsCurrentlyAnimatingProperty(
1257 Animation::OPACITY, observer_type)
loysod71ece82015-07-03 13:48:501258 : layer_tree_impl_->IsAnimatingOpacityProperty(this);
1259}
1260
1261bool LayerImpl::HasPotentiallyRunningOpacityAnimation() const {
ajuma315a4782015-07-24 21:16:341262 LayerAnimationController::ObserverType observer_type =
1263 IsActive() ? LayerAnimationController::ObserverType::ACTIVE
1264 : LayerAnimationController::ObserverType::PENDING;
1265 return layer_animation_controller_
1266 ? layer_animation_controller_->IsPotentiallyAnimatingProperty(
1267 Animation::OPACITY, observer_type)
1268 : layer_tree_impl_->HasPotentiallyRunningOpacityAnimation(this);
[email protected]7aba6662013-03-12 10:17:341269}
1270
[email protected]43615872013-03-13 16:35:171271bool LayerImpl::OpacityIsAnimatingOnImplOnly() const {
loysod71ece82015-07-03 13:48:501272 if (!layer_animation_controller_)
1273 return layer_tree_impl_->OpacityIsAnimatingOnImplOnly(this);
1274
[email protected]43615872013-03-13 16:35:171275 Animation* opacity_animation =
ericrk7c030992015-02-20 01:39:381276 layer_animation_controller_->GetAnimation(Animation::OPACITY);
[email protected]43615872013-03-13 16:35:171277 return opacity_animation && opacity_animation->is_impl_only();
1278}
1279
vollick933f496e2015-12-08 04:22:051280void LayerImpl::SetElementId(uint64_t element_id) {
1281 if (element_id == element_id_)
1282 return;
1283
1284 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("compositor-worker"),
1285 "LayerImpl::SetElementId", "id", element_id);
1286
vollick9c7f6d02016-01-08 04:36:381287 layer_tree_impl_->RemoveFromElementMap(this);
vollick933f496e2015-12-08 04:22:051288 element_id_ = element_id;
vollick9c7f6d02016-01-08 04:36:381289 layer_tree_impl_->AddToElementMap(this);
vollick933f496e2015-12-08 04:22:051290 SetNeedsPushProperties();
1291}
1292
1293void LayerImpl::SetMutableProperties(uint32_t properties) {
1294 if (mutable_properties_ == properties)
1295 return;
1296
1297 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("compositor-worker"),
1298 "LayerImpl::SetMutableProperties", "properties", properties);
1299
1300 mutable_properties_ = properties;
vollick9c7f6d02016-01-08 04:36:381301 // If this layer is already in the element map, update its properties.
1302 layer_tree_impl_->AddToElementMap(this);
vollick933f496e2015-12-08 04:22:051303 SetNeedsPushProperties();
1304}
1305
[email protected]7bbeaf4e2013-11-26 10:27:221306void LayerImpl::SetBlendMode(SkXfermode::Mode blend_mode) {
1307 if (blend_mode_ == blend_mode)
1308 return;
1309
1310 blend_mode_ = blend_mode;
1311 NoteLayerPropertyChangedForSubtree();
1312}
1313
1314void LayerImpl::SetIsRootForIsolatedGroup(bool root) {
1315 if (is_root_for_isolated_group_ == root)
1316 return;
1317
1318 is_root_for_isolated_group_ = root;
[email protected]ad0250b2014-01-18 03:24:341319 SetNeedsPushProperties();
[email protected]7bbeaf4e2013-11-26 10:27:221320}
1321
[email protected]14bc5d682014-01-17 07:26:471322void LayerImpl::SetPosition(const gfx::PointF& position) {
[email protected]7aba6662013-03-12 10:17:341323 if (position_ == position)
1324 return;
1325
1326 position_ = position;
1327 NoteLayerPropertyChangedForSubtree();
1328}
1329
[email protected]56fffdd2014-02-11 19:50:571330void LayerImpl::SetShouldFlattenTransform(bool flatten) {
1331 if (should_flatten_transform_ == flatten)
[email protected]7aba6662013-03-12 10:17:341332 return;
1333
[email protected]56fffdd2014-02-11 19:50:571334 should_flatten_transform_ = flatten;
1335 NoteLayerPropertyChangedForSubtree();
1336}
1337
[email protected]a9d4d4f2014-06-19 06:49:281338void LayerImpl::Set3dSortingContextId(int id) {
1339 if (id == sorting_context_id_)
[email protected]56fffdd2014-02-11 19:50:571340 return;
[email protected]a9d4d4f2014-06-19 06:49:281341 sorting_context_id_ = id;
[email protected]7aba6662013-03-12 10:17:341342 NoteLayerPropertyChangedForSubtree();
1343}
1344
vmpstr3a24da5042015-05-27 03:33:311345void LayerImpl::SetFrameTimingRequests(
1346 const std::vector<FrameTimingRequest>& requests) {
1347 frame_timing_requests_ = requests;
vmpstr3d1d72c2015-01-26 18:27:401348 frame_timing_requests_dirty_ = true;
1349 SetNeedsPushProperties();
1350}
1351
vmpstrd704c872015-04-03 20:29:511352void LayerImpl::GatherFrameTimingRequestIds(std::vector<int64_t>* request_ids) {
1353 for (const auto& request : frame_timing_requests_)
1354 request_ids->push_back(request.id());
1355}
1356
[email protected]7aba6662013-03-12 10:17:341357void LayerImpl::SetTransform(const gfx::Transform& transform) {
1358 if (transform_ == transform)
1359 return;
1360
1361 transform_ = transform;
[email protected]08bdf1b2014-04-16 23:23:291362 transform_is_invertible_ = transform_.IsInvertible();
1363 NoteLayerPropertyChangedForSubtree();
1364}
1365
1366void LayerImpl::SetTransformAndInvertibility(const gfx::Transform& transform,
1367 bool transform_is_invertible) {
1368 if (transform_ == transform) {
1369 DCHECK(transform_is_invertible_ == transform_is_invertible)
1370 << "Can't change invertibility if transform is unchanged";
1371 return;
1372 }
1373 transform_ = transform;
1374 transform_is_invertible_ = transform_is_invertible;
[email protected]af37ce802013-10-07 23:53:281375 NoteLayerPropertyChangedForSubtree();
[email protected]7aba6662013-03-12 10:17:341376}
1377
1378bool LayerImpl::TransformIsAnimating() const {
ajuma315a4782015-07-24 21:16:341379 LayerAnimationController::ObserverType observer_type =
1380 IsActive() ? LayerAnimationController::ObserverType::ACTIVE
1381 : LayerAnimationController::ObserverType::PENDING;
loysod71ece82015-07-03 13:48:501382 return layer_animation_controller_
ajuma315a4782015-07-24 21:16:341383 ? layer_animation_controller_->IsCurrentlyAnimatingProperty(
1384 Animation::TRANSFORM, observer_type)
loysod71ece82015-07-03 13:48:501385 : layer_tree_impl_->IsAnimatingTransformProperty(this);
1386}
1387
1388bool LayerImpl::HasPotentiallyRunningTransformAnimation() const {
ajuma315a4782015-07-24 21:16:341389 LayerAnimationController::ObserverType observer_type =
1390 IsActive() ? LayerAnimationController::ObserverType::ACTIVE
1391 : LayerAnimationController::ObserverType::PENDING;
1392 return layer_animation_controller_
1393 ? layer_animation_controller_->IsPotentiallyAnimatingProperty(
1394 Animation::TRANSFORM, observer_type)
1395 : layer_tree_impl_->HasPotentiallyRunningTransformAnimation(this);
[email protected]7aba6662013-03-12 10:17:341396}
1397
[email protected]43615872013-03-13 16:35:171398bool LayerImpl::TransformIsAnimatingOnImplOnly() const {
loysod71ece82015-07-03 13:48:501399 if (!layer_animation_controller_)
1400 return layer_tree_impl_->TransformIsAnimatingOnImplOnly(this);
1401
[email protected]43615872013-03-13 16:35:171402 Animation* transform_animation =
ericrk7c030992015-02-20 01:39:381403 layer_animation_controller_->GetAnimation(Animation::TRANSFORM);
[email protected]43615872013-03-13 16:35:171404 return transform_animation && transform_animation->is_impl_only();
1405}
1406
loysod71ece82015-07-03 13:48:501407bool LayerImpl::HasOnlyTranslationTransforms() const {
1408 if (!layer_animation_controller_)
1409 return layer_tree_impl_->HasOnlyTranslationTransforms(this);
1410
ajumadd3592c2015-08-20 15:07:291411 LayerAnimationController::ObserverType observer_type =
1412 IsActive() ? LayerAnimationController::ObserverType::ACTIVE
1413 : LayerAnimationController::ObserverType::PENDING;
1414 return layer_animation_controller_->HasOnlyTranslationTransforms(
1415 observer_type);
loysod71ece82015-07-03 13:48:501416}
1417
weiliangcc154ce22015-12-09 03:39:261418bool LayerImpl::AnimationsPreserveAxisAlignment() const {
1419 return layer_animation_controller_
1420 ? layer_animation_controller_->AnimationsPreserveAxisAlignment()
1421 : layer_tree_impl_->AnimationsPreserveAxisAlignment(this);
1422}
1423
loysod71ece82015-07-03 13:48:501424bool LayerImpl::MaximumTargetScale(float* max_scale) const {
1425 if (!layer_animation_controller_)
1426 return layer_tree_impl_->MaximumTargetScale(this, max_scale);
1427
ajumadd3592c2015-08-20 15:07:291428 LayerAnimationController::ObserverType observer_type =
1429 IsActive() ? LayerAnimationController::ObserverType::ACTIVE
1430 : LayerAnimationController::ObserverType::PENDING;
1431 return layer_animation_controller_->MaximumTargetScale(observer_type,
1432 max_scale);
loysod71ece82015-07-03 13:48:501433}
1434
1435bool LayerImpl::AnimationStartScale(float* start_scale) const {
1436 if (!layer_animation_controller_)
1437 return layer_tree_impl_->AnimationStartScale(this, start_scale);
1438
ajumadd3592c2015-08-20 15:07:291439 LayerAnimationController::ObserverType observer_type =
1440 IsActive() ? LayerAnimationController::ObserverType::ACTIVE
1441 : LayerAnimationController::ObserverType::PENDING;
1442 return layer_animation_controller_->AnimationStartScale(observer_type,
1443 start_scale);
loysod71ece82015-07-03 13:48:501444}
1445
ajumae7425272015-07-13 18:37:341446bool LayerImpl::HasAnyAnimationTargetingProperty(
1447 Animation::TargetProperty property) const {
1448 if (!layer_animation_controller_)
1449 return layer_tree_impl_->HasAnyAnimationTargetingProperty(this, property);
1450
1451 return !!layer_animation_controller_->GetAnimation(property);
1452}
1453
loysod71ece82015-07-03 13:48:501454bool LayerImpl::HasFilterAnimationThatInflatesBounds() const {
1455 if (!layer_animation_controller_)
1456 return layer_tree_impl_->HasFilterAnimationThatInflatesBounds(this);
1457
1458 return layer_animation_controller_->HasFilterAnimationThatInflatesBounds();
1459}
1460
1461bool LayerImpl::HasTransformAnimationThatInflatesBounds() const {
1462 if (!layer_animation_controller_)
1463 return layer_tree_impl_->HasTransformAnimationThatInflatesBounds(this);
1464
1465 return layer_animation_controller_->HasTransformAnimationThatInflatesBounds();
1466}
1467
1468bool LayerImpl::HasAnimationThatInflatesBounds() const {
1469 if (!layer_animation_controller_)
1470 return layer_tree_impl_->HasAnimationThatInflatesBounds(this);
1471
1472 return layer_animation_controller_->HasAnimationThatInflatesBounds();
1473}
1474
1475bool LayerImpl::FilterAnimationBoundsForBox(const gfx::BoxF& box,
1476 gfx::BoxF* bounds) const {
1477 if (!layer_animation_controller_)
1478 return layer_tree_impl_->FilterAnimationBoundsForBox(this, box, bounds);
1479
1480 return layer_animation_controller_->FilterAnimationBoundsForBox(box, bounds);
1481}
1482
1483bool LayerImpl::TransformAnimationBoundsForBox(const gfx::BoxF& box,
1484 gfx::BoxF* bounds) const {
1485 if (!layer_animation_controller_)
1486 return layer_tree_impl_->TransformAnimationBoundsForBox(this, box, bounds);
1487
1488 return layer_animation_controller_->TransformAnimationBoundsForBox(box,
1489 bounds);
1490}
1491
danakj19f0c9e2014-10-11 03:24:421492void LayerImpl::SetUpdateRect(const gfx::Rect& update_rect) {
[email protected]ad0250b2014-01-18 03:24:341493 update_rect_ = update_rect;
1494 SetNeedsPushProperties();
1495}
1496
danakjd344ab92015-08-28 19:25:511497void LayerImpl::AddDamageRect(const gfx::Rect& damage_rect) {
1498 damage_rect_.Union(damage_rect);
[email protected]cfa7fd922014-04-29 11:50:031499}
1500
aeliasd0070ba2015-01-31 13:44:491501void LayerImpl::SetCurrentScrollOffset(const gfx::ScrollOffset& scroll_offset) {
1502 DCHECK(IsActive());
1503 if (scroll_offset_->SetCurrent(scroll_offset))
danakja342d6f3b2015-09-17 22:25:481504 DidUpdateScrollOffset();
boliu7d5dbab2014-10-10 20:05:471505}
1506
aeliasd0070ba2015-01-31 13:44:491507void LayerImpl::PushScrollOffsetFromMainThread(
1508 const gfx::ScrollOffset& scroll_offset) {
1509 PushScrollOffset(&scroll_offset);
[email protected]b34c97982013-08-24 15:21:381510}
[email protected]7aba6662013-03-12 10:17:341511
danakjb5197d32015-02-03 23:39:491512void LayerImpl::PushScrollOffsetFromMainThreadAndClobberActiveValue(
1513 const gfx::ScrollOffset& scroll_offset) {
1514 scroll_offset_->set_clobber_active_value();
1515 PushScrollOffset(&scroll_offset);
1516}
1517
aeliasd0070ba2015-01-31 13:44:491518gfx::ScrollOffset LayerImpl::PullDeltaForMainThread() {
miletusd799dd22015-03-19 04:23:171519 // TODO(miletus): Remove all this temporary flooring machinery when
1520 // Blink fully supports fractional scrolls.
1521 gfx::ScrollOffset current_offset = CurrentScrollOffset();
bokan5a025bd62015-07-20 11:08:201522 gfx::ScrollOffset current_delta = IsActive()
1523 ? scroll_offset_->Delta()
1524 : scroll_offset_->PendingDelta().get();
1525 gfx::ScrollOffset floored_delta(floor(current_delta.x()),
1526 floor(current_delta.y()));
1527 gfx::ScrollOffset diff_delta = floored_delta - current_delta;
1528 gfx::ScrollOffset tmp_offset = current_offset + diff_delta;
miletusd799dd22015-03-19 04:23:171529 scroll_offset_->SetCurrent(tmp_offset);
1530 gfx::ScrollOffset delta = scroll_offset_->PullDeltaForMainThread();
1531 scroll_offset_->SetCurrent(current_offset);
1532 return delta;
aeliasd0070ba2015-01-31 13:44:491533}
[email protected]adeda572014-01-31 00:49:471534
aeliasd0070ba2015-01-31 13:44:491535gfx::ScrollOffset LayerImpl::CurrentScrollOffset() const {
1536 return scroll_offset_->Current(IsActive());
[email protected]7aba6662013-03-12 10:17:341537}
1538
[email protected]1960a712013-04-30 17:06:471539gfx::Vector2dF LayerImpl::ScrollDelta() const {
aeliasd0070ba2015-01-31 13:44:491540 if (IsActive())
1541 return gfx::Vector2dF(scroll_offset_->Delta().x(),
1542 scroll_offset_->Delta().y());
1543 else
1544 return gfx::Vector2dF(scroll_offset_->PendingDelta().get().x(),
1545 scroll_offset_->PendingDelta().get().y());
1546}
1547
1548void LayerImpl::SetScrollDelta(const gfx::Vector2dF& delta) {
1549 DCHECK(IsActive());
ajuma5e47dec2015-05-29 22:10:231550 DCHECK(scrollable() || delta.IsZero());
aeliasd0070ba2015-01-31 13:44:491551 SetCurrentScrollOffset(scroll_offset_->ActiveBase() +
1552 gfx::ScrollOffset(delta));
1553}
1554
1555gfx::ScrollOffset LayerImpl::BaseScrollOffset() const {
1556 if (IsActive())
1557 return scroll_offset_->ActiveBase();
1558 else
1559 return scroll_offset_->PendingBase();
1560}
1561
1562void LayerImpl::PushScrollOffset(const gfx::ScrollOffset* scroll_offset) {
1563 DCHECK(scroll_offset || IsActive());
1564 bool changed = false;
1565 if (scroll_offset) {
1566 DCHECK(!IsActive() || !layer_tree_impl_->FindPendingTreeLayerById(id()));
1567 changed |= scroll_offset_->PushFromMainThread(*scroll_offset);
miletusf57925d2014-10-01 19:38:131568 }
aeliasd0070ba2015-01-31 13:44:491569 if (IsActive()) {
1570 changed |= scroll_offset_->PushPendingToActive();
aeliasd0070ba2015-01-31 13:44:491571 }
1572
1573 if (changed)
danakja342d6f3b2015-09-17 22:25:481574 DidUpdateScrollOffset();
[email protected]1960a712013-04-30 17:06:471575}
1576
ajuma9db24fb2015-06-29 20:15:071577void LayerImpl::UpdatePropertyTreeScrollOffset() {
enne1eb3a922015-06-17 17:37:501578 // TODO(enne): in the future, scrolling should update the scroll tree
1579 // directly instead of going through layers.
1580 if (transform_tree_index_ != -1) {
1581 TransformTree& transform_tree =
1582 layer_tree_impl()->property_trees()->transform_tree;
1583 TransformNode* node = transform_tree.Node(transform_tree_index_);
1584 gfx::ScrollOffset current_offset = scroll_offset_->Current(IsActive());
1585 if (node->data.scroll_offset != current_offset) {
1586 node->data.scroll_offset = current_offset;
1587 node->data.needs_local_transform_update = true;
1588 transform_tree.set_needs_update(true);
1589 }
1590 }
1591}
1592
danakja342d6f3b2015-09-17 22:25:481593void LayerImpl::DidUpdateScrollOffset() {
enne04192cf92015-05-20 00:32:221594 DCHECK(scroll_offset_);
1595
aeliasa57c40d122015-10-08 00:20:091596 layer_tree_impl()->DidUpdateScrollState(id());
aeliasd0070ba2015-01-31 13:44:491597 NoteLayerPropertyChangedForSubtree();
enne04192cf92015-05-20 00:32:221598
ajuma9db24fb2015-06-29 20:15:071599 UpdatePropertyTreeScrollOffset();
enne04192cf92015-05-20 00:32:221600
vmpstre86240822015-05-11 21:10:111601 // Inform the pending twin that a property changed.
1602 if (layer_tree_impl()->IsActiveTree()) {
1603 LayerImpl* pending_twin = layer_tree_impl()->FindPendingTreeLayerById(id());
1604 if (pending_twin)
danakja342d6f3b2015-09-17 22:25:481605 pending_twin->DidUpdateScrollOffset();
vmpstre86240822015-05-11 21:10:111606 }
[email protected]ffb2720f2013-03-15 19:18:371607}
1608
[email protected]7aba6662013-03-12 10:17:341609void LayerImpl::SetDoubleSided(bool double_sided) {
1610 if (double_sided_ == double_sided)
1611 return;
1612
1613 double_sided_ = double_sided;
1614 NoteLayerPropertyChangedForSubtree();
1615}
1616
danakj64767d902015-06-19 00:10:431617SimpleEnclosedRegion LayerImpl::VisibleOpaqueRegion() const {
[email protected]7aba6662013-03-12 10:17:341618 if (contents_opaque())
danakj64767d902015-06-19 00:10:431619 return SimpleEnclosedRegion(visible_layer_rect());
[email protected]d5467eb72014-08-22 01:16:431620 return SimpleEnclosedRegion();
[email protected]7aba6662013-03-12 10:17:341621}
1622
[email protected]37349bc2013-06-04 01:31:521623void LayerImpl::DidBeginTracing() {}
1624
[email protected]9db24462014-01-14 02:25:501625void LayerImpl::ReleaseResources() {}
[email protected]7aba6662013-03-12 10:17:341626
vmpstr9ce5c662015-02-05 23:29:261627void LayerImpl::RecreateResources() {
1628}
1629
miletusf57925d2014-10-01 19:38:131630gfx::ScrollOffset LayerImpl::MaxScrollOffset() const {
aeliasa57c40d122015-10-08 00:20:091631 LayerImpl* scroll_clip_layer =
1632 layer_tree_impl()->LayerById(scroll_clip_layer_id_);
1633 if (!scroll_clip_layer || bounds().IsEmpty())
miletusf57925d2014-10-01 19:38:131634 return gfx::ScrollOffset();
[email protected]610834cb2014-01-29 13:54:331635
aeliasc26b50b72015-07-14 20:18:251636 LayerImpl const* page_scale_layer = layer_tree_impl()->PageScaleLayer();
[email protected]adeda572014-01-31 00:49:471637 DCHECK(this != page_scale_layer);
[email protected]adeda572014-01-31 00:49:471638 DCHECK(this != layer_tree_impl()->InnerViewportScrollLayer() ||
1639 IsContainerForFixedPositionLayers());
1640
[email protected]adeda572014-01-31 00:49:471641 float scale_factor = 1.f;
sunxd676696572016-01-07 16:28:301642 DCHECK(scroll_clip_layer != page_scale_layer);
1643 if (!scroll_clip_layer->IsAffectedByPageScale() && IsAffectedByPageScale())
1644 scale_factor = layer_tree_impl()->current_page_scale_factor();
[email protected]adeda572014-01-31 00:49:471645
aeliasd0070ba2015-01-31 13:44:491646 gfx::SizeF scaled_scroll_bounds =
danakjddaec912015-09-25 19:38:401647 gfx::ScaleSize(BoundsForScrolling(), scale_factor);
1648 scaled_scroll_bounds.SetSize(std::floor(scaled_scroll_bounds.width()),
1649 std::floor(scaled_scroll_bounds.height()));
[email protected]adeda572014-01-31 00:49:471650
miletusf57925d2014-10-01 19:38:131651 gfx::ScrollOffset max_offset(
aeliasa57c40d122015-10-08 00:20:091652 scaled_scroll_bounds.width() - scroll_clip_layer->bounds().width(),
1653 scaled_scroll_bounds.height() - scroll_clip_layer->bounds().height());
[email protected]adeda572014-01-31 00:49:471654 // We need the final scroll offset to be in CSS coords.
1655 max_offset.Scale(1 / scale_factor);
miletusf57925d2014-10-01 19:38:131656 max_offset.SetToMax(gfx::ScrollOffset());
1657 return max_offset;
[email protected]adeda572014-01-31 00:49:471658}
1659
aeliasd0070ba2015-01-31 13:44:491660gfx::ScrollOffset LayerImpl::ClampScrollOffsetToLimits(
1661 gfx::ScrollOffset offset) const {
1662 offset.SetToMin(MaxScrollOffset());
1663 offset.SetToMax(gfx::ScrollOffset());
1664 return offset;
1665}
[email protected]adeda572014-01-31 00:49:471666
aeliasd0070ba2015-01-31 13:44:491667gfx::Vector2dF LayerImpl::ClampScrollToMaxScrollOffset() {
1668 gfx::ScrollOffset old_offset = CurrentScrollOffset();
1669 gfx::ScrollOffset clamped_offset = ClampScrollOffsetToLimits(old_offset);
miletusf57925d2014-10-01 19:38:131670 gfx::Vector2dF delta = clamped_offset.DeltaFrom(old_offset);
[email protected]adeda572014-01-31 00:49:471671 if (!delta.IsZero())
1672 ScrollBy(delta);
[email protected]adeda572014-01-31 00:49:471673 return delta;
1674}
1675
[email protected]ad0250b2014-01-18 03:24:341676void LayerImpl::SetNeedsPushProperties() {
1677 if (needs_push_properties_)
1678 return;
1679 if (!parent_should_know_need_push_properties() && parent_)
1680 parent_->AddDependentNeedsPushProperties();
1681 needs_push_properties_ = true;
1682}
1683
1684void LayerImpl::AddDependentNeedsPushProperties() {
1685 DCHECK_GE(num_dependents_need_push_properties_, 0);
1686
1687 if (!parent_should_know_need_push_properties() && parent_)
1688 parent_->AddDependentNeedsPushProperties();
1689
1690 num_dependents_need_push_properties_++;
1691}
1692
1693void LayerImpl::RemoveDependentNeedsPushProperties() {
1694 num_dependents_need_push_properties_--;
1695 DCHECK_GE(num_dependents_need_push_properties_, 0);
1696
1697 if (!parent_should_know_need_push_properties() && parent_)
1698 parent_->RemoveDependentNeedsPushProperties();
1699}
1700
hendrikwc5e915852015-05-13 01:29:031701void LayerImpl::GetAllPrioritizedTilesForTracing(
1702 std::vector<PrioritizedTile>* prioritized_tiles) const {
vmpstrd7de03c2014-08-27 18:11:011703}
1704
ssid911e40e2015-02-09 17:55:201705void LayerImpl::AsValueInto(base::trace_event::TracedValue* state) const {
[email protected]f5ad4282014-02-15 14:23:161706 TracedValue::MakeDictIntoImplicitSnapshotWithCategory(
1707 TRACE_DISABLED_BY_DEFAULT("cc.debug"),
[email protected]b4dc36472014-02-26 02:48:251708 state,
1709 "cc::LayerImpl",
1710 LayerTypeAsString(),
1711 this);
[email protected]f6742f52013-05-08 23:52:221712 state->SetInteger("layer_id", id());
jungjik.lee50f9c8e2015-01-21 14:06:161713 MathUtil::AddToTracedValue("bounds", bounds_, state);
[email protected]d12aa932014-08-01 13:10:381714
danakj38955562014-09-13 02:56:431715 state->SetDouble("opacity", opacity());
1716
jungjik.lee50f9c8e2015-01-21 14:06:161717 MathUtil::AddToTracedValue("position", position_, state);
[email protected]d12aa932014-08-01 13:10:381718
[email protected]f6742f52013-05-08 23:52:221719 state->SetInteger("draws_content", DrawsContent());
vmpstr91e23092015-06-08 22:24:161720 state->SetInteger("gpu_memory_usage",
1721 base::saturated_cast<int>(GPUMemoryUsageInBytes()));
[email protected]d12aa932014-08-01 13:10:381722
vollickfd6e4f4a2016-01-22 19:13:291723 if (mutable_properties_ != MutableProperty::kNone) {
vollick933f496e2015-12-08 04:22:051724 state->SetInteger("element_id", base::saturated_cast<int>(element_id_));
1725 state->SetInteger("mutable_properties", mutable_properties_);
1726 }
1727
aeliasd0070ba2015-01-31 13:44:491728 MathUtil::AddToTracedValue(
1729 "scroll_offset", scroll_offset_ ? scroll_offset_->Current(IsActive())
1730 : gfx::ScrollOffset(),
1731 state);
1732
jungjik.lee50f9c8e2015-01-21 14:06:161733 MathUtil::AddToTracedValue("transform_origin", transform_origin_, state);
[email protected]8c5690222013-02-15 17:36:431734
[email protected]7aba6662013-03-12 10:17:341735 bool clipped;
danakj5e6ff6d2015-09-05 04:43:441736 gfx::QuadF layer_quad =
ajumab6aa1c62015-12-01 21:01:101737 MathUtil::MapQuad(ScreenSpaceTransform(),
danakj5e6ff6d2015-09-05 04:43:441738 gfx::QuadF(gfx::RectF(gfx::Rect(bounds()))), &clipped);
jungjik.lee50f9c8e2015-01-21 14:06:161739 MathUtil::AddToTracedValue("layer_quad", layer_quad, state);
[email protected]78d78612013-09-12 18:04:041740 if (!touch_event_handler_region_.IsEmpty()) {
[email protected]d12aa932014-08-01 13:10:381741 state->BeginArray("touch_event_handler_region");
1742 touch_event_handler_region_.AsValueInto(state);
1743 state->EndArray();
[email protected]78d78612013-09-12 18:04:041744 }
1745 if (have_wheel_event_handlers_) {
Dana Jansensc46d3742015-06-18 01:33:141746 gfx::Rect wheel_rect(bounds());
[email protected]78d78612013-09-12 18:04:041747 Region wheel_region(wheel_rect);
[email protected]d12aa932014-08-01 13:10:381748 state->BeginArray("wheel_event_handler_region");
1749 wheel_region.AsValueInto(state);
1750 state->EndArray();
[email protected]78d78612013-09-12 18:04:041751 }
[email protected]f998c532014-03-31 20:02:511752 if (have_scroll_event_handlers_) {
Dana Jansensc46d3742015-06-18 01:33:141753 gfx::Rect scroll_rect(bounds());
[email protected]f998c532014-03-31 20:02:511754 Region scroll_region(scroll_rect);
[email protected]d12aa932014-08-01 13:10:381755 state->BeginArray("scroll_event_handler_region");
1756 scroll_region.AsValueInto(state);
1757 state->EndArray();
[email protected]f998c532014-03-31 20:02:511758 }
[email protected]78d78612013-09-12 18:04:041759 if (!non_fast_scrollable_region_.IsEmpty()) {
[email protected]d12aa932014-08-01 13:10:381760 state->BeginArray("non_fast_scrollable_region");
1761 non_fast_scrollable_region_.AsValueInto(state);
1762 state->EndArray();
[email protected]78d78612013-09-12 18:04:041763 }
rbyers18779d822015-02-05 06:22:061764 if (scroll_blocks_on_) {
1765 state->SetInteger("scroll_blocks_on", scroll_blocks_on_);
1766 }
[email protected]f6742f52013-05-08 23:52:221767
[email protected]d12aa932014-08-01 13:10:381768 state->BeginArray("children");
1769 for (size_t i = 0; i < children_.size(); ++i) {
1770 state->BeginDictionary();
1771 children_[i]->AsValueInto(state);
1772 state->EndDictionary();
1773 }
1774 state->EndArray();
1775 if (mask_layer_) {
1776 state->BeginDictionary("mask_layer");
1777 mask_layer_->AsValueInto(state);
1778 state->EndDictionary();
1779 }
1780 if (replica_layer_) {
1781 state->BeginDictionary("replica_layer");
1782 replica_layer_->AsValueInto(state);
1783 state->EndDictionary();
1784 }
[email protected]0e98cdd2013-08-23 00:44:301785
1786 if (scroll_parent_)
1787 state->SetInteger("scroll_parent", scroll_parent_->id());
1788
1789 if (clip_parent_)
1790 state->SetInteger("clip_parent", clip_parent_->id());
[email protected]c2a56ff2013-10-14 19:32:511791
1792 state->SetBoolean("can_use_lcd_text", can_use_lcd_text());
1793 state->SetBoolean("contents_opaque", contents_opaque());
[email protected]a1286742013-11-13 17:11:401794
[email protected]3d86dd7a2014-01-24 01:33:111795 state->SetBoolean(
1796 "has_animation_bounds",
loysod71ece82015-07-03 13:48:501797 layer_animation_controller_
1798 ? layer_animation_controller_->HasAnimationThatInflatesBounds()
1799 : layer_tree_impl_->HasAnimationThatInflatesBounds(this));
[email protected]3d86dd7a2014-01-24 01:33:111800
1801 gfx::BoxF box;
jungjik.lee50f9c8e2015-01-21 14:06:161802 if (LayerUtils::GetAnimationBounds(*this, &box))
1803 MathUtil::AddToTracedValue("animation_bounds", box, state);
[email protected]9f3be432013-12-03 03:53:221804
1805 if (debug_info_.get()) {
1806 std::string str;
1807 debug_info_->AppendAsTraceFormat(&str);
1808 base::JSONReader json_reader;
[email protected]685de6b12014-01-09 12:25:051809 scoped_ptr<base::Value> debug_info_value(json_reader.ReadToValue(str));
1810
[email protected]478224312014-01-10 17:33:471811 if (debug_info_value->IsType(base::Value::TYPE_DICTIONARY)) {
kulkarni.a4015690f12014-10-10 13:50:061812 base::DictionaryValue* dictionary_value = nullptr;
[email protected]685de6b12014-01-09 12:25:051813 bool converted_to_dictionary =
1814 debug_info_value->GetAsDictionary(&dictionary_value);
1815 DCHECK(converted_to_dictionary);
[email protected]d12aa932014-08-01 13:10:381816 for (base::DictionaryValue::Iterator it(*dictionary_value); !it.IsAtEnd();
1817 it.Advance()) {
estade7bc801fb2015-05-07 01:53:081818 state->SetValue(it.key().data(), it.value().CreateDeepCopy());
[email protected]d12aa932014-08-01 13:10:381819 }
[email protected]685de6b12014-01-09 12:25:051820 } else {
1821 NOTREACHED();
1822 }
[email protected]9f3be432013-12-03 03:53:221823 }
vmpstr3d1d72c2015-01-26 18:27:401824
1825 if (!frame_timing_requests_.empty()) {
1826 state->BeginArray("frame_timing_requests");
1827 for (const auto& request : frame_timing_requests_) {
1828 state->BeginDictionary();
1829 state->SetInteger("request_id", request.id());
1830 MathUtil::AddToTracedValue("request_rect", request.rect(), state);
1831 state->EndDictionary();
1832 }
1833 state->EndArray();
1834 }
[email protected]8c5690222013-02-15 17:36:431835}
1836
[email protected]390bb1ff2014-05-09 17:14:401837bool LayerImpl::IsDrawnRenderSurfaceLayerListMember() const {
1838 return draw_properties_.last_drawn_render_surface_layer_list_id ==
1839 layer_tree_impl_->current_render_surface_list_id();
1840}
1841
[email protected]cdf5b952013-05-15 15:39:291842size_t LayerImpl::GPUMemoryUsageInBytes() const { return 0; }
1843
[email protected]5e5648a2013-11-18 00:39:331844void LayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) {
1845 benchmark->RunOnLayer(this);
1846}
[email protected]749cbc62014-07-10 01:06:351847
[email protected]ad63b2f2014-08-11 17:39:541848int LayerImpl::NumDescendantsThatDrawContent() const {
1849 return num_descendants_that_draw_content_;
1850}
1851
[email protected]749cbc62014-07-10 01:06:351852void LayerImpl::NotifyAnimationFinished(
1853 base::TimeTicks monotonic_time,
dstockwellaf2a117b2014-10-16 21:42:291854 Animation::TargetProperty target_property,
1855 int group) {
ericrk7c030992015-02-20 01:39:381856 if (target_property == Animation::SCROLL_OFFSET)
[email protected]749cbc62014-07-10 01:06:351857 layer_tree_impl_->InputScrollAnimationFinished();
1858}
1859
awoloszyne83f28c2014-12-22 15:40:001860void LayerImpl::SetHasRenderSurface(bool should_have_render_surface) {
1861 if (!!render_surface() == should_have_render_surface)
1862 return;
1863
1864 SetNeedsPushProperties();
awoloszyne83f28c2014-12-22 15:40:001865 if (should_have_render_surface) {
1866 render_surface_ = make_scoped_ptr(new RenderSurfaceImpl(this));
1867 return;
1868 }
1869 render_surface_.reset();
1870}
1871
ajumad9432e32015-11-30 19:43:441872gfx::Transform LayerImpl::DrawTransform() const {
1873 // Only drawn layers have up-to-date draw properties when property trees are
1874 // enabled.
1875 if (layer_tree_impl()->settings().use_property_trees &&
1876 !IsDrawnRenderSurfaceLayerListMember()) {
1877 if (layer_tree_impl()->property_trees()->non_root_surfaces_enabled) {
1878 return DrawTransformFromPropertyTrees(
1879 this, layer_tree_impl()->property_trees()->transform_tree);
1880 } else {
1881 return ScreenSpaceTransformFromPropertyTrees(
1882 this, layer_tree_impl()->property_trees()->transform_tree);
1883 }
1884 }
1885
1886 return draw_properties().target_space_transform;
1887}
1888
ajumab6aa1c62015-12-01 21:01:101889gfx::Transform LayerImpl::ScreenSpaceTransform() const {
1890 // Only drawn layers have up-to-date draw properties when property trees are
1891 // enabled.
1892 if (layer_tree_impl()->settings().use_property_trees &&
1893 !IsDrawnRenderSurfaceLayerListMember()) {
1894 return ScreenSpaceTransformFromPropertyTrees(
1895 this, layer_tree_impl()->property_trees()->transform_tree);
1896 }
1897
1898 return draw_properties().screen_space_transform;
1899}
1900
weiliangcc154ce22015-12-09 03:39:261901void LayerImpl::SetForceRenderSurface(bool force_render_surface) {
1902 if (force_render_surface == force_render_surface_)
1903 return;
1904
1905 force_render_surface_ = force_render_surface;
1906 NoteLayerPropertyChanged();
1907}
1908
daplatz350219e2015-03-04 19:04:411909Region LayerImpl::GetInvalidationRegion() {
1910 return Region(update_rect_);
1911}
1912
vmpstrd46a7ac2015-03-18 01:11:121913gfx::Rect LayerImpl::GetEnclosingRectInTargetSpace() const {
ajumad9432e32015-11-30 19:43:441914 return MathUtil::MapEnclosingClippedRect(DrawTransform(),
1915 gfx::Rect(bounds()));
vmpstrd46a7ac2015-03-18 01:11:121916}
1917
1918gfx::Rect LayerImpl::GetScaledEnclosingRectInTargetSpace(float scale) const {
ajumad9432e32015-11-30 19:43:441919 gfx::Transform scaled_draw_transform = DrawTransform();
vmpstrd46a7ac2015-03-18 01:11:121920 scaled_draw_transform.Scale(SK_MScalar1 / scale, SK_MScalar1 / scale);
danakjddaec912015-09-25 19:38:401921 gfx::Size scaled_bounds = gfx::ScaleToCeiledSize(bounds(), scale);
vmpstrd46a7ac2015-03-18 01:11:121922 return MathUtil::MapEnclosingClippedRect(scaled_draw_transform,
Dana Jansensc46d3742015-06-18 01:33:141923 gfx::Rect(scaled_bounds));
vmpstrd46a7ac2015-03-18 01:11:121924}
1925
jaydasikab5504ca2015-12-18 23:41:551926bool LayerImpl::LayerIsHidden() const {
1927 if (layer_tree_impl()->settings().use_property_trees) {
1928 return is_hidden_from_property_trees_;
1929 } else {
1930 return hide_layer_and_subtree_ || (parent() && parent()->LayerIsHidden());
1931 }
1932}
1933
enne637715732015-07-07 02:05:261934float LayerImpl::GetIdealContentsScale() const {
1935 float page_scale = IsAffectedByPageScale()
1936 ? layer_tree_impl()->current_page_scale_factor()
1937 : 1.f;
1938 float device_scale = layer_tree_impl()->device_scale_factor();
1939
1940 float default_scale = page_scale * device_scale;
1941 if (!layer_tree_impl()
1942 ->settings()
1943 .layer_transforms_should_scale_layer_contents) {
1944 return default_scale;
1945 }
1946
enne637715732015-07-07 02:05:261947 gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents(
ajumad9432e32015-11-30 19:43:441948 DrawTransform(), default_scale);
enne637715732015-07-07 02:05:261949 return std::max(transform_scales.x(), transform_scales.y());
1950}
1951
[email protected]bc5e77c2012-11-05 20:00:491952} // namespace cc