OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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/common/native_pixmap_manager_gbm.h" | 5 #include "ui/ozone/platform/drm/common/native_pixmap_manager_gbm.h" |
6 | 6 |
7 #include "base/file_descriptor_posix.h" | 7 #include "base/file_descriptor_posix.h" |
| 8 #include "ui/ozone/platform/drm/gpu/vgem_pixmap.h" |
8 | 9 |
9 namespace ui { | 10 namespace ui { |
10 | 11 |
| 12 namespace { |
| 13 |
| 14 NativePixmap::BufferUsage NativePixmapBufferUsageFromSurfaceFactoryOzone( |
| 15 SurfaceFactoryOzone::BufferUsage usage) { |
| 16 switch (usage) { |
| 17 case SurfaceFactoryOzone::MAP: |
| 18 return NativePixmap::MAP; |
| 19 case SurfaceFactoryOzone::PERSISTENT_MAP: |
| 20 return NativePixmap::PERSISTENT_MAP; |
| 21 case SurfaceFactoryOzone::SCANOUT: |
| 22 return NativePixmap::SCANOUT; |
| 23 } |
| 24 NOTREACHED(); |
| 25 return NativePixmap::SCANOUT; |
| 26 } |
| 27 } |
| 28 |
11 NativePixmapManager* CreateNativePixmapManagerGbm() { | 29 NativePixmapManager* CreateNativePixmapManagerGbm() { |
12 return new NativePixmapManagerGbm(); | 30 return new NativePixmapManagerGbm(); |
13 } | 31 } |
14 | 32 |
15 NativePixmapManagerGbm::NativePixmapManagerGbm() { | 33 NativePixmapManagerGbm::NativePixmapManagerGbm() { |
16 } | 34 } |
17 | 35 |
18 NativePixmapManagerGbm::~NativePixmapManagerGbm() { | 36 NativePixmapManagerGbm::~NativePixmapManagerGbm() { |
19 } | 37 } |
20 | 38 |
21 void NativePixmapManagerGbm::Initialize(const base::FileDescriptor& device_fd) { | 39 void NativePixmapManagerGbm::Initialize(const base::FileDescriptor& device_fd) { |
22 DCHECK_EQ(vgem_fd_.get(), -1); | 40 DCHECK_EQ(vgem_fd_.get(), -1); |
23 if (device_fd.fd > 0) | 41 if (device_fd.fd > 0) |
24 vgem_fd_.reset(device_fd.fd); | 42 vgem_fd_.reset(device_fd.fd); |
25 } | 43 } |
26 | 44 |
27 std::vector<NativePixmapManager::Configuration> | 45 std::vector<NativePixmapManager::Configuration> |
28 NativePixmapManagerGbm::GetSupportedNativePixmapConfigurations() const { | 46 NativePixmapManagerGbm::GetSupportedNativePixmapConfigurations() const { |
29 std::vector<Configuration> configurations = { | 47 std::vector<Configuration> configurations = { |
30 {SurfaceFactoryOzone::BGRA_8888, SurfaceFactoryOzone::SCANOUT}, | 48 {SurfaceFactoryOzone::BGRA_8888, SurfaceFactoryOzone::SCANOUT}, |
31 {SurfaceFactoryOzone::RGBX_8888, SurfaceFactoryOzone::SCANOUT}}; | 49 {SurfaceFactoryOzone::RGBX_8888, SurfaceFactoryOzone::SCANOUT}}; |
| 50 // Map requires VGEM supports. |
| 51 if (vgem_fd_.is_valid()) { |
| 52 configurations.push_back( |
| 53 {SurfaceFactoryOzone::BGRA_8888, SurfaceFactoryOzone::MAP}); |
| 54 } |
32 return configurations; | 55 return configurations; |
33 } | 56 } |
34 | 57 |
| 58 scoped_refptr<NativePixmap> NativePixmapManagerGbm::CreateFromFileDescriptor( |
| 59 base::FileDescriptor handle, |
| 60 gfx::Size size, |
| 61 SurfaceFactoryOzone::BufferFormat format, |
| 62 SurfaceFactoryOzone::BufferUsage usage) { |
| 63 scoped_refptr<VgemPixmap> pixmap(new VgemPixmap( |
| 64 handle, base::FileDescriptor(vgem_fd_.get(), false), size, format, |
| 65 NativePixmapBufferUsageFromSurfaceFactoryOzone(usage))); |
| 66 if (!pixmap->Initialize()) |
| 67 return nullptr; |
| 68 |
| 69 return pixmap; |
| 70 } |
| 71 |
35 } // namespace ui | 72 } // namespace ui |
OLD | NEW |