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

Unified Diff: ui/compositor/layer_unittest.cc

Issue 133273026: cc: Remove ReadPixels from compositor layer_unittests.cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Final patch Created 6 years, 11 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/compositor/layer_unittest.cc
diff --git a/ui/compositor/layer_unittest.cc b/ui/compositor/layer_unittest.cc
index 71aa73f28773d705542e1d51bc954f2ae09f70f1..736f92af0911c329ecbf83f6fce48de13966bb2f 100644
--- a/ui/compositor/layer_unittest.cc
+++ b/ui/compositor/layer_unittest.cc
@@ -17,6 +17,8 @@
#include "cc/layers/delegated_frame_provider.h"
#include "cc/layers/delegated_frame_resource_collection.h"
#include "cc/layers/layer.h"
+#include "cc/output/copy_output_request.h"
+#include "cc/output/copy_output_result.h"
#include "cc/output/delegated_frame_data.h"
#include "cc/test/pixel_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -129,8 +131,34 @@ class LayerWithRealCompositorTest : public testing::Test {
}
bool ReadPixels(SkBitmap* bitmap) {
- return GetCompositor()->ReadPixels(bitmap,
- gfx::Rect(GetCompositor()->size()));
+ return ReadPixels(bitmap, gfx::Rect(GetCompositor()->size()));
+ }
+
+ bool ReadPixels(SkBitmap* bitmap, gfx::Rect source_rect) {
+ scoped_refptr<ReadbackHolder> holder(new ReadbackHolder);
+ scoped_ptr<cc::CopyOutputRequest> request =
+ cc::CopyOutputRequest::CreateBitmapRequest(
+ base::Bind(&ReadbackHolder::OutputRequestCallback, holder));
+ request->set_area(source_rect);
+
+ GetCompositor()->root_layer()->RequestCopyOfOutput(request.Pass());
+
+ // Wait for copy response. This needs to wait as the compositor could
+ // be in the middle of a draw right now, and the commit with the
+ // copy output request may not be done on the first draw.
+ for (int i = 0; i < 2; i++) {
+ GetCompositor()->ScheduleDraw();
+ WaitForDraw();
+ }
+
+ if (holder->completed()) {
+ *bitmap = holder->result();
+ return true;
+ }
+
+ // Callback never called.
+ NOTREACHED();
+ return false;
}
void WaitForDraw() {
@@ -152,6 +180,29 @@ class LayerWithRealCompositorTest : public testing::Test {
}
private:
+ class ReadbackHolder : public base::RefCountedThreadSafe<ReadbackHolder> {
+ public:
+ ReadbackHolder() : completed_(false) {}
+
+ void OutputRequestCallback(scoped_ptr<cc::CopyOutputResult> result) {
+ DCHECK(!completed_);
+ result_ = result->TakeBitmap();
+ completed_ = true;
+ }
+ bool completed() const {
+ return completed_;
+ };
+ const SkBitmap& result() const { return *result_; }
+
+ private:
+ friend class base::RefCountedThreadSafe<ReadbackHolder>;
+
+ virtual ~ReadbackHolder() {}
+
+ scoped_ptr<SkBitmap> result_;
+ bool completed_;
+ };
+
scoped_ptr<TestCompositorHost> window_;
// The root directory for test files.
@@ -806,7 +857,7 @@ TEST_F(LayerWithRealCompositorTest, DrawPixels) {
DrawTree(layer.get());
SkBitmap bitmap;
- ASSERT_TRUE(GetCompositor()->ReadPixels(&bitmap, gfx::Rect(viewport_size)));
+ ASSERT_TRUE(ReadPixels(&bitmap, gfx::Rect(viewport_size)));
ASSERT_FALSE(bitmap.empty());
SkAutoLockPixels lock(bitmap);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698