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 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(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::RGBX_8888, gfx::BufferUsage::SCANOUT}}; | 50 {gfx::BufferFormat::RGBX_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 | |
reveman
2015/08/13 17:16:43
nit: NOTREACHED(); return nullptr; or add a commen
dshwang
2015/08/13 18:13:25
Done by code. I think code is better than comment.
| |
71 case gfx::BufferUsage::PERSISTENT_MAP: | |
72 NOTREACHED(); | |
73 return nullptr; | |
74 case gfx::BufferUsage::SCANOUT: | |
75 return make_scoped_ptr<ClientNativePixmapGbm>( | |
76 new ClientNativePixmapGbm); | |
77 } | |
78 NOTREACHED(); | |
79 return nullptr; | |
49 } | 80 } |
50 | 81 |
51 private: | 82 private: |
83 #if defined(USE_VGEM_MAP) | |
84 base::ScopedFD vgem_fd_; | |
85 #endif | |
86 | |
52 DISALLOW_COPY_AND_ASSIGN(ClientNativePixmapFactoryGbm); | 87 DISALLOW_COPY_AND_ASSIGN(ClientNativePixmapFactoryGbm); |
53 }; | 88 }; |
54 | 89 |
55 } // namespace | 90 } // namespace |
56 | 91 |
57 ClientNativePixmapFactory* CreateClientNativePixmapFactoryGbm() { | 92 ClientNativePixmapFactory* CreateClientNativePixmapFactoryGbm() { |
58 return new ClientNativePixmapFactoryGbm(); | 93 return new ClientNativePixmapFactoryGbm(); |
59 } | 94 } |
60 | 95 |
61 } // namespace ui | 96 } // namespace ui |
OLD | NEW |