Roll third_party/android_tools to the latest: updated the support library to 19.0.1
[chromium-blink-merge.git] / ui / gfx / gpu_memory_buffer.h
blob4a7b142d175fb517065d977003a9397e7459c0c5
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>
14 #endif
16 namespace gfx {
18 enum GpuMemoryBufferType {
19 EMPTY_BUFFER,
20 SHARED_MEMORY_BUFFER,
21 EGL_CLIENT_BUFFER,
22 IO_SURFACE_BUFFER
25 struct GpuMemoryBufferHandle {
26 GpuMemoryBufferHandle()
27 : type(EMPTY_BUFFER),
28 handle(base::SharedMemory::NULLHandle())
29 #if defined(OS_ANDROID)
30 , native_buffer(NULL)
31 #endif
32 #if defined(OS_MACOSX)
33 , io_surface_id(0)
34 #endif
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;
42 #endif
43 #if defined(OS_MACOSX)
44 uint32 io_surface_id;
45 #endif
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 {
59 public:
60 enum AccessMode {
61 READ_ONLY,
62 WRITE_ONLY,
63 READ_WRITE,
66 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
75 // completed.
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;
88 } // namespace gfx
90 #endif // UI_GFX_GPU_MEMORY_BUFFER_H_