| 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" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 27 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 28 const RendererSettings& renderer_settings, | 28 const RendererSettings& renderer_settings, |
| 29 base::SingleThreadTaskRunner* task_runner, | 29 base::SingleThreadTaskRunner* task_runner, |
| 30 bool synchronous_composite, | 30 bool synchronous_composite, |
| 31 bool force_disable_reclaim_resources) | 31 bool force_disable_reclaim_resources) |
| 32 : CompositorFrameSink(std::move(compositor_context_provider), | 32 : CompositorFrameSink(std::move(compositor_context_provider), |
| 33 std::move(worker_context_provider)), | 33 std::move(worker_context_provider)), |
| 34 surface_manager_(new SurfaceManager), | 34 surface_manager_(new SurfaceManager), |
| 35 surface_id_allocator_(new SurfaceIdAllocator( | 35 surface_id_allocator_(new SurfaceIdAllocator( |
| 36 FrameSinkId(kCompositorClientId, kCompositorSinkId))), | 36 FrameSinkId(kCompositorClientId, kCompositorSinkId))), |
| 37 surface_factory_(new SurfaceFactory(surface_manager_.get(), this)) { | 37 surface_factory_(new SurfaceFactory(surface_manager_.get(), this)), |
| 38 weak_ptrs_(this) { |
| 38 std::unique_ptr<SyntheticBeginFrameSource> begin_frame_source; | 39 std::unique_ptr<SyntheticBeginFrameSource> begin_frame_source; |
| 39 std::unique_ptr<DisplayScheduler> scheduler; | 40 std::unique_ptr<DisplayScheduler> scheduler; |
| 40 if (!synchronous_composite) { | 41 if (!synchronous_composite) { |
| 41 if (renderer_settings.disable_display_vsync) { | 42 if (renderer_settings.disable_display_vsync) { |
| 42 begin_frame_source.reset(new BackToBackBeginFrameSource( | 43 begin_frame_source.reset(new BackToBackBeginFrameSource( |
| 43 base::MakeUnique<DelayBasedTimeSource>(task_runner))); | 44 base::MakeUnique<DelayBasedTimeSource>(task_runner))); |
| 44 } else { | 45 } else { |
| 45 begin_frame_source.reset(new DelayBasedBeginFrameSource( | 46 begin_frame_source.reset(new DelayBasedBeginFrameSource( |
| 46 base::MakeUnique<DelayBasedTimeSource>(task_runner))); | 47 base::MakeUnique<DelayBasedTimeSource>(task_runner))); |
| 47 begin_frame_source->SetAuthoritativeVSyncInterval( | 48 begin_frame_source->SetAuthoritativeVSyncInterval( |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 surface_manager_->UnregisterSurfaceFactoryClient( | 110 surface_manager_->UnregisterSurfaceFactoryClient( |
| 110 surface_id_allocator_->frame_sink_id()); | 111 surface_id_allocator_->frame_sink_id()); |
| 111 surface_manager_->InvalidateFrameSinkId( | 112 surface_manager_->InvalidateFrameSinkId( |
| 112 surface_id_allocator_->frame_sink_id()); | 113 surface_id_allocator_->frame_sink_id()); |
| 113 bound_ = false; | 114 bound_ = false; |
| 114 } | 115 } |
| 115 display_ = nullptr; | 116 display_ = nullptr; |
| 116 surface_factory_ = nullptr; | 117 surface_factory_ = nullptr; |
| 117 surface_id_allocator_ = nullptr; | 118 surface_id_allocator_ = nullptr; |
| 118 surface_manager_ = nullptr; | 119 surface_manager_ = nullptr; |
| 120 weak_ptrs_.InvalidateWeakPtrs(); |
| 119 CompositorFrameSink::DetachFromClient(); | 121 CompositorFrameSink::DetachFromClient(); |
| 120 } | 122 } |
| 121 | 123 |
| 122 void TestCompositorFrameSink::SwapBuffers(CompositorFrame frame) { | 124 void TestCompositorFrameSink::SwapBuffers(CompositorFrame frame) { |
| 123 if (test_client_) | 125 if (test_client_) |
| 124 test_client_->DisplayReceivedCompositorFrame(frame); | 126 test_client_->DisplayReceivedCompositorFrame(frame); |
| 125 | 127 |
| 126 if (delegated_surface_id_.is_null()) { | 128 if (delegated_surface_id_.is_null()) { |
| 127 delegated_surface_id_ = surface_id_allocator_->GenerateId(); | 129 delegated_surface_id_ = surface_id_allocator_->GenerateId(); |
| 128 surface_factory_->Create(delegated_surface_id_); | 130 surface_factory_->Create(delegated_surface_id_); |
| 129 } | 131 } |
| 130 display_->SetSurfaceId(delegated_surface_id_, | 132 display_->SetSurfaceId(delegated_surface_id_, |
| 131 frame.metadata.device_scale_factor); | 133 frame.metadata.device_scale_factor); |
| 132 | 134 |
| 133 gfx::Size frame_size = | 135 gfx::Size frame_size = |
| 134 frame.delegated_frame_data->render_pass_list.back()->output_rect.size(); | 136 frame.delegated_frame_data->render_pass_list.back()->output_rect.size(); |
| 135 display_->Resize(frame_size); | 137 display_->Resize(frame_size); |
| 136 | 138 |
| 137 bool synchronous = !display_->has_scheduler(); | 139 bool synchronous = !display_->has_scheduler(); |
| 138 | 140 |
| 139 surface_factory_->SubmitCompositorFrame( | 141 surface_factory_->SubmitCompositorFrame( |
| 140 delegated_surface_id_, std::move(frame), | 142 delegated_surface_id_, std::move(frame), |
| 141 base::Bind(&TestCompositorFrameSink::DidDrawCallback, | 143 base::Bind(&TestCompositorFrameSink::DidDrawCallback, |
| 142 base::Unretained(this))); | 144 weak_ptrs_.GetWeakPtr(), synchronous)); |
| 143 | 145 |
| 144 for (std::unique_ptr<CopyOutputRequest>& copy_request : copy_requests_) | 146 for (std::unique_ptr<CopyOutputRequest>& copy_request : copy_requests_) |
| 145 surface_factory_->RequestCopyOfSurface(delegated_surface_id_, | 147 surface_factory_->RequestCopyOfSurface(delegated_surface_id_, |
| 146 std::move(copy_request)); | 148 std::move(copy_request)); |
| 147 copy_requests_.clear(); | 149 copy_requests_.clear(); |
| 148 | 150 |
| 149 if (synchronous) | 151 if (synchronous) |
| 150 display_->DrawAndSwap(); | 152 display_->DrawAndSwap(); |
| 151 } | 153 } |
| 152 | 154 |
| 153 void TestCompositorFrameSink::DidDrawCallback() { | 155 void TestCompositorFrameSink::DidDrawCallback(bool synchronous) { |
| 154 // This is the frame ack to unthrottle the next frame, not actually a notice | 156 // This is the frame ack to unthrottle the next frame, not actually a notice |
| 155 // that drawing is done. | 157 // that drawing is done. |
| 156 CompositorFrameSink::PostSwapBuffersComplete(); | 158 if (synchronous) { |
| 159 // For synchronous draws, this must be posted to a new stack because we are |
| 160 // still the original call to SwapBuffers, and we want to leave that before |
| 161 // saying that it is done. |
| 162 CompositorFrameSink::PostSwapBuffersComplete(); |
| 163 } else { |
| 164 client_->DidSwapBuffersComplete(); |
| 165 } |
| 157 } | 166 } |
| 158 | 167 |
| 159 void TestCompositorFrameSink::ForceReclaimResources() { | 168 void TestCompositorFrameSink::ForceReclaimResources() { |
| 160 if (capabilities_.can_force_reclaim_resources && | 169 if (capabilities_.can_force_reclaim_resources && |
| 161 !delegated_surface_id_.is_null()) { | 170 !delegated_surface_id_.is_null()) { |
| 162 surface_factory_->SubmitCompositorFrame(delegated_surface_id_, | 171 surface_factory_->SubmitCompositorFrame(delegated_surface_id_, |
| 163 CompositorFrame(), | 172 CompositorFrame(), |
| 164 SurfaceFactory::DrawCallback()); | 173 SurfaceFactory::DrawCallback()); |
| 165 } | 174 } |
| 166 } | 175 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 185 if (test_client_) | 194 if (test_client_) |
| 186 test_client_->DisplayWillDrawAndSwap(will_draw_and_swap, render_passes); | 195 test_client_->DisplayWillDrawAndSwap(will_draw_and_swap, render_passes); |
| 187 } | 196 } |
| 188 | 197 |
| 189 void TestCompositorFrameSink::DisplayDidDrawAndSwap() { | 198 void TestCompositorFrameSink::DisplayDidDrawAndSwap() { |
| 190 if (test_client_) | 199 if (test_client_) |
| 191 test_client_->DisplayDidDrawAndSwap(); | 200 test_client_->DisplayDidDrawAndSwap(); |
| 192 } | 201 } |
| 193 | 202 |
| 194 } // namespace cc | 203 } // namespace cc |
| OLD | NEW |