Fixed off by one errors in clipping.
[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 "gamma_context.h"
27 #include "gamma_vb.h"
28 #include "glint_dri.h"
29
30 #include "imports.h"
31
32 gammaScreenPtr gammaCreateScreen( __DRIscreenPrivate *sPriv )
33 {
34 gammaScreenPtr gammaScreen;
35 GLINTDRIPtr gDRIPriv = (GLINTDRIPtr)sPriv->pDevPriv;
36 int i;
37
38 #if 0
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 );
44 return NULL;
45 }
46
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 );
52 return GL_FALSE;
53 }
54
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 );
60 return GL_FALSE;
61 }
62 #endif
63
64 /* Allocate the private area */
65 gammaScreen = (gammaScreenPtr) CALLOC( sizeof(*gammaScreen) );
66 if ( !gammaScreen ) return NULL;
67
68 gammaScreen->regionCount = 4; /* Magic number. Can we fix this? */
69
70 gammaScreen->regions = CALLOC(gammaScreen->regionCount *
71 sizeof(gammaRegion));
72
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;
81
82 /* Next, map all the regions */
83 for (i = 0; i < gammaScreen->regionCount; i++) {
84 if (drmMap(sPriv->fd,
85 gammaScreen->regions[i].handle,
86 gammaScreen->regions[i].size,
87 &gammaScreen->regions[i].map)) {
88 while (--i > 0) {
89 (void)drmUnmap(gammaScreen->regions[i].map,
90 gammaScreen->regions[i].size);
91 }
92 return GL_FALSE;
93 }
94 }
95
96 /* Get the list of dma buffers */
97 gammaScreen->bufs = drmMapBufs(sPriv->fd);
98
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--;
104 }
105 return GL_FALSE;
106 }
107
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;
119
120 gammaScreen->driScreen = sPriv;
121
122 return gammaScreen;
123 }
124
125 /* Destroy the device specific screen private data struct.
126 */
127 void gammaDestroyScreen( __DRIscreenPrivate *sPriv )
128 {
129 gammaScreenPtr gammaScreen = (gammaScreenPtr)sPriv->private;
130
131 /* First, unmap the dma buffers */
132 drmUnmapBufs( gammaScreen->bufs );
133
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--;
139 }
140 FREE(gammaScreen->regions);
141 FREE(gammaScreen);
142 }