OLD | NEW |
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 Loading... |
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)); | 138 scoped_refptr<GbmPixmap> pixmap(new GbmPixmap(buffer)); |
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::ScheduleOverlayPlane( | 161 bool GbmSurfaceFactory::ScheduleOverlayPlane( |
130 gfx::AcceleratedWidget widget, | 162 gfx::AcceleratedWidget widget, |
131 int plane_z_order, | 163 int plane_z_order, |
132 gfx::OverlayTransform plane_transform, | 164 gfx::OverlayTransform plane_transform, |
133 scoped_refptr<NativePixmap> buffer, | 165 scoped_refptr<NativePixmap> buffer, |
134 const gfx::Rect& display_bounds, | 166 const gfx::Rect& display_bounds, |
135 const gfx::RectF& crop_rect) { | 167 const gfx::RectF& crop_rect) { |
136 DCHECK(thread_checker_.CalledOnValidThread()); | 168 DCHECK(thread_checker_.CalledOnValidThread()); |
137 scoped_refptr<GbmPixmap> pixmap = static_cast<GbmPixmap*>(buffer.get()); | 169 scoped_refptr<GbmPixmap> pixmap = static_cast<GbmPixmap*>(buffer.get()); |
138 if (!pixmap.get()) { | 170 if (!pixmap.get()) { |
(...skipping 11 matching lines...) Expand all Loading... |
150 return allow_surfaceless_; | 182 return allow_surfaceless_; |
151 } | 183 } |
152 | 184 |
153 scoped_refptr<GbmDevice> GbmSurfaceFactory::GetGbmDevice( | 185 scoped_refptr<GbmDevice> GbmSurfaceFactory::GetGbmDevice( |
154 gfx::AcceleratedWidget widget) { | 186 gfx::AcceleratedWidget widget) { |
155 return static_cast<GbmDevice*>( | 187 return static_cast<GbmDevice*>( |
156 drm_device_manager_->GetDrmDevice(widget).get()); | 188 drm_device_manager_->GetDrmDevice(widget).get()); |
157 } | 189 } |
158 | 190 |
159 } // namespace ui | 191 } // namespace ui |
OLD | NEW |