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" | |
8 #include "ui/gfx/native_pixmap_handle_ozone.h" | 7 #include "ui/gfx/native_pixmap_handle_ozone.h" |
9 #include "ui/ozone/public/client_native_pixmap_factory.h" | 8 #include "ui/ozone/public/client_native_pixmap_factory.h" |
10 | 9 |
11 #if defined(USE_VGEM_MAP) | 10 #if defined(USE_VGEM_MAP) |
12 #include <fcntl.h> | 11 #include "base/synchronization/waitable_event.h" |
12 #include "base/threading/platform_thread.h" | |
13 #include "base/threading/thread_restrictions.h" | |
13 #include "ui/ozone/platform/drm/gpu/client_native_pixmap_vgem.h" | 14 #include "ui/ozone/platform/drm/gpu/client_native_pixmap_vgem.h" |
14 #endif | 15 #endif |
15 | 16 |
16 namespace ui { | 17 namespace ui { |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 class ClientNativePixmapGbm : public ClientNativePixmap { | 21 class ClientNativePixmapGbm : public ClientNativePixmap { |
21 public: | 22 public: |
22 ClientNativePixmapGbm() {} | 23 ClientNativePixmapGbm() {} |
23 ~ClientNativePixmapGbm() override {} | 24 ~ClientNativePixmapGbm() override {} |
24 | 25 |
25 void* Map() override { | 26 void* Map() override { |
26 NOTREACHED(); | 27 NOTREACHED(); |
27 return nullptr; | 28 return nullptr; |
28 } | 29 } |
29 void Unmap() override { NOTREACHED(); } | 30 void Unmap() override { NOTREACHED(); } |
30 void GetStride(int* stride) const override { NOTREACHED(); } | 31 void GetStride(int* stride) const override { NOTREACHED(); } |
31 }; | 32 }; |
32 | 33 |
34 } // namespace | |
35 | |
33 class ClientNativePixmapFactoryGbm : public ClientNativePixmapFactory { | 36 class ClientNativePixmapFactoryGbm : public ClientNativePixmapFactory { |
34 public: | 37 public: |
35 ClientNativePixmapFactoryGbm() { | 38 ClientNativePixmapFactoryGbm() : set_vgem_fd_event_(true, false) {} |
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 } | |
44 ~ClientNativePixmapFactoryGbm() override {} | 39 ~ClientNativePixmapFactoryGbm() override {} |
45 | 40 |
46 // ClientNativePixmapFactory: | 41 // ClientNativePixmapFactory: |
42 void Initialize(base::ScopedFD device_fd) override { | |
43 #if defined(USE_VGEM_MAP) | |
44 DCHECK_LT(vgem_fd_.get(), 0); | |
45 vgem_fd_ = device_fd.Pass(); | |
46 #if DCHECK_IS_ON() | |
47 set_vgem_fd_thread_id_ = base::PlatformThread::CurrentRef(); | |
48 #endif | |
49 set_vgem_fd_event_.Signal(); | |
50 #endif | |
51 } | |
47 std::vector<Configuration> GetSupportedConfigurations() const override { | 52 std::vector<Configuration> GetSupportedConfigurations() const override { |
48 const Configuration kConfigurations[] = { | 53 const Configuration kConfigurations[] = { |
49 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::SCANOUT}, | 54 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::SCANOUT}, |
50 {gfx::BufferFormat::BGRX_8888, gfx::BufferUsage::SCANOUT}}; | 55 {gfx::BufferFormat::BGRX_8888, gfx::BufferUsage::SCANOUT}}; |
51 std::vector<Configuration> configurations( | 56 std::vector<Configuration> configurations( |
52 kConfigurations, kConfigurations + arraysize(kConfigurations)); | 57 kConfigurations, kConfigurations + arraysize(kConfigurations)); |
53 #if defined(USE_VGEM_MAP) | 58 #if defined(USE_VGEM_MAP) |
54 configurations.push_back( | 59 configurations.push_back( |
55 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::MAP}); | 60 {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::MAP}); |
56 #endif | 61 #endif |
57 return configurations; | 62 return configurations; |
58 } | 63 } |
59 scoped_ptr<ClientNativePixmap> ImportFromHandle( | 64 scoped_ptr<ClientNativePixmap> ImportFromHandle( |
60 const gfx::NativePixmapHandle& handle, | 65 const gfx::NativePixmapHandle& handle, |
61 const gfx::Size& size, | 66 const gfx::Size& size, |
62 gfx::BufferUsage usage) override { | 67 gfx::BufferUsage usage) override { |
63 base::ScopedFD scoped_fd(handle.fd.fd); | 68 base::ScopedFD scoped_fd(handle.fd.fd); |
64 | 69 |
65 switch (usage) { | 70 switch (usage) { |
66 case gfx::BufferUsage::MAP: | 71 case gfx::BufferUsage::MAP: |
67 #if defined(USE_VGEM_MAP) | 72 #if defined(USE_VGEM_MAP) |
73 // A valid |vgem_fd_| is required to acquire a VGEM bo. This will wait | |
74 // for a valid |vgem_fd_| if one has not yet been set. | |
75 { | |
76 base::ThreadRestrictions::ScopedAllowWait allow_wait; | |
77 set_vgem_fd_event_.Wait(); | |
78 } | |
79 #if DCHECK_IS_ON() | |
80 DCHECK(!(set_vgem_fd_thread_id_ == base::PlatformThread::CurrentRef())); | |
81 #endif | |
82 DCHECK_GE(vgem_fd_.get(), 0); | |
reveman
2015/08/25 17:06:19
I think this DCHECK_GE is all we need after discus
dshwang
2015/08/26 13:27:44
That's excellent conclusion which everybody is hap
| |
68 return ClientNativePixmapVgem::ImportFromDmabuf( | 83 return ClientNativePixmapVgem::ImportFromDmabuf( |
69 vgem_fd_.get(), scoped_fd.get(), size, handle.stride); | 84 vgem_fd_.get(), scoped_fd.get(), size, handle.stride); |
70 #endif | 85 #endif |
71 NOTREACHED(); | 86 NOTREACHED(); |
72 return nullptr; | 87 return nullptr; |
73 case gfx::BufferUsage::PERSISTENT_MAP: | 88 case gfx::BufferUsage::PERSISTENT_MAP: |
74 NOTREACHED(); | 89 NOTREACHED(); |
75 return nullptr; | 90 return nullptr; |
76 case gfx::BufferUsage::SCANOUT: | 91 case gfx::BufferUsage::SCANOUT: |
77 return make_scoped_ptr<ClientNativePixmapGbm>( | 92 return make_scoped_ptr<ClientNativePixmapGbm>( |
78 new ClientNativePixmapGbm); | 93 new ClientNativePixmapGbm); |
79 } | 94 } |
80 NOTREACHED(); | 95 NOTREACHED(); |
81 return nullptr; | 96 return nullptr; |
82 } | 97 } |
83 | 98 |
84 private: | 99 private: |
85 #if defined(USE_VGEM_MAP) | 100 #if defined(USE_VGEM_MAP) |
86 base::ScopedFD vgem_fd_; | 101 base::ScopedFD vgem_fd_; |
102 #if DCHECK_IS_ON() | |
103 base::PlatformThreadRef set_vgem_fd_thread_id_; | |
104 #endif | |
105 base::WaitableEvent set_vgem_fd_event_; | |
87 #endif | 106 #endif |
88 | 107 |
89 DISALLOW_COPY_AND_ASSIGN(ClientNativePixmapFactoryGbm); | 108 DISALLOW_COPY_AND_ASSIGN(ClientNativePixmapFactoryGbm); |
90 }; | 109 }; |
91 | 110 |
92 } // namespace | |
93 | |
94 ClientNativePixmapFactory* CreateClientNativePixmapFactoryGbm() { | 111 ClientNativePixmapFactory* CreateClientNativePixmapFactoryGbm() { |
95 return new ClientNativePixmapFactoryGbm(); | 112 return new ClientNativePixmapFactoryGbm(); |
96 } | 113 } |
97 | 114 |
98 } // namespace ui | 115 } // namespace ui |
OLD | NEW |