1 // Copyright 2013 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.
5 #ifndef UI_GFX_GPU_MEMORY_BUFFER_H_
6 #define UI_GFX_GPU_MEMORY_BUFFER_H_
8 #include "base/memory/shared_memory.h"
9 #include "base/trace_event/memory_dump_manager.h"
10 #include "build/build_config.h"
11 #include "ui/gfx/buffer_types.h"
12 #include "ui/gfx/generic_shared_memory_id.h"
13 #include "ui/gfx/gfx_export.h"
15 #if defined(USE_OZONE)
16 #include "ui/gfx/native_pixmap_handle_ozone.h"
19 extern "C" typedef struct _ClientBuffer
* ClientBuffer
;
23 enum GpuMemoryBufferType
{
27 SURFACE_TEXTURE_BUFFER
,
29 GPU_MEMORY_BUFFER_TYPE_LAST
= OZONE_NATIVE_PIXMAP
32 using GpuMemoryBufferId
= gfx::GenericSharedMemoryId
;
34 struct GFX_EXPORT GpuMemoryBufferHandle
{
35 GpuMemoryBufferHandle();
36 bool is_null() const { return type
== EMPTY_BUFFER
; }
37 GpuMemoryBufferType type
;
39 base::SharedMemoryHandle handle
;
40 #if defined(USE_OZONE)
41 NativePixmapHandle native_pixmap_handle
;
45 base::trace_event::MemoryAllocatorDumpGuid GFX_EXPORT
46 GetGpuMemoryBufferGUIDForTracing(uint64 tracing_process_id
,
47 GpuMemoryBufferId buffer_id
);
49 // This interface typically correspond to a type of shared memory that is also
50 // shared with the GPU. A GPU memory buffer can be written to directly by
51 // regular CPU code, but can also be read by the GPU.
52 class GFX_EXPORT GpuMemoryBuffer
{
54 virtual ~GpuMemoryBuffer() {}
56 // Maps each plane of the buffer into the client's address space so it can be
57 // written to by the CPU. A pointer to plane K is stored at index K-1 of the
58 // |data| array. This call may block, for instance if the GPU needs to finish
59 // accessing the buffer or if CPU caches need to be synchronized. Returns
61 virtual bool Map(void** data
) = 0;
63 // Unmaps the buffer. It's illegal to use the pointer returned by Map() after
64 // this has been called.
65 virtual void Unmap() = 0;
67 // Returns true iff the buffer is mapped.
68 virtual bool IsMapped() const = 0;
70 // Returns the format for the buffer.
71 virtual BufferFormat
GetFormat() const = 0;
73 // Fills the stride in bytes for each plane of the buffer. The stride of
74 // plane K is stored at index K-1 of the |stride| array.
75 virtual void GetStride(int* stride
) const = 0;
77 // Returns a unique identifier associated with buffer.
78 virtual GpuMemoryBufferId
GetId() const = 0;
80 // Returns a platform specific handle for this buffer.
81 virtual GpuMemoryBufferHandle
GetHandle() const = 0;
83 // Type-checking downcast routine.
84 virtual ClientBuffer
AsClientBuffer() = 0;
89 #endif // UI_GFX_GPU_MEMORY_BUFFER_H_