| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/gpu/gbm_buffer.h" | 5 #include "ui/ozone/platform/drm/gpu/gbm_buffer.h" |
| 6 | 6 |
| 7 #include <drm.h> | 7 #include <drm.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <gbm.h> | 9 #include <gbm.h> |
| 10 #include <xf86drm.h> | 10 #include <xf86drm.h> |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "ui/ozone/platform/drm/gpu/gbm_surfaceless.h" | 23 #include "ui/ozone/platform/drm/gpu/gbm_surfaceless.h" |
| 24 #include "ui/ozone/public/ozone_platform.h" | 24 #include "ui/ozone/public/ozone_platform.h" |
| 25 #include "ui/ozone/public/surface_factory_ozone.h" | 25 #include "ui/ozone/public/surface_factory_ozone.h" |
| 26 | 26 |
| 27 namespace ui { | 27 namespace ui { |
| 28 | 28 |
| 29 GbmBuffer::GbmBuffer(const scoped_refptr<GbmDevice>& gbm, | 29 GbmBuffer::GbmBuffer(const scoped_refptr<GbmDevice>& gbm, |
| 30 gbm_bo* bo, | 30 gbm_bo* bo, |
| 31 uint32_t format, | 31 uint32_t format, |
| 32 uint32_t flags, | 32 uint32_t flags, |
| 33 uint64_t modifier, |
| 34 uint32_t addfb_flags, |
| 33 std::vector<base::ScopedFD>&& fds, | 35 std::vector<base::ScopedFD>&& fds, |
| 34 const gfx::Size& size, | 36 const gfx::Size& size, |
| 37 |
| 35 const std::vector<gfx::NativePixmapPlane>&& planes) | 38 const std::vector<gfx::NativePixmapPlane>&& planes) |
| 36 : GbmBufferBase(gbm, bo, format, flags), | 39 : GbmBufferBase(gbm, bo, format, flags, modifier, addfb_flags), |
| 37 format_(format), | 40 format_(format), |
| 38 flags_(flags), | 41 flags_(flags), |
| 39 fds_(std::move(fds)), | 42 fds_(std::move(fds)), |
| 40 size_(size), | 43 size_(size), |
| 41 planes_(std::move(planes)) {} | 44 planes_(std::move(planes)) {} |
| 42 | 45 |
| 43 GbmBuffer::~GbmBuffer() { | 46 GbmBuffer::~GbmBuffer() { |
| 44 if (bo()) | 47 if (bo()) |
| 45 gbm_bo_destroy(bo()); | 48 gbm_bo_destroy(bo()); |
| 46 } | 49 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 DCHECK_LT(index, planes_.size()); | 87 DCHECK_LT(index, planes_.size()); |
| 85 return planes_[index].modifier; | 88 return planes_[index].modifier; |
| 86 } | 89 } |
| 87 | 90 |
| 88 // TODO(reveman): This should not be needed once crbug.com/597932 is fixed, | 91 // TODO(reveman): This should not be needed once crbug.com/597932 is fixed, |
| 89 // as the size would be queried directly from the underlying bo. | 92 // as the size would be queried directly from the underlying bo. |
| 90 gfx::Size GbmBuffer::GetSize() const { | 93 gfx::Size GbmBuffer::GetSize() const { |
| 91 return size_; | 94 return size_; |
| 92 } | 95 } |
| 93 | 96 |
| 94 // static | 97 scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferForBO( |
| 95 scoped_refptr<GbmBuffer> GbmBuffer::CreateBuffer( | |
| 96 const scoped_refptr<GbmDevice>& gbm, | 98 const scoped_refptr<GbmDevice>& gbm, |
| 99 gbm_bo* bo, |
| 97 uint32_t format, | 100 uint32_t format, |
| 98 const gfx::Size& size, | 101 const gfx::Size& size, |
| 99 uint32_t flags) { | 102 uint32_t flags, |
| 100 TRACE_EVENT2("drm", "GbmBuffer::CreateBuffer", "device", | 103 uint64_t modifier, |
| 101 gbm->device_path().value(), "size", size.ToString()); | 104 uint32_t addfb_flags) { |
| 102 | |
| 103 gbm_bo* bo = | |
| 104 gbm_bo_create(gbm->device(), size.width(), size.height(), format, flags); | |
| 105 if (!bo) | 105 if (!bo) |
| 106 return nullptr; | 106 return nullptr; |
| 107 | 107 |
| 108 std::vector<base::ScopedFD> fds; | 108 std::vector<base::ScopedFD> fds; |
| 109 std::vector<gfx::NativePixmapPlane> planes; | 109 std::vector<gfx::NativePixmapPlane> planes; |
| 110 | 110 |
| 111 for (size_t i = 0; i < gbm_bo_get_num_planes(bo); ++i) { | 111 for (size_t i = 0; i < gbm_bo_get_num_planes(bo); ++i) { |
| 112 // The fd returned by gbm_bo_get_fd is not ref-counted and need to be | 112 // The fd returned by gbm_bo_get_fd is not ref-counted and need to be |
| 113 // kept open for the lifetime of the buffer. | 113 // kept open for the lifetime of the buffer. |
| 114 base::ScopedFD fd(gbm_bo_get_plane_fd(bo, i)); | 114 base::ScopedFD fd(gbm_bo_get_plane_fd(bo, i)); |
| 115 | 115 |
| 116 // TODO(dcastagna): support multiple fds. | 116 // TODO(dcastagna): support multiple fds. |
| 117 // crbug.com/642410 | 117 // crbug.com/642410 |
| 118 if (!i) { | 118 if (!i) { |
| 119 if (!fd.is_valid()) { | 119 if (!fd.is_valid()) { |
| 120 PLOG(ERROR) << "Failed to export buffer to dma_buf"; | 120 PLOG(ERROR) << "Failed to export buffer to dma_buf"; |
| 121 gbm_bo_destroy(bo); | 121 gbm_bo_destroy(bo); |
| 122 return nullptr; | 122 return nullptr; |
| 123 } | 123 } |
| 124 fds.emplace_back(std::move(fd)); | 124 fds.emplace_back(std::move(fd)); |
| 125 } | 125 } |
| 126 | 126 |
| 127 planes.emplace_back( | 127 planes.emplace_back( |
| 128 gbm_bo_get_plane_stride(bo, i), gbm_bo_get_plane_offset(bo, i), | 128 gbm_bo_get_plane_stride(bo, i), gbm_bo_get_plane_offset(bo, i), |
| 129 gbm_bo_get_plane_size(bo, i), gbm_bo_get_plane_format_modifier(bo, i)); | 129 gbm_bo_get_plane_size(bo, i), gbm_bo_get_plane_format_modifier(bo, i)); |
| 130 } | 130 } |
| 131 scoped_refptr<GbmBuffer> buffer(new GbmBuffer( | 131 scoped_refptr<GbmBuffer> buffer( |
| 132 gbm, bo, format, flags, std::move(fds), size, std::move(planes))); | 132 new GbmBuffer(gbm, bo, format, flags, modifier, addfb_flags, |
| 133 std::move(fds), size, std::move(planes))); |
| 133 if (flags & GBM_BO_USE_SCANOUT && !buffer->GetFramebufferId()) | 134 if (flags & GBM_BO_USE_SCANOUT && !buffer->GetFramebufferId()) |
| 134 return nullptr; | 135 return nullptr; |
| 135 | 136 |
| 136 return buffer; | 137 return buffer; |
| 137 } | 138 } |
| 138 | 139 |
| 139 // static | 140 // static |
| 141 scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferWithModifiers( |
| 142 const scoped_refptr<GbmDevice>& gbm, |
| 143 uint32_t format, |
| 144 const gfx::Size& size, |
| 145 uint32_t flags, |
| 146 const std::vector<uint64_t>& modifiers) { |
| 147 TRACE_EVENT2("drm", "GbmBuffer::CreateBufferWithModifiers", "device", |
| 148 gbm->device_path().value(), "size", size.ToString()); |
| 149 |
| 150 gbm_bo* bo = |
| 151 gbm_bo_create_with_modifiers(gbm->device(), size.width(), size.height(), |
| 152 format, modifiers.data(), modifiers.size()); |
| 153 |
| 154 return CreateBufferForBO(gbm, bo, format, size, flags, |
| 155 gbm_bo_get_format_modifier(bo), |
| 156 DRM_MODE_FB_MODIFIERS); |
| 157 } |
| 158 |
| 159 // static |
| 160 scoped_refptr<GbmBuffer> GbmBuffer::CreateBuffer( |
| 161 const scoped_refptr<GbmDevice>& gbm, |
| 162 uint32_t format, |
| 163 const gfx::Size& size, |
| 164 uint32_t flags) { |
| 165 TRACE_EVENT2("drm", "GbmBuffer::CreateBuffer", "device", |
| 166 gbm->device_path().value(), "size", size.ToString()); |
| 167 |
| 168 gbm_bo* bo = |
| 169 gbm_bo_create(gbm->device(), size.width(), size.height(), format, flags); |
| 170 |
| 171 return CreateBufferForBO(gbm, bo, format, size, flags, 0, 0); |
| 172 } |
| 173 |
| 174 // static |
| 140 scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferFromFds( | 175 scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferFromFds( |
| 141 const scoped_refptr<GbmDevice>& gbm, | 176 const scoped_refptr<GbmDevice>& gbm, |
| 142 uint32_t format, | 177 uint32_t format, |
| 143 const gfx::Size& size, | 178 const gfx::Size& size, |
| 144 std::vector<base::ScopedFD>&& fds, | 179 std::vector<base::ScopedFD>&& fds, |
| 145 const std::vector<gfx::NativePixmapPlane>& planes) { | 180 const std::vector<gfx::NativePixmapPlane>& planes) { |
| 146 TRACE_EVENT2("drm", "GbmBuffer::CreateBufferFromFD", "device", | 181 TRACE_EVENT2("drm", "GbmBuffer::CreateBufferFromFD", "device", |
| 147 gbm->device_path().value(), "size", size.ToString()); | 182 gbm->device_path().value(), "size", size.ToString()); |
| 148 DCHECK_LE(fds.size(), planes.size()); | 183 DCHECK_LE(fds.size(), planes.size()); |
| 149 DCHECK_EQ(planes[0].offset, 0); | 184 DCHECK_EQ(planes[0].offset, 0); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 170 if (!bo) { | 205 if (!bo) { |
| 171 LOG(ERROR) << "nullptr returned from gbm_bo_import"; | 206 LOG(ERROR) << "nullptr returned from gbm_bo_import"; |
| 172 return nullptr; | 207 return nullptr; |
| 173 } | 208 } |
| 174 } | 209 } |
| 175 | 210 |
| 176 uint32_t flags = GBM_BO_USE_RENDERING; | 211 uint32_t flags = GBM_BO_USE_RENDERING; |
| 177 if (use_scanout) | 212 if (use_scanout) |
| 178 flags |= GBM_BO_USE_SCANOUT; | 213 flags |= GBM_BO_USE_SCANOUT; |
| 179 scoped_refptr<GbmBuffer> buffer(new GbmBuffer( | 214 scoped_refptr<GbmBuffer> buffer(new GbmBuffer( |
| 180 gbm, bo, format, flags, std::move(fds), size, std::move(planes))); | 215 gbm, bo, format, flags, 0, 0, std::move(fds), size, std::move(planes))); |
| 181 // If scanout support for buffer is expected then make sure we managed to | 216 // If scanout support for buffer is expected then make sure we managed to |
| 182 // create a framebuffer for it as otherwise using it for scanout will fail. | 217 // create a framebuffer for it as otherwise using it for scanout will fail. |
| 183 if (use_scanout && !buffer->GetFramebufferId()) | 218 if (use_scanout && !buffer->GetFramebufferId()) |
| 184 return nullptr; | 219 return nullptr; |
| 185 | 220 |
| 186 return buffer; | 221 return buffer; |
| 187 } | 222 } |
| 188 | 223 |
| 189 GbmPixmap::GbmPixmap(GbmSurfaceFactory* surface_manager, | 224 GbmPixmap::GbmPixmap(GbmSurfaceFactory* surface_manager, |
| 190 const scoped_refptr<GbmBuffer>& buffer) | 225 const scoped_refptr<GbmBuffer>& buffer) |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 DCHECK(!processing_callback_.is_null()); | 334 DCHECK(!processing_callback_.is_null()); |
| 300 if (!processing_callback_.Run(this, processed_pixmap_)) { | 335 if (!processing_callback_.Run(this, processed_pixmap_)) { |
| 301 LOG(ERROR) << "Failed processing NativePixmap"; | 336 LOG(ERROR) << "Failed processing NativePixmap"; |
| 302 return nullptr; | 337 return nullptr; |
| 303 } | 338 } |
| 304 | 339 |
| 305 return processed_pixmap_->buffer(); | 340 return processed_pixmap_->buffer(); |
| 306 } | 341 } |
| 307 | 342 |
| 308 } // namespace ui | 343 } // namespace ui |
| OLD | NEW |