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

Side by Side Diff: ui/ozone/platform/drm/gpu/gbm_surface_factory.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
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/drm/gpu/gbm_surface_factory.h" 5 #include "ui/ozone/platform/drm/gpu/gbm_surface_factory.h"
6 6
7 #include <gbm.h> 7 #include <gbm.h>
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/posix/eintr_wrapper.h"
10 #include "third_party/khronos/EGL/egl.h" 11 #include "third_party/khronos/EGL/egl.h"
11 #include "ui/ozone/common/egl_util.h" 12 #include "ui/ozone/common/egl_util.h"
12 #include "ui/ozone/platform/drm/gpu/drm_device_manager.h" 13 #include "ui/ozone/platform/drm/gpu/drm_device_manager.h"
13 #include "ui/ozone/platform/drm/gpu/drm_window.h" 14 #include "ui/ozone/platform/drm/gpu/drm_window.h"
14 #include "ui/ozone/platform/drm/gpu/gbm_buffer.h" 15 #include "ui/ozone/platform/drm/gpu/gbm_buffer.h"
15 #include "ui/ozone/platform/drm/gpu/gbm_device.h" 16 #include "ui/ozone/platform/drm/gpu/gbm_device.h"
16 #include "ui/ozone/platform/drm/gpu/gbm_surface.h" 17 #include "ui/ozone/platform/drm/gpu/gbm_surface.h"
17 #include "ui/ozone/platform/drm/gpu/gbm_surfaceless.h" 18 #include "ui/ozone/platform/drm/gpu/gbm_surfaceless.h"
18 #include "ui/ozone/platform/drm/gpu/hardware_display_controller.h" 19 #include "ui/ozone/platform/drm/gpu/hardware_display_controller.h"
19 #include "ui/ozone/platform/drm/gpu/screen_manager.h" 20 #include "ui/ozone/platform/drm/gpu/screen_manager.h"
20 #include "ui/ozone/public/native_pixmap.h" 21 #include "ui/ozone/public/native_pixmap.h"
21 #include "ui/ozone/public/surface_ozone_canvas.h" 22 #include "ui/ozone/public/surface_ozone_canvas.h"
22 #include "ui/ozone/public/surface_ozone_egl.h" 23 #include "ui/ozone/public/surface_ozone_egl.h"
23 24
24 namespace ui { 25 namespace ui {
25 26
27 namespace {
28
29 bool ShareToRenderProcess(int fd, base::FileDescriptor* new_handle) {
30 int duped_handle = HANDLE_EINTR(dup(fd));
31 if (duped_handle < 0) {
32 DPLOG(ERROR) << "dup() failed.";
33 *new_handle = base::FileDescriptor();
34 return false;
35 }
36
37 *new_handle = base::FileDescriptor(duped_handle, true);
38 return true;
39 }
40
41 } // namespace
42
26 GbmSurfaceFactory::GbmSurfaceFactory(bool allow_surfaceless) 43 GbmSurfaceFactory::GbmSurfaceFactory(bool allow_surfaceless)
27 : DrmSurfaceFactory(NULL), allow_surfaceless_(allow_surfaceless) { 44 : DrmSurfaceFactory(NULL),
45 allow_surfaceless_(allow_surfaceless),
46 drm_device_manager_(nullptr) {
28 } 47 }
29 48
30 GbmSurfaceFactory::~GbmSurfaceFactory() { 49 GbmSurfaceFactory::~GbmSurfaceFactory() {
31 DCHECK(thread_checker_.CalledOnValidThread()); 50 DCHECK(thread_checker_.CalledOnValidThread());
32 } 51 }
33 52
34 void GbmSurfaceFactory::InitializeGpu(DrmDeviceManager* drm_device_manager, 53 void GbmSurfaceFactory::InitializeGpu(DrmDeviceManager* drm_device_manager,
35 ScreenManager* screen_manager) { 54 ScreenManager* screen_manager) {
36 drm_device_manager_ = drm_device_manager; 55 drm_device_manager_ = drm_device_manager;
37 screen_manager_ = screen_manager; 56 screen_manager_ = screen_manager;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 120
102 return make_scoped_ptr(new GbmSurfaceless(screen_manager_->GetWindow(widget), 121 return make_scoped_ptr(new GbmSurfaceless(screen_manager_->GetWindow(widget),
103 drm_device_manager_)); 122 drm_device_manager_));
104 } 123 }
105 124
106 scoped_refptr<ui::NativePixmap> GbmSurfaceFactory::CreateNativePixmap( 125 scoped_refptr<ui::NativePixmap> GbmSurfaceFactory::CreateNativePixmap(
107 gfx::AcceleratedWidget widget, 126 gfx::AcceleratedWidget widget,
108 gfx::Size size, 127 gfx::Size size,
109 BufferFormat format, 128 BufferFormat format,
110 BufferUsage usage) { 129 BufferUsage usage) {
111 if (usage == MAP)
112 return nullptr;
113
114 scoped_refptr<GbmDevice> gbm = GetGbmDevice(widget); 130 scoped_refptr<GbmDevice> gbm = GetGbmDevice(widget);
115 DCHECK(gbm); 131 DCHECK(gbm);
116 132
117 scoped_refptr<GbmBuffer> buffer = 133 scoped_refptr<GbmBuffer> buffer =
118 GbmBuffer::CreateBuffer(gbm, format, size, true); 134 GbmBuffer::CreateBuffer(gbm, format, size, usage == SCANOUT);
119 if (!buffer.get()) 135 if (!buffer.get())
120 return nullptr; 136 return nullptr;
121 137
122 scoped_refptr<GbmPixmap> pixmap(new GbmPixmap(buffer, screen_manager_)); 138 scoped_refptr<GbmPixmap> pixmap(new GbmPixmap(buffer, screen_manager_));
123 if (!pixmap->Initialize()) 139 if (!pixmap->Initialize())
124 return nullptr; 140 return nullptr;
125 141
126 return pixmap; 142 return pixmap;
127 } 143 }
128 144
145 base::FileDescriptor GbmSurfaceFactory::ExportDmaBuf(
146 gfx::AcceleratedWidget widget,
147 scoped_refptr<NativePixmap> pixmap) {
148 scoped_refptr<GbmDevice> gbm = GetGbmDevice(widget);
149 DCHECK(gbm);
150 DCHECK(pixmap->GetBufferUsage() == NativePixmap::MAP);
151
152 base::FileDescriptor dma_buf;
153 if (!ShareToRenderProcess(pixmap->GetDmaBufFd(), &dma_buf)) {
154 DLOG(ERROR) << "Fail to duplicate a DMA-BUF file descriptor";
155 return base::FileDescriptor();
156 }
157
158 return dma_buf;
159 }
160
129 bool GbmSurfaceFactory::CanShowPrimaryPlaneAsOverlay() { 161 bool GbmSurfaceFactory::CanShowPrimaryPlaneAsOverlay() {
130 DCHECK(thread_checker_.CalledOnValidThread()); 162 DCHECK(thread_checker_.CalledOnValidThread());
131 return allow_surfaceless_; 163 return allow_surfaceless_;
132 } 164 }
133 165
134 scoped_refptr<GbmDevice> GbmSurfaceFactory::GetGbmDevice( 166 scoped_refptr<GbmDevice> GbmSurfaceFactory::GetGbmDevice(
135 gfx::AcceleratedWidget widget) { 167 gfx::AcceleratedWidget widget) {
136 return static_cast<GbmDevice*>( 168 return static_cast<GbmDevice*>(
137 drm_device_manager_->GetDrmDevice(widget).get()); 169 drm_device_manager_->GetDrmDevice(widget).get());
138 } 170 }
139 171
140 } // namespace ui 172 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698