2 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * Author: Alan Hourihane <alanh@tungstengraphics.com>
27 * Author: Jakob Bornecrantz <wallbraker@gmail.com>
32 #include "xorg-server.h"
34 #include "xf86_OSproc.h"
36 #include "xf86PciInfo.h"
38 #include "mipointer.h"
40 #include <X11/extensions/randr.h>
45 #include "miscstruct.h"
46 #include "dixstruct.h"
48 #include <X11/extensions/Xv.h>
49 #ifndef XSERVER_LIBPCIACCESS
50 #error "libpciaccess needed"
53 #include <pciaccess.h>
55 #include "pipe/p_context.h"
56 #include "xorg_tracker.h"
57 #include "xorg_winsys.h"
64 * Functions and symbols exported to Xorg via pointers.
67 static Bool
drv_pre_init(ScrnInfoPtr pScrn
, int flags
);
68 static Bool
drv_screen_init(int scrnIndex
, ScreenPtr pScreen
, int argc
,
70 static Bool
drv_switch_mode(int scrnIndex
, DisplayModePtr mode
, int flags
);
71 static void drv_adjust_frame(int scrnIndex
, int x
, int y
, int flags
);
72 static Bool
drv_enter_vt(int scrnIndex
, int flags
);
73 static void drv_leave_vt(int scrnIndex
, int flags
);
74 static void drv_free_screen(int scrnIndex
, int flags
);
75 static ModeStatus
drv_valid_mode(int scrnIndex
, DisplayModePtr mode
, Bool verbose
,
84 static const OptionInfoRec drv_options
[] = {
85 {OPTION_SW_CURSOR
, "SWcursor", OPTV_BOOLEAN
, {0}, FALSE
},
86 {OPTION_2D_ACCEL
, "2DAccel", OPTV_BOOLEAN
, {0}, FALSE
},
87 {-1, NULL
, OPTV_NONE
, {0}, FALSE
}
92 * Exported Xorg driver functions to winsys
96 xorg_tracker_available_options(int chipid
, int busid
)
102 xorg_tracker_set_functions(ScrnInfoPtr scrn
)
104 scrn
->PreInit
= drv_pre_init
;
105 scrn
->ScreenInit
= drv_screen_init
;
106 scrn
->SwitchMode
= drv_switch_mode
;
107 scrn
->AdjustFrame
= drv_adjust_frame
;
108 scrn
->EnterVT
= drv_enter_vt
;
109 scrn
->LeaveVT
= drv_leave_vt
;
110 scrn
->FreeScreen
= drv_free_screen
;
111 scrn
->ValidMode
= drv_valid_mode
;
116 * Internal function definitions
119 static Bool
drv_init_front_buffer_functions(ScrnInfoPtr pScrn
);
120 static Bool
drv_close_screen(int scrnIndex
, ScreenPtr pScreen
);
121 static Bool
drv_save_hw_state(ScrnInfoPtr pScrn
);
122 static Bool
drv_restore_hw_state(ScrnInfoPtr pScrn
);
130 drv_get_rec(ScrnInfoPtr pScrn
)
132 if (pScrn
->driverPrivate
)
135 pScrn
->driverPrivate
= xnfcalloc(sizeof(modesettingRec
), 1);
141 drv_free_rec(ScrnInfoPtr pScrn
)
146 if (!pScrn
->driverPrivate
)
149 xfree(pScrn
->driverPrivate
);
151 pScrn
->driverPrivate
= NULL
;
155 drv_probe_ddc(ScrnInfoPtr pScrn
, int index
)
157 ConfiguredMonitor
= NULL
;
161 drv_crtc_resize(ScrnInfoPtr pScrn
, int width
, int height
)
163 modesettingPtr ms
= modesettingPTR(pScrn
);
164 PixmapPtr rootPixmap
;
165 ScreenPtr pScreen
= pScrn
->pScreen
;
167 if (width
== pScrn
->virtualX
&& height
== pScrn
->virtualY
)
170 pScrn
->virtualX
= width
;
171 pScrn
->virtualY
= height
;
174 * Remove the old framebuffer & texture.
176 drmModeRmFB(ms
->fd
, ms
->fb_id
);
177 if (!ms
->destroy_front_buffer(pScrn
))
178 FatalError("failed to destroy front buffer\n");
180 rootPixmap
= pScreen
->GetScreenPixmap(pScreen
);
181 if (!pScreen
->ModifyPixmapHeader(rootPixmap
, width
, height
, -1, -1, -1, NULL
))
184 /* HW dependent - FIXME */
185 pScrn
->displayWidth
= pScrn
->virtualX
;
187 /* now create new frontbuffer */
188 return ms
->create_front_buffer(pScrn
) && ms
->bind_front_buffer(pScrn
);
191 static const xf86CrtcConfigFuncsRec crtc_config_funcs
= {
192 .resize
= drv_crtc_resize
196 drv_init_drm(ScrnInfoPtr pScrn
)
198 modesettingPtr ms
= modesettingPTR(pScrn
);
200 /* deal with server regeneration */
205 sprintf(BusID
, "PCI:%d:%d:%d",
206 ((ms
->PciInfo
->domain
<< 8) | ms
->PciInfo
->bus
),
207 ms
->PciInfo
->dev
, ms
->PciInfo
->func
210 ms
->fd
= drmOpen(NULL
, BusID
);
220 drv_init_resource_management(ScrnInfoPtr pScrn
)
222 modesettingPtr ms
= modesettingPTR(pScrn
);
224 ScreenPtr pScreen = pScrn->pScreen;
225 PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
226 Bool fbAccessDisabled;
230 if (ms
->screen
|| ms
->kms
)
233 ms
->api
= drm_api_create();
235 ms
->screen
= ms
->api
->create_screen(ms
->api
, ms
->fd
, NULL
);
240 if (ms
->api
->destroy
)
241 ms
->api
->destroy(ms
->api
);
247 if (!kms_create(ms
->fd
, &ms
->kms
))
255 drv_close_resource_management(ScrnInfoPtr pScrn
)
257 modesettingPtr ms
= modesettingPTR(pScrn
);
260 ms
->screen
->destroy(ms
->screen
);
263 if (ms
->api
&& ms
->api
->destroy
)
264 ms
->api
->destroy(ms
->api
);
269 kms_destroy(&ms
->kms
);
276 drv_pre_init(ScrnInfoPtr pScrn
, int flags
)
278 xf86CrtcConfigPtr xf86_config
;
280 rgb defaultWeight
= { 0, 0, 0 };
283 int max_width
, max_height
;
285 if (pScrn
->numEntities
!= 1)
288 pEnt
= xf86GetEntityInfo(pScrn
->entityList
[0]);
290 if (flags
& PROBE_DETECT
) {
291 drv_probe_ddc(pScrn
, pEnt
->index
);
295 /* Allocate driverPrivate */
296 if (!drv_get_rec(pScrn
))
299 ms
= modesettingPTR(pScrn
);
300 ms
->SaveGeneration
= -1;
303 pScrn
->displayWidth
= 640; /* default it */
305 if (ms
->pEnt
->location
.type
!= BUS_PCI
)
308 ms
->PciInfo
= xf86GetPciInfoForEntity(ms
->pEnt
->index
);
310 /* Allocate an entity private if necessary */
311 if (xf86IsEntityShared(pScrn
->entityList
[0])) {
312 FatalError("Entity");
314 msEnt
= xf86GetEntityPrivate(pScrn
->entityList
[0],
315 modesettingEntityIndex
)->ptr
;
316 ms
->entityPrivate
= msEnt
;
321 ms
->entityPrivate
= NULL
;
323 if (xf86IsEntityShared(pScrn
->entityList
[0])) {
324 if (xf86IsPrimInitDone(pScrn
->entityList
[0])) {
327 xf86SetPrimInitDone(pScrn
->entityList
[0]);
333 if (!drv_init_drm(pScrn
))
336 pScrn
->monitor
= pScrn
->confScreen
->monitor
;
337 pScrn
->progClock
= TRUE
;
342 PreferConvert24to32
| SupportConvert24to32
| Support32bppFb
))
345 switch (pScrn
->depth
) {
351 xf86DrvMsg(pScrn
->scrnIndex
, X_ERROR
,
352 "Given depth (%d) is not supported by the driver\n",
356 xf86PrintDepthBpp(pScrn
);
358 if (!xf86SetWeight(pScrn
, defaultWeight
, defaultWeight
))
360 if (!xf86SetDefaultVisual(pScrn
, -1))
363 /* Process the options */
364 xf86CollectOptions(pScrn
, NULL
);
365 if (!(ms
->Options
= xalloc(sizeof(drv_options
))))
367 memcpy(ms
->Options
, drv_options
, sizeof(drv_options
));
368 xf86ProcessOptions(pScrn
->scrnIndex
, pScrn
->options
, ms
->Options
);
370 /* Allocate an xf86CrtcConfig */
371 xf86CrtcConfigInit(pScrn
, &crtc_config_funcs
);
372 xf86_config
= XF86_CRTC_CONFIG_PTR(pScrn
);
376 xf86CrtcSetSizeRange(pScrn
, 320, 200, max_width
, max_height
);
378 if (xf86ReturnOptValBool(ms
->Options
, OPTION_SW_CURSOR
, FALSE
)) {
382 drv_save_hw_state(pScrn
);
384 xorg_crtc_init(pScrn
);
385 xorg_output_init(pScrn
);
387 if (!xf86InitialConfiguration(pScrn
, TRUE
)) {
388 xf86DrvMsg(pScrn
->scrnIndex
, X_ERROR
, "No valid modes.\n");
389 drv_restore_hw_state(pScrn
);
393 drv_restore_hw_state(pScrn
);
396 * If the driver can do gamma correction, it should call xf86SetGamma() here.
399 Gamma zeros
= { 0.0, 0.0, 0.0 };
401 if (!xf86SetGamma(pScrn
, zeros
)) {
406 if (pScrn
->modes
== NULL
) {
407 xf86DrvMsg(pScrn
->scrnIndex
, X_ERROR
, "No modes.\n");
411 pScrn
->currentMode
= pScrn
->modes
;
413 /* Set display resolution */
414 xf86SetDpi(pScrn
, 0, 0);
416 /* Load the required sub modules */
417 if (!xf86LoadSubModule(pScrn
, "fb"))
420 /* XXX: these aren't needed when we are using libkms */
421 if (!xf86LoadSubModule(pScrn
, "exa"))
425 if (!xf86LoadSubModule(pScrn
, "dri2"))
433 drv_save_hw_state(ScrnInfoPtr pScrn
)
435 /*xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);*/
441 drv_restore_hw_state(ScrnInfoPtr pScrn
)
443 /*xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);*/
448 static void drv_block_handler(int i
, pointer blockData
, pointer pTimeout
,
451 ScreenPtr pScreen
= screenInfo
.screens
[i
];
452 modesettingPtr ms
= modesettingPTR(xf86Screens
[pScreen
->myNum
]);
454 pScreen
->BlockHandler
= ms
->blockHandler
;
455 pScreen
->BlockHandler(i
, blockData
, pTimeout
, pReadmask
);
456 pScreen
->BlockHandler
= drv_block_handler
;
461 ms
->ctx
->flush(ms
->ctx
, PIPE_FLUSH_RENDER_CACHE
, &ms
->fence
[XORG_NR_FENCES
-1]);
464 ms
->ctx
->screen
->fence_finish(ms
->ctx
->screen
, ms
->fence
[0], 0);
466 /* The amount of rendering generated by a block handler can be
467 * quite small. Let us get a fair way ahead of hardware before
470 for (j
= 0; j
< XORG_NR_FENCES
; j
++)
471 ms
->screen
->fence_reference(ms
->screen
,
475 ms
->screen
->fence_reference(ms
->screen
,
476 &ms
->fence
[XORG_NR_FENCES
-1],
481 #ifdef DRM_MODE_FEATURE_DIRTYFB
483 RegionPtr dirty
= DamageRegion(ms
->damage
);
484 unsigned num_cliprects
= REGION_NUM_RECTS(dirty
);
487 drmModeClip
*clip
= alloca(num_cliprects
* sizeof(drmModeClip
));
488 BoxPtr rect
= REGION_RECTS(dirty
);
491 /* XXX no need for copy? */
492 for (i
= 0; i
< num_cliprects
; i
++, rect
++) {
493 clip
[i
].x1
= rect
->x1
;
494 clip
[i
].y1
= rect
->y1
;
495 clip
[i
].x2
= rect
->x2
;
496 clip
[i
].y2
= rect
->y2
;
499 /* TODO query connector property to see if this is needed */
500 ret
= drmModeDirtyFB(ms
->fd
, ms
->fb_id
, clip
, num_cliprects
);
502 debug_printf("%s: failed to send dirty (%i, %s)\n",
503 __func__
, ret
, strerror(-ret
));
506 DamageEmpty(ms
->damage
);
513 drv_create_screen_resources(ScreenPtr pScreen
)
515 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
516 modesettingPtr ms
= modesettingPTR(pScrn
);
517 PixmapPtr rootPixmap
;
522 pScreen
->CreateScreenResources
= ms
->createScreenResources
;
523 ret
= pScreen
->CreateScreenResources(pScreen
);
524 pScreen
->CreateScreenResources
= drv_create_screen_resources
;
526 ms
->bind_front_buffer(pScrn
);
530 drv_adjust_frame(pScrn
->scrnIndex
, pScrn
->frameX0
, pScrn
->frameY0
, 0);
532 #ifdef DRM_MODE_FEATURE_DIRTYFB
533 rootPixmap
= pScreen
->GetScreenPixmap(pScreen
);
534 ms
->damage
= DamageCreate(NULL
, NULL
, DamageReportNone
, TRUE
,
535 pScreen
, rootPixmap
);
538 DamageRegister(&rootPixmap
->drawable
, ms
->damage
);
540 xf86DrvMsg(pScrn
->scrnIndex
, X_INFO
, "Damage tracking initialized\n");
542 xf86DrvMsg(pScrn
->scrnIndex
, X_ERROR
,
543 "Failed to create screen damage record\n");
554 drv_screen_init(int scrnIndex
, ScreenPtr pScreen
, int argc
, char **argv
)
556 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
557 modesettingPtr ms
= modesettingPTR(pScrn
);
560 if (!drv_init_drm(pScrn
)) {
561 FatalError("Could not init DRM");
565 if (!drv_init_resource_management(pScrn
)) {
566 FatalError("Could not init resource management (!pipe_screen && !libkms)");
570 if (!drv_init_front_buffer_functions(pScrn
)) {
571 FatalError("Could not init front buffer manager");
575 pScrn
->pScreen
= pScreen
;
577 /* HW dependent - FIXME */
578 pScrn
->displayWidth
= pScrn
->virtualX
;
580 miClearVisualTypes();
582 if (!miSetVisualTypes(pScrn
->depth
,
583 miGetDefaultVisualMask(pScrn
->depth
),
584 pScrn
->rgbBits
, pScrn
->defaultVisual
))
587 if (!miSetPixmapDepths())
590 pScrn
->memPhysBase
= 0;
593 if (!fbScreenInit(pScreen
, NULL
,
594 pScrn
->virtualX
, pScrn
->virtualY
,
595 pScrn
->xDpi
, pScrn
->yDpi
,
596 pScrn
->displayWidth
, pScrn
->bitsPerPixel
))
599 if (pScrn
->bitsPerPixel
> 8) {
600 /* Fixup RGB ordering */
601 visual
= pScreen
->visuals
+ pScreen
->numVisuals
;
602 while (--visual
>= pScreen
->visuals
) {
603 if ((visual
->class | DynamicClass
) == DirectColor
) {
604 visual
->offsetRed
= pScrn
->offset
.red
;
605 visual
->offsetGreen
= pScrn
->offset
.green
;
606 visual
->offsetBlue
= pScrn
->offset
.blue
;
607 visual
->redMask
= pScrn
->mask
.red
;
608 visual
->greenMask
= pScrn
->mask
.green
;
609 visual
->blueMask
= pScrn
->mask
.blue
;
614 fbPictureInit(pScreen
, NULL
, 0);
616 ms
->blockHandler
= pScreen
->BlockHandler
;
617 pScreen
->BlockHandler
= drv_block_handler
;
618 ms
->createScreenResources
= pScreen
->CreateScreenResources
;
619 pScreen
->CreateScreenResources
= drv_create_screen_resources
;
621 xf86SetBlackWhitePixels(pScreen
);
624 ms
->exa
= xorg_exa_init(pScrn
, xf86ReturnOptValBool(ms
->Options
,
625 OPTION_2D_ACCEL
, TRUE
));
626 ms
->debug_fallback
= debug_get_bool_option("XORG_DEBUG_FALLBACK", TRUE
);
628 xorg_xv_init(pScreen
);
630 xorg_dri2_init(pScreen
);
634 miInitializeBackingStore(pScreen
);
635 xf86SetBackingStore(pScreen
);
636 xf86SetSilkenMouse(pScreen
);
637 miDCInitialize(pScreen
, xf86GetPointerScreenFuncs());
639 /* Need to extend HWcursor support to handle mask interleave */
641 xf86_cursors_init(pScreen
, 64, 64,
642 HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64
|
643 HARDWARE_CURSOR_ARGB
);
645 /* Must force it before EnterVT, so we are in control of VT and
646 * later memory should be bound when allocating, e.g rotate_mem */
647 pScrn
->vtSema
= TRUE
;
649 pScreen
->SaveScreen
= xf86SaveScreen
;
650 ms
->CloseScreen
= pScreen
->CloseScreen
;
651 pScreen
->CloseScreen
= drv_close_screen
;
653 if (!xf86CrtcScreenInit(pScreen
))
656 if (!miCreateDefColormap(pScreen
))
659 xf86DPMSInit(pScreen
, xf86DPMSSet
, 0);
661 if (serverGeneration
== 1)
662 xf86ShowUnusedOptions(pScrn
->scrnIndex
, pScrn
->options
);
664 if (ms
->winsys_screen_init
)
665 ms
->winsys_screen_init(pScrn
);
667 return drv_enter_vt(scrnIndex
, 1);
671 drv_adjust_frame(int scrnIndex
, int x
, int y
, int flags
)
673 ScrnInfoPtr pScrn
= xf86Screens
[scrnIndex
];
674 xf86CrtcConfigPtr config
= XF86_CRTC_CONFIG_PTR(pScrn
);
675 xf86OutputPtr output
= config
->output
[config
->compat_output
];
676 xf86CrtcPtr crtc
= output
->crtc
;
678 if (crtc
&& crtc
->enabled
) {
679 crtc
->funcs
->set_mode_major(crtc
, pScrn
->currentMode
,
681 crtc
->x
= output
->initial_x
+ x
;
682 crtc
->y
= output
->initial_y
+ y
;
687 drv_free_screen(int scrnIndex
, int flags
)
689 drv_free_rec(xf86Screens
[scrnIndex
]);
693 drv_leave_vt(int scrnIndex
, int flags
)
695 ScrnInfoPtr pScrn
= xf86Screens
[scrnIndex
];
696 modesettingPtr ms
= modesettingPTR(pScrn
);
697 xf86CrtcConfigPtr config
= XF86_CRTC_CONFIG_PTR(pScrn
);
700 if (ms
->winsys_leave_vt
)
701 ms
->winsys_leave_vt(pScrn
);
703 for (o
= 0; o
< config
->num_crtc
; o
++) {
704 xf86CrtcPtr crtc
= config
->crtc
[o
];
706 xorg_crtc_cursor_destroy(crtc
);
708 if (crtc
->rotatedPixmap
|| crtc
->rotatedData
) {
709 crtc
->funcs
->shadow_destroy(crtc
, crtc
->rotatedPixmap
,
711 crtc
->rotatedPixmap
= NULL
;
712 crtc
->rotatedData
= NULL
;
716 drmModeRmFB(ms
->fd
, ms
->fb_id
);
718 drv_restore_hw_state(pScrn
);
720 if (drmDropMaster(ms
->fd
))
721 xf86DrvMsg(pScrn
->scrnIndex
, X_WARNING
,
722 "drmDropMaster failed: %s\n", strerror(errno
));
724 pScrn
->vtSema
= FALSE
;
728 * This gets called when gaining control of the VT, and from ScreenInit().
731 drv_enter_vt(int scrnIndex
, int flags
)
733 ScrnInfoPtr pScrn
= xf86Screens
[scrnIndex
];
734 modesettingPtr ms
= modesettingPTR(pScrn
);
736 if (drmSetMaster(ms
->fd
)) {
737 if (errno
== EINVAL
) {
738 xf86DrvMsg(pScrn
->scrnIndex
, X_WARNING
,
739 "drmSetMaster failed: 2.6.29 or newer kernel required for "
740 "multi-server DRI\n");
742 xf86DrvMsg(pScrn
->scrnIndex
, X_WARNING
,
743 "drmSetMaster failed: %s\n", strerror(errno
));
748 * Only save state once per server generation since that's what most
749 * drivers do. Could change this to save state at each VT enter.
751 if (ms
->SaveGeneration
!= serverGeneration
) {
752 ms
->SaveGeneration
= serverGeneration
;
753 drv_save_hw_state(pScrn
);
756 if (!ms
->create_front_buffer(pScrn
))
759 if (!flags
&& !ms
->bind_front_buffer(pScrn
))
762 if (!xf86SetDesiredModes(pScrn
))
765 if (ms
->winsys_enter_vt
)
766 ms
->winsys_enter_vt(pScrn
);
772 drv_switch_mode(int scrnIndex
, DisplayModePtr mode
, int flags
)
774 ScrnInfoPtr pScrn
= xf86Screens
[scrnIndex
];
776 return xf86SetSingleMode(pScrn
, mode
, RR_Rotate_0
);
780 drv_close_screen(int scrnIndex
, ScreenPtr pScreen
)
782 ScrnInfoPtr pScrn
= xf86Screens
[scrnIndex
];
783 modesettingPtr ms
= modesettingPTR(pScrn
);
786 drv_leave_vt(scrnIndex
, 0);
789 if (ms
->winsys_screen_close
)
790 ms
->winsys_screen_close(pScrn
);
794 xorg_dri2_close(pScreen
);
797 pScreen
->BlockHandler
= ms
->blockHandler
;
798 pScreen
->CreateScreenResources
= ms
->createScreenResources
;
800 #ifdef DRM_MODE_FEATURE_DIRTYFB
802 DamageUnregister(&pScreen
->GetScreenPixmap(pScreen
)->drawable
, ms
->damage
);
803 DamageDestroy(ms
->damage
);
808 drmModeRmFB(ms
->fd
, ms
->fb_id
);
809 ms
->destroy_front_buffer(pScrn
);
812 xorg_exa_close(pScrn
);
815 drv_close_resource_management(pScrn
);
820 pScrn
->vtSema
= FALSE
;
821 pScreen
->CloseScreen
= ms
->CloseScreen
;
822 return (*pScreen
->CloseScreen
) (scrnIndex
, pScreen
);
826 drv_valid_mode(int scrnIndex
, DisplayModePtr mode
, Bool verbose
, int flags
)
833 * Front buffer backing store functions.
837 drv_destroy_front_buffer_ga3d(ScrnInfoPtr pScrn
)
839 modesettingPtr ms
= modesettingPTR(pScrn
);
840 pipe_texture_reference(&ms
->root_texture
, NULL
);
845 drv_create_front_buffer_ga3d(ScrnInfoPtr pScrn
)
847 modesettingPtr ms
= modesettingPTR(pScrn
);
848 unsigned handle
, stride
;
849 struct pipe_texture
*tex
;
854 tex
= xorg_exa_create_root_texture(pScrn
, pScrn
->virtualX
, pScrn
->virtualY
,
855 pScrn
->depth
, pScrn
->bitsPerPixel
);
860 if (!ms
->api
->local_handle_from_texture(ms
->api
, ms
->screen
,
866 ret
= drmModeAddFB(ms
->fd
,
875 debug_printf("%s: failed to create framebuffer (%i, %s)",
876 __func__
, ret
, strerror(-ret
));
882 drv_adjust_frame(pScrn
->scrnIndex
, pScrn
->frameX0
, pScrn
->frameY0
, 0);
884 pipe_texture_reference(&ms
->root_texture
, tex
);
885 pipe_texture_reference(&tex
, NULL
);
890 pipe_texture_reference(&tex
, NULL
);
895 drv_bind_front_buffer_ga3d(ScrnInfoPtr pScrn
)
897 modesettingPtr ms
= modesettingPTR(pScrn
);
898 ScreenPtr pScreen
= pScrn
->pScreen
;
899 PixmapPtr rootPixmap
= pScreen
->GetScreenPixmap(pScreen
);
900 struct pipe_texture
*check
;
902 xorg_exa_set_displayed_usage(rootPixmap
);
903 xorg_exa_set_shared_usage(rootPixmap
);
904 xorg_exa_set_texture(rootPixmap
, ms
->root_texture
);
905 if (!pScreen
->ModifyPixmapHeader(rootPixmap
, -1, -1, -1, -1, -1, NULL
))
906 FatalError("Couldn't adjust screen pixmap\n");
908 check
= xorg_exa_get_texture(rootPixmap
);
909 if (ms
->root_texture
!= check
)
910 FatalError("Created new root texture\n");
912 pipe_texture_reference(&check
, NULL
);
918 drv_destroy_front_buffer_kms(ScrnInfoPtr pScrn
)
920 modesettingPtr ms
= modesettingPTR(pScrn
);
921 ScreenPtr pScreen
= pScrn
->pScreen
;
922 PixmapPtr rootPixmap
= pScreen
->GetScreenPixmap(pScreen
);
927 kms_bo_unmap(ms
->root_bo
);
928 kms_bo_destroy(&ms
->root_bo
);
933 drv_create_front_buffer_kms(ScrnInfoPtr pScrn
)
935 modesettingPtr ms
= modesettingPTR(pScrn
);
936 unsigned handle
, stride
;
941 attr
[0] = KMS_BO_TYPE
;
942 attr
[1] = KMS_BO_TYPE_SCANOUT
;
944 attr
[3] = pScrn
->virtualX
;
945 attr
[4] = KMS_HEIGHT
;
946 attr
[5] = pScrn
->virtualY
;
949 if (kms_bo_create(ms
->kms
, attr
, &bo
))
952 if (kms_bo_get_prop(bo
, KMS_PITCH
, &stride
))
955 if (kms_bo_get_prop(bo
, KMS_HANDLE
, &handle
))
958 ret
= drmModeAddFB(ms
->fd
,
967 debug_printf("%s: failed to create framebuffer (%i, %s)",
968 __func__
, ret
, strerror(-ret
));
974 drv_adjust_frame(pScrn
->scrnIndex
, pScrn
->frameX0
, pScrn
->frameY0
, 0);
985 drv_bind_front_buffer_kms(ScrnInfoPtr pScrn
)
987 modesettingPtr ms
= modesettingPTR(pScrn
);
988 ScreenPtr pScreen
= pScrn
->pScreen
;
989 PixmapPtr rootPixmap
= pScreen
->GetScreenPixmap(pScreen
);
993 if (kms_bo_get_prop(ms
->root_bo
, KMS_PITCH
, &stride
))
996 if (kms_bo_map(ms
->root_bo
, &ptr
))
999 pScreen
->ModifyPixmapHeader(rootPixmap
,
1003 pScrn
->bitsPerPixel
,
1009 kms_bo_destroy(&ms
->root_bo
);
1012 #endif /* HAVE_LIBKMS */
1014 static Bool
drv_init_front_buffer_functions(ScrnInfoPtr pScrn
)
1016 modesettingPtr ms
= modesettingPTR(pScrn
);
1018 ms
->destroy_front_buffer
= drv_destroy_front_buffer_ga3d
;
1019 ms
->create_front_buffer
= drv_create_front_buffer_ga3d
;
1020 ms
->bind_front_buffer
= drv_bind_front_buffer_ga3d
;
1022 } else if (ms
->kms
) {
1023 ms
->destroy_front_buffer
= drv_destroy_front_buffer_kms
;
1024 ms
->create_front_buffer
= drv_create_front_buffer_kms
;
1025 ms
->bind_front_buffer
= drv_bind_front_buffer_kms
;
1033 /* vim: set sw=4 ts=8 sts=4: */