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 12 matching lines...) Expand all Loading... |
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<gfx::NativePixmapPlane>& planes, | 33 const std::vector<std::pair<int, int>>& strides_and_offsets, |
34 base::ScopedFD fd) | 34 base::ScopedFD fd) |
35 : GpuMemoryBufferImpl(id, size, format, callback), | 35 : GpuMemoryBufferImpl(id, size, format, callback), |
36 pixmap_(std::move(pixmap)), | 36 pixmap_(std::move(pixmap)), |
37 planes_(planes), | 37 strides_and_offsets_(strides_and_offsets), |
38 fd_(std::move(fd)), | 38 fd_(std::move(fd)), |
39 data_(nullptr) {} | 39 data_(nullptr) {} |
40 | 40 |
41 GpuMemoryBufferImplOzoneNativePixmap::~GpuMemoryBufferImplOzoneNativePixmap() {} | 41 GpuMemoryBufferImplOzoneNativePixmap::~GpuMemoryBufferImplOzoneNativePixmap() {} |
42 | 42 |
43 // static | 43 // static |
44 std::unique_ptr<GpuMemoryBufferImplOzoneNativePixmap> | 44 std::unique_ptr<GpuMemoryBufferImplOzoneNativePixmap> |
45 GpuMemoryBufferImplOzoneNativePixmap::CreateFromHandle( | 45 GpuMemoryBufferImplOzoneNativePixmap::CreateFromHandle( |
46 const gfx::GpuMemoryBufferHandle& handle, | 46 const gfx::GpuMemoryBufferHandle& handle, |
47 const gfx::Size& size, | 47 const gfx::Size& size, |
48 gfx::BufferFormat format, | 48 gfx::BufferFormat format, |
49 gfx::BufferUsage usage, | 49 gfx::BufferUsage usage, |
50 const DestructionCallback& callback) { | 50 const DestructionCallback& callback) { |
51 DCHECK_EQ(handle.native_pixmap_handle.fds.size(), 1u); | 51 DCHECK_EQ(handle.native_pixmap_handle.fds.size(), 1u); |
52 | 52 |
53 // GpuMemoryBufferImpl needs the FD to implement GetHandle() but | 53 // GpuMemoryBufferImpl needs the FD to implement GetHandle() but |
54 // ui::ClientNativePixmapFactory::ImportFromHandle is expected to take | 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 | 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. | 56 // order to pass a valid FD to the GpuMemoryBufferImpl ctor. |
57 base::ScopedFD scoped_fd( | 57 base::ScopedFD scoped_fd( |
58 HANDLE_EINTR(dup(handle.native_pixmap_handle.fds[0].fd))); | 58 HANDLE_EINTR(dup(handle.native_pixmap_handle.fds[0].fd))); |
59 if (!scoped_fd.is_valid()) { | 59 if (!scoped_fd.is_valid()) { |
60 PLOG(ERROR) << "dup"; | 60 PLOG(ERROR) << "dup"; |
61 return nullptr; | 61 return nullptr; |
62 } | 62 } |
63 | 63 |
64 gfx::NativePixmapHandle native_pixmap_handle; | 64 gfx::NativePixmapHandle native_pixmap_handle; |
65 native_pixmap_handle.fds.emplace_back(handle.native_pixmap_handle.fds[0].fd, | 65 native_pixmap_handle.fds.emplace_back(handle.native_pixmap_handle.fds[0].fd, |
66 true /* auto_close */); | 66 true /* auto_close */); |
67 native_pixmap_handle.planes = handle.native_pixmap_handle.planes; | 67 native_pixmap_handle.strides_and_offsets = |
| 68 handle.native_pixmap_handle.strides_and_offsets; |
68 std::unique_ptr<ui::ClientNativePixmap> native_pixmap = | 69 std::unique_ptr<ui::ClientNativePixmap> native_pixmap = |
69 ui::ClientNativePixmapFactory::GetInstance()->ImportFromHandle( | 70 ui::ClientNativePixmapFactory::GetInstance()->ImportFromHandle( |
70 native_pixmap_handle, size, usage); | 71 native_pixmap_handle, size, usage); |
71 DCHECK(native_pixmap); | 72 DCHECK(native_pixmap); |
72 | 73 |
73 return base::WrapUnique(new GpuMemoryBufferImplOzoneNativePixmap( | 74 return base::WrapUnique(new GpuMemoryBufferImplOzoneNativePixmap( |
74 handle.id, size, format, callback, std::move(native_pixmap), | 75 handle.id, size, format, callback, std::move(native_pixmap), |
75 handle.native_pixmap_handle.planes, std::move(scoped_fd))); | 76 handle.native_pixmap_handle.strides_and_offsets, std::move(scoped_fd))); |
76 } | 77 } |
77 | 78 |
78 // static | 79 // static |
79 bool GpuMemoryBufferImplOzoneNativePixmap::IsConfigurationSupported( | 80 bool GpuMemoryBufferImplOzoneNativePixmap::IsConfigurationSupported( |
80 gfx::BufferFormat format, | 81 gfx::BufferFormat format, |
81 gfx::BufferUsage usage) { | 82 gfx::BufferUsage usage) { |
82 return gpu::IsNativeGpuMemoryBufferConfigurationSupported(format, usage); | 83 return gpu::IsNativeGpuMemoryBufferConfigurationSupported(format, usage); |
83 } | 84 } |
84 | 85 |
85 // static | 86 // static |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 return stride; | 131 return stride; |
131 } | 132 } |
132 | 133 |
133 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplOzoneNativePixmap::GetHandle() | 134 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplOzoneNativePixmap::GetHandle() |
134 const { | 135 const { |
135 gfx::GpuMemoryBufferHandle handle; | 136 gfx::GpuMemoryBufferHandle handle; |
136 handle.type = gfx::OZONE_NATIVE_PIXMAP; | 137 handle.type = gfx::OZONE_NATIVE_PIXMAP; |
137 handle.id = id_; | 138 handle.id = id_; |
138 handle.native_pixmap_handle.fds.emplace_back(fd_.get(), | 139 handle.native_pixmap_handle.fds.emplace_back(fd_.get(), |
139 false /* auto_close */); | 140 false /* auto_close */); |
140 handle.native_pixmap_handle.planes = planes_; | 141 handle.native_pixmap_handle.strides_and_offsets = strides_and_offsets_; |
141 return handle; | 142 return handle; |
142 } | 143 } |
143 | 144 |
144 } // namespace gpu | 145 } // namespace gpu |
OLD | NEW |