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 #if defined(OS_ANDROID)
13 #include <third_party/khronos/EGL/egl.h>
18 enum GpuMemoryBufferType {
24 struct GpuMemoryBufferHandle {
25 GpuMemoryBufferHandle()
27 handle(base::SharedMemory::NULLHandle())
28 #if defined(OS_ANDROID)
33 bool is_null() const { return type == EMPTY_BUFFER; }
34 GpuMemoryBufferType type;
35 base::SharedMemoryHandle handle;
36 #if defined(OS_ANDROID)
37 EGLClientBuffer native_buffer;
41 // Interface for creating and accessing a zero-copy GPU memory buffer.
42 // This design evolved from the generalization of GraphicBuffer API
43 // of Android framework.
45 // THREADING CONSIDERATIONS:
47 // This interface is thread-safe. However, multiple threads mapping
48 // a buffer for Write or ReadOrWrite simultaneously may result in undefined
49 // behavior and is not allowed.
50 class GFX_EXPORT GpuMemoryBuffer {
59 virtual ~GpuMemoryBuffer();
61 // Maps the buffer so the client can write the bitmap data in |*vaddr|
62 // subsequently. This call may block, for instance if the hardware needs
63 // to finish rendering or if CPU caches need to be synchronized.
64 virtual void Map(AccessMode mode, void** vaddr) = 0;
66 // Unmaps the buffer. Called after all changes to the buffer are
68 virtual void Unmap() = 0;
70 // Returns true iff the buffer is mapped.
71 virtual bool IsMapped() const = 0;
73 // Returns the stride in bytes for the buffer.
74 virtual uint32 GetStride() const = 0;
76 // Returns a platform specific handle for this buffer.
77 virtual GpuMemoryBufferHandle GetHandle() const = 0;
82 #endif // UI_GFX_GPU_MEMORY_BUFFER_H_