OLD | NEW |
| (Empty) |
1 // Copyright 2010 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.h" | |
6 | |
7 #include <algorithm> | |
8 | |
9 #include "base/atomic_sequence_num.h" | |
10 #include "base/location.h" | |
11 #include "base/metrics/histogram.h" | |
12 #include "base/single_thread_task_runner.h" | |
13 #include "base/time/time.h" | |
14 #include "base/trace_event/trace_event.h" | |
15 #include "cc/animation/animation.h" | |
16 #include "cc/animation/animation_events.h" | |
17 #include "cc/animation/animation_registrar.h" | |
18 #include "cc/animation/keyframed_animation_curve.h" | |
19 #include "cc/animation/layer_animation_controller.h" | |
20 #include "cc/base/simple_enclosed_region.h" | |
21 #include "cc/debug/frame_viewer_instrumentation.h" | |
22 #include "cc/layers/layer_client.h" | |
23 #include "cc/layers/layer_impl.h" | |
24 #include "cc/layers/scrollbar_layer_interface.h" | |
25 #include "cc/output/copy_output_request.h" | |
26 #include "cc/output/copy_output_result.h" | |
27 #include "cc/trees/layer_tree_host.h" | |
28 #include "cc/trees/layer_tree_impl.h" | |
29 #include "third_party/skia/include/core/SkImageFilter.h" | |
30 #include "ui/gfx/geometry/rect_conversions.h" | |
31 #include "ui/gfx/geometry/vector2d_conversions.h" | |
32 | |
33 namespace cc { | |
34 | |
35 base::StaticAtomicSequenceNumber g_next_layer_id; | |
36 | |
37 scoped_refptr<Layer> Layer::Create() { | |
38 return make_scoped_refptr(new Layer()); | |
39 } | |
40 | |
41 Layer::Layer() | |
42 : needs_push_properties_(false), | |
43 num_dependents_need_push_properties_(false), | |
44 stacking_order_changed_(false), | |
45 // Layer IDs start from 1. | |
46 layer_id_(g_next_layer_id.GetNext() + 1), | |
47 ignore_set_needs_commit_(false), | |
48 sorting_context_id_(0), | |
49 parent_(nullptr), | |
50 layer_tree_host_(nullptr), | |
51 scroll_clip_layer_id_(INVALID_ID), | |
52 num_descendants_that_draw_content_(0), | |
53 transform_tree_index_(-1), | |
54 opacity_tree_index_(-1), | |
55 clip_tree_index_(-1), | |
56 should_flatten_transform_from_property_tree_(false), | |
57 should_scroll_on_main_thread_(false), | |
58 have_wheel_event_handlers_(false), | |
59 have_scroll_event_handlers_(false), | |
60 user_scrollable_horizontal_(true), | |
61 user_scrollable_vertical_(true), | |
62 is_root_for_isolated_group_(false), | |
63 is_container_for_fixed_position_layers_(false), | |
64 is_drawable_(false), | |
65 draws_content_(false), | |
66 hide_layer_and_subtree_(false), | |
67 masks_to_bounds_(false), | |
68 contents_opaque_(false), | |
69 double_sided_(true), | |
70 should_flatten_transform_(true), | |
71 use_parent_backface_visibility_(false), | |
72 draw_checkerboard_for_missing_tiles_(false), | |
73 force_render_surface_(false), | |
74 transform_is_invertible_(true), | |
75 has_render_surface_(false), | |
76 scroll_blocks_on_(SCROLL_BLOCKS_ON_NONE), | |
77 background_color_(0), | |
78 opacity_(1.f), | |
79 blend_mode_(SkXfermode::kSrcOver_Mode), | |
80 scroll_parent_(nullptr), | |
81 clip_parent_(nullptr), | |
82 replica_layer_(nullptr), | |
83 raster_scale_(0.f), | |
84 client_(nullptr), | |
85 frame_timing_requests_dirty_(false) { | |
86 layer_animation_controller_ = LayerAnimationController::Create(layer_id_); | |
87 layer_animation_controller_->AddValueObserver(this); | |
88 layer_animation_controller_->set_value_provider(this); | |
89 } | |
90 | |
91 Layer::~Layer() { | |
92 // Our parent should be holding a reference to us so there should be no | |
93 // way for us to be destroyed while we still have a parent. | |
94 DCHECK(!parent()); | |
95 // Similarly we shouldn't have a layer tree host since it also keeps a | |
96 // reference to us. | |
97 DCHECK(!layer_tree_host()); | |
98 | |
99 layer_animation_controller_->RemoveValueObserver(this); | |
100 layer_animation_controller_->remove_value_provider(this); | |
101 | |
102 RemoveFromScrollTree(); | |
103 RemoveFromClipTree(); | |
104 | |
105 // Remove the parent reference from all children and dependents. | |
106 RemoveAllChildren(); | |
107 if (mask_layer_.get()) { | |
108 DCHECK_EQ(this, mask_layer_->parent()); | |
109 mask_layer_->RemoveFromParent(); | |
110 } | |
111 if (replica_layer_.get()) { | |
112 DCHECK_EQ(this, replica_layer_->parent()); | |
113 replica_layer_->RemoveFromParent(); | |
114 } | |
115 } | |
116 | |
117 void Layer::SetLayerTreeHost(LayerTreeHost* host) { | |
118 if (layer_tree_host_ == host) | |
119 return; | |
120 | |
121 layer_tree_host_ = host; | |
122 | |
123 // When changing hosts, the layer needs to commit its properties to the impl | |
124 // side for the new host. | |
125 SetNeedsPushProperties(); | |
126 | |
127 for (size_t i = 0; i < children_.size(); ++i) | |
128 children_[i]->SetLayerTreeHost(host); | |
129 | |
130 if (mask_layer_.get()) | |
131 mask_layer_->SetLayerTreeHost(host); | |
132 if (replica_layer_.get()) | |
133 replica_layer_->SetLayerTreeHost(host); | |
134 | |
135 if (host) { | |
136 layer_animation_controller_->SetAnimationRegistrar( | |
137 host->animation_registrar()); | |
138 | |
139 if (host->settings().layer_transforms_should_scale_layer_contents) | |
140 reset_raster_scale_to_unknown(); | |
141 } | |
142 | |
143 if (host && layer_animation_controller_->has_any_animation()) | |
144 host->SetNeedsCommit(); | |
145 } | |
146 | |
147 void Layer::SetNeedsUpdate() { | |
148 if (layer_tree_host_ && !ignore_set_needs_commit_) | |
149 layer_tree_host_->SetNeedsUpdateLayers(); | |
150 } | |
151 | |
152 void Layer::SetNeedsCommit() { | |
153 if (!layer_tree_host_) | |
154 return; | |
155 | |
156 SetNeedsPushProperties(); | |
157 | |
158 if (ignore_set_needs_commit_) | |
159 return; | |
160 | |
161 layer_tree_host_->SetNeedsCommit(); | |
162 } | |
163 | |
164 void Layer::SetNeedsFullTreeSync() { | |
165 if (!layer_tree_host_) | |
166 return; | |
167 | |
168 layer_tree_host_->SetNeedsFullTreeSync(); | |
169 } | |
170 | |
171 void Layer::SetNextCommitWaitsForActivation() { | |
172 if (!layer_tree_host_) | |
173 return; | |
174 | |
175 layer_tree_host_->SetNextCommitWaitsForActivation(); | |
176 } | |
177 | |
178 void Layer::SetNeedsPushProperties() { | |
179 if (needs_push_properties_) | |
180 return; | |
181 if (!parent_should_know_need_push_properties() && parent_) | |
182 parent_->AddDependentNeedsPushProperties(); | |
183 needs_push_properties_ = true; | |
184 } | |
185 | |
186 void Layer::AddDependentNeedsPushProperties() { | |
187 DCHECK_GE(num_dependents_need_push_properties_, 0); | |
188 | |
189 if (!parent_should_know_need_push_properties() && parent_) | |
190 parent_->AddDependentNeedsPushProperties(); | |
191 | |
192 num_dependents_need_push_properties_++; | |
193 } | |
194 | |
195 void Layer::RemoveDependentNeedsPushProperties() { | |
196 num_dependents_need_push_properties_--; | |
197 DCHECK_GE(num_dependents_need_push_properties_, 0); | |
198 | |
199 if (!parent_should_know_need_push_properties() && parent_) | |
200 parent_->RemoveDependentNeedsPushProperties(); | |
201 } | |
202 | |
203 bool Layer::IsPropertyChangeAllowed() const { | |
204 if (!layer_tree_host_) | |
205 return true; | |
206 | |
207 if (!layer_tree_host_->settings().strict_layer_property_change_checking) | |
208 return true; | |
209 | |
210 return !layer_tree_host_->in_paint_layer_contents(); | |
211 } | |
212 | |
213 gfx::Rect Layer::LayerRectToContentRect(const gfx::Rect& layer_rect) const { | |
214 gfx::Rect content_rect = gfx::ScaleToEnclosingRect( | |
215 layer_rect, contents_scale_x(), contents_scale_y()); | |
216 // Intersect with content rect to avoid the extra pixel because for some | |
217 // values x and y, ceil((x / y) * y) may be x + 1. | |
218 content_rect.Intersect(gfx::Rect(content_bounds())); | |
219 return content_rect; | |
220 } | |
221 | |
222 skia::RefPtr<SkPicture> Layer::GetPicture() const { | |
223 return skia::RefPtr<SkPicture>(); | |
224 } | |
225 | |
226 void Layer::SetParent(Layer* layer) { | |
227 DCHECK(!layer || !layer->HasAncestor(this)); | |
228 | |
229 if (parent_should_know_need_push_properties()) { | |
230 if (parent_) | |
231 parent_->RemoveDependentNeedsPushProperties(); | |
232 if (layer) | |
233 layer->AddDependentNeedsPushProperties(); | |
234 } | |
235 | |
236 parent_ = layer; | |
237 SetLayerTreeHost(parent_ ? parent_->layer_tree_host() : nullptr); | |
238 | |
239 if (!layer_tree_host_) | |
240 return; | |
241 const LayerTreeSettings& settings = layer_tree_host_->settings(); | |
242 if (!settings.layer_transforms_should_scale_layer_contents) | |
243 return; | |
244 | |
245 reset_raster_scale_to_unknown(); | |
246 if (mask_layer_.get()) | |
247 mask_layer_->reset_raster_scale_to_unknown(); | |
248 if (replica_layer_.get() && replica_layer_->mask_layer_.get()) | |
249 replica_layer_->mask_layer_->reset_raster_scale_to_unknown(); | |
250 } | |
251 | |
252 void Layer::AddChild(scoped_refptr<Layer> child) { | |
253 InsertChild(child, children_.size()); | |
254 } | |
255 | |
256 void Layer::InsertChild(scoped_refptr<Layer> child, size_t index) { | |
257 DCHECK(IsPropertyChangeAllowed()); | |
258 child->RemoveFromParent(); | |
259 AddDrawableDescendants(child->NumDescendantsThatDrawContent() + | |
260 (child->DrawsContent() ? 1 : 0)); | |
261 child->SetParent(this); | |
262 child->stacking_order_changed_ = true; | |
263 | |
264 index = std::min(index, children_.size()); | |
265 children_.insert(children_.begin() + index, child); | |
266 SetNeedsFullTreeSync(); | |
267 } | |
268 | |
269 void Layer::RemoveFromParent() { | |
270 DCHECK(IsPropertyChangeAllowed()); | |
271 if (parent_) | |
272 parent_->RemoveChildOrDependent(this); | |
273 } | |
274 | |
275 void Layer::RemoveChildOrDependent(Layer* child) { | |
276 if (mask_layer_.get() == child) { | |
277 mask_layer_->SetParent(nullptr); | |
278 mask_layer_ = nullptr; | |
279 SetNeedsFullTreeSync(); | |
280 return; | |
281 } | |
282 if (replica_layer_.get() == child) { | |
283 replica_layer_->SetParent(nullptr); | |
284 replica_layer_ = nullptr; | |
285 SetNeedsFullTreeSync(); | |
286 return; | |
287 } | |
288 | |
289 for (LayerList::iterator iter = children_.begin(); | |
290 iter != children_.end(); | |
291 ++iter) { | |
292 if (iter->get() != child) | |
293 continue; | |
294 | |
295 child->SetParent(nullptr); | |
296 AddDrawableDescendants(-child->NumDescendantsThatDrawContent() - | |
297 (child->DrawsContent() ? 1 : 0)); | |
298 children_.erase(iter); | |
299 SetNeedsFullTreeSync(); | |
300 return; | |
301 } | |
302 } | |
303 | |
304 void Layer::ReplaceChild(Layer* reference, scoped_refptr<Layer> new_layer) { | |
305 DCHECK(reference); | |
306 DCHECK_EQ(reference->parent(), this); | |
307 DCHECK(IsPropertyChangeAllowed()); | |
308 | |
309 if (reference == new_layer.get()) | |
310 return; | |
311 | |
312 int reference_index = IndexOfChild(reference); | |
313 if (reference_index == -1) { | |
314 NOTREACHED(); | |
315 return; | |
316 } | |
317 | |
318 reference->RemoveFromParent(); | |
319 | |
320 if (new_layer.get()) { | |
321 new_layer->RemoveFromParent(); | |
322 InsertChild(new_layer, reference_index); | |
323 } | |
324 } | |
325 | |
326 int Layer::IndexOfChild(const Layer* reference) { | |
327 for (size_t i = 0; i < children_.size(); ++i) { | |
328 if (children_[i].get() == reference) | |
329 return i; | |
330 } | |
331 return -1; | |
332 } | |
333 | |
334 void Layer::SetBounds(const gfx::Size& size) { | |
335 DCHECK(IsPropertyChangeAllowed()); | |
336 if (bounds() == size) | |
337 return; | |
338 | |
339 bounds_ = size; | |
340 SetNeedsCommit(); | |
341 } | |
342 | |
343 Layer* Layer::RootLayer() { | |
344 Layer* layer = this; | |
345 while (layer->parent()) | |
346 layer = layer->parent(); | |
347 return layer; | |
348 } | |
349 | |
350 void Layer::RemoveAllChildren() { | |
351 DCHECK(IsPropertyChangeAllowed()); | |
352 while (children_.size()) { | |
353 Layer* layer = children_[0].get(); | |
354 DCHECK_EQ(this, layer->parent()); | |
355 layer->RemoveFromParent(); | |
356 } | |
357 } | |
358 | |
359 void Layer::SetChildren(const LayerList& children) { | |
360 DCHECK(IsPropertyChangeAllowed()); | |
361 if (children == children_) | |
362 return; | |
363 | |
364 RemoveAllChildren(); | |
365 for (size_t i = 0; i < children.size(); ++i) | |
366 AddChild(children[i]); | |
367 } | |
368 | |
369 bool Layer::HasAncestor(const Layer* ancestor) const { | |
370 for (const Layer* layer = parent(); layer; layer = layer->parent()) { | |
371 if (layer == ancestor) | |
372 return true; | |
373 } | |
374 return false; | |
375 } | |
376 | |
377 void Layer::RequestCopyOfOutput( | |
378 scoped_ptr<CopyOutputRequest> request) { | |
379 DCHECK(IsPropertyChangeAllowed()); | |
380 if (request->IsEmpty()) | |
381 return; | |
382 copy_requests_.push_back(request.Pass()); | |
383 SetNeedsCommit(); | |
384 } | |
385 | |
386 void Layer::SetBackgroundColor(SkColor background_color) { | |
387 DCHECK(IsPropertyChangeAllowed()); | |
388 if (background_color_ == background_color) | |
389 return; | |
390 background_color_ = background_color; | |
391 SetNeedsCommit(); | |
392 } | |
393 | |
394 SkColor Layer::SafeOpaqueBackgroundColor() const { | |
395 SkColor color = background_color(); | |
396 if (SkColorGetA(color) == 255 && !contents_opaque()) { | |
397 color = SK_ColorTRANSPARENT; | |
398 } else if (SkColorGetA(color) != 255 && contents_opaque()) { | |
399 for (const Layer* layer = parent(); layer; | |
400 layer = layer->parent()) { | |
401 color = layer->background_color(); | |
402 if (SkColorGetA(color) == 255) | |
403 break; | |
404 } | |
405 if (SkColorGetA(color) != 255) | |
406 color = layer_tree_host_->background_color(); | |
407 if (SkColorGetA(color) != 255) | |
408 color = SkColorSetA(color, 255); | |
409 } | |
410 return color; | |
411 } | |
412 | |
413 void Layer::CalculateContentsScale(float ideal_contents_scale, | |
414 float* contents_scale_x, | |
415 float* contents_scale_y, | |
416 gfx::Size* content_bounds) { | |
417 DCHECK(layer_tree_host_); | |
418 | |
419 *contents_scale_x = 1; | |
420 *contents_scale_y = 1; | |
421 *content_bounds = bounds(); | |
422 } | |
423 | |
424 void Layer::SetMasksToBounds(bool masks_to_bounds) { | |
425 DCHECK(IsPropertyChangeAllowed()); | |
426 if (masks_to_bounds_ == masks_to_bounds) | |
427 return; | |
428 masks_to_bounds_ = masks_to_bounds; | |
429 SetNeedsCommit(); | |
430 } | |
431 | |
432 void Layer::SetMaskLayer(Layer* mask_layer) { | |
433 DCHECK(IsPropertyChangeAllowed()); | |
434 if (mask_layer_.get() == mask_layer) | |
435 return; | |
436 if (mask_layer_.get()) { | |
437 DCHECK_EQ(this, mask_layer_->parent()); | |
438 mask_layer_->RemoveFromParent(); | |
439 } | |
440 mask_layer_ = mask_layer; | |
441 if (mask_layer_.get()) { | |
442 DCHECK(!mask_layer_->parent()); | |
443 mask_layer_->RemoveFromParent(); | |
444 mask_layer_->SetParent(this); | |
445 mask_layer_->SetIsMask(true); | |
446 } | |
447 SetNeedsFullTreeSync(); | |
448 } | |
449 | |
450 void Layer::SetReplicaLayer(Layer* layer) { | |
451 DCHECK(IsPropertyChangeAllowed()); | |
452 if (replica_layer_.get() == layer) | |
453 return; | |
454 if (replica_layer_.get()) { | |
455 DCHECK_EQ(this, replica_layer_->parent()); | |
456 replica_layer_->RemoveFromParent(); | |
457 } | |
458 replica_layer_ = layer; | |
459 if (replica_layer_.get()) { | |
460 DCHECK(!replica_layer_->parent()); | |
461 replica_layer_->RemoveFromParent(); | |
462 replica_layer_->SetParent(this); | |
463 } | |
464 SetNeedsFullTreeSync(); | |
465 } | |
466 | |
467 void Layer::SetFilters(const FilterOperations& filters) { | |
468 DCHECK(IsPropertyChangeAllowed()); | |
469 if (filters_ == filters) | |
470 return; | |
471 filters_ = filters; | |
472 SetNeedsCommit(); | |
473 } | |
474 | |
475 bool Layer::FilterIsAnimating() const { | |
476 return layer_animation_controller_->IsAnimatingProperty(Animation::FILTER); | |
477 } | |
478 | |
479 void Layer::SetBackgroundFilters(const FilterOperations& filters) { | |
480 DCHECK(IsPropertyChangeAllowed()); | |
481 if (background_filters_ == filters) | |
482 return; | |
483 background_filters_ = filters; | |
484 SetNeedsCommit(); | |
485 } | |
486 | |
487 void Layer::SetOpacity(float opacity) { | |
488 DCHECK(IsPropertyChangeAllowed()); | |
489 if (opacity_ == opacity) | |
490 return; | |
491 opacity_ = opacity; | |
492 SetNeedsCommit(); | |
493 } | |
494 | |
495 bool Layer::OpacityIsAnimating() const { | |
496 return layer_animation_controller_->IsAnimatingProperty(Animation::OPACITY); | |
497 } | |
498 | |
499 bool Layer::OpacityCanAnimateOnImplThread() const { | |
500 return false; | |
501 } | |
502 | |
503 void Layer::SetBlendMode(SkXfermode::Mode blend_mode) { | |
504 DCHECK(IsPropertyChangeAllowed()); | |
505 if (blend_mode_ == blend_mode) | |
506 return; | |
507 | |
508 // Allowing only blend modes that are defined in the CSS Compositing standard: | |
509 // http://dev.w3.org/fxtf/compositing-1/#blending | |
510 switch (blend_mode) { | |
511 case SkXfermode::kSrcOver_Mode: | |
512 case SkXfermode::kScreen_Mode: | |
513 case SkXfermode::kOverlay_Mode: | |
514 case SkXfermode::kDarken_Mode: | |
515 case SkXfermode::kLighten_Mode: | |
516 case SkXfermode::kColorDodge_Mode: | |
517 case SkXfermode::kColorBurn_Mode: | |
518 case SkXfermode::kHardLight_Mode: | |
519 case SkXfermode::kSoftLight_Mode: | |
520 case SkXfermode::kDifference_Mode: | |
521 case SkXfermode::kExclusion_Mode: | |
522 case SkXfermode::kMultiply_Mode: | |
523 case SkXfermode::kHue_Mode: | |
524 case SkXfermode::kSaturation_Mode: | |
525 case SkXfermode::kColor_Mode: | |
526 case SkXfermode::kLuminosity_Mode: | |
527 // supported blend modes | |
528 break; | |
529 case SkXfermode::kClear_Mode: | |
530 case SkXfermode::kSrc_Mode: | |
531 case SkXfermode::kDst_Mode: | |
532 case SkXfermode::kDstOver_Mode: | |
533 case SkXfermode::kSrcIn_Mode: | |
534 case SkXfermode::kDstIn_Mode: | |
535 case SkXfermode::kSrcOut_Mode: | |
536 case SkXfermode::kDstOut_Mode: | |
537 case SkXfermode::kSrcATop_Mode: | |
538 case SkXfermode::kDstATop_Mode: | |
539 case SkXfermode::kXor_Mode: | |
540 case SkXfermode::kPlus_Mode: | |
541 case SkXfermode::kModulate_Mode: | |
542 // Porter Duff Compositing Operators are not yet supported | |
543 // http://dev.w3.org/fxtf/compositing-1/#porterduffcompositingoperators | |
544 NOTREACHED(); | |
545 return; | |
546 } | |
547 | |
548 blend_mode_ = blend_mode; | |
549 SetNeedsCommit(); | |
550 } | |
551 | |
552 void Layer::SetIsRootForIsolatedGroup(bool root) { | |
553 DCHECK(IsPropertyChangeAllowed()); | |
554 if (is_root_for_isolated_group_ == root) | |
555 return; | |
556 is_root_for_isolated_group_ = root; | |
557 SetNeedsCommit(); | |
558 } | |
559 | |
560 void Layer::SetContentsOpaque(bool opaque) { | |
561 DCHECK(IsPropertyChangeAllowed()); | |
562 if (contents_opaque_ == opaque) | |
563 return; | |
564 contents_opaque_ = opaque; | |
565 SetNeedsCommit(); | |
566 } | |
567 | |
568 void Layer::SetPosition(const gfx::PointF& position) { | |
569 DCHECK(IsPropertyChangeAllowed()); | |
570 if (position_ == position) | |
571 return; | |
572 position_ = position; | |
573 SetNeedsCommit(); | |
574 } | |
575 | |
576 bool Layer::IsContainerForFixedPositionLayers() const { | |
577 if (!transform_.IsIdentityOrTranslation()) | |
578 return true; | |
579 if (parent_ && !parent_->transform_.IsIdentityOrTranslation()) | |
580 return true; | |
581 return is_container_for_fixed_position_layers_; | |
582 } | |
583 | |
584 void Layer::SetTransform(const gfx::Transform& transform) { | |
585 DCHECK(IsPropertyChangeAllowed()); | |
586 if (transform_ == transform) | |
587 return; | |
588 transform_ = transform; | |
589 transform_is_invertible_ = transform.IsInvertible(); | |
590 SetNeedsCommit(); | |
591 } | |
592 | |
593 void Layer::SetTransformOrigin(const gfx::Point3F& transform_origin) { | |
594 DCHECK(IsPropertyChangeAllowed()); | |
595 if (transform_origin_ == transform_origin) | |
596 return; | |
597 transform_origin_ = transform_origin; | |
598 SetNeedsCommit(); | |
599 } | |
600 | |
601 bool Layer::AnimationsPreserveAxisAlignment() const { | |
602 return layer_animation_controller_->AnimationsPreserveAxisAlignment(); | |
603 } | |
604 | |
605 bool Layer::TransformIsAnimating() const { | |
606 return layer_animation_controller_->IsAnimatingProperty(Animation::TRANSFORM); | |
607 } | |
608 | |
609 void Layer::SetScrollParent(Layer* parent) { | |
610 DCHECK(IsPropertyChangeAllowed()); | |
611 if (scroll_parent_ == parent) | |
612 return; | |
613 | |
614 if (scroll_parent_) | |
615 scroll_parent_->RemoveScrollChild(this); | |
616 | |
617 scroll_parent_ = parent; | |
618 | |
619 if (scroll_parent_) | |
620 scroll_parent_->AddScrollChild(this); | |
621 | |
622 SetNeedsCommit(); | |
623 } | |
624 | |
625 void Layer::AddScrollChild(Layer* child) { | |
626 if (!scroll_children_) | |
627 scroll_children_.reset(new std::set<Layer*>); | |
628 scroll_children_->insert(child); | |
629 SetNeedsCommit(); | |
630 } | |
631 | |
632 void Layer::RemoveScrollChild(Layer* child) { | |
633 scroll_children_->erase(child); | |
634 if (scroll_children_->empty()) | |
635 scroll_children_ = nullptr; | |
636 SetNeedsCommit(); | |
637 } | |
638 | |
639 void Layer::SetClipParent(Layer* ancestor) { | |
640 DCHECK(IsPropertyChangeAllowed()); | |
641 if (clip_parent_ == ancestor) | |
642 return; | |
643 | |
644 if (clip_parent_) | |
645 clip_parent_->RemoveClipChild(this); | |
646 | |
647 clip_parent_ = ancestor; | |
648 | |
649 if (clip_parent_) | |
650 clip_parent_->AddClipChild(this); | |
651 | |
652 SetNeedsCommit(); | |
653 } | |
654 | |
655 void Layer::AddClipChild(Layer* child) { | |
656 if (!clip_children_) | |
657 clip_children_.reset(new std::set<Layer*>); | |
658 clip_children_->insert(child); | |
659 SetNeedsCommit(); | |
660 } | |
661 | |
662 void Layer::RemoveClipChild(Layer* child) { | |
663 clip_children_->erase(child); | |
664 if (clip_children_->empty()) | |
665 clip_children_ = nullptr; | |
666 SetNeedsCommit(); | |
667 } | |
668 | |
669 void Layer::SetScrollOffset(const gfx::ScrollOffset& scroll_offset) { | |
670 DCHECK(IsPropertyChangeAllowed()); | |
671 | |
672 if (scroll_offset_ == scroll_offset) | |
673 return; | |
674 scroll_offset_ = scroll_offset; | |
675 SetNeedsCommit(); | |
676 } | |
677 | |
678 void Layer::SetScrollCompensationAdjustment( | |
679 const gfx::Vector2dF& scroll_compensation_adjustment) { | |
680 if (scroll_compensation_adjustment_ == scroll_compensation_adjustment) | |
681 return; | |
682 scroll_compensation_adjustment_ = scroll_compensation_adjustment; | |
683 SetNeedsCommit(); | |
684 } | |
685 | |
686 gfx::Vector2dF Layer::ScrollCompensationAdjustment() const { | |
687 return scroll_compensation_adjustment_; | |
688 } | |
689 | |
690 void Layer::SetScrollOffsetFromImplSide( | |
691 const gfx::ScrollOffset& scroll_offset) { | |
692 DCHECK(IsPropertyChangeAllowed()); | |
693 // This function only gets called during a BeginMainFrame, so there | |
694 // is no need to call SetNeedsUpdate here. | |
695 DCHECK(layer_tree_host_ && layer_tree_host_->CommitRequested()); | |
696 if (scroll_offset_ == scroll_offset) | |
697 return; | |
698 scroll_offset_ = scroll_offset; | |
699 SetNeedsPushProperties(); | |
700 if (!did_scroll_callback_.is_null()) | |
701 did_scroll_callback_.Run(); | |
702 // The callback could potentially change the layer structure: | |
703 // "this" may have been destroyed during the process. | |
704 } | |
705 | |
706 void Layer::SetScrollClipLayerId(int clip_layer_id) { | |
707 DCHECK(IsPropertyChangeAllowed()); | |
708 if (scroll_clip_layer_id_ == clip_layer_id) | |
709 return; | |
710 scroll_clip_layer_id_ = clip_layer_id; | |
711 SetNeedsCommit(); | |
712 } | |
713 | |
714 void Layer::SetUserScrollable(bool horizontal, bool vertical) { | |
715 DCHECK(IsPropertyChangeAllowed()); | |
716 if (user_scrollable_horizontal_ == horizontal && | |
717 user_scrollable_vertical_ == vertical) | |
718 return; | |
719 user_scrollable_horizontal_ = horizontal; | |
720 user_scrollable_vertical_ = vertical; | |
721 SetNeedsCommit(); | |
722 } | |
723 | |
724 void Layer::SetShouldScrollOnMainThread(bool should_scroll_on_main_thread) { | |
725 DCHECK(IsPropertyChangeAllowed()); | |
726 if (should_scroll_on_main_thread_ == should_scroll_on_main_thread) | |
727 return; | |
728 should_scroll_on_main_thread_ = should_scroll_on_main_thread; | |
729 SetNeedsCommit(); | |
730 } | |
731 | |
732 void Layer::SetHaveWheelEventHandlers(bool have_wheel_event_handlers) { | |
733 DCHECK(IsPropertyChangeAllowed()); | |
734 if (have_wheel_event_handlers_ == have_wheel_event_handlers) | |
735 return; | |
736 have_wheel_event_handlers_ = have_wheel_event_handlers; | |
737 SetNeedsCommit(); | |
738 } | |
739 | |
740 void Layer::SetHaveScrollEventHandlers(bool have_scroll_event_handlers) { | |
741 DCHECK(IsPropertyChangeAllowed()); | |
742 if (have_scroll_event_handlers_ == have_scroll_event_handlers) | |
743 return; | |
744 have_scroll_event_handlers_ = have_scroll_event_handlers; | |
745 SetNeedsCommit(); | |
746 } | |
747 | |
748 void Layer::SetNonFastScrollableRegion(const Region& region) { | |
749 DCHECK(IsPropertyChangeAllowed()); | |
750 if (non_fast_scrollable_region_ == region) | |
751 return; | |
752 non_fast_scrollable_region_ = region; | |
753 SetNeedsCommit(); | |
754 } | |
755 | |
756 void Layer::SetTouchEventHandlerRegion(const Region& region) { | |
757 DCHECK(IsPropertyChangeAllowed()); | |
758 if (touch_event_handler_region_ == region) | |
759 return; | |
760 touch_event_handler_region_ = region; | |
761 SetNeedsCommit(); | |
762 } | |
763 | |
764 void Layer::SetScrollBlocksOn(ScrollBlocksOn scroll_blocks_on) { | |
765 DCHECK(IsPropertyChangeAllowed()); | |
766 if (scroll_blocks_on_ == scroll_blocks_on) | |
767 return; | |
768 scroll_blocks_on_ = scroll_blocks_on; | |
769 SetNeedsCommit(); | |
770 } | |
771 | |
772 void Layer::SetDrawCheckerboardForMissingTiles(bool checkerboard) { | |
773 DCHECK(IsPropertyChangeAllowed()); | |
774 if (draw_checkerboard_for_missing_tiles_ == checkerboard) | |
775 return; | |
776 draw_checkerboard_for_missing_tiles_ = checkerboard; | |
777 SetNeedsCommit(); | |
778 } | |
779 | |
780 void Layer::SetForceRenderSurface(bool force) { | |
781 DCHECK(IsPropertyChangeAllowed()); | |
782 if (force_render_surface_ == force) | |
783 return; | |
784 force_render_surface_ = force; | |
785 SetNeedsCommit(); | |
786 } | |
787 | |
788 void Layer::SetDoubleSided(bool double_sided) { | |
789 DCHECK(IsPropertyChangeAllowed()); | |
790 if (double_sided_ == double_sided) | |
791 return; | |
792 double_sided_ = double_sided; | |
793 SetNeedsCommit(); | |
794 } | |
795 | |
796 void Layer::Set3dSortingContextId(int id) { | |
797 DCHECK(IsPropertyChangeAllowed()); | |
798 if (id == sorting_context_id_) | |
799 return; | |
800 sorting_context_id_ = id; | |
801 SetNeedsCommit(); | |
802 } | |
803 | |
804 void Layer::SetShouldFlattenTransform(bool should_flatten) { | |
805 DCHECK(IsPropertyChangeAllowed()); | |
806 if (should_flatten_transform_ == should_flatten) | |
807 return; | |
808 should_flatten_transform_ = should_flatten; | |
809 SetNeedsCommit(); | |
810 } | |
811 | |
812 void Layer::SetIsDrawable(bool is_drawable) { | |
813 DCHECK(IsPropertyChangeAllowed()); | |
814 if (is_drawable_ == is_drawable) | |
815 return; | |
816 | |
817 is_drawable_ = is_drawable; | |
818 UpdateDrawsContent(HasDrawableContent()); | |
819 } | |
820 | |
821 void Layer::SetHideLayerAndSubtree(bool hide) { | |
822 DCHECK(IsPropertyChangeAllowed()); | |
823 if (hide_layer_and_subtree_ == hide) | |
824 return; | |
825 | |
826 hide_layer_and_subtree_ = hide; | |
827 SetNeedsCommit(); | |
828 } | |
829 | |
830 void Layer::SetNeedsDisplayRect(const gfx::Rect& dirty_rect) { | |
831 if (dirty_rect.IsEmpty()) | |
832 return; | |
833 | |
834 SetNeedsPushProperties(); | |
835 update_rect_.Union(dirty_rect); | |
836 | |
837 if (DrawsContent()) | |
838 SetNeedsUpdate(); | |
839 } | |
840 | |
841 bool Layer::DescendantIsFixedToContainerLayer() const { | |
842 for (size_t i = 0; i < children_.size(); ++i) { | |
843 if (children_[i]->position_constraint_.is_fixed_position() || | |
844 children_[i]->DescendantIsFixedToContainerLayer()) | |
845 return true; | |
846 } | |
847 return false; | |
848 } | |
849 | |
850 void Layer::SetIsContainerForFixedPositionLayers(bool container) { | |
851 if (is_container_for_fixed_position_layers_ == container) | |
852 return; | |
853 is_container_for_fixed_position_layers_ = container; | |
854 | |
855 if (layer_tree_host_ && layer_tree_host_->CommitRequested()) | |
856 return; | |
857 | |
858 // Only request a commit if we have a fixed positioned descendant. | |
859 if (DescendantIsFixedToContainerLayer()) | |
860 SetNeedsCommit(); | |
861 } | |
862 | |
863 void Layer::SetPositionConstraint(const LayerPositionConstraint& constraint) { | |
864 DCHECK(IsPropertyChangeAllowed()); | |
865 if (position_constraint_ == constraint) | |
866 return; | |
867 position_constraint_ = constraint; | |
868 SetNeedsCommit(); | |
869 } | |
870 | |
871 static void RunCopyCallbackOnMainThread(scoped_ptr<CopyOutputRequest> request, | |
872 scoped_ptr<CopyOutputResult> result) { | |
873 request->SendResult(result.Pass()); | |
874 } | |
875 | |
876 static void PostCopyCallbackToMainThread( | |
877 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner, | |
878 scoped_ptr<CopyOutputRequest> request, | |
879 scoped_ptr<CopyOutputResult> result) { | |
880 main_thread_task_runner->PostTask(FROM_HERE, | |
881 base::Bind(&RunCopyCallbackOnMainThread, | |
882 base::Passed(&request), | |
883 base::Passed(&result))); | |
884 } | |
885 | |
886 void Layer::PushPropertiesTo(LayerImpl* layer) { | |
887 DCHECK(layer_tree_host_); | |
888 | |
889 // If we did not SavePaintProperties() for the layer this frame, then push the | |
890 // real property values, not the paint property values. | |
891 bool use_paint_properties = paint_properties_.source_frame_number == | |
892 layer_tree_host_->source_frame_number(); | |
893 | |
894 layer->SetTransformOrigin(transform_origin_); | |
895 layer->SetBackgroundColor(background_color_); | |
896 layer->SetBounds(use_paint_properties ? paint_properties_.bounds | |
897 : bounds_); | |
898 layer->SetContentBounds(content_bounds()); | |
899 layer->SetContentsScale(contents_scale_x(), contents_scale_y()); | |
900 | |
901 if (frame_viewer_instrumentation::IsTracingLayerTreeSnapshots()) | |
902 layer->SetDebugInfo(TakeDebugInfo()); | |
903 | |
904 layer->SetDoubleSided(double_sided_); | |
905 layer->SetDrawCheckerboardForMissingTiles( | |
906 draw_checkerboard_for_missing_tiles_); | |
907 layer->SetDrawsContent(DrawsContent()); | |
908 layer->SetHideLayerAndSubtree(hide_layer_and_subtree_); | |
909 layer->SetHasRenderSurface(has_render_surface_ || layer->HasCopyRequest()); | |
910 if (!layer->FilterIsAnimatingOnImplOnly() && !FilterIsAnimating()) | |
911 layer->SetFilters(filters_); | |
912 DCHECK(!(FilterIsAnimating() && layer->FilterIsAnimatingOnImplOnly())); | |
913 layer->SetBackgroundFilters(background_filters()); | |
914 layer->SetMasksToBounds(masks_to_bounds_); | |
915 layer->SetShouldScrollOnMainThread(should_scroll_on_main_thread_); | |
916 layer->SetHaveWheelEventHandlers(have_wheel_event_handlers_); | |
917 layer->SetHaveScrollEventHandlers(have_scroll_event_handlers_); | |
918 layer->SetNonFastScrollableRegion(non_fast_scrollable_region_); | |
919 layer->SetTouchEventHandlerRegion(touch_event_handler_region_); | |
920 layer->SetScrollBlocksOn(scroll_blocks_on_); | |
921 layer->SetContentsOpaque(contents_opaque_); | |
922 if (!layer->OpacityIsAnimatingOnImplOnly() && !OpacityIsAnimating()) | |
923 layer->SetOpacity(opacity_); | |
924 DCHECK(!(OpacityIsAnimating() && layer->OpacityIsAnimatingOnImplOnly())); | |
925 layer->SetBlendMode(blend_mode_); | |
926 layer->SetIsRootForIsolatedGroup(is_root_for_isolated_group_); | |
927 layer->SetPosition(position_); | |
928 layer->SetIsContainerForFixedPositionLayers( | |
929 IsContainerForFixedPositionLayers()); | |
930 layer->SetPositionConstraint(position_constraint_); | |
931 layer->SetShouldFlattenTransform(should_flatten_transform_); | |
932 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); | |
933 if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating()) | |
934 layer->SetTransformAndInvertibility(transform_, transform_is_invertible_); | |
935 DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly())); | |
936 layer->Set3dSortingContextId(sorting_context_id_); | |
937 layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_); | |
938 | |
939 layer->SetScrollClipLayer(scroll_clip_layer_id_); | |
940 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); | |
941 layer->set_user_scrollable_vertical(user_scrollable_vertical_); | |
942 | |
943 LayerImpl* scroll_parent = nullptr; | |
944 if (scroll_parent_) { | |
945 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); | |
946 DCHECK(scroll_parent); | |
947 } | |
948 | |
949 layer->SetScrollParent(scroll_parent); | |
950 if (scroll_children_) { | |
951 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>; | |
952 for (std::set<Layer*>::iterator it = scroll_children_->begin(); | |
953 it != scroll_children_->end(); | |
954 ++it) { | |
955 DCHECK_EQ((*it)->scroll_parent(), this); | |
956 LayerImpl* scroll_child = | |
957 layer->layer_tree_impl()->LayerById((*it)->id()); | |
958 DCHECK(scroll_child); | |
959 scroll_children->insert(scroll_child); | |
960 } | |
961 layer->SetScrollChildren(scroll_children); | |
962 } else { | |
963 layer->SetScrollChildren(nullptr); | |
964 } | |
965 | |
966 LayerImpl* clip_parent = nullptr; | |
967 if (clip_parent_) { | |
968 clip_parent = | |
969 layer->layer_tree_impl()->LayerById(clip_parent_->id()); | |
970 DCHECK(clip_parent); | |
971 } | |
972 | |
973 layer->SetClipParent(clip_parent); | |
974 if (clip_children_) { | |
975 std::set<LayerImpl*>* clip_children = new std::set<LayerImpl*>; | |
976 for (std::set<Layer*>::iterator it = clip_children_->begin(); | |
977 it != clip_children_->end(); ++it) { | |
978 DCHECK_EQ((*it)->clip_parent(), this); | |
979 LayerImpl* clip_child = layer->layer_tree_impl()->LayerById((*it)->id()); | |
980 DCHECK(clip_child); | |
981 clip_children->insert(clip_child); | |
982 } | |
983 layer->SetClipChildren(clip_children); | |
984 } else { | |
985 layer->SetClipChildren(nullptr); | |
986 } | |
987 | |
988 // When a scroll offset animation is interrupted the new scroll position on | |
989 // the pending tree will clobber any impl-side scrolling occuring on the | |
990 // active tree. To do so, avoid scrolling the pending tree along with it | |
991 // instead of trying to undo that scrolling later. | |
992 if (layer_animation_controller_->scroll_offset_animation_was_interrupted()) | |
993 layer->PushScrollOffsetFromMainThreadAndClobberActiveValue(scroll_offset_); | |
994 else | |
995 layer->PushScrollOffsetFromMainThread(scroll_offset_); | |
996 layer->SetScrollCompensationAdjustment(ScrollCompensationAdjustment()); | |
997 | |
998 // Wrap the copy_requests_ in a PostTask to the main thread. | |
999 ScopedPtrVector<CopyOutputRequest> main_thread_copy_requests; | |
1000 for (ScopedPtrVector<CopyOutputRequest>::iterator it = copy_requests_.begin(); | |
1001 it != copy_requests_.end(); | |
1002 ++it) { | |
1003 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner = | |
1004 layer_tree_host()->proxy()->MainThreadTaskRunner(); | |
1005 scoped_ptr<CopyOutputRequest> original_request = copy_requests_.take(it); | |
1006 const CopyOutputRequest& original_request_ref = *original_request; | |
1007 scoped_ptr<CopyOutputRequest> main_thread_request = | |
1008 CopyOutputRequest::CreateRelayRequest( | |
1009 original_request_ref, | |
1010 base::Bind(&PostCopyCallbackToMainThread, | |
1011 main_thread_task_runner, | |
1012 base::Passed(&original_request))); | |
1013 main_thread_copy_requests.push_back(main_thread_request.Pass()); | |
1014 } | |
1015 copy_requests_.clear(); | |
1016 layer->PassCopyRequests(&main_thread_copy_requests); | |
1017 | |
1018 // If the main thread commits multiple times before the impl thread actually | |
1019 // draws, then damage tracking will become incorrect if we simply clobber the | |
1020 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e. | |
1021 // union) any update changes that have occurred on the main thread. | |
1022 update_rect_.Union(layer->update_rect()); | |
1023 layer->SetUpdateRect(update_rect_); | |
1024 | |
1025 layer->SetStackingOrderChanged(stacking_order_changed_); | |
1026 | |
1027 layer_animation_controller_->PushAnimationUpdatesTo( | |
1028 layer->layer_animation_controller()); | |
1029 | |
1030 if (frame_timing_requests_dirty_) { | |
1031 layer->PassFrameTimingRequests(&frame_timing_requests_); | |
1032 frame_timing_requests_dirty_ = false; | |
1033 } | |
1034 | |
1035 // Reset any state that should be cleared for the next update. | |
1036 stacking_order_changed_ = false; | |
1037 update_rect_ = gfx::Rect(); | |
1038 | |
1039 needs_push_properties_ = false; | |
1040 num_dependents_need_push_properties_ = 0; | |
1041 } | |
1042 | |
1043 scoped_ptr<LayerImpl> Layer::CreateLayerImpl(LayerTreeImpl* tree_impl) { | |
1044 return LayerImpl::Create(tree_impl, layer_id_, | |
1045 new LayerImpl::SyncedScrollOffset); | |
1046 } | |
1047 | |
1048 bool Layer::DrawsContent() const { | |
1049 return draws_content_; | |
1050 } | |
1051 | |
1052 bool Layer::HasDrawableContent() const { | |
1053 return is_drawable_; | |
1054 } | |
1055 | |
1056 void Layer::UpdateDrawsContent(bool has_drawable_content) { | |
1057 bool draws_content = has_drawable_content; | |
1058 DCHECK(is_drawable_ || !has_drawable_content); | |
1059 if (draws_content == draws_content_) | |
1060 return; | |
1061 | |
1062 if (HasDelegatedContent()) { | |
1063 // Layers with delegated content need to be treated as if they have as | |
1064 // many children as the number of layers they own delegated quads for. | |
1065 // Since we don't know this number right now, we choose one that acts like | |
1066 // infinity for our purposes. | |
1067 AddDrawableDescendants(draws_content ? 1000 : -1000); | |
1068 } | |
1069 | |
1070 if (parent()) | |
1071 parent()->AddDrawableDescendants(draws_content ? 1 : -1); | |
1072 | |
1073 draws_content_ = draws_content; | |
1074 SetNeedsCommit(); | |
1075 } | |
1076 | |
1077 int Layer::NumDescendantsThatDrawContent() const { | |
1078 return num_descendants_that_draw_content_; | |
1079 } | |
1080 | |
1081 void Layer::SavePaintProperties() { | |
1082 DCHECK(layer_tree_host_); | |
1083 | |
1084 // TODO(reveman): Save all layer properties that we depend on not | |
1085 // changing until PushProperties() has been called. crbug.com/231016 | |
1086 paint_properties_.bounds = bounds_; | |
1087 paint_properties_.source_frame_number = | |
1088 layer_tree_host_->source_frame_number(); | |
1089 } | |
1090 | |
1091 bool Layer::Update(ResourceUpdateQueue* queue, | |
1092 const OcclusionTracker<Layer>* occlusion) { | |
1093 DCHECK(layer_tree_host_); | |
1094 DCHECK_EQ(layer_tree_host_->source_frame_number(), | |
1095 paint_properties_.source_frame_number) << | |
1096 "SavePaintProperties must be called for any layer that is painted."; | |
1097 return false; | |
1098 } | |
1099 | |
1100 bool Layer::NeedMoreUpdates() { | |
1101 return false; | |
1102 } | |
1103 | |
1104 bool Layer::IsSuitableForGpuRasterization() const { | |
1105 return true; | |
1106 } | |
1107 | |
1108 scoped_refptr<base::trace_event::ConvertableToTraceFormat> | |
1109 Layer::TakeDebugInfo() { | |
1110 if (client_) | |
1111 return client_->TakeDebugInfo(); | |
1112 else | |
1113 return nullptr; | |
1114 } | |
1115 | |
1116 void Layer::SetHasRenderSurface(bool has_render_surface) { | |
1117 if (has_render_surface_ == has_render_surface) | |
1118 return; | |
1119 has_render_surface_ = has_render_surface; | |
1120 // We do not need SetNeedsCommit here, since this is only ever called | |
1121 // during a commit, from CalculateDrawProperties. | |
1122 SetNeedsPushProperties(); | |
1123 } | |
1124 | |
1125 void Layer::CreateRenderSurface() { | |
1126 DCHECK(!render_surface_); | |
1127 render_surface_ = make_scoped_ptr(new RenderSurface(this)); | |
1128 } | |
1129 | |
1130 void Layer::ClearRenderSurface() { | |
1131 render_surface_ = nullptr; | |
1132 } | |
1133 | |
1134 void Layer::ClearRenderSurfaceLayerList() { | |
1135 if (render_surface_) | |
1136 render_surface_->ClearLayerLists(); | |
1137 } | |
1138 | |
1139 gfx::ScrollOffset Layer::ScrollOffsetForAnimation() const { | |
1140 return CurrentScrollOffset(); | |
1141 } | |
1142 | |
1143 // On<Property>Animated is called due to an ongoing accelerated animation. | |
1144 // Since this animation is also being run on the compositor thread, there | |
1145 // is no need to request a commit to push this value over, so the value is | |
1146 // set directly rather than by calling Set<Property>. | |
1147 void Layer::OnFilterAnimated(const FilterOperations& filters) { | |
1148 filters_ = filters; | |
1149 } | |
1150 | |
1151 void Layer::OnOpacityAnimated(float opacity) { | |
1152 opacity_ = opacity; | |
1153 } | |
1154 | |
1155 void Layer::OnTransformAnimated(const gfx::Transform& transform) { | |
1156 if (transform_ == transform) | |
1157 return; | |
1158 transform_ = transform; | |
1159 transform_is_invertible_ = transform.IsInvertible(); | |
1160 } | |
1161 | |
1162 void Layer::OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) { | |
1163 // Do nothing. Scroll deltas will be sent from the compositor thread back | |
1164 // to the main thread in the same manner as during non-animated | |
1165 // compositor-driven scrolling. | |
1166 } | |
1167 | |
1168 void Layer::OnAnimationWaitingForDeletion() { | |
1169 // Animations are only deleted during PushProperties. | |
1170 SetNeedsPushProperties(); | |
1171 } | |
1172 | |
1173 bool Layer::IsActive() const { | |
1174 return true; | |
1175 } | |
1176 | |
1177 bool Layer::AddAnimation(scoped_ptr <Animation> animation) { | |
1178 if (!layer_animation_controller_->animation_registrar()) | |
1179 return false; | |
1180 | |
1181 if (animation->target_property() == Animation::SCROLL_OFFSET && | |
1182 !layer_animation_controller_->animation_registrar() | |
1183 ->supports_scroll_animations()) | |
1184 return false; | |
1185 | |
1186 UMA_HISTOGRAM_BOOLEAN("Renderer.AnimationAddedToOrphanLayer", | |
1187 !layer_tree_host_); | |
1188 layer_animation_controller_->AddAnimation(animation.Pass()); | |
1189 SetNeedsCommit(); | |
1190 return true; | |
1191 } | |
1192 | |
1193 void Layer::PauseAnimation(int animation_id, double time_offset) { | |
1194 layer_animation_controller_->PauseAnimation( | |
1195 animation_id, base::TimeDelta::FromSecondsD(time_offset)); | |
1196 SetNeedsCommit(); | |
1197 } | |
1198 | |
1199 void Layer::RemoveAnimation(int animation_id) { | |
1200 layer_animation_controller_->RemoveAnimation(animation_id); | |
1201 SetNeedsCommit(); | |
1202 } | |
1203 | |
1204 void Layer::RemoveAnimation(int animation_id, | |
1205 Animation::TargetProperty property) { | |
1206 layer_animation_controller_->RemoveAnimation(animation_id, property); | |
1207 SetNeedsCommit(); | |
1208 } | |
1209 | |
1210 void Layer::SetLayerAnimationControllerForTest( | |
1211 scoped_refptr<LayerAnimationController> controller) { | |
1212 layer_animation_controller_->RemoveValueObserver(this); | |
1213 layer_animation_controller_ = controller; | |
1214 layer_animation_controller_->AddValueObserver(this); | |
1215 SetNeedsCommit(); | |
1216 } | |
1217 | |
1218 bool Layer::HasActiveAnimation() const { | |
1219 return layer_animation_controller_->HasActiveAnimation(); | |
1220 } | |
1221 | |
1222 void Layer::AddLayerAnimationEventObserver( | |
1223 LayerAnimationEventObserver* animation_observer) { | |
1224 layer_animation_controller_->AddEventObserver(animation_observer); | |
1225 } | |
1226 | |
1227 void Layer::RemoveLayerAnimationEventObserver( | |
1228 LayerAnimationEventObserver* animation_observer) { | |
1229 layer_animation_controller_->RemoveEventObserver(animation_observer); | |
1230 } | |
1231 | |
1232 SimpleEnclosedRegion Layer::VisibleContentOpaqueRegion() const { | |
1233 if (contents_opaque()) | |
1234 return SimpleEnclosedRegion(visible_content_rect()); | |
1235 return SimpleEnclosedRegion(); | |
1236 } | |
1237 | |
1238 ScrollbarLayerInterface* Layer::ToScrollbarLayer() { | |
1239 return nullptr; | |
1240 } | |
1241 | |
1242 RenderingStatsInstrumentation* Layer::rendering_stats_instrumentation() const { | |
1243 return layer_tree_host_->rendering_stats_instrumentation(); | |
1244 } | |
1245 | |
1246 void Layer::RemoveFromScrollTree() { | |
1247 if (scroll_children_.get()) { | |
1248 std::set<Layer*> copy = *scroll_children_; | |
1249 for (std::set<Layer*>::iterator it = copy.begin(); it != copy.end(); ++it) | |
1250 (*it)->SetScrollParent(nullptr); | |
1251 } | |
1252 | |
1253 DCHECK(!scroll_children_); | |
1254 SetScrollParent(nullptr); | |
1255 } | |
1256 | |
1257 void Layer::RemoveFromClipTree() { | |
1258 if (clip_children_.get()) { | |
1259 std::set<Layer*> copy = *clip_children_; | |
1260 for (std::set<Layer*>::iterator it = copy.begin(); it != copy.end(); ++it) | |
1261 (*it)->SetClipParent(nullptr); | |
1262 } | |
1263 | |
1264 DCHECK(!clip_children_); | |
1265 SetClipParent(nullptr); | |
1266 } | |
1267 | |
1268 void Layer::AddDrawableDescendants(int num) { | |
1269 DCHECK_GE(num_descendants_that_draw_content_, 0); | |
1270 DCHECK_GE(num_descendants_that_draw_content_ + num, 0); | |
1271 if (num == 0) | |
1272 return; | |
1273 num_descendants_that_draw_content_ += num; | |
1274 SetNeedsCommit(); | |
1275 if (parent()) | |
1276 parent()->AddDrawableDescendants(num); | |
1277 } | |
1278 | |
1279 void Layer::RunMicroBenchmark(MicroBenchmark* benchmark) { | |
1280 benchmark->RunOnLayer(this); | |
1281 } | |
1282 | |
1283 bool Layer::HasDelegatedContent() const { | |
1284 return false; | |
1285 } | |
1286 | |
1287 gfx::Transform Layer::screen_space_transform_from_property_trees( | |
1288 const TransformTree& tree) const { | |
1289 gfx::Transform xform(1, 0, 0, 1, offset_to_transform_parent().x(), | |
1290 offset_to_transform_parent().y()); | |
1291 if (transform_tree_index() >= 0) { | |
1292 gfx::Transform ssxform = tree.Node(transform_tree_index())->data.to_screen; | |
1293 xform.ConcatTransform(ssxform); | |
1294 if (should_flatten_transform_from_property_tree_) | |
1295 xform.FlattenTo2d(); | |
1296 } | |
1297 xform.Scale(1.0 / contents_scale_x(), 1.0 / contents_scale_y()); | |
1298 return xform; | |
1299 } | |
1300 | |
1301 gfx::Transform Layer::draw_transform_from_property_trees( | |
1302 const TransformTree& tree) const { | |
1303 const TransformNode* node = tree.Node(transform_tree_index()); | |
1304 // TODO(vollick): ultimately we'll need to find this information (whether or | |
1305 // not we establish a render surface) somewhere other than the layer. | |
1306 const TransformNode* target_node = | |
1307 has_render_surface_ ? node : tree.Node(node->data.content_target_id); | |
1308 | |
1309 gfx::Transform xform; | |
1310 const bool owns_non_root_surface = parent() && render_surface(); | |
1311 if (!owns_non_root_surface) { | |
1312 // If you're not the root, or you don't own a surface, you need to apply | |
1313 // your local offset. | |
1314 xform = node->data.to_target; | |
1315 if (should_flatten_transform_from_property_tree_) | |
1316 xform.FlattenTo2d(); | |
1317 xform.Translate(offset_to_transform_parent().x(), | |
1318 offset_to_transform_parent().y()); | |
1319 // A fixed-position layer does not necessarily have the same render target | |
1320 // as its transform node. In particular, its transform node may be an | |
1321 // ancestor of its render target's transform node. For example, given layer | |
1322 // tree R->S->F, suppose F is fixed and S owns a render surface (e.g., say S | |
1323 // has opacity 0.9 and both S and F draw content). Then F's transform node | |
1324 // is the root node, so the target space transform from that node is defined | |
1325 // with respect to the root render surface. But F will render to S's | |
1326 // surface, so must apply a change of basis transform to the target space | |
1327 // transform from its transform node. | |
1328 if (position_constraint_.is_fixed_position()) { | |
1329 gfx::Transform tree_target_to_render_target; | |
1330 tree.ComputeTransform(node->data.content_target_id, | |
1331 render_target()->transform_tree_index(), | |
1332 &tree_target_to_render_target); | |
1333 xform.ConcatTransform(tree_target_to_render_target); | |
1334 } | |
1335 } else { | |
1336 // Surfaces need to apply their sublayer scale. | |
1337 xform.Scale(target_node->data.sublayer_scale.x(), | |
1338 target_node->data.sublayer_scale.y()); | |
1339 } | |
1340 xform.Scale(1.0 / contents_scale_x(), 1.0 / contents_scale_y()); | |
1341 return xform; | |
1342 } | |
1343 | |
1344 float Layer::DrawOpacityFromPropertyTrees(const OpacityTree& tree) const { | |
1345 if (!render_target()) | |
1346 return 0.f; | |
1347 | |
1348 const OpacityNode* target_node = | |
1349 tree.Node(render_target()->opacity_tree_index()); | |
1350 const OpacityNode* node = tree.Node(opacity_tree_index()); | |
1351 if (node == target_node) | |
1352 return 1.f; | |
1353 | |
1354 float draw_opacity = 1.f; | |
1355 while (node != target_node) { | |
1356 draw_opacity *= node->data; | |
1357 node = tree.parent(node); | |
1358 } | |
1359 return draw_opacity; | |
1360 } | |
1361 | |
1362 void Layer::SetFrameTimingRequests( | |
1363 const std::vector<FrameTimingRequest>& requests) { | |
1364 frame_timing_requests_ = requests; | |
1365 frame_timing_requests_dirty_ = true; | |
1366 SetNeedsCommit(); | |
1367 } | |
1368 | |
1369 void Layer::DidBeginTracing() { | |
1370 // We'll be dumping layer trees as part of trace, so make sure | |
1371 // PushPropertiesTo() propagates layer debug info to the impl | |
1372 // side -- otherwise this won't happen for the the layers that | |
1373 // remain unchanged since tracing started. | |
1374 SetNeedsPushProperties(); | |
1375 } | |
1376 | |
1377 } // namespace cc | |
OLD | NEW |