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

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

Issue 15435003: cc: Add CopyAsBitmapRequest class to hold the readback callback. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nolint Created 7 years, 7 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/base/thread.h"
14 #include "cc/layers/layer_impl.h" 14 #include "cc/layers/layer_impl.h"
15 #include "cc/output/copy_output_request.h"
15 #include "cc/trees/layer_tree_host.h" 16 #include "cc/trees/layer_tree_host.h"
16 #include "cc/trees/layer_tree_impl.h" 17 #include "cc/trees/layer_tree_impl.h"
17 #include "third_party/WebKit/Source/Platform/chromium/public/WebAnimationDelegat e.h" 18 #include "third_party/WebKit/Source/Platform/chromium/public/WebAnimationDelegat e.h"
18 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayerScrollClien t.h" 19 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayerScrollClien t.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 {
23 24
24 static int s_next_layer_id = 1; 25 static int s_next_layer_id = 1;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 61
61 layer_animation_controller_ = LayerAnimationController::Create(layer_id_); 62 layer_animation_controller_ = LayerAnimationController::Create(layer_id_);
62 layer_animation_controller_->AddValueObserver(this); 63 layer_animation_controller_->AddValueObserver(this);
63 } 64 }
64 65
65 Layer::~Layer() { 66 Layer::~Layer() {
66 // Our parent should be holding a reference to us so there should be no 67 // Our parent should be holding a reference to us so there should be no
67 // way for us to be destroyed while we still have a parent. 68 // way for us to be destroyed while we still have a parent.
68 DCHECK(!parent()); 69 DCHECK(!parent());
69 70
70 for (size_t i = 0; i < request_copy_callbacks_.size(); ++i)
71 request_copy_callbacks_[i].Run(scoped_ptr<SkBitmap>());
72
73 layer_animation_controller_->RemoveValueObserver(this); 71 layer_animation_controller_->RemoveValueObserver(this);
74 72
75 // Remove the parent reference from all children and dependents. 73 // Remove the parent reference from all children and dependents.
76 RemoveAllChildren(); 74 RemoveAllChildren();
77 if (mask_layer_) { 75 if (mask_layer_) {
78 DCHECK_EQ(this, mask_layer_->parent()); 76 DCHECK_EQ(this, mask_layer_->parent());
79 mask_layer_->RemoveFromParent(); 77 mask_layer_->RemoveFromParent();
80 } 78 }
81 if (replica_layer_) { 79 if (replica_layer_) {
82 DCHECK_EQ(this, replica_layer_->parent()); 80 DCHECK_EQ(this, replica_layer_->parent());
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 void Layer::SetChildren(const LayerList& children) { 302 void Layer::SetChildren(const LayerList& children) {
305 DCHECK(IsPropertyChangeAllowed()); 303 DCHECK(IsPropertyChangeAllowed());
306 if (children == children_) 304 if (children == children_)
307 return; 305 return;
308 306
309 RemoveAllChildren(); 307 RemoveAllChildren();
310 for (size_t i = 0; i < children.size(); ++i) 308 for (size_t i = 0; i < children.size(); ++i)
311 AddChild(children[i]); 309 AddChild(children[i]);
312 } 310 }
313 311
314 void Layer::RequestCopyAsBitmap(RequestCopyAsBitmapCallback callback) { 312 void Layer::RequestCopyOfOutput(
313 scoped_ptr<CopyOutputRequest> request) {
315 DCHECK(IsPropertyChangeAllowed()); 314 DCHECK(IsPropertyChangeAllowed());
316 if (callback.is_null()) 315 if (request->IsEmpty())
317 return; 316 return;
318 request_copy_callbacks_.push_back(callback); 317 copy_requests_.push_back(request.Pass());
319 SetNeedsCommit(); 318 SetNeedsCommit();
320 } 319 }
321 320
322 void Layer::SetAnchorPoint(gfx::PointF anchor_point) { 321 void Layer::SetAnchorPoint(gfx::PointF anchor_point) {
323 DCHECK(IsPropertyChangeAllowed()); 322 DCHECK(IsPropertyChangeAllowed());
324 if (anchor_point_ == anchor_point) 323 if (anchor_point_ == anchor_point)
325 return; 324 return;
326 anchor_point_ = anchor_point; 325 anchor_point_ = anchor_point;
327 SetNeedsCommit(); 326 SetNeedsCommit();
328 } 327 }
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 } 614 }
616 615
617 void Layer::SetPositionConstraint(const LayerPositionConstraint& constraint) { 616 void Layer::SetPositionConstraint(const LayerPositionConstraint& constraint) {
618 DCHECK(IsPropertyChangeAllowed()); 617 DCHECK(IsPropertyChangeAllowed());
619 if (position_constraint_ == constraint) 618 if (position_constraint_ == constraint)
620 return; 619 return;
621 position_constraint_ = constraint; 620 position_constraint_ = constraint;
622 SetNeedsCommit(); 621 SetNeedsCommit();
623 } 622 }
624 623
625 static void RunCopyCallbackOnMainThread( 624 static void RunCopyCallbackOnMainThread(scoped_ptr<CopyOutputRequest> request,
626 const Layer::RequestCopyAsBitmapCallback& callback, 625 scoped_ptr<SkBitmap> bitmap) {
627 scoped_ptr<SkBitmap> bitmap) { 626 if (request->HasBitmapRequest())
628 callback.Run(bitmap.Pass()); 627 request->SendBitmapResult(bitmap.Pass());
629 } 628 }
630 629
631 static void PostCopyCallbackToMainThread( 630 static void PostCopyCallbackToMainThread(Thread* main_thread,
632 Thread* main_thread, 631 scoped_ptr<CopyOutputRequest> request,
633 const Layer::RequestCopyAsBitmapCallback& callback, 632 scoped_ptr<SkBitmap> bitmap) {
634 scoped_ptr<SkBitmap> bitmap) {
635 main_thread->PostTask(base::Bind(&RunCopyCallbackOnMainThread, 633 main_thread->PostTask(base::Bind(&RunCopyCallbackOnMainThread,
636 callback, 634 base::Passed(&request),
637 base::Passed(&bitmap))); 635 base::Passed(&bitmap)));
638 } 636 }
639 637
640 void Layer::PushPropertiesTo(LayerImpl* layer) { 638 void Layer::PushPropertiesTo(LayerImpl* layer) {
641 layer->SetAnchorPoint(anchor_point_); 639 layer->SetAnchorPoint(anchor_point_);
642 layer->SetAnchorPointZ(anchor_point_z_); 640 layer->SetAnchorPointZ(anchor_point_z_);
643 layer->SetBackgroundColor(background_color_); 641 layer->SetBackgroundColor(background_color_);
644 layer->SetBounds(paint_properties_.bounds); 642 layer->SetBounds(paint_properties_.bounds);
645 layer->SetContentBounds(content_bounds()); 643 layer->SetContentBounds(content_bounds());
646 layer->SetContentsScale(contents_scale_x(), contents_scale_y()); 644 layer->SetContentsScale(contents_scale_x(), contents_scale_y());
(...skipping 24 matching lines...) Expand all
671 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); 669 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_);
672 layer->SetSublayerTransform(sublayer_transform_); 670 layer->SetSublayerTransform(sublayer_transform_);
673 if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating()) 671 if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating())
674 layer->SetTransform(transform_); 672 layer->SetTransform(transform_);
675 DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly())); 673 DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly()));
676 674
677 layer->SetScrollable(scrollable_); 675 layer->SetScrollable(scrollable_);
678 layer->SetScrollOffset(scroll_offset_); 676 layer->SetScrollOffset(scroll_offset_);
679 layer->SetMaxScrollOffset(max_scroll_offset_); 677 layer->SetMaxScrollOffset(max_scroll_offset_);
680 678
681 // Wrap the request_copy_callbacks_ in a PostTask to the main thread. 679 // Wrap the copy_requests_ in a PostTask to the main thread.
682 std::vector<RequestCopyAsBitmapCallback> main_thread_request_copy_callbacks; 680 ScopedPtrVector<CopyOutputRequest> main_thread_copy_requests;
683 for (size_t i = 0; i < request_copy_callbacks_.size(); ++i) { 681 for (ScopedPtrVector<CopyOutputRequest>::iterator it = copy_requests_.begin();
684 main_thread_request_copy_callbacks.push_back( 682 it != copy_requests_.end();
685 base::Bind(&PostCopyCallbackToMainThread, 683 ++it) {
686 layer_tree_host()->proxy()->MainThread(), 684 scoped_ptr<CopyOutputRequest> original_request = copy_requests_.take(it);
687 request_copy_callbacks_[i])); 685 scoped_ptr<CopyOutputRequest> main_thread_request =
686 CopyOutputRequest::CreateBitmapRequest(base::Bind(
687 &PostCopyCallbackToMainThread,
688 layer_tree_host()->proxy()->MainThread(),
689 base::Passed(&original_request)));
690 main_thread_copy_requests.push_back(main_thread_request.Pass());
688 } 691 }
689 request_copy_callbacks_.clear(); 692 copy_requests_.clear();
690 layer->PassRequestCopyCallbacks(&main_thread_request_copy_callbacks); 693 layer->PassCopyRequests(&main_thread_copy_requests);
691 694
692 // If the main thread commits multiple times before the impl thread actually 695 // If the main thread commits multiple times before the impl thread actually
693 // draws, then damage tracking will become incorrect if we simply clobber the 696 // draws, then damage tracking will become incorrect if we simply clobber the
694 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e. 697 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e.
695 // union) any update changes that have occurred on the main thread. 698 // union) any update changes that have occurred on the main thread.
696 update_rect_.Union(layer->update_rect()); 699 update_rect_.Union(layer->update_rect());
697 layer->set_update_rect(update_rect_); 700 layer->set_update_rect(update_rect_);
698 701
699 if (layer->layer_tree_impl()->settings().impl_side_painting) { 702 if (layer->layer_tree_impl()->settings().impl_side_painting) {
700 DCHECK(layer->layer_tree_impl()->IsPendingTree()); 703 DCHECK(layer->layer_tree_impl()->IsPendingTree());
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 846
844 ScrollbarLayer* Layer::ToScrollbarLayer() { 847 ScrollbarLayer* Layer::ToScrollbarLayer() {
845 return NULL; 848 return NULL;
846 } 849 }
847 850
848 RenderingStatsInstrumentation* Layer::rendering_stats_instrumentation() const { 851 RenderingStatsInstrumentation* Layer::rendering_stats_instrumentation() const {
849 return layer_tree_host_->rendering_stats_instrumentation(); 852 return layer_tree_host_->rendering_stats_instrumentation();
850 } 853 }
851 854
852 } // namespace cc 855 } // 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