Chromium Code Reviews| Index: gpu/ipc/client/gpu_memory_buffer_impl_ozone_native_pixmap.cc |
| diff --git a/gpu/ipc/client/gpu_memory_buffer_impl_ozone_native_pixmap.cc b/gpu/ipc/client/gpu_memory_buffer_impl_ozone_native_pixmap.cc |
| index c676e39d0d5b160c0e7a505da22aafe8d85a8702..177d26d7f63e70e287ffe7f4bb3e6b39c32e7c1f 100644 |
| --- a/gpu/ipc/client/gpu_memory_buffer_impl_ozone_native_pixmap.cc |
| +++ b/gpu/ipc/client/gpu_memory_buffer_impl_ozone_native_pixmap.cc |
| @@ -29,9 +29,13 @@ GpuMemoryBufferImplOzoneNativePixmap::GpuMemoryBufferImplOzoneNativePixmap( |
| const gfx::Size& size, |
| gfx::BufferFormat format, |
| const DestructionCallback& callback, |
| - std::unique_ptr<ui::ClientNativePixmap> pixmap) |
| + std::unique_ptr<ui::ClientNativePixmap> pixmap, |
| + const std::vector<std::pair<int, int>>& strides_and_offsets, |
| + base::ScopedFD fd) |
|
Daniele Castagna
2016/06/16 21:14:26
nit: Make this rvalue reference or pointer, so it'
reveman
2016/06/16 21:46:20
done
|
| : GpuMemoryBufferImpl(id, size, format, callback), |
| pixmap_(std::move(pixmap)), |
| + strides_and_offsets_(strides_and_offsets), |
| + fd_(std::move(fd)), |
| data_(nullptr) {} |
| GpuMemoryBufferImplOzoneNativePixmap::~GpuMemoryBufferImplOzoneNativePixmap() {} |
| @@ -44,12 +48,26 @@ GpuMemoryBufferImplOzoneNativePixmap::CreateFromHandle( |
| gfx::BufferFormat format, |
| gfx::BufferUsage usage, |
| const DestructionCallback& callback) { |
| + DCHECK_EQ(handle.native_pixmap_handle.fds.size(), 1u); |
| + base::ScopedFD scoped_fd(handle.native_pixmap_handle.fds[0].fd); |
| + |
| + // GpuMemoryBufferImpl needs the FD to implement GetHandle() but |
| + // ui::ClientNativePixmapFactory::ImportFromHandle is expected to take |
| + // ownership of the FD passed in the handle so we have to dup it here in |
| + // order to pass a valid FD to the GpuMemoryBufferImpl ctor. |
| + gfx::NativePixmapHandle native_pixmap_handle; |
| + native_pixmap_handle.fds.emplace_back( |
| + base::FileDescriptor(HANDLE_EINTR(dup(scoped_fd.get())), true)); |
|
Daniele Castagna
2016/06/16 21:14:26
nit: you can omit base::FileDescriptor. But leavin
reveman
2016/06/16 21:46:20
Done.
|
| + native_pixmap_handle.strides_and_offsets = |
| + handle.native_pixmap_handle.strides_and_offsets; |
| std::unique_ptr<ui::ClientNativePixmap> native_pixmap = |
| ui::ClientNativePixmapFactory::GetInstance()->ImportFromHandle( |
| - handle.native_pixmap_handle, size, usage); |
| + native_pixmap_handle, size, usage); |
| DCHECK(native_pixmap); |
| + |
| return base::WrapUnique(new GpuMemoryBufferImplOzoneNativePixmap( |
| - handle.id, size, format, callback, std::move(native_pixmap))); |
| + handle.id, size, format, callback, std::move(native_pixmap), |
| + handle.native_pixmap_handle.strides_and_offsets, std::move(scoped_fd))); |
| } |
| // static |
| @@ -112,6 +130,14 @@ gfx::GpuMemoryBufferHandle GpuMemoryBufferImplOzoneNativePixmap::GetHandle() |
| gfx::GpuMemoryBufferHandle handle; |
| handle.type = gfx::OZONE_NATIVE_PIXMAP; |
| handle.id = id_; |
| + base::ScopedFD scoped_fd(HANDLE_EINTR(dup(fd_.get()))); |
| + if (!scoped_fd.is_valid()) { |
| + PLOG(ERROR) << "dup"; |
| + return gfx::GpuMemoryBufferHandle(); |
| + } |
| + handle.native_pixmap_handle.fds.emplace_back( |
| + base::FileDescriptor(scoped_fd.release(), true)); |
| + handle.native_pixmap_handle.strides_and_offsets = strides_and_offsets_; |
| return handle; |
| } |