[PATCH 10/12] Add glamor back into the driver

Keith Packard keithp at keithp.com
Thu Jul 24 16:18:26 PDT 2014


This adds glamor support back into the driver, but instad of going
through UXA, this uses it directly instead.

Signed-off-by: Keith Packard <keithp at keithp.com>
---
 src/uxa/intel.h         |  17 +++
 src/uxa/intel_display.c |  30 ++++-
 src/uxa/intel_dri.c     |  20 +++
 src/uxa/intel_driver.c  | 247 ++++++++++++++++++++++++++++---------
 src/uxa/intel_glamor.c  | 316 +++++++++++++++++++++++++-----------------------
 src/uxa/intel_glamor.h  |  18 ++-
 src/uxa/intel_present.c |   5 -
 src/uxa/intel_uxa.c     |   5 +
 src/uxa/intel_video.c   |  75 +++++++-----
 9 files changed, 480 insertions(+), 253 deletions(-)

diff --git a/src/uxa/intel.h b/src/uxa/intel.h
index 64f573b..5fbb2c7 100644
--- a/src/uxa/intel.h
+++ b/src/uxa/intel.h
@@ -111,10 +111,21 @@ enum dri_type {
 	DRI_ACTIVE
 };
 
+enum accel_type {
+#if USE_GLAMOR
+        ACCEL_GLAMOR,
+#endif
+#if USE_UXA
+        ACCEL_UXA,
+#endif
+};
+
 typedef struct intel_screen_private {
 	ScrnInfoPtr scrn;
 	int cpp;
 
+        enum accel_type accel;
+
 #define RENDER_BATCH			I915_EXEC_RENDER
 #define BLT_BATCH			I915_EXEC_BLT
 	unsigned int current_batch;
@@ -127,6 +138,7 @@ typedef struct intel_screen_private {
 
 	dri_bufmgr *bufmgr;
 
+#if USE_UXA
 	uint32_t batch_ptr[4096];
 	/** Byte offset in batch_ptr for the next dword to be emitted. */
 	unsigned int batch_used;
@@ -142,6 +154,7 @@ typedef struct intel_screen_private {
 	struct list batch_pixmaps;
 	drm_intel_bo *wa_scratch_bo;
 	OsTimerPtr cache_expire;
+#endif
 
 	/* For Xvideo */
 	Bool use_overlay;
@@ -178,8 +191,10 @@ typedef struct intel_screen_private {
 	void (*batch_flush) (struct intel_screen_private *intel);
 	void (*batch_commit_notify) (struct intel_screen_private *intel);
 
+#if USE_UXA
 	struct _UxaDriver *uxa_driver;
 	int uxa_flags;
+#endif
 	Bool need_sync;
 	int accel_pixmap_offset_alignment;
 	int accel_max_x;
@@ -212,6 +227,7 @@ typedef struct intel_screen_private {
 		drm_intel_bo *gen6_depth_stencil_bo;
 	} video;
 
+#if USE_UXA
 	/* Render accel state */
 	float scale_units[2][2];
 	/** Transform pointers for src/mask, or NULL if identity */
@@ -269,6 +285,7 @@ typedef struct intel_screen_private {
 
 	/* 965 render acceleration state */
 	struct gen4_render_state *gen4_render_state;
+#endif
 
 	/* DRI enabled this generation. */
 	enum dri_type dri2, dri3;
diff --git a/src/uxa/intel_display.c b/src/uxa/intel_display.c
index add09b0..a4c4b82 100644
--- a/src/uxa/intel_display.c
+++ b/src/uxa/intel_display.c
@@ -56,6 +56,9 @@
 #include "xf86DDC.h"
 #include "fb.h"
 #include "uxa.h"
+#if USE_GLAMOR
+#include "intel_glamor.h"
+#endif
 
 #define KNOWN_MODE_FLAGS ((1<<14)-1)
 
@@ -182,7 +185,7 @@ intel_output_backlight_init(xf86OutputPtr output)
 {
 	struct intel_output *intel_output = output->driver_private;
 	intel_screen_private *intel = intel_get_screen_private(output->scrn);
-	char *str;
+	const char *str;
 
 #if !USE_BACKLIGHT
 	return;
@@ -683,7 +686,10 @@ intel_set_scanout_pixmap(xf86CrtcPtr crtc, PixmapPtr ppix)
 		return TRUE;
 	}
 
-	bo = intel_get_pixmap_bo(ppix);
+        bo = intel_get_pixmap_bo(ppix);
+        if (!bo)
+                return FALSE;
+
 	if (intel->front_buffer) {
 		ErrorF("have front buffer\n");
 	}
@@ -1472,8 +1478,20 @@ intel_xf86crtc_resize(ScrnInfoPtr scrn, int width, int height)
 	scrn->virtualX = width;
 	scrn->virtualY = height;
 
-	if (!intel_uxa_create_screen_resources(scrn->pScreen))
-		goto fail;
+        switch (intel->accel) {
+#if USE_GLAMOR
+        case ACCEL_GLAMOR:
+                if (!intel_glamor_create_screen_resources(scrn->pScreen))
+                        goto fail;
+                break;
+#endif
+#if USE_UXA
+        case ACCEL_UXA:
+                if (!intel_uxa_create_screen_resources(scrn->pScreen))
+                        goto fail;
+                break;
+#endif
+        }
 
 	for (i = 0; i < xf86_config->num_crtc; i++) {
 		xf86CrtcPtr crtc = xf86_config->crtc[i];
@@ -1532,7 +1550,7 @@ intel_do_pageflip(intel_screen_private *intel,
 	xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn);
 	struct intel_crtc *crtc = config->crtc[0]->driver_private;
 	struct intel_mode *mode = crtc->mode;
-	unsigned int pitch = scrn->displayWidth * intel->cpp;
+        unsigned int pitch = scrn->displayWidth * intel->cpp;
 	struct intel_pageflip *flip;
 	uint32_t new_fb_id;
 	uint32_t flags;
@@ -2235,7 +2253,7 @@ intel_create_pixmap_for_bo(ScreenPtr pScreen, dri_bo *bo,
 		return NullPixmap;
 	}
 
-	intel_set_pixmap_bo(pixmap, bo);
+        intel_set_pixmap_bo(pixmap, bo);
 	return pixmap;
 }
 
diff --git a/src/uxa/intel_dri.c b/src/uxa/intel_dri.c
index 78734cb..2055346 100644
--- a/src/uxa/intel_dri.c
+++ b/src/uxa/intel_dri.c
@@ -883,6 +883,26 @@ I830DRI2ScheduleFlip(struct intel_screen_private *intel,
 
 		drm_intel_bo_disable_reuse(new_back);
 		dri_bo_flink(new_back, &intel->back_name);
+#if USE_GLAMOR
+		if (intel->accel == ACCEL_GLAMOR) {
+                        I830DRI2BufferPrivatePtr drvpriv;
+                        PixmapPtr front_pixmap, back_pixmap;
+                        ScreenPtr screen;
+
+			screen = draw->pScreen;
+			drvpriv = info->front->driverPrivate;
+			front_pixmap = drvpriv->pixmap;
+
+			back_pixmap = intel_glamor_create_back_pixmap(screen,
+								      front_pixmap,
+								      new_back);
+			if (back_pixmap == NULL) {
+				drm_intel_bo_unreference(new_back);
+				return FALSE;
+			}
+			intel->back_pixmap = back_pixmap;
+		}
+#endif
 	} else {
 		new_back = intel->back_buffer;
 		intel->back_buffer = NULL;
diff --git a/src/uxa/intel_driver.c b/src/uxa/intel_driver.c
index 6d38cfe..065c679 100644
--- a/src/uxa/intel_driver.c
+++ b/src/uxa/intel_driver.c
@@ -164,29 +164,83 @@ static Bool i830CreateScreenResources(ScreenPtr screen)
 	if (!(*screen->CreateScreenResources) (screen))
 		return FALSE;
 
-	if (!intel_uxa_create_screen_resources(screen))
-		return FALSE;
+        switch (intel->accel) {
+#if USE_GLAMOR
+        case ACCEL_GLAMOR:
+                if (!intel_glamor_create_screen_resources(screen))
+                        return FALSE;
+                break;
+#endif
+#if USE_UXA
+        case ACCEL_UXA:
+                if (!intel_uxa_create_screen_resources(screen))
+                        return FALSE;
+                intel_copy_fb(scrn);
+#endif
+        }
 
-	intel_copy_fb(scrn);
 	return TRUE;
 }
 
 void
 intel_set_pixmap_bo(PixmapPtr pixmap, dri_bo *bo)
 {
-        intel_uxa_set_pixmap_bo(pixmap, bo);
+	ScrnInfoPtr scrn = xf86ScreenToScrn(pixmap->drawable.pScreen);
+	intel_screen_private *intel = intel_get_screen_private(scrn);
+
+        switch (intel->accel) {
+#if USE_GLAMOR
+        case ACCEL_GLAMOR:
+                intel_glamor_set_pixmap_bo(pixmap, bo);
+                break;
+#endif
+#if USE_UXA
+        case ACCEL_UXA:
+                intel_uxa_set_pixmap_bo(pixmap, bo);
+                break;
+#endif
+        default:
+                ErrorF("No accel architecture, cannot set pixmap bo\n");
+                break;
+        }
 }
 
 dri_bo *
 intel_get_pixmap_bo(PixmapPtr pixmap)
 {
-        return intel_uxa_get_pixmap_bo(pixmap);
+	ScrnInfoPtr scrn = xf86ScreenToScrn(pixmap->drawable.pScreen);
+	intel_screen_private *intel = intel_get_screen_private(scrn);
+
+	switch (intel->accel) {
+#if USE_GLAMOR
+	case ACCEL_GLAMOR:
+		return intel_glamor_get_pixmap_bo(pixmap);
+#endif
+#if USE_UXA
+        case ACCEL_UXA:
+		return intel_uxa_get_pixmap_bo(pixmap);
+#endif
+        default:
+                ErrorF("No accel architecture, cannot set pixmap bo\n");
+	        return NULL;
+        }
 }
 
 void
 intel_flush(intel_screen_private *intel)
 {
-        intel_batch_submit(intel->scrn);
+	switch (intel->accel) {
+#if USE_GLAMOR
+	case ACCEL_GLAMOR:
+                intel_glamor_flush(intel);
+                break;
+#endif
+#if USE_UXA
+        case ACCEL_UXA:
+                intel_batch_submit(intel->scrn);
+                break;
+#endif
+        }
 }
 
 static void PreInitCleanup(ScrnInfoPtr scrn)
@@ -204,6 +258,41 @@ static void intel_check_chipset_option(ScrnInfoPtr scrn)
 	intel_detect_chipset(scrn, intel->pEnt);
 }
 
+static void intel_check_accel_option(ScrnInfoPtr scrn)
+{
+	intel_screen_private *intel = intel_get_screen_private(scrn);
+	enum { NONE, SNA, UXA, GLAMOR } accel_method = DEFAULT_ACCEL_METHOD;
+	const char *s;
+
+	s = xf86GetOptValString(intel->Options, OPTION_ACCEL_METHOD);
+	if (s != NULL) {
+#if USE_GLAMOR
+                if (strcasecmp(s, "glamor") == 0)
+                        accel_method = GLAMOR;
+                else
+#endif
+#if USE_UXA
+                if (strcasecmp(s, "uxa") == 0)
+                        accel_method = UXA;
+                else
+#endif
+                        accel_method = DEFAULT_ACCEL_METHOD;
+        }
+        switch (accel_method) {
+        default:
+#if USE_GLAMOR
+        case GLAMOR:
+                intel->accel = ACCEL_GLAMOR;
+                break;
+#endif
+#if USE_UXA
+        case UXA:
+                intel->accel = ACCEL_UXA;
+                break;
+#endif
+        }
+}
+
 static Bool I830GetEarlyOptions(ScrnInfoPtr scrn)
 {
 	intel_screen_private *intel = intel_get_screen_private(scrn);
@@ -213,6 +302,7 @@ static Bool I830GetEarlyOptions(ScrnInfoPtr scrn)
 	if (!intel->Options)
 		return FALSE;
 
+#if USE_UXA
 	intel->fallback_debug = xf86ReturnOptValBool(intel->Options,
 						     OPTION_FALLBACKDEBUG,
 						     FALSE);
@@ -234,6 +324,7 @@ static Bool I830GetEarlyOptions(ScrnInfoPtr scrn)
 				 FALSE))
 		intel->debug_flush |= DEBUG_FLUSH_WAIT;
 
+#endif
 	return TRUE;
 }
 
@@ -526,6 +617,7 @@ static Bool I830PreInit(ScrnInfoPtr scrn, int flags)
 	intel_setup_capabilities(scrn);
 	intel_check_chipset_option(scrn);
 	intel_check_dri_option(scrn);
+        intel_check_accel_option(scrn);
 
 	if (!intel_init_bufmgr(intel)) {
 		PreInitCleanup(scrn);
@@ -612,24 +704,33 @@ static Bool I830PreInit(ScrnInfoPtr scrn, int flags)
 		return FALSE;
 	}
 
+        switch (intel->accel) {
 #if USE_GLAMOR
-	if (!intel_glamor_pre_init(scrn)) {
-		PreInitCleanup(scrn);
-		xf86DrvMsg(scrn->scrnIndex, X_ERROR,
-			"Failed to pre init glamor display.\n");
-		return FALSE;
-	}
+        case ACCEL_GLAMOR:
+                if (!intel_glamor_pre_init(scrn)) {
+                        PreInitCleanup(scrn);
+                        xf86DrvMsg(scrn->scrnIndex, X_ERROR,
+                                   "Failed to pre init glamor display.\n");
+                        intel->accel = ACCEL_UXA;
+                }
+                break;
 #endif
-
-	/* Load the dri modules if requested. */
+#if USE_UXA
+        case ACCEL_UXA:
+                /* Load the dri modules if requested. */
 #if HAVE_DRI2
-	if (intel->dri2 != DRI_DISABLED && !xf86LoadSubModule(scrn, "dri2"))
-		intel->dri2 = DRI_DISABLED;
+                if (intel->dri2 != DRI_DISABLED && !xf86LoadSubModule(scrn, "dri2"))
+                        intel->dri2 = DRI_DISABLED;
 #endif
 #if HAVE_DRI3
-	if (intel->dri3 != DRI_DISABLED && !xf86LoadSubModule(scrn, "dri3"))
-		intel->dri3 = DRI_DISABLED;
+                if (intel->dri3 != DRI_DISABLED && !xf86LoadSubModule(scrn, "dri3"))
+                        intel->dri3 = DRI_DISABLED;
+#endif
+                break;
 #endif
+        default:
+                break;
+        }
 
 	return TRUE;
 }
@@ -876,11 +977,6 @@ I830ScreenInit(SCREEN_INIT_ARGS_DECL)
 	if (!intel_init_initial_framebuffer(scrn))
 		return FALSE;
 
-	intel_batch_init(scrn);
-
-	if (INTEL_INFO(intel)->gen >= 040 && INTEL_INFO(intel)->gen < 0100)
-		gen4_render_state_init(scrn);
-
 	miClearVisualTypes();
 	if (!miSetVisualTypes(scrn->depth,
 			      miGetDefaultVisualMask(scrn->depth),
@@ -915,23 +1011,37 @@ I830ScreenInit(SCREEN_INIT_ARGS_DECL)
 
 	xf86SetBlackWhitePixels(screen);
 
-	if (!intel_uxa_init(screen)) {
-		xf86DrvMsg(scrn->scrnIndex, X_ERROR,
-			   "Hardware acceleration initialization failed\n");
-		return FALSE;
-	}
-
+        switch (intel->accel) {
+#if USE_GLAMOR
+        case ACCEL_GLAMOR:
+                if (!intel_glamor_init(screen)) {
+                        xf86DrvMsg(scrn->scrnIndex, X_ERROR,
+                                   "Glamor acceleration initialization failed\n");
+                        return FALSE;
+                }
+                break;
+#endif
+#if USE_UXA
+        case ACCEL_UXA:
+                if (!intel_uxa_init(screen)) {
+                        xf86DrvMsg(scrn->scrnIndex, X_ERROR,
+                                   "Hardware acceleration initialization failed\n");
+                        return FALSE;
+                }
 #if HAVE_DRI2
-	if (intel->dri2 == DRI_NONE && I830DRI2ScreenInit(screen))
-		intel->dri2 = DRI_ACTIVE;
+                if (intel->dri2 == DRI_NONE && I830DRI2ScreenInit(screen))
+                        intel->dri2 = DRI_ACTIVE;
 #endif
 
 #if HAVE_DRI3
-	if (!intel_sync_init(screen))
-		intel->dri3 = DRI_DISABLED;
-	if (intel->dri3 == DRI_NONE && intel_dri3_screen_init(screen))
-		intel->dri3 = DRI_ACTIVE;
+                if (!intel_sync_init(screen))
+                        intel->dri3 = DRI_DISABLED;
+                if (intel->dri3 == DRI_NONE && intel_dri3_screen_init(screen))
+                        intel->dri3 = DRI_ACTIVE;
+#endif
+                break;
 #endif
+        }
 
 	if (xf86ReturnOptValBool(intel->Options, OPTION_PRESENT, TRUE))
 		intel_present_screen_init(screen);
@@ -1129,18 +1239,33 @@ static Bool I830CloseScreen(CLOSE_SCREEN_ARGS_DECL)
 
 	DeleteCallback(&FlushCallback, intel_flush_callback, scrn);
 
+        switch (intel->accel) {
 #if USE_GLAMOR
-	intel_glamor_close_screen(screen);
+        case ACCEL_GLAMOR:
+                intel_glamor_close_screen(screen);
+                break;
 #endif
+#if USE_UXA
+        case ACCEL_UXA:
 
-	TimerFree(intel->cache_expire);
-	intel->cache_expire = NULL;
+                TimerFree(intel->cache_expire);
+                intel->cache_expire = NULL;
 
-	if (intel->uxa_driver) {
-		uxa_driver_fini(screen);
-		free(intel->uxa_driver);
-		intel->uxa_driver = NULL;
-	}
+                intel_batch_teardown(scrn);
+
+                if (INTEL_INFO(intel)->gen >= 040 && INTEL_INFO(intel)->gen < 0100)
+                        gen4_render_state_cleanup(scrn);
+
+                if (intel->uxa_driver) {
+                        uxa_driver_fini(screen);
+                        free(intel->uxa_driver);
+                        intel->uxa_driver = NULL;
+                }
+                break;
+#endif
+        default:
+                break;
+        }
 
 	if (intel->back_pixmap) {
 		screen->DestroyPixmap(intel->back_pixmap);
@@ -1162,11 +1287,6 @@ static Bool I830CloseScreen(CLOSE_SCREEN_ARGS_DECL)
 		I830LeaveVT(VT_FUNC_ARGS(0));
 	}
 
-	intel_batch_teardown(scrn);
-
-	if (INTEL_INFO(intel)->gen >= 040 && INTEL_INFO(intel)->gen < 0100)
-		gen4_render_state_cleanup(scrn);
-
 	xf86_cursors_fini(screen);
 
 	i965_free_video(scrn);
@@ -1174,17 +1294,28 @@ static Bool I830CloseScreen(CLOSE_SCREEN_ARGS_DECL)
 	screen->CloseScreen = intel->CloseScreen;
 	(*screen->CloseScreen) (CLOSE_SCREEN_ARGS);
 
-	if (intel->dri2 == DRI_ACTIVE) {
-		I830DRI2CloseScreen(screen);
-		intel->dri2 = DRI_NONE;
-	}
-
-	if (intel->dri3 == DRI_ACTIVE) {
-		/* nothing to do here? */
-		intel->dri3 = DRI_NONE;
-	}
+        switch (intel->accel) {
+#if USE_UXA
+        case ACCEL_UXA:
+#if HAVE_DRI2
+                if (intel->dri2 == DRI_ACTIVE) {
+                        I830DRI2CloseScreen(screen);
+                        intel->dri2 = DRI_NONE;
+                }
+#endif
+#if HAVE_DRI3
+                if (intel->dri3 == DRI_ACTIVE) {
+                        /* nothing to do here? */
+                        intel->dri3 = DRI_NONE;
+                }
+                intel_sync_close(screen);
+#endif
 
-	intel_sync_close(screen);
+                break;
+#endif
+        default:
+                break;
+        }
 
 	xf86GARTCloseScreen(scrn->scrnIndex);
 
diff --git a/src/uxa/intel_glamor.c b/src/uxa/intel_glamor.c
index 21636d1..e2bc24c 100644
--- a/src/uxa/intel_glamor.c
+++ b/src/uxa/intel_glamor.c
@@ -35,31 +35,89 @@
 #include <xf86.h>
 #define GLAMOR_FOR_XORG  1
 #include <glamor.h>
+#include <unistd.h>
 
 #include "intel.h"
 #include "i915_drm.h"
 #include "intel_glamor.h"
-#include "uxa.h"
 #include "intel_options.h"
 
-void
-intel_glamor_exchange_buffers(struct intel_screen_private *intel,
-			      PixmapPtr src,
-			      PixmapPtr dst)
+struct intel_glamor_pixmap {
+        dri_bo  *bo;
+};
+
+static DevPrivateKeyRec intel_glamor_pixmap_key;
+
+static inline struct intel_glamor_pixmap *intel_glamor_get_pixmap(PixmapPtr pixmap)
 {
-	if (!(intel->uxa_flags & UXA_USE_GLAMOR))
-		return;
-	glamor_egl_exchange_buffers(src, dst);
+        return dixGetPrivateAddr(&pixmap->devPrivates, &intel_glamor_pixmap_key);
 }
 
-XF86VideoAdaptorPtr intel_glamor_xv_init(ScreenPtr screen, int num_ports)
+dri_bo *
+intel_glamor_get_pixmap_bo(PixmapPtr pixmap)
 {
-	ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
-	intel_screen_private *intel = intel_get_screen_private(scrn);
+        dri_bo  *bo = intel_glamor_get_pixmap(pixmap)->bo;
+
+        if (!bo) {
+                ScreenPtr       screen = pixmap->drawable.pScreen;
+                CARD16          stride;
+                CARD32          size;
+                int             fd;
+
+                fd = glamor_fd_from_pixmap(screen,
+                                           pixmap,
+                                           &stride,
+                                           &size);
+
+                if (fd >= 0) {
+                        ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+                        intel_screen_private *intel = intel_get_screen_private(scrn);
+
+                        bo = drm_intel_bo_gem_create_from_prime(intel->bufmgr,
+                                                                fd,
+                                                                size);
+                        close(fd);
+                        intel_glamor_get_pixmap(pixmap)->bo = bo;
+                }
+        }
+        return bo;
+}
 
-	if ((intel->uxa_flags & UXA_USE_GLAMOR) == 0)
-		return NULL;
+static void
+intel_glamor_reference_pixmap_bo(PixmapPtr pixmap, drm_intel_bo *bo)
+{
+        struct intel_glamor_pixmap      *glamor_pixmap = intel_glamor_get_pixmap(pixmap);
+
+        if (glamor_pixmap->bo) {
+                ErrorF("Unreference bo %d size %lu from pixmap %d x %d\n",
+                       glamor_pixmap->bo->handle, glamor_pixmap->bo->size, pixmap->drawable.width, pixmap->drawable.height);
+                drm_intel_bo_unreference(glamor_pixmap->bo);
+                glamor_pixmap->bo = NULL;
+        }
+
+        if (bo) {
+                ErrorF("Reference bo %d size %lu from pixmap %d x %d\n",
+                       bo->handle, bo->size, pixmap->drawable.width, pixmap->drawable.height);
+                drm_intel_bo_reference(bo);
+                glamor_pixmap->bo = bo;
+        }
+}
 
+Bool
+intel_glamor_set_pixmap_bo(PixmapPtr pixmap, drm_intel_bo *bo)
+{
+        if (bo == NULL || glamor_egl_create_textured_pixmap(pixmap,
+                                                            bo->handle,
+                                                            intel_pixmap_pitch(pixmap)))
+        {
+                intel_glamor_reference_pixmap_bo(pixmap, bo);
+                return TRUE;
+        }
+        return FALSE;
+}
+
+XF86VideoAdaptorPtr intel_glamor_xv_init(ScreenPtr screen, int num_ports)
+{
 	return glamor_xv_init(screen, num_ports);
 }
 
@@ -68,33 +126,42 @@ intel_glamor_create_screen_resources(ScreenPtr screen)
 {
 	ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
 	intel_screen_private *intel = intel_get_screen_private(scrn);
-
-	if (!(intel->uxa_flags & UXA_USE_GLAMOR))
-		return TRUE;
+        PixmapPtr pixmap = screen->GetScreenPixmap(screen);
+        int     old_width, old_height, old_pitch;
+        Bool    ret;
 
 	if (!glamor_glyphs_init(screen))
 		return FALSE;
 
-	if (!glamor_egl_create_textured_screen_ext(screen,
-						   intel->front_buffer->handle,
-						   intel->front_pitch,
-						   &intel->back_pixmap))
+        old_width = pixmap->drawable.width;
+        old_height = pixmap->drawable.height;
+        old_pitch = pixmap->devKind;
+
+	if (!screen->ModifyPixmapHeader(pixmap,
+					scrn->virtualX,
+					scrn->virtualY,
+					-1, -1,
+					intel->front_pitch,
+					NULL))
 		return FALSE;
 
-	return TRUE;
-}
+        ret = glamor_egl_create_textured_screen_ext(screen,
+                                                    intel->front_buffer->handle,
+                                                    intel->front_pitch,
+                                                    &intel->back_pixmap);
 
-static Bool
-intel_glamor_enabled(intel_screen_private *intel)
-{
-	enum { SNA, UXA, GLAMOR } default_accel_method = DEFAULT_ACCEL_METHOD;
-	const char *s;
+        if (!ret)
+                goto fail;
+
+        intel_glamor_reference_pixmap_bo(pixmap, intel->front_buffer);
+
+        return TRUE;
 
-	s = xf86GetOptValString(intel->Options, OPTION_ACCEL_METHOD);
-	if (s == NULL)
-		return default_accel_method == GLAMOR;
+fail:
+        screen->ModifyPixmapHeader(pixmap,
+                                   old_width, old_height, -1, -1, old_pitch, NULL);
 
-	return strcasecmp(s, "glamor") == 0;
+        return FALSE;
 }
 
 Bool
@@ -104,9 +171,6 @@ intel_glamor_pre_init(ScrnInfoPtr scrn)
 	pointer glamor_module;
 	CARD32 version;
 
-	if (!intel_glamor_enabled(intel))
-		return TRUE;
-
 #if XORG_VERSION_CURRENT < XORG_VERSION_NUMERIC(1,15,0,0,0)
 	if (!xf86LoaderCheckSymbol("glamor_egl_init")) {
 		xf86DrvMsg(scrn->scrnIndex,  X_ERROR,
@@ -117,139 +181,57 @@ intel_glamor_pre_init(ScrnInfoPtr scrn)
 #endif
 
 	/* Load glamor module */
-	if ((glamor_module = xf86LoadSubModule(scrn, GLAMOR_EGL_MODULE_NAME))) {
-		version = xf86GetModuleVersion(glamor_module);
-		if (version < MODULE_VERSION_NUMERIC(0,3,1)) {
-			xf86DrvMsg(scrn->scrnIndex, X_ERROR,
-			"Incompatible glamor version, required >= 0.3.0.\n");
-		} else {
-			if (glamor_egl_init(scrn, intel->drmSubFD)) {
-				xf86DrvMsg(scrn->scrnIndex, X_INFO,
-					   "glamor detected, initialising egl layer.\n");
-				intel->uxa_flags = UXA_GLAMOR_EGL_INITIALIZED;
-			} else
-				xf86DrvMsg(scrn->scrnIndex, X_WARNING,
-					   "glamor detected, failed to initialize egl.\n");
-		}
-	} else
+        glamor_module = xf86LoadSubModule(scrn, GLAMOR_EGL_MODULE_NAME);
+	if (!glamor_module) {
 		xf86DrvMsg(scrn->scrnIndex, X_WARNING,
 			   "glamor not available\n");
+                return TRUE;
+        }
+
+        version = xf86GetModuleVersion(glamor_module);
+        if (version < MODULE_VERSION_NUMERIC(0,3,1)) {
+                xf86DrvMsg(scrn->scrnIndex, X_ERROR,
+                           "Incompatible glamor version, required >= 0.3.0.\n");
+                return TRUE;
+        }
+        if (!glamor_egl_init(scrn, intel->drmSubFD)) {
+                xf86DrvMsg(scrn->scrnIndex, X_WARNING,
+                           "glamor detected, failed to initialize egl.\n");
+                return TRUE;
+        }
+        xf86DrvMsg(scrn->scrnIndex, X_INFO,
+                   "glamor detected, initialising egl layer.\n");
 
 	return TRUE;
 }
 
-PixmapPtr
-intel_glamor_create_pixmap(ScreenPtr screen, int w, int h,
-			   int depth, unsigned int usage)
-{
-	ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
-	intel_screen_private *intel = intel_get_screen_private(scrn);
-
-	if (intel->uxa_flags & UXA_USE_GLAMOR)
-		return glamor_create_pixmap(screen, w, h, depth, usage);
-	else
-		return NULL;
-}
-
-Bool
-intel_glamor_create_textured_pixmap(PixmapPtr pixmap)
-{
-	ScrnInfoPtr scrn = xf86ScreenToScrn(pixmap->drawable.pScreen);
-	intel_screen_private *intel = intel_get_screen_private(scrn);
-	struct intel_uxa_pixmap *priv;
-
-	if ((intel->uxa_flags & UXA_USE_GLAMOR) == 0)
-		return TRUE;
-
-	priv = intel_uxa_get_pixmap_private(pixmap);
-	if (glamor_egl_create_textured_pixmap(pixmap, priv->bo->handle,
-					      priv->stride)) {
-		drm_intel_bo_disable_reuse(priv->bo);
-		priv->pinned |= PIN_GLAMOR;
-		return TRUE;
-	} else
-		return FALSE;
-}
-
-void
-intel_glamor_destroy_pixmap(PixmapPtr pixmap)
-{
-	ScrnInfoPtr scrn = xf86ScreenToScrn(pixmap->drawable.pScreen);
-	intel_screen_private * intel;
-
-	intel = intel_get_screen_private(scrn);
-	if (intel->uxa_flags & UXA_USE_GLAMOR)
-		glamor_egl_destroy_textured_pixmap(pixmap);
-}
-
-static void
-intel_glamor_need_flush(DrawablePtr pDrawable)
-{
-	ScrnInfoPtr scrn = xf86ScreenToScrn(pDrawable->pScreen);
-	intel_screen_private * intel;
-
-	intel = intel_get_screen_private(scrn);
-	intel->needs_flush = TRUE;
-}
-
-static void
-intel_glamor_finish_access(PixmapPtr pixmap, uxa_access_t access)
-{
-	switch(access) {
-	case UXA_ACCESS_RO:
-	case UXA_ACCESS_RW:
-	case UXA_GLAMOR_ACCESS_RO:
-		break;
-	case UXA_GLAMOR_ACCESS_RW:
-		intel_glamor_need_flush(&pixmap->drawable);
-		break;
-	default:
-		ErrorF("Invalid access mode %d\n", access);
-	}
-
-	return;
-}
-
 Bool
 intel_glamor_init(ScreenPtr screen)
 {
 	ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
-	intel_screen_private *intel = intel_get_screen_private(scrn);
 
-	if ((intel->uxa_flags & UXA_GLAMOR_EGL_INITIALIZED) == 0)
-		goto fail;
+	if (!dixPrivateKeyRegistered(&intel_glamor_pixmap_key))
+                if (!dixRegisterPrivateKey(&intel_glamor_pixmap_key, PRIVATE_PIXMAP, sizeof (struct intel_glamor_pixmap)))
+                        return FALSE;
 
 	if (!glamor_init(screen,
-#if defined(GLAMOR_NO_DRI3)
-			 /* Not doing DRI3 yet, since Present support hasn't landed. */
-			 GLAMOR_NO_DRI3 |
-#endif
 			 GLAMOR_INVERTED_Y_AXIS |
-			 GLAMOR_USE_EGL_SCREEN)) {
+			 GLAMOR_USE_EGL_SCREEN |
+                         GLAMOR_USE_SCREEN |
+                         GLAMOR_USE_PICTURE_SCREEN))
+        {
 		xf86DrvMsg(scrn->scrnIndex, X_ERROR,
 			   "Failed to initialize glamor.\n");
-		goto fail;
+		return FALSE;
 	}
 
 	if (!glamor_egl_init_textured_pixmap(screen)) {
 		xf86DrvMsg(scrn->scrnIndex, X_ERROR,
 			   "Failed to initialize textured pixmap of screen for glamor.\n");
-		goto fail;
+		return FALSE;
 	}
 
-	intel->uxa_driver->flags |= UXA_USE_GLAMOR;
-	intel->uxa_flags |= intel->uxa_driver->flags;
-
-	intel->uxa_driver->finish_access = intel_glamor_finish_access;
-
-	xf86DrvMsg(scrn->scrnIndex, X_INFO,
-		   "Use GLAMOR acceleration.\n");
 	return TRUE;
-
-  fail:
-	xf86DrvMsg(scrn->scrnIndex, X_INFO,
-		   "Use legacy UXA acceleration.\n");
-	return FALSE;
 }
 
 void
@@ -258,18 +240,52 @@ intel_glamor_flush(intel_screen_private * intel)
 	ScreenPtr screen;
 
 	screen = xf86ScrnToScreen(intel->scrn);
-	if (intel->uxa_flags & UXA_USE_GLAMOR)
-		glamor_block_handler(screen);
+        glamor_block_handler(screen);
 }
 
 Bool
 intel_glamor_close_screen(ScreenPtr screen)
 {
-	ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
-	intel_screen_private *intel = intel_get_screen_private(scrn);
+	return TRUE;
+}
 
-	if (intel->uxa_flags & UXA_USE_GLAMOR)
-		intel->uxa_flags &= ~UXA_USE_GLAMOR;
+#if HAVE_DRI2
+void
+intel_glamor_exchange_buffers(struct intel_screen_private *intel,
+			      PixmapPtr src,
+			      PixmapPtr dst)
+{
+	glamor_egl_exchange_buffers(src, dst);
+}
 
-	return TRUE;
+PixmapPtr
+intel_glamor_create_back_pixmap(ScreenPtr screen,
+				PixmapPtr front_pixmap,
+				drm_intel_bo *back_bo)
+{
+	PixmapPtr back_pixmap;
+
+	back_pixmap = screen->CreatePixmap(screen,
+					   0,
+					   0,
+				           front_pixmap->drawable.depth,
+				           0);
+	if (back_pixmap == NULL)
+		return NULL;
+
+	screen->ModifyPixmapHeader(back_pixmap,
+				   front_pixmap->drawable.width,
+				   front_pixmap->drawable.height,
+				   0, 0,
+				   front_pixmap->devKind,
+				   0);
+	if (!intel_glamor_set_pixmap_bo(back_pixmap, back_bo)) {
+		ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+		xf86DrvMsg(scrn->scrnIndex, X_WARNING,
+			   "Failed to create textured back pixmap.\n");
+		screen->DestroyPixmap(back_pixmap);
+		return NULL;
+	}
+	return back_pixmap;
 }
+#endif
diff --git a/src/uxa/intel_glamor.h b/src/uxa/intel_glamor.h
index 97c2257..2fcabdf 100644
--- a/src/uxa/intel_glamor.h
+++ b/src/uxa/intel_glamor.h
@@ -40,11 +40,21 @@ void intel_glamor_free_screen(int scrnIndex, int flags);
 
 void intel_glamor_flush(intel_screen_private * intel);
 
-Bool intel_glamor_create_textured_pixmap(PixmapPtr pixmap);
-void intel_glamor_destroy_pixmap(PixmapPtr pixmap);
-PixmapPtr intel_glamor_create_pixmap(ScreenPtr screen, int w, int h,
-				     int depth, unsigned int usage);
+#if HAVE_DRI2
+PixmapPtr
+intel_glamor_create_back_pixmap(ScreenPtr screen,
+				PixmapPtr front_pixmap,
+				drm_intel_bo *back_bo);
+
 void intel_glamor_exchange_buffers(struct intel_screen_private *intel, PixmapPtr src, PixmapPtr dst);
+#endif
+
 XF86VideoAdaptorPtr intel_glamor_xv_init(ScreenPtr screen, int num_ports);
 
+dri_bo *
+intel_glamor_get_pixmap_bo(PixmapPtr pixmap);
+
+Bool
+intel_glamor_set_pixmap_bo(PixmapPtr pixmap, dri_bo *bo);
+
 #endif /* INTEL_GLAMOR_H */
diff --git a/src/uxa/intel_present.c b/src/uxa/intel_present.c
index b901fb1..04aeb78 100644
--- a/src/uxa/intel_present.c
+++ b/src/uxa/intel_present.c
@@ -54,11 +54,6 @@
 
 #include "present.h"
 
-#if USE_GLAMOR
-#include "intel_glamor.h"
-#endif
-#include "uxa.h"
-
 struct intel_present_vblank_event {
 	uint64_t        event_id;
 };
diff --git a/src/uxa/intel_uxa.c b/src/uxa/intel_uxa.c
index da4eb97..e9d905b 100644
--- a/src/uxa/intel_uxa.c
+++ b/src/uxa/intel_uxa.c
@@ -1272,6 +1272,11 @@ Bool intel_uxa_init(ScreenPtr screen)
 	ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
 	intel_screen_private *intel = intel_get_screen_private(scrn);
 
+	intel_batch_init(scrn);
+
+	if (INTEL_INFO(intel)->gen >= 040 && INTEL_INFO(intel)->gen < 0100)
+		gen4_render_state_init(scrn);
+
 #if HAS_DIXREGISTERPRIVATEKEY
 	if (!dixRegisterPrivateKey(&uxa_pixmap_index, PRIVATE_PIXMAP, 0))
 #else
diff --git a/src/uxa/intel_video.c b/src/uxa/intel_video.c
index ae3d351..73920e6 100644
--- a/src/uxa/intel_video.c
+++ b/src/uxa/intel_video.c
@@ -81,7 +81,10 @@
 #if USE_GLAMOR
 #include "intel_glamor.h"
 #endif
+#if USE_UXA
 #include "intel_uxa.h"
+#endif
+
 #include "intel_video_overlay.h"
 
 Atom intel_xv_Brightness, intel_xv_Contrast, intel_xv_Saturation, intel_xv_ColorKey, intel_xv_Pipe;
@@ -165,14 +168,14 @@ void intel_video_init(ScreenPtr screen)
 	ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
 	intel_screen_private *intel = intel_get_screen_private(scrn);
 	XF86VideoAdaptorPtr *adaptors = NULL, *newAdaptors = NULL;
-	XF86VideoAdaptorPtr overlayAdaptor = NULL, texturedAdaptor = NULL, glamorAdaptor = NULL;
+	XF86VideoAdaptorPtr overlayAdaptor = NULL, texturedAdaptor = NULL;
 	int num_adaptors = xf86XVListGenericAdaptors(scrn, &adaptors);
 
 	/* Give our adaptor list enough space for the overlay and/or texture video
 	 * adaptors.
 	 */
 	newAdaptors = realloc(adaptors,
-			      (num_adaptors + 3) * sizeof(XF86VideoAdaptorPtr));
+			      (num_adaptors + 2) * sizeof(XF86VideoAdaptorPtr));
 
 	if (newAdaptors == NULL) {
 		free(adaptors);
@@ -186,21 +189,37 @@ void intel_video_init(ScreenPtr screen)
 	intel_xv_Brightness = MAKE_ATOM("XV_BRIGHTNESS");
 	intel_xv_Contrast = MAKE_ATOM("XV_CONTRAST");
 
-        /* Set up textured video if we can do it at this depth and we are on
-         * supported hardware.
-         */
-        if (!intel->force_fallback &&
-            scrn->bitsPerPixel >= 16 &&
-            INTEL_INFO(intel)->gen >= 030 &&
-            INTEL_INFO(intel)->gen < 0100) {
-                texturedAdaptor = intel_uxa_video_setup_image_textured(screen);
-                if (texturedAdaptor != NULL) {
-                        xf86DrvMsg(scrn->scrnIndex, X_INFO,
-                                   "Set up textured video\n");
-                } else {
-                        xf86DrvMsg(scrn->scrnIndex, X_ERROR,
-                                   "Failed to set up textured video\n");
+        switch (intel->accel) {
+#if USE_UXA
+        case ACCEL_UXA:
+                /* Set up textured video if we can do it at this depth and we are on
+                 * supported hardware.
+                 */
+                if (!intel->force_fallback &&
+                    scrn->bitsPerPixel >= 16 &&
+                    INTEL_INFO(intel)->gen >= 030 &&
+                    INTEL_INFO(intel)->gen < 0100) {
+                        texturedAdaptor = intel_uxa_video_setup_image_textured(screen);
+                        if (texturedAdaptor != NULL) {
+                                xf86DrvMsg(scrn->scrnIndex, X_INFO,
+                                           "Set up textured video\n");
+                        } else {
+                                xf86DrvMsg(scrn->scrnIndex, X_ERROR,
+                                           "Failed to set up textured video\n");
+                        }
                 }
+                break;
+#endif
+#if USE_GLAMOR
+        case ACCEL_GLAMOR:
+                texturedAdaptor = intel_glamor_xv_init(screen, 16);
+                if (texturedAdaptor != NULL)
+                        xf86DrvMsg(scrn->scrnIndex, X_INFO,
+                                   "Set up textured video using glamor\n");
+                break;
+#endif
+        default:
+                break;
         }
 
         overlayAdaptor = intel_video_overlay_setup_image(screen);
@@ -215,23 +234,12 @@ void intel_video_init(ScreenPtr screen)
 		}
 	}
 
-#if USE_GLAMOR
-	glamorAdaptor = intel_glamor_xv_init(screen, 16);
-	if (glamorAdaptor != NULL)
-		xf86DrvMsg(scrn->scrnIndex, X_INFO,
-			   "Set up textured video using glamor\n");
-#endif
-
-
 	if (overlayAdaptor && intel->XvPreferOverlay)
 		adaptors[num_adaptors++] = overlayAdaptor;
 
 	if (texturedAdaptor)
 		adaptors[num_adaptors++] = texturedAdaptor;
 
-	if (glamorAdaptor)
-		adaptors[num_adaptors++] = glamorAdaptor;
-
 	if (overlayAdaptor && !intel->XvPreferOverlay)
 		adaptors[num_adaptors++] = overlayAdaptor;
 
@@ -243,9 +251,16 @@ void intel_video_init(ScreenPtr screen)
 		intel->XvEnabled = FALSE;
 	}
 
-        if (texturedAdaptor)
-                intel_xvmc_adaptor_init(screen);
-
+#if defined(INTEL_XVMC) && defined(USE_UXA)
+        switch (intel->accel) {
+        case ACCEL_UXA:
+                if (texturedAdaptor)
+                        intel_xvmc_adaptor_init(screen);
+                break;
+        default:
+                break;
+        }
+#endif
 	free(adaptors);
 }
 
-- 
2.0.1



More information about the xorg-devel mailing list