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

Side by Side Diff: components/gles2/command_buffer_impl.cc

Issue 1150093003: Move GLES2, GPU & Surfaces into the ViewManager directory. This does not merge the applications, th… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 7 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 | « components/gles2/command_buffer_impl.h ('k') | components/gles2/command_buffer_impl_observer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 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 "components/gles2/command_buffer_impl.h"
6
7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h"
9 #include "components/gles2/command_buffer_driver.h"
10 #include "components/gles2/command_buffer_impl_observer.h"
11 #include "gpu/command_buffer/service/sync_point_manager.h"
12
13 namespace gles2 {
14 namespace {
15 void DestroyDriver(scoped_ptr<CommandBufferDriver> driver) {
16 // Just let ~scoped_ptr run.
17 }
18
19 void RunCallback(const mojo::Callback<void()>& callback) {
20 callback.Run();
21 }
22
23 class CommandBufferDriverClientImpl : public CommandBufferDriver::Client {
24 public:
25 CommandBufferDriverClientImpl(
26 base::WeakPtr<CommandBufferImpl> command_buffer,
27 scoped_refptr<base::SingleThreadTaskRunner> control_task_runner)
28 : command_buffer_(command_buffer),
29 control_task_runner_(control_task_runner) {}
30
31 private:
32 void UpdateVSyncParameters(base::TimeTicks timebase,
33 base::TimeDelta interval) override {
34 control_task_runner_->PostTask(
35 FROM_HERE, base::Bind(&CommandBufferImpl::UpdateVSyncParameters,
36 command_buffer_, timebase, interval));
37 }
38
39 void DidLoseContext() override {
40 control_task_runner_->PostTask(
41 FROM_HERE, base::Bind(&CommandBufferImpl::DidLoseContext,
42 command_buffer_));
43 }
44
45 base::WeakPtr<CommandBufferImpl> command_buffer_;
46 scoped_refptr<base::SingleThreadTaskRunner> control_task_runner_;
47 };
48 }
49
50 CommandBufferImpl::CommandBufferImpl(
51 mojo::InterfaceRequest<mojo::CommandBuffer> request,
52 mojo::ViewportParameterListenerPtr listener,
53 scoped_refptr<base::SingleThreadTaskRunner> control_task_runner,
54 gpu::SyncPointManager* sync_point_manager,
55 scoped_ptr<CommandBufferDriver> driver)
56 : sync_point_manager_(sync_point_manager),
57 driver_task_runner_(base::MessageLoop::current()->task_runner()),
58 driver_(driver.Pass()),
59 viewport_parameter_listener_(listener.Pass()),
60 binding_(this),
61 observer_(nullptr),
62 weak_factory_(this) {
63 driver_->set_client(make_scoped_ptr(new CommandBufferDriverClientImpl(
64 weak_factory_.GetWeakPtr(), control_task_runner)));
65
66 control_task_runner->PostTask(
67 FROM_HERE, base::Bind(&CommandBufferImpl::BindToRequest,
68 base::Unretained(this), base::Passed(&request)));
69 }
70
71 CommandBufferImpl::~CommandBufferImpl() {
72 if (observer_)
73 observer_->OnCommandBufferImplDestroyed();
74 driver_task_runner_->PostTask(
75 FROM_HERE, base::Bind(&DestroyDriver, base::Passed(&driver_)));
76 }
77
78 void CommandBufferImpl::Initialize(
79 mojo::CommandBufferSyncClientPtr sync_client,
80 mojo::CommandBufferSyncPointClientPtr sync_point_client,
81 mojo::CommandBufferLostContextObserverPtr loss_observer,
82 mojo::ScopedSharedBufferHandle shared_state) {
83 sync_point_client_ = sync_point_client.Pass();
84 driver_task_runner_->PostTask(
85 FROM_HERE,
86 base::Bind(&CommandBufferDriver::Initialize,
87 base::Unretained(driver_.get()), base::Passed(&sync_client),
88 base::Passed(&loss_observer),
89 base::Passed(&shared_state)));
90 }
91
92 void CommandBufferImpl::SetGetBuffer(int32_t buffer) {
93 driver_task_runner_->PostTask(
94 FROM_HERE, base::Bind(&CommandBufferDriver::SetGetBuffer,
95 base::Unretained(driver_.get()), buffer));
96 }
97
98 void CommandBufferImpl::Flush(int32_t put_offset) {
99 driver_task_runner_->PostTask(
100 FROM_HERE, base::Bind(&CommandBufferDriver::Flush,
101 base::Unretained(driver_.get()), put_offset));
102 }
103
104 void CommandBufferImpl::MakeProgress(int32_t last_get_offset) {
105 driver_task_runner_->PostTask(
106 FROM_HERE, base::Bind(&CommandBufferDriver::MakeProgress,
107 base::Unretained(driver_.get()), last_get_offset));
108 }
109
110 void CommandBufferImpl::RegisterTransferBuffer(
111 int32_t id,
112 mojo::ScopedSharedBufferHandle transfer_buffer,
113 uint32_t size) {
114 driver_task_runner_->PostTask(
115 FROM_HERE, base::Bind(&CommandBufferDriver::RegisterTransferBuffer,
116 base::Unretained(driver_.get()), id,
117 base::Passed(&transfer_buffer), size));
118 }
119
120 void CommandBufferImpl::DestroyTransferBuffer(int32_t id) {
121 driver_task_runner_->PostTask(
122 FROM_HERE, base::Bind(&CommandBufferDriver::DestroyTransferBuffer,
123 base::Unretained(driver_.get()), id));
124 }
125
126 void CommandBufferImpl::InsertSyncPoint(bool retire) {
127 uint32_t sync_point = sync_point_manager_->GenerateSyncPoint();
128 sync_point_client_->DidInsertSyncPoint(sync_point);
129 if (retire) {
130 driver_task_runner_->PostTask(
131 FROM_HERE, base::Bind(&gpu::SyncPointManager::RetireSyncPoint,
132 sync_point_manager_, sync_point));
133 }
134 }
135
136 void CommandBufferImpl::RetireSyncPoint(uint32_t sync_point) {
137 driver_task_runner_->PostTask(
138 FROM_HERE, base::Bind(&gpu::SyncPointManager::RetireSyncPoint,
139 sync_point_manager_, sync_point));
140 }
141
142 void CommandBufferImpl::Echo(const mojo::Callback<void()>& callback) {
143 driver_task_runner_->PostTaskAndReply(FROM_HERE, base::Bind(&base::DoNothing),
144 base::Bind(&RunCallback, callback));
145 }
146
147 void CommandBufferImpl::BindToRequest(
148 mojo::InterfaceRequest<mojo::CommandBuffer> request) {
149 binding_.Bind(request.Pass());
150 }
151
152 void CommandBufferImpl::DidLoseContext() {
153 binding_.OnConnectionError();
154 }
155
156 void CommandBufferImpl::UpdateVSyncParameters(base::TimeTicks timebase,
157 base::TimeDelta interval) {
158 if (!viewport_parameter_listener_)
159 return;
160 viewport_parameter_listener_->OnVSyncParametersUpdated(
161 timebase.ToInternalValue(), interval.ToInternalValue());
162 }
163
164 } // namespace gles2
OLDNEW
« no previous file with comments | « components/gles2/command_buffer_impl.h ('k') | components/gles2/command_buffer_impl_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698