Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Side by Side Diff: cc/test/test_compositor_frame_sink.cc

Issue 2337913003: Fork cc::OutputSurface into cc::CompositorFrameSink. (Closed)
Patch Set: cfsfork: rebase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_delegating_output_surface.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/copy_output_request.h" 12 #include "cc/output/copy_output_request.h"
12 #include "cc/output/direct_renderer.h" 13 #include "cc/output/direct_renderer.h"
14 #include "cc/output/output_surface.h"
13 #include "cc/output/texture_mailbox_deleter.h" 15 #include "cc/output/texture_mailbox_deleter.h"
14 16
15 static constexpr uint32_t kCompositorClientId = 1; 17 static constexpr uint32_t kCompositorClientId = 1;
16 18
17 namespace cc { 19 namespace cc {
18 20
19 TestDelegatingOutputSurface::TestDelegatingOutputSurface( 21 TestCompositorFrameSink::TestCompositorFrameSink(
20 scoped_refptr<ContextProvider> compositor_context_provider, 22 scoped_refptr<ContextProvider> compositor_context_provider,
21 scoped_refptr<ContextProvider> worker_context_provider, 23 scoped_refptr<ContextProvider> worker_context_provider,
22 std::unique_ptr<OutputSurface> display_output_surface, 24 std::unique_ptr<OutputSurface> display_output_surface,
23 SharedBitmapManager* shared_bitmap_manager, 25 SharedBitmapManager* shared_bitmap_manager,
24 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, 26 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
25 const RendererSettings& renderer_settings, 27 const RendererSettings& renderer_settings,
26 base::SingleThreadTaskRunner* task_runner, 28 base::SingleThreadTaskRunner* task_runner,
27 bool synchronous_composite, 29 bool synchronous_composite,
28 bool force_disable_reclaim_resources) 30 bool force_disable_reclaim_resources)
29 : OutputSurface(std::move(compositor_context_provider), 31 : CompositorFrameSink(std::move(compositor_context_provider),
30 std::move(worker_context_provider), 32 std::move(worker_context_provider),
31 nullptr), 33 nullptr),
32 surface_manager_(new SurfaceManager), 34 surface_manager_(new SurfaceManager),
33 surface_id_allocator_(new SurfaceIdAllocator(kCompositorClientId)), 35 surface_id_allocator_(new SurfaceIdAllocator(kCompositorClientId)),
34 surface_factory_(new SurfaceFactory(surface_manager_.get(), this)), 36 surface_factory_(new SurfaceFactory(surface_manager_.get(), this)),
35 weak_ptrs_(this) { 37 weak_ptrs_(this) {
36 std::unique_ptr<SyntheticBeginFrameSource> begin_frame_source; 38 std::unique_ptr<SyntheticBeginFrameSource> begin_frame_source;
37 std::unique_ptr<DisplayScheduler> scheduler; 39 std::unique_ptr<DisplayScheduler> scheduler;
38 if (!synchronous_composite) { 40 if (!synchronous_composite) {
39 if (renderer_settings.disable_display_vsync) { 41 if (renderer_settings.disable_display_vsync) {
40 begin_frame_source.reset(new BackToBackBeginFrameSource( 42 begin_frame_source.reset(new BackToBackBeginFrameSource(
41 base::MakeUnique<DelayBasedTimeSource>(task_runner))); 43 base::MakeUnique<DelayBasedTimeSource>(task_runner)));
(...skipping 10 matching lines...) Expand all
52 } 54 }
53 const bool context_shared_with_compositor = 55 const bool context_shared_with_compositor =
54 display_output_surface->context_provider() == context_provider(); 56 display_output_surface->context_provider() == context_provider();
55 display_.reset( 57 display_.reset(
56 new Display(shared_bitmap_manager, gpu_memory_buffer_manager, 58 new Display(shared_bitmap_manager, gpu_memory_buffer_manager,
57 renderer_settings, std::move(begin_frame_source), 59 renderer_settings, std::move(begin_frame_source),
58 std::move(display_output_surface), std::move(scheduler), 60 std::move(display_output_surface), std::move(scheduler),
59 base::MakeUnique<TextureMailboxDeleter>(task_runner))); 61 base::MakeUnique<TextureMailboxDeleter>(task_runner)));
60 62
61 capabilities_.delegated_rendering = true; 63 capabilities_.delegated_rendering = true;
62 // Since this OutputSurface and the Display are tightly coupled and in the 64 // Since this CompositorFrameSink and the Display are tightly coupled and in
63 // same process/thread, the LayerTreeHostImpl can reclaim resources from 65 // the same process/thread, the LayerTreeHostImpl can reclaim resources from
64 // the Display. But we allow tests to disable this to mimic an out-of-process 66 // the Display. But we allow tests to disable this to mimic an out-of-process
65 // Display. 67 // Display.
66 capabilities_.can_force_reclaim_resources = !force_disable_reclaim_resources; 68 capabilities_.can_force_reclaim_resources = !force_disable_reclaim_resources;
67 capabilities_.delegated_sync_points_required = 69 capabilities_.delegated_sync_points_required =
68 !context_shared_with_compositor; 70 !context_shared_with_compositor;
69 } 71 }
70 72
71 TestDelegatingOutputSurface::~TestDelegatingOutputSurface() { 73 TestCompositorFrameSink::~TestCompositorFrameSink() {
72 DCHECK(copy_requests_.empty()); 74 DCHECK(copy_requests_.empty());
73 } 75 }
74 76
75 void TestDelegatingOutputSurface::RequestCopyOfOutput( 77 void TestCompositorFrameSink::RequestCopyOfOutput(
76 std::unique_ptr<CopyOutputRequest> request) { 78 std::unique_ptr<CopyOutputRequest> request) {
77 copy_requests_.push_back(std::move(request)); 79 copy_requests_.push_back(std::move(request));
78 } 80 }
79 81
80 bool TestDelegatingOutputSurface::BindToClient(OutputSurfaceClient* client) { 82 bool TestCompositorFrameSink::BindToClient(CompositorFrameSinkClient* client) {
81 if (!OutputSurface::BindToClient(client)) 83 if (!CompositorFrameSink::BindToClient(client))
82 return false; 84 return false;
83 85
84 // We want the Display's output surface to hear about lost context, and since 86 // We want the Display's OutputSurface to hear about lost context, and since
85 // this shares a context with it (when delegated_sync_points_required is 87 // this shares a context with it (when delegated_sync_points_required is
86 // false), we should not be listening for lost context callbacks on the 88 // false), we should not be listening for lost context callbacks on the
87 // context here. 89 // context here.
88 if (!capabilities_.delegated_sync_points_required && context_provider()) 90 if (!capabilities_.delegated_sync_points_required && context_provider())
89 context_provider()->SetLostContextCallback(base::Closure()); 91 context_provider()->SetLostContextCallback(base::Closure());
90 92
91 surface_manager_->RegisterSurfaceClientId(surface_id_allocator_->client_id()); 93 surface_manager_->RegisterSurfaceClientId(surface_id_allocator_->client_id());
92 surface_manager_->RegisterSurfaceFactoryClient( 94 surface_manager_->RegisterSurfaceFactoryClient(
93 surface_id_allocator_->client_id(), this); 95 surface_id_allocator_->client_id(), this);
94 display_->Initialize(this, surface_manager_.get(), 96 display_->Initialize(this, surface_manager_.get(),
95 surface_id_allocator_->client_id()); 97 surface_id_allocator_->client_id());
96 display_->renderer_for_testing()->SetEnlargePassTextureAmountForTesting( 98 display_->renderer_for_testing()->SetEnlargePassTextureAmountForTesting(
97 enlarge_pass_texture_amount_); 99 enlarge_pass_texture_amount_);
98 display_->SetVisible(true); 100 display_->SetVisible(true);
99 bound_ = true; 101 bound_ = true;
100 return true; 102 return true;
101 } 103 }
102 104
103 void TestDelegatingOutputSurface::DetachFromClient() { 105 void TestCompositorFrameSink::DetachFromClient() {
104 // Some tests make BindToClient fail on purpose. ^__^ 106 // Some tests make BindToClient fail on purpose. ^__^
105 if (bound_) { 107 if (bound_) {
106 if (!delegated_surface_id_.is_null()) 108 if (!delegated_surface_id_.is_null())
107 surface_factory_->Destroy(delegated_surface_id_); 109 surface_factory_->Destroy(delegated_surface_id_);
108 surface_manager_->UnregisterSurfaceFactoryClient( 110 surface_manager_->UnregisterSurfaceFactoryClient(
109 surface_id_allocator_->client_id()); 111 surface_id_allocator_->client_id());
110 surface_manager_->InvalidateSurfaceClientId( 112 surface_manager_->InvalidateSurfaceClientId(
111 surface_id_allocator_->client_id()); 113 surface_id_allocator_->client_id());
112 bound_ = false; 114 bound_ = false;
113 } 115 }
114 display_ = nullptr; 116 display_ = nullptr;
115 surface_factory_ = nullptr; 117 surface_factory_ = nullptr;
116 surface_id_allocator_ = nullptr; 118 surface_id_allocator_ = nullptr;
117 surface_manager_ = nullptr; 119 surface_manager_ = nullptr;
118 weak_ptrs_.InvalidateWeakPtrs(); 120 weak_ptrs_.InvalidateWeakPtrs();
119 OutputSurface::DetachFromClient(); 121 CompositorFrameSink::DetachFromClient();
120 } 122 }
121 123
122 void TestDelegatingOutputSurface::SwapBuffers(CompositorFrame frame) { 124 void TestCompositorFrameSink::SwapBuffers(CompositorFrame frame) {
123 if (test_client_) 125 if (test_client_)
124 test_client_->DisplayReceivedCompositorFrame(frame); 126 test_client_->DisplayReceivedCompositorFrame(frame);
125 127
126 if (delegated_surface_id_.is_null()) { 128 if (delegated_surface_id_.is_null()) {
127 delegated_surface_id_ = surface_id_allocator_->GenerateId(); 129 delegated_surface_id_ = surface_id_allocator_->GenerateId();
128 surface_factory_->Create(delegated_surface_id_); 130 surface_factory_->Create(delegated_surface_id_);
129 } 131 }
130 display_->SetSurfaceId(delegated_surface_id_, 132 display_->SetSurfaceId(delegated_surface_id_,
131 frame.metadata.device_scale_factor); 133 frame.metadata.device_scale_factor);
132 134
133 gfx::Size frame_size = 135 gfx::Size frame_size =
134 frame.delegated_frame_data->render_pass_list.back()->output_rect.size(); 136 frame.delegated_frame_data->render_pass_list.back()->output_rect.size();
135 display_->Resize(frame_size); 137 display_->Resize(frame_size);
136 138
137 bool synchronous = !display_->has_scheduler(); 139 bool synchronous = !display_->has_scheduler();
138 140
139 surface_factory_->SubmitCompositorFrame( 141 surface_factory_->SubmitCompositorFrame(
140 delegated_surface_id_, std::move(frame), 142 delegated_surface_id_, std::move(frame),
141 base::Bind(&TestDelegatingOutputSurface::DidDrawCallback, 143 base::Bind(&TestCompositorFrameSink::DidDrawCallback,
142 weak_ptrs_.GetWeakPtr(), synchronous)); 144 weak_ptrs_.GetWeakPtr(), synchronous));
143 145
144 for (std::unique_ptr<CopyOutputRequest>& copy_request : copy_requests_) 146 for (std::unique_ptr<CopyOutputRequest>& copy_request : copy_requests_)
145 surface_factory_->RequestCopyOfSurface(delegated_surface_id_, 147 surface_factory_->RequestCopyOfSurface(delegated_surface_id_,
146 std::move(copy_request)); 148 std::move(copy_request));
147 copy_requests_.clear(); 149 copy_requests_.clear();
148 150
149 if (synchronous) 151 if (synchronous)
150 display_->DrawAndSwap(); 152 display_->DrawAndSwap();
151 } 153 }
152 154
153 void TestDelegatingOutputSurface::DidDrawCallback(bool synchronous) { 155 void TestCompositorFrameSink::DidDrawCallback(bool synchronous) {
154 // This is the frame ack to unthrottle the next frame, not actually a notice 156 // This is the frame ack to unthrottle the next frame, not actually a notice
155 // that drawing is done. 157 // that drawing is done.
156 if (synchronous) { 158 if (synchronous) {
157 // For synchronous draws, this must be posted to a new stack because we are 159 // For synchronous draws, this must be posted to a new stack because we are
158 // still the original call to SwapBuffers, and we want to leave that before 160 // still the original call to SwapBuffers, and we want to leave that before
159 // saying that it is done. 161 // saying that it is done.
160 OutputSurface::PostSwapBuffersComplete(); 162 CompositorFrameSink::PostSwapBuffersComplete();
161 } else { 163 } else {
162 client_->DidSwapBuffersComplete(); 164 client_->DidSwapBuffersComplete();
163 } 165 }
164 } 166 }
165 167
166 void TestDelegatingOutputSurface::ForceReclaimResources() { 168 void TestCompositorFrameSink::ForceReclaimResources() {
167 if (capabilities_.can_force_reclaim_resources && 169 if (capabilities_.can_force_reclaim_resources &&
168 !delegated_surface_id_.is_null()) { 170 !delegated_surface_id_.is_null()) {
169 surface_factory_->SubmitCompositorFrame(delegated_surface_id_, 171 surface_factory_->SubmitCompositorFrame(delegated_surface_id_,
170 CompositorFrame(), 172 CompositorFrame(),
171 SurfaceFactory::DrawCallback()); 173 SurfaceFactory::DrawCallback());
172 } 174 }
173 } 175 }
174 176
175 void TestDelegatingOutputSurface::BindFramebuffer() { 177 void TestCompositorFrameSink::BindFramebuffer() {
176 // This is a delegating output surface, no framebuffer/direct drawing support. 178 // This is a delegating output surface, no framebuffer/direct drawing support.
177 NOTREACHED(); 179 NOTREACHED();
178 } 180 }
179 181
180 uint32_t TestDelegatingOutputSurface::GetFramebufferCopyTextureFormat() { 182 uint32_t TestCompositorFrameSink::GetFramebufferCopyTextureFormat() {
181 // This is a delegating output surface, no framebuffer/direct drawing support. 183 // This is a delegating output surface, no framebuffer/direct drawing support.
182 NOTREACHED(); 184 NOTREACHED();
183 return 0; 185 return 0;
184 } 186 }
185 187
186 void TestDelegatingOutputSurface::ReturnResources( 188 void TestCompositorFrameSink::ReturnResources(
187 const ReturnedResourceArray& resources) { 189 const ReturnedResourceArray& resources) {
188 client_->ReclaimResources(resources); 190 client_->ReclaimResources(resources);
189 } 191 }
190 192
191 void TestDelegatingOutputSurface::SetBeginFrameSource( 193 void TestCompositorFrameSink::SetBeginFrameSource(
192 BeginFrameSource* begin_frame_source) { 194 BeginFrameSource* begin_frame_source) {
193 client_->SetBeginFrameSource(begin_frame_source); 195 client_->SetBeginFrameSource(begin_frame_source);
194 } 196 }
195 197
196 void TestDelegatingOutputSurface::DisplayOutputSurfaceLost() { 198 void TestCompositorFrameSink::DisplayOutputSurfaceLost() {
197 client_->DidLoseOutputSurface(); 199 client_->DidLoseCompositorFrameSink();
198 } 200 }
199 201
200 void TestDelegatingOutputSurface::DisplayWillDrawAndSwap( 202 void TestCompositorFrameSink::DisplayWillDrawAndSwap(
201 bool will_draw_and_swap, 203 bool will_draw_and_swap,
202 const RenderPassList& render_passes) { 204 const RenderPassList& render_passes) {
203 if (test_client_) 205 if (test_client_)
204 test_client_->DisplayWillDrawAndSwap(will_draw_and_swap, render_passes); 206 test_client_->DisplayWillDrawAndSwap(will_draw_and_swap, render_passes);
205 } 207 }
206 208
207 void TestDelegatingOutputSurface::DisplayDidDrawAndSwap() { 209 void TestCompositorFrameSink::DisplayDidDrawAndSwap() {
208 if (test_client_) 210 if (test_client_)
209 test_client_->DisplayDidDrawAndSwap(); 211 test_client_->DisplayDidDrawAndSwap();
210 } 212 }
211 213
212 } // namespace cc 214 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698