Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: cc/layer.cc

Issue 12603013: Part 10 of cc/ directory shuffles: layers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/layer.h ('k') | cc/layer_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/layer.h"
6
7 #include "cc/animation/animation.h"
8 #include "cc/animation/animation_events.h"
9 #include "cc/animation/layer_animation_controller.h"
10 #include "cc/layer_impl.h"
11 #include "cc/trees/layer_tree_host.h"
12 #include "cc/trees/layer_tree_impl.h"
13 #include "third_party/WebKit/Source/Platform/chromium/public/WebAnimationDelegat e.h"
14 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayerScrollClien t.h"
15 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h"
16 #include "third_party/skia/include/core/SkImageFilter.h"
17 #include "ui/gfx/rect_conversions.h"
18
19 namespace cc {
20
21 static int s_next_layer_id = 1;
22
23 scoped_refptr<Layer> Layer::Create() {
24 return make_scoped_refptr(new Layer());
25 }
26
27 Layer::Layer()
28 : needs_display_(false),
29 stacking_order_changed_(false),
30 layer_id_(s_next_layer_id++),
31 ignore_set_needs_commit_(false),
32 parent_(NULL),
33 layer_tree_host_(NULL),
34 scrollable_(false),
35 should_scroll_on_main_thread_(false),
36 have_wheel_event_handlers_(false),
37 anchor_point_(0.5f, 0.5f),
38 background_color_(0),
39 opacity_(1.f),
40 anchor_point_z_(0.f),
41 is_container_for_fixed_position_layers_(false),
42 fixed_to_container_layer_(false),
43 is_drawable_(false),
44 masks_to_bounds_(false),
45 contents_opaque_(false),
46 double_sided_(true),
47 preserves_3d_(false),
48 use_parent_backface_visibility_(false),
49 draw_checkerboard_for_missing_tiles_(false),
50 force_render_surface_(false),
51 replica_layer_(NULL),
52 raster_scale_(1.f),
53 automatically_compute_raster_scale_(false),
54 bounds_contain_page_scale_(false),
55 layer_animation_delegate_(NULL),
56 layer_scroll_client_(NULL) {
57 if (layer_id_ < 0) {
58 s_next_layer_id = 1;
59 layer_id_ = s_next_layer_id++;
60 }
61
62 layer_animation_controller_ = LayerAnimationController::Create(layer_id_);
63 layer_animation_controller_->AddObserver(this);
64 AddLayerAnimationEventObserver(layer_animation_controller_.get());
65 }
66
67 Layer::~Layer() {
68 // Our parent should be holding a reference to us so there should be no
69 // way for us to be destroyed while we still have a parent.
70 DCHECK(!parent());
71
72 layer_animation_controller_->RemoveObserver(this);
73
74 // Remove the parent reference from all children and dependents.
75 RemoveAllChildren();
76 if (mask_layer_) {
77 DCHECK_EQ(this, mask_layer_->parent());
78 mask_layer_->RemoveFromParent();
79 }
80 if (replica_layer_) {
81 DCHECK_EQ(this, replica_layer_->parent());
82 replica_layer_->RemoveFromParent();
83 }
84 }
85
86 void Layer::SetLayerTreeHost(LayerTreeHost* host) {
87 if (layer_tree_host_ == host)
88 return;
89
90 layer_tree_host_ = host;
91
92 for (size_t i = 0; i < children_.size(); ++i)
93 children_[i]->SetLayerTreeHost(host);
94
95 if (mask_layer_)
96 mask_layer_->SetLayerTreeHost(host);
97 if (replica_layer_)
98 replica_layer_->SetLayerTreeHost(host);
99
100 layer_animation_controller_->SetAnimationRegistrar(
101 host ? host->animation_registrar() : NULL);
102
103 if (host && layer_animation_controller_->has_any_animation())
104 host->SetNeedsCommit();
105 if (host &&
106 (!filters_.isEmpty() || !background_filters_.isEmpty() || filter_))
107 layer_tree_host_->set_needs_filter_context();
108
109 }
110
111 void Layer::SetNeedsCommit() {
112 if (ignore_set_needs_commit_)
113 return;
114 if (layer_tree_host_)
115 layer_tree_host_->SetNeedsCommit();
116 }
117
118 void Layer::SetNeedsFullTreeSync() {
119 if (layer_tree_host_)
120 layer_tree_host_->SetNeedsFullTreeSync();
121 }
122
123 gfx::Rect Layer::LayerRectToContentRect(const gfx::RectF& layer_rect) const {
124 gfx::RectF content_rect =
125 gfx::ScaleRect(layer_rect, contents_scale_x(), contents_scale_y());
126 // Intersect with content rect to avoid the extra pixel because for some
127 // values x and y, ceil((x / y) * y) may be x + 1.
128 content_rect.Intersect(gfx::Rect(gfx::Point(), content_bounds()));
129 return gfx::ToEnclosingRect(content_rect);
130 }
131
132 bool Layer::BlocksPendingCommit() const {
133 return false;
134 }
135
136 bool Layer::CanClipSelf() const {
137 return false;
138 }
139
140 bool Layer::BlocksPendingCommitRecursive() const {
141 if (BlocksPendingCommit())
142 return true;
143 if (mask_layer() && mask_layer()->BlocksPendingCommitRecursive())
144 return true;
145 if (replica_layer() && replica_layer()->BlocksPendingCommitRecursive())
146 return true;
147 for (size_t i = 0; i < children_.size(); ++i) {
148 if (children_[i]->BlocksPendingCommitRecursive())
149 return true;
150 }
151 return false;
152 }
153
154 void Layer::SetParent(Layer* layer) {
155 DCHECK(!layer || !layer->HasAncestor(this));
156 parent_ = layer;
157 SetLayerTreeHost(parent_ ? parent_->layer_tree_host() : NULL);
158
159 ForceAutomaticRasterScaleToBeRecomputed();
160 if (mask_layer_)
161 mask_layer_->ForceAutomaticRasterScaleToBeRecomputed();
162 if (replica_layer_ && replica_layer_->mask_layer_)
163 replica_layer_->mask_layer_->ForceAutomaticRasterScaleToBeRecomputed();
164 }
165
166 bool Layer::HasAncestor(Layer* ancestor) const {
167 for (const Layer* layer = parent(); layer; layer = layer->parent()) {
168 if (layer == ancestor)
169 return true;
170 }
171 return false;
172 }
173
174 void Layer::AddChild(scoped_refptr<Layer> child) {
175 InsertChild(child, children_.size());
176 }
177
178 void Layer::InsertChild(scoped_refptr<Layer> child, size_t index) {
179 child->RemoveFromParent();
180 child->SetParent(this);
181 child->stacking_order_changed_ = true;
182
183 index = std::min(index, children_.size());
184 children_.insert(children_.begin() + index, child);
185 SetNeedsFullTreeSync();
186 }
187
188 void Layer::RemoveFromParent() {
189 if (parent_)
190 parent_->RemoveChildOrDependent(this);
191 }
192
193 void Layer::RemoveChildOrDependent(Layer* child) {
194 if (mask_layer_ == child) {
195 mask_layer_->SetParent(NULL);
196 mask_layer_ = NULL;
197 SetNeedsFullTreeSync();
198 return;
199 }
200 if (replica_layer_ == child) {
201 replica_layer_->SetParent(NULL);
202 replica_layer_ = NULL;
203 SetNeedsFullTreeSync();
204 return;
205 }
206
207 for (LayerList::iterator iter = children_.begin();
208 iter != children_.end();
209 ++iter) {
210 if (*iter != child)
211 continue;
212
213 child->SetParent(NULL);
214 children_.erase(iter);
215 SetNeedsFullTreeSync();
216 return;
217 }
218 }
219
220 void Layer::ReplaceChild(Layer* reference, scoped_refptr<Layer> new_layer) {
221 DCHECK(reference);
222 DCHECK_EQ(reference->parent(), this);
223
224 if (reference == new_layer)
225 return;
226
227 int reference_index = IndexOfChild(reference);
228 if (reference_index == -1) {
229 NOTREACHED();
230 return;
231 }
232
233 reference->RemoveFromParent();
234
235 if (new_layer) {
236 new_layer->RemoveFromParent();
237 InsertChild(new_layer, reference_index);
238 }
239 }
240
241 int Layer::IndexOfChild(const Layer* reference) {
242 for (size_t i = 0; i < children_.size(); ++i) {
243 if (children_[i] == reference)
244 return i;
245 }
246 return -1;
247 }
248
249 void Layer::SetBounds(gfx::Size size) {
250 if (bounds() == size)
251 return;
252
253 bool first_resize = bounds().IsEmpty() && !size.IsEmpty();
254
255 bounds_ = size;
256
257 if (first_resize)
258 SetNeedsDisplay();
259 else
260 SetNeedsCommit();
261 }
262
263 Layer* Layer::RootLayer() {
264 Layer* layer = this;
265 while (layer->parent())
266 layer = layer->parent();
267 return layer;
268 }
269
270 void Layer::RemoveAllChildren() {
271 while (children_.size()) {
272 Layer* layer = children_[0].get();
273 DCHECK_EQ(this, layer->parent());
274 layer->RemoveFromParent();
275 }
276 }
277
278 void Layer::SetChildren(const LayerList& children) {
279 if (children == children_)
280 return;
281
282 RemoveAllChildren();
283 for (size_t i = 0; i < children.size(); ++i)
284 AddChild(children[i]);
285 }
286
287 void Layer::SetAnchorPoint(gfx::PointF anchor_point) {
288 if (anchor_point_ == anchor_point)
289 return;
290 anchor_point_ = anchor_point;
291 SetNeedsCommit();
292 }
293
294 void Layer::SetAnchorPointZ(float anchor_point_z) {
295 if (anchor_point_z_ == anchor_point_z)
296 return;
297 anchor_point_z_ = anchor_point_z;
298 SetNeedsCommit();
299 }
300
301 void Layer::SetBackgroundColor(SkColor background_color) {
302 if (background_color_ == background_color)
303 return;
304 background_color_ = background_color;
305 SetNeedsCommit();
306 }
307
308 void Layer::CalculateContentsScale(
309 float ideal_contents_scale,
310 bool animating_transform_to_screen,
311 float* contents_scale_x,
312 float* contents_scale_y,
313 gfx::Size* contentBounds) {
314 *contents_scale_x = 1;
315 *contents_scale_y = 1;
316 *contentBounds = bounds();
317 }
318
319 void Layer::SetMasksToBounds(bool masks_to_bounds) {
320 if (masks_to_bounds_ == masks_to_bounds)
321 return;
322 masks_to_bounds_ = masks_to_bounds;
323 SetNeedsCommit();
324 }
325
326 void Layer::SetMaskLayer(Layer* mask_layer) {
327 if (mask_layer_ == mask_layer)
328 return;
329 if (mask_layer_) {
330 DCHECK_EQ(this, mask_layer_->parent());
331 mask_layer_->RemoveFromParent();
332 }
333 mask_layer_ = mask_layer;
334 if (mask_layer_) {
335 DCHECK(!mask_layer_->parent());
336 mask_layer_->RemoveFromParent();
337 mask_layer_->SetParent(this);
338 mask_layer_->SetIsMask(true);
339 }
340 SetNeedsFullTreeSync();
341 }
342
343 void Layer::SetReplicaLayer(Layer* layer) {
344 if (replica_layer_ == layer)
345 return;
346 if (replica_layer_) {
347 DCHECK_EQ(this, replica_layer_->parent());
348 replica_layer_->RemoveFromParent();
349 }
350 replica_layer_ = layer;
351 if (replica_layer_) {
352 DCHECK(!replica_layer_->parent());
353 replica_layer_->RemoveFromParent();
354 replica_layer_->SetParent(this);
355 }
356 SetNeedsFullTreeSync();
357 }
358
359 void Layer::SetFilters(const WebKit::WebFilterOperations& filters) {
360 if (filters_ == filters)
361 return;
362 DCHECK(!filter_);
363 filters_ = filters;
364 SetNeedsCommit();
365 if (!filters.isEmpty() && layer_tree_host_)
366 layer_tree_host_->set_needs_filter_context();
367 }
368
369 void Layer::SetFilter(const skia::RefPtr<SkImageFilter>& filter) {
370 if (filter_.get() == filter.get())
371 return;
372 DCHECK(filters_.isEmpty());
373 filter_ = filter;
374 SetNeedsCommit();
375 if (filter && layer_tree_host_)
376 layer_tree_host_->set_needs_filter_context();
377 }
378
379 void Layer::SetBackgroundFilters(const WebKit::WebFilterOperations& filters) {
380 if (background_filters_ == filters)
381 return;
382 background_filters_ = filters;
383 SetNeedsCommit();
384 if (!filters.isEmpty() && layer_tree_host_)
385 layer_tree_host_->set_needs_filter_context();
386 }
387
388 void Layer::SetOpacity(float opacity) {
389 if (opacity_ == opacity)
390 return;
391 opacity_ = opacity;
392 SetNeedsCommit();
393 }
394
395 bool Layer::OpacityIsAnimating() const {
396 return layer_animation_controller_->IsAnimatingProperty(Animation::Opacity);
397 }
398
399 bool Layer::OpacityCanAnimateOnImplThread() const {
400 return false;
401 }
402
403 void Layer::SetContentsOpaque(bool opaque) {
404 if (contents_opaque_ == opaque)
405 return;
406 contents_opaque_ = opaque;
407 SetNeedsCommit();
408 }
409
410 void Layer::SetPosition(gfx::PointF position) {
411 if (position_ == position)
412 return;
413 position_ = position;
414 SetNeedsCommit();
415 }
416
417 void Layer::SetSublayerTransform(const gfx::Transform& sublayer_transform) {
418 if (sublayer_transform_ == sublayer_transform)
419 return;
420 sublayer_transform_ = sublayer_transform;
421 SetNeedsCommit();
422 }
423
424 void Layer::SetTransform(const gfx::Transform& transform) {
425 if (transform_ == transform)
426 return;
427 transform_ = transform;
428 SetNeedsCommit();
429 }
430
431 bool Layer::TransformIsAnimating() const {
432 return layer_animation_controller_->IsAnimatingProperty(Animation::Transform);
433 }
434
435 void Layer::SetScrollOffset(gfx::Vector2d scroll_offset) {
436 if (scroll_offset_ == scroll_offset)
437 return;
438 scroll_offset_ = scroll_offset;
439 if (layer_scroll_client_)
440 layer_scroll_client_->didScroll();
441 SetNeedsCommit();
442 }
443
444 void Layer::SetMaxScrollOffset(gfx::Vector2d max_scroll_offset) {
445 if (max_scroll_offset_ == max_scroll_offset)
446 return;
447 max_scroll_offset_ = max_scroll_offset;
448 SetNeedsCommit();
449 }
450
451 void Layer::SetScrollable(bool scrollable) {
452 if (scrollable_ == scrollable)
453 return;
454 scrollable_ = scrollable;
455 SetNeedsCommit();
456 }
457
458 void Layer::SetShouldScrollOnMainThread(bool should_scroll_on_main_thread) {
459 if (should_scroll_on_main_thread_ == should_scroll_on_main_thread)
460 return;
461 should_scroll_on_main_thread_ = should_scroll_on_main_thread;
462 SetNeedsCommit();
463 }
464
465 void Layer::SetHaveWheelEventHandlers(bool have_wheel_event_handlers) {
466 if (have_wheel_event_handlers_ == have_wheel_event_handlers)
467 return;
468 have_wheel_event_handlers_ = have_wheel_event_handlers;
469 SetNeedsCommit();
470 }
471
472 void Layer::SetNonFastScrollableRegion(const Region& region) {
473 if (non_fast_scrollable_region_ == region)
474 return;
475 non_fast_scrollable_region_ = region;
476 SetNeedsCommit();
477 }
478
479 void Layer::SetTouchEventHandlerRegion(const Region& region) {
480 if (touch_event_handler_region_ == region)
481 return;
482 touch_event_handler_region_ = region;
483 }
484
485 void Layer::SetDrawCheckerboardForMissingTiles(bool checkerboard) {
486 if (draw_checkerboard_for_missing_tiles_ == checkerboard)
487 return;
488 draw_checkerboard_for_missing_tiles_ = checkerboard;
489 SetNeedsCommit();
490 }
491
492 void Layer::SetForceRenderSurface(bool force) {
493 if (force_render_surface_ == force)
494 return;
495 force_render_surface_ = force;
496 SetNeedsCommit();
497 }
498
499 void Layer::SetImplTransform(const gfx::Transform& transform) {
500 if (impl_transform_ == transform)
501 return;
502 impl_transform_ = transform;
503 SetNeedsCommit();
504 }
505
506 void Layer::SetDoubleSided(bool double_sided) {
507 if (double_sided_ == double_sided)
508 return;
509 double_sided_ = double_sided;
510 SetNeedsCommit();
511 }
512
513 void Layer::SetIsDrawable(bool is_drawable) {
514 if (is_drawable_ == is_drawable)
515 return;
516
517 is_drawable_ = is_drawable;
518 SetNeedsCommit();
519 }
520
521 void Layer::SetNeedsDisplayRect(const gfx::RectF& dirty_rect) {
522 update_rect_.Union(dirty_rect);
523 needs_display_ = true;
524
525 // Simply mark the contents as dirty. For non-root layers, the call to
526 // SetNeedsCommit will schedule a fresh compositing pass.
527 // For the root layer, SetNeedsCommit has no effect.
528 if (DrawsContent() && !update_rect_.IsEmpty())
529 SetNeedsCommit();
530 }
531
532 bool Layer::DescendantIsFixedToContainerLayer() const {
533 for (size_t i = 0; i < children_.size(); ++i) {
534 if (children_[i]->fixed_to_container_layer() ||
535 children_[i]->DescendantIsFixedToContainerLayer())
536 return true;
537 }
538 return false;
539 }
540
541 void Layer::SetIsContainerForFixedPositionLayers(bool container) {
542 if (is_container_for_fixed_position_layers_ == container)
543 return;
544 is_container_for_fixed_position_layers_ = container;
545
546 if (layer_tree_host_ && layer_tree_host_->CommitRequested())
547 return;
548
549 // Only request a commit if we have a fixed positioned descendant.
550 if (DescendantIsFixedToContainerLayer())
551 SetNeedsCommit();
552 }
553
554 void Layer::SetFixedToContainerLayer(bool fixed_to_container_layer) {
555 if (fixed_to_container_layer_ == fixed_to_container_layer)
556 return;
557 fixed_to_container_layer_ = fixed_to_container_layer;
558 SetNeedsCommit();
559 }
560
561 void Layer::PushPropertiesTo(LayerImpl* layer) {
562 layer->SetAnchorPoint(anchor_point_);
563 layer->SetAnchorPointZ(anchor_point_z_);
564 layer->SetBackgroundColor(background_color_);
565 layer->SetBounds(bounds_);
566 layer->SetContentBounds(content_bounds());
567 layer->SetContentsScale(contents_scale_x(), contents_scale_y());
568 layer->SetDebugName(debug_name_);
569 layer->SetDoubleSided(double_sided_);
570 layer->SetDrawCheckerboardForMissingTiles(
571 draw_checkerboard_for_missing_tiles_);
572 layer->SetForceRenderSurface(force_render_surface_);
573 layer->SetDrawsContent(DrawsContent());
574 layer->SetFilters(filters());
575 layer->SetFilter(filter());
576 layer->SetBackgroundFilters(background_filters());
577 layer->SetMasksToBounds(masks_to_bounds_);
578 layer->SetShouldScrollOnMainThread(should_scroll_on_main_thread_);
579 layer->SetHaveWheelEventHandlers(have_wheel_event_handlers_);
580 layer->SetNonFastScrollableRegion(non_fast_scrollable_region_);
581 layer->SetTouchEventHandlerRegion(touch_event_handler_region_);
582 layer->SetContentsOpaque(contents_opaque_);
583 if (!layer->OpacityIsAnimatingOnImplOnly())
584 layer->SetOpacity(opacity_);
585 DCHECK(!(OpacityIsAnimating() && layer->OpacityIsAnimatingOnImplOnly()));
586 layer->SetPosition(position_);
587 layer->SetIsContainerForFixedPositionLayers(
588 is_container_for_fixed_position_layers_);
589 layer->SetFixedToContainerLayer(fixed_to_container_layer_);
590 layer->SetPreserves3d(preserves_3d());
591 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_);
592 layer->SetSublayerTransform(sublayer_transform_);
593 if (!layer->TransformIsAnimatingOnImplOnly())
594 layer->SetTransform(transform_);
595 DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly()));
596
597 layer->SetScrollable(scrollable_);
598 layer->SetScrollOffset(scroll_offset_);
599 layer->SetMaxScrollOffset(max_scroll_offset_);
600
601 // If the main thread commits multiple times before the impl thread actually
602 // draws, then damage tracking will become incorrect if we simply clobber the
603 // updateRect here. The LayerImpl's updateRect needs to accumulate (i.e.
604 // union) any update changes that have occurred on the main thread.
605 update_rect_.Union(layer->update_rect());
606 layer->set_update_rect(update_rect_);
607
608 if (layer->layer_tree_impl()->settings().implSidePainting) {
609 DCHECK(layer->layer_tree_impl()->IsPendingTree());
610 LayerImpl* active_twin =
611 layer->layer_tree_impl()->FindActiveTreeLayerById(id());
612 // Update the scroll delta from the active layer, which may have
613 // adjusted its scroll delta prior to this pending layer being created.
614 // This code is identical to that in LayerImpl::setScrollDelta.
615 if (active_twin) {
616 DCHECK(layer->sent_scroll_delta().IsZero());
617 layer->SetScrollDelta(active_twin->scroll_delta() -
618 active_twin->sent_scroll_delta());
619 }
620 } else {
621 layer->SetScrollDelta(layer->scroll_delta() - layer->sent_scroll_delta());
622 layer->SetSentScrollDelta(gfx::Vector2d());
623 }
624
625 layer->SetStackingOrderChanged(stacking_order_changed_);
626
627 layer_animation_controller_->PushAnimationUpdatesTo(
628 layer->layer_animation_controller());
629
630 // Reset any state that should be cleared for the next update.
631 stacking_order_changed_ = false;
632 update_rect_ = gfx::RectF();
633 }
634
635 scoped_ptr<LayerImpl> Layer::CreateLayerImpl(LayerTreeImpl* tree_impl) {
636 return LayerImpl::Create(tree_impl, layer_id_);
637 }
638
639 bool Layer::DrawsContent() const {
640 return is_drawable_;
641 }
642
643 bool Layer::NeedMoreUpdates() {
644 return false;
645 }
646
647 void Layer::SetDebugName(const std::string& debug_name) {
648 debug_name_ = debug_name;
649 SetNeedsCommit();
650 }
651
652 void Layer::SetRasterScale(float scale) {
653 if (raster_scale_ == scale)
654 return;
655 raster_scale_ = scale;
656
657 // When automatically computed, this acts like a draw property.
658 if (automatically_compute_raster_scale_)
659 return;
660 SetNeedsDisplay();
661 }
662
663 void Layer::SetAutomaticallyComputeRasterScale(bool automatic) {
664 if (automatically_compute_raster_scale_ == automatic)
665 return;
666 automatically_compute_raster_scale_ = automatic;
667
668 if (automatically_compute_raster_scale_)
669 ForceAutomaticRasterScaleToBeRecomputed();
670 else
671 SetRasterScale(1);
672 }
673
674 void Layer::ForceAutomaticRasterScaleToBeRecomputed() {
675 if (!automatically_compute_raster_scale_)
676 return;
677 if (!raster_scale_)
678 return;
679 raster_scale_ = 0.f;
680 SetNeedsCommit();
681 }
682
683 void Layer::SetBoundsContainPageScale(bool bounds_contain_page_scale) {
684 for (size_t i = 0; i < children_.size(); ++i)
685 children_[i]->SetBoundsContainPageScale(bounds_contain_page_scale);
686
687 if (bounds_contain_page_scale == bounds_contain_page_scale_)
688 return;
689
690 bounds_contain_page_scale_ = bounds_contain_page_scale;
691 SetNeedsDisplay();
692 }
693
694 void Layer::CreateRenderSurface() {
695 DCHECK(!draw_properties_.render_surface);
696 draw_properties_.render_surface = make_scoped_ptr(new RenderSurface(this));
697 draw_properties_.render_target = this;
698 }
699
700 void Layer::OnOpacityAnimated(float opacity) {
701 // This is called due to an ongoing accelerated animation. Since this
702 // animation is also being run on the impl thread, there is no need to request
703 // a commit to push this value over, so set the value directly rather than
704 // calling setOpacity.
705 opacity_ = opacity;
706 }
707
708 void Layer::OnTransformAnimated(const gfx::Transform& transform) {
709 // This is called due to an ongoing accelerated animation. Since this
710 // animation is also being run on the impl thread, there is no need to request
711 // a commit to push this value over, so set this value directly rather than
712 // calling setTransform.
713 transform_ = transform;
714 }
715
716 bool Layer::IsActive() const {
717 return true;
718 }
719
720 bool Layer::AddAnimation(scoped_ptr <Animation> animation) {
721 if (!layer_animation_controller_->animation_registrar())
722 return false;
723
724 layer_animation_controller_->AddAnimation(animation.Pass());
725 SetNeedsCommit();
726 return true;
727 }
728
729 void Layer::PauseAnimation(int animation_id, double time_offset) {
730 layer_animation_controller_->PauseAnimation(animation_id, time_offset);
731 SetNeedsCommit();
732 }
733
734 void Layer::RemoveAnimation(int animation_id) {
735 layer_animation_controller_->RemoveAnimation(animation_id);
736 SetNeedsCommit();
737 }
738
739 void Layer::SuspendAnimations(double monotonic_time) {
740 layer_animation_controller_->SuspendAnimations(monotonic_time);
741 SetNeedsCommit();
742 }
743
744 void Layer::ResumeAnimations(double monotonic_time) {
745 layer_animation_controller_->ResumeAnimations(monotonic_time);
746 SetNeedsCommit();
747 }
748
749 void Layer::SetLayerAnimationController(
750 scoped_refptr<LayerAnimationController> controller) {
751 RemoveLayerAnimationEventObserver(layer_animation_controller_.get());
752 layer_animation_controller_->RemoveObserver(this);
753 layer_animation_controller_ = controller;
754 layer_animation_controller_->set_force_sync();
755 layer_animation_controller_->AddObserver(this);
756 AddLayerAnimationEventObserver(layer_animation_controller_.get());
757 SetNeedsCommit();
758 }
759
760 scoped_refptr<LayerAnimationController>
761 Layer::ReleaseLayerAnimationController() {
762 layer_animation_controller_->RemoveObserver(this);
763 scoped_refptr<LayerAnimationController> to_return =
764 layer_animation_controller_;
765 layer_animation_controller_ = LayerAnimationController::Create(id());
766 layer_animation_controller_->AddObserver(this);
767 layer_animation_controller_->SetAnimationRegistrar(
768 to_return->animation_registrar());
769 return to_return;
770 }
771
772 bool Layer::HasActiveAnimation() const {
773 return layer_animation_controller_->HasActiveAnimation();
774 }
775
776 void Layer::NotifyAnimationStarted(const AnimationEvent& event,
777 double wall_clock_time) {
778 FOR_EACH_OBSERVER(LayerAnimationEventObserver, layer_animation_observers_,
779 OnAnimationStarted(event));
780 if (layer_animation_delegate_)
781 layer_animation_delegate_->notifyAnimationStarted(wall_clock_time);
782 }
783
784 void Layer::NotifyAnimationFinished(double wall_clock_time) {
785 if (layer_animation_delegate_)
786 layer_animation_delegate_->notifyAnimationFinished(wall_clock_time);
787 }
788
789 void Layer::NotifyAnimationPropertyUpdate(const AnimationEvent& event) {
790 if (event.target_property == Animation::Opacity)
791 SetOpacity(event.opacity);
792 else
793 SetTransform(event.transform);
794 }
795
796 void Layer::AddLayerAnimationEventObserver(
797 LayerAnimationEventObserver* animation_observer) {
798 if (!layer_animation_observers_.HasObserver(animation_observer))
799 layer_animation_observers_.AddObserver(animation_observer);
800 }
801
802 void Layer::RemoveLayerAnimationEventObserver(
803 LayerAnimationEventObserver* animation_observer) {
804 layer_animation_observers_.RemoveObserver(animation_observer);
805 }
806
807 Region Layer::VisibleContentOpaqueRegion() const {
808 if (contents_opaque())
809 return visible_content_rect();
810 return Region();
811 }
812
813 ScrollbarLayer* Layer::ToScrollbarLayer() {
814 return NULL;
815 }
816
817 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layer.h ('k') | cc/layer_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698