OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "cc/test/layer_tree_pixel_test.h" | 5 #include "cc/test/layer_tree_pixel_test.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/memory/ptr_util.h" |
11 #include "base/path_service.h" | 12 #include "base/path_service.h" |
12 #include "cc/base/switches.h" | 13 #include "cc/base/switches.h" |
13 #include "cc/layers/solid_color_layer.h" | 14 #include "cc/layers/solid_color_layer.h" |
14 #include "cc/layers/texture_layer.h" | 15 #include "cc/layers/texture_layer.h" |
15 #include "cc/output/copy_output_request.h" | 16 #include "cc/output/copy_output_request.h" |
16 #include "cc/output/copy_output_result.h" | 17 #include "cc/output/copy_output_result.h" |
17 #include "cc/output/direct_renderer.h" | 18 #include "cc/output/direct_renderer.h" |
18 #include "cc/resources/texture_mailbox.h" | 19 #include "cc/resources/texture_mailbox.h" |
19 #include "cc/test/paths.h" | 20 #include "cc/test/paths.h" |
20 #include "cc/test/pixel_comparator.h" | 21 #include "cc/test/pixel_comparator.h" |
(...skipping 10 matching lines...) Expand all Loading... |
31 namespace cc { | 32 namespace cc { |
32 | 33 |
33 LayerTreePixelTest::LayerTreePixelTest() | 34 LayerTreePixelTest::LayerTreePixelTest() |
34 : pixel_comparator_(new ExactPixelComparator(true)), | 35 : pixel_comparator_(new ExactPixelComparator(true)), |
35 test_type_(PIXEL_TEST_GL), | 36 test_type_(PIXEL_TEST_GL), |
36 pending_texture_mailbox_callbacks_(0) { | 37 pending_texture_mailbox_callbacks_(0) { |
37 } | 38 } |
38 | 39 |
39 LayerTreePixelTest::~LayerTreePixelTest() {} | 40 LayerTreePixelTest::~LayerTreePixelTest() {} |
40 | 41 |
41 scoped_ptr<OutputSurface> LayerTreePixelTest::CreateOutputSurface() { | 42 std::unique_ptr<OutputSurface> LayerTreePixelTest::CreateOutputSurface() { |
42 gfx::Size surface_expansion_size(40, 60); | 43 gfx::Size surface_expansion_size(40, 60); |
43 scoped_ptr<PixelTestOutputSurface> output_surface; | 44 std::unique_ptr<PixelTestOutputSurface> output_surface; |
44 | 45 |
45 switch (test_type_) { | 46 switch (test_type_) { |
46 case PIXEL_TEST_SOFTWARE: { | 47 case PIXEL_TEST_SOFTWARE: { |
47 scoped_ptr<PixelTestSoftwareOutputDevice> software_output_device( | 48 std::unique_ptr<PixelTestSoftwareOutputDevice> software_output_device( |
48 new PixelTestSoftwareOutputDevice); | 49 new PixelTestSoftwareOutputDevice); |
49 software_output_device->set_surface_expansion_size( | 50 software_output_device->set_surface_expansion_size( |
50 surface_expansion_size); | 51 surface_expansion_size); |
51 output_surface = make_scoped_ptr( | 52 output_surface = base::WrapUnique( |
52 new PixelTestOutputSurface(std::move(software_output_device))); | 53 new PixelTestOutputSurface(std::move(software_output_device))); |
53 break; | 54 break; |
54 } | 55 } |
55 case PIXEL_TEST_GL: { | 56 case PIXEL_TEST_GL: { |
56 bool flipped_output_surface = false; | 57 bool flipped_output_surface = false; |
57 scoped_refptr<TestInProcessContextProvider> compositor( | 58 scoped_refptr<TestInProcessContextProvider> compositor( |
58 new TestInProcessContextProvider(nullptr)); | 59 new TestInProcessContextProvider(nullptr)); |
59 scoped_refptr<TestInProcessContextProvider> worker( | 60 scoped_refptr<TestInProcessContextProvider> worker( |
60 new TestInProcessContextProvider(compositor.get())); | 61 new TestInProcessContextProvider(compositor.get())); |
61 output_surface = make_scoped_ptr(new PixelTestOutputSurface( | 62 output_surface = base::WrapUnique(new PixelTestOutputSurface( |
62 std::move(compositor), std::move(worker), flipped_output_surface)); | 63 std::move(compositor), std::move(worker), flipped_output_surface)); |
63 break; | 64 break; |
64 } | 65 } |
65 } | 66 } |
66 | 67 |
67 output_surface->set_surface_expansion_size(surface_expansion_size); | 68 output_surface->set_surface_expansion_size(surface_expansion_size); |
68 return std::move(output_surface); | 69 return std::move(output_surface); |
69 } | 70 } |
70 | 71 |
71 void LayerTreePixelTest::WillCommitCompleteOnThread(LayerTreeHostImpl* impl) { | 72 void LayerTreePixelTest::WillCommitCompleteOnThread(LayerTreeHostImpl* impl) { |
72 if (impl->sync_tree()->source_frame_number() != 0) | 73 if (impl->sync_tree()->source_frame_number() != 0) |
73 return; | 74 return; |
74 | 75 |
75 DirectRenderer* renderer = static_cast<DirectRenderer*>(impl->renderer()); | 76 DirectRenderer* renderer = static_cast<DirectRenderer*>(impl->renderer()); |
76 renderer->SetEnlargePassTextureAmountForTesting(enlarge_texture_amount_); | 77 renderer->SetEnlargePassTextureAmountForTesting(enlarge_texture_amount_); |
77 } | 78 } |
78 | 79 |
79 scoped_ptr<CopyOutputRequest> LayerTreePixelTest::CreateCopyOutputRequest() { | 80 std::unique_ptr<CopyOutputRequest> |
| 81 LayerTreePixelTest::CreateCopyOutputRequest() { |
80 return CopyOutputRequest::CreateBitmapRequest( | 82 return CopyOutputRequest::CreateBitmapRequest( |
81 base::Bind(&LayerTreePixelTest::ReadbackResult, base::Unretained(this))); | 83 base::Bind(&LayerTreePixelTest::ReadbackResult, base::Unretained(this))); |
82 } | 84 } |
83 | 85 |
84 void LayerTreePixelTest::ReadbackResult(scoped_ptr<CopyOutputResult> result) { | 86 void LayerTreePixelTest::ReadbackResult( |
| 87 std::unique_ptr<CopyOutputResult> result) { |
85 ASSERT_TRUE(result->HasBitmap()); | 88 ASSERT_TRUE(result->HasBitmap()); |
86 result_bitmap_ = result->TakeBitmap(); | 89 result_bitmap_ = result->TakeBitmap(); |
87 EndTest(); | 90 EndTest(); |
88 } | 91 } |
89 | 92 |
90 void LayerTreePixelTest::BeginTest() { | 93 void LayerTreePixelTest::BeginTest() { |
91 Layer* target = readback_target_ ? readback_target_ | 94 Layer* target = readback_target_ ? readback_target_ |
92 : layer_tree_host()->root_layer(); | 95 : layer_tree_host()->root_layer(); |
93 target->RequestCopyOfOutput(CreateCopyOutputRequest()); | 96 target->RequestCopyOfOutput(CreateCopyOutputRequest()); |
94 PostSetNeedsCommitToMainThread(); | 97 PostSetNeedsCommitToMainThread(); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 } | 202 } |
200 | 203 |
201 void LayerTreePixelTest::SetupTree() { | 204 void LayerTreePixelTest::SetupTree() { |
202 scoped_refptr<Layer> root = Layer::Create(); | 205 scoped_refptr<Layer> root = Layer::Create(); |
203 root->SetBounds(content_root_->bounds()); | 206 root->SetBounds(content_root_->bounds()); |
204 root->AddChild(content_root_); | 207 root->AddChild(content_root_); |
205 layer_tree_host()->SetRootLayer(root); | 208 layer_tree_host()->SetRootLayer(root); |
206 LayerTreeTest::SetupTree(); | 209 LayerTreeTest::SetupTree(); |
207 } | 210 } |
208 | 211 |
209 scoped_ptr<SkBitmap> LayerTreePixelTest::CopyTextureMailboxToBitmap( | 212 std::unique_ptr<SkBitmap> LayerTreePixelTest::CopyTextureMailboxToBitmap( |
210 const gfx::Size& size, | 213 const gfx::Size& size, |
211 const TextureMailbox& texture_mailbox) { | 214 const TextureMailbox& texture_mailbox) { |
212 DCHECK(texture_mailbox.IsTexture()); | 215 DCHECK(texture_mailbox.IsTexture()); |
213 if (!texture_mailbox.IsTexture()) | 216 if (!texture_mailbox.IsTexture()) |
214 return nullptr; | 217 return nullptr; |
215 | 218 |
216 scoped_ptr<gpu::GLInProcessContext> context = CreateTestInProcessContext(); | 219 std::unique_ptr<gpu::GLInProcessContext> context = |
| 220 CreateTestInProcessContext(); |
217 GLES2Interface* gl = context->GetImplementation(); | 221 GLES2Interface* gl = context->GetImplementation(); |
218 | 222 |
219 if (texture_mailbox.sync_token().HasData()) | 223 if (texture_mailbox.sync_token().HasData()) |
220 gl->WaitSyncTokenCHROMIUM(texture_mailbox.sync_token().GetConstData()); | 224 gl->WaitSyncTokenCHROMIUM(texture_mailbox.sync_token().GetConstData()); |
221 | 225 |
222 GLuint texture_id = 0; | 226 GLuint texture_id = 0; |
223 gl->GenTextures(1, &texture_id); | 227 gl->GenTextures(1, &texture_id); |
224 gl->BindTexture(GL_TEXTURE_2D, texture_id); | 228 gl->BindTexture(GL_TEXTURE_2D, texture_id); |
225 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 229 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
226 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 230 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
227 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 231 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
228 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 232 gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
229 gl->ConsumeTextureCHROMIUM(texture_mailbox.target(), texture_mailbox.name()); | 233 gl->ConsumeTextureCHROMIUM(texture_mailbox.target(), texture_mailbox.name()); |
230 gl->BindTexture(GL_TEXTURE_2D, 0); | 234 gl->BindTexture(GL_TEXTURE_2D, 0); |
231 | 235 |
232 GLuint fbo = 0; | 236 GLuint fbo = 0; |
233 gl->GenFramebuffers(1, &fbo); | 237 gl->GenFramebuffers(1, &fbo); |
234 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo); | 238 gl->BindFramebuffer(GL_FRAMEBUFFER, fbo); |
235 gl->FramebufferTexture2D( | 239 gl->FramebufferTexture2D( |
236 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture_id, 0); | 240 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture_id, 0); |
237 EXPECT_EQ(static_cast<unsigned>(GL_FRAMEBUFFER_COMPLETE), | 241 EXPECT_EQ(static_cast<unsigned>(GL_FRAMEBUFFER_COMPLETE), |
238 gl->CheckFramebufferStatus(GL_FRAMEBUFFER)); | 242 gl->CheckFramebufferStatus(GL_FRAMEBUFFER)); |
239 | 243 |
240 scoped_ptr<uint8_t[]> pixels(new uint8_t[size.GetArea() * 4]); | 244 std::unique_ptr<uint8_t[]> pixels(new uint8_t[size.GetArea() * 4]); |
241 gl->ReadPixels(0, | 245 gl->ReadPixels(0, |
242 0, | 246 0, |
243 size.width(), | 247 size.width(), |
244 size.height(), | 248 size.height(), |
245 GL_RGBA, | 249 GL_RGBA, |
246 GL_UNSIGNED_BYTE, | 250 GL_UNSIGNED_BYTE, |
247 pixels.get()); | 251 pixels.get()); |
248 | 252 |
249 gl->DeleteFramebuffers(1, &fbo); | 253 gl->DeleteFramebuffers(1, &fbo); |
250 gl->DeleteTextures(1, &texture_id); | 254 gl->DeleteTextures(1, &texture_id); |
251 | 255 |
252 scoped_ptr<SkBitmap> bitmap(new SkBitmap); | 256 std::unique_ptr<SkBitmap> bitmap(new SkBitmap); |
253 bitmap->allocN32Pixels(size.width(), size.height()); | 257 bitmap->allocN32Pixels(size.width(), size.height()); |
254 | 258 |
255 uint8_t* out_pixels = static_cast<uint8_t*>(bitmap->getPixels()); | 259 uint8_t* out_pixels = static_cast<uint8_t*>(bitmap->getPixels()); |
256 | 260 |
257 size_t row_bytes = size.width() * 4; | 261 size_t row_bytes = size.width() * 4; |
258 size_t total_bytes = size.height() * row_bytes; | 262 size_t total_bytes = size.height() * row_bytes; |
259 for (size_t dest_y = 0; dest_y < total_bytes; dest_y += row_bytes) { | 263 for (size_t dest_y = 0; dest_y < total_bytes; dest_y += row_bytes) { |
260 // Flip Y axis. | 264 // Flip Y axis. |
261 size_t src_y = total_bytes - dest_y - row_bytes; | 265 size_t src_y = total_bytes - dest_y - row_bytes; |
262 // Swizzle OpenGL -> Skia byte order. | 266 // Swizzle OpenGL -> Skia byte order. |
263 for (size_t x = 0; x < row_bytes; x += 4) { | 267 for (size_t x = 0; x < row_bytes; x += 4) { |
264 out_pixels[dest_y + x + SK_R32_SHIFT/8] = pixels.get()[src_y + x + 0]; | 268 out_pixels[dest_y + x + SK_R32_SHIFT/8] = pixels.get()[src_y + x + 0]; |
265 out_pixels[dest_y + x + SK_G32_SHIFT/8] = pixels.get()[src_y + x + 1]; | 269 out_pixels[dest_y + x + SK_G32_SHIFT/8] = pixels.get()[src_y + x + 1]; |
266 out_pixels[dest_y + x + SK_B32_SHIFT/8] = pixels.get()[src_y + x + 2]; | 270 out_pixels[dest_y + x + SK_B32_SHIFT/8] = pixels.get()[src_y + x + 2]; |
267 out_pixels[dest_y + x + SK_A32_SHIFT/8] = pixels.get()[src_y + x + 3]; | 271 out_pixels[dest_y + x + SK_A32_SHIFT/8] = pixels.get()[src_y + x + 3]; |
268 } | 272 } |
269 } | 273 } |
270 | 274 |
271 return bitmap; | 275 return bitmap; |
272 } | 276 } |
273 | 277 |
274 void LayerTreePixelTest::Finish() { | 278 void LayerTreePixelTest::Finish() { |
275 scoped_ptr<gpu::GLInProcessContext> context = CreateTestInProcessContext(); | 279 std::unique_ptr<gpu::GLInProcessContext> context = |
| 280 CreateTestInProcessContext(); |
276 GLES2Interface* gl = context->GetImplementation(); | 281 GLES2Interface* gl = context->GetImplementation(); |
277 gl->Finish(); | 282 gl->Finish(); |
278 } | 283 } |
279 | 284 |
280 } // namespace cc | 285 } // namespace cc |
OLD | NEW |