[PATCH xf86-video-amdgpu 02/11] Split out struct drmmode_scanout for rotation shadow buffer information

Michel Dänzer michel at daenzer.net
Wed Jun 10 02:04:17 PDT 2015


From: Michel Dänzer <michel.daenzer at amd.com>

Will be used for other kinds of dedicated scanout buffers as well.

(cherry picked from radeon commit 9be7dd382e86d2b804de81d4e2af7431b2e16843)

Signed-off-by: Darren Powell <darren.powell at amd.com>
Signed-off-by: Michel Dänzer <michel.daenzer at amd.com>
---
 src/amdgpu_present.c  |   2 +-
 src/drmmode_display.c | 159 +++++++++++++++++++++++++++++---------------------
 src/drmmode_display.h |   9 ++-
 3 files changed, 102 insertions(+), 68 deletions(-)

diff --git a/src/amdgpu_present.c b/src/amdgpu_present.c
index c0a5a32..75a4ba3 100644
--- a/src/amdgpu_present.c
+++ b/src/amdgpu_present.c
@@ -227,7 +227,7 @@ amdgpu_present_check_flip(RRCrtcPtr crtc, WindowPtr window, PixmapPtr pixmap,
 		drmmode_crtc_private_ptr drmmode_crtc = xf86_crtc->driver_private;
 
 		if (!drmmode_crtc ||
-		    drmmode_crtc->rotate_buffer != NULL ||
+		    drmmode_crtc->rotate.bo != NULL ||
 		    drmmode_crtc->dpms_mode != DPMSModeOn)
 			return FALSE;
 	}
diff --git a/src/drmmode_display.c b/src/drmmode_display.c
index c391ab2..7264ea0 100644
--- a/src/drmmode_display.c
+++ b/src/drmmode_display.c
@@ -314,6 +314,93 @@ void drmmode_copy_fb(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
 	}
 }
 
+static void
+drmmode_crtc_scanout_destroy(drmmode_ptr drmmode,
+                             struct drmmode_scanout *scanout)
+{
+
+	if (scanout->pixmap) {
+		drmmode_destroy_bo_pixmap(scanout->pixmap);
+		scanout->pixmap = NULL;
+	}
+
+	if (scanout->bo) {
+		drmModeRmFB(drmmode->fd, scanout->fb_id);
+		scanout->fb_id = 0;
+		amdgpu_bo_unref(&scanout->bo);
+		scanout->bo = NULL;
+	}
+
+}
+
+static void *
+drmmode_crtc_scanout_allocate(xf86CrtcPtr crtc,
+                              struct drmmode_scanout *scanout,
+                              int width, int height)
+{
+	ScrnInfoPtr pScrn = crtc->scrn;
+	AMDGPUInfoPtr info = AMDGPUPTR(pScrn);
+	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+	drmmode_ptr drmmode = drmmode_crtc->drmmode;
+	int ret;
+	int pitch;
+	union gbm_bo_handle bo_handle;
+
+	/* rotation requires acceleration */
+	if (info->shadow_fb) {
+		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+			   "Rotation requires acceleration!\n");
+		return NULL;
+	}
+
+	scanout->bo = amdgpu_alloc_pixmap_bo(pScrn, width, height,
+					       pScrn->depth, 0,
+					       pScrn->bitsPerPixel, &pitch);
+	if (!scanout->bo) {
+		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+			   "Failed to allocate rotation buffer memory\n");
+		return NULL;
+	}
+
+	bo_handle = gbm_bo_get_handle(scanout->bo->bo.gbm);
+	ret = drmModeAddFB(drmmode->fd, width, height, pScrn->depth,
+			   pScrn->bitsPerPixel, pitch,
+			   bo_handle.u32, &scanout->fb_id);
+	if (ret) {
+		ErrorF("failed to add rotate fb\n");
+	}
+
+	return scanout->bo;
+}
+
+static PixmapPtr
+drmmode_crtc_scanout_create(xf86CrtcPtr crtc,
+                            struct drmmode_scanout *scanout,
+                            void *data, int width, int height)
+{
+	ScrnInfoPtr pScrn = crtc->scrn;
+	unsigned long rotate_pitch;
+
+	if (!data)
+		data = drmmode_crtc_scanout_allocate(crtc, scanout, width, height);
+
+	rotate_pitch = gbm_bo_get_stride(scanout->bo->bo.gbm);
+
+	scanout->pixmap = drmmode_create_bo_pixmap(pScrn,
+						 width, height,
+						 pScrn->depth,
+						 pScrn->bitsPerPixel,
+						 rotate_pitch,
+						 scanout->bo);
+	if (scanout->pixmap == NULL) {
+		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+		           "Couldn't allocate shadow pixmap for rotated CRTC\n");
+	}
+	return scanout->pixmap;
+
+}
+
+
 static Bool
 drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
 		       Rotation rotation, int x, int y)
@@ -406,8 +493,8 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
 			y = 0;
 		} else
 #endif
