Merge commit 'origin/gallium-0.1' into gallium-0.2
[mesa.git] / src / mesa / drivers / dri / gamma / gamma_screen.c
1 /*
2 * Copyright 2001 by Alan Hourihane.
3 *
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.
13 *
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.
21 *
22 * Authors: Alan Hourihane, <alanh@tungstengraphics.com>
23 *
24 */
25
26 #include "gammacontext.h"
27 #include "gamma_vb.h"
28 #include "glint_dri.h"
29
30 #include "main/imports.h"
31
32 gammaScreenPtr gammaCreateScreen( __DRIscreenPrivate *sPriv )
33 {
34 gammaScreenPtr gammaScreen;
35 GLINTDRIPtr gDRIPriv = (GLINTDRIPtr)sPriv->pDevPriv;
36 int i;
37
38 if (sPriv->devPrivSize != sizeof(GLINTDRIRec)) {
39 fprintf(stderr,"\nERROR! sizeof(GLINTDRIRec) does not match passed size from device driver\n");
40 return GL_FALSE;
41 }
42
43 #if 0
44 /* Check the DRI externsion version */
45 if ( sPriv->driMajor != 3 || sPriv->driMinor != 1 ) {
46 __driUtilMessage( "Gamma DRI driver expected DRI version 4.0.x "
47 "but got version %d.%d.%d",
48 sPriv->driMajor, sPriv->driMinor, sPriv->driPatch );
49 return NULL;
50 }
51
52 /* Check that the DDX driver version is compatible */
53 if ( sPriv->ddxMajor != 4 ||
54 sPriv->ddxMinor != 0 ||
55 sPriv->ddxPatch < 0 ) {
56 __driUtilMessage( "r128 DRI driver expected DDX driver version 4.0.x but got version %d.%d.%d", sPriv->ddxMajor, sPriv->ddxMinor, sPriv->ddxPatch );
57 return GL_FALSE;
58 }
59
60 /* Check that the DRM driver version is compatible */
61 if ( sPriv->drmMajor != 2 ||
62 sPriv->drmMinor != 1 ||
63 sPriv->drmPatch < 0 ) {
64 __driUtilMessage( "r128 DRI driver expected DRM driver version 2.1.x but got version %d.%d.%d", sPriv->drmMajor, sPriv->drmMinor, sPriv->drmPatch );
65 return GL_FALSE;
66 }
67 #endif
68
69 /* Allocate the private area */
70 gammaScreen = (gammaScreenPtr) CALLOC( sizeof(*gammaScreen) );
71 if ( !gammaScreen ) return NULL;
72
73 gammaScreen->regionCount = 4; /* Magic number. Can we fix this? */
74
75 gammaScreen->regions = CALLOC(gammaScreen->regionCount *
76 sizeof(gammaRegion));
77
78 gammaScreen->regions[0].handle = gDRIPriv->registers0.handle;
79 gammaScreen->regions[0].size = gDRIPriv->registers0.size;
80 gammaScreen->regions[1].handle = gDRIPriv->registers1.handle;
81 gammaScreen->regions[1].size = gDRIPriv->registers1.size;
82 gammaScreen->regions[2].handle = gDRIPriv->registers2.handle;
83 gammaScreen->regions[2].size = gDRIPriv->registers2.size;
84 gammaScreen->regions[3].handle = gDRIPriv->registers3.handle;
85 gammaScreen->regions[3].size = gDRIPriv->registers3.size;
86
87 /* Next, map all the regions */
88 for (i = 0; i < gammaScreen->regionCount; i++) {
89 if (drmMap(sPriv->fd,
90 gammaScreen->regions[i].handle,
91 gammaScreen->regions[i].size,
92 &gammaScreen->regions[i].map)) {
93 while (--i > 0) {
94 (void)drmUnmap(gammaScreen->regions[i].map,
95 gammaScreen->regions[i].size);
96 }
97 return GL_FALSE;
98 }
99 }
100
101 /* Get the list of dma buffers */
102 gammaScreen->bufs = drmMapBufs(sPriv->fd);
103
104 if (!gammaScreen->bufs) {
105 while (gammaScreen->regionCount > 0) {
106 (void)drmUnmap(gammaScreen->regions[gammaScreen->regionCount].map,
107 gammaScreen->regions[gammaScreen->regionCount].size);
108 gammaScreen->regionCount--;
109 }
110 return GL_FALSE;
111 }
112
113 gammaScreen->textureSize = gDRIPriv->textureSize;
114 gammaScreen->logTextureGranularity = gDRIPriv->logTextureGranularity;
115 gammaScreen->cpp = gDRIPriv->cpp;
116 gammaScreen->frontOffset = gDRIPriv->frontOffset;
117 gammaScreen->frontPitch = gDRIPriv->frontPitch;
118 gammaScreen->backOffset = gDRIPriv->backOffset;
119 gammaScreen->backPitch = gDRIPriv->backPitch;
120 gammaScreen->backX = gDRIPriv->backX;
121 gammaScreen->backY = gDRIPriv->backY;
122 gammaScreen->depthOffset = gDRIPriv->depthOffset;
123 gammaScreen->depthPitch = gDRIPriv->depthPitch;
124
125 gammaScreen->driScreen = sPriv;
126
127 return gammaScreen;
128 }
129
130 /* Destroy the device specific screen private data struct.
131 */
132 void gammaDestroyScreen( __DRIscreenPrivate *sPriv )
133 {
134 gammaScreenPtr gammaScreen = (gammaScreenPtr)sPriv->private;
135
136 /* First, unmap the dma buffers */
137 drmUnmapBufs( gammaScreen->bufs );
138
139 /* Next, unmap all the regions */
140 while (gammaScreen->regionCount > 0) {
141 (void)drmUnmap(gammaScreen->regions[gammaScreen->regionCount].map,
142 gammaScreen->regions[gammaScreen->regionCount].size);
143 gammaScreen->regionCount--;
144 }
145 FREE(gammaScreen->regions);
146 FREE(gammaScreen);
147 }