Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(408)

Side by Side Diff: ui/ozone/platform/dri/gbm_buffer.cc

Issue 812933003: [Ozone-Dri] Create GbmWrapper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@pass-wrapper
Patch Set: Rebased Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/ozone/platform/dri/gbm_buffer.h ('k') | ui/ozone/platform/dri/gbm_surface.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/dri/gbm_buffer.h" 5 #include "ui/ozone/platform/dri/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 "ui/ozone/platform/dri/dri_wrapper.h" 13 #include "ui/ozone/platform/dri/gbm_wrapper.h"
14 14
15 namespace ui { 15 namespace ui {
16 16
17 namespace { 17 namespace {
18 18
19 int GetGbmFormatFromBufferFormat(SurfaceFactoryOzone::BufferFormat fmt) { 19 int GetGbmFormatFromBufferFormat(SurfaceFactoryOzone::BufferFormat fmt) {
20 switch (fmt) { 20 switch (fmt) {
21 case SurfaceFactoryOzone::RGBA_8888: 21 case SurfaceFactoryOzone::RGBA_8888:
22 return GBM_BO_FORMAT_ARGB8888; 22 return GBM_BO_FORMAT_ARGB8888;
23 case SurfaceFactoryOzone::RGBX_8888: 23 case SurfaceFactoryOzone::RGBX_8888:
24 return GBM_BO_FORMAT_XRGB8888; 24 return GBM_BO_FORMAT_XRGB8888;
25 default: 25 default:
26 NOTREACHED(); 26 NOTREACHED();
27 return 0; 27 return 0;
28 } 28 }
29 } 29 }
30 30
31 } // namespace 31 } // namespace
32 32
33 GbmBuffer::GbmBuffer(DriWrapper* dri, gbm_bo* bo, bool scanout) 33 GbmBuffer::GbmBuffer(GbmWrapper* gbm, gbm_bo* bo, bool scanout)
34 : GbmBufferBase(dri, bo, scanout) { 34 : GbmBufferBase(gbm, bo, scanout) {
35 } 35 }
36 36
37 GbmBuffer::~GbmBuffer() { 37 GbmBuffer::~GbmBuffer() {
38 if (bo()) 38 if (bo())
39 gbm_bo_destroy(bo()); 39 gbm_bo_destroy(bo());
40 } 40 }
41 41
42 // static 42 // static
43 scoped_refptr<GbmBuffer> GbmBuffer::CreateBuffer( 43 scoped_refptr<GbmBuffer> GbmBuffer::CreateBuffer(
44 DriWrapper* dri, 44 GbmWrapper* gbm,
45 gbm_device* device,
46 SurfaceFactoryOzone::BufferFormat format, 45 SurfaceFactoryOzone::BufferFormat format,
47 const gfx::Size& size, 46 const gfx::Size& size,
48 bool scanout) { 47 bool scanout) {
49 unsigned flags = GBM_BO_USE_RENDERING; 48 unsigned flags = GBM_BO_USE_RENDERING;
50 if (scanout) 49 if (scanout)
51 flags |= GBM_BO_USE_SCANOUT; 50 flags |= GBM_BO_USE_SCANOUT;
52 gbm_bo* bo = gbm_bo_create(device, 51 gbm_bo* bo = gbm_bo_create(gbm->device(), size.width(), size.height(),
53 size.width(), 52 GetGbmFormatFromBufferFormat(format), flags);
54 size.height(),
55 GetGbmFormatFromBufferFormat(format),
56 flags);
57 if (!bo) 53 if (!bo)
58 return NULL; 54 return NULL;
59 55
60 scoped_refptr<GbmBuffer> buffer(new GbmBuffer(dri, bo, scanout)); 56 scoped_refptr<GbmBuffer> buffer(new GbmBuffer(gbm, bo, scanout));
61 if (scanout && !buffer->GetFramebufferId()) 57 if (scanout && !buffer->GetFramebufferId())
62 return NULL; 58 return NULL;
63 59
64 return buffer; 60 return buffer;
65 } 61 }
66 62
67 GbmPixmap::GbmPixmap(scoped_refptr<GbmBuffer> buffer) 63 GbmPixmap::GbmPixmap(scoped_refptr<GbmBuffer> buffer)
68 : buffer_(buffer), dma_buf_(-1) { 64 : buffer_(buffer), dma_buf_(-1) {
69 } 65 }
70 66
71 bool GbmPixmap::Initialize(DriWrapper* dri) { 67 bool GbmPixmap::Initialize(GbmWrapper* gbm) {
72 // 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
73 // which might do some optimizations on buffer allocation, 69 // which might do some optimizations on buffer allocation,
74 // especially when sharing buffers via DMABUF. 70 // especially when sharing buffers via DMABUF.
75 dma_buf_ = gbm_bo_get_fd(buffer_->bo()); 71 dma_buf_ = gbm_bo_get_fd(buffer_->bo());
76 if (dma_buf_ < 0) { 72 if (dma_buf_ < 0) {
77 LOG(ERROR) << "Failed to export buffer to dma_buf"; 73 LOG(ERROR) << "Failed to export buffer to dma_buf";
78 return false; 74 return false;
79 } 75 }
80 return true; 76 return true;
81 } 77 }
82 78
83 GbmPixmap::~GbmPixmap() { 79 GbmPixmap::~GbmPixmap() {
84 if (dma_buf_ > 0) 80 if (dma_buf_ > 0)
85 close(dma_buf_); 81 close(dma_buf_);
86 } 82 }
87 83
88 void* GbmPixmap::GetEGLClientBuffer() { 84 void* GbmPixmap::GetEGLClientBuffer() {
89 return nullptr; 85 return nullptr;
90 } 86 }
91 87
92 int GbmPixmap::GetDmaBufFd() { 88 int GbmPixmap::GetDmaBufFd() {
93 return dma_buf_; 89 return dma_buf_;
94 } 90 }
95 91
96 int GbmPixmap::GetDmaBufPitch() { 92 int GbmPixmap::GetDmaBufPitch() {
97 return gbm_bo_get_stride(buffer_->bo()); 93 return gbm_bo_get_stride(buffer_->bo());
98 } 94 }
99 95
100 } // namespace ui 96 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/dri/gbm_buffer.h ('k') | ui/ozone/platform/dri/gbm_surface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698