Chromium Code Reviews| 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 { |
| 63 DCHECK(handle.fd.auto_close); | |
|
reveman
2015/08/13 14:03:58
This DCHECK is still inappropriate imo. This funct
dshwang
2015/08/13 14:59:02
Ok, Done.
| |
| 47 base::ScopedFD scoped_fd(handle.fd.fd); | 64 base::ScopedFD scoped_fd(handle.fd.fd); |
| 65 | |
| 66 #if defined(USE_VGEM_MAP) | |
| 67 if (usage == gfx::BufferUsage::MAP) | |
|
reveman
2015/08/13 14:03:58
can we remove this if statement? if we need it the
dshwang
2015/08/13 14:59:02
I restored the switch because ClientNativePixmapGb
reveman
2015/08/13 15:15:58
Just curious, why is ClientNativePixmapGbm better
dshwang
2015/08/13 15:45:28
ClientNativePixmapVgem imports handle via drmPrime
reveman
2015/08/13 17:16:43
Why does it consume more battery? Could you explai
dshwang
2015/08/13 18:13:25
I made you confused by ambiguous reply. What I mea
dshwang
2015/08/13 18:22:09
After rethinking, I'm not sure SCANOUT and MAP is
| |
| 68 return ClientNativePixmapVgem::ImportFromDmabuf( | |
| 69 vgem_fd_.get(), scoped_fd.get(), size, handle.stride); | |
|
reveman
2015/08/13 14:03:58
nit: {} as multiple lines
| |
| 70 #endif | |
| 48 return make_scoped_ptr<ClientNativePixmapGbm>(new ClientNativePixmapGbm); | 71 return make_scoped_ptr<ClientNativePixmapGbm>(new ClientNativePixmapGbm); |
| 49 } | 72 } |
| 50 | 73 |
| 51 private: | 74 private: |
| 75 #if defined(USE_VGEM_MAP) | |
| 76 base::ScopedFD vgem_fd_; | |
| 77 #endif | |
| 78 | |
| 52 DISALLOW_COPY_AND_ASSIGN(ClientNativePixmapFactoryGbm); | 79 DISALLOW_COPY_AND_ASSIGN(ClientNativePixmapFactoryGbm); |
| 53 }; | 80 }; |
| 54 | 81 |
| 55 } // namespace | 82 } // namespace |
| 56 | 83 |
| 57 ClientNativePixmapFactory* CreateClientNativePixmapFactoryGbm() { | 84 ClientNativePixmapFactory* CreateClientNativePixmapFactoryGbm() { |
| 58 return new ClientNativePixmapFactoryGbm(); | 85 return new ClientNativePixmapFactoryGbm(); |
| 59 } | 86 } |
| 60 | 87 |
| 61 } // namespace ui | 88 } // namespace ui |
| OLD | NEW |