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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: mojo/services/gles2/command_buffer_impl.cc
diff --git a/mojo/services/gles2/command_buffer_impl.cc b/mojo/services/gles2/command_buffer_impl.cc
index 62c7f2a24e1e0e69da36bc3b060fd7d221758e63..c190098ac3a925f92e0a66761fa8e3788aabd308 100644
--- a/mojo/services/gles2/command_buffer_impl.cc
+++ b/mojo/services/gles2/command_buffer_impl.cc
@@ -4,56 +4,94 @@
#include "mojo/services/gles2/command_buffer_impl.h"
+#include "base/message_loop/message_loop.h"
#include "mojo/services/gles2/command_buffer_driver.h"
namespace mojo {
+namespace {
+void DestoryDriver(scoped_ptr<CommandBufferDriver> driver) {
jamesr 2014/11/19 06:43:02 typo 'Destory'
+ // Just let ~scoped_ptr run.
+}
+}
+
+CommandBufferImpl::CommandBufferImpl(
+ InterfaceRequest<CommandBuffer> request,
+ scoped_refptr<base::SingleThreadTaskRunner> control_task_runner,
+ scoped_ptr<CommandBufferDriver> driver)
+ : driver_task_runner_(base::MessageLoop::current()->task_runner()),
+ driver_(driver.Pass()),
+ weak_factory_(this) {
+ driver_->SetContextLostCallback(control_task_runner,
+ base::Bind(&CommandBufferImpl::OnContextLost,
+ weak_factory_.GetWeakPtr()));
-CommandBufferImpl::CommandBufferImpl(InterfaceRequest<CommandBuffer> request,
- scoped_ptr<CommandBufferDriver> driver)
- : binding_(this, request.Pass()), driver_(driver.Pass()) {
- driver_->SetContextLostCallback(
- base::Bind(&CommandBufferImpl::OnContextLost, base::Unretained(this)));
+ control_task_runner->PostTask(
+ FROM_HERE,
+ base::Bind(&CommandBufferImpl::BindToRequest, base::Unretained(this),
+ 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!
}
CommandBufferImpl::~CommandBufferImpl() {
- binding_.client()->DidDestroy();
+ binding_->client()->DidDestroy();
+ driver_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&DestoryDriver, base::Passed(driver_.Pass())));
jamesr 2014/11/19 06:43:02 same re: Passed+Pass
}
-void CommandBufferImpl::Initialize(
- CommandBufferSyncClientPtr sync_client,
- mojo::ScopedSharedBufferHandle shared_state) {
- driver_->Initialize(sync_client.Pass(), shared_state.Pass());
+void CommandBufferImpl::Initialize(CommandBufferSyncClientPtr sync_client,
+ ScopedSharedBufferHandle shared_state) {
+ driver_task_runner_->PostTask(FROM_HERE,
+ base::Bind(&CommandBufferDriver::Initialize,
+ base::Unretained(driver_.get()),
+ base::Passed(sync_client.Pass()),
+ base::Passed(shared_state.Pass())));
jamesr 2014/11/19 06:43:02 ditto
}
void CommandBufferImpl::SetGetBuffer(int32_t buffer) {
- driver_->SetGetBuffer(buffer);
+ driver_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&CommandBufferDriver::SetGetBuffer,
+ base::Unretained(driver_.get()), buffer));
}
void CommandBufferImpl::Flush(int32_t put_offset) {
- driver_->Flush(put_offset);
+ driver_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&CommandBufferDriver::Flush,
+ base::Unretained(driver_.get()), put_offset));
}
void CommandBufferImpl::MakeProgress(int32_t last_get_offset) {
- driver_->MakeProgress(last_get_offset);
+ driver_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&CommandBufferDriver::MakeProgress,
+ base::Unretained(driver_.get()), last_get_offset));
}
void CommandBufferImpl::RegisterTransferBuffer(
int32_t id,
- mojo::ScopedSharedBufferHandle transfer_buffer,
+ ScopedSharedBufferHandle transfer_buffer,
uint32_t size) {
- driver_->RegisterTransferBuffer(id, transfer_buffer.Pass(), size);
+ driver_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&CommandBufferDriver::RegisterTransferBuffer,
+ base::Unretained(driver_.get()), id,
+ base::Passed(transfer_buffer.Pass()), size));
jamesr 2014/11/19 06:43:02 ditto re base::Passed(...Pass())
}
void CommandBufferImpl::DestroyTransferBuffer(int32_t id) {
- driver_->DestroyTransferBuffer(id);
+ driver_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&CommandBufferDriver::DestroyTransferBuffer,
+ base::Unretained(driver_.get()), id));
}
void CommandBufferImpl::Echo(const Callback<void()>& callback) {
- callback.Run();
+ driver_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&CommandBufferDriver::Echo,
+ base::Unretained(driver_.get()), callback));
+}
+
+void CommandBufferImpl::BindToRequest(InterfaceRequest<CommandBuffer> request) {
+ binding_.reset(new StrongBinding<CommandBuffer>(this, request.Pass()));
}
void CommandBufferImpl::OnContextLost(int32_t reason) {
- binding_.client()->LostContext(reason);
+ binding_->client()->LostContext(reason);
}
} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698