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<std::pair<int, int>>& strides_and_offsets, | 33 const std::vector<gfx::NativePixmapPlane>& planes, |
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 strides_and_offsets_(strides_and_offsets), | 37 planes_(planes), |
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.strides_and_offsets = | 67 native_pixmap_handle.planes = handle.native_pixmap_handle.planes; |
68 handle.native_pixmap_handle.strides_and_offsets; | |
69 std::unique_ptr<ui::ClientNativePixmap> native_pixmap = | 68 std::unique_ptr<ui::ClientNativePixmap> native_pixmap = |
70 ui::ClientNativePixmapFactory::GetInstance()->ImportFromHandle( | 69 ui::ClientNativePixmapFactory::GetInstance()->ImportFromHandle( |
71 native_pixmap_handle, size, usage); | 70 native_pixmap_handle, size, usage); |
72 DCHECK(native_pixmap); | 71 DCHECK(native_pixmap); |
73 | 72 |
74 return base::WrapUnique(new GpuMemoryBufferImplOzoneNativePixmap( | 73 return base::WrapUnique(new GpuMemoryBufferImplOzoneNativePixmap( |
75 handle.id, size, format, callback, std::move(native_pixmap), | 74 handle.id, size, format, callback, std::move(native_pixmap), |
76 handle.native_pixmap_handle.strides_and_offsets, std::move(scoped_fd))); | 75 handle.native_pixmap_handle.planes, std::move(scoped_fd))); |
77 } | 76 } |
78 | 77 |
79 // static | 78 // static |
80 bool GpuMemoryBufferImplOzoneNativePixmap::IsConfigurationSupported( | 79 bool GpuMemoryBufferImplOzoneNativePixmap::IsConfigurationSupported( |
81 gfx::BufferFormat format, | 80 gfx::BufferFormat format, |
82 gfx::BufferUsage usage) { | 81 gfx::BufferUsage usage) { |
83 return gpu::IsNativeGpuMemoryBufferConfigurationSupported(format, usage); | 82 return gpu::IsNativeGpuMemoryBufferConfigurationSupported(format, usage); |
84 } | 83 } |
85 | 84 |
86 // static | 85 // static |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 return stride; | 130 return stride; |
132 } | 131 } |
133 | 132 |
134 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplOzoneNativePixmap::GetHandle() | 133 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplOzoneNativePixmap::GetHandle() |
135 const { | 134 const { |
136 gfx::GpuMemoryBufferHandle handle; | 135 gfx::GpuMemoryBufferHandle handle; |
137 handle.type = gfx::OZONE_NATIVE_PIXMAP; | 136 handle.type = gfx::OZONE_NATIVE_PIXMAP; |
138 handle.id = id_; | 137 handle.id = id_; |
139 handle.native_pixmap_handle.fds.emplace_back(fd_.get(), | 138 handle.native_pixmap_handle.fds.emplace_back(fd_.get(), |
140 false /* auto_close */); | 139 false /* auto_close */); |
141 handle.native_pixmap_handle.strides_and_offsets = strides_and_offsets_; | 140 handle.native_pixmap_handle.planes = planes_; |
142 return handle; | 141 return handle; |
143 } | 142 } |
144 | 143 |
145 } // namespace gpu | 144 } // namespace gpu |
OLD | NEW |