Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "gpu/ipc/client/gpu_memory_buffer_impl_ozone_native_pixmap.h" | 5 #include "gpu/ipc/client/gpu_memory_buffer_impl_ozone_native_pixmap.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "gpu/ipc/common/gpu_memory_buffer_support.h" | 10 #include "gpu/ipc/common/gpu_memory_buffer_support.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 // returns and reference count drops to 0. | 22 // returns and reference count drops to 0. |
| 23 } | 23 } |
| 24 | 24 |
| 25 } // namespace | 25 } // namespace |
| 26 | 26 |
| 27 GpuMemoryBufferImplOzoneNativePixmap::GpuMemoryBufferImplOzoneNativePixmap( | 27 GpuMemoryBufferImplOzoneNativePixmap::GpuMemoryBufferImplOzoneNativePixmap( |
| 28 gfx::GpuMemoryBufferId id, | 28 gfx::GpuMemoryBufferId id, |
| 29 const gfx::Size& size, | 29 const gfx::Size& size, |
| 30 gfx::BufferFormat format, | 30 gfx::BufferFormat format, |
| 31 const DestructionCallback& callback, | 31 const DestructionCallback& callback, |
| 32 std::unique_ptr<ui::ClientNativePixmap> pixmap) | 32 std::unique_ptr<ui::ClientNativePixmap> pixmap, |
| 33 const std::vector<std::pair<int, int>>& strides_and_offsets, | |
| 34 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
| |
| 33 : GpuMemoryBufferImpl(id, size, format, callback), | 35 : GpuMemoryBufferImpl(id, size, format, callback), |
| 34 pixmap_(std::move(pixmap)), | 36 pixmap_(std::move(pixmap)), |
| 37 strides_and_offsets_(strides_and_offsets), | |
| 38 fd_(std::move(fd)), | |
| 35 data_(nullptr) {} | 39 data_(nullptr) {} |
| 36 | 40 |
| 37 GpuMemoryBufferImplOzoneNativePixmap::~GpuMemoryBufferImplOzoneNativePixmap() {} | 41 GpuMemoryBufferImplOzoneNativePixmap::~GpuMemoryBufferImplOzoneNativePixmap() {} |
| 38 | 42 |
| 39 // static | 43 // static |
| 40 std::unique_ptr<GpuMemoryBufferImplOzoneNativePixmap> | 44 std::unique_ptr<GpuMemoryBufferImplOzoneNativePixmap> |
| 41 GpuMemoryBufferImplOzoneNativePixmap::CreateFromHandle( | 45 GpuMemoryBufferImplOzoneNativePixmap::CreateFromHandle( |
| 42 const gfx::GpuMemoryBufferHandle& handle, | 46 const gfx::GpuMemoryBufferHandle& handle, |
| 43 const gfx::Size& size, | 47 const gfx::Size& size, |
| 44 gfx::BufferFormat format, | 48 gfx::BufferFormat format, |
| 45 gfx::BufferUsage usage, | 49 gfx::BufferUsage usage, |
| 46 const DestructionCallback& callback) { | 50 const DestructionCallback& callback) { |
| 51 DCHECK_EQ(handle.native_pixmap_handle.fds.size(), 1u); | |
| 52 base::ScopedFD scoped_fd(handle.native_pixmap_handle.fds[0].fd); | |
| 53 | |
| 54 // GpuMemoryBufferImpl needs the FD to implement GetHandle() but | |
| 55 // ui::ClientNativePixmapFactory::ImportFromHandle is expected to take | |
| 56 // ownership of the FD passed in the handle so we have to dup it here in | |
| 57 // order to pass a valid FD to the GpuMemoryBufferImpl ctor. | |
| 58 gfx::NativePixmapHandle native_pixmap_handle; | |
| 59 native_pixmap_handle.fds.emplace_back( | |
| 60 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.
| |
| 61 native_pixmap_handle.strides_and_offsets = | |
| 62 handle.native_pixmap_handle.strides_and_offsets; | |
| 47 std::unique_ptr<ui::ClientNativePixmap> native_pixmap = | 63 std::unique_ptr<ui::ClientNativePixmap> native_pixmap = |
| 48 ui::ClientNativePixmapFactory::GetInstance()->ImportFromHandle( | 64 ui::ClientNativePixmapFactory::GetInstance()->ImportFromHandle( |
| 49 handle.native_pixmap_handle, size, usage); | 65 native_pixmap_handle, size, usage); |
| 50 DCHECK(native_pixmap); | 66 DCHECK(native_pixmap); |
| 67 | |
| 51 return base::WrapUnique(new GpuMemoryBufferImplOzoneNativePixmap( | 68 return base::WrapUnique(new GpuMemoryBufferImplOzoneNativePixmap( |
| 52 handle.id, size, format, callback, std::move(native_pixmap))); | 69 handle.id, size, format, callback, std::move(native_pixmap), |
| 70 handle.native_pixmap_handle.strides_and_offsets, std::move(scoped_fd))); | |
| 53 } | 71 } |
| 54 | 72 |
| 55 // static | 73 // static |
| 56 bool GpuMemoryBufferImplOzoneNativePixmap::IsConfigurationSupported( | 74 bool GpuMemoryBufferImplOzoneNativePixmap::IsConfigurationSupported( |
| 57 gfx::BufferFormat format, | 75 gfx::BufferFormat format, |
| 58 gfx::BufferUsage usage) { | 76 gfx::BufferUsage usage) { |
| 59 return gpu::IsNativeGpuMemoryBufferConfigurationSupported(format, usage); | 77 return gpu::IsNativeGpuMemoryBufferConfigurationSupported(format, usage); |
| 60 } | 78 } |
| 61 | 79 |
| 62 // static | 80 // static |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 int stride; | 123 int stride; |
| 106 pixmap_->GetStride(&stride); | 124 pixmap_->GetStride(&stride); |
| 107 return stride; | 125 return stride; |
| 108 } | 126 } |
| 109 | 127 |
| 110 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplOzoneNativePixmap::GetHandle() | 128 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplOzoneNativePixmap::GetHandle() |
| 111 const { | 129 const { |
| 112 gfx::GpuMemoryBufferHandle handle; | 130 gfx::GpuMemoryBufferHandle handle; |
| 113 handle.type = gfx::OZONE_NATIVE_PIXMAP; | 131 handle.type = gfx::OZONE_NATIVE_PIXMAP; |
| 114 handle.id = id_; | 132 handle.id = id_; |
| 133 base::ScopedFD scoped_fd(HANDLE_EINTR(dup(fd_.get()))); | |
| 134 if (!scoped_fd.is_valid()) { | |
| 135 PLOG(ERROR) << "dup"; | |
| 136 return gfx::GpuMemoryBufferHandle(); | |
| 137 } | |
| 138 handle.native_pixmap_handle.fds.emplace_back( | |
| 139 base::FileDescriptor(scoped_fd.release(), true)); | |
| 140 handle.native_pixmap_handle.strides_and_offsets = strides_and_offsets_; | |
| 115 return handle; | 141 return handle; |
| 116 } | 142 } |
| 117 | 143 |
| 118 } // namespace gpu | 144 } // namespace gpu |
| OLD | NEW |