| 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> |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 // Optimal format for rendering on overlay. | 26 // Optimal format for rendering on overlay. |
| 27 const gfx::BufferFormat kOverlayRenderFormat = gfx::BufferFormat::UYVY_422; | 27 const gfx::BufferFormat kOverlayRenderFormat = gfx::BufferFormat::UYVY_422; |
| 28 } // namespace | 28 } // namespace |
| 29 | 29 |
| 30 namespace ui { | 30 namespace ui { |
| 31 | 31 |
| 32 GbmBuffer::GbmBuffer(const scoped_refptr<GbmDevice>& gbm, | 32 GbmBuffer::GbmBuffer(const scoped_refptr<GbmDevice>& gbm, |
| 33 gbm_bo* bo, | 33 gbm_bo* bo, |
| 34 gfx::BufferFormat format, |
| 34 gfx::BufferUsage usage) | 35 gfx::BufferUsage usage) |
| 35 : GbmBufferBase(gbm, bo, usage == gfx::BufferUsage::SCANOUT), | 36 : GbmBufferBase(gbm, bo, format, usage), format_(format), usage_(usage) {} |
| 36 usage_(usage) {} | |
| 37 | 37 |
| 38 GbmBuffer::~GbmBuffer() { | 38 GbmBuffer::~GbmBuffer() { |
| 39 if (bo()) | 39 if (bo()) |
| 40 gbm_bo_destroy(bo()); | 40 gbm_bo_destroy(bo()); |
| 41 } | 41 } |
| 42 | 42 |
| 43 // static | 43 // static |
| 44 scoped_refptr<GbmBuffer> GbmBuffer::CreateBuffer( | 44 scoped_refptr<GbmBuffer> GbmBuffer::CreateBuffer( |
| 45 const scoped_refptr<GbmDevice>& gbm, | 45 const scoped_refptr<GbmDevice>& gbm, |
| 46 gfx::BufferFormat format, | 46 gfx::BufferFormat format, |
| 47 const gfx::Size& size, | 47 const gfx::Size& size, |
| 48 gfx::BufferUsage usage) { | 48 gfx::BufferUsage usage) { |
| 49 TRACE_EVENT2("drm", "GbmBuffer::CreateBuffer", "device", | 49 TRACE_EVENT2("drm", "GbmBuffer::CreateBuffer", "device", |
| 50 gbm->device_path().value(), "size", size.ToString()); | 50 gbm->device_path().value(), "size", size.ToString()); |
| 51 bool use_scanout = (usage == gfx::BufferUsage::SCANOUT); | 51 bool use_scanout = (usage == gfx::BufferUsage::SCANOUT); |
| 52 unsigned flags = 0; | 52 unsigned flags = 0; |
| 53 // GBM_BO_USE_SCANOUT is the hint of x-tiling. | 53 // GBM_BO_USE_SCANOUT is the hint of x-tiling. |
| 54 if (use_scanout) | 54 if (use_scanout) |
| 55 flags = GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING; | 55 flags = GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING; |
| 56 gbm_bo* bo = gbm_bo_create(gbm->device(), size.width(), size.height(), | 56 gbm_bo* bo = gbm_bo_create(gbm->device(), size.width(), size.height(), |
| 57 GetFourCCFormatFromBufferFormat(format), flags); | 57 GetFourCCFormatFromBufferFormat(format), flags); |
| 58 if (!bo) | 58 if (!bo) |
| 59 return nullptr; | 59 return nullptr; |
| 60 | 60 |
| 61 scoped_refptr<GbmBuffer> buffer(new GbmBuffer(gbm, bo, usage)); | 61 scoped_refptr<GbmBuffer> buffer(new GbmBuffer(gbm, bo, format, usage)); |
| 62 if (use_scanout && !buffer->GetFramebufferId()) | 62 if (use_scanout && !buffer->GetFramebufferId()) |
| 63 return nullptr; | 63 return nullptr; |
| 64 | 64 |
| 65 return buffer; | 65 return buffer; |
| 66 } | 66 } |
| 67 | 67 |
| 68 GbmPixmap::GbmPixmap(GbmSurfaceFactory* surface_manager) | 68 GbmPixmap::GbmPixmap(GbmSurfaceFactory* surface_manager) |
| 69 : surface_manager_(surface_manager) {} | 69 : surface_manager_(surface_manager) {} |
| 70 | 70 |
| 71 void GbmPixmap::Initialize(base::ScopedFD dma_buf, int dma_buf_pitch) { | 71 void GbmPixmap::Initialize(base::ScopedFD dma_buf, int dma_buf_pitch) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 | 135 |
| 136 int GbmPixmap::GetDmaBufFd() const { | 136 int GbmPixmap::GetDmaBufFd() const { |
| 137 return dma_buf_.get(); | 137 return dma_buf_.get(); |
| 138 } | 138 } |
| 139 | 139 |
| 140 int GbmPixmap::GetDmaBufPitch() const { | 140 int GbmPixmap::GetDmaBufPitch() const { |
| 141 return dma_buf_pitch_; | 141 return dma_buf_pitch_; |
| 142 } | 142 } |
| 143 | 143 |
| 144 gfx::BufferFormat GbmPixmap::GetBufferFormat() const { | 144 gfx::BufferFormat GbmPixmap::GetBufferFormat() const { |
| 145 return GetBufferFormatFromFourCCFormat(buffer_->GetFramebufferPixelFormat()); | 145 return buffer_->GetFormat(); |
| 146 } | 146 } |
| 147 | 147 |
| 148 gfx::Size GbmPixmap::GetBufferSize() const { | 148 gfx::Size GbmPixmap::GetBufferSize() const { |
| 149 return buffer_->GetSize(); | 149 return buffer_->GetSize(); |
| 150 } | 150 } |
| 151 | 151 |
| 152 bool GbmPixmap::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, | 152 bool GbmPixmap::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, |
| 153 int plane_z_order, | 153 int plane_z_order, |
| 154 gfx::OverlayTransform plane_transform, | 154 gfx::OverlayTransform plane_transform, |
| 155 const gfx::Rect& display_bounds, | 155 const gfx::Rect& display_bounds, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 gfx::Size pixmap_size = buffer_->GetSize(); | 200 gfx::Size pixmap_size = buffer_->GetSize(); |
| 201 // If the required size is not integer-sized, round it to the next integer. | 201 // If the required size is not integer-sized, round it to the next integer. |
| 202 *target_size = gfx::ToCeiledSize( | 202 *target_size = gfx::ToCeiledSize( |
| 203 gfx::SizeF(display_bounds.width() / crop_rect.width(), | 203 gfx::SizeF(display_bounds.width() / crop_rect.width(), |
| 204 display_bounds.height() / crop_rect.height())); | 204 display_bounds.height() / crop_rect.height())); |
| 205 | 205 |
| 206 return pixmap_size != *target_size || GetBufferFormat() != *target_format; | 206 return pixmap_size != *target_size || GetBufferFormat() != *target_format; |
| 207 } | 207 } |
| 208 | 208 |
| 209 } // namespace ui | 209 } // namespace ui |
| OLD | NEW |