1 // Copyright 2017 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 MEDIA_GPU_TEST_LOCAL_GPU_MEMORY_BUFFER_MANAGER_H_
6 #define MEDIA_GPU_TEST_LOCAL_GPU_MEMORY_BUFFER_MANAGER_H_
7 
8 #include <memory>
9 
10 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h"
11 #include "media/gpu/media_gpu_export.h"
12 #include "ui/gfx/buffer_types.h"
13 
14 struct gbm_device;
15 
16 namespace gfx {
17 class GpuMemoryBuffer;
18 struct NativePixmapHandle;
19 class Size;
20 }  // namespace gfx
21 
22 namespace media {
23 
24 // A local, as opposed to the default IPC-based, implementation of
25 // gfx::GpuMemoryBufferManager which interacts with the DRM render node device
26 // directly. The LocalGpuMemoryBufferManager is only for testing purposes and
27 // should not be used in production.
28 class MEDIA_GPU_EXPORT LocalGpuMemoryBufferManager
29     : public gpu::GpuMemoryBufferManager {
30  public:
31   LocalGpuMemoryBufferManager();
32 
33   // gpu::GpuMemoryBufferManager implementation
34   ~LocalGpuMemoryBufferManager() override;
35   std::unique_ptr<gfx::GpuMemoryBuffer> CreateGpuMemoryBuffer(
36       const gfx::Size& size,
37       gfx::BufferFormat format,
38       gfx::BufferUsage usage,
39       gpu::SurfaceHandle surface_handle) override;
40   void SetDestructionSyncToken(gfx::GpuMemoryBuffer* buffer,
41                                const gpu::SyncToken& sync_token) override;
42 
43   // Imports a DmaBuf as a GpuMemoryBuffer to be able to map it. The
44   // GBM_BO_USE_SW_READ_OFTEN usage is specified so that the user of the
45   // returned GpuMemoryBuffer is guaranteed to have a linear view when mapping
46   // it.
47   std::unique_ptr<gfx::GpuMemoryBuffer> ImportDmaBuf(
48       const gfx::NativePixmapHandle& handle,
49       const gfx::Size& size,
50       gfx::BufferFormat format);
51 
52   // Returns true if the combination of |format| and |usage| is supported by
53   // CreateGpuMemoryBuffer().
54   bool IsFormatAndUsageSupported(gfx::BufferFormat format,
55                                  gfx::BufferUsage usage);
56 
57  private:
58   gbm_device* gbm_device_;
59 
60   DISALLOW_COPY_AND_ASSIGN(LocalGpuMemoryBufferManager);
61 };
62 
63 }  // namespace media
64 
65 #endif  // MEDIA_GPU_TEST_LOCAL_GPU_MEMORY_BUFFER_MANAGER_H_
66