diff mbox

[12/13] i830_memory: switch frontbuffer to drm_intel_bo

Message ID e15d40ae9edc70c46ed43f07daff060e130f0ffd.1267517278.git.daniel.vetter@ffwll.ch (mailing list archive)
State Deferred, archived
Headers show

Commit Message

Daniel Vetter March 2, 2010, 8:22 a.m. UTC
None
diff mbox

Patch

diff --git a/src/drmmode_display.c b/src/drmmode_display.c
index 5e2349e..fd31b1d 100644
--- a/src/drmmode_display.c
+++ b/src/drmmode_display.c
@@ -324,7 +324,7 @@  drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
 		ret = drmModeAddFB(drmmode->fd,
 				   scrn->virtualX, scrn->virtualY,
 				   scrn->depth, scrn->bitsPerPixel,
-				   pitch, intel->front_buffer->bo->handle,
+				   pitch, intel->front_buffer->handle,
 				   &drmmode->fb_id);
 		if (ret < 0) {
 			ErrorF("failed to add fb\n");
@@ -1240,7 +1240,7 @@  drmmode_xf86crtc_resize (ScrnInfoPtr scrn, int width, int height)
 		    drmmode_crtc = xf86_config->crtc[0]->driver_private;
 	drmmode_ptr drmmode = drmmode_crtc->drmmode;
 	intel_screen_private *intel = intel_get_screen_private(scrn);
-	i830_memory *old_front = NULL;
+	drm_intel_bo *old_front = NULL;
 	Bool	    ret;
 	ScreenPtr   screen = screenInfo.screens[scrn->scrnIndex];
 	uint32_t    old_fb_id;
@@ -1269,12 +1269,12 @@  drmmode_xf86crtc_resize (ScrnInfoPtr scrn, int width, int height)
 
 	ret = drmModeAddFB(drmmode->fd, width, height, scrn->depth,
 			   scrn->bitsPerPixel, pitch * intel->cpp,
-			   intel->front_buffer->bo->handle,
+			   intel->front_buffer->handle,
 			   &drmmode->fb_id);
 	if (ret)
 		goto fail;
 
-	i830_set_pixmap_bo(screen->GetScreenPixmap(screen), intel->front_buffer->bo);
+	i830_set_pixmap_bo(screen->GetScreenPixmap(screen), intel->front_buffer);
 
 	screen->ModifyPixmapHeader(screen->GetScreenPixmap(screen),
 				   width, height, -1, -1, pitch * intel->cpp, NULL);
@@ -1292,13 +1292,13 @@  drmmode_xf86crtc_resize (ScrnInfoPtr scrn, int width, int height)
 	if (old_fb_id)
 		drmModeRmFB(drmmode->fd, old_fb_id);
 	if (old_front)
-		i830_free_memory(scrn, old_front);
+		drm_intel_bo_unreference(old_front);
 
 	return TRUE;
 
  fail:
 	if (intel->front_buffer)
-		i830_free_memory(scrn, intel->front_buffer);
+		drm_intel_bo_unreference(intel->front_buffer);
 	intel->front_buffer = old_front;
 	scrn->virtualX = old_width;
 	scrn->virtualY = old_height;
@@ -1361,7 +1361,7 @@  drmmode_do_pageflip(ScreenPtr screen, dri_bo *new_front, dri_bo *old_front,
 	dri_bo_unpin(new_front);
 
 	scrn->fbOffset = new_front->offset;
-	intel->front_buffer->bo = new_front;
+	intel->front_buffer = new_front;
 	drmmode->old_fb_id = old_fb_id;
 
 	return TRUE;
diff --git a/src/i830.h b/src/i830.h
index 6030dfc..8482ca9 100644
--- a/src/i830.h
+++ b/src/i830.h
@@ -236,7 +236,7 @@  typedef struct intel_screen_private {
 	/** Linked list of buffer object memory allocations */
 	i830_memory *bo_list;
 
-	i830_memory *front_buffer;
+	drm_intel_bo *front_buffer;
 	/* One big buffer for all cursors for kernels that support this */
 	drm_intel_bo *cursor_mem_argb[2];
 
@@ -457,7 +457,7 @@  unsigned long i830_get_fence_pitch(intel_screen_private *intel, unsigned long pi
 				   uint32_t tiling_mode);
 void i830_set_gem_max_sizes(ScrnInfoPtr scrn);
 
-i830_memory *i830_allocate_framebuffer(ScrnInfoPtr scrn);
+drm_intel_bo *i830_allocate_framebuffer(ScrnInfoPtr scrn);
 
 /* i830_render.c */
 Bool i830_check_composite(int op, PicturePtr sourcec, PicturePtr mask,
diff --git a/src/i830_driver.c b/src/i830_driver.c
index 733f409..99db7c6 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -1199,7 +1199,7 @@  I830ScreenInit(int scrnIndex, ScreenPtr screen, int argc, char **argv)
 	 * set the initial framebuffer pixmap to point at
 	 * it
 	 */
-	scrn->fbOffset = intel->front_buffer->bo->offset;
+	scrn->fbOffset = intel->front_buffer->offset;
 
 	DPRINTF(PFX, "assert( if(!fbScreenInit(screen, ...) )\n");
 	if (!fbScreenInit(screen, NULL,
@@ -1444,7 +1444,7 @@  static Bool I830CloseScreen(int scrnIndex, ScreenPtr screen)
 	if (intel->front_buffer) {
 		i830_set_pixmap_bo(screen->GetScreenPixmap(screen), NULL);
 		drmmode_closefb(scrn);
-		i830_free_memory(scrn, intel->front_buffer);
+		drm_intel_bo_unreference(intel->front_buffer);
 		intel->front_buffer = NULL;
 	}
 
diff --git a/src/i830_memory.c b/src/i830_memory.c
index 309656a..089667d 100644
--- a/src/i830_memory.c
+++ b/src/i830_memory.c
@@ -208,6 +208,7 @@  void i830_reset_allocations(ScrnInfoPtr scrn)
 		intel->cursor_mem_argb[p] = NULL;
 	}
 
+	drm_intel_bo_unreference(intel->front_buffer);
 	intel->front_buffer = NULL;
 }
 
@@ -336,14 +337,14 @@  static Bool IsTileable(ScrnInfoPtr scrn, int pitch)
  * Used once for each X screen, so once with RandR 1.2 and twice with classic
  * dualhead.
  */
-i830_memory *i830_allocate_framebuffer(ScrnInfoPtr scrn)
+drm_intel_bo *i830_allocate_framebuffer(ScrnInfoPtr scrn)
 {
 	intel_screen_private *intel = intel_get_screen_private(scrn);
 	unsigned int pitch = scrn->displayWidth * intel->cpp;
 	long size, fb_height;
-	int flags;
-	i830_memory *front_buffer = NULL;
-	uint32_t tiling_mode;
+	int flags, ret;
+	drm_intel_bo *front_buffer = NULL;
+	uint32_t tiling_mode, requested_tiling_mode;
 
 	flags = ALLOW_SHARING | DISABLE_REUSE;
 
@@ -367,8 +368,13 @@  i830_memory *i830_allocate_framebuffer(ScrnInfoPtr scrn)
 		return NULL;
 	}
 
-	front_buffer = i830_allocate_memory(scrn, "front buffer", size,
-					    pitch, flags, tiling_mode);
+	if (tiling_mode != I915_TILING_NONE) {
+		/* round to size necessary for the fence register to work */
+		size = i830_get_fence_size(intel, size);
+	}
+
+	front_buffer = drm_intel_bo_alloc(intel->bufmgr, "front buffer",
+					  size, GTT_PAGE_SIZE);
 
 	if (front_buffer == NULL) {
 		xf86DrvMsg(scrn->scrnIndex, X_ERROR,
@@ -376,6 +382,16 @@  i830_memory *i830_allocate_framebuffer(ScrnInfoPtr scrn)
 		return NULL;
 	}
 
+	requested_tiling_mode = tiling_mode;
+	ret = drm_intel_bo_set_tiling(front_buffer, &tiling_mode, pitch);
+	if (ret != 0 || tiling_mode != requested_tiling_mode) {
+		xf86DrvMsg(scrn->scrnIndex, X_ERROR,
+			   "Failed to set tiling on frontbuffer: %s\n",
+			   ret == 0 ? "rejected by kernel" : strerror(-ret));
+	}
+
+	drm_intel_bo_disable_reuse(front_buffer);
+
 	i830_set_gem_max_sizes(scrn);
 
 	return front_buffer;
@@ -438,7 +454,7 @@  Bool i830_reinit_memory(ScrnInfoPtr scrn)
 	i830_set_gem_max_sizes(scrn);
 
 	if (intel->front_buffer)
-		scrn->fbOffset = intel->front_buffer->bo->offset;
+		scrn->fbOffset = intel->front_buffer->offset;
 
 	return TRUE;
 }
diff --git a/src/i830_uxa.c b/src/i830_uxa.c
index 50835db..9904311 100644
--- a/src/i830_uxa.c
+++ b/src/i830_uxa.c
@@ -616,7 +616,7 @@  static void i830_uxa_finish_access(PixmapPtr pixmap)
 	ScrnInfoPtr scrn = xf86Screens[screen->myNum];
 	intel_screen_private *intel = intel_get_screen_private(scrn);
 
-	if (bo == intel->front_buffer->bo)
+	if (bo == intel->front_buffer)
 		intel->need_flush = TRUE;
 
 	if (bo->size > intel->max_gtt_map_size)
@@ -791,7 +791,7 @@  void i830_uxa_block_handler(ScreenPtr screen)
 	intel_screen_private *intel = intel_get_screen_private(scrn);
 
 	if (intel->need_flush) {
-		dri_bo_wait_rendering(intel->front_buffer->bo);
+		dri_bo_wait_rendering(intel->front_buffer);
 		intel->need_flush = FALSE;
 	}
 }
@@ -900,7 +900,7 @@  void i830_uxa_create_screen_resources(ScreenPtr screen)
 {
 	ScrnInfoPtr scrn = xf86Screens[screen->myNum];
 	intel_screen_private *intel = intel_get_screen_private(scrn);
-	dri_bo *bo = intel->front_buffer->bo;
+	dri_bo *bo = intel->front_buffer;
 
 	if (bo != NULL) {
 		PixmapPtr pixmap = screen->GetScreenPixmap(screen);