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

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

Issue 2875453002: Add a size parameter to SharedMemoryHandle. (Closed)
Patch Set: Remove extraneous period. Created 3 years, 7 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_struct_traits.h ('k') | ui/surface/transport_dib_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
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));
56 } 56 }
57 return data.ReadPlanes(&out->planes); 57 return data.ReadPlanes(&out->planes);
58 #else 58 #else
59 return false; 59 return false;
60 #endif 60 #endif
61 } 61 }
62 62
63 mojo::ScopedHandle StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView, 63 mojo::ScopedSharedBufferHandle
64 gfx::GpuMemoryBufferHandle>:: 64 StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView,
65 gfx::GpuMemoryBufferHandle>::
65 shared_memory_handle(const gfx::GpuMemoryBufferHandle& handle) { 66 shared_memory_handle(const gfx::GpuMemoryBufferHandle& handle) {
66 if (handle.type != gfx::SHARED_MEMORY_BUFFER) 67 if (handle.type != gfx::SHARED_MEMORY_BUFFER)
67 return mojo::ScopedHandle(); 68 return mojo::ScopedSharedBufferHandle();
68 #if defined(OS_MACOSX) 69 return mojo::WrapSharedMemoryHandle(handle.handle, handle.handle.GetSize(),
69 base::SharedMemoryHandle shm_handle = handle.handle; 70 false);
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 = handle.handle.GetHandle();
79 return mojo::WrapPlatformFile(platform_file);
80 #endif // defined(OS_MACOSX)
81 } 71 }
82 72
83 const gfx::NativePixmapHandle& 73 const gfx::NativePixmapHandle&
84 StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView, 74 StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView,
85 gfx::GpuMemoryBufferHandle>:: 75 gfx::GpuMemoryBufferHandle>::
86 native_pixmap_handle(const gfx::GpuMemoryBufferHandle& handle) { 76 native_pixmap_handle(const gfx::GpuMemoryBufferHandle& handle) {
87 #if defined(OS_LINUX) 77 #if defined(OS_LINUX)
88 return handle.native_pixmap_handle; 78 return handle.native_pixmap_handle;
89 #else 79 #else
90 static gfx::NativePixmapHandle pixmap_handle; 80 static gfx::NativePixmapHandle pixmap_handle;
(...skipping 14 matching lines...) Expand all
105 } 95 }
106 96
107 bool StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView, 97 bool StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView,
108 gfx::GpuMemoryBufferHandle>:: 98 gfx::GpuMemoryBufferHandle>::
109 Read(gfx::mojom::GpuMemoryBufferHandleDataView data, 99 Read(gfx::mojom::GpuMemoryBufferHandleDataView data,
110 gfx::GpuMemoryBufferHandle* out) { 100 gfx::GpuMemoryBufferHandle* out) {
111 if (!data.ReadType(&out->type) || !data.ReadId(&out->id)) 101 if (!data.ReadType(&out->type) || !data.ReadId(&out->id))
112 return false; 102 return false;
113 103
114 if (out->type == gfx::SHARED_MEMORY_BUFFER) { 104 if (out->type == gfx::SHARED_MEMORY_BUFFER) {
115 mojo::ScopedHandle handle = data.TakeSharedMemoryHandle(); 105 mojo::ScopedSharedBufferHandle handle = data.TakeSharedMemoryHandle();
116 if (handle.is_valid()) { 106 if (handle.is_valid()) {
117 #if defined(OS_MACOSX)
118 mojo::Handle mojo_handle = handle.release();
119 mojo::ScopedSharedBufferHandle buffer_handle =
120 mojo::MakeScopedHandle(mojo::SharedBufferHandle(mojo_handle.value()));
121 MojoResult unwrap_result = mojo::UnwrapSharedMemoryHandle( 107 MojoResult unwrap_result = mojo::UnwrapSharedMemoryHandle(
122 std::move(buffer_handle), &out->handle, nullptr, nullptr); 108 std::move(handle), &out->handle, nullptr, nullptr);
123 if (unwrap_result != MOJO_RESULT_OK) 109 if (unwrap_result != MOJO_RESULT_OK)
124 return false; 110 return false;
125 #else // defined(OS_MACOSX)
126 base::PlatformFile platform_file;
127 MojoResult unwrap_result =
128 mojo::UnwrapPlatformFile(std::move(handle), &platform_file);
129 if (unwrap_result != MOJO_RESULT_OK)
130 return false;
131 // TODO(rockot): Pass GUIDs through Mojo. https://crbug.com/713763.
132 // TODO(erikchen): During serialization, the SharedMemoryHandle is
133 // decomposed on Linux into a file_descriptor. The serialization path
134 // should be changed to serialize a Mojo shared buffer instead.
135 // https://crbug.com/713763.
136 base::UnguessableToken guid = base::UnguessableToken::Create();
137 #if defined(OS_WIN)
138 out->handle = base::SharedMemoryHandle(platform_file, guid);
139 #else
140 out->handle = base::SharedMemoryHandle(
141 base::FileDescriptor(platform_file, true), guid);
142 #endif
143 #endif // defined(OS_MACOSX)
144 } 111 }
145 112
146 out->offset = data.offset(); 113 out->offset = data.offset();
147 out->stride = data.stride(); 114 out->stride = data.stride();
148 } 115 }
149 #if defined(OS_LINUX) 116 #if defined(OS_LINUX)
150 if (out->type == gfx::NATIVE_PIXMAP && 117 if (out->type == gfx::NATIVE_PIXMAP &&
151 !data.ReadNativePixmapHandle(&out->native_pixmap_handle)) 118 !data.ReadNativePixmapHandle(&out->native_pixmap_handle))
152 return false; 119 return false;
153 #endif 120 #endif
154 #if defined(OS_MACOSX) && !defined(OS_IOS) 121 #if defined(OS_MACOSX) && !defined(OS_IOS)
155 if (out->type == gfx::IO_SURFACE_BUFFER) { 122 if (out->type == gfx::IO_SURFACE_BUFFER) {
156 mach_port_t mach_port; 123 mach_port_t mach_port;
157 MojoResult unwrap_result = 124 MojoResult unwrap_result =
158 mojo::UnwrapMachPort(data.TakeMachPort(), &mach_port); 125 mojo::UnwrapMachPort(data.TakeMachPort(), &mach_port);
159 if (unwrap_result != MOJO_RESULT_OK) 126 if (unwrap_result != MOJO_RESULT_OK)
160 return false; 127 return false;
161 out->mach_port.reset(mach_port); 128 out->mach_port.reset(mach_port);
162 } 129 }
163 #endif 130 #endif
164 return true; 131 return true;
165 } 132 }
166 133
167 } // namespace mojo 134 } // namespace mojo
OLDNEW
« no previous file with comments | « ui/gfx/mojo/buffer_types_struct_traits.h ('k') | ui/surface/transport_dib_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698