| 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" |
| 11 #include "cc/output/begin_frame_args.h" | 11 #include "cc/output/begin_frame_args.h" |
| 12 #include "cc/output/compositor_frame_sink_client.h" | 12 #include "cc/output/compositor_frame_sink_client.h" |
| 13 #include "cc/output/copy_output_request.h" | 13 #include "cc/output/copy_output_request.h" |
| 14 #include "cc/output/direct_renderer.h" | 14 #include "cc/output/direct_renderer.h" |
| 15 #include "cc/output/output_surface.h" | 15 #include "cc/output/output_surface.h" |
| 16 #include "cc/output/texture_mailbox_deleter.h" | 16 #include "cc/output/texture_mailbox_deleter.h" |
| 17 #include "cc/surfaces/compositor_frame_sink_support.h" | 17 #include "cc/surfaces/compositor_frame_sink_support.h" |
| 18 | 18 |
| 19 namespace cc { | 19 namespace cc { |
| 20 | 20 |
| 21 static constexpr FrameSinkId kCompositorFrameSinkId(1, 1); | 21 static constexpr FrameSinkId kCompositorFrameSinkId(1, 1); |
| 22 | 22 |
| 23 TestCompositorFrameSink::TestCompositorFrameSink( | 23 TestCompositorFrameSink::TestCompositorFrameSink( |
| 24 scoped_refptr<ContextProvider> compositor_context_provider, | 24 scoped_refptr<ContextProvider> compositor_context_provider, |
| 25 scoped_refptr<ContextProvider> worker_context_provider, | 25 scoped_refptr<ContextProvider> worker_context_provider, |
| 26 SharedBitmapManager* shared_bitmap_manager, | 26 SharedBitmapManager* shared_bitmap_manager, |
| 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 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 29 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 30 bool synchronous_composite, | 30 bool synchronous_composite) |
| 31 bool force_disable_reclaim_resources) | |
| 32 : CompositorFrameSink(std::move(compositor_context_provider), | 31 : CompositorFrameSink(std::move(compositor_context_provider), |
| 33 std::move(worker_context_provider), | 32 std::move(worker_context_provider), |
| 34 gpu_memory_buffer_manager, | 33 gpu_memory_buffer_manager, |
| 35 shared_bitmap_manager), | 34 shared_bitmap_manager), |
| 36 synchronous_composite_(synchronous_composite), | 35 synchronous_composite_(synchronous_composite), |
| 37 renderer_settings_(renderer_settings), | 36 renderer_settings_(renderer_settings), |
| 38 task_runner_(std::move(task_runner)), | 37 task_runner_(std::move(task_runner)), |
| 39 frame_sink_id_(kCompositorFrameSinkId), | 38 frame_sink_id_(kCompositorFrameSinkId), |
| 40 surface_manager_(new SurfaceManager), | 39 surface_manager_(new SurfaceManager), |
| 41 local_surface_id_allocator_(new LocalSurfaceIdAllocator()), | 40 local_surface_id_allocator_(new LocalSurfaceIdAllocator()), |
| 42 external_begin_frame_source_(this), | 41 external_begin_frame_source_(this), |
| 43 weak_ptr_factory_(this) { | 42 weak_ptr_factory_(this) { |
| 44 // Since this CompositorFrameSink and the Display are tightly coupled and in | |
| 45 // the same process/thread, the LayerTreeHostImpl can reclaim resources from | |
| 46 // the Display. But we allow tests to disable this to mimic an out-of-process | |
| 47 // Display. | |
| 48 capabilities_.can_force_reclaim_resources = !force_disable_reclaim_resources; | |
| 49 // Always use sync tokens so that code paths in resource provider that deal | 43 // Always use sync tokens so that code paths in resource provider that deal |
| 50 // with sync tokens are tested. | 44 // with sync tokens are tested. |
| 51 capabilities_.delegated_sync_points_required = true; | 45 capabilities_.delegated_sync_points_required = true; |
| 52 } | 46 } |
| 53 | 47 |
| 54 TestCompositorFrameSink::~TestCompositorFrameSink() { | 48 TestCompositorFrameSink::~TestCompositorFrameSink() { |
| 55 DCHECK(copy_requests_.empty()); | 49 DCHECK(copy_requests_.empty()); |
| 56 } | 50 } |
| 57 | 51 |
| 58 void TestCompositorFrameSink::RequestCopyOfOutput( | 52 void TestCompositorFrameSink::RequestCopyOfOutput( |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 display_->DrawAndSwap(); | 147 display_->DrawAndSwap(); |
| 154 // Post this to get a new stack frame so that we exit this function before | 148 // Post this to get a new stack frame so that we exit this function before |
| 155 // calling the client to tell it that it is done. | 149 // calling the client to tell it that it is done. |
| 156 task_runner_->PostTask( | 150 task_runner_->PostTask( |
| 157 FROM_HERE, | 151 FROM_HERE, |
| 158 base::BindOnce(&TestCompositorFrameSink::SendCompositorFrameAckToClient, | 152 base::BindOnce(&TestCompositorFrameSink::SendCompositorFrameAckToClient, |
| 159 weak_ptr_factory_.GetWeakPtr())); | 153 weak_ptr_factory_.GetWeakPtr())); |
| 160 } | 154 } |
| 161 } | 155 } |
| 162 | 156 |
| 163 void TestCompositorFrameSink::ForceReclaimResources() { | |
| 164 if (capabilities_.can_force_reclaim_resources && | |
| 165 delegated_local_surface_id_.is_valid()) { | |
| 166 support_->ForceReclaimResources(); | |
| 167 } | |
| 168 } | |
| 169 | |
| 170 void TestCompositorFrameSink::DidReceiveCompositorFrameAck( | 157 void TestCompositorFrameSink::DidReceiveCompositorFrameAck( |
| 171 const ReturnedResourceArray& resources) { | 158 const ReturnedResourceArray& resources) { |
| 172 ReclaimResources(resources); | 159 ReclaimResources(resources); |
| 173 // In synchronous mode, we manually send acks and this method should not be | 160 // In synchronous mode, we manually send acks and this method should not be |
| 174 // used. | 161 // used. |
| 175 if (!display_->has_scheduler()) | 162 if (!display_->has_scheduler()) |
| 176 return; | 163 return; |
| 177 client_->DidReceiveCompositorFrameAck(); | 164 client_->DidReceiveCompositorFrameAck(); |
| 178 } | 165 } |
| 179 | 166 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 208 support_->SetNeedsBeginFrame(needs_begin_frames); | 195 support_->SetNeedsBeginFrame(needs_begin_frames); |
| 209 } | 196 } |
| 210 | 197 |
| 211 void TestCompositorFrameSink::OnDidFinishFrame(const BeginFrameAck& ack) {} | 198 void TestCompositorFrameSink::OnDidFinishFrame(const BeginFrameAck& ack) {} |
| 212 | 199 |
| 213 void TestCompositorFrameSink::SendCompositorFrameAckToClient() { | 200 void TestCompositorFrameSink::SendCompositorFrameAckToClient() { |
| 214 client_->DidReceiveCompositorFrameAck(); | 201 client_->DidReceiveCompositorFrameAck(); |
| 215 } | 202 } |
| 216 | 203 |
| 217 } // namespace cc | 204 } // namespace cc |
| OLD | NEW |