glx: Add an optional function call for getting the DRI driver interface.
[mesa.git] / src / glx / dri_common.c
1 /*
2 * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
3 * Copyright © 2008 Red Hat, Inc.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Soft-
7 * ware"), to deal in the Software without restriction, including without
8 * limitation the rights to use, copy, modify, merge, publish, distribute,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, provided that the above copyright
11 * notice(s) and this permission notice appear in all copies of the Soft-
12 * ware and that both the above copyright notice(s) and this permission
13 * notice appear in supporting documentation.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
17 * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY
18 * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN
19 * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE-
20 * QUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
22 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFOR-
23 * MANCE OF THIS SOFTWARE.
24 *
25 * Except as contained in this notice, the name of a copyright holder shall
26 * not be used in advertising or otherwise to promote the sale, use or
27 * other dealings in this Software without prior written authorization of
28 * the copyright holder.
29 *
30 * Authors:
31 * Kevin E. Martin <kevin@precisioninsight.com>
32 * Brian Paul <brian@precisioninsight.com>
33 * Kristian Høgsberg (krh@redhat.com)
34 */
35
36 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
37
38 #include <unistd.h>
39 #include <dlfcn.h>
40 #include <stdarg.h>
41 #include "glxclient.h"
42 #include "dri_common.h"
43
44 #ifndef RTLD_NOW
45 #define RTLD_NOW 0
46 #endif
47 #ifndef RTLD_GLOBAL
48 #define RTLD_GLOBAL 0
49 #endif
50
51 /**
52 * Print informational message to stderr if LIBGL_DEBUG is set to
53 * "verbose".
54 */
55 _X_HIDDEN void
56 InfoMessageF(const char *f, ...)
57 {
58 va_list args;
59 const char *env;
60
61 if ((env = getenv("LIBGL_DEBUG")) && strstr(env, "verbose")) {
62 fprintf(stderr, "libGL: ");
63 va_start(args, f);
64 vfprintf(stderr, f, args);
65 va_end(args);
66 }
67 }
68
69 /**
70 * Print error message to stderr if LIBGL_DEBUG is set to anything but
71 * "quiet", (do nothing if LIBGL_DEBUG is unset).
72 */
73 _X_HIDDEN void
74 ErrorMessageF(const char *f, ...)
75 {
76 va_list args;
77 const char *env;
78
79 if ((env = getenv("LIBGL_DEBUG")) && !strstr(env, "quiet")) {
80 fprintf(stderr, "libGL error: ");
81 va_start(args, f);
82 vfprintf(stderr, f, args);
83 va_end(args);
84 }
85 }
86
87 /**
88 * Print error message unless LIBGL_DEBUG is set to "quiet".
89 *
90 * The distinction between CriticalErrorMessageF and ErrorMessageF is
91 * that critcial errors will be printed by default, (even when
92 * LIBGL_DEBUG is unset).
93 */
94 _X_HIDDEN void
95 CriticalErrorMessageF(const char *f, ...)
96 {
97 va_list args;
98 const char *env;
99
100 if (!(env = getenv("LIBGL_DEBUG")) || !strstr(env, "quiet")) {
101 fprintf(stderr, "libGL error: ");
102 va_start(args, f);
103 vfprintf(stderr, f, args);
104 va_end(args);
105
106 if (!env || !strstr(env, "verbose"))
107 fprintf(stderr, "libGL error: Try again with LIBGL_DEBUG=verbose for more details.\n");
108 }
109 }
110
111 #ifndef DEFAULT_DRIVER_DIR
112 /* this is normally defined in Mesa/configs/default with DRI_DRIVER_SEARCH_PATH */
113 #define DEFAULT_DRIVER_DIR "/usr/local/lib/dri"
114 #endif
115
116 /**
117 * Try to \c dlopen the named driver.
118 *
119 * This function adds the "_dri.so" suffix to the driver name and searches the
120 * directories specified by the \c LIBGL_DRIVERS_PATH environment variable in
121 * order to find the driver.
122 *
123 * \param driverName - a name like "i965", "radeon", "nouveau", etc.
124 *
125 * \returns
126 * A handle from \c dlopen, or \c NULL if driver file not found.
127 */
128 _X_HIDDEN void *
129 driOpenDriver(const char *driverName)
130 {
131 void *glhandle, *handle;
132 const char *libPaths, *p, *next;
133 char realDriverName[200];
134 int len;
135
136 /* Attempt to make sure libGL symbols will be visible to the driver */
137 glhandle = dlopen("libGL.so.1", RTLD_NOW | RTLD_GLOBAL);
138
139 libPaths = NULL;
140 if (geteuid() == getuid()) {
141 /* don't allow setuid apps to use LIBGL_DRIVERS_PATH */
142 libPaths = getenv("LIBGL_DRIVERS_PATH");
143 if (!libPaths)
144 libPaths = getenv("LIBGL_DRIVERS_DIR"); /* deprecated */
145 }
146 if (libPaths == NULL)
147 libPaths = DEFAULT_DRIVER_DIR;
148
149 handle = NULL;
150 for (p = libPaths; *p; p = next) {
151 next = strchr(p, ':');
152 if (next == NULL) {
153 len = strlen(p);
154 next = p + len;
155 }
156 else {
157 len = next - p;
158 next++;
159 }
160
161 #ifdef GLX_USE_TLS
162 snprintf(realDriverName, sizeof realDriverName,
163 "%.*s/tls/%s_dri.so", len, p, driverName);
164 InfoMessageF("OpenDriver: trying %s\n", realDriverName);
165 handle = dlopen(realDriverName, RTLD_NOW | RTLD_GLOBAL);
166 #endif
167
168 if (handle == NULL) {
169 snprintf(realDriverName, sizeof realDriverName,
170 "%.*s/%s_dri.so", len, p, driverName);
171 InfoMessageF("OpenDriver: trying %s\n", realDriverName);
172 handle = dlopen(realDriverName, RTLD_NOW | RTLD_GLOBAL);
173 }
174
175 if (handle != NULL)
176 break;
177 else
178 ErrorMessageF("dlopen %s failed (%s)\n", realDriverName, dlerror());
179 }
180
181 if (!handle)
182 ErrorMessageF("unable to load driver: %s_dri.so\n", driverName);
183
184 if (glhandle)
185 dlclose(glhandle);
186
187 return handle;
188 }
189
190 _X_HIDDEN const __DRIextension **
191 driGetDriverExtensions(void *handle, const char *driver_name)
192 {
193 const __DRIextension **extensions = NULL;
194 const __DRIextension **(*get_extensions)(void);
195 char *get_extensions_name;
196
197 if (asprintf(&get_extensions_name, "%s_%s",
198 __DRI_DRIVER_GET_EXTENSIONS, driver_name) != -1) {
199 get_extensions = dlsym(handle, get_extensions_name);
200 if (get_extensions) {
201 free(get_extensions_name);
202 return get_extensions();
203 } else {
204 InfoMessageF("driver does not expose %s(): %s\n",
205 get_extensions_name, dlerror());
206 free(get_extensions_name);
207 }
208 }
209
210 extensions = dlsym(handle, __DRI_DRIVER_EXTENSIONS);
211 if (extensions == NULL) {
212 ErrorMessageF("driver exports no extensions (%s)\n", dlerror());
213 return NULL;
214 }
215
216 return extensions;
217 }
218
219 static GLboolean
220 __driGetMSCRate(__DRIdrawable *draw,
221 int32_t * numerator, int32_t * denominator,
222 void *loaderPrivate)
223 {
224 __GLXDRIdrawable *glxDraw = loaderPrivate;
225
226 return __glxGetMscRate(glxDraw, numerator, denominator);
227 }
228
229 _X_HIDDEN const __DRIsystemTimeExtension systemTimeExtension = {
230 {__DRI_SYSTEM_TIME, __DRI_SYSTEM_TIME_VERSION},
231 __glXGetUST,
232 __driGetMSCRate
233 };
234
235 #define __ATTRIB(attrib, field) \
236 { attrib, offsetof(struct glx_config, field) }
237
238 static const struct
239 {
240 unsigned int attrib, offset;
241 } attribMap[] = {
242 __ATTRIB(__DRI_ATTRIB_BUFFER_SIZE, rgbBits),
243 __ATTRIB(__DRI_ATTRIB_LEVEL, level),
244 __ATTRIB(__DRI_ATTRIB_RED_SIZE, redBits),
245 __ATTRIB(__DRI_ATTRIB_GREEN_SIZE, greenBits),
246 __ATTRIB(__DRI_ATTRIB_BLUE_SIZE, blueBits),
247 __ATTRIB(__DRI_ATTRIB_ALPHA_SIZE, alphaBits),
248 __ATTRIB(__DRI_ATTRIB_DEPTH_SIZE, depthBits),
249 __ATTRIB(__DRI_ATTRIB_STENCIL_SIZE, stencilBits),
250 __ATTRIB(__DRI_ATTRIB_ACCUM_RED_SIZE, accumRedBits),
251 __ATTRIB(__DRI_ATTRIB_ACCUM_GREEN_SIZE, accumGreenBits),
252 __ATTRIB(__DRI_ATTRIB_ACCUM_BLUE_SIZE, accumBlueBits),
253 __ATTRIB(__DRI_ATTRIB_ACCUM_ALPHA_SIZE, accumAlphaBits),
254 __ATTRIB(__DRI_ATTRIB_SAMPLE_BUFFERS, sampleBuffers),
255 __ATTRIB(__DRI_ATTRIB_SAMPLES, samples),
256 __ATTRIB(__DRI_ATTRIB_DOUBLE_BUFFER, doubleBufferMode),
257 __ATTRIB(__DRI_ATTRIB_STEREO, stereoMode),
258 __ATTRIB(__DRI_ATTRIB_AUX_BUFFERS, numAuxBuffers),
259 #if 0
260 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_TYPE, transparentPixel),
261 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_INDEX_VALUE, transparentIndex),
262 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_RED_VALUE, transparentRed),
263 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_GREEN_VALUE, transparentGreen),
264 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_BLUE_VALUE, transparentBlue),
265 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE, transparentAlpha),
266 __ATTRIB(__DRI_ATTRIB_RED_MASK, redMask),
267 __ATTRIB(__DRI_ATTRIB_GREEN_MASK, greenMask),
268 __ATTRIB(__DRI_ATTRIB_BLUE_MASK, blueMask),
269 __ATTRIB(__DRI_ATTRIB_ALPHA_MASK, alphaMask),
270 #endif
271 __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_WIDTH, maxPbufferWidth),
272 __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_HEIGHT, maxPbufferHeight),
273 __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_PIXELS, maxPbufferPixels),
274 __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH, optimalPbufferWidth),
275 __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT, optimalPbufferHeight),
276 #if 0
277 __ATTRIB(__DRI_ATTRIB_SWAP_METHOD, swapMethod),
278 #endif
279 __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGB, bindToTextureRgb),
280 __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGBA, bindToTextureRgba),
281 __ATTRIB(__DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE,
282 bindToMipmapTexture),
283 __ATTRIB(__DRI_ATTRIB_YINVERTED, yInverted),
284 __ATTRIB(__DRI_ATTRIB_FRAMEBUFFER_SRGB_CAPABLE, sRGBCapable)
285 };
286
287 static int
288 scalarEqual(struct glx_config *mode, unsigned int attrib, unsigned int value)
289 {
290 unsigned int glxValue;
291 int i;
292
293 for (i = 0; i < ARRAY_SIZE(attribMap); i++)
294 if (attribMap[i].attrib == attrib) {
295 glxValue = *(unsigned int *) ((char *) mode + attribMap[i].offset);
296 return glxValue == GLX_DONT_CARE || glxValue == value;
297 }
298
299 return GL_TRUE; /* Is a non-existing attribute equal to value? */
300 }
301
302 static int
303 driConfigEqual(const __DRIcoreExtension *core,
304 struct glx_config *config, const __DRIconfig *driConfig)
305 {
306 unsigned int attrib, value, glxValue;
307 int i;
308
309 i = 0;
310 while (core->indexConfigAttrib(driConfig, i++, &attrib, &value)) {
311 switch (attrib) {
312 case __DRI_ATTRIB_RENDER_TYPE:
313 glxValue = 0;
314 if (value & __DRI_ATTRIB_RGBA_BIT) {
315 glxValue |= GLX_RGBA_BIT;
316 }
317 if (value & __DRI_ATTRIB_COLOR_INDEX_BIT) {
318 glxValue |= GLX_COLOR_INDEX_BIT;
319 }
320 if (value & __DRI_ATTRIB_FLOAT_BIT) {
321 glxValue |= GLX_RGBA_FLOAT_BIT_ARB;
322 }
323 if (value & __DRI_ATTRIB_UNSIGNED_FLOAT_BIT) {
324 glxValue |= GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT;
325 }
326 if (glxValue != config->renderType)
327 return GL_FALSE;
328 break;
329
330 case __DRI_ATTRIB_CONFIG_CAVEAT:
331 if (value & __DRI_ATTRIB_NON_CONFORMANT_CONFIG)
332 glxValue = GLX_NON_CONFORMANT_CONFIG;
333 else if (value & __DRI_ATTRIB_SLOW_BIT)
334 glxValue = GLX_SLOW_CONFIG;
335 else
336 glxValue = GLX_NONE;
337 if (glxValue != config->visualRating)
338 return GL_FALSE;
339 break;
340
341 case __DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS:
342 glxValue = 0;
343 if (value & __DRI_ATTRIB_TEXTURE_1D_BIT)
344 glxValue |= GLX_TEXTURE_1D_BIT_EXT;
345 if (value & __DRI_ATTRIB_TEXTURE_2D_BIT)
346 glxValue |= GLX_TEXTURE_2D_BIT_EXT;
347 if (value & __DRI_ATTRIB_TEXTURE_RECTANGLE_BIT)
348 glxValue |= GLX_TEXTURE_RECTANGLE_BIT_EXT;
349 if (config->bindToTextureTargets != GLX_DONT_CARE &&
350 glxValue != config->bindToTextureTargets)
351 return GL_FALSE;
352 break;
353
354 default:
355 if (!scalarEqual(config, attrib, value))
356 return GL_FALSE;
357 }
358 }
359
360 return GL_TRUE;
361 }
362
363 static struct glx_config *
364 createDriMode(const __DRIcoreExtension * core,
365 struct glx_config *config, const __DRIconfig **driConfigs)
366 {
367 __GLXDRIconfigPrivate *driConfig;
368 int i;
369
370 for (i = 0; driConfigs[i]; i++) {
371 if (driConfigEqual(core, config, driConfigs[i]))
372 break;
373 }
374
375 if (driConfigs[i] == NULL)
376 return NULL;
377
378 driConfig = malloc(sizeof *driConfig);
379 if (driConfig == NULL)
380 return NULL;
381
382 driConfig->base = *config;
383 driConfig->driConfig = driConfigs[i];
384
385 return &driConfig->base;
386 }
387
388 _X_HIDDEN struct glx_config *
389 driConvertConfigs(const __DRIcoreExtension * core,
390 struct glx_config *configs, const __DRIconfig **driConfigs)
391 {
392 struct glx_config head, *tail, *m;
393
394 tail = &head;
395 head.next = NULL;
396 for (m = configs; m; m = m->next) {
397 tail->next = createDriMode(core, m, driConfigs);
398 if (tail->next == NULL) {
399 /* no matching dri config for m */
400 continue;
401 }
402
403
404 tail = tail->next;
405 }
406
407 return head.next;
408 }
409
410 _X_HIDDEN void
411 driDestroyConfigs(const __DRIconfig **configs)
412 {
413 int i;
414
415 for (i = 0; configs[i]; i++)
416 free((__DRIconfig *) configs[i]);
417 free(configs);
418 }
419
420 _X_HIDDEN __GLXDRIdrawable *
421 driFetchDrawable(struct glx_context *gc, GLXDrawable glxDrawable)
422 {
423 struct glx_display *const priv = __glXInitialize(gc->psc->dpy);
424 __GLXDRIdrawable *pdraw;
425 struct glx_screen *psc;
426
427 if (priv == NULL)
428 return NULL;
429
430 psc = priv->screens[gc->screen];
431 if (priv->drawHash == NULL)
432 return NULL;
433
434 if (__glxHashLookup(priv->drawHash, glxDrawable, (void *) &pdraw) == 0) {
435 pdraw->refcount ++;
436 return pdraw;
437 }
438
439 pdraw = psc->driScreen->createDrawable(psc, glxDrawable,
440 glxDrawable, gc->config);
441
442 if (pdraw == NULL) {
443 ErrorMessageF("failed to create drawable\n");
444 return NULL;
445 }
446
447 if (__glxHashInsert(priv->drawHash, glxDrawable, pdraw)) {
448 (*pdraw->destroyDrawable) (pdraw);
449 return NULL;
450 }
451 pdraw->refcount = 1;
452
453 return pdraw;
454 }
455
456 _X_HIDDEN void
457 driReleaseDrawables(struct glx_context *gc)
458 {
459 const struct glx_display *priv = gc->psc->display;
460 __GLXDRIdrawable *pdraw;
461
462 if (priv == NULL)
463 return;
464
465 if (__glxHashLookup(priv->drawHash,
466 gc->currentDrawable, (void *) &pdraw) == 0) {
467 if (pdraw->drawable == pdraw->xDrawable) {
468 pdraw->refcount --;
469 if (pdraw->refcount == 0) {
470 (*pdraw->destroyDrawable)(pdraw);
471 __glxHashDelete(priv->drawHash, gc->currentDrawable);
472 }
473 }
474 }
475
476 if (__glxHashLookup(priv->drawHash,
477 gc->currentReadable, (void *) &pdraw) == 0) {
478 if (pdraw->drawable == pdraw->xDrawable) {
479 pdraw->refcount --;
480 if (pdraw->refcount == 0) {
481 (*pdraw->destroyDrawable)(pdraw);
482 __glxHashDelete(priv->drawHash, gc->currentReadable);
483 }
484 }
485 }
486
487 gc->currentDrawable = None;
488 gc->currentReadable = None;
489
490 }
491
492 _X_HIDDEN bool
493 dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
494 unsigned *major_ver, unsigned *minor_ver,
495 uint32_t *render_type, uint32_t *flags, unsigned *api,
496 int *reset, unsigned *error)
497 {
498 unsigned i;
499 bool got_profile = false;
500 uint32_t profile;
501
502 *major_ver = 1;
503 *minor_ver = 0;
504 *render_type = GLX_RGBA_TYPE;
505 *reset = __DRI_CTX_RESET_NO_NOTIFICATION;
506 *flags = 0;
507 *api = __DRI_API_OPENGL;
508
509 if (num_attribs == 0) {
510 return true;
511 }
512
513 /* This is actually an internal error, but what the heck.
514 */
515 if (attribs == NULL) {
516 *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
517 return false;
518 }
519
520 for (i = 0; i < num_attribs; i++) {
521 switch (attribs[i * 2]) {
522 case GLX_CONTEXT_MAJOR_VERSION_ARB:
523 *major_ver = attribs[i * 2 + 1];
524 break;
525 case GLX_CONTEXT_MINOR_VERSION_ARB:
526 *minor_ver = attribs[i * 2 + 1];
527 break;
528 case GLX_CONTEXT_FLAGS_ARB:
529 *flags = attribs[i * 2 + 1];
530 break;
531 case GLX_CONTEXT_PROFILE_MASK_ARB:
532 profile = attribs[i * 2 + 1];
533 got_profile = true;
534 break;
535 case GLX_RENDER_TYPE:
536 *render_type = attribs[i * 2 + 1];
537 break;
538 case GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB:
539 switch (attribs[i * 2 + 1]) {
540 case GLX_NO_RESET_NOTIFICATION_ARB:
541 *reset = __DRI_CTX_RESET_NO_NOTIFICATION;
542 break;
543 case GLX_LOSE_CONTEXT_ON_RESET_ARB:
544 *reset = __DRI_CTX_RESET_LOSE_CONTEXT;
545 break;
546 default:
547 *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
548 return false;
549 }
550 break;
551 default:
552 /* If an unknown attribute is received, fail.
553 */
554 *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
555 return false;
556 }
557 }
558
559 if (!got_profile) {
560 if (*major_ver > 3 || (*major_ver == 3 && *minor_ver >= 2))
561 *api = __DRI_API_OPENGL_CORE;
562 } else {
563 switch (profile) {
564 case GLX_CONTEXT_CORE_PROFILE_BIT_ARB:
565 /* There are no profiles before OpenGL 3.2. The
566 * GLX_ARB_create_context_profile spec says:
567 *
568 * "If the requested OpenGL version is less than 3.2,
569 * GLX_CONTEXT_PROFILE_MASK_ARB is ignored and the functionality
570 * of the context is determined solely by the requested version."
571 */
572 *api = (*major_ver > 3 || (*major_ver == 3 && *minor_ver >= 2))
573 ? __DRI_API_OPENGL_CORE : __DRI_API_OPENGL;
574 break;
575 case GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB:
576 *api = __DRI_API_OPENGL;
577 break;
578 case GLX_CONTEXT_ES2_PROFILE_BIT_EXT:
579 *api = __DRI_API_GLES2;
580 break;
581 default:
582 *error = __DRI_CTX_ERROR_BAD_API;
583 return false;
584 }
585 }
586
587 /* Unknown flag value.
588 */
589 if (*flags & ~(__DRI_CTX_FLAG_DEBUG | __DRI_CTX_FLAG_FORWARD_COMPATIBLE
590 | __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS)) {
591 *error = __DRI_CTX_ERROR_UNKNOWN_FLAG;
592 return false;
593 }
594
595 /* There are no forward-compatible contexts before OpenGL 3.0. The
596 * GLX_ARB_create_context spec says:
597 *
598 * "Forward-compatible contexts are defined only for OpenGL versions
599 * 3.0 and later."
600 */
601 if (*major_ver < 3 && (*flags & __DRI_CTX_FLAG_FORWARD_COMPATIBLE) != 0) {
602 *error = __DRI_CTX_ERROR_BAD_FLAG;
603 return false;
604 }
605
606 if (*major_ver >= 3 && *render_type == GLX_COLOR_INDEX_TYPE) {
607 *error = __DRI_CTX_ERROR_BAD_FLAG;
608 return false;
609 }
610
611 /* The GLX_EXT_create_context_es2_profile spec says:
612 *
613 * "... If the version requested is 2.0, and the
614 * GLX_CONTEXT_ES2_PROFILE_BIT_EXT bit is set in the
615 * GLX_CONTEXT_PROFILE_MASK_ARB attribute (see below), then the context
616 * returned will implement OpenGL ES 2.0. This is the only way in which
617 * an implementation may request an OpenGL ES 2.0 context."
618 */
619 if (*api == __DRI_API_GLES2 && (*major_ver != 2 || *minor_ver != 0)) {
620 *error = __DRI_CTX_ERROR_BAD_API;
621 return false;
622 }
623
624 *error = __DRI_CTX_ERROR_SUCCESS;
625 return true;
626 }
627
628 #endif /* GLX_DIRECT_RENDERING */