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

Unified Diff: components/mus/common/gpu_service.cc

Issue 2056833002: WIP HW (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/mus/common/gpu_service.h ('k') | components/mus/gpu/gpu_service_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/mus/common/gpu_service.cc
diff --git a/components/mus/common/gpu_service.cc b/components/mus/common/gpu_service.cc
index a0d4908b5127a15108b7afda15fa2f05ec2615a0..9bb0f572c60fb010bff31aad1636c7c2c7c16e67 100644
--- a/components/mus/common/gpu_service.cc
+++ b/components/mus/common/gpu_service.cc
@@ -8,9 +8,7 @@
#include "base/memory/singleton.h"
#include "base/threading/thread_restrictions.h"
#include "components/mus/common/gpu_type_converters.h"
-#include "components/mus/common/mojo_gpu_memory_buffer_manager.h"
#include "components/mus/common/switches.h"
-#include "components/mus/public/interfaces/gpu_service.mojom.h"
#include "mojo/public/cpp/system/platform_handle.h"
#include "services/shell/public/cpp/connector.h"
@@ -21,7 +19,9 @@ GpuService::GpuService()
shutdown_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC,
base::WaitableEvent::InitialState::NOT_SIGNALED),
io_thread_("GPUIOThread"),
- gpu_memory_buffer_manager_(new MojoGpuMemoryBufferManager) {
+ gpu_memory_buffer_manager_(new MojoGpuMemoryBufferManager),
+ is_establishing_(false),
+ establishing_condition_(&lock_) {
base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0);
thread_options.priority = base::ThreadPriority::NORMAL;
CHECK(io_thread_.StartWithOptions(thread_options));
@@ -41,24 +41,56 @@ GpuService* GpuService::GetInstance() {
base::LeakySingletonTraits<GpuService>>::get();
}
-scoped_refptr<gpu::GpuChannelHost> GpuService::EstablishGpuChannel(
- shell::Connector* connector) {
+void GpuService::EstablishGpuChannel(shell::Connector* connector,
+ const base::Closure& callback) {
base::AutoLock auto_lock(lock_);
- if (gpu_channel_ && gpu_channel_->IsLost()) {
- gpu_channel_->DestroyChannel();
- gpu_channel_ = nullptr;
+ auto task_runner = base::ThreadTaskRunnerHandle::Get();
+ DCHECK(task_runner);
+
+ if (GetGpuChannelLocked()) {
+ DCHECK(establish_callbacks_.empty());
+ DCHECK(!is_establishing_);
+ task_runner->PostTask(FROM_HERE, callback);
+ return;
}
- if (gpu_channel_)
+ establish_callbacks_.push_back(std::make_pair(task_runner, callback));
+ if (!is_establishing_) {
+ is_establishing_ = true;
+ mus::mojom::GpuServicePtr gpu_service;
+ connector->ConnectToInterface("mojo:mus", &gpu_service);
+ const bool locked = false;
+ gpu_service->EstablishGpuChannel(base::Bind(
+ &GpuService::EstablishGpuChannelDone, base::Unretained(this), locked));
+ }
+}
+
+scoped_refptr<gpu::GpuChannelHost> GpuService::EstablishGpuChannelSync(
+ shell::Connector* connector) {
+ fprintf(stderr, "EEE %d %s %d\n", getpid(), __PRETTY_FUNCTION__, __LINE__);
+ base::AutoLock auto_lock(lock_);
+ if (GetGpuChannelLocked())
return gpu_channel_;
- mus::mojom::GpuServicePtr gpu_service;
- connector->ConnectToInterface("mojo:mus", &gpu_service);
+ if (is_establishing_) {
+ do {
+ establishing_condition_.Wait();
+ } while (is_establishing_);
+ fprintf(stderr, "EEE %d %s %d\n", getpid(), __PRETTY_FUNCTION__, __LINE__);
+ return gpu_channel_;
+ }
+
+ is_establishing_ = true;
int client_id = 0;
mojom::ChannelHandlePtr channel_handle;
mojom::GpuInfoPtr gpu_info;
+ mus::mojom::GpuServicePtr gpu_service;
+ connector->ConnectToInterface("mojo:mus", &gpu_service);
+
{
+ // Unlock the |lock_| during the sync mojo method call.
+ base::AutoUnlock auto_unlock(lock_);
// TODO(penghuang): Remove the ScopedAllowWait when HW rendering is enabled
// in mus chrome.
base::ThreadRestrictions::ScopedAllowWait allow_wait;
@@ -66,17 +98,58 @@ scoped_refptr<gpu::GpuChannelHost> GpuService::EstablishGpuChannel(
&gpu_info)) {
DLOG(WARNING)
<< "Channel encountered error while establishing gpu channel.";
- return nullptr;
}
}
- // TODO(penghuang): Get the real gpu info from mus.
- gpu_channel_ = gpu::GpuChannelHost::Create(
- this, client_id, gpu::GPUInfo(), channel_handle.To<IPC::ChannelHandle>(),
- &shutdown_event_, gpu_memory_buffer_manager_.get());
+ const bool locked = true;
+ EstablishGpuChannelDone(locked, client_id, std::move(channel_handle),
+ std::move(gpu_info));
+ fprintf(stderr, "EEE %d %s %d\n", getpid(), __PRETTY_FUNCTION__, __LINE__);
return gpu_channel_;
}
+scoped_refptr<gpu::GpuChannelHost> GpuService::GetGpuChannel() {
+ base::AutoLock auto_lock(lock_);
+ return GetGpuChannelLocked();
+}
+
+scoped_refptr<gpu::GpuChannelHost> GpuService::GetGpuChannelLocked() {
+ if (gpu_channel_ && gpu_channel_->IsLost()) {
+ gpu_channel_->DestroyChannel();
+ gpu_channel_ = nullptr;
+ }
+ return gpu_channel_;
+}
+
+void GpuService::EstablishGpuChannelDone(bool locked,
+ int client_id,
+ mojom::ChannelHandlePtr channel_handle,
+ mojom::GpuInfoPtr gpu_info) {
+ scoped_refptr<gpu::GpuChannelHost> gpu_channel;
+ if (client_id) {
+ // TODO(penghuang): Get the real gpu info from mus.
+ gpu_channel = gpu::GpuChannelHost::Create(
+ this, client_id, gpu::GPUInfo(),
+ channel_handle.To<IPC::ChannelHandle>(), &shutdown_event_,
+ gpu_memory_buffer_manager_.get());
+ }
+
+ std::unique_ptr<base::AutoLock> auto_lock;
+ if (!locked)
+ auto_lock = base::MakeUnique<base::AutoLock>(lock_);
+
+ DCHECK(is_establishing_);
+ DCHECK(!gpu_channel_);
+
+ is_establishing_ = false;
+ gpu_channel_ = gpu_channel;
+ establishing_condition_.Broadcast();
+
+ for (const auto& i : establish_callbacks_)
+ i.first->PostTask(FROM_HERE, i.second);
+ establish_callbacks_.clear();
+}
+
bool GpuService::IsMainThread() {
return base::MessageLoop::current() == main_message_loop_;
}
« no previous file with comments | « components/mus/common/gpu_service.h ('k') | components/mus/gpu/gpu_service_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698