| 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 | 17 |
| 18 namespace cc { | 18 namespace cc { |
| 19 | 19 |
| 20 static constexpr FrameSinkId kCompositorFrameSinkId(1, 1); | 20 static constexpr FrameSinkId kCompositorFrameSinkId(1, 1); |
| 21 | 21 |
| 22 TestCompositorFrameSink::TestCompositorFrameSink( | 22 TestCompositorFrameSink::TestCompositorFrameSink( |
| 23 scoped_refptr<ContextProvider> compositor_context_provider, | 23 scoped_refptr<ContextProvider> compositor_context_provider, |
| 24 scoped_refptr<ContextProvider> worker_context_provider, | 24 scoped_refptr<ContextProvider> worker_context_provider, |
| 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 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 28 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 29 bool synchronous_composite) | 29 bool synchronous_composite, |
| 30 bool force_disable_reclaim_resources) |
| 30 : CompositorFrameSink(std::move(compositor_context_provider), | 31 : CompositorFrameSink(std::move(compositor_context_provider), |
| 31 std::move(worker_context_provider), | 32 std::move(worker_context_provider), |
| 32 gpu_memory_buffer_manager, | 33 gpu_memory_buffer_manager, |
| 33 shared_bitmap_manager), | 34 shared_bitmap_manager), |
| 34 synchronous_composite_(synchronous_composite), | 35 synchronous_composite_(synchronous_composite), |
| 35 renderer_settings_(renderer_settings), | 36 renderer_settings_(renderer_settings), |
| 36 task_runner_(std::move(task_runner)), | 37 task_runner_(std::move(task_runner)), |
| 37 frame_sink_id_(kCompositorFrameSinkId), | 38 frame_sink_id_(kCompositorFrameSinkId), |
| 38 surface_manager_(new SurfaceManager), | 39 surface_manager_(new SurfaceManager), |
| 39 surface_id_allocator_(new SurfaceIdAllocator()), | 40 surface_id_allocator_(new SurfaceIdAllocator()), |
| 40 surface_factory_( | 41 surface_factory_( |
| 41 new SurfaceFactory(frame_sink_id_, surface_manager_.get(), this)), | 42 new SurfaceFactory(frame_sink_id_, surface_manager_.get(), this)), |
| 42 weak_ptr_factory_(this) { | 43 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; |
| 43 // Always use sync tokens so that code paths in resource provider that deal | 49 // Always use sync tokens so that code paths in resource provider that deal |
| 44 // with sync tokens are tested. | 50 // with sync tokens are tested. |
| 45 capabilities_.delegated_sync_points_required = true; | 51 capabilities_.delegated_sync_points_required = true; |
| 46 } | 52 } |
| 47 | 53 |
| 48 TestCompositorFrameSink::~TestCompositorFrameSink() { | 54 TestCompositorFrameSink::~TestCompositorFrameSink() { |
| 49 DCHECK(copy_requests_.empty()); | 55 DCHECK(copy_requests_.empty()); |
| 50 } | 56 } |
| 51 | 57 |
| 52 void TestCompositorFrameSink::RequestCopyOfOutput( | 58 void TestCompositorFrameSink::RequestCopyOfOutput( |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 weak_ptr_factory_.GetWeakPtr())); | 165 weak_ptr_factory_.GetWeakPtr())); |
| 160 } | 166 } |
| 161 } | 167 } |
| 162 | 168 |
| 163 void TestCompositorFrameSink::DidDrawCallback() { | 169 void TestCompositorFrameSink::DidDrawCallback() { |
| 164 // 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 |
| 165 // done. | 171 // done. |
| 166 client_->DidReceiveCompositorFrameAck(); | 172 client_->DidReceiveCompositorFrameAck(); |
| 167 } | 173 } |
| 168 | 174 |
| 175 void TestCompositorFrameSink::ForceReclaimResources() { |
| 176 if (capabilities_.can_force_reclaim_resources && |
| 177 delegated_local_frame_id_.is_valid()) { |
| 178 surface_factory_->ClearSurface(); |
| 179 } |
| 180 } |
| 181 |
| 169 void TestCompositorFrameSink::ReturnResources( | 182 void TestCompositorFrameSink::ReturnResources( |
| 170 const ReturnedResourceArray& resources) { | 183 const ReturnedResourceArray& resources) { |
| 171 client_->ReclaimResources(resources); | 184 client_->ReclaimResources(resources); |
| 172 } | 185 } |
| 173 | 186 |
| 174 void TestCompositorFrameSink::SetBeginFrameSource( | 187 void TestCompositorFrameSink::SetBeginFrameSource( |
| 175 BeginFrameSource* begin_frame_source) { | 188 BeginFrameSource* begin_frame_source) { |
| 176 client_->SetBeginFrameSource(begin_frame_source); | 189 client_->SetBeginFrameSource(begin_frame_source); |
| 177 } | 190 } |
| 178 | 191 |
| 179 void TestCompositorFrameSink::DisplayOutputSurfaceLost() { | 192 void TestCompositorFrameSink::DisplayOutputSurfaceLost() { |
| 180 client_->DidLoseCompositorFrameSink(); | 193 client_->DidLoseCompositorFrameSink(); |
| 181 } | 194 } |
| 182 | 195 |
| 183 void TestCompositorFrameSink::DisplayWillDrawAndSwap( | 196 void TestCompositorFrameSink::DisplayWillDrawAndSwap( |
| 184 bool will_draw_and_swap, | 197 bool will_draw_and_swap, |
| 185 const RenderPassList& render_passes) { | 198 const RenderPassList& render_passes) { |
| 186 test_client_->DisplayWillDrawAndSwap(will_draw_and_swap, render_passes); | 199 test_client_->DisplayWillDrawAndSwap(will_draw_and_swap, render_passes); |
| 187 } | 200 } |
| 188 | 201 |
| 189 void TestCompositorFrameSink::DisplayDidDrawAndSwap() { | 202 void TestCompositorFrameSink::DisplayDidDrawAndSwap() { |
| 190 test_client_->DisplayDidDrawAndSwap(); | 203 test_client_->DisplayDidDrawAndSwap(); |
| 191 } | 204 } |
| 192 | 205 |
| 193 } // namespace cc | 206 } // namespace cc |
| OLD | NEW |