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

Side by Side Diff: ui/ozone/platform/drm/gpu/gbm_buffer.cc

Issue 1285183008: Ozone integration. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: add missing license header Created 5 years, 4 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/drm/gpu/gbm_buffer.h ('k') | ui/ozone/platform/drm/gpu/gbm_buffer_base.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "ui/ozone/platform/drm/gpu/gbm_buffer.h"
6
7 #include <drm.h>
8 #include <fcntl.h>
9 #include <gbm.h>
10 #include <xf86drm.h>
11
12 #include "base/logging.h"
13 #include "base/trace_event/trace_event.h"
14 #include "ui/ozone/platform/drm/gpu/drm_window.h"
15 #include "ui/ozone/platform/drm/gpu/gbm_device.h"
16
17 namespace ui {
18
19 namespace {
20
21 int GetGbmFormatFromBufferFormat(SurfaceFactoryOzone::BufferFormat fmt) {
22 switch (fmt) {
23 case SurfaceFactoryOzone::BGRA_8888:
24 return GBM_BO_FORMAT_ARGB8888;
25 case SurfaceFactoryOzone::RGBX_8888:
26 return GBM_BO_FORMAT_XRGB8888;
27 default:
28 NOTREACHED();
29 return 0;
30 }
31 }
32
33 } // namespace
34
35 GbmBuffer::GbmBuffer(const scoped_refptr<GbmDevice>& gbm,
36 gbm_bo* bo,
37 bool scanout)
38 : GbmBufferBase(gbm, bo, scanout) {
39 }
40
41 GbmBuffer::~GbmBuffer() {
42 if (bo())
43 gbm_bo_destroy(bo());
44 }
45
46 // static
47 scoped_refptr<GbmBuffer> GbmBuffer::CreateBuffer(
48 const scoped_refptr<GbmDevice>& gbm,
49 SurfaceFactoryOzone::BufferFormat format,
50 const gfx::Size& size,
51 bool scanout) {
52 TRACE_EVENT2("drm", "GbmBuffer::CreateBuffer", "device",
53 gbm->device_path().value(), "size", size.ToString());
54 unsigned flags = GBM_BO_USE_RENDERING;
55 if (scanout)
56 flags |= GBM_BO_USE_SCANOUT;
57 gbm_bo* bo = gbm_bo_create(gbm->device(), size.width(), size.height(),
58 GetGbmFormatFromBufferFormat(format), flags);
59 if (!bo)
60 return NULL;
61
62 scoped_refptr<GbmBuffer> buffer(new GbmBuffer(gbm, bo, scanout));
63 if (scanout && !buffer->GetFramebufferId())
64 return NULL;
65
66 return buffer;
67 }
68
69 GbmPixmap::GbmPixmap(const scoped_refptr<GbmBuffer>& buffer,
70 ScreenManager* screen_manager)
71 : buffer_(buffer), screen_manager_(screen_manager) {
72 }
73
74 bool GbmPixmap::Initialize() {
75 // We want to use the GBM API because it's going to call into libdrm
76 // which might do some optimizations on buffer allocation,
77 // especially when sharing buffers via DMABUF.
78 dma_buf_ = gbm_bo_get_fd(buffer_->bo());
79 if (dma_buf_ < 0) {
80 PLOG(ERROR) << "Failed to export buffer to dma_buf";
81 return false;
82 }
83 return true;
84 }
85
86 GbmPixmap::~GbmPixmap() {
87 if (dma_buf_ > 0)
88 close(dma_buf_);
89 }
90
91 void* GbmPixmap::GetEGLClientBuffer() {
92 return nullptr;
93 }
94
95 int GbmPixmap::GetDmaBufFd() {
96 return dma_buf_;
97 }
98
99 int GbmPixmap::GetDmaBufPitch() {
100 return gbm_bo_get_stride(buffer_->bo());
101 }
102
103 bool GbmPixmap::ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
104 int plane_z_order,
105 gfx::OverlayTransform plane_transform,
106 const gfx::Rect& display_bounds,
107 const gfx::RectF& crop_rect) {
108 screen_manager_->GetWindow(widget)->QueueOverlayPlane(OverlayPlane(
109 buffer_, plane_z_order, plane_transform, display_bounds, crop_rect));
110 return true;
111 }
112
113 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/drm/gpu/gbm_buffer.h ('k') | ui/ozone/platform/drm/gpu/gbm_buffer_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698