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
3 // found in the LICENSE file.
5 #include "ui/ozone/platform/drm/gpu/gbm_buffer.h"
12 #include "base/logging.h"
13 #include "base/trace_event/trace_event.h"
14 #include "ui/ozone/platform/drm/gpu/gbm_device.h"
20 int GetGbmFormatFromBufferFormat(SurfaceFactoryOzone::BufferFormat fmt
) {
22 case SurfaceFactoryOzone::RGBA_8888
:
23 return GBM_BO_FORMAT_ARGB8888
;
24 case SurfaceFactoryOzone::RGBX_8888
:
25 return GBM_BO_FORMAT_XRGB8888
;
34 GbmBuffer::GbmBuffer(const scoped_refptr
<GbmDevice
>& gbm
,
37 : GbmBufferBase(gbm
, bo
, scanout
) {
40 GbmBuffer::~GbmBuffer() {
46 scoped_refptr
<GbmBuffer
> GbmBuffer::CreateBuffer(
47 const scoped_refptr
<GbmDevice
>& gbm
,
48 SurfaceFactoryOzone::BufferFormat format
,
49 const gfx::Size
& size
,
51 TRACE_EVENT2("drm", "GbmBuffer::CreateBuffer", "device",
52 gbm
->device_path().value(), "size", size
.ToString());
53 unsigned flags
= GBM_BO_USE_RENDERING
;
55 flags
|= GBM_BO_USE_SCANOUT
;
56 gbm_bo
* bo
= gbm_bo_create(gbm
->device(), size
.width(), size
.height(),
57 GetGbmFormatFromBufferFormat(format
), flags
);
61 scoped_refptr
<GbmBuffer
> buffer(new GbmBuffer(gbm
, bo
, scanout
));
62 if (scanout
&& !buffer
->GetFramebufferId())
68 GbmPixmap::GbmPixmap(const scoped_refptr
<GbmBuffer
>& buffer
)
69 : buffer_(buffer
), dma_buf_(-1) {
72 bool GbmPixmap::Initialize() {
73 // We want to use the GBM API because it's going to call into libdrm
74 // which might do some optimizations on buffer allocation,
75 // especially when sharing buffers via DMABUF.
76 dma_buf_
= gbm_bo_get_fd(buffer_
->bo());
78 PLOG(ERROR
) << "Failed to export buffer to dma_buf";
84 GbmPixmap::~GbmPixmap() {
89 void* GbmPixmap::GetEGLClientBuffer() {
93 int GbmPixmap::GetDmaBufFd() {
97 int GbmPixmap::GetDmaBufPitch() {
98 return gbm_bo_get_stride(buffer_
->bo());