-		if (drmmode_crtc->rotate_fb_id) {
-			fb_id = drmmode_crtc->rotate_fb_id;
+		if (drmmode_crtc->rotate.fb_id) {
+			fb_id = drmmode_crtc->rotate.fb_id;
 			x = y = 0;
 		}
 		ret =
@@ -527,68 +614,19 @@ static void drmmode_show_cursor(xf86CrtcPtr crtc)
 static void *drmmode_crtc_shadow_allocate(xf86CrtcPtr crtc, int width,
 					  int height)
 {
-	ScrnInfoPtr pScrn = crtc->scrn;
-	AMDGPUInfoPtr info = AMDGPUPTR(pScrn);
 	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
-	drmmode_ptr drmmode = drmmode_crtc->drmmode;
-	struct amdgpu_buffer *rotate_buffer = NULL;
-	int ret;
-	int pitch;
-	union gbm_bo_handle bo_handle;
-
-	/* rotation requires acceleration */
-	if (info->shadow_fb) {
-		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-			   "Rotation requires acceleration!\n");
-		return NULL;
-	}
 
-	rotate_buffer = amdgpu_alloc_pixmap_bo(pScrn, width, height,
-					       pScrn->depth, 0,
-					       pScrn->bitsPerPixel, &pitch);
-	if (!rotate_buffer) {
-		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-			   "Failed to allocate rotation buffer memory\n");
-		return NULL;
-	}
-
-	bo_handle = gbm_bo_get_handle(rotate_buffer->bo.gbm);
-	ret = drmModeAddFB(drmmode->fd, width, height, crtc->scrn->depth,
-			   crtc->scrn->bitsPerPixel, pitch,
-			   bo_handle.u32, &drmmode_crtc->rotate_fb_id);
-	if (ret) {
-		ErrorF("failed to add rotate fb\n");
-	}
-
-	drmmode_crtc->rotate_buffer = rotate_buffer;
-	return rotate_buffer;
+	return drmmode_crtc_scanout_allocate(crtc, &drmmode_crtc->rotate,
+					     width, height);
 }
 
 static PixmapPtr
 drmmode_crtc_shadow_create(xf86CrtcPtr crtc, void *data, int width, int height)
 {
-	ScrnInfoPtr pScrn = crtc->scrn;
 	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
-	unsigned long rotate_pitch;
-	PixmapPtr rotate_pixmap;
-
-	if (!data)
-		data = drmmode_crtc_shadow_allocate(crtc, width, height);
-
-	rotate_pitch = gbm_bo_get_stride(drmmode_crtc->rotate_buffer->bo.gbm);
-
-	rotate_pixmap = drmmode_create_bo_pixmap(pScrn,
-						 width, height,
-						 pScrn->depth,
-						 pScrn->bitsPerPixel,
-						 rotate_pitch,
-						 drmmode_crtc->rotate_buffer);
-	if (rotate_pixmap == NULL) {
-		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-			   "Couldn't allocate shadow pixmap for rotated CRTC\n");
-	}
-	return rotate_pixmap;
 
+	return drmmode_crtc_scanout_create(crtc, &drmmode_crtc->rotate, data,
+					   width, height);
 }
 
 static void
@@ -598,16 +636,7 @@ drmmode_crtc_shadow_destroy(xf86CrtcPtr crtc, PixmapPtr rotate_pixmap,
 	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
 	drmmode_ptr drmmode = drmmode_crtc->drmmode;
 
-	if (rotate_pixmap)
-		drmmode_destroy_bo_pixmap(rotate_pixmap);
-
-	if (data) {
-		drmModeRmFB(drmmode->fd, drmmode_crtc->rotate_fb_id);
-		drmmode_crtc->rotate_fb_id = 0;
-		amdgpu_bo_unref(&drmmode_crtc->rotate_buffer);
-		drmmode_crtc->rotate_buffer = NULL;
-	}
-
+	drmmode_crtc_scanout_destroy(drmmode, &drmmode_crtc->rotate);
 }
 
 static void
diff --git a/src/drmmode_display.h b/src/drmmode_display.h
index df46099..77d9c03 100644
--- a/src/drmmode_display.h
+++ b/src/drmmode_display.h
@@ -70,13 +70,18 @@ typedef struct {
 	amdgpu_drm_abort_proc abort;
 } drmmode_flipevtcarrier_rec, *drmmode_flipevtcarrier_ptr;
 
+struct drmmode_scanout {
+	struct amdgpu_buffer *bo;
+	PixmapPtr pixmap;
+	unsigned fb_id;
+};
+
 typedef struct {
 	drmmode_ptr drmmode;
 	drmModeCrtcPtr mode_crtc;
 	int hw_id;
 	struct amdgpu_buffer *cursor_buffer;
-	struct amdgpu_buffer *rotate_buffer;
-	unsigned rotate_fb_id;
+	struct drmmode_scanout rotate;
 	int dpms_mode;
 	CARD64 dpms_last_ust;
 	uint32_t dpms_last_seq;
-- 
2.1.4



More information about the xorg-driver-ati mailing list