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"
13 #include "ui/gfx/x/x11_types.h"
18 enum GpuMemoryBufferType
{
22 ANDROID_NATIVE_BUFFER
,
23 SURFACE_TEXTURE_BUFFER
,
26 GPU_MEMORY_BUFFER_TYPE_LAST
= OZONE_NATIVE_BUFFER
29 // TODO(alexst): Merge this with GpuMemoryBufferId as part of switchover to
30 // the new API for GpuMemoryBuffer allocation when it's done.
31 #if defined(OS_ANDROID)
32 struct SurfaceTextureId
{
33 SurfaceTextureId() : primary_id(0), secondary_id(0) {}
34 SurfaceTextureId(int32 primary_id
, int32 secondary_id
)
35 : primary_id(primary_id
), secondary_id(secondary_id
) {}
41 struct GpuMemoryBufferId
{
42 GpuMemoryBufferId() : primary_id(0), secondary_id(0) {}
43 GpuMemoryBufferId(int32 primary_id
, int32 secondary_id
)
44 : primary_id(primary_id
), secondary_id(secondary_id
) {}
49 struct GFX_EXPORT GpuMemoryBufferHandle
{
50 GpuMemoryBufferHandle();
51 bool is_null() const { return type
== EMPTY_BUFFER
; }
52 GpuMemoryBufferType type
;
53 base::SharedMemoryHandle handle
;
54 GpuMemoryBufferId global_id
;
55 #if defined(OS_MACOSX)
58 #if defined(OS_ANDROID)
60 SurfaceTextureId surface_texture_id
;
67 // This interface typically correspond to a type of shared memory that is also
68 // shared with the GPU. A GPU memory buffer can be written to directly by
69 // regular CPU code, but can also be read by the GPU.
70 class GFX_EXPORT GpuMemoryBuffer
{
73 virtual ~GpuMemoryBuffer();
75 // Maps the buffer into the client's address space so it can be written to by
76 // the CPU. This call may block, for instance if the GPU needs to finish
77 // accessing the buffer or if CPU caches need to be synchronized. Returns NULL
79 virtual void* Map() = 0;
81 // Unmaps the buffer. It's illegal to use the pointer returned by Map() after
82 // this has been called.
83 virtual void Unmap() = 0;
85 // Returns true iff the buffer is mapped.
86 virtual bool IsMapped() const = 0;
88 // Returns the stride in bytes for the buffer.
89 virtual uint32
GetStride() const = 0;
91 // Returns a platform specific handle for this buffer.
92 virtual GpuMemoryBufferHandle
GetHandle() const = 0;
97 #endif // UI_GFX_GPU_MEMORY_BUFFER_H_