| 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), |
| 40 format_(format), | 38 format_(format), |
| 41 flags_(flags), | 39 flags_(flags), |
| 42 fds_(std::move(fds)), | |
| 43 size_(size), | 40 size_(size), |
| 44 planes_(std::move(planes)) {} | 41 helper_(new gfx::NativePixmapDmabufHelper(std::move(fds), |
| 42 std::move(planes))) {} |
| 45 | 43 |
| 46 GbmBuffer::~GbmBuffer() { | 44 GbmBuffer::~GbmBuffer() { |
| 47 if (bo()) | 45 if (bo()) |
| 48 gbm_bo_destroy(bo()); | 46 gbm_bo_destroy(bo()); |
| 49 } | 47 } |
| 50 | 48 |
| 51 bool GbmBuffer::AreFdsValid() const { | 49 bool GbmBuffer::AreFdsValid() const { |
| 52 if (fds_.empty()) | 50 return helper_->AreFdsValid(); |
| 53 return false; | |
| 54 | |
| 55 for (const auto& fd : fds_) { | |
| 56 if (fd.get() == -1) | |
| 57 return false; | |
| 58 } | |
| 59 return true; | |
| 60 } | 51 } |
| 61 | 52 |
| 62 size_t GbmBuffer::GetFdCount() const { | 53 size_t GbmBuffer::GetFdCount() const { |
| 63 return fds_.size(); | 54 return helper_->GetFdCount(); |
| 64 } | 55 } |
| 65 | 56 |
| 66 int GbmBuffer::GetFd(size_t index) const { | 57 int GbmBuffer::GetFd(size_t index) const { |
| 67 DCHECK_LT(index, fds_.size()); | 58 return helper_->GetFd(index); |
| 68 return fds_[index].get(); | |
| 69 } | 59 } |
| 70 | 60 |
| 71 int GbmBuffer::GetStride(size_t index) const { | 61 int GbmBuffer::GetStride(size_t index) const { |
| 72 DCHECK_LT(index, planes_.size()); | 62 return helper_->GetStride(index); |
| 73 return planes_[index].stride; | |
| 74 } | 63 } |
| 75 | 64 |
| 76 int GbmBuffer::GetOffset(size_t index) const { | 65 int GbmBuffer::GetOffset(size_t index) const { |
| 77 DCHECK_LT(index, planes_.size()); | 66 return helper_->GetOffset(index); |
| 78 return planes_[index].offset; | |
| 79 } | 67 } |
| 80 | 68 |
| 81 size_t GbmBuffer::GetSize(size_t index) const { | 69 size_t GbmBuffer::GetSize(size_t index) const { |
| 82 DCHECK_LT(index, planes_.size()); | 70 return helper_->GetSize(index); |
| 83 return planes_[index].size; | |
| 84 } | 71 } |
| 85 | 72 |
| 86 // TODO(reveman): This should not be needed once crbug.com/597932 is fixed, | 73 // TODO(reveman): This should not be needed once crbug.com/597932 is fixed, |
| 87 // as the size would be queried directly from the underlying bo. | 74 // as the size would be queried directly from the underlying bo. |
| 88 gfx::Size GbmBuffer::GetSize() const { | 75 gfx::Size GbmBuffer::GetSize() const { |
| 89 return size_; | 76 return size_; |
| 90 } | 77 } |
| 91 | 78 |
| 92 scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferForBO( | 79 scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferForBO( |
| 93 const scoped_refptr<GbmDevice>& gbm, | 80 const scoped_refptr<GbmDevice>& gbm, |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 if (try_scanout) | 198 if (try_scanout) |
| 212 flags |= GBM_BO_USE_SCANOUT; | 199 flags |= GBM_BO_USE_SCANOUT; |
| 213 scoped_refptr<GbmBuffer> buffer(new GbmBuffer( | 200 scoped_refptr<GbmBuffer> buffer(new GbmBuffer( |
| 214 gbm, bo, format, flags, 0, 0, std::move(fds), size, std::move(planes))); | 201 gbm, bo, format, flags, 0, 0, std::move(fds), size, std::move(planes))); |
| 215 | 202 |
| 216 return buffer; | 203 return buffer; |
| 217 } | 204 } |
| 218 | 205 |
| 219 GbmPixmap::GbmPixmap(GbmSurfaceFactory* surface_manager, | 206 GbmPixmap::GbmPixmap(GbmSurfaceFactory* surface_manager, |
| 220 const scoped_refptr<GbmBuffer>& buffer) | 207 const scoped_refptr<GbmBuffer>& buffer) |
| 221 : surface_manager_(surface_manager), buffer_(buffer) {} | 208 : NativePixmapDmaBuf( |
| 209 buffer->GetSize(), |
| 210 ui::GetBufferFormatFromFourCCFormat(buffer->GetFormat()), |
| 211 buffer->helper()), |
| 212 surface_manager_(surface_manager), |
| 213 buffer_(buffer) {} |
| 214 |
| 215 GbmPixmap::~GbmPixmap() {} |
| 216 |
| 217 uint64_t GbmPixmap::GetDmaBufModifier(size_t plane) const { |
| 218 return buffer_->GetFormatModifier(); |
| 219 } |
| 220 |
| 221 bool GbmPixmap::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, |
| 222 int plane_z_order, |
| 223 gfx::OverlayTransform plane_transform, |
| 224 const gfx::Rect& display_bounds, |
| 225 const gfx::RectF& crop_rect) { |
| 226 DCHECK(buffer_->GetFlags() & GBM_BO_USE_SCANOUT); |
| 227 OverlayPlane::ProcessBufferCallback processing_callback; |
| 228 if (!processing_callback_.is_null()) |
| 229 processing_callback = base::Bind(&GbmPixmap::ProcessBuffer, this); |
| 230 |
| 231 surface_manager_->GetSurface(widget)->QueueOverlayPlane( |
| 232 OverlayPlane(buffer_, plane_z_order, plane_transform, display_bounds, |
| 233 crop_rect, processing_callback)); |
| 234 |
| 235 return true; |
| 236 } |
| 222 | 237 |
| 223 void GbmPixmap::SetProcessingCallback( | 238 void GbmPixmap::SetProcessingCallback( |
| 224 const ProcessingCallback& processing_callback) { | 239 const ProcessingCallback& processing_callback) { |
| 225 DCHECK(processing_callback_.is_null()); | 240 DCHECK(processing_callback_.is_null()); |
| 226 processing_callback_ = processing_callback; | 241 processing_callback_ = processing_callback; |
| 227 } | 242 } |
| 228 | 243 |
| 229 gfx::NativePixmapHandle GbmPixmap::ExportHandle() { | 244 gfx::NativePixmapHandle GbmPixmap::ExportHandle() { |
| 230 gfx::NativePixmapHandle handle; | 245 gfx::NativePixmapHandle handle; |
| 231 gfx::BufferFormat format = | 246 gfx::BufferFormat format = |
| (...skipping 11 matching lines...) Expand all Loading... |
| 243 handle.fds.emplace_back( | 258 handle.fds.emplace_back( |
| 244 base::FileDescriptor(scoped_fd.release(), true /* auto_close */)); | 259 base::FileDescriptor(scoped_fd.release(), true /* auto_close */)); |
| 245 } | 260 } |
| 246 handle.planes.emplace_back(buffer_->GetStride(i), buffer_->GetOffset(i), | 261 handle.planes.emplace_back(buffer_->GetStride(i), buffer_->GetOffset(i), |
| 247 buffer_->GetSize(i), | 262 buffer_->GetSize(i), |
| 248 buffer_->GetFormatModifier()); | 263 buffer_->GetFormatModifier()); |
| 249 } | 264 } |
| 250 return handle; | 265 return handle; |
| 251 } | 266 } |
| 252 | 267 |
| 253 GbmPixmap::~GbmPixmap() { | |
| 254 } | |
| 255 | |
| 256 void* GbmPixmap::GetEGLClientBuffer() const { | |
| 257 return nullptr; | |
| 258 } | |
| 259 | |
| 260 bool GbmPixmap::AreDmaBufFdsValid() const { | |
| 261 return buffer_->AreFdsValid(); | |
| 262 } | |
| 263 | |
| 264 size_t GbmPixmap::GetDmaBufFdCount() const { | |
| 265 return buffer_->GetFdCount(); | |
| 266 } | |
| 267 | |
| 268 int GbmPixmap::GetDmaBufFd(size_t plane) const { | |
| 269 return buffer_->GetFd(plane); | |
| 270 } | |
| 271 | |
| 272 int GbmPixmap::GetDmaBufPitch(size_t plane) const { | |
| 273 return buffer_->GetStride(plane); | |
| 274 } | |
| 275 | |
| 276 int GbmPixmap::GetDmaBufOffset(size_t plane) const { | |
| 277 return buffer_->GetOffset(plane); | |
| 278 } | |
| 279 | |
| 280 uint64_t GbmPixmap::GetDmaBufModifier(size_t plane) const { | |
| 281 return buffer_->GetFormatModifier(); | |
| 282 } | |
| 283 | |
| 284 gfx::BufferFormat GbmPixmap::GetBufferFormat() const { | |
| 285 return ui::GetBufferFormatFromFourCCFormat(buffer_->GetFormat()); | |
| 286 } | |
| 287 | |
| 288 gfx::Size GbmPixmap::GetBufferSize() const { | |
| 289 return buffer_->GetSize(); | |
| 290 } | |
| 291 | |
| 292 bool GbmPixmap::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, | |
| 293 int plane_z_order, | |
| 294 gfx::OverlayTransform plane_transform, | |
| 295 const gfx::Rect& display_bounds, | |
| 296 const gfx::RectF& crop_rect) { | |
| 297 DCHECK(buffer_->GetFlags() & GBM_BO_USE_SCANOUT); | |
| 298 OverlayPlane::ProcessBufferCallback processing_callback; | |
| 299 if (!processing_callback_.is_null()) | |
| 300 processing_callback = base::Bind(&GbmPixmap::ProcessBuffer, this); | |
| 301 | |
| 302 surface_manager_->GetSurface(widget)->QueueOverlayPlane( | |
| 303 OverlayPlane(buffer_, plane_z_order, plane_transform, display_bounds, | |
| 304 crop_rect, processing_callback)); | |
| 305 | |
| 306 return true; | |
| 307 } | |
| 308 | |
| 309 scoped_refptr<ScanoutBuffer> GbmPixmap::ProcessBuffer(const gfx::Size& size, | 268 scoped_refptr<ScanoutBuffer> GbmPixmap::ProcessBuffer(const gfx::Size& size, |
| 310 uint32_t format) { | 269 uint32_t format) { |
| 311 DCHECK(GetBufferSize() != size || | 270 DCHECK(GetBufferSize() != size || |
| 312 buffer_->GetFramebufferPixelFormat() != format); | 271 buffer_->GetFramebufferPixelFormat() != format); |
| 313 | 272 |
| 314 if (!processed_pixmap_ || size != processed_pixmap_->GetBufferSize() || | 273 if (!processed_pixmap_ || size != processed_pixmap_->GetBufferSize() || |
| 315 format != processed_pixmap_->buffer()->GetFramebufferPixelFormat()) { | 274 format != processed_pixmap_->buffer()->GetFramebufferPixelFormat()) { |
| 316 // Release any old processed pixmap. | 275 // Release any old processed pixmap. |
| 317 processed_pixmap_ = nullptr; | 276 processed_pixmap_ = nullptr; |
| 318 scoped_refptr<GbmBuffer> buffer = GbmBuffer::CreateBuffer( | 277 scoped_refptr<GbmBuffer> buffer = GbmBuffer::CreateBuffer( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 329 DCHECK(!processing_callback_.is_null()); | 288 DCHECK(!processing_callback_.is_null()); |
| 330 if (!processing_callback_.Run(this, processed_pixmap_)) { | 289 if (!processing_callback_.Run(this, processed_pixmap_)) { |
| 331 LOG(ERROR) << "Failed processing NativePixmap"; | 290 LOG(ERROR) << "Failed processing NativePixmap"; |
| 332 return nullptr; | 291 return nullptr; |
| 333 } | 292 } |
| 334 | 293 |
| 335 return processed_pixmap_->buffer(); | 294 return processed_pixmap_->buffer(); |
| 336 } | 295 } |
| 337 | 296 |
| 338 } // namespace ui | 297 } // namespace ui |
| OLD | NEW |