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