| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/gpu/gpu_client.h" |
| 6 |
| 7 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" |
| 8 #include "content/browser/gpu/gpu_process_host.h" |
| 9 #include "content/common/child_process_host_impl.h" |
| 10 #include "content/public/browser/browser_thread.h" |
| 11 #include "gpu/ipc/client/gpu_channel_host.h" |
| 12 #include "gpu/ipc/client/gpu_memory_buffer_impl.h" |
| 13 #include "gpu/ipc/client/gpu_memory_buffer_impl_shared_memory.h" |
| 14 |
| 15 namespace content { |
| 16 |
| 17 GpuClient::GpuClient(int render_process_id) |
| 18 : render_process_id_(render_process_id), weak_factory_(this) { |
| 19 bindings_.set_connection_error_handler( |
| 20 base::Bind(&GpuClient::OnError, base::Unretained(this))); |
| 21 } |
| 22 |
| 23 GpuClient::~GpuClient() { |
| 24 bindings_.CloseAllBindings(); |
| 25 OnError(); |
| 26 } |
| 27 |
| 28 void GpuClient::Add(ui::mojom::GpuRequest request) { |
| 29 bindings_.AddBinding(this, std::move(request)); |
| 30 } |
| 31 |
| 32 void GpuClient::OnError() { |
| 33 if (!bindings_.empty()) |
| 34 return; |
| 35 BrowserGpuMemoryBufferManager* gpu_memory_buffer_manager = |
| 36 BrowserGpuMemoryBufferManager::current(); |
| 37 if (gpu_memory_buffer_manager) |
| 38 gpu_memory_buffer_manager->ProcessRemoved(render_process_id_); |
| 39 } |
| 40 |
| 41 void GpuClient::OnEstablishGpuChannel( |
| 42 const EstablishGpuChannelCallback& callback, |
| 43 const IPC::ChannelHandle& channel, |
| 44 const gpu::GPUInfo& gpu_info) { |
| 45 mojo::ScopedMessagePipeHandle channel_handle; |
| 46 channel_handle.reset(channel.mojo_handle); |
| 47 callback.Run(render_process_id_, std::move(channel_handle), gpu_info); |
| 48 } |
| 49 |
| 50 void GpuClient::OnCreateGpuMemoryBuffer( |
| 51 const CreateGpuMemoryBufferCallback& callback, |
| 52 const gfx::GpuMemoryBufferHandle& handle) { |
| 53 callback.Run(handle); |
| 54 } |
| 55 |
| 56 void GpuClient::EstablishGpuChannel( |
| 57 const EstablishGpuChannelCallback& callback) { |
| 58 GpuProcessHost* host = |
| 59 GpuProcessHost::Get(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED); |
| 60 if (!host) { |
| 61 OnEstablishGpuChannel(callback, IPC::ChannelHandle(), gpu::GPUInfo()); |
| 62 return; |
| 63 } |
| 64 |
| 65 bool preempts = false; |
| 66 bool allow_view_command_buffers = false; |
| 67 bool allow_real_time_streams = false; |
| 68 host->EstablishGpuChannel( |
| 69 render_process_id_, |
| 70 ChildProcessHostImpl::ChildProcessUniqueIdToTracingProcessId( |
| 71 render_process_id_), |
| 72 preempts, allow_view_command_buffers, allow_real_time_streams, |
| 73 base::Bind(&GpuClient::OnEstablishGpuChannel, weak_factory_.GetWeakPtr(), |
| 74 callback)); |
| 75 } |
| 76 |
| 77 void GpuClient::CreateGpuMemoryBuffer( |
| 78 gfx::GpuMemoryBufferId id, |
| 79 const gfx::Size& size, |
| 80 gfx::BufferFormat format, |
| 81 gfx::BufferUsage usage, |
| 82 const ui::mojom::Gpu::CreateGpuMemoryBufferCallback& callback) { |
| 83 DCHECK(BrowserGpuMemoryBufferManager::current()); |
| 84 |
| 85 base::CheckedNumeric<int> bytes = size.width(); |
| 86 bytes *= size.height(); |
| 87 if (!bytes.IsValid()) { |
| 88 OnCreateGpuMemoryBuffer(callback, gfx::GpuMemoryBufferHandle()); |
| 89 return; |
| 90 } |
| 91 |
| 92 BrowserGpuMemoryBufferManager::current() |
| 93 ->AllocateGpuMemoryBufferForChildProcess( |
| 94 id, size, format, usage, render_process_id_, |
| 95 base::Bind(&GpuClient::OnCreateGpuMemoryBuffer, |
| 96 weak_factory_.GetWeakPtr(), callback)); |
| 97 } |
| 98 |
| 99 void GpuClient::DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, |
| 100 const gpu::SyncToken& sync_token) { |
| 101 DCHECK(BrowserGpuMemoryBufferManager::current()); |
| 102 |
| 103 BrowserGpuMemoryBufferManager::current()->ChildProcessDeletedGpuMemoryBuffer( |
| 104 id, render_process_id_, sync_token); |
| 105 } |
| 106 |
| 107 } // namespace content |
| OLD | NEW |