| 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 | 12 |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 13 #include "base/posix/eintr_wrapper.h" | 14 #include "base/posix/eintr_wrapper.h" |
| 14 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
| 15 #include "ui/gfx/geometry/size_conversions.h" | 16 #include "ui/gfx/geometry/size_conversions.h" |
| 16 #include "ui/gfx/native_pixmap_handle_ozone.h" | 17 #include "ui/gfx/native_pixmap_handle_ozone.h" |
| 17 #include "ui/ozone/platform/drm/common/drm_util.h" | 18 #include "ui/ozone/platform/drm/common/drm_util.h" |
| 18 #include "ui/ozone/platform/drm/gpu/drm_window.h" | 19 #include "ui/ozone/platform/drm/gpu/drm_window.h" |
| 19 #include "ui/ozone/platform/drm/gpu/gbm_device.h" | 20 #include "ui/ozone/platform/drm/gpu/gbm_device.h" |
| 20 #include "ui/ozone/platform/drm/gpu/gbm_surface_factory.h" | 21 #include "ui/ozone/platform/drm/gpu/gbm_surface_factory.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 if (use_scanout && !buffer->GetFramebufferId()) | 63 if (use_scanout && !buffer->GetFramebufferId()) |
| 63 return nullptr; | 64 return nullptr; |
| 64 | 65 |
| 65 return buffer; | 66 return buffer; |
| 66 } | 67 } |
| 67 | 68 |
| 68 GbmPixmap::GbmPixmap(GbmSurfaceFactory* surface_manager) | 69 GbmPixmap::GbmPixmap(GbmSurfaceFactory* surface_manager) |
| 69 : surface_manager_(surface_manager) {} | 70 : surface_manager_(surface_manager) {} |
| 70 | 71 |
| 71 void GbmPixmap::Initialize(base::ScopedFD dma_buf, int dma_buf_pitch) { | 72 void GbmPixmap::Initialize(base::ScopedFD dma_buf, int dma_buf_pitch) { |
| 72 dma_buf_ = dma_buf.Pass(); | 73 dma_buf_ = std::move(dma_buf); |
| 73 dma_buf_pitch_ = dma_buf_pitch; | 74 dma_buf_pitch_ = dma_buf_pitch; |
| 74 } | 75 } |
| 75 | 76 |
| 76 bool GbmPixmap::InitializeFromBuffer(const scoped_refptr<GbmBuffer>& buffer) { | 77 bool GbmPixmap::InitializeFromBuffer(const scoped_refptr<GbmBuffer>& buffer) { |
| 77 // We want to use the GBM API because it's going to call into libdrm | 78 // We want to use the GBM API because it's going to call into libdrm |
| 78 // which might do some optimizations on buffer allocation, | 79 // which might do some optimizations on buffer allocation, |
| 79 // especially when sharing buffers via DMABUF. | 80 // especially when sharing buffers via DMABUF. |
| 80 base::ScopedFD dma_buf(gbm_bo_get_fd(buffer->bo())); | 81 base::ScopedFD dma_buf(gbm_bo_get_fd(buffer->bo())); |
| 81 if (!dma_buf.is_valid()) { | 82 if (!dma_buf.is_valid()) { |
| 82 PLOG(ERROR) << "Failed to export buffer to dma_buf"; | 83 PLOG(ERROR) << "Failed to export buffer to dma_buf"; |
| 83 return false; | 84 return false; |
| 84 } | 85 } |
| 85 Initialize(dma_buf.Pass(), gbm_bo_get_stride(buffer->bo())); | 86 Initialize(std::move(dma_buf), gbm_bo_get_stride(buffer->bo())); |
| 86 buffer_ = buffer; | 87 buffer_ = buffer; |
| 87 return true; | 88 return true; |
| 88 } | 89 } |
| 89 | 90 |
| 90 void GbmPixmap::SetProcessingCallback( | 91 void GbmPixmap::SetProcessingCallback( |
| 91 const ProcessingCallback& processing_callback) { | 92 const ProcessingCallback& processing_callback) { |
| 92 processing_callback_ = processing_callback; | 93 processing_callback_ = processing_callback; |
| 93 } | 94 } |
| 94 | 95 |
| 95 scoped_refptr<NativePixmap> GbmPixmap::GetProcessedPixmap( | 96 scoped_refptr<NativePixmap> GbmPixmap::GetProcessedPixmap( |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 gfx::Size pixmap_size = buffer_->GetSize(); | 201 gfx::Size pixmap_size = buffer_->GetSize(); |
| 201 // If the required size is not integer-sized, round it to the next integer. | 202 // If the required size is not integer-sized, round it to the next integer. |
| 202 *target_size = gfx::ToCeiledSize( | 203 *target_size = gfx::ToCeiledSize( |
| 203 gfx::SizeF(display_bounds.width() / crop_rect.width(), | 204 gfx::SizeF(display_bounds.width() / crop_rect.width(), |
| 204 display_bounds.height() / crop_rect.height())); | 205 display_bounds.height() / crop_rect.height())); |
| 205 | 206 |
| 206 return pixmap_size != *target_size || GetBufferFormat() != *target_format; | 207 return pixmap_size != *target_size || GetBufferFormat() != *target_format; |
| 207 } | 208 } |
| 208 | 209 |
| 209 } // namespace ui | 210 } // namespace ui |
| OLD | NEW |