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.
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
};
57 psp
= CALLOC_STRUCT(__DRIscreenRec
);
61 setupLoaderExtensions(psp
, extensions
);
63 psp
->loaderPrivate
= data
;
65 psp
->extensions
= emptyExtensionList
;
69 *driver_configs
= driDriverAPI
.InitScreen(psp
);
70 if (*driver_configs
== NULL
) {
78 static void driDestroyScreen(__DRIscreen
*psp
)
81 driDriverAPI
.DestroyScreen(psp
);
86 static const __DRIextension
**driGetExtensions(__DRIscreen
*psp
)
88 return psp
->extensions
;
97 driCreateNewContextForAPI(__DRIscreen
*psp
, int api
,
98 const __DRIconfig
*config
,
99 __DRIcontext
*shared
, void *data
)
102 const struct gl_config
*modes
= (config
!= NULL
) ? &config
->modes
: NULL
;
103 void * const shareCtx
= (shared
!= NULL
) ? shared
->driverPrivate
: NULL
;
107 case __DRI_API_OPENGL
:
108 mesa_api
= API_OPENGL
;
111 mesa_api
= API_OPENGLES
;
113 case __DRI_API_GLES2
:
114 mesa_api
= API_OPENGLES2
;
120 pcp
= CALLOC_STRUCT(__DRIcontextRec
);
124 pcp
->loaderPrivate
= data
;
126 pcp
->driScreenPriv
= psp
;
127 pcp
->driDrawablePriv
= NULL
;
128 pcp
->driReadablePriv
= NULL
;
130 if (!driDriverAPI
.CreateContext(mesa_api
, modes
, pcp
, shareCtx
)) {
138 static __DRIcontext
*
139 driCreateNewContext(__DRIscreen
*psp
, const __DRIconfig
*config
,
140 __DRIcontext
*shared
, void *data
)
142 return driCreateNewContextForAPI(psp
, __DRI_API_OPENGL
,
143 config
, shared
, data
);
147 driDestroyContext(__DRIcontext
*pcp
)
150 driDriverAPI
.DestroyContext(pcp
);
156 driCopyContext(__DRIcontext
*dst
, __DRIcontext
*src
, unsigned long mask
)
161 static void dri_get_drawable(__DRIdrawable
*pdp
);
162 static void dri_put_drawable(__DRIdrawable
*pdp
);
164 static int driBindContext(__DRIcontext
*pcp
,
168 /* Bind the drawable to the context */
170 pcp
->driDrawablePriv
= pdp
;
171 pcp
->driReadablePriv
= prp
;
173 pdp
->driContextPriv
= pcp
;
174 dri_get_drawable(pdp
);
176 if (prp
&& pdp
!= prp
) {
177 dri_get_drawable(prp
);
181 return driDriverAPI
.MakeCurrent(pcp
, pdp
, prp
);
184 static int driUnbindContext(__DRIcontext
*pcp
)
192 pdp
= pcp
->driDrawablePriv
;
193 prp
= pcp
->driReadablePriv
;
195 /* already unbound */
199 driDriverAPI
.UnbindContext(pcp
);
201 dri_put_drawable(pdp
);
204 dri_put_drawable(prp
);
207 pcp
->driDrawablePriv
= NULL
;
208 pcp
->driReadablePriv
= NULL
;
218 static void dri_get_drawable(__DRIdrawable
*pdp
)
223 static void dri_put_drawable(__DRIdrawable
*pdp
)
230 driDriverAPI
.DestroyBuffer(pdp
);
235 static __DRIdrawable
*
236 driCreateNewDrawable(__DRIscreen
*psp
,
237 const __DRIconfig
*config
, void *data
)
241 pdp
= CALLOC_STRUCT(__DRIdrawableRec
);
245 pdp
->loaderPrivate
= data
;
247 pdp
->driScreenPriv
= psp
;
248 pdp
->driContextPriv
= NULL
;
250 dri_get_drawable(pdp
);
252 if (!driDriverAPI
.CreateBuffer(psp
, pdp
, &config
->modes
, GL_FALSE
)) {
257 pdp
->lastStamp
= 1; /* const */
263 driDestroyDrawable(__DRIdrawable
*pdp
)
265 dri_put_drawable(pdp
);
268 static void driSwapBuffers(__DRIdrawable
*pdp
)
270 driDriverAPI
.SwapBuffers(pdp
);
273 const __DRIcoreExtension driCoreExtension
= {
274 { __DRI_CORE
, __DRI_CORE_VERSION
},
275 NULL
, /* driCreateNewScreen */
279 driIndexConfigAttrib
,
280 NULL
, /* driCreateNewDrawable */
290 const __DRIswrastExtension driSWRastExtension
= {
291 /* Force the version to 2 because the underlying driver don't (can't!)
292 * support the extra requirements of CreateContextAttribs.
296 driCreateNewDrawable
,
297 driCreateNewContextForAPI
,