| 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 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <unordered_map> | 10 #include <unordered_map> |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 | 283 |
| 284 void SetMockDeviceOrientationData(const OrientationData& data) { | 284 void SetMockDeviceOrientationData(const OrientationData& data) { |
| 285 RendererBlinkPlatformImpl::SetMockDeviceOrientationDataForTesting(data); | 285 RendererBlinkPlatformImpl::SetMockDeviceOrientationDataForTesting(data); |
| 286 } | 286 } |
| 287 | 287 |
| 288 namespace { | 288 namespace { |
| 289 | 289 |
| 290 // Invokes a callback on commit (on the main thread) to obtain the output | 290 // Invokes a callback on commit (on the main thread) to obtain the output |
| 291 // surface that should be used, then asks that output surface to submit the copy | 291 // surface that should be used, then asks that output surface to submit the copy |
| 292 // request at SwapBuffers time. | 292 // request at SwapBuffers time. |
| 293 // DO NOT SUBMIT - clean this up / do this right... |
| 293 class CopyRequestSwapPromise : public cc::SwapPromise { | 294 class CopyRequestSwapPromise : public cc::SwapPromise { |
| 294 public: | 295 public: |
| 295 using FindLayerTreeFrameSinkCallback = | 296 using FindLayerTreeFrameSinkCallback = |
| 296 base::Callback<viz::TestLayerTreeFrameSink*()>; | 297 base::Callback<viz::TestLayerTreeFrameSink*()>; |
| 297 CopyRequestSwapPromise( | 298 CopyRequestSwapPromise(std::unique_ptr<cc::CopyOutputRequest> request) |
| 298 std::unique_ptr<cc::CopyOutputRequest> request, | 299 : copy_request_(std::move(request)) {} |
| 299 FindLayerTreeFrameSinkCallback find_layer_tree_frame_sink_callback) | |
| 300 : copy_request_(std::move(request)), | |
| 301 find_layer_tree_frame_sink_callback_( | |
| 302 std::move(find_layer_tree_frame_sink_callback)) {} | |
| 303 | 300 |
| 304 // cc::SwapPromise implementation. | 301 // cc::SwapPromise implementation. |
| 305 void OnCommit() override { | 302 void OnCommit() override { copy_request_->SendEmptyResult(); } |
| 306 layer_tree_frame_sink_from_commit_ = | |
| 307 find_layer_tree_frame_sink_callback_.Run(); | |
| 308 DCHECK(layer_tree_frame_sink_from_commit_); | |
| 309 } | |
| 310 void DidActivate() override {} | 303 void DidActivate() override {} |
| 311 void WillSwap(cc::CompositorFrameMetadata*) override { | 304 void WillSwap(cc::CompositorFrameMetadata*) override {} |
| 312 layer_tree_frame_sink_from_commit_->RequestCopyOfOutput( | |
| 313 std::move(copy_request_)); | |
| 314 } | |
| 315 void DidSwap() override {} | 305 void DidSwap() override {} |
| 316 DidNotSwapAction DidNotSwap(DidNotSwapReason r) override { | 306 DidNotSwapAction DidNotSwap(DidNotSwapReason r) override { |
| 317 // The compositor should always swap in layout test mode. | 307 // The compositor should always swap in layout test mode. |
| 318 NOTREACHED() << "did not swap for reason " << r; | 308 NOTREACHED() << "did not swap for reason " << r; |
| 319 return DidNotSwapAction::BREAK_PROMISE; | 309 return DidNotSwapAction::BREAK_PROMISE; |
| 320 } | 310 } |
| 321 int64_t TraceId() const override { return 0; } | 311 int64_t TraceId() const override { return 0; } |
| 322 | 312 |
| 323 private: | 313 private: |
| 324 std::unique_ptr<cc::CopyOutputRequest> copy_request_; | 314 std::unique_ptr<cc::CopyOutputRequest> copy_request_; |
| 325 FindLayerTreeFrameSinkCallback find_layer_tree_frame_sink_callback_; | |
| 326 viz::TestLayerTreeFrameSink* layer_tree_frame_sink_from_commit_ = nullptr; | |
| 327 }; | 315 }; |
| 328 | 316 |
| 329 } // namespace | 317 } // namespace |
| 330 | 318 |
| 331 class LayoutTestDependenciesImpl : public LayoutTestDependencies, | 319 class LayoutTestDependenciesImpl : public LayoutTestDependencies, |
| 332 public viz::TestLayerTreeFrameSinkClient { | 320 public viz::TestLayerTreeFrameSinkClient { |
| 333 public: | 321 public: |
| 334 std::unique_ptr<cc::LayerTreeFrameSink> CreateLayerTreeFrameSink( | |
| 335 int32_t routing_id, | |
| 336 scoped_refptr<gpu::GpuChannelHost> gpu_channel, | |
| 337 scoped_refptr<cc::ContextProvider> compositor_context_provider, | |
| 338 scoped_refptr<cc::ContextProvider> worker_context_provider, | |
| 339 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | |
| 340 CompositorDependencies* deps) override { | |
| 341 // This could override the GpuChannel for a LayerTreeFrameSink that was | |
| 342 // previously being created but in that case the old GpuChannel would be | |
| 343 // lost as would the LayerTreeFrameSink. | |
| 344 gpu_channel_ = gpu_channel; | |
| 345 | |
| 346 auto* task_runner = deps->GetCompositorImplThreadTaskRunner().get(); | |
| 347 bool synchronous_composite = !task_runner; | |
| 348 if (!task_runner) | |
| 349 task_runner = base::ThreadTaskRunnerHandle::Get().get(); | |
| 350 | |
| 351 cc::RendererSettings renderer_settings; | |
| 352 base::CommandLine* cmd = base::CommandLine::ForCurrentProcess(); | |
| 353 renderer_settings.enable_color_correct_rendering = | |
| 354 base::FeatureList::IsEnabled(features::kColorCorrectRendering); | |
| 355 renderer_settings.allow_antialiasing &= | |
| 356 !cmd->HasSwitch(cc::switches::kDisableCompositedAntialiasing); | |
| 357 renderer_settings.highp_threshold_min = 2048; | |
| 358 | |
| 359 constexpr bool disable_display_vsync = false; | |
| 360 constexpr double refresh_rate = 60.0; | |
| 361 auto layer_tree_frame_sink = base::MakeUnique<viz::TestLayerTreeFrameSink>( | |
| 362 std::move(compositor_context_provider), | |
| 363 std::move(worker_context_provider), nullptr /* shared_bitmap_manager */, | |
| 364 gpu_memory_buffer_manager, renderer_settings, task_runner, | |
| 365 synchronous_composite, disable_display_vsync, refresh_rate); | |
| 366 layer_tree_frame_sink->SetClient(this); | |
| 367 layer_tree_frame_sinks_[routing_id] = layer_tree_frame_sink.get(); | |
| 368 return std::move(layer_tree_frame_sink); | |
| 369 } | |
| 370 | |
| 371 std::unique_ptr<cc::SwapPromise> RequestCopyOfOutput( | 322 std::unique_ptr<cc::SwapPromise> RequestCopyOfOutput( |
| 372 int32_t routing_id, | 323 int32_t routing_id, |
| 373 std::unique_ptr<cc::CopyOutputRequest> request) override { | 324 std::unique_ptr<cc::CopyOutputRequest> request) override { |
| 374 // Note that we can't immediately check layer_tree_frame_sinks_, since it | 325 // Note that we can't immediately check layer_tree_frame_sinks_, since it |
| 375 // may not have been created yet. Instead, we wait until OnCommit to find | 326 // may not have been created yet. Instead, we wait until OnCommit to find |
| 376 // the currently active LayerTreeFrameSink for the given RenderWidget | 327 // the currently active LayerTreeFrameSink for the given RenderWidget |
| 377 // routing_id. | 328 // routing_id. |
| 378 return base::MakeUnique<CopyRequestSwapPromise>( | 329 return base::MakeUnique<CopyRequestSwapPromise>(std::move(request)); |
| 379 std::move(request), | |
| 380 base::Bind( | |
| 381 &LayoutTestDependenciesImpl::FindLayerTreeFrameSink, | |
| 382 // |this| will still be valid, because its lifetime is tied to | |
| 383 // RenderThreadImpl, which outlives layout test execution. | |
| 384 base::Unretained(this), routing_id)); | |
| 385 } | 330 } |
| 386 | 331 |
| 387 // TestLayerTreeFrameSinkClient implementation. | 332 // TestLayerTreeFrameSinkClient implementation. |
| 388 std::unique_ptr<cc::OutputSurface> CreateDisplayOutputSurface( | 333 std::unique_ptr<cc::OutputSurface> CreateDisplayOutputSurface( |
| 389 scoped_refptr<cc::ContextProvider> compositor_context_provider) override { | 334 scoped_refptr<cc::ContextProvider> compositor_context_provider) override { |
| 390 // This is for an offscreen context for the compositor. So the default | 335 // This is for an offscreen context for the compositor. So the default |
| 391 // framebuffer doesn't need alpha, depth, stencil, antialiasing. | 336 // framebuffer doesn't need alpha, depth, stencil, antialiasing. |
| 392 gpu::gles2::ContextCreationAttribHelper attributes; | 337 gpu::gles2::ContextCreationAttribHelper attributes; |
| 393 attributes.alpha_size = -1; | 338 attributes.alpha_size = -1; |
| 394 attributes.depth_size = 0; | 339 attributes.depth_size = 0; |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 } | 556 } |
| 612 } | 557 } |
| 613 | 558 |
| 614 bool IsNavigationInitiatedByRenderer(const blink::WebURLRequest& request) { | 559 bool IsNavigationInitiatedByRenderer(const blink::WebURLRequest& request) { |
| 615 RequestExtraData* extra_data = | 560 RequestExtraData* extra_data = |
| 616 static_cast<RequestExtraData*>(request.GetExtraData()); | 561 static_cast<RequestExtraData*>(request.GetExtraData()); |
| 617 return extra_data && extra_data->navigation_initiated_by_renderer(); | 562 return extra_data && extra_data->navigation_initiated_by_renderer(); |
| 618 } | 563 } |
| 619 | 564 |
| 620 } // namespace content | 565 } // namespace content |
| OLD | NEW |