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

Side by Side Diff: services/gfx/compositor/backend/gpu_output.cc

Issue 1552963002: Initial checkin of the new Mozart compositor. (Closed) Base URL: git@github.com:domokit/mojo.git@moz-11
Patch Set: Created 4 years, 11 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
(Empty)
1 // Copyright 2015 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 "services/gfx/compositor/backend/gpu_output.h"
6
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h"
11 #include "services/gfx/compositor/backend/gpu_rasterizer.h"
12
13 namespace compositor {
14
15 template <typename T>
16 static void Drop(scoped_ptr<T> ptr) {}
17
18 static scoped_ptr<base::MessagePump> CreateMessagePumpMojo() {
19 return base::MessageLoop::CreateMessagePumpForType(
20 base::MessageLoop::TYPE_DEFAULT);
21 }
22
23 GpuOutput::GpuOutput(mojo::ContextProviderPtr context_provider,
24 const SchedulerCallbacks& scheduler_callbacks,
25 const base::Closure& error_callback)
26 : frame_queue_(std::make_shared<FrameQueue>()),
27 scheduler_(std::make_shared<VsyncScheduler>(base::MessageLoop::current()
28 ->task_runner(),
29 scheduler_callbacks)),
30 rasterizer_delegate_(
31 make_scoped_ptr(new RasterizerDelegate(frame_queue_))) {
32 DCHECK(context_provider);
33
34 base::Thread::Options options;
35 options.message_pump_factory = base::Bind(&CreateMessagePumpMojo);
36
37 rasterizer_thread_.reset(new base::Thread("gpu_rasterizer"));
38 rasterizer_thread_->StartWithOptions(options);
39 rasterizer_task_runner_ = rasterizer_thread_->message_loop()->task_runner();
40
41 rasterizer_task_runner_->PostTask(
42 FROM_HERE,
43 base::Bind(&RasterizerDelegate::CreateRasterizer,
44 base::Unretained(rasterizer_delegate_.get()),
45 base::Passed(context_provider.PassInterface()), scheduler_,
46 base::MessageLoop::current()->task_runner(), error_callback));
47 }
48
49 GpuOutput::~GpuOutput() {
50 // Ensure destruction happens on the correct thread.
51 rasterizer_task_runner_->PostTask(
52 FROM_HERE, base::Bind(&Drop<RasterizerDelegate>,
53 base::Passed(&rasterizer_delegate_)));
54 }
55
56 Scheduler* GpuOutput::scheduler() {
57 return scheduler_.get();
58 }
59
60 void GpuOutput::SubmitFrame(const std::shared_ptr<RenderFrame>& frame) {
61 if (frame_queue_->PutFrame(frame)) {
abarth 2016/01/10 04:22:09 We should talk in person about whether this schedu
jeffbrown 2016/01/16 03:28:31 Agreed. This needs backpressure. I'll fix that l
62 rasterizer_task_runner_->PostTask(
63 FROM_HERE, base::Bind(&RasterizerDelegate::SubmitNextFrame,
64 base::Unretained(rasterizer_delegate_.get())));
65 }
66 }
67
68 GpuOutput::FrameQueue::FrameQueue() {}
69
70 GpuOutput::FrameQueue::~FrameQueue() {}
71
72 bool GpuOutput::FrameQueue::PutFrame(
73 const std::shared_ptr<RenderFrame>& frame) {
74 std::lock_guard<std::mutex> lock(mutex_);
75 bool was_empty = !next_frame_.get();
76 next_frame_ = frame;
77 return was_empty;
78 }
79
80 std::shared_ptr<RenderFrame> GpuOutput::FrameQueue::TakeFrame() {
81 std::lock_guard<std::mutex> lock(mutex_);
82 return std::move(next_frame_);
83 }
84
85 GpuOutput::RasterizerDelegate::RasterizerDelegate(
86 const std::shared_ptr<FrameQueue>& frame_queue)
87 : frame_queue_(frame_queue) {
88 DCHECK(frame_queue_);
89 }
90
91 GpuOutput::RasterizerDelegate::~RasterizerDelegate() {}
92
93 void GpuOutput::RasterizerDelegate::CreateRasterizer(
94 mojo::InterfacePtrInfo<mojo::ContextProvider> context_provider_info,
95 const std::shared_ptr<VsyncScheduler>& scheduler,
96 const scoped_refptr<base::TaskRunner>& task_runner,
97 const base::Closure& error_callback) {
98 rasterizer_.reset(
99 new GpuRasterizer(mojo::MakeProxy(context_provider_info.Pass()).Pass(),
100 scheduler, task_runner, error_callback));
101 }
102
103 void GpuOutput::RasterizerDelegate::SubmitNextFrame() {
104 std::shared_ptr<RenderFrame> frame(frame_queue_->TakeFrame());
105 DCHECK(frame);
106 rasterizer_->SubmitFrame(frame);
107 }
108
109 } // namespace compositor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698