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

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

Issue 2741343003: Update liftetime management of GpuClient (Closed)
Patch Set: fix x11 re-definition Created 3 years, 9 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 | « services/ui/ws/gpu_host.h ('k') | services/ui/ws/gpu_host_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/ui/ws/gpu_host.cc
diff --git a/services/ui/ws/gpu_host.cc b/services/ui/ws/gpu_host.cc
index 76fe6d833a86d4428c4bf9191bfead8c41b7e6cf..1414fe28e7693b6abbeedeaa78d4058f2cb1c432 100644
--- a/services/ui/ws/gpu_host.cc
+++ b/services/ui/ws/gpu_host.cc
@@ -16,6 +16,7 @@
#include "mojo/public/cpp/system/platform_handle.h"
#include "services/service_manager/public/cpp/connection.h"
#include "services/ui/common/server_gpu_memory_buffer_manager.h"
+#include "services/ui/ws/gpu_client.h"
#include "services/ui/ws/gpu_host_delegate.h"
#include "ui/gfx/buffer_format_util.h"
@@ -31,71 +32,6 @@ namespace {
// The client Id 1 is reserved for the display compositor.
const int32_t kInternalGpuChannelClientId = 2;
-// The implementation that relays requests from clients to the real
-// service implementation in the GPU process over mojom.GpuService.
-class GpuClient : public mojom::Gpu {
- public:
- GpuClient(int client_id,
- gpu::GPUInfo* gpu_info,
- ServerGpuMemoryBufferManager* gpu_memory_buffer_manager,
- mojom::GpuService* gpu_service)
- : client_id_(client_id),
- gpu_info_(gpu_info),
- gpu_memory_buffer_manager_(gpu_memory_buffer_manager),
- gpu_service_(gpu_service) {
- DCHECK(gpu_memory_buffer_manager_);
- DCHECK(gpu_service_);
- }
- ~GpuClient() override {
- gpu_memory_buffer_manager_->DestroyAllGpuMemoryBufferForClient(client_id_);
- }
-
- private:
- void OnGpuChannelEstablished(const EstablishGpuChannelCallback& callback,
- mojo::ScopedMessagePipeHandle channel_handle) {
- callback.Run(client_id_, std::move(channel_handle), *gpu_info_);
- }
-
- // mojom::Gpu 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_->EstablishGpuChannel(
- client_id_, client_tracing_id, is_gpu_host,
- base::Bind(&GpuClient::OnGpuChannelEstablished, base::Unretained(this),
- callback));
- }
-
- void CreateGpuMemoryBuffer(
- gfx::GpuMemoryBufferId id,
- const gfx::Size& size,
- gfx::BufferFormat format,
- gfx::BufferUsage usage,
- const mojom::Gpu::CreateGpuMemoryBufferCallback& callback) override {
- auto handle = gpu_memory_buffer_manager_->CreateGpuMemoryBufferHandle(
- id, client_id_, size, format, usage, gpu::kNullSurfaceHandle);
- callback.Run(handle);
- }
-
- void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
- const gpu::SyncToken& sync_token) override {
- gpu_memory_buffer_manager_->DestroyGpuMemoryBuffer(id, client_id_,
- sync_token);
- }
-
- const int client_id_;
-
- // The objects these pointers refer to are owned by the GpuHost object.
- const gpu::GPUInfo* gpu_info_;
- ServerGpuMemoryBufferManager* gpu_memory_buffer_manager_;
- mojom::GpuService* gpu_service_;
-
- DISALLOW_COPY_AND_ASSIGN(GpuClient);
-};
-
} // namespace
GpuHost::GpuHost(GpuHostDelegate* delegate)
@@ -121,11 +57,7 @@ GpuHost::GpuHost(GpuHostDelegate* delegate)
GpuHost::~GpuHost() {}
void GpuHost::Add(mojom::GpuRequest request) {
- mojo::MakeStrongBinding(
- base::MakeUnique<GpuClient>(next_client_id_++, &gpu_info_,
- gpu_memory_buffer_manager_.get(),
- gpu_service_.get()),
- std::move(request));
+ AddInternal(std::move(request));
}
void GpuHost::OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) {
@@ -146,6 +78,15 @@ void GpuHost::CreateDisplayCompositor(
gpu_main_->CreateDisplayCompositor(std::move(request), std::move(client));
}
+GpuClient* GpuHost::AddInternal(mojom::GpuRequest request) {
+ auto client(base::MakeUnique<GpuClient>(next_client_id_++, &gpu_info_,
+ gpu_memory_buffer_manager_.get(),
+ gpu_service_.get()));
+ GpuClient* client_ref = client.get();
+ gpu_bindings_.AddBinding(std::move(client), std::move(request));
+ return client_ref;
+}
+
void GpuHost::OnBadMessageFromGpu() {
// TODO(sad): Received some unexpected message from the gpu process. We
// should kill the process and restart it.
« no previous file with comments | « services/ui/ws/gpu_host.h ('k') | services/ui/ws/gpu_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698