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(OZONE_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 bool Map(void** data) override { |
21 NOTREACHED(); | 26 NOTREACHED(); |
22 return false; | 27 return false; |
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(OZONE_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 kConfiguratioins[] = { | 48 const Configuration kConfiguratioins[] = { |
36 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::SCANOUT}, | 49 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::SCANOUT}, |
37 {gfx::BufferFormat::RGBX_8888, gfx::BufferUsage::SCANOUT}}; | 50 {gfx::BufferFormat::RGBX_8888, gfx::BufferUsage::SCANOUT}}; |
38 std::vector<Configuration> configurations( | 51 std::vector<Configuration> configurations( |
39 kConfiguratioins, kConfiguratioins + arraysize(kConfiguratioins)); | 52 kConfiguratioins, kConfiguratioins + arraysize(kConfiguratioins)); |
53 #if defined(OZONE_USE_VGEM_MAP) | |
54 // Map requires VGEM supports. | |
55 DCHECK_GE(vgem_fd_.get(), 0); | |
reveman
2015/08/12 22:32:25
nit: you already have this DCHECK in the ctor. I t
dshwang
2015/08/13 11:30:55
Done.
| |
56 configurations.push_back( | |
57 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::MAP}); | |
58 #endif | |
40 return configurations; | 59 return configurations; |
41 } | 60 } |
42 scoped_ptr<ClientNativePixmap> ImportFromHandle( | 61 scoped_ptr<ClientNativePixmap> ImportFromHandle( |
43 const gfx::NativePixmapHandle& handle, | 62 const gfx::NativePixmapHandle& handle, |
44 const gfx::Size& size, | 63 const gfx::Size& size, |
45 gfx::BufferFormat format, | 64 gfx::BufferFormat format, |
reveman
2015/08/12 22:32:25
Format is not used for anything but a DCHECK. Can
dshwang
2015/08/13 11:30:55
remove |format| in this API
| |
46 gfx::BufferUsage usage) override { | 65 gfx::BufferUsage usage) override { |
66 DCHECK(IsConfigurationSupported(format, usage)); | |
67 DCHECK(handle.fd.auto_close); | |
47 base::ScopedFD close_fd(handle.fd.fd); | 68 base::ScopedFD close_fd(handle.fd.fd); |
48 return make_scoped_ptr<ClientNativePixmapGbm>(new ClientNativePixmapGbm); | 69 |
70 switch (usage) { | |
reveman
2015/08/12 22:32:25
To keep things simple, I'd ignore the usage here a
dshwang
2015/08/13 11:30:55
Done.
| |
71 case gfx::BufferUsage::MAP: | |
72 break; | |
spang
2015/08/12 21:40:03
This is pretty strange control flow - can you move
dshwang
2015/08/13 11:30:55
Done.
| |
73 case gfx::BufferUsage::PERSISTENT_MAP: | |
reveman
2015/08/12 22:32:25
nit: PERSISTENT_MAP is not supported. NOTREACHED h
dshwang
2015/08/13 11:30:55
As changing control flow, PERSISTENT_MAP branch di
| |
74 case gfx::BufferUsage::SCANOUT: | |
75 return make_scoped_ptr<ClientNativePixmapGbm>( | |
76 new ClientNativePixmapGbm); | |
77 } | |
reveman
2015/08/12 22:32:25
nit: please NOTREACHED for when usage is an invali
dshwang
2015/08/13 11:30:55
Done.
| |
78 | |
79 #if defined(OZONE_USE_VGEM_MAP) | |
80 DCHECK_GE(vgem_fd_.get(), 0); | |
81 return ClientNativePixmapVgem::Create( | |
82 handle, base::FileDescriptor(vgem_fd_.get(), false), size); | |
83 #else | |
84 NOTREACHED(); | |
85 return nullptr; | |
86 #endif | |
49 } | 87 } |
50 | 88 |
51 private: | 89 private: |
90 bool IsConfigurationSupported(gfx::BufferFormat format, | |
spang
2015/08/12 21:40:03
I'd suggest removing this to keep the signal/noise
reveman
2015/08/12 22:32:25
I agree, especially if we ignore the |usage| and |
dshwang
2015/08/13 11:30:55
Done.
| |
91 gfx::BufferUsage usage) { | |
92 std::vector<Configuration> configurations(GetSupportedConfigurations()); | |
93 for (auto& configuration : configurations) { | |
94 if (configuration.format == format && configuration.usage == usage) | |
95 return true; | |
96 } | |
97 return false; | |
98 } | |
99 | |
100 #if defined(OZONE_USE_VGEM_MAP) | |
101 base::ScopedFD vgem_fd_; | |
102 #endif | |
103 | |
52 DISALLOW_COPY_AND_ASSIGN(ClientNativePixmapFactoryGbm); | 104 DISALLOW_COPY_AND_ASSIGN(ClientNativePixmapFactoryGbm); |
53 }; | 105 }; |
54 | 106 |
55 } // namespace | 107 } // namespace |
56 | 108 |
57 ClientNativePixmapFactory* CreateClientNativePixmapFactoryGbm() { | 109 ClientNativePixmapFactory* CreateClientNativePixmapFactoryGbm() { |
58 return new ClientNativePixmapFactoryGbm(); | 110 return new ClientNativePixmapFactoryGbm(); |
59 } | 111 } |
60 | 112 |
61 } // namespace ui | 113 } // namespace ui |
OLD | NEW |