Atomic: Notify Watcher to observe device fd
[chromium-blink-merge.git] / ui / gfx / gpu_memory_buffer.h
blob263a0ef41da40ddd140556c2ccc0d73d51a30afe
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/gfx_export.h"
14 extern "C" typedef struct _ClientBuffer* ClientBuffer;
16 namespace gfx {
18 enum GpuMemoryBufferType {
19 EMPTY_BUFFER,
20 SHARED_MEMORY_BUFFER,
21 IO_SURFACE_BUFFER,
22 SURFACE_TEXTURE_BUFFER,
23 OZONE_NATIVE_PIXMAP,
24 GPU_MEMORY_BUFFER_TYPE_LAST = OZONE_NATIVE_PIXMAP
27 using GpuMemoryBufferId = int32;
29 struct GFX_EXPORT GpuMemoryBufferHandle {
30 GpuMemoryBufferHandle();
31 bool is_null() const { return type == EMPTY_BUFFER; }
32 GpuMemoryBufferType type;
33 GpuMemoryBufferId id;
34 base::SharedMemoryHandle handle;
37 base::trace_event::MemoryAllocatorDumpGuid GFX_EXPORT
38 GetGpuMemoryBufferGUIDForTracing(uint64 tracing_process_id,
39 GpuMemoryBufferId buffer_id);
41 // This interface typically correspond to a type of shared memory that is also
42 // shared with the GPU. A GPU memory buffer can be written to directly by
43 // regular CPU code, but can also be read by the GPU.
44 class GFX_EXPORT GpuMemoryBuffer {
45 public:
46 virtual ~GpuMemoryBuffer() {}
48 // Maps each plane of the buffer into the client's address space so it can be
49 // written to by the CPU. A pointer to plane K is stored at index K-1 of the
50 // |data| array. This call may block, for instance if the GPU needs to finish
51 // accessing the buffer or if CPU caches need to be synchronized. Returns
52 // false on failure.
53 virtual bool Map(void** data) = 0;
55 // Unmaps the buffer. It's illegal to use the pointer returned by Map() after
56 // this has been called.
57 virtual void Unmap() = 0;
59 // Returns true iff the buffer is mapped.
60 virtual bool IsMapped() const = 0;
62 // Returns the format for the buffer.
63 virtual BufferFormat GetFormat() const = 0;
65 // Fills the stride in bytes for each plane of the buffer. The stride of
66 // plane K is stored at index K-1 of the |stride| array.
67 virtual void GetStride(int* stride) const = 0;
69 // Returns a unique identifier associated with buffer.
70 virtual GpuMemoryBufferId GetId() const = 0;
72 // Returns a platform specific handle for this buffer.
73 virtual GpuMemoryBufferHandle GetHandle() const = 0;
75 // Type-checking downcast routine.
76 virtual ClientBuffer AsClientBuffer() = 0;
79 } // namespace gfx
81 #endif // UI_GFX_GPU_MEMORY_BUFFER_H_