Shorten audio_modem test_support target to just "test_support".
[chromium-blink-merge.git] / ui / gfx / gpu_memory_buffer.h
blobaefad9dc9dad1c17617ece2b9243bcc37d51cdb3
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 "build/build_config.h"
10 #include "ui/gfx/gfx_export.h"
12 extern "C" typedef struct _ClientBuffer* ClientBuffer;
14 namespace gfx {
16 enum GpuMemoryBufferType {
17 EMPTY_BUFFER,
18 SHARED_MEMORY_BUFFER,
19 IO_SURFACE_BUFFER,
20 SURFACE_TEXTURE_BUFFER,
21 OZONE_NATIVE_BUFFER,
22 GPU_MEMORY_BUFFER_TYPE_LAST = OZONE_NATIVE_BUFFER
25 using GpuMemoryBufferId = int32;
27 struct GFX_EXPORT GpuMemoryBufferHandle {
28 GpuMemoryBufferHandle();
29 bool is_null() const { return type == EMPTY_BUFFER; }
30 GpuMemoryBufferType type;
31 GpuMemoryBufferId id;
32 base::SharedMemoryHandle handle;
35 // This interface typically correspond to a type of shared memory that is also
36 // shared with the GPU. A GPU memory buffer can be written to directly by
37 // regular CPU code, but can also be read by the GPU.
38 class GFX_EXPORT GpuMemoryBuffer {
39 public:
40 // The format needs to be taken into account when mapping a buffer into the
41 // client's address space.
42 enum Format {
43 ATC,
44 ATCIA,
45 DXT1,
46 DXT5,
47 ETC1,
48 R_8,
49 RGBA_4444,
50 RGBA_8888,
51 RGBX_8888,
52 BGRA_8888,
53 YUV_420,
55 FORMAT_LAST = YUV_420
58 // The usage mode affects how a buffer can be used. Only buffers created with
59 // MAP can be mapped into the client's address space and accessed by the CPU.
60 // PERSISTENT_MAP adds the additional condition that successive Map() calls
61 // (with Unmap() calls between) will return a pointer to the same memory
62 // contents.
63 enum Usage { MAP, PERSISTENT_MAP, SCANOUT, USAGE_LAST = SCANOUT };
65 virtual ~GpuMemoryBuffer() {}
67 // Maps each plane of the buffer into the client's address space so it can be
68 // written to by the CPU. A pointer to plane K is stored at index K-1 of the
69 // |data| array. This call may block, for instance if the GPU needs to finish
70 // accessing the buffer or if CPU caches need to be synchronized. Returns
71 // false on failure.
72 virtual bool Map(void** data) = 0;
74 // Unmaps the buffer. It's illegal to use the pointer returned by Map() after
75 // this has been called.
76 virtual void Unmap() = 0;
78 // Returns true iff the buffer is mapped.
79 virtual bool IsMapped() const = 0;
81 // Returns the format for the buffer.
82 virtual Format GetFormat() const = 0;
84 // Fills the stride in bytes for each plane of the buffer. The stride of
85 // plane K is stored at index K-1 of the |stride| array.
86 virtual void GetStride(int* stride) const = 0;
88 // Returns a platform specific handle for this buffer.
89 virtual GpuMemoryBufferHandle GetHandle() const = 0;
91 // Type-checking downcast routine.
92 virtual ClientBuffer AsClientBuffer() = 0;
95 } // namespace gfx
97 #endif // UI_GFX_GPU_MEMORY_BUFFER_H_