Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(531)

Side by Side Diff: ui/gfx/mojo/buffer_types_traits.cc

Issue 2694923003: Rename buffer_types_traits.{cc,h} to match normal conventions. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gfx/mojo/buffer_types_traits.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/gfx/mojo/buffer_types_traits.h"
6
7 #include "mojo/public/cpp/system/platform_handle.h"
8
9 namespace mojo {
10
11 void* StructTraits<gfx::mojom::NativePixmapHandleDataView,
12 gfx::NativePixmapHandle>::
13 SetUpContext(const gfx::NativePixmapHandle& pixmap_handle) {
14 return new PixmapHandleFdList();
15 }
16
17 void StructTraits<gfx::mojom::NativePixmapHandleDataView,
18 gfx::NativePixmapHandle>::
19 TearDownContext(const gfx::NativePixmapHandle& handle, void* context) {
20 delete static_cast<PixmapHandleFdList*>(context);
21 }
22
23 std::vector<mojo::ScopedHandle> StructTraits<
24 gfx::mojom::NativePixmapHandleDataView,
25 gfx::NativePixmapHandle>::fds(const gfx::NativePixmapHandle& pixmap_handle,
26 void* context) {
27 PixmapHandleFdList* handles = static_cast<PixmapHandleFdList*>(context);
28 #if defined(USE_OZONE)
29 if (handles->empty()) {
30 // Generate the handles here, but do not send them yet.
31 for (const base::FileDescriptor& fd : pixmap_handle.fds) {
32 base::PlatformFile platform_file = fd.fd;
33 handles->push_back(mojo::WrapPlatformFile(platform_file));
34 }
35 return PixmapHandleFdList(handles->size());
36 }
37 #endif // defined(USE_OZONE)
38 return std::move(*handles);
39 }
40
41 bool StructTraits<
42 gfx::mojom::NativePixmapHandleDataView,
43 gfx::NativePixmapHandle>::Read(gfx::mojom::NativePixmapHandleDataView data,
44 gfx::NativePixmapHandle* out) {
45 #if defined(USE_OZONE)
46 mojo::ArrayDataView<mojo::ScopedHandle> handles_data_view;
47 data.GetFdsDataView(&handles_data_view);
48 for (size_t i = 0; i < handles_data_view.size(); ++i) {
49 mojo::ScopedHandle handle = handles_data_view.Take(i);
50 base::PlatformFile platform_file;
51 if (mojo::UnwrapPlatformFile(std::move(handle), &platform_file) !=
52 MOJO_RESULT_OK)
53 return false;
54 constexpr bool auto_close = true;
55 out->fds.push_back(base::FileDescriptor(platform_file, auto_close));
56 }
57 return data.ReadPlanes(&out->planes);
58 #else
59 return false;
60 #endif
61 }
62
63 mojo::ScopedHandle StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView,
64 gfx::GpuMemoryBufferHandle>::
65 shared_memory_handle(const gfx::GpuMemoryBufferHandle& handle) {
66 if (handle.type != gfx::SHARED_MEMORY_BUFFER)
67 return mojo::ScopedHandle();
68 #if defined(OS_MACOSX)
69 base::SharedMemoryHandle shm_handle = handle.handle;
70 size_t num_bytes = 0;
71 if (!shm_handle.GetSize(&num_bytes))
72 return mojo::ScopedHandle();
73 mojo::ScopedSharedBufferHandle scoped_handle =
74 mojo::WrapSharedMemoryHandle(shm_handle, num_bytes, false);
75 mojo::Handle mojo_handle = scoped_handle.release();
76 return mojo::MakeScopedHandle(mojo_handle);
77 #else // defined(OS_MACOSX)
78 base::PlatformFile platform_file = base::kInvalidPlatformFile;
79 #if defined(OS_WIN)
80 platform_file = handle.handle.GetHandle();
81 #else
82 platform_file = handle.handle.fd;
83 #endif
84 return mojo::WrapPlatformFile(platform_file);
85 #endif // defined(OS_MACOSX)
86 }
87
88 const gfx::NativePixmapHandle&
89 StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView,
90 gfx::GpuMemoryBufferHandle>::
91 native_pixmap_handle(const gfx::GpuMemoryBufferHandle& handle) {
92 #if defined(USE_OZONE)
93 return handle.native_pixmap_handle;
94 #else
95 static gfx::NativePixmapHandle pixmap_handle;
96 return pixmap_handle;
97 #endif
98 }
99
100 mojo::ScopedHandle StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView,
101 gfx::GpuMemoryBufferHandle>::
102 mach_port(const gfx::GpuMemoryBufferHandle& handle) {
103 #if defined(OS_MACOSX) && !defined(OS_IOS)
104 if (handle.type != gfx::IO_SURFACE_BUFFER)
105 return mojo::ScopedHandle();
106 return mojo::WrapMachPort(handle.mach_port.get());
107 #else
108 return mojo::ScopedHandle();
109 #endif
110 }
111
112 bool StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView,
113 gfx::GpuMemoryBufferHandle>::
114 Read(gfx::mojom::GpuMemoryBufferHandleDataView data,
115 gfx::GpuMemoryBufferHandle* out) {
116 if (!data.ReadType(&out->type) || !data.ReadId(&out->id))
117 return false;
118
119 if (out->type == gfx::SHARED_MEMORY_BUFFER) {
120 mojo::ScopedHandle handle = data.TakeSharedMemoryHandle();
121 if (handle.is_valid()) {
122 #if defined(OS_MACOSX)
123 mojo::Handle mojo_handle = handle.release();
124 mojo::ScopedSharedBufferHandle buffer_handle =
125 mojo::MakeScopedHandle(mojo::SharedBufferHandle(mojo_handle.value()));
126 MojoResult unwrap_result = mojo::UnwrapSharedMemoryHandle(
127 std::move(buffer_handle), &out->handle, nullptr, nullptr);
128 if (unwrap_result != MOJO_RESULT_OK)
129 return false;
130 #else // defined(OS_MACOSX)
131 base::PlatformFile platform_file;
132 MojoResult unwrap_result =
133 mojo::UnwrapPlatformFile(std::move(handle), &platform_file);
134 if (unwrap_result != MOJO_RESULT_OK)
135 return false;
136 #if defined(OS_WIN)
137 out->handle =
138 base::SharedMemoryHandle(platform_file, base::GetCurrentProcId());
139 #else
140 out->handle = base::SharedMemoryHandle(platform_file, true);
141 #endif
142 #endif // defined(OS_MACOSX)
143 }
144
145 out->offset = data.offset();
146 out->stride = data.stride();
147 }
148 #if defined(USE_OZONE)
149 if (out->type == gfx::OZONE_NATIVE_PIXMAP &&
150 !data.ReadNativePixmapHandle(&out->native_pixmap_handle))
151 return false;
152 #endif
153 #if defined(OS_MACOSX) && !defined(OS_IOS)
154 if (out->type == gfx::IO_SURFACE_BUFFER) {
155 mach_port_t mach_port;
156 MojoResult unwrap_result =
157 mojo::UnwrapMachPort(data.TakeMachPort(), &mach_port);
158 if (unwrap_result != MOJO_RESULT_OK)
159 return false;
160 out->mach_port.reset(mach_port);
161 }
162 #endif
163 return true;
164 }
165
166 } // namespace mojo
OLDNEW
« no previous file with comments | « ui/gfx/mojo/buffer_types_traits.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698