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

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

Issue 1161533005: Fix crash when backgrounding MojoShell on Android. Fixes issue #186. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 6 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 2014 The Chromium Authors. All rights reserved. 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 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 "services/gles2/command_buffer_impl.h" 5 #include "services/gles2/command_buffer_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "gpu/command_buffer/service/sync_point_manager.h" 9 #include "gpu/command_buffer/service/sync_point_manager.h"
10 #include "services/gles2/command_buffer_driver.h" 10 #include "services/gles2/command_buffer_driver.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 }; 46 };
47 } 47 }
48 48
49 CommandBufferImpl::CommandBufferImpl( 49 CommandBufferImpl::CommandBufferImpl(
50 mojo::InterfaceRequest<mojo::CommandBuffer> request, 50 mojo::InterfaceRequest<mojo::CommandBuffer> request,
51 mojo::ViewportParameterListenerPtr listener, 51 mojo::ViewportParameterListenerPtr listener,
52 scoped_refptr<base::SingleThreadTaskRunner> control_task_runner, 52 scoped_refptr<base::SingleThreadTaskRunner> control_task_runner,
53 gpu::SyncPointManager* sync_point_manager, 53 gpu::SyncPointManager* sync_point_manager,
54 scoped_ptr<CommandBufferDriver> driver) 54 scoped_ptr<CommandBufferDriver> driver)
55 : sync_point_manager_(sync_point_manager), 55 : sync_point_manager_(sync_point_manager),
56 control_task_runner_(control_task_runner),
56 driver_task_runner_(base::MessageLoop::current()->task_runner()), 57 driver_task_runner_(base::MessageLoop::current()->task_runner()),
57 driver_(driver.Pass()), 58 driver_(driver.Pass()),
58 viewport_parameter_listener_(listener.Pass()), 59 viewport_parameter_listener_(listener.Pass()),
59 binding_(this), 60 binding_(this),
60 observer_(nullptr), 61 observer_(nullptr),
61 weak_factory_(this) { 62 weak_factory_(this) {
62 driver_->set_client(make_scoped_ptr(new CommandBufferDriverClientImpl( 63 driver_->set_client(make_scoped_ptr(new CommandBufferDriverClientImpl(
63 weak_factory_.GetWeakPtr(), control_task_runner))); 64 weak_factory_.GetWeakPtr(), control_task_runner)));
64 65
65 control_task_runner->PostTask( 66 control_task_runner_->PostTask(
66 FROM_HERE, base::Bind(&CommandBufferImpl::BindToRequest, 67 FROM_HERE, base::Bind(&CommandBufferImpl::BindToRequest,
67 base::Unretained(this), base::Passed(&request))); 68 base::Unretained(this), base::Passed(&request)));
68 } 69 }
69 70
70 CommandBufferImpl::~CommandBufferImpl() { 71 CommandBufferImpl::~CommandBufferImpl() {
71 if (observer_) {
72 observer_->OnCommandBufferImplDestroyed();
73 }
74 driver_task_runner_->PostTask( 72 driver_task_runner_->PostTask(
75 FROM_HERE, base::Bind(&DestroyDriver, base::Passed(&driver_))); 73 FROM_HERE, base::Bind(&DestroyDriver, base::Passed(&driver_)));
76 } 74 }
77 75
78 void CommandBufferImpl::Initialize( 76 void CommandBufferImpl::Initialize(
79 mojo::CommandBufferSyncClientPtr sync_client, 77 mojo::CommandBufferSyncClientPtr sync_client,
80 mojo::CommandBufferSyncPointClientPtr sync_point_client, 78 mojo::CommandBufferSyncPointClientPtr sync_point_client,
81 mojo::CommandBufferLostContextObserverPtr loss_observer, 79 mojo::CommandBufferLostContextObserverPtr loss_observer,
82 mojo::ScopedSharedBufferHandle shared_state) { 80 mojo::ScopedSharedBufferHandle shared_state) {
83 sync_point_client_ = sync_point_client.Pass(); 81 sync_point_client_ = sync_point_client.Pass();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 } 138 }
141 139
142 void CommandBufferImpl::Echo(const mojo::Callback<void()>& callback) { 140 void CommandBufferImpl::Echo(const mojo::Callback<void()>& callback) {
143 driver_task_runner_->PostTaskAndReply(FROM_HERE, base::Bind(&base::DoNothing), 141 driver_task_runner_->PostTaskAndReply(FROM_HERE, base::Bind(&base::DoNothing),
144 base::Bind(&RunCallback, callback)); 142 base::Bind(&RunCallback, callback));
145 } 143 }
146 144
147 void CommandBufferImpl::BindToRequest( 145 void CommandBufferImpl::BindToRequest(
148 mojo::InterfaceRequest<mojo::CommandBuffer> request) { 146 mojo::InterfaceRequest<mojo::CommandBuffer> request) {
149 binding_.Bind(request.Pass()); 147 binding_.Bind(request.Pass());
148 binding_.set_error_handler(this);
150 } 149 }
151 150
152 void CommandBufferImpl::DidLoseContext() { 151 void CommandBufferImpl::DidLoseContext() {
153 binding_.OnConnectionError(); 152 NotifyAndDestroy();
blundell 2015/06/03 14:48:59 This method is called on |control_task_runner_| at
etiennej 2015/06/03 15:00:40 Right. Fixed.
153 }
154
155 void CommandBufferImpl::OnConnectionError() {
156 // Called from the control_task_runner thread as we bound to the message pipe
157 // handle on that thread. However, the observer have to be notified on the
158 // thread that created this object, so we post on driver_task_runner.
159 driver_task_runner_->PostTask(
160 FROM_HERE,
161 base::Bind(&CommandBufferImpl::NotifyAndDestroy, base::Unretained(this)));
162 }
163
164 void CommandBufferImpl::NotifyAndDestroy() {
165 if (observer_) {
166 observer_->OnCommandBufferImplDestroyed();
167 }
168 // We have notified the observer on the right thread. However, destruction of
169 // this object must happen on control_task_runner_
170 control_task_runner_->PostTask(
171 FROM_HERE,
172 base::Bind(&CommandBufferImpl::Destroy, base::Unretained(this)));
173 }
174
175 void CommandBufferImpl::Destroy() {
176 delete this;
154 } 177 }
155 178
156 void CommandBufferImpl::UpdateVSyncParameters(base::TimeTicks timebase, 179 void CommandBufferImpl::UpdateVSyncParameters(base::TimeTicks timebase,
157 base::TimeDelta interval) { 180 base::TimeDelta interval) {
158 if (!viewport_parameter_listener_) 181 if (!viewport_parameter_listener_)
159 return; 182 return;
160 viewport_parameter_listener_->OnVSyncParametersUpdated( 183 viewport_parameter_listener_->OnVSyncParametersUpdated(
161 timebase.ToInternalValue(), interval.ToInternalValue()); 184 timebase.ToInternalValue(), interval.ToInternalValue());
162 } 185 }
163 186
164 } // namespace gles2 187 } // namespace gles2
OLDNEW
« no previous file with comments | « services/gles2/command_buffer_impl.h ('k') | services/native_viewport/onscreen_context_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698