| 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 "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 surface_factory_ = nullptr; | 120 surface_factory_ = nullptr; |
| 121 surface_id_allocator_ = nullptr; | 121 surface_id_allocator_ = nullptr; |
| 122 surface_manager_ = nullptr; | 122 surface_manager_ = nullptr; |
| 123 test_client_ = nullptr; | 123 test_client_ = nullptr; |
| 124 CompositorFrameSink::DetachFromClient(); | 124 CompositorFrameSink::DetachFromClient(); |
| 125 } | 125 } |
| 126 | 126 |
| 127 void TestCompositorFrameSink::SubmitCompositorFrame(CompositorFrame frame) { | 127 void TestCompositorFrameSink::SubmitCompositorFrame(CompositorFrame frame) { |
| 128 test_client_->DisplayReceivedCompositorFrame(frame); | 128 test_client_->DisplayReceivedCompositorFrame(frame); |
| 129 | 129 |
| 130 if (!delegated_local_frame_id_.is_valid()) { | 130 if (!delegated_local_surface_id_.is_valid()) { |
| 131 delegated_local_frame_id_ = surface_id_allocator_->GenerateId(); | 131 delegated_local_surface_id_ = surface_id_allocator_->GenerateId(); |
| 132 } | 132 } |
| 133 display_->SetLocalFrameId(delegated_local_frame_id_, | 133 display_->SetLocalSurfaceId(delegated_local_surface_id_, |
| 134 frame.metadata.device_scale_factor); | 134 frame.metadata.device_scale_factor); |
| 135 | 135 |
| 136 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size(); | 136 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size(); |
| 137 display_->Resize(frame_size); | 137 display_->Resize(frame_size); |
| 138 | 138 |
| 139 bool synchronous = !display_->has_scheduler(); | 139 bool synchronous = !display_->has_scheduler(); |
| 140 | 140 |
| 141 SurfaceFactory::DrawCallback draw_callback; | 141 SurfaceFactory::DrawCallback draw_callback; |
| 142 if (!synchronous) { | 142 if (!synchronous) { |
| 143 // For async draws, we use a callback tell when it is done, but for sync | 143 // For async draws, we use a callback tell when it is done, but for sync |
| 144 // draws we don't need one. Unretained is safe here because the callback | 144 // draws we don't need one. Unretained is safe here because the callback |
| 145 // will be run when |surface_factory_| is destroyed which is owned by this | 145 // will be run when |surface_factory_| is destroyed which is owned by this |
| 146 // class. | 146 // class. |
| 147 draw_callback = base::Bind(&TestCompositorFrameSink::DidDrawCallback, | 147 draw_callback = base::Bind(&TestCompositorFrameSink::DidDrawCallback, |
| 148 base::Unretained(this)); | 148 base::Unretained(this)); |
| 149 } | 149 } |
| 150 | 150 |
| 151 surface_factory_->SubmitCompositorFrame(delegated_local_frame_id_, | 151 surface_factory_->SubmitCompositorFrame(delegated_local_surface_id_, |
| 152 std::move(frame), draw_callback); | 152 std::move(frame), draw_callback); |
| 153 | 153 |
| 154 for (std::unique_ptr<CopyOutputRequest>& copy_request : copy_requests_) { | 154 for (std::unique_ptr<CopyOutputRequest>& copy_request : copy_requests_) { |
| 155 surface_factory_->RequestCopyOfSurface(std::move(copy_request)); | 155 surface_factory_->RequestCopyOfSurface(std::move(copy_request)); |
| 156 } | 156 } |
| 157 copy_requests_.clear(); | 157 copy_requests_.clear(); |
| 158 | 158 |
| 159 if (synchronous) { | 159 if (synchronous) { |
| 160 display_->DrawAndSwap(); | 160 display_->DrawAndSwap(); |
| 161 // Post this to get a new stack frame so that we exit this function before | 161 // Post this to get a new stack frame so that we exit this function before |
| 162 // calling the client to tell it that it is done. | 162 // calling the client to tell it that it is done. |
| 163 task_runner_->PostTask(FROM_HERE, | 163 task_runner_->PostTask(FROM_HERE, |
| 164 base::Bind(&TestCompositorFrameSink::DidDrawCallback, | 164 base::Bind(&TestCompositorFrameSink::DidDrawCallback, |
| 165 weak_ptr_factory_.GetWeakPtr())); | 165 weak_ptr_factory_.GetWeakPtr())); |
| 166 } | 166 } |
| 167 } | 167 } |
| 168 | 168 |
| 169 void TestCompositorFrameSink::DidDrawCallback() { | 169 void TestCompositorFrameSink::DidDrawCallback() { |
| 170 // This is to unthrottle the next frame, not actually a notice that drawing is | 170 // This is to unthrottle the next frame, not actually a notice that drawing is |
| 171 // done. | 171 // done. |
| 172 client_->DidReceiveCompositorFrameAck(); | 172 client_->DidReceiveCompositorFrameAck(); |
| 173 } | 173 } |
| 174 | 174 |
| 175 void TestCompositorFrameSink::ForceReclaimResources() { | 175 void TestCompositorFrameSink::ForceReclaimResources() { |
| 176 if (capabilities_.can_force_reclaim_resources && | 176 if (capabilities_.can_force_reclaim_resources && |
| 177 delegated_local_frame_id_.is_valid()) { | 177 delegated_local_surface_id_.is_valid()) { |
| 178 surface_factory_->ClearSurface(); | 178 surface_factory_->ClearSurface(); |
| 179 } | 179 } |
| 180 } | 180 } |
| 181 | 181 |
| 182 void TestCompositorFrameSink::ReturnResources( | 182 void TestCompositorFrameSink::ReturnResources( |
| 183 const ReturnedResourceArray& resources) { | 183 const ReturnedResourceArray& resources) { |
| 184 client_->ReclaimResources(resources); | 184 client_->ReclaimResources(resources); |
| 185 } | 185 } |
| 186 | 186 |
| 187 void TestCompositorFrameSink::SetBeginFrameSource( | 187 void TestCompositorFrameSink::SetBeginFrameSource( |
| 188 BeginFrameSource* begin_frame_source) { | 188 BeginFrameSource* begin_frame_source) { |
| 189 client_->SetBeginFrameSource(begin_frame_source); | 189 client_->SetBeginFrameSource(begin_frame_source); |
| 190 } | 190 } |
| 191 | 191 |
| 192 void TestCompositorFrameSink::DisplayOutputSurfaceLost() { | 192 void TestCompositorFrameSink::DisplayOutputSurfaceLost() { |
| 193 client_->DidLoseCompositorFrameSink(); | 193 client_->DidLoseCompositorFrameSink(); |
| 194 } | 194 } |
| 195 | 195 |
| 196 void TestCompositorFrameSink::DisplayWillDrawAndSwap( | 196 void TestCompositorFrameSink::DisplayWillDrawAndSwap( |
| 197 bool will_draw_and_swap, | 197 bool will_draw_and_swap, |
| 198 const RenderPassList& render_passes) { | 198 const RenderPassList& render_passes) { |
| 199 test_client_->DisplayWillDrawAndSwap(will_draw_and_swap, render_passes); | 199 test_client_->DisplayWillDrawAndSwap(will_draw_and_swap, render_passes); |
| 200 } | 200 } |
| 201 | 201 |
| 202 void TestCompositorFrameSink::DisplayDidDrawAndSwap() { | 202 void TestCompositorFrameSink::DisplayDidDrawAndSwap() { |
| 203 test_client_->DisplayDidDrawAndSwap(); | 203 test_client_->DisplayDidDrawAndSwap(); |
| 204 } | 204 } |
| 205 | 205 |
| 206 } // namespace cc | 206 } // namespace cc |
| OLD | NEW |