Chromium Code Reviews| 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 // Try to use scanout if supported. | 186 // Try to use scanout if supported. |
| 187 bool try_scanout = | 187 bool try_scanout = gbm_device_is_format_supported( |
| 188 gbm_device_is_format_supported( | 188 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); | |
| 191 | 189 |
| 192 gbm_bo* bo = nullptr; | 190 gbm_bo* bo = nullptr; |
| 193 if (try_scanout) { | 191 if (try_scanout) { |
| 194 struct gbm_import_fd_data fd_data; | 192 struct gbm_import_fd_planar_data fd_data {}; |
|
reveman
2017/03/21 03:36:09
nit: leave uninitialized so asan can detect if gbm
Daniele Castagna
2017/03/21 03:47:09
Done.
| |
| 195 fd_data.fd = fds[0].get(); | |
| 196 fd_data.width = size.width(); | 193 fd_data.width = size.width(); |
| 197 fd_data.height = size.height(); | 194 fd_data.height = size.height(); |
| 198 fd_data.stride = planes[0].stride; | |
| 199 fd_data.format = format; | 195 fd_data.format = format; |
| 200 | 196 |
| 197 DCHECK_LT(planes.size(), 3u); | |
| 198 for (size_t i = 0; i < planes.size(); ++i) { | |
| 199 fd_data.fds[i] = fds[i < fds.size() ? i : 0].get(); | |
|
reveman
2017/03/21 03:36:09
what if fds.size() is 2 and planes.size() is 3. do
Daniele Castagna
2017/03/21 03:47:09
This is consistent with what we do for eglCreateIm
| |
| 200 fd_data.strides[i] = planes[i].stride; | |
| 201 fd_data.offsets[i] = planes[i].offset; | |
| 202 fd_data.format_modifiers[i] = planes[i].modifier; | |
| 203 } | |
| 204 | |
| 201 // The fd passed to gbm_bo_import is not ref-counted and need to be | 205 // The fd passed to gbm_bo_import is not ref-counted and need to be |
| 202 // kept open for the lifetime of the buffer. | 206 // kept open for the lifetime of the buffer. |
| 203 bo = gbm_bo_import(gbm->device(), GBM_BO_IMPORT_FD, &fd_data, | 207 bo = gbm_bo_import(gbm->device(), GBM_BO_IMPORT_FD_PLANAR, &fd_data, |
| 204 GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING); | 208 GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING); |
| 205 if (!bo) { | 209 if (!bo) { |
| 206 LOG(ERROR) << "nullptr returned from gbm_bo_import"; | 210 LOG(ERROR) << "nullptr returned from gbm_bo_import"; |
| 207 return nullptr; | 211 return nullptr; |
| 208 } | 212 } |
| 209 } | 213 } |
| 210 | 214 |
| 211 uint32_t flags = GBM_BO_USE_RENDERING; | 215 uint32_t flags = GBM_BO_USE_RENDERING; |
| 212 if (try_scanout) | 216 if (try_scanout) |
| 213 flags |= GBM_BO_USE_SCANOUT; | 217 flags |= GBM_BO_USE_SCANOUT; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 330 DCHECK(!processing_callback_.is_null()); | 334 DCHECK(!processing_callback_.is_null()); |
| 331 if (!processing_callback_.Run(this, processed_pixmap_)) { | 335 if (!processing_callback_.Run(this, processed_pixmap_)) { |
| 332 LOG(ERROR) << "Failed processing NativePixmap"; | 336 LOG(ERROR) << "Failed processing NativePixmap"; |
| 333 return nullptr; | 337 return nullptr; |
| 334 } | 338 } |
| 335 | 339 |
| 336 return processed_pixmap_->buffer(); | 340 return processed_pixmap_->buffer(); |
| 337 } | 341 } |
| 338 | 342 |
| 339 } // namespace ui | 343 } // namespace ui |
| OLD | NEW |