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