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