OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "cc/test/pixel_test_delegating_output_surface.h" | |
6 | |
7 #include <stdint.h> | |
8 #include <memory> | |
9 #include <utility> | |
10 | |
11 #include "base/memory/ptr_util.h" | |
12 #include "base/threading/thread_task_runner_handle.h" | |
13 #include "cc/output/begin_frame_args.h" | |
14 #include "cc/output/compositor_frame_ack.h" | |
15 #include "cc/output/direct_renderer.h" | |
16 #include "cc/output/texture_mailbox_deleter.h" | |
17 #include "cc/scheduler/begin_frame_source.h" | |
18 #include "cc/scheduler/delay_based_time_source.h" | |
19 #include "cc/test/begin_frame_args_test.h" | |
20 #include "cc/test/pixel_test_output_surface.h" | |
21 #include "cc/test/pixel_test_software_output_device.h" | |
22 #include "cc/test/test_in_process_context_provider.h" | |
23 | |
24 static constexpr uint32_t kCompositorClientId = 1; | |
25 | |
26 namespace cc { | |
27 | |
28 PixelTestDelegatingOutputSurface::PixelTestDelegatingOutputSurface( | |
29 scoped_refptr<ContextProvider> compositor_context_provider, | |
30 scoped_refptr<ContextProvider> worker_context_provider, | |
31 scoped_refptr<ContextProvider> display_context_provider, | |
32 const RendererSettings& renderer_settings, | |
33 SharedBitmapManager* shared_bitmap_manager, | |
34 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | |
35 const gfx::Size& surface_expansion_size, | |
36 bool allow_force_reclaim_resources, | |
37 bool synchronous_composite) | |
38 : OutputSurface(std::move(compositor_context_provider), | |
39 std::move(worker_context_provider), | |
40 nullptr), | |
41 shared_bitmap_manager_(shared_bitmap_manager), | |
42 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), | |
43 surface_expansion_size_(surface_expansion_size), | |
44 allow_force_reclaim_resources_(allow_force_reclaim_resources), | |
45 synchronous_composite_(synchronous_composite), | |
46 renderer_settings_(renderer_settings), | |
47 display_context_provider_(std::move(display_context_provider)), | |
48 surface_manager_(new SurfaceManager), | |
49 surface_id_allocator_(new SurfaceIdAllocator(kCompositorClientId)), | |
50 surface_factory_(new SurfaceFactory(surface_manager_.get(), this)), | |
51 weak_ptrs_(this) { | |
52 capabilities_.delegated_rendering = true; | |
53 capabilities_.can_force_reclaim_resources = allow_force_reclaim_resources_; | |
54 | |
55 surface_id_allocator_->RegisterSurfaceClientId(surface_manager_.get()); | |
56 } | |
57 | |
58 PixelTestDelegatingOutputSurface::~PixelTestDelegatingOutputSurface() {} | |
59 | |
60 bool PixelTestDelegatingOutputSurface::BindToClient( | |
61 OutputSurfaceClient* client) { | |
62 if (!OutputSurface::BindToClient(client)) | |
63 return false; | |
64 | |
65 surface_manager_->RegisterSurfaceFactoryClient( | |
66 surface_id_allocator_->client_id(), this); | |
67 | |
68 // The PixelTestOutputSurface is owned by the Display. | |
69 std::unique_ptr<PixelTestOutputSurface> output_surface; | |
70 | |
71 if (!context_provider()) { | |
72 std::unique_ptr<PixelTestSoftwareOutputDevice> software_output_device( | |
73 new PixelTestSoftwareOutputDevice); | |
74 software_output_device->set_surface_expansion_size(surface_expansion_size_); | |
75 output_surface = base::MakeUnique<PixelTestOutputSurface>( | |
76 std::move(software_output_device)); | |
77 } else { | |
78 bool flipped_output_surface = false; | |
79 output_surface = base::MakeUnique<PixelTestOutputSurface>( | |
80 std::move(display_context_provider_), nullptr, flipped_output_surface); | |
81 } | |
82 output_surface->set_surface_expansion_size(surface_expansion_size_); | |
83 | |
84 auto* task_runner = base::ThreadTaskRunnerHandle::Get().get(); | |
85 CHECK(task_runner); | |
86 | |
87 std::unique_ptr<SyntheticBeginFrameSource> begin_frame_source; | |
88 std::unique_ptr<DisplayScheduler> scheduler; | |
89 if (!synchronous_composite_) { | |
90 begin_frame_source.reset(new DelayBasedBeginFrameSource( | |
91 base::MakeUnique<DelayBasedTimeSource>(task_runner))); | |
92 scheduler.reset(new DisplayScheduler( | |
93 begin_frame_source.get(), task_runner, | |
94 output_surface->capabilities().max_frames_pending)); | |
95 } | |
96 | |
97 display_.reset(new Display( | |
98 surface_manager_.get(), shared_bitmap_manager_, | |
99 gpu_memory_buffer_manager_, renderer_settings_, | |
100 surface_id_allocator_->client_id(), std::move(begin_frame_source), | |
101 std::move(output_surface), std::move(scheduler), | |
102 base::MakeUnique<TextureMailboxDeleter>(task_runner))); | |
103 display_->SetEnlargePassTextureAmountForTesting(enlarge_pass_texture_amount_); | |
104 | |
105 display_->Initialize(&display_client_); | |
106 return true; | |
107 } | |
108 | |
109 void PixelTestDelegatingOutputSurface::DetachFromClient() { | |
110 if (!delegated_surface_id_.is_null()) | |
111 surface_factory_->Destroy(delegated_surface_id_); | |
112 surface_manager_->UnregisterSurfaceFactoryClient( | |
113 surface_id_allocator_->client_id()); | |
114 | |
115 display_ = nullptr; | |
116 surface_factory_ = nullptr; | |
117 surface_id_allocator_ = nullptr; | |
118 surface_manager_ = nullptr; | |
119 weak_ptrs_.InvalidateWeakPtrs(); | |
120 OutputSurface::DetachFromClient(); | |
121 } | |
122 | |
123 void PixelTestDelegatingOutputSurface::SwapBuffers(CompositorFrame frame) { | |
124 if (delegated_surface_id_.is_null()) { | |
125 delegated_surface_id_ = surface_id_allocator_->GenerateId(); | |
126 surface_factory_->Create(delegated_surface_id_); | |
127 } | |
128 display_->SetSurfaceId(delegated_surface_id_, | |
129 frame.metadata.device_scale_factor); | |
130 | |
131 gfx::Size frame_size = | |
132 frame.delegated_frame_data->render_pass_list.back()->output_rect.size(); | |
133 display_->Resize(frame_size); | |
134 | |
135 surface_factory_->SubmitCompositorFrame( | |
136 delegated_surface_id_, std::move(frame), | |
137 base::Bind(&PixelTestDelegatingOutputSurface::DrawCallback, | |
138 weak_ptrs_.GetWeakPtr())); | |
139 | |
140 if (synchronous_composite_) | |
141 display_->DrawAndSwap(); | |
142 } | |
143 | |
144 void PixelTestDelegatingOutputSurface::SetEnlargePassTextureAmount( | |
145 const gfx::Size& amount) { | |
146 DCHECK(!HasClient()); | |
147 enlarge_pass_texture_amount_ = amount; | |
148 } | |
149 | |
150 void PixelTestDelegatingOutputSurface::DrawCallback(SurfaceDrawStatus) { | |
151 client_->DidSwapBuffersComplete(); | |
152 } | |
153 | |
154 void PixelTestDelegatingOutputSurface::ForceReclaimResources() { | |
155 if (allow_force_reclaim_resources_ && !delegated_surface_id_.is_null()) { | |
156 surface_factory_->SubmitCompositorFrame(delegated_surface_id_, | |
157 CompositorFrame(), | |
158 SurfaceFactory::DrawCallback()); | |
159 } | |
160 } | |
161 | |
162 void PixelTestDelegatingOutputSurface::BindFramebuffer() { | |
163 // This is a delegating output surface, no framebuffer/direct drawing support. | |
164 NOTREACHED(); | |
165 } | |
166 | |
167 uint32_t PixelTestDelegatingOutputSurface::GetFramebufferCopyTextureFormat() { | |
168 // This is a delegating output surface, no framebuffer/direct drawing support. | |
169 NOTREACHED(); | |
170 return 0; | |
171 } | |
172 | |
173 void PixelTestDelegatingOutputSurface::ReturnResources( | |
174 const ReturnedResourceArray& resources) { | |
175 CompositorFrameAck ack; | |
176 ack.resources = resources; | |
177 client_->ReclaimResources(&ack); | |
178 } | |
179 | |
180 void PixelTestDelegatingOutputSurface::SetBeginFrameSource( | |
181 BeginFrameSource* begin_frame_source) { | |
182 client_->SetBeginFrameSource(begin_frame_source); | |
183 } | |
184 | |
185 } // namespace cc | |
OLD | NEW |