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

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

Issue 2726293002: Revert of TestCompositorFrameSink should use CompositorFrameSinkSupport (Closed)
Patch Set: Created 3 years, 9 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
« no previous file with comments | « cc/test/test_compositor_frame_sink.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_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"
18 17
19 namespace cc { 18 namespace cc {
20 19
21 static constexpr FrameSinkId kCompositorFrameSinkId(1, 1); 20 static constexpr FrameSinkId kCompositorFrameSinkId(1, 1);
22 21
23 TestCompositorFrameSink::TestCompositorFrameSink( 22 TestCompositorFrameSink::TestCompositorFrameSink(
24 scoped_refptr<ContextProvider> compositor_context_provider, 23 scoped_refptr<ContextProvider> compositor_context_provider,
25 scoped_refptr<ContextProvider> worker_context_provider, 24 scoped_refptr<ContextProvider> worker_context_provider,
26 SharedBitmapManager* shared_bitmap_manager, 25 SharedBitmapManager* shared_bitmap_manager,
27 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, 26 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
28 const RendererSettings& renderer_settings, 27 const RendererSettings& renderer_settings,
29 scoped_refptr<base::SingleThreadTaskRunner> task_runner, 28 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
30 bool synchronous_composite, 29 bool synchronous_composite,
31 bool force_disable_reclaim_resources) 30 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 surface_factory_(
42 new SurfaceFactory(frame_sink_id_, surface_manager_.get(), this)),
43 weak_ptr_factory_(this) { 43 weak_ptr_factory_(this) {
44 // Since this CompositorFrameSink and the Display are tightly coupled and in 44 // Since this CompositorFrameSink and the Display are tightly coupled and in
45 // the same process/thread, the LayerTreeHostImpl can reclaim resources from 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 46 // the Display. But we allow tests to disable this to mimic an out-of-process
47 // Display. 47 // Display.
48 capabilities_.can_force_reclaim_resources = !force_disable_reclaim_resources; 48 capabilities_.can_force_reclaim_resources = !force_disable_reclaim_resources;
49 // 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
50 // with sync tokens are tested. 50 // with sync tokens are tested.
51 capabilities_.delegated_sync_points_required = true; 51 capabilities_.delegated_sync_points_required = true;
52 } 52 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 renderer_settings_, frame_sink_id_, begin_frame_source_.get(), 91 renderer_settings_, frame_sink_id_, begin_frame_source_.get(),
92 std::move(display_output_surface), std::move(scheduler), 92 std::move(display_output_surface), std::move(scheduler),
93 base::MakeUnique<TextureMailboxDeleter>(task_runner_.get()))); 93 base::MakeUnique<TextureMailboxDeleter>(task_runner_.get())));
94 94
95 // We want the Display's OutputSurface to hear about lost context, and when 95 // We want the Display's OutputSurface to hear about lost context, and when
96 // this shares a context with it we should not be listening for lost context 96 // this shares a context with it we should not be listening for lost context
97 // callbacks on the context here. 97 // callbacks on the context here.
98 if (display_context_shared_with_compositor && context_provider()) 98 if (display_context_shared_with_compositor && context_provider())
99 context_provider()->SetLostContextCallback(base::Closure()); 99 context_provider()->SetLostContextCallback(base::Closure());
100 100
101 support_ = base::MakeUnique<CompositorFrameSinkSupport>( 101 surface_manager_->RegisterFrameSinkId(frame_sink_id_);
102 this, surface_manager_.get(), frame_sink_id_, false /* is_root */, 102 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this);
103 true /* handles_frame_sink_id_invalidation */,
104 true /* needs_sync_points */);
105 client_->SetBeginFrameSource(&external_begin_frame_source_);
106
107 display_->Initialize(this, surface_manager_.get()); 103 display_->Initialize(this, surface_manager_.get());
108 display_->renderer_for_testing()->SetEnlargePassTextureAmountForTesting( 104 display_->renderer_for_testing()->SetEnlargePassTextureAmountForTesting(
109 enlarge_pass_texture_amount_); 105 enlarge_pass_texture_amount_);
110 display_->SetVisible(true); 106 display_->SetVisible(true);
107 bound_ = true;
111 return true; 108 return true;
112 } 109 }
113 110
114 void TestCompositorFrameSink::DetachFromClient() { 111 void TestCompositorFrameSink::DetachFromClient() {
115 client_->SetBeginFrameSource(nullptr); 112 // Some tests make BindToClient fail on purpose. ^__^
116 support_ = nullptr; 113 if (bound_) {
117 display_ = nullptr; 114 surface_factory_->EvictSurface();
115 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_);
116 surface_manager_->InvalidateFrameSinkId(frame_sink_id_);
117 display_ = nullptr;
118 bound_ = false;
119 }
120 surface_factory_ = nullptr;
118 local_surface_id_allocator_ = nullptr; 121 local_surface_id_allocator_ = nullptr;
119 surface_manager_ = nullptr; 122 surface_manager_ = nullptr;
120 test_client_ = nullptr; 123 test_client_ = nullptr;
121 CompositorFrameSink::DetachFromClient(); 124 CompositorFrameSink::DetachFromClient();
122 } 125 }
123 126
124 void TestCompositorFrameSink::SubmitCompositorFrame(CompositorFrame frame) { 127 void TestCompositorFrameSink::SubmitCompositorFrame(CompositorFrame frame) {
125 test_client_->DisplayReceivedCompositorFrame(frame); 128 test_client_->DisplayReceivedCompositorFrame(frame);
126 129
127 if (!delegated_local_surface_id_.is_valid()) { 130 if (!delegated_local_surface_id_.is_valid()) {
128 delegated_local_surface_id_ = local_surface_id_allocator_->GenerateId(); 131 delegated_local_surface_id_ = local_surface_id_allocator_->GenerateId();
129 } 132 }
130 display_->SetLocalSurfaceId(delegated_local_surface_id_, 133 display_->SetLocalSurfaceId(delegated_local_surface_id_,
131 frame.metadata.device_scale_factor); 134 frame.metadata.device_scale_factor);
132 135
133 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();
134 display_->Resize(frame_size); 137 display_->Resize(frame_size);
135 138
136 support_->SubmitCompositorFrame(delegated_local_surface_id_, 139 bool synchronous = !display_->has_scheduler();
137 std::move(frame)); 140
141 SurfaceFactory::DrawCallback draw_callback;
142 if (!synchronous) {
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
145 // will be run when |surface_factory_| is destroyed which is owned by this
146 // class.
147 draw_callback = base::Bind(&TestCompositorFrameSink::DidDrawCallback,
148 base::Unretained(this));
149 }
150
151 surface_factory_->SubmitCompositorFrame(delegated_local_surface_id_,
152 std::move(frame), draw_callback);
138 153
139 for (std::unique_ptr<CopyOutputRequest>& copy_request : copy_requests_) { 154 for (std::unique_ptr<CopyOutputRequest>& copy_request : copy_requests_) {
140 support_->RequestCopyOfSurface(std::move(copy_request)); 155 surface_factory_->RequestCopyOfSurface(std::move(copy_request));
141 } 156 }
142 copy_requests_.clear(); 157 copy_requests_.clear();
143 158
144 if (!display_->has_scheduler()) { 159 if (synchronous) {
145 display_->DrawAndSwap(); 160 display_->DrawAndSwap();
146 // 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
147 // calling the client to tell it that it is done. 162 // calling the client to tell it that it is done.
148 task_runner_->PostTask( 163 task_runner_->PostTask(FROM_HERE,
149 FROM_HERE, 164 base::Bind(&TestCompositorFrameSink::DidDrawCallback,
150 base::Bind(&TestCompositorFrameSink::SendCompositorFrameAckToClient, 165 weak_ptr_factory_.GetWeakPtr()));
151 weak_ptr_factory_.GetWeakPtr()));
152 } 166 }
153 } 167 }
154 168
169 void TestCompositorFrameSink::DidDrawCallback() {
170 // This is to unthrottle the next frame, not actually a notice that drawing is
171 // done.
172 client_->DidReceiveCompositorFrameAck();
173 }
174
155 void TestCompositorFrameSink::ForceReclaimResources() { 175 void TestCompositorFrameSink::ForceReclaimResources() {
156 if (capabilities_.can_force_reclaim_resources && 176 if (capabilities_.can_force_reclaim_resources &&
157 delegated_local_surface_id_.is_valid()) { 177 delegated_local_surface_id_.is_valid()) {
158 support_->ForceReclaimResources(); 178 surface_factory_->ClearSurface();
159 } 179 }
160 } 180 }
161 181
162 void TestCompositorFrameSink::DidReceiveCompositorFrameAck() { 182 void TestCompositorFrameSink::ReturnResources(
163 // In synchronous mode, we manually send acks and this method should not be
164 // used.
165 if (!display_->has_scheduler())
166 return;
167 client_->DidReceiveCompositorFrameAck();
168 }
169
170 void TestCompositorFrameSink::OnBeginFrame(const BeginFrameArgs& args) {
171 external_begin_frame_source_.OnBeginFrame(args);
172 }
173
174 void TestCompositorFrameSink::ReclaimResources(
175 const ReturnedResourceArray& resources) { 183 const ReturnedResourceArray& resources) {
176 client_->ReclaimResources(resources); 184 client_->ReclaimResources(resources);
177 } 185 }
178 186
179 void TestCompositorFrameSink::WillDrawSurface( 187 void TestCompositorFrameSink::SetBeginFrameSource(
180 const LocalSurfaceId& local_surface_id, 188 BeginFrameSource* begin_frame_source) {
181 const gfx::Rect& damage_rect) {} 189 client_->SetBeginFrameSource(begin_frame_source);
190 }
182 191
183 void TestCompositorFrameSink::DisplayOutputSurfaceLost() { 192 void TestCompositorFrameSink::DisplayOutputSurfaceLost() {
184 client_->DidLoseCompositorFrameSink(); 193 client_->DidLoseCompositorFrameSink();
185 } 194 }
186 195
187 void TestCompositorFrameSink::DisplayWillDrawAndSwap( 196 void TestCompositorFrameSink::DisplayWillDrawAndSwap(
188 bool will_draw_and_swap, 197 bool will_draw_and_swap,
189 const RenderPassList& render_passes) { 198 const RenderPassList& render_passes) {
190 test_client_->DisplayWillDrawAndSwap(will_draw_and_swap, render_passes); 199 test_client_->DisplayWillDrawAndSwap(will_draw_and_swap, render_passes);
191 } 200 }
192 201
193 void TestCompositorFrameSink::DisplayDidDrawAndSwap() { 202 void TestCompositorFrameSink::DisplayDidDrawAndSwap() {
194 test_client_->DisplayDidDrawAndSwap(); 203 test_client_->DisplayDidDrawAndSwap();
195 } 204 }
196 205
197 void TestCompositorFrameSink::OnNeedsBeginFrames(bool needs_begin_frames) {
198 support_->SetNeedsBeginFrame(needs_begin_frames);
199 }
200
201 void TestCompositorFrameSink::OnDidFinishFrame(const BeginFrameAck& ack) {}
202
203 void TestCompositorFrameSink::SendCompositorFrameAckToClient() {
204 client_->DidReceiveCompositorFrameAck();
205 }
206
207 } // namespace cc 206 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/test_compositor_frame_sink.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698