2 * Copyright 2001 by Alan Hourihane.
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Alan Hourihane not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. Alan Hourihane makes no representations
11 * about the suitability of this software for any purpose. It is provided
12 * "as is" without express or implied warranty.
14 * ALAN HOURIHANE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL ALAN HOURIHANE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
22 * Authors: Alan Hourihane, <alanh@tungstengraphics.com>
26 #include "gamma_context.h"
28 #include "glint_dri.h"
32 gammaScreenPtr
gammaCreateScreen( __DRIscreenPrivate
*sPriv
)
34 gammaScreenPtr gammaScreen
;
35 GLINTDRIPtr gDRIPriv
= (GLINTDRIPtr
)sPriv
->pDevPriv
;
39 /* Check the DRI externsion version */
40 if ( sPriv
->driMajor
!= 3 || sPriv
->driMinor
!= 1 ) {
41 __driUtilMessage( "Gamma DRI driver expected DRI version 4.0.x "
42 "but got version %d.%d.%d",
43 sPriv
->driMajor
, sPriv
->driMinor
, sPriv
->driPatch
);
47 /* Check that the DDX driver version is compatible */
48 if ( sPriv
->ddxMajor
!= 4 ||
49 sPriv
->ddxMinor
!= 0 ||
50 sPriv
->ddxPatch
< 0 ) {
51 __driUtilMessage( "r128 DRI driver expected DDX driver version 4.0.x but got version %d.%d.%d", sPriv
->ddxMajor
, sPriv
->ddxMinor
, sPriv
->ddxPatch
);
55 /* Check that the DRM driver version is compatible */
56 if ( sPriv
->drmMajor
!= 2 ||
57 sPriv
->drmMinor
!= 1 ||
58 sPriv
->drmPatch
< 0 ) {
59 __driUtilMessage( "r128 DRI driver expected DRM driver version 2.1.x but got version %d.%d.%d", sPriv
->drmMajor
, sPriv
->drmMinor
, sPriv
->drmPatch
);
64 /* Allocate the private area */
65 gammaScreen
= (gammaScreenPtr
) CALLOC( sizeof(*gammaScreen
) );
66 if ( !gammaScreen
) return NULL
;
68 gammaScreen
->regionCount
= 4; /* Magic number. Can we fix this? */
70 gammaScreen
->regions
= CALLOC(gammaScreen
->regionCount
*
73 gammaScreen
->regions
[0].handle
= gDRIPriv
->registers0
.handle
;
74 gammaScreen
->regions
[0].size
= gDRIPriv
->registers0
.size
;
75 gammaScreen
->regions
[1].handle
= gDRIPriv
->registers1
.handle
;
76 gammaScreen
->regions
[1].size
= gDRIPriv
->registers1
.size
;
77 gammaScreen
->regions
[2].handle
= gDRIPriv
->registers2
.handle
;
78 gammaScreen
->regions
[2].size
= gDRIPriv
->registers2
.size
;
79 gammaScreen
->regions
[3].handle
= gDRIPriv
->registers3
.handle
;
80 gammaScreen
->regions
[3].size
= gDRIPriv
->registers3
.size
;
82 /* Next, map all the regions */
83 for (i
= 0; i
< gammaScreen
->regionCount
; i
++) {
85 gammaScreen
->regions
[i
].handle
,
86 gammaScreen
->regions
[i
].size
,
87 &gammaScreen
->regions
[i
].map
)) {
89 (void)drmUnmap(gammaScreen
->regions
[i
].map
,
90 gammaScreen
->regions
[i
].size
);
96 /* Get the list of dma buffers */
97 gammaScreen
->bufs
= drmMapBufs(sPriv
->fd
);
99 if (!gammaScreen
->bufs
) {
100 while (gammaScreen
->regionCount
> 0) {
101 (void)drmUnmap(gammaScreen
->regions
[gammaScreen
->regionCount
].map
,
102 gammaScreen
->regions
[gammaScreen
->regionCount
].size
);
103 gammaScreen
->regionCount
--;
108 gammaScreen
->textureSize
= gDRIPriv
->textureSize
;
109 gammaScreen
->logTextureGranularity
= gDRIPriv
->logTextureGranularity
;
110 gammaScreen
->cpp
= gDRIPriv
->cpp
;
111 gammaScreen
->frontOffset
= gDRIPriv
->frontOffset
;
112 gammaScreen
->frontPitch
= gDRIPriv
->frontPitch
;
113 gammaScreen
->backOffset
= gDRIPriv
->backOffset
;
114 gammaScreen
->backPitch
= gDRIPriv
->backPitch
;
115 gammaScreen
->backX
= gDRIPriv
->backX
;
116 gammaScreen
->backY
= gDRIPriv
->backY
;
117 gammaScreen
->depthOffset
= gDRIPriv
->depthOffset
;
118 gammaScreen
->depthPitch
= gDRIPriv
->depthPitch
;
120 gammaScreen
->driScreen
= sPriv
;
125 /* Destroy the device specific screen private data struct.
127 void gammaDestroyScreen( __DRIscreenPrivate
*sPriv
)
129 gammaScreenPtr gammaScreen
= (gammaScreenPtr
)sPriv
->private;
131 /* First, unmap the dma buffers */
132 drmUnmapBufs( gammaScreen
->bufs
);
134 /* Next, unmap all the regions */
135 while (gammaScreen
->regionCount
> 0) {
136 (void)drmUnmap(gammaScreen
->regions
[gammaScreen
->regionCount
].map
,
137 gammaScreen
->regions
[gammaScreen
->regionCount
].size
);
138 gammaScreen
->regionCount
--;
140 FREE(gammaScreen
->regions
);