| Index: cc/layers/layer.cc
|
| diff --git a/cc/layers/layer.cc b/cc/layers/layer.cc
|
| index 43a0335a889f2aadd0040ff26c87958adfd0e161..6584e718a6e86a40e319bb94e11d9ea00ec978e6 100644
|
| --- a/cc/layers/layer.cc
|
| +++ b/cc/layers/layer.cc
|
| @@ -10,6 +10,7 @@
|
| #include "cc/animation/animation.h"
|
| #include "cc/animation/animation_events.h"
|
| #include "cc/animation/layer_animation_controller.h"
|
| +#include "cc/base/thread.h"
|
| #include "cc/layers/layer_impl.h"
|
| #include "cc/trees/layer_tree_host.h"
|
| #include "cc/trees/layer_tree_impl.h"
|
| @@ -69,6 +70,9 @@ Layer::~Layer() {
|
| // way for us to be destroyed while we still have a parent.
|
| DCHECK(!parent());
|
|
|
| + for (size_t i = 0; i < request_copy_callbacks_.size(); ++i)
|
| + request_copy_callbacks_[i].Run(scoped_ptr<SkBitmap>());
|
| +
|
| layer_animation_controller_->RemoveValueObserver(this);
|
|
|
| // Remove the parent reference from all children and dependents.
|
| @@ -301,6 +305,14 @@ void Layer::SetChildren(const LayerList& children) {
|
| AddChild(children[i]);
|
| }
|
|
|
| +void Layer::RequestCopyAsBitmap(RequestCopyAsBitmapCallback callback) {
|
| + DCHECK(IsPropertyChangeAllowed());
|
| + if (callback.is_null())
|
| + return;
|
| + request_copy_callbacks_.push_back(callback);
|
| + SetNeedsCommit();
|
| +}
|
| +
|
| void Layer::SetAnchorPoint(gfx::PointF anchor_point) {
|
| DCHECK(IsPropertyChangeAllowed());
|
| if (anchor_point_ == anchor_point)
|
| @@ -610,6 +622,21 @@ void Layer::SetPositionConstraint(const LayerPositionConstraint& constraint) {
|
| SetNeedsCommit();
|
| }
|
|
|
| +static void RunCopyCallbackOnMainThread(
|
| + const Layer::RequestCopyAsBitmapCallback& callback,
|
| + scoped_ptr<SkBitmap> bitmap) {
|
| + callback.Run(bitmap.Pass());
|
| +}
|
| +
|
| +static void PostCopyCallbackToMainThread(
|
| + Thread* main_thread,
|
| + const Layer::RequestCopyAsBitmapCallback& callback,
|
| + scoped_ptr<SkBitmap> bitmap) {
|
| + main_thread->PostTask(base::Bind(&RunCopyCallbackOnMainThread,
|
| + callback,
|
| + base::Passed(&bitmap)));
|
| +}
|
| +
|
| void Layer::PushPropertiesTo(LayerImpl* layer) {
|
| layer->SetAnchorPoint(anchor_point_);
|
| layer->SetAnchorPointZ(anchor_point_z_);
|
| @@ -651,6 +678,17 @@ void Layer::PushPropertiesTo(LayerImpl* layer) {
|
| layer->SetScrollOffset(scroll_offset_);
|
| layer->SetMaxScrollOffset(max_scroll_offset_);
|
|
|
| + // Wrap the request_copy_callbacks_ in a PostTask to the main thread.
|
| + std::vector<RequestCopyAsBitmapCallback> main_thread_request_copy_callbacks;
|
| + for (size_t i = 0; i < request_copy_callbacks_.size(); ++i) {
|
| + main_thread_request_copy_callbacks.push_back(
|
| + base::Bind(&PostCopyCallbackToMainThread,
|
| + layer_tree_host()->proxy()->MainThread(),
|
| + request_copy_callbacks_[i]));
|
| + }
|
| + request_copy_callbacks_.clear();
|
| + layer->PassRequestCopyCallbacks(&main_thread_request_copy_callbacks);
|
| +
|
| // If the main thread commits multiple times before the impl thread actually
|
| // draws, then damage tracking will become incorrect if we simply clobber the
|
| // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e.
|
|
|