OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_GFX_GPU_MEMORY_BUFFER_H_ | 5 #ifndef UI_GFX_GPU_MEMORY_BUFFER_H_ |
6 #define UI_GFX_GPU_MEMORY_BUFFER_H_ | 6 #define UI_GFX_GPU_MEMORY_BUFFER_H_ |
7 | 7 |
8 #include "base/memory/shared_memory.h" | 8 #include "base/memory/shared_memory.h" |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 #include "ui/gfx/gfx_export.h" | 10 #include "ui/gfx/gfx_export.h" |
11 | 11 |
12 #if defined(USE_X11) | |
13 #include "ui/gfx/x/x11_types.h" | |
14 #endif | |
15 | |
16 extern "C" typedef struct _ClientBuffer* ClientBuffer; | 12 extern "C" typedef struct _ClientBuffer* ClientBuffer; |
17 | 13 |
18 namespace gfx { | 14 namespace gfx { |
19 | 15 |
20 enum GpuMemoryBufferType { | 16 enum GpuMemoryBufferType { |
21 EMPTY_BUFFER, | 17 EMPTY_BUFFER, |
22 SHARED_MEMORY_BUFFER, | 18 SHARED_MEMORY_BUFFER, |
23 IO_SURFACE_BUFFER, | 19 IO_SURFACE_BUFFER, |
24 SURFACE_TEXTURE_BUFFER, | 20 SURFACE_TEXTURE_BUFFER, |
25 X11_PIXMAP_BUFFER, | |
26 OZONE_NATIVE_BUFFER, | 21 OZONE_NATIVE_BUFFER, |
27 GPU_MEMORY_BUFFER_TYPE_LAST = OZONE_NATIVE_BUFFER | 22 GPU_MEMORY_BUFFER_TYPE_LAST = OZONE_NATIVE_BUFFER |
28 }; | 23 }; |
29 | 24 |
30 struct GpuMemoryBufferId { | 25 using GpuMemoryBufferId = int32; |
31 GpuMemoryBufferId() : primary_id(0), secondary_id(0) {} | |
32 GpuMemoryBufferId(int32 primary_id, int32 secondary_id) | |
33 : primary_id(primary_id), secondary_id(secondary_id) {} | |
34 int32 primary_id; | |
35 int32 secondary_id; | |
36 }; | |
37 | 26 |
38 struct GFX_EXPORT GpuMemoryBufferHandle { | 27 struct GFX_EXPORT GpuMemoryBufferHandle { |
39 GpuMemoryBufferHandle(); | 28 GpuMemoryBufferHandle(); |
40 bool is_null() const { return type == EMPTY_BUFFER; } | 29 bool is_null() const { return type == EMPTY_BUFFER; } |
41 GpuMemoryBufferType type; | 30 GpuMemoryBufferType type; |
| 31 GpuMemoryBufferId id; |
42 base::SharedMemoryHandle handle; | 32 base::SharedMemoryHandle handle; |
43 GpuMemoryBufferId global_id; | 33 #if defined(OS_MACOSX) |
44 #if defined(USE_X11) | 34 uint32 io_surface_id; |
45 XID pixmap; | |
46 #endif | 35 #endif |
47 }; | 36 }; |
48 | 37 |
49 // This interface typically correspond to a type of shared memory that is also | 38 // This interface typically correspond to a type of shared memory that is also |
50 // shared with the GPU. A GPU memory buffer can be written to directly by | 39 // shared with the GPU. A GPU memory buffer can be written to directly by |
51 // regular CPU code, but can also be read by the GPU. | 40 // regular CPU code, but can also be read by the GPU. |
52 class GFX_EXPORT GpuMemoryBuffer { | 41 class GFX_EXPORT GpuMemoryBuffer { |
53 public: | 42 public: |
54 // The format needs to be taken into account when mapping a buffer into the | 43 // The format needs to be taken into account when mapping a buffer into the |
55 // client's address space. | 44 // client's address space. |
56 enum Format { | 45 enum Format { |
57 ATC, | 46 ATC, |
58 ATCIA, | 47 ATCIA, |
59 DXT1, | 48 DXT1, |
60 DXT5, | 49 DXT5, |
61 ETC1, | 50 ETC1, |
62 RGBA_8888, | 51 RGBA_8888, |
63 RGBX_8888, | 52 RGBX_8888, |
64 BGRA_8888, | 53 BGRA_8888, |
65 FORMAT_LAST = BGRA_8888 | 54 FORMAT_LAST = BGRA_8888 |
66 }; | 55 }; |
67 | 56 |
68 // The usage mode affects how a buffer can be used. Only buffers created with | 57 // The usage mode affects how a buffer can be used. Only buffers created with |
69 // MAP can be mapped into the client's address space and accessed by the CPU. | 58 // MAP can be mapped into the client's address space and accessed by the CPU. |
70 enum Usage { MAP, SCANOUT, USAGE_LAST = SCANOUT }; | 59 // PERSISTENT_MAP adds the additional condition that successive Map() calls |
| 60 // (with Unmap() calls between) will return a pointer to the same memory |
| 61 // contents. |
| 62 enum Usage { MAP, PERSISTENT_MAP, SCANOUT, USAGE_LAST = SCANOUT }; |
71 | 63 |
72 virtual ~GpuMemoryBuffer() {} | 64 virtual ~GpuMemoryBuffer() {} |
73 | 65 |
74 // Maps each plane of the buffer into the client's address space so it can be | 66 // Maps each plane of the buffer into the client's address space so it can be |
75 // written to by the CPU. A pointer to plane K is stored at index K-1 of the | 67 // written to by the CPU. A pointer to plane K is stored at index K-1 of the |
76 // |data| array. This call may block, for instance if the GPU needs to finish | 68 // |data| array. 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 | 69 // accessing the buffer or if CPU caches need to be synchronized. Returns |
78 // false on failure. | 70 // false on failure. |
79 virtual bool Map(void** data) = 0; | 71 virtual bool Map(void** data) = 0; |
80 | 72 |
(...skipping 14 matching lines...) Expand all Loading... |
95 // Returns a platform specific handle for this buffer. | 87 // Returns a platform specific handle for this buffer. |
96 virtual GpuMemoryBufferHandle GetHandle() const = 0; | 88 virtual GpuMemoryBufferHandle GetHandle() const = 0; |
97 | 89 |
98 // Type-checking downcast routine. | 90 // Type-checking downcast routine. |
99 virtual ClientBuffer AsClientBuffer() = 0; | 91 virtual ClientBuffer AsClientBuffer() = 0; |
100 }; | 92 }; |
101 | 93 |
102 } // namespace gfx | 94 } // namespace gfx |
103 | 95 |
104 #endif // UI_GFX_GPU_MEMORY_BUFFER_H_ | 96 #endif // UI_GFX_GPU_MEMORY_BUFFER_H_ |
OLD | NEW |