Commit a01342d0 authored by Alexandros Frantzis's avatar Alexandros Frantzis Committed by Commit Bot

ozone: Ensure we don't return invalid GbmBuffer objects

In this particular case, ensure we don't return a non-null GbmBuffer
backed by a null gbm_bo.

Bug: 882429
Change-Id: I4f54102f18d6c177984316b07f30a1f1e4da92ff
Reviewed-on: https://chromium-review.googlesource.com/1219087
Commit-Queue: Michael Spang <spang@chromium.org>
Reviewed-by: default avatarMaksim Sisov <msisov@igalia.com>
Reviewed-by: default avatarMichael Spang <spang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593764}
parent 404bbbd8
......@@ -218,27 +218,30 @@ class Device final : public ui::GbmDevice {
gbm_flags &= ~GBM_BO_USE_SCANOUT;
struct gbm_bo* bo = nullptr;
if (gbm_device_is_format_supported(device_, format, gbm_flags)) {
struct gbm_import_fd_planar_data fd_data;
fd_data.width = size.width();
fd_data.height = size.height();
fd_data.format = format;
DCHECK_LE(planes.size(), 3u);
for (size_t i = 0; i < planes.size(); ++i) {
fd_data.fds[i] = fds[i < fds.size() ? i : 0].get();
fd_data.strides[i] = planes[i].stride;
fd_data.offsets[i] = planes[i].offset;
fd_data.format_modifiers[i] = planes[i].modifier;
}
if (!gbm_device_is_format_supported(device_, format, gbm_flags)) {
LOG(ERROR) << "gbm format not supported: " << format;
return nullptr;
}
// The fd passed to gbm_bo_import is not ref-counted and need to be
// kept open for the lifetime of the buffer.
bo = gbm_bo_import(device_, GBM_BO_IMPORT_FD_PLANAR, &fd_data, gbm_flags);
if (!bo) {
LOG(ERROR) << "nullptr returned from gbm_bo_import";
return nullptr;
}
struct gbm_import_fd_planar_data fd_data;
fd_data.width = size.width();
fd_data.height = size.height();
fd_data.format = format;
DCHECK_LE(planes.size(), 3u);
for (size_t i = 0; i < planes.size(); ++i) {
fd_data.fds[i] = fds[i < fds.size() ? i : 0].get();
fd_data.strides[i] = planes[i].stride;
fd_data.offsets[i] = planes[i].offset;
fd_data.format_modifiers[i] = planes[i].modifier;
}
// The fd passed to gbm_bo_import is not ref-counted and need to be
// kept open for the lifetime of the buffer.
bo = gbm_bo_import(device_, GBM_BO_IMPORT_FD_PLANAR, &fd_data, gbm_flags);
if (!bo) {
LOG(ERROR) << "nullptr returned from gbm_bo_import";
return nullptr;
}
return std::make_unique<Buffer>(bo, format, gbm_flags, planes[0].modifier,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment