[PATCH xf86-video-amdgpu 3/6] Create amdgpu_pixmap_get_fb_ptr helper

Michel Dänzer michel at daenzer.net
Tue Aug 29 08:30:46 UTC 2017


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

Preparatory, no functional change intended yet.

Also inline amdgpu_pixmap_create_fb into amdgpu_pixmap_get_fb, since
there's only one call-site.

(Ported from radeon commit 20f6b56fdb74d88086e8e094013fedbb14e50a24)

Signed-off-by: Michel Dänzer <michel.daenzer at amd.com>
---
 src/amdgpu_pixmap.h | 46 +++++++++++++++++++++++++++-------------------
 1 file changed, 27 insertions(+), 19 deletions(-)

diff --git a/src/amdgpu_pixmap.h b/src/amdgpu_pixmap.h
index 00fb5bf05..eded17037 100644
--- a/src/amdgpu_pixmap.h
+++ b/src/amdgpu_pixmap.h
@@ -121,39 +121,47 @@ amdgpu_fb_create(int drm_fd, uint32_t width, uint32_t height, uint8_t depth,
 	return NULL;
 }
 
-static inline struct drmmode_fb*
-amdgpu_pixmap_create_fb(int drm_fd, PixmapPtr pix)
+static inline struct drmmode_fb**
+amdgpu_pixmap_get_fb_ptr(PixmapPtr pix)
 {
-	uint32_t handle;
+	ScrnInfoPtr scrn = xf86ScreenToScrn(pix->drawable.pScreen);
+	AMDGPUInfoPtr info = AMDGPUPTR(scrn);
 
-	if (!amdgpu_pixmap_get_handle(pix, &handle))
-		return NULL;
+	if (info->use_glamor) {
+		struct amdgpu_pixmap *priv = amdgpu_get_pixmap_private(pix);
+
+		if (!priv)
+			return NULL;
+
+		return &priv->fb;
+	}
 
-	return amdgpu_fb_create(drm_fd, pix->drawable.width, pix->drawable.height,
-				pix->drawable.depth, pix->drawable.bitsPerPixel,
-				pix->devKind, handle);
+	return NULL;
 }
 
 static inline struct drmmode_fb*
 amdgpu_pixmap_get_fb(PixmapPtr pix)
 {
-	ScrnInfoPtr scrn = xf86ScreenToScrn(pix->drawable.pScreen);
-	AMDGPUEntPtr pAMDGPUEnt = AMDGPUEntPriv(scrn);
-	AMDGPUInfoPtr info = AMDGPUPTR(scrn);
+	struct drmmode_fb **fb_ptr = amdgpu_pixmap_get_fb_ptr(pix);
 
-	if (info->use_glamor) {
-		struct amdgpu_pixmap *priv = amdgpu_get_pixmap_private(pix);
+	if (!fb_ptr)
+		return NULL;
 
-		if (!priv)
-			return NULL;
+	if (!*fb_ptr) {
+		uint32_t handle;
 
-		if (!priv->fb)
-			priv->fb = amdgpu_pixmap_create_fb(pAMDGPUEnt->fd, pix);
+		if (amdgpu_pixmap_get_handle(pix, &handle)) {
+			ScrnInfoPtr scrn = xf86ScreenToScrn(pix->drawable.pScreen);
+			AMDGPUEntPtr pAMDGPUEnt = AMDGPUEntPriv(scrn);
 
-		return priv->fb;
+			*fb_ptr = amdgpu_fb_create(pAMDGPUEnt->fd, pix->drawable.width,
+						   pix->drawable.height, pix->drawable.depth,
+						   pix->drawable.bitsPerPixel, pix->devKind,
+						   handle);
+		}
 	}
 
-	return NULL;
+	return *fb_ptr;
 }
 
 enum {
-- 
2.14.1



More information about the amd-gfx mailing list