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

Unified 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 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 a1cb0fe9b202ed5f2cdb0e1dcb8f0493a40ea01b..cdc2d8de6239d8fd497c96443418ef7cffe2af4e 100644
--- a/cc/layers/layer.cc
+++ b/cc/layers/layer.cc
@@ -12,6 +12,7 @@
#include "cc/animation/layer_animation_controller.h"
#include "cc/base/thread.h"
#include "cc/layers/layer_impl.h"
+#include "cc/output/copy_output_request.h"
#include "cc/trees/layer_tree_host.h"
#include "cc/trees/layer_tree_impl.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebAnimationDelegate.h"
@@ -67,9 +68,6 @@ 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.
@@ -311,11 +309,12 @@ void Layer::SetChildren(const LayerList& children) {
AddChild(children[i]);
}
-void Layer::RequestCopyAsBitmap(RequestCopyAsBitmapCallback callback) {
+void Layer::RequestCopyOfOutput(
+ scoped_ptr<CopyOutputRequest> request) {
DCHECK(IsPropertyChangeAllowed());
- if (callback.is_null())
+ if (request->IsEmpty())
return;
- request_copy_callbacks_.push_back(callback);
+ copy_requests_.push_back(request.Pass());
SetNeedsCommit();
}
@@ -622,18 +621,17 @@ void Layer::SetPositionConstraint(const LayerPositionConstraint& constraint) {
SetNeedsCommit();
}
-static void RunCopyCallbackOnMainThread(
- const Layer::RequestCopyAsBitmapCallback& callback,
- scoped_ptr<SkBitmap> bitmap) {
- callback.Run(bitmap.Pass());
+static void RunCopyCallbackOnMainThread(scoped_ptr<CopyOutputRequest> request,
+ scoped_ptr<SkBitmap> bitmap) {
+ if (request->HasBitmapRequest())
+ request->SendBitmapResult(bitmap.Pass());
}
-static void PostCopyCallbackToMainThread(
- Thread* main_thread,
- const Layer::RequestCopyAsBitmapCallback& callback,
- scoped_ptr<SkBitmap> bitmap) {
+static void PostCopyCallbackToMainThread(Thread* main_thread,
+ scoped_ptr<CopyOutputRequest> request,
+ scoped_ptr<SkBitmap> bitmap) {
main_thread->PostTask(base::Bind(&RunCopyCallbackOnMainThread,
- callback,
+ base::Passed(&request),
base::Passed(&bitmap)));
}
@@ -678,16 +676,21 @@ 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]));
+ // Wrap the copy_requests_ in a PostTask to the main thread.
+ ScopedPtrVector<CopyOutputRequest> main_thread_copy_requests;
+ for (ScopedPtrVector<CopyOutputRequest>::iterator it = copy_requests_.begin();
+ it != copy_requests_.end();
+ ++it) {
+ scoped_ptr<CopyOutputRequest> original_request = copy_requests_.take(it);
+ scoped_ptr<CopyOutputRequest> main_thread_request =
+ CopyOutputRequest::CreateBitmapRequest(base::Bind(
+ &PostCopyCallbackToMainThread,
+ layer_tree_host()->proxy()->MainThread(),
+ base::Passed(&original_request)));
+ main_thread_copy_requests.push_back(main_thread_request.Pass());
}
- request_copy_callbacks_.clear();
- layer->PassRequestCopyCallbacks(&main_thread_request_copy_callbacks);
+ copy_requests_.clear();
+ layer->PassCopyRequests(&main_thread_copy_requests);
// If the main thread commits multiple times before the impl thread actually
// draws, then damage tracking will become incorrect if we simply clobber the
« 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