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

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

Issue 1381133002: ozone: Implement support for CreateGpuMemoryBufferFromHandle for OzoneNativePixmap backed GMBs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gmb-factory-create-from-handle
Patch Set: fixed fd ownership errors Created 5 years, 2 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
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 117a52f7c1bb145828cc6132d9dcb074c35962ce..4e17dd7213bcdbb09f281f084314754b1c666fed 100644
--- a/ui/ozone/platform/drm/gpu/gbm_buffer.cc
+++ b/ui/ozone/platform/drm/gpu/gbm_buffer.cc
@@ -58,19 +58,25 @@ scoped_refptr<GbmBuffer> GbmBuffer::CreateBuffer(
return buffer;
}
-GbmPixmap::GbmPixmap(const scoped_refptr<GbmBuffer>& buffer,
- GbmSurfaceFactory* surface_manager)
- : buffer_(buffer), surface_manager_(surface_manager) {}
+GbmPixmap::GbmPixmap(GbmSurfaceFactory* surface_manager)
+ : surface_manager_(surface_manager) {}
-bool GbmPixmap::Initialize() {
+void GbmPixmap::Initialize(int dma_buf, int dma_buf_pitch) {
+ dma_buf_ = dma_buf;
+ dma_buf_pitch_ = dma_buf_pitch;
+}
+
+bool GbmPixmap::InitializeFromBuffer(const scoped_refptr<GbmBuffer>& buffer) {
// We want to use the GBM API because it's going to call into libdrm
// which might do some optimizations on buffer allocation,
// especially when sharing buffers via DMABUF.
- dma_buf_ = gbm_bo_get_fd(buffer_->bo());
- if (dma_buf_ < 0) {
+ int dma_buf = gbm_bo_get_fd(buffer->bo());
+ if (dma_buf < 0) {
PLOG(ERROR) << "Failed to export buffer to dma_buf";
return false;
}
+ Initialize(dma_buf, gbm_bo_get_stride(buffer->bo()));
+ buffer_ = buffer;
return true;
}
@@ -92,7 +98,7 @@ gfx::NativePixmapHandle GbmPixmap::ExportHandle() {
}
handle.fd = base::FileDescriptor(dmabuf_fd, true /* auto_close */);
- handle.stride = gbm_bo_get_stride(buffer_->bo());
+ handle.stride = dma_buf_pitch_;
return handle;
}
@@ -110,7 +116,7 @@ int GbmPixmap::GetDmaBufFd() {
}
int GbmPixmap::GetDmaBufPitch() {
- return gbm_bo_get_stride(buffer_->bo());
+ return dma_buf_pitch_;
}
bool GbmPixmap::ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
@@ -118,7 +124,6 @@ bool GbmPixmap::ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
gfx::OverlayTransform plane_transform,
const gfx::Rect& display_bounds,
const gfx::RectF& crop_rect) {
- DCHECK(buffer_->GetUsage() == gfx::BufferUsage::SCANOUT);
gfx::Size required_size;
if (plane_z_order &&
ShouldApplyScaling(display_bounds, crop_rect, &required_size)) {
@@ -131,6 +136,13 @@ bool GbmPixmap::ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
}
}
+ // TODO(reveman): Add support for imported buffers. crbug.com/541558
+ if (!buffer_) {
+ PLOG(ERROR) << "ScheduleOverlayPlane requires a buffer.";
+ return false;
+ }
+
+ DCHECK(buffer_->GetUsage() == gfx::BufferUsage::SCANOUT);
surface_manager_->GetSurface(widget)->QueueOverlayPlane(OverlayPlane(
buffer_, plane_z_order, plane_transform, display_bounds, crop_rect));
return true;
@@ -144,6 +156,11 @@ bool GbmPixmap::ShouldApplyScaling(const gfx::Rect& display_bounds,
return false;
}
+ if (!buffer_) {
+ PLOG(ERROR) << "ShouldApplyScaling requires a buffer.";
+ return false;
+ }
+
gfx::Size pixmap_size = buffer_->GetSize();
// If the required size is not integer-sized, round it to the next integer.
*required_size = gfx::ToCeiledSize(

Powered by Google App Engine
This is Rietveld 408576698