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

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 18 matching lines...) Expand all
29 29
30 private: 30 private:
31 void UpdateVSyncParameters(base::TimeTicks timebase, 31 void UpdateVSyncParameters(base::TimeTicks timebase,
32 base::TimeDelta interval) override { 32 base::TimeDelta interval) override {
33 control_task_runner_->PostTask( 33 control_task_runner_->PostTask(
34 FROM_HERE, base::Bind(&CommandBufferImpl::UpdateVSyncParameters, 34 FROM_HERE, base::Bind(&CommandBufferImpl::UpdateVSyncParameters,
35 command_buffer_, timebase, interval)); 35 command_buffer_, timebase, interval));
36 } 36 }
37 37
38 void DidLoseContext() override { 38 void DidLoseContext() override {
39 control_task_runner_->PostTask( 39 command_buffer_->DidLoseContext();
40 FROM_HERE, base::Bind(&CommandBufferImpl::DidLoseContext,
41 command_buffer_));
42 } 40 }
43 41
44 base::WeakPtr<CommandBufferImpl> command_buffer_; 42 base::WeakPtr<CommandBufferImpl> command_buffer_;
45 scoped_refptr<base::SingleThreadTaskRunner> control_task_runner_; 43 scoped_refptr<base::SingleThreadTaskRunner> control_task_runner_;
46 }; 44 };
47 } 45 }
48 46
49 CommandBufferImpl::CommandBufferImpl( 47 CommandBufferImpl::CommandBufferImpl(
50 mojo::InterfaceRequest<mojo::CommandBuffer> request, 48 mojo::InterfaceRequest<mojo::CommandBuffer> request,
51 mojo::ViewportParameterListenerPtr listener, 49 mojo::ViewportParameterListenerPtr listener,
52 scoped_refptr<base::SingleThreadTaskRunner> control_task_runner, 50 scoped_refptr<base::SingleThreadTaskRunner> control_task_runner,
53 gpu::SyncPointManager* sync_point_manager, 51 gpu::SyncPointManager* sync_point_manager,
54 scoped_ptr<CommandBufferDriver> driver) 52 scoped_ptr<CommandBufferDriver> driver)
55 : sync_point_manager_(sync_point_manager), 53 : sync_point_manager_(sync_point_manager),
54 control_task_runner_(control_task_runner),
56 driver_task_runner_(base::MessageLoop::current()->task_runner()), 55 driver_task_runner_(base::MessageLoop::current()->task_runner()),
57 driver_(driver.Pass()), 56 driver_(driver.Pass()),
58 viewport_parameter_listener_(listener.Pass()), 57 viewport_parameter_listener_(listener.Pass()),
59 binding_(this), 58 binding_(this),
60 observer_(nullptr), 59 observer_(nullptr),
61 weak_factory_(this) { 60 weak_factory_(this) {
62 driver_->set_client(make_scoped_ptr(new CommandBufferDriverClientImpl( 61 driver_->set_client(make_scoped_ptr(new CommandBufferDriverClientImpl(
63 weak_factory_.GetWeakPtr(), control_task_runner))); 62 weak_factory_.GetWeakPtr(), control_task_runner)));
64 63
65 control_task_runner->PostTask( 64 control_task_runner_->PostTask(
66 FROM_HERE, base::Bind(&CommandBufferImpl::BindToRequest, 65 FROM_HERE, base::Bind(&CommandBufferImpl::BindToRequest,
67 base::Unretained(this), base::Passed(&request))); 66 base::Unretained(this), base::Passed(&request)));
68 } 67 }
69 68
70 CommandBufferImpl::~CommandBufferImpl() { 69 CommandBufferImpl::~CommandBufferImpl() {
71 if (observer_) {
72 observer_->OnCommandBufferImplDestroyed();
73 }
74 driver_task_runner_->PostTask( 70 driver_task_runner_->PostTask(
75 FROM_HERE, base::Bind(&DestroyDriver, base::Passed(&driver_))); 71 FROM_HERE, base::Bind(&DestroyDriver, base::Passed(&driver_)));
76 } 72 }
77 73
78 void CommandBufferImpl::Initialize( 74 void CommandBufferImpl::Initialize(
79 mojo::CommandBufferSyncClientPtr sync_client, 75 mojo::CommandBufferSyncClientPtr sync_client,
80 mojo::CommandBufferSyncPointClientPtr sync_point_client, 76 mojo::CommandBufferSyncPointClientPtr sync_point_client,
81 mojo::CommandBufferLostContextObserverPtr loss_observer, 77 mojo::CommandBufferLostContextObserverPtr loss_observer,
82 mojo::ScopedSharedBufferHandle shared_state) { 78 mojo::ScopedSharedBufferHandle shared_state) {
83 sync_point_client_ = sync_point_client.Pass(); 79 sync_point_client_ = sync_point_client.Pass();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 } 136 }
141 137
142 void CommandBufferImpl::Echo(const mojo::Callback<void()>& callback) { 138 void CommandBufferImpl::Echo(const mojo::Callback<void()>& callback) {
143 driver_task_runner_->PostTaskAndReply(FROM_HERE, base::Bind(&base::DoNothing), 139 driver_task_runner_->PostTaskAndReply(FROM_HERE, base::Bind(&base::DoNothing),
144 base::Bind(&RunCallback, callback)); 140 base::Bind(&RunCallback, callback));
145 } 141 }
146 142
147 void CommandBufferImpl::BindToRequest( 143 void CommandBufferImpl::BindToRequest(
148 mojo::InterfaceRequest<mojo::CommandBuffer> request) { 144 mojo::InterfaceRequest<mojo::CommandBuffer> request) {
149 binding_.Bind(request.Pass()); 145 binding_.Bind(request.Pass());
146 binding_.set_error_handler(this);
150 } 147 }
151 148
152 void CommandBufferImpl::DidLoseContext() { 149 void CommandBufferImpl::DidLoseContext() {
153 binding_.OnConnectionError(); 150 NotifyAndDestroy();
151 }
152
153 void CommandBufferImpl::OnConnectionError() {
154 // Called from the control_task_runner thread as we bound to the message pipe
155 // handle on that thread. However, the observer have to be notified on the
156 // thread that created this object, so we post on driver_task_runner.
157 driver_task_runner_->PostTask(
158 FROM_HERE,
159 base::Bind(&CommandBufferImpl::NotifyAndDestroy, base::Unretained(this)));
160 }
161
162 void CommandBufferImpl::NotifyAndDestroy() {
163 if (observer_) {
164 observer_->OnCommandBufferImplDestroyed();
165 }
166 // We have notified the observer on the right thread. However, destruction of
167 // this object must happen on control_task_runner_
168 control_task_runner_->PostTask(
169 FROM_HERE,
170 base::Bind(&CommandBufferImpl::Destroy, base::Unretained(this)));
171 }
172
173 void CommandBufferImpl::Destroy() {
174 delete this;
154 } 175 }
155 176
156 void CommandBufferImpl::UpdateVSyncParameters(base::TimeTicks timebase, 177 void CommandBufferImpl::UpdateVSyncParameters(base::TimeTicks timebase,
157 base::TimeDelta interval) { 178 base::TimeDelta interval) {
158 if (!viewport_parameter_listener_) 179 if (!viewport_parameter_listener_)
159 return; 180 return;
160 viewport_parameter_listener_->OnVSyncParametersUpdated( 181 viewport_parameter_listener_->OnVSyncParametersUpdated(
161 timebase.ToInternalValue(), interval.ToInternalValue()); 182 timebase.ToInternalValue(), interval.ToInternalValue());
162 } 183 }
163 184
164 } // namespace gles2 185 } // 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