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

Side by Side Diff: cc/layers/layer.cc

Issue 14060015: cc: Async readback. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 8 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/layers/layer.h ('k') | cc/layers/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
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/layers/layer.h" 5 #include "cc/layers/layer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "cc/animation/animation.h" 10 #include "cc/animation/animation.h"
11 #include "cc/animation/animation_events.h" 11 #include "cc/animation/animation_events.h"
12 #include "cc/animation/layer_animation_controller.h" 12 #include "cc/animation/layer_animation_controller.h"
13 #include "cc/base/thread.h"
13 #include "cc/layers/layer_impl.h" 14 #include "cc/layers/layer_impl.h"
14 #include "cc/trees/layer_tree_host.h" 15 #include "cc/trees/layer_tree_host.h"
15 #include "cc/trees/layer_tree_impl.h" 16 #include "cc/trees/layer_tree_impl.h"
16 #include "third_party/WebKit/Source/Platform/chromium/public/WebAnimationDelegat e.h" 17 #include "third_party/WebKit/Source/Platform/chromium/public/WebAnimationDelegat e.h"
17 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayerScrollClien t.h" 18 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayerScrollClien t.h"
18 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" 19 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h"
19 #include "third_party/skia/include/core/SkImageFilter.h" 20 #include "third_party/skia/include/core/SkImageFilter.h"
20 #include "ui/gfx/rect_conversions.h" 21 #include "ui/gfx/rect_conversions.h"
21 22
22 namespace cc { 23 namespace cc {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 63
63 layer_animation_controller_ = LayerAnimationController::Create(layer_id_); 64 layer_animation_controller_ = LayerAnimationController::Create(layer_id_);
64 layer_animation_controller_->AddValueObserver(this); 65 layer_animation_controller_->AddValueObserver(this);
65 } 66 }
66 67
67 Layer::~Layer() { 68 Layer::~Layer() {
68 // Our parent should be holding a reference to us so there should be no 69 // 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 // way for us to be destroyed while we still have a parent.
70 DCHECK(!parent()); 71 DCHECK(!parent());
71 72
73 for (size_t i = 0; i < request_copy_callbacks_.size(); ++i)
74 request_copy_callbacks_[i].Run(scoped_ptr<SkBitmap>());
75
72 layer_animation_controller_->RemoveValueObserver(this); 76 layer_animation_controller_->RemoveValueObserver(this);
73 77
74 // Remove the parent reference from all children and dependents. 78 // Remove the parent reference from all children and dependents.
75 RemoveAllChildren(); 79 RemoveAllChildren();
76 if (mask_layer_) { 80 if (mask_layer_) {
77 DCHECK_EQ(this, mask_layer_->parent()); 81 DCHECK_EQ(this, mask_layer_->parent());
78 mask_layer_->RemoveFromParent(); 82 mask_layer_->RemoveFromParent();
79 } 83 }
80 if (replica_layer_) { 84 if (replica_layer_) {
81 DCHECK_EQ(this, replica_layer_->parent()); 85 DCHECK_EQ(this, replica_layer_->parent());
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 void Layer::SetChildren(const LayerList& children) { 298 void Layer::SetChildren(const LayerList& children) {
295 DCHECK(IsPropertyChangeAllowed()); 299 DCHECK(IsPropertyChangeAllowed());
296 if (children == children_) 300 if (children == children_)
297 return; 301 return;
298 302
299 RemoveAllChildren(); 303 RemoveAllChildren();
300 for (size_t i = 0; i < children.size(); ++i) 304 for (size_t i = 0; i < children.size(); ++i)
301 AddChild(children[i]); 305 AddChild(children[i]);
302 } 306 }
303 307
308 void Layer::RequestCopyAsBitmap(RequestCopyAsBitmapCallback callback) {
309 DCHECK(IsPropertyChangeAllowed());
310 if (callback.is_null())
311 return;
312 request_copy_callbacks_.push_back(callback);
313 SetNeedsCommit();
314 }
315
304 void Layer::SetAnchorPoint(gfx::PointF anchor_point) { 316 void Layer::SetAnchorPoint(gfx::PointF anchor_point) {
305 DCHECK(IsPropertyChangeAllowed()); 317 DCHECK(IsPropertyChangeAllowed());
306 if (anchor_point_ == anchor_point) 318 if (anchor_point_ == anchor_point)
307 return; 319 return;
308 anchor_point_ = anchor_point; 320 anchor_point_ = anchor_point;
309 SetNeedsCommit(); 321 SetNeedsCommit();
310 } 322 }
311 323
312 void Layer::SetAnchorPointZ(float anchor_point_z) { 324 void Layer::SetAnchorPointZ(float anchor_point_z) {
313 DCHECK(IsPropertyChangeAllowed()); 325 DCHECK(IsPropertyChangeAllowed());
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 } 615 }
604 616
605 void Layer::SetPositionConstraint(const LayerPositionConstraint& constraint) { 617 void Layer::SetPositionConstraint(const LayerPositionConstraint& constraint) {
606 DCHECK(IsPropertyChangeAllowed()); 618 DCHECK(IsPropertyChangeAllowed());
607 if (position_constraint_ == constraint) 619 if (position_constraint_ == constraint)
608 return; 620 return;
609 position_constraint_ = constraint; 621 position_constraint_ = constraint;
610 SetNeedsCommit(); 622 SetNeedsCommit();
611 } 623 }
612 624
625 static void RunCopyCallbackOnMainThread(
626 const Layer::RequestCopyAsBitmapCallback& callback,
627 scoped_ptr<SkBitmap> bitmap) {
628 callback.Run(bitmap.Pass());
629 }
630
631 static void PostCopyCallbackToMainThread(
632 Thread* main_thread,
633 const Layer::RequestCopyAsBitmapCallback& callback,
634 scoped_ptr<SkBitmap> bitmap) {
635 main_thread->PostTask(base::Bind(&RunCopyCallbackOnMainThread,
636 callback,
637 base::Passed(&bitmap)));
638 }
639
613 void Layer::PushPropertiesTo(LayerImpl* layer) { 640 void Layer::PushPropertiesTo(LayerImpl* layer) {
614 layer->SetAnchorPoint(anchor_point_); 641 layer->SetAnchorPoint(anchor_point_);
615 layer->SetAnchorPointZ(anchor_point_z_); 642 layer->SetAnchorPointZ(anchor_point_z_);
616 layer->SetBackgroundColor(background_color_); 643 layer->SetBackgroundColor(background_color_);
617 layer->SetBounds(paint_properties_.bounds); 644 layer->SetBounds(paint_properties_.bounds);
618 layer->SetContentBounds(content_bounds()); 645 layer->SetContentBounds(content_bounds());
619 layer->SetContentsScale(contents_scale_x(), contents_scale_y()); 646 layer->SetContentsScale(contents_scale_x(), contents_scale_y());
620 layer->SetDebugName(debug_name_); 647 layer->SetDebugName(debug_name_);
621 layer->SetDoubleSided(double_sided_); 648 layer->SetDoubleSided(double_sided_);
622 layer->SetDrawCheckerboardForMissingTiles( 649 layer->SetDrawCheckerboardForMissingTiles(
(...skipping 21 matching lines...) Expand all
644 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); 671 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_);
645 layer->SetSublayerTransform(sublayer_transform_); 672 layer->SetSublayerTransform(sublayer_transform_);
646 if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating()) 673 if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating())
647 layer->SetTransform(transform_); 674 layer->SetTransform(transform_);
648 DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly())); 675 DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly()));
649 676
650 layer->SetScrollable(scrollable_); 677 layer->SetScrollable(scrollable_);
651 layer->SetScrollOffset(scroll_offset_); 678 layer->SetScrollOffset(scroll_offset_);
652 layer->SetMaxScrollOffset(max_scroll_offset_); 679 layer->SetMaxScrollOffset(max_scroll_offset_);
653 680
681 // Wrap the request_copy_callbacks_ in a PostTask to the main thread.
682 std::vector<RequestCopyAsBitmapCallback> main_thread_request_copy_callbacks;
683 for (size_t i = 0; i < request_copy_callbacks_.size(); ++i) {
684 main_thread_request_copy_callbacks.push_back(
685 base::Bind(&PostCopyCallbackToMainThread,
686 layer_tree_host()->proxy()->MainThread(),
687 request_copy_callbacks_[i]));
688 }
689 request_copy_callbacks_.clear();
690 layer->PassRequestCopyCallbacks(&main_thread_request_copy_callbacks);
691
654 // If the main thread commits multiple times before the impl thread actually 692 // If the main thread commits multiple times before the impl thread actually
655 // draws, then damage tracking will become incorrect if we simply clobber the 693 // draws, then damage tracking will become incorrect if we simply clobber the
656 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e. 694 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e.
657 // union) any update changes that have occurred on the main thread. 695 // union) any update changes that have occurred on the main thread.
658 update_rect_.Union(layer->update_rect()); 696 update_rect_.Union(layer->update_rect());
659 layer->set_update_rect(update_rect_); 697 layer->set_update_rect(update_rect_);
660 698
661 if (layer->layer_tree_impl()->settings().impl_side_painting) { 699 if (layer->layer_tree_impl()->settings().impl_side_painting) {
662 DCHECK(layer->layer_tree_impl()->IsPendingTree()); 700 DCHECK(layer->layer_tree_impl()->IsPendingTree());
663 LayerImpl* active_twin = 701 LayerImpl* active_twin =
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 885
848 ScrollbarLayer* Layer::ToScrollbarLayer() { 886 ScrollbarLayer* Layer::ToScrollbarLayer() {
849 return NULL; 887 return NULL;
850 } 888 }
851 889
852 RenderingStatsInstrumentation* Layer::rendering_stats_instrumentation() const { 890 RenderingStatsInstrumentation* Layer::rendering_stats_instrumentation() const {
853 return layer_tree_host_->rendering_stats_instrumentation(); 891 return layer_tree_host_->rendering_stats_instrumentation();
854 } 892 }
855 893
856 } // namespace cc 894 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/layer.h ('k') | cc/layers/layer_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698