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/client_native_pixmap_factory_gbm.h" | 5 #include "ui/ozone/platform/drm/client_native_pixmap_factory_gbm.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "ui/gfx/native_pixmap_handle_ozone.h" | 10 #include "ui/gfx/native_pixmap_handle_ozone.h" |
| 11 #include "ui/ozone/platform/drm/common/client_native_pixmap_dmabuf.h" | |
| 11 #include "ui/ozone/public/client_native_pixmap_factory.h" | 12 #include "ui/ozone/public/client_native_pixmap_factory.h" |
| 12 | 13 |
| 13 #if defined(USE_VGEM_MAP) | |
| 14 #include "ui/ozone/platform/drm/common/client_native_pixmap_vgem.h" | |
| 15 #endif | |
| 16 | |
| 17 namespace ui { | 14 namespace ui { |
| 18 | 15 |
| 19 namespace { | 16 namespace { |
| 20 | 17 |
| 21 class ClientNativePixmapGbm : public ClientNativePixmap { | 18 class ClientNativePixmapGbm : public ClientNativePixmap { |
| 22 public: | 19 public: |
| 23 ClientNativePixmapGbm() {} | 20 ClientNativePixmapGbm() {} |
| 24 ~ClientNativePixmapGbm() override {} | 21 ~ClientNativePixmapGbm() override {} |
| 25 | 22 |
| 26 void* Map() override { | 23 void* Map() override { |
| 27 NOTREACHED(); | 24 NOTREACHED(); |
| 28 return nullptr; | 25 return nullptr; |
| 29 } | 26 } |
| 30 void Unmap() override { NOTREACHED(); } | 27 void Unmap() override { NOTREACHED(); } |
| 31 void GetStride(int* stride) const override { NOTREACHED(); } | 28 void GetStride(int* stride) const override { NOTREACHED(); } |
| 32 }; | 29 }; |
| 33 | 30 |
| 34 } // namespace | 31 } // namespace |
| 35 | 32 |
| 36 class ClientNativePixmapFactoryGbm : public ClientNativePixmapFactory { | 33 class ClientNativePixmapFactoryGbm : public ClientNativePixmapFactory { |
| 37 public: | 34 public: |
| 38 ClientNativePixmapFactoryGbm() {} | 35 ClientNativePixmapFactoryGbm() {} |
| 39 ~ClientNativePixmapFactoryGbm() override {} | 36 ~ClientNativePixmapFactoryGbm() override {} |
| 40 | 37 |
| 41 // ClientNativePixmapFactory: | 38 // ClientNativePixmapFactory: |
| 42 void Initialize(base::ScopedFD device_fd) override { | |
| 43 #if defined(USE_VGEM_MAP) | |
| 44 // It's called in IO thread. We rely on clients for thread-safety. | |
| 45 // Switching to an IPC message filter ensures thread-safety. | |
| 46 DCHECK_LT(vgem_fd_.get(), 0); | |
| 47 vgem_fd_ = std::move(device_fd); | |
| 48 #endif | |
| 49 } | |
| 50 bool IsConfigurationSupported(gfx::BufferFormat format, | 39 bool IsConfigurationSupported(gfx::BufferFormat format, |
| 51 gfx::BufferUsage usage) const override { | 40 gfx::BufferUsage usage) const override { |
| 52 switch (usage) { | 41 switch (usage) { |
| 53 case gfx::BufferUsage::GPU_READ: | 42 case gfx::BufferUsage::GPU_READ: |
| 54 case gfx::BufferUsage::SCANOUT: | 43 case gfx::BufferUsage::SCANOUT: |
| 55 return format == gfx::BufferFormat::RGBA_8888 || | 44 return format == gfx::BufferFormat::RGBA_8888 || |
| 56 format == gfx::BufferFormat::RGBX_8888 || | 45 format == gfx::BufferFormat::RGBX_8888 || |
| 57 format == gfx::BufferFormat::BGRA_8888 || | 46 format == gfx::BufferFormat::BGRA_8888 || |
| 58 format == gfx::BufferFormat::BGRX_8888; | 47 format == gfx::BufferFormat::BGRX_8888; |
| 59 case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE: | 48 case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE: |
| 60 case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT: { | 49 case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT: { |
| 61 #if defined(USE_VGEM_MAP) | 50 return format == gfx::BufferFormat::BGRA_8888; |
|
dshwang
2016/03/23 15:52:51
After this CL, Ozone GBM support BGRA_8888, no mat
spang
2016/03/23 16:04:01
Aren't we only turning on one-copy via flags on ve
dshwang
2016/03/23 16:31:11
Ok, it makes sense.
We add --enable-native-gpu-mem
| |
| 62 return vgem_fd_.is_valid() && format == gfx::BufferFormat::BGRA_8888; | |
| 63 #else | |
| 64 return false; | |
| 65 #endif | |
| 66 } | 51 } |
| 67 } | 52 } |
| 68 NOTREACHED(); | 53 NOTREACHED(); |
| 69 return false; | 54 return false; |
| 70 } | 55 } |
| 71 scoped_ptr<ClientNativePixmap> ImportFromHandle( | 56 scoped_ptr<ClientNativePixmap> ImportFromHandle( |
| 72 const gfx::NativePixmapHandle& handle, | 57 const gfx::NativePixmapHandle& handle, |
| 73 const gfx::Size& size, | 58 const gfx::Size& size, |
| 74 gfx::BufferUsage usage) override { | 59 gfx::BufferUsage usage) override { |
| 75 base::ScopedFD scoped_fd(handle.fd.fd); | 60 base::ScopedFD scoped_fd(handle.fd.fd); |
| 76 | 61 |
| 77 switch (usage) { | 62 switch (usage) { |
| 78 case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE: | 63 case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE: |
| 79 case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT: | 64 case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT: |
| 80 #if defined(USE_VGEM_MAP) | 65 return ClientNativePixmapDmaBuf::ImportFromDmabuf( |
| 81 // A valid |vgem_fd_| is required to acquire a VGEM bo. |vgem_fd_| is | 66 scoped_fd.get(), size, handle.stride); |
| 82 // set before a widget is created. | |
| 83 DCHECK_GE(vgem_fd_.get(), 0); | |
| 84 return ClientNativePixmapVgem::ImportFromDmabuf( | |
| 85 vgem_fd_.get(), scoped_fd.get(), size, handle.stride); | |
| 86 #endif | |
| 87 NOTREACHED(); | |
| 88 return nullptr; | |
| 89 case gfx::BufferUsage::GPU_READ: | 67 case gfx::BufferUsage::GPU_READ: |
| 90 case gfx::BufferUsage::SCANOUT: | 68 case gfx::BufferUsage::SCANOUT: |
| 91 return make_scoped_ptr<ClientNativePixmapGbm>( | 69 return make_scoped_ptr<ClientNativePixmapGbm>( |
| 92 new ClientNativePixmapGbm); | 70 new ClientNativePixmapGbm); |
| 93 } | 71 } |
| 94 NOTREACHED(); | 72 NOTREACHED(); |
| 95 return nullptr; | 73 return nullptr; |
| 96 } | 74 } |
| 97 | 75 |
| 98 private: | |
| 99 #if defined(USE_VGEM_MAP) | |
| 100 base::ScopedFD vgem_fd_; | |
| 101 #endif | |
| 102 | |
| 103 DISALLOW_COPY_AND_ASSIGN(ClientNativePixmapFactoryGbm); | 76 DISALLOW_COPY_AND_ASSIGN(ClientNativePixmapFactoryGbm); |
| 104 }; | 77 }; |
| 105 | 78 |
| 106 ClientNativePixmapFactory* CreateClientNativePixmapFactoryGbm() { | 79 ClientNativePixmapFactory* CreateClientNativePixmapFactoryGbm() { |
| 107 return new ClientNativePixmapFactoryGbm(); | 80 return new ClientNativePixmapFactoryGbm(); |
| 108 } | 81 } |
| 109 | 82 |
| 110 } // namespace ui | 83 } // namespace ui |
| OLD | NEW |