blob: 0353a787a3bbcb5ad75f93bcfb800cf23efad9ca [file] [log] [blame]
James Robinson646469d2014-10-03 15:33:28 -07001// Copyright 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "cc/layers/layer_impl.h"
6
James Robinson646469d2014-10-03 15:33:28 -07007#include "base/json/json_reader.h"
8#include "base/strings/stringprintf.h"
Benjamin Lermancdfc88d2015-02-03 14:35:12 +01009#include "base/trace_event/trace_event.h"
10#include "base/trace_event/trace_event_argument.h"
James Robinson646469d2014-10-03 15:33:28 -070011#include "cc/animation/animation_registrar.h"
12#include "cc/animation/scrollbar_animation_controller.h"
13#include "cc/base/math_util.h"
14#include "cc/base/simple_enclosed_region.h"
15#include "cc/debug/debug_colors.h"
16#include "cc/debug/layer_tree_debug_state.h"
17#include "cc/debug/micro_benchmark_impl.h"
18#include "cc/debug/traced_value.h"
19#include "cc/input/layer_scroll_offset_delegate.h"
20#include "cc/layers/layer_utils.h"
21#include "cc/layers/painted_scrollbar_layer_impl.h"
22#include "cc/output/copy_output_request.h"
23#include "cc/quads/debug_border_draw_quad.h"
24#include "cc/quads/render_pass.h"
25#include "cc/trees/layer_tree_host_common.h"
26#include "cc/trees/layer_tree_impl.h"
27#include "cc/trees/layer_tree_settings.h"
28#include "cc/trees/proxy.h"
James Robinson30d547e2014-10-23 18:20:06 -070029#include "ui/gfx/geometry/box_f.h"
30#include "ui/gfx/geometry/point_conversions.h"
31#include "ui/gfx/geometry/quad_f.h"
32#include "ui/gfx/geometry/rect_conversions.h"
33#include "ui/gfx/geometry/size_conversions.h"
James Robinson646469d2014-10-03 15:33:28 -070034#include "ui/gfx/geometry/vector2d_conversions.h"
James Robinson646469d2014-10-03 15:33:28 -070035
36namespace cc {
Benjamin Lermancdfc88d2015-02-03 14:35:12 +010037LayerImpl::LayerImpl(LayerTreeImpl* layer_impl, int id)
38 : LayerImpl(layer_impl, id, new LayerImpl::SyncedScrollOffset) {
39}
40
41LayerImpl::LayerImpl(LayerTreeImpl* tree_impl,
42 int id,
43 scoped_refptr<SyncedScrollOffset> scroll_offset)
James Robinsone2ac7e82014-10-15 13:21:59 -070044 : parent_(nullptr),
45 scroll_parent_(nullptr),
46 clip_parent_(nullptr),
James Robinson646469d2014-10-03 15:33:28 -070047 mask_layer_id_(-1),
48 replica_layer_id_(-1),
49 layer_id_(id),
50 layer_tree_impl_(tree_impl),
Benjamin Lermancdfc88d2015-02-03 14:35:12 +010051 scroll_offset_(scroll_offset),
James Robinsone2ac7e82014-10-15 13:21:59 -070052 scroll_offset_delegate_(nullptr),
53 scroll_clip_layer_(nullptr),
James Robinson646469d2014-10-03 15:33:28 -070054 should_scroll_on_main_thread_(false),
55 have_wheel_event_handlers_(false),
56 have_scroll_event_handlers_(false),
Benjamin Lermane8ca9b72015-02-24 16:42:13 +010057 scroll_blocks_on_(SCROLL_BLOCKS_ON_NONE),
James Robinson646469d2014-10-03 15:33:28 -070058 user_scrollable_horizontal_(true),
59 user_scrollable_vertical_(true),
60 stacking_order_changed_(false),
61 double_sided_(true),
62 should_flatten_transform_(true),
63 layer_property_changed_(false),
64 masks_to_bounds_(false),
65 contents_opaque_(false),
66 is_root_for_isolated_group_(false),
67 use_parent_backface_visibility_(false),
68 draw_checkerboard_for_missing_tiles_(false),
69 draws_content_(false),
70 hide_layer_and_subtree_(false),
James Robinson646469d2014-10-03 15:33:28 -070071 transform_is_invertible_(true),
72 is_container_for_fixed_position_layers_(false),
73 background_color_(0),
74 opacity_(1.0),
75 blend_mode_(SkXfermode::kSrcOver_Mode),
76 num_descendants_that_draw_content_(0),
77 draw_depth_(0.f),
78 needs_push_properties_(false),
79 num_dependents_need_push_properties_(0),
80 sorting_context_id_(0),
Elliot Glayshereae49292015-01-28 10:47:32 -080081 current_draw_mode_(DRAW_MODE_NONE),
82 frame_timing_requests_dirty_(false) {
James Robinson646469d2014-10-03 15:33:28 -070083 DCHECK_GT(layer_id_, 0);
84 DCHECK(layer_tree_impl_);
85 layer_tree_impl_->RegisterLayer(this);
Benjamin Lerman507bb1a2015-02-26 13:15:17 +010086 AnimationRegistrar* registrar = layer_tree_impl_->GetAnimationRegistrar();
James Robinson646469d2014-10-03 15:33:28 -070087 layer_animation_controller_ =
88 registrar->GetAnimationControllerForId(layer_id_);
89 layer_animation_controller_->AddValueObserver(this);
90 if (IsActive()) {
91 layer_animation_controller_->set_value_provider(this);
92 layer_animation_controller_->set_layer_animation_delegate(this);
93 }
94 SetNeedsPushProperties();
95}
96
97LayerImpl::~LayerImpl() {
98 DCHECK_EQ(DRAW_MODE_NONE, current_draw_mode_);
99
100 layer_animation_controller_->RemoveValueObserver(this);
101 layer_animation_controller_->remove_value_provider(this);
102 layer_animation_controller_->remove_layer_animation_delegate(this);
103
104 if (!copy_requests_.empty() && layer_tree_impl_->IsActiveTree())
105 layer_tree_impl()->RemoveLayerWithCopyOutputRequest(this);
106 layer_tree_impl_->UnregisterLayer(this);
107
108 TRACE_EVENT_OBJECT_DELETED_WITH_ID(
109 TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerImpl", this);
110}
111
112void LayerImpl::AddChild(scoped_ptr<LayerImpl> child) {
113 child->SetParent(this);
114 DCHECK_EQ(layer_tree_impl(), child->layer_tree_impl());
115 children_.push_back(child.Pass());
116 layer_tree_impl()->set_needs_update_draw_properties();
117}
118
119scoped_ptr<LayerImpl> LayerImpl::RemoveChild(LayerImpl* child) {
120 for (OwnedLayerImplList::iterator it = children_.begin();
121 it != children_.end();
122 ++it) {
123 if (*it == child) {
124 scoped_ptr<LayerImpl> ret = children_.take(it);
125 children_.erase(it);
126 layer_tree_impl()->set_needs_update_draw_properties();
127 return ret.Pass();
128 }
129 }
130 return nullptr;
131}
132
133void LayerImpl::SetParent(LayerImpl* parent) {
134 if (parent_should_know_need_push_properties()) {
135 if (parent_)
136 parent_->RemoveDependentNeedsPushProperties();
137 if (parent)
138 parent->AddDependentNeedsPushProperties();
139 }
140 parent_ = parent;
141}
142
143void LayerImpl::ClearChildList() {
144 if (children_.empty())
145 return;
146
147 children_.clear();
148 layer_tree_impl()->set_needs_update_draw_properties();
149}
150
151bool LayerImpl::HasAncestor(const LayerImpl* ancestor) const {
152 if (!ancestor)
153 return false;
154
155 for (const LayerImpl* layer = this; layer; layer = layer->parent()) {
156 if (layer == ancestor)
157 return true;
158 }
159
160 return false;
161}
162
163void LayerImpl::SetScrollParent(LayerImpl* parent) {
164 if (scroll_parent_ == parent)
165 return;
166
167 // Having both a scroll parent and a scroll offset delegate is unsupported.
168 DCHECK(!scroll_offset_delegate_);
169
170 if (parent)
171 DCHECK_EQ(layer_tree_impl()->LayerById(parent->id()), parent);
172
173 scroll_parent_ = parent;
174 SetNeedsPushProperties();
175}
176
177void LayerImpl::SetDebugInfo(
Etienne Membrives386015a2015-02-19 17:27:12 +0100178 scoped_refptr<base::trace_event::ConvertableToTraceFormat> other) {
James Robinson646469d2014-10-03 15:33:28 -0700179 debug_info_ = other;
180 SetNeedsPushProperties();
181}
182
183void LayerImpl::SetScrollChildren(std::set<LayerImpl*>* children) {
184 if (scroll_children_.get() == children)
185 return;
186 scroll_children_.reset(children);
187 SetNeedsPushProperties();
188}
189
190void LayerImpl::SetNumDescendantsThatDrawContent(int num_descendants) {
191 if (num_descendants_that_draw_content_ == num_descendants)
192 return;
193 num_descendants_that_draw_content_ = num_descendants;
194 SetNeedsPushProperties();
195}
196
197void LayerImpl::SetClipParent(LayerImpl* ancestor) {
198 if (clip_parent_ == ancestor)
199 return;
200
201 clip_parent_ = ancestor;
202 SetNeedsPushProperties();
203}
204
205void LayerImpl::SetClipChildren(std::set<LayerImpl*>* children) {
206 if (clip_children_.get() == children)
207 return;
208 clip_children_.reset(children);
209 SetNeedsPushProperties();
210}
211
212void LayerImpl::PassCopyRequests(ScopedPtrVector<CopyOutputRequest>* requests) {
213 if (requests->empty())
214 return;
James Robinson9127e722014-12-29 14:41:55 -0800215 DCHECK(render_surface());
James Robinson646469d2014-10-03 15:33:28 -0700216 bool was_empty = copy_requests_.empty();
217 copy_requests_.insert_and_take(copy_requests_.end(), requests);
218 requests->clear();
219
220 if (was_empty && layer_tree_impl()->IsActiveTree())
221 layer_tree_impl()->AddLayerWithCopyOutputRequest(this);
222 NoteLayerPropertyChangedForSubtree();
223}
224
225void LayerImpl::TakeCopyRequestsAndTransformToTarget(
226 ScopedPtrVector<CopyOutputRequest>* requests) {
227 DCHECK(!copy_requests_.empty());
228 DCHECK(layer_tree_impl()->IsActiveTree());
James Robinson9127e722014-12-29 14:41:55 -0800229 DCHECK_EQ(render_target(), this);
James Robinson646469d2014-10-03 15:33:28 -0700230
231 size_t first_inserted_request = requests->size();
232 requests->insert_and_take(requests->end(), &copy_requests_);
233 copy_requests_.clear();
234
235 for (size_t i = first_inserted_request; i < requests->size(); ++i) {
236 CopyOutputRequest* request = requests->at(i);
237 if (!request->has_area())
238 continue;
239
240 gfx::Rect request_in_layer_space = request->area();
241 gfx::Rect request_in_content_space =
242 LayerRectToContentRect(request_in_layer_space);
243 request->set_area(MathUtil::MapEnclosingClippedRect(
244 draw_properties_.target_space_transform, request_in_content_space));
245 }
246
247 layer_tree_impl()->RemoveLayerWithCopyOutputRequest(this);
Benjamin Lermancdfc88d2015-02-03 14:35:12 +0100248 layer_tree_impl()->set_needs_update_draw_properties();
James Robinson646469d2014-10-03 15:33:28 -0700249}
250
James Robinson646469d2014-10-03 15:33:28 -0700251void LayerImpl::ClearRenderSurfaceLayerList() {
James Robinson9127e722014-12-29 14:41:55 -0800252 if (render_surface_)
253 render_surface_->ClearLayerLists();
James Robinson646469d2014-10-03 15:33:28 -0700254}
255
256void LayerImpl::PopulateSharedQuadState(SharedQuadState* state) const {
James Robinson6e9a1c92014-11-13 17:05:42 -0800257 state->SetAll(
258 draw_properties_.target_space_transform, draw_properties_.content_bounds,
259 draw_properties_.visible_content_rect, draw_properties_.clip_rect,
260 draw_properties_.is_clipped, draw_properties_.opacity,
261 draw_properties_.blend_mode, sorting_context_id_);
James Robinson646469d2014-10-03 15:33:28 -0700262}
263
Etienne Membrives386015a2015-02-19 17:27:12 +0100264void LayerImpl::PopulateScaledSharedQuadState(SharedQuadState* state,
265 float scale) const {
266 gfx::Transform scaled_draw_transform =
267 draw_properties_.target_space_transform;
268 scaled_draw_transform.Scale(SK_MScalar1 / scale, SK_MScalar1 / scale);
269 gfx::Size scaled_content_bounds =
270 gfx::ToCeiledSize(gfx::ScaleSize(bounds(), scale));
271 gfx::Rect scaled_visible_content_rect =
272 gfx::ScaleToEnclosingRect(visible_content_rect(), scale);
273 scaled_visible_content_rect.Intersect(gfx::Rect(scaled_content_bounds));
274
275 state->SetAll(scaled_draw_transform, scaled_content_bounds,
276 scaled_visible_content_rect, draw_properties().clip_rect,
277 draw_properties().is_clipped, draw_properties().opacity,
278 draw_properties().blend_mode, sorting_context_id_);
279}
280
James Robinson646469d2014-10-03 15:33:28 -0700281bool LayerImpl::WillDraw(DrawMode draw_mode,
282 ResourceProvider* resource_provider) {
283 // WillDraw/DidDraw must be matched.
284 DCHECK_NE(DRAW_MODE_NONE, draw_mode);
285 DCHECK_EQ(DRAW_MODE_NONE, current_draw_mode_);
286 current_draw_mode_ = draw_mode;
287 return true;
288}
289
290void LayerImpl::DidDraw(ResourceProvider* resource_provider) {
291 DCHECK_NE(DRAW_MODE_NONE, current_draw_mode_);
292 current_draw_mode_ = DRAW_MODE_NONE;
293}
294
295bool LayerImpl::ShowDebugBorders() const {
296 return layer_tree_impl()->debug_state().show_debug_borders;
297}
298
299void LayerImpl::GetDebugBorderProperties(SkColor* color, float* width) const {
300 if (draws_content_) {
301 *color = DebugColors::ContentLayerBorderColor();
302 *width = DebugColors::ContentLayerBorderWidth(layer_tree_impl());
303 return;
304 }
305
306 if (masks_to_bounds_) {
307 *color = DebugColors::MaskingLayerBorderColor();
308 *width = DebugColors::MaskingLayerBorderWidth(layer_tree_impl());
309 return;
310 }
311
312 *color = DebugColors::ContainerLayerBorderColor();
313 *width = DebugColors::ContainerLayerBorderWidth(layer_tree_impl());
314}
315
316void LayerImpl::AppendDebugBorderQuad(
317 RenderPass* render_pass,
318 const gfx::Size& content_bounds,
319 const SharedQuadState* shared_quad_state,
320 AppendQuadsData* append_quads_data) const {
321 SkColor color;
322 float width;
323 GetDebugBorderProperties(&color, &width);
324 AppendDebugBorderQuad(render_pass,
325 content_bounds,
326 shared_quad_state,
327 append_quads_data,
328 color,
329 width);
330}
331
332void LayerImpl::AppendDebugBorderQuad(RenderPass* render_pass,
333 const gfx::Size& content_bounds,
334 const SharedQuadState* shared_quad_state,
335 AppendQuadsData* append_quads_data,
336 SkColor color,
337 float width) const {
338 if (!ShowDebugBorders())
339 return;
340
341 gfx::Rect quad_rect(content_bounds);
342 gfx::Rect visible_quad_rect(quad_rect);
343 DebugBorderDrawQuad* debug_border_quad =
344 render_pass->CreateAndAppendDrawQuad<DebugBorderDrawQuad>();
345 debug_border_quad->SetNew(
346 shared_quad_state, quad_rect, visible_quad_rect, color, width);
Etienne Membrives386015a2015-02-19 17:27:12 +0100347 if (contents_opaque()) {
348 // When opaque, draw a second inner border that is thicker than the outer
349 // border, but more transparent.
350 static const float kFillOpacity = 0.3f;
351 SkColor fill_color = SkColorSetA(
352 color, static_cast<uint8_t>(SkColorGetA(color) * kFillOpacity));
353 float fill_width = width * 3;
354 gfx::Rect fill_rect = quad_rect;
355 fill_rect.Inset(fill_width / 2.f, fill_width / 2.f);
356 gfx::Rect visible_fill_rect =
357 gfx::IntersectRects(visible_quad_rect, fill_rect);
358 DebugBorderDrawQuad* fill_quad =
359 render_pass->CreateAndAppendDrawQuad<DebugBorderDrawQuad>();
360 fill_quad->SetNew(shared_quad_state, fill_rect, visible_fill_rect,
361 fill_color, fill_width);
362 }
James Robinson646469d2014-10-03 15:33:28 -0700363}
364
365bool LayerImpl::HasDelegatedContent() const {
366 return false;
367}
368
369bool LayerImpl::HasContributingDelegatedRenderPasses() const {
370 return false;
371}
372
373RenderPassId LayerImpl::FirstContributingRenderPassId() const {
374 return RenderPassId(0, 0);
375}
376
377RenderPassId LayerImpl::NextContributingRenderPassId(RenderPassId id) const {
378 return RenderPassId(0, 0);
379}
380
James Robinson80d418c2014-10-16 16:00:02 -0700381void LayerImpl::GetContentsResourceId(ResourceProvider::ResourceId* resource_id,
382 gfx::Size* resource_size) const {
James Robinson646469d2014-10-03 15:33:28 -0700383 NOTREACHED();
James Robinson80d418c2014-10-16 16:00:02 -0700384 *resource_id = 0;
James Robinson646469d2014-10-03 15:33:28 -0700385}
386
James Robinson646469d2014-10-03 15:33:28 -0700387gfx::Vector2dF LayerImpl::ScrollBy(const gfx::Vector2dF& scroll) {
Benjamin Lermancdfc88d2015-02-03 14:35:12 +0100388 RefreshFromScrollDelegate();
389
390 gfx::ScrollOffset adjusted_scroll(scroll);
James Robinsone2ac7e82014-10-15 13:21:59 -0700391 if (layer_tree_impl()->settings().use_pinch_virtual_viewport) {
392 if (!user_scrollable_horizontal_)
393 adjusted_scroll.set_x(0);
394 if (!user_scrollable_vertical_)
395 adjusted_scroll.set_y(0);
396 }
James Robinson646469d2014-10-03 15:33:28 -0700397 DCHECK(scrollable());
Benjamin Lermancdfc88d2015-02-03 14:35:12 +0100398 gfx::ScrollOffset old_offset = CurrentScrollOffset();
399 gfx::ScrollOffset new_offset =
400 ClampScrollOffsetToLimits(old_offset + adjusted_scroll);
401 SetCurrentScrollOffset(new_offset);
James Robinson646469d2014-10-03 15:33:28 -0700402
Benjamin Lermancdfc88d2015-02-03 14:35:12 +0100403 gfx::ScrollOffset unscrolled =
404 old_offset + gfx::ScrollOffset(scroll) - new_offset;
405 return gfx::Vector2dF(unscrolled.x(), unscrolled.y());
James Robinson646469d2014-10-03 15:33:28 -0700406}
407
408void LayerImpl::SetScrollClipLayer(int scroll_clip_layer_id) {
409 scroll_clip_layer_ = layer_tree_impl()->LayerById(scroll_clip_layer_id);
410}
411
James Robinsone2ac7e82014-10-15 13:21:59 -0700412bool LayerImpl::user_scrollable(ScrollbarOrientation orientation) const {
413 return (orientation == HORIZONTAL) ? user_scrollable_horizontal_
414 : user_scrollable_vertical_;
415}
416
James Robinson646469d2014-10-03 15:33:28 -0700417void LayerImpl::ApplySentScrollDeltasFromAbortedCommit() {
James Robinson646469d2014-10-03 15:33:28 -0700418 DCHECK(layer_tree_impl()->IsActiveTree());
Benjamin Lermancdfc88d2015-02-03 14:35:12 +0100419 scroll_offset_->AbortCommit();
James Robinson646469d2014-10-03 15:33:28 -0700420}
421
422InputHandler::ScrollStatus LayerImpl::TryScroll(
423 const gfx::PointF& screen_space_point,
James Robinson7b766f42015-02-06 15:14:04 -0800424 InputHandler::ScrollInputType type,
425 ScrollBlocksOn effective_block_mode) const {
James Robinson646469d2014-10-03 15:33:28 -0700426 if (should_scroll_on_main_thread()) {
427 TRACE_EVENT0("cc", "LayerImpl::TryScroll: Failed ShouldScrollOnMainThread");
Benjamin Lermane8ca9b72015-02-24 16:42:13 +0100428 return InputHandler::SCROLL_ON_MAIN_THREAD;
James Robinson646469d2014-10-03 15:33:28 -0700429 }
430
431 if (!screen_space_transform().IsInvertible()) {
432 TRACE_EVENT0("cc", "LayerImpl::TryScroll: Ignored NonInvertibleTransform");
Benjamin Lermane8ca9b72015-02-24 16:42:13 +0100433 return InputHandler::SCROLL_IGNORED;
James Robinson646469d2014-10-03 15:33:28 -0700434 }
435
436 if (!non_fast_scrollable_region().IsEmpty()) {
437 bool clipped = false;
438 gfx::Transform inverse_screen_space_transform(
439 gfx::Transform::kSkipInitialization);
440 if (!screen_space_transform().GetInverse(&inverse_screen_space_transform)) {
441 // TODO(shawnsingh): We shouldn't be applying a projection if screen space
442 // transform is uninvertible here. Perhaps we should be returning
Benjamin Lermane8ca9b72015-02-24 16:42:13 +0100443 // SCROLL_ON_MAIN_THREAD in this case?
James Robinson646469d2014-10-03 15:33:28 -0700444 }
445
446 gfx::PointF hit_test_point_in_content_space =
447 MathUtil::ProjectPoint(inverse_screen_space_transform,
448 screen_space_point,
449 &clipped);
450 gfx::PointF hit_test_point_in_layer_space =
451 gfx::ScalePoint(hit_test_point_in_content_space,
452 1.f / contents_scale_x(),
453 1.f / contents_scale_y());
454 if (!clipped &&
455 non_fast_scrollable_region().Contains(
456 gfx::ToRoundedPoint(hit_test_point_in_layer_space))) {
457 TRACE_EVENT0("cc",
458 "LayerImpl::tryScroll: Failed NonFastScrollableRegion");
Benjamin Lermane8ca9b72015-02-24 16:42:13 +0100459 return InputHandler::SCROLL_ON_MAIN_THREAD;
James Robinson646469d2014-10-03 15:33:28 -0700460 }
461 }
462
James Robinson7b766f42015-02-06 15:14:04 -0800463 if (have_scroll_event_handlers() &&
Benjamin Lermane8ca9b72015-02-24 16:42:13 +0100464 effective_block_mode & SCROLL_BLOCKS_ON_SCROLL_EVENT) {
James Robinson7b766f42015-02-06 15:14:04 -0800465 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Failed ScrollEventHandlers");
Benjamin Lermane8ca9b72015-02-24 16:42:13 +0100466 return InputHandler::SCROLL_ON_MAIN_THREAD;
James Robinson7b766f42015-02-06 15:14:04 -0800467 }
468
Benjamin Lermane8ca9b72015-02-24 16:42:13 +0100469 if (type == InputHandler::WHEEL && have_wheel_event_handlers() &&
470 effective_block_mode & SCROLL_BLOCKS_ON_WHEEL_EVENT) {
James Robinson646469d2014-10-03 15:33:28 -0700471 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Failed WheelEventHandlers");
Benjamin Lermane8ca9b72015-02-24 16:42:13 +0100472 return InputHandler::SCROLL_ON_MAIN_THREAD;
James Robinson646469d2014-10-03 15:33:28 -0700473 }
474
475 if (!scrollable()) {
476 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Ignored not scrollable");
Benjamin Lermane8ca9b72015-02-24 16:42:13 +0100477 return InputHandler::SCROLL_IGNORED;
James Robinson646469d2014-10-03 15:33:28 -0700478 }
479
480 gfx::ScrollOffset max_scroll_offset = MaxScrollOffset();
481 if (max_scroll_offset.x() <= 0 && max_scroll_offset.y() <= 0) {
482 TRACE_EVENT0("cc",
483 "LayerImpl::tryScroll: Ignored. Technically scrollable,"
484 " but has no affordance in either direction.");
Benjamin Lermane8ca9b72015-02-24 16:42:13 +0100485 return InputHandler::SCROLL_IGNORED;
James Robinson646469d2014-10-03 15:33:28 -0700486 }
487
Benjamin Lermane8ca9b72015-02-24 16:42:13 +0100488 return InputHandler::SCROLL_STARTED;
James Robinson646469d2014-10-03 15:33:28 -0700489}
490
491gfx::Rect LayerImpl::LayerRectToContentRect(
492 const gfx::RectF& layer_rect) const {
493 gfx::RectF content_rect =
494 gfx::ScaleRect(layer_rect, contents_scale_x(), contents_scale_y());
495 // Intersect with content rect to avoid the extra pixel because for some
496 // values x and y, ceil((x / y) * y) may be x + 1.
497 content_rect.Intersect(gfx::Rect(content_bounds()));
498 return gfx::ToEnclosingRect(content_rect);
499}
500
501skia::RefPtr<SkPicture> LayerImpl::GetPicture() {
502 return skia::RefPtr<SkPicture>();
503}
504
505scoped_ptr<LayerImpl> LayerImpl::CreateLayerImpl(LayerTreeImpl* tree_impl) {
Benjamin Lermancdfc88d2015-02-03 14:35:12 +0100506 return LayerImpl::Create(tree_impl, layer_id_, scroll_offset_);
James Robinson646469d2014-10-03 15:33:28 -0700507}
508
509void LayerImpl::PushPropertiesTo(LayerImpl* layer) {
510 layer->SetTransformOrigin(transform_origin_);
511 layer->SetBackgroundColor(background_color_);
512 layer->SetBounds(bounds_);
513 layer->SetContentBounds(content_bounds());
514 layer->SetContentsScale(contents_scale_x(), contents_scale_y());
515 layer->SetDoubleSided(double_sided_);
516 layer->SetDrawCheckerboardForMissingTiles(
517 draw_checkerboard_for_missing_tiles_);
James Robinson646469d2014-10-03 15:33:28 -0700518 layer->SetDrawsContent(DrawsContent());
519 layer->SetHideLayerAndSubtree(hide_layer_and_subtree_);
Benjamin Lermane8ca9b72015-02-24 16:42:13 +0100520 layer->SetHasRenderSurface(!!render_surface() || layer->HasCopyRequest());
James Robinson646469d2014-10-03 15:33:28 -0700521 layer->SetFilters(filters());
522 layer->SetBackgroundFilters(background_filters());
523 layer->SetMasksToBounds(masks_to_bounds_);
524 layer->SetShouldScrollOnMainThread(should_scroll_on_main_thread_);
525 layer->SetHaveWheelEventHandlers(have_wheel_event_handlers_);
526 layer->SetHaveScrollEventHandlers(have_scroll_event_handlers_);
James Robinson7b766f42015-02-06 15:14:04 -0800527 layer->SetScrollBlocksOn(scroll_blocks_on_);
James Robinson646469d2014-10-03 15:33:28 -0700528 layer->SetNonFastScrollableRegion(non_fast_scrollable_region_);
529 layer->SetTouchEventHandlerRegion(touch_event_handler_region_);
530 layer->SetContentsOpaque(contents_opaque_);
531 layer->SetOpacity(opacity_);
532 layer->SetBlendMode(blend_mode_);
533 layer->SetIsRootForIsolatedGroup(is_root_for_isolated_group_);
534 layer->SetPosition(position_);
535 layer->SetIsContainerForFixedPositionLayers(
536 is_container_for_fixed_position_layers_);
537 layer->SetPositionConstraint(position_constraint_);
538 layer->SetShouldFlattenTransform(should_flatten_transform_);
539 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_);
540 layer->SetTransformAndInvertibility(transform_, transform_is_invertible_);
541
542 layer->SetScrollClipLayer(scroll_clip_layer_ ? scroll_clip_layer_->id()
543 : Layer::INVALID_ID);
544 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_);
545 layer->set_user_scrollable_vertical(user_scrollable_vertical_);
James Robinson1ae030a2014-11-07 08:32:47 -0800546
Benjamin Lermancdfc88d2015-02-03 14:35:12 +0100547 layer->SetScrollCompensationAdjustment(scroll_compensation_adjustment_);
James Robinson5e66a792015-01-21 17:02:08 -0800548
Benjamin Lermancdfc88d2015-02-03 14:35:12 +0100549 layer->PushScrollOffset(nullptr);
James Robinson1ae030a2014-11-07 08:32:47 -0800550
James Robinson646469d2014-10-03 15:33:28 -0700551 layer->Set3dSortingContextId(sorting_context_id_);
552 layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_);
553
James Robinsone2ac7e82014-10-15 13:21:59 -0700554 LayerImpl* scroll_parent = nullptr;
James Robinson646469d2014-10-03 15:33:28 -0700555 if (scroll_parent_) {
556 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id());
557 DCHECK(scroll_parent);
558 }
559
560 layer->SetScrollParent(scroll_parent);
561 if (scroll_children_) {
562 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>;
563 for (std::set<LayerImpl*>::iterator it = scroll_children_->begin();
564 it != scroll_children_->end();
565 ++it) {
566 DCHECK_EQ((*it)->scroll_parent(), this);
567 LayerImpl* scroll_child =
568 layer->layer_tree_impl()->LayerById((*it)->id());
569 DCHECK(scroll_child);
570 scroll_children->insert(scroll_child);
571 }
572 layer->SetScrollChildren(scroll_children);
573 } else {
James Robinsone2ac7e82014-10-15 13:21:59 -0700574 layer->SetScrollChildren(nullptr);
James Robinson646469d2014-10-03 15:33:28 -0700575 }
576
James Robinsone2ac7e82014-10-15 13:21:59 -0700577 LayerImpl* clip_parent = nullptr;
James Robinson646469d2014-10-03 15:33:28 -0700578 if (clip_parent_) {
579 clip_parent = layer->layer_tree_impl()->LayerById(
580 clip_parent_->id());
581 DCHECK(clip_parent);
582 }
583
584 layer->SetClipParent(clip_parent);
585 if (clip_children_) {
586 std::set<LayerImpl*>* clip_children = new std::set<LayerImpl*>;
587 for (std::set<LayerImpl*>::iterator it = clip_children_->begin();
588 it != clip_children_->end(); ++it)
589 clip_children->insert(layer->layer_tree_impl()->LayerById((*it)->id()));
590 layer->SetClipChildren(clip_children);
591 } else {
James Robinsone2ac7e82014-10-15 13:21:59 -0700592 layer->SetClipChildren(nullptr);
James Robinson646469d2014-10-03 15:33:28 -0700593 }
594
595 layer->PassCopyRequests(&copy_requests_);
596
597 // If the main thread commits multiple times before the impl thread actually
598 // draws, then damage tracking will become incorrect if we simply clobber the
599 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e.
600 // union) any update changes that have occurred on the main thread.
601 update_rect_.Union(layer->update_rect());
602 layer->SetUpdateRect(update_rect_);
603
604 layer->SetStackingOrderChanged(stacking_order_changed_);
605 layer->SetDebugInfo(debug_info_);
606
Elliot Glayshereae49292015-01-28 10:47:32 -0800607 if (frame_timing_requests_dirty_) {
608 layer->PassFrameTimingRequests(&frame_timing_requests_);
609 frame_timing_requests_dirty_ = false;
610 }
611
James Robinson646469d2014-10-03 15:33:28 -0700612 // Reset any state that should be cleared for the next update.
613 stacking_order_changed_ = false;
James Robinsone2ac7e82014-10-15 13:21:59 -0700614 update_rect_ = gfx::Rect();
James Robinson646469d2014-10-03 15:33:28 -0700615 needs_push_properties_ = false;
616 num_dependents_need_push_properties_ = 0;
617}
618
619gfx::Vector2dF LayerImpl::FixedContainerSizeDelta() const {
620 if (!scroll_clip_layer_)
621 return gfx::Vector2dF();
622
James Robinson646469d2014-10-03 15:33:28 -0700623 gfx::Vector2dF delta_from_scroll = scroll_clip_layer_->bounds_delta();
James Robinson675df572014-10-22 17:20:33 -0700624
625 // In virtual-viewport mode, we don't need to compensate for pinch zoom or
626 // scale since the fixed container is the outer viewport, which sits below
627 // the page scale.
628 if (layer_tree_impl()->settings().use_pinch_virtual_viewport)
629 return delta_from_scroll;
630
James Robinson1027bc12014-12-04 14:51:42 -0800631 float scale_delta = layer_tree_impl()->page_scale_delta();
632 float scale = layer_tree_impl()->current_page_scale_factor() /
633 layer_tree_impl()->page_scale_delta();
634
James Robinson646469d2014-10-03 15:33:28 -0700635 delta_from_scroll.Scale(1.f / scale);
636
637 // The delta-from-pinch component requires some explanation: A viewport of
638 // size (w,h) will appear to be size (w/s,h/s) under scale s in the content
639 // space. If s -> s' on the impl thread, where s' = s * ds, then the apparent
640 // viewport size change in the content space due to ds is:
641 //
642 // (w/s',h/s') - (w/s,h/s) = (w,h)(1/s' - 1/s) = (w,h)(1 - ds)/(s ds)
643 //
644 gfx::Vector2dF delta_from_pinch =
645 gfx::Rect(scroll_clip_layer_->bounds()).bottom_right() - gfx::PointF();
646 delta_from_pinch.Scale((1.f - scale_delta) / (scale * scale_delta));
647
648 return delta_from_scroll + delta_from_pinch;
649}
650
651base::DictionaryValue* LayerImpl::LayerTreeAsJson() const {
652 base::DictionaryValue* result = new base::DictionaryValue;
653 result->SetString("LayerType", LayerTypeAsString());
654
655 base::ListValue* list = new base::ListValue;
656 list->AppendInteger(bounds().width());
657 list->AppendInteger(bounds().height());
658 result->Set("Bounds", list);
659
660 list = new base::ListValue;
661 list->AppendDouble(position_.x());
662 list->AppendDouble(position_.y());
663 result->Set("Position", list);
664
665 const gfx::Transform& gfx_transform = draw_properties_.target_space_transform;
666 double transform[16];
667 gfx_transform.matrix().asColMajord(transform);
668 list = new base::ListValue;
669 for (int i = 0; i < 16; ++i)
670 list->AppendDouble(transform[i]);
671 result->Set("DrawTransform", list);
672
673 result->SetBoolean("DrawsContent", draws_content_);
674 result->SetBoolean("Is3dSorted", Is3dSorted());
Benjamin Lermane8ca9b72015-02-24 16:42:13 +0100675 result->SetDouble("OPACITY", opacity());
James Robinson646469d2014-10-03 15:33:28 -0700676 result->SetBoolean("ContentsOpaque", contents_opaque_);
677
678 if (scrollable())
679 result->SetBoolean("Scrollable", true);
680
681 if (have_wheel_event_handlers_)
682 result->SetBoolean("WheelHandler", have_wheel_event_handlers_);
683 if (have_scroll_event_handlers_)
684 result->SetBoolean("ScrollHandler", have_scroll_event_handlers_);
685 if (!touch_event_handler_region_.IsEmpty()) {
686 scoped_ptr<base::Value> region = touch_event_handler_region_.AsValue();
687 result->Set("TouchRegion", region.release());
688 }
689
James Robinson7b766f42015-02-06 15:14:04 -0800690 if (scroll_blocks_on_) {
691 list = new base::ListValue;
Benjamin Lermane8ca9b72015-02-24 16:42:13 +0100692 if (scroll_blocks_on_ & SCROLL_BLOCKS_ON_START_TOUCH)
James Robinson7b766f42015-02-06 15:14:04 -0800693 list->AppendString("StartTouch");
Benjamin Lermane8ca9b72015-02-24 16:42:13 +0100694 if (scroll_blocks_on_ & SCROLL_BLOCKS_ON_WHEEL_EVENT)
James Robinson7b766f42015-02-06 15:14:04 -0800695 list->AppendString("WheelEvent");
Benjamin Lermane8ca9b72015-02-24 16:42:13 +0100696 if (scroll_blocks_on_ & SCROLL_BLOCKS_ON_SCROLL_EVENT)
James Robinson7b766f42015-02-06 15:14:04 -0800697 list->AppendString("ScrollEvent");
698 result->Set("ScrollBlocksOn", list);
699 }
700
James Robinson646469d2014-10-03 15:33:28 -0700701 list = new base::ListValue;
702 for (size_t i = 0; i < children_.size(); ++i)
703 list->Append(children_[i]->LayerTreeAsJson());
704 result->Set("Children", list);
705
706 return result;
707}
708
709void LayerImpl::SetStackingOrderChanged(bool stacking_order_changed) {
710 if (stacking_order_changed) {
711 stacking_order_changed_ = true;
712 NoteLayerPropertyChangedForSubtree();
713 }
714}
715
716void LayerImpl::NoteLayerPropertyChanged() {
717 layer_property_changed_ = true;
718 layer_tree_impl()->set_needs_update_draw_properties();
719 SetNeedsPushProperties();
720}
721
722void LayerImpl::NoteLayerPropertyChangedForSubtree() {
723 layer_property_changed_ = true;
724 layer_tree_impl()->set_needs_update_draw_properties();
725 for (size_t i = 0; i < children_.size(); ++i)
726 children_[i]->NoteLayerPropertyChangedForDescendantsInternal();
727 SetNeedsPushProperties();
728}
729
730void LayerImpl::NoteLayerPropertyChangedForDescendantsInternal() {
731 layer_property_changed_ = true;
732 for (size_t i = 0; i < children_.size(); ++i)
733 children_[i]->NoteLayerPropertyChangedForDescendantsInternal();
734}
735
736void LayerImpl::NoteLayerPropertyChangedForDescendants() {
737 layer_tree_impl()->set_needs_update_draw_properties();
738 for (size_t i = 0; i < children_.size(); ++i)
739 children_[i]->NoteLayerPropertyChangedForDescendantsInternal();
740 SetNeedsPushProperties();
741}
742
743const char* LayerImpl::LayerTypeAsString() const {
744 return "cc::LayerImpl";
745}
746
747void LayerImpl::ResetAllChangeTrackingForSubtree() {
748 layer_property_changed_ = false;
749
James Robinsone2ac7e82014-10-15 13:21:59 -0700750 update_rect_ = gfx::Rect();
James Robinson646469d2014-10-03 15:33:28 -0700751 damage_rect_ = gfx::RectF();
752
James Robinson9127e722014-12-29 14:41:55 -0800753 if (render_surface_)
754 render_surface_->ResetPropertyChangedFlag();
James Robinson646469d2014-10-03 15:33:28 -0700755
756 if (mask_layer_)
757 mask_layer_->ResetAllChangeTrackingForSubtree();
758
759 if (replica_layer_) {
760 // This also resets the replica mask, if it exists.
761 replica_layer_->ResetAllChangeTrackingForSubtree();
762 }
763
764 for (size_t i = 0; i < children_.size(); ++i)
765 children_[i]->ResetAllChangeTrackingForSubtree();
766
767 needs_push_properties_ = false;
768 num_dependents_need_push_properties_ = 0;
769}
770
771gfx::ScrollOffset LayerImpl::ScrollOffsetForAnimation() const {
Benjamin Lermancdfc88d2015-02-03 14:35:12 +0100772 return CurrentScrollOffset();
James Robinson646469d2014-10-03 15:33:28 -0700773}
774
775void LayerImpl::OnFilterAnimated(const FilterOperations& filters) {
776 SetFilters(filters);
777}
778
779void LayerImpl::OnOpacityAnimated(float opacity) {
780 SetOpacity(opacity);
781}
782
783void LayerImpl::OnTransformAnimated(const gfx::Transform& transform) {
784 SetTransform(transform);
785}
786
787void LayerImpl::OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) {
788 // Only layers in the active tree should need to do anything here, since
789 // layers in the pending tree will find out about these changes as a
Benjamin Lermancdfc88d2015-02-03 14:35:12 +0100790 // result of the shared SyncedProperty.
James Robinson646469d2014-10-03 15:33:28 -0700791 if (!IsActive())
792 return;
793
Benjamin Lermancdfc88d2015-02-03 14:35:12 +0100794 SetCurrentScrollOffset(scroll_offset);
James Robinson646469d2014-10-03 15:33:28 -0700795
796 layer_tree_impl_->DidAnimateScrollOffset();
797}
798
799void LayerImpl::OnAnimationWaitingForDeletion() {}
800
801bool LayerImpl::IsActive() const {
802 return layer_tree_impl_->IsActiveTree();
803}
804
James Robinson646469d2014-10-03 15:33:28 -0700805gfx::Size LayerImpl::bounds() const {
James Robinsone2ac7e82014-10-15 13:21:59 -0700806 gfx::Vector2d delta = gfx::ToCeiledVector2d(bounds_delta_);
807 return gfx::Size(bounds_.width() + delta.x(),
808 bounds_.height() + delta.y());
809}
810
811gfx::SizeF LayerImpl::BoundsForScrolling() const {
812 return gfx::SizeF(bounds_.width() + bounds_delta_.x(),
813 bounds_.height() + bounds_delta_.y());
James Robinson646469d2014-10-03 15:33:28 -0700814}
815
816void LayerImpl::SetBounds(const gfx::Size& bounds) {
817 if (bounds_ == bounds)
818 return;
819
820 bounds_ = bounds;
821
James Robinsonbaf71d32014-10-08 13:00:20 -0700822 ScrollbarParametersDidChange(true);
James Robinson646469d2014-10-03 15:33:28 -0700823 if (masks_to_bounds())
824 NoteLayerPropertyChangedForSubtree();
825 else
826 NoteLayerPropertyChanged();
827}
828
829void LayerImpl::SetBoundsDelta(const gfx::Vector2dF& bounds_delta) {
830 if (bounds_delta_ == bounds_delta)
831 return;
832
833 bounds_delta_ = bounds_delta;
834
James Robinsonbaf71d32014-10-08 13:00:20 -0700835 ScrollbarParametersDidChange(true);
James Robinson646469d2014-10-03 15:33:28 -0700836 if (masks_to_bounds())
837 NoteLayerPropertyChangedForSubtree();
838 else
839 NoteLayerPropertyChanged();
840}
841
842void LayerImpl::SetMaskLayer(scoped_ptr<LayerImpl> mask_layer) {
843 int new_layer_id = mask_layer ? mask_layer->id() : -1;
844
845 if (mask_layer) {
846 DCHECK_EQ(layer_tree_impl(), mask_layer->layer_tree_impl());
847 DCHECK_NE(new_layer_id, mask_layer_id_);
848 } else if (new_layer_id == mask_layer_id_) {
849 return;
850 }
851
852 mask_layer_ = mask_layer.Pass();
853 mask_layer_id_ = new_layer_id;
854 if (mask_layer_)
855 mask_layer_->SetParent(this);
856 NoteLayerPropertyChangedForSubtree();
857}
858
859scoped_ptr<LayerImpl> LayerImpl::TakeMaskLayer() {
860 mask_layer_id_ = -1;
861 return mask_layer_.Pass();
862}
863
864void LayerImpl::SetReplicaLayer(scoped_ptr<LayerImpl> replica_layer) {
865 int new_layer_id = replica_layer ? replica_layer->id() : -1;
866
867 if (replica_layer) {
868 DCHECK_EQ(layer_tree_impl(), replica_layer->layer_tree_impl());
869 DCHECK_NE(new_layer_id, replica_layer_id_);
870 } else if (new_layer_id == replica_layer_id_) {
871 return;
872 }
873
874 replica_layer_ = replica_layer.Pass();
875 replica_layer_id_ = new_layer_id;
876 if (replica_layer_)
877 replica_layer_->SetParent(this);
878 NoteLayerPropertyChangedForSubtree();
879}
880
881scoped_ptr<LayerImpl> LayerImpl::TakeReplicaLayer() {
882 replica_layer_id_ = -1;
883 return replica_layer_.Pass();
884}
885
886ScrollbarLayerImplBase* LayerImpl::ToScrollbarLayer() {
James Robinsone2ac7e82014-10-15 13:21:59 -0700887 return nullptr;
James Robinson646469d2014-10-03 15:33:28 -0700888}
889
890void LayerImpl::SetDrawsContent(bool draws_content) {
891 if (draws_content_ == draws_content)
892 return;
893
894 draws_content_ = draws_content;
895 NoteLayerPropertyChanged();
896}
897
898void LayerImpl::SetHideLayerAndSubtree(bool hide) {
899 if (hide_layer_and_subtree_ == hide)
900 return;
901
902 hide_layer_and_subtree_ = hide;
903 NoteLayerPropertyChangedForSubtree();
904}
905
906void LayerImpl::SetTransformOrigin(const gfx::Point3F& transform_origin) {
907 if (transform_origin_ == transform_origin)
908 return;
909 transform_origin_ = transform_origin;
910 NoteLayerPropertyChangedForSubtree();
911}
912
913void LayerImpl::SetBackgroundColor(SkColor background_color) {
914 if (background_color_ == background_color)
915 return;
916
917 background_color_ = background_color;
918 NoteLayerPropertyChanged();
919}
920
921SkColor LayerImpl::SafeOpaqueBackgroundColor() const {
922 SkColor color = background_color();
923 if (SkColorGetA(color) == 255 && !contents_opaque()) {
924 color = SK_ColorTRANSPARENT;
925 } else if (SkColorGetA(color) != 255 && contents_opaque()) {
926 for (const LayerImpl* layer = parent(); layer;
927 layer = layer->parent()) {
928 color = layer->background_color();
929 if (SkColorGetA(color) == 255)
930 break;
931 }
932 if (SkColorGetA(color) != 255)
933 color = layer_tree_impl()->background_color();
934 if (SkColorGetA(color) != 255)
935 color = SkColorSetA(color, 255);
936 }
937 return color;
938}
939
940void LayerImpl::SetFilters(const FilterOperations& filters) {
941 if (filters_ == filters)
942 return;
943
944 filters_ = filters;
945 NoteLayerPropertyChangedForSubtree();
946}
947
948bool LayerImpl::FilterIsAnimating() const {
Benjamin Lermane8ca9b72015-02-24 16:42:13 +0100949 return layer_animation_controller_->IsAnimatingProperty(Animation::FILTER);
James Robinson646469d2014-10-03 15:33:28 -0700950}
951
952bool LayerImpl::FilterIsAnimatingOnImplOnly() const {
953 Animation* filter_animation =
Benjamin Lermane8ca9b72015-02-24 16:42:13 +0100954 layer_animation_controller_->GetAnimation(Animation::FILTER);
James Robinson646469d2014-10-03 15:33:28 -0700955 return filter_animation && filter_animation->is_impl_only();
956}
957
958void LayerImpl::SetBackgroundFilters(
959 const FilterOperations& filters) {
960 if (background_filters_ == filters)
961 return;
962
963 background_filters_ = filters;
964 NoteLayerPropertyChanged();
965}
966
967void LayerImpl::SetMasksToBounds(bool masks_to_bounds) {
968 if (masks_to_bounds_ == masks_to_bounds)
969 return;
970
971 masks_to_bounds_ = masks_to_bounds;
972 NoteLayerPropertyChangedForSubtree();
973}
974
975void LayerImpl::SetContentsOpaque(bool opaque) {
976 if (contents_opaque_ == opaque)
977 return;
978
979 contents_opaque_ = opaque;
980 NoteLayerPropertyChangedForSubtree();
981}
982
983void LayerImpl::SetOpacity(float opacity) {
984 if (opacity_ == opacity)
985 return;
986
987 opacity_ = opacity;
988 NoteLayerPropertyChangedForSubtree();
989}
990
991bool LayerImpl::OpacityIsAnimating() const {
Benjamin Lermane8ca9b72015-02-24 16:42:13 +0100992 return layer_animation_controller_->IsAnimatingProperty(Animation::OPACITY);
James Robinson646469d2014-10-03 15:33:28 -0700993}
994
995bool LayerImpl::OpacityIsAnimatingOnImplOnly() const {
996 Animation* opacity_animation =
Benjamin Lermane8ca9b72015-02-24 16:42:13 +0100997 layer_animation_controller_->GetAnimation(Animation::OPACITY);
James Robinson646469d2014-10-03 15:33:28 -0700998 return opacity_animation && opacity_animation->is_impl_only();
999}
1000
1001void LayerImpl::SetBlendMode(SkXfermode::Mode blend_mode) {
1002 if (blend_mode_ == blend_mode)
1003 return;
1004
1005 blend_mode_ = blend_mode;
1006 NoteLayerPropertyChangedForSubtree();
1007}
1008
1009void LayerImpl::SetIsRootForIsolatedGroup(bool root) {
1010 if (is_root_for_isolated_group_ == root)
1011 return;
1012
1013 is_root_for_isolated_group_ = root;
1014 SetNeedsPushProperties();
1015}
1016
1017void LayerImpl::SetPosition(const gfx::PointF& position) {
1018 if (position_ == position)
1019 return;
1020
1021 position_ = position;
1022 NoteLayerPropertyChangedForSubtree();
1023}
1024
1025void LayerImpl::SetShouldFlattenTransform(bool flatten) {
1026 if (should_flatten_transform_ == flatten)
1027 return;
1028
1029 should_flatten_transform_ = flatten;
1030 NoteLayerPropertyChangedForSubtree();
1031}
1032
1033void LayerImpl::Set3dSortingContextId(int id) {
1034 if (id == sorting_context_id_)
1035 return;
1036 sorting_context_id_ = id;
1037 NoteLayerPropertyChangedForSubtree();
1038}
1039
Elliot Glayshereae49292015-01-28 10:47:32 -08001040void LayerImpl::PassFrameTimingRequests(
1041 std::vector<FrameTimingRequest>* requests) {
1042 frame_timing_requests_.swap(*requests);
1043 frame_timing_requests_dirty_ = true;
1044 SetNeedsPushProperties();
1045}
1046
James Robinson646469d2014-10-03 15:33:28 -07001047void LayerImpl::SetTransform(const gfx::Transform& transform) {
1048 if (transform_ == transform)
1049 return;
1050
1051 transform_ = transform;
1052 transform_is_invertible_ = transform_.IsInvertible();
1053 NoteLayerPropertyChangedForSubtree();
1054}
1055
1056void LayerImpl::SetTransformAndInvertibility(const gfx::Transform& transform,
1057 bool transform_is_invertible) {
1058 if (transform_ == transform) {
1059 DCHECK(transform_is_invertible_ == transform_is_invertible)
1060 << "Can't change invertibility if transform is unchanged";
1061 return;
1062 }
1063 transform_ = transform;
1064 transform_is_invertible_ = transform_is_invertible;
1065 NoteLayerPropertyChangedForSubtree();
1066}
1067
1068bool LayerImpl::TransformIsAnimating() const {
Benjamin Lermane8ca9b72015-02-24 16:42:13 +01001069 return layer_animation_controller_->IsAnimatingProperty(Animation::TRANSFORM);
James Robinson646469d2014-10-03 15:33:28 -07001070}
1071
1072bool LayerImpl::TransformIsAnimatingOnImplOnly() const {
1073 Animation* transform_animation =
Benjamin Lermane8ca9b72015-02-24 16:42:13 +01001074 layer_animation_controller_->GetAnimation(Animation::TRANSFORM);
James Robinson646469d2014-10-03 15:33:28 -07001075 return transform_animation && transform_animation->is_impl_only();
1076}
1077
James Robinsone2ac7e82014-10-15 13:21:59 -07001078void LayerImpl::SetUpdateRect(const gfx::Rect& update_rect) {
James Robinson646469d2014-10-03 15:33:28 -07001079 update_rect_ = update_rect;
1080 SetNeedsPushProperties();
1081}
1082
1083void LayerImpl::AddDamageRect(const gfx::RectF& damage_rect) {
1084 damage_rect_ = gfx::UnionRects(damage_rect_, damage_rect);
1085}
1086
1087void LayerImpl::SetContentBounds(const gfx::Size& content_bounds) {
1088 if (this->content_bounds() == content_bounds)
1089 return;
1090
1091 draw_properties_.content_bounds = content_bounds;
1092 NoteLayerPropertyChanged();
1093}
1094
1095void LayerImpl::SetContentsScale(float contents_scale_x,
1096 float contents_scale_y) {
1097 if (this->contents_scale_x() == contents_scale_x &&
1098 this->contents_scale_y() == contents_scale_y)
1099 return;
1100
1101 draw_properties_.contents_scale_x = contents_scale_x;
1102 draw_properties_.contents_scale_y = contents_scale_y;
1103 NoteLayerPropertyChanged();
1104}
1105
1106void LayerImpl::SetScrollOffsetDelegate(
1107 ScrollOffsetDelegate* scroll_offset_delegate) {
1108 // Having both a scroll parent and a scroll offset delegate is unsupported.
1109 DCHECK(!scroll_parent_);
Benjamin Lermancdfc88d2015-02-03 14:35:12 +01001110 RefreshFromScrollDelegate();
James Robinson646469d2014-10-03 15:33:28 -07001111 scroll_offset_delegate_ = scroll_offset_delegate;
1112 if (scroll_offset_delegate_)
Benjamin Lermancdfc88d2015-02-03 14:35:12 +01001113 scroll_offset_delegate_->SetCurrentScrollOffset(CurrentScrollOffset());
James Robinson646469d2014-10-03 15:33:28 -07001114}
1115
1116bool LayerImpl::IsExternalFlingActive() const {
1117 return scroll_offset_delegate_ &&
1118 scroll_offset_delegate_->IsExternalFlingActive();
1119}
1120
Benjamin Lermancdfc88d2015-02-03 14:35:12 +01001121void LayerImpl::SetCurrentScrollOffset(const gfx::ScrollOffset& scroll_offset) {
1122 DCHECK(IsActive());
1123 if (scroll_offset_->SetCurrent(scroll_offset))
1124 DidUpdateScrollOffset();
James Robinsone2ac7e82014-10-15 13:21:59 -07001125}
1126
Benjamin Lermancdfc88d2015-02-03 14:35:12 +01001127void LayerImpl::PushScrollOffsetFromMainThread(
1128 const gfx::ScrollOffset& scroll_offset) {
1129 PushScrollOffset(&scroll_offset);
James Robinson646469d2014-10-03 15:33:28 -07001130}
1131
James Robinson7b766f42015-02-06 15:14:04 -08001132void LayerImpl::PushScrollOffsetFromMainThreadAndClobberActiveValue(
1133 const gfx::ScrollOffset& scroll_offset) {
1134 scroll_offset_->set_clobber_active_value();
1135 PushScrollOffset(&scroll_offset);
1136}
1137
Benjamin Lermancdfc88d2015-02-03 14:35:12 +01001138gfx::ScrollOffset LayerImpl::PullDeltaForMainThread() {
1139 RefreshFromScrollDelegate();
James Robinson7b766f42015-02-06 15:14:04 -08001140 return scroll_offset_->PullDeltaForMainThread();
Benjamin Lermancdfc88d2015-02-03 14:35:12 +01001141}
James Robinson646469d2014-10-03 15:33:28 -07001142
Benjamin Lermancdfc88d2015-02-03 14:35:12 +01001143void LayerImpl::RefreshFromScrollDelegate() {
1144 if (scroll_offset_delegate_) {
1145 SetCurrentScrollOffset(
1146 gfx::ScrollOffset(scroll_offset_delegate_->GetCurrentScrollOffset()));
James Robinson646469d2014-10-03 15:33:28 -07001147 }
Benjamin Lermancdfc88d2015-02-03 14:35:12 +01001148}
James Robinson646469d2014-10-03 15:33:28 -07001149
Benjamin Lermancdfc88d2015-02-03 14:35:12 +01001150gfx::ScrollOffset LayerImpl::CurrentScrollOffset() const {
1151 return scroll_offset_->Current(IsActive());
James Robinson646469d2014-10-03 15:33:28 -07001152}
1153
1154gfx::Vector2dF LayerImpl::ScrollDelta() const {
Benjamin Lermancdfc88d2015-02-03 14:35:12 +01001155 if (IsActive())
1156 return gfx::Vector2dF(scroll_offset_->Delta().x(),
1157 scroll_offset_->Delta().y());
1158 else
1159 return gfx::Vector2dF(scroll_offset_->PendingDelta().get().x(),
1160 scroll_offset_->PendingDelta().get().y());
1161}
1162
1163void LayerImpl::SetScrollDelta(const gfx::Vector2dF& delta) {
1164 DCHECK(IsActive());
1165 SetCurrentScrollOffset(scroll_offset_->ActiveBase() +
1166 gfx::ScrollOffset(delta));
1167}
1168
1169gfx::ScrollOffset LayerImpl::BaseScrollOffset() const {
1170 if (IsActive())
1171 return scroll_offset_->ActiveBase();
1172 else
1173 return scroll_offset_->PendingBase();
1174}
1175
1176void LayerImpl::PushScrollOffset(const gfx::ScrollOffset* scroll_offset) {
1177 DCHECK(scroll_offset || IsActive());
1178 bool changed = false;
1179 if (scroll_offset) {
1180 DCHECK(!IsActive() || !layer_tree_impl_->FindPendingTreeLayerById(id()));
1181 changed |= scroll_offset_->PushFromMainThread(*scroll_offset);
James Robinson646469d2014-10-03 15:33:28 -07001182 }
Benjamin Lermancdfc88d2015-02-03 14:35:12 +01001183 if (IsActive()) {
1184 changed |= scroll_offset_->PushPendingToActive();
Benjamin Lermancdfc88d2015-02-03 14:35:12 +01001185 }
1186
1187 if (changed)
1188 DidUpdateScrollOffset();
James Robinson646469d2014-10-03 15:33:28 -07001189}
1190
Benjamin Lermancdfc88d2015-02-03 14:35:12 +01001191void LayerImpl::DidUpdateScrollOffset() {
1192 if (scroll_offset_delegate_) {
1193 scroll_offset_delegate_->SetCurrentScrollOffset(CurrentScrollOffset());
1194 scroll_offset_delegate_->Update();
1195 RefreshFromScrollDelegate();
1196 }
James Robinson646469d2014-10-03 15:33:28 -07001197
Benjamin Lermancdfc88d2015-02-03 14:35:12 +01001198 NoteLayerPropertyChangedForSubtree();
1199 ScrollbarParametersDidChange(false);
James Robinson646469d2014-10-03 15:33:28 -07001200}
1201
1202void LayerImpl::SetDoubleSided(bool double_sided) {
1203 if (double_sided_ == double_sided)
1204 return;
1205
1206 double_sided_ = double_sided;
1207 NoteLayerPropertyChangedForSubtree();
1208}
1209
1210SimpleEnclosedRegion LayerImpl::VisibleContentOpaqueRegion() const {
1211 if (contents_opaque())
1212 return SimpleEnclosedRegion(visible_content_rect());
1213 return SimpleEnclosedRegion();
1214}
1215
1216void LayerImpl::DidBeginTracing() {}
1217
1218void LayerImpl::ReleaseResources() {}
1219
James Robinson7b766f42015-02-06 15:14:04 -08001220void LayerImpl::RecreateResources() {
1221}
1222
James Robinson646469d2014-10-03 15:33:28 -07001223gfx::ScrollOffset LayerImpl::MaxScrollOffset() const {
1224 if (!scroll_clip_layer_ || bounds().IsEmpty())
1225 return gfx::ScrollOffset();
1226
1227 LayerImpl const* page_scale_layer = layer_tree_impl()->page_scale_layer();
1228 DCHECK(this != page_scale_layer);
1229 DCHECK(this != layer_tree_impl()->InnerViewportScrollLayer() ||
1230 IsContainerForFixedPositionLayers());
1231
James Robinson646469d2014-10-03 15:33:28 -07001232 float scale_factor = 1.f;
1233 for (LayerImpl const* current_layer = this;
Benjamin Lermancdfc88d2015-02-03 14:35:12 +01001234 current_layer != scroll_clip_layer_->parent();
James Robinson646469d2014-10-03 15:33:28 -07001235 current_layer = current_layer->parent()) {
Benjamin Lermancdfc88d2015-02-03 14:35:12 +01001236 if (current_layer == page_scale_layer)
1237 scale_factor = layer_tree_impl()->current_page_scale_factor();
James Robinson646469d2014-10-03 15:33:28 -07001238 }
James Robinson646469d2014-10-03 15:33:28 -07001239
Benjamin Lermancdfc88d2015-02-03 14:35:12 +01001240 gfx::SizeF scaled_scroll_bounds =
1241 gfx::ToFlooredSize(gfx::ScaleSize(BoundsForScrolling(), scale_factor));
James Robinson646469d2014-10-03 15:33:28 -07001242 scaled_scroll_bounds = gfx::ToFlooredSize(scaled_scroll_bounds);
1243
1244 gfx::ScrollOffset max_offset(
1245 scaled_scroll_bounds.width() - scroll_clip_layer_->bounds().width(),
1246 scaled_scroll_bounds.height() - scroll_clip_layer_->bounds().height());
1247 // We need the final scroll offset to be in CSS coords.
1248 max_offset.Scale(1 / scale_factor);
1249 max_offset.SetToMax(gfx::ScrollOffset());
1250 return max_offset;
1251}
1252
Benjamin Lermancdfc88d2015-02-03 14:35:12 +01001253gfx::ScrollOffset LayerImpl::ClampScrollOffsetToLimits(
1254 gfx::ScrollOffset offset) const {
1255 offset.SetToMin(MaxScrollOffset());
1256 offset.SetToMax(gfx::ScrollOffset());
1257 return offset;
1258}
James Robinson646469d2014-10-03 15:33:28 -07001259
Benjamin Lermancdfc88d2015-02-03 14:35:12 +01001260gfx::Vector2dF LayerImpl::ClampScrollToMaxScrollOffset() {
1261 gfx::ScrollOffset old_offset = CurrentScrollOffset();
1262 gfx::ScrollOffset clamped_offset = ClampScrollOffsetToLimits(old_offset);
James Robinson646469d2014-10-03 15:33:28 -07001263 gfx::Vector2dF delta = clamped_offset.DeltaFrom(old_offset);
1264 if (!delta.IsZero())
1265 ScrollBy(delta);
James Robinson646469d2014-10-03 15:33:28 -07001266 return delta;
1267}
1268
1269void LayerImpl::SetScrollbarPosition(ScrollbarLayerImplBase* scrollbar_layer,
James Robinsonbaf71d32014-10-08 13:00:20 -07001270 LayerImpl* scrollbar_clip_layer,
1271 bool on_resize) const {
James Robinson646469d2014-10-03 15:33:28 -07001272 DCHECK(scrollbar_layer);
1273 LayerImpl* page_scale_layer = layer_tree_impl()->page_scale_layer();
1274
1275 DCHECK(this != page_scale_layer);
1276 DCHECK(scrollbar_clip_layer);
James Robinsone2ac7e82014-10-15 13:21:59 -07001277 gfx::RectF clip_rect(gfx::PointF(),
1278 scrollbar_clip_layer->BoundsForScrolling());
James Robinson646469d2014-10-03 15:33:28 -07001279
1280 // See comment in MaxScrollOffset() regarding the use of the content layer
1281 // bounds here.
James Robinsone2ac7e82014-10-15 13:21:59 -07001282 gfx::RectF scroll_rect(gfx::PointF(), BoundsForScrolling());
James Robinson646469d2014-10-03 15:33:28 -07001283
1284 if (scroll_rect.size().IsEmpty())
1285 return;
1286
James Robinson646469d2014-10-03 15:33:28 -07001287 gfx::ScrollOffset current_offset;
1288 for (LayerImpl const* current_layer = this;
Benjamin Lermancdfc88d2015-02-03 14:35:12 +01001289 current_layer != scrollbar_clip_layer->parent();
James Robinson646469d2014-10-03 15:33:28 -07001290 current_layer = current_layer->parent()) {
Benjamin Lermancdfc88d2015-02-03 14:35:12 +01001291 current_offset += current_layer->CurrentScrollOffset();
James Robinson646469d2014-10-03 15:33:28 -07001292 if (current_layer == page_scale_layer) {
James Robinson1027bc12014-12-04 14:51:42 -08001293 float scale_factor = layer_tree_impl()->current_page_scale_factor();
James Robinson646469d2014-10-03 15:33:28 -07001294 current_offset.Scale(scale_factor);
1295 scroll_rect.Scale(scale_factor);
James Robinson646469d2014-10-03 15:33:28 -07001296 }
1297 }
James Robinson646469d2014-10-03 15:33:28 -07001298
1299 bool scrollbar_needs_animation = false;
1300 scrollbar_needs_animation |= scrollbar_layer->SetVerticalAdjust(
1301 scrollbar_clip_layer->bounds_delta().y());
1302 if (scrollbar_layer->orientation() == HORIZONTAL) {
1303 float visible_ratio = clip_rect.width() / scroll_rect.width();
1304 scrollbar_needs_animation |=
1305 scrollbar_layer->SetCurrentPos(current_offset.x());
1306 scrollbar_needs_animation |=
1307 scrollbar_layer->SetMaximum(scroll_rect.width() - clip_rect.width());
1308 scrollbar_needs_animation |=
1309 scrollbar_layer->SetVisibleToTotalLengthRatio(visible_ratio);
1310 } else {
1311 float visible_ratio = clip_rect.height() / scroll_rect.height();
1312 scrollbar_needs_animation |=
1313 scrollbar_layer->SetCurrentPos(current_offset.y());
1314 scrollbar_needs_animation |=
1315 scrollbar_layer->SetMaximum(scroll_rect.height() - clip_rect.height());
1316 scrollbar_needs_animation |=
1317 scrollbar_layer->SetVisibleToTotalLengthRatio(visible_ratio);
1318 }
1319 if (scrollbar_needs_animation) {
1320 layer_tree_impl()->set_needs_update_draw_properties();
1321 // TODO(wjmaclean) The scrollbar animator for the pinch-zoom scrollbars
1322 // should activate for every scroll on the main frame, not just the
1323 // scrolls that move the pinch virtual viewport (i.e. trigger from
1324 // either inner or outer viewport).
1325 if (scrollbar_animation_controller_) {
Benjamin Lermancdfc88d2015-02-03 14:35:12 +01001326 // Non-overlay scrollbars shouldn't trigger animations.
1327 if (scrollbar_layer->is_overlay_scrollbar())
James Robinsonbaf71d32014-10-08 13:00:20 -07001328 scrollbar_animation_controller_->DidScrollUpdate(on_resize);
James Robinson646469d2014-10-03 15:33:28 -07001329 }
1330 }
1331}
1332
1333void LayerImpl::DidBecomeActive() {
1334 if (layer_tree_impl_->settings().scrollbar_animator ==
Benjamin Lermane8ca9b72015-02-24 16:42:13 +01001335 LayerTreeSettings::NO_ANIMATOR) {
James Robinson646469d2014-10-03 15:33:28 -07001336 return;
1337 }
1338
1339 bool need_scrollbar_animation_controller = scrollable() && scrollbars_;
1340 if (!need_scrollbar_animation_controller) {
1341 scrollbar_animation_controller_ = nullptr;
1342 return;
1343 }
1344
1345 if (scrollbar_animation_controller_)
1346 return;
1347
1348 scrollbar_animation_controller_ =
1349 layer_tree_impl_->CreateScrollbarAnimationController(this);
1350}
1351
1352void LayerImpl::ClearScrollbars() {
1353 if (!scrollbars_)
1354 return;
1355
James Robinsone2ac7e82014-10-15 13:21:59 -07001356 scrollbars_.reset(nullptr);
James Robinson646469d2014-10-03 15:33:28 -07001357}
1358
1359void LayerImpl::AddScrollbar(ScrollbarLayerImplBase* layer) {
1360 DCHECK(layer);
1361 DCHECK(!scrollbars_ || scrollbars_->find(layer) == scrollbars_->end());
1362 if (!scrollbars_)
1363 scrollbars_.reset(new ScrollbarSet());
1364
1365 scrollbars_->insert(layer);
1366}
1367
1368void LayerImpl::RemoveScrollbar(ScrollbarLayerImplBase* layer) {
1369 DCHECK(scrollbars_);
1370 DCHECK(layer);
1371 DCHECK(scrollbars_->find(layer) != scrollbars_->end());
1372
1373 scrollbars_->erase(layer);
1374 if (scrollbars_->empty())
1375 scrollbars_ = nullptr;
1376}
1377
1378bool LayerImpl::HasScrollbar(ScrollbarOrientation orientation) const {
1379 if (!scrollbars_)
1380 return false;
1381
1382 for (ScrollbarSet::iterator it = scrollbars_->begin();
1383 it != scrollbars_->end();
1384 ++it)
1385 if ((*it)->orientation() == orientation)
1386 return true;
1387
1388 return false;
1389}
1390
James Robinsonbaf71d32014-10-08 13:00:20 -07001391void LayerImpl::ScrollbarParametersDidChange(bool on_resize) {
James Robinson646469d2014-10-03 15:33:28 -07001392 if (!scrollbars_)
1393 return;
1394
1395 for (ScrollbarSet::iterator it = scrollbars_->begin();
1396 it != scrollbars_->end();
James Robinsonbaf71d32014-10-08 13:00:20 -07001397 ++it) {
1398 bool is_scroll_layer = (*it)->ScrollLayerId() == layer_id_;
1399 bool scroll_layer_resized = is_scroll_layer && on_resize;
1400 (*it)->ScrollbarParametersDidChange(scroll_layer_resized);
1401 }
James Robinson646469d2014-10-03 15:33:28 -07001402}
1403
1404void LayerImpl::SetNeedsPushProperties() {
1405 if (needs_push_properties_)
1406 return;
1407 if (!parent_should_know_need_push_properties() && parent_)
1408 parent_->AddDependentNeedsPushProperties();
1409 needs_push_properties_ = true;
1410}
1411
1412void LayerImpl::AddDependentNeedsPushProperties() {
1413 DCHECK_GE(num_dependents_need_push_properties_, 0);
1414
1415 if (!parent_should_know_need_push_properties() && parent_)
1416 parent_->AddDependentNeedsPushProperties();
1417
1418 num_dependents_need_push_properties_++;
1419}
1420
1421void LayerImpl::RemoveDependentNeedsPushProperties() {
1422 num_dependents_need_push_properties_--;
1423 DCHECK_GE(num_dependents_need_push_properties_, 0);
1424
1425 if (!parent_should_know_need_push_properties() && parent_)
1426 parent_->RemoveDependentNeedsPushProperties();
1427}
1428
1429void LayerImpl::GetAllTilesForTracing(std::set<const Tile*>* tiles) const {
1430}
1431
Etienne Membrives386015a2015-02-19 17:27:12 +01001432void LayerImpl::AsValueInto(base::trace_event::TracedValue* state) const {
James Robinson646469d2014-10-03 15:33:28 -07001433 TracedValue::MakeDictIntoImplicitSnapshotWithCategory(
1434 TRACE_DISABLED_BY_DEFAULT("cc.debug"),
1435 state,
1436 "cc::LayerImpl",
1437 LayerTypeAsString(),
1438 this);
1439 state->SetInteger("layer_id", id());
James Robinson5e66a792015-01-21 17:02:08 -08001440 MathUtil::AddToTracedValue("bounds", bounds_, state);
James Robinson646469d2014-10-03 15:33:28 -07001441
1442 state->SetDouble("opacity", opacity());
1443
James Robinson5e66a792015-01-21 17:02:08 -08001444 MathUtil::AddToTracedValue("position", position_, state);
James Robinson646469d2014-10-03 15:33:28 -07001445
1446 state->SetInteger("draws_content", DrawsContent());
1447 state->SetInteger("gpu_memory_usage", GPUMemoryUsageInBytes());
1448
Benjamin Lermancdfc88d2015-02-03 14:35:12 +01001449 MathUtil::AddToTracedValue(
1450 "scroll_offset", scroll_offset_ ? scroll_offset_->Current(IsActive())
1451 : gfx::ScrollOffset(),
1452 state);
1453
James Robinson5e66a792015-01-21 17:02:08 -08001454 MathUtil::AddToTracedValue("transform_origin", transform_origin_, state);
James Robinson646469d2014-10-03 15:33:28 -07001455
1456 bool clipped;
1457 gfx::QuadF layer_quad = MathUtil::MapQuad(
1458 screen_space_transform(),
1459 gfx::QuadF(gfx::Rect(content_bounds())),
1460 &clipped);
James Robinson5e66a792015-01-21 17:02:08 -08001461 MathUtil::AddToTracedValue("layer_quad", layer_quad, state);
James Robinson646469d2014-10-03 15:33:28 -07001462 if (!touch_event_handler_region_.IsEmpty()) {
1463 state->BeginArray("touch_event_handler_region");
1464 touch_event_handler_region_.AsValueInto(state);
1465 state->EndArray();
1466 }
1467 if (have_wheel_event_handlers_) {
1468 gfx::Rect wheel_rect(content_bounds());
1469 Region wheel_region(wheel_rect);
1470 state->BeginArray("wheel_event_handler_region");
1471 wheel_region.AsValueInto(state);
1472 state->EndArray();
1473 }
1474 if (have_scroll_event_handlers_) {
1475 gfx::Rect scroll_rect(content_bounds());
1476 Region scroll_region(scroll_rect);
1477 state->BeginArray("scroll_event_handler_region");
1478 scroll_region.AsValueInto(state);
1479 state->EndArray();
1480 }
1481 if (!non_fast_scrollable_region_.IsEmpty()) {
1482 state->BeginArray("non_fast_scrollable_region");
1483 non_fast_scrollable_region_.AsValueInto(state);
1484 state->EndArray();
1485 }
James Robinson7b766f42015-02-06 15:14:04 -08001486 if (scroll_blocks_on_) {
1487 state->SetInteger("scroll_blocks_on", scroll_blocks_on_);
1488 }
James Robinson646469d2014-10-03 15:33:28 -07001489
1490 state->BeginArray("children");
1491 for (size_t i = 0; i < children_.size(); ++i) {
1492 state->BeginDictionary();
1493 children_[i]->AsValueInto(state);
1494 state->EndDictionary();
1495 }
1496 state->EndArray();
1497 if (mask_layer_) {
1498 state->BeginDictionary("mask_layer");
1499 mask_layer_->AsValueInto(state);
1500 state->EndDictionary();
1501 }
1502 if (replica_layer_) {
1503 state->BeginDictionary("replica_layer");
1504 replica_layer_->AsValueInto(state);
1505 state->EndDictionary();
1506 }
1507
1508 if (scroll_parent_)
1509 state->SetInteger("scroll_parent", scroll_parent_->id());
1510
1511 if (clip_parent_)
1512 state->SetInteger("clip_parent", clip_parent_->id());
1513
1514 state->SetBoolean("can_use_lcd_text", can_use_lcd_text());
1515 state->SetBoolean("contents_opaque", contents_opaque());
1516
1517 state->SetBoolean(
1518 "has_animation_bounds",
1519 layer_animation_controller()->HasAnimationThatInflatesBounds());
1520
1521 gfx::BoxF box;
James Robinson5e66a792015-01-21 17:02:08 -08001522 if (LayerUtils::GetAnimationBounds(*this, &box))
1523 MathUtil::AddToTracedValue("animation_bounds", box, state);
James Robinson646469d2014-10-03 15:33:28 -07001524
1525 if (debug_info_.get()) {
1526 std::string str;
1527 debug_info_->AppendAsTraceFormat(&str);
1528 base::JSONReader json_reader;
1529 scoped_ptr<base::Value> debug_info_value(json_reader.ReadToValue(str));
1530
1531 if (debug_info_value->IsType(base::Value::TYPE_DICTIONARY)) {
James Robinsone2ac7e82014-10-15 13:21:59 -07001532 base::DictionaryValue* dictionary_value = nullptr;
James Robinson646469d2014-10-03 15:33:28 -07001533 bool converted_to_dictionary =
1534 debug_info_value->GetAsDictionary(&dictionary_value);
1535 DCHECK(converted_to_dictionary);
1536 for (base::DictionaryValue::Iterator it(*dictionary_value); !it.IsAtEnd();
1537 it.Advance()) {
1538 state->SetValue(it.key().data(), it.value().DeepCopy());
1539 }
1540 } else {
1541 NOTREACHED();
1542 }
1543 }
Elliot Glayshereae49292015-01-28 10:47:32 -08001544
1545 if (!frame_timing_requests_.empty()) {
1546 state->BeginArray("frame_timing_requests");
1547 for (const auto& request : frame_timing_requests_) {
1548 state->BeginDictionary();
1549 state->SetInteger("request_id", request.id());
1550 MathUtil::AddToTracedValue("request_rect", request.rect(), state);
1551 state->EndDictionary();
1552 }
1553 state->EndArray();
1554 }
James Robinson646469d2014-10-03 15:33:28 -07001555}
1556
1557bool LayerImpl::IsDrawnRenderSurfaceLayerListMember() const {
1558 return draw_properties_.last_drawn_render_surface_layer_list_id ==
1559 layer_tree_impl_->current_render_surface_list_id();
1560}
1561
1562size_t LayerImpl::GPUMemoryUsageInBytes() const { return 0; }
1563
1564void LayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) {
1565 benchmark->RunOnLayer(this);
1566}
1567
1568int LayerImpl::NumDescendantsThatDrawContent() const {
1569 return num_descendants_that_draw_content_;
1570}
1571
1572void LayerImpl::NotifyAnimationFinished(
1573 base::TimeTicks monotonic_time,
James Robinson80d418c2014-10-16 16:00:02 -07001574 Animation::TargetProperty target_property,
1575 int group) {
Benjamin Lermane8ca9b72015-02-24 16:42:13 +01001576 if (target_property == Animation::SCROLL_OFFSET)
James Robinson646469d2014-10-03 15:33:28 -07001577 layer_tree_impl_->InputScrollAnimationFinished();
1578}
1579
James Robinson9127e722014-12-29 14:41:55 -08001580void LayerImpl::SetHasRenderSurface(bool should_have_render_surface) {
1581 if (!!render_surface() == should_have_render_surface)
1582 return;
1583
1584 SetNeedsPushProperties();
1585 layer_tree_impl()->set_needs_update_draw_properties();
1586 if (should_have_render_surface) {
1587 render_surface_ = make_scoped_ptr(new RenderSurfaceImpl(this));
1588 return;
1589 }
1590 render_surface_.reset();
1591}
1592
Dave Moorecc0e4f92015-03-10 15:23:04 -07001593Region LayerImpl::GetInvalidationRegion() {
1594 return Region(update_rect_);
1595}
1596
James Robinson646469d2014-10-03 15:33:28 -07001597} // namespace cc