| 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 | 11 |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/posix/eintr_wrapper.h" | 13 #include "base/posix/eintr_wrapper.h" |
| 14 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
| 15 #include "ui/gfx/geometry/size_conversions.h" | 15 #include "ui/gfx/geometry/size_conversions.h" |
| 16 #include "ui/gfx/native_pixmap_handle_ozone.h" | 16 #include "ui/gfx/native_pixmap_handle_ozone.h" |
| 17 #include "ui/ozone/platform/drm/common/drm_util.h" | 17 #include "ui/ozone/platform/drm/common/drm_util.h" |
| 18 #include "ui/ozone/platform/drm/gpu/drm_window.h" | 18 #include "ui/ozone/platform/drm/gpu/drm_window.h" |
| 19 #include "ui/ozone/platform/drm/gpu/gbm_device.h" | 19 #include "ui/ozone/platform/drm/gpu/gbm_device.h" |
| 20 #include "ui/ozone/platform/drm/gpu/gbm_surface_factory.h" | 20 #include "ui/ozone/platform/drm/gpu/gbm_surface_factory.h" |
| 21 #include "ui/ozone/platform/drm/gpu/gbm_surfaceless.h" | 21 #include "ui/ozone/platform/drm/gpu/gbm_surfaceless.h" |
| 22 | 22 |
| 23 namespace ui { | 23 namespace ui { |
| 24 | 24 |
| 25 GbmBuffer::GbmBuffer(const scoped_refptr<GbmDevice>& gbm, | 25 GbmBuffer::GbmBuffer(const scoped_refptr<GbmDevice>& gbm, |
| 26 gbm_bo* bo, | 26 gbm_bo* bo, |
| 27 gfx::BufferUsage usage) | 27 gfx::BufferUsage usage) |
| 28 : GbmBufferBase(gbm, | 28 : GbmBufferBase(gbm, bo, usage == gfx::BufferUsage::SCANOUT), |
| 29 bo, | |
| 30 usage == gfx::BufferUsage::GPU_READ || | |
| 31 usage == gfx::BufferUsage::GPU_READ_WRITE), | |
| 32 usage_(usage) {} | 29 usage_(usage) {} |
| 33 | 30 |
| 34 GbmBuffer::~GbmBuffer() { | 31 GbmBuffer::~GbmBuffer() { |
| 35 if (bo()) | 32 if (bo()) |
| 36 gbm_bo_destroy(bo()); | 33 gbm_bo_destroy(bo()); |
| 37 } | 34 } |
| 38 | 35 |
| 39 // static | 36 // static |
| 40 scoped_refptr<GbmBuffer> GbmBuffer::CreateBuffer( | 37 scoped_refptr<GbmBuffer> GbmBuffer::CreateBuffer( |
| 41 const scoped_refptr<GbmDevice>& gbm, | 38 const scoped_refptr<GbmDevice>& gbm, |
| 42 gfx::BufferFormat format, | 39 gfx::BufferFormat format, |
| 43 const gfx::Size& size, | 40 const gfx::Size& size, |
| 44 gfx::BufferUsage usage) { | 41 gfx::BufferUsage usage) { |
| 45 TRACE_EVENT2("drm", "GbmBuffer::CreateBuffer", "device", | 42 TRACE_EVENT2("drm", "GbmBuffer::CreateBuffer", "device", |
| 46 gbm->device_path().value(), "size", size.ToString()); | 43 gbm->device_path().value(), "size", size.ToString()); |
| 47 bool with_cpu_access = | 44 bool use_scanout = (usage == gfx::BufferUsage::SCANOUT); |
| 48 usage == gfx::BufferUsage::GPU_READ_CPU_READ_WRITE || | |
| 49 usage == gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT; | |
| 50 unsigned flags = 0; | 45 unsigned flags = 0; |
| 51 // GBM_BO_USE_SCANOUT is the hint of x-tiling. | 46 // GBM_BO_USE_SCANOUT is the hint of x-tiling. |
| 52 if (!with_cpu_access) | 47 if (use_scanout) |
| 53 flags = GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING; | 48 flags = GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING; |
| 54 gbm_bo* bo = gbm_bo_create(gbm->device(), size.width(), size.height(), | 49 gbm_bo* bo = gbm_bo_create(gbm->device(), size.width(), size.height(), |
| 55 GetFourCCFormatFromBufferFormat(format), flags); | 50 GetFourCCFormatFromBufferFormat(format), flags); |
| 56 if (!bo) | 51 if (!bo) |
| 57 return nullptr; | 52 return nullptr; |
| 58 | 53 |
| 59 scoped_refptr<GbmBuffer> buffer(new GbmBuffer(gbm, bo, usage)); | 54 scoped_refptr<GbmBuffer> buffer(new GbmBuffer(gbm, bo, usage)); |
| 60 if (!with_cpu_access && !buffer->GetFramebufferId()) | 55 if (use_scanout && !buffer->GetFramebufferId()) |
| 61 return nullptr; | 56 return nullptr; |
| 62 | 57 |
| 63 return buffer; | 58 return buffer; |
| 64 } | 59 } |
| 65 | 60 |
| 66 GbmPixmap::GbmPixmap(GbmSurfaceFactory* surface_manager) | 61 GbmPixmap::GbmPixmap(GbmSurfaceFactory* surface_manager) |
| 67 : surface_manager_(surface_manager) {} | 62 : surface_manager_(surface_manager) {} |
| 68 | 63 |
| 69 void GbmPixmap::Initialize(base::ScopedFD dma_buf, int dma_buf_pitch) { | 64 void GbmPixmap::Initialize(base::ScopedFD dma_buf, int dma_buf_pitch) { |
| 70 dma_buf_ = dma_buf.Pass(); | 65 dma_buf_ = dma_buf.Pass(); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 return false; | 133 return false; |
| 139 } | 134 } |
| 140 } | 135 } |
| 141 | 136 |
| 142 // TODO(reveman): Add support for imported buffers. crbug.com/541558 | 137 // TODO(reveman): Add support for imported buffers. crbug.com/541558 |
| 143 if (!buffer_) { | 138 if (!buffer_) { |
| 144 PLOG(ERROR) << "ScheduleOverlayPlane requires a buffer."; | 139 PLOG(ERROR) << "ScheduleOverlayPlane requires a buffer."; |
| 145 return false; | 140 return false; |
| 146 } | 141 } |
| 147 | 142 |
| 148 DCHECK(buffer_->GetUsage() == gfx::BufferUsage::GPU_READ || | 143 DCHECK(buffer_->GetUsage() == gfx::BufferUsage::SCANOUT); |
| 149 buffer_->GetUsage() == gfx::BufferUsage::GPU_READ_WRITE); | |
| 150 surface_manager_->GetSurface(widget)->QueueOverlayPlane(OverlayPlane( | 144 surface_manager_->GetSurface(widget)->QueueOverlayPlane(OverlayPlane( |
| 151 buffer_, plane_z_order, plane_transform, display_bounds, crop_rect)); | 145 buffer_, plane_z_order, plane_transform, display_bounds, crop_rect)); |
| 152 return true; | 146 return true; |
| 153 } | 147 } |
| 154 | 148 |
| 155 bool GbmPixmap::ShouldApplyScaling(const gfx::Rect& display_bounds, | 149 bool GbmPixmap::ShouldApplyScaling(const gfx::Rect& display_bounds, |
| 156 const gfx::RectF& crop_rect, | 150 const gfx::RectF& crop_rect, |
| 157 gfx::Size* required_size) { | 151 gfx::Size* required_size) { |
| 158 if (crop_rect.width() == 0 || crop_rect.height() == 0) { | 152 if (crop_rect.width() == 0 || crop_rect.height() == 0) { |
| 159 PLOG(ERROR) << "ShouldApplyScaling passed zero scaling target."; | 153 PLOG(ERROR) << "ShouldApplyScaling passed zero scaling target."; |
| 160 return false; | 154 return false; |
| 161 } | 155 } |
| 162 | 156 |
| 163 if (!buffer_) { | 157 if (!buffer_) { |
| 164 PLOG(ERROR) << "ShouldApplyScaling requires a buffer."; | 158 PLOG(ERROR) << "ShouldApplyScaling requires a buffer."; |
| 165 return false; | 159 return false; |
| 166 } | 160 } |
| 167 | 161 |
| 168 gfx::Size pixmap_size = buffer_->GetSize(); | 162 gfx::Size pixmap_size = buffer_->GetSize(); |
| 169 // If the required size is not integer-sized, round it to the next integer. | 163 // If the required size is not integer-sized, round it to the next integer. |
| 170 *required_size = gfx::ToCeiledSize( | 164 *required_size = gfx::ToCeiledSize( |
| 171 gfx::SizeF(display_bounds.width() / crop_rect.width(), | 165 gfx::SizeF(display_bounds.width() / crop_rect.width(), |
| 172 display_bounds.height() / crop_rect.height())); | 166 display_bounds.height() / crop_rect.height())); |
| 173 return pixmap_size != *required_size; | 167 return pixmap_size != *required_size; |
| 174 } | 168 } |
| 175 | 169 |
| 176 } // namespace ui | 170 } // namespace ui |
| OLD | NEW |