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
{
25 struct GpuMemoryBufferHandle
{
26 GpuMemoryBufferHandle()
28 handle(base::SharedMemory::NULLHandle())
29 #if defined(OS_ANDROID)
32 #if defined(OS_MACOSX)
37 bool is_null() const { return type
== EMPTY_BUFFER
; }
38 GpuMemoryBufferType type
;
39 base::SharedMemoryHandle handle
;
40 #if defined(OS_ANDROID)
41 EGLClientBuffer native_buffer
;
43 #if defined(OS_MACOSX)
49 // Interface for creating and accessing a zero-copy GPU memory buffer.
50 // This design evolved from the generalization of GraphicBuffer API
51 // of Android framework.
53 // THREADING CONSIDERATIONS:
55 // This interface is thread-safe. However, multiple threads mapping
56 // a buffer for Write or ReadOrWrite simultaneously may result in undefined
57 // behavior and is not allowed.
58 class GFX_EXPORT GpuMemoryBuffer
{
67 virtual ~GpuMemoryBuffer();
69 // Maps the buffer so the client can write the bitmap data in |*vaddr|
70 // subsequently. This call may block, for instance if the hardware needs
71 // to finish rendering or if CPU caches need to be synchronized.
72 virtual void Map(AccessMode mode
, void** vaddr
) = 0;
74 // Unmaps the buffer. Called after all changes to the buffer are
76 virtual void Unmap() = 0;
78 // Returns true iff the buffer is mapped.
79 virtual bool IsMapped() const = 0;
81 // Returns the stride in bytes for the buffer.
82 virtual uint32
GetStride() const = 0;
84 // Returns a platform specific handle for this buffer.
85 virtual GpuMemoryBufferHandle
GetHandle() const = 0;
90 #endif // UI_GFX_GPU_MEMORY_BUFFER_H_