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

Side by Side 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: Remove unused task runner 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "cc/layers/delegated_frame_provider.h" 15 #include "cc/layers/delegated_frame_provider.h"
16 #include "cc/layers/delegated_frame_resource_collection.h" 16 #include "cc/layers/delegated_frame_resource_collection.h"
17 #include "cc/layers/layer.h" 17 #include "cc/layers/layer.h"
18 #include "cc/output/copy_output_request.h"
19 #include "cc/output/copy_output_result.h"
18 #include "cc/output/delegated_frame_data.h" 20 #include "cc/output/delegated_frame_data.h"
19 #include "cc/test/pixel_test_utils.h" 21 #include "cc/test/pixel_test_utils.h"
20 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
21 #include "ui/compositor/compositor_observer.h" 23 #include "ui/compositor/compositor_observer.h"
22 #include "ui/compositor/layer.h" 24 #include "ui/compositor/layer.h"
23 #include "ui/compositor/layer_animation_sequence.h" 25 #include "ui/compositor/layer_animation_sequence.h"
24 #include "ui/compositor/layer_animator.h" 26 #include "ui/compositor/layer_animator.h"
25 #include "ui/compositor/test/context_factories_for_test.h" 27 #include "ui/compositor/test/context_factories_for_test.h"
26 #include "ui/compositor/test/test_compositor_host.h" 28 #include "ui/compositor/test/test_compositor_host.h"
27 #include "ui/compositor/test/test_layers.h" 29 #include "ui/compositor/test/test_layers.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 return layer; 121 return layer;
120 } 122 }
121 123
122 void DrawTree(Layer* root) { 124 void DrawTree(Layer* root) {
123 GetCompositor()->SetRootLayer(root); 125 GetCompositor()->SetRootLayer(root);
124 GetCompositor()->ScheduleDraw(); 126 GetCompositor()->ScheduleDraw();
125 WaitForDraw(); 127 WaitForDraw();
126 } 128 }
127 129
128 bool ReadPixels(SkBitmap* bitmap) { 130 bool ReadPixels(SkBitmap* bitmap) {
129 return GetCompositor()->ReadPixels(bitmap, 131 return ReadPixels(bitmap, gfx::Rect(GetCompositor()->size()));
130 gfx::Rect(GetCompositor()->size())); 132 }
133
134 bool ReadPixels(SkBitmap* bitmap, gfx::Rect source_rect) {
135 scoped_refptr<ReadbackHolder> holder(new ReadbackHolder);
136 scoped_ptr<cc::CopyOutputRequest> request =
137 cc::CopyOutputRequest::CreateBitmapRequest(
138 base::Bind(&ReadbackHolder::OutputRequestCallback, holder));
139 request->set_area(source_rect);
140
141 GetCompositor()->root_layer()->RequestCopyOfOutput(request.Pass());
142
143 // Wait for copy response.
144 WaitForDraw();
145
146 if (holder->completed()) {
147 *bitmap = holder->result();
148 return true;
149 }
150
151 // Callback never called.
152 NOTREACHED();
153 return false;
131 } 154 }
132 155
133 void WaitForDraw() { 156 void WaitForDraw() {
134 ui::DrawWaiterForTest::Wait(GetCompositor()); 157 ui::DrawWaiterForTest::Wait(GetCompositor());
135 } 158 }
136 159
137 void WaitForCommit() { 160 void WaitForCommit() {
138 ui::DrawWaiterForTest::WaitForCommit(GetCompositor()); 161 ui::DrawWaiterForTest::WaitForCommit(GetCompositor());
139 } 162 }
140 163
141 // Invalidates the entire contents of the layer. 164 // Invalidates the entire contents of the layer.
142 void SchedulePaintForLayer(Layer* layer) { 165 void SchedulePaintForLayer(Layer* layer) {
143 layer->SchedulePaint( 166 layer->SchedulePaint(
144 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height())); 167 gfx::Rect(0, 0, layer->bounds().width(), layer->bounds().height()));
145 } 168 }
146 169
147 const base::FilePath& test_data_directory() const { 170 const base::FilePath& test_data_directory() const {
148 return test_data_directory_; 171 return test_data_directory_;
149 } 172 }
150 173
151 private: 174 private:
175 class ReadbackHolder : public base::RefCountedThreadSafe<ReadbackHolder> {
176 public:
177 ReadbackHolder() : completed_(false) {}
178
179 void OutputRequestCallback(scoped_ptr<cc::CopyOutputResult> result) {
180 DCHECK(!completed_);
181 result_ = result->TakeBitmap();
182 completed_ = true;
183 }
184 bool completed() const {
185 return completed_;
186 };
187 const SkBitmap& result() const { return *result_.get(); }
danakj 2014/01/17 17:36:36 can't you just do *result?
enne (OOO) 2014/01/17 17:51:13 I don't think so, since result is a scoped_ptr.
enne (OOO) 2014/01/17 17:52:27 By which I mean I misunderstood what you were aski
188
189 private:
190 friend class base::RefCountedThreadSafe<ReadbackHolder>;
191
192 virtual ~ReadbackHolder() {}
193
194 scoped_ptr<SkBitmap> result_;
195 bool completed_;
196 };
197
152 scoped_ptr<TestCompositorHost> window_; 198 scoped_ptr<TestCompositorHost> window_;
153 199
154 // The root directory for test files. 200 // The root directory for test files.
155 base::FilePath test_data_directory_; 201 base::FilePath test_data_directory_;
156 202
157 DISALLOW_COPY_AND_ASSIGN(LayerWithRealCompositorTest); 203 DISALLOW_COPY_AND_ASSIGN(LayerWithRealCompositorTest);
158 }; 204 };
159 205
160 // LayerDelegate that paints colors to the layer. 206 // LayerDelegate that paints colors to the layer.
161 class TestLayerDelegate : public LayerDelegate { 207 class TestLayerDelegate : public LayerDelegate {
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 CreateColorLayer(SK_ColorRED, gfx::Rect(viewport_size))); 822 CreateColorLayer(SK_ColorRED, gfx::Rect(viewport_size)));
777 scoped_ptr<Layer> layer2( 823 scoped_ptr<Layer> layer2(
778 CreateColorLayer(SK_ColorBLUE, 824 CreateColorLayer(SK_ColorBLUE,
779 gfx::Rect(0, 0, viewport_size.width(), blue_height))); 825 gfx::Rect(0, 0, viewport_size.width(), blue_height)));
780 826
781 layer->Add(layer2.get()); 827 layer->Add(layer2.get());
782 828
783 DrawTree(layer.get()); 829 DrawTree(layer.get());
784 830
785 SkBitmap bitmap; 831 SkBitmap bitmap;
786 ASSERT_TRUE(GetCompositor()->ReadPixels(&bitmap, gfx::Rect(viewport_size))); 832 ASSERT_TRUE(ReadPixels(&bitmap, gfx::Rect(viewport_size)));
787 ASSERT_FALSE(bitmap.empty()); 833 ASSERT_FALSE(bitmap.empty());
788 834
789 SkAutoLockPixels lock(bitmap); 835 SkAutoLockPixels lock(bitmap);
790 for (int x = 0; x < viewport_size.width(); x++) { 836 for (int x = 0; x < viewport_size.width(); x++) {
791 for (int y = 0; y < viewport_size.height(); y++) { 837 for (int y = 0; y < viewport_size.height(); y++) {
792 SkColor actual_color = bitmap.getColor(x, y); 838 SkColor actual_color = bitmap.getColor(x, y);
793 SkColor expected_color = y < blue_height ? SK_ColorBLUE : SK_ColorRED; 839 SkColor expected_color = y < blue_height ? SK_ColorBLUE : SK_ColorRED;
794 EXPECT_EQ(expected_color, actual_color) 840 EXPECT_EQ(expected_color, actual_color)
795 << "Pixel error at x=" << x << " y=" << y << "; " 841 << "Pixel error at x=" << x << " y=" << y << "; "
796 << "actual RGBA=(" 842 << "actual RGBA=("
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
1442 l1->SetOpacity(0.5f); 1488 l1->SetOpacity(0.5f);
1443 1489
1444 // Change l1's cc::Layer. 1490 // Change l1's cc::Layer.
1445 l1->SwitchCCLayerForTest(); 1491 l1->SwitchCCLayerForTest();
1446 1492
1447 // Ensure that the opacity animation completed. 1493 // Ensure that the opacity animation completed.
1448 EXPECT_FLOAT_EQ(l1->opacity(), 0.5f); 1494 EXPECT_FLOAT_EQ(l1->opacity(), 0.5f);
1449 } 1495 }
1450 1496
1451 } // namespace ui 1497 } // namespace ui
OLDNEW
« 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