Chromium Code Reviews| Index: ui/ozone/platform/drm/common/client_native_pixmap_factory_gbm.cc |
| diff --git a/ui/ozone/platform/drm/common/client_native_pixmap_factory_gbm.cc b/ui/ozone/platform/drm/common/client_native_pixmap_factory_gbm.cc |
| index 76a94b89ad9f65b9fa74ae900072f02b7a85dc65..65a347fc34a9015e8d7298a477f86fb91edd3688 100644 |
| --- a/ui/ozone/platform/drm/common/client_native_pixmap_factory_gbm.cc |
| +++ b/ui/ozone/platform/drm/common/client_native_pixmap_factory_gbm.cc |
| @@ -4,12 +4,13 @@ |
| #include "ui/ozone/platform/drm/common/client_native_pixmap_factory_gbm.h" |
| -#include "base/file_descriptor_posix.h" |
| #include "ui/gfx/native_pixmap_handle_ozone.h" |
| #include "ui/ozone/public/client_native_pixmap_factory.h" |
| #if defined(USE_VGEM_MAP) |
| #include <fcntl.h> |
| +#include "base/synchronization/waitable_event.h" |
| +#include "base/threading/platform_thread.h" |
| #include "ui/ozone/platform/drm/gpu/client_native_pixmap_vgem.h" |
| #endif |
| @@ -32,18 +33,35 @@ class ClientNativePixmapGbm : public ClientNativePixmap { |
| class ClientNativePixmapFactoryGbm : public ClientNativePixmapFactory { |
| public: |
| - ClientNativePixmapFactoryGbm() { |
| + ClientNativePixmapFactoryGbm() : set_vgem_fd_event_(true, false) {} |
| + ~ClientNativePixmapFactoryGbm() override {} |
| + |
| + // ClientNativePixmapFactory: |
| + int OpenVgemFD() const override { |
| #if defined(USE_VGEM_MAP) |
| - // TODO(dshwang): remove ad-hoc file open. crrev.com/1248713002 |
| static const char kVgemPath[] = "/dev/dri/renderD129"; |
| int vgem_fd = open(kVgemPath, O_RDWR | O_CLOEXEC); |
| - vgem_fd_.reset(vgem_fd); |
| - DCHECK_GE(vgem_fd_.get(), 0) << "Failed to open: " << kVgemPath; |
| + DCHECK_GE(vgem_fd, 0) << "Failed to open: " << kVgemPath; |
| + return vgem_fd; |
| +#endif |
| + return -1; |
| + } |
| + |
|
reveman
2015/08/14 13:19:13
nit: remove blank line as this is part of the Clie
dshwang
2015/08/14 16:20:27
Done.
|
| + void SetVgemFD(const base::FileDescriptor& vgem_fd) override { |
| +#if defined(USE_VGEM_MAP) |
| + if (vgem_fd_.get() < 0) { |
|
reveman
2015/08/14 13:19:13
hm, are you sure this gets called multiple times?
dshwang
2015/08/14 16:20:27
When I test using --renderer-process-limit=2, it d
|
| + vgem_fd_.reset(vgem_fd.fd); |
| +#ifndef NDEBUG |
| + set_vgem_fd_thread_id_ = base::PlatformThread::CurrentRef(); |
| +#endif |
| + set_vgem_fd_event_.Signal(); |
| + return; |
| + } |
| + // Many child threads can live in the same process. e.g. --single-process |
| + base::ScopedFD scoped_fd(vgem_fd.fd); |
| #endif |
| } |
| - ~ClientNativePixmapFactoryGbm() override {} |
| - // ClientNativePixmapFactory: |
| std::vector<Configuration> GetSupportedConfigurations() const override { |
| const Configuration kConfigurations[] = { |
| {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::SCANOUT}, |
| @@ -65,6 +83,13 @@ class ClientNativePixmapFactoryGbm : public ClientNativePixmapFactory { |
| switch (usage) { |
| case gfx::BufferUsage::MAP: |
| #if defined(USE_VGEM_MAP) |
| + // A valid |vgem_fd_| is required to acquire a VGEM bo. This will wait |
| + // for a valid |vgem_fd_| if one has not yet been set. |
| + set_vgem_fd_event_.Wait(); |
| +#ifndef NDEBUG |
| + DCHECK(!(set_vgem_fd_thread_id_ == base::PlatformThread::CurrentRef())); |
| +#endif |
| + DCHECK(vgem_fd_.get()); |
| return ClientNativePixmapVgem::ImportFromDmabuf( |
| vgem_fd_.get(), scoped_fd.get(), size, handle.stride); |
| #endif |
| @@ -84,6 +109,10 @@ class ClientNativePixmapFactoryGbm : public ClientNativePixmapFactory { |
| private: |
| #if defined(USE_VGEM_MAP) |
| base::ScopedFD vgem_fd_; |
| +#ifndef NDEBUG |
| + base::PlatformThreadRef set_vgem_fd_thread_id_; |
| +#endif |
| + base::WaitableEvent set_vgem_fd_event_; |
| #endif |
| DISALLOW_COPY_AND_ASSIGN(ClientNativePixmapFactoryGbm); |