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/gbm_surface_factory.h" | 5 #include "ui/ozone/platform/drm/gbm_surface_factory.h" |
6 | 6 |
7 #include <gbm.h> | 7 #include <gbm.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/posix/eintr_wrapper.h" |
11 #include "third_party/khronos/EGL/egl.h" | 12 #include "third_party/khronos/EGL/egl.h" |
12 #include "ui/gfx/geometry/rect_conversions.h" | 13 #include "ui/gfx/geometry/rect_conversions.h" |
13 #include "ui/ozone/common/egl_util.h" | 14 #include "ui/ozone/common/egl_util.h" |
14 #include "ui/ozone/platform/drm/gpu/drm_device_manager.h" | 15 #include "ui/ozone/platform/drm/gpu/drm_device_manager.h" |
15 #include "ui/ozone/platform/drm/gpu/drm_window.h" | 16 #include "ui/ozone/platform/drm/gpu/drm_window.h" |
16 #include "ui/ozone/platform/drm/gpu/gbm_buffer.h" | 17 #include "ui/ozone/platform/drm/gpu/gbm_buffer.h" |
17 #include "ui/ozone/platform/drm/gpu/gbm_device.h" | 18 #include "ui/ozone/platform/drm/gpu/gbm_device.h" |
18 #include "ui/ozone/platform/drm/gpu/gbm_surface.h" | 19 #include "ui/ozone/platform/drm/gpu/gbm_surface.h" |
19 #include "ui/ozone/platform/drm/gpu/gbm_surfaceless.h" | 20 #include "ui/ozone/platform/drm/gpu/gbm_surfaceless.h" |
20 #include "ui/ozone/platform/drm/gpu/hardware_display_controller.h" | 21 #include "ui/ozone/platform/drm/gpu/hardware_display_controller.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 case gfx::OVERLAY_TRANSFORM_NONE: | 65 case gfx::OVERLAY_TRANSFORM_NONE: |
65 return true; | 66 return true; |
66 default: | 67 default: |
67 return false; | 68 return false; |
68 } | 69 } |
69 } | 70 } |
70 | 71 |
71 DISALLOW_COPY_AND_ASSIGN(SingleOverlay); | 72 DISALLOW_COPY_AND_ASSIGN(SingleOverlay); |
72 }; | 73 }; |
73 | 74 |
| 75 bool ShareToRenderProcess(int fd, base::FileDescriptor* new_handle) { |
| 76 int duped_handle = HANDLE_EINTR(dup(fd)); |
| 77 if (duped_handle < 0) { |
| 78 DPLOG(ERROR) << "dup() failed."; |
| 79 *new_handle = base::FileDescriptor(); |
| 80 return false; |
| 81 } |
| 82 |
| 83 *new_handle = base::FileDescriptor(duped_handle, true); |
| 84 return true; |
| 85 } |
| 86 |
74 } // namespace | 87 } // namespace |
75 | 88 |
76 GbmSurfaceFactory::GbmSurfaceFactory(bool allow_surfaceless) | 89 GbmSurfaceFactory::GbmSurfaceFactory(bool allow_surfaceless) |
77 : DrmSurfaceFactory(NULL), allow_surfaceless_(allow_surfaceless) { | 90 : DrmSurfaceFactory(NULL), |
| 91 allow_surfaceless_(allow_surfaceless), |
| 92 drm_device_manager_(nullptr) { |
78 } | 93 } |
79 | 94 |
80 GbmSurfaceFactory::~GbmSurfaceFactory() { | 95 GbmSurfaceFactory::~GbmSurfaceFactory() { |
81 } | 96 } |
82 | 97 |
83 void GbmSurfaceFactory::InitializeGpu(DrmDeviceManager* drm_device_manager, | 98 void GbmSurfaceFactory::InitializeGpu(DrmDeviceManager* drm_device_manager, |
84 ScreenManager* screen_manager) { | 99 ScreenManager* screen_manager) { |
85 drm_device_manager_ = drm_device_manager; | 100 drm_device_manager_ = drm_device_manager; |
86 screen_manager_ = screen_manager; | 101 screen_manager_ = screen_manager; |
87 } | 102 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 | 159 |
145 return make_scoped_ptr(new GbmSurfaceless(screen_manager_->GetWindow(widget), | 160 return make_scoped_ptr(new GbmSurfaceless(screen_manager_->GetWindow(widget), |
146 drm_device_manager_)); | 161 drm_device_manager_)); |
147 } | 162 } |
148 | 163 |
149 scoped_refptr<ui::NativePixmap> GbmSurfaceFactory::CreateNativePixmap( | 164 scoped_refptr<ui::NativePixmap> GbmSurfaceFactory::CreateNativePixmap( |
150 gfx::AcceleratedWidget widget, | 165 gfx::AcceleratedWidget widget, |
151 gfx::Size size, | 166 gfx::Size size, |
152 BufferFormat format, | 167 BufferFormat format, |
153 BufferUsage usage) { | 168 BufferUsage usage) { |
154 if (usage == MAP) | |
155 return nullptr; | |
156 | |
157 scoped_refptr<GbmDevice> gbm = GetGbmDevice(widget); | 169 scoped_refptr<GbmDevice> gbm = GetGbmDevice(widget); |
158 DCHECK(gbm); | 170 DCHECK(gbm); |
159 | 171 |
160 scoped_refptr<GbmBuffer> buffer = | 172 scoped_refptr<GbmBuffer> buffer = |
161 GbmBuffer::CreateBuffer(gbm, format, size, true); | 173 GbmBuffer::CreateBuffer(gbm, format, size, usage == SCANOUT); |
162 if (!buffer.get()) | 174 if (!buffer.get()) |
163 return nullptr; | 175 return nullptr; |
164 | 176 |
165 scoped_refptr<GbmPixmap> pixmap(new GbmPixmap(buffer)); | 177 scoped_refptr<GbmPixmap> pixmap(new GbmPixmap(buffer)); |
166 if (!pixmap->Initialize()) | 178 if (!pixmap->Initialize()) |
167 return nullptr; | 179 return nullptr; |
168 | 180 |
169 return pixmap; | 181 return pixmap; |
170 } | 182 } |
171 | 183 |
| 184 gfx::GpuMemoryBufferHandle GbmSurfaceFactory::ExportGpuMemoryBufferHandle( |
| 185 gfx::AcceleratedWidget widget, |
| 186 scoped_refptr<NativePixmap> pixmap) { |
| 187 scoped_refptr<GbmDevice> gbm = GetGbmDevice(widget); |
| 188 DCHECK(gbm); |
| 189 |
| 190 base::FileDescriptor dup_handle; |
| 191 if (!ShareToRenderProcess(pixmap->GetDmaBufFd(), &dup_handle)) { |
| 192 DLOG(ERROR) << "Fail to duplicate a DMA-BUF file descriptor"; |
| 193 return gfx::GpuMemoryBufferHandle(); |
| 194 } |
| 195 |
| 196 int vgem_fd = drm_device_manager_->GetVgemDevice()->get_fd(); |
| 197 if (vgem_fd < 0) { |
| 198 LOG(ERROR) << "This device doesn't support VGEM."; |
| 199 return gfx::GpuMemoryBufferHandle(); |
| 200 } |
| 201 |
| 202 base::FileDescriptor dup_device_handle; |
| 203 if (!ShareToRenderProcess(vgem_fd, &dup_device_handle)) { |
| 204 base::ScopedFD fd(dup_handle.fd); |
| 205 LOG(ERROR) << "Fail to duplicate a VGEM file descriptor"; |
| 206 return gfx::GpuMemoryBufferHandle(); |
| 207 } |
| 208 |
| 209 gfx::GpuMemoryBufferHandle handle; |
| 210 handle.type = gfx::OZONE_NATIVE_BUFFER; |
| 211 handle.handle = dup_handle; |
| 212 handle.device_handle = dup_device_handle; |
| 213 return handle; |
| 214 } |
| 215 |
172 OverlayCandidatesOzone* GbmSurfaceFactory::GetOverlayCandidates( | 216 OverlayCandidatesOzone* GbmSurfaceFactory::GetOverlayCandidates( |
173 gfx::AcceleratedWidget w) { | 217 gfx::AcceleratedWidget w) { |
174 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 218 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
175 switches::kOzoneTestSingleOverlaySupport)) | 219 switches::kOzoneTestSingleOverlaySupport)) |
176 return new SingleOverlay(); | 220 return new SingleOverlay(); |
177 return NULL; | 221 return NULL; |
178 } | 222 } |
179 | 223 |
180 bool GbmSurfaceFactory::ScheduleOverlayPlane( | 224 bool GbmSurfaceFactory::ScheduleOverlayPlane( |
181 gfx::AcceleratedWidget widget, | 225 gfx::AcceleratedWidget widget, |
(...skipping 10 matching lines...) Expand all Loading... |
192 screen_manager_->GetWindow(widget)->QueueOverlayPlane( | 236 screen_manager_->GetWindow(widget)->QueueOverlayPlane( |
193 OverlayPlane(pixmap->buffer(), plane_z_order, plane_transform, | 237 OverlayPlane(pixmap->buffer(), plane_z_order, plane_transform, |
194 display_bounds, crop_rect)); | 238 display_bounds, crop_rect)); |
195 return true; | 239 return true; |
196 } | 240 } |
197 | 241 |
198 bool GbmSurfaceFactory::CanShowPrimaryPlaneAsOverlay() { | 242 bool GbmSurfaceFactory::CanShowPrimaryPlaneAsOverlay() { |
199 return allow_surfaceless_; | 243 return allow_surfaceless_; |
200 } | 244 } |
201 | 245 |
202 bool GbmSurfaceFactory::CanCreateNativePixmap(BufferUsage usage) { | 246 std::vector<SurfaceFactoryOzone::Configuration> |
203 switch (usage) { | 247 GbmSurfaceFactory::GetSupportedNativePixmapConfigurations() const { |
204 case MAP: | 248 std::vector<Configuration> configurations; |
205 return false; | 249 configurations.push_back( |
206 case SCANOUT: | 250 {SurfaceFactoryOzone::BGRA_8888, SurfaceFactoryOzone::SCANOUT}); |
207 return true; | 251 configurations.push_back( |
208 } | 252 {SurfaceFactoryOzone::RGBX_8888, SurfaceFactoryOzone::SCANOUT}); |
209 NOTREACHED(); | 253 // MAP is supported on the device, which supports VGEM. |
210 return false; | 254 if (drm_device_manager_ && drm_device_manager_->GetVgemDevice()) |
| 255 configurations.push_back( |
| 256 {SurfaceFactoryOzone::BGRA_8888, SurfaceFactoryOzone::MAP}); |
| 257 return configurations; |
211 } | 258 } |
212 | 259 |
213 scoped_refptr<GbmDevice> GbmSurfaceFactory::GetGbmDevice( | 260 scoped_refptr<GbmDevice> GbmSurfaceFactory::GetGbmDevice( |
214 gfx::AcceleratedWidget widget) { | 261 gfx::AcceleratedWidget widget) { |
215 return static_cast<GbmDevice*>( | 262 return static_cast<GbmDevice*>( |
216 drm_device_manager_->GetDrmDevice(widget).get()); | 263 drm_device_manager_->GetDrmDevice(widget).get()); |
217 } | 264 } |
218 | 265 |
219 } // namespace ui | 266 } // namespace ui |
OLD | NEW |