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

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

Issue 1134993003: ozone: Implement zero/one-copy texture for Ozone GBM. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase to ToT Created 5 years, 5 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
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/vgem_pixmap.h"
6
7 #include <fcntl.h>
8 #include <sys/mman.h>
9 #include <xf86drm.h>
10
11 #include "base/trace_event/trace_event.h"
12 #include "ui/ozone/public/surface_factory_ozone.h"
13
14 namespace ui {
15
16 namespace {
17
18 size_t StrideInBytes(size_t width, SurfaceFactoryOzone::BufferFormat format) {
19 switch (format) {
20 case SurfaceFactoryOzone::BGRA_8888:
21 case SurfaceFactoryOzone::RGBX_8888:
22 return width * 4;
23 case SurfaceFactoryOzone::UNKNOWN:
24 NOTREACHED();
25 }
26 NOTREACHED();
27 return 0;
28 }
29
30 } // namespace
31
32 VgemPixmap::VgemPixmap(base::FileDescriptor handle,
33 base::FileDescriptor vgem_handle,
34 gfx::Size size,
35 SurfaceFactoryOzone::BufferFormat format,
36 BufferUsage usage)
37 : vgem_bo_handle_(0),
38 vgem_fd_(vgem_handle),
39 size_(size),
40 format_(format),
41 usage_(usage),
42 stride_(StrideInBytes(size_.width(), format_)),
43 mmap_ptr_(nullptr) {
44 if (usage_ == MAP) {
45 DCHECK(vgem_fd_.fd > 0);
46 DCHECK(handle.fd > 0);
47 dma_buf_.reset(handle.fd);
48 }
49 }
50
51 bool VgemPixmap::Initialize() {
52 if (usage_ == SCANOUT)
53 return true;
54
55 DCHECK(vgem_fd_.fd);
56 int ret = drmPrimeFDToHandle(vgem_fd_.fd, dma_buf_.get(), &vgem_bo_handle_);
57 if (ret) {
58 LOG(ERROR) << "drmPrimeFDToHandle failed, handle:" << vgem_bo_handle_;
59 return false;
60 }
61 return true;
62 }
63
64 VgemPixmap::~VgemPixmap() {
65 if (vgem_bo_handle_) {
66 DCHECK_EQ(usage_, MAP);
67 struct drm_mode_destroy_dumb destroy;
68 memset(&destroy, 0, sizeof(destroy));
69 destroy.handle = vgem_bo_handle_;
70 int ret = drmIoctl(vgem_fd_.fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy);
spang 2015/07/24 22:08:25 I think you want DRM_IOCTL_GEM_CLOSE here.
71 if (!ret)
72 LOG(ERROR) << "fail to free a vgem buffer. error:" << ret;
73 vgem_bo_handle_ = 0;
74 }
75 }
76
77 void* VgemPixmap::GetEGLClientBuffer() {
78 return nullptr;
79 }
80
81 int VgemPixmap::GetDmaBufFd() {
82 return dma_buf_.get();
83 }
84
85 int VgemPixmap::GetDmaBufPitch() {
86 return stride_;
87 }
88
89 bool VgemPixmap::ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
90 int plane_z_order,
91 gfx::OverlayTransform plane_transform,
92 const gfx::Rect& display_bounds,
93 const gfx::RectF& crop_rect) {
94 // VgemPixmap is used in Browser and Renderer, so this feature is not needed.
95 NOTREACHED();
96 return false;
97 }
98
99 void VgemPixmap::SetScalingCallback(const ScalingCallback& scaling_callback) {
100 // VgemPixmap is used in Browser and Renderer, so this feature is not needed.
101 NOTREACHED();
102 }
103
104 scoped_refptr<NativePixmap> VgemPixmap::GetScaledPixmap(gfx::Size new_size) {
105 // VgemPixmap is used in Browser and Renderer, so this feature is not needed.
106 NOTREACHED();
107 return nullptr;
108 }
109
110 NativePixmap::BufferUsage VgemPixmap::GetBufferUsage() const {
111 return usage_;
112 }
113
114 void* VgemPixmap::Map() {
115 TRACE_EVENT0("gpu", "VgemPixmap::Map");
116 DCHECK(!mmap_ptr_);
117 DCHECK(vgem_bo_handle_);
118 DCHECK_EQ(usage_, MAP);
119
120 struct drm_mode_map_dumb mmap_arg;
121 memset(&mmap_arg, 0, sizeof(mmap_arg));
122 mmap_arg.handle = vgem_bo_handle_;
123
124 int ret = drmIoctl(vgem_fd_.fd, DRM_IOCTL_MODE_MAP_DUMB, &mmap_arg);
spang 2015/07/24 22:08:25 I think you want DRM_IOCTL_VGEM_MODE_MAP_DUMB here
dshwang 2015/07/28 15:23:12 Done. fyi, inside vgem implementation, DRM_IOCTL_V
125 if (ret) {
126 LOG(ERROR) << "fail to map a vgem buffer. error:" << ret;
127 return nullptr;
128 }
129 DCHECK(mmap_arg.offset);
130
131 size_t size = stride_ * size_.height();
132 mmap_ptr_ = mmap(nullptr, size, (PROT_READ | PROT_WRITE), MAP_SHARED,
133 vgem_fd_.fd, mmap_arg.offset);
134 DCHECK(mmap_ptr_ != MAP_FAILED);
135 return mmap_ptr_;
136 }
137
138 void VgemPixmap::Unmap() {
139 TRACE_EVENT0("gpu", "VgemPixmap::Unmap");
140 DCHECK(mmap_ptr_);
141 DCHECK(vgem_bo_handle_);
142 DCHECK_EQ(usage_, MAP);
143
144 size_t size = stride_ * size_.height();
145 int ret = munmap(mmap_ptr_, size);
146 DCHECK(!ret);
147 mmap_ptr_ = nullptr;
148 }
149
150 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698