| 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/gpu/mus_gpu_memory_buffer_manager.h" | 5 #include "services/ui/ws/mus_gpu_memory_buffer_manager.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "gpu/ipc/client/gpu_memory_buffer_impl.h" | 8 #include "gpu/ipc/client/gpu_memory_buffer_impl.h" |
| 9 #include "gpu/ipc/client/gpu_memory_buffer_impl_shared_memory.h" | 9 #include "gpu/ipc/client/gpu_memory_buffer_impl_shared_memory.h" |
| 10 #include "gpu/ipc/common/gpu_memory_buffer_support.h" | 10 #include "gpu/ipc/common/gpu_memory_buffer_support.h" |
| 11 #include "gpu/ipc/service/gpu_memory_buffer_factory.h" | |
| 12 #include "services/ui/common/generic_shared_memory_id_generator.h" | 11 #include "services/ui/common/generic_shared_memory_id_generator.h" |
| 13 #include "services/ui/gpu/gpu_service_internal.h" | 12 #include "services/ui/gpu/gpu_service_internal.h" |
| 14 | 13 |
| 15 namespace ui { | 14 namespace ui { |
| 16 | 15 |
| 17 namespace { | 16 namespace { |
| 18 | 17 |
| 19 MusGpuMemoryBufferManager* g_gpu_memory_buffer_manager = nullptr; | |
| 20 | |
| 21 bool IsNativeGpuMemoryBufferFactoryConfigurationSupported( | 18 bool IsNativeGpuMemoryBufferFactoryConfigurationSupported( |
| 22 gfx::BufferFormat format, | 19 gfx::BufferFormat format, |
| 23 gfx::BufferUsage usage) { | 20 gfx::BufferUsage usage) { |
| 24 switch (gpu::GetNativeGpuMemoryBufferType()) { | 21 switch (gpu::GetNativeGpuMemoryBufferType()) { |
| 25 case gfx::SHARED_MEMORY_BUFFER: | 22 case gfx::SHARED_MEMORY_BUFFER: |
| 26 return false; | 23 return false; |
| 27 case gfx::IO_SURFACE_BUFFER: | 24 case gfx::IO_SURFACE_BUFFER: |
| 28 case gfx::SURFACE_TEXTURE_BUFFER: | 25 case gfx::SURFACE_TEXTURE_BUFFER: |
| 29 case gfx::OZONE_NATIVE_PIXMAP: | 26 case gfx::OZONE_NATIVE_PIXMAP: |
| 30 return gpu::IsNativeGpuMemoryBufferConfigurationSupported(format, usage); | 27 return gpu::IsNativeGpuMemoryBufferConfigurationSupported(format, usage); |
| 31 default: | 28 default: |
| 32 NOTREACHED(); | 29 NOTREACHED(); |
| 33 return false; | 30 return false; |
| 34 } | 31 } |
| 35 } | 32 } |
| 36 } | |
| 37 | 33 |
| 38 MusGpuMemoryBufferManager* MusGpuMemoryBufferManager::current() { | 34 } // namespace |
| 39 return g_gpu_memory_buffer_manager; | 35 |
| 40 } | 36 namespace ws { |
| 41 | 37 |
| 42 MusGpuMemoryBufferManager::MusGpuMemoryBufferManager( | 38 MusGpuMemoryBufferManager::MusGpuMemoryBufferManager( |
| 43 GpuServiceInternal* gpu_service, | 39 GpuServiceInternal* gpu_service, |
| 44 int client_id) | 40 int client_id) |
| 45 : gpu_service_(gpu_service), client_id_(client_id), weak_factory_(this) { | 41 : gpu_service_(gpu_service), client_id_(client_id), weak_factory_(this) {} |
| 46 DCHECK(!g_gpu_memory_buffer_manager); | |
| 47 g_gpu_memory_buffer_manager = this; | |
| 48 } | |
| 49 | 42 |
| 50 MusGpuMemoryBufferManager::~MusGpuMemoryBufferManager() { | 43 MusGpuMemoryBufferManager::~MusGpuMemoryBufferManager() {} |
| 51 g_gpu_memory_buffer_manager = nullptr; | |
| 52 } | |
| 53 | 44 |
| 54 std::unique_ptr<gfx::GpuMemoryBuffer> | 45 std::unique_ptr<gfx::GpuMemoryBuffer> |
| 55 MusGpuMemoryBufferManager::AllocateGpuMemoryBuffer( | 46 MusGpuMemoryBufferManager::AllocateGpuMemoryBuffer( |
| 56 const gfx::Size& size, | 47 const gfx::Size& size, |
| 57 gfx::BufferFormat format, | 48 gfx::BufferFormat format, |
| 58 gfx::BufferUsage usage, | 49 gfx::BufferUsage usage, |
| 59 gpu::SurfaceHandle surface_handle) { | 50 gpu::SurfaceHandle surface_handle) { |
| 60 gfx::GpuMemoryBufferId id = GetNextGenericSharedMemoryId(); | 51 gfx::GpuMemoryBufferId id = GetNextGenericSharedMemoryId(); |
| 61 const bool is_native = | 52 const bool is_native = |
| 62 IsNativeGpuMemoryBufferFactoryConfigurationSupported(format, usage); | 53 IsNativeGpuMemoryBufferFactoryConfigurationSupported(format, usage); |
| 63 if (is_native) { | 54 if (is_native) { |
| 64 gfx::GpuMemoryBufferHandle handle = | 55 gfx::GpuMemoryBufferHandle handle = gpu_service_->CreateGpuMemoryBuffer( |
| 65 gpu_service_->gpu_memory_buffer_factory()->CreateGpuMemoryBuffer( | 56 id, size, format, usage, client_id_, surface_handle); |
| 66 id, size, format, usage, client_id_, surface_handle); | |
| 67 if (handle.is_null()) | 57 if (handle.is_null()) |
| 68 return nullptr; | 58 return nullptr; |
| 69 return gpu::GpuMemoryBufferImpl::CreateFromHandle( | 59 return gpu::GpuMemoryBufferImpl::CreateFromHandle( |
| 70 handle, size, format, usage, | 60 handle, size, format, usage, |
| 71 base::Bind(&MusGpuMemoryBufferManager::DestroyGpuMemoryBuffer, | 61 base::Bind(&MusGpuMemoryBufferManager::DestroyGpuMemoryBuffer, |
| 72 weak_factory_.GetWeakPtr(), id, client_id_, is_native)); | 62 weak_factory_.GetWeakPtr(), id, client_id_, is_native)); |
| 73 } | 63 } |
| 74 | 64 |
| 75 DCHECK(gpu::GpuMemoryBufferImplSharedMemory::IsUsageSupported(usage)) | 65 DCHECK(gpu::GpuMemoryBufferImplSharedMemory::IsUsageSupported(usage)) |
| 76 << static_cast<int>(usage); | 66 << static_cast<int>(usage); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 101 static_cast<gpu::GpuMemoryBufferImpl*>(buffer)->set_destruction_sync_token( | 91 static_cast<gpu::GpuMemoryBufferImpl*>(buffer)->set_destruction_sync_token( |
| 102 sync_token); | 92 sync_token); |
| 103 } | 93 } |
| 104 | 94 |
| 105 void MusGpuMemoryBufferManager::DestroyGpuMemoryBuffer( | 95 void MusGpuMemoryBufferManager::DestroyGpuMemoryBuffer( |
| 106 gfx::GpuMemoryBufferId id, | 96 gfx::GpuMemoryBufferId id, |
| 107 int client_id, | 97 int client_id, |
| 108 bool is_native, | 98 bool is_native, |
| 109 const gpu::SyncToken& sync_token) { | 99 const gpu::SyncToken& sync_token) { |
| 110 if (is_native) { | 100 if (is_native) { |
| 111 gpu_service_->gpu_channel_manager()->DestroyGpuMemoryBuffer(id, client_id, | 101 gpu_service_->DestroyGpuMemoryBuffer(id, client_id, sync_token); |
| 112 sync_token); | |
| 113 } | 102 } |
| 114 } | 103 } |
| 115 | 104 |
| 105 } // namespace ws |
| 116 } // namespace ui | 106 } // namespace ui |
| OLD | NEW |