- add sources.
[platform/framework/web/crosswalk.git] / src / ui / gfx / gpu_memory_buffer.h
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.
4
5 #ifndef UI_GFX_GPU_MEMORY_BUFFER_H_
6 #define UI_GFX_GPU_MEMORY_BUFFER_H_
7
8 #include "base/memory/shared_memory.h"
9 #include "build/build_config.h"
10 #include "ui/gfx/gfx_export.h"
11
12 #if defined(OS_ANDROID)
13 #include <third_party/khronos/EGL/egl.h>
14 #endif
15
16 namespace gfx {
17
18 enum GpuMemoryBufferType {
19   EMPTY_BUFFER,
20   SHARED_MEMORY_BUFFER,
21   EGL_CLIENT_BUFFER
22 };
23
24 struct GpuMemoryBufferHandle {
25   GpuMemoryBufferHandle()
26       : type(EMPTY_BUFFER),
27         handle(base::SharedMemory::NULLHandle())
28 #if defined(OS_ANDROID)
29         , native_buffer(NULL)
30 #endif
31   {
32   }
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;
38 #endif
39 };
40
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.
44 //
45 // THREADING CONSIDERATIONS:
46 //
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 {
51  public:
52   enum AccessMode {
53     READ_ONLY,
54     WRITE_ONLY,
55     READ_WRITE,
56   };
57
58   GpuMemoryBuffer();
59   virtual ~GpuMemoryBuffer();
60
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;
65
66   // Unmaps the buffer. Called after all changes to the buffer are
67   // completed.
68   virtual void Unmap() = 0;
69
70   // Returns true iff the buffer is mapped.
71   virtual bool IsMapped() const = 0;
72
73   // Returns the stride in bytes for the buffer.
74   virtual uint32 GetStride() const = 0;
75
76   // Returns a platform specific handle for this buffer.
77   virtual GpuMemoryBufferHandle GetHandle() const = 0;
78 };
79
80 }  // namespace gfx
81
82 #endif  // UI_GFX_GPU_MEMORY_BUFFER_H_