Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1857)

Unified Diff: ui/ozone/platform/drm/gpu/gbm_buffer.cc

Issue 1837703002: gpu: Export/import buffers created by Ozone GMB factory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move dup() to ShareGpuMemoryBufferToGpuProcess Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gpu/ipc/service/gpu_memory_buffer_factory_ozone_native_pixmap.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/ozone/platform/drm/gpu/gbm_buffer.cc
diff --git a/ui/ozone/platform/drm/gpu/gbm_buffer.cc b/ui/ozone/platform/drm/gpu/gbm_buffer.cc
index 549b067782d11ffd1dc69067ccdc11ccab5d1224..b670e8d520a1de252c103870d9b06795e671157d 100644
--- a/ui/ozone/platform/drm/gpu/gbm_buffer.cc
+++ b/ui/ozone/platform/drm/gpu/gbm_buffer.cc
@@ -143,11 +143,41 @@ scoped_refptr<GbmBuffer> GbmBuffer::CreateBufferFromFds(
TRACE_EVENT2("drm", "GbmBuffer::CreateBufferFromFD", "device",
gbm->device_path().value(), "size", size.ToString());
DCHECK_EQ(fds.size(), strides.size());
- // TODO(reveman): Use gbm_bo_import after making buffers survive
- // GPU process crashes. crbug.com/597932
- return make_scoped_refptr(
- new GbmBuffer(gbm, nullptr, format, gfx::BufferUsage::GPU_READ,
- std::move(fds), size, strides, offsets));
+ DCHECK_EQ(fds.size(), 1u);
+ DCHECK_EQ(offsets[0], 0);
+
+ struct gbm_import_fd_data fd_data;
+ fd_data.fd = fds[0].get();
+ fd_data.width = size.width();
+ fd_data.height = size.height();
+ fd_data.stride = strides[0];
+ fd_data.format = GetFourCCFormatFromBufferFormat(format);
+
+ // Use scanout if supported.
+ const std::vector<uint32_t>& scanout_formats =
+ gbm->plane_manager()->GetSupportedFormats();
+ bool use_scanout = std::find(scanout_formats.begin(), scanout_formats.end(),
+ fd_data.format) != scanout_formats.end();
+ unsigned flags = 0;
+ if (use_scanout)
+ flags = GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING;
+
+ // The fd passed to gbm_bo_import is not ref-counted and need to be
+ // kept open for the lifetime of the buffer.
+ gbm_bo* bo = gbm_bo_import(gbm->device(), GBM_BO_IMPORT_FD, &fd_data, flags);
+ if (!bo)
+ return nullptr;
+
+ scoped_refptr<GbmBuffer> buffer(new GbmBuffer(
+ gbm, bo, format,
+ use_scanout ? gfx::BufferUsage::SCANOUT : gfx::BufferUsage::GPU_READ,
+ std::move(fds), size, strides, offsets));
+ // If scanout support for buffer is expected then make sure we managed to
+ // create a framebuffer for it as otherwise using it for scanout will fail.
+ if (use_scanout && !buffer->GetFramebufferId())
+ return nullptr;
+
+ return buffer;
}
GbmPixmap::GbmPixmap(GbmSurfaceFactory* surface_manager,
« no previous file with comments | « gpu/ipc/service/gpu_memory_buffer_factory_ozone_native_pixmap.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698