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

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

Issue 739493002: Introduce command buffer control thread (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Forward echo too Created 6 years, 1 month 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 "mojo/services/gles2/command_buffer_impl.h" 5 #include "mojo/services/gles2/command_buffer_impl.h"
6 6
7 #include "base/message_loop/message_loop.h"
7 #include "mojo/services/gles2/command_buffer_driver.h" 8 #include "mojo/services/gles2/command_buffer_driver.h"
8 9
9 namespace mojo { 10 namespace mojo {
11 namespace {
12 void DestoryDriver(scoped_ptr<CommandBufferDriver> driver) {
jamesr 2014/11/19 06:43:02 typo 'Destory'
13 // Just let ~scoped_ptr run.
14 }
15 }
10 16
11 CommandBufferImpl::CommandBufferImpl(InterfaceRequest<CommandBuffer> request, 17 CommandBufferImpl::CommandBufferImpl(
12 scoped_ptr<CommandBufferDriver> driver) 18 InterfaceRequest<CommandBuffer> request,
13 : binding_(this, request.Pass()), driver_(driver.Pass()) { 19 scoped_refptr<base::SingleThreadTaskRunner> control_task_runner,
14 driver_->SetContextLostCallback( 20 scoped_ptr<CommandBufferDriver> driver)
15 base::Bind(&CommandBufferImpl::OnContextLost, base::Unretained(this))); 21 : driver_task_runner_(base::MessageLoop::current()->task_runner()),
22 driver_(driver.Pass()),
23 weak_factory_(this) {
24 driver_->SetContextLostCallback(control_task_runner,
25 base::Bind(&CommandBufferImpl::OnContextLost,
26 weak_factory_.GetWeakPtr()));
27
28 control_task_runner->PostTask(
29 FROM_HERE,
30 base::Bind(&CommandBufferImpl::BindToRequest, base::Unretained(this),
31 base::Passed(request.Pass())));
jamesr 2014/11/19 06:43:02 base::Passed(xxx.Pass()) is redundant, you should
abarth-chromium 2014/11/19 15:42:11 Ah, it was the & that I was missing. Thanks!
16 } 32 }
17 33
18 CommandBufferImpl::~CommandBufferImpl() { 34 CommandBufferImpl::~CommandBufferImpl() {
19 binding_.client()->DidDestroy(); 35 binding_->client()->DidDestroy();
36 driver_task_runner_->PostTask(
37 FROM_HERE, base::Bind(&DestoryDriver, base::Passed(driver_.Pass())));
jamesr 2014/11/19 06:43:02 same re: Passed+Pass
20 } 38 }
21 39
22 void CommandBufferImpl::Initialize( 40 void CommandBufferImpl::Initialize(CommandBufferSyncClientPtr sync_client,
23 CommandBufferSyncClientPtr sync_client, 41 ScopedSharedBufferHandle shared_state) {
24 mojo::ScopedSharedBufferHandle shared_state) { 42 driver_task_runner_->PostTask(FROM_HERE,
25 driver_->Initialize(sync_client.Pass(), shared_state.Pass()); 43 base::Bind(&CommandBufferDriver::Initialize,
44 base::Unretained(driver_.get()),
45 base::Passed(sync_client.Pass()),
46 base::Passed(shared_state.Pass())));
jamesr 2014/11/19 06:43:02 ditto
26 } 47 }
27 48
28 void CommandBufferImpl::SetGetBuffer(int32_t buffer) { 49 void CommandBufferImpl::SetGetBuffer(int32_t buffer) {
29 driver_->SetGetBuffer(buffer); 50 driver_task_runner_->PostTask(
51 FROM_HERE, base::Bind(&CommandBufferDriver::SetGetBuffer,
52 base::Unretained(driver_.get()), buffer));
30 } 53 }
31 54
32 void CommandBufferImpl::Flush(int32_t put_offset) { 55 void CommandBufferImpl::Flush(int32_t put_offset) {
33 driver_->Flush(put_offset); 56 driver_task_runner_->PostTask(
57 FROM_HERE, base::Bind(&CommandBufferDriver::Flush,
58 base::Unretained(driver_.get()), put_offset));
34 } 59 }
35 60
36 void CommandBufferImpl::MakeProgress(int32_t last_get_offset) { 61 void CommandBufferImpl::MakeProgress(int32_t last_get_offset) {
37 driver_->MakeProgress(last_get_offset); 62 driver_task_runner_->PostTask(
63 FROM_HERE, base::Bind(&CommandBufferDriver::MakeProgress,
64 base::Unretained(driver_.get()), last_get_offset));
38 } 65 }
39 66
40 void CommandBufferImpl::RegisterTransferBuffer( 67 void CommandBufferImpl::RegisterTransferBuffer(
41 int32_t id, 68 int32_t id,
42 mojo::ScopedSharedBufferHandle transfer_buffer, 69 ScopedSharedBufferHandle transfer_buffer,
43 uint32_t size) { 70 uint32_t size) {
44 driver_->RegisterTransferBuffer(id, transfer_buffer.Pass(), size); 71 driver_task_runner_->PostTask(
72 FROM_HERE, base::Bind(&CommandBufferDriver::RegisterTransferBuffer,
73 base::Unretained(driver_.get()), id,
74 base::Passed(transfer_buffer.Pass()), size));
jamesr 2014/11/19 06:43:02 ditto re base::Passed(...Pass())
45 } 75 }
46 76
47 void CommandBufferImpl::DestroyTransferBuffer(int32_t id) { 77 void CommandBufferImpl::DestroyTransferBuffer(int32_t id) {
48 driver_->DestroyTransferBuffer(id); 78 driver_task_runner_->PostTask(
79 FROM_HERE, base::Bind(&CommandBufferDriver::DestroyTransferBuffer,
80 base::Unretained(driver_.get()), id));
49 } 81 }
50 82
51 void CommandBufferImpl::Echo(const Callback<void()>& callback) { 83 void CommandBufferImpl::Echo(const Callback<void()>& callback) {
52 callback.Run(); 84 driver_task_runner_->PostTask(
85 FROM_HERE, base::Bind(&CommandBufferDriver::Echo,
86 base::Unretained(driver_.get()), callback));
87 }
88
89 void CommandBufferImpl::BindToRequest(InterfaceRequest<CommandBuffer> request) {
90 binding_.reset(new StrongBinding<CommandBuffer>(this, request.Pass()));
53 } 91 }
54 92
55 void CommandBufferImpl::OnContextLost(int32_t reason) { 93 void CommandBufferImpl::OnContextLost(int32_t reason) {
56 binding_.client()->LostContext(reason); 94 binding_->client()->LostContext(reason);
57 } 95 }
58 96
59 } // namespace mojo 97 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698