| OLD | NEW |
| 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 "content/public/test/layouttest_support.h" | 5 #include "content/public/test/layouttest_support.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 int64_t TraceId() const override { return 0; } | 314 int64_t TraceId() const override { return 0; } |
| 315 | 315 |
| 316 private: | 316 private: |
| 317 std::unique_ptr<cc::CopyOutputRequest> copy_request_; | 317 std::unique_ptr<cc::CopyOutputRequest> copy_request_; |
| 318 FindCompositorFrameSinkCallback find_compositor_frame_sink_callback_; | 318 FindCompositorFrameSinkCallback find_compositor_frame_sink_callback_; |
| 319 cc::TestCompositorFrameSink* compositor_frame_sink_from_commit_ = nullptr; | 319 cc::TestCompositorFrameSink* compositor_frame_sink_from_commit_ = nullptr; |
| 320 }; | 320 }; |
| 321 | 321 |
| 322 } // namespace | 322 } // namespace |
| 323 | 323 |
| 324 class LayoutTestDependenciesImpl : public LayoutTestDependencies { | 324 class LayoutTestDependenciesImpl : public LayoutTestDependencies, |
| 325 public cc::TestCompositorFrameSinkClient { |
| 325 public: | 326 public: |
| 326 std::unique_ptr<cc::CompositorFrameSink> CreateCompositorFrameSink( | 327 std::unique_ptr<cc::CompositorFrameSink> CreateCompositorFrameSink( |
| 327 int32_t routing_id, | 328 int32_t routing_id, |
| 328 scoped_refptr<gpu::GpuChannelHost> gpu_channel, | 329 scoped_refptr<gpu::GpuChannelHost> gpu_channel, |
| 329 scoped_refptr<cc::ContextProvider> compositor_context_provider, | 330 scoped_refptr<cc::ContextProvider> compositor_context_provider, |
| 330 scoped_refptr<cc::ContextProvider> worker_context_provider, | 331 scoped_refptr<cc::ContextProvider> worker_context_provider, |
| 331 CompositorDependencies* deps) override { | 332 CompositorDependencies* deps) override { |
| 332 // This is for an offscreen context for the compositor. So the default | 333 // This could override the GpuChannel for a CompositorFrameSink that was |
| 333 // framebuffer doesn't need alpha, depth, stencil, antialiasing. | 334 // previously being created but in that case the old GpuChannel would be |
| 334 gpu::gles2::ContextCreationAttribHelper attributes; | 335 // lost as would the CompositorFrameSink. |
| 335 attributes.alpha_size = -1; | 336 gpu_channel_ = gpu_channel; |
| 336 attributes.depth_size = 0; | |
| 337 attributes.stencil_size = 0; | |
| 338 attributes.samples = 0; | |
| 339 attributes.sample_buffers = 0; | |
| 340 attributes.bind_generates_resource = false; | |
| 341 attributes.lose_context_when_out_of_memory = true; | |
| 342 const bool automatic_flushes = false; | |
| 343 const bool support_locking = false; | |
| 344 | |
| 345 bool flipped_output_surface = false; | |
| 346 std::unique_ptr<cc::OutputSurface> display_output_surface( | |
| 347 new cc::PixelTestOutputSurface( | |
| 348 make_scoped_refptr(new ContextProviderCommandBuffer( | |
| 349 std::move(gpu_channel), gpu::GPU_STREAM_DEFAULT, | |
| 350 gpu::GpuStreamPriority::NORMAL, gpu::kNullSurfaceHandle, | |
| 351 GURL("chrome://gpu/" | |
| 352 "LayoutTestDependenciesImpl::CreateOutputSurface"), | |
| 353 automatic_flushes, support_locking, gpu::SharedMemoryLimits(), | |
| 354 attributes, nullptr, | |
| 355 command_buffer_metrics::OFFSCREEN_CONTEXT_FOR_TESTING)), | |
| 356 flipped_output_surface)); | |
| 357 | 337 |
| 358 auto* task_runner = deps->GetCompositorImplThreadTaskRunner().get(); | 338 auto* task_runner = deps->GetCompositorImplThreadTaskRunner().get(); |
| 359 bool synchronous_composite = !task_runner; | 339 bool synchronous_composite = !task_runner; |
| 360 if (!task_runner) | 340 if (!task_runner) |
| 361 task_runner = base::ThreadTaskRunnerHandle::Get().get(); | 341 task_runner = base::ThreadTaskRunnerHandle::Get().get(); |
| 362 | 342 |
| 363 cc::LayerTreeSettings settings = | 343 cc::LayerTreeSettings settings = |
| 364 RenderWidgetCompositor::GenerateLayerTreeSettings( | 344 RenderWidgetCompositor::GenerateLayerTreeSettings( |
| 365 *base::CommandLine::ForCurrentProcess(), deps, 1.f); | 345 *base::CommandLine::ForCurrentProcess(), deps, 1.f); |
| 366 | 346 |
| 367 auto compositor_frame_sink = base::MakeUnique<cc::TestCompositorFrameSink>( | 347 auto compositor_frame_sink = base::MakeUnique<cc::TestCompositorFrameSink>( |
| 368 std::move(compositor_context_provider), | 348 std::move(compositor_context_provider), |
| 369 std::move(worker_context_provider), std::move(display_output_surface), | 349 std::move(worker_context_provider), deps->GetSharedBitmapManager(), |
| 370 deps->GetSharedBitmapManager(), deps->GetGpuMemoryBufferManager(), | 350 deps->GetGpuMemoryBufferManager(), settings.renderer_settings, |
| 371 settings.renderer_settings, task_runner, synchronous_composite, | 351 task_runner, synchronous_composite, |
| 372 false /* force_disable_reclaim_resources */); | 352 false /* force_disable_reclaim_resources */); |
| 353 compositor_frame_sink->SetClient(this); |
| 373 compositor_frame_sinks_[routing_id] = compositor_frame_sink.get(); | 354 compositor_frame_sinks_[routing_id] = compositor_frame_sink.get(); |
| 374 return std::move(compositor_frame_sink); | 355 return std::move(compositor_frame_sink); |
| 375 } | 356 } |
| 376 | 357 |
| 377 std::unique_ptr<cc::SwapPromise> RequestCopyOfOutput( | 358 std::unique_ptr<cc::SwapPromise> RequestCopyOfOutput( |
| 378 int32_t routing_id, | 359 int32_t routing_id, |
| 379 std::unique_ptr<cc::CopyOutputRequest> request) override { | 360 std::unique_ptr<cc::CopyOutputRequest> request) override { |
| 380 // Note that we can't immediately check compositor_frame_sinks_, since it | 361 // Note that we can't immediately check compositor_frame_sinks_, since it |
| 381 // may not have been created yet. Instead, we wait until OnCommit to find | 362 // may not have been created yet. Instead, we wait until OnCommit to find |
| 382 // the currently active CompositorFrameSink for the given RenderWidget | 363 // the currently active CompositorFrameSink for the given RenderWidget |
| 383 // routing_id. | 364 // routing_id. |
| 384 return base::MakeUnique<CopyRequestSwapPromise>( | 365 return base::MakeUnique<CopyRequestSwapPromise>( |
| 385 std::move(request), | 366 std::move(request), |
| 386 base::Bind( | 367 base::Bind( |
| 387 &LayoutTestDependenciesImpl::FindCompositorFrameSink, | 368 &LayoutTestDependenciesImpl::FindCompositorFrameSink, |
| 388 // |this| will still be valid, because its lifetime is tied to | 369 // |this| will still be valid, because its lifetime is tied to |
| 389 // RenderThreadImpl, which outlives layout test execution. | 370 // RenderThreadImpl, which outlives layout test execution. |
| 390 base::Unretained(this), routing_id)); | 371 base::Unretained(this), routing_id)); |
| 391 } | 372 } |
| 392 | 373 |
| 374 // TestCompositorFrameSinkClient implementation. |
| 375 std::unique_ptr<cc::OutputSurface> CreateDisplayOutputSurface( |
| 376 scoped_refptr<cc::ContextProvider> compositor_context_provider) override { |
| 377 // This is for an offscreen context for the compositor. So the default |
| 378 // framebuffer doesn't need alpha, depth, stencil, antialiasing. |
| 379 gpu::gles2::ContextCreationAttribHelper attributes; |
| 380 attributes.alpha_size = -1; |
| 381 attributes.depth_size = 0; |
| 382 attributes.stencil_size = 0; |
| 383 attributes.samples = 0; |
| 384 attributes.sample_buffers = 0; |
| 385 attributes.bind_generates_resource = false; |
| 386 attributes.lose_context_when_out_of_memory = true; |
| 387 const bool automatic_flushes = false; |
| 388 const bool support_locking = false; |
| 389 |
| 390 bool flipped_output_surface = false; |
| 391 return base::MakeUnique<cc::PixelTestOutputSurface>( |
| 392 make_scoped_refptr(new ContextProviderCommandBuffer( |
| 393 gpu_channel_, gpu::GPU_STREAM_DEFAULT, |
| 394 gpu::GpuStreamPriority::NORMAL, gpu::kNullSurfaceHandle, |
| 395 GURL("chrome://gpu/" |
| 396 "LayoutTestDependenciesImpl::CreateOutputSurface"), |
| 397 automatic_flushes, support_locking, gpu::SharedMemoryLimits(), |
| 398 attributes, nullptr, |
| 399 command_buffer_metrics::OFFSCREEN_CONTEXT_FOR_TESTING)), |
| 400 flipped_output_surface); |
| 401 } |
| 402 void DisplayReceivedCompositorFrame( |
| 403 const cc::CompositorFrame& frame) override {} |
| 404 void DisplayWillDrawAndSwap( |
| 405 bool will_draw_and_swap, |
| 406 const cc::RenderPassList& render_passes) override {} |
| 407 void DisplayDidDrawAndSwap() override {} |
| 408 |
| 393 private: | 409 private: |
| 394 cc::TestCompositorFrameSink* FindCompositorFrameSink(int32_t routing_id) { | 410 cc::TestCompositorFrameSink* FindCompositorFrameSink(int32_t routing_id) { |
| 395 auto it = compositor_frame_sinks_.find(routing_id); | 411 auto it = compositor_frame_sinks_.find(routing_id); |
| 396 return it == compositor_frame_sinks_.end() ? nullptr : it->second; | 412 return it == compositor_frame_sinks_.end() ? nullptr : it->second; |
| 397 } | 413 } |
| 398 | 414 |
| 399 // Entries are not removed, so this map can grow. However, it is only used in | 415 // Entries are not removed, so this map can grow. However, it is only used in |
| 400 // layout tests, so this memory usage does not occur in production. | 416 // layout tests, so this memory usage does not occur in production. |
| 401 // Entries in this map will outlive the output surface, because this object is | 417 // Entries in this map will outlive the output surface, because this object is |
| 402 // owned by RenderThreadImpl, which outlives layout test execution. | 418 // owned by RenderThreadImpl, which outlives layout test execution. |
| 403 std::unordered_map<int32_t, cc::TestCompositorFrameSink*> | 419 std::unordered_map<int32_t, cc::TestCompositorFrameSink*> |
| 404 compositor_frame_sinks_; | 420 compositor_frame_sinks_; |
| 421 scoped_refptr<gpu::GpuChannelHost> gpu_channel_; |
| 405 }; | 422 }; |
| 406 | 423 |
| 407 void EnableRendererLayoutTestMode() { | 424 void EnableRendererLayoutTestMode() { |
| 408 RenderThreadImpl::current()->set_layout_test_dependencies( | 425 RenderThreadImpl::current()->set_layout_test_dependencies( |
| 409 base::MakeUnique<LayoutTestDependenciesImpl>()); | 426 base::MakeUnique<LayoutTestDependenciesImpl>()); |
| 410 | 427 |
| 411 #if defined(OS_WIN) | 428 #if defined(OS_WIN) |
| 412 RegisterSideloadedTypefaces(SkFontMgr_New_DirectWrite()); | 429 RegisterSideloadedTypefaces(SkFontMgr_New_DirectWrite()); |
| 413 #endif | 430 #endif |
| 414 } | 431 } |
| (...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1104 return result; | 1121 return result; |
| 1105 } | 1122 } |
| 1106 | 1123 |
| 1107 void SchedulerRunIdleTasks(const base::Closure& callback) { | 1124 void SchedulerRunIdleTasks(const base::Closure& callback) { |
| 1108 blink::scheduler::RendererScheduler* scheduler = | 1125 blink::scheduler::RendererScheduler* scheduler = |
| 1109 content::RenderThreadImpl::current()->GetRendererScheduler(); | 1126 content::RenderThreadImpl::current()->GetRendererScheduler(); |
| 1110 blink::scheduler::RunIdleTasksForTesting(scheduler, callback); | 1127 blink::scheduler::RunIdleTasksForTesting(scheduler, callback); |
| 1111 } | 1128 } |
| 1112 | 1129 |
| 1113 } // namespace content | 1130 } // namespace content |
| OLD | NEW |