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 #ifndef GPU_IPC_COMMON_GPU_MEMORY_BUFFER_SUPPORT_H_ 6 #define GPU_IPC_COMMON_GPU_MEMORY_BUFFER_SUPPORT_H_ 7 8 #include <memory> 9 10 #include "base/callback.h" 11 #include "base/macros.h" 12 #include "build/build_config.h" 13 #include "gpu/gpu_export.h" 14 #include "gpu/ipc/common/gpu_memory_buffer_impl.h" 15 #include "ui/gfx/buffer_types.h" 16 #include "ui/gfx/geometry/size.h" 17 #include "ui/gfx/gpu_memory_buffer.h" 18 19 #if defined(OS_LINUX) || defined(OS_BSD) || defined(USE_OZONE) 20 namespace gfx { 21 class ClientNativePixmapFactory; 22 } 23 #endif 24 25 namespace gpu { 26 27 // Provides a common factory for GPU memory buffer implementations. 28 class GPU_EXPORT GpuMemoryBufferSupport { 29 public: 30 GpuMemoryBufferSupport(); 31 virtual ~GpuMemoryBufferSupport(); 32 33 // Returns the native GPU memory buffer factory type. Returns EMPTY_BUFFER 34 // type if native buffers are not supported. 35 gfx::GpuMemoryBufferType GetNativeGpuMemoryBufferType(); 36 37 // Returns whether the provided buffer format is supported. 38 bool IsNativeGpuMemoryBufferConfigurationSupported(gfx::BufferFormat format, 39 gfx::BufferUsage usage); 40 41 #if defined(OS_LINUX) || defined(OS_BSD) || defined(USE_OZONE) client_native_pixmap_factory()42 gfx::ClientNativePixmapFactory* client_native_pixmap_factory() { 43 return client_native_pixmap_factory_.get(); 44 } 45 #endif 46 47 // Returns whether the provided buffer format is supported. 48 bool IsConfigurationSupportedForTest(gfx::GpuMemoryBufferType type, 49 gfx::BufferFormat format, 50 gfx::BufferUsage usage); 51 52 // Creates a GpuMemoryBufferImpl from the given |handle|. |size| and |format| 53 // should match what was used to allocate the |handle|. |callback|, if 54 // non-null, is called when instance is deleted, which is not necessarily on 55 // the same thread as this function was called on and instance was created on. 56 virtual std::unique_ptr<GpuMemoryBufferImpl> 57 CreateGpuMemoryBufferImplFromHandle( 58 gfx::GpuMemoryBufferHandle handle, 59 const gfx::Size& size, 60 gfx::BufferFormat format, 61 gfx::BufferUsage usage, 62 GpuMemoryBufferImpl::DestructionCallback callback); 63 64 private: 65 #if defined(OS_LINUX) || defined(OS_BSD) || defined(USE_OZONE) 66 std::unique_ptr<gfx::ClientNativePixmapFactory> client_native_pixmap_factory_; 67 #endif 68 69 DISALLOW_COPY_AND_ASSIGN(GpuMemoryBufferSupport); 70 }; 71 72 } // namespace gpu 73 74 #endif // GPU_IPC_COMMON_GPU_MEMORY_BUFFER_SUPPORT_H_ 75