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 "ui/ozone/platform/drm/gpu/gbm_buffer.h" | 5 #include "ui/ozone/platform/drm/gpu/gbm_buffer.h" |
6 | 6 |
7 #include <drm.h> | 7 #include <drm.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <gbm.h> | 9 #include <gbm.h> |
10 #include <xf86drm.h> | 10 #include <xf86drm.h> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/posix/eintr_wrapper.h" | 14 #include "base/posix/eintr_wrapper.h" |
15 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
16 #include "ui/gfx/buffer_format_util.h" | 16 #include "ui/gfx/buffer_format_util.h" |
17 #include "ui/gfx/geometry/size_conversions.h" | 17 #include "ui/gfx/geometry/size_conversions.h" |
18 #include "ui/gfx/native_pixmap_handle.h" | |
19 #include "ui/ozone/platform/drm/common/drm_util.h" | 18 #include "ui/ozone/platform/drm/common/drm_util.h" |
20 #include "ui/ozone/platform/drm/gpu/drm_window.h" | 19 #include "ui/ozone/platform/drm/gpu/drm_window.h" |
21 #include "ui/ozone/platform/drm/gpu/gbm_device.h" | 20 #include "ui/ozone/platform/drm/gpu/gbm_device.h" |
22 #include "ui/ozone/platform/drm/gpu/gbm_surface_factory.h" | 21 #include "ui/ozone/platform/drm/gpu/gbm_surface_factory.h" |
23 #include "ui/ozone/platform/drm/gpu/gbm_surfaceless.h" | 22 #include "ui/ozone/platform/drm/gpu/gbm_surfaceless.h" |
24 #include "ui/ozone/public/ozone_platform.h" | 23 #include "ui/ozone/public/ozone_platform.h" |
25 #include "ui/ozone/public/surface_factory_ozone.h" | 24 #include "ui/ozone/public/surface_factory_ozone.h" |
26 | 25 |
27 namespace ui { | 26 namespace ui { |
28 | 27 |
29 GbmBuffer::GbmBuffer(const scoped_refptr<GbmDevice>& gbm, | 28 GbmBuffer::GbmBuffer(const scoped_refptr<GbmDevice>& gbm, |
30 gbm_bo* bo, | 29 gbm_bo* bo, |
31 uint32_t format, | 30 uint32_t format, |
32 uint32_t flags, | 31 uint32_t flags, |
33 uint64_t modifier, | 32 uint64_t modifier, |
34 uint32_t addfb_flags, | 33 uint32_t addfb_flags, |
35 std::vector<base::ScopedFD>&& fds, | 34 std::vector<base::ScopedFD>&& fds, |
36 const gfx::Size& size, | 35 const gfx::Size& size, |
37 | |
38 const std::vector<gfx::NativePixmapPlane>&& planes) | 36 const std::vector<gfx::NativePixmapPlane>&& planes) |
39 : GbmBufferBase(gbm, bo, format, flags, modifier, addfb_flags), | 37 : GbmBufferBase(gbm, bo, format, flags, modifier, addfb_flags), |
| 38 NativePixmapDmabufHelper(std::move(fds), std::move(planes)), |
40 format_(format), | 39 format_(format), |
41 flags_(flags), | 40 flags_(flags), |
42 fds_(std::move(fds)), | 41 size_(size) {} |
43 size_(size), | |
44 planes_(std::move(planes)) {} | |
45 | 42 |
46 GbmBuffer::~GbmBuffer() { | 43 GbmBuffer::~GbmBuffer() { |
47 if (bo()) | 44 if (bo()) |
48 gbm_bo_destroy(bo()); | 45 gbm_bo_destroy(bo()); |
49 } | 46 } |
50 | 47 |
51 bool GbmBuffer::AreFdsValid() const { | |
52 if (fds_.empty()) | |
53 return false; | |
54 | |
55 for (const auto& fd : fds_) { | |
56 if (fd.get() == -1) | |
57 return false; | |
58 } | |
59 return true; | |
60 } | |
61 | |
62 size_t GbmBuffer::GetFdCount() const { | |
63 return fds_.size(); | |
64 } | |
65 | |
66 int GbmBuffer::GetFd(size_t index) const { | |
67 DCHECK_LT(index, fds_.size()); | |
68 return fds_[index].get(); | |
69 } | |
70 | |
71 int GbmBuffer::GetStride(size_t index) const { | |
72 DCHECK_LT(index, planes_.size()); | |
73 return planes_[index].stride; | |
74 } | |
75 | |
76 int GbmBuffer::GetOffset(size_t index) const { | |
77 DCHECK_LT(index, planes_.size()); | |
78 return planes_[index].offset; | |
79 } | |
80 | |
81 size_t GbmBuffer::GetSize(size_t index) const { | |
82 DCHECK_LT(index, planes_.size()); | |
83 return planes_[index].size; | |
84 } | |
85 | |
86 uint64_t GbmBuffer::GetFormatModifier(size_t index) const { | |
87 DCHECK_LT(index, planes_.size()); | |
88 return planes_[index].modifier; | |
89 } | |
90 | |
91 // TODO(reveman): This should not be needed once crbug.com/597932 is fixed, | 48 // TODO(reveman): This should not be needed once crbug.com/597932 is fixed, |
92 // as the size would be queried directly from the underlying bo. | 49 // as the size would be queried directly from the underlying bo. |
93 gfx::Size GbmBuffer::GetSize() const { | 50 gfx::Size GbmBuffer::GetSize() const { |
94 return size_; | 51 return size_; |
95 } | 52 } |
96 | 53 |
| 54 size_t GbmBuffer::GetSize(size_t plane) const { |
| 55 return gfx::NativePixmapDmabufHelper::GetSize(plane); |
| 56 } |
| 57 |
97 scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferForBO( | 58 scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferForBO( |
98 const scoped_refptr<GbmDevice>& gbm, | 59 const scoped_refptr<GbmDevice>& gbm, |
99 gbm_bo* bo, | 60 gbm_bo* bo, |
100 uint32_t format, | 61 uint32_t format, |
101 const gfx::Size& size, | 62 const gfx::Size& size, |
102 uint32_t flags, | 63 uint32_t flags, |
103 uint64_t modifier, | 64 uint64_t modifier, |
104 uint32_t addfb_flags) { | 65 uint32_t addfb_flags) { |
105 if (!bo) | 66 if (!bo) |
106 return nullptr; | 67 return nullptr; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 if (try_scanout) | 177 if (try_scanout) |
217 flags |= GBM_BO_USE_SCANOUT; | 178 flags |= GBM_BO_USE_SCANOUT; |
218 scoped_refptr<GbmBuffer> buffer(new GbmBuffer( | 179 scoped_refptr<GbmBuffer> buffer(new GbmBuffer( |
219 gbm, bo, format, flags, 0, 0, std::move(fds), size, std::move(planes))); | 180 gbm, bo, format, flags, 0, 0, std::move(fds), size, std::move(planes))); |
220 | 181 |
221 return buffer; | 182 return buffer; |
222 } | 183 } |
223 | 184 |
224 GbmPixmap::GbmPixmap(GbmSurfaceFactory* surface_manager, | 185 GbmPixmap::GbmPixmap(GbmSurfaceFactory* surface_manager, |
225 const scoped_refptr<GbmBuffer>& buffer) | 186 const scoped_refptr<GbmBuffer>& buffer) |
226 : surface_manager_(surface_manager), buffer_(buffer) {} | 187 : NativePixmapDmaBuf( |
| 188 buffer->GetSize(), |
| 189 ui::GetBufferFormatFromFourCCFormat(buffer->GetFormat()), |
| 190 *buffer), |
| 191 surface_manager_(surface_manager), |
| 192 buffer_(buffer) {} |
227 | 193 |
228 void GbmPixmap::SetProcessingCallback( | 194 void GbmPixmap::SetProcessingCallback( |
229 const ProcessingCallback& processing_callback) { | 195 const ProcessingCallback& processing_callback) { |
230 DCHECK(processing_callback_.is_null()); | 196 DCHECK(processing_callback_.is_null()); |
231 processing_callback_ = processing_callback; | 197 processing_callback_ = processing_callback; |
232 } | 198 } |
233 | 199 |
234 gfx::NativePixmapHandle GbmPixmap::ExportHandle() { | 200 gfx::NativePixmapHandle GbmPixmap::ExportHandle() { |
235 gfx::NativePixmapHandle handle; | 201 gfx::NativePixmapHandle handle; |
236 gfx::BufferFormat format = | 202 gfx::BufferFormat format = |
(...skipping 14 matching lines...) Expand all Loading... |
251 handle.planes.emplace_back(buffer_->GetStride(i), buffer_->GetOffset(i), | 217 handle.planes.emplace_back(buffer_->GetStride(i), buffer_->GetOffset(i), |
252 buffer_->GetSize(i), | 218 buffer_->GetSize(i), |
253 buffer_->GetFormatModifier(i)); | 219 buffer_->GetFormatModifier(i)); |
254 } | 220 } |
255 return handle; | 221 return handle; |
256 } | 222 } |
257 | 223 |
258 GbmPixmap::~GbmPixmap() { | 224 GbmPixmap::~GbmPixmap() { |
259 } | 225 } |
260 | 226 |
261 void* GbmPixmap::GetEGLClientBuffer() const { | |
262 return nullptr; | |
263 } | |
264 | |
265 bool GbmPixmap::AreDmaBufFdsValid() const { | |
266 return buffer_->AreFdsValid(); | |
267 } | |
268 | |
269 size_t GbmPixmap::GetDmaBufFdCount() const { | |
270 return buffer_->GetFdCount(); | |
271 } | |
272 | |
273 int GbmPixmap::GetDmaBufFd(size_t plane) const { | |
274 return buffer_->GetFd(plane); | |
275 } | |
276 | |
277 int GbmPixmap::GetDmaBufPitch(size_t plane) const { | |
278 return buffer_->GetStride(plane); | |
279 } | |
280 | |
281 int GbmPixmap::GetDmaBufOffset(size_t plane) const { | |
282 return buffer_->GetOffset(plane); | |
283 } | |
284 | |
285 uint64_t GbmPixmap::GetDmaBufModifier(size_t plane) const { | |
286 return buffer_->GetFormatModifier(plane); | |
287 } | |
288 | |
289 gfx::BufferFormat GbmPixmap::GetBufferFormat() const { | |
290 return ui::GetBufferFormatFromFourCCFormat(buffer_->GetFormat()); | |
291 } | |
292 | |
293 gfx::Size GbmPixmap::GetBufferSize() const { | |
294 return buffer_->GetSize(); | |
295 } | |
296 | |
297 bool GbmPixmap::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, | 227 bool GbmPixmap::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, |
298 int plane_z_order, | 228 int plane_z_order, |
299 gfx::OverlayTransform plane_transform, | 229 gfx::OverlayTransform plane_transform, |
300 const gfx::Rect& display_bounds, | 230 const gfx::Rect& display_bounds, |
301 const gfx::RectF& crop_rect) { | 231 const gfx::RectF& crop_rect) { |
302 DCHECK(buffer_->GetFlags() & GBM_BO_USE_SCANOUT); | 232 DCHECK(buffer_->GetFlags() & GBM_BO_USE_SCANOUT); |
303 OverlayPlane::ProcessBufferCallback processing_callback; | 233 OverlayPlane::ProcessBufferCallback processing_callback; |
304 if (!processing_callback_.is_null()) | 234 if (!processing_callback_.is_null()) |
305 processing_callback = base::Bind(&GbmPixmap::ProcessBuffer, this); | 235 processing_callback = base::Bind(&GbmPixmap::ProcessBuffer, this); |
306 | 236 |
(...skipping 27 matching lines...) Expand all Loading... |
334 DCHECK(!processing_callback_.is_null()); | 264 DCHECK(!processing_callback_.is_null()); |
335 if (!processing_callback_.Run(this, processed_pixmap_)) { | 265 if (!processing_callback_.Run(this, processed_pixmap_)) { |
336 LOG(ERROR) << "Failed processing NativePixmap"; | 266 LOG(ERROR) << "Failed processing NativePixmap"; |
337 return nullptr; | 267 return nullptr; |
338 } | 268 } |
339 | 269 |
340 return processed_pixmap_->buffer(); | 270 return processed_pixmap_->buffer(); |
341 } | 271 } |
342 | 272 |
343 } // namespace ui | 273 } // namespace ui |
OLD | NEW |