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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/layers/layer.h ('k') | cc/layers/layer_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
« 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