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 static constexpr cc::FrameSinkId kCompositorFrameSinkId(1, 1); | 17 namespace cc { |
18 | 18 |
19 namespace cc { | 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, | 24 std::unique_ptr<OutputSurface> display_output_surface, |
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 frame_sink_id_(kCompositorFrameSinkId), | 33 frame_sink_id_(kCompositorFrameSinkId), |
34 surface_manager_(new SurfaceManager), | 34 surface_manager_(new SurfaceManager), |
35 surface_id_allocator_(new SurfaceIdAllocator(frame_sink_id_)), | 35 surface_id_allocator_(new SurfaceIdAllocator()), |
36 surface_factory_( | 36 surface_factory_( |
37 new SurfaceFactory(frame_sink_id_, surface_manager_.get(), this)), | 37 new SurfaceFactory(frame_sink_id_, surface_manager_.get(), this)), |
38 weak_ptrs_(this) { | 38 weak_ptrs_(this) { |
39 std::unique_ptr<SyntheticBeginFrameSource> begin_frame_source; | 39 std::unique_ptr<SyntheticBeginFrameSource> begin_frame_source; |
40 std::unique_ptr<DisplayScheduler> scheduler; | 40 std::unique_ptr<DisplayScheduler> scheduler; |
41 if (!synchronous_composite) { | 41 if (!synchronous_composite) { |
42 if (renderer_settings.disable_display_vsync) { | 42 if (renderer_settings.disable_display_vsync) { |
43 begin_frame_source.reset(new BackToBackBeginFrameSource( | 43 begin_frame_source.reset(new BackToBackBeginFrameSource( |
44 base::MakeUnique<DelayBasedTimeSource>(task_runner))); | 44 base::MakeUnique<DelayBasedTimeSource>(task_runner))); |
45 } else { | 45 } else { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 display_->renderer_for_testing()->SetEnlargePassTextureAmountForTesting( | 96 display_->renderer_for_testing()->SetEnlargePassTextureAmountForTesting( |
97 enlarge_pass_texture_amount_); | 97 enlarge_pass_texture_amount_); |
98 display_->SetVisible(true); | 98 display_->SetVisible(true); |
99 bound_ = true; | 99 bound_ = true; |
100 return true; | 100 return true; |
101 } | 101 } |
102 | 102 |
103 void TestCompositorFrameSink::DetachFromClient() { | 103 void TestCompositorFrameSink::DetachFromClient() { |
104 // Some tests make BindToClient fail on purpose. ^__^ | 104 // Some tests make BindToClient fail on purpose. ^__^ |
105 if (bound_) { | 105 if (bound_) { |
106 if (!delegated_surface_id_.is_null()) | 106 if (!delegated_local_frame_id_.is_null()) |
107 surface_factory_->Destroy(delegated_surface_id_); | 107 surface_factory_->Destroy(delegated_local_frame_id_); |
108 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); | 108 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); |
109 surface_manager_->InvalidateFrameSinkId(frame_sink_id_); | 109 surface_manager_->InvalidateFrameSinkId(frame_sink_id_); |
110 bound_ = false; | 110 bound_ = false; |
111 } | 111 } |
112 display_ = nullptr; | 112 display_ = nullptr; |
113 surface_factory_ = nullptr; | 113 surface_factory_ = nullptr; |
114 surface_id_allocator_ = nullptr; | 114 surface_id_allocator_ = nullptr; |
115 surface_manager_ = nullptr; | 115 surface_manager_ = nullptr; |
116 weak_ptrs_.InvalidateWeakPtrs(); | 116 weak_ptrs_.InvalidateWeakPtrs(); |
117 CompositorFrameSink::DetachFromClient(); | 117 CompositorFrameSink::DetachFromClient(); |
118 } | 118 } |
119 | 119 |
120 void TestCompositorFrameSink::SwapBuffers(CompositorFrame frame) { | 120 void TestCompositorFrameSink::SwapBuffers(CompositorFrame frame) { |
121 if (test_client_) | 121 if (test_client_) |
122 test_client_->DisplayReceivedCompositorFrame(frame); | 122 test_client_->DisplayReceivedCompositorFrame(frame); |
123 | 123 |
124 if (delegated_surface_id_.is_null()) { | 124 if (delegated_local_frame_id_.is_null()) { |
125 delegated_surface_id_ = surface_id_allocator_->GenerateId(); | 125 delegated_local_frame_id_ = surface_id_allocator_->GenerateId(); |
126 surface_factory_->Create(delegated_surface_id_); | 126 surface_factory_->Create(delegated_local_frame_id_); |
127 } | 127 } |
128 display_->SetSurfaceId(delegated_surface_id_, | 128 display_->SetSurfaceId(SurfaceId(frame_sink_id_, delegated_local_frame_id_), |
129 frame.metadata.device_scale_factor); | 129 frame.metadata.device_scale_factor); |
130 | 130 |
131 gfx::Size frame_size = | 131 gfx::Size frame_size = |
132 frame.delegated_frame_data->render_pass_list.back()->output_rect.size(); | 132 frame.delegated_frame_data->render_pass_list.back()->output_rect.size(); |
133 display_->Resize(frame_size); | 133 display_->Resize(frame_size); |
134 | 134 |
135 bool synchronous = !display_->has_scheduler(); | 135 bool synchronous = !display_->has_scheduler(); |
136 | 136 |
137 surface_factory_->SubmitCompositorFrame( | 137 surface_factory_->SubmitCompositorFrame( |
138 delegated_surface_id_, std::move(frame), | 138 delegated_local_frame_id_, std::move(frame), |
139 base::Bind(&TestCompositorFrameSink::DidDrawCallback, | 139 base::Bind(&TestCompositorFrameSink::DidDrawCallback, |
140 weak_ptrs_.GetWeakPtr(), synchronous)); | 140 weak_ptrs_.GetWeakPtr(), synchronous)); |
141 | 141 |
142 for (std::unique_ptr<CopyOutputRequest>& copy_request : copy_requests_) | 142 for (std::unique_ptr<CopyOutputRequest>& copy_request : copy_requests_) { |
143 surface_factory_->RequestCopyOfSurface(delegated_surface_id_, | 143 surface_factory_->RequestCopyOfSurface(delegated_local_frame_id_, |
144 std::move(copy_request)); | 144 std::move(copy_request)); |
| 145 } |
145 copy_requests_.clear(); | 146 copy_requests_.clear(); |
146 | 147 |
147 if (synchronous) | 148 if (synchronous) |
148 display_->DrawAndSwap(); | 149 display_->DrawAndSwap(); |
149 } | 150 } |
150 | 151 |
151 void TestCompositorFrameSink::DidDrawCallback(bool synchronous) { | 152 void TestCompositorFrameSink::DidDrawCallback(bool synchronous) { |
152 // This is the frame ack to unthrottle the next frame, not actually a notice | 153 // This is the frame ack to unthrottle the next frame, not actually a notice |
153 // that drawing is done. | 154 // that drawing is done. |
154 if (synchronous) { | 155 if (synchronous) { |
155 // For synchronous draws, this must be posted to a new stack because we are | 156 // For synchronous draws, this must be posted to a new stack because we are |
156 // still the original call to SwapBuffers, and we want to leave that before | 157 // still the original call to SwapBuffers, and we want to leave that before |
157 // saying that it is done. | 158 // saying that it is done. |
158 CompositorFrameSink::PostSwapBuffersComplete(); | 159 CompositorFrameSink::PostSwapBuffersComplete(); |
159 } else { | 160 } else { |
160 client_->DidSwapBuffersComplete(); | 161 client_->DidSwapBuffersComplete(); |
161 } | 162 } |
162 } | 163 } |
163 | 164 |
164 void TestCompositorFrameSink::ForceReclaimResources() { | 165 void TestCompositorFrameSink::ForceReclaimResources() { |
165 if (capabilities_.can_force_reclaim_resources && | 166 if (capabilities_.can_force_reclaim_resources && |
166 !delegated_surface_id_.is_null()) { | 167 !delegated_local_frame_id_.is_null()) { |
167 surface_factory_->SubmitCompositorFrame(delegated_surface_id_, | 168 surface_factory_->SubmitCompositorFrame(delegated_local_frame_id_, |
168 CompositorFrame(), | 169 CompositorFrame(), |
169 SurfaceFactory::DrawCallback()); | 170 SurfaceFactory::DrawCallback()); |
170 } | 171 } |
171 } | 172 } |
172 | 173 |
173 void TestCompositorFrameSink::ReturnResources( | 174 void TestCompositorFrameSink::ReturnResources( |
174 const ReturnedResourceArray& resources) { | 175 const ReturnedResourceArray& resources) { |
175 client_->ReclaimResources(resources); | 176 client_->ReclaimResources(resources); |
176 } | 177 } |
177 | 178 |
(...skipping 12 matching lines...) Expand all Loading... |
190 if (test_client_) | 191 if (test_client_) |
191 test_client_->DisplayWillDrawAndSwap(will_draw_and_swap, render_passes); | 192 test_client_->DisplayWillDrawAndSwap(will_draw_and_swap, render_passes); |
192 } | 193 } |
193 | 194 |
194 void TestCompositorFrameSink::DisplayDidDrawAndSwap() { | 195 void TestCompositorFrameSink::DisplayDidDrawAndSwap() { |
195 if (test_client_) | 196 if (test_client_) |
196 test_client_->DisplayDidDrawAndSwap(); | 197 test_client_->DisplayDidDrawAndSwap(); |
197 } | 198 } |
198 | 199 |
199 } // namespace cc | 200 } // namespace cc |
OLD | NEW |