| 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 const scoped_refptr<GbmDevice>& gbm, | 176 const scoped_refptr<GbmDevice>& gbm, |
| 177 uint32_t format, | 177 uint32_t format, |
| 178 const gfx::Size& size, | 178 const gfx::Size& size, |
| 179 std::vector<base::ScopedFD>&& fds, | 179 std::vector<base::ScopedFD>&& fds, |
| 180 const std::vector<gfx::NativePixmapPlane>& planes) { | 180 const std::vector<gfx::NativePixmapPlane>& planes) { |
| 181 TRACE_EVENT2("drm", "GbmBuffer::CreateBufferFromFD", "device", | 181 TRACE_EVENT2("drm", "GbmBuffer::CreateBufferFromFD", "device", |
| 182 gbm->device_path().value(), "size", size.ToString()); | 182 gbm->device_path().value(), "size", size.ToString()); |
| 183 DCHECK_LE(fds.size(), planes.size()); | 183 DCHECK_LE(fds.size(), planes.size()); |
| 184 DCHECK_EQ(planes[0].offset, 0); | 184 DCHECK_EQ(planes[0].offset, 0); |
| 185 | 185 |
| 186 // Use scanout if supported. | 186 // Try to use scanout if supported. |
| 187 bool use_scanout = | 187 bool try_scanout = |
| 188 gbm_device_is_format_supported( | 188 gbm_device_is_format_supported( |
| 189 gbm->device(), format, GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING) && | 189 gbm->device(), format, GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING) && |
| 190 (planes.size() == 1); | 190 (planes.size() == 1); |
| 191 | 191 |
| 192 gbm_bo* bo = nullptr; | 192 gbm_bo* bo = nullptr; |
| 193 if (use_scanout) { | 193 if (try_scanout) { |
| 194 struct gbm_import_fd_data fd_data; | 194 struct gbm_import_fd_data fd_data; |
| 195 fd_data.fd = fds[0].get(); | 195 fd_data.fd = fds[0].get(); |
| 196 fd_data.width = size.width(); | 196 fd_data.width = size.width(); |
| 197 fd_data.height = size.height(); | 197 fd_data.height = size.height(); |
| 198 fd_data.stride = planes[0].stride; | 198 fd_data.stride = planes[0].stride; |
| 199 fd_data.format = format; | 199 fd_data.format = format; |
| 200 | 200 |
| 201 // The fd passed to gbm_bo_import is not ref-counted and need to be | 201 // The fd passed to gbm_bo_import is not ref-counted and need to be |
| 202 // kept open for the lifetime of the buffer. | 202 // kept open for the lifetime of the buffer. |
| 203 bo = gbm_bo_import(gbm->device(), GBM_BO_IMPORT_FD, &fd_data, | 203 bo = gbm_bo_import(gbm->device(), GBM_BO_IMPORT_FD, &fd_data, |
| 204 GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING); | 204 GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING); |
| 205 if (!bo) { | 205 if (!bo) { |
| 206 LOG(ERROR) << "nullptr returned from gbm_bo_import"; | 206 LOG(ERROR) << "nullptr returned from gbm_bo_import"; |
| 207 return nullptr; | 207 return nullptr; |
| 208 } | 208 } |
| 209 } | 209 } |
| 210 | 210 |
| 211 uint32_t flags = GBM_BO_USE_RENDERING; | 211 uint32_t flags = GBM_BO_USE_RENDERING; |
| 212 if (use_scanout) | 212 if (try_scanout) |
| 213 flags |= GBM_BO_USE_SCANOUT; | 213 flags |= GBM_BO_USE_SCANOUT; |
| 214 scoped_refptr<GbmBuffer> buffer(new GbmBuffer( | 214 scoped_refptr<GbmBuffer> buffer(new GbmBuffer( |
| 215 gbm, bo, format, flags, 0, 0, std::move(fds), size, std::move(planes))); | 215 gbm, bo, format, flags, 0, 0, std::move(fds), size, std::move(planes))); |
| 216 // If scanout support for buffer is expected then make sure we managed to | |
| 217 // create a framebuffer for it as otherwise using it for scanout will fail. | |
| 218 if (use_scanout && !buffer->GetFramebufferId()) | |
| 219 return nullptr; | |
| 220 | 216 |
| 221 return buffer; | 217 return buffer; |
| 222 } | 218 } |
| 223 | 219 |
| 224 GbmPixmap::GbmPixmap(GbmSurfaceFactory* surface_manager, | 220 GbmPixmap::GbmPixmap(GbmSurfaceFactory* surface_manager, |
| 225 const scoped_refptr<GbmBuffer>& buffer) | 221 const scoped_refptr<GbmBuffer>& buffer) |
| 226 : surface_manager_(surface_manager), buffer_(buffer) {} | 222 : surface_manager_(surface_manager), buffer_(buffer) {} |
| 227 | 223 |
| 228 void GbmPixmap::SetProcessingCallback( | 224 void GbmPixmap::SetProcessingCallback( |
| 229 const ProcessingCallback& processing_callback) { | 225 const ProcessingCallback& processing_callback) { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 DCHECK(!processing_callback_.is_null()); | 330 DCHECK(!processing_callback_.is_null()); |
| 335 if (!processing_callback_.Run(this, processed_pixmap_)) { | 331 if (!processing_callback_.Run(this, processed_pixmap_)) { |
| 336 LOG(ERROR) << "Failed processing NativePixmap"; | 332 LOG(ERROR) << "Failed processing NativePixmap"; |
| 337 return nullptr; | 333 return nullptr; |
| 338 } | 334 } |
| 339 | 335 |
| 340 return processed_pixmap_->buffer(); | 336 return processed_pixmap_->buffer(); |
| 341 } | 337 } |
| 342 | 338 |
| 343 } // namespace ui | 339 } // namespace ui |
| OLD | NEW |