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 if (ms
->screen
|| ms
->kms
)
227 ms
->api
= drm_api_create();
229 ms
->screen
= ms
->api
->create_screen(ms
->api
, ms
->fd
, NULL
);
234 if (ms
->api
->destroy
)
235 ms
->api
->destroy(ms
->api
);
241 if (!kms_create(ms
->fd
, &ms
->kms
))
249 drv_close_resource_management(ScrnInfoPtr pScrn
)
251 modesettingPtr ms
= modesettingPTR(pScrn
);
254 ms
->screen
->destroy(ms
->screen
);
257 if (ms
->api
&& ms
->api
->destroy
)
258 ms
->api
->destroy(ms
->api
);
263 kms_destroy(ms
->kms
);
271 drv_pre_init(ScrnInfoPtr pScrn
, int flags
)
273 xf86CrtcConfigPtr xf86_config
;
275 rgb defaultWeight
= { 0, 0, 0 };
278 int max_width
, max_height
;
280 if (pScrn
->numEntities
!= 1)
283 pEnt
= xf86GetEntityInfo(pScrn
->entityList
[0]);
285 if (flags
& PROBE_DETECT
) {
286 drv_probe_ddc(pScrn
, pEnt
->index
);
290 /* Allocate driverPrivate */
291 if (!drv_get_rec(pScrn
))
294 ms
= modesettingPTR(pScrn
);
295 ms
->SaveGeneration
= -1;
298 pScrn
->displayWidth
= 640; /* default it */
300 if (ms
->pEnt
->location
.type
!= BUS_PCI
)
303 ms
->PciInfo
= xf86GetPciInfoForEntity(ms
->pEnt
->index
);
305 /* Allocate an entity private if necessary */
306 if (xf86IsEntityShared(pScrn
->entityList
[0])) {
307 FatalError("Entity");
309 msEnt
= xf86GetEntityPrivate(pScrn
->entityList
[0],
310 modesettingEntityIndex
)->ptr
;
311 ms
->entityPrivate
= msEnt
;
316 ms
->entityPrivate
= NULL
;
318 if (xf86IsEntityShared(pScrn
->entityList
[0])) {
319 if (xf86IsPrimInitDone(pScrn
->entityList
[0])) {
322 xf86SetPrimInitDone(pScrn
->entityList
[0]);
328 if (!drv_init_drm(pScrn
))
331 pScrn
->monitor
= pScrn
->confScreen
->monitor
;
332 pScrn
->progClock
= TRUE
;
337 PreferConvert24to32
| SupportConvert24to32
| Support32bppFb
))
340 switch (pScrn
->depth
) {
346 xf86DrvMsg(pScrn
->scrnIndex
, X_ERROR
,
347 "Given depth (%d) is not supported by the driver\n",
351 xf86PrintDepthBpp(pScrn
);
353 if (!xf86SetWeight(pScrn
, defaultWeight
, defaultWeight
))
355 if (!xf86SetDefaultVisual(pScrn
, -1))
358 /* Process the options */
359 xf86CollectOptions(pScrn
, NULL
);
360 if (!(ms
->Options
= xalloc(sizeof(drv_options
))))
362 memcpy(ms
->Options
, drv_options
, sizeof(drv_options
));
363 xf86ProcessOptions(pScrn
->scrnIndex
, pScrn
->options
, ms
->Options
);
365 /* Allocate an xf86CrtcConfig */
366 xf86CrtcConfigInit(pScrn
, &crtc_config_funcs
);
367 xf86_config
= XF86_CRTC_CONFIG_PTR(pScrn
);
371 xf86CrtcSetSizeRange(pScrn
, 320, 200, max_width
, max_height
);
373 if (xf86ReturnOptValBool(ms
->Options
, OPTION_SW_CURSOR
, FALSE
)) {
377 drv_save_hw_state(pScrn
);
379 xorg_crtc_init(pScrn
);
380 xorg_output_init(pScrn
);
382 if (!xf86InitialConfiguration(pScrn
, TRUE
)) {
383 xf86DrvMsg(pScrn
->scrnIndex
, X_ERROR
, "No valid modes.\n");
384 drv_restore_hw_state(pScrn
);
388 drv_restore_hw_state(pScrn
);
391 * If the driver can do gamma correction, it should call xf86SetGamma() here.
394 Gamma zeros
= { 0.0, 0.0, 0.0 };
396 if (!xf86SetGamma(pScrn
, zeros
)) {
401 if (pScrn
->modes
== NULL
) {
402 xf86DrvMsg(pScrn
->scrnIndex
, X_ERROR
, "No modes.\n");
406 pScrn
->currentMode
= pScrn
->modes
;
408 /* Set display resolution */
409 xf86SetDpi(pScrn
, 0, 0);
411 /* Load the required sub modules */
412 if (!xf86LoadSubModule(pScrn
, "fb"))
415 /* XXX: these aren't needed when we are using libkms */
416 if (!xf86LoadSubModule(pScrn
, "exa"))
420 if (!xf86LoadSubModule(pScrn
, "dri2"))
428 drv_save_hw_state(ScrnInfoPtr pScrn
)
430 /*xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);*/
436 drv_restore_hw_state(ScrnInfoPtr pScrn
)
438 /*xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);*/
443 static void drv_block_handler(int i
, pointer blockData
, pointer pTimeout
,
446 ScreenPtr pScreen
= screenInfo
.screens
[i
];
447 modesettingPtr ms
= modesettingPTR(xf86Screens
[pScreen
->myNum
]);
449 pScreen
->BlockHandler
= ms
->blockHandler
;
450 pScreen
->BlockHandler(i
, blockData
, pTimeout
, pReadmask
);
451 pScreen
->BlockHandler
= drv_block_handler
;
454 ms
->ctx
->flush(ms
->ctx
, PIPE_FLUSH_RENDER_CACHE
, NULL
);
456 #ifdef DRM_MODE_FEATURE_DIRTYFB
458 RegionPtr dirty
= DamageRegion(ms
->damage
);
459 unsigned num_cliprects
= REGION_NUM_RECTS(dirty
);
462 drmModeClip
*clip
= alloca(num_cliprects
* sizeof(drmModeClip
));
463 BoxPtr rect
= REGION_RECTS(dirty
);
466 /* XXX no need for copy? */
467 for (i
= 0; i
< num_cliprects
; i
++, rect
++) {
468 clip
[i
].x1
= rect
->x1
;
469 clip
[i
].y1
= rect
->y1
;
470 clip
[i
].x2
= rect
->x2
;
471 clip
[i
].y2
= rect
->y2
;
474 /* TODO query connector property to see if this is needed */
475 drmModeDirtyFB(ms
->fd
, ms
->fb_id
, clip
, num_cliprects
);
477 DamageEmpty(ms
->damage
);
484 drv_create_screen_resources(ScreenPtr pScreen
)
486 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
487 modesettingPtr ms
= modesettingPTR(pScrn
);
488 PixmapPtr rootPixmap
;
493 pScreen
->CreateScreenResources
= ms
->createScreenResources
;
494 ret
= pScreen
->CreateScreenResources(pScreen
);
495 pScreen
->CreateScreenResources
= drv_create_screen_resources
;
497 ms
->bind_front_buffer(pScrn
);
501 drv_adjust_frame(pScrn
->scrnIndex
, pScrn
->frameX0
, pScrn
->frameY0
, 0);
503 #ifdef DRM_MODE_FEATURE_DIRTYFB
504 rootPixmap
= pScreen
->GetScreenPixmap(pScreen
);
505 ms
->damage
= DamageCreate(NULL
, NULL
, DamageReportNone
, TRUE
,
506 pScreen
, rootPixmap
);
509 DamageRegister(&rootPixmap
->drawable
, ms
->damage
);
511 xf86DrvMsg(pScrn
->scrnIndex
, X_INFO
, "Damage tracking initialized\n");
513 xf86DrvMsg(pScrn
->scrnIndex
, X_ERROR
,
514 "Failed to create screen damage record\n");
525 drv_screen_init(int scrnIndex
, ScreenPtr pScreen
, int argc
, char **argv
)
527 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
528 modesettingPtr ms
= modesettingPTR(pScrn
);
531 if (!drv_init_drm(pScrn
)) {
532 FatalError("Could not init DRM");
536 if (!drv_init_resource_management(pScrn
)) {
537 FatalError("Could not init resource management (!pipe_screen && !libkms)");
541 if (!drv_init_front_buffer_functions(pScrn
)) {
542 FatalError("Could not init front buffer manager");
546 pScrn
->pScreen
= pScreen
;
548 /* HW dependent - FIXME */
549 pScrn
->displayWidth
= pScrn
->virtualX
;
551 miClearVisualTypes();
553 if (!miSetVisualTypes(pScrn
->depth
,
554 miGetDefaultVisualMask(pScrn
->depth
),
555 pScrn
->rgbBits
, pScrn
->defaultVisual
))
558 if (!miSetPixmapDepths())
561 pScrn
->memPhysBase
= 0;
564 if (!fbScreenInit(pScreen
, NULL
,
565 pScrn
->virtualX
, pScrn
->virtualY
,
566 pScrn
->xDpi
, pScrn
->yDpi
,
567 pScrn
->displayWidth
, pScrn
->bitsPerPixel
))
570 if (pScrn
->bitsPerPixel
> 8) {
571 /* Fixup RGB ordering */
572 visual
= pScreen
->visuals
+ pScreen
->numVisuals
;
573 while (--visual
>= pScreen
->visuals
) {
574 if ((visual
->class | DynamicClass
) == DirectColor
) {
575 visual
->offsetRed
= pScrn
->offset
.red
;
576 visual
->offsetGreen
= pScrn
->offset
.green
;
577 visual
->offsetBlue
= pScrn
->offset
.blue
;
578 visual
->redMask
= pScrn
->mask
.red
;
579 visual
->greenMask
= pScrn
->mask
.green
;
580 visual
->blueMask
= pScrn
->mask
.blue
;
585 fbPictureInit(pScreen
, NULL
, 0);
587 ms
->blockHandler
= pScreen
->BlockHandler
;
588 pScreen
->BlockHandler
= drv_block_handler
;
589 ms
->createScreenResources
= pScreen
->CreateScreenResources
;
590 pScreen
->CreateScreenResources
= drv_create_screen_resources
;
592 xf86SetBlackWhitePixels(pScreen
);
595 ms
->exa
= xorg_exa_init(pScrn
, xf86ReturnOptValBool(ms
->Options
,
596 OPTION_2D_ACCEL
, TRUE
));
597 ms
->debug_fallback
= debug_get_bool_option("XORG_DEBUG_FALLBACK", TRUE
);
599 xorg_xv_init(pScreen
);
601 xorg_dri2_init(pScreen
);
605 miInitializeBackingStore(pScreen
);
606 xf86SetBackingStore(pScreen
);
607 xf86SetSilkenMouse(pScreen
);
608 miDCInitialize(pScreen
, xf86GetPointerScreenFuncs());
610 /* Need to extend HWcursor support to handle mask interleave */
612 xf86_cursors_init(pScreen
, 64, 64,
613 HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64
|
614 HARDWARE_CURSOR_ARGB
);
616 /* Must force it before EnterVT, so we are in control of VT and
617 * later memory should be bound when allocating, e.g rotate_mem */
618 pScrn
->vtSema
= TRUE
;
620 pScreen
->SaveScreen
= xf86SaveScreen
;
621 ms
->CloseScreen
= pScreen
->CloseScreen
;
622 pScreen
->CloseScreen
= drv_close_screen
;
624 if (!xf86CrtcScreenInit(pScreen
))
627 if (!miCreateDefColormap(pScreen
))
630 xf86DPMSInit(pScreen
, xf86DPMSSet
, 0);
632 if (serverGeneration
== 1)
633 xf86ShowUnusedOptions(pScrn
->scrnIndex
, pScrn
->options
);
635 return drv_enter_vt(scrnIndex
, 1);
639 drv_adjust_frame(int scrnIndex
, int x
, int y
, int flags
)
641 ScrnInfoPtr pScrn
= xf86Screens
[scrnIndex
];
642 xf86CrtcConfigPtr config
= XF86_CRTC_CONFIG_PTR(pScrn
);
643 xf86OutputPtr output
= config
->output
[config
->compat_output
];
644 xf86CrtcPtr crtc
= output
->crtc
;
646 if (crtc
&& crtc
->enabled
) {
647 crtc
->funcs
->set_mode_major(crtc
, pScrn
->currentMode
,
649 crtc
->x
= output
->initial_x
+ x
;
650 crtc
->y
= output
->initial_y
+ y
;
655 drv_free_screen(int scrnIndex
, int flags
)
657 drv_free_rec(xf86Screens
[scrnIndex
]);
661 drv_leave_vt(int scrnIndex
, int flags
)
663 ScrnInfoPtr pScrn
= xf86Screens
[scrnIndex
];
664 modesettingPtr ms
= modesettingPTR(pScrn
);
665 xf86CrtcConfigPtr config
= XF86_CRTC_CONFIG_PTR(pScrn
);
668 for (o
= 0; o
< config
->num_crtc
; o
++) {
669 xf86CrtcPtr crtc
= config
->crtc
[o
];
671 xorg_crtc_cursor_destroy(crtc
);
673 if (crtc
->rotatedPixmap
|| crtc
->rotatedData
) {
674 crtc
->funcs
->shadow_destroy(crtc
, crtc
->rotatedPixmap
,
676 crtc
->rotatedPixmap
= NULL
;
677 crtc
->rotatedData
= NULL
;
681 drmModeRmFB(ms
->fd
, ms
->fb_id
);
683 drv_restore_hw_state(pScrn
);
685 if (drmDropMaster(ms
->fd
))
686 xf86DrvMsg(pScrn
->scrnIndex
, X_WARNING
,
687 "drmDropMaster failed: %s\n", strerror(errno
));
689 pScrn
->vtSema
= FALSE
;
693 * This gets called when gaining control of the VT, and from ScreenInit().
696 drv_enter_vt(int scrnIndex
, int flags
)
698 ScrnInfoPtr pScrn
= xf86Screens
[scrnIndex
];
699 modesettingPtr ms
= modesettingPTR(pScrn
);
701 if (drmSetMaster(ms
->fd
)) {
702 if (errno
== EINVAL
) {
703 xf86DrvMsg(pScrn
->scrnIndex
, X_WARNING
,
704 "drmSetMaster failed: 2.6.29 or newer kernel required for "
705 "multi-server DRI\n");
707 xf86DrvMsg(pScrn
->scrnIndex
, X_WARNING
,
708 "drmSetMaster failed: %s\n", strerror(errno
));
713 * Only save state once per server generation since that's what most
714 * drivers do. Could change this to save state at each VT enter.
716 if (ms
->SaveGeneration
!= serverGeneration
) {
717 ms
->SaveGeneration
= serverGeneration
;
718 drv_save_hw_state(pScrn
);
721 if (!ms
->create_front_buffer(pScrn
))
724 if (!flags
&& !ms
->bind_front_buffer(pScrn
))
727 if (!xf86SetDesiredModes(pScrn
))
734 drv_switch_mode(int scrnIndex
, DisplayModePtr mode
, int flags
)
736 ScrnInfoPtr pScrn
= xf86Screens
[scrnIndex
];
738 return xf86SetSingleMode(pScrn
, mode
, RR_Rotate_0
);
742 drv_close_screen(int scrnIndex
, ScreenPtr pScreen
)
744 ScrnInfoPtr pScrn
= xf86Screens
[scrnIndex
];
745 modesettingPtr ms
= modesettingPTR(pScrn
);
748 drv_leave_vt(scrnIndex
, 0);
753 xorg_dri2_close(pScreen
);
756 pScreen
->BlockHandler
= ms
->blockHandler
;
757 pScreen
->CreateScreenResources
= ms
->createScreenResources
;
759 #ifdef DRM_MODE_FEATURE_DIRTYFB
761 DamageUnregister(&pScreen
->GetScreenPixmap(pScreen
)->drawable
, ms
->damage
);
762 DamageDestroy(ms
->damage
);
767 drmModeRmFB(ms
->fd
, ms
->fb_id
);
768 ms
->destroy_front_buffer(pScrn
);
771 xorg_exa_close(pScrn
);
774 drv_close_resource_management(pScrn
);
779 pScrn
->vtSema
= FALSE
;
780 pScreen
->CloseScreen
= ms
->CloseScreen
;
781 return (*pScreen
->CloseScreen
) (scrnIndex
, pScreen
);
785 drv_valid_mode(int scrnIndex
, DisplayModePtr mode
, Bool verbose
, int flags
)
792 * Front buffer backing store functions.
796 drv_destroy_front_buffer_ga3d(ScrnInfoPtr pScrn
)
798 modesettingPtr ms
= modesettingPTR(pScrn
);
799 pipe_texture_reference(&ms
->root_texture
, NULL
);
804 drv_create_front_buffer_ga3d(ScrnInfoPtr pScrn
)
806 modesettingPtr ms
= modesettingPTR(pScrn
);
807 unsigned handle
, stride
;
808 struct pipe_texture
*tex
;
812 tex
= xorg_exa_create_root_texture(pScrn
, pScrn
->virtualX
, pScrn
->virtualY
,
813 pScrn
->depth
, pScrn
->bitsPerPixel
);
818 if (!ms
->api
->local_handle_from_texture(ms
->api
, ms
->screen
,
835 drv_adjust_frame(pScrn
->scrnIndex
, pScrn
->frameX0
, pScrn
->frameY0
, 0);
837 pipe_texture_reference(&ms
->root_texture
, tex
);
838 pipe_texture_reference(&tex
, NULL
);
844 drv_bind_front_buffer_ga3d(ScrnInfoPtr pScrn
)
846 modesettingPtr ms
= modesettingPTR(pScrn
);
847 ScreenPtr pScreen
= pScrn
->pScreen
;
848 PixmapPtr rootPixmap
= pScreen
->GetScreenPixmap(pScreen
);
849 struct pipe_texture
*check
;
851 xorg_exa_set_displayed_usage(rootPixmap
);
852 xorg_exa_set_shared_usage(rootPixmap
);
853 xorg_exa_set_texture(rootPixmap
, ms
->root_texture
);
854 if (!pScreen
->ModifyPixmapHeader(rootPixmap
, -1, -1, -1, -1, -1, NULL
))
855 FatalError("Couldn't adjust screen pixmap\n");
857 check
= xorg_exa_get_texture(rootPixmap
);
858 if (ms
->root_texture
!= check
)
859 FatalError("Created new root texture\n");
861 pipe_texture_reference(&check
, NULL
);
867 drv_destroy_front_buffer_kms(ScrnInfoPtr pScrn
)
869 modesettingPtr ms
= modesettingPTR(pScrn
);
874 kms_bo_unmap(ms
->root_bo
);
875 kms_bo_destroy(ms
->root_bo
);
881 drv_create_front_buffer_kms(ScrnInfoPtr pScrn
)
883 modesettingPtr ms
= modesettingPTR(pScrn
);
884 unsigned handle
, stride
;
888 attr
[0] = KMS_BO_TYPE
;
889 attr
[1] = KMS_BO_TYPE_SCANOUT
;
891 attr
[3] = pScrn
->virtualX
;
892 attr
[4] = KMS_HEIGHT
;
893 attr
[5] = pScrn
->virtualY
;
896 if (kms_bo_create(ms
->kms
, attr
, &bo
))
899 if (kms_bo_get_prop(bo
, KMS_PITCH
, &stride
))
902 if (kms_bo_get_prop(bo
, KMS_HANDLE
, &handle
))
916 drv_adjust_frame(pScrn
->scrnIndex
, pScrn
->frameX0
, pScrn
->frameY0
, 0);
927 drv_bind_front_buffer_kms(ScrnInfoPtr pScrn
)
929 modesettingPtr ms
= modesettingPTR(pScrn
);
930 ScreenPtr pScreen
= pScrn
->pScreen
;
931 PixmapPtr rootPixmap
= pScreen
->GetScreenPixmap(pScreen
);
935 if (kms_bo_get_prop(ms
->root_bo
, KMS_PITCH
, &stride
))
938 if (kms_bo_map(ms
->root_bo
, &ptr
))
941 pScreen
->ModifyPixmapHeader(rootPixmap
,
950 #endif /* HAVE_LIBKMS */
952 static Bool
drv_init_front_buffer_functions(ScrnInfoPtr pScrn
)
954 modesettingPtr ms
= modesettingPTR(pScrn
);
956 ms
->destroy_front_buffer
= drv_destroy_front_buffer_ga3d
;
957 ms
->create_front_buffer
= drv_create_front_buffer_ga3d
;
958 ms
->bind_front_buffer
= drv_bind_front_buffer_ga3d
;
960 } else if (ms
->kms
) {
961 ms
->destroy_front_buffer
= drv_destroy_front_buffer_kms
;
962 ms
->create_front_buffer
= drv_create_front_buffer_kms
;
963 ms
->bind_front_buffer
= drv_bind_front_buffer_kms
;
971 /* vim: set sw=4 ts=8 sts=4: */