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 "cc/output/compositor_frame_metadata.h" | 8 #include "cc/output/compositor_frame_metadata.h" |
9 #include "cc/output/gl_renderer.h" | 9 #include "cc/output/gl_renderer.h" |
10 #include "cc/output/output_surface.h" | 10 #include "cc/output/output_surface.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 output_surface_.get(), | 70 output_surface_.get(), |
71 resource_provider_.get(), | 71 resource_provider_.get(), |
72 0); | 72 0); |
73 | 73 |
74 scoped_refptr<webkit::gpu::ContextProviderInProcess> offscreen_contexts = | 74 scoped_refptr<webkit::gpu::ContextProviderInProcess> offscreen_contexts = |
75 webkit::gpu::ContextProviderInProcess::Create(); | 75 webkit::gpu::ContextProviderInProcess::Create(); |
76 ASSERT_TRUE(offscreen_contexts->BindToCurrentThread()); | 76 ASSERT_TRUE(offscreen_contexts->BindToCurrentThread()); |
77 resource_provider_->set_offscreen_context_provider(offscreen_contexts); | 77 resource_provider_->set_offscreen_context_provider(offscreen_contexts); |
78 } | 78 } |
79 | 79 |
| 80 bool PixelTest::RunPixelTest(RenderPassList* pass_list, |
| 81 const base::FilePath& ref_file, |
| 82 const PixelComparator& comparator) { |
| 83 pass_list->back()->copy_callbacks.push_back( |
| 84 base::Bind(&PixelTest::ReadbackResult, base::Unretained(this))); |
| 85 |
| 86 renderer_->DecideRenderPassAllocationsForFrame(*pass_list); |
| 87 renderer_->DrawFrame(pass_list); |
| 88 |
| 89 // TODO(danakj): When the glReadPixels is async, wait for it to finish. |
| 90 |
| 91 return PixelsMatchReference(ref_file, comparator); |
| 92 } |
| 93 |
| 94 void PixelTest::ReadbackResult(scoped_ptr<SkBitmap> bitmap) { |
| 95 result_bitmap_ = bitmap.Pass(); |
| 96 } |
| 97 |
80 bool PixelTest::PixelsMatchReference(const base::FilePath& ref_file, | 98 bool PixelTest::PixelsMatchReference(const base::FilePath& ref_file, |
81 const PixelComparator& comparator) { | 99 const PixelComparator& comparator) { |
82 gfx::Rect device_viewport_rect(device_viewport_size_); | |
83 | |
84 SkBitmap bitmap; | |
85 bitmap.setConfig(SkBitmap::kARGB_8888_Config, | |
86 device_viewport_rect.width(), | |
87 device_viewport_rect.height()); | |
88 bitmap.allocPixels(); | |
89 unsigned char* pixels = static_cast<unsigned char*>(bitmap.getPixels()); | |
90 renderer_->GetFramebufferPixels(pixels, device_viewport_rect); | |
91 | |
92 base::FilePath test_data_dir; | 100 base::FilePath test_data_dir; |
93 if (!PathService::Get(cc::DIR_TEST_DATA, &test_data_dir)) | 101 if (!PathService::Get(cc::DIR_TEST_DATA, &test_data_dir)) |
94 return false; | 102 return false; |
95 | 103 |
| 104 // If this is false, we didn't set up a readback on a render pass. |
| 105 if (!result_bitmap_) |
| 106 return false; |
| 107 |
96 // To rebaseline: | 108 // To rebaseline: |
97 // return WritePNGFile(bitmap, test_data_dir.Append(ref_file)); | 109 // return WritePNGFile(*result_bitmap_, test_data_dir.Append(ref_file), true); |
98 | 110 |
99 return MatchesPNGFile(bitmap, test_data_dir.Append(ref_file), comparator); | 111 return MatchesPNGFile(*result_bitmap_, |
| 112 test_data_dir.Append(ref_file), |
| 113 comparator); |
100 } | 114 } |
101 | 115 |
102 } // namespace cc | 116 } // namespace cc |
OLD | NEW |