| 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/pixel_test.h" | 5 #include "cc/test/pixel_test.h" |
| 6 | 6 |
| 7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
| 8 #include "base/run_loop.h" |
| 8 #include "cc/output/compositor_frame_metadata.h" | 9 #include "cc/output/compositor_frame_metadata.h" |
| 9 #include "cc/output/gl_renderer.h" | 10 #include "cc/output/gl_renderer.h" |
| 10 #include "cc/output/output_surface.h" | 11 #include "cc/output/output_surface.h" |
| 11 #include "cc/resources/resource_provider.h" | 12 #include "cc/resources/resource_provider.h" |
| 12 #include "cc/test/paths.h" | 13 #include "cc/test/paths.h" |
| 13 #include "cc/test/pixel_test_utils.h" | 14 #include "cc/test/pixel_test_utils.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "ui/gl/gl_implementation.h" | 16 #include "ui/gl/gl_implementation.h" |
| 16 #include "webkit/gpu/context_provider_in_process.h" | 17 #include "webkit/gpu/context_provider_in_process.h" |
| 17 #include "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" | 18 #include "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 | 74 |
| 74 scoped_refptr<webkit::gpu::ContextProviderInProcess> offscreen_contexts = | 75 scoped_refptr<webkit::gpu::ContextProviderInProcess> offscreen_contexts = |
| 75 webkit::gpu::ContextProviderInProcess::Create(); | 76 webkit::gpu::ContextProviderInProcess::Create(); |
| 76 ASSERT_TRUE(offscreen_contexts->BindToCurrentThread()); | 77 ASSERT_TRUE(offscreen_contexts->BindToCurrentThread()); |
| 77 resource_provider_->set_offscreen_context_provider(offscreen_contexts); | 78 resource_provider_->set_offscreen_context_provider(offscreen_contexts); |
| 78 } | 79 } |
| 79 | 80 |
| 80 bool PixelTest::RunPixelTest(RenderPassList* pass_list, | 81 bool PixelTest::RunPixelTest(RenderPassList* pass_list, |
| 81 const base::FilePath& ref_file, | 82 const base::FilePath& ref_file, |
| 82 const PixelComparator& comparator) { | 83 const PixelComparator& comparator) { |
| 84 base::RunLoop run_loop; |
| 85 |
| 83 pass_list->back()->copy_callbacks.push_back( | 86 pass_list->back()->copy_callbacks.push_back( |
| 84 base::Bind(&PixelTest::ReadbackResult, base::Unretained(this))); | 87 base::Bind(&PixelTest::ReadbackResult, |
| 88 base::Unretained(this), |
| 89 run_loop.QuitClosure())); |
| 85 | 90 |
| 86 renderer_->DecideRenderPassAllocationsForFrame(*pass_list); | 91 renderer_->DecideRenderPassAllocationsForFrame(*pass_list); |
| 87 renderer_->DrawFrame(pass_list); | 92 renderer_->DrawFrame(pass_list); |
| 88 | 93 |
| 89 // TODO(danakj): When the glReadPixels is async, wait for it to finish. | 94 // Wait for the readback to complete. |
| 95 output_surface_->context3d()->finish(); |
| 96 run_loop.Run(); |
| 90 | 97 |
| 91 return PixelsMatchReference(ref_file, comparator); | 98 return PixelsMatchReference(ref_file, comparator); |
| 92 } | 99 } |
| 93 | 100 |
| 94 void PixelTest::ReadbackResult(scoped_ptr<SkBitmap> bitmap) { | 101 void PixelTest::ReadbackResult(base::Closure quit_run_loop, |
| 102 scoped_ptr<SkBitmap> bitmap) { |
| 95 result_bitmap_ = bitmap.Pass(); | 103 result_bitmap_ = bitmap.Pass(); |
| 104 quit_run_loop.Run(); |
| 96 } | 105 } |
| 97 | 106 |
| 98 bool PixelTest::PixelsMatchReference(const base::FilePath& ref_file, | 107 bool PixelTest::PixelsMatchReference(const base::FilePath& ref_file, |
| 99 const PixelComparator& comparator) { | 108 const PixelComparator& comparator) { |
| 100 base::FilePath test_data_dir; | 109 base::FilePath test_data_dir; |
| 101 if (!PathService::Get(cc::DIR_TEST_DATA, &test_data_dir)) | 110 if (!PathService::Get(cc::DIR_TEST_DATA, &test_data_dir)) |
| 102 return false; | 111 return false; |
| 103 | 112 |
| 104 // If this is false, we didn't set up a readback on a render pass. | 113 // If this is false, we didn't set up a readback on a render pass. |
| 105 if (!result_bitmap_) | 114 if (!result_bitmap_) |
| 106 return false; | 115 return false; |
| 107 | 116 |
| 108 // To rebaseline: | 117 // To rebaseline: |
| 109 // return WritePNGFile(*result_bitmap_, test_data_dir.Append(ref_file), true); | 118 // return WritePNGFile(*result_bitmap_, test_data_dir.Append(ref_file), true); |
| 110 | 119 |
| 111 return MatchesPNGFile(*result_bitmap_, | 120 return MatchesPNGFile(*result_bitmap_, |
| 112 test_data_dir.Append(ref_file), | 121 test_data_dir.Append(ref_file), |
| 113 comparator); | 122 comparator); |
| 114 } | 123 } |
| 115 | 124 |
| 116 } // namespace cc | 125 } // namespace cc |
| OLD | NEW |