Merge branch 'mesa_7_7_branch'
[mesa.git] / src / gallium / state_trackers / xorg / xorg_driver.c
index da86295c316922ee2af3266f12bec1e150b09e49..4d169a1d14caa285f020bb44d97f9bef71c24bc0 100644 (file)
@@ -220,6 +220,12 @@ static Bool
 drv_init_resource_management(ScrnInfoPtr pScrn)
 {
     modesettingPtr ms = modesettingPTR(pScrn);
+    /*
+    ScreenPtr pScreen = pScrn->pScreen;
+    PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
+    Bool fbAccessDisabled;
+    CARD8 *fbstart;
+     */
 
     if (ms->screen || ms->kms)
        return TRUE;
@@ -249,9 +255,19 @@ static Bool
 drv_close_resource_management(ScrnInfoPtr pScrn)
 {
     modesettingPtr ms = modesettingPTR(pScrn);
+    int i;
 
-    if (ms->screen)
+    if (ms->screen) {
+       assert(ms->ctx == NULL);
+
+       for (i = 0; i < XORG_NR_FENCES; i++) {
+           if (ms->fence[i]) {
+               ms->screen->fence_finish(ms->screen, ms->fence[i], 0);
+               ms->screen->fence_reference(ms->screen, &ms->fence[i], NULL);
+           }
+       }
        ms->screen->destroy(ms->screen);
+    }
     ms->screen = NULL;
 
     if (ms->api && ms->api->destroy)
@@ -260,8 +276,7 @@ drv_close_resource_management(ScrnInfoPtr pScrn)
 
 #ifdef HAVE_LIBKMS
     if (ms->kms)
-       kms_destroy(ms->kms);
-    ms->kms = NULL;
+       kms_destroy(&ms->kms);
 #endif
 
     return TRUE;
@@ -462,7 +477,7 @@ static void drv_block_handler(int i, pointer blockData, pointer pTimeout,
         * quite small.  Let us get a fair way ahead of hardware before
         * throttling.
         */
-       for (j = 0; j < XORG_NR_FENCES; j++)
+       for (j = 0; j < XORG_NR_FENCES - 1; j++)
           ms->screen->fence_reference(ms->screen,
                                       &ms->fence[j],
                                       ms->fence[j+1]);
@@ -481,7 +496,7 @@ static void drv_block_handler(int i, pointer blockData, pointer pTimeout,
        if (num_cliprects) {
            drmModeClip *clip = alloca(num_cliprects * sizeof(drmModeClip));
            BoxPtr rect = REGION_RECTS(dirty);
-           int i;
+           int i, ret;
 
            /* XXX no need for copy? */
            for (i = 0; i < num_cliprects; i++, rect++) {
@@ -492,7 +507,11 @@ static void drv_block_handler(int i, pointer blockData, pointer pTimeout,
            }
 
            /* TODO query connector property to see if this is needed */
-           drmModeDirtyFB(ms->fd, ms->fb_id, clip, num_cliprects);
+           ret = drmModeDirtyFB(ms->fd, ms->fb_id, clip, num_cliprects);
+           if (ret) {
+               debug_printf("%s: failed to send dirty (%i, %s)\n",
+                            __func__, ret, strerror(-ret));
+           }
 
            DamageEmpty(ms->damage);
        }
@@ -688,6 +707,9 @@ drv_leave_vt(int scrnIndex, int flags)
     xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
     int o;
 
+    if (ms->winsys_leave_vt)
+       ms->winsys_leave_vt(pScrn);
+
     for (o = 0; o < config->num_crtc; o++) {
        xf86CrtcPtr crtc = config->crtc[o];
 
@@ -750,6 +772,9 @@ drv_enter_vt(int scrnIndex, int flags)
     if (!xf86SetDesiredModes(pScrn))
        return FALSE;
 
+    if (ms->winsys_enter_vt)
+       ms->winsys_enter_vt(pScrn);
+
     return TRUE;
 }
 
@@ -832,6 +857,7 @@ drv_create_front_buffer_ga3d(ScrnInfoPtr pScrn)
     modesettingPtr ms = modesettingPTR(pScrn);
     unsigned handle, stride;
     struct pipe_texture *tex;
+    int ret;
 
     ms->noEvict = TRUE;
 
@@ -845,16 +871,21 @@ drv_create_front_buffer_ga3d(ScrnInfoPtr pScrn)
                                            tex,
                                            &stride,
                                            &handle))
-       return FALSE;
+       goto err_destroy;
 
-    drmModeAddFB(ms->fd,
-                pScrn->virtualX,
-                pScrn->virtualY,
-                pScrn->depth,
-                pScrn->bitsPerPixel,
-                stride,
-                handle,
-                 &ms->fb_id);
+    ret = drmModeAddFB(ms->fd,
+                      pScrn->virtualX,
+                      pScrn->virtualY,
+                      pScrn->depth,
+                      pScrn->bitsPerPixel,
+                      stride,
+                      handle,
+                      &ms->fb_id);
+    if (ret) {
+       debug_printf("%s: failed to create framebuffer (%i, %s)",
+                    __func__, ret, strerror(-ret));
+       goto err_destroy;
+    }
 
     pScrn->frameX0 = 0;
     pScrn->frameY0 = 0;
@@ -864,6 +895,10 @@ drv_create_front_buffer_ga3d(ScrnInfoPtr pScrn)
     pipe_texture_reference(&tex, NULL);
 
     return TRUE;
+
+err_destroy:
+    pipe_texture_reference(&tex, NULL);
+    return FALSE;
 }
 
 static Bool
@@ -893,13 +928,20 @@ static Bool
 drv_destroy_front_buffer_kms(ScrnInfoPtr pScrn)
 {
     modesettingPtr ms = modesettingPTR(pScrn);
+    ScreenPtr pScreen = pScrn->pScreen;
+    PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
+
+    /* XXX Do something with the rootPixmap.
+     * This currently works fine but if we are getting crashes in
+     * the fb functions after VT switches maybe look more into it.
+     */
+    (void)rootPixmap;
 
     if (!ms->root_bo)
        return TRUE;
 
     kms_bo_unmap(ms->root_bo);
-    kms_bo_destroy(ms->root_bo);
-    ms->root_bo = NULL;
+    kms_bo_destroy(&ms->root_bo);
     return TRUE;
 }
 
@@ -910,6 +952,7 @@ drv_create_front_buffer_kms(ScrnInfoPtr pScrn)
     unsigned handle, stride;
     struct kms_bo *bo;
     unsigned attr[8];
+    int ret;
 
     attr[0] = KMS_BO_TYPE;
     attr[1] = KMS_BO_TYPE_SCANOUT;
@@ -928,14 +971,19 @@ drv_create_front_buffer_kms(ScrnInfoPtr pScrn)
     if (kms_bo_get_prop(bo, KMS_HANDLE, &handle))
        goto err_destroy;
 
-    drmModeAddFB(ms->fd,
-                pScrn->virtualX,
-                pScrn->virtualY,
-                pScrn->depth,
-                pScrn->bitsPerPixel,
-                stride,
-                handle,
-                 &ms->fb_id);
+    ret = drmModeAddFB(ms->fd,
+                      pScrn->virtualX,
+                      pScrn->virtualY,
+                      pScrn->depth,
+                      pScrn->bitsPerPixel,
+                      stride,
+                      handle,
+                      &ms->fb_id);
+    if (ret) {
+       debug_printf("%s: failed to create framebuffer (%i, %s)",
+                    __func__, ret, strerror(-ret));
+       goto err_destroy;
+    }
 
     pScrn->frameX0 = 0;
     pScrn->frameY0 = 0;
@@ -945,7 +993,7 @@ drv_create_front_buffer_kms(ScrnInfoPtr pScrn)
     return TRUE;
 
 err_destroy:
-    kms_bo_destroy(bo);
+    kms_bo_destroy(&bo);
     return FALSE;
 }
 
@@ -962,7 +1010,7 @@ drv_bind_front_buffer_kms(ScrnInfoPtr pScrn)
        return FALSE;
 
     if (kms_bo_map(ms->root_bo, &ptr))
-       return FALSE;
+       goto err_destroy;
 
     pScreen->ModifyPixmapHeader(rootPixmap,
                                pScreen->width,
@@ -972,6 +1020,10 @@ drv_bind_front_buffer_kms(ScrnInfoPtr pScrn)
                                stride,
                                ptr);
     return TRUE;
+
+err_destroy:
+    kms_bo_destroy(&ms->root_bo);
+    return FALSE;
 }
 #endif /* HAVE_LIBKMS */