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

Side by Side Diff: ui/ozone/platform/drm/gpu/client_native_pixmap_vgem.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: remove the return type from Pixmap::Map() 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
OLDNEW
(Empty)
1 // Copyright 2015 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/client_native_pixmap_vgem.h"
6
7 #include <fcntl.h>
8 #include <sys/mman.h>
9 #include <vgem_drm.h>
10 #include <xf86drm.h>
11
12 #include "base/process/memory.h"
13 #include "base/trace_event/trace_event.h"
14
15 namespace ui {
16
17 // static
18 scoped_ptr<ClientNativePixmap> ClientNativePixmapVgem::ImportFromDmabuf(
19 int vgem_fd,
20 int dmabuf_fd,
21 const gfx::Size& size,
22 int stride) {
23 DCHECK_GE(vgem_fd, 0);
24 DCHECK_GE(dmabuf_fd, 0);
25 uint32_t vgem_bo_handle = 0;
26 int ret = drmPrimeFDToHandle(vgem_fd, dmabuf_fd, &vgem_bo_handle);
27 DCHECK(!ret) << "drmPrimeFDToHandle failed.";
28 return make_scoped_ptr(
29 new ClientNativePixmapVgem(vgem_fd, vgem_bo_handle, size, stride));
30 }
31
32 ClientNativePixmapVgem::ClientNativePixmapVgem(int vgem_fd,
33 uint32_t vgem_bo_handle,
34 const gfx::Size& size,
35 int stride)
36 : vgem_fd_(vgem_fd),
37 vgem_bo_handle_(vgem_bo_handle),
38 size_(size),
39 stride_(stride),
40 data_(nullptr) {
41 DCHECK(vgem_bo_handle_);
42 }
43
44 ClientNativePixmapVgem::~ClientNativePixmapVgem() {
45 DCHECK(!data_);
46 struct drm_gem_close close = {0};
47 close.handle = vgem_bo_handle_;
48 int ret = drmIoctl(vgem_fd_, DRM_IOCTL_GEM_CLOSE, &close);
49 DCHECK(!ret) << "fail to free a vgem buffer.";
50 }
51
52 void* ClientNativePixmapVgem::Map() {
53 TRACE_EVENT0("gpu", "ClientNativePixmapVgem::Map");
54 DCHECK(!data_);
55 struct drm_mode_map_dumb mmap_arg = {0};
56 mmap_arg.handle = vgem_bo_handle_;
57
58 size_t size = stride_ * size_.height();
59 int ret = drmIoctl(vgem_fd_, DRM_IOCTL_VGEM_MODE_MAP_DUMB, &mmap_arg);
60 if (ret) {
61 PLOG(ERROR) << "fail to map a vgem buffer.";
62 base::TerminateBecauseOutOfMemory(size);
63 return nullptr;
reveman 2015/08/19 13:18:11 nit: you don't need this return statement as base:
dshwang 2015/08/19 13:23:20 Done.
64 }
65 DCHECK(mmap_arg.offset);
66
67 data_ = mmap(nullptr, size, (PROT_READ | PROT_WRITE), MAP_SHARED, vgem_fd_,
68 mmap_arg.offset);
69 DCHECK_NE(data_, MAP_FAILED);
70 return data_;
71 }
72
73 void ClientNativePixmapVgem::Unmap() {
74 TRACE_EVENT0("gpu", "ClientNativePixmapVgem::Unmap");
75 DCHECK(data_);
76
77 // TODO(dshwang): keep it consistently mapped, and unmap it in dtor.
78 size_t size = stride_ * size_.height();
79 int ret = munmap(data_, size);
80 DCHECK(!ret) << "fail to munmap a vgem buffer.";
81 data_ = nullptr;
82 }
83
84 void ClientNativePixmapVgem::GetStride(int* stride) const {
85 *stride = stride_;
86 }
87
88 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698