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

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: Route echo better 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
« no previous file with comments | « mojo/services/gles2/command_buffer_impl.h ('k') | mojo/services/gles2/gpu_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 DestroyDriver(scoped_ptr<CommandBufferDriver> driver) {
13 // Just let ~scoped_ptr run.
14 }
10 15
11 CommandBufferImpl::CommandBufferImpl(InterfaceRequest<CommandBuffer> request, 16 void RunCallback(const Callback<void()>& callback) {
12 scoped_ptr<CommandBufferDriver> driver) 17 callback.Run();
13 : binding_(this, request.Pass()), driver_(driver.Pass()) { 18 }
14 driver_->SetContextLostCallback( 19 }
15 base::Bind(&CommandBufferImpl::OnContextLost, base::Unretained(this))); 20
21 CommandBufferImpl::CommandBufferImpl(
22 InterfaceRequest<CommandBuffer> request,
23 scoped_refptr<base::SingleThreadTaskRunner> control_task_runner,
24 scoped_ptr<CommandBufferDriver> driver)
25 : driver_task_runner_(base::MessageLoop::current()->task_runner()),
26 driver_(driver.Pass()),
27 binding_(this),
28 weak_factory_(this) {
29 driver_->SetContextLostCallback(control_task_runner,
30 base::Bind(&CommandBufferImpl::OnContextLost,
31 weak_factory_.GetWeakPtr()));
32
33 control_task_runner->PostTask(
34 FROM_HERE, base::Bind(&CommandBufferImpl::BindToRequest,
35 base::Unretained(this), base::Passed(&request)));
16 } 36 }
17 37
18 CommandBufferImpl::~CommandBufferImpl() { 38 CommandBufferImpl::~CommandBufferImpl() {
19 binding_.client()->DidDestroy(); 39 binding_.client()->DidDestroy();
40 driver_task_runner_->PostTask(
41 FROM_HERE, base::Bind(&DestroyDriver, base::Passed(&driver_)));
20 } 42 }
21 43
22 void CommandBufferImpl::Initialize( 44 void CommandBufferImpl::Initialize(CommandBufferSyncClientPtr sync_client,
23 CommandBufferSyncClientPtr sync_client, 45 ScopedSharedBufferHandle shared_state) {
24 mojo::ScopedSharedBufferHandle shared_state) { 46 driver_task_runner_->PostTask(
25 driver_->Initialize(sync_client.Pass(), shared_state.Pass()); 47 FROM_HERE,
48 base::Bind(&CommandBufferDriver::Initialize,
49 base::Unretained(driver_.get()), base::Passed(&sync_client),
50 base::Passed(&shared_state)));
26 } 51 }
27 52
28 void CommandBufferImpl::SetGetBuffer(int32_t buffer) { 53 void CommandBufferImpl::SetGetBuffer(int32_t buffer) {
29 driver_->SetGetBuffer(buffer); 54 driver_task_runner_->PostTask(
55 FROM_HERE, base::Bind(&CommandBufferDriver::SetGetBuffer,
56 base::Unretained(driver_.get()), buffer));
30 } 57 }
31 58
32 void CommandBufferImpl::Flush(int32_t put_offset) { 59 void CommandBufferImpl::Flush(int32_t put_offset) {
33 driver_->Flush(put_offset); 60 driver_task_runner_->PostTask(
61 FROM_HERE, base::Bind(&CommandBufferDriver::Flush,
62 base::Unretained(driver_.get()), put_offset));
34 } 63 }
35 64
36 void CommandBufferImpl::MakeProgress(int32_t last_get_offset) { 65 void CommandBufferImpl::MakeProgress(int32_t last_get_offset) {
37 driver_->MakeProgress(last_get_offset); 66 driver_task_runner_->PostTask(
67 FROM_HERE, base::Bind(&CommandBufferDriver::MakeProgress,
68 base::Unretained(driver_.get()), last_get_offset));
38 } 69 }
39 70
40 void CommandBufferImpl::RegisterTransferBuffer( 71 void CommandBufferImpl::RegisterTransferBuffer(
41 int32_t id, 72 int32_t id,
42 mojo::ScopedSharedBufferHandle transfer_buffer, 73 ScopedSharedBufferHandle transfer_buffer,
43 uint32_t size) { 74 uint32_t size) {
44 driver_->RegisterTransferBuffer(id, transfer_buffer.Pass(), size); 75 driver_task_runner_->PostTask(
76 FROM_HERE, base::Bind(&CommandBufferDriver::RegisterTransferBuffer,
77 base::Unretained(driver_.get()), id,
78 base::Passed(&transfer_buffer), size));
45 } 79 }
46 80
47 void CommandBufferImpl::DestroyTransferBuffer(int32_t id) { 81 void CommandBufferImpl::DestroyTransferBuffer(int32_t id) {
48 driver_->DestroyTransferBuffer(id); 82 driver_task_runner_->PostTask(
83 FROM_HERE, base::Bind(&CommandBufferDriver::DestroyTransferBuffer,
84 base::Unretained(driver_.get()), id));
49 } 85 }
50 86
51 void CommandBufferImpl::Echo(const Callback<void()>& callback) { 87 void CommandBufferImpl::Echo(const Callback<void()>& callback) {
52 callback.Run(); 88 driver_task_runner_->PostTaskAndReply(FROM_HERE, base::Bind(&base::DoNothing),
89 base::Bind(&RunCallback, callback));
90 }
91
92 void CommandBufferImpl::BindToRequest(InterfaceRequest<CommandBuffer> request) {
93 binding_.Bind(request.Pass());
53 } 94 }
54 95
55 void CommandBufferImpl::OnContextLost(int32_t reason) { 96 void CommandBufferImpl::OnContextLost(int32_t reason) {
56 binding_.client()->LostContext(reason); 97 binding_.client()->LostContext(reason);
57 } 98 }
58 99
59 } // namespace mojo 100 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/gles2/command_buffer_impl.h ('k') | mojo/services/gles2/gpu_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698