OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "cc/test/pixel_test.h" |
| 6 |
| 7 #include "base/command_line.h" |
| 8 #include "base/message_loop/message_loop_proxy.h" |
| 9 #include "base/path_service.h" |
| 10 #include "base/run_loop.h" |
| 11 #include "cc/base/blocking_task_runner.h" |
| 12 #include "cc/base/switches.h" |
| 13 #include "cc/output/compositor_frame_metadata.h" |
| 14 #include "cc/output/copy_output_request.h" |
| 15 #include "cc/output/copy_output_result.h" |
| 16 #include "cc/output/gl_renderer.h" |
| 17 #include "cc/output/output_surface_client.h" |
| 18 #include "cc/output/software_renderer.h" |
| 19 #include "cc/resources/resource_provider.h" |
| 20 #include "cc/resources/texture_mailbox_deleter.h" |
| 21 #include "cc/resources/tile_task_worker_pool.h" |
| 22 #include "cc/test/fake_output_surface_client.h" |
| 23 #include "cc/test/paths.h" |
| 24 #include "cc/test/pixel_test_output_surface.h" |
| 25 #include "cc/test/pixel_test_software_output_device.h" |
| 26 #include "cc/test/pixel_test_utils.h" |
| 27 #include "cc/test/test_gpu_memory_buffer_manager.h" |
| 28 #include "cc/test/test_in_process_context_provider.h" |
| 29 #include "cc/test/test_shared_bitmap_manager.h" |
| 30 #include "gpu/command_buffer/client/gles2_interface.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" |
| 32 |
| 33 namespace cc { |
| 34 |
| 35 PixelTest::PixelTest() |
| 36 : device_viewport_size_(gfx::Size(200, 200)), |
| 37 disable_picture_quad_image_filtering_(false), |
| 38 output_surface_client_(new FakeOutputSurfaceClient), |
| 39 main_thread_task_runner_( |
| 40 BlockingTaskRunner::Create(base::MessageLoopProxy::current())) { |
| 41 } |
| 42 PixelTest::~PixelTest() {} |
| 43 |
| 44 bool PixelTest::RunPixelTest(RenderPassList* pass_list, |
| 45 const base::FilePath& ref_file, |
| 46 const PixelComparator& comparator) { |
| 47 return RunPixelTestWithReadbackTarget(pass_list, |
| 48 pass_list->back(), |
| 49 ref_file, |
| 50 comparator); |
| 51 } |
| 52 |
| 53 bool PixelTest::RunPixelTestWithReadbackTarget( |
| 54 RenderPassList* pass_list, |
| 55 RenderPass* target, |
| 56 const base::FilePath& ref_file, |
| 57 const PixelComparator& comparator) { |
| 58 return RunPixelTestWithReadbackTargetAndArea( |
| 59 pass_list, target, ref_file, comparator, nullptr); |
| 60 } |
| 61 |
| 62 bool PixelTest::RunPixelTestWithReadbackTargetAndArea( |
| 63 RenderPassList* pass_list, |
| 64 RenderPass* target, |
| 65 const base::FilePath& ref_file, |
| 66 const PixelComparator& comparator, |
| 67 const gfx::Rect* copy_rect) { |
| 68 base::RunLoop run_loop; |
| 69 |
| 70 scoped_ptr<CopyOutputRequest> request = |
| 71 CopyOutputRequest::CreateBitmapRequest( |
| 72 base::Bind(&PixelTest::ReadbackResult, |
| 73 base::Unretained(this), |
| 74 run_loop.QuitClosure())); |
| 75 if (copy_rect) |
| 76 request->set_area(*copy_rect); |
| 77 target->copy_requests.push_back(request.Pass()); |
| 78 |
| 79 float device_scale_factor = 1.f; |
| 80 gfx::Rect device_viewport_rect = |
| 81 gfx::Rect(device_viewport_size_) + external_device_viewport_offset_; |
| 82 gfx::Rect device_clip_rect = external_device_clip_rect_.IsEmpty() |
| 83 ? device_viewport_rect |
| 84 : external_device_clip_rect_; |
| 85 renderer_->DecideRenderPassAllocationsForFrame(*pass_list); |
| 86 renderer_->DrawFrame(pass_list, |
| 87 device_scale_factor, |
| 88 device_viewport_rect, |
| 89 device_clip_rect, |
| 90 disable_picture_quad_image_filtering_); |
| 91 |
| 92 // Wait for the readback to complete. |
| 93 if (output_surface_->context_provider()) |
| 94 output_surface_->context_provider()->ContextGL()->Finish(); |
| 95 run_loop.Run(); |
| 96 |
| 97 return PixelsMatchReference(ref_file, comparator); |
| 98 } |
| 99 |
| 100 void PixelTest::ReadbackResult(base::Closure quit_run_loop, |
| 101 scoped_ptr<CopyOutputResult> result) { |
| 102 ASSERT_TRUE(result->HasBitmap()); |
| 103 result_bitmap_ = result->TakeBitmap().Pass(); |
| 104 quit_run_loop.Run(); |
| 105 } |
| 106 |
| 107 bool PixelTest::PixelsMatchReference(const base::FilePath& ref_file, |
| 108 const PixelComparator& comparator) { |
| 109 base::FilePath test_data_dir; |
| 110 if (!PathService::Get(CCPaths::DIR_TEST_DATA, &test_data_dir)) |
| 111 return false; |
| 112 |
| 113 // If this is false, we didn't set up a readback on a render pass. |
| 114 if (!result_bitmap_) |
| 115 return false; |
| 116 |
| 117 base::CommandLine* cmd = base::CommandLine::ForCurrentProcess(); |
| 118 if (cmd->HasSwitch(switches::kCCRebaselinePixeltests)) |
| 119 return WritePNGFile(*result_bitmap_, test_data_dir.Append(ref_file), true); |
| 120 |
| 121 return MatchesPNGFile( |
| 122 *result_bitmap_, test_data_dir.Append(ref_file), comparator); |
| 123 } |
| 124 |
| 125 void PixelTest::SetUpGLRenderer(bool use_skia_gpu_backend, |
| 126 bool flipped_output_surface) { |
| 127 enable_pixel_output_.reset(new gfx::DisableNullDrawGLBindings); |
| 128 |
| 129 output_surface_.reset(new PixelTestOutputSurface( |
| 130 new TestInProcessContextProvider, new TestInProcessContextProvider, |
| 131 flipped_output_surface)); |
| 132 output_surface_->BindToClient(output_surface_client_.get()); |
| 133 |
| 134 shared_bitmap_manager_.reset(new TestSharedBitmapManager); |
| 135 gpu_memory_buffer_manager_.reset(new TestGpuMemoryBufferManager); |
| 136 resource_provider_ = |
| 137 ResourceProvider::Create(output_surface_.get(), |
| 138 shared_bitmap_manager_.get(), |
| 139 gpu_memory_buffer_manager_.get(), |
| 140 main_thread_task_runner_.get(), |
| 141 0, |
| 142 false, |
| 143 1); |
| 144 |
| 145 texture_mailbox_deleter_ = make_scoped_ptr( |
| 146 new TextureMailboxDeleter(base::MessageLoopProxy::current())); |
| 147 |
| 148 renderer_ = GLRenderer::Create( |
| 149 this, &settings_.renderer_settings, output_surface_.get(), |
| 150 resource_provider_.get(), texture_mailbox_deleter_.get(), 0); |
| 151 } |
| 152 |
| 153 void PixelTest::ForceExpandedViewport(const gfx::Size& surface_expansion) { |
| 154 static_cast<PixelTestOutputSurface*>(output_surface_.get()) |
| 155 ->set_surface_expansion_size(surface_expansion); |
| 156 SoftwareOutputDevice* device = output_surface_->software_device(); |
| 157 if (device) { |
| 158 static_cast<PixelTestSoftwareOutputDevice*>(device) |
| 159 ->set_surface_expansion_size(surface_expansion); |
| 160 } |
| 161 } |
| 162 |
| 163 void PixelTest::ForceViewportOffset(const gfx::Vector2d& viewport_offset) { |
| 164 external_device_viewport_offset_ = viewport_offset; |
| 165 } |
| 166 |
| 167 void PixelTest::ForceDeviceClip(const gfx::Rect& clip) { |
| 168 external_device_clip_rect_ = clip; |
| 169 } |
| 170 |
| 171 void PixelTest::EnableExternalStencilTest() { |
| 172 static_cast<PixelTestOutputSurface*>(output_surface_.get()) |
| 173 ->set_has_external_stencil_test(true); |
| 174 } |
| 175 |
| 176 void PixelTest::SetUpSoftwareRenderer() { |
| 177 scoped_ptr<SoftwareOutputDevice> device(new PixelTestSoftwareOutputDevice()); |
| 178 output_surface_.reset(new PixelTestOutputSurface(device.Pass())); |
| 179 output_surface_->BindToClient(output_surface_client_.get()); |
| 180 shared_bitmap_manager_.reset(new TestSharedBitmapManager()); |
| 181 resource_provider_ = |
| 182 ResourceProvider::Create(output_surface_.get(), |
| 183 shared_bitmap_manager_.get(), |
| 184 gpu_memory_buffer_manager_.get(), |
| 185 main_thread_task_runner_.get(), |
| 186 0, |
| 187 false, |
| 188 1); |
| 189 renderer_ = |
| 190 SoftwareRenderer::Create(this, &settings_.renderer_settings, |
| 191 output_surface_.get(), resource_provider_.get()); |
| 192 } |
| 193 |
| 194 } // namespace cc |
OLD | NEW |