OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "ui/gfx/mojo/buffer_types_struct_traits.h" | 5 #include "ui/gfx/mojo/buffer_types_struct_traits.h" |
6 | 6 |
7 #include "mojo/public/cpp/system/platform_handle.h" | 7 #include "mojo/public/cpp/system/platform_handle.h" |
8 | 8 |
9 namespace mojo { | 9 namespace mojo { |
10 | 10 |
11 void* StructTraits<gfx::mojom::NativePixmapHandleDataView, | 11 void* StructTraits<gfx::mojom::NativePixmapHandleDataView, |
12 gfx::NativePixmapHandle>:: | 12 gfx::NativePixmapHandle>:: |
13 SetUpContext(const gfx::NativePixmapHandle& pixmap_handle) { | 13 SetUpContext(const gfx::NativePixmapHandle& pixmap_handle) { |
14 return new PixmapHandleFdList(); | 14 return new PixmapHandleFdList(); |
15 } | 15 } |
16 | 16 |
17 void StructTraits<gfx::mojom::NativePixmapHandleDataView, | 17 void StructTraits<gfx::mojom::NativePixmapHandleDataView, |
18 gfx::NativePixmapHandle>:: | 18 gfx::NativePixmapHandle>:: |
19 TearDownContext(const gfx::NativePixmapHandle& handle, void* context) { | 19 TearDownContext(const gfx::NativePixmapHandle& handle, void* context) { |
20 delete static_cast<PixmapHandleFdList*>(context); | 20 delete static_cast<PixmapHandleFdList*>(context); |
21 } | 21 } |
22 | 22 |
23 std::vector<mojo::ScopedHandle> StructTraits< | 23 std::vector<mojo::ScopedHandle> StructTraits< |
24 gfx::mojom::NativePixmapHandleDataView, | 24 gfx::mojom::NativePixmapHandleDataView, |
25 gfx::NativePixmapHandle>::fds(const gfx::NativePixmapHandle& pixmap_handle, | 25 gfx::NativePixmapHandle>::fds(const gfx::NativePixmapHandle& pixmap_handle, |
26 void* context) { | 26 void* context) { |
27 PixmapHandleFdList* handles = static_cast<PixmapHandleFdList*>(context); | 27 PixmapHandleFdList* handles = static_cast<PixmapHandleFdList*>(context); |
28 #if defined(USE_OZONE) | 28 #if defined(OS_LINUX) |
29 if (handles->empty()) { | 29 if (handles->empty()) { |
30 // Generate the handles here, but do not send them yet. | 30 // Generate the handles here, but do not send them yet. |
31 for (const base::FileDescriptor& fd : pixmap_handle.fds) { | 31 for (const base::FileDescriptor& fd : pixmap_handle.fds) { |
32 base::PlatformFile platform_file = fd.fd; | 32 base::PlatformFile platform_file = fd.fd; |
33 handles->push_back(mojo::WrapPlatformFile(platform_file)); | 33 handles->push_back(mojo::WrapPlatformFile(platform_file)); |
34 } | 34 } |
35 return PixmapHandleFdList(handles->size()); | 35 return PixmapHandleFdList(handles->size()); |
36 } | 36 } |
37 #endif // defined(USE_OZONE) | 37 #endif // defined(OS_LINUX) |
38 return std::move(*handles); | 38 return std::move(*handles); |
39 } | 39 } |
40 | 40 |
41 bool StructTraits< | 41 bool StructTraits< |
42 gfx::mojom::NativePixmapHandleDataView, | 42 gfx::mojom::NativePixmapHandleDataView, |
43 gfx::NativePixmapHandle>::Read(gfx::mojom::NativePixmapHandleDataView data, | 43 gfx::NativePixmapHandle>::Read(gfx::mojom::NativePixmapHandleDataView data, |
44 gfx::NativePixmapHandle* out) { | 44 gfx::NativePixmapHandle* out) { |
45 #if defined(USE_OZONE) | 45 #if defined(OS_LINUX) |
46 mojo::ArrayDataView<mojo::ScopedHandle> handles_data_view; | 46 mojo::ArrayDataView<mojo::ScopedHandle> handles_data_view; |
47 data.GetFdsDataView(&handles_data_view); | 47 data.GetFdsDataView(&handles_data_view); |
48 for (size_t i = 0; i < handles_data_view.size(); ++i) { | 48 for (size_t i = 0; i < handles_data_view.size(); ++i) { |
49 mojo::ScopedHandle handle = handles_data_view.Take(i); | 49 mojo::ScopedHandle handle = handles_data_view.Take(i); |
50 base::PlatformFile platform_file; | 50 base::PlatformFile platform_file; |
51 if (mojo::UnwrapPlatformFile(std::move(handle), &platform_file) != | 51 if (mojo::UnwrapPlatformFile(std::move(handle), &platform_file) != |
52 MOJO_RESULT_OK) | 52 MOJO_RESULT_OK) |
53 return false; | 53 return false; |
54 constexpr bool auto_close = true; | 54 constexpr bool auto_close = true; |
55 out->fds.push_back(base::FileDescriptor(platform_file, auto_close)); | 55 out->fds.push_back(base::FileDescriptor(platform_file, auto_close)); |
(...skipping 26 matching lines...) Expand all Loading... |
82 platform_file = handle.handle.fd; | 82 platform_file = handle.handle.fd; |
83 #endif | 83 #endif |
84 return mojo::WrapPlatformFile(platform_file); | 84 return mojo::WrapPlatformFile(platform_file); |
85 #endif // defined(OS_MACOSX) | 85 #endif // defined(OS_MACOSX) |
86 } | 86 } |
87 | 87 |
88 const gfx::NativePixmapHandle& | 88 const gfx::NativePixmapHandle& |
89 StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView, | 89 StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView, |
90 gfx::GpuMemoryBufferHandle>:: | 90 gfx::GpuMemoryBufferHandle>:: |
91 native_pixmap_handle(const gfx::GpuMemoryBufferHandle& handle) { | 91 native_pixmap_handle(const gfx::GpuMemoryBufferHandle& handle) { |
92 #if defined(USE_OZONE) | 92 #if defined(OS_LINUX) |
93 return handle.native_pixmap_handle; | 93 return handle.native_pixmap_handle; |
94 #else | 94 #else |
95 static gfx::NativePixmapHandle pixmap_handle; | 95 static gfx::NativePixmapHandle pixmap_handle; |
96 return pixmap_handle; | 96 return pixmap_handle; |
97 #endif | 97 #endif |
98 } | 98 } |
99 | 99 |
100 mojo::ScopedHandle StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView, | 100 mojo::ScopedHandle StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView, |
101 gfx::GpuMemoryBufferHandle>:: | 101 gfx::GpuMemoryBufferHandle>:: |
102 mach_port(const gfx::GpuMemoryBufferHandle& handle) { | 102 mach_port(const gfx::GpuMemoryBufferHandle& handle) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 base::SharedMemoryHandle(platform_file, base::GetCurrentProcId()); | 138 base::SharedMemoryHandle(platform_file, base::GetCurrentProcId()); |
139 #else | 139 #else |
140 out->handle = base::SharedMemoryHandle(platform_file, true); | 140 out->handle = base::SharedMemoryHandle(platform_file, true); |
141 #endif | 141 #endif |
142 #endif // defined(OS_MACOSX) | 142 #endif // defined(OS_MACOSX) |
143 } | 143 } |
144 | 144 |
145 out->offset = data.offset(); | 145 out->offset = data.offset(); |
146 out->stride = data.stride(); | 146 out->stride = data.stride(); |
147 } | 147 } |
148 #if defined(USE_OZONE) | 148 #if defined(OS_LINUX) |
149 if (out->type == gfx::OZONE_NATIVE_PIXMAP && | 149 if (out->type == gfx::OZONE_NATIVE_PIXMAP && |
150 !data.ReadNativePixmapHandle(&out->native_pixmap_handle)) | 150 !data.ReadNativePixmapHandle(&out->native_pixmap_handle)) |
151 return false; | 151 return false; |
152 #endif | 152 #endif |
153 #if defined(OS_MACOSX) && !defined(OS_IOS) | 153 #if defined(OS_MACOSX) && !defined(OS_IOS) |
154 if (out->type == gfx::IO_SURFACE_BUFFER) { | 154 if (out->type == gfx::IO_SURFACE_BUFFER) { |
155 mach_port_t mach_port; | 155 mach_port_t mach_port; |
156 MojoResult unwrap_result = | 156 MojoResult unwrap_result = |
157 mojo::UnwrapMachPort(data.TakeMachPort(), &mach_port); | 157 mojo::UnwrapMachPort(data.TakeMachPort(), &mach_port); |
158 if (unwrap_result != MOJO_RESULT_OK) | 158 if (unwrap_result != MOJO_RESULT_OK) |
159 return false; | 159 return false; |
160 out->mach_port.reset(mach_port); | 160 out->mach_port.reset(mach_port); |
161 } | 161 } |
162 #endif | 162 #endif |
163 return true; | 163 return true; |
164 } | 164 } |
165 | 165 |
166 } // namespace mojo | 166 } // namespace mojo |
OLD | NEW |