Correctly track texture cleared state for sharing
[chromium-blink-merge.git] / ui / gfx / gpu_memory_buffer.h
blobe6ce5d25af8da9069b5ae3b310c281ae8df1c36c
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;
33 #if defined(OS_MACOSX)
34 uint32 io_surface_id;
35 #endif
38 // This interface typically correspond to a type of shared memory that is also
39 // shared with the GPU. A GPU memory buffer can be written to directly by
40 // regular CPU code, but can also be read by the GPU.
41 class GFX_EXPORT GpuMemoryBuffer {
42 public:
43 // The format needs to be taken into account when mapping a buffer into the
44 // client's address space.
45 enum Format { RGBA_8888, RGBX_8888, BGRA_8888, FORMAT_LAST = BGRA_8888 };
47 // The usage mode affects how a buffer can be used. Only buffers created with
48 // MAP can be mapped into the client's address space and accessed by the CPU.
49 enum Usage { MAP, SCANOUT, USAGE_LAST = SCANOUT };
51 virtual ~GpuMemoryBuffer() {}
53 // Maps the buffer into the client's address space so it can be written to by
54 // the CPU. This call may block, for instance if the GPU needs to finish
55 // accessing the buffer or if CPU caches need to be synchronized. Returns NULL
56 // on failure.
57 virtual void* Map() = 0;
59 // Unmaps the buffer. It's illegal to use the pointer returned by Map() after
60 // this has been called.
61 virtual void Unmap() = 0;
63 // Returns true iff the buffer is mapped.
64 virtual bool IsMapped() const = 0;
66 // Returns the format for the buffer.
67 virtual Format GetFormat() const = 0;
69 // Returns the stride in bytes for the buffer.
70 virtual uint32 GetStride() 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_