| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/test_compositor_frame_sink.h" | 5 #include "cc/test/test_compositor_frame_sink.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "cc/output/begin_frame_args.h" | 10 #include "cc/output/begin_frame_args.h" |
| 11 #include "cc/output/compositor_frame_sink_client.h" | 11 #include "cc/output/compositor_frame_sink_client.h" |
| 12 #include "cc/output/copy_output_request.h" | 12 #include "cc/output/copy_output_request.h" |
| 13 #include "cc/output/direct_renderer.h" | 13 #include "cc/output/direct_renderer.h" |
| 14 #include "cc/output/output_surface.h" | 14 #include "cc/output/output_surface.h" |
| 15 #include "cc/output/texture_mailbox_deleter.h" | 15 #include "cc/output/texture_mailbox_deleter.h" |
| 16 | 16 |
| 17 namespace cc { | 17 namespace cc { |
| 18 | 18 |
| 19 static constexpr FrameSinkId kCompositorFrameSinkId(1, 1); | 19 static constexpr FrameSinkId kCompositorFrameSinkId(1, 1); |
| 20 | 20 |
| 21 TestCompositorFrameSink::TestCompositorFrameSink( | 21 TestCompositorFrameSink::TestCompositorFrameSink( |
| 22 scoped_refptr<ContextProvider> compositor_context_provider, | 22 scoped_refptr<ContextProvider> compositor_context_provider, |
| 23 scoped_refptr<ContextProvider> worker_context_provider, | 23 scoped_refptr<ContextProvider> worker_context_provider, |
| 24 std::unique_ptr<OutputSurface> display_output_surface, | |
| 25 SharedBitmapManager* shared_bitmap_manager, | 24 SharedBitmapManager* shared_bitmap_manager, |
| 26 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 25 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 27 const RendererSettings& renderer_settings, | 26 const RendererSettings& renderer_settings, |
| 28 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 27 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 29 bool synchronous_composite, | 28 bool synchronous_composite, |
| 30 bool force_disable_reclaim_resources) | 29 bool force_disable_reclaim_resources) |
| 31 : CompositorFrameSink(std::move(compositor_context_provider), | 30 : CompositorFrameSink(std::move(compositor_context_provider), |
| 32 std::move(worker_context_provider)), | 31 std::move(worker_context_provider)), |
| 32 synchronous_composite_(synchronous_composite), |
| 33 renderer_settings_(renderer_settings), |
| 34 shared_bitmap_manager_(shared_bitmap_manager), |
| 35 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), |
| 33 task_runner_(std::move(task_runner)), | 36 task_runner_(std::move(task_runner)), |
| 34 frame_sink_id_(kCompositorFrameSinkId), | 37 frame_sink_id_(kCompositorFrameSinkId), |
| 35 surface_manager_(new SurfaceManager), | 38 surface_manager_(new SurfaceManager), |
| 36 surface_id_allocator_(new SurfaceIdAllocator()), | 39 surface_id_allocator_(new SurfaceIdAllocator()), |
| 37 surface_factory_( | 40 surface_factory_( |
| 38 new SurfaceFactory(frame_sink_id_, surface_manager_.get(), this)), | 41 new SurfaceFactory(frame_sink_id_, surface_manager_.get(), this)), |
| 39 display_context_shared_with_compositor_( | |
| 40 display_output_surface->context_provider() == context_provider()), | |
| 41 weak_ptr_factory_(this) { | 42 weak_ptr_factory_(this) { |
| 42 std::unique_ptr<SyntheticBeginFrameSource> begin_frame_source; | |
| 43 std::unique_ptr<DisplayScheduler> scheduler; | |
| 44 if (!synchronous_composite) { | |
| 45 if (renderer_settings.disable_display_vsync) { | |
| 46 begin_frame_source.reset(new BackToBackBeginFrameSource( | |
| 47 base::MakeUnique<DelayBasedTimeSource>(task_runner_.get()))); | |
| 48 } else { | |
| 49 begin_frame_source.reset(new DelayBasedBeginFrameSource( | |
| 50 base::MakeUnique<DelayBasedTimeSource>(task_runner_.get()))); | |
| 51 begin_frame_source->SetAuthoritativeVSyncInterval( | |
| 52 base::TimeDelta::FromMilliseconds(1000.f / | |
| 53 renderer_settings.refresh_rate)); | |
| 54 } | |
| 55 scheduler.reset(new DisplayScheduler( | |
| 56 begin_frame_source.get(), task_runner_.get(), | |
| 57 display_output_surface->capabilities().max_frames_pending)); | |
| 58 } | |
| 59 display_.reset( | |
| 60 new Display(shared_bitmap_manager, gpu_memory_buffer_manager, | |
| 61 renderer_settings, std::move(begin_frame_source), | |
| 62 std::move(display_output_surface), std::move(scheduler), | |
| 63 base::MakeUnique<TextureMailboxDeleter>(task_runner_.get()))); | |
| 64 | |
| 65 // Since this CompositorFrameSink and the Display are tightly coupled and in | 43 // Since this CompositorFrameSink and the Display are tightly coupled and in |
| 66 // the same process/thread, the LayerTreeHostImpl can reclaim resources from | 44 // the same process/thread, the LayerTreeHostImpl can reclaim resources from |
| 67 // the Display. But we allow tests to disable this to mimic an out-of-process | 45 // the Display. But we allow tests to disable this to mimic an out-of-process |
| 68 // Display. | 46 // Display. |
| 69 capabilities_.can_force_reclaim_resources = !force_disable_reclaim_resources; | 47 capabilities_.can_force_reclaim_resources = !force_disable_reclaim_resources; |
| 70 // Always use sync tokens so that code paths in resource provider that deal | 48 // Always use sync tokens so that code paths in resource provider that deal |
| 71 // with sync tokens are tested. | 49 // with sync tokens are tested. |
| 72 capabilities_.delegated_sync_points_required = true; | 50 capabilities_.delegated_sync_points_required = true; |
| 73 } | 51 } |
| 74 | 52 |
| 75 TestCompositorFrameSink::~TestCompositorFrameSink() { | 53 TestCompositorFrameSink::~TestCompositorFrameSink() { |
| 76 DCHECK(copy_requests_.empty()); | 54 DCHECK(copy_requests_.empty()); |
| 77 } | 55 } |
| 78 | 56 |
| 79 void TestCompositorFrameSink::RequestCopyOfOutput( | 57 void TestCompositorFrameSink::RequestCopyOfOutput( |
| 80 std::unique_ptr<CopyOutputRequest> request) { | 58 std::unique_ptr<CopyOutputRequest> request) { |
| 81 copy_requests_.push_back(std::move(request)); | 59 copy_requests_.push_back(std::move(request)); |
| 82 } | 60 } |
| 83 | 61 |
| 84 bool TestCompositorFrameSink::BindToClient(CompositorFrameSinkClient* client) { | 62 bool TestCompositorFrameSink::BindToClient(CompositorFrameSinkClient* client) { |
| 85 if (!CompositorFrameSink::BindToClient(client)) | 63 if (!CompositorFrameSink::BindToClient(client)) |
| 86 return false; | 64 return false; |
| 87 | 65 |
| 66 std::unique_ptr<OutputSurface> display_output_surface = |
| 67 test_client_->CreateDisplayOutputSurface(context_provider()); |
| 68 bool display_context_shared_with_compositor = |
| 69 display_output_surface->context_provider() == context_provider(); |
| 70 |
| 71 std::unique_ptr<SyntheticBeginFrameSource> begin_frame_source; |
| 72 std::unique_ptr<DisplayScheduler> scheduler; |
| 73 if (!synchronous_composite_) { |
| 74 if (renderer_settings_.disable_display_vsync) { |
| 75 begin_frame_source.reset(new BackToBackBeginFrameSource( |
| 76 base::MakeUnique<DelayBasedTimeSource>(task_runner_.get()))); |
| 77 } else { |
| 78 begin_frame_source.reset(new DelayBasedBeginFrameSource( |
| 79 base::MakeUnique<DelayBasedTimeSource>(task_runner_.get()))); |
| 80 begin_frame_source->SetAuthoritativeVSyncInterval( |
| 81 base::TimeDelta::FromMilliseconds(1000.f / |
| 82 renderer_settings_.refresh_rate)); |
| 83 } |
| 84 scheduler.reset(new DisplayScheduler( |
| 85 begin_frame_source.get(), task_runner_.get(), |
| 86 display_output_surface->capabilities().max_frames_pending)); |
| 87 } |
| 88 |
| 89 display_.reset( |
| 90 new Display(shared_bitmap_manager_, gpu_memory_buffer_manager_, |
| 91 renderer_settings_, std::move(begin_frame_source), |
| 92 std::move(display_output_surface), std::move(scheduler), |
| 93 base::MakeUnique<TextureMailboxDeleter>(task_runner_.get()))); |
| 94 |
| 88 // We want the Display's OutputSurface to hear about lost context, and when | 95 // We want the Display's OutputSurface to hear about lost context, and when |
| 89 // this shares a context with it we should not be listening for lost context | 96 // this shares a context with it we should not be listening for lost context |
| 90 // callbacks on the context here. | 97 // callbacks on the context here. |
| 91 if (display_context_shared_with_compositor_ && context_provider()) | 98 if (display_context_shared_with_compositor && context_provider()) |
| 92 context_provider()->SetLostContextCallback(base::Closure()); | 99 context_provider()->SetLostContextCallback(base::Closure()); |
| 93 | 100 |
| 94 surface_manager_->RegisterFrameSinkId(frame_sink_id_); | 101 surface_manager_->RegisterFrameSinkId(frame_sink_id_); |
| 95 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this); | 102 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this); |
| 96 display_->Initialize(this, surface_manager_.get(), frame_sink_id_); | 103 display_->Initialize(this, surface_manager_.get(), frame_sink_id_); |
| 97 display_->renderer_for_testing()->SetEnlargePassTextureAmountForTesting( | 104 display_->renderer_for_testing()->SetEnlargePassTextureAmountForTesting( |
| 98 enlarge_pass_texture_amount_); | 105 enlarge_pass_texture_amount_); |
| 99 display_->SetVisible(true); | 106 display_->SetVisible(true); |
| 100 bound_ = true; | 107 bound_ = true; |
| 101 return true; | 108 return true; |
| 102 } | 109 } |
| 103 | 110 |
| 104 void TestCompositorFrameSink::DetachFromClient() { | 111 void TestCompositorFrameSink::DetachFromClient() { |
| 105 // Some tests make BindToClient fail on purpose. ^__^ | 112 // Some tests make BindToClient fail on purpose. ^__^ |
| 106 if (bound_) { | 113 if (bound_) { |
| 107 if (!delegated_local_frame_id_.is_null()) | 114 if (!delegated_local_frame_id_.is_null()) |
| 108 surface_factory_->Destroy(delegated_local_frame_id_); | 115 surface_factory_->Destroy(delegated_local_frame_id_); |
| 109 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); | 116 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); |
| 110 surface_manager_->InvalidateFrameSinkId(frame_sink_id_); | 117 surface_manager_->InvalidateFrameSinkId(frame_sink_id_); |
| 118 display_ = nullptr; |
| 111 bound_ = false; | 119 bound_ = false; |
| 112 } | 120 } |
| 113 display_ = nullptr; | |
| 114 surface_factory_ = nullptr; | 121 surface_factory_ = nullptr; |
| 115 surface_id_allocator_ = nullptr; | 122 surface_id_allocator_ = nullptr; |
| 116 surface_manager_ = nullptr; | 123 surface_manager_ = nullptr; |
| 124 test_client_ = nullptr; |
| 117 CompositorFrameSink::DetachFromClient(); | 125 CompositorFrameSink::DetachFromClient(); |
| 118 } | 126 } |
| 119 | 127 |
| 120 void TestCompositorFrameSink::SubmitCompositorFrame(CompositorFrame frame) { | 128 void TestCompositorFrameSink::SubmitCompositorFrame(CompositorFrame frame) { |
| 121 if (test_client_) | 129 test_client_->DisplayReceivedCompositorFrame(frame); |
| 122 test_client_->DisplayReceivedCompositorFrame(frame); | |
| 123 | 130 |
| 124 if (delegated_local_frame_id_.is_null()) { | 131 if (delegated_local_frame_id_.is_null()) { |
| 125 delegated_local_frame_id_ = surface_id_allocator_->GenerateId(); | 132 delegated_local_frame_id_ = surface_id_allocator_->GenerateId(); |
| 126 surface_factory_->Create(delegated_local_frame_id_); | 133 surface_factory_->Create(delegated_local_frame_id_); |
| 127 } | 134 } |
| 128 display_->SetSurfaceId(SurfaceId(frame_sink_id_, delegated_local_frame_id_), | 135 display_->SetSurfaceId(SurfaceId(frame_sink_id_, delegated_local_frame_id_), |
| 129 frame.metadata.device_scale_factor); | 136 frame.metadata.device_scale_factor); |
| 130 | 137 |
| 131 gfx::Size frame_size = | 138 gfx::Size frame_size = |
| 132 frame.delegated_frame_data->render_pass_list.back()->output_rect.size(); | 139 frame.delegated_frame_data->render_pass_list.back()->output_rect.size(); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 client_->SetBeginFrameSource(begin_frame_source); | 195 client_->SetBeginFrameSource(begin_frame_source); |
| 189 } | 196 } |
| 190 | 197 |
| 191 void TestCompositorFrameSink::DisplayOutputSurfaceLost() { | 198 void TestCompositorFrameSink::DisplayOutputSurfaceLost() { |
| 192 client_->DidLoseCompositorFrameSink(); | 199 client_->DidLoseCompositorFrameSink(); |
| 193 } | 200 } |
| 194 | 201 |
| 195 void TestCompositorFrameSink::DisplayWillDrawAndSwap( | 202 void TestCompositorFrameSink::DisplayWillDrawAndSwap( |
| 196 bool will_draw_and_swap, | 203 bool will_draw_and_swap, |
| 197 const RenderPassList& render_passes) { | 204 const RenderPassList& render_passes) { |
| 198 if (test_client_) | 205 test_client_->DisplayWillDrawAndSwap(will_draw_and_swap, render_passes); |
| 199 test_client_->DisplayWillDrawAndSwap(will_draw_and_swap, render_passes); | |
| 200 } | 206 } |
| 201 | 207 |
| 202 void TestCompositorFrameSink::DisplayDidDrawAndSwap() { | 208 void TestCompositorFrameSink::DisplayDidDrawAndSwap() { |
| 203 if (test_client_) | 209 test_client_->DisplayDidDrawAndSwap(); |
| 204 test_client_->DisplayDidDrawAndSwap(); | |
| 205 } | 210 } |
| 206 | 211 |
| 207 } // namespace cc | 212 } // namespace cc |
| OLD | NEW |