2 * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
4 * Copyright 2010 George Sapountzis <gsapountzis@gmail.com>
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * DRISW utility functions, i.e. dri_util.c stripped from drm-specific bits.
30 #include "drisw_util.h"
39 setupLoaderExtensions(__DRIscreen
*psp
,
40 const __DRIextension
**extensions
)
44 for (i
= 0; extensions
[i
]; i
++) {
45 if (strcmp(extensions
[i
]->name
, __DRI_SWRAST_LOADER
) == 0)
46 psp
->swrast_loader
= (__DRIswrastLoaderExtension
*) extensions
[i
];
51 driCreateNewScreen(int scrn
, const __DRIextension
**extensions
,
52 const __DRIconfig
***driver_configs
, void *data
)
54 static const __DRIextension
*emptyExtensionList
[] = { NULL
};
59 psp
= CALLOC_STRUCT(__DRIscreenRec
);
63 setupLoaderExtensions(psp
, extensions
);
65 psp
->extensions
= emptyExtensionList
;
69 *driver_configs
= driDriverAPI
.InitScreen(psp
);
71 if (*driver_configs
== NULL
) {
79 static void driDestroyScreen(__DRIscreen
*psp
)
82 driDriverAPI
.DestroyScreen(psp
);
88 static const __DRIextension
**driGetExtensions(__DRIscreen
*psp
)
90 return psp
->extensions
;
99 driCreateNewContext(__DRIscreen
*psp
, const __DRIconfig
*config
,
100 __DRIcontext
*shared
, void *data
)
103 void * const shareCtx
= (shared
!= NULL
) ? shared
->driverPrivate
: NULL
;
105 pcp
= CALLOC_STRUCT(__DRIcontextRec
);
109 pcp
->loaderPrivate
= data
;
111 pcp
->driScreenPriv
= psp
;
112 pcp
->driDrawablePriv
= NULL
;
113 pcp
->driReadablePriv
= NULL
;
115 if (!driDriverAPI
.CreateContext(&config
->modes
, pcp
, shareCtx
)) {
124 driDestroyContext(__DRIcontext
*pcp
)
127 driDriverAPI
.DestroyContext(pcp
);
133 driCopyContext(__DRIcontext
*dst
, __DRIcontext
*src
, unsigned long mask
)
138 static void dri_get_drawable(__DRIdrawable
*pdp
);
139 static void dri_put_drawable(__DRIdrawable
*pdp
);
141 static int driBindContext(__DRIcontext
*pcp
,
145 /* Bind the drawable to the context */
147 pcp
->driDrawablePriv
= pdp
;
148 pcp
->driReadablePriv
= prp
;
150 pdp
->driContextPriv
= pcp
;
151 dri_get_drawable(pdp
);
153 if ( prp
&& pdp
!= prp
) {
154 dri_get_drawable(prp
);
158 return driDriverAPI
.MakeCurrent(pcp
, pdp
, prp
);
161 static int driUnbindContext(__DRIcontext
*pcp
)
169 pdp
= pcp
->driDrawablePriv
;
170 prp
= pcp
->driReadablePriv
;
172 /* already unbound */
176 driDriverAPI
.UnbindContext(pcp
);
178 dri_put_drawable(pdp
);
181 dri_put_drawable(prp
);
184 pcp
->driDrawablePriv
= NULL
;
185 pcp
->driReadablePriv
= NULL
;
195 static void dri_get_drawable(__DRIdrawable
*pdp
)
200 static void dri_put_drawable(__DRIdrawable
*pdp
)
207 driDriverAPI
.DestroyBuffer(pdp
);
213 static __DRIdrawable
*
214 driCreateNewDrawable(__DRIscreen
*psp
,
215 const __DRIconfig
*config
, void *data
)
219 pdp
= CALLOC_STRUCT(__DRIdrawableRec
);
223 pdp
->loaderPrivate
= data
;
225 pdp
->driScreenPriv
= psp
;
226 pdp
->driContextPriv
= NULL
;
228 dri_get_drawable(pdp
);
230 if (!driDriverAPI
.CreateBuffer(psp
, pdp
, &config
->modes
, GL_FALSE
)) {
235 pdp
->lastStamp
= 1; /* const */
241 driDestroyDrawable(__DRIdrawable
*pdp
)
243 dri_put_drawable(pdp
);
246 static void driSwapBuffers(__DRIdrawable
*pdp
)
248 driDriverAPI
.SwapBuffers(pdp
);
251 const __DRIcoreExtension driCoreExtension
= {
252 { __DRI_CORE
, __DRI_CORE_VERSION
},
253 NULL
, /* driCreateNewScreen */
257 driIndexConfigAttrib
,
258 NULL
, /* driCreateNewDrawable */
268 const __DRIswrastExtension driSWRastExtension
= {
269 { __DRI_SWRAST
, __DRI_SWRAST_VERSION
},