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

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

Issue 2402173002: cc: Get rid of PostSwapBuffersComplete. (Closed)
Patch Set: postswap: fix-blimp-unittest-post-swap-acks Created 4 years, 2 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_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 "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/compositor_frame_sink_client.h"
12 #include "cc/output/copy_output_request.h" 12 #include "cc/output/copy_output_request.h"
13 #include "cc/output/direct_renderer.h" 13 #include "cc/output/direct_renderer.h"
14 #include "cc/output/output_surface.h" 14 #include "cc/output/output_surface.h"
15 #include "cc/output/texture_mailbox_deleter.h" 15 #include "cc/output/texture_mailbox_deleter.h"
16 16
17 namespace cc { 17 namespace cc {
18 18
19 static constexpr FrameSinkId kCompositorFrameSinkId(1, 1); 19 static constexpr FrameSinkId kCompositorFrameSinkId(1, 1);
20 20
21 TestCompositorFrameSink::TestCompositorFrameSink( 21 TestCompositorFrameSink::TestCompositorFrameSink(
22 scoped_refptr<ContextProvider> compositor_context_provider, 22 scoped_refptr<ContextProvider> compositor_context_provider,
23 scoped_refptr<ContextProvider> worker_context_provider, 23 scoped_refptr<ContextProvider> worker_context_provider,
24 std::unique_ptr<OutputSurface> display_output_surface, 24 std::unique_ptr<OutputSurface> display_output_surface,
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 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 bool force_disable_reclaim_resources)
31 : CompositorFrameSink(std::move(compositor_context_provider), 31 : CompositorFrameSink(std::move(compositor_context_provider),
32 std::move(worker_context_provider)), 32 std::move(worker_context_provider)),
33 task_runner_(std::move(task_runner)),
33 frame_sink_id_(kCompositorFrameSinkId), 34 frame_sink_id_(kCompositorFrameSinkId),
34 surface_manager_(new SurfaceManager), 35 surface_manager_(new SurfaceManager),
35 surface_id_allocator_(new SurfaceIdAllocator()), 36 surface_id_allocator_(new SurfaceIdAllocator()),
36 surface_factory_( 37 surface_factory_(
37 new SurfaceFactory(frame_sink_id_, surface_manager_.get(), this)), 38 new SurfaceFactory(frame_sink_id_, surface_manager_.get(), this)),
38 display_context_shared_with_compositor_( 39 display_context_shared_with_compositor_(
39 display_output_surface->context_provider() == context_provider()) { 40 display_output_surface->context_provider() == context_provider()),
41 weak_ptr_factory_(this) {
40 std::unique_ptr<SyntheticBeginFrameSource> begin_frame_source; 42 std::unique_ptr<SyntheticBeginFrameSource> begin_frame_source;
41 std::unique_ptr<DisplayScheduler> scheduler; 43 std::unique_ptr<DisplayScheduler> scheduler;
42 if (!synchronous_composite) { 44 if (!synchronous_composite) {
43 if (renderer_settings.disable_display_vsync) { 45 if (renderer_settings.disable_display_vsync) {
44 begin_frame_source.reset(new BackToBackBeginFrameSource( 46 begin_frame_source.reset(new BackToBackBeginFrameSource(
45 base::MakeUnique<DelayBasedTimeSource>(task_runner))); 47 base::MakeUnique<DelayBasedTimeSource>(task_runner_.get())));
46 } else { 48 } else {
47 begin_frame_source.reset(new DelayBasedBeginFrameSource( 49 begin_frame_source.reset(new DelayBasedBeginFrameSource(
48 base::MakeUnique<DelayBasedTimeSource>(task_runner))); 50 base::MakeUnique<DelayBasedTimeSource>(task_runner_.get())));
49 begin_frame_source->SetAuthoritativeVSyncInterval( 51 begin_frame_source->SetAuthoritativeVSyncInterval(
50 base::TimeDelta::FromMilliseconds(1000.f / 52 base::TimeDelta::FromMilliseconds(1000.f /
51 renderer_settings.refresh_rate)); 53 renderer_settings.refresh_rate));
52 } 54 }
53 scheduler.reset(new DisplayScheduler( 55 scheduler.reset(new DisplayScheduler(
54 begin_frame_source.get(), task_runner, 56 begin_frame_source.get(), task_runner_.get(),
55 display_output_surface->capabilities().max_frames_pending)); 57 display_output_surface->capabilities().max_frames_pending));
56 } 58 }
57 display_.reset( 59 display_.reset(
58 new Display(shared_bitmap_manager, gpu_memory_buffer_manager, 60 new Display(shared_bitmap_manager, gpu_memory_buffer_manager,
59 renderer_settings, std::move(begin_frame_source), 61 renderer_settings, std::move(begin_frame_source),
60 std::move(display_output_surface), std::move(scheduler), 62 std::move(display_output_surface), std::move(scheduler),
61 base::MakeUnique<TextureMailboxDeleter>(task_runner))); 63 base::MakeUnique<TextureMailboxDeleter>(task_runner_.get())));
62 64
63 // Since this CompositorFrameSink and the Display are tightly coupled and in 65 // Since this CompositorFrameSink and the Display are tightly coupled and in
64 // the same process/thread, the LayerTreeHostImpl can reclaim resources from 66 // the same process/thread, the LayerTreeHostImpl can reclaim resources from
65 // the Display. But we allow tests to disable this to mimic an out-of-process 67 // the Display. But we allow tests to disable this to mimic an out-of-process
66 // Display. 68 // Display.
67 capabilities_.can_force_reclaim_resources = !force_disable_reclaim_resources; 69 capabilities_.can_force_reclaim_resources = !force_disable_reclaim_resources;
68 // Always use sync tokens so that code paths in resource provider that deal 70 // Always use sync tokens so that code paths in resource provider that deal
69 // with sync tokens are tested. 71 // with sync tokens are tested.
70 capabilities_.delegated_sync_points_required = true; 72 capabilities_.delegated_sync_points_required = true;
71 } 73 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 } 127 }
126 display_->SetSurfaceId(SurfaceId(frame_sink_id_, delegated_local_frame_id_), 128 display_->SetSurfaceId(SurfaceId(frame_sink_id_, delegated_local_frame_id_),
127 frame.metadata.device_scale_factor); 129 frame.metadata.device_scale_factor);
128 130
129 gfx::Size frame_size = 131 gfx::Size frame_size =
130 frame.delegated_frame_data->render_pass_list.back()->output_rect.size(); 132 frame.delegated_frame_data->render_pass_list.back()->output_rect.size();
131 display_->Resize(frame_size); 133 display_->Resize(frame_size);
132 134
133 bool synchronous = !display_->has_scheduler(); 135 bool synchronous = !display_->has_scheduler();
134 136
135 surface_factory_->SubmitCompositorFrame( 137 SurfaceFactory::DrawCallback draw_callback;
136 delegated_local_frame_id_, std::move(frame), 138 if (!synchronous) {
137 base::Bind(&TestCompositorFrameSink::DidDrawCallback, 139 // For async draws, we use a callback tell when it is done, but for sync
138 base::Unretained(this))); 140 // draws we don't need one. Unretained is safe here because the callback
141 // will be run when |surface_factory_| is destroyed which is owned by this
142 // class.
143 draw_callback = base::Bind(&TestCompositorFrameSink::DidDrawCallback,
144 base::Unretained(this));
145 }
146
147 surface_factory_->SubmitCompositorFrame(delegated_local_frame_id_,
148 std::move(frame), draw_callback);
139 149
140 for (std::unique_ptr<CopyOutputRequest>& copy_request : copy_requests_) { 150 for (std::unique_ptr<CopyOutputRequest>& copy_request : copy_requests_) {
141 surface_factory_->RequestCopyOfSurface(delegated_local_frame_id_, 151 surface_factory_->RequestCopyOfSurface(delegated_local_frame_id_,
142 std::move(copy_request)); 152 std::move(copy_request));
143 } 153 }
144 copy_requests_.clear(); 154 copy_requests_.clear();
145 155
146 if (synchronous) 156 if (synchronous) {
147 display_->DrawAndSwap(); 157 display_->DrawAndSwap();
158 // Post this to get a new stack frame so that we exit this function before
159 // calling the client to tell it that it is done.
160 task_runner_->PostTask(FROM_HERE,
161 base::Bind(&TestCompositorFrameSink::DidDrawCallback,
162 weak_ptr_factory_.GetWeakPtr()));
163 }
148 } 164 }
149 165
150 void TestCompositorFrameSink::DidDrawCallback() { 166 void TestCompositorFrameSink::DidDrawCallback() {
151 // This is the frame ack to unthrottle the next frame, not actually a notice 167 // This is the frame ack to unthrottle the next frame, not actually a notice
152 // that drawing is done. 168 // that drawing is done.
153 CompositorFrameSink::PostSwapBuffersComplete(); 169 client_->DidSwapBuffersComplete();
154 } 170 }
155 171
156 void TestCompositorFrameSink::ForceReclaimResources() { 172 void TestCompositorFrameSink::ForceReclaimResources() {
157 if (capabilities_.can_force_reclaim_resources && 173 if (capabilities_.can_force_reclaim_resources &&
158 !delegated_local_frame_id_.is_null()) { 174 !delegated_local_frame_id_.is_null()) {
159 surface_factory_->SubmitCompositorFrame(delegated_local_frame_id_, 175 surface_factory_->SubmitCompositorFrame(delegated_local_frame_id_,
160 CompositorFrame(), 176 CompositorFrame(),
161 SurfaceFactory::DrawCallback()); 177 SurfaceFactory::DrawCallback());
162 } 178 }
163 } 179 }
(...skipping 18 matching lines...) Expand all
182 if (test_client_) 198 if (test_client_)
183 test_client_->DisplayWillDrawAndSwap(will_draw_and_swap, render_passes); 199 test_client_->DisplayWillDrawAndSwap(will_draw_and_swap, render_passes);
184 } 200 }
185 201
186 void TestCompositorFrameSink::DisplayDidDrawAndSwap() { 202 void TestCompositorFrameSink::DisplayDidDrawAndSwap() {
187 if (test_client_) 203 if (test_client_)
188 test_client_->DisplayDidDrawAndSwap(); 204 test_client_->DisplayDidDrawAndSwap();
189 } 205 }
190 206
191 } // namespace cc 207 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/test_compositor_frame_sink.h ('k') | content/browser/compositor/browser_compositor_output_surface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698