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/client_native_pixmap_factory_gbm.h" | 5 #include "ui/ozone/platform/drm/common/client_native_pixmap_factory_gbm.h" |
6 | 6 |
7 #include "base/file_descriptor_posix.h" | 7 #include "base/file_descriptor_posix.h" |
8 #include "ui/gfx/native_pixmap_handle_ozone.h" | 8 #include "ui/gfx/native_pixmap_handle_ozone.h" |
9 #include "ui/ozone/public/client_native_pixmap_factory.h" | 9 #include "ui/ozone/public/client_native_pixmap_factory.h" |
10 | 10 |
| 11 #if defined(USE_VGEM_MAP) |
| 12 #include <fcntl.h> |
| 13 #include "ui/ozone/platform/drm/gpu/client_native_pixmap_vgem.h" |
| 14 #endif |
| 15 |
11 namespace ui { | 16 namespace ui { |
12 | 17 |
13 namespace { | 18 namespace { |
14 | 19 |
15 class ClientNativePixmapGbm : public ClientNativePixmap { | 20 class ClientNativePixmapGbm : public ClientNativePixmap { |
16 public: | 21 public: |
17 ClientNativePixmapGbm() {} | 22 ClientNativePixmapGbm() {} |
18 ~ClientNativePixmapGbm() override {} | 23 ~ClientNativePixmapGbm() override {} |
19 | 24 |
20 bool Map(void** data) override { | 25 void* Map() override { |
21 NOTREACHED(); | 26 NOTREACHED(); |
22 return false; | 27 return nullptr; |
23 } | 28 } |
24 void Unmap() override { NOTREACHED(); } | 29 void Unmap() override { NOTREACHED(); } |
25 void GetStride(int* stride) const override { NOTREACHED(); } | 30 void GetStride(int* stride) const override { NOTREACHED(); } |
26 }; | 31 }; |
27 | 32 |
28 class ClientNativePixmapFactoryGbm : public ClientNativePixmapFactory { | 33 class ClientNativePixmapFactoryGbm : public ClientNativePixmapFactory { |
29 public: | 34 public: |
30 ClientNativePixmapFactoryGbm() {} | 35 ClientNativePixmapFactoryGbm() { |
| 36 #if defined(USE_VGEM_MAP) |
| 37 // TODO(dshwang): remove ad-hoc file open. crrev.com/1248713002 |
| 38 static const char kVgemPath[] = "/dev/dri/renderD129"; |
| 39 int vgem_fd = open(kVgemPath, O_RDWR | O_CLOEXEC); |
| 40 vgem_fd_.reset(vgem_fd); |
| 41 DCHECK_GE(vgem_fd_.get(), 0) << "Failed to open: " << kVgemPath; |
| 42 #endif |
| 43 } |
31 ~ClientNativePixmapFactoryGbm() override {} | 44 ~ClientNativePixmapFactoryGbm() override {} |
32 | 45 |
33 // ClientNativePixmapFactory: | 46 // ClientNativePixmapFactory: |
34 std::vector<Configuration> GetSupportedConfigurations() const override { | 47 std::vector<Configuration> GetSupportedConfigurations() const override { |
35 const Configuration kConfigurations[] = { | 48 const Configuration kConfigurations[] = { |
36 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::SCANOUT}, | 49 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::SCANOUT}, |
37 {gfx::BufferFormat::BGRX_8888, gfx::BufferUsage::SCANOUT}}; | 50 {gfx::BufferFormat::BGRX_8888, gfx::BufferUsage::SCANOUT}}; |
38 std::vector<Configuration> configurations( | 51 std::vector<Configuration> configurations( |
39 kConfigurations, kConfigurations + arraysize(kConfigurations)); | 52 kConfigurations, kConfigurations + arraysize(kConfigurations)); |
| 53 #if defined(USE_VGEM_MAP) |
| 54 configurations.push_back( |
| 55 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::MAP}); |
| 56 #endif |
40 return configurations; | 57 return configurations; |
41 } | 58 } |
42 scoped_ptr<ClientNativePixmap> ImportFromHandle( | 59 scoped_ptr<ClientNativePixmap> ImportFromHandle( |
43 const gfx::NativePixmapHandle& handle, | 60 const gfx::NativePixmapHandle& handle, |
44 const gfx::Size& size, | 61 const gfx::Size& size, |
45 gfx::BufferFormat format, | |
46 gfx::BufferUsage usage) override { | 62 gfx::BufferUsage usage) override { |
47 base::ScopedFD scoped_fd(handle.fd.fd); | 63 base::ScopedFD scoped_fd(handle.fd.fd); |
48 return make_scoped_ptr<ClientNativePixmapGbm>(new ClientNativePixmapGbm); | 64 |
| 65 switch (usage) { |
| 66 case gfx::BufferUsage::MAP: |
| 67 #if defined(USE_VGEM_MAP) |
| 68 return ClientNativePixmapVgem::ImportFromDmabuf( |
| 69 vgem_fd_.get(), scoped_fd.get(), size, handle.stride); |
| 70 #endif |
| 71 NOTREACHED(); |
| 72 return nullptr; |
| 73 case gfx::BufferUsage::PERSISTENT_MAP: |
| 74 NOTREACHED(); |
| 75 return nullptr; |
| 76 case gfx::BufferUsage::SCANOUT: |
| 77 return make_scoped_ptr<ClientNativePixmapGbm>( |
| 78 new ClientNativePixmapGbm); |
| 79 } |
| 80 NOTREACHED(); |
| 81 return nullptr; |
49 } | 82 } |
50 | 83 |
51 private: | 84 private: |
| 85 #if defined(USE_VGEM_MAP) |
| 86 base::ScopedFD vgem_fd_; |
| 87 #endif |
| 88 |
52 DISALLOW_COPY_AND_ASSIGN(ClientNativePixmapFactoryGbm); | 89 DISALLOW_COPY_AND_ASSIGN(ClientNativePixmapFactoryGbm); |
53 }; | 90 }; |
54 | 91 |
55 } // namespace | 92 } // namespace |
56 | 93 |
57 ClientNativePixmapFactory* CreateClientNativePixmapFactoryGbm() { | 94 ClientNativePixmapFactory* CreateClientNativePixmapFactoryGbm() { |
58 return new ClientNativePixmapFactoryGbm(); | 95 return new ClientNativePixmapFactoryGbm(); |
59 } | 96 } |
60 | 97 |
61 } // namespace ui | 98 } // namespace ui |
OLD | NEW |