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

Side by Side Diff: cc/layer.cc

Issue 12774006: cc: Chromify Layer and LayerImpl classes. (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
OLDNEW
1 // Copyright 2010 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/layer.h" 5 #include "cc/layer.h"
6 6
7 #include "cc/animation.h" 7 #include "cc/animation.h"
8 #include "cc/animation_events.h" 8 #include "cc/animation_events.h"
9 #include "cc/layer_animation_controller.h" 9 #include "cc/layer_animation_controller.h"
10 #include "cc/layer_impl.h" 10 #include "cc/layer_impl.h"
11 #include "cc/layer_tree_host.h" 11 #include "cc/layer_tree_host.h"
12 #include "cc/layer_tree_impl.h" 12 #include "cc/layer_tree_impl.h"
13 #include "third_party/WebKit/Source/Platform/chromium/public/WebAnimationDelegat e.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" 14 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayerScrollClien t.h"
15 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h"
16 #include "third_party/skia/include/core/SkImageFilter.h" 16 #include "third_party/skia/include/core/SkImageFilter.h"
17 #include "ui/gfx/rect_conversions.h" 17 #include "ui/gfx/rect_conversions.h"
18 18
19 namespace cc { 19 namespace cc {
20 20
21 static int s_nextLayerId = 1; 21 static int s_next_layer_id = 1;
enne (OOO) 2013/03/12 02:40:19 I thought this was weird, but the style guide real
danakj 2013/03/12 02:47:16 Yeh.. not sure.
22 22
23 scoped_refptr<Layer> Layer::create() 23 scoped_refptr<Layer> Layer::Create() {
24 { 24 return make_scoped_refptr(new Layer());
25 return make_scoped_refptr(new Layer());
26 } 25 }
27 26
28 Layer::Layer() 27 Layer::Layer()
29 : m_needsDisplay(false) 28 : needs_display_(false),
30 , m_stackingOrderChanged(false) 29 stacking_order_changed_(false),
31 , m_layerId(s_nextLayerId++) 30 layer_id_(s_next_layer_id++),
32 , m_ignoreSetNeedsCommit(false) 31 ignore_set_needs_commit_(false),
33 , m_parent(0) 32 parent_(NULL),
34 , m_layerTreeHost(0) 33 layer_tree_host_(NULL),
35 , m_scrollable(false) 34 scrollable_(false),
36 , m_shouldScrollOnMainThread(false) 35 should_scroll_on_main_thread_(false),
37 , m_haveWheelEventHandlers(false) 36 have_wheel_event_handlers_(false),
38 , m_anchorPoint(0.5, 0.5) 37 anchor_point_(0.5f, 0.5f),
39 , m_backgroundColor(0) 38 background_color_(0),
40 , m_opacity(1.0) 39 opacity_(1.f),
41 , m_anchorPointZ(0) 40 anchor_point_z_(0.f),
42 , m_isContainerForFixedPositionLayers(false) 41 is_container_for_fixed_position_layers_(false),
43 , m_fixedToContainerLayer(false) 42 fixed_to_container_layer_(false),
44 , m_isDrawable(false) 43 is_drawable_(false),
45 , m_masksToBounds(false) 44 masks_to_bounds_(false),
46 , m_contentsOpaque(false) 45 contents_opaque_(false),
47 , m_doubleSided(true) 46 double_sided_(true),
48 , m_preserves3D(false) 47 preserves_3d_(false),
49 , m_useParentBackfaceVisibility(false) 48 use_parent_backface_visibility_(false),
50 , m_drawCheckerboardForMissingTiles(false) 49 draw_checkerboard_for_missing_tiles_(false),
51 , m_forceRenderSurface(false) 50 force_render_surface_(false),
52 , m_replicaLayer(0) 51 replica_layer_(NULL),
53 , m_rasterScale(1.0) 52 raster_scale_(1.f),
54 , m_automaticallyComputeRasterScale(false) 53 automatically_compute_raster_scale_(false),
55 , m_boundsContainPageScale(false) 54 bounds_contain_page_scale_(false),
56 , m_layerAnimationDelegate(0) 55 layer_animation_delegate_(NULL),
57 , m_layerScrollClient(0) 56 layer_scroll_client_(NULL) {
58 { 57 if (layer_id_ < 0) {
59 if (m_layerId < 0) { 58 s_next_layer_id = 1;
60 s_nextLayerId = 1; 59 layer_id_ = s_next_layer_id++;
61 m_layerId = s_nextLayerId++; 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->animationRegistrar() : 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_->setNeedsFilterContext();
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_->setNeedsFilterContext();
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_->setNeedsFilterContext();
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_->setNeedsFilterContext();
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 void Layer::SetContentsOpaque(bool opaque) {
400 if (contents_opaque_ == opaque)
401 return;
402 contents_opaque_ = opaque;
403 SetNeedsCommit();
404 }
405
406 void Layer::SetPosition(gfx::PointF position) {
407 if (position_ == position)
408 return;
409 position_ = position;
410 SetNeedsCommit();
411 }
412
413 void Layer::SetSublayerTransform(const gfx::Transform& sublayer_transform) {
414 if (sublayer_transform_ == sublayer_transform)
415 return;
416 sublayer_transform_ = sublayer_transform;
417 SetNeedsCommit();
418 }
419
420 void Layer::SetTransform(const gfx::Transform& transform) {
421 if (transform_ == transform)
422 return;
423 transform_ = transform;
424 SetNeedsCommit();
425 }
426
427 bool Layer::TransformIsAnimating() const {
428 return layer_animation_controller_->IsAnimatingProperty(Animation::Transform);
429 }
430
431 void Layer::SetScrollOffset(gfx::Vector2d scroll_offset) {
432 if (scroll_offset_ == scroll_offset)
433 return;
434 scroll_offset_ = scroll_offset;
435 if (layer_scroll_client_)
436 layer_scroll_client_->didScroll();
437 SetNeedsCommit();
438 }
439
440 void Layer::SetMaxScrollOffset(gfx::Vector2d max_scroll_offset) {
441 if (max_scroll_offset_ == max_scroll_offset)
442 return;
443 max_scroll_offset_ = max_scroll_offset;
444 SetNeedsCommit();
445 }
446
447 void Layer::SetScrollable(bool scrollable) {
448 if (scrollable_ == scrollable)
449 return;
450 scrollable_ = scrollable;
451 SetNeedsCommit();
452 }
453
454 void Layer::SetShouldScrollOnMainThread(bool should_scroll_on_main_thread) {
455 if (should_scroll_on_main_thread_ == should_scroll_on_main_thread)
456 return;
457 should_scroll_on_main_thread_ = should_scroll_on_main_thread;
458 SetNeedsCommit();
459 }
460
461 void Layer::SetHaveWheelEventHandlers(bool have_wheel_event_handlers) {
462 if (have_wheel_event_handlers_ == have_wheel_event_handlers)
463 return;
464 have_wheel_event_handlers_ = have_wheel_event_handlers;
465 SetNeedsCommit();
466 }
467
468 void Layer::SetNonFastScrollableRegion(const Region& region) {
469 if (non_fast_scrollable_region_ == region)
470 return;
471 non_fast_scrollable_region_ = region;
472 SetNeedsCommit();
473 }
474
475 void Layer::SetTouchEventHandlerRegion(const Region& region) {
476 if (touch_event_handler_region_ == region)
477 return;
478 touch_event_handler_region_ = region;
479 }
480
481 void Layer::SetDrawCheckerboardForMissingTiles(bool checkerboard) {
482 if (draw_checkerboard_for_missing_tiles_ == checkerboard)
483 return;
484 draw_checkerboard_for_missing_tiles_ = checkerboard;
485 SetNeedsCommit();
486 }
487
488 void Layer::SetForceRenderSurface(bool force) {
489 if (force_render_surface_ == force)
490 return;
491 force_render_surface_ = force;
492 SetNeedsCommit();
493 }
494
495 void Layer::SetImplTransform(const gfx::Transform& transform) {
496 if (impl_transform_ == transform)
497 return;
498 impl_transform_ = transform;
499 SetNeedsCommit();
500 }
501
502 void Layer::SetDoubleSided(bool double_sided) {
503 if (double_sided_ == double_sided)
504 return;
505 double_sided_ = double_sided;
506 SetNeedsCommit();
507 }
508
509 void Layer::SetIsDrawable(bool is_drawable) {
510 if (is_drawable_ == is_drawable)
511 return;
512
513 is_drawable_ = is_drawable;
514 SetNeedsCommit();
515 }
516
517 void Layer::SetNeedsDisplayRect(const gfx::RectF& dirty_rect) {
518 update_rect_.Union(dirty_rect);
519 needs_display_ = true;
520
521 // Simply mark the contents as dirty. For non-root layers, the call to
522 // setNeedsCommit will schedule a fresh compositing pass.
523 // For the root layer, setNeedsCommit has no effect.
524 if (DrawsContent() && !update_rect_.IsEmpty())
525 SetNeedsCommit();
526 }
527
528 bool Layer::DescendantIsFixedToContainerLayer() const {
529 for (size_t i = 0; i < children_.size(); ++i) {
530 if (children_[i]->fixed_to_container_layer() ||
531 children_[i]->DescendantIsFixedToContainerLayer())
532 return true;
533 }
534 return false;
535 }
536
537 void Layer::SetIsContainerForFixedPositionLayers(bool container) {
538 if (is_container_for_fixed_position_layers_ == container)
539 return;
540 is_container_for_fixed_position_layers_ = container;
541
542 if (layer_tree_host_ && layer_tree_host_->commitRequested())
543 return;
544
545 // Only request a commit if we have a fixed positioned descendant.
546 if (DescendantIsFixedToContainerLayer())
547 SetNeedsCommit();
548 }
549
550 void Layer::SetFixedToContainerLayer(bool fixed_to_container_layer) {
551 if (fixed_to_container_layer_ == fixed_to_container_layer)
552 return;
553 fixed_to_container_layer_ = fixed_to_container_layer;
554 SetNeedsCommit();
555 }
556
557 void Layer::PushPropertiesTo(LayerImpl* layer) {
558 layer->SetAnchorPoint(anchor_point_);
559 layer->SetAnchorPointZ(anchor_point_z_);
560 layer->SetBackgroundColor(background_color_);
561 layer->SetBounds(bounds_);
562 layer->SetContentBounds(content_bounds());
563 layer->SetContentsScale(contents_scale_x(), contents_scale_y());
564 layer->SetDebugName(debug_name_);
565 layer->SetDoubleSided(double_sided_);
566 layer->SetDrawCheckerboardForMissingTiles(
567 draw_checkerboard_for_missing_tiles_);
568 layer->SetForceRenderSurface(force_render_surface_);
569 layer->SetDrawsContent(DrawsContent());
570 layer->SetFilters(filters());
571 layer->SetFilter(filter());
572 layer->SetBackgroundFilters(background_filters());
573 layer->SetMasksToBounds(masks_to_bounds_);
574 layer->SetShouldScrollOnMainThread(should_scroll_on_main_thread_);
575 layer->SetHaveWheelEventHandlers(have_wheel_event_handlers_);
576 layer->SetNonFastScrollableRegion(non_fast_scrollable_region_);
577 layer->SetTouchEventHandlerRegion(touch_event_handler_region_);
578 layer->SetContentsOpaque(contents_opaque_);
579 if (!OpacityIsAnimating())
580 layer->SetOpacity(opacity_);
581 layer->SetPosition(position_);
582 layer->SetIsContainerForFixedPositionLayers(
583 is_container_for_fixed_position_layers_);
584 layer->SetFixedToContainerLayer(fixed_to_container_layer_);
585 layer->SetPreserves3d(preserves_3d());
586 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_);
587 layer->SetSublayerTransform(sublayer_transform_);
588 if (!TransformIsAnimating())
589 layer->SetTransform(transform_);
590
591 layer->SetScrollable(scrollable_);
592 layer->SetScrollOffset(scroll_offset_);
593 layer->SetMaxScrollOffset(max_scroll_offset_);
594
595 // If the main thread commits multiple times before the impl thread actually
596 // draws, then damage tracking will become incorrect if we simply clobber the
597 // updateRect here. The LayerImpl's updateRect needs to accumulate (i.e.
598 // union) any update changes that have occurred on the main thread.
599 update_rect_.Union(layer->update_rect());
600 layer->set_update_rect(update_rect_);
601
602 if (layer->layer_tree_impl()->settings().implSidePainting) {
603 DCHECK(layer->layer_tree_impl()->IsPendingTree());
604 LayerImpl* active_twin =
605 layer->layer_tree_impl()->FindActiveTreeLayerById(id());
606 // Update the scroll delta from the active layer, which may have
607 // adjusted its scroll delta prior to this pending layer being created.
608 // This code is identical to that in LayerImpl::setScrollDelta.
609 if (active_twin) {
610 DCHECK(layer->sent_scroll_delta().IsZero());
611 layer->SetScrollDelta(active_twin->scroll_delta() -
612 active_twin->sent_scroll_delta());
62 } 613 }
63 614 } else {
64 m_layerAnimationController = LayerAnimationController::Create(m_layerId); 615 layer->SetScrollDelta(layer->scroll_delta() - layer->sent_scroll_delta());
65 m_layerAnimationController->AddObserver(this); 616 layer->SetSentScrollDelta(gfx::Vector2d());
66 addLayerAnimationEventObserver(m_layerAnimationController.get()); 617 }
67 } 618
68 619 layer->SetStackingOrderChanged(stacking_order_changed_);
69 Layer::~Layer() 620
70 { 621 layer_animation_controller_->PushAnimationUpdatesTo(
71 // Our parent should be holding a reference to us so there should be no 622 layer->layer_animation_controller());
72 // way for us to be destroyed while we still have a parent. 623
73 DCHECK(!parent()); 624 // Reset any state that should be cleared for the next update.
74 625 stacking_order_changed_ = false;
75 m_layerAnimationController->RemoveObserver(this); 626 update_rect_ = gfx::RectF();
76 627 }
77 // Remove the parent reference from all children and dependents. 628
78 removeAllChildren(); 629 scoped_ptr<LayerImpl> Layer::CreateLayerImpl(LayerTreeImpl* tree_impl) {
79 if (m_maskLayer) { 630 return LayerImpl::Create(tree_impl, layer_id_);
80 DCHECK_EQ(this, m_maskLayer->parent()); 631 }
81 m_maskLayer->removeFromParent(); 632
82 } 633 bool Layer::DrawsContent() const {
83 if (m_replicaLayer) { 634 return is_drawable_;
84 DCHECK_EQ(this, m_replicaLayer->parent()); 635 }
85 m_replicaLayer->removeFromParent(); 636
86 } 637 bool Layer::NeedMoreUpdates() {
87 } 638 return false;
88 639 }
89 void Layer::setLayerTreeHost(LayerTreeHost* host) 640
90 { 641 void Layer::SetDebugName(const std::string& debug_name) {
91 if (m_layerTreeHost == host) 642 debug_name_ = debug_name;
92 return; 643 SetNeedsCommit();
93 644 }
94 m_layerTreeHost = host; 645
95 646 void Layer::SetRasterScale(float scale) {
96 for (size_t i = 0; i < m_children.size(); ++i) 647 if (raster_scale_ == scale)
97 m_children[i]->setLayerTreeHost(host); 648 return;
98 649 raster_scale_ = scale;
99 if (m_maskLayer) 650
100 m_maskLayer->setLayerTreeHost(host); 651 // When automatically computed, this acts like a draw property.
101 if (m_replicaLayer) 652 if (automatically_compute_raster_scale_)
102 m_replicaLayer->setLayerTreeHost(host); 653 return;
103 654 SetNeedsDisplay();
104 m_layerAnimationController->SetAnimationRegistrar(host ? host->animationRegi strar() : 0); 655 }
105 656
106 if (host && m_layerAnimationController->has_any_animation()) 657 void Layer::SetAutomaticallyComputeRasterScale(bool automatic) {
107 host->setNeedsCommit(); 658 if (automatically_compute_raster_scale_ == automatic)
108 if (host && (!m_filters.isEmpty() || !m_backgroundFilters.isEmpty() || m_fil ter)) 659 return;
109 m_layerTreeHost->setNeedsFilterContext(); 660 automatically_compute_raster_scale_ = automatic;
110 661
111 } 662 if (automatically_compute_raster_scale_)
112 663 ForceAutomaticRasterScaleToBeRecomputed();
113 void Layer::setNeedsCommit() 664 else
114 { 665 SetRasterScale(1);
115 if (m_ignoreSetNeedsCommit) 666 }
116 return; 667
117 if (m_layerTreeHost) 668 void Layer::ForceAutomaticRasterScaleToBeRecomputed() {
118 m_layerTreeHost->setNeedsCommit(); 669 if (!automatically_compute_raster_scale_)
119 } 670 return;
120 671 if (!raster_scale_)
121 void Layer::setNeedsFullTreeSync() 672 return;
122 { 673 raster_scale_ = 0.f;
123 if (m_layerTreeHost) 674 SetNeedsCommit();
124 m_layerTreeHost->setNeedsFullTreeSync(); 675 }
125 } 676
126 677 void Layer::SetBoundsContainPageScale(bool bounds_contain_page_scale) {
127 gfx::Rect Layer::layerRectToContentRect(const gfx::RectF& layerRect) const 678 for (size_t i = 0; i < children_.size(); ++i)
128 { 679 children_[i]->SetBoundsContainPageScale(bounds_contain_page_scale);
129 gfx::RectF contentRect = gfx::ScaleRect(layerRect, contentsScaleX(), content sScaleY()); 680
130 // Intersect with content rect to avoid the extra pixel because for some 681 if (bounds_contain_page_scale == bounds_contain_page_scale_)
131 // values x and y, ceil((x / y) * y) may be x + 1. 682 return;
132 contentRect.Intersect(gfx::Rect(gfx::Point(), contentBounds())); 683
133 return gfx::ToEnclosingRect(contentRect); 684 bounds_contain_page_scale_ = bounds_contain_page_scale;
134 } 685 SetNeedsDisplay();
135 686 }
136 bool Layer::blocksPendingCommit() const 687
137 { 688 void Layer::CreateRenderSurface() {
689 DCHECK(!draw_properties_.render_surface);
690 draw_properties_.render_surface = make_scoped_ptr(new RenderSurface(this));
691 draw_properties_.render_target = this;
692 }
693
694 void Layer::OnOpacityAnimated(float opacity) {
695 // This is called due to an ongoing accelerated animation. Since this
696 // animation is also being run on the impl thread, there is no need to request
697 // a commit to push this value over, so set the value directly rather than
698 // calling setOpacity.
699 opacity_ = opacity;
700 }
701
702 void Layer::OnTransformAnimated(const gfx::Transform& transform) {
703 // This is called due to an ongoing accelerated animation. Since this
704 // animation is also being run on the impl thread, there is no need to request
705 // a commit to push this value over, so set this value directly rather than
706 // calling setTransform.
707 transform_ = transform;
708 }
709
710 bool Layer::IsActive() const {
711 return true;
712 }
713
714 bool Layer::AddAnimation(scoped_ptr <Animation> animation) {
715 if (!layer_animation_controller_->animation_registrar())
138 return false; 716 return false;
139 } 717
140 718 layer_animation_controller_->AddAnimation(animation.Pass());
141 bool Layer::canClipSelf() const 719 SetNeedsCommit();
142 { 720 return true;
143 return false; 721 }
144 } 722
145 723 void Layer::PauseAnimation(int animation_id, double time_offset) {
146 bool Layer::blocksPendingCommitRecursive() const 724 layer_animation_controller_->PauseAnimation(animation_id, time_offset);
147 { 725 SetNeedsCommit();
148 if (blocksPendingCommit()) 726 }
149 return true; 727
150 if (maskLayer() && maskLayer()->blocksPendingCommitRecursive()) 728 void Layer::RemoveAnimation(int animation_id) {
151 return true; 729 layer_animation_controller_->RemoveAnimation(animation_id);
152 if (replicaLayer() && replicaLayer()->blocksPendingCommitRecursive()) 730 SetNeedsCommit();
153 return true; 731 }
154 for (size_t i = 0; i < m_children.size(); ++i) 732
155 { 733 void Layer::SuspendAnimations(double monotonic_time) {
156 if (m_children[i]->blocksPendingCommitRecursive()) 734 layer_animation_controller_->SuspendAnimations(monotonic_time);
157 return true; 735 SetNeedsCommit();
158 } 736 }
159 return false; 737
160 } 738 void Layer::ResumeAnimations(double monotonic_time) {
161 739 layer_animation_controller_->ResumeAnimations(monotonic_time);
162 void Layer::setParent(Layer* layer) 740 SetNeedsCommit();
163 { 741 }
164 DCHECK(!layer || !layer->hasAncestor(this)); 742
165 m_parent = layer; 743 void Layer::SetLayerAnimationController(
166 setLayerTreeHost(m_parent ? m_parent->layerTreeHost() : 0); 744 scoped_refptr<LayerAnimationController> controller) {
167 745 RemoveLayerAnimationEventObserver(layer_animation_controller_.get());
168 forceAutomaticRasterScaleToBeRecomputed(); 746 layer_animation_controller_->RemoveObserver(this);
169 if (m_maskLayer) 747 layer_animation_controller_ = controller;
170 m_maskLayer->forceAutomaticRasterScaleToBeRecomputed(); 748 layer_animation_controller_->set_force_sync();
171 if (m_replicaLayer && m_replicaLayer->m_maskLayer) 749 layer_animation_controller_->AddObserver(this);
172 m_replicaLayer->m_maskLayer->forceAutomaticRasterScaleToBeRecomputed(); 750 AddLayerAnimationEventObserver(layer_animation_controller_.get());
173 } 751 SetNeedsCommit();
174 752 }
175 bool Layer::hasAncestor(Layer* ancestor) const 753
176 { 754 scoped_refptr<LayerAnimationController>
177 for (const Layer* layer = parent(); layer; layer = layer->parent()) { 755 Layer::ReleaseLayerAnimationController() {
178 if (layer == ancestor) 756 layer_animation_controller_->RemoveObserver(this);
179 return true; 757 scoped_refptr<LayerAnimationController> to_return =
180 } 758 layer_animation_controller_;
181 return false; 759 layer_animation_controller_ = LayerAnimationController::Create(id());
182 } 760 layer_animation_controller_->AddObserver(this);
183 761 layer_animation_controller_->SetAnimationRegistrar(
184 void Layer::addChild(scoped_refptr<Layer> child) 762 to_return->animation_registrar());
185 { 763 return to_return;
186 insertChild(child, m_children.size()); 764 }
187 } 765
188 766 bool Layer::HasActiveAnimation() const {
189 void Layer::insertChild(scoped_refptr<Layer> child, size_t index) 767 return layer_animation_controller_->HasActiveAnimation();
190 { 768 }
191 child->removeFromParent(); 769
192 child->setParent(this); 770 void Layer::NotifyAnimationStarted(const AnimationEvent& event,
193 child->m_stackingOrderChanged = true; 771 double wall_clock_time) {
194 772 FOR_EACH_OBSERVER(LayerAnimationEventObserver, layer_animation_observers_,
195 index = std::min(index, m_children.size()); 773 OnAnimationStarted(event));
196 m_children.insert(m_children.begin() + index, child); 774 if (layer_animation_delegate_)
197 setNeedsFullTreeSync(); 775 layer_animation_delegate_->notifyAnimationStarted(wall_clock_time);
198 } 776 }
199 777
200 void Layer::removeFromParent() 778 void Layer::NotifyAnimationFinished(double wall_clock_time) {
201 { 779 if (layer_animation_delegate_)
202 if (m_parent) 780 layer_animation_delegate_->notifyAnimationFinished(wall_clock_time);
203 m_parent->removeChildOrDependent(this); 781 }
204 } 782
205 783 void Layer::NotifyAnimationPropertyUpdate(const AnimationEvent& event) {
206 void Layer::removeChildOrDependent(Layer* child) 784 if (event.target_property == Animation::Opacity)
207 { 785 SetOpacity(event.opacity);
208 if (m_maskLayer == child) { 786 else
209 m_maskLayer->setParent(NULL); 787 SetTransform(event.transform);
210 m_maskLayer = NULL; 788 }
211 setNeedsFullTreeSync(); 789
212 return; 790 void Layer::AddLayerAnimationEventObserver(
213 } 791 LayerAnimationEventObserver* animation_observer) {
214 if (m_replicaLayer == child) { 792 if (!layer_animation_observers_.HasObserver(animation_observer))
215 m_replicaLayer->setParent(NULL); 793 layer_animation_observers_.AddObserver(animation_observer);
216 m_replicaLayer = NULL; 794 }
217 setNeedsFullTreeSync(); 795
218 return; 796 void Layer::RemoveLayerAnimationEventObserver(
219 } 797 LayerAnimationEventObserver* animation_observer) {
220 798 layer_animation_observers_.RemoveObserver(animation_observer);
221 for (LayerList::iterator iter = m_children.begin(); iter != m_children.end() ; ++iter) 799 }
222 { 800
223 if (*iter != child) 801 Region Layer::VisibleContentOpaqueRegion() const {
224 continue; 802 if (contents_opaque())
225 803 return visible_content_rect();
226 child->setParent(0); 804 return Region();
227 m_children.erase(iter); 805 }
228 setNeedsFullTreeSync(); 806
229 return; 807 ScrollbarLayer* Layer::ToScrollbarLayer() {
230 } 808 return NULL;
231 }
232
233 void Layer::replaceChild(Layer* reference, scoped_refptr<Layer> newLayer)
234 {
235 DCHECK(reference);
236 DCHECK_EQ(reference->parent(), this);
237
238 if (reference == newLayer)
239 return;
240
241 int referenceIndex = indexOfChild(reference);
242 if (referenceIndex == -1) {
243 NOTREACHED();
244 return;
245 }
246
247 reference->removeFromParent();
248
249 if (newLayer) {
250 newLayer->removeFromParent();
251 insertChild(newLayer, referenceIndex);
252 }
253 }
254
255 int Layer::indexOfChild(const Layer* reference)
256 {
257 for (size_t i = 0; i < m_children.size(); ++i) {
258 if (m_children[i] == reference)
259 return i;
260 }
261 return -1;
262 }
263
264 void Layer::setBounds(const gfx::Size& size)
265 {
266 if (bounds() == size)
267 return;
268
269 bool firstResize = bounds().IsEmpty() && !size.IsEmpty();
270
271 m_bounds = size;
272
273 if (firstResize)
274 setNeedsDisplay();
275 else
276 setNeedsCommit();
277 }
278
279 Layer* Layer::rootLayer()
280 {
281 Layer* layer = this;
282 while (layer->parent())
283 layer = layer->parent();
284 return layer;
285 }
286
287 void Layer::removeAllChildren()
288 {
289 while (m_children.size()) {
290 Layer* layer = m_children[0].get();
291 DCHECK_EQ(this, layer->parent());
292 layer->removeFromParent();
293 }
294 }
295
296 void Layer::setChildren(const LayerList& children)
297 {
298 if (children == m_children)
299 return;
300
301 removeAllChildren();
302 for (size_t i = 0; i < children.size(); ++i)
303 addChild(children[i]);
304 }
305
306 Layer* Layer::childAt(size_t index)
307 {
308 DCHECK_LT(index, m_children.size());
309 return m_children[index].get();
310 }
311
312 void Layer::setAnchorPoint(const gfx::PointF& anchorPoint)
313 {
314 if (m_anchorPoint == anchorPoint)
315 return;
316 m_anchorPoint = anchorPoint;
317 setNeedsCommit();
318 }
319
320 void Layer::setAnchorPointZ(float anchorPointZ)
321 {
322 if (m_anchorPointZ == anchorPointZ)
323 return;
324 m_anchorPointZ = anchorPointZ;
325 setNeedsCommit();
326 }
327
328 void Layer::setBackgroundColor(SkColor backgroundColor)
329 {
330 if (m_backgroundColor == backgroundColor)
331 return;
332 m_backgroundColor = backgroundColor;
333 setNeedsCommit();
334 }
335
336 void Layer::calculateContentsScale(
337 float idealContentsScale,
338 bool animatingTransformToScreen,
339 float* contentsScaleX,
340 float* contentsScaleY,
341 gfx::Size* contentBounds)
342 {
343 *contentsScaleX = 1;
344 *contentsScaleY = 1;
345 *contentBounds = bounds();
346 }
347
348 void Layer::setMasksToBounds(bool masksToBounds)
349 {
350 if (m_masksToBounds == masksToBounds)
351 return;
352 m_masksToBounds = masksToBounds;
353 setNeedsCommit();
354 }
355
356 void Layer::setMaskLayer(Layer* maskLayer)
357 {
358 if (m_maskLayer == maskLayer)
359 return;
360 if (m_maskLayer) {
361 DCHECK_EQ(this, m_maskLayer->parent());
362 m_maskLayer->removeFromParent();
363 }
364 m_maskLayer = maskLayer;
365 if (m_maskLayer) {
366 DCHECK(!m_maskLayer->parent());
367 m_maskLayer->removeFromParent();
368 m_maskLayer->setParent(this);
369 m_maskLayer->setIsMask(true);
370 }
371 setNeedsFullTreeSync();
372 }
373
374 void Layer::setReplicaLayer(Layer* layer)
375 {
376 if (m_replicaLayer == layer)
377 return;
378 if (m_replicaLayer) {
379 DCHECK_EQ(this, m_replicaLayer->parent());
380 m_replicaLayer->removeFromParent();
381 }
382 m_replicaLayer = layer;
383 if (m_replicaLayer) {
384 DCHECK(!m_replicaLayer->parent());
385 m_replicaLayer->removeFromParent();
386 m_replicaLayer->setParent(this);
387 }
388 setNeedsFullTreeSync();
389 }
390
391 void Layer::setFilters(const WebKit::WebFilterOperations& filters)
392 {
393 if (m_filters == filters)
394 return;
395 DCHECK(!m_filter);
396 m_filters = filters;
397 setNeedsCommit();
398 if (!filters.isEmpty() && m_layerTreeHost)
399 m_layerTreeHost->setNeedsFilterContext();
400 }
401
402 void Layer::setFilter(const skia::RefPtr<SkImageFilter>& filter)
403 {
404 if (m_filter.get() == filter.get())
405 return;
406 DCHECK(m_filters.isEmpty());
407 m_filter = filter;
408 setNeedsCommit();
409 if (filter && m_layerTreeHost)
410 m_layerTreeHost->setNeedsFilterContext();
411 }
412
413 void Layer::setBackgroundFilters(const WebKit::WebFilterOperations& backgroundFi lters)
414 {
415 if (m_backgroundFilters == backgroundFilters)
416 return;
417 m_backgroundFilters = backgroundFilters;
418 setNeedsCommit();
419 if (!backgroundFilters.isEmpty() && m_layerTreeHost)
420 m_layerTreeHost->setNeedsFilterContext();
421 }
422
423 void Layer::setOpacity(float opacity)
424 {
425 if (m_opacity == opacity)
426 return;
427 m_opacity = opacity;
428 setNeedsCommit();
429 }
430
431 float Layer::opacity() const
432 {
433 return m_opacity;
434 }
435
436 bool Layer::opacityIsAnimating() const
437 {
438 return m_layerAnimationController->IsAnimatingProperty(Animation::Opacity);
439 }
440
441 void Layer::setContentsOpaque(bool opaque)
442 {
443 if (m_contentsOpaque == opaque)
444 return;
445 m_contentsOpaque = opaque;
446 setNeedsCommit();
447 }
448
449 void Layer::setPosition(const gfx::PointF& position)
450 {
451 if (m_position == position)
452 return;
453 m_position = position;
454 setNeedsCommit();
455 }
456
457 void Layer::setSublayerTransform(const gfx::Transform& sublayerTransform)
458 {
459 if (m_sublayerTransform == sublayerTransform)
460 return;
461 m_sublayerTransform = sublayerTransform;
462 setNeedsCommit();
463 }
464
465 void Layer::setTransform(const gfx::Transform& transform)
466 {
467 if (m_transform == transform)
468 return;
469 m_transform = transform;
470 setNeedsCommit();
471 }
472
473 const gfx::Transform& Layer::transform() const
474 {
475 return m_transform;
476 }
477
478 bool Layer::transformIsAnimating() const
479 {
480 return m_layerAnimationController->IsAnimatingProperty(Animation::Transform) ;
481 }
482
483 void Layer::setScrollOffset(gfx::Vector2d scrollOffset)
484 {
485 if (m_scrollOffset == scrollOffset)
486 return;
487 m_scrollOffset = scrollOffset;
488 if (m_layerScrollClient)
489 m_layerScrollClient->didScroll();
490 setNeedsCommit();
491 }
492
493 void Layer::setMaxScrollOffset(gfx::Vector2d maxScrollOffset)
494 {
495 if (m_maxScrollOffset == maxScrollOffset)
496 return;
497 m_maxScrollOffset = maxScrollOffset;
498 setNeedsCommit();
499 }
500
501 void Layer::setScrollable(bool scrollable)
502 {
503 if (m_scrollable == scrollable)
504 return;
505 m_scrollable = scrollable;
506 setNeedsCommit();
507 }
508
509 void Layer::setShouldScrollOnMainThread(bool shouldScrollOnMainThread)
510 {
511 if (m_shouldScrollOnMainThread == shouldScrollOnMainThread)
512 return;
513 m_shouldScrollOnMainThread = shouldScrollOnMainThread;
514 setNeedsCommit();
515 }
516
517 void Layer::setHaveWheelEventHandlers(bool haveWheelEventHandlers)
518 {
519 if (m_haveWheelEventHandlers == haveWheelEventHandlers)
520 return;
521 m_haveWheelEventHandlers = haveWheelEventHandlers;
522 setNeedsCommit();
523 }
524
525 void Layer::setNonFastScrollableRegion(const Region& region)
526 {
527 if (m_nonFastScrollableRegion == region)
528 return;
529 m_nonFastScrollableRegion = region;
530 setNeedsCommit();
531 }
532
533 void Layer::setTouchEventHandlerRegion(const Region& region)
534 {
535 if (m_touchEventHandlerRegion == region)
536 return;
537 m_touchEventHandlerRegion = region;
538 }
539
540 void Layer::setDrawCheckerboardForMissingTiles(bool checkerboard)
541 {
542 if (m_drawCheckerboardForMissingTiles == checkerboard)
543 return;
544 m_drawCheckerboardForMissingTiles = checkerboard;
545 setNeedsCommit();
546 }
547
548 void Layer::setForceRenderSurface(bool force)
549 {
550 if (m_forceRenderSurface == force)
551 return;
552 m_forceRenderSurface = force;
553 setNeedsCommit();
554 }
555
556 void Layer::setImplTransform(const gfx::Transform& transform)
557 {
558 if (m_implTransform == transform)
559 return;
560 m_implTransform = transform;
561 setNeedsCommit();
562 }
563
564 void Layer::setDoubleSided(bool doubleSided)
565 {
566 if (m_doubleSided == doubleSided)
567 return;
568 m_doubleSided = doubleSided;
569 setNeedsCommit();
570 }
571
572 void Layer::setIsDrawable(bool isDrawable)
573 {
574 if (m_isDrawable == isDrawable)
575 return;
576
577 m_isDrawable = isDrawable;
578 setNeedsCommit();
579 }
580
581 void Layer::setNeedsDisplayRect(const gfx::RectF& dirtyRect)
582 {
583 m_updateRect.Union(dirtyRect);
584 m_needsDisplay = true;
585
586 // Simply mark the contents as dirty. For non-root layers, the call to
587 // setNeedsCommit will schedule a fresh compositing pass.
588 // For the root layer, setNeedsCommit has no effect.
589 if (drawsContent() && !m_updateRect.IsEmpty())
590 setNeedsCommit();
591 }
592
593 bool Layer::descendantIsFixedToContainerLayer() const
594 {
595 for (size_t i = 0; i < m_children.size(); ++i) {
596 if (m_children[i]->fixedToContainerLayer() || m_children[i]->descendantI sFixedToContainerLayer())
597 return true;
598 }
599 return false;
600 }
601
602 void Layer::setIsContainerForFixedPositionLayers(bool isContainerForFixedPositio nLayers)
603 {
604 if (m_isContainerForFixedPositionLayers == isContainerForFixedPositionLayers )
605 return;
606 m_isContainerForFixedPositionLayers = isContainerForFixedPositionLayers;
607
608 if (m_layerTreeHost && m_layerTreeHost->commitRequested())
609 return;
610
611 // Only request a commit if we have a fixed positioned descendant.
612 if (descendantIsFixedToContainerLayer())
613 setNeedsCommit();
614 }
615
616 void Layer::setFixedToContainerLayer(bool fixedToContainerLayer)
617 {
618 if (m_fixedToContainerLayer == fixedToContainerLayer)
619 return;
620 m_fixedToContainerLayer = fixedToContainerLayer;
621 setNeedsCommit();
622 }
623
624 void Layer::pushPropertiesTo(LayerImpl* layer)
625 {
626 layer->setAnchorPoint(m_anchorPoint);
627 layer->setAnchorPointZ(m_anchorPointZ);
628 layer->setBackgroundColor(m_backgroundColor);
629 layer->setBounds(m_bounds);
630 layer->setContentBounds(contentBounds());
631 layer->setContentsScale(contentsScaleX(), contentsScaleY());
632 layer->setDebugName(m_debugName);
633 layer->setDoubleSided(m_doubleSided);
634 layer->setDrawCheckerboardForMissingTiles(m_drawCheckerboardForMissingTiles) ;
635 layer->setForceRenderSurface(m_forceRenderSurface);
636 layer->setDrawsContent(drawsContent());
637 layer->setFilters(filters());
638 layer->setFilter(filter());
639 layer->setBackgroundFilters(backgroundFilters());
640 layer->setMasksToBounds(m_masksToBounds);
641 layer->setShouldScrollOnMainThread(m_shouldScrollOnMainThread);
642 layer->setHaveWheelEventHandlers(m_haveWheelEventHandlers);
643 layer->setNonFastScrollableRegion(m_nonFastScrollableRegion);
644 layer->setTouchEventHandlerRegion(m_touchEventHandlerRegion);
645 layer->setContentsOpaque(m_contentsOpaque);
646 if (!opacityIsAnimating())
647 layer->setOpacity(m_opacity);
648 layer->setPosition(m_position);
649 layer->setIsContainerForFixedPositionLayers(m_isContainerForFixedPositionLay ers);
650 layer->setFixedToContainerLayer(m_fixedToContainerLayer);
651 layer->setPreserves3D(preserves3D());
652 layer->setUseParentBackfaceVisibility(m_useParentBackfaceVisibility);
653 layer->setSublayerTransform(m_sublayerTransform);
654 if (!transformIsAnimating())
655 layer->setTransform(m_transform);
656
657 layer->setScrollable(m_scrollable);
658 layer->setScrollOffset(m_scrollOffset);
659 layer->setMaxScrollOffset(m_maxScrollOffset);
660
661 // If the main thread commits multiple times before the impl thread actually draws, then damage tracking
662 // will become incorrect if we simply clobber the updateRect here. The Layer Impl's updateRect needs to
663 // accumulate (i.e. union) any update changes that have occurred on the main thread.
664 m_updateRect.Union(layer->updateRect());
665 layer->setUpdateRect(m_updateRect);
666
667 if (layer->layerTreeImpl()->settings().implSidePainting) {
668 DCHECK(layer->layerTreeImpl()->IsPendingTree());
669 LayerImpl* active_twin = layer->layerTreeImpl()->FindActiveTreeLayerById (id());
670 // Update the scroll delta from the active layer, which may have
671 // adjusted its scroll delta prior to this pending layer being created.
672 // This code is identical to that in LayerImpl::setScrollDelta.
673 if (active_twin) {
674 DCHECK(layer->sentScrollDelta().IsZero());
675 layer->setScrollDelta(active_twin->scrollDelta() - active_twin->sent ScrollDelta());
676 }
677 } else {
678 layer->setScrollDelta(layer->scrollDelta() - layer->sentScrollDelta());
679 layer->setSentScrollDelta(gfx::Vector2d());
680 }
681
682 layer->setStackingOrderChanged(m_stackingOrderChanged);
683
684 m_layerAnimationController->PushAnimationUpdatesTo(layer->layerAnimationCont roller());
685
686 // Reset any state that should be cleared for the next update.
687 m_stackingOrderChanged = false;
688 m_updateRect = gfx::RectF();
689 }
690
691 scoped_ptr<LayerImpl> Layer::createLayerImpl(LayerTreeImpl* treeImpl)
692 {
693 return LayerImpl::create(treeImpl, m_layerId);
694 }
695
696 bool Layer::drawsContent() const
697 {
698 return m_isDrawable;
699 }
700
701 bool Layer::needMoreUpdates()
702 {
703 return false;
704 }
705
706 void Layer::setDebugName(const std::string& debugName)
707 {
708 m_debugName = debugName;
709 setNeedsCommit();
710 }
711
712 void Layer::setRasterScale(float scale)
713 {
714 if (m_rasterScale == scale)
715 return;
716 m_rasterScale = scale;
717
718 // When automatically computed, this acts like a draw property.
719 if (m_automaticallyComputeRasterScale)
720 return;
721 setNeedsDisplay();
722 }
723
724 void Layer::setAutomaticallyComputeRasterScale(bool automatic)
725 {
726 if (m_automaticallyComputeRasterScale == automatic)
727 return;
728 m_automaticallyComputeRasterScale = automatic;
729
730 if (m_automaticallyComputeRasterScale)
731 forceAutomaticRasterScaleToBeRecomputed();
732 else
733 setRasterScale(1);
734 }
735
736 void Layer::forceAutomaticRasterScaleToBeRecomputed()
737 {
738 if (!m_automaticallyComputeRasterScale)
739 return;
740 if (!m_rasterScale)
741 return;
742 m_rasterScale = 0;
743 setNeedsCommit();
744 }
745
746 void Layer::setBoundsContainPageScale(bool boundsContainPageScale)
747 {
748 for (size_t i = 0; i < m_children.size(); ++i)
749 m_children[i]->setBoundsContainPageScale(boundsContainPageScale);
750
751 if (boundsContainPageScale == m_boundsContainPageScale)
752 return;
753
754 m_boundsContainPageScale = boundsContainPageScale;
755 setNeedsDisplay();
756 }
757
758 void Layer::createRenderSurface()
759 {
760 DCHECK(!m_drawProperties.render_surface);
761 m_drawProperties.render_surface = make_scoped_ptr(new RenderSurface(this));
762 m_drawProperties.render_target = this;
763 }
764
765 int Layer::id() const
766 {
767 return m_layerId;
768 }
769
770 void Layer::OnOpacityAnimated(float opacity)
771 {
772 // This is called due to an ongoing accelerated animation. Since this animat ion is
773 // also being run on the impl thread, there is no need to request a commit t o push
774 // this value over, so set the value directly rather than calling setOpacity .
775 m_opacity = opacity;
776 }
777
778 void Layer::OnTransformAnimated(const gfx::Transform& transform)
779 {
780 // This is called due to an ongoing accelerated animation. Since this animat ion is
781 // also being run on the impl thread, there is no need to request a commit t o push
782 // this value over, so set this value directly rather than calling setTransf orm.
783 m_transform = transform;
784 }
785
786 bool Layer::IsActive() const
787 {
788 return true;
789 }
790
791 bool Layer::AddAnimation(scoped_ptr <Animation> animation)
792 {
793 if (!m_layerAnimationController->animation_registrar())
794 return false;
795
796 m_layerAnimationController->AddAnimation(animation.Pass());
797 setNeedsCommit();
798 return true;
799 }
800
801 void Layer::PauseAnimation(int animationId, double timeOffset)
802 {
803 m_layerAnimationController->PauseAnimation(animationId, timeOffset);
804 setNeedsCommit();
805 }
806
807 void Layer::RemoveAnimation(int animationId)
808 {
809 m_layerAnimationController->RemoveAnimation(animationId);
810 setNeedsCommit();
811 }
812
813 void Layer::suspendAnimations(double monotonicTime)
814 {
815 m_layerAnimationController->SuspendAnimations(monotonicTime);
816 setNeedsCommit();
817 }
818
819 void Layer::resumeAnimations(double monotonicTime)
820 {
821 m_layerAnimationController->ResumeAnimations(monotonicTime);
822 setNeedsCommit();
823 }
824
825 void Layer::setLayerAnimationController(scoped_refptr<LayerAnimationController> layerAnimationController)
826 {
827 removeLayerAnimationEventObserver(m_layerAnimationController.get());
828 m_layerAnimationController->RemoveObserver(this);
829 m_layerAnimationController = layerAnimationController;
830 m_layerAnimationController->set_force_sync();
831 m_layerAnimationController->AddObserver(this);
832 addLayerAnimationEventObserver(m_layerAnimationController.get());
833 setNeedsCommit();
834 }
835
836 scoped_refptr<LayerAnimationController> Layer::releaseLayerAnimationController()
837 {
838 m_layerAnimationController->RemoveObserver(this);
839 scoped_refptr<LayerAnimationController> toReturn = m_layerAnimationControlle r;
840 m_layerAnimationController = LayerAnimationController::Create(id());
841 m_layerAnimationController->AddObserver(this);
842 m_layerAnimationController->SetAnimationRegistrar(toReturn->animation_regist rar());
843 return toReturn;
844 }
845
846 bool Layer::hasActiveAnimation() const
847 {
848 return m_layerAnimationController->HasActiveAnimation();
849 }
850
851 void Layer::notifyAnimationStarted(const AnimationEvent& event, double wallClock Time)
852 {
853 FOR_EACH_OBSERVER(LayerAnimationEventObserver, m_layerAnimationObservers,
854 OnAnimationStarted(event));
855 if (m_layerAnimationDelegate)
856 m_layerAnimationDelegate->notifyAnimationStarted(wallClockTime);
857 }
858
859 void Layer::notifyAnimationFinished(double wallClockTime)
860 {
861 if (m_layerAnimationDelegate)
862 m_layerAnimationDelegate->notifyAnimationFinished(wallClockTime);
863 }
864
865 void Layer::notifyAnimationPropertyUpdate(const AnimationEvent& event)
866 {
867 if (event.target_property == Animation::Opacity)
868 setOpacity(event.opacity);
869 else
870 setTransform(event.transform);
871 }
872
873 void Layer::addLayerAnimationEventObserver(LayerAnimationEventObserver* animatio nObserver)
874 {
875 if (!m_layerAnimationObservers.HasObserver(animationObserver))
876 m_layerAnimationObservers.AddObserver(animationObserver);
877 }
878
879 void Layer::removeLayerAnimationEventObserver(LayerAnimationEventObserver* anima tionObserver)
880 {
881 m_layerAnimationObservers.RemoveObserver(animationObserver);
882 }
883
884 Region Layer::visibleContentOpaqueRegion() const
885 {
886 if (contentsOpaque())
887 return visibleContentRect();
888 return Region();
889 }
890
891 ScrollbarLayer* Layer::toScrollbarLayer()
892 {
893 return 0;
894 }
895
896 void sortLayers(std::vector<scoped_refptr<Layer> >::iterator, std::vector<scoped _refptr<Layer> >::iterator, void*)
897 {
898 // Currently we don't use z-order to decide what to paint, so there's no nee d to actually sort Layers.
899 } 809 }
900 810
901 } // namespace cc 811 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698