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

Unified Diff: services/ui/ws/gpu_service_proxy.cc

Issue 2448983003: gpu: Refactor memory buffer handling code out of content.
Patch Set: . Created 4 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
« no previous file with comments | « services/ui/ws/gpu_service_proxy.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/ui/ws/gpu_service_proxy.cc
diff --git a/services/ui/ws/gpu_service_proxy.cc b/services/ui/ws/gpu_service_proxy.cc
index 2beb73c57504d3c05764bf59c4b9b2074e96147a..78040e7434f6eecccbdf82f857e62811f28a1e5c 100644
--- a/services/ui/ws/gpu_service_proxy.cc
+++ b/services/ui/ws/gpu_service_proxy.cc
@@ -9,6 +9,7 @@
#include "base/run_loop.h"
#include "base/threading/thread_task_runner_handle.h"
#include "gpu/ipc/client/gpu_channel_host.h"
+#include "mojo/public/cpp/bindings/strong_binding.h"
#include "services/service_manager/public/cpp/connection.h"
#include "services/ui/ws/gpu_service_proxy_delegate.h"
#include "services/ui/ws/mus_gpu_memory_buffer_manager.h"
@@ -21,6 +22,66 @@ namespace {
const int32_t kInternalGpuChannelClientId = 1;
const uint64_t kInternalGpuChannelClientTracingId = 1;
+class GpuServiceImpl : public mojom::GpuService {
+ public:
+ GpuServiceImpl(int client_id,
+ gpu::GPUInfo* gpu_info,
+ gpu::GpuHostMemoryBufferManager* gpu_memory_buffer_manager,
+ mojom::GpuServiceInternal* gpu_service_internal)
+ : client_id_(client_id),
+ gpu_info_(gpu_info),
+ gpu_memory_buffer_manager_(gpu_memory_buffer_manager),
+ gpu_service_internal_(gpu_service_internal) {}
+ ~GpuServiceImpl() override {}
+
+ private:
+ void OnGpuChannelEstablished(const EstablishGpuChannelCallback& callback,
+ mojo::ScopedMessagePipeHandle channel_handle) {
+ callback.Run(client_id_, std::move(channel_handle), *gpu_info_);
+ }
+
+ // mojom::GpuService overrides:
+ void EstablishGpuChannel(
+ const EstablishGpuChannelCallback& callback) override {
+ // TODO(sad): crbug.com/617415 figure out how to generate a meaningful
+ // tracing id.
+ const uint64_t client_tracing_id = 0;
+ constexpr bool is_gpu_host = false;
+ gpu_service_internal_->EstablishGpuChannel(
+ client_id_, client_tracing_id, is_gpu_host,
+ base::Bind(&GpuServiceImpl::OnGpuChannelEstablished,
+ base::Unretained(this), callback));
+ }
+
+ void CreateGpuMemoryBuffer(
+ gfx::GpuMemoryBufferId id,
+ const gfx::Size& size,
+ gfx::BufferFormat format,
+ gfx::BufferUsage usage,
+ const mojom::GpuService::CreateGpuMemoryBufferCallback& callback)
+ override {
+#if 0
+ NOTIMPLEMENTED();
+ callback.Run(gfx::GpuMemoryBufferHandle());
+#else
+ gpu_memory_buffer_manager_->AllocateGpuMemoryBufferForClient(
+ id, size, format, usage, client_id_, callback);
+#endif
+ }
+
+ void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
+ const gpu::SyncToken& sync_token) override {
+ NOTIMPLEMENTED();
+ }
+
+ const int client_id_;
+ const gpu::GPUInfo* gpu_info_;
+ gpu::GpuHostMemoryBufferManager* gpu_memory_buffer_manager_;
+ mojom::GpuServiceInternal* gpu_service_internal_;
+
+ DISALLOW_COPY_AND_ASSIGN(GpuServiceImpl);
+};
+
} // namespace
GpuServiceProxy::GpuServiceProxy(GpuServiceProxyDelegate* delegate)
@@ -35,6 +96,15 @@ GpuServiceProxy::GpuServiceProxy(GpuServiceProxyDelegate* delegate)
gpu_main_.Create(GetProxy(&gpu_service_));
gpu_service_->Initialize(
base::Bind(&GpuServiceProxy::OnInitialized, base::Unretained(this)));
+
+ io_thread_ = base::MakeUnique<base::Thread>("GPUIOThread");
+ base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0);
+ thread_options.priority = base::ThreadPriority::NORMAL;
+ CHECK(io_thread_->StartWithOptions(thread_options));
+
+ gpu_memory_buffer_manager_ =
+ base::MakeUnique<gpu::GpuHostMemoryBufferManager>();
+ gpu_memory_buffer_manager_->SetIO(io_thread_->task_runner());
}
GpuServiceProxy::~GpuServiceProxy() {
@@ -43,7 +113,11 @@ GpuServiceProxy::~GpuServiceProxy() {
}
void GpuServiceProxy::Add(mojom::GpuServiceRequest request) {
- bindings_.AddBinding(this, std::move(request));
+ mojo::MakeStrongBinding(
+ base::MakeUnique<GpuServiceImpl>(next_client_id_++, &gpu_info_,
+ gpu_memory_buffer_manager_.get(),
+ gpu_service_.get()),
+ std::move(request));
}
void GpuServiceProxy::OnInitialized(const gpu::GPUInfo& gpu_info) {
@@ -58,13 +132,6 @@ void GpuServiceProxy::OnInitialized(const gpu::GPUInfo& gpu_info) {
void GpuServiceProxy::OnInternalGpuChannelEstablished(
mojo::ScopedMessagePipeHandle channel_handle) {
- io_thread_ = base::MakeUnique<base::Thread>("GPUIOThread");
- base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0);
- thread_options.priority = base::ThreadPriority::NORMAL;
- CHECK(io_thread_->StartWithOptions(thread_options));
-
- gpu_memory_buffer_manager_ = base::MakeUnique<MusGpuMemoryBufferManager>(
- gpu_service_.get(), kInternalGpuChannelClientId);
gpu_channel_ = gpu::GpuChannelHost::Create(
this, kInternalGpuChannelClientId, gpu_info_,
IPC::ChannelHandle(channel_handle.release()), &shutdown_event_,
@@ -73,41 +140,6 @@ void GpuServiceProxy::OnInternalGpuChannelEstablished(
delegate_->OnGpuChannelEstablished(gpu_channel_);
}
-void GpuServiceProxy::OnGpuChannelEstablished(
- const EstablishGpuChannelCallback& callback,
- int32_t client_id,
- mojo::ScopedMessagePipeHandle channel_handle) {
- callback.Run(client_id, std::move(channel_handle), gpu_info_);
-}
-
-void GpuServiceProxy::EstablishGpuChannel(
- const EstablishGpuChannelCallback& callback) {
- const int client_id = next_client_id_++;
- // TODO(sad): crbug.com/617415 figure out how to generate a meaningful tracing
- // id.
- const uint64_t client_tracing_id = 0;
- constexpr bool is_gpu_host = false;
- gpu_service_->EstablishGpuChannel(
- client_id, client_tracing_id, is_gpu_host,
- base::Bind(&GpuServiceProxy::OnGpuChannelEstablished,
- base::Unretained(this), callback, client_id));
-}
-
-void GpuServiceProxy::CreateGpuMemoryBuffer(
- gfx::GpuMemoryBufferId id,
- const gfx::Size& size,
- gfx::BufferFormat format,
- gfx::BufferUsage usage,
- uint64_t surface_id,
- const mojom::GpuService::CreateGpuMemoryBufferCallback& callback) {
- NOTIMPLEMENTED();
-}
-
-void GpuServiceProxy::DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
- const gpu::SyncToken& sync_token) {
- NOTIMPLEMENTED();
-}
-
bool GpuServiceProxy::IsMainThread() {
return main_thread_task_runner_->BelongsToCurrentThread();
}
« no previous file with comments | « services/ui/ws/gpu_service_proxy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698