Chromium Code Reviews| OLD | NEW | 
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "services/ui/ws/gpu_service_proxy.h" | 5 #include "services/ui/ws/gpu_service_proxy.h" | 
| 6 | 6 | 
| 7 #include "base/memory/shared_memory.h" | 7 #include "base/memory/shared_memory.h" | 
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" | 
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" | 
| 10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" | 
| 11 #include "gpu/ipc/client/gpu_channel_host.h" | 11 #include "gpu/ipc/client/gpu_channel_host.h" | 
| 12 #include "gpu/ipc/client/gpu_memory_buffer_impl_shared_memory.h" | |
| 13 #include "mojo/public/cpp/system/buffer.h" | |
| 14 #include "mojo/public/cpp/system/platform_handle.h" | |
| 12 #include "services/service_manager/public/cpp/connection.h" | 15 #include "services/service_manager/public/cpp/connection.h" | 
| 13 #include "services/ui/ws/gpu_service_proxy_delegate.h" | 16 #include "services/ui/ws/gpu_service_proxy_delegate.h" | 
| 14 #include "services/ui/ws/mus_gpu_memory_buffer_manager.h" | 17 #include "services/ui/ws/mus_gpu_memory_buffer_manager.h" | 
| 18 #include "ui/gfx/buffer_format_util.h" | |
| 15 | 19 | 
| 16 namespace ui { | 20 namespace ui { | 
| 17 namespace ws { | 21 namespace ws { | 
| 18 | 22 | 
| 19 namespace { | 23 namespace { | 
| 20 | 24 | 
| 21 const int32_t kInternalGpuChannelClientId = 1; | 25 const int32_t kInternalGpuChannelClientId = 1; | 
| 22 const uint64_t kInternalGpuChannelClientTracingId = 1; | 26 const uint64_t kInternalGpuChannelClientTracingId = 1; | 
| 23 | 27 | 
| 24 } // namespace | 28 } // namespace | 
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 client_id, client_tracing_id, is_gpu_host, | 95 client_id, client_tracing_id, is_gpu_host, | 
| 92 base::Bind(&GpuServiceProxy::OnGpuChannelEstablished, | 96 base::Bind(&GpuServiceProxy::OnGpuChannelEstablished, | 
| 93 base::Unretained(this), callback, client_id)); | 97 base::Unretained(this), callback, client_id)); | 
| 94 } | 98 } | 
| 95 | 99 | 
| 96 void GpuServiceProxy::CreateGpuMemoryBuffer( | 100 void GpuServiceProxy::CreateGpuMemoryBuffer( | 
| 97 gfx::GpuMemoryBufferId id, | 101 gfx::GpuMemoryBufferId id, | 
| 98 const gfx::Size& size, | 102 const gfx::Size& size, | 
| 99 gfx::BufferFormat format, | 103 gfx::BufferFormat format, | 
| 100 gfx::BufferUsage usage, | 104 gfx::BufferUsage usage, | 
| 101 uint64_t surface_id, | |
| 102 const mojom::GpuService::CreateGpuMemoryBufferCallback& callback) { | 105 const mojom::GpuService::CreateGpuMemoryBufferCallback& callback) { | 
| 103 NOTIMPLEMENTED(); | 106 // TODO(sad): Check to see if native gpu memory buffer can be used first. | 
| 107 if (!gpu::GpuMemoryBufferImplSharedMemory::IsUsageSupported(usage) || | |
| 108 !gpu::GpuMemoryBufferImplSharedMemory::IsSizeValidForFormat(size, | |
| 109 format)) { | |
| 110 callback.Run(gfx::GpuMemoryBufferHandle()); | |
| 111 return; | |
| 112 } | |
| 113 | |
| 114 size_t bytes = 0; | |
| 115 if (!gfx::BufferSizeForBufferFormatChecked(size, format, &bytes)) { | |
| 116 callback.Run(gfx::GpuMemoryBufferHandle()); | |
| 117 return; | |
| 118 } | |
| 119 | |
| 120 mojo::ScopedSharedBufferHandle mojo_handle = | |
| 121 mojo::SharedBufferHandle::Create(bytes); | |
| 122 if (!mojo_handle.is_valid()) { | |
| 123 callback.Run(gfx::GpuMemoryBufferHandle()); | |
| 124 return; | |
| 125 } | |
| 126 | |
| 127 base::SharedMemoryHandle shm_handle; | |
| 128 size_t shm_size; | |
| 129 bool readonly; | |
| 130 MojoResult result = mojo::UnwrapSharedMemoryHandle( | |
| 131 std::move(mojo_handle), &shm_handle, &shm_size, &readonly); | |
| 132 if (result != MOJO_RESULT_OK) { | |
| 133 callback.Run(gfx::GpuMemoryBufferHandle()); | |
| 134 return; | |
| 135 } | |
| 136 DCHECK_EQ(shm_size, bytes); | |
| 137 DCHECK(!readonly); | |
| 138 const int stride = base::checked_cast<int>( | |
| 139 gfx::RowSizeForBufferFormat(size.width(), format, 0)); | |
| 140 | |
| 141 gfx::GpuMemoryBufferHandle gmb_handle; | |
| 142 gmb_handle.type = gfx::SHARED_MEMORY_BUFFER; | |
| 143 gmb_handle.id = id; | |
| 144 gmb_handle.handle = shm_handle; | |
| 145 gmb_handle.offset = 0; | |
| 146 gmb_handle.stride = stride; | |
| 147 callback.Run(gmb_handle); | |
| 104 } | 148 } | 
| 105 | 149 | 
| 106 void GpuServiceProxy::DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, | 150 void GpuServiceProxy::DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, | 
| 107 const gpu::SyncToken& sync_token) { | 151 const gpu::SyncToken& sync_token) { | 
| 
 
reveman
2016/11/08 19:46:45
fyi: this sync_token is only needed for macos and
 
 | |
| 108 NOTIMPLEMENTED(); | 152 // NOTIMPLEMENTED(); | 
| 109 } | 153 } | 
| 110 | 154 | 
| 111 bool GpuServiceProxy::IsMainThread() { | 155 bool GpuServiceProxy::IsMainThread() { | 
| 112 return main_thread_task_runner_->BelongsToCurrentThread(); | 156 return main_thread_task_runner_->BelongsToCurrentThread(); | 
| 113 } | 157 } | 
| 114 | 158 | 
| 115 scoped_refptr<base::SingleThreadTaskRunner> | 159 scoped_refptr<base::SingleThreadTaskRunner> | 
| 116 GpuServiceProxy::GetIOThreadTaskRunner() { | 160 GpuServiceProxy::GetIOThreadTaskRunner() { | 
| 117 return io_thread_->task_runner(); | 161 return io_thread_->task_runner(); | 
| 118 } | 162 } | 
| 119 | 163 | 
| 120 std::unique_ptr<base::SharedMemory> GpuServiceProxy::AllocateSharedMemory( | 164 std::unique_ptr<base::SharedMemory> GpuServiceProxy::AllocateSharedMemory( | 
| 121 size_t size) { | 165 size_t size) { | 
| 122 std::unique_ptr<base::SharedMemory> shm(new base::SharedMemory()); | 166 std::unique_ptr<base::SharedMemory> shm(new base::SharedMemory()); | 
| 123 if (!shm->CreateAnonymous(size)) | 167 if (!shm->CreateAnonymous(size)) | 
| 124 shm.reset(); | 168 shm.reset(); | 
| 125 return shm; | 169 return shm; | 
| 126 } | 170 } | 
| 127 | 171 | 
| 128 } // namespace ws | 172 } // namespace ws | 
| 129 } // namespace ui | 173 } // namespace ui | 
| OLD | NEW |