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
{
22 ANDROID_NATIVE_BUFFER
,
23 SURFACE_TEXTURE_BUFFER
,
24 GPU_MEMORY_BUFFER_TYPE_LAST
= SURFACE_TEXTURE_BUFFER
27 // TODO(alexst): Merge this with GpuMemoryBufferId as part of switchover to
28 // the new API for GpuMemoryBuffer allocation when it's done.
29 #if defined(OS_ANDROID)
30 struct SurfaceTextureId
{
31 SurfaceTextureId() : primary_id(0), secondary_id(0) {}
32 SurfaceTextureId(int32 primary_id
, int32 secondary_id
)
33 : primary_id(primary_id
), secondary_id(secondary_id
) {}
39 struct GpuMemoryBufferId
{
40 GpuMemoryBufferId() : primary_id(0), secondary_id(0) {}
41 GpuMemoryBufferId(int32 primary_id
, int32 secondary_id
)
42 : primary_id(primary_id
), secondary_id(secondary_id
) {}
47 struct GFX_EXPORT GpuMemoryBufferHandle
{
48 GpuMemoryBufferHandle();
49 bool is_null() const { return type
== EMPTY_BUFFER
; }
50 GpuMemoryBufferType type
;
51 base::SharedMemoryHandle handle
;
52 GpuMemoryBufferId global_id
;
53 #if defined(OS_MACOSX)
56 #if defined(OS_ANDROID)
57 EGLClientBuffer native_buffer
;
58 SurfaceTextureId surface_texture_id
;
62 // This interface typically correspond to a type of shared memory that is also
63 // shared with the GPU. A GPU memory buffer can be written to directly by
64 // regular CPU code, but can also be read by the GPU.
65 class GFX_EXPORT GpuMemoryBuffer
{
68 virtual ~GpuMemoryBuffer();
70 // Maps the buffer into the client's address space so it can be written to by
71 // the CPU. This call may block, for instance if the GPU needs to finish
72 // accessing the buffer or if CPU caches need to be synchronized. Returns NULL
74 virtual void* Map() = 0;
76 // Unmaps the buffer. It's illegal to use the pointer returned by Map() after
77 // this has been called.
78 virtual void Unmap() = 0;
80 // Returns true iff the buffer is mapped.
81 virtual bool IsMapped() const = 0;
83 // Returns the stride in bytes for the buffer.
84 virtual uint32
GetStride() const = 0;
86 // Returns a platform specific handle for this buffer.
87 virtual GpuMemoryBufferHandle
GetHandle() const = 0;
92 #endif // UI_GFX_GPU_MEMORY_BUFFER_H_