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) |
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 |
| 53 // GpuMemoryBufferImpl needs the FD to implement GetHandle() but |
| 54 // ui::ClientNativePixmapFactory::ImportFromHandle is expected to take |
| 55 // ownership of the FD passed in the handle so we have to dup it here in |
| 56 // order to pass a valid FD to the GpuMemoryBufferImpl ctor. |
| 57 base::ScopedFD scoped_fd( |
| 58 HANDLE_EINTR(dup(handle.native_pixmap_handle.fds[0].fd))); |
| 59 if (!scoped_fd.is_valid()) { |
| 60 PLOG(ERROR) << "dup"; |
| 61 return nullptr; |
| 62 } |
| 63 |
| 64 gfx::NativePixmapHandle native_pixmap_handle; |
| 65 native_pixmap_handle.fds.emplace_back(handle.native_pixmap_handle.fds[0].fd, |
| 66 true /* auto_close */); |
| 67 native_pixmap_handle.strides_and_offsets = |
| 68 handle.native_pixmap_handle.strides_and_offsets; |
47 std::unique_ptr<ui::ClientNativePixmap> native_pixmap = | 69 std::unique_ptr<ui::ClientNativePixmap> native_pixmap = |
48 ui::ClientNativePixmapFactory::GetInstance()->ImportFromHandle( | 70 ui::ClientNativePixmapFactory::GetInstance()->ImportFromHandle( |
49 handle.native_pixmap_handle, size, usage); | 71 native_pixmap_handle, size, usage); |
50 DCHECK(native_pixmap); | 72 DCHECK(native_pixmap); |
| 73 |
51 return base::WrapUnique(new GpuMemoryBufferImplOzoneNativePixmap( | 74 return base::WrapUnique(new GpuMemoryBufferImplOzoneNativePixmap( |
52 handle.id, size, format, callback, std::move(native_pixmap))); | 75 handle.id, size, format, callback, std::move(native_pixmap), |
| 76 handle.native_pixmap_handle.strides_and_offsets, std::move(scoped_fd))); |
53 } | 77 } |
54 | 78 |
55 // static | 79 // static |
56 bool GpuMemoryBufferImplOzoneNativePixmap::IsConfigurationSupported( | 80 bool GpuMemoryBufferImplOzoneNativePixmap::IsConfigurationSupported( |
57 gfx::BufferFormat format, | 81 gfx::BufferFormat format, |
58 gfx::BufferUsage usage) { | 82 gfx::BufferUsage usage) { |
59 return gpu::IsNativeGpuMemoryBufferConfigurationSupported(format, usage); | 83 return gpu::IsNativeGpuMemoryBufferConfigurationSupported(format, usage); |
60 } | 84 } |
61 | 85 |
62 // static | 86 // static |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 int stride; | 129 int stride; |
106 pixmap_->GetStride(&stride); | 130 pixmap_->GetStride(&stride); |
107 return stride; | 131 return stride; |
108 } | 132 } |
109 | 133 |
110 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplOzoneNativePixmap::GetHandle() | 134 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplOzoneNativePixmap::GetHandle() |
111 const { | 135 const { |
112 gfx::GpuMemoryBufferHandle handle; | 136 gfx::GpuMemoryBufferHandle handle; |
113 handle.type = gfx::OZONE_NATIVE_PIXMAP; | 137 handle.type = gfx::OZONE_NATIVE_PIXMAP; |
114 handle.id = id_; | 138 handle.id = id_; |
| 139 handle.native_pixmap_handle.fds.emplace_back(fd_.get(), |
| 140 false /* auto_close */); |
| 141 handle.native_pixmap_handle.strides_and_offsets = strides_and_offsets_; |
115 return handle; | 142 return handle; |
116 } | 143 } |
117 | 144 |
118 } // namespace gpu | 145 } // namespace gpu |
OLD | NEW |