| 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, |
| 33 std::vector<base::ScopedFD>&& fds, | 34 std::vector<base::ScopedFD>&& fds, |
| 34 const gfx::Size& size, | 35 const gfx::Size& size, |
| 35 const std::vector<gfx::NativePixmapPlane>&& planes) | 36 const std::vector<gfx::NativePixmapPlane>&& planes) |
| 36 : GbmBufferBase(gbm, bo, format, flags), | 37 : GbmBufferBase(gbm, bo, format, flags), |
| 37 format_(format), | 38 format_(format), |
| 38 flags_(flags), | 39 flags_(flags), |
| 40 modifier_(modifier), |
| 39 fds_(std::move(fds)), | 41 fds_(std::move(fds)), |
| 40 size_(size), | 42 size_(size), |
| 41 planes_(std::move(planes)) {} | 43 planes_(std::move(planes)) {} |
| 42 | 44 |
| 43 GbmBuffer::~GbmBuffer() { | 45 GbmBuffer::~GbmBuffer() { |
| 44 if (bo()) | 46 if (bo()) |
| 45 gbm_bo_destroy(bo()); | 47 gbm_bo_destroy(bo()); |
| 46 } | 48 } |
| 47 | 49 |
| 48 bool GbmBuffer::AreFdsValid() const { | 50 bool GbmBuffer::AreFdsValid() const { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 return nullptr; | 124 return nullptr; |
| 123 } | 125 } |
| 124 fds.emplace_back(std::move(fd)); | 126 fds.emplace_back(std::move(fd)); |
| 125 } | 127 } |
| 126 | 128 |
| 127 planes.emplace_back( | 129 planes.emplace_back( |
| 128 gbm_bo_get_plane_stride(bo, i), gbm_bo_get_plane_offset(bo, i), | 130 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)); | 131 gbm_bo_get_plane_size(bo, i), gbm_bo_get_plane_format_modifier(bo, i)); |
| 130 } | 132 } |
| 131 scoped_refptr<GbmBuffer> buffer(new GbmBuffer( | 133 scoped_refptr<GbmBuffer> buffer(new GbmBuffer( |
| 132 gbm, bo, format, flags, std::move(fds), size, std::move(planes))); | 134 gbm, bo, format, flags, 0, std::move(fds), size, std::move(planes))); |
| 133 if (flags & GBM_BO_USE_SCANOUT && !buffer->GetFramebufferId()) | 135 if (flags & GBM_BO_USE_SCANOUT && !buffer->GetFramebufferId()) |
| 134 return nullptr; | 136 return nullptr; |
| 135 | 137 |
| 138 return buffer; |
| 139 } |
| 140 |
| 141 // static |
| 142 scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferWithModifiers( |
| 143 const scoped_refptr<GbmDevice>& gbm, |
| 144 uint32_t format, |
| 145 const gfx::Size& size, |
| 146 uint32_t flags, |
| 147 const uint64_t *modifiers, uint32_t nmodifiers) { |
| 148 TRACE_EVENT2("drm", "GbmBuffer::CreateBufferWithModifiers", "device", |
| 149 gbm->device_path().value(), "size", size.ToString()); |
| 150 |
| 151 gbm_bo* bo = |
| 152 gbm_bo_create_with_modifiers(gbm->device(), size.width(), size.height(), for
mat, |
| 153 modifiers, nmodifiers); |
| 154 if (!bo) |
| 155 return nullptr; |
| 156 |
| 157 uint64_t modifier = gbm_bo_get_format_modifier(bo); |
| 158 |
| 159 std::vector<base::ScopedFD> fds; |
| 160 std::vector<gfx::NativePixmapPlane> planes; |
| 161 |
| 162 for (size_t i = 0; i < gbm_bo_get_num_planes(bo); ++i) { |
| 163 // The fd returned by gbm_bo_get_fd is not ref-counted and need to be |
| 164 // kept open for the lifetime of the buffer. |
| 165 base::ScopedFD fd(gbm_bo_get_plane_fd(bo, i)); |
| 166 |
| 167 // TODO(dcastagna): support multiple fds. |
| 168 // crbug.com/642410 |
| 169 if (!i) { |
| 170 if (!fd.is_valid()) { |
| 171 PLOG(ERROR) << "Failed to export buffer to dma_buf"; |
| 172 gbm_bo_destroy(bo); |
| 173 return nullptr; |
| 174 } |
| 175 fds.emplace_back(std::move(fd)); |
| 176 } |
| 177 |
| 178 planes.emplace_back( |
| 179 gbm_bo_get_plane_stride(bo, i), gbm_bo_get_plane_offset(bo, i), |
| 180 gbm_bo_get_plane_size(bo, i), gbm_bo_get_plane_format_modifier(bo, i)); |
| 181 } |
| 182 scoped_refptr<GbmBuffer> buffer(new GbmBuffer( |
| 183 gbm, bo, format, flags, modifier, std::move(fds), size, std::move(planes))); |
| 184 if (flags & GBM_BO_USE_SCANOUT && !buffer->GetFramebufferId()) |
| 185 return nullptr; |
| 186 |
| 136 return buffer; | 187 return buffer; |
| 137 } | 188 } |
| 138 | 189 |
| 139 // static | 190 // static |
| 140 scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferFromFds( | 191 scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferFromFds( |
| 141 const scoped_refptr<GbmDevice>& gbm, | 192 const scoped_refptr<GbmDevice>& gbm, |
| 142 uint32_t format, | 193 uint32_t format, |
| 143 const gfx::Size& size, | 194 const gfx::Size& size, |
| 144 std::vector<base::ScopedFD>&& fds, | 195 std::vector<base::ScopedFD>&& fds, |
| 145 const std::vector<gfx::NativePixmapPlane>& planes) { | 196 const std::vector<gfx::NativePixmapPlane>& planes) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 170 if (!bo) { | 221 if (!bo) { |
| 171 LOG(ERROR) << "nullptr returned from gbm_bo_import"; | 222 LOG(ERROR) << "nullptr returned from gbm_bo_import"; |
| 172 return nullptr; | 223 return nullptr; |
| 173 } | 224 } |
| 174 } | 225 } |
| 175 | 226 |
| 176 uint32_t flags = GBM_BO_USE_RENDERING; | 227 uint32_t flags = GBM_BO_USE_RENDERING; |
| 177 if (use_scanout) | 228 if (use_scanout) |
| 178 flags |= GBM_BO_USE_SCANOUT; | 229 flags |= GBM_BO_USE_SCANOUT; |
| 179 scoped_refptr<GbmBuffer> buffer(new GbmBuffer( | 230 scoped_refptr<GbmBuffer> buffer(new GbmBuffer( |
| 180 gbm, bo, format, flags, std::move(fds), size, std::move(planes))); | 231 gbm, bo, format, 0, flags, std::move(fds), size, std::move(planes))); |
| 181 // If scanout support for buffer is expected then make sure we managed to | 232 // 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. | 233 // create a framebuffer for it as otherwise using it for scanout will fail. |
| 183 if (use_scanout && !buffer->GetFramebufferId()) | 234 if (use_scanout && !buffer->GetFramebufferId()) |
| 184 return nullptr; | 235 return nullptr; |
| 185 | 236 |
| 186 return buffer; | 237 return buffer; |
| 187 } | 238 } |
| 188 | 239 |
| 189 GbmPixmap::GbmPixmap(GbmSurfaceFactory* surface_manager, | 240 GbmPixmap::GbmPixmap(GbmSurfaceFactory* surface_manager, |
| 190 const scoped_refptr<GbmBuffer>& buffer) | 241 const scoped_refptr<GbmBuffer>& buffer) |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 DCHECK(!processing_callback_.is_null()); | 350 DCHECK(!processing_callback_.is_null()); |
| 300 if (!processing_callback_.Run(this, processed_pixmap_)) { | 351 if (!processing_callback_.Run(this, processed_pixmap_)) { |
| 301 LOG(ERROR) << "Failed processing NativePixmap"; | 352 LOG(ERROR) << "Failed processing NativePixmap"; |
| 302 return nullptr; | 353 return nullptr; |
| 303 } | 354 } |
| 304 | 355 |
| 305 return processed_pixmap_->buffer(); | 356 return processed_pixmap_->buffer(); |
| 306 } | 357 } |
| 307 | 358 |
| 308 } // namespace ui | 359 } // namespace ui |
| OLD | NEW |