| 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/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
| 14 #include "ui/ozone/platform/drm/gpu/gbm_device.h" | 14 #include "ui/ozone/platform/drm/gpu/gbm_device.h" |
| 15 | 15 |
| 16 namespace ui { | 16 namespace ui { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 int GetGbmFormatFromBufferFormat(SurfaceFactoryOzone::BufferFormat fmt) { | 20 int GetGbmFormatFromBufferFormat(SurfaceFactoryOzone::BufferFormat fmt) { |
| 21 switch (fmt) { | 21 switch (fmt) { |
| 22 case SurfaceFactoryOzone::RGBA_8888: | 22 case SurfaceFactoryOzone::BGRA_8888: |
| 23 return GBM_BO_FORMAT_ARGB8888; | 23 return GBM_BO_FORMAT_ARGB8888; |
| 24 case SurfaceFactoryOzone::RGBX_8888: | 24 case SurfaceFactoryOzone::RGBX_8888: |
| 25 return GBM_BO_FORMAT_XRGB8888; | 25 return GBM_BO_FORMAT_XRGB8888; |
| 26 default: | 26 default: |
| 27 NOTREACHED(); | 27 NOTREACHED(); |
| 28 return 0; | 28 return 0; |
| 29 } | 29 } |
| 30 } | 30 } |
| 31 | 31 |
| 32 } // namespace | 32 } // namespace |
| 33 | 33 |
| 34 GbmBuffer::GbmBuffer(const scoped_refptr<GbmDevice>& gbm, | 34 GbmBuffer::GbmBuffer(const scoped_refptr<GbmDevice>& gbm, gbm_bo* bo) |
| 35 gbm_bo* bo, | 35 : GbmBufferBase(gbm, bo) { |
| 36 bool scanout) | |
| 37 : GbmBufferBase(gbm, bo, scanout) { | |
| 38 } | 36 } |
| 39 | 37 |
| 40 GbmBuffer::~GbmBuffer() { | 38 GbmBuffer::~GbmBuffer() { |
| 41 if (bo()) | 39 if (bo()) |
| 42 gbm_bo_destroy(bo()); | 40 gbm_bo_destroy(bo()); |
| 43 } | 41 } |
| 44 | 42 |
| 45 // static | 43 // static |
| 46 scoped_refptr<GbmBuffer> GbmBuffer::CreateBuffer( | 44 scoped_refptr<GbmBuffer> GbmBuffer::CreateBuffer( |
| 47 const scoped_refptr<GbmDevice>& gbm, | 45 const scoped_refptr<GbmDevice>& gbm, |
| 48 SurfaceFactoryOzone::BufferFormat format, | 46 SurfaceFactoryOzone::BufferFormat format, |
| 49 const gfx::Size& size, | 47 const gfx::Size& size) { |
| 50 bool scanout) { | |
| 51 TRACE_EVENT2("drm", "GbmBuffer::CreateBuffer", "device", | 48 TRACE_EVENT2("drm", "GbmBuffer::CreateBuffer", "device", |
| 52 gbm->device_path().value(), "size", size.ToString()); | 49 gbm->device_path().value(), "size", size.ToString()); |
| 53 unsigned flags = GBM_BO_USE_RENDERING; | 50 unsigned flags = GBM_BO_USE_RENDERING | GBM_BO_USE_SCANOUT; |
| 54 if (scanout) | |
| 55 flags |= GBM_BO_USE_SCANOUT; | |
| 56 gbm_bo* bo = gbm_bo_create(gbm->device(), size.width(), size.height(), | 51 gbm_bo* bo = gbm_bo_create(gbm->device(), size.width(), size.height(), |
| 57 GetGbmFormatFromBufferFormat(format), flags); | 52 GetGbmFormatFromBufferFormat(format), flags); |
| 58 if (!bo) | 53 if (!bo) |
| 59 return NULL; | 54 return nullptr; |
| 60 | 55 |
| 61 scoped_refptr<GbmBuffer> buffer(new GbmBuffer(gbm, bo, scanout)); | 56 scoped_refptr<GbmBuffer> buffer(new GbmBuffer(gbm, bo)); |
| 62 if (scanout && !buffer->GetFramebufferId()) | 57 if (!buffer->GetFramebufferId()) |
| 63 return NULL; | 58 return nullptr; |
| 64 | 59 |
| 65 return buffer; | 60 return buffer; |
| 66 } | 61 } |
| 67 | 62 |
| 68 GbmPixmap::GbmPixmap(const scoped_refptr<GbmBuffer>& buffer) | 63 GbmPixmap::GbmPixmap(const scoped_refptr<GbmBuffer>& buffer) |
| 69 : buffer_(buffer), dma_buf_(-1) { | 64 : buffer_(buffer), dma_buf_(-1) { |
| 70 } | 65 } |
| 71 | 66 |
| 72 bool GbmPixmap::Initialize() { | 67 bool GbmPixmap::Initialize() { |
| 73 // We want to use the GBM API because it's going to call into libdrm | 68 // We want to use the GBM API because it's going to call into libdrm |
| (...skipping 18 matching lines...) Expand all Loading... |
| 92 | 87 |
| 93 int GbmPixmap::GetDmaBufFd() { | 88 int GbmPixmap::GetDmaBufFd() { |
| 94 return dma_buf_; | 89 return dma_buf_; |
| 95 } | 90 } |
| 96 | 91 |
| 97 int GbmPixmap::GetDmaBufPitch() { | 92 int GbmPixmap::GetDmaBufPitch() { |
| 98 return gbm_bo_get_stride(buffer_->bo()); | 93 return gbm_bo_get_stride(buffer_->bo()); |
| 99 } | 94 } |
| 100 | 95 |
| 101 } // namespace ui | 96 } // namespace ui |
| OLD | NEW